@soba-so/react 0.0.17 → 0.0.18
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.
- package/dist/ModelPicker.d.ts +31 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.mjs +360 -9
- package/dist/styles.css +352 -1
- package/dist/tier.d.ts +35 -0
- package/dist/types.d.ts +106 -0
- package/dist/useCheckout.d.ts +41 -0
- package/dist/useCompute.d.ts +91 -0
- package/dist/useConnectButton.d.ts +75 -0
- package/dist/useConnectNudge.d.ts +204 -0
- package/dist/useModel.d.ts +93 -0
- package/dist/useOpenSobaConnect.d.ts +1 -1
- package/package.json +9 -8
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
var Cn=class extends Error{status;constructor(n,t){super(n),this.name="ConnectError",this.status=t}},as=5*6e4,Nn=class{session;baseUrl;doFetch;lastMachines=null;machinesUrl=null;gatewayBackUntil=0;constructor(n){this.session=n.session,this.baseUrl=(n.baseUrl??"").replace(/\/+$/,""),this.doFetch=n.fetchImpl??fetch.bind(globalThis)}async context(){let n=await this.request("GET","/v1/connect");return this.setMachinesUrl(n.machines_url),n}setMachinesUrl(n){typeof n=="string"&&/^https?:\/\//.test(n)&&(this.machinesUrl=n)}async machines(){let n=this.lastMachines,t=n?`?v=${encodeURIComponent(n.version)}`:"",r;if(this.machinesUrl&&Date.now()>=this.gatewayBackUntil)try{r=await this.request("GET",`${this.machinesUrl}${t}`)}catch(a){if(a instanceof Cn&&a.status===401)throw a;this.gatewayBackUntil=Date.now()+as}if(r??=await this.request("GET",`/v1/machines${t}`),r.unchanged&&n)return n.machines;let s=Array.isArray(r.machines)?r.machines:[];return this.lastMachines=typeof r.version=="string"?{version:r.version,machines:s}:null,s}lookup(n){return this.request("GET",`/v1/device/lookup?code=${encodeURIComponent(n)}`)}approve(n){return this.request("POST","/v1/device/approve",{user_code:n})}claim(n){return this.request("POST","/v1/device/claim",{pairing_nonce:n})}deny(n){return this.request("POST","/v1/device/deny",{user_code:n})}plans(){return this.request("GET","/v1/plans")}selectPlan(n){return this.request("POST","/v1/plans/select",{plan:n})}checkoutPlan(n,t){return this.request("POST","/v1/plans/checkout",{plan:n,...t?.successUrl?{success_url:t.successUrl}:{},...t?.cancelUrl?{cancel_url:t.cancelUrl}:{}})}leavePlan(){return this.request("DELETE","/v1/plans/select")}hosted(){return this.request("GET","/v1/hosted")}startHosted(){return this.request("POST","/v1/hosted/start")}disconnectHosted(n){return this.request("DELETE",n?`/v1/hosted?provider=${encodeURIComponent(n)}`:"/v1/hosted")}approveRuntime(n,t){return this.request("POST","/v1/runtimes/approve",{machine_id:n,runtime_id:t})}async request(n,t,r){let s=await this.doFetch(/^https?:\/\//.test(t)?t:`${this.baseUrl}${t}`,{method:n,headers:{authorization:`Bearer ${this.session}`,...r?{"content-type":"application/json"}:{}},...r?{body:JSON.stringify(r)}:{}}),a={};try{a=await s.json()}catch{}if(!s.ok){let o=typeof a.error=="string"?a.error:`Request failed (${s.status})`;throw new Cn(o,s.status)}return a}};function kn(e){let n=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!n?.[1])return"#ffffff";let t=n[1].length===3?[...n[1]].map(a=>a+a).join(""):n[1],r=a=>{let o=Number.parseInt(t.slice(a*2,a*2+2),16)/255;return o<=.04045?o/12.92:((o+.055)/1.055)**2.4};return .2126*r(0)+.7152*r(1)+.0722*r(2)>.45?"#101012":"#ffffff"}function dt(e){let n=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!n?.[1])return null;let t=n[1].length===3?[...n[1]].map(r=>r+r).join(""):n[1];return[0,1,2].map(r=>Number.parseInt(t.slice(r*2,r*2+2),16))}function cn(e,n,t){let r=dt(e),s=dt(n);return!r||!s?e:`#${r.map((o,c)=>Math.round(o+(s[c]-o)*t)).map(o=>o.toString(16).padStart(2,"0")).join("")}`}function Ye(e,n){if(!dt(e))return{};let t=kn(e),r=n?.trim();return{"--sc-ground":e,"--sc-shell":e,"--sc-sheet":cn(e,t,.07),"--sc-raised":cn(e,t,.13),"--sc-line":cn(e,t,.18),"--sc-line-2":cn(e,t,.28),"--sc-text":t,"--sc-text-2":cn(t,e,.15),"--sc-muted":cn(t,e,.38),...r?{"--sc-accent":r,"--sc-accent-fg":kn(r)}:{"--sc-accent":t,"--sc-accent-fg":e}}}function pt(e){return e.authenticated===!0?{tone:"ok",text:"signed in"}:e.authenticated===!1?{tone:"warn",text:e.auth_hint??"signed out on that machine"}:{tone:"unknown",text:"could not tell"}}function mt(e){let{platform:n,arch:t}=e;if(!n)return null;let r=n==="darwin"||n==="macos",s=r?"Mac":n==="win32"||n==="windows"?"Windows PC":"Linux machine";return r?`${t==="aarch64"||t==="arm64"?"Apple silicon ":""}${s}`:s}function xn(e){return e.find(n=>n.state==="offline")??null}function Je(e){let n=e.label?.trim(),t=e.name?.trim();return n&&(!t||n!==t)?n:(t??n??"").replace(/\.(local|lan|home|internal)$/i,"").replace(/[-_]+/g," ").trim()||n||"This machine"}function Sn(e){let n=r=>r.state==="busy"?0:r.state==="online"?1:2,t=r=>r.last_seen_at?Date.parse(r.last_seen_at):0;return[...e].sort((r,s)=>n(r)-n(s)||t(s)-t(r))[0]??null}function un(e){return e?e.state==="busy"?{tone:"busy",word:"Serving"}:e.state==="online"?{tone:"ok",word:"Connected"}:{tone:"off",word:"Asleep"}:{tone:"off",word:"No compute"}}function ht(e){return e.state==="online"||e.state==="busy"}function ft(e){if(!e)return"never seen";let n=Date.parse(e);if(Number.isNaN(n))return"never seen";let t=Date.now()-n,r=6e4;return t<2*r?"just now":t<60*r?`${Math.floor(t/r)} min ago`:t<24*60*r?`${Math.floor(t/(60*r))} hr ago`:`${Math.floor(t/(24*60*r))} days ago`}import{jsx as ve,jsxs as is}from"react/jsx-runtime";function j({className:e}){return is("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:[ve("path",{d:"M18.125 7.039A8.6 8.6 0 1 0 18.125 16.961A6 6 0 0 1 18.125 7.039Z",fill:"currentColor"}),ve("path",{d:"M19.925 7.039A8.6 8.6 0 0 1 19.925 16.961A6 6 0 0 0 19.925 7.039Z",fill:"currentColor"})]})}function gr({className:e}){return ve("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:ve("path",{fill:"currentColor",d:"M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z"})})}function Qe({className:e}){return ve("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:ve("path",{fill:"currentColor",d:"M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"})})}function zn({className:e}){return ve("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:ve("path",{d:"M4 5h16v11H4zM9 20h6M12 16v4",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function gt({className:e}){return ve("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:ve("path",{d:"M5 6h14v10H5zM2.5 19.5h19",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}var $e={claude:gr,chatgpt:Qe,local:zn};var de=[{id:"claude",costClass:"user-subscription",short:"Claude Code",label:"Continue with Claude",title:"The Claude plan you already pay for",cost:"Nothing beyond the plan",prerequisite:"Claude Code installed and signed in",hint:"Install it from claude.ai/code, then run `claude` once and sign in.",install:"https://claude.com/product/claude-code",expects:["claude-code"]},{id:"chatgpt",costClass:"user-subscription",short:"Codex",label:"Continue with ChatGPT",title:"The ChatGPT plan you already pay for",cost:"Nothing beyond the plan",prerequisite:"Codex installed and signed in",hint:"Install Codex, then run `codex` once and sign in.",install:"https://learn.chatgpt.com/codex/cli",expects:["codex"]},{id:"local",costClass:"user-hardware",short:"Local models",label:"Use a model on this machine",title:"A model on your own machine",cost:"Free. You bought the hardware",prerequisite:"Ollama running, with a model pulled",hint:"Install Ollama, then `ollama pull` a model before pairing.",install:"https://ollama.com",expects:["ollama","openai-api"]}],br=["claude","chatgpt"];function bt(){return de.filter(e=>br.includes(e.id))}function yt(e){return de.filter(n=>n.costClass===e)}function wt(e){return de.find(n=>n.expects.includes(e))??null}import{jsx as C,jsxs as q}from"react/jsx-runtime";function Ze({machines:e,hosted:n=[],onApproveRuntime:t,onDisconnectHosted:r,onPair:s,onRefresh:a,refreshing:o,busy:c,appName:i,error:u}){let d=Sn(e),f=e.filter(b=>b.id!==d?.id);return!d&&n.length===0&&!s?C("p",{className:"sc-note",children:"Nothing connected yet."}):q("div",{className:"sc-tray",children:[d&&C(Vn,{title:"This machine",action:a&&C("button",{type:"button",className:"sc-disc",onClick:a,disabled:o,"aria-label":"Refresh",title:"Refresh",children:C(ms,{spinning:!!o})}),children:C(ls,{machine:d})}),d&&C(Vn,{title:"Agents on it",children:d.runtimes.length>0?d.runtimes.map(b=>C(us,{runtime:b,...t?{onApprove:()=>t(d.id,b.id)}:{}},b.id)):C("p",{className:"sc-row-note",children:"No agent advertised. Install Claude Code, Codex or Ollama on that machine."})}),n.length>0&&C(Vn,{title:n.length>1?"Connected plans":"Connected plan",children:n.map(b=>C(ds,{credential:b,appName:i,busy:c,...r?{onDisconnect:()=>r(b.provider)}:{}},b.provider))}),(f.length>0||s)&&q(Vn,{title:f.length>0?"Your other machines":d?"Add a machine":"Your machines",children:[f.map(b=>C(cs,{machine:b},b.id)),s&&q("button",{type:"button",className:"sc-pair",onClick:s,children:[C("span",{className:"sc-otile","aria-hidden":"true",children:C(ps,{})}),C("span",{className:"sc-oname",children:e.length>0?"Pair another machine":"Connect a machine"})]})]}),u&&C("p",{className:"sc-error sc-tray-error",children:u})]})}function Vn({title:e,action:n,children:t}){return q("section",{className:"sc-group",children:[q("div",{className:"sc-group-cap",children:[C("p",{className:"sc-group-title",children:e}),n]}),C("div",{className:"sc-group-card",children:t})]})}function ls({machine:e}){let n=ht(e),t=[n?null:"Asleep or offline",mt(e),e.always_on?"always on":null,n&&e.capacity>0?`${e.active} of ${e.capacity} in flight`:ft(e.last_seen_at)].filter(Boolean);return q("div",{className:"sc-mrow",children:[q("span",{className:"sc-mtile","aria-hidden":"true",children:[C(yr,{}),C("span",{className:`sc-mbadge sc-mbadge-${un(e).tone}`})]}),q("span",{className:"sc-mid",children:[C("span",{className:"sc-mname",children:Je(e)}),C("span",{className:"sc-mmeta",children:t.map((r,s)=>q("span",{children:[s>0&&C("span",{className:"sc-mmeta-sep",children:"\xB7"}),r]},r))})]})]})}function cs({machine:e}){let n=un(e);return q("div",{className:"sc-orow",children:[C("span",{className:"sc-otile","aria-hidden":"true",children:C(yr,{})}),C("span",{className:"sc-oname",children:Je(e)}),C("span",{className:"sc-oword",children:n.word}),C("span",{className:`sc-dot sc-dot-${n.tone}`,"aria-hidden":"true"})]})}function us({runtime:e,onApprove:n}){let t=wt(e.id),r=t?$e[t.id]:null,s=pt(e);return q("div",{className:"sc-arow",children:[C("span",{className:"sc-runtime-tile","aria-hidden":"true",children:r&&C(r,{className:"sc-runtime-mark"})}),q("span",{className:"sc-aname",children:[e.display_name,e.version&&q("span",{className:"sc-aversion",children:[" ",e.version]})]}),e.quarantined?n?C("button",{type:"button",className:"sc-row-act",onClick:n,children:"Let it serve"}):C("span",{className:"sc-averdict sc-tone-warn",children:"new, not serving yet"}):s.tone==="ok"?q("span",{className:"sc-averdict",children:[C("span",{className:"sc-dot sc-dot-ok","aria-hidden":"true"}),C("span",{className:"sc-sr",children:s.text})]}):C("span",{className:`sc-averdict sc-tone-${s.tone}`,children:s.text})]})}function ds({credential:e,appName:n,busy:t,onDisconnect:r}){return q("div",{className:"sc-hrow",children:[q("div",{className:"sc-orow",children:[C("span",{className:"sc-otile","aria-hidden":"true",children:C(Qe,{className:"sc-omark"})}),q("span",{className:"sc-mid",children:[C("span",{className:"sc-oname",children:e.provider==="openai-chatgpt"?"ChatGPT plan":e.provider}),C("span",{className:"sc-mmeta",children:e.account_label??"signed in"})]}),r&&C("button",{type:"button",className:"sc-row-act",onClick:r,disabled:t,children:"Disconnect"})]}),r&&q("p",{className:"sc-row-note",children:[n??"This app"," stops using it. To withdraw the grant entirely, remove it in your OpenAI settings."]})]})}function yr(){return q("svg",{viewBox:"0 0 32 24","aria-hidden":"true",focusable:"false",className:"sc-mglyph",children:[C("rect",{x:"4",y:"1.5",width:"24",height:"15",rx:"2.5",fill:"var(--sc-sheet, #ffffff)",stroke:"currentColor",strokeWidth:"2"}),C("rect",{x:"1",y:"19.5",width:"30",height:"2.5",rx:"1.25",fill:"currentColor"})]})}function ps(){return C("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:"sc-oglyph",children:C("path",{d:"M12 5v14M5 12h14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}function ms({spinning:e}){return C("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e?"sc-dglyph sc-spin":"sc-dglyph",children:C("path",{d:"M21 12a9 9 0 1 1-2.64-6.36M21 3v6h-6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as hs}from"react/jsx-runtime";function Pn({machines:e,onApproveRuntime:n}){return hs(Ze,{machines:e,...n?{onApproveRuntime:n}:{}})}var vt={ready:{arc:!0},serving:{arc:!0,slot:"stream"},paused:{arc:!1,slot:"zzz"},thinking:{arc:!1,slot:"dots"},connecting:{arc:!1,slot:"orbit"},attention:{arc:!1,slot:"bang"},gone:{arc:!1,slot:"cross"},snap:{arc:!1,slot:"snap"},listening:{arc:!1,slot:"bars"},permission:{arc:!1,slot:"ring"},ai:{arc:!1,slot:"sparks"}};var Ct="105 162 420 420",Nt="M407.1 308.9 A158 158 0 1 0 407.1 491.1 A116 116 0 0 1 407.1 308.9 Z",Xe="M448.5 320 A110 110 0 0 1 448.5 480";import{Fragment as En,jsx as k,jsxs as De}from"react/jsx-runtime";function kt({kind:e,size:n=44,className:t}){let r=vt[e];return De("svg",{className:`bx${t?` ${t}`:""}`,"data-expression":e,viewBox:Ct,overflow:"visible",width:n,height:n,"aria-hidden":"true",children:[k("path",{d:Nt,fill:"currentColor"}),k("path",{className:"bx-arc",d:Xe,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),r.slot==="stream"&&k(fs,{}),r.slot==="zzz"&&k(gs,{}),r.slot==="dots"&&k(bs,{}),r.slot==="bang"&&k(ys,{}),r.slot==="orbit"&&k(ws,{}),r.slot==="cross"&&k(vs,{}),r.slot==="snap"&&k(Cs,{}),r.slot==="bars"&&k(Ns,{}),r.slot==="ring"&&k(ks,{}),r.slot==="sparks"&&k(xs,{})]})}function fs(){return k("path",{className:"bx-st",d:"M475.3 290.3 A150 150 0 0 1 475.3 509.7",fill:"none",stroke:"currentColor",strokeWidth:"15",strokeLinecap:"round",strokeDasharray:"0.1 31"})}function gs(){return De(En,{children:[k("g",{className:"bx-z1",children:k("path",{d:"M444 372 H496 L444 436 H496",fill:"none",stroke:"currentColor",strokeWidth:"20",strokeLinecap:"round",strokeLinejoin:"round"})}),k("g",{className:"bx-z2",children:k("path",{d:"M492 300 H522 L492 338 H522",fill:"none",stroke:"currentColor",strokeWidth:"15",strokeLinecap:"round",strokeLinejoin:"round"})})]})}function bs(){return De(En,{children:[k("circle",{className:"bx-th",cx:"463.1",cy:"336.9",r:"21",fill:"currentColor"}),k("circle",{className:"bx-th bx-th2",cx:"483",cy:"400",r:"21",fill:"currentColor"}),k("circle",{className:"bx-th bx-th3",cx:"463.1",cy:"463.1",r:"21",fill:"currentColor"})]})}function ys(){return De("g",{className:"bx-at",children:[k("line",{x1:"490",y1:"312",x2:"490",y2:"414",stroke:"currentColor",strokeWidth:"46",strokeLinecap:"round"}),k("circle",{cx:"490",cy:"484",r:"28",fill:"currentColor"})]})}function ws(){return De("g",{className:"bx-ob",children:[k("path",{d:Xe,fill:"none",stroke:"var(--tile-bg, transparent)",strokeWidth:41,strokeLinecap:"round"}),k("path",{d:Xe,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})]})}function vs(){return De(En,{children:[k("path",{className:"bx-xa",d:Xe,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),k("g",{className:"bx-xx",children:k("path",{d:"M442 364 L514 436 M514 364 L442 436",fill:"none",stroke:"currentColor",strokeWidth:"24",strokeLinecap:"round"})})]})}function Cs(){return k("path",{className:"bx-snap",d:Xe,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})}function Ns(){return De("g",{stroke:"currentColor",strokeWidth:"17",strokeLinecap:"round",children:[k("line",{className:"bx-vb",x1:"452",y1:"370",x2:"452",y2:"430"}),k("line",{className:"bx-vb bx-vb2",x1:"482",y1:"330",x2:"482",y2:"470"}),k("line",{className:"bx-vb bx-vb3",x1:"512",y1:"355",x2:"512",y2:"445"})]})}function ks(){return k(En,{children:[[450,366],[474,376],[484,400],[474,424],[450,434],[426,424],[416,400],[426,376]].map(([n,t],r)=>k("circle",{className:"bx-w",cx:n,cy:t,r:"11",fill:"currentColor",style:{animationDelay:`${-1.2+r*.15}s`}},r))})}function xs(){return De(En,{children:[k("g",{className:"bx-sp",children:k("path",{d:"M460 300 Q465.4 324.6 490 330 Q465.4 335.4 460 360 Q454.6 335.4 430 330 Q454.6 324.6 460 300 Z",fill:"currentColor"})}),k("g",{className:"bx-sp bx-sp2",children:k("path",{d:"M486 356 Q493.92 392.08 530 400 Q493.92 407.92 486 444 Q478.08 407.92 442 400 Q478.08 392.08 486 356 Z",fill:"currentColor"})}),k("g",{className:"bx-sp bx-sp3",children:k("path",{d:"M460 440 Q465.4 464.6 490 470 Q465.4 475.4 460 500 Q454.6 475.4 430 470 Q454.6 464.6 460 440 Z",fill:"currentColor"})})]})}import{useCallback as ie,useEffect as ae,useId as Ls,useMemo as Ue,useRef as dn,useState as U}from"react";var Mn=[{slug:"mac-arm",label:"macOS, Apple silicon"},{slug:"mac-intel",label:"macOS, Intel"},{slug:"windows",label:"Windows"},{slug:"linux",label:"Linux"}];function Rn(e){if(!e)return"";try{return new URL(e).origin}catch{return""}}function Cr(e,n){return n<2*6e4?e:n<10*6e4?Math.max(e,6e4):n<30*6e4?Math.max(e,3*6e4):Math.max(e,10*6e4)}var Ss=3e3,Ps=2*6e4,jn=Date.now(),Yn=new Set,vr=!1;function _s(){if(vr||typeof window>"u")return;vr=!0;let e=()=>{let t=jn;if(jn=Date.now(),jn-t>Ps)for(let r of Yn)r()};for(let t of["pointerdown","keydown","wheel","touchstart"])window.addEventListener(t,e,{capture:!0,passive:!0});let n=()=>{if(!document.hidden)for(let t of Yn)t()};window.addEventListener("focus",n),document.addEventListener("visibilitychange",n)}function He(e,n,t={}){_s();let r,s=t.immediate===!1?Date.now():0,a=!1,o=!1,c=()=>{o||(r=setTimeout(i,t.idle===!1?n:Cr(n,Date.now()-jn)))},i=async()=>{if(clearTimeout(r),!(o||a)){if(typeof document>"u"||!document.hidden){a=!0,s=Date.now();try{await e()}catch{}finally{a=!1}}c()}},u=()=>{Date.now()-s>Math.min(n,Ss)&&i()};return Yn.add(u),t.immediate===!1?c():i(),()=>{o=!0,clearTimeout(r),Yn.delete(u)}}var xt="soba";function Nr(){return`${xt}://show`}function Ln(e,n,t){let r=`${xt}://connect?url=${encodeURIComponent(e)}`;return n&&(r+=`&nonce=${encodeURIComponent(n)}`),t&&(r+=`&want=${encodeURIComponent(t)}`),r}function Tn(){let e=globalThis.crypto;if(!e?.getRandomValues)return null;let n=e.getRandomValues(new Uint8Array(32)),t="";for(let r of n)t+=String.fromCharCode(r);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var Es=1600;function St(e={}){return Et(e)}async function Pt(e,n={}){if(typeof window>"u"||typeof document>"u")return"unknown";let t=Et(n);try{window.location.href=Ln(e,n.nonce,n.want)}catch{return"absent"}return t}async function _t(e={}){if(typeof window>"u"||typeof document>"u")return"unknown";let n=Et(e);try{window.location.href=Nr()}catch{return"absent"}return n}async function Et(e){if(typeof window>"u"||typeof document>"u")return"unknown";let n=e.graceMs??Es,t=document.visibilityState==="visible"&&document.hasFocus(),r=!1,s=()=>{r=!0},a=()=>{document.visibilityState==="hidden"&&(r=!0)};return window.addEventListener("blur",s),window.addEventListener("pagehide",s),document.addEventListener("visibilitychange",a),await new Promise(o=>setTimeout(o,n)),window.removeEventListener("blur",s),window.removeEventListener("pagehide",s),document.removeEventListener("visibilitychange",a),t?r?"opened":"absent":"unknown"}var kr="soba.connect.choice",Ms=180*24*60*60*1e3;function Sr(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return(n>>>0).toString(36)}function Mt(e,n){return e?n?`${kr}.${e}.${Sr(n)}`:`${kr}.${e}`:null}function Rt(e){if(!e||typeof localStorage>"u")return null;try{let n=localStorage.getItem(e);if(!n)return null;let t=JSON.parse(n);if(Date.now()-Date.parse(t.at)>Ms)return null;let r=de.find(s=>s.id===t.choice);return r?r.id:null}catch{return null}}function Lt(e,n){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({choice:n,at:new Date().toISOString()}))}catch{}}var xr="soba.connect.dismissed",Rs=30*24*60*60*1e3;function Tt(e,n){return e?n?`${xr}.${e}.${Sr(n)}`:`${xr}.${e}`:null}function Ot(e){if(!e||typeof localStorage>"u")return!1;try{let n=localStorage.getItem(e);if(!n)return!1;let t=JSON.parse(n);return Date.now()-Date.parse(t.at)<Rs}catch{return!1}}function At(e){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({at:new Date().toISOString()}))}catch{}}import{Fragment as Zn,jsx as l,jsxs as N}from"react/jsx-runtime";var It=2e3,Ts=1e4,Os=9e4,As=6e4;function $t(e,n,t,r=[],s){return e?"code":n&&(t.length>0||r.length>0)?"manage":s?"launch":"choose"}function Is(e){let n=Math.max(0,Math.round(e/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function Ut({client:e,initialCode:n,initialChoice:t,onConnected:r,showStatus:s=!0,initialContext:a=null,initialMachines:o,onClose:c,headingId:i,theme:u,reason:d,active:f=!0}){let b=!!a&&o!==void 0,[g,m]=U(b?$t(n,s,o??[],[],t):"loading"),[y,S]=U(a),[x,O]=U(o??[]),[H,z]=U(n??""),[_,F]=U(null),[A,P]=U(null),[B,Y]=U(!1),[xe,le]=U(0),[ge,Re]=U(()=>Date.now()),[V,be]=U(null),[qe,ye]=U(!1),[ce,J]=U(!1),[yn,we]=U("browser"),[Le,sn]=U(null),[oe,Q]=U([]),[R,pe]=U(0),[Se,on]=U(null),me=dn(null),[E,it]=U(t??null),[M,lt]=U(null),Fe=Ue(()=>{let p=y?.accent?.trim(),v=y?.background?.trim();if(!(!p&&!v))return v?{...Ye(v,p),background:v,borderRadius:"inherit"}:{"--sc-accent":p,"--sc-accent-fg":kn(p)}},[y?.accent,y?.background]),ue=Ls(),re=i??ue,Te=dn(null);ae(()=>{if(!e||b)return;let p=!0;return Promise.all([e.context(),e.machines()]).then(([v,I])=>{p&&(S(v),O(I),m($t(n,s,I)))}).catch(v=>{p&&(P(v.message),m("choose"))}),()=>{p=!1}},[e,n,s,b]),ae(()=>{g!=="loading"||!b||m($t(n,s,o??[]))},[g,b,n,s,o]),ae(()=>{o&&O(o)},[o]),ae(()=>{a&&S(a)},[a]);let an=dn(!1),ln=dn(g);ln.current=g;let Ge=dn(oe);Ge.current=oe;let Ke=!!y?.hosted_available;ae(()=>{!s&&ln.current==="manage"&&m("choose")},[s]),ae(()=>{if(!e||!f||g!=="manage")return;let p=!0,v=He(async()=>{try{let I=await e.machines();if(!p)return;O(I);let $=!Ke||an.current;I.length===0&&Ge.current.length===0&&$&&ln.current==="manage"&&m("choose")}catch{}},Ts,{immediate:!1});return()=>{p=!1,v()}},[g,e,Ke,f]);let ze=Mt(y?.publishable_key??null);ae(()=>{lt(Rt(ze))},[ze]),ae(()=>{if(!e||!Ke)return;let p=!0;return e.hosted().then(v=>{p&&(Q(v.credentials),!an.current&&(an.current=!0,v.credentials.length>0&&s&&ln.current==="choose"&&m("manage")))}).catch(()=>{}),()=>{p=!1}},[e,Ke,s]),ae(()=>{if(!e||!f||g!=="hosted")return;let p=!0,v=async()=>{try{let Ie=await e.hosted();if(!p)return!1;if(Q(Ie.credentials),Ie.credentials.length>0)return m("hosted_connected"),on(null),!0}catch{}return!1},I=async()=>{me.current?.closed&&(me.current=null,!await v()&&p&&m("choose"))},$=He(v,It,{immediate:!1}),je=setInterval(I,400),_e=Ie=>{let fr=Ie.data;fr?.source==="soba"&&fr.type==="hosted_result"&&v()};return window.addEventListener("message",_e),()=>{p=!1,$(),clearInterval(je),window.removeEventListener("message",_e),me.current=null}},[e,g,f]);let ct=ie(()=>{if(!e)return;let p=window.open("","soba-connect-plan","width=520,height=760,noopener=no");me.current=p,m("hosted"),pe(Date.now()),on(null),P(null),e.startHosted().then(({url:v})=>{if(p&&!p.closed){p.location.href=v;return}on(v)}).catch(v=>{p?.close(),me.current=null,P(v.message),m("choose")})},[e]),Wn=ie(async p=>{if(e){Y(!0);try{await e.disconnectHosted(p),Q((await e.hosted()).credentials)}catch(v){P(v.message)}finally{Y(!1)}}},[e]);ae(()=>{if(!e||!f||g!=="waiting")return;let p=!0,v=He(async()=>{try{let I=await e.machines();if(!p)return;O(I);let $=Te.current;if(!$)return;let je=I.filter(Ie=>!$.has(Ie.id)),_e=je.find(Ie=>Ie.state!=="offline")??je[0];_e&&(sn(_e.id),E&&Lt(ze,E),m("connected"),r?.(I))}catch{}},It,{immediate:!1});return()=>{p=!1,v()}},[g,e,r,E,ze,f]);let qn=ie(async()=>{if(e){P(null),Y(!0);try{let p=await e.lookup(H);F(p),m("confirm")}catch(p){P(p.message)}finally{Y(!1)}}},[e,H]),Fn=ie(async()=>{if(e){P(null),Y(!0);try{try{Te.current=new Set((await e.machines()).map(p=>p.id))}catch{Te.current=new Set(x.map(p=>p.id))}await e.approve(H),m("waiting"),le(Date.now())}catch(p){P(p.message)}finally{Y(!1)}}},[e,H,x]),Gn=ie(async()=>{if(e){Y(!0);try{await e.deny(H),we("browser"),m("denied")}catch(p){P(p.message)}finally{Y(!1)}}},[e,H]),G=Ue(()=>y?.connect_url??null,[y]),[K,Oe]=U(()=>Tn()),Kn=Ue(()=>G?Ln(G,K??void 0,E??void 0):null,[G,K,E]),ut=Ue(()=>Rn(G),[G]),w=ie(p=>{if(x.length===0)return null;let v=de.find($=>$.id===p);if(!v)return null;let I=x.flatMap($=>$.runtimes??[]).filter($=>v.expects.includes($.id));return I.length===0?{tone:"dim",text:"not installed"}:I.some($=>$.authenticated===!0)?{tone:"ok",text:"ready"}:I.every($=>$.authenticated===!1)?{tone:"warn",text:"needs signing in"}:{tone:"dim",text:"installed"}},[x]),Z=ie((p=null)=>{it(p),P(null),be(null),ye(!1),J(!1),se.current=!1,Oe(Tn()),m("launch")},[]),se=dn(!!t);ae(()=>{g!=="launch"||!G||se.current||(se.current=!0,ye(!0),Pt(G,{...K?{nonce:K}:{},...E?{want:E}:{}}).then(be))},[g,G,K,E]);let wn=ie(()=>{ye(!0),St().then(be)},[]),Pe=ie(p=>{if(ce){let v=Tn();J(!1),Oe(v),G&&(p.preventDefault(),window.location.href=Ln(G,v??void 0,E??void 0))}wn()},[ce,wn,G,E]),vn=Ue(()=>{let p=y?.runtimes;return p?de.filter(v=>p.includes(v.id)):bt()},[y?.runtimes]),X=Ue(()=>{let p=de.find(v=>v.id===E);return p?{choice:p,Mark:$e[p.id]??null}:null},[E]),Ae=Ue(()=>x.find(p=>p.id===Le),[x,Le]);ae(()=>{let p=K;if(!e||!f||g!=="launch"||!p)return;let v=!1,I=Date.now()+15e4,$=()=>{};return $=He(async()=>{if(Date.now()>I){$(),J(!0);return}try{let je=await e.claim(p);if(v)return;if(je.declined){$(),be(null),we("machine"),m("denied");return}if(!je.claimed)return;$();try{Te.current=new Set((await e.machines()).map(_e=>_e.id))}catch{Te.current=new Set(x.map(_e=>_e.id))}m("waiting"),le(Date.now())}catch{}},It,{immediate:!1,idle:!1}),()=>{v=!0,$()}},[e,g,x,K,f]);let Ve=Ue(()=>{if(!_)return null;if(_.approved||_.denied)return"answered";let p=_.expires_at?Date.parse(_.expires_at):Number.NaN;return Number.isFinite(p)&&p<=ge?"expired":"live"},[_,ge]);ae(()=>{if(!(g==="confirm"&&Ve==="live"||g==="waiting"||g==="hosted"))return;let v=setInterval(()=>Re(Date.now()),1e3);return()=>clearInterval(v)},[g,Ve]);let hr=ie(async(p,v)=>{if(e)try{await e.approveRuntime(p,v),O(await e.machines())}catch(I){P(I.message)}},[e]);return g==="loading"?l("div",{className:"soba-connect",...u?{"data-theme":u}:{},style:Fe,children:l("div",{className:"sc-card",children:l("p",{className:"sc-note",children:"Loading\u2026"})})}):N("div",{className:"soba-connect",...u?{"data-theme":u}:{},style:Fe,children:[c&&l("button",{type:"button",className:"sc-modal-close",onClick:c,"aria-label":"Close",children:"\xD7"}),g==="manage"&&N("div",{className:"sc-card",children:[l("h2",{className:"sc-title",id:re,children:"Your compute"}),N("p",{className:"sc-sub",children:[l(Jn,{context:y})," ",x.length>0&&oe.length>0?"runs on your connected plan, and on these machines while they are awake.":oe.length>0?"runs on the plan you connected. Nothing here is charged to you.":"runs on these machines, while they are awake."]}),l(Ze,{machines:x,hosted:oe,onApproveRuntime:hr,onDisconnectHosted:p=>void Wn(p),onPair:()=>m("choose"),busy:B,...y?.app.name?{appName:y.app.name}:{}}),A&&l("p",{className:"sc-error",children:A})]}),g==="choose"&&N("div",{className:"sc-card",children:[l(Ds,{context:y}),l("h2",{className:"sc-h",id:re,children:d==="payment_required"?"Carry on with your own AI":d==="no_compute"?"This run needs a machine":"Connect your AI"}),l("p",{className:"sc-p",children:"Use compute you already have."}),G&&vn.length>0&&N(Zn,{children:[l("div",{className:"sc-opts",children:vn.map(p=>{let v=$e[p.id];return N("button",{type:"button",className:"sc-opt",onClick:()=>Z(p.id),children:[l("span",{className:"sc-opt-tile","aria-hidden":"true",children:v&&l(v,{className:"sc-opt-mark"})}),l("span",{className:"sc-opt-text",children:l("span",{className:"sc-opt-label",children:p.label})}),(()=>{let I=w(p.id);return I?l("span",{className:`sc-opt-has sc-opt-has-${I.tone}`,children:I.text}):M===p.id?l("span",{className:"sc-opt-last",children:"last used"}):l(Dt,{className:"sc-opt-go"})})()]},p.id)})}),N("p",{className:"sc-opt-note",children:["Your accounts stay there. ",Pr(y)," never sees them."]})]}),(!G||vn.length===0)&&l("p",{className:"sc-error",style:{marginTop:16},children:"This app has no publishable key yet, so there is nothing to pair against."}),A&&l("p",{className:"sc-error",children:A}),G&&y?.show_code===!0&&l("div",{className:"sc-opt-alt",children:l("button",{type:"button",className:"sc-alt-link",onClick:()=>m("code"),children:"I have a code"})})]}),g==="launch"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>m("choose")}),l("p",{className:"sc-head-title",children:"Soba App"})]}),l(Qn,{mark:X?.Mark??j,still:ce||!qe&&V===null}),l("h2",{className:"sc-h",id:re,children:ce?"No answer from this machine":V==="absent"?"Nothing opened":V===null?"Opening Soba App\u2026":"Approve it on this machine"}),ce?l("p",{className:"sc-p",children:"The Soba app did not answer. It may not be open, or nobody was there. Try again when you are ready."}):V==="absent"?l("p",{className:"sc-p",children:"Nothing opened on this machine. Open it yourself below, or install it if it is not here yet."}):l("p",{className:"sc-p",children:V===null?"Approve it there and this page does the rest.":"This page finishes on its own."}),X&&N("p",{className:"sc-prereq",children:[X.Mark&&l(X.Mark,{className:"sc-rt-mark"}),"Needs ",X.choice.prerequisite]}),N("div",{className:"sc-stack",style:{marginTop:18},children:[l("a",{className:V==="absent"||ce?"sc-btn sc-btn-primary":"sc-btn",href:Kn??"#",onClick:Pe,children:ce?"Try again":V==="absent"?"Open Soba App":"Open it again"}),l("p",{className:"sc-note",children:V===null?"Your browser will ask permission first.":"Your browser asks permission the first time."}),X&&V==="absent"&&l("p",{className:"sc-note",children:l(Hs,{text:X.choice.hint})}),N("div",{className:"sc-foot-strip",children:[l("span",{children:"Not installed on this machine?"}),N("button",{type:"button",className:"sc-foot-go",onClick:()=>m("get"),children:["Get it",l(Dt,{})]})]})]})]}),g==="get"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>m("launch")}),l("p",{className:"sc-head-title",children:"Get Soba App"})]}),l("div",{className:"sc-opts",children:Mn.map(p=>N("a",{className:"sc-opt",href:`${ut}/download/${p.slug}`,target:"_blank",rel:"noreferrer noopener",children:[l("span",{className:"sc-opt-tile","aria-hidden":"true",children:l(gt,{className:"sc-opt-mark"})}),l("span",{className:"sc-opt-text",children:l("span",{className:"sc-opt-label",children:p.label})}),l(Dt,{className:"sc-opt-go"})]},p.slug))}),l("p",{className:"sc-opt-note",children:"Install it, then come back here and press the row you started with."})]}),g==="code"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>m("choose")}),l("p",{className:"sc-head-title",children:"Soba App"})]}),l("h2",{className:"sc-h",id:re,children:"Enter the code from that machine"}),l("p",{className:"sc-p",children:"Eight characters, shown by the Soba app once you paste the link."}),N("form",{className:"sc-stack",style:{marginTop:16},onSubmit:p=>{p.preventDefault(),qn()},children:[l("input",{className:"sc-input",value:H,onChange:p=>z(p.target.value),placeholder:"ACDE-F234",autoComplete:"off",autoFocus:!0,"aria-label":"Pairing code"}),A&&l("p",{className:"sc-error",children:A}),l("button",{type:"submit",className:"sc-btn sc-btn-primary",disabled:B||H.length<8,children:B?"Checking\u2026":"Continue"})]})]}),g==="confirm"&&_&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>m("code")}),l("p",{className:"sc-head-title",children:"Soba App"})]}),l("h2",{className:"sc-title",children:"Attach this machine to your account?"}),N("p",{className:"sc-sub",children:[l(Jn,{context:y})," may send your runs to it once you approve. It can never see the account or the keys on it."]}),N("ul",{className:"sc-facts",children:[l(On,{k:"Code",v:_.user_code}),l(On,{k:"Machine",v:_.hostname??"not stated"}),l(On,{k:"System",v:[_.platform,_.arch].filter(Boolean).join(" / ")||"not stated"}),l(On,{k:"Asked by",v:_.client??"not stated"}),_.labels.length>0&&l(On,{k:"Labels",v:_.labels.join(", ")})]}),l("p",{className:"sc-note",style:{marginTop:12},children:"Every line above is what that machine said about itself. If none of it looks like a computer of yours, say no."}),Ve==="expired"&&l("p",{className:"sc-error",children:"That code has expired. Ask the machine for a new one. It prints a fresh code each time it starts."}),Ve==="answered"&&l("p",{className:"sc-error",children:"That code has already been answered. If it was not you, deny the next one."}),A&&l("p",{className:"sc-error",children:A}),N("div",{className:"sc-row",style:{marginTop:16},children:[l("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:()=>void Fn(),disabled:B||Ve!=="live",children:"Approve"}),l("button",{type:"button",className:"sc-btn",onClick:()=>void Gn(),disabled:B||Ve==="answered",children:"No, deny it"})]}),Ve==="live"&&_.expires_at&&N("p",{className:"sc-note",style:{marginTop:10},children:["This code expires in ",Is(Date.parse(_.expires_at)-ge),"."]})]}),g==="waiting"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>m("choose")}),l("p",{className:"sc-head-title",children:X?.choice.short??"Soba App"})]}),l(Qn,{mark:X?.Mark??j}),l("h2",{className:"sc-h",id:re,children:"Approved. Waiting for it to connect"}),l("p",{className:"sc-p",children:"Nothing more to do here. This page changes when it arrives."}),xe>0&&ge-xe>Os&&l("p",{className:"sc-note sc-tone-warn",style:{marginTop:14,textAlign:"center"},children:"Still nothing. Look at the Soba app on that machine: it says what it is doing. This keeps watching either way."})]}),g==="connected"&&N("div",{className:"sc-card",children:[l(Ht,{tone:"ok"}),l("h2",{className:"sc-h",id:re,children:Ae?.label?`${Ae.label} is connected`:"Connected"}),N("p",{className:"sc-p",children:[l(Jn,{context:y})," will use ",Ae?.label?"it":"this machine"," from now on, while it is awake."]}),s&&N(Zn,{children:[l("div",{style:{marginTop:16},children:l(Pn,{machines:x,onApproveRuntime:hr})}),l("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:14},onClick:()=>m("manage"),children:"Done"})]})]}),g==="hosted"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>m("choose")}),l("p",{className:"sc-head-title",children:"ChatGPT"})]}),Se?l(Qn,{mark:Qe,still:!0}):l(Qn,{mark:Qe}),l("h2",{className:"sc-h",id:re,children:Se?"Your browser blocked the window":"Finish signing in to ChatGPT"}),l("p",{className:"sc-p",children:Se?"Nothing opened. Open the sign-in yourself below. A link you click is allowed where a window we open is not.":"Approve it in the window that opened."}),N("div",{className:"sc-stack",style:{marginTop:18},children:[Se&&l("a",{className:"sc-btn sc-btn-primary",href:Se,target:"soba-connect-plan",rel:"noreferrer",children:"Open the ChatGPT sign-in"}),A&&l("p",{className:"sc-error",children:A}),R>0&&ge-R>As&&l("p",{className:"sc-note sc-tone-warn",children:"Still nothing. The window may have been closed before it finished, or the sign-in may have been declined. This keeps watching either way."})]})]}),g==="hosted_connected"&&N("div",{className:"sc-card",children:[l(Ht,{tone:"ok"}),l("h2",{className:"sc-h",id:re,children:"ChatGPT is connected"}),N("p",{className:"sc-p",children:[l(Jn,{context:y})," will run on your ChatGPT plan",oe[0]?.account_label?` (${oe[0].account_label})`:"",". Nothing more to pay, nothing to install."]}),l("p",{className:"sc-opt-note",style:{textAlign:"center"},children:"It runs on our side, so it has no access to your files or your terminal."}),s&&N(Zn,{children:[l("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>m("manage"),children:"Done"}),l("div",{className:"sc-opt-alt",children:l("button",{type:"button",className:"sc-alt-link",onClick:()=>m("choose"),children:"Connect a machine too"})})]})]}),g==="denied"&&N("div",{className:"sc-card",children:[l(Ht,{tone:"off"}),l("h2",{className:"sc-h",id:re,children:"Declined"}),l("p",{className:"sc-p",children:yn==="machine"?"Nothing was connected. You can ask again whenever you like.":"That machine was not attached to your account, and the terminal has been told so."}),l("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>m("choose"),children:"Back to the start"})]})]})}function Pr(e){return e?.app.name??"this app"}function $s(e){let n=e?.app.icon_urls;if(n?.length)return n;let t=e?.app.icon_url;return t?[t]:[]}function _r(e){let n=$s(e),[t,r]=U([]),s=ie(c=>{c&&r(i=>i.includes(c)?i:[...i,c])},[]),a=ie(c=>s(c.currentTarget.getAttribute("src")),[s]),o=ie(c=>{c?.complete&&c.naturalWidth===0&&s(c.getAttribute("src"))},[s]);return{icon:n.find(c=>!t.includes(c)),onError:a,ref:o}}function Ds({context:e}){let{icon:n,onError:t,ref:r}=_r(e);return e?.app.mark==="soba"?l(j,{className:"sc-app-mark"}):n?l("img",{className:"sc-app-mark",src:n,alt:"","aria-hidden":"true",ref:r,onError:t}):null}function Jn({context:e}){let{icon:n,onError:t,ref:r}=_r(e),s=e?.app.mark==="soba";return N("span",{className:"sc-app",children:[s&&l(j,{className:"sc-app-icon"}),!s&&n&&l("img",{className:"sc-app-icon",src:n,alt:"",ref:r,onError:t}),Pr(e)]})}function pn({onClick:e}){return l("button",{type:"button",className:"sc-head-back",onClick:e,"aria-label":"Back",children:l("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:l("path",{d:"M15 5 8 12l7 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function Dt({className:e}){return l("svg",{className:e,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:l("path",{d:"M9 5l7 7-7 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Qn({mark:e,still:n}){return N("span",{className:"sc-waiting","aria-hidden":"true",children:[!n&&l("svg",{className:"sc-waiting-orbit",viewBox:"0 0 100 100","aria-hidden":"true",focusable:"false",children:l("circle",{className:"sc-waiting-arc",cx:"50",cy:"50",r:"46"})}),l(e,{className:"sc-waiting-mark"})]})}function Ht({tone:e}){return l("span",{className:`sc-result sc-result-${e}`,"aria-hidden":"true",children:l(kt,{kind:e==="ok"?"snap":"gone",size:84})})}function Hs({text:e}){return l(Zn,{children:e.split("`").map((n,t)=>t%2===1?l("code",{className:"sc-inline-code",children:n},t):n)})}function On({k:e,v:n}){return N("li",{className:"sc-fact",children:[l("span",{className:"sc-fact-key",children:e}),l("span",{children:n})]})}import{useEffect as Us,useRef as Wt}from"react";var Xn=0,Bt=null;function Er(){if(typeof document>"u")return()=>{};Xn===0&&(Bt=document.body.style.overflow,document.body.style.overflow="hidden"),Xn+=1;let e=!1;return()=>{e||(e=!0,Xn-=1,Xn===0&&(document.body.style.overflow=Bt??"",Bt=null))}}import{jsx as Mr}from"react/jsx-runtime";function An({open:e,onClose:n,labelledBy:t,theme:r,style:s,children:a}){let o=Wt(null),c=Wt(null),i=Wt(null);return Us(()=>{let u=o.current;if(u){if(!e){u.open&&u.close();return}return u.open||u.showModal(),document.activeElement===u&&c.current?.focus(),Er()}},[e]),Mr("dialog",{ref:o,className:"soba-connect sc-modal","aria-labelledby":t,...r?{"data-theme":r}:{},style:s,onCancel:u=>{u.preventDefault(),n()},onPointerDown:u=>{i.current=u.target},onClick:u=>{u.target===u.currentTarget&&i.current===u.currentTarget&&n()},children:Mr("div",{className:"sc-modal-sheet",ref:c,tabIndex:-1,children:a})})}import{useEffect as qt,useRef as Bs}from"react";import{jsx as Ws}from"react/jsx-runtime";var en=8;function Ft({open:e,onClose:n,anchor:t,label:r,theme:s,style:a,children:o}){let c=Bs(null);return qt(()=>{let i=c.current;if(!(!i||!(typeof i.showPopover=="function")))try{e?i.showPopover():i.hidePopover()}catch{}},[e]),qt(()=>{if(!e)return;let i=()=>{let d=c.current,f=t.current;if(!d||!f)return;let b=f.getBoundingClientRect(),g=d.offsetWidth,m=d.offsetHeight,y=window.innerWidth-g-en,S=Math.max(en,Math.min(b.right-g,Math.max(en,y))),x=b.bottom+en,O=b.top-en-m,H=x+m>window.innerHeight-en&&O>en?O:x;d.style.left=`${Math.round(S)}px`,d.style.top=`${Math.round(H)}px`};i();let u=requestAnimationFrame(i);return window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{cancelAnimationFrame(u),window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[e,t]),qt(()=>{if(!e)return;let i=d=>{d.key==="Escape"&&n()},u=d=>{let f=d.target;f&&(c.current?.contains(f)||t.current?.contains(f)||n())};return document.addEventListener("keydown",i),document.addEventListener("pointerdown",u,!0),()=>{document.removeEventListener("keydown",i),document.removeEventListener("pointerdown",u,!0)}},[e,n,t]),Ws("div",{ref:c,role:"dialog","aria-label":r,className:"soba-connect sc-pop",...s?{"data-theme":s}:{},popover:"manual",hidden:!e,style:a,children:o})}function Ee(e){let n=`${e.unit}s`;return e.reward==="unlimited"?`Unlimited ${n} on your own AI`:e.reward==="included"&&e.includedUnits!==null?`${Fs(e.includedUnits)} ${n} a month once you connect`:e.reward==="credit"&&e.creditMicros>0?`${qs(e.creditMicros)} back each month you stay connected`:null}function Me(e){return e==="unlimited"||e==="included"}var Lr=new Set(["user-hardware","user-subscription"]),Rr=new Set(["open-weights","frontier"]);function he(e){return e===null||e.length===0?!1:e.every(n=>Lr.has(n))}var qs=e=>(e/1e6).toLocaleString("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}),Fs=e=>e.toLocaleString("en-US");function Gt(e,n){if(!(n===null||n.some(a=>Rr.has(a))))return!1;let r=e.findIndex(a=>Lr.has(a));if(r===-1)return!1;let s=e.findIndex(a=>Rr.has(a));return s===-1||r<s}import{createContext as Gs,useContext as Ks}from"react";var Kt=Gs(null);function W(){let e=Ks(Kt);if(!e)throw new Error("useSoba() must be used inside a <SobaProvider>.");return e}import{createContext as Tr,useContext as Or}from"react";var zt=Tr(null);function et(){return Or(zt)}var Vt=Tr({context:null,machines:void 0,theme:"light"});function D(){return Or(Vt)}import{jsx as In}from"react/jsx-runtime";function zs({className:e}){let{theme:n}=D(),t=e?`soba-connect ${e}`:"soba-connect";return In("div",{className:t,"data-theme":n,children:In(jt,{})})}function jt(){let{compute:e}=W();return e.loading&&!e.machines.length?In("p",{className:"sc-note",children:"Loading\u2026"}):e.error&&!e.machines.length?In("p",{className:"sc-error",children:e.error.message}):In(Pn,{machines:e.machines})}import{useCallback as tt,useEffect as Yt,useRef as Jt,useState as hn}from"react";import{useId as Vs}from"react";import{jsx as mn,jsxs as nt}from"react/jsx-runtime";function $n({open:e,onOpenChange:n,initialCode:t,onConnected:r,showStatus:s,reason:a}){let{error:o}=W(),c=et(),i=D(),u=()=>n(!1),d=Vs(),f=i.context?.background?.trim(),b=f?Ye(f,i.context?.accent):void 0;return nt(An,{open:e,onClose:u,labelledBy:d,theme:i.theme,style:b,children:[o?nt("div",{className:"sc-card",children:[mn("h2",{className:"sc-title",id:d,children:"Could not start"}),mn("p",{className:"sc-error",children:o.message})]}):!c&&!i.context?nt("div",{className:"sc-card",children:[mn("h2",{className:"sc-title",id:d,children:"One moment"}),mn("p",{className:"sc-note",children:"Getting your compute\u2026"})]}):mn(Ut,{client:c,active:e,onClose:u,headingId:d,theme:i.theme,initialContext:i.context,...i.machines!==void 0?{initialMachines:i.machines}:{},...t?{initialCode:t}:{},...r?{onConnected:r}:{},...s===void 0?{}:{showStatus:s},...a?{reason:a}:{}}),nt("p",{className:"sc-modal-foot",children:[mn(j,{className:"sc-foot-mark"}),"Secured by Soba"]})]})}import{Fragment as Qt,jsx as Be,jsxs as Dn}from"react/jsx-runtime";function nn({children:e,variant:n,className:t,initialCode:r,onConnected:s,defaultOpen:a,open:o,onOpenChange:c,showConnected:i=!0}){let{compute:u,connect:d}=W(),f=D(),{theme:b}=f,g=et(),[m,y]=hn(a??!!r),S=Jt(null),x=o!==void 0,O=!x&&!a&&!r&&d.hasModal,H=x?o:O?d.isOpen:m,z=R=>{O?R?d.open("manual"):d.close():x||y(R),c?.(R)},_=Jt(H);Yt(()=>{_.current&&!H&&S.current?.focus(),_.current=H},[H]);let F=Sn(u.machines),A=i&&F!==null,P=un(F),[B,Y]=hn(!1),xe=tt(()=>Y(!1),[]),[le,ge]=hn(!1),Re=tt(async()=>{ge(!0);try{await u.refresh()}finally{ge(!1)}},[u]),V=Jt(Re);V.current=Re,Yt(()=>{B&&V.current()},[B]);let[be,qe]=hn(!1),[ye,ce]=hn([]),J=!!f.context?.hosted_available;Yt(()=>{if(!B||!g||!J)return;let R=!0;return g.hosted().then(pe=>{R&&ce(pe.credentials)}).catch(()=>{}),()=>{R=!1}},[B,g,J]);let[yn,we]=hn(null),Le=tt(async(R,pe)=>{if(g){we(null);try{await g.approveRuntime(R,pe),await u.refresh()}catch(Se){we(Se.message)}}},[g,u]),sn=tt(async R=>{if(g){we(null);try{await g.disconnectHosted(R),ce((await g.hosted()).credentials)}catch(pe){we(pe.message)}}},[g]),oe=f.context?.background?.trim(),Q=oe?Ye(oe,f.context?.accent):void 0;return Dn(Qt,{children:[Be("button",{ref:S,type:"button","data-theme":b,className:["sc-btn",A?"sc-btn-connected":"sc-btn-icon",!A&&n==="primary"?"sc-btn-primary":"",t].filter(Boolean).join(" "),...A&&!e?{"aria-haspopup":"dialog","aria-expanded":B,"aria-label":F?`${P.word} on ${Je(F)}`:P.word}:{},onClick:()=>{if(A&&!e&&!x&&!a&&!r){Y(R=>!R);return}z(!0)},children:e??(A?Dn(Qt,{children:[Be("span",{className:"sc-pill-tile","aria-hidden":"true",children:Be(j,{className:P.tone==="busy"?"sc-pill-mark sc-pill-mark-busy":"sc-pill-mark"})}),Dn("span",{className:"sc-btn-connected-text",children:[P.word,F&&Dn("span",{className:"sc-btn-connected-where",children:[" on ",Je(F)]})]}),Be("i",{className:`sc-dot sc-dot-${P.tone}`,"aria-hidden":"true"})]}):Dn(Qt,{children:[Be(j,{className:"sc-btn-mark"}),"Connect compute"]}))}),Be(Ft,{open:B,onClose:xe,anchor:S,label:"Your compute",theme:b,...Q?{style:Q}:{},children:Be(Ze,{machines:u.machines,hosted:ye,onApproveRuntime:(R,pe)=>void Le(R,pe),onDisconnectHosted:R=>void sn(R),onRefresh:()=>void Re(),refreshing:le,error:yn,onPair:()=>{Y(!1),O?d.open("pair"):(qe(!0),z(!0))},...f.context?.app.name?{appName:f.context.app.name}:{}})}),!O&&Be($n,{open:H,onOpenChange:R=>{R||qe(!1),z(R)},...be?{showStatus:!1}:{},...r?{initialCode:r}:{},...s?{onConnected:s}:{}})]})}import{jsx as Zt,jsxs as Ys}from"react/jsx-runtime";function js({initialCode:e,onConnected:n,className:t,showStatus:r=!0}){let{theme:s}=D();return Ys("div",{className:t?`soba-connect ${t}`:"soba-connect","data-theme":s,children:[r&&Zt(jt,{}),Zt("div",{className:"sc-compute-act",children:Zt(nn,{...e?{initialCode:e}:{},...n?{onConnected:n}:{}})})]})}import{useEffect as Ur,useId as to,useState as er}from"react";import{useCallback as Js,useState as Qs}from"react";function rt(){let[e,n]=Qs(null);return{open:Js(()=>{n(null),_t().then(n)},[]),launch:e,note:e==="absent"?"Nothing opened here. That machine may be a different computer, or asleep.":null}}import{useCallback as Ar,useMemo as Ir}from"react";function tn(e){if(!e)return null;if(typeof e=="string")return e;if(typeof Response<"u"&&e instanceof Response)return $r(e.status);let n=e,t=n.error;return typeof t?.code=="string"?t.code:typeof t?.type=="string"?t.type:typeof n.code=="string"?n.code:typeof n.status=="number"?$r(n.status):n.cause&&n.cause!==e?tn(n.cause):null}function $r(e){return e===402?"payment_required":e===409?"no_compute":null}function Xt(...e){let[n,t]=e,{plan:r,compute:s,connect:a}=W(),o=t?.predict??e.length===0,c=Xs(Zs(n),s)??(o?eo(r,s):null),i=r.plan,u=r.plans,d=Ir(()=>{if(c!=="payment_required")return null;let m=i?.price??0,y=i?.included_units??0;return u.find(S=>S.id!==i?.id&&S.price>m&&(S.included_units===null||S.included_units>y))??null},[c,u,i]),f=Ar(async()=>{if(!d)return;if(d.selectable){await r.select(d.id);return}let m=await r.checkout(d.id);window.location.assign(m)},[d,r]),b=a.open,g=Ar(()=>{c&&b(c)},[b,c]);return Ir(()=>{if(!c)return null;let m=i?Ee({unit:i.unit,reward:i.connected_reward,includedUnits:i.connected_included_units,creditMicros:i.connected_credit*1e6}):null,y=i&&Me(i.connected_reward)?m:null;return{reason:c,...no(c,{connectOffer:y,connected:s.connected,online:s.online,machine:xn(s.machines)?.label??null,unit:i?.unit??"message",interval:i?.interval??"month",upgrade:d!==null,resets:r.current?.period_end??null}),connectOffer:y,upgradeTo:d,connect:g,upgrade:f}},[c,i,s,d,g,f,r.current?.period_end])}function Zs(e){let n=tn(e);return n==="payment_required"||n==="no_compute"?n:null}function Xs(e,n){return e==="no_compute"&&n.connected&&n.online?null:e}function eo(e,n){let t=e.plan;return!t||n.loading?null:he(t.route_allow)&&!n.online?"no_compute":e.remaining===0&&t.overage==="stop"?"payment_required":null}function no(e,n){if(e==="payment_required"){let t=`No ${n.unit}s left this ${n.interval}`;return n.connectOffer&&!n.connected?{title:t,body:`${n.connectOffer}. Connecting takes a minute and costs nothing.`}:n.connectOffer&&!n.online?{title:t,body:`${n.connectOffer}. Waking ${n.machine??"your machine"} is enough.`}:n.upgrade?{title:t,body:n.resets?`A larger plan carries on now. This one comes back on ${Dr(n.resets)}.`:"A larger plan carries on now, or wait for this one to renew."}:{title:t,body:n.resets?`Your allowance comes back on ${Dr(n.resets)}.`:"Your allowance comes back at the start of the next period."}}return n.connected&&!n.online?{title:`${n.machine??"Your machine"} can't be reached`,body:"This run needs it awake and connected. Open Soba App on that machine, or connect another one."}:{title:"Nothing connected yet",body:"This app runs on AI you already pay for, on a machine of your own. Connect one and this run has somewhere to go."}}function Dr(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}import{Fragment as nr,jsx as L,jsxs as Ce}from"react/jsx-runtime";function ro(e){let{at:n=.25,className:t,error:r,fallback:s=null}=e,a=e.predict??!("error"in e),{plan:o,compute:c,connect:i}=W(),{theme:u}=D(),[d,f]=er(null),b=to(),g=Tt(i.publishableKey),[m,y]=er(!1);Ur(()=>{y(Ot(g))},[g]);let S=L(nr,{children:s}),x=o.plan;if(!x||o.loading||c.loading)return S;let O=e.allow!==void 0?e.allow:x.route_allow;if(c.connected)return c.online?S:L(Hr,{className:t,theme:u,stalled:!0,children:L(so,{machine:xn(c.machines)?.label??null,ownCompute:he(O),onConnectAnother:()=>i.open("no_compute")})});let H=(()=>{let P=tn(r);return P==="payment_required"||P==="no_compute"})(),z=x.ask_to_connect!==!1&&Gt(x.route_prefer,O);if(!a&&!H&&!z)return S;let _=he(O)?ao(x.unit,he(x.route_allow)):Me(x.connected_reward)?lo(o,x,n):z?io(x.unit):null;if(!_||_.dismissible&&m)return S;let F=!_.dismissible&&(!a||_.meter!==null&&_.meter.left===0),A=d??F;return Ce(Hr,{className:t,theme:u,children:[Ce("div",{className:"sc-nudge-top",children:[Ce("div",{className:"sc-nudge-say",children:[L("p",{className:"sc-nudge-title",children:_.title}),L("p",{className:"sc-nudge-detail",children:_.detail}),Ce("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more","aria-expanded":A,"aria-controls":b,onClick:()=>f(!A),children:[A?"Hide the details":"How it works",L(uo,{})]})]}),_.dismissible?L("button",{type:"button",className:"sc-nudge-dismiss","aria-label":"Dismiss",title:"Dismiss",onClick:()=>{y(!0),At(g)},children:L(co,{})}):null]}),A?L("ol",{className:"sc-nudge-steps",id:b,children:oo(i.app?.name,Rn(i.connectUrl)).map(P=>Ce("li",{children:[P.opens?L("button",{type:"button",className:"sc-step-lead",onClick:()=>i.open("manual"),children:P.lead}):L("strong",{children:P.lead}),P.detail?L("span",{children:P.detail}):null,P.links.length>0?Ce("span",{className:"sc-step-links",children:[P.linksLead,P.links.map(B=>L("a",{href:B.href,target:"_blank",rel:"noreferrer noopener",children:B.label},B.href))]}):null]},P.lead))}):null,L(nn,{variant:"primary"})]})}function Hr({className:e,theme:n,stalled:t,children:r}){return L("div",{className:e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill","data-theme":n,children:L("div",{className:t?"sc-nudge sc-nudge-stalled":"sc-nudge",children:r})})}function so({machine:e,ownCompute:n,onConnectAnother:t}){let r=rt(),{compute:s}=W(),[a,o]=er(!1),{refresh:c}=s;return Ur(()=>{if(r.launch===null||r.launch==="absent")return;o(!1);let i=setInterval(()=>void c(),3e3),u=setTimeout(()=>{clearInterval(i),o(!0)},2e4);return()=>{clearInterval(i),clearTimeout(u)}},[r.launch,c]),Ce(nr,{children:[L("div",{className:"sc-nudge-top",children:Ce("div",{className:"sc-nudge-say",children:[Ce("p",{className:"sc-nudge-title",children:[e??"Your machine"," can\u2019t be reached"]}),L("p",{className:"sc-nudge-detail",children:n?"The Soba app there has stopped reporting in, so runs have nowhere to go until it is back.":"The Soba app there has stopped reporting in, so nothing will run on your own AI until it is back."}),r.note&&L("p",{className:"sc-nudge-note",children:r.note}),a&&L("p",{className:"sc-nudge-note",children:"The Soba app is open, but this machine still isn\u2019t reporting in. It may no longer be connected to this app."}),(r.launch==="absent"||a)&&L("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more",onClick:t,children:a?"Connect it again":"Connect another machine"})]})}),L("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:r.open,children:"Open Soba App"})]})}function oo(e,n){return[{lead:"Download Soba App",detail:"",linksLead:n?"Get it for":void 0,links:n?Mn.map(t=>({label:t.label,href:`${n}/download/${t.slug}`})):[]},{lead:"Connect compute",detail:"Press this, then approve the pairing when the app asks.",opens:!0,links:[]},{lead:"Let your AIs serve",detail:`It finds what is installed on that machine. Allow one, and ${e??"this app"} sends every run there.`,linksLead:"Nothing on it yet?",links:de.map(t=>({label:t.short,href:t.install}))}]}function ao(e,n){return{title:n?"This plan runs on your own AI.":`These ${e}s run on your own AI.`,detail:`Connect a machine and your ${e}s run there, free, on access you already have.`,meter:null}}function io(e){return{title:"This plan prefers your own AI.",detail:`Connect a machine and your ${e}s run there instead, on access you already have.`,meter:null,dismissible:!0}}function lo(e,n,t){let{remaining:r,included:s}=e;if(r===null||s===null||s===0||r>Math.ceil(s*t))return null;let a=Ee({unit:n.unit,reward:n.connected_reward,includedUnits:n.connected_included_units,creditMicros:n.connected_credit*1e6});return a?{title:r===0?`No ${n.unit}s left this month.`:`${r} ${n.unit}${r===1?"":"s"} left this month.`,detail:Ce(nr,{children:[a,"."]}),meter:{left:r,of:s}}:null}function co(){return L("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-x",children:L("path",{d:"m4.8 4.8 6.4 6.4M11.2 4.8l-6.4 6.4",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})})}function uo(){return L("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-chev",children:L("path",{d:"M4.5 6.5 8 10l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})})}var po=new Set(["delta","thinking","status","done","error"]);function fn(e){let n;try{n=JSON.parse(e)}catch{return null}if(!n||typeof n!="object")return null;let t=n,r=t.type==="event"?t.event:t;if(!r||typeof r!="object")return null;let s=r;if(typeof s.type!="string"||!po.has(s.type))return null;let a={type:s.type};return typeof s.text=="string"&&(a.text=s.text),typeof s.message=="string"&&(a.message=s.message),typeof s.tool=="string"&&(a.tool=s.tool),typeof s.tier=="string"&&(a.tier=s.tier),s.usage&&typeof s.usage=="object"&&(a.usage=s.usage),typeof s.reason=="string"&&(a.reason=s.reason),typeof s.retryable=="boolean"&&(a.retryable=s.retryable),(s.state==="interrupted"||s.state==="resumed")&&(a.state=s.state),a}async function*tr(e){let n=e.body;if(!n)throw new Error("That run response had no body to stream.");let t=(e.headers.get("content-type")??"").includes("ndjson"),r=n.getReader(),s=new TextDecoder,a="",o=[];try{for(;;){let i=await r.read();if(i.done)break;for(a+=s.decode(i.value,{stream:!0});;){let u=a.indexOf(`
|
|
3
|
-
`);if(
|
|
4
|
-
`);if(
|
|
5
|
-
`);if(c&&c!=="[DONE]"){let i=
|
|
6
|
-
`);i!==-1;i=s.indexOf(`
|
|
7
|
-
`)){let u=s.slice(0,i).replace(/\r$/,"");if(s=s.slice(i+1),u==="")o.length&&(yield{id:a,data:o.join(`
|
|
8
|
-
`)}),a=null,o=[];else if(u.startsWith("id:")){let d=Number(u.slice(3).trim());a=Number.isFinite(d)?d:null}else if(u.startsWith("data:")){let d=u.slice(5);o.push(d.startsWith(" ")?d.slice(1):d)}}}}finally{t.cancel().catch(()=>{})}}var rr=(e,n)=>new Promise(t=>{let r=setTimeout(t,e);n?.addEventListener("abort",()=>{clearTimeout(r),t()})});async function*go(e,n={}){let t=n.fetchImpl??fetch.bind(globalThis),r=await ho(e,n,t)??{url:e.url,bearer:e.token,open:null},s=n.maxRetries??6,a=n.after??0,o=0;for(;;){if(n.signal?.aborted)return;let c;try{c=r.open??await t(r.url,{headers:{authorization:`Bearer ${r.bearer}`,accept:"text/event-stream",...a?{"last-event-id":String(a)}:{}},...n.signal?{signal:n.signal}:{}}),r.open=null}catch(i){if(n.signal?.aborted)return;if(++o>s)throw i;await rr(1e3*o,n.signal);continue}if(c.status===503&&o<s){o++,await rr(Number(c.headers.get("retry-after")??3)*1e3,n.signal);continue}if(!c.ok){let i=`Could not read this run (${c.status}).`;try{let u=await c.json();u.error?.message&&(i=u.error.message)}catch{}throw new Error(i)}for await(let i of fo(c)){i.id!==null&&(a=i.id),o=0;let u=fn(i.data);if(u&&(yield u,u.type==="done"||u.type==="error"))return}if(n.signal?.aborted)return;if(++o>s)throw new Error("Lost this run's stream and could not get it back.");await rr(1e3*o,n.signal)}}import{useEffect as bo}from"react";var qr="data-soba-react",Fr=!1;function Hn(){if(Fr||typeof document>"u"||(Fr=!0,document.querySelector(`style[${qr}]`)))return;let e=document.createElement("style");e.setAttribute(qr,""),e.textContent=`.soba-connect {
|
|
2
|
+
import{useRef as ls,useState as cs}from"react";var In=class extends Error{status;constructor(n,t){super(n),this.name="ConnectError",this.status=t}},ns=5*6e4,Tn=class{session;baseUrl;doFetch;lastMachines=null;machinesUrl=null;gatewayBackUntil=0;constructor(n){this.session=n.session,this.baseUrl=(n.baseUrl??"").replace(/\/+$/,""),this.doFetch=n.fetchImpl??fetch.bind(globalThis)}async context(){let n=await this.request("GET","/v1/connect");return this.setMachinesUrl(n.machines_url),n}setMachinesUrl(n){typeof n=="string"&&/^https?:\/\//.test(n)&&(this.machinesUrl=n)}async machines(){let n=this.lastMachines,t=n?`?v=${encodeURIComponent(n.version)}`:"",r;if(this.machinesUrl&&Date.now()>=this.gatewayBackUntil)try{r=await this.request("GET",`${this.machinesUrl}${t}`)}catch(s){if(s instanceof In&&s.status===401)throw s;this.gatewayBackUntil=Date.now()+ns}if(r??=await this.request("GET",`/v1/machines${t}`),r.unchanged&&n)return n.machines;let o=Array.isArray(r.machines)?r.machines:[];return this.lastMachines=typeof r.version=="string"?{version:r.version,machines:o}:null,o}async runs(){let n=await this.request("GET","/v1/machines/runs");return Array.isArray(n.runs)?n.runs:[]}lookup(n){return this.request("GET",`/v1/device/lookup?code=${encodeURIComponent(n)}`)}approve(n){return this.request("POST","/v1/device/approve",{user_code:n})}claim(n){return this.request("POST","/v1/device/claim",{pairing_nonce:n})}deny(n){return this.request("POST","/v1/device/deny",{user_code:n})}plans(){return this.request("GET","/v1/plans")}selectPlan(n){return this.request("POST","/v1/plans/select",{plan:n})}checkoutPlan(n,t){return this.request("POST","/v1/plans/checkout",{plan:n,...t?.successUrl?{success_url:t.successUrl}:{},...t?.cancelUrl?{cancel_url:t.cancelUrl}:{}})}leavePlan(){return this.request("DELETE","/v1/plans/select")}hosted(){return this.request("GET","/v1/hosted")}startHosted(){return this.request("POST","/v1/hosted/start")}disconnectHosted(n){return this.request("DELETE",n?`/v1/hosted?provider=${encodeURIComponent(n)}`:"/v1/hosted")}approveRuntime(n,t){return this.request("POST","/v1/runtimes/approve",{machine_id:n,runtime_id:t})}preferRuntime(n,t){return this.request("POST","/v1/runtimes/prefer",{machine_id:n,runtime_id:t})}async request(n,t,r){let o=await this.doFetch(/^https?:\/\//.test(t)?t:`${this.baseUrl}${t}`,{method:n,headers:{authorization:`Bearer ${this.session}`,...r?{"content-type":"application/json"}:{}},...r?{body:JSON.stringify(r)}:{}}),s={};try{s=await o.json()}catch{}if(!o.ok){let a=typeof s.error=="string"?s.error:`Request failed (${o.status})`;throw new In(a,o.status)}return s}};function Ln(e){let n=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!n?.[1])return"#ffffff";let t=n[1].length===3?[...n[1]].map(s=>s+s).join(""):n[1],r=s=>{let a=Number.parseInt(t.slice(s*2,s*2+2),16)/255;return a<=.04045?a/12.92:((a+.055)/1.055)**2.4};return .2126*r(0)+.7152*r(1)+.0722*r(2)>.45?"#101012":"#ffffff"}function $t(e){let n=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!n?.[1])return null;let t=n[1].length===3?[...n[1]].map(r=>r+r).join(""):n[1];return[0,1,2].map(r=>Number.parseInt(t.slice(r*2,r*2+2),16))}function kn(e,n,t){let r=$t(e),o=$t(n);return!r||!o?e:`#${r.map((a,c)=>Math.round(a+(o[c]-a)*t)).map(a=>a.toString(16).padStart(2,"0")).join("")}`}function ln(e,n){if(!$t(e))return{};let t=Ln(e),r=n?.trim();return{"--sc-ground":e,"--sc-shell":e,"--sc-sheet":kn(e,t,.07),"--sc-raised":kn(e,t,.13),"--sc-line":kn(e,t,.18),"--sc-line-2":kn(e,t,.28),"--sc-text":t,"--sc-text-2":kn(t,e,.15),"--sc-muted":kn(t,e,.38),...r?{"--sc-accent":r,"--sc-accent-fg":Ln(r)}:{"--sc-accent":t,"--sc-accent-fg":e}}}function An(e){return e.authenticated===!0?{tone:"ok",text:"signed in"}:e.authenticated===!1?{tone:"warn",text:e.auth_hint??"signed out on that machine"}:{tone:"unknown",text:"could not tell"}}function $n(e){let{platform:n,arch:t}=e;if(!n)return null;let r=n==="darwin"||n==="macos",o=r?"Mac":n==="win32"||n==="windows"?"Windows PC":"Linux machine";return r?`${t==="aarch64"||t==="arm64"?"Apple silicon ":""}${o}`:o}function cn(e){return e.find(n=>n.state==="offline")??null}function Dt(e){return e.state==="busy"?{tone:"busy",text:`serving ${e.active} of ${e.capacity}`}:e.state==="online"?{tone:"ok",text:"connected"}:{tone:"off",text:"asleep or offline"}}function V(e){let n=e.label?.trim(),t=e.name?.trim();return n&&(!t||n!==t)?n:(t??n??"").replace(/\.(local|lan|home|internal)$/i,"").replace(/[-_]+/g," ").trim()||n||"This machine"}function mt(e,n){let t=o=>o.state==="busy"?0:o.state==="online"?1:2,r=o=>o.last_seen_at?Date.parse(o.last_seen_at):0;return t(e)-t(n)||r(n)-r(e)}function Ee(e){return[...e].sort(mt)[0]??null}function Ge(e){return e?e.state==="busy"?{tone:"busy",word:"Serving"}:e.state==="online"?{tone:"ok",word:"Connected"}:{tone:"off",word:"Asleep"}:{tone:"off",word:"No compute"}}function Ht(e){return e.state==="online"||e.state==="busy"}function Dn(e){if(!e)return"never seen";let n=Date.parse(e);if(Number.isNaN(n))return"never seen";let t=Date.now()-n,r=6e4;return t<2*r?"just now":t<60*r?`${Math.floor(t/r)} min ago`:t<24*60*r?`${Math.floor(t/(60*r))} hr ago`:`${Math.floor(t/(24*60*r))} days ago`}function ye(e){return e.runtimes.filter(n=>n.id!=="shell"&&!n.quarantined&&!n.absent)}function De(e){let n=a=>a?e.runtimes.find(c=>c.id===a)??null:null;if(e.requested_runtime)return{by:"app",runtimeId:e.requested_runtime,runtime:n(e.requested_runtime)};let t=ye(e),r=t.find(a=>a.id===e.preferred_runtime);if(r)return{by:"you",runtimeId:r.id,runtime:r};let o=a=>a.id==="claude-code"?0:a.id==="codex"?1:2,s=[...t].sort((a,c)=>o(a)-o(c))[0]??null;return{by:"default",runtimeId:s?.id??null,runtime:s}}import{useEffect as Xr,useRef as ts}from"react";import{Fragment as ss,jsx as Ne,jsxs as Ut}from"react/jsx-runtime";function Hn({anchor:e,label:n,options:t,current:r,onClose:o,onPick:s}){let a=ts(null);return Xr(()=>{let i=a.current,l=e.current;if(!i||!l)return;try{typeof i.showPopover=="function"&&i.showPopover()}catch{}let u=l.getBoundingClientRect(),p=i.offsetWidth,y=i.offsetHeight,f=Math.max(8,Math.min(u.right-p,window.innerWidth-p-8)),m=u.bottom+6,w=m+y>window.innerHeight-8&&u.top-6-y>8?u.top-6-y:m;i.style.left=`${Math.round(f)}px`,i.style.top=`${Math.round(w)}px`,i.querySelector('[aria-checked="true"]')?.focus()},[e]),Xr(()=>{let i=l=>{let u=l.target;!u||a.current?.contains(u)||e.current?.contains(u)||o()};return document.addEventListener("pointerdown",i,!0),()=>document.removeEventListener("pointerdown",i,!0)},[e,o]),Ne("div",{ref:a,role:"menu","aria-label":n,className:"sc-menu",popover:"manual",onKeyDown:i=>{let l=[...a.current?.querySelectorAll("[role=menuitemradio]")??[]],u=l.indexOf(document.activeElement);if(i.key==="Escape")i.stopPropagation(),i.nativeEvent.stopImmediatePropagation(),o(),e.current?.focus();else if(i.key==="ArrowDown"||i.key==="ArrowUp"){i.preventDefault();let p=i.key==="ArrowDown"?1:-1;l[(u+p+l.length)%l.length]?.focus()}else i.key==="Tab"&&o()},children:t.map(i=>Ne(rs,{option:i,checked:r===i.id,onClose:o,onPick:s},i.id??""))})}function rs({option:e,checked:n,onClose:t,onPick:r}){return Ut(ss,{children:[e.heading?Ne("div",{className:"sc-menu-head",role:"presentation",children:e.heading}):e.rule?Ne("div",{className:"sc-menu-sep"}):null,Ut("button",{type:"button",role:"menuitemradio","aria-checked":n,className:"sc-menu-item",onClick:()=>n?t():r(e.id),children:[e.glyph,Ut("span",{className:"sc-menu-text",children:[Ne("span",{className:"sc-menu-label",children:e.label}),e.note&&Ne("span",{className:"sc-menu-note",children:e.note})]}),n&&Ne(os,{})]})]})}function os(){return Ne("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:"sc-menu-check",children:Ne("path",{d:"M5 12.5l4.5 4.5L19 7.5",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Cn({open:e}){return Ne("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e?"sc-chev sc-chev-open":"sc-chev",children:Ne("path",{d:"M9 6l6 6-6 6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as we,jsxs as is}from"react/jsx-runtime";function j({className:e}){return is("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:[we("path",{d:"M18.125 7.039A8.6 8.6 0 1 0 18.125 16.961A6 6 0 0 1 18.125 7.039Z",fill:"currentColor"}),we("path",{d:"M19.925 7.039A8.6 8.6 0 0 1 19.925 16.961A6 6 0 0 0 19.925 7.039Z",fill:"currentColor"})]})}function eo({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{fill:"currentColor",d:"M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z"})})}function un({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{fill:"currentColor",d:"M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"})})}function ft({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{d:"M4 5h16v11H4zM9 20h6M12 16v4",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function as({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{d:"M5 7l5 5-5 5M12 18h7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Wt({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{d:"M5 6h14v10H5zM2.5 19.5h19",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}var ze={claude:eo,chatgpt:un,local:ft},no={shell:as};var ce=[{id:"claude",costClass:"user-subscription",short:"Claude Code",label:"Continue with Claude",title:"The Claude plan you already pay for",cost:"Nothing beyond the plan",prerequisite:"Claude Code installed and signed in",hint:"Install it from claude.ai/code, then run `claude` once and sign in.",install:"https://claude.com/product/claude-code",expects:["claude-code"]},{id:"chatgpt",costClass:"user-subscription",short:"Codex",label:"Continue with ChatGPT",title:"The ChatGPT plan you already pay for",cost:"Nothing beyond the plan",prerequisite:"Codex installed and signed in",hint:"Install Codex, then run `codex` once and sign in.",install:"https://learn.chatgpt.com/codex/cli",expects:["codex"]},{id:"local",costClass:"user-hardware",short:"Local models",label:"Use a model on this machine",title:"A model on your own machine",cost:"Free. You bought the hardware",prerequisite:"Ollama running, with a model pulled",hint:"Install Ollama, then `ollama pull` a model before pairing.",install:"https://ollama.com",expects:["ollama","openai-api"]}],to=["claude","chatgpt"];function Bt(){return ce.filter(e=>to.includes(e.id))}function qt(e){return ce.filter(n=>n.costClass===e)}function Ft(e){return ce.find(n=>n.expects.includes(e))??null}import{Fragment as oo,jsx as b,jsxs as O}from"react/jsx-runtime";function dn({machines:e,hosted:n=[],onApproveRuntime:t,onPreferRuntime:r,onDisconnectHosted:o,onPair:s,onRefresh:a,refreshing:c,busy:i,appName:l,error:u,runs:p,runsOpen:y,onToggleRuns:f,markOf:m,loading:w,machineMenu:P,machineNote:R,children:_}){let M=Ee(e),B=e.filter(N=>N.id!==M?.id),I=M&&p?ps(p,M):{};return!M&&n.length===0&&!s?b("p",{className:"sc-note",children:"Nothing connected yet."}):O("div",{className:"sc-tray",children:[M&&O(Nn,{title:"This machine",action:(a||P)&&O("span",{className:"sc-cap-acts",children:[a&&b("button",{type:"button",className:"sc-disc",onClick:a,disabled:c,"aria-label":"Refresh",title:"Refresh",children:b(Ms,{spinning:!!c})}),P]}),children:[b(us,{machine:M,...f?{onToggle:f,open:!!y}:{}}),R]}),M&&f&&y&&b(ms,{machine:M,runs:p??null,...m?{markOf:m}:{}}),M&&b(Nn,{title:"Agents on it",action:b(ks,{machine:M,appName:l,busy:i,...m?{markOf:m}:{},...r?{onPick:N=>r(M.id,N)}:{}}),children:w&&M.runtimes.length===0?b("p",{className:"sc-row-note",children:"Looking\u2026"}):M.runtimes.length>0?M.runtimes.map(N=>b(ws,{runtime:N,serving:I[N.id]??N.serving??0,...m?{mark:m(N)}:{},...t?{onApprove:()=>t(M.id,N.id)}:{}},N.id)):b("p",{className:"sc-row-note",children:"No agent advertised. Install Claude Code, Codex or Ollama on that machine."})}),n.length>0&&b(Nn,{title:n.length>1?"Connected plans":"Connected plan",children:n.map(N=>b(Ns,{credential:N,appName:l,busy:i,...o?{onDisconnect:()=>o(N.provider)}:{}},N.provider))}),(B.length>0||s)&&O(Nn,{title:B.length>0?"Your other machines":M?"Add a machine":"Your machines",children:[B.map(N=>b(ys,{machine:N},N.id)),s&&O("button",{type:"button",className:"sc-pair",onClick:s,children:[b("span",{className:"sc-otile","aria-hidden":"true",children:b(xs,{})}),b("span",{className:"sc-oname",children:e.length>0?"Pair another machine":"Connect a machine"})]})]}),_,u&&b("p",{className:"sc-error sc-tray-error",children:u})]})}function Nn({title:e,action:n,children:t}){return O("section",{className:"sc-group",children:[O("div",{className:"sc-group-cap",children:[b("p",{className:"sc-group-title",children:e}),n]}),b("div",{className:"sc-group-card",children:t})]})}function us({machine:e,onToggle:n,open:t}){let r=Ht(e),o=[r?null:e.pairing_lost?"No longer connected here":"Asleep or offline",$n(e),e.always_on?"always on":null,r&&e.capacity>0?`${e.active} of ${e.capacity} in flight`:Dn(e.last_seen_at)].filter(Boolean),s=O(oo,{children:[O("span",{className:"sc-mtile","aria-hidden":"true",children:[b(ro,{}),b("span",{className:`sc-mbadge sc-mbadge-${Ge(e).tone}`})]}),O("span",{className:"sc-mid",children:[b("span",{className:"sc-mname",children:V(e)}),b("span",{className:"sc-mmeta",children:o.map((a,c)=>O("span",{children:[c>0&&b("span",{className:"sc-mmeta-sep",children:"\xB7"}),a]},a))})]})]});return!n||!r?b("div",{className:"sc-mrow",children:s}):O("button",{type:"button",className:"sc-mrow sc-mrow-btn",onClick:n,"aria-expanded":!!t,title:t?"Hide what it is running":"See what it is running",children:[s,b(Cn,{open:!!t})]})}function ds(e,n){return e.filter(t=>t.machine_id===n.id||t.machine_id===null)}function ps(e,n){let t={};for(let r of e)r.machine_id!==n.id||r.status!=="running"||!r.runtime_id||(t[r.runtime_id]=(t[r.runtime_id]??0)+1);return t}function ms({machine:e,runs:n,markOf:t}){let r=n?ds(n,e):[],o=s=>{if(!s||!t)return null;let a=e.runtimes.find(c=>c.id===s);return a?t(a):null};return b(Nn,{title:"Running now",children:n===null?b("p",{className:"sc-row-note",children:"Looking\u2026"}):r.length===0?b("p",{className:"sc-row-note",children:"Nothing running."}):r.map(s=>{let a=o(s.runtime_id);return b(fs,{run:s,...a?{mark:a}:{}},s.id)})})}function fs({run:e,mark:n}){let t=e.runtime_id?ht(e.runtime_id):null;return O("div",{className:"sc-rrow",children:[b("span",{className:"sc-runtime-tile","aria-hidden":"true",children:n??(t&&b(t,{className:"sc-runtime-mark"}))}),O("span",{className:"sc-mid",children:[O("span",{className:"sc-rtop",children:[b("span",{className:"sc-aname",children:hs(e)}),b("span",{className:"sc-averdict",children:bs(e.started_at)})]}),b("span",{className:"sc-rstep",children:gs(e)})]})]})}function ht(e){let n=Ft(e);return(n?ze[n.id]:null)??no[e]??null}function hs(e){if(e.label)return e.label;if(e.task){let n=e.task.replace(/[_-]+/g," ").trim();return n.charAt(0).toUpperCase()+n.slice(1)}return"A run"}function gs(e){if(e.status==="queued")return"Waiting for a free slot";if(e.step)return e.step;switch(e.phase?.kind){case"thinking":return"Thinking";case"writing":return"Writing";case"tool":return e.phase.tool?`Using ${e.phase.tool}`:"Using a tool";case"approval":return e.phase.tool?`Waiting for you to allow ${e.phase.tool}`:"Waiting for your approval";default:return e.first_output_at?"Working":"Starting"}}function bs(e){let n=Math.max(0,Math.round((Date.now()-new Date(e).getTime())/1e3));if(n<60)return`${n}s`;let t=Math.floor(n/60);return t<60?`${t}m ${String(n%60).padStart(2,"0")}s`:`${Math.floor(t/60)}h ${String(t%60).padStart(2,"0")}m`}function ys({machine:e}){let n=Ge(e);return O("div",{className:"sc-orow",children:[b("span",{className:"sc-otile","aria-hidden":"true",children:b(ro,{})}),b("span",{className:"sc-oname",children:V(e)}),b("span",{className:"sc-oword",children:n.word}),b("span",{className:`sc-dot sc-dot-${n.tone}`,"aria-hidden":"true"})]})}function ws({runtime:e,serving:n=0,mark:t,onApprove:r}){let o=An(e),s=O(oo,{children:[b(vs,{runtime:e,mark:t}),O("span",{className:e.absent?"sc-aname sc-aname-absent":"sc-aname",children:[e.display_name,e.version&&O("span",{className:"sc-aversion",children:[" ",e.version]})]}),n>0?O("span",{className:"sc-averdict",children:[b(Ss,{}),b("span",{className:"sc-aserving",children:n>1?`${n} running`:"running"})]}):e.absent?b("span",{className:"sc-averdict sc-tone-absent",children:"not offered"}):e.quarantined?r?b("button",{type:"button",className:"sc-row-act",onClick:r,children:"Let it serve"}):b("span",{className:"sc-averdict sc-tone-warn",children:"new, not serving yet"}):o.tone==="ok"?O("span",{className:"sc-averdict",children:[b("span",{className:"sc-dot sc-dot-ok","aria-hidden":"true"}),b("span",{className:"sc-sr",children:o.text})]}):b("span",{className:`sc-averdict sc-tone-${o.tone}`,children:o.text})]});return b("div",{className:"sc-arow",children:s})}function vs({runtime:e,mark:n}){if(n)return b("span",{className:"sc-runtime-tile","aria-hidden":"true",children:n});let t=ht(e.id);return b("span",{className:"sc-runtime-tile","aria-hidden":"true",children:t&&b(t,{className:"sc-runtime-mark"})})}function ks({machine:e,appName:n,busy:t,markOf:r,onPick:o}){let s=De(e),a=ye(e),[c,i]=cs(!1),l=ls(null);if(s.by!=="app"&&a.length===0)return null;let u=f=>{if(!f)return null;if(r)return r(f);let m=ht(f.id);return b("span",{className:"sc-runtime-tile","aria-hidden":"true",children:m&&b(m,{className:"sc-runtime-mark"})})},p=f=>{if(!f)return null;if(r)return b("span",{className:"sc-runs-mark",children:r(f)});let m=ht(f.id);return m?b(m,{className:"sc-runs-glyph"}):null},y;return s.by==="app"?y=O("span",{className:"sc-runs-fixed",title:`Set by ${n??"the app"}`,children:[p(s.runtime),s.runtime?.display_name??s.runtimeId]}):!o||a.length<2?y=O("span",{className:"sc-runs-fixed",children:[p(s.runtime),s.runtime?.display_name]}):y=O("button",{ref:l,type:"button",className:"sc-runs-btn","aria-haspopup":"menu","aria-expanded":c,"aria-label":`Runs go to ${s.runtime?.display_name??"the default"}. Change`,disabled:t,onClick:()=>i(f=>!f),children:[p(s.runtime),b("span",{className:"sc-runs-label",children:s.runtime?.display_name}),b(Cn,{open:!0})]}),O("span",{className:"sc-runs-to",children:[b("span",{className:"sc-runs-cap",children:s.by==="app"?`${n??"App"} uses`:"Runs on"}),y,c&&o&&b(Cs,{anchor:l,machine:e,tile:u,onClose:()=>i(!1),onPick:f=>{i(!1),o(f)}})]})}function Cs({anchor:e,machine:n,tile:t,onClose:r,onPick:o}){let s=De(n),a=De({...n,preferred_runtime:null}).runtime,c=s.by==="you"?s.runtimeId:null,i=[{id:null,label:"Automatic",...a?{note:`Uses ${a.display_name}`}:{},glyph:t(a)},...ye(n).map((l,u)=>({id:l.id,label:l.display_name,glyph:t(l),...u===0?{rule:!0}:{}}))];return b(Hn,{anchor:e,label:"Which agent runs go to",options:i,current:c,onClose:r,onPick:o})}function Ns({credential:e,appName:n,busy:t,onDisconnect:r}){return O("div",{className:"sc-hrow",children:[O("div",{className:"sc-orow",children:[b("span",{className:"sc-otile","aria-hidden":"true",children:b(un,{className:"sc-omark"})}),O("span",{className:"sc-mid",children:[b("span",{className:"sc-oname",children:e.provider==="openai-chatgpt"?"ChatGPT plan":e.provider}),b("span",{className:"sc-mmeta",children:e.account_label??"signed in"})]}),r&&b("button",{type:"button",className:"sc-row-act",onClick:r,disabled:t,children:"Disconnect"})]}),r&&O("p",{className:"sc-row-note",children:[n??"This app"," stops using it. To withdraw the grant entirely, remove it in your OpenAI settings."]})]})}function ro(){return O("svg",{viewBox:"0 0 32 24","aria-hidden":"true",focusable:"false",className:"sc-mglyph",children:[b("rect",{x:"4",y:"1.5",width:"24",height:"15",rx:"2.5",fill:"var(--sc-sheet, #ffffff)",stroke:"currentColor",strokeWidth:"2"}),b("rect",{x:"1",y:"19.5",width:"30",height:"2.5",rx:"1.25",fill:"currentColor"})]})}function xs(){return b("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:"sc-oglyph",children:b("path",{d:"M12 5v14M5 12h14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}function Ss(){return O("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:"sc-sglyph sc-spin",children:[b("circle",{cx:"12",cy:"12",r:"9",fill:"none",stroke:"currentColor",strokeWidth:"3",opacity:"0.25"}),b("path",{d:"M12 3a9 9 0 0 1 9 9",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round"})]})}function Ms({spinning:e}){return b("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e?"sc-dglyph sc-spin":"sc-dglyph",children:b("path",{d:"M21 12a9 9 0 1 1-2.64-6.36M21 3v6h-6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as Ps}from"react/jsx-runtime";function Un({machines:e,onApproveRuntime:n}){return Ps(dn,{machines:e,...n?{onApproveRuntime:n}:{}})}var Gt={ready:{arc:!0},serving:{arc:!0,slot:"stream"},paused:{arc:!1,slot:"zzz"},thinking:{arc:!1,slot:"dots"},connecting:{arc:!1,slot:"orbit"},attention:{arc:!1,slot:"bang"},gone:{arc:!1,slot:"cross"},snap:{arc:!1,slot:"snap"},listening:{arc:!1,slot:"bars"},permission:{arc:!1,slot:"ring"},ai:{arc:!1,slot:"sparks"}};var zt="105 162 420 420",Kt="M407.1 308.9 A158 158 0 1 0 407.1 491.1 A116 116 0 0 1 407.1 308.9 Z",pn="M448.5 320 A110 110 0 0 1 448.5 480";import{Fragment as Bn,jsx as S,jsxs as Ke}from"react/jsx-runtime";function Vt({kind:e,size:n=44,className:t}){let r=Gt[e];return Ke("svg",{className:`bx${t?` ${t}`:""}`,"data-expression":e,viewBox:zt,overflow:"visible",width:n,height:n,"aria-hidden":"true",children:[S("path",{d:Kt,fill:"currentColor"}),S("path",{className:"bx-arc",d:pn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),r.slot==="stream"&&S(Rs,{}),r.slot==="zzz"&&S(_s,{}),r.slot==="dots"&&S(Es,{}),r.slot==="bang"&&S(Os,{}),r.slot==="orbit"&&S(Is,{}),r.slot==="cross"&&S(Ts,{}),r.slot==="snap"&&S(Ls,{}),r.slot==="bars"&&S(As,{}),r.slot==="ring"&&S($s,{}),r.slot==="sparks"&&S(Ds,{})]})}function Rs(){return S("path",{className:"bx-st",d:"M475.3 290.3 A150 150 0 0 1 475.3 509.7",fill:"none",stroke:"currentColor",strokeWidth:"15",strokeLinecap:"round",strokeDasharray:"0.1 31"})}function _s(){return Ke(Bn,{children:[S("g",{className:"bx-z1",children:S("path",{d:"M444 372 H496 L444 436 H496",fill:"none",stroke:"currentColor",strokeWidth:"20",strokeLinecap:"round",strokeLinejoin:"round"})}),S("g",{className:"bx-z2",children:S("path",{d:"M492 300 H522 L492 338 H522",fill:"none",stroke:"currentColor",strokeWidth:"15",strokeLinecap:"round",strokeLinejoin:"round"})})]})}function Es(){return Ke(Bn,{children:[S("circle",{className:"bx-th",cx:"463.1",cy:"336.9",r:"21",fill:"currentColor"}),S("circle",{className:"bx-th bx-th2",cx:"483",cy:"400",r:"21",fill:"currentColor"}),S("circle",{className:"bx-th bx-th3",cx:"463.1",cy:"463.1",r:"21",fill:"currentColor"})]})}function Os(){return Ke("g",{className:"bx-at",children:[S("line",{x1:"490",y1:"312",x2:"490",y2:"414",stroke:"currentColor",strokeWidth:"46",strokeLinecap:"round"}),S("circle",{cx:"490",cy:"484",r:"28",fill:"currentColor"})]})}function Is(){return Ke("g",{className:"bx-ob",children:[S("path",{d:pn,fill:"none",stroke:"var(--tile-bg, transparent)",strokeWidth:41,strokeLinecap:"round"}),S("path",{d:pn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})]})}function Ts(){return Ke(Bn,{children:[S("path",{className:"bx-xa",d:pn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),S("g",{className:"bx-xx",children:S("path",{d:"M442 364 L514 436 M514 364 L442 436",fill:"none",stroke:"currentColor",strokeWidth:"24",strokeLinecap:"round"})})]})}function Ls(){return S("path",{className:"bx-snap",d:pn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})}function As(){return Ke("g",{stroke:"currentColor",strokeWidth:"17",strokeLinecap:"round",children:[S("line",{className:"bx-vb",x1:"452",y1:"370",x2:"452",y2:"430"}),S("line",{className:"bx-vb bx-vb2",x1:"482",y1:"330",x2:"482",y2:"470"}),S("line",{className:"bx-vb bx-vb3",x1:"512",y1:"355",x2:"512",y2:"445"})]})}function $s(){return S(Bn,{children:[[450,366],[474,376],[484,400],[474,424],[450,434],[426,424],[416,400],[426,376]].map(([n,t],r)=>S("circle",{className:"bx-w",cx:n,cy:t,r:"11",fill:"currentColor",style:{animationDelay:`${-1.2+r*.15}s`}},r))})}function Ds(){return Ke(Bn,{children:[S("g",{className:"bx-sp",children:S("path",{d:"M460 300 Q465.4 324.6 490 330 Q465.4 335.4 460 360 Q454.6 335.4 430 330 Q454.6 324.6 460 300 Z",fill:"currentColor"})}),S("g",{className:"bx-sp bx-sp2",children:S("path",{d:"M486 356 Q493.92 392.08 530 400 Q493.92 407.92 486 444 Q478.08 407.92 442 400 Q478.08 392.08 486 356 Z",fill:"currentColor"})}),S("g",{className:"bx-sp bx-sp3",children:S("path",{d:"M460 440 Q465.4 464.6 490 470 Q465.4 475.4 460 500 Q454.6 475.4 430 470 Q454.6 464.6 460 440 Z",fill:"currentColor"})})]})}import{useCallback as oe,useEffect as ue,useId as zs,useMemo as Ve,useRef as xn,useState as W}from"react";var qn=[{slug:"mac-arm",label:"macOS, Apple silicon"},{slug:"mac-intel",label:"macOS, Intel"},{slug:"windows",label:"Windows"},{slug:"linux",label:"Linux"}];function Fn(e){if(!e)return"";try{return new URL(e).origin}catch{return""}}function io(e,n){return n<2*6e4?e:n<10*6e4?Math.max(e,6e4):n<30*6e4?Math.max(e,3*6e4):Math.max(e,10*6e4)}var Hs=3e3,Us=2*6e4,gt=Date.now(),bt=new Set,ao=!1;function Ws(){if(ao||typeof window>"u")return;ao=!0;let e=()=>{let t=gt;if(gt=Date.now(),gt-t>Us)for(let r of bt)r()};for(let t of["pointerdown","keydown","wheel","touchstart"])window.addEventListener(t,e,{capture:!0,passive:!0});let n=()=>{if(!document.hidden)for(let t of bt)t()};window.addEventListener("focus",n),document.addEventListener("visibilitychange",n)}function Oe(e,n,t={}){Ws();let r,o=t.immediate===!1?Date.now():0,s=!1,a=!1,c=()=>{a||(r=setTimeout(i,t.idle===!1?n:io(n,Date.now()-gt)))},i=async()=>{if(clearTimeout(r),!(a||s)){if(typeof document>"u"||!document.hidden){s=!0,o=Date.now();try{await e()}catch{}finally{s=!1}}c()}},l=()=>{Date.now()-o>Math.min(n,Hs)&&i()};return bt.add(l),t.immediate===!1?c():i(),()=>{a=!0,clearTimeout(r),bt.delete(l)}}var jt="soba";function lo(){return`${jt}://show`}function Gn(e,n,t){let r=`${jt}://connect?url=${encodeURIComponent(e)}`;return n&&(r+=`&nonce=${encodeURIComponent(n)}`),t&&(r+=`&want=${encodeURIComponent(t)}`),r}function zn(){let e=globalThis.crypto;if(!e?.getRandomValues)return null;let n=e.getRandomValues(new Uint8Array(32)),t="";for(let r of n)t+=String.fromCharCode(r);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var Bs=1600;function Yt(e={}){return Qt(e)}async function Zt(e,n={}){if(typeof window>"u"||typeof document>"u")return"unknown";let t=Qt(n);try{window.location.href=Gn(e,n.nonce,n.want)}catch{return"absent"}return t}async function Jt(e={}){if(typeof window>"u"||typeof document>"u")return"unknown";let n=Qt(e);try{window.location.href=lo()}catch{return"absent"}return n}async function Qt(e){if(typeof window>"u"||typeof document>"u")return"unknown";let n=e.graceMs??Bs,t=document.visibilityState==="visible"&&document.hasFocus(),r=!1,o=()=>{r=!0},s=()=>{document.visibilityState==="hidden"&&(r=!0)};return window.addEventListener("blur",o),window.addEventListener("pagehide",o),document.addEventListener("visibilitychange",s),await new Promise(a=>setTimeout(a,n)),window.removeEventListener("blur",o),window.removeEventListener("pagehide",o),document.removeEventListener("visibilitychange",s),t?r?"opened":"absent":"unknown"}var co="soba.connect.choice",qs=180*24*60*60*1e3;function Xt(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return(n>>>0).toString(36)}function er(e,n){return e?n?`${co}.${e}.${Xt(n)}`:`${co}.${e}`:null}function nr(e){if(!e||typeof localStorage>"u")return null;try{let n=localStorage.getItem(e);if(!n)return null;let t=JSON.parse(n);if(Date.now()-Date.parse(t.at)>qs)return null;let r=ce.find(o=>o.id===t.choice);return r?r.id:null}catch{return null}}function tr(e,n){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({choice:n,at:new Date().toISOString()}))}catch{}}var uo="soba.connect.model",Fs=180*24*60*60*1e3;function rr(e,n){return e?n?`${uo}.${e}.${Xt(n)}`:`${uo}.${e}`:null}function yt(e){if(!e||typeof localStorage>"u")return null;try{let n=localStorage.getItem(e);if(!n)return null;let t=JSON.parse(n);if(Date.now()-Date.parse(t.at)>Fs)return null;let r=t.choice;return typeof r!="string"||!r||r.length>120?null:/^[\w.:@+-]+(\/[\w.:@+-]+)?$/.test(r)?r:null}catch{return null}}function or(e,n){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({choice:n,at:new Date().toISOString()}))}catch{}}var po="soba.connect.dismissed",Gs=30*24*60*60*1e3;function sr(e,n){return e?n?`${po}.${e}.${Xt(n)}`:`${po}.${e}`:null}function ar(e){if(!e||typeof localStorage>"u")return!1;try{let n=localStorage.getItem(e);if(!n)return!1;let t=JSON.parse(n);return Date.now()-Date.parse(t.at)<Gs}catch{return!1}}function ir(e){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({at:new Date().toISOString()}))}catch{}}import{Fragment as kt,jsx as d,jsxs as x}from"react/jsx-runtime";var lr=2e3,Ks=1e4,Vs=9e4,js=6e4;function cr(e,n,t,r=[],o){return e?"code":n&&(t.length>0||r.length>0)?"manage":o?"launch":"choose"}function Ys(e){let n=Math.max(0,Math.round(e/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function pr({client:e,initialCode:n,initialChoice:t,onConnected:r,showStatus:o=!0,initialContext:s=null,initialMachines:a,onClose:c,headingId:i,theme:l,reason:u,active:p=!0}){let y=!!s&&a!==void 0,[f,m]=W(y?cr(n,o,a??[],[],t):"loading"),[w,P]=W(s),[R,_]=W(a??[]),[M,B]=W(n??""),[I,N]=W(null),[F,T]=W(null),[se,X]=W(!1),[ve,K]=W(0),[ae,We]=W(()=>Date.now()),[Y,Me]=W(null),[Xe,de]=W(!1),[pe,ee]=W(!1),[gn,en]=W("browser"),[Le,nn]=W(null),[me,ne]=W([]),[Be,Pe]=W(0),[Ae,qe]=W(null),ie=xn(null),[E,bn]=W(t??null),[v,G]=W(null),te=Ve(()=>{let h=w?.accent?.trim(),C=w?.background?.trim();if(!(!h&&!C))return C?{...ln(C,h),background:C,borderRadius:"inherit"}:{"--sc-accent":h,"--sc-accent-fg":Ln(h)}},[w?.accent,w?.background]),fe=zs(),re=i??fe,Fe=xn(null);ue(()=>{if(!e||y)return;let h=!0;return Promise.all([e.context(),e.machines()]).then(([C,$])=>{h&&(P(C),_($),m(cr(n,o,$)))}).catch(C=>{h&&(T(C.message),m("choose"))}),()=>{h=!1}},[e,n,o,y]),ue(()=>{f!=="loading"||!y||m(cr(n,o,a??[]))},[f,y,n,o,a]),ue(()=>{a&&_(a)},[a]),ue(()=>{s&&P(s)},[s]);let yn=xn(!1),wn=xn(f);wn.current=f;let tn=xn(me);tn.current=me;let rn=!!w?.hosted_available;ue(()=>{!o&&wn.current==="manage"&&m("choose")},[o]),ue(()=>{if(!e||!p||f!=="manage")return;let h=!0,C=Oe(async()=>{try{let $=await e.machines();if(!h)return;_($);let U=!rn||yn.current;$.length===0&&tn.current.length===0&&U&&wn.current==="manage"&&m("choose")}catch{}},Ks,{immediate:!1});return()=>{h=!1,C()}},[f,e,rn,p]);let on=er(w?.publishable_key??null);ue(()=>{G(nr(on))},[on]),ue(()=>{if(!e||!rn)return;let h=!0;return e.hosted().then(C=>{h&&(ne(C.credentials),!yn.current&&(yn.current=!0,C.credentials.length>0&&o&&wn.current==="choose"&&m("manage")))}).catch(()=>{}),()=>{h=!1}},[e,rn,o]),ue(()=>{if(!e||!p||f!=="hosted")return;let h=!0,C=async()=>{try{let _e=await e.hosted();if(!h)return!1;if(ne(_e.credentials),_e.credentials.length>0)return m("hosted_connected"),qe(null),!0}catch{}return!1},$=async()=>{ie.current?.closed&&(ie.current=null,!await C()&&h&&m("choose"))},U=Oe(C,lr,{immediate:!1}),an=setInterval($,400),Ce=_e=>{let On=_e.data;On?.source==="soba"&&On.type==="hosted_result"&&C()};return window.addEventListener("message",Ce),()=>{h=!1,U(),clearInterval(an),window.removeEventListener("message",Ce),ie.current=null}},[e,f,p]);let It=oe(()=>{if(!e)return;let h=window.open("","soba-connect-plan","width=520,height=760,noopener=no");ie.current=h,m("hosted"),Pe(Date.now()),qe(null),T(null),e.startHosted().then(({url:C})=>{if(h&&!h.closed){h.location.href=C;return}qe(C)}).catch(C=>{h?.close(),ie.current=null,T(C.message),m("choose")})},[e]),it=oe(async h=>{if(e){X(!0);try{await e.disconnectHosted(h),ne((await e.hosted()).credentials)}catch(C){T(C.message)}finally{X(!1)}}},[e]);ue(()=>{if(!e||!p||f!=="waiting")return;let h=!0,C=Oe(async()=>{try{let $=await e.machines();if(!h)return;_($);let U=Fe.current;if(!U)return;let an=$.filter(_e=>!U.has(_e.id)),Ce=an.find(_e=>_e.state!=="offline")??an[0];if(Ce){nn(Ce.id),E&&tr(on,E);let _e=ce.find(At=>At.id===E)?.expects??[],On=ye(Ce).find(At=>_e.includes(At.id));On&&e.preferRuntime(Ce.id,On.id).catch(()=>{}),m("connected"),r?.($)}}catch{}},lr,{immediate:!1});return()=>{h=!1,C()}},[f,e,r,E,on,p]);let lt=oe(async()=>{if(e){T(null),X(!0);try{let h=await e.lookup(M);N(h),m("confirm")}catch(h){T(h.message)}finally{X(!1)}}},[e,M]),vn=oe(async()=>{if(e){T(null),X(!0);try{try{Fe.current=new Set((await e.machines()).map(h=>h.id))}catch{Fe.current=new Set(R.map(h=>h.id))}await e.approve(M),m("waiting"),K(Date.now())}catch(h){T(h.message)}finally{X(!1)}}},[e,M,R]),ct=oe(async()=>{if(e){X(!0);try{await e.deny(M),en("browser"),m("denied")}catch(h){T(h.message)}finally{X(!1)}}},[e,M]),q=Ve(()=>w?.connect_url??null,[w]),[Re,he]=W(()=>zn()),sn=Ve(()=>q?Gn(q,Re??void 0,E??void 0):null,[q,Re,E]),ut=Ve(()=>Fn(q),[q]),Tt=oe(h=>{if(R.length===0)return null;let C=ce.find(U=>U.id===h);if(!C)return null;let $=R.flatMap(U=>U.runtimes??[]).filter(U=>C.expects.includes(U.id));return $.length===0?{tone:"dim",text:"not installed"}:$.some(U=>U.authenticated===!0)?{tone:"ok",text:"ready"}:$.every(U=>U.authenticated===!1)?{tone:"warn",text:"needs signing in"}:{tone:"dim",text:"installed"}},[R]),k=oe((h=null)=>{bn(h),T(null),Me(null),de(!1),ee(!1),z.current=!1,he(zn()),m("launch")},[]),z=xn(!!t);ue(()=>{f!=="launch"||!q||z.current||(z.current=!0,de(!0),Zt(q,{...Re?{nonce:Re}:{},...E?{want:E}:{}}).then(Me))},[f,q,Re,E]);let le=oe(()=>{de(!0),Yt().then(Me)},[]),dt=oe(h=>{if(pe){let C=zn();ee(!1),he(C),q&&(h.preventDefault(),window.location.href=Gn(q,C??void 0,E??void 0))}le()},[pe,le,q,E]),ge=Ve(()=>{let h=w?.runtimes;return h?ce.filter(C=>h.includes(C.id)):Bt()},[w?.runtimes]),ke=Ve(()=>{let h=ce.find(C=>C.id===E);return h?{choice:h,Mark:ze[h.id]??null}:null},[E]),$e=Ve(()=>R.find(h=>h.id===Le),[R,Le]);ue(()=>{let h=Re;if(!e||!p||f!=="launch"||!h)return;let C=!1,$=Date.now()+15e4,U=()=>{};return U=Oe(async()=>{if(Date.now()>$){U(),ee(!0);return}try{let an=await e.claim(h);if(C)return;if(an.declined){U(),Me(null),en("machine"),m("denied");return}if(!an.claimed)return;U();try{Fe.current=new Set((await e.machines()).map(Ce=>Ce.id))}catch{Fe.current=new Set(R.map(Ce=>Ce.id))}m("waiting"),K(Date.now())}catch{}},lr,{immediate:!1,idle:!1}),()=>{C=!0,U()}},[e,f,R,Re,p]);let be=Ve(()=>{if(!I)return null;if(I.approved||I.denied)return"answered";let h=I.expires_at?Date.parse(I.expires_at):Number.NaN;return Number.isFinite(h)&&h<=ae?"expired":"live"},[I,ae]);ue(()=>{if(!(f==="confirm"&&be==="live"||f==="waiting"||f==="hosted"))return;let C=setInterval(()=>We(Date.now()),1e3);return()=>clearInterval(C)},[f,be]);let pt=oe(async(h,C)=>{if(e)try{await e.approveRuntime(h,C),_(await e.machines())}catch($){T($.message)}},[e]),Lt=oe(async(h,C)=>{if(e)try{await e.preferRuntime(h,C),_(await e.machines())}catch($){T($.message)}},[e]);return f==="loading"?d("div",{className:"soba-connect",...l?{"data-theme":l}:{},style:te,children:d("div",{className:"sc-card",children:d("p",{className:"sc-note",children:"Loading\u2026"})})}):x("div",{className:"soba-connect",...l?{"data-theme":l}:{},style:te,children:[c&&d("button",{type:"button",className:"sc-modal-close",onClick:c,"aria-label":"Close",children:"\xD7"}),f==="manage"&&x("div",{className:"sc-card",children:[d("h2",{className:"sc-title",id:re,children:"Your compute"}),x("p",{className:"sc-sub",children:[d(wt,{context:w})," ",R.length>0&&me.length>0?"runs on your connected plan, and on these machines while they are awake.":me.length>0?"runs on the plan you connected. Nothing here is charged to you.":"runs on these machines, while they are awake."]}),d(dn,{machines:R,hosted:me,onApproveRuntime:pt,onPreferRuntime:(h,C)=>void Lt(h,C),onDisconnectHosted:h=>void it(h),onPair:()=>m("choose"),busy:se,...w?.app.name?{appName:w.app.name}:{}}),F&&d("p",{className:"sc-error",children:F})]}),f==="choose"&&x("div",{className:"sc-card",children:[d(Js,{context:w}),d("h2",{className:"sc-h",id:re,children:u==="payment_required"?"Carry on with your own AI":u==="no_compute"?"This run needs a machine":"Connect your AI"}),d("p",{className:"sc-p",children:"Use compute you already have."}),q&&ge.length>0&&x(kt,{children:[d("div",{className:"sc-opts",children:ge.map(h=>{let C=ze[h.id];return x("button",{type:"button",className:"sc-opt",onClick:()=>k(h.id),children:[d("span",{className:"sc-opt-tile","aria-hidden":"true",children:C&&d(C,{className:"sc-opt-mark"})}),d("span",{className:"sc-opt-text",children:d("span",{className:"sc-opt-label",children:h.label})}),(()=>{let $=Tt(h.id);return $?d("span",{className:`sc-opt-has sc-opt-has-${$.tone}`,children:$.text}):v===h.id?d("span",{className:"sc-opt-last",children:"last used"}):d(ur,{className:"sc-opt-go"})})()]},h.id)})}),x("p",{className:"sc-opt-note",children:["Your accounts stay there. ",mo(w)," never sees them."]})]}),(!q||ge.length===0)&&d("p",{className:"sc-error",style:{marginTop:16},children:"This app has no publishable key yet, so there is nothing to pair against."}),F&&d("p",{className:"sc-error",children:F}),q&&w?.show_code===!0&&d("div",{className:"sc-opt-alt",children:d("button",{type:"button",className:"sc-alt-link",onClick:()=>m("code"),children:"I have a code"})})]}),f==="launch"&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:"Soba App"})]}),d(vt,{mark:ke?.Mark??j,still:pe||!Xe&&Y===null}),d("h2",{className:"sc-h",id:re,children:pe?"No answer from this machine":Y==="absent"?"Nothing opened":Y===null?"Opening Soba App\u2026":"Approve it on this machine"}),pe?d("p",{className:"sc-p",children:"The Soba app did not answer. It may not be open, or nobody was there. Try again when you are ready."}):Y==="absent"?d("p",{className:"sc-p",children:"Nothing opened on this machine. Open it yourself below, or install it if it is not here yet."}):d("p",{className:"sc-p",children:Y===null?"Approve it there and this page does the rest.":"This page finishes on its own."}),ke&&x("p",{className:"sc-prereq",children:[ke.Mark&&d(ke.Mark,{className:"sc-rt-mark"}),"Needs ",ke.choice.prerequisite]}),x("div",{className:"sc-stack",style:{marginTop:18},children:[d("a",{className:Y==="absent"||pe?"sc-btn sc-btn-primary":"sc-btn",href:sn??"#",onClick:dt,children:pe?"Try again":Y==="absent"?"Open Soba App":"Open it again"}),d("p",{className:"sc-note",children:Y===null?"Your browser will ask permission first.":"Your browser asks permission the first time."}),ke&&Y==="absent"&&d("p",{className:"sc-note",children:d(Qs,{text:ke.choice.hint})}),x("div",{className:"sc-foot-strip",children:[d("span",{children:"Not installed on this machine?"}),x("button",{type:"button",className:"sc-foot-go",onClick:()=>m("get"),children:["Get it",d(ur,{})]})]})]})]}),f==="get"&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("launch")}),d("p",{className:"sc-head-title",children:"Get Soba App"})]}),d("div",{className:"sc-opts",children:qn.map(h=>x("a",{className:"sc-opt",href:`${ut}/download/${h.slug}`,target:"_blank",rel:"noreferrer noopener",children:[d("span",{className:"sc-opt-tile","aria-hidden":"true",children:d(Wt,{className:"sc-opt-mark"})}),d("span",{className:"sc-opt-text",children:d("span",{className:"sc-opt-label",children:h.label})}),d(ur,{className:"sc-opt-go"})]},h.slug))}),d("p",{className:"sc-opt-note",children:"Install it, then come back here and press the row you started with."})]}),f==="code"&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:"Soba App"})]}),d("h2",{className:"sc-h",id:re,children:"Enter the code from that machine"}),d("p",{className:"sc-p",children:"Eight characters, shown by the Soba app once you paste the link."}),x("form",{className:"sc-stack",style:{marginTop:16},onSubmit:h=>{h.preventDefault(),lt()},children:[d("input",{className:"sc-input",value:M,onChange:h=>B(h.target.value),placeholder:"ACDE-F234",autoComplete:"off",autoFocus:!0,"aria-label":"Pairing code"}),F&&d("p",{className:"sc-error",children:F}),d("button",{type:"submit",className:"sc-btn sc-btn-primary",disabled:se||M.length<8,children:se?"Checking\u2026":"Continue"})]})]}),f==="confirm"&&I&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("code")}),d("p",{className:"sc-head-title",children:"Soba App"})]}),d("h2",{className:"sc-title",children:"Attach this machine to your account?"}),x("p",{className:"sc-sub",children:[d(wt,{context:w})," may send your runs to it once you approve. It can never see the account or the keys on it."]}),x("ul",{className:"sc-facts",children:[d(Kn,{k:"Code",v:I.user_code}),d(Kn,{k:"Machine",v:I.hostname??"not stated"}),d(Kn,{k:"System",v:[I.platform,I.arch].filter(Boolean).join(" / ")||"not stated"}),d(Kn,{k:"Asked by",v:I.client??"not stated"}),I.labels.length>0&&d(Kn,{k:"Labels",v:I.labels.join(", ")})]}),d("p",{className:"sc-note",style:{marginTop:12},children:"Every line above is what that machine said about itself. If none of it looks like a computer of yours, say no."}),be==="expired"&&d("p",{className:"sc-error",children:"That code has expired. Ask the machine for a new one. It prints a fresh code each time it starts."}),be==="answered"&&d("p",{className:"sc-error",children:"That code has already been answered. If it was not you, deny the next one."}),F&&d("p",{className:"sc-error",children:F}),x("div",{className:"sc-row",style:{marginTop:16},children:[d("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:()=>void vn(),disabled:se||be!=="live",children:"Approve"}),d("button",{type:"button",className:"sc-btn",onClick:()=>void ct(),disabled:se||be==="answered",children:"No, deny it"})]}),be==="live"&&I.expires_at&&x("p",{className:"sc-note",style:{marginTop:10},children:["This code expires in ",Ys(Date.parse(I.expires_at)-ae),"."]})]}),f==="waiting"&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:ke?.choice.short??"Soba App"})]}),d(vt,{mark:ke?.Mark??j}),d("h2",{className:"sc-h",id:re,children:"Approved. Waiting for it to connect"}),d("p",{className:"sc-p",children:"Nothing more to do here. This page changes when it arrives."}),ve>0&&ae-ve>Vs&&d("p",{className:"sc-note sc-tone-warn",style:{marginTop:14,textAlign:"center"},children:"Still nothing. Look at the Soba app on that machine: it says what it is doing. This keeps watching either way."})]}),f==="connected"&&x("div",{className:"sc-card",children:[d(dr,{tone:"ok"}),d("h2",{className:"sc-h",id:re,children:$e?.label?`${$e.label} is connected`:"Connected"}),x("p",{className:"sc-p",children:[d(wt,{context:w})," will use ",$e?.label?"it":"this machine"," from now on, while it is awake."]}),o&&x(kt,{children:[d("div",{style:{marginTop:16},children:d(Un,{machines:R,onApproveRuntime:pt})}),d("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:14},onClick:()=>m("manage"),children:"Done"})]})]}),f==="hosted"&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:"ChatGPT"})]}),Ae?d(vt,{mark:un,still:!0}):d(vt,{mark:un}),d("h2",{className:"sc-h",id:re,children:Ae?"Your browser blocked the window":"Finish signing in to ChatGPT"}),d("p",{className:"sc-p",children:Ae?"Nothing opened. Open the sign-in yourself below. A link you click is allowed where a window we open is not.":"Approve it in the window that opened."}),x("div",{className:"sc-stack",style:{marginTop:18},children:[Ae&&d("a",{className:"sc-btn sc-btn-primary",href:Ae,target:"soba-connect-plan",rel:"noreferrer",children:"Open the ChatGPT sign-in"}),F&&d("p",{className:"sc-error",children:F}),Be>0&&ae-Be>js&&d("p",{className:"sc-note sc-tone-warn",children:"Still nothing. The window may have been closed before it finished, or the sign-in may have been declined. This keeps watching either way."})]})]}),f==="hosted_connected"&&x("div",{className:"sc-card",children:[d(dr,{tone:"ok"}),d("h2",{className:"sc-h",id:re,children:"ChatGPT is connected"}),x("p",{className:"sc-p",children:[d(wt,{context:w})," will run on your ChatGPT plan",me[0]?.account_label?` (${me[0].account_label})`:"",". Nothing more to pay, nothing to install."]}),d("p",{className:"sc-opt-note",style:{textAlign:"center"},children:"It runs on our side, so it has no access to your files or your terminal."}),o&&x(kt,{children:[d("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>m("manage"),children:"Done"}),d("div",{className:"sc-opt-alt",children:d("button",{type:"button",className:"sc-alt-link",onClick:()=>m("choose"),children:"Connect a machine too"})})]})]}),f==="denied"&&x("div",{className:"sc-card",children:[d(dr,{tone:"off"}),d("h2",{className:"sc-h",id:re,children:"Declined"}),d("p",{className:"sc-p",children:gn==="machine"?"Nothing was connected. You can ask again whenever you like.":"That machine was not attached to your account, and the terminal has been told so."}),d("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>m("choose"),children:"Back to the start"})]})]})}function mo(e){return e?.app.name??"this app"}function Zs(e){let n=e?.app.icon_urls;if(n?.length)return n;let t=e?.app.icon_url;return t?[t]:[]}function fo(e){let n=Zs(e),[t,r]=W([]),o=oe(c=>{c&&r(i=>i.includes(c)?i:[...i,c])},[]),s=oe(c=>o(c.currentTarget.getAttribute("src")),[o]),a=oe(c=>{c?.complete&&c.naturalWidth===0&&o(c.getAttribute("src"))},[o]);return{icon:n.find(c=>!t.includes(c)),onError:s,ref:a}}function Js({context:e}){let{icon:n,onError:t,ref:r}=fo(e);return e?.app.mark==="soba"?d(j,{className:"sc-app-mark"}):n?d("img",{className:"sc-app-mark",src:n,alt:"","aria-hidden":"true",ref:r,onError:t}):null}function wt({context:e}){let{icon:n,onError:t,ref:r}=fo(e),o=e?.app.mark==="soba";return x("span",{className:"sc-app",children:[o&&d(j,{className:"sc-app-icon"}),!o&&n&&d("img",{className:"sc-app-icon",src:n,alt:"",ref:r,onError:t}),mo(e)]})}function Sn({onClick:e}){return d("button",{type:"button",className:"sc-head-back",onClick:e,"aria-label":"Back",children:d("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:d("path",{d:"M15 5 8 12l7 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function ur({className:e}){return d("svg",{className:e,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:d("path",{d:"M9 5l7 7-7 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function vt({mark:e,still:n}){return x("span",{className:"sc-waiting","aria-hidden":"true",children:[!n&&d("svg",{className:"sc-waiting-orbit",viewBox:"0 0 100 100","aria-hidden":"true",focusable:"false",children:d("circle",{className:"sc-waiting-arc",cx:"50",cy:"50",r:"46"})}),d(e,{className:"sc-waiting-mark"})]})}function dr({tone:e}){return d("span",{className:`sc-result sc-result-${e}`,"aria-hidden":"true",children:d(Vt,{kind:e==="ok"?"snap":"gone",size:84})})}function Qs({text:e}){return d(kt,{children:e.split("`").map((n,t)=>t%2===1?d("code",{className:"sc-inline-code",children:n},t):n)})}function Kn({k:e,v:n}){return x("li",{className:"sc-fact",children:[d("span",{className:"sc-fact-key",children:e}),d("span",{children:n})]})}import{useEffect as Xs,useRef as fr}from"react";var Ct=0,mr=null;function ho(){if(typeof document>"u")return()=>{};Ct===0&&(mr=document.body.style.overflow,document.body.style.overflow="hidden"),Ct+=1;let e=!1;return()=>{e||(e=!0,Ct-=1,Ct===0&&(document.body.style.overflow=mr??"",mr=null))}}import{jsx as go}from"react/jsx-runtime";function Vn({open:e,onClose:n,labelledBy:t,theme:r,style:o,children:s}){let a=fr(null),c=fr(null),i=fr(null);return Xs(()=>{let l=a.current;if(l){if(!e){l.open&&l.close();return}return l.open||l.showModal(),document.activeElement===l&&c.current?.focus(),ho()}},[e]),go("dialog",{ref:a,className:"soba-connect sc-modal","aria-labelledby":t,...r?{"data-theme":r}:{},style:o,onCancel:l=>{l.preventDefault(),n()},onPointerDown:l=>{i.current=l.target},onClick:l=>{l.target===l.currentTarget&&i.current===l.currentTarget&&n()},children:go("div",{className:"sc-modal-sheet",ref:c,tabIndex:-1,children:s})})}import{useRef as ta,useState as ra}from"react";var ea={"claude-code":{small:"haiku",large:"opus"}};function bo(e){let n=ea[e];return!!(n?.small||n?.large)}var na={haiku:"Haiku",sonnet:"Sonnet",opus:"Opus",fable:"Fable"};function yo(e){return na[e]??e}function hr(e){let n=[...e].sort(mt),t=Ee([...e]),r=t?De(t):null,s=[{id:"auto",kind:"auto",label:"Automatic",model:"auto",...r?.runtime?{note:`Uses ${r.runtime.display_name}`}:{}}];n.some(u=>ye(u).some(p=>bo(p.id)))&&s.push({id:"small",kind:"size",label:"Fast",note:"quick and cheap",model:"small"},{id:"large",kind:"size",label:"Best",note:"the most capable",model:"large"});let c=new Map;for(let u of n)for(let p of ye(u))for(let y of p.models){if(!y)continue;let f=`${p.id}/${y}`,m=c.get(f);if(m){m.machines.add(V(u));continue}c.set(f,{option:{id:f,kind:"named",label:yo(y),model:y,runtime:p.id,runtimeName:p.display_name,costClass:p.cost_class},machines:new Set([V(u)])})}let i=new Set;for(let{machines:u}of c.values())for(let p of u)i.add(p);let l=i.size>1;for(let{option:u,machines:p}of c.values()){let y=l&&p.size===1?[...p][0]:void 0;s.push(y?{...u,machine:y}:u)}return s}function jn(e){let n=[],t=[];for(let r of e){if(r.kind!=="named"){n.push(r);continue}let o=r.runtimeName??r.runtime??"",s=t.find(a=>a.heading===o);s?s.options.push(r):t.push({heading:o,options:[r]})}return n.length?[{heading:null,options:n},...t]:t}function gr(e,n){let t=e.find(o=>o.kind==="auto")??{id:"auto",kind:"auto",label:"Automatic",model:"auto"};if(!n||n==="auto")return{selected:t,unavailable:null};let r=e.find(o=>o.id===n);return r?{selected:r,unavailable:null}:{selected:t,unavailable:n}}function br(e){return e.runtime?{model:e.model,runtime:e.runtime}:{model:e.model}}function Yn(e){return e.length>1}import{jsx as Nt,jsxs as wo}from"react/jsx-runtime";function yr({options:e,selected:n,onPick:t,caption:r,disabled:o,className:s}){let[a,c]=ra(!1),i=ta(null);if(!Yn(e))return null;let l=s?`sc-mp ${s}`:"sc-mp";return wo("span",{className:l,children:[r&&Nt("span",{className:"sc-mp-cap",children:r}),wo("button",{ref:i,type:"button",className:"sc-mp-btn","aria-haspopup":"menu","aria-expanded":a,"aria-label":`Model: ${n.label}. Change`,disabled:o,onClick:()=>c(u=>!u),children:[Nt("span",{className:"sc-mp-label",children:n.label}),Nt(Cn,{open:!0})]}),a&&Nt(Hn,{anchor:i,label:"Which model answers",options:oa(e),current:n.id,onClose:()=>c(!1),onPick:u=>{c(!1),u&&t(u)}})]})}function oa(e){let n=[];for(let t of jn(e))t.options.forEach((r,o)=>{let s=sa(r);n.push({id:r.id,label:r.label,...s?{note:s}:{},...t.heading&&o===0?{heading:t.heading}:{},...!t.heading&&r.kind==="size"&&o===1?{rule:!0}:{}})});return n}function sa(e){return e.kind!=="named"?e.note:e.machine?`on ${e.machine}`:void 0}import{useEffect as wr,useRef as aa}from"react";import{jsx as ia}from"react/jsx-runtime";var mn=8;function vr({open:e,onClose:n,anchor:t,label:r,theme:o,style:s,children:a}){let c=aa(null);return wr(()=>{let i=c.current;if(!(!i||!(typeof i.showPopover=="function")))try{e?i.showPopover():i.hidePopover()}catch{}},[e]),wr(()=>{if(!e)return;let i=()=>{let u=c.current,p=t.current;if(!u||!p)return;let y=p.getBoundingClientRect(),f=u.offsetWidth,m=u.offsetHeight,w=window.innerWidth-f-mn,P=Math.max(mn,Math.min(y.right-f,Math.max(mn,w))),R=y.bottom+mn,_=y.top-mn-m,M=R+m>window.innerHeight-mn&&_>mn?_:R;u.style.left=`${Math.round(P)}px`,u.style.top=`${Math.round(M)}px`};i();let l=requestAnimationFrame(i);return window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{cancelAnimationFrame(l),window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[e,t]),wr(()=>{if(!e)return;let i=u=>{u.key==="Escape"&&n()},l=u=>{let p=u.target;p&&(c.current?.contains(p)||t.current?.contains(p)||n())};return document.addEventListener("keydown",i),document.addEventListener("pointerdown",l,!0),()=>{document.removeEventListener("keydown",i),document.removeEventListener("pointerdown",l,!0)}},[e,n,t]),ia("div",{ref:c,role:"dialog","aria-label":r,className:"soba-connect sc-pop",...o?{"data-theme":o}:{},popover:"manual",hidden:!e,style:s,children:a})}var Zn=new Map,Mn=new Map,vo=!1;function la(){vo||typeof window>"u"||(vo=!0,window.addEventListener("storage",e=>{!e.key||!Zn.has(e.key)||(Mn.set(e.key,yt(e.key)),kr(e.key))}))}function kr(e){for(let n of Zn.get(e)??[])n()}function Jn(e){return e??""}function Cr(e,n){let t=Jn(e);la();let r=Zn.get(t)??new Set;return r.add(n),Zn.set(t,r),()=>{r.delete(n),r.size===0&&Zn.delete(t)}}function xt(e){let n=Jn(e),t=Mn.get(n);if(t!==void 0)return t;let r=e?yt(e):null;return Mn.set(n,r),r}function Nr(){return null}function xr(e,n){xt(e)===null&&(Mn.set(Jn(e),n),kr(Jn(e)))}function Sr(e,n){let t=Jn(e);Mn.get(t)!==n&&(Mn.set(t,n),or(e,n),kr(t))}function He(e){let n=`${e.unit}s`;return e.reward==="unlimited"?`Unlimited ${n} on your own AI`:e.reward==="included"&&e.includedUnits!==null?`${ua(e.includedUnits)} ${n} a month once you connect`:e.reward==="credit"&&e.creditMicros>0?`${ca(e.creditMicros)} back each month you stay connected`:null}function Ue(e){return e==="unlimited"||e==="included"}var Co=new Set(["user-hardware","user-subscription"]),ko=new Set(["open-weights","frontier"]);function xe(e){return e===null||e.length===0?!1:e.every(n=>Co.has(n))}var ca=e=>(e/1e6).toLocaleString("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}),ua=e=>e.toLocaleString("en-US");function Mr(e,n){if(!(n===null||n.some(s=>ko.has(s))))return!1;let r=e.findIndex(s=>Co.has(s));if(r===-1)return!1;let o=e.findIndex(s=>ko.has(s));return o===-1||r<o}import{createContext as No,useContext as xo}from"react";var Pr=No(null);function St(){return xo(Pr)}var Rr=No({context:null,machines:void 0,theme:"light"});function H(){return xo(Rr)}import{useMemo as ma}from"react";import{createContext as da,useContext as pa}from"react";var _r=da(null);function D(){let e=pa(_r);if(!e)throw new Error("useSoba() must be used inside a <SobaProvider>.");return e}function Qn(){let{compute:e}=D();return ma(()=>{let n=e.machines,t=[...n].sort((s,a)=>Ee([s,a])===s?-1:1).map(fa),r=Ee([...n]),o=cn(n);return{view:t.length?"machines":e.loading?"loading":e.error?"error":"empty",machines:t,primary:r?t.find(s=>s.machine.id===r.id)??null:null,connected:e.connected,online:e.online,stalled:e.connected&&!e.online&&o?t.find(s=>s.machine.id===o.id)??null:null,loading:e.loading,error:e.error,refresh:e.refresh}},[e])}function fa(e){let n=De(e);return{machine:e,name:V(e),state:Ge(e),status:Dt(e),hardware:$n(e),lastSeen:e.state==="offline"?Dn(e.last_seen_at):null,runtimes:ye(e).map(t=>({runtime:t,name:t.display_name,auth:An(t),quarantined:!!t.quarantined})),runsOn:{by:n.by,name:n.runtime?.display_name??null}}}import{jsx as Xn}from"react/jsx-runtime";function ha({className:e}){let{theme:n}=H(),t=e?`soba-connect ${e}`:"soba-connect";return Xn("div",{className:t,"data-theme":n,children:Xn(Er,{})})}function Er(){let e=Qn();return e.view==="loading"?Xn("p",{className:"sc-note",children:"Loading\u2026"}):e.view==="error"?Xn("p",{className:"sc-error",children:e.error?.message}):Xn(Un,{machines:e.machines.map(n=>n.machine)})}import{useCallback as nt,useEffect as Rt,useMemo as wa,useRef as Or,useState as je}from"react";import{useId as ga}from"react";import{jsx as Pn,jsxs as Mt}from"react/jsx-runtime";function et({open:e,onOpenChange:n,initialCode:t,onConnected:r,showStatus:o,reason:s}){let{error:a}=D(),c=St(),i=H(),l=()=>n(!1),u=ga(),p=i.context?.background?.trim(),y=p?ln(p,i.context?.accent):void 0;return Mt(Vn,{open:e,onClose:l,labelledBy:u,theme:i.theme,style:y,children:[a?Mt("div",{className:"sc-card",children:[Pn("h2",{className:"sc-title",id:u,children:"Could not start"}),Pn("p",{className:"sc-error",children:a.message})]}):!c&&!i.context?Mt("div",{className:"sc-card",children:[Pn("h2",{className:"sc-title",id:u,children:"One moment"}),Pn("p",{className:"sc-note",children:"Getting your compute\u2026"})]}):Pn(pr,{client:c,active:e,onClose:l,headingId:u,theme:i.theme,initialContext:i.context,...i.machines!==void 0?{initialMachines:i.machines}:{},...t?{initialCode:t}:{},...r?{onConnected:r}:{},...o===void 0?{}:{showStatus:o},...s?{reason:s}:{}}),Mt("p",{className:"sc-modal-foot",children:[Pn(j,{className:"sc-foot-mark"}),"Secured by Soba"]})]})}import{useCallback as ba}from"react";function ya(){let{connect:e}=D(),n=Qn(),t=ba(()=>e.open("manual"),[e]);return{...Pt(n.primary?.machine??null),machine:n.primary,open:t,canOpen:e.hasModal,loading:n.view==="loading"}}function Pt(e){let n=Ge(e);return{label:e?n.word:"Connect compute",ariaLabel:e?`${n.word} on ${V(e)}`:"Connect compute",connected:e!==null,state:n}}import{Fragment as Ir,jsx as Ye,jsxs as tt}from"react/jsx-runtime";function fn({children:e,variant:n,className:t,initialCode:r,onConnected:o,defaultOpen:s,open:a,onOpenChange:c,showConnected:i=!0}){let{compute:l,connect:u}=D(),p=H(),{theme:y}=p,f=St(),[m,w]=je(s??!!r),P=Or(null),R=a!==void 0,_=!R&&!s&&!r&&u.hasModal,M=R?a:_?u.isOpen:m,B=v=>{_?v?u.open("manual"):u.close():R||w(v),c?.(v)},I=Or(M);Rt(()=>{I.current&&!M&&P.current?.focus(),I.current=M},[M]);let[N,F]=je(null),[T,se]=je(!1),X=wa(()=>T&&N?va(l.machines,N):l.machines,[l.machines,T,N]),ve=Ee(X),K=Pt(ve),ae=i&&K.connected,We=K.state,Y=nt(()=>se(!1),[]),[Me,Xe]=je(!1),de=nt(async()=>{Xe(!0);try{await l.refresh()}finally{Xe(!1)}},[l]),pe=Or(de);pe.current=de,Rt(()=>{T&&pe.current()},[T]);let[ee,gn]=je(!1),[en,Le]=je([]),nn=!!p.context?.hosted_available;Rt(()=>{if(!T||!f||!nn)return;let v=!0;return f.hosted().then(G=>{v&&Le(G.credentials)}).catch(()=>{}),()=>{v=!1}},[T,f,nn]);let[me,ne]=je(!1);Rt(()=>{if(!T||!f)return;let v=!0,G=Oe(async()=>{let te=await f.runs();v&&F(te)},3e3);return()=>{v=!1,G()}},[T,f]);let[Be,Pe]=je(null),Ae=nt(async(v,G)=>{if(f){Pe(null);try{await f.approveRuntime(v,G),await l.refresh()}catch(te){Pe(te.message)}}},[f,l]),qe=nt(async(v,G)=>{if(f){Pe(null);try{await f.preferRuntime(v,G),await l.refresh()}catch(te){Pe(te.message)}}},[f,l]),ie=nt(async v=>{if(f){Pe(null);try{await f.disconnectHosted(v),Le((await f.hosted()).credentials)}catch(G){Pe(G.message)}}},[f]),E=p.context?.background?.trim(),bn=E?ln(E,p.context?.accent):void 0;return tt(Ir,{children:[Ye("button",{ref:P,type:"button","data-theme":y,className:["sc-btn",ae?"sc-btn-connected":"sc-btn-icon",!ae&&n==="primary"?"sc-btn-primary":"",t].filter(Boolean).join(" "),...ae&&!e?{"aria-haspopup":"dialog","aria-expanded":T,"aria-label":K.ariaLabel}:{},onClick:()=>{if(ae&&!e&&!R&&!s&&!r){se(v=>!v);return}B(!0)},children:e??(ae?tt(Ir,{children:[Ye("span",{className:"sc-pill-tile","aria-hidden":"true",children:Ye(j,{className:We.tone==="busy"?"sc-pill-mark sc-pill-mark-busy":"sc-pill-mark"})}),tt("span",{className:"sc-btn-connected-text",children:[We.word,ve&&tt("span",{className:"sc-btn-connected-where",children:[" on ",V(ve)]})]}),Ye("i",{className:`sc-dot sc-dot-${We.tone}`,"aria-hidden":"true"})]}):tt(Ir,{children:[Ye(j,{className:"sc-btn-mark"}),"Connect compute"]}))}),Ye(vr,{open:T,onClose:Y,anchor:P,label:"Your compute",theme:y,...bn?{style:bn}:{},children:Ye(dn,{machines:X,hosted:en,onApproveRuntime:(v,G)=>void Ae(v,G),onPreferRuntime:(v,G)=>void qe(v,G),onDisconnectHosted:v=>void ie(v),onRefresh:()=>void de(),refreshing:Me,error:Be,runs:N,runsOpen:me,onToggleRuns:()=>ne(v=>!v),onPair:()=>{se(!1),_?u.open("pair"):(gn(!0),B(!0))},...p.context?.app.name?{appName:p.context.app.name}:{}})}),!_&&Ye(et,{open:M,onOpenChange:v=>{v||gn(!1),B(v)},...ee?{showStatus:!1}:{},...r?{initialCode:r}:{},...o?{onConnected:o}:{}})]})}function va(e,n){return e.map(t=>{if(t.state==="offline")return t;let r=n.filter(o=>o.machine_id===t.id).length;return{...t,active:r,state:r>0?"busy":"online"}})}import{jsx as Tr,jsxs as Ca}from"react/jsx-runtime";function ka({initialCode:e,onConnected:n,className:t,showStatus:r=!0}){let{theme:o}=H();return Ca("div",{className:t?`soba-connect ${t}`:"soba-connect","data-theme":o,children:[r&&Tr(Er,{}),Tr("div",{className:"sc-compute-act",children:Tr(fn,{...e?{initialCode:e}:{},...n?{onConnected:n}:{}})})]})}import{useId as La,useState as Aa}from"react";import{useCallback as Ar,useEffect as _o,useState as Eo}from"react";import{useCallback as Na,useState as xa}from"react";function rt(){let[e,n]=xa(null);return{open:Na(()=>{n(null),Jt().then(n)},[]),launch:e,note:e==="absent"?"Nothing opened here. That machine may be a different computer, or asleep.":null}}import{useCallback as So,useMemo as Mo}from"react";function hn(e){if(!e)return null;if(typeof e=="string")return e;if(typeof Response<"u"&&e instanceof Response)return Po(e.status);let n=e,t=n.error;return typeof t?.code=="string"?t.code:typeof t?.type=="string"?t.type:typeof n.code=="string"?n.code:typeof n.status=="number"?Po(n.status):n.cause&&n.cause!==e?hn(n.cause):null}function Po(e){return e===402?"payment_required":e===409?"no_compute":null}function Lr(...e){let[n,t]=e,{plan:r,compute:o,connect:s}=D(),a=t?.predict??e.length===0,c=Ma(Sa(n),o)??(a?Pa(r,o):null),i=r.plan,l=r.plans,u=Mo(()=>{if(c!=="payment_required")return null;let m=i?.price??0,w=i?.included_units??0;return l.find(P=>P.id!==i?.id&&P.price>m&&(P.included_units===null||P.included_units>w))??null},[c,l,i]),p=So(async()=>{if(!u)return;if(u.selectable){await r.select(u.id);return}let m=await r.checkout(u.id);window.location.assign(m)},[u,r]),y=s.open,f=So(()=>{c&&y(c)},[y,c]);return Mo(()=>{if(!c)return null;let m=i?He({unit:i.unit,reward:i.connected_reward,includedUnits:i.connected_included_units,creditMicros:i.connected_credit*1e6}):null,w=i&&Ue(i.connected_reward)?m:null;return{reason:c,...Ra(c,{connectOffer:w,connected:o.connected,online:o.online,machine:cn(o.machines)?.label??null,unit:i?.unit??"message",interval:i?.interval??"month",upgrade:u!==null,resets:r.current?.period_end??null}),connectOffer:w,upgradeTo:u,connect:f,upgrade:p}},[c,i,o,u,f,p,r.current?.period_end])}function Sa(e){let n=hn(e);return n==="payment_required"||n==="no_compute"?n:null}function Ma(e,n){return e==="no_compute"&&n.connected&&n.online?null:e}function Pa(e,n){let t=e.plan;return!t||n.loading?null:xe(t.route_allow)&&!n.online?"no_compute":e.remaining===0&&t.overage==="stop"?"payment_required":null}function Ra(e,n){if(e==="payment_required"){let t=`No ${n.unit}s left this ${n.interval}`;return n.connectOffer&&!n.connected?{title:t,body:`${n.connectOffer}. Connecting takes a minute and costs nothing.`}:n.connectOffer&&!n.online?{title:t,body:`${n.connectOffer}. Waking ${n.machine??"your machine"} is enough.`}:n.upgrade?{title:t,body:n.resets?`A larger plan carries on now. This one comes back on ${Ro(n.resets)}.`:"A larger plan carries on now, or wait for this one to renew."}:{title:t,body:n.resets?`Your allowance comes back on ${Ro(n.resets)}.`:"Your allowance comes back at the start of the next period."}}return n.connected&&!n.online?{title:`${n.machine??"Your machine"} can't be reached`,body:"This run needs it awake and connected. Open Soba App on that machine, or connect another one."}:{title:"Nothing connected yet",body:"This app runs on AI you already pay for, on a machine of your own. Connect one and this run has somewhere to go."}}function Ro(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}function _a(e){let{plan:n,allowance:t,connected:r,online:o,quiet:s,error:a,predict:c,at:i,waved:l}=e;if(!n)return null;let u=e.allow!==void 0?e.allow:n.route_allow;if(r){if(o)return null;let w=xe(u);return{reason:"stalled",title:`${s??"Your machine"} can\u2019t be reached`,detail:w?"The Soba app there has stopped reporting in, so runs have nowhere to go until it is back.":"The Soba app there has stopped reporting in, so nothing will run on your own AI until it is back.",meter:null,dismissible:!1,atTheWall:!1,ownCompute:w}}let p=hn(a),y=p==="payment_required"||p==="no_compute",f=n.ask_to_connect!==!1&&Mr(n.route_prefer,u);if(!c&&!y&&!f)return null;let m=xe(u)?Ea(n.unit,xe(n.route_allow)):Ue(n.connected_reward)?Ia(t,n,i):f?Oa(n.unit):null;return!m||m.dismissible&&l?null:{...m,dismissible:!!m.dismissible,ownCompute:!1,atTheWall:!m.dismissible&&(!c||m.meter!==null&&m.meter.left===0)}}function $r(e={}){let{at:n=.25,error:t,allow:r}=e,o=e.predict??!(e.errorGiven??t!==void 0),{plan:s,compute:a,connect:c}=D(),i=sr(c.publishableKey),[l,u]=Eo(!1);_o(()=>{u(ar(i))},[i]);let p=Ar(()=>{u(!0),ir(i)},[i]),y=Ar(()=>c.open("manual"),[c]),f=Ar(()=>c.open("no_compute"),[c]),m=rt(),[w,P]=Eo(!1),{refresh:R}=a,{launch:_}=m;_o(()=>{if(_===null||_==="absent")return;P(!1);let F=setInterval(()=>void R(),3e3),T=setTimeout(()=>{clearInterval(F),P(!0)},2e4);return()=>{clearInterval(F),clearTimeout(T)}},[_,R]);let M=Ta(c.app?.name,Fn(c.connectUrl)),B=s.loading||a.loading,I=cn(a.machines),N=B?null:_a({plan:s.plan,allowance:{remaining:s.remaining,included:s.included},connected:a.connected,online:a.online,quiet:I?V(I):null,error:t,predict:o,...r!==void 0?{allow:r}:{},at:n,waved:l});return{reason:N?.reason??null,visible:N!==null,title:N?.title??null,detail:N?.detail??null,meter:N?.meter??null,dismissible:N?.dismissible??!1,dismissed:l,dismiss:p,open:y,atTheWall:N?.atTheWall??!1,steps:M,stalled:N?.reason==="stalled"?{machine:I?V(I):null,ownCompute:N.ownCompute,wake:m.open,launch:m.launch,note:m.note,stuck:w,connectAnother:f}:null,loading:B}}function Ea(e,n){return{reason:"needed",title:n?"This plan runs on your own AI.":`These ${e}s run on your own AI.`,detail:`Connect a machine and your ${e}s run there, free, on access you already have.`,meter:null}}function Oa(e){return{reason:"preferred",title:"This plan prefers your own AI.",detail:`Connect a machine and your ${e}s run there instead, on access you already have.`,meter:null,dismissible:!0}}function Ia(e,n,t){let{remaining:r,included:o}=e;if(r===null||o===null||o===0||r>Math.ceil(o*t))return null;let s=He({unit:n.unit,reward:n.connected_reward,includedUnits:n.connected_included_units,creditMicros:n.connected_credit*1e6});return s?{reason:"running",title:r===0?`No ${n.unit}s left this month.`:`${r} ${n.unit}${r===1?"":"s"} left this month.`,detail:`${s}.`,meter:{left:r,of:o}}:null}function Ta(e,n){return[{lead:"Download Soba App",detail:"",...n?{linksLead:"Get it for"}:{},links:n?qn.map(t=>({label:t.label,href:`${n}/download/${t.slug}`})):[]},{lead:"Connect compute",detail:"Press this, then approve the pairing when the app asks.",opens:!0,links:[]},{lead:"Let your AIs serve",detail:`It finds what is installed on that machine. Allow one, and ${e??"this app"} sends every run there.`,linksLead:"Nothing on it yet?",links:ce.map(t=>({label:t.short,href:t.install}))}]}import{Fragment as Io,jsx as L,jsxs as Ze}from"react/jsx-runtime";function $a(e){let{className:n,fallback:t=null}=e,r=$r({...e.at===void 0?{}:{at:e.at},...e.predict===void 0?{}:{predict:e.predict},...e.allow===void 0?{}:{allow:e.allow},error:e.error,errorGiven:"error"in e}),{connect:o}=D(),{theme:s}=H(),[a,c]=Aa(null),i=La(),l=L(Io,{children:t});if(!r.visible)return l;if(r.stalled)return L(Oo,{className:n,theme:s,stalled:!0,children:L(Da,{title:r.title??"",detail:r.detail??"",stalled:r.stalled})});let u=a??r.atTheWall;return Ze(Oo,{className:n,theme:s,children:[Ze("div",{className:"sc-nudge-top",children:[Ze("div",{className:"sc-nudge-say",children:[L("p",{className:"sc-nudge-title",children:r.title}),L("p",{className:"sc-nudge-detail",children:r.detail}),Ze("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more","aria-expanded":u,"aria-controls":i,onClick:()=>c(!u),children:[u?"Hide the details":"How it works",L(Ua,{})]})]}),r.dismissible?L("button",{type:"button",className:"sc-nudge-dismiss","aria-label":"Dismiss",title:"Dismiss",onClick:r.dismiss,children:L(Ha,{})}):null]}),u?L("ol",{className:"sc-nudge-steps",id:i,children:r.steps.map(p=>Ze("li",{children:[p.opens?L("button",{type:"button",className:"sc-step-lead",onClick:()=>o.open("manual"),children:p.lead}):L("strong",{children:p.lead}),p.detail?L("span",{children:p.detail}):null,p.links.length>0?Ze("span",{className:"sc-step-links",children:[p.linksLead,p.links.map(y=>L("a",{href:y.href,target:"_blank",rel:"noreferrer noopener",children:y.label},y.href))]}):null]},p.lead))}):null,L(fn,{variant:"primary"})]})}function Oo({className:e,theme:n,stalled:t,children:r}){return L("div",{className:e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill","data-theme":n,children:L("div",{className:t?"sc-nudge sc-nudge-stalled":"sc-nudge",children:r})})}function Da({title:e,detail:n,stalled:t}){return Ze(Io,{children:[L("div",{className:"sc-nudge-top",children:Ze("div",{className:"sc-nudge-say",children:[L("p",{className:"sc-nudge-title",children:e}),L("p",{className:"sc-nudge-detail",children:n}),t.note&&L("p",{className:"sc-nudge-note",children:t.note}),t.stuck&&L("p",{className:"sc-nudge-note",children:"The Soba app is open, but this machine still isn\u2019t reporting in. It may no longer be connected to this app."}),(t.launch==="absent"||t.stuck)&&L("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more",onClick:t.connectAnother,children:t.stuck?"Connect it again":"Connect another machine"})]})}),L("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:t.wake,children:"Open Soba App"})]})}function Ha(){return L("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-x",children:L("path",{d:"m4.8 4.8 6.4 6.4M11.2 4.8l-6.4 6.4",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})})}function Ua(){return L("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-chev",children:L("path",{d:"M4.5 6.5 8 10l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})})}var Wa=new Set(["delta","thinking","status","done","error"]);function Rn(e){let n;try{n=JSON.parse(e)}catch{return null}if(!n||typeof n!="object")return null;let t=n,r=t.type==="event"?t.event:t;if(!r||typeof r!="object")return null;let o=r;if(typeof o.type!="string"||!Wa.has(o.type))return null;let s={type:o.type};return typeof o.text=="string"&&(s.text=o.text),typeof o.message=="string"&&(s.message=o.message),typeof o.tool=="string"&&(s.tool=o.tool),typeof o.tier=="string"&&(s.tier=o.tier),o.usage&&typeof o.usage=="object"&&(s.usage=o.usage),typeof o.session=="string"&&(s.session=o.session),typeof o.toolInput=="string"&&(s.toolInput=o.toolInput),o.git&&typeof o.git=="object"&&(s.git=o.git),o.turn&&typeof o.turn=="object"&&typeof o.turn.text=="string"&&(s.turn={text:o.turn.text}),typeof o.reason=="string"&&(s.reason=o.reason),typeof o.retryable=="boolean"&&(s.retryable=o.retryable),(o.state==="interrupted"||o.state==="resumed")&&(s.state=o.state),s}async function*Dr(e){let n=e.body;if(!n)throw new Error("That run response had no body to stream.");let t=(e.headers.get("content-type")??"").includes("ndjson"),r=n.getReader(),o=new TextDecoder,s="",a=[];try{for(;;){let i=await r.read();if(i.done)break;for(s+=o.decode(i.value,{stream:!0});;){let l=s.indexOf(`
|
|
3
|
+
`);if(l===-1)break;let u=Lo(s.slice(0,l));if(s=s.slice(l+1),t){let p=u.trim()?Rn(u):null;p&&(yield p);continue}if(u===""){let p=a.join(`
|
|
4
|
+
`);if(a=[],p==="[DONE]")return;let y=p?Rn(p):null;y&&(yield y);continue}To(u,a)}}!t&&s&&To(Lo(s),a);let c=t?s.trim():a.join(`
|
|
5
|
+
`);if(c&&c!=="[DONE]"){let i=Rn(c);i&&(yield i)}}finally{r.cancel().catch(()=>{})}}function To(e,n){if(!e||e.startsWith(":"))return;let t=e.indexOf(":");if(t===-1||e.slice(0,t)!=="data")return;let r=e.slice(t+1);n.push(r.startsWith(" ")?r.slice(1):r)}function Lo(e){return e.endsWith("\r")?e.slice(0,-1):e}async function Ba(e){let n="";for await(let t of e)if(t.type==="delta"&&t.text&&(n+=t.text),t.type==="error")throw new Error(t.message??"The run ended with an error.");return n}import{useCallback as Hr,useEffect as qa,useMemo as Ur,useSyncExternalStore as Fa}from"react";function Wr(e={}){let{compute:n,connect:t}=D(),{value:r,onChange:o,defaultValue:s,remember:a=!0,user:c}=e,i=r!==void 0,l=a&&!i?rr(t.publishableKey,c):null,u=Hr(_=>Cr(l,_),[l]),p=Fa(u,Hr(()=>xt(l),[l]),Nr),y=Ur(()=>hr(n.machines),[n.machines]),f=Ur(()=>jn(y),[y]);qa(()=>{i||!s||xr(l,s)},[i,s,l]);let m=i?r:p??s??null,{selected:w,unavailable:P}=Ur(()=>gr(y,m??null),[y,m]),R=Hr(_=>{i||Sr(l,_),o?.(_)},[i,l,o]);return{options:y,groups:f,selected:w,select:R,run:br(w),unavailable:P,pickable:Yn(y),loading:n.loading&&!n.machines.length}}import{jsx as Ao}from"react/jsx-runtime";function Ga({caption:e,disabled:n,className:t,...r}){let{theme:o}=H(),{options:s,selected:a,select:c,pickable:i}=Wr(r);return i?Ao("span",{className:"soba-connect sc-inline","data-theme":o,children:Ao(yr,{options:s,selected:a,onPick:c,...e?{caption:e}:{},...n?{disabled:n}:{},...t?{className:t}:{}})}):null}import{useEffect as za}from"react";var $o="data-soba-react",Do=!1;function ot(){if(Do||typeof document>"u"||(Do=!0,document.querySelector(`style[${$o}]`)))return;let e=document.createElement("style");e.setAttribute($o,""),e.textContent=`.soba-connect {
|
|
9
6
|
--sc-ground: #ffffff;
|
|
10
7
|
--sc-sheet: #ffffff;
|
|
11
8
|
--sc-raised: #f6f6f7;
|
|
@@ -204,6 +201,10 @@ a.sc-btn {
|
|
|
204
201
|
color: var(--sc-muted, #6b6b73);
|
|
205
202
|
}
|
|
206
203
|
|
|
204
|
+
.sc-tone-absent {
|
|
205
|
+
color: var(--sc-faint, #a1a1aa);
|
|
206
|
+
}
|
|
207
|
+
|
|
207
208
|
.sc-error {
|
|
208
209
|
color: var(--sc-warn, #b06f14);
|
|
209
210
|
font-size: var(--sc-fs-body);
|
|
@@ -270,6 +271,13 @@ a.sc-btn {
|
|
|
270
271
|
padding: 0 2px 3px 12px;
|
|
271
272
|
}
|
|
272
273
|
|
|
274
|
+
.sc-cap-acts {
|
|
275
|
+
flex: none;
|
|
276
|
+
display: flex;
|
|
277
|
+
align-items: center;
|
|
278
|
+
gap: 4px;
|
|
279
|
+
}
|
|
280
|
+
|
|
273
281
|
.sc-group-title {
|
|
274
282
|
flex: 1;
|
|
275
283
|
min-width: 0;
|
|
@@ -409,6 +417,71 @@ a.sc-btn {
|
|
|
409
417
|
color: var(--sc-line-2, #dcdce0);
|
|
410
418
|
}
|
|
411
419
|
|
|
420
|
+
.sc-mrow-btn {
|
|
421
|
+
width: calc(100% + 4px);
|
|
422
|
+
margin-left: -4px;
|
|
423
|
+
padding-left: 4px;
|
|
424
|
+
border: 0;
|
|
425
|
+
border-radius: 10px;
|
|
426
|
+
background: transparent;
|
|
427
|
+
color: inherit;
|
|
428
|
+
font: inherit;
|
|
429
|
+
text-align: left;
|
|
430
|
+
cursor: pointer;
|
|
431
|
+
transition: background-color 120ms ease;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.sc-mrow-btn:hover {
|
|
435
|
+
background: var(--sc-tray-sunk, #f6f6f7);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.sc-mrow-btn:hover .sc-mbadge {
|
|
439
|
+
box-shadow: 0 0 0 2.5px var(--sc-tray-sunk, #f6f6f7);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
.sc-chev {
|
|
443
|
+
flex: none;
|
|
444
|
+
width: 14px;
|
|
445
|
+
height: 14px;
|
|
446
|
+
color: var(--sc-muted, #6b6b73);
|
|
447
|
+
transition: transform 120ms ease;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.sc-chev-open {
|
|
451
|
+
transform: rotate(90deg);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
.sc-rrow {
|
|
455
|
+
display: flex;
|
|
456
|
+
align-items: flex-start;
|
|
457
|
+
gap: 10px;
|
|
458
|
+
padding: 6px 12px 6px 0;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
.sc-rrow .sc-runtime-tile {
|
|
462
|
+
margin-top: 1px;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.sc-rtop {
|
|
466
|
+
display: flex;
|
|
467
|
+
align-items: baseline;
|
|
468
|
+
gap: 8px;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
.sc-rtop .sc-averdict {
|
|
472
|
+
font-variant-numeric: tabular-nums;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
.sc-rstep {
|
|
476
|
+
display: -webkit-box;
|
|
477
|
+
overflow: hidden;
|
|
478
|
+
-webkit-box-orient: vertical;
|
|
479
|
+
-webkit-line-clamp: 2;
|
|
480
|
+
font-size: var(--sc-fs-label);
|
|
481
|
+
line-height: 1.4;
|
|
482
|
+
color: var(--sc-muted, #6b6b73);
|
|
483
|
+
}
|
|
484
|
+
|
|
412
485
|
.sc-arow {
|
|
413
486
|
display: flex;
|
|
414
487
|
align-items: center;
|
|
@@ -443,6 +516,10 @@ a.sc-btn {
|
|
|
443
516
|
font-size: var(--sc-fs-small);
|
|
444
517
|
}
|
|
445
518
|
|
|
519
|
+
.sc-aname-absent {
|
|
520
|
+
color: var(--sc-muted, #6b6b73);
|
|
521
|
+
}
|
|
522
|
+
|
|
446
523
|
.sc-aversion {
|
|
447
524
|
color: var(--sc-muted, #6b6b73);
|
|
448
525
|
}
|
|
@@ -456,6 +533,18 @@ a.sc-btn {
|
|
|
456
533
|
color: var(--sc-muted, #6b6b73);
|
|
457
534
|
}
|
|
458
535
|
|
|
536
|
+
.sc-sglyph {
|
|
537
|
+
flex: none;
|
|
538
|
+
width: 11px;
|
|
539
|
+
height: 11px;
|
|
540
|
+
color: var(--sc-ok, #22a06b);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
.sc-aserving {
|
|
544
|
+
margin-left: 5px;
|
|
545
|
+
font-variant-numeric: tabular-nums;
|
|
546
|
+
}
|
|
547
|
+
|
|
459
548
|
.sc-orow {
|
|
460
549
|
display: flex;
|
|
461
550
|
align-items: center;
|
|
@@ -524,6 +613,11 @@ a.sc-btn {
|
|
|
524
613
|
background: var(--sc-tray-sunk, #f6f6f7);
|
|
525
614
|
}
|
|
526
615
|
|
|
616
|
+
.sc-open-app {
|
|
617
|
+
color: inherit;
|
|
618
|
+
text-decoration: none;
|
|
619
|
+
}
|
|
620
|
+
|
|
527
621
|
.sc-hrow {
|
|
528
622
|
padding-bottom: 2px;
|
|
529
623
|
}
|
|
@@ -536,6 +630,246 @@ a.sc-btn {
|
|
|
536
630
|
color: var(--sc-muted, #6b6b73);
|
|
537
631
|
}
|
|
538
632
|
|
|
633
|
+
.sc-runs-to {
|
|
634
|
+
display: inline-flex;
|
|
635
|
+
flex: none;
|
|
636
|
+
align-items: center;
|
|
637
|
+
gap: 2px;
|
|
638
|
+
min-width: 0;
|
|
639
|
+
max-width: 62%;
|
|
640
|
+
font-size: var(--sc-fs-label);
|
|
641
|
+
color: var(--sc-muted, #6b6b73);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
.sc-runs-cap {
|
|
645
|
+
flex: none;
|
|
646
|
+
white-space: nowrap;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
.sc-runs-fixed,
|
|
650
|
+
.sc-runs-btn {
|
|
651
|
+
display: inline-flex;
|
|
652
|
+
align-items: center;
|
|
653
|
+
gap: 5px;
|
|
654
|
+
min-width: 0;
|
|
655
|
+
height: 24px;
|
|
656
|
+
padding: 0 6px;
|
|
657
|
+
font-size: var(--sc-fs-label);
|
|
658
|
+
font-weight: 500;
|
|
659
|
+
color: var(--sc-text-2, #3f3f46);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
.sc-runs-btn {
|
|
663
|
+
padding-right: 4px;
|
|
664
|
+
border: 0;
|
|
665
|
+
border-radius: var(--sc-r-pill, 999px);
|
|
666
|
+
background: transparent;
|
|
667
|
+
font-family: inherit;
|
|
668
|
+
cursor: pointer;
|
|
669
|
+
transition: background-color 120ms ease, color 120ms ease;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
.sc-runs-btn:hover:not(:disabled),
|
|
673
|
+
.sc-runs-btn[aria-expanded="true"] {
|
|
674
|
+
background: var(--sc-tray-card, #ffffff);
|
|
675
|
+
color: var(--sc-text, #1a1a1c);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
.sc-runs-btn:disabled {
|
|
679
|
+
opacity: 0.5;
|
|
680
|
+
cursor: default;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
.sc-runs-glyph {
|
|
684
|
+
flex: none;
|
|
685
|
+
width: 12px;
|
|
686
|
+
height: 12px;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
.sc-runs-mark {
|
|
690
|
+
display: inline-grid;
|
|
691
|
+
flex: none;
|
|
692
|
+
place-items: center;
|
|
693
|
+
width: 14px;
|
|
694
|
+
height: 14px;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
.sc-runs-mark > * {
|
|
698
|
+
max-width: 14px;
|
|
699
|
+
max-height: 14px;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
.sc-runs-label {
|
|
703
|
+
min-width: 0;
|
|
704
|
+
overflow: hidden;
|
|
705
|
+
text-overflow: ellipsis;
|
|
706
|
+
white-space: nowrap;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
.sc-runs-btn .sc-chev {
|
|
710
|
+
width: 11px;
|
|
711
|
+
height: 11px;
|
|
712
|
+
color: var(--sc-faint, #a1a1aa);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
.sc-menu {
|
|
716
|
+
position: fixed;
|
|
717
|
+
inset: auto;
|
|
718
|
+
z-index: 2147483647;
|
|
719
|
+
width: 248px;
|
|
720
|
+
margin: 0;
|
|
721
|
+
padding: 4px;
|
|
722
|
+
border: 1px solid var(--sc-line, #e9e9eb);
|
|
723
|
+
border-radius: 12px;
|
|
724
|
+
background: var(--sc-tray-card, #ffffff);
|
|
725
|
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
|
|
726
|
+
color: var(--sc-text, #1a1a1c);
|
|
727
|
+
|
|
728
|
+
max-height: 60vh;
|
|
729
|
+
overflow-y: auto;
|
|
730
|
+
overscroll-behavior: contain;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
.sc-menu-item {
|
|
734
|
+
display: flex;
|
|
735
|
+
align-items: center;
|
|
736
|
+
gap: 10px;
|
|
737
|
+
width: 100%;
|
|
738
|
+
min-height: 34px;
|
|
739
|
+
padding: 5px 8px;
|
|
740
|
+
border: 0;
|
|
741
|
+
border-radius: 8px;
|
|
742
|
+
background: transparent;
|
|
743
|
+
font: inherit;
|
|
744
|
+
font-size: var(--sc-fs-small);
|
|
745
|
+
color: inherit;
|
|
746
|
+
text-align: left;
|
|
747
|
+
cursor: pointer;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
.sc-menu-item:hover,
|
|
751
|
+
.sc-menu-item:focus-visible {
|
|
752
|
+
background: var(--sc-tray-sunk, #f6f6f7);
|
|
753
|
+
outline: none;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
.sc-menu-text {
|
|
757
|
+
display: flex;
|
|
758
|
+
flex: 1;
|
|
759
|
+
min-width: 0;
|
|
760
|
+
flex-direction: column;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
.sc-menu-label {
|
|
764
|
+
overflow: hidden;
|
|
765
|
+
text-overflow: ellipsis;
|
|
766
|
+
white-space: nowrap;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
.sc-menu-note {
|
|
770
|
+
font-size: var(--sc-fs-label);
|
|
771
|
+
line-height: 1.4;
|
|
772
|
+
color: var(--sc-muted, #6b6b73);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
.sc-menu-check {
|
|
776
|
+
flex: none;
|
|
777
|
+
width: 15px;
|
|
778
|
+
height: 15px;
|
|
779
|
+
color: var(--sc-text-2, #3f3f46);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
.sc-menu-sep {
|
|
783
|
+
height: 1px;
|
|
784
|
+
margin: 4px 6px;
|
|
785
|
+
background: var(--sc-line, #e9e9eb);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
.sc-menu-head {
|
|
789
|
+
margin: 6px 6px 2px;
|
|
790
|
+
padding-top: 7px;
|
|
791
|
+
border-top: 1px solid var(--sc-line, #e9e9eb);
|
|
792
|
+
font-size: var(--sc-fs-label);
|
|
793
|
+
font-weight: 500;
|
|
794
|
+
color: var(--sc-muted, #6b6b73);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
.sc-menu > .sc-menu-head:first-child {
|
|
798
|
+
margin-top: 2px;
|
|
799
|
+
padding-top: 0;
|
|
800
|
+
border-top: 0;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
.sc-mp {
|
|
804
|
+
display: inline-flex;
|
|
805
|
+
align-items: center;
|
|
806
|
+
gap: 2px;
|
|
807
|
+
max-width: 100%;
|
|
808
|
+
min-width: 0;
|
|
809
|
+
font-size: var(--sc-fs-label);
|
|
810
|
+
color: var(--sc-muted, #6b6b73);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
.sc-mp-cap {
|
|
814
|
+
flex: none;
|
|
815
|
+
white-space: nowrap;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
.sc-mp-btn {
|
|
819
|
+
display: inline-flex;
|
|
820
|
+
align-items: center;
|
|
821
|
+
gap: 5px;
|
|
822
|
+
min-width: 0;
|
|
823
|
+
height: 26px;
|
|
824
|
+
padding: 0 5px 0 7px;
|
|
825
|
+
border: 0;
|
|
826
|
+
border-radius: var(--sc-r-pill, 999px);
|
|
827
|
+
background: transparent;
|
|
828
|
+
font: inherit;
|
|
829
|
+
font-size: var(--sc-fs-label);
|
|
830
|
+
font-weight: 500;
|
|
831
|
+
color: var(--sc-text-2, #3f3f46);
|
|
832
|
+
cursor: pointer;
|
|
833
|
+
transition: background-color 120ms ease, color 120ms ease;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
.sc-mp-btn:hover:not(:disabled),
|
|
837
|
+
.sc-mp-btn[aria-expanded="true"] {
|
|
838
|
+
background: var(--sc-raised, #f6f6f7);
|
|
839
|
+
color: var(--sc-text, #1a1a1c);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
.sc-mp-btn:disabled {
|
|
843
|
+
opacity: 0.5;
|
|
844
|
+
cursor: default;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
.sc-mp-mark {
|
|
848
|
+
display: inline-grid;
|
|
849
|
+
flex: none;
|
|
850
|
+
place-items: center;
|
|
851
|
+
width: 13px;
|
|
852
|
+
height: 13px;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
.sc-mp-glyph {
|
|
856
|
+
max-width: 13px;
|
|
857
|
+
max-height: 13px;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
.sc-mp-label {
|
|
861
|
+
min-width: 0;
|
|
862
|
+
overflow: hidden;
|
|
863
|
+
text-overflow: ellipsis;
|
|
864
|
+
white-space: nowrap;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
.sc-mp-btn .sc-chev {
|
|
868
|
+
width: 11px;
|
|
869
|
+
height: 11px;
|
|
870
|
+
color: var(--sc-faint, #a1a1aa);
|
|
871
|
+
}
|
|
872
|
+
|
|
539
873
|
.sc-row-act {
|
|
540
874
|
flex: none;
|
|
541
875
|
padding: 3px 9px;
|
|
@@ -612,7 +946,9 @@ a.sc-btn {
|
|
|
612
946
|
.sc-spin {
|
|
613
947
|
animation: none;
|
|
614
948
|
}
|
|
615
|
-
.sc-pair
|
|
949
|
+
.sc-pair,
|
|
950
|
+
.sc-mrow-btn,
|
|
951
|
+
.sc-chev {
|
|
616
952
|
transition: none;
|
|
617
953
|
}
|
|
618
954
|
}
|
|
@@ -687,6 +1023,15 @@ a.sc-btn {
|
|
|
687
1023
|
--sc-shadow-2: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px -12px rgb(0 0 0 / 64%);
|
|
688
1024
|
}
|
|
689
1025
|
|
|
1026
|
+
.soba-connect.sc-inline {
|
|
1027
|
+
display: inline-flex;
|
|
1028
|
+
width: auto;
|
|
1029
|
+
max-width: 100%;
|
|
1030
|
+
margin-inline: 0;
|
|
1031
|
+
|
|
1032
|
+
line-height: 1;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
690
1035
|
.soba-connect.sc-fill {
|
|
691
1036
|
max-width: none;
|
|
692
1037
|
|
|
@@ -1527,9 +1872,12 @@ a.sc-btn {
|
|
|
1527
1872
|
.sc-step-lead:focus-visible,
|
|
1528
1873
|
.sc-step-links a:focus-visible,
|
|
1529
1874
|
.sc-alt-link:focus-visible,
|
|
1875
|
+
.sc-runs-btn:focus-visible,
|
|
1876
|
+
.sc-mp-btn:focus-visible,
|
|
1530
1877
|
.sc-row-act:focus-visible,
|
|
1531
1878
|
.sc-disc:focus-visible,
|
|
1532
1879
|
.sc-pair:focus-visible,
|
|
1880
|
+
.sc-mrow-btn:focus-visible,
|
|
1533
1881
|
.sc-input:focus-visible,
|
|
1534
1882
|
.sc-modal-close:focus-visible {
|
|
1535
1883
|
outline: 2px solid var(--sc-accent, #18181b);
|
|
@@ -2659,4 +3007,7 @@ li.sc-plan-row.sc-plan-current {
|
|
|
2659
3007
|
.sc-opt-has-warn {
|
|
2660
3008
|
color: var(--sc-warn, #b06f14);
|
|
2661
3009
|
}
|
|
2662
|
-
`,document.head.appendChild(e)}import{jsx as Ne,jsxs as Un}from"react/jsx-runtime";function Gr(e){if(!e)return null;let n=tn(e);if(n==="payment_required"||n==="no_compute")return null;if(typeof e=="string")return e||null;let t=e,r=t.error?.message;return typeof r=="string"&&r?r:typeof t.message=="string"&&t.message?t.message:"The run ended with an error."}function yo(){return Un("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[Ne("path",{d:"M8 5v4",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),Ne("circle",{cx:"8",cy:"11.6",r:"0.9",fill:"currentColor"}),Ne("circle",{cx:"8",cy:"8",r:"6.4",stroke:"currentColor",strokeWidth:"1.3"})]})}function wo({error:e,onRetry:n,onDismiss:t,title:r,className:s}){let a=Gr(e),o=D();return bo(()=>Hn(),[]),a?Ne("div",{className:s?`soba-connect ${s}`:"soba-connect","data-theme":o.theme,role:"alert",children:Un("div",{className:"sc-card sc-limit sc-run-error",children:[Un("div",{className:"sc-limit-head",children:[Ne("span",{className:"sc-limit-mark sc-run-error-mark","aria-hidden":"true",children:Ne(yo,{})}),Un("div",{children:[Ne("h2",{className:"sc-limit-title",children:r??"That run did not finish"}),Ne("p",{className:"sc-limit-body sc-run-error-message",children:a})]})]}),(t||n)&&Un("div",{className:"sc-limit-actions",children:[t&&Ne("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,children:"Dismiss"}),n&&Ne("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:n,children:"Try again"})]})]})}):null}import{useId as vo,useState as Kr}from"react";import{jsx as ee,jsxs as st}from"react/jsx-runtime";function Co({reason:e}){return ee("span",{className:"sc-limit-mark","aria-hidden":"true",children:e==="no_compute"?ee(zn,{}):ee(j,{})})}function No(e){let{error:n,variant:t="card",onDismiss:r,className:s}=e,a=Xt(n,{predict:e.predict??!("error"in e)}),o=vo(),c=D();if(!a)return null;let i=ee(ko,{offer:a,headingId:o,onDismiss:r});return t==="dialog"?ee(An,{open:!0,onClose:()=>r?.(),labelledBy:o,theme:c.theme,children:i}):ee("div",{className:s?`soba-connect ${s}`:"soba-connect","data-theme":c.theme,children:i})}function ko({offer:e,headingId:n,onDismiss:t}){let{compute:r}=W(),[s,a]=Kr(!1),[o,c]=Kr(null),i=e.reason==="no_compute"&&r.connected&&!r.online,u=i||e.connectOffer!==null||!r.connected,d=rt();async function f(){a(!0),c(null);try{await e.upgrade()}catch(b){c(b.message)}finally{a(!1)}}return st("div",{className:"sc-card sc-limit",children:[st("div",{className:"sc-limit-head",children:[ee(Co,{reason:e.reason}),st("div",{children:[ee("h2",{className:"sc-limit-title",id:n,children:e.title}),ee("p",{className:"sc-limit-body",children:e.body})]})]}),o&&ee("p",{className:"sc-error",children:o}),i&&d.note&&ee("p",{className:"sc-limit-note",children:d.note}),st("div",{className:"sc-limit-actions",children:[t&&ee("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,disabled:s,children:"Not now"}),e.upgradeTo&&ee("button",{type:"button",className:u?"sc-btn":"sc-btn sc-btn-primary",onClick:()=>void f(),disabled:s,children:s?"Opening\u2026":e.upgradeTo.selectable?`Switch to ${e.upgradeTo.name}`:`${e.upgradeTo.name} for $${e.upgradeTo.price.toLocaleString()}/${e.upgradeTo.interval}`}),u&&ee("button",{type:"button",className:i?"sc-btn":"sc-btn sc-btn-primary",onClick:e.connect,disabled:s,children:i?"Connect another machine":"Connect compute"}),i&&ee("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:d.open,disabled:s,children:"Open Soba App"})]})]})}import{useMemo as xo}from"react";function Bn(){let{plan:e,compute:n,connect:t}=W();return xo(()=>{let r=e.plan,s=e.current,a={plan:r,assignment:s,loading:e.loading,error:e.error,periodEnd:s?.period_end?new Date(s.period_end):null};if(!r)return{...a,state:"none",trialDaysLeft:null,ceiling:null,raised:!1,uncounted:!1,used:0,remaining:null,percent:null,unlimited:!1,reward:null,summary:"Nothing is assigned to this account, so runs are bounded by whatever the app allows."};let o=_o(s?.trial_ends_at??null),c=r.connected_reward==="included"&&n.connected&&r.connected_included_units!==null,i=c?r.connected_included_units:r.included_units,u=r.connected_reward==="unlimited"&&n.connected,d=i===null,f=e.used??0,b=i===null?null:Math.max(0,i-f),g=i&&i>0?Math.min(100,Math.round(f/i*100)):null,m=i!==null&&f>=i,y=o!==null?"trial":d?"unlimited":m?r.overage==="meter"?"metered":"spent":"within";return{...a,state:y,trialDaysLeft:o,ceiling:i,raised:c,uncounted:u,used:f,remaining:b,percent:g,unlimited:d,reward:So(r,c||u,n.connected,()=>t.open("manual")),summary:Po({plan:r,assignment:s,used:f,ceiling:i,trialDaysLeft:o,raised:c,uncounted:u,state:y})}},[e,n.connected,t])}function So(e,n,t,r){let s=Ee({unit:e.unit,reward:e.connected_reward,includedUnits:e.connected_included_units,creditMicros:e.connected_credit*1e6});return s?{line:s,inForce:n,required:!1,connected:t,actionable:Me(e.connected_reward)&&!t,open:r}:he(e.route_allow)&&!t?{line:"Nothing connected yet, so nothing can run.",inForce:!1,required:!0,connected:t,actionable:!0,open:r}:null}function Po(e){let{plan:n,assignment:t,used:r,ceiling:s,trialDaysLeft:a,raised:o,uncounted:c,state:i}=e,u=`${n.unit}${r===1?"":"s"}`,d=c?" Runs your own AI serves do not count toward it.":"";if(i==="trial"&&a!==null){let g=n.price===0?"it continues free":`it is $${n.price.toLocaleString()} a ${n.interval}`;return`${a} ${a===1?"day":"days"} left of your trial, then ${g}.`}if(i==="unlimited")return`${r.toLocaleString()} ${u} this period. No ceiling on this plan.`;if(i==="metered"){let g=r-(s??0);return n.overage_per_unit>0?`${g.toLocaleString()} past the allowance, billed at $${n.overage_per_unit} a ${n.unit}.${d}`:`${g.toLocaleString()} past the allowance.${d}`}if(i==="spent")return t?.period_end?`Allowance spent. It comes back on ${zr(t.period_end)}.${d}`:`Allowance spent. It comes back at the start of the next period.${d}`;let f=Math.max(0,(s??0)-r),b=o?` Raised from ${(n.included_units??0).toLocaleString()} while your own AI is connected.`:t?.period_end?` Resets ${zr(t.period_end)}.`:"";return`${f.toLocaleString()} of ${(s??0).toLocaleString()} ${n.unit}s left.${b}${d}`}function _o(e){if(!e)return null;let n=new Date(e).getTime()-Date.now();return Number.isNaN(n)||n<=0?null:Math.max(1,Math.ceil(n/864e5))}function zr(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}import{Fragment as Mo,jsx as ne,jsxs as fe}from"react/jsx-runtime";function sr({heading:e="Current plan",showUsage:n=!0,showName:t=!0,className:r}){let s=Bn(),{theme:a}=D(),o=b=>ne("section",{className:r?`soba-connect sc-fill ${r}`:"soba-connect sc-fill","data-theme":a,children:fe("div",{className:"sc-card sc-current",children:[e&&ne("h2",{className:"sc-section-title",children:e}),b]})});if(s.error)return o(ne("p",{className:"sc-error",children:s.error.message}));if(s.loading)return o(ne("p",{className:"sc-note",children:"Loading\u2026"}));if(!s.plan)return o(fe("div",{className:"sc-current-main",children:[ne("p",{className:"sc-current-name",children:"No plan"}),ne("p",{className:"sc-sub",children:s.summary})]}));let{plan:c,trialDaysLeft:i,percent:u,unlimited:d,reward:f}=s;return o(fe(Mo,{children:[fe("div",{className:"sc-current-grid",children:[(t||i!==null)&&fe("div",{className:"sc-current-main",children:[t?fe("p",{className:"sc-current-name",children:[c.name,i!==null&&fe("span",{className:"sc-trial-badge",children:[i," ",i===1?"day":"days"," left"]})]}):i!==null&&ne("p",{className:"sc-current-trial",children:fe("span",{className:"sc-trial-badge",children:[i," ",i===1?"day":"days"," left"]})}),t&&c.description&&ne("p",{className:"sc-sub",children:c.description})]}),n&&fe("div",{className:"sc-usage",children:[fe("div",{className:"sc-row-between",children:[ne("span",{className:"sc-fact-key",children:"Usage"}),ne("span",{className:u!==null&&u>=100?"sc-usage-figure sc-usage-over":"sc-usage-figure",children:d?"Unlimited":u===null?"Metered":`${u}% used`})]}),u!==null&&ne("div",{className:"sc-meter",role:"presentation",children:u>0&&ne("span",{className:u>=100?"sc-meter-fill sc-meter-full":"sc-meter-fill",style:{width:`${u}%`}})}),ne("p",{className:"sc-usage-line",children:s.summary})]})]}),f&&fe("div",{className:"sc-current-foot",children:[ne("p",{className:f.required?"sc-plan-reward-line sc-plan-reward-need":f.inForce?"sc-plan-reward-line":"sc-plan-reward-line sc-plan-reward-open",children:f.required?f.line:f.inForce?`In force: ${Eo(f.line)}.`:f.line}),(f.actionable||f.connected)&&ne(nn,{})]})]}))}var Eo=e=>e.charAt(0).toLowerCase()+e.slice(1);import{useCallback as Ro,useMemo as Lo,useState as Vr}from"react";var To={"user-hardware":"your own machine","user-subscription":"your own AI subscription","open-weights":"open models we host",frontier:"frontier models"},Oo=new Set(["user-hardware","user-subscription"]);function or(e={}){let{plan:n,compute:t,connect:r}=W(),[s,a]=Vr(null),[o,c]=Vr(null),{featured:i,onSelect:u,successUrl:d,cancelUrl:f}=e,b=Ro(async m=>{a(m.id),c(null);try{if(m.selectable)await n.select(m.id);else if(u)u(m);else{let y=await n.checkout(m.id,{...d?{successUrl:d}:{},...f?{cancelUrl:f}:{}});window.location.assign(y);return}}catch(y){throw c(y.message),y}finally{(m.selectable||u)&&a(null)}},[n,u,d,f]),g=Lo(()=>n.plans.map(m=>{let y=n.current?.plan_id===m.id;return{plan:m,current:y,featured:i===m.id&&!y,price:Ao(m),allowance:m.included_units===null?`Unlimited ${m.unit}s`:`${m.included_units.toLocaleString()} ${m.unit}${m.included_units===1?"":"s"}`,allowanceNote:Io(m),computeLabel:m.route_allow===null?"any compute":m.route_allow.length===0?"no compute":null,compute:(m.route_allow??[]).map(S=>({costClass:S,label:To[S]??S,owned:Oo.has(S),runtimes:yt(S).map(x=>x.id)})),connect:$o(m,y,t.connected,()=>r.open("manual")),cta:{label:Do(m,y,s===m.id),disabled:y||s!==null,busy:s===m.id,take:()=>b(m)}}}),[n.plans,n.current,i,t.connected,r,s,b]);return{offers:g,current:g.find(m=>m.current)??null,loading:n.loading,error:n.error,failed:o}}function Ao(e){return e.price===0?{amount:"Free",interval:null,free:!0}:{amount:`$${e.price.toLocaleString()}`,interval:e.interval,free:!1}}function Io(e){let n=[];return e.included_units===null?n.push("No ceiling on this plan"):(n.push(`Included each ${e.interval}`),e.overage==="meter"&&e.overage_per_unit>0?n.push(`then $${e.overage_per_unit} a ${e.unit}`):e.included_units>0&&n.push(`then ${e.unit}s stop`)),e.trial_days>0&&n.push(`${e.trial_days}-day trial`),n.join(" \xB7 ")}function $o(e,n,t,r){let s=Ee({unit:e.unit,reward:e.connected_reward,includedUnits:e.connected_included_units,creditMicros:e.connected_credit*1e6}),a=he(e.route_allow)&&!t;if(!s&&!a)return null;let o=Me(e.connected_reward);return{key:s?"Connect your own":"To use this",line:s??(n?"Nothing connected yet, so nothing can run.":"Runs only on compute you connect."),reward:s!==null,actionable:n&&(o||a)&&!t,open:r}}function Do(e,n,t){return n?"Your plan":t?e.selectable?"Switching\u2026":"Opening\u2026":e.selectable?"Choose":`Subscribe for $${e.price.toLocaleString()}/${e.interval}`}import{jsx as h,jsxs as T}from"react/jsx-runtime";function ot(e){return e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill"}function ar({onSelect:e,successUrl:n,cancelUrl:t,showCompute:r=!0,showConnect:s=!1,variant:a="cards",featured:o,className:c}){let{offers:i,loading:u,error:d,failed:f}=or({...o?{featured:o}:{},...e?{onSelect:e}:{},...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}}),{theme:b}=D();if(d)return h("div",{className:ot(c),"data-theme":b,children:h("div",{className:"sc-card",children:h("p",{className:"sc-error",children:d.message})})});if(u)return h("div",{className:ot(c),"data-theme":b,children:h("div",{className:"sc-card",children:h("p",{className:"sc-note",children:"Loading plans\u2026"})})});if(i.length===0)return h("div",{className:ot(c),"data-theme":b,children:h("div",{className:"sc-card",children:h("p",{className:"sc-note",children:"This app has no plans yet."})})});let g={showCompute:r,showConnect:s};return T("div",{className:ot(c),"data-theme":b,"data-variant":a,children:[a==="rows"?h(Uo,{offers:i,shelf:g}):a==="table"?h(Bo,{offers:i,shelf:g}):h(Ho,{offers:i,shelf:g}),f&&h("p",{className:"sc-error",children:f})]})}function Ho({offers:e,shelf:n}){return h("div",{className:"sc-plans",children:e.map(t=>T("div",{className:jr("sc-plan",t),children:[T("div",{className:"sc-row-between",children:[h("span",{className:"sc-title",children:t.plan.name}),h(ir,{offer:t})]}),h("p",{className:"sc-sub",children:t.plan.description}),h(lr,{price:t.price,free:"forever"}),h(dr,{offer:t,shelf:n}),h(Yr,{offer:t}),h("div",{className:"sc-plan-band",children:n.showCompute&&h(ur,{offer:t})}),h("div",{className:"sc-plan-band",children:h(cr,{offer:t})})]},t.plan.id))})}function Uo({offers:e,shelf:n}){return h("ul",{className:"sc-plan-rows",children:e.map(t=>T("li",{className:jr("sc-plan-row",t),children:[T("div",{className:"sc-row-main",children:[T("span",{className:"sc-row-name",children:[h("span",{className:"sc-title",children:t.plan.name}),h(ir,{offer:t})]}),t.plan.description&&h("p",{className:"sc-sub",children:t.plan.description}),h(Yr,{offer:t}),n.showCompute&&h(ur,{offer:t,inline:!0}),h(cr,{offer:t,inline:!0})]}),T("div",{className:"sc-row-side",children:[h(lr,{price:t.price,free:"forever",small:!0}),h(dr,{offer:t,shelf:n})]})]},t.plan.id))})}function Bo({offers:e,shelf:n}){let t=e.some(o=>o.plan.overage_per_unit>0),r=e.some(o=>o.plan.trial_days>0),s=e.some(o=>o.connect!==null),a=o=>[o.current?"sc-col-current":"",o.featured?"sc-col-featured":""].filter(Boolean).join(" ")||void 0;return h("div",{className:"sc-table-scroll",children:T("table",{className:"sc-plan-table",children:[h("thead",{children:T("tr",{children:[h("td",{}),e.map(o=>T("th",{scope:"col",className:a(o),children:[T("span",{className:"sc-row-name",children:[h("span",{className:"sc-title",children:o.plan.name}),h(ir,{offer:o})]}),h(lr,{price:o.price,small:!0})]},o.plan.id))]})}),T("tbody",{children:[T("tr",{children:[h("th",{scope:"row",children:"Included"}),e.map(o=>h("td",{className:a(o),children:o.allowance},o.plan.id))]}),t&&T("tr",{children:[h("th",{scope:"row",children:"Then"}),e.map(o=>h("td",{className:a(o),children:o.plan.overage_per_unit>0?`$${o.plan.overage_per_unit} / ${o.plan.unit}`:h("span",{className:"sc-muted-cell",children:"Stops"})},o.plan.id))]}),r&&T("tr",{children:[h("th",{scope:"row",children:"Trial"}),e.map(o=>h("td",{className:a(o),children:o.plan.trial_days>0?`${o.plan.trial_days} days`:h("span",{className:"sc-muted-cell",children:"None"})},o.plan.id))]}),n.showCompute&&T("tr",{children:[h("th",{scope:"row",children:"Runs on"}),e.map(o=>h("td",{className:a(o),children:h(ur,{offer:o,bare:!0})},o.plan.id))]}),s&&T("tr",{children:[h("th",{scope:"row",children:"Connect your own"}),e.map(o=>h("td",{className:a(o),children:h(cr,{offer:o,bare:!0})},o.plan.id))]}),T("tr",{className:"sc-table-buy",children:[h("td",{}),e.map(o=>h("td",{className:a(o),children:h(dr,{offer:o,shelf:n})},o.plan.id))]})]})]})})}function jr(e,n){return[e,n.current?"sc-plan-current":"",n.featured?"sc-plan-featured":""].filter(Boolean).join(" ")}function ir({offer:e}){return e.current?h("span",{className:"sc-plan-badge",children:"Current"}):e.featured?h("span",{className:"sc-plan-badge-soft",children:"Recommended"}):null}function lr({price:e,small:n,free:t}){return T("p",{className:n?"sc-plan-price sc-plan-price-sm":"sc-plan-price",children:[h("span",{className:"sc-plan-amount",children:e.amount}),e.interval?T("span",{className:"sc-plan-interval",children:["/",e.interval]}):t&&h("span",{className:"sc-plan-interval sc-plan-after",children:t})]})}function Yr({offer:e}){return T("p",{className:"sc-plan-allowance",children:[h("span",{className:"sc-plan-figure",children:e.allowance}),h("span",{className:"sc-plan-qualifier",children:e.allowanceNote})]})}function cr({offer:e,inline:n,bare:t}){let r=e.connect;if(!r)return t?h("span",{className:"sc-muted-cell",children:"None"}):null;let s=r.reward?"sc-plan-reward-line":"sc-plan-reward-line sc-plan-reward-need",a=r.actionable?T("button",{type:"button",className:`${s} sc-plan-reward-act`,"aria-label":"Connect compute",onClick:r.open,children:[h("span",{className:"sc-reward-said",children:r.line}),T("span",{className:"sc-reward-do","aria-hidden":!0,children:[h(j,{className:"sc-reward-mark"}),"Connect compute"]})]}):h("p",{className:s,children:r.line});return t?a:h("div",{className:n?"sc-plan-reward sc-plan-reward-inline":"sc-plan-reward",children:a})}function ur({offer:e,inline:n,bare:t}){let r=e.computeLabel?h("ul",{className:n?"sc-compute sc-compute-inline":"sc-compute",children:h("li",{children:e.computeLabel})}):h("ul",{className:n?"sc-compute sc-compute-inline":"sc-compute",children:e.compute.map(s=>T("li",{className:s.owned?"sc-compute-own":void 0,children:[s.label,h(Wo,{runtimes:s.runtimes})]},s.costClass))});return t?r:T("div",{className:n?"sc-plan-compute sc-plan-compute-inline":"sc-plan-compute",children:[h("span",{className:"sc-fact-key",children:"Runs on"}),r]})}function dr({offer:e,shelf:n}){let t=e.connect;return n.showConnect&&t?.actionable?T("button",{type:"button",className:"sc-btn sc-btn-primary sc-btn-icon",onClick:t.open,children:[h(j,{className:"sc-btn-mark"}),"Connect compute"]}):h("button",{type:"button",className:e.current?"sc-btn":"sc-btn sc-btn-primary",disabled:e.cta.disabled,onClick:()=>void e.cta.take().catch(()=>{}),children:e.cta.label})}function Wo({runtimes:e}){return e.length===0?null:h("span",{className:"sc-compute-marks",children:e.map(n=>{let t=$e[n];return t?h(t,{className:"sc-rt-mark"},n):null})})}import{jsx as pr,jsxs as Jr}from"react/jsx-runtime";function qo({heading:e,plansHeading:n,showUsage:t=!0,showName:r=!0,className:s,...a}){let{plan:o,loading:c}=Bn(),{theme:i}=D(),u=n??(c?"Plans":o?"Change plan":"Choose a plan");return Jr("div",{className:s?`soba-connect sc-fill sc-billing ${s}`:"soba-connect sc-fill sc-billing","data-theme":i,children:[pr(sr,{...e===void 0?{}:{heading:e},showUsage:t,showName:r}),Jr("section",{className:"sc-billing-plans",children:[u&&pr("h2",{className:"sc-section-title",children:u}),pr(ar,{...a})]})]})}import{useState as Qr}from"react";import{jsx as Zr,jsxs as Go}from"react/jsx-runtime";function Fo({plan:e,successUrl:n,cancelUrl:t,label:r,className:s}){let{plan:a}=W(),{theme:o}=D(),[c,i]=Qr(!1),[u,d]=Qr(null);async function f(){i(!0),d(null);try{let b=await a.checkout(e.id,{...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}});window.location.assign(b)}catch(b){d(b.message),i(!1)}}return Go("div",{className:s?`soba-connect ${s}`:"soba-connect","data-theme":o,children:[Zr("button",{type:"button",className:"sc-btn sc-btn-primary",disabled:c,onClick:()=>void f(),children:c?"Opening\u2026":r??`Subscribe for $${e.price.toLocaleString()}/${e.interval}`}),u&&Zr("p",{className:"sc-error",children:u})]})}import{useCallback as ke,useEffect as We,useMemo as bn,useRef as rn,useState as te}from"react";var Ko="soba.session:";function Xr(e){return!e.cacheKey||!e.endpoint?null:Ko+JSON.stringify([e.endpoint,e.user??null,e.cacheKey])}function zo(e){try{let n=globalThis.localStorage?.getItem(e);if(!n)return null;let t=JSON.parse(n);return typeof t.token!="string"||typeof t.expiresAt!="number"?null:{token:t.token,expiresAt:t.expiresAt}}catch{return null}}function Vo(e,n){try{n?globalThis.localStorage?.setItem(e,JSON.stringify(n)):globalThis.localStorage?.removeItem(e)}catch{}}var es=6e4,jo=1e4,at=class{#e;#n=null;#r=null;#t;#s=new Set;constructor(n){this.#t=n,this.#e=n.token??null;let t=Xr(n),r=t&&!this.#e?zo(t):null;r&&r.expiresAt-es>Date.now()&&(this.#e=r.token,this.#n=r.expiresAt)}get token(){return this.#e}get expiresAt(){return this.#n}get canRefresh(){return!!this.#t.endpoint}get refreshAt(){return!this.canRefresh||this.#n===null?null:Math.max(Date.now()+jo,this.#n-es)}subscribe(n){return this.#s.add(n),()=>this.#s.delete(n)}async ensure(){return this.#e?this.#e:this.refresh()}async refresh(){if(this.#r)return this.#r;let n=this.#t.endpoint;if(!n)throw new Error("This Soba session cannot be refreshed. Pass `sessionEndpoint` so the provider can mint a new one.");let t=this.#t.fetchImpl??fetch.bind(globalThis);this.#r=(async()=>{let r=await t(n,{method:"POST",headers:{"content-type":"application/json"},credentials:"same-origin",body:JSON.stringify(this.#t.user?{user:this.#t.user}:{})});if(!r.ok)throw new Error(`Could not start a Soba session (${r.status} from ${n}).`);let s=await r.json(),a=s.session??s.token;if(!a)throw new Error(`${n} answered without a \`session\`. See @soba-so/react's README.`);let o=s.expires_in??s.expiresIn;this.#e=a,this.#n=typeof o=="number"?Date.now()+o*1e3:null;let c=Xr(this.#t);c&&Vo(c,this.#n===null?null:{token:a,expiresAt:this.#n});for(let i of this.#s)i();return a})();try{return await this.#r}finally{this.#r=null}}},gn=new Map,ns=new WeakMap,Yo=1;function Jo(e){if(e.token||!e.endpoint)return null;let n=0;return e.fetchImpl&&(n=ns.get(e.fetchImpl)??Yo++,ns.set(e.fetchImpl,n)),JSON.stringify([e.endpoint,e.user??null,n,e.cacheKey??null])}function ts(e){let n=Jo(e);if(!n)return new at(e);let t=gn.get(n)??{holder:new at(e),users:0};return gn.set(n,t),t.holder}function rs(e){for(let n of gn.values())n.holder===e&&n.users++}function ss(e){for(let[n,t]of gn)if(t.holder===e){setTimeout(()=>{--t.users<=0&&gn.get(n)===t&&gn.delete(n)},0);return}}function os(e,n=fetch.bind(globalThis)){return async(t,r)=>{let s=await n(t,r);if(s.status!==401||!e.canRefresh)return s;let a;try{a=await e.refresh()}catch{return s}return n(t,Qo(r,a))}}function Qo(e,n){let t=new Headers(e?.headers);return t.set("authorization",`Bearer ${n}`),{...e,headers:t}}import{jsx as mr,jsxs as na}from"react/jsx-runtime";var Zo="https://www.soba.so",Xo=3e4;function ea(e){let{children:n,session:t,sessionEndpoint:r,user:s,sessionCacheKey:a,runEndpoint:o,theme:c,initialMachines:i,initialConnect:u=null,initialPlans:d,initialCurrentPlan:f=null,baseUrl:b=Zo,pollMs:g=Xo,injectStyles:m=!0,modal:y=!0,fetchImpl:S,onError:x}=e,[O,H]=te(t??null),[z,_]=te(null),[F,A]=te(u),[P,B]=te(null),[Y,xe]=te(u===null),[le,ge]=te(i??[]),[Re,V]=te(null),[be,qe]=te(i===void 0),[ye,ce]=te(d??[]),[J,yn]=te(f),[we,Le]=te(null),[sn,oe]=te(d===void 0),[Q,R]=te(null),[pe,Se]=te(!1),on=rn(x);on.current=x;let me=ke(w=>{_(w),on.current?.(w)},[]);We(()=>{m&&Hn()},[m]);let E=bn(()=>ts({...t?{token:t}:{},...r?{endpoint:r}:{},...s?{user:s}:{},...S?{fetchImpl:S}:{},...a?{cacheKey:a}:{}}),[t,r,s,S,a]);We(()=>{let w=!0;rs(E);let Z=E.subscribe(()=>{w&&H(E.token)});return!E.token&&!E.canRefresh?me(new Error("<SobaProvider> needs a `session` or a `sessionEndpoint`. A browser cannot mint one: that takes your secret key.")):E.ensure().then(()=>w&&H(E.token),se=>w&&me(se)),()=>{w=!1,Z(),ss(E)}},[E,me]),We(()=>{z&&(xe(!1),qe(!1),oe(!1),B(w=>w??z),V(w=>w??z),Le(w=>w??z))},[z]),We(()=>{let w=E.refreshAt;if(w===null)return;let Z=()=>{E.refresh().catch(Pe=>me(Pe))},se=()=>{document.hidden||(document.removeEventListener("visibilitychange",se),Z())},wn=setTimeout(()=>{typeof document<"u"&&document.hidden?document.addEventListener("visibilitychange",se):Z()},Math.max(0,w-Date.now()));return()=>{clearTimeout(wn),typeof document<"u"&&document.removeEventListener("visibilitychange",se)}},[E,me,O]);let it=rn(u?.machines_url??null),M=bn(()=>{if(!O)return null;let w=new Nn({session:O,baseUrl:b,fetchImpl:os(E,S??fetch.bind(globalThis))});return w.setMachinesUrl(it.current),w},[O,b,E,S]),lt=rn(u!==null);We(()=>{if(!M||lt.current)return;let w=!0;return xe(!0),M.context().then(Z=>{w&&(A(Z),B(null),xe(!1))},Z=>{w&&(B(Z),xe(!1))}),()=>{w=!1}},[M]);let Fe=ke(async()=>{if(M)try{let w=await M.machines();ge(Array.isArray(w)?w:[]),V(null)}catch(w){V(w)}finally{qe(!1)}},[M]),ue=ke(async()=>{if(M)try{let w=await M.plans();ce(w.plans),yn(w.current),Le(null)}catch(w){Le(w)}finally{oe(!1)}},[M]),re=rn(!1),[Te,an]=te(!1),ln=rn(d!==void 0),Ge=rn(!1),Ke=ke(()=>{re.current||(re.current=!0,Ge.current&&queueMicrotask(()=>{Ge.current&&an(!0)}))},[]);We(()=>(Ge.current=!0,re.current&&an(!0),()=>{Ge.current=!1}),[]),We(()=>{!M||!Te||ln.current||ue()},[M,Te,ue]);let ze=ke(async w=>{if(!M)throw new Error("No session yet.");await M.selectPlan(w),await ue()},[M,ue]),ct=ke(async(w,Z)=>{if(!M)throw new Error("No session yet.");let se=await M.checkoutPlan(w,Z);if(!se.url)throw new Error("Checkout could not be started.");return se.url},[M]),Wn=ke(async()=>{if(!M)throw new Error("No session yet.");await M.leavePlan(),await ue()},[M,ue]),qn=rn(i!==void 0);We(()=>{if(!M)return;let w=He(Fe,g,{immediate:!qn.current});return qn.current=!1,w},[M,Fe,g]);let Fn=ke(async w=>{if(!o)throw new Error("Pass `runEndpoint` to <SobaProvider> to start runs from the browser. It is your own route: it holds your secret key, calls soba.run(), and forwards the stream.");let{signal:Z,...se}=w,Pe=await(S??fetch.bind(globalThis))(o,{method:"POST",headers:{"content-type":"application/json",accept:"text/event-stream"},credentials:"same-origin",body:JSON.stringify(se),...Z?{signal:Z}:{}});if(!Pe.ok){let X=await Pe.json().catch(()=>null),Ae=new Error(X?.error?.message??`${o} answered ${Pe.status}.`);throw Ae.status=Pe.status,X?.error?.code&&(Ae.code=X.error.code),X?.error&&(Ae.error=X.error),Ae}let vn=tr(Pe);return async function*(){try{yield*vn}finally{re.current&&ue()}}()},[o,S,ue]),Gn=ke((w="manual")=>{y&&(Se(!0),R(w))},[y]),G=ke(()=>R(null),[]),K=bn(()=>J?ye.find(w=>w.id===J.plan_id)??null:null,[ye,J]),Oe=bn(()=>K?K.connected_reward==="included"&&le.length>0&&K.connected_included_units!==null?K.connected_included_units:K.included_units:null,[K,le]),Kn=bn(()=>({plans:ye,current:J,plan:K,used:J?.units_used??null,included:Oe,remaining:Oe!==null&&J?Math.max(0,Oe-J.units_used):null,unlimited:K!==null&&Oe===null,loading:sn,error:we,select:ze,checkout:ct,leave:Wn,refresh:ue}),[ye,J,K,Oe,sn,we,ze,ct,Wn,ue]),ut=bn(()=>({session:O,client:M,error:z,get plan(){return Ke(),Kn},compute:{machines:le,connected:le.length>0,online:le.some(w=>w.state!=="offline"),loading:be,error:Re,refresh:Fe},connect:{app:F?.app??null,command:F?.command??null,connectUrl:F?.connect_url??null,publishableKey:F?.publishable_key??null,loading:Y,error:P,open:Gn,close:G,isOpen:Q!==null,hasModal:y},run:Fn}),[O,M,z,Kn,Ke,Q,Gn,G,y,le,be,Re,Fe,F,Y,P,Fn]);return mr(zt.Provider,{value:M,children:mr(Vt.Provider,{value:{context:F,machines:be?void 0:le,theme:c??F?.theme??"light"},children:na(Kt.Provider,{value:ut,children:[n,y&&pe&&mr($n,{open:Q!==null,onOpenChange:w=>R(w?Q??"manual":null),...Q==="payment_required"||Q==="no_compute"?{reason:Q}:{},...Q==="pair"?{showStatus:!1}:{}})]})})})}export{zs as ComputeStatus,nn as ConnectButton,js as ConnectCompute,$n as ConnectModal,ro as ConnectNudge,wo as RunError,No as RunLimit,qo as SobaBilling,Fo as SobaCheckout,sr as SobaCurrentPlan,ar as SobaPlans,ea as SobaProvider,mo as collectText,Hn as injectStyles,fn as parseEvent,tr as readEvents,Gr as runErrorMessage,tn as sobaErrorCode,Bn as useCurrentPlan,or as usePlans,Xt as useRunLimit,W as useSoba,go as watchRun};
|
|
3010
|
+
`,document.head.appendChild(e)}import{jsx as Ie,jsxs as st}from"react/jsx-runtime";function Ho(e){if(!e)return null;let n=hn(e);if(n==="payment_required"||n==="no_compute")return null;if(typeof e=="string")return e||null;let t=e,r=t.error?.message;return typeof r=="string"&&r?r:typeof t.message=="string"&&t.message?t.message:"The run ended with an error."}function Ka(){return st("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[Ie("path",{d:"M8 5v4",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),Ie("circle",{cx:"8",cy:"11.6",r:"0.9",fill:"currentColor"}),Ie("circle",{cx:"8",cy:"8",r:"6.4",stroke:"currentColor",strokeWidth:"1.3"})]})}function Va({error:e,onRetry:n,onDismiss:t,title:r,className:o}){let s=Ho(e),a=H();return za(()=>ot(),[]),s?Ie("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":a.theme,role:"alert",children:st("div",{className:"sc-card sc-limit sc-run-error",children:[st("div",{className:"sc-limit-head",children:[Ie("span",{className:"sc-limit-mark sc-run-error-mark","aria-hidden":"true",children:Ie(Ka,{})}),st("div",{children:[Ie("h2",{className:"sc-limit-title",children:r??"That run did not finish"}),Ie("p",{className:"sc-limit-body sc-run-error-message",children:s})]})]}),(t||n)&&st("div",{className:"sc-limit-actions",children:[t&&Ie("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,children:"Dismiss"}),n&&Ie("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:n,children:"Try again"})]})]})}):null}import{useId as ja,useState as Uo}from"react";import{jsx as Z,jsxs as _t}from"react/jsx-runtime";function Ya({reason:e}){return Z("span",{className:"sc-limit-mark","aria-hidden":"true",children:e==="no_compute"?Z(ft,{}):Z(j,{})})}function Za(e){let{error:n,variant:t="card",onDismiss:r,className:o}=e,s=Lr(n,{predict:e.predict??!("error"in e)}),a=ja(),c=H();if(!s)return null;let i=Z(Ja,{offer:s,headingId:a,onDismiss:r});return t==="dialog"?Z(Vn,{open:!0,onClose:()=>r?.(),labelledBy:a,theme:c.theme,children:i}):Z("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":c.theme,children:i})}function Ja({offer:e,headingId:n,onDismiss:t}){let{compute:r}=D(),[o,s]=Uo(!1),[a,c]=Uo(null),i=e.reason==="no_compute"&&r.connected&&!r.online,l=i||e.connectOffer!==null||!r.connected,u=rt();async function p(){s(!0),c(null);try{await e.upgrade()}catch(y){c(y.message)}finally{s(!1)}}return _t("div",{className:"sc-card sc-limit",children:[_t("div",{className:"sc-limit-head",children:[Z(Ya,{reason:e.reason}),_t("div",{children:[Z("h2",{className:"sc-limit-title",id:n,children:e.title}),Z("p",{className:"sc-limit-body",children:e.body})]})]}),a&&Z("p",{className:"sc-error",children:a}),i&&u.note&&Z("p",{className:"sc-limit-note",children:u.note}),_t("div",{className:"sc-limit-actions",children:[t&&Z("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,disabled:o,children:"Not now"}),e.upgradeTo&&Z("button",{type:"button",className:l?"sc-btn":"sc-btn sc-btn-primary",onClick:()=>void p(),disabled:o,children:o?"Opening\u2026":e.upgradeTo.selectable?`Switch to ${e.upgradeTo.name}`:`${e.upgradeTo.name} for $${e.upgradeTo.price.toLocaleString()}/${e.upgradeTo.interval}`}),l&&Z("button",{type:"button",className:i?"sc-btn":"sc-btn sc-btn-primary",onClick:e.connect,disabled:o,children:i?"Connect another machine":"Connect compute"}),i&&Z("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:u.open,disabled:o,children:"Open Soba App"})]})]})}import{useMemo as Qa}from"react";function at(){let{plan:e,compute:n,connect:t}=D();return Qa(()=>{let r=e.plan,o=e.current,s={plan:r,assignment:o,loading:e.loading,error:e.error,periodEnd:o?.period_end?new Date(o.period_end):null};if(!r)return{...s,state:"none",trialDaysLeft:null,ceiling:null,raised:!1,uncounted:!1,used:0,remaining:null,percent:null,unlimited:!1,reward:null,summary:"Nothing is assigned to this account, so runs are bounded by whatever the app allows."};let a=ni(o?.trial_ends_at??null),c=r.connected_reward==="included"&&n.connected&&r.connected_included_units!==null,i=c?r.connected_included_units:r.included_units,l=r.connected_reward==="unlimited"&&n.connected,u=i===null,p=e.used??0,y=i===null?null:Math.max(0,i-p),f=i&&i>0?Math.min(100,Math.round(p/i*100)):null,m=i!==null&&p>=i,w=a!==null?"trial":u?"unlimited":m?r.overage==="meter"?"metered":"spent":"within";return{...s,state:w,trialDaysLeft:a,ceiling:i,raised:c,uncounted:l,used:p,remaining:y,percent:f,unlimited:u,reward:Xa(r,c||l,n.connected,()=>t.open("manual")),summary:ei({plan:r,assignment:o,used:p,ceiling:i,trialDaysLeft:a,raised:c,uncounted:l,state:w})}},[e,n.connected,t])}function Xa(e,n,t,r){let o=He({unit:e.unit,reward:e.connected_reward,includedUnits:e.connected_included_units,creditMicros:e.connected_credit*1e6});return o?{line:o,inForce:n,required:!1,connected:t,actionable:Ue(e.connected_reward)&&!t,open:r}:xe(e.route_allow)&&!t?{line:"Nothing connected yet, so nothing can run.",inForce:!1,required:!0,connected:t,actionable:!0,open:r}:null}function ei(e){let{plan:n,assignment:t,used:r,ceiling:o,trialDaysLeft:s,raised:a,uncounted:c,state:i}=e,l=`${n.unit}${r===1?"":"s"}`,u=c?" Runs your own AI serves do not count toward it.":"";if(i==="trial"&&s!==null){let f=n.price===0?"it continues free":`it is $${n.price.toLocaleString()} a ${n.interval}`;return`${s} ${s===1?"day":"days"} left of your trial, then ${f}.`}if(i==="unlimited")return`${r.toLocaleString()} ${l} this period. No ceiling on this plan.`;if(i==="metered"){let f=r-(o??0);return n.overage_per_unit>0?`${f.toLocaleString()} past the allowance, billed at $${n.overage_per_unit} a ${n.unit}.${u}`:`${f.toLocaleString()} past the allowance.${u}`}if(i==="spent")return t?.period_end?`Allowance spent. It comes back on ${Wo(t.period_end)}.${u}`:`Allowance spent. It comes back at the start of the next period.${u}`;let p=Math.max(0,(o??0)-r),y=a?` Raised from ${(n.included_units??0).toLocaleString()} while your own AI is connected.`:t?.period_end?` Resets ${Wo(t.period_end)}.`:"";return`${p.toLocaleString()} of ${(o??0).toLocaleString()} ${n.unit}s left.${y}${u}`}function ni(e){if(!e)return null;let n=new Date(e).getTime()-Date.now();return Number.isNaN(n)||n<=0?null:Math.max(1,Math.ceil(n/864e5))}function Wo(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}import{Fragment as ri,jsx as J,jsxs as Se}from"react/jsx-runtime";function Br({heading:e="Current plan",showUsage:n=!0,showName:t=!0,className:r}){let o=at(),{theme:s}=H(),a=y=>J("section",{className:r?`soba-connect sc-fill ${r}`:"soba-connect sc-fill","data-theme":s,children:Se("div",{className:"sc-card sc-current",children:[e&&J("h2",{className:"sc-section-title",children:e}),y]})});if(o.error)return a(J("p",{className:"sc-error",children:o.error.message}));if(o.loading)return a(J("p",{className:"sc-note",children:"Loading\u2026"}));if(!o.plan)return a(Se("div",{className:"sc-current-main",children:[J("p",{className:"sc-current-name",children:"No plan"}),J("p",{className:"sc-sub",children:o.summary})]}));let{plan:c,trialDaysLeft:i,percent:l,unlimited:u,reward:p}=o;return a(Se(ri,{children:[Se("div",{className:"sc-current-grid",children:[(t||i!==null)&&Se("div",{className:"sc-current-main",children:[t?Se("p",{className:"sc-current-name",children:[c.name,i!==null&&Se("span",{className:"sc-trial-badge",children:[i," ",i===1?"day":"days"," left"]})]}):i!==null&&J("p",{className:"sc-current-trial",children:Se("span",{className:"sc-trial-badge",children:[i," ",i===1?"day":"days"," left"]})}),t&&c.description&&J("p",{className:"sc-sub",children:c.description})]}),n&&Se("div",{className:"sc-usage",children:[Se("div",{className:"sc-row-between",children:[J("span",{className:"sc-fact-key",children:"Usage"}),J("span",{className:l!==null&&l>=100?"sc-usage-figure sc-usage-over":"sc-usage-figure",children:u?"Unlimited":l===null?"Metered":`${l}% used`})]}),l!==null&&J("div",{className:"sc-meter",role:"presentation",children:l>0&&J("span",{className:l>=100?"sc-meter-fill sc-meter-full":"sc-meter-fill",style:{width:`${l}%`}})}),J("p",{className:"sc-usage-line",children:o.summary})]})]}),p&&Se("div",{className:"sc-current-foot",children:[J("p",{className:p.required?"sc-plan-reward-line sc-plan-reward-need":p.inForce?"sc-plan-reward-line":"sc-plan-reward-line sc-plan-reward-open",children:p.required?p.line:p.inForce?`In force: ${ti(p.line)}.`:p.line}),(p.actionable||p.connected)&&J(fn,{})]})]}))}var ti=e=>e.charAt(0).toLowerCase()+e.slice(1);import{useCallback as oi,useMemo as si,useState as Bo}from"react";var ai={"user-hardware":"your own machine","user-subscription":"your own AI subscription","open-weights":"open models we host",frontier:"frontier models"},ii=new Set(["user-hardware","user-subscription"]);function qr(e={}){let{plan:n,compute:t,connect:r}=D(),[o,s]=Bo(null),[a,c]=Bo(null),{featured:i,onSelect:l,successUrl:u,cancelUrl:p}=e,y=oi(async m=>{s(m.id),c(null);try{if(m.selectable)await n.select(m.id);else if(l)l(m);else{let w=await n.checkout(m.id,{...u?{successUrl:u}:{},...p?{cancelUrl:p}:{}});window.location.assign(w);return}}catch(w){throw c(w.message),w}finally{(m.selectable||l)&&s(null)}},[n,l,u,p]),f=si(()=>n.plans.map(m=>{let w=n.current?.plan_id===m.id;return{plan:m,current:w,featured:i===m.id&&!w,price:li(m),allowance:m.included_units===null?`Unlimited ${m.unit}s`:`${m.included_units.toLocaleString()} ${m.unit}${m.included_units===1?"":"s"}`,allowanceNote:ci(m),computeLabel:m.route_allow===null?"any compute":m.route_allow.length===0?"no compute":null,compute:(m.route_allow??[]).map(P=>({costClass:P,label:ai[P]??P,owned:ii.has(P),runtimes:qt(P).map(R=>R.id)})),connect:ui(m,w,t.connected,()=>r.open("manual")),cta:{label:di(m,w,o===m.id),disabled:w||o!==null,busy:o===m.id,take:()=>y(m)}}}),[n.plans,n.current,i,t.connected,r,o,y]);return{offers:f,current:f.find(m=>m.current)??null,loading:n.loading,error:n.error,failed:a}}function li(e){return e.price===0?{amount:"Free",interval:null,free:!0}:{amount:`$${e.price.toLocaleString()}`,interval:e.interval,free:!1}}function ci(e){let n=[];return e.included_units===null?n.push("No ceiling on this plan"):(n.push(`Included each ${e.interval}`),e.overage==="meter"&&e.overage_per_unit>0?n.push(`then $${e.overage_per_unit} a ${e.unit}`):e.included_units>0&&n.push(`then ${e.unit}s stop`)),e.trial_days>0&&n.push(`${e.trial_days}-day trial`),n.join(" \xB7 ")}function ui(e,n,t,r){let o=He({unit:e.unit,reward:e.connected_reward,includedUnits:e.connected_included_units,creditMicros:e.connected_credit*1e6}),s=xe(e.route_allow)&&!t;if(!o&&!s)return null;let a=Ue(e.connected_reward);return{key:o?"Connect your own":"To use this",line:o??(n?"Nothing connected yet, so nothing can run.":"Runs only on compute you connect."),reward:o!==null,actionable:n&&(a||s)&&!t,open:r}}function di(e,n,t){return n?"Your plan":t?e.selectable?"Switching\u2026":"Opening\u2026":e.selectable?"Choose":`Subscribe for $${e.price.toLocaleString()}/${e.interval}`}import{jsx as g,jsxs as A}from"react/jsx-runtime";function Et(e){return e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill"}function Fr({onSelect:e,successUrl:n,cancelUrl:t,showCompute:r=!0,showConnect:o=!1,variant:s="cards",featured:a,className:c}){let{offers:i,loading:l,error:u,failed:p}=qr({...a?{featured:a}:{},...e?{onSelect:e}:{},...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}}),{theme:y}=H();if(u)return g("div",{className:Et(c),"data-theme":y,children:g("div",{className:"sc-card",children:g("p",{className:"sc-error",children:u.message})})});if(l)return g("div",{className:Et(c),"data-theme":y,children:g("div",{className:"sc-card",children:g("p",{className:"sc-note",children:"Loading plans\u2026"})})});if(i.length===0)return g("div",{className:Et(c),"data-theme":y,children:g("div",{className:"sc-card",children:g("p",{className:"sc-note",children:"This app has no plans yet."})})});let f={showCompute:r,showConnect:o};return A("div",{className:Et(c),"data-theme":y,"data-variant":s,children:[s==="rows"?g(mi,{offers:i,shelf:f}):s==="table"?g(fi,{offers:i,shelf:f}):g(pi,{offers:i,shelf:f}),p&&g("p",{className:"sc-error",children:p})]})}function pi({offers:e,shelf:n}){return g("div",{className:"sc-plans",children:e.map(t=>A("div",{className:qo("sc-plan",t),children:[A("div",{className:"sc-row-between",children:[g("span",{className:"sc-title",children:t.plan.name}),g(Gr,{offer:t})]}),g("p",{className:"sc-sub",children:t.plan.description}),g(zr,{price:t.price,free:"forever"}),g(jr,{offer:t,shelf:n}),g(Fo,{offer:t}),g("div",{className:"sc-plan-band",children:n.showCompute&&g(Vr,{offer:t})}),g("div",{className:"sc-plan-band",children:g(Kr,{offer:t})})]},t.plan.id))})}function mi({offers:e,shelf:n}){return g("ul",{className:"sc-plan-rows",children:e.map(t=>A("li",{className:qo("sc-plan-row",t),children:[A("div",{className:"sc-row-main",children:[A("span",{className:"sc-row-name",children:[g("span",{className:"sc-title",children:t.plan.name}),g(Gr,{offer:t})]}),t.plan.description&&g("p",{className:"sc-sub",children:t.plan.description}),g(Fo,{offer:t}),n.showCompute&&g(Vr,{offer:t,inline:!0}),g(Kr,{offer:t,inline:!0})]}),A("div",{className:"sc-row-side",children:[g(zr,{price:t.price,free:"forever",small:!0}),g(jr,{offer:t,shelf:n})]})]},t.plan.id))})}function fi({offers:e,shelf:n}){let t=e.some(a=>a.plan.overage_per_unit>0),r=e.some(a=>a.plan.trial_days>0),o=e.some(a=>a.connect!==null),s=a=>[a.current?"sc-col-current":"",a.featured?"sc-col-featured":""].filter(Boolean).join(" ")||void 0;return g("div",{className:"sc-table-scroll",children:A("table",{className:"sc-plan-table",children:[g("thead",{children:A("tr",{children:[g("td",{}),e.map(a=>A("th",{scope:"col",className:s(a),children:[A("span",{className:"sc-row-name",children:[g("span",{className:"sc-title",children:a.plan.name}),g(Gr,{offer:a})]}),g(zr,{price:a.price,small:!0})]},a.plan.id))]})}),A("tbody",{children:[A("tr",{children:[g("th",{scope:"row",children:"Included"}),e.map(a=>g("td",{className:s(a),children:a.allowance},a.plan.id))]}),t&&A("tr",{children:[g("th",{scope:"row",children:"Then"}),e.map(a=>g("td",{className:s(a),children:a.plan.overage_per_unit>0?`$${a.plan.overage_per_unit} / ${a.plan.unit}`:g("span",{className:"sc-muted-cell",children:"Stops"})},a.plan.id))]}),r&&A("tr",{children:[g("th",{scope:"row",children:"Trial"}),e.map(a=>g("td",{className:s(a),children:a.plan.trial_days>0?`${a.plan.trial_days} days`:g("span",{className:"sc-muted-cell",children:"None"})},a.plan.id))]}),n.showCompute&&A("tr",{children:[g("th",{scope:"row",children:"Runs on"}),e.map(a=>g("td",{className:s(a),children:g(Vr,{offer:a,bare:!0})},a.plan.id))]}),o&&A("tr",{children:[g("th",{scope:"row",children:"Connect your own"}),e.map(a=>g("td",{className:s(a),children:g(Kr,{offer:a,bare:!0})},a.plan.id))]}),A("tr",{className:"sc-table-buy",children:[g("td",{}),e.map(a=>g("td",{className:s(a),children:g(jr,{offer:a,shelf:n})},a.plan.id))]})]})]})})}function qo(e,n){return[e,n.current?"sc-plan-current":"",n.featured?"sc-plan-featured":""].filter(Boolean).join(" ")}function Gr({offer:e}){return e.current?g("span",{className:"sc-plan-badge",children:"Current"}):e.featured?g("span",{className:"sc-plan-badge-soft",children:"Recommended"}):null}function zr({price:e,small:n,free:t}){return A("p",{className:n?"sc-plan-price sc-plan-price-sm":"sc-plan-price",children:[g("span",{className:"sc-plan-amount",children:e.amount}),e.interval?A("span",{className:"sc-plan-interval",children:["/",e.interval]}):t&&g("span",{className:"sc-plan-interval sc-plan-after",children:t})]})}function Fo({offer:e}){return A("p",{className:"sc-plan-allowance",children:[g("span",{className:"sc-plan-figure",children:e.allowance}),g("span",{className:"sc-plan-qualifier",children:e.allowanceNote})]})}function Kr({offer:e,inline:n,bare:t}){let r=e.connect;if(!r)return t?g("span",{className:"sc-muted-cell",children:"None"}):null;let o=r.reward?"sc-plan-reward-line":"sc-plan-reward-line sc-plan-reward-need",s=r.actionable?A("button",{type:"button",className:`${o} sc-plan-reward-act`,"aria-label":"Connect compute",onClick:r.open,children:[g("span",{className:"sc-reward-said",children:r.line}),A("span",{className:"sc-reward-do","aria-hidden":!0,children:[g(j,{className:"sc-reward-mark"}),"Connect compute"]})]}):g("p",{className:o,children:r.line});return t?s:g("div",{className:n?"sc-plan-reward sc-plan-reward-inline":"sc-plan-reward",children:s})}function Vr({offer:e,inline:n,bare:t}){let r=e.computeLabel?g("ul",{className:n?"sc-compute sc-compute-inline":"sc-compute",children:g("li",{children:e.computeLabel})}):g("ul",{className:n?"sc-compute sc-compute-inline":"sc-compute",children:e.compute.map(o=>A("li",{className:o.owned?"sc-compute-own":void 0,children:[o.label,g(hi,{runtimes:o.runtimes})]},o.costClass))});return t?r:A("div",{className:n?"sc-plan-compute sc-plan-compute-inline":"sc-plan-compute",children:[g("span",{className:"sc-fact-key",children:"Runs on"}),r]})}function jr({offer:e,shelf:n}){let t=e.connect;return n.showConnect&&t?.actionable?A("button",{type:"button",className:"sc-btn sc-btn-primary sc-btn-icon",onClick:t.open,children:[g(j,{className:"sc-btn-mark"}),"Connect compute"]}):g("button",{type:"button",className:e.current?"sc-btn":"sc-btn sc-btn-primary",disabled:e.cta.disabled,onClick:()=>void e.cta.take().catch(()=>{}),children:e.cta.label})}function hi({runtimes:e}){return e.length===0?null:g("span",{className:"sc-compute-marks",children:e.map(n=>{let t=ze[n];return t?g(t,{className:"sc-rt-mark"},n):null})})}import{jsx as Yr,jsxs as Go}from"react/jsx-runtime";function gi({heading:e,plansHeading:n,showUsage:t=!0,showName:r=!0,className:o,...s}){let{plan:a,loading:c}=at(),{theme:i}=H(),l=n??(c?"Plans":a?"Change plan":"Choose a plan");return Go("div",{className:o?`soba-connect sc-fill sc-billing ${o}`:"soba-connect sc-fill sc-billing","data-theme":i,children:[Yr(Br,{...e===void 0?{}:{heading:e},showUsage:t,showName:r}),Go("section",{className:"sc-billing-plans",children:[l&&Yr("h2",{className:"sc-section-title",children:l}),Yr(Fr,{...s})]})]})}import{useCallback as zo,useState as Ko}from"react";function Zr({plan:e,successUrl:n,cancelUrl:t,label:r}){let{plan:o}=D(),[s,a]=Ko(!1),[c,i]=Ko(null),l=zo(()=>o.checkout(e.id,{...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}}),[o,e.id,n,t]),u=zo(async()=>{a(!0),i(null);try{window.location.assign(await l())}catch(p){i(p.message),a(!1)}},[l]);return{label:s?"Opening\u2026":r??`Subscribe for $${e.price.toLocaleString()}/${e.interval}`,busy:s,error:c,buy:u,session:l}}import{jsx as Vo,jsxs as yi}from"react/jsx-runtime";function bi({plan:e,successUrl:n,cancelUrl:t,label:r,className:o}){let{theme:s}=H(),a=Zr({plan:e,...n?{successUrl:n}:{},...t?{cancelUrl:t}:{},...r?{label:r}:{}});return yi("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":s,children:[Vo("button",{type:"button",className:"sc-btn sc-btn-primary",disabled:a.busy,onClick:()=>void a.buy(),children:a.label}),a.error&&Vo("p",{className:"sc-error",children:a.error})]})}import{useCallback as Te,useEffect as Je,useMemo as En,useRef as Qe,useState as Q}from"react";var wi="soba.session:";function jo(e){return!e.cacheKey||!e.endpoint?null:wi+JSON.stringify([e.endpoint,e.user??null,e.cacheKey])}function vi(e){try{let n=globalThis.localStorage?.getItem(e);if(!n)return null;let t=JSON.parse(n);return typeof t.token!="string"||typeof t.expiresAt!="number"?null:{token:t.token,expiresAt:t.expiresAt}}catch{return null}}function ki(e,n){try{n?globalThis.localStorage?.setItem(e,JSON.stringify(n)):globalThis.localStorage?.removeItem(e)}catch{}}var Yo=6e4,Ci=1e4,Ot=class{#e;#n=null;#r=null;#t;#o=new Set;constructor(n){this.#t=n,this.#e=n.token??null;let t=jo(n),r=t&&!this.#e?vi(t):null;r&&r.expiresAt-Yo>Date.now()&&(this.#e=r.token,this.#n=r.expiresAt)}get token(){return this.#e}get expiresAt(){return this.#n}get canRefresh(){return!!this.#t.endpoint}get refreshAt(){return!this.canRefresh||this.#n===null?null:Math.max(Date.now()+Ci,this.#n-Yo)}subscribe(n){return this.#o.add(n),()=>this.#o.delete(n)}async ensure(){return this.#e?this.#e:this.refresh()}async refresh(){if(this.#r)return this.#r;let n=this.#t.endpoint;if(!n)throw new Error("This Soba session cannot be refreshed. Pass `sessionEndpoint` so the provider can mint a new one.");let t=this.#t.fetchImpl??fetch.bind(globalThis);this.#r=(async()=>{let r=await t(n,{method:"POST",headers:{"content-type":"application/json"},credentials:"same-origin",body:JSON.stringify(this.#t.user?{user:this.#t.user}:{})});if(!r.ok)throw new Error(`Could not start a Soba session (${r.status} from ${n}).`);let o=await r.json(),s=o.session??o.token;if(!s)throw new Error(`${n} answered without a \`session\`. See @soba-so/react's README.`);let a=o.expires_in??o.expiresIn;this.#e=s,this.#n=typeof a=="number"?Date.now()+a*1e3:null;let c=jo(this.#t);c&&ki(c,this.#n===null?null:{token:s,expiresAt:this.#n});for(let i of this.#o)i();return s})();try{return await this.#r}finally{this.#r=null}}},_n=new Map,Zo=new WeakMap,Ni=1;function xi(e){if(e.token||!e.endpoint)return null;let n=0;return e.fetchImpl&&(n=Zo.get(e.fetchImpl)??Ni++,Zo.set(e.fetchImpl,n)),JSON.stringify([e.endpoint,e.user??null,n,e.cacheKey??null])}function Jo(e){let n=xi(e);if(!n)return new Ot(e);let t=_n.get(n)??{holder:new Ot(e),users:0};return _n.set(n,t),t.holder}function Qo(e){for(let n of _n.values())n.holder===e&&n.users++}function Xo(e){for(let[n,t]of _n)if(t.holder===e){setTimeout(()=>{--t.users<=0&&_n.get(n)===t&&_n.delete(n)},0);return}}function es(e,n=fetch.bind(globalThis)){return async(t,r)=>{let o=await n(t,r);if(o.status!==401||!e.canRefresh)return o;let s;try{s=await e.refresh()}catch{return o}return n(t,Si(r,s))}}function Si(e,n){let t=new Headers(e?.headers);return t.set("authorization",`Bearer ${n}`),{...e,headers:t}}import{jsx as Jr,jsxs as _i}from"react/jsx-runtime";var Mi="https://www.soba.so",Pi=3e4;function Ri(e){let{children:n,session:t,sessionEndpoint:r,user:o,sessionCacheKey:s,runEndpoint:a,theme:c,initialMachines:i,initialConnect:l=null,initialPlans:u,initialCurrentPlan:p=null,baseUrl:y=Mi,pollMs:f=Pi,injectStyles:m=!0,modal:w=!0,fetchImpl:P,onError:R}=e,[_,M]=Q(t??null),[B,I]=Q(null),[N,F]=Q(l),[T,se]=Q(null),[X,ve]=Q(l===null),[K,ae]=Q(i??[]),[We,Y]=Q(null),[Me,Xe]=Q(i===void 0),[de,pe]=Q(u??[]),[ee,gn]=Q(p),[en,Le]=Q(null),[nn,me]=Q(u===void 0),[ne,Be]=Q(null),[Pe,Ae]=Q(!1),qe=Qe(R);qe.current=R;let ie=Te(k=>{I(k),qe.current?.(k)},[]);Je(()=>{m&&ot()},[m]);let E=En(()=>Jo({...t?{token:t}:{},...r?{endpoint:r}:{},...o?{user:o}:{},...P?{fetchImpl:P}:{},...s?{cacheKey:s}:{}}),[t,r,o,P,s]);Je(()=>{let k=!0;Qo(E);let z=E.subscribe(()=>{k&&M(E.token)});return!E.token&&!E.canRefresh?ie(new Error("<SobaProvider> needs a `session` or a `sessionEndpoint`. A browser cannot mint one: that takes your secret key.")):E.ensure().then(()=>k&&M(E.token),le=>k&&ie(le)),()=>{k=!1,z(),Xo(E)}},[E,ie]),Je(()=>{B&&(ve(!1),Xe(!1),me(!1),se(k=>k??B),Y(k=>k??B),Le(k=>k??B))},[B]),Je(()=>{let k=E.refreshAt;if(k===null)return;let z=()=>{E.refresh().catch(ge=>ie(ge))},le=()=>{document.hidden||(document.removeEventListener("visibilitychange",le),z())},dt=setTimeout(()=>{typeof document<"u"&&document.hidden?document.addEventListener("visibilitychange",le):z()},Math.max(0,k-Date.now()));return()=>{clearTimeout(dt),typeof document<"u"&&document.removeEventListener("visibilitychange",le)}},[E,ie,_]);let bn=Qe(l?.machines_url??null),v=En(()=>{if(!_)return null;let k=new Tn({session:_,baseUrl:y,fetchImpl:es(E,P??fetch.bind(globalThis))});return k.setMachinesUrl(bn.current),k},[_,y,E,P]),G=Qe(l!==null);Je(()=>{if(!v||G.current)return;let k=!0;return ve(!0),v.context().then(z=>{k&&(F(z),se(null),ve(!1))},z=>{k&&(se(z),ve(!1))}),()=>{k=!1}},[v]);let te=Te(async()=>{if(v)try{let k=await v.machines();ae(Array.isArray(k)?k:[]),Y(null)}catch(k){Y(k)}finally{Xe(!1)}},[v]),fe=Te(async()=>{if(v)try{let k=await v.plans();pe(k.plans),gn(k.current),Le(null)}catch(k){Le(k)}finally{me(!1)}},[v]),re=Qe(!1),[Fe,yn]=Q(!1),wn=Qe(u!==void 0),tn=Qe(!1),rn=Te(()=>{re.current||(re.current=!0,tn.current&&queueMicrotask(()=>{tn.current&&yn(!0)}))},[]);Je(()=>(tn.current=!0,re.current&&yn(!0),()=>{tn.current=!1}),[]),Je(()=>{!v||!Fe||wn.current||fe()},[v,Fe,fe]);let on=Te(async k=>{if(!v)throw new Error("No session yet.");await v.selectPlan(k),await fe()},[v,fe]),It=Te(async(k,z)=>{if(!v)throw new Error("No session yet.");let le=await v.checkoutPlan(k,z);if(!le.url)throw new Error("Checkout could not be started.");return le.url},[v]),it=Te(async()=>{if(!v)throw new Error("No session yet.");await v.leavePlan(),await fe()},[v,fe]),lt=Qe(i!==void 0);Je(()=>{if(!v)return;let k=Oe(te,f,{immediate:!lt.current});return lt.current=!1,k},[v,te,f]);let vn=Te((k="manual")=>{w&&(Ae(!0),Be(k))},[w]),ct=Te(()=>Be(null),[]),q=Qe(K);q.current=K;let Re=Te(async k=>{if(!a)throw new Error("Pass `runEndpoint` to <SobaProvider> to start runs from the browser. It is your own route: it holds your secret key, calls soba.run(), and forwards the stream.");let{signal:z,...le}=k,ge=await(P??fetch.bind(globalThis))(a,{method:"POST",headers:{"content-type":"application/json",accept:"text/event-stream"},credentials:"same-origin",body:JSON.stringify(le),...z?{signal:z}:{}});if(!ge.ok){let $e=await ge.json().catch(()=>null),be=new Error($e?.error?.message??`${a} answered ${ge.status}.`);be.status=ge.status,$e?.error?.code&&(be.code=$e.error.code),$e?.error&&(be.error=$e.error);let pt=q.current.length>0&&!q.current.some(Lt=>Lt.state!=="offline");throw ge.status===409&&pt&&vn("no_compute"),be}let ke=Dr(ge);return async function*(){try{yield*ke}finally{re.current&&fe()}}()},[a,P,fe,vn]),he=En(()=>ee?de.find(k=>k.id===ee.plan_id)??null:null,[de,ee]),sn=En(()=>he?he.connected_reward==="included"&&K.length>0&&he.connected_included_units!==null?he.connected_included_units:he.included_units:null,[he,K]),ut=En(()=>({plans:de,current:ee,plan:he,used:ee?.units_used??null,included:sn,remaining:sn!==null&&ee?Math.max(0,sn-ee.units_used):null,unlimited:he!==null&&sn===null,loading:nn,error:en,select:on,checkout:It,leave:it,refresh:fe}),[de,ee,he,sn,nn,en,on,It,it,fe]),Tt=En(()=>({session:_,client:v,error:B,get plan(){return rn(),ut},compute:{machines:K,connected:K.length>0,online:K.some(k=>k.state!=="offline"),loading:Me,error:We,refresh:te},connect:{app:N?.app??null,command:N?.command??null,connectUrl:N?.connect_url??null,publishableKey:N?.publishable_key??null,loading:X,error:T,open:vn,close:ct,isOpen:ne!==null,hasModal:w},run:Re}),[_,v,B,ut,rn,ne,vn,ct,w,K,Me,We,te,N,X,T,Re]);return Jr(Pr.Provider,{value:v,children:Jr(Rr.Provider,{value:{context:N,machines:Me?void 0:K,theme:c??N?.theme??"light"},children:_i(_r.Provider,{value:Tt,children:[n,w&&Pe&&Jr(et,{open:ne!==null,onOpenChange:k=>Be(k?ne??"manual":null),onConnected:()=>{te()},...ne==="payment_required"||ne==="no_compute"?{reason:ne}:{},...ne==="pair"?{showStatus:!1}:{}})]})})})}function Ei(e){return e?Oi[e]??e:null}var Oi={"user-hardware":"your own computer","user-subscription":"your own AI plan","user-api-key":"your own API key","open-weights":"open models we host",frontier:"a frontier model we pay for"};async function Ii(e,n,t){let r=n.local;if(!r?.session||n.after)return null;let o=/\/v1\/runs\/([^/]+)\/events/.exec(e.url)?.[1];if(!o)return null;let s=`http://127.0.0.1:${r.port??47321}/v1/runs/${o}/events`,a=new AbortController,c=()=>a.abort();n.signal?.addEventListener("abort",c);let i=setTimeout(()=>a.abort(),r.timeoutMs??3e3);try{let l=await t(s,{headers:{authorization:`Bearer ${r.session}`,accept:"text/event-stream"},signal:a.signal});return l.ok?{url:s,bearer:r.session,open:l}:null}catch{return null}finally{clearTimeout(i),n.signal?.removeEventListener("abort",c)}}async function*Ti(e){let n=e.body;if(!n)return;let t=n.getReader(),r=new TextDecoder,o="",s=null,a=[];try{for(;;){let c=await t.read();if(c.done)return;o+=r.decode(c.value,{stream:!0});for(let i=o.indexOf(`
|
|
3011
|
+
`);i!==-1;i=o.indexOf(`
|
|
3012
|
+
`)){let l=o.slice(0,i).replace(/\r$/,"");if(o=o.slice(i+1),l==="")a.length&&(yield{id:s,data:a.join(`
|
|
3013
|
+
`)}),s=null,a=[];else if(l.startsWith("id:")){let u=Number(l.slice(3).trim());s=Number.isFinite(u)?u:null}else if(l.startsWith("data:")){let u=l.slice(5);a.push(u.startsWith(" ")?u.slice(1):u)}}}}finally{t.cancel().catch(()=>{})}}var Qr=(e,n)=>new Promise(t=>{let r=setTimeout(t,e);n?.addEventListener("abort",()=>{clearTimeout(r),t()})});async function*Li(e,n={}){let t=n.fetchImpl??fetch.bind(globalThis),r=await Ii(e,n,t)??{url:e.url,bearer:e.token,open:null},o=n.maxRetries??6,s=n.after??0,a=0;for(;;){if(n.signal?.aborted)return;let c;try{c=r.open??await t(r.url,{headers:{authorization:`Bearer ${r.bearer}`,accept:"text/event-stream",...s?{"last-event-id":String(s)}:{}},...n.signal?{signal:n.signal}:{}}),r.open=null}catch(i){if(n.signal?.aborted)return;if(++a>o)throw i;await Qr(1e3*a,n.signal);continue}if(c.status===503&&a<o){a++,await Qr(Number(c.headers.get("retry-after")??3)*1e3,n.signal);continue}if(!c.ok){let i=`Could not read this run (${c.status}).`;try{let l=await c.json();l.error?.message&&(i=l.error.message)}catch{}throw new Error(i)}for await(let i of Ti(c)){i.id!==null&&(s=i.id),a=0;let l=Rn(i.data);if(l&&(yield l,l.type==="done"||l.type==="error"))return}if(n.signal?.aborted)return;if(++a>o)throw new Error("Lost this run's stream and could not get it back.");await Qr(1e3*a,n.signal)}}export{ha as ComputeStatus,fn as ConnectButton,ka as ConnectCompute,et as ConnectModal,$a as ConnectNudge,Ga as ModelPicker,Va as RunError,Za as RunLimit,gi as SobaBilling,bi as SobaCheckout,Br as SobaCurrentPlan,Fr as SobaPlans,Ri as SobaProvider,Ba as collectText,Pt as connectSays,ot as injectStyles,Rn as parseEvent,Dr as readEvents,Ho as runErrorMessage,hn as sobaErrorCode,Ei as tierLabel,Zr as useCheckout,Qn as useCompute,ya as useConnectButton,$r as useConnectNudge,at as useCurrentPlan,Wr as useModel,rt as useOpenSobaConnect,qr as usePlans,Lr as useRunLimit,D as useSoba,Li as watchRun};
|