@soba-so/react 0.0.14 → 0.0.16
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/README.md +9 -2
- package/dist/SobaProvider.d.ts +5 -2
- package/dist/context.d.ts +10 -3
- package/dist/index.mjs +364 -447
- package/dist/session.d.ts +3 -0
- package/dist/styles.css +359 -442
- package/dist/types.d.ts +6 -0
- package/package.json +8 -9
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
var Ln=class extends Error{status;constructor(n,t){super(n),this.name="ConnectError",this.status=t}},sn=class{session;baseUrl;doFetch;constructor(n){this.session=n.session,this.baseUrl=(n.baseUrl??"").replace(/\/+$/,""),this.doFetch=n.fetchImpl??fetch.bind(globalThis)}context(){return this.request("GET","/v1/connect")}async machines(){return(await this.request("GET","/v1/machines")).machines}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(`${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 i=typeof a.error=="string"?a.error:`Request failed (${s.status})`;throw new Ln(i,s.status)}return a}};function on(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 i=Number.parseInt(t.slice(a*2,a*2+2),16)/255;return i<=.04045?i/12.92:((i+.055)/1.055)**2.4};return .2126*r(0)+.7152*r(1)+.0722*r(2)>.45?"#101012":"#ffffff"}function zn(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 Ye(e,n,t){let r=zn(e),s=zn(n);return!r||!s?e:`#${r.map((i,u)=>Math.round(i+(s[u]-i)*t)).map(i=>i.toString(16).padStart(2,"0")).join("")}`}function an(e,n){if(!zn(e))return{};let t=on(e),r=n?.trim();return{"--sc-ground":e,"--sc-shell":e,"--sc-sheet":Ye(e,t,.07),"--sc-raised":Ye(e,t,.13),"--sc-line":Ye(e,t,.18),"--sc-line-2":Ye(e,t,.28),"--sc-text":t,"--sc-text-2":Ye(t,e,.15),"--sc-muted":Ye(t,e,.38),...r?{"--sc-accent":r,"--sc-accent-fg":on(r)}:{"--sc-accent":t,"--sc-accent-fg":e}}}function Kn(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 jn(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 ln(e){return e.find(n=>n.state==="offline")??null}function cn(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"}}import{jsx as me,jsxs as Or}from"react/jsx-runtime";function V({className:e}){return Or("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:[me("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"}),me("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 Gt({className:e}){return me("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:me("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 me("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:me("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 Ze({className:e}){return me("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:me("path",{d:"M4 5h16v11H4zM9 20h6M12 16v4",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function $e({className:e}){return me("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:me("path",{d:"M5 6h14v10H5zM2.5 19.5h19",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}var he={claude:Gt,chatgpt:Qe,local:Ze};var te=[{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"]}],Vt=["claude","chatgpt"];function Yn(){return te.filter(e=>Vt.includes(e.id))}function Qn(e){return te.filter(n=>n.costClass===e)}function un(e){return te.find(n=>n.expects.includes(e))??null}import{jsx as W,jsxs as De}from"react/jsx-runtime";function Je({machines:e,onApproveRuntime:n}){return e.length?W("div",{children:e.map(t=>{let r=cn(t),s=jn(t);return De("div",{className:"sc-machine",children:[De("div",{className:"sc-idrow",children:[W("span",{className:"sc-opt-tile","aria-hidden":"true",children:W($e,{className:"sc-opt-mark"})}),De("span",{className:"sc-opt-text",children:[W("span",{className:"sc-opt-label",children:t.label??"This machine"}),(s||t.always_on)&&De("span",{className:"sc-machine-meta",children:[s&&W("span",{children:s}),t.always_on&&W("span",{className:"sc-machine-tag",children:"always on"})]})]}),De("span",{className:"sc-machine-state",children:[W("span",{className:`sc-dot sc-dot-${r.tone}`,"aria-hidden":"true"}),r.text]})]}),De("ul",{className:"sc-runtimes",children:[t.runtimes.map(a=>W(Tr,{runtime:a,...n?{onApprove:()=>n(t.id,a.id)}:{}},a.id)),!t.runtimes.length&&W("li",{className:"sc-note",children:"No runtime advertised. Install Claude Code, Codex or Ollama on that machine."})]})]},t.id)})}):W("p",{className:"sc-note",children:"Nothing connected yet."})}function Tr({runtime:e,onApprove:n}){let t=un(e.id),r=t?he[t.id]:null,s=Kn(e);return De("li",{className:"sc-runtime",children:[W("span",{className:"sc-runtime-tile","aria-hidden":"true",children:r&&W(r,{className:"sc-runtime-mark"})}),W("span",{className:"sc-runtime-name",children:e.display_name}),e.quarantined?n?W("button",{type:"button",className:"sc-conn-action",onClick:n,children:"Let it serve"}):W("span",{className:"sc-runtime-verdict sc-tone-warn",children:"new, not serving yet"}):W("span",{className:`sc-runtime-verdict sc-tone-${s.tone}`,children:s.text})]})}var Zn={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 Jn="105 162 420 420",Xn="M407.1 308.9 A158 158 0 1 0 407.1 491.1 A116 116 0 0 1 407.1 308.9 Z",Ue="M448.5 320 A110 110 0 0 1 448.5 480";import{Fragment as pn,jsx as C,jsxs as _e}from"react/jsx-runtime";function et({kind:e,size:n=44,className:t}){let r=Zn[e];return _e("svg",{className:`bx${t?` ${t}`:""}`,"data-expression":e,viewBox:Jn,overflow:"visible",width:n,height:n,"aria-hidden":"true",children:[C("path",{d:Xn,fill:"currentColor"}),C("path",{className:"bx-arc",d:Ue,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),r.slot==="stream"&&C(Ir,{}),r.slot==="zzz"&&C(Ar,{}),r.slot==="dots"&&C($r,{}),r.slot==="bang"&&C(Dr,{}),r.slot==="orbit"&&C(Ur,{}),r.slot==="cross"&&C(Hr,{}),r.slot==="snap"&&C(qr,{}),r.slot==="bars"&&C(Br,{}),r.slot==="ring"&&C(Fr,{}),r.slot==="sparks"&&C(Wr,{})]})}function Ir(){return C("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 Ar(){return _e(pn,{children:[C("g",{className:"bx-z1",children:C("path",{d:"M444 372 H496 L444 436 H496",fill:"none",stroke:"currentColor",strokeWidth:"20",strokeLinecap:"round",strokeLinejoin:"round"})}),C("g",{className:"bx-z2",children:C("path",{d:"M492 300 H522 L492 338 H522",fill:"none",stroke:"currentColor",strokeWidth:"15",strokeLinecap:"round",strokeLinejoin:"round"})})]})}function $r(){return _e(pn,{children:[C("circle",{className:"bx-th",cx:"463.1",cy:"336.9",r:"21",fill:"currentColor"}),C("circle",{className:"bx-th bx-th2",cx:"483",cy:"400",r:"21",fill:"currentColor"}),C("circle",{className:"bx-th bx-th3",cx:"463.1",cy:"463.1",r:"21",fill:"currentColor"})]})}function Dr(){return _e("g",{className:"bx-at",children:[C("line",{x1:"490",y1:"312",x2:"490",y2:"414",stroke:"currentColor",strokeWidth:"46",strokeLinecap:"round"}),C("circle",{cx:"490",cy:"484",r:"28",fill:"currentColor"})]})}function Ur(){return _e("g",{className:"bx-ob",children:[C("path",{d:Ue,fill:"none",stroke:"var(--tile-bg, transparent)",strokeWidth:41,strokeLinecap:"round"}),C("path",{d:Ue,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})]})}function Hr(){return _e(pn,{children:[C("path",{className:"bx-xa",d:Ue,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),C("g",{className:"bx-xx",children:C("path",{d:"M442 364 L514 436 M514 364 L442 436",fill:"none",stroke:"currentColor",strokeWidth:"24",strokeLinecap:"round"})})]})}function qr(){return C("path",{className:"bx-snap",d:Ue,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})}function Br(){return _e("g",{stroke:"currentColor",strokeWidth:"17",strokeLinecap:"round",children:[C("line",{className:"bx-vb",x1:"452",y1:"370",x2:"452",y2:"430"}),C("line",{className:"bx-vb bx-vb2",x1:"482",y1:"330",x2:"482",y2:"470"}),C("line",{className:"bx-vb bx-vb3",x1:"512",y1:"355",x2:"512",y2:"445"})]})}function Fr(){return C(pn,{children:[[450,366],[474,376],[484,400],[474,424],[450,434],[426,424],[416,400],[426,376]].map(([n,t],r)=>C("circle",{className:"bx-w",cx:n,cy:t,r:"11",fill:"currentColor",style:{animationDelay:`${-1.2+r*.15}s`}},r))})}function Wr(){return _e(pn,{children:[C("g",{className:"bx-sp",children:C("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"})}),C("g",{className:"bx-sp bx-sp2",children:C("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"})}),C("g",{className:"bx-sp bx-sp3",children:C("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 J,useEffect as re,useId as Kr,useMemo as Ee,useRef as Xe,useState as $}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 hn(e){if(!e)return"";try{return new URL(e).origin}catch{return""}}var nt="soba";function Kt(){return`${nt}://show`}function fn(e,n,t){let r=`${nt}://connect?url=${encodeURIComponent(e)}`;return n&&(r+=`&nonce=${encodeURIComponent(n)}`),t&&(r+=`&want=${encodeURIComponent(t)}`),r}function gn(){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 Gr=1600;function tt(e={}){return ot(e)}async function rt(e,n={}){if(typeof window>"u"||typeof document>"u")return"unknown";let t=ot(n);try{window.location.href=fn(e,n.nonce,n.want)}catch{return"absent"}return t}async function st(e={}){if(typeof window>"u"||typeof document>"u")return"unknown";let n=ot(e);try{window.location.href=Kt()}catch{return"absent"}return n}async function ot(e){if(typeof window>"u"||typeof document>"u")return"unknown";let n=e.graceMs??Gr,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(i=>setTimeout(i,n)),window.removeEventListener("blur",s),window.removeEventListener("pagehide",s),document.removeEventListener("visibilitychange",a),t?r?"opened":"absent":"unknown"}var jt="soba.connect.choice",Vr=180*24*60*60*1e3;function Qt(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 at(e,n){return e?n?`${jt}.${e}.${Qt(n)}`:`${jt}.${e}`:null}function it(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)>Vr)return null;let r=te.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 Yt="soba.connect.dismissed",zr=30*24*60*60*1e3;function ct(e,n){return e?n?`${Yt}.${e}.${Qt(n)}`:`${Yt}.${e}`:null}function ut(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)<zr}catch{return!1}}function dt(e){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({at:new Date().toISOString()}))}catch{}}import{Fragment as Tn,jsx as o,jsxs as v}from"react/jsx-runtime";var pt=2e3,jr=1e4,Yr=9e4,Qr=6e4;function mt(e,n,t,r=[],s){return e?"code":n&&(t.length>0||r.length>0)?"manage":s?"launch":"choose"}function Zr(e){let n=Math.max(0,Math.round(e/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function gt({client:e,initialCode:n,initialChoice:t,onConnected:r,showStatus:s=!0,initialContext:a=null,initialMachines:i,onClose:u,headingId:l,theme:p,reason:f}){let g=!!a&&i!==void 0,[m,b]=$(g?mt(n,s,i??[],[],t):"loading"),[h,k]=$(a),[N,x]=$(i??[]),[U,j]=$(n??""),[S,O]=$(null),[H,T]=$(null),[M,q]=$(!1),[G,ce]=$(0),[Me,_n]=$(()=>Date.now()),[Q,ke]=$(null),[En,xe]=$(!1),[be,X]=$(!1),[Bn,tn]=$("browser"),[We,Mn]=$(null),[ue,se]=$([]),[Ge,Fn]=$(0),[Re,Ve]=$(null),oe=Xe(null),[R,P]=$(t??null),[Le,ee]=$(null),rn=Ee(()=>{let c=h?.accent?.trim(),w=h?.background?.trim();if(!(!c&&!w))return w?{...an(w,c),background:w,borderRadius:"inherit"}:{"--sc-accent":c,"--sc-accent-fg":on(c)}},[h?.accent,h?.background]),Rn=Kr(),ae=l??Rn,Se=Xe(null);re(()=>{if(!e||g)return;let c=!0;return Promise.all([e.context(),e.machines()]).then(([w,L])=>{c&&(k(w),x(L),b(mt(n,s,L)))}).catch(w=>{c&&(T(w.message),b("choose"))}),()=>{c=!1}},[e,n,s,g]),re(()=>{m!=="loading"||!g||b(mt(n,s,i??[]))},[m,g,n,s,i]),re(()=>{i&&x(i)},[i]),re(()=>{a&&k(a)},[a]);let ze=Xe(!1),Ke=Xe(m);Ke.current=m;let ne=Xe(ue);ne.current=ue;let de=!!h?.hosted_available;re(()=>{if(!e||m!=="manage")return;let c=!0,w=setInterval(async()=>{try{let L=await e.machines();if(!c)return;x(L);let A=!de||ze.current;L.length===0&&ne.current.length===0&&A&&Ke.current==="manage"&&b("choose")}catch{}},jr);return()=>{c=!1,clearInterval(w)}},[m,e,de]);let je=at(h?.publishable_key??null);re(()=>{ee(it(je))},[je]),re(()=>{if(!e||!de)return;let c=!0;return e.hosted().then(w=>{c&&(se(w.credentials),!ze.current&&(ze.current=!0,w.credentials.length>0&&s&&Ke.current==="choose"&&b("manage")))}).catch(()=>{}),()=>{c=!1}},[e,de,s]),re(()=>{if(!e||m!=="hosted")return;let c=!0,w=async()=>{try{let Pe=await e.hosted();if(!c)return!1;if(se(Pe.credentials),Pe.credentials.length>0)return b("hosted_connected"),Ve(null),!0}catch{}return!1},L=async()=>{oe.current?.closed&&(oe.current=null,!await w()&&c&&b("choose"))},A=setInterval(()=>{w(),L()},pt),Ae=setInterval(L,400),we=Pe=>{let Wt=Pe.data;Wt?.source==="soba"&&Wt.type==="hosted_result"&&w()};return window.addEventListener("message",we),()=>{c=!1,clearInterval(A),clearInterval(Ae),window.removeEventListener("message",we),oe.current=null}},[e,m]);let y=J(()=>{if(!e)return;let c=window.open("","soba-connect-plan","width=520,height=760,noopener=no");oe.current=c,b("hosted"),Fn(Date.now()),Ve(null),T(null),e.startHosted().then(({url:w})=>{if(c&&!c.closed){c.location.href=w;return}Ve(w)}).catch(w=>{c?.close(),oe.current=null,T(w.message),b("choose")})},[e]),B=J(async c=>{if(e){q(!0);try{await e.disconnectHosted(c),se((await e.hosted()).credentials)}catch(w){T(w.message)}finally{q(!1)}}},[e]);re(()=>{if(!e||m!=="waiting")return;let c=!0,w=setInterval(async()=>{try{let L=await e.machines();if(!c)return;x(L);let A=Se.current;if(!A)return;let Ae=L.filter(Pe=>!A.has(Pe.id)),we=Ae.find(Pe=>Pe.state!=="offline")??Ae[0];we&&(Mn(we.id),R&<(je,R),b("connected"),r?.(L))}catch{}},pt);return()=>{c=!1,clearInterval(w)}},[m,e,r,R,je]);let pe=J(async()=>{if(e){T(null),q(!0);try{let c=await e.lookup(U);O(c),b("confirm")}catch(c){T(c.message)}finally{q(!1)}}},[e,U]),qt=J(async()=>{if(e){T(null),q(!0);try{try{Se.current=new Set((await e.machines()).map(c=>c.id))}catch{Se.current=new Set(N.map(c=>c.id))}await e.approve(U),b("waiting"),ce(Date.now())}catch(c){T(c.message)}finally{q(!1)}}},[e,U,N]),Oe=J(async()=>{if(e){q(!0);try{await e.deny(U),tn("browser"),b("denied")}catch(c){T(c.message)}finally{q(!1)}}},[e,U]),F=Ee(()=>h?.connect_url??null,[h]),[Z,Te]=$(()=>gn()),_r=Ee(()=>F?fn(F,Z??void 0,R??void 0):null,[F,Z,R]),Er=Ee(()=>hn(F),[F]),Mr=J(c=>{if(N.length===0)return null;let w=te.find(A=>A.id===c);if(!w)return null;let L=N.flatMap(A=>A.runtimes??[]).filter(A=>w.expects.includes(A.id));return L.length===0?{tone:"dim",text:"not installed"}:L.some(A=>A.authenticated===!0)?{tone:"ok",text:"ready"}:L.every(A=>A.authenticated===!1)?{tone:"warn",text:"needs signing in"}:{tone:"dim",text:"installed"}},[N]),Rr=J((c=null)=>{P(c),T(null),ke(null),xe(!1),X(!1),Wn.current=!1,Te(gn()),b("launch")},[]),Wn=Xe(!!t);re(()=>{m!=="launch"||!F||Wn.current||(Wn.current=!0,xe(!0),rt(F,{...Z?{nonce:Z}:{},...R?{want:R}:{}}).then(ke))},[m,F,Z,R]);let Bt=J(()=>{xe(!0),tt().then(ke)},[]),Lr=J(c=>{if(be){let w=gn();X(!1),Te(w),F&&(c.preventDefault(),window.location.href=fn(F,w??void 0,R??void 0))}Bt()},[be,Bt,F,R]),Gn=Ee(()=>{let c=h?.runtimes;return c?te.filter(w=>c.includes(w.id)):Yn()},[h?.runtimes]),ye=Ee(()=>{let c=te.find(w=>w.id===R);return c?{choice:c,Mark:he[c.id]??null}:null},[R]),Vn=Ee(()=>N.find(c=>c.id===We),[N,We]);re(()=>{let c=Z;if(!e||m!=="launch"||!c)return;let w=!1,L=Date.now()+15e4,A=setInterval(async()=>{if(Date.now()>L){clearInterval(A),X(!0);return}try{let Ae=await e.claim(c);if(w)return;if(Ae.declined){clearInterval(A),ke(null),tn("machine"),b("denied");return}if(!Ae.claimed)return;clearInterval(A);try{Se.current=new Set((await e.machines()).map(we=>we.id))}catch{Se.current=new Set(N.map(we=>we.id))}b("waiting"),ce(Date.now())}catch{}},pt);return()=>{w=!0,clearInterval(A)}},[e,m,N,Z]);let Ie=Ee(()=>{if(!S)return null;if(S.approved||S.denied)return"answered";let c=S.expires_at?Date.parse(S.expires_at):Number.NaN;return Number.isFinite(c)&&c<=Me?"expired":"live"},[S,Me]);re(()=>{if(!(m==="confirm"&&Ie==="live"||m==="waiting"||m==="hosted"))return;let w=setInterval(()=>_n(Date.now()),1e3);return()=>clearInterval(w)},[m,Ie]);let Ft=J(async(c,w)=>{if(e)try{await e.approveRuntime(c,w),x(await e.machines())}catch(L){T(L.message)}},[e]);return m==="loading"?o("div",{className:"soba-connect",...p?{"data-theme":p}:{},style:rn,children:o("div",{className:"sc-card",children:o("p",{className:"sc-note",children:"Loading\u2026"})})}):v("div",{className:"soba-connect",...p?{"data-theme":p}:{},style:rn,children:[u&&o("button",{type:"button",className:"sc-modal-close",onClick:u,"aria-label":"Close",children:"\xD7"}),m==="manage"&&v("div",{className:"sc-card",children:[o("h2",{className:"sc-title",children:"Your compute"}),v("p",{className:"sc-sub",children:[o(bn,{context:h})," ",N.length>0&&ue.length>0?"runs on your connected plan, and on these machines while they are awake.":ue.length>0?"runs on the plan you connected. Nothing here is charged to you.":"runs on these machines, while they are awake."]}),v("div",{className:"sc-conns",children:[ue.map(c=>v("div",{className:"sc-conn",children:[o("span",{className:"sc-opt-tile","aria-hidden":"true",children:o(Qe,{className:"sc-opt-mark"})}),v("div",{className:"sc-opt-text",children:[o("span",{className:"sc-opt-label",children:c.provider==="openai-chatgpt"?"ChatGPT plan":c.provider}),o("span",{className:"sc-opt-sub",children:c.account_label??"signed in"})]}),o("button",{type:"button",className:"sc-conn-action",onClick:()=>void B(c.provider),disabled:M,children:"Disconnect"}),v("p",{className:"sc-conn-note",children:[o(bn,{context:h})," stops using it. To withdraw the grant entirely, remove it in your OpenAI settings."]})]},c.provider)),o(Je,{machines:N,onApproveRuntime:Ft})]}),H&&o("p",{className:"sc-error",children:H}),o("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>b("choose"),children:N.length>0?"Connect another machine":"Connect compute"})]}),m==="choose"&&v("div",{className:"sc-card",children:[o(Xr,{context:h}),o("h2",{className:"sc-h",id:ae,children:f==="payment_required"?"Carry on with your own AI":f==="no_compute"?"This run needs a machine":"Connect your AI"}),o("p",{className:"sc-p",children:"Use compute you already have."}),F&&Gn.length>0&&v(Tn,{children:[o("div",{className:"sc-opts",children:Gn.map(c=>{let w=he[c.id];return v("button",{type:"button",className:"sc-opt",onClick:()=>Rr(c.id),children:[o("span",{className:"sc-opt-tile","aria-hidden":"true",children:w&&o(w,{className:"sc-opt-mark"})}),o("span",{className:"sc-opt-text",children:o("span",{className:"sc-opt-label",children:c.label})}),(()=>{let L=Mr(c.id);return L?o("span",{className:`sc-opt-has sc-opt-has-${L.tone}`,children:L.text}):Le===c.id?o("span",{className:"sc-opt-last",children:"last used"}):o(ht,{className:"sc-opt-go"})})()]},c.id)})}),v("p",{className:"sc-opt-note",children:["Your accounts stay there. ",Zt(h)," never sees them."]})]}),(!F||Gn.length===0)&&o("p",{className:"sc-error",style:{marginTop:16},children:"This app has no publishable key yet, so there is nothing to pair against."}),H&&o("p",{className:"sc-error",children:H}),F&&h?.show_code===!0&&o("div",{className:"sc-opt-alt",children:o("button",{type:"button",className:"sc-alt-link",onClick:()=>b("code"),children:"I have a code"})})]}),m==="launch"&&v("div",{className:"sc-card",children:[v("div",{className:"sc-head",children:[o(en,{onClick:()=>b("choose")}),o("p",{className:"sc-head-title",children:"Soba App"})]}),o(On,{mark:ye?.Mark??V,still:be||!En&&Q===null}),o("h2",{className:"sc-h",id:ae,children:be?"No answer from this machine":Q==="absent"?"Nothing opened":Q===null?"Opening Soba App\u2026":"Approve it on this machine"}),be?o("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."}):Q==="absent"?o("p",{className:"sc-p",children:"Nothing opened on this machine. Open it yourself below, or install it if it is not here yet."}):o("p",{className:"sc-p",children:Q===null?"Approve it there and this page does the rest.":"This page finishes on its own."}),ye&&v("p",{className:"sc-prereq",children:[ye.Mark&&o(ye.Mark,{className:"sc-rt-mark"}),"Needs ",ye.choice.prerequisite]}),v("div",{className:"sc-stack",style:{marginTop:18},children:[o("a",{className:Q==="absent"||be?"sc-btn sc-btn-primary":"sc-btn",href:_r??"#",onClick:Lr,children:be?"Try again":Q==="absent"?"Open Soba App":"Open it again"}),o("p",{className:"sc-note",children:Q===null?"Your browser will ask permission first.":"Your browser asks permission the first time."}),ye&&Q==="absent"&&o("p",{className:"sc-note",children:o(es,{text:ye.choice.hint})}),v("div",{className:"sc-foot-strip",children:[o("span",{children:"Not installed on this machine?"}),v("button",{type:"button",className:"sc-foot-go",onClick:()=>b("get"),children:["Get it",o(ht,{})]})]})]})]}),m==="get"&&v("div",{className:"sc-card",children:[v("div",{className:"sc-head",children:[o(en,{onClick:()=>b("launch")}),o("p",{className:"sc-head-title",children:"Get Soba App"})]}),o("div",{className:"sc-opts",children:mn.map(c=>v("a",{className:"sc-opt",href:`${Er}/download/${c.slug}`,target:"_blank",rel:"noreferrer noopener",children:[o("span",{className:"sc-opt-tile","aria-hidden":"true",children:o($e,{className:"sc-opt-mark"})}),o("span",{className:"sc-opt-text",children:o("span",{className:"sc-opt-label",children:c.label})}),o(ht,{className:"sc-opt-go"})]},c.slug))}),o("p",{className:"sc-opt-note",children:"Install it, then come back here and press the row you started with."})]}),m==="code"&&v("div",{className:"sc-card",children:[v("div",{className:"sc-head",children:[o(en,{onClick:()=>b("choose")}),o("p",{className:"sc-head-title",children:"Soba App"})]}),o("h2",{className:"sc-h",id:ae,children:"Enter the code from that machine"}),o("p",{className:"sc-p",children:"Eight characters, shown by the Soba app once you paste the link."}),v("form",{className:"sc-stack",style:{marginTop:16},onSubmit:c=>{c.preventDefault(),pe()},children:[o("input",{className:"sc-input",value:U,onChange:c=>j(c.target.value),placeholder:"ACDE-F234",autoComplete:"off",autoFocus:!0,"aria-label":"Pairing code"}),H&&o("p",{className:"sc-error",children:H}),o("button",{type:"submit",className:"sc-btn sc-btn-primary",disabled:M||U.length<8,children:M?"Checking\u2026":"Continue"})]})]}),m==="confirm"&&S&&v("div",{className:"sc-card",children:[v("div",{className:"sc-head",children:[o(en,{onClick:()=>b("code")}),o("p",{className:"sc-head-title",children:"Soba App"})]}),o("h2",{className:"sc-title",children:"Attach this machine to your account?"}),v("p",{className:"sc-sub",children:[o(bn,{context:h})," may send your runs to it once you approve. It can never see the account or the keys on it."]}),v("ul",{className:"sc-facts",children:[o(yn,{k:"Code",v:S.user_code}),o(yn,{k:"Machine",v:S.hostname??"not stated"}),o(yn,{k:"System",v:[S.platform,S.arch].filter(Boolean).join(" / ")||"not stated"}),o(yn,{k:"Asked by",v:S.client??"not stated"}),S.labels.length>0&&o(yn,{k:"Labels",v:S.labels.join(", ")})]}),o("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."}),Ie==="expired"&&o("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."}),Ie==="answered"&&o("p",{className:"sc-error",children:"That code has already been answered. If it was not you, deny the next one."}),H&&o("p",{className:"sc-error",children:H}),v("div",{className:"sc-row",style:{marginTop:16},children:[o("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:()=>void qt(),disabled:M||Ie!=="live",children:"Approve"}),o("button",{type:"button",className:"sc-btn",onClick:()=>void Oe(),disabled:M||Ie==="answered",children:"No, deny it"})]}),Ie==="live"&&S.expires_at&&v("p",{className:"sc-note",style:{marginTop:10},children:["This code expires in ",Zr(Date.parse(S.expires_at)-Me),"."]})]}),m==="waiting"&&v("div",{className:"sc-card",children:[v("div",{className:"sc-head",children:[o(en,{onClick:()=>b("choose")}),o("p",{className:"sc-head-title",children:ye?.choice.short??"Soba App"})]}),o(On,{mark:ye?.Mark??V}),o("h2",{className:"sc-h",id:ae,children:"Approved. Waiting for it to connect"}),o("p",{className:"sc-p",children:"Nothing more to do here. This page changes when it arrives."}),G>0&&Me-G>Yr&&o("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."})]}),m==="connected"&&v("div",{className:"sc-card",children:[o(ft,{tone:"ok"}),o("h2",{className:"sc-h",id:ae,children:Vn?.label?`${Vn.label} is connected`:"Connected"}),v("p",{className:"sc-p",children:[o(bn,{context:h})," will use ",Vn?.label?"it":"this machine"," from now on, while it is awake."]}),s&&v(Tn,{children:[o("div",{style:{marginTop:16},children:o(Je,{machines:N,onApproveRuntime:Ft})}),o("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:14},onClick:()=>b("manage"),children:"Done"})]})]}),m==="hosted"&&v("div",{className:"sc-card",children:[v("div",{className:"sc-head",children:[o(en,{onClick:()=>b("choose")}),o("p",{className:"sc-head-title",children:"ChatGPT"})]}),Re?o(On,{mark:Qe,still:!0}):o(On,{mark:Qe}),o("h2",{className:"sc-h",id:ae,children:Re?"Your browser blocked the window":"Finish signing in to ChatGPT"}),o("p",{className:"sc-p",children:Re?"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."}),v("div",{className:"sc-stack",style:{marginTop:18},children:[Re&&o("a",{className:"sc-btn sc-btn-primary",href:Re,target:"soba-connect-plan",rel:"noreferrer",children:"Open the ChatGPT sign-in"}),H&&o("p",{className:"sc-error",children:H}),Ge>0&&Me-Ge>Qr&&o("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."})]})]}),m==="hosted_connected"&&v("div",{className:"sc-card",children:[o(ft,{tone:"ok"}),o("h2",{className:"sc-h",id:ae,children:"ChatGPT is connected"}),v("p",{className:"sc-p",children:[o(bn,{context:h})," will run on your ChatGPT plan",ue[0]?.account_label?` (${ue[0].account_label})`:"",". Nothing more to pay, nothing to install."]}),o("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&&v(Tn,{children:[o("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>b("manage"),children:"Done"}),o("div",{className:"sc-opt-alt",children:o("button",{type:"button",className:"sc-alt-link",onClick:()=>b("choose"),children:"Connect a machine too"})})]})]}),m==="denied"&&v("div",{className:"sc-card",children:[o(ft,{tone:"off"}),o("h2",{className:"sc-h",id:ae,children:"Declined"}),o("p",{className:"sc-p",children:Bn==="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."}),o("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>b("choose"),children:"Back to the start"})]})]})}function Zt(e){return e?.app.name??"this app"}function Jr(e){let n=e?.app.icon_urls;if(n?.length)return n;let t=e?.app.icon_url;return t?[t]:[]}function Jt(e){let n=Jr(e),[t,r]=$([]),s=J(u=>{u&&r(l=>l.includes(u)?l:[...l,u])},[]),a=J(u=>s(u.currentTarget.getAttribute("src")),[s]),i=J(u=>{u?.complete&&u.naturalWidth===0&&s(u.getAttribute("src"))},[s]);return{icon:n.find(u=>!t.includes(u)),onError:a,ref:i}}function Xr({context:e}){let{icon:n,onError:t,ref:r}=Jt(e);return e?.app.mark==="soba"?o(V,{className:"sc-app-mark"}):n?o("img",{className:"sc-app-mark",src:n,alt:"","aria-hidden":"true",ref:r,onError:t}):null}function bn({context:e}){let{icon:n,onError:t,ref:r}=Jt(e),s=e?.app.mark==="soba";return v("span",{className:"sc-app",children:[s&&o(V,{className:"sc-app-icon"}),!s&&n&&o("img",{className:"sc-app-icon",src:n,alt:"",ref:r,onError:t}),Zt(e)]})}function en({onClick:e}){return o("button",{type:"button",className:"sc-head-back",onClick:e,"aria-label":"Back",children:o("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:o("path",{d:"M15 5 8 12l7 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function ht({className:e}){return o("svg",{className:e,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:o("path",{d:"M9 5l7 7-7 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function On({mark:e,still:n}){return v("span",{className:"sc-waiting","aria-hidden":"true",children:[!n&&o("svg",{className:"sc-waiting-orbit",viewBox:"0 0 100 100","aria-hidden":"true",focusable:"false",children:o("circle",{className:"sc-waiting-arc",cx:"50",cy:"50",r:"46"})}),o(e,{className:"sc-waiting-mark"})]})}function ft({tone:e}){return o("span",{className:`sc-result sc-result-${e}`,"aria-hidden":"true",children:o(et,{kind:e==="ok"?"snap":"gone",size:84})})}function es({text:e}){return o(Tn,{children:e.split("`").map((n,t)=>t%2===1?o("code",{className:"sc-inline-code",children:n},t):n)})}function yn({k:e,v:n}){return v("li",{className:"sc-fact",children:[o("span",{className:"sc-fact-key",children:e}),o("span",{children:n})]})}import{useEffect as ns,useRef as yt}from"react";var In=0,bt=null;function Xt(){if(typeof document>"u")return()=>{};In===0&&(bt=document.body.style.overflow,document.body.style.overflow="hidden"),In+=1;let e=!1;return()=>{e||(e=!0,In-=1,In===0&&(document.body.style.overflow=bt??"",bt=null))}}import{jsx as er}from"react/jsx-runtime";function wn({open:e,onClose:n,labelledBy:t,theme:r,style:s,children:a}){let i=yt(null),u=yt(null),l=yt(null);return ns(()=>{let p=i.current;if(p){if(!e){p.open&&p.close();return}return p.open||p.showModal(),document.activeElement===p&&u.current?.focus(),Xt()}},[e]),er("dialog",{ref:i,className:"soba-connect sc-modal","aria-labelledby":t,...r?{"data-theme":r}:{},style:s,onCancel:p=>{p.preventDefault(),n()},onPointerDown:p=>{l.current=p.target},onClick:p=>{p.target===p.currentTarget&&l.current===p.currentTarget&&n()},children:er("div",{className:"sc-modal-sheet",ref:u,tabIndex:-1,children:a})})}function ve(e){let n=`${e.unit}s`;return e.reward==="unlimited"?`Unlimited ${n} on your own AI`:e.reward==="included"&&e.includedUnits!==null?`${rs(e.includedUnits)} ${n} a month once you connect`:e.reward==="credit"&&e.creditMicros>0?`${ts(e.creditMicros)} back each month you stay connected`:null}function Ce(e){return e==="unlimited"||e==="included"}var tr=new Set(["user-hardware","user-subscription"]),nr=new Set(["open-weights","frontier"]);function ie(e){return e===null||e.length===0?!1:e.every(n=>tr.has(n))}var ts=e=>(e/1e6).toLocaleString("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}),rs=e=>e.toLocaleString("en-US");function wt(e,n){if(!(n===null||n.some(a=>nr.has(a))))return!1;let r=e.findIndex(a=>tr.has(a));if(r===-1)return!1;let s=e.findIndex(a=>nr.has(a));return s===-1||r<s}import{createContext as ss,useContext as os}from"react";var vt=ss(null);function D(){let e=os(vt);if(!e)throw new Error("useSoba() must be used inside a <SobaProvider>.");return e}import{createContext as rr,useContext as sr}from"react";var Ct=rr(null);function or(){return sr(Ct)}var Nt=rr({context:null,machines:void 0,theme:"light"});function I(){return sr(Nt)}import{jsx as vn}from"react/jsx-runtime";function as({className:e}){let{theme:n}=I(),t=e?`soba-connect ${e}`:"soba-connect";return vn("div",{className:t,"data-theme":n,children:vn(kt,{})})}function kt(){let{compute:e}=D();return e.loading&&!e.machines.length?vn("p",{className:"sc-note",children:"Loading\u2026"}):e.error&&!e.machines.length?vn("p",{className:"sc-error",children:e.error.message}):vn(Je,{machines:e.machines})}import{useEffect as ls,useRef as ar,useState as cs}from"react";import{useId as is}from"react";import{jsx as nn,jsxs as An}from"react/jsx-runtime";function Cn({open:e,onOpenChange:n,initialCode:t,onConnected:r,showStatus:s,reason:a}){let{error:i}=D(),u=or(),l=I(),p=()=>n(!1),f=is(),g=l.context?.background?.trim(),m=g?an(g,l.context?.accent):void 0;return An(wn,{open:e,onClose:p,labelledBy:f,theme:l.theme,style:m,children:[i?An("div",{className:"sc-card",children:[nn("h2",{className:"sc-title",id:f,children:"Could not start"}),nn("p",{className:"sc-error",children:i.message})]}):!u&&!l.context?An("div",{className:"sc-card",children:[nn("h2",{className:"sc-title",id:f,children:"One moment"}),nn("p",{className:"sc-note",children:"Getting your compute\u2026"})]}):nn(gt,{client:u,onClose:p,headingId:f,theme:l.theme,initialContext:l.context,...l.machines!==void 0?{initialMachines:l.machines}:{},...t?{initialCode:t}:{},...r?{onConnected:r}:{},...s===void 0?{}:{showStatus:s},...a?{reason:a}:{}}),An("p",{className:"sc-modal-foot",children:[nn(V,{className:"sc-foot-mark"}),"Secured by Soba"]})]})}import{Fragment as xt,jsx as He,jsxs as Nn}from"react/jsx-runtime";function qe({children:e,variant:n,className:t,initialCode:r,onConnected:s,defaultOpen:a,open:i,onOpenChange:u,showConnected:l=!0}){let{compute:p,connect:f}=D(),{theme:g}=I(),[m,b]=cs(a??!!r),h=ar(null),k=i!==void 0,N=!k&&!a&&!r&&f.hasModal,x=k?i:N?f.isOpen:m,U=G=>{N?G?f.open("manual"):f.close():k||b(G),u?.(G)},j=ar(x);ls(()=>{j.current&&!x&&h.current?.focus(),j.current=x},[x]);let S=p.machines.find(G=>G.state!=="offline")??p.machines[0],O=S?.runtimes?.find(G=>!G.quarantined)??S?.runtimes?.[0],H=l&&S!==void 0,T=S?cn(S):null,M=O?un(O.id):void 0,q=(M?he[M.id]:void 0)??(O?Ze:$e);return Nn(xt,{children:[He("button",{ref:h,type:"button","data-theme":g,className:["sc-btn",H?"sc-btn-connected":"sc-btn-icon",!H&&n==="primary"?"sc-btn-primary":"",t].filter(Boolean).join(" "),onClick:()=>U(!0),children:e??(H?Nn(xt,{children:[He("span",{className:"sc-runtime-tile","aria-hidden":"true",children:He(q,{className:"sc-runtime-mark"})}),Nn("span",{className:"sc-btn-connected-text",children:[O?.display_name??"Connected",S?.label&&Nn("span",{className:"sc-btn-connected-where",children:[" on ",S.label]})]}),He("i",{className:`sc-dot sc-dot-${T?.tone??"off"}`,"aria-hidden":"true"}),T&&He("span",{className:"sc-sr",children:T.text})]}):Nn(xt,{children:[He(V,{className:"sc-btn-mark"}),"Connect compute"]}))}),!N&&He(Cn,{open:x,onOpenChange:U,...r?{initialCode:r}:{},...s?{onConnected:s}:{}})]})}import{jsx as St,jsxs as ds}from"react/jsx-runtime";function us({initialCode:e,onConnected:n,className:t,showStatus:r=!0}){let{theme:s}=I();return ds("div",{className:t?`soba-connect ${t}`:"soba-connect","data-theme":s,children:[r&&St(kt,{}),St("div",{className:"sc-compute-act",children:St(qe,{...e?{initialCode:e}:{},...n?{onConnected:n}:{}})})]})}import{useEffect as pr,useId as ys,useState as _t}from"react";import{useCallback as ps,useState as ms}from"react";function $n(){let[e,n]=ms(null);return{open:ps(()=>{n(null),st().then(n)},[]),launch:e,note:e==="absent"?"Nothing opened here. That machine may be a different computer, or asleep.":null}}import{useCallback as ir,useMemo as lr}from"react";function Be(e){if(!e)return null;if(typeof e=="string")return e;if(typeof Response<"u"&&e instanceof Response)return cr(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"?cr(n.status):n.cause&&n.cause!==e?Be(n.cause):null}function cr(e){return e===402?"payment_required":e===409?"no_compute":null}function Pt(...e){let[n,t]=e,{plan:r,compute:s,connect:a}=D(),i=t?.predict??e.length===0,u=fs(hs(n),s)??(i?gs(r,s):null),l=r.plan,p=r.plans,f=lr(()=>{if(u!=="payment_required")return null;let h=l?.price??0,k=l?.included_units??0;return p.find(N=>N.id!==l?.id&&N.price>h&&(N.included_units===null||N.included_units>k))??null},[u,p,l]),g=ir(async()=>{if(!f)return;if(f.selectable){await r.select(f.id);return}let h=await r.checkout(f.id);window.location.assign(h)},[f,r]),m=a.open,b=ir(()=>{u&&m(u)},[m,u]);return lr(()=>{if(!u)return null;let h=l?ve({unit:l.unit,reward:l.connected_reward,includedUnits:l.connected_included_units,creditMicros:l.connected_credit*1e6}):null,k=l&&Ce(l.connected_reward)?h:null;return{reason:u,...bs(u,{connectOffer:k,connected:s.connected,online:s.online,machine:ln(s.machines)?.label??null,unit:l?.unit??"message",interval:l?.interval??"month",upgrade:f!==null,resets:r.current?.period_end??null}),connectOffer:k,upgradeTo:f,connect:b,upgrade:g}},[u,l,s,f,b,g,r.current?.period_end])}function hs(e){let n=Be(e);return n==="payment_required"||n==="no_compute"?n:null}function fs(e,n){return e==="no_compute"&&n.connected&&n.online?null:e}function gs(e,n){let t=e.plan;return!t||n.loading?null:ie(t.route_allow)&&!n.online?"no_compute":e.remaining===0&&t.overage==="stop"?"payment_required":null}function bs(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 ${ur(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 ${ur(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 ur(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}import{Fragment as Et,jsx as _,jsxs as fe}from"react/jsx-runtime";function ws(e){let{at:n=.25,className:t,error:r,fallback:s=null}=e,a=e.predict??!("error"in e),{plan:i,compute:u,connect:l}=D(),{theme:p}=I(),[f,g]=_t(null),m=ys(),b=ct(l.publishableKey),[h,k]=_t(!1);pr(()=>{k(ut(b))},[b]);let N=_(Et,{children:s}),x=i.plan;if(!x||i.loading||u.loading)return N;let U=e.allow!==void 0?e.allow:x.route_allow;if(u.connected)return u.online?N:_(dr,{className:t,theme:p,stalled:!0,children:_(vs,{machine:ln(u.machines)?.label??null,ownCompute:ie(U),onConnectAnother:()=>l.open("no_compute")})});let j=(()=>{let M=Be(r);return M==="payment_required"||M==="no_compute"})(),S=x.ask_to_connect!==!1&&wt(x.route_prefer,U);if(!a&&!j&&!S)return N;let O=ie(U)?Ns(x.unit,ie(x.route_allow)):Ce(x.connected_reward)?xs(i,x,n):S?ks(x.unit):null;if(!O||O.dismissible&&h)return N;let H=!O.dismissible&&(!a||O.meter!==null&&O.meter.left===0),T=f??H;return fe(dr,{className:t,theme:p,children:[fe("div",{className:"sc-nudge-top",children:[fe("div",{className:"sc-nudge-say",children:[_("p",{className:"sc-nudge-title",children:O.title}),_("p",{className:"sc-nudge-detail",children:O.detail}),fe("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more","aria-expanded":T,"aria-controls":m,onClick:()=>g(!T),children:[T?"Hide the details":"How it works",_(Ps,{})]})]}),O.dismissible?_("button",{type:"button",className:"sc-nudge-dismiss","aria-label":"Dismiss",title:"Dismiss",onClick:()=>{k(!0),dt(b)},children:_(Ss,{})}):null]}),T?_("ol",{className:"sc-nudge-steps",id:m,children:Cs(l.app?.name,hn(l.connectUrl)).map(M=>fe("li",{children:[M.opens?_("button",{type:"button",className:"sc-step-lead",onClick:()=>l.open("manual"),children:M.lead}):_("strong",{children:M.lead}),M.detail?_("span",{children:M.detail}):null,M.links.length>0?fe("span",{className:"sc-step-links",children:[M.linksLead,M.links.map(q=>_("a",{href:q.href,target:"_blank",rel:"noreferrer noopener",children:q.label},q.href))]}):null]},M.lead))}):null,_(qe,{variant:"primary"})]})}function dr({className:e,theme:n,stalled:t,children:r}){return _("div",{className:e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill","data-theme":n,children:_("div",{className:t?"sc-nudge sc-nudge-stalled":"sc-nudge",children:r})})}function vs({machine:e,ownCompute:n,onConnectAnother:t}){let r=$n(),{compute:s}=D(),[a,i]=_t(!1),{refresh:u}=s;return pr(()=>{if(r.launch===null||r.launch==="absent")return;i(!1);let l=setInterval(()=>void u(),3e3),p=setTimeout(()=>{clearInterval(l),i(!0)},2e4);return()=>{clearInterval(l),clearTimeout(p)}},[r.launch,u]),fe(Et,{children:[_("div",{className:"sc-nudge-top",children:fe("div",{className:"sc-nudge-say",children:[fe("p",{className:"sc-nudge-title",children:[e??"Your machine"," can\u2019t be reached"]}),_("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&&_("p",{className:"sc-nudge-note",children:r.note}),a&&_("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)&&_("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more",onClick:t,children:a?"Connect it again":"Connect another machine"})]})}),_("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:r.open,children:"Open Soba App"})]})}function Cs(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:te.map(t=>({label:t.short,href:t.install}))}]}function Ns(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 ks(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 xs(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=ve({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:fe(Et,{children:[a,"."]}),meter:{left:r,of:s}}:null}function Ss(){return _("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-x",children:_("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 Ps(){return _("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-chev",children:_("path",{d:"M4.5 6.5 8 10l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})})}var _s=new Set(["delta","thinking","status","done","error"]);function Dn(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"||!_s.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),a}async function*Mt(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="",i=[];try{for(;;){let l=await r.read();if(l.done)break;for(a+=s.decode(l.value,{stream:!0});;){let p=a.indexOf(`
|
|
3
|
-
`);if(
|
|
4
|
-
`);if(
|
|
5
|
-
`);if(
|
|
2
|
+
var vn=class extends Error{status;constructor(n,t){super(n),this.name="ConnectError",this.status=t}},ro=5*6e4,Cn=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 vn&&s.status===401)throw s;this.gatewayBackUntil=Date.now()+ro}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}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 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 vn(a,o.status)}return s}};function Nn(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 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),o=dt(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 Ke(e,n){if(!dt(e))return{};let t=Nn(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":Nn(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",o=r?"Mac":n==="win32"||n==="windows"?"Windows PC":"Linux machine";return r?`${t==="aarch64"||t==="arm64"?"Apple silicon ":""}${o}`:o}function kn(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 xn(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,o)=>n(r)-n(o)||t(o)-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 we,jsxs as oo}from"react/jsx-runtime";function j({className:e}){return oo("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 fr({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 Ye({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 Gn({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 gt({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 Ie={claude:fr,chatgpt:Ye,local:Gn};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"]}],gr=["claude","chatgpt"];function bt(){return ce.filter(e=>gr.includes(e.id))}function yt(e){return ce.filter(n=>n.costClass===e)}function wt(e){return ce.find(n=>n.expects.includes(e))??null}import{jsx as C,jsxs as V}from"react/jsx-runtime";function Qe({machines:e,hosted:n=[],onApproveRuntime:t,onDisconnectHosted:r,onPair:o,onRefresh:s,refreshing:a,busy:c,appName:i,error:u}){let m=xn(e),f=e.filter(b=>b.id!==m?.id);return!m&&n.length===0&&!o?C("p",{className:"sc-note",children:"Nothing connected yet."}):V("div",{className:"sc-tray",children:[m&&C(Vn,{title:"This machine",action:s&&C("button",{type:"button",className:"sc-disc",onClick:s,disabled:a,"aria-label":"Refresh",title:"Refresh",children:C(uo,{spinning:!!a})}),children:C(so,{machine:m})}),m&&C(Vn,{title:"Agents on it",children:m.runtimes.length>0?m.runtimes.map(b=>C(io,{runtime:b,...t?{onApprove:()=>t(m.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(lo,{credential:b,appName:i,busy:c,...r?{onDisconnect:()=>r(b.provider)}:{}},b.provider))}),(f.length>0||o)&&V(Vn,{title:f.length>0?"Your other machines":m?"Add a machine":"Your machines",children:[f.map(b=>C(ao,{machine:b},b.id)),o&&V("button",{type:"button",className:"sc-pair",onClick:o,children:[C("span",{className:"sc-otile","aria-hidden":"true",children:C(co,{})}),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 V("section",{className:"sc-group",children:[V("div",{className:"sc-group-cap",children:[C("p",{className:"sc-group-title",children:e}),n]}),C("div",{className:"sc-group-card",children:t})]})}function so({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 V("div",{className:"sc-mrow",children:[V("span",{className:"sc-mtile","aria-hidden":"true",children:[C(br,{}),C("span",{className:`sc-mbadge sc-mbadge-${un(e).tone}`})]}),V("span",{className:"sc-mid",children:[C("span",{className:"sc-mname",children:je(e)}),C("span",{className:"sc-mmeta",children:t.map((r,o)=>V("span",{children:[o>0&&C("span",{className:"sc-mmeta-sep",children:"\xB7"}),r]},r))})]})]})}function ao({machine:e}){let n=un(e);return V("div",{className:"sc-orow",children:[C("span",{className:"sc-otile","aria-hidden":"true",children:C(br,{})}),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 io({runtime:e,onApprove:n}){let t=wt(e.id),r=t?Ie[t.id]:null,o=pt(e);return V("div",{className:"sc-arow",children:[C("span",{className:"sc-runtime-tile","aria-hidden":"true",children:r&&C(r,{className:"sc-runtime-mark"})}),V("span",{className:"sc-aname",children:[e.display_name,e.version&&V("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"}):o.tone==="ok"?V("span",{className:"sc-averdict",children:[C("span",{className:"sc-dot sc-dot-ok","aria-hidden":"true"}),C("span",{className:"sc-sr",children:o.text})]}):C("span",{className:`sc-averdict sc-tone-${o.tone}`,children:o.text})]})}function lo({credential:e,appName:n,busy:t,onDisconnect:r}){return V("div",{className:"sc-hrow",children:[V("div",{className:"sc-orow",children:[C("span",{className:"sc-otile","aria-hidden":"true",children:C(Ye,{className:"sc-omark"})}),V("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&&V("p",{className:"sc-row-note",children:[n??"This app"," stops using it. To withdraw the grant entirely, remove it in your OpenAI settings."]})]})}function br(){return V("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 co(){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 uo({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 po}from"react/jsx-runtime";function Sn({machines:e,onApproveRuntime:n}){return po(Qe,{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",Ze="M448.5 320 A110 110 0 0 1 448.5 480";import{Fragment as _n,jsx as x,jsxs as $e}from"react/jsx-runtime";function kt({kind:e,size:n=44,className:t}){let r=vt[e];return $e("svg",{className:`bx${t?` ${t}`:""}`,"data-expression":e,viewBox:Ct,overflow:"visible",width:n,height:n,"aria-hidden":"true",children:[x("path",{d:Nt,fill:"currentColor"}),x("path",{className:"bx-arc",d:Ze,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),r.slot==="stream"&&x(mo,{}),r.slot==="zzz"&&x(ho,{}),r.slot==="dots"&&x(fo,{}),r.slot==="bang"&&x(go,{}),r.slot==="orbit"&&x(bo,{}),r.slot==="cross"&&x(yo,{}),r.slot==="snap"&&x(wo,{}),r.slot==="bars"&&x(vo,{}),r.slot==="ring"&&x(Co,{}),r.slot==="sparks"&&x(No,{})]})}function mo(){return x("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 ho(){return $e(_n,{children:[x("g",{className:"bx-z1",children:x("path",{d:"M444 372 H496 L444 436 H496",fill:"none",stroke:"currentColor",strokeWidth:"20",strokeLinecap:"round",strokeLinejoin:"round"})}),x("g",{className:"bx-z2",children:x("path",{d:"M492 300 H522 L492 338 H522",fill:"none",stroke:"currentColor",strokeWidth:"15",strokeLinecap:"round",strokeLinejoin:"round"})})]})}function fo(){return $e(_n,{children:[x("circle",{className:"bx-th",cx:"463.1",cy:"336.9",r:"21",fill:"currentColor"}),x("circle",{className:"bx-th bx-th2",cx:"483",cy:"400",r:"21",fill:"currentColor"}),x("circle",{className:"bx-th bx-th3",cx:"463.1",cy:"463.1",r:"21",fill:"currentColor"})]})}function go(){return $e("g",{className:"bx-at",children:[x("line",{x1:"490",y1:"312",x2:"490",y2:"414",stroke:"currentColor",strokeWidth:"46",strokeLinecap:"round"}),x("circle",{cx:"490",cy:"484",r:"28",fill:"currentColor"})]})}function bo(){return $e("g",{className:"bx-ob",children:[x("path",{d:Ze,fill:"none",stroke:"var(--tile-bg, transparent)",strokeWidth:41,strokeLinecap:"round"}),x("path",{d:Ze,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})]})}function yo(){return $e(_n,{children:[x("path",{className:"bx-xa",d:Ze,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),x("g",{className:"bx-xx",children:x("path",{d:"M442 364 L514 436 M514 364 L442 436",fill:"none",stroke:"currentColor",strokeWidth:"24",strokeLinecap:"round"})})]})}function wo(){return x("path",{className:"bx-snap",d:Ze,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})}function vo(){return $e("g",{stroke:"currentColor",strokeWidth:"17",strokeLinecap:"round",children:[x("line",{className:"bx-vb",x1:"452",y1:"370",x2:"452",y2:"430"}),x("line",{className:"bx-vb bx-vb2",x1:"482",y1:"330",x2:"482",y2:"470"}),x("line",{className:"bx-vb bx-vb3",x1:"512",y1:"355",x2:"512",y2:"445"})]})}function Co(){return x(_n,{children:[[450,366],[474,376],[484,400],[474,424],[450,434],[426,424],[416,400],[426,376]].map(([n,t],r)=>x("circle",{className:"bx-w",cx:n,cy:t,r:"11",fill:"currentColor",style:{animationDelay:`${-1.2+r*.15}s`}},r))})}function No(){return $e(_n,{children:[x("g",{className:"bx-sp",children:x("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"})}),x("g",{className:"bx-sp bx-sp2",children:x("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"})}),x("g",{className:"bx-sp bx-sp3",children:x("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 re,useId as Mo,useMemo as He,useRef as dn,useState as H}from"react";var En=[{slug:"mac-arm",label:"macOS, Apple silicon"},{slug:"mac-intel",label:"macOS, Intel"},{slug:"windows",label:"Windows"},{slug:"linux",label:"Linux"}];function Mn(e){if(!e)return"";try{return new URL(e).origin}catch{return""}}function vr(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 ko=3e3,xo=2*6e4,zn=Date.now(),Kn=new Set,wr=!1;function So(){if(wr||typeof window>"u")return;wr=!0;let e=()=>{let t=zn;if(zn=Date.now(),zn-t>xo)for(let r of Kn)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 Kn)t()};window.addEventListener("focus",n),document.addEventListener("visibilitychange",n)}function De(e,n,t={}){So();let r,o=t.immediate===!1?Date.now():0,s=!1,a=!1,c=()=>{a||(r=setTimeout(i,t.idle===!1?n:vr(n,Date.now()-zn)))},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()}},u=()=>{Date.now()-o>Math.min(n,ko)&&i()};return Kn.add(u),t.immediate===!1?c():i(),()=>{a=!0,clearTimeout(r),Kn.delete(u)}}var xt="soba";function Cr(){return`${xt}://show`}function Rn(e,n,t){let r=`${xt}://connect?url=${encodeURIComponent(e)}`;return n&&(r+=`&nonce=${encodeURIComponent(n)}`),t&&(r+=`&want=${encodeURIComponent(t)}`),r}function Ln(){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 Po=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=Rn(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=Cr()}catch{return"absent"}return n}async function Et(e){if(typeof window>"u"||typeof document>"u")return"unknown";let n=e.graceMs??Po,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 Nr="soba.connect.choice",_o=180*24*60*60*1e3;function xr(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?`${Nr}.${e}.${xr(n)}`:`${Nr}.${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)>_o)return null;let r=ce.find(o=>o.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 kr="soba.connect.dismissed",Eo=30*24*60*60*1e3;function Tt(e,n){return e?n?`${kr}.${e}.${xr(n)}`:`${kr}.${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)<Eo}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 Qn,jsx as l,jsxs as N}from"react/jsx-runtime";var It=2e3,Ro=1e4,Lo=9e4,To=6e4;function $t(e,n,t,r=[],o){return e?"code":n&&(t.length>0||r.length>0)?"manage":o?"launch":"choose"}function Oo(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:o=!0,initialContext:s=null,initialMachines:a,onClose:c,headingId:i,theme:u,reason:m,active:f=!0}){let b=!!s&&a!==void 0,[g,p]=H(b?$t(n,o,a??[],[],t):"loading"),[y,_]=H(s),[k,U]=H(a??[]),[M,fe]=H(n??""),[S,se]=H(null),[T,P]=H(null),[W,z]=H(!1),[ae,tn]=H(0),[ue,ke]=H(()=>Date.now()),[K,xe]=H(null),[Se,qe]=H(!1),[F,Te]=H(!1),[rn,de]=H("browser"),[We,on]=H(null),[G,ge]=H([]),[O,pe]=H(0),[be,Pe]=H(null),B=dn(null),[X,E]=H(t??null),[at,sn]=H(null),ne=He(()=>{let d=y?.accent?.trim(),v=y?.background?.trim();if(!(!d&&!v))return v?{...Ke(v,d),background:v,borderRadius:"inherit"}:{"--sc-accent":d,"--sc-accent-fg":Nn(d)}},[y?.accent,y?.background]),an=Mo(),ie=i??an,Oe=dn(null);re(()=>{if(!e||b)return;let d=!0;return Promise.all([e.context(),e.machines()]).then(([v,I])=>{d&&(_(v),U(I),p($t(n,o,I)))}).catch(v=>{d&&(P(v.message),p("choose"))}),()=>{d=!1}},[e,n,o,b]),re(()=>{g!=="loading"||!b||p($t(n,o,a??[]))},[g,b,n,o,a]),re(()=>{a&&U(a)},[a]),re(()=>{s&&_(s)},[s]);let bn=dn(!1),_e=dn(g);_e.current=g;let yn=dn(G);yn.current=G;let Fe=!!y?.hosted_available;re(()=>{!o&&_e.current==="manage"&&p("choose")},[o]),re(()=>{if(!e||!f||g!=="manage")return;let d=!0,v=De(async()=>{try{let I=await e.machines();if(!d)return;U(I);let $=!Fe||bn.current;I.length===0&&yn.current.length===0&&$&&_e.current==="manage"&&p("choose")}catch{}},Ro,{immediate:!1});return()=>{d=!1,v()}},[g,e,Fe,f]);let Ge=Mt(y?.publishable_key??null);re(()=>{sn(Rt(Ge))},[Ge]),re(()=>{if(!e||!Fe)return;let d=!0;return e.hosted().then(v=>{d&&(ge(v.credentials),!bn.current&&(bn.current=!0,v.credentials.length>0&&o&&_e.current==="choose"&&p("manage")))}).catch(()=>{}),()=>{d=!1}},[e,Fe,o]),re(()=>{if(!e||!f||g!=="hosted")return;let d=!0,v=async()=>{try{let Ae=await e.hosted();if(!d)return!1;if(ge(Ae.credentials),Ae.credentials.length>0)return p("hosted_connected"),Pe(null),!0}catch{}return!1},I=async()=>{B.current?.closed&&(B.current=null,!await v()&&d&&p("choose"))},$=De(v,It,{immediate:!1}),ze=setInterval(I,400),Me=Ae=>{let hr=Ae.data;hr?.source==="soba"&&hr.type==="hosted_result"&&v()};return window.addEventListener("message",Me),()=>{d=!1,$(),clearInterval(ze),window.removeEventListener("message",Me),B.current=null}},[e,g,f]);let it=oe(()=>{if(!e)return;let d=window.open("","soba-connect-plan","width=520,height=760,noopener=no");B.current=d,p("hosted"),pe(Date.now()),Pe(null),P(null),e.startHosted().then(({url:v})=>{if(d&&!d.closed){d.location.href=v;return}Pe(v)}).catch(v=>{d?.close(),B.current=null,P(v.message),p("choose")})},[e]),Bn=oe(async d=>{if(e){z(!0);try{await e.disconnectHosted(d),ge((await e.hosted()).credentials)}catch(v){P(v.message)}finally{z(!1)}}},[e]);re(()=>{if(!e||!f||g!=="waiting")return;let d=!0,v=De(async()=>{try{let I=await e.machines();if(!d)return;U(I);let $=Oe.current;if(!$)return;let ze=I.filter(Ae=>!$.has(Ae.id)),Me=ze.find(Ae=>Ae.state!=="offline")??ze[0];Me&&(on(Me.id),X&&Lt(Ge,X),p("connected"),r?.(I))}catch{}},It,{immediate:!1});return()=>{d=!1,v()}},[g,e,r,X,Ge,f]);let qn=oe(async()=>{if(e){P(null),z(!0);try{let d=await e.lookup(M);se(d),p("confirm")}catch(d){P(d.message)}finally{z(!1)}}},[e,M]),Wn=oe(async()=>{if(e){P(null),z(!0);try{try{Oe.current=new Set((await e.machines()).map(d=>d.id))}catch{Oe.current=new Set(k.map(d=>d.id))}await e.approve(M),p("waiting"),tn(Date.now())}catch(d){P(d.message)}finally{z(!1)}}},[e,M,k]),Fn=oe(async()=>{if(e){z(!0);try{await e.deny(M),de("browser"),p("denied")}catch(d){P(d.message)}finally{z(!1)}}},[e,M]),A=He(()=>y?.connect_url??null,[y]),[te,wn]=H(()=>Ln()),lt=He(()=>A?Rn(A,te??void 0,X??void 0):null,[A,te,X]),w=He(()=>Mn(A),[A]),Y=oe(d=>{if(k.length===0)return null;let v=ce.find($=>$.id===d);if(!v)return null;let I=k.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"}},[k]),le=oe((d=null)=>{E(d),P(null),xe(null),qe(!1),Te(!1),ln.current=!1,wn(Ln()),p("launch")},[]),ln=dn(!!t);re(()=>{g!=="launch"||!A||ln.current||(ln.current=!0,qe(!0),Pt(A,{...te?{nonce:te}:{},...X?{want:X}:{}}).then(xe))},[g,A,te,X]);let ye=oe(()=>{qe(!0),St().then(xe)},[]),ct=oe(d=>{if(F){let v=Ln();Te(!1),wn(v),A&&(d.preventDefault(),window.location.href=Rn(A,v??void 0,X??void 0))}ye()},[F,ye,A,X]),Ee=He(()=>{let d=y?.runtimes;return d?ce.filter(v=>d.includes(v.id)):bt()},[y?.runtimes]),ee=He(()=>{let d=ce.find(v=>v.id===X);return d?{choice:d,Mark:Ie[d.id]??null}:null},[X]),ut=He(()=>k.find(d=>d.id===We),[k,We]);re(()=>{let d=te;if(!e||!f||g!=="launch"||!d)return;let v=!1,I=Date.now()+15e4,$=()=>{};return $=De(async()=>{if(Date.now()>I){$(),Te(!0);return}try{let ze=await e.claim(d);if(v)return;if(ze.declined){$(),xe(null),de("machine"),p("denied");return}if(!ze.claimed)return;$();try{Oe.current=new Set((await e.machines()).map(Me=>Me.id))}catch{Oe.current=new Set(k.map(Me=>Me.id))}p("waiting"),tn(Date.now())}catch{}},It,{immediate:!1,idle:!1}),()=>{v=!0,$()}},[e,g,k,te,f]);let Ve=He(()=>{if(!S)return null;if(S.approved||S.denied)return"answered";let d=S.expires_at?Date.parse(S.expires_at):Number.NaN;return Number.isFinite(d)&&d<=ue?"expired":"live"},[S,ue]);re(()=>{if(!(g==="confirm"&&Ve==="live"||g==="waiting"||g==="hosted"))return;let v=setInterval(()=>ke(Date.now()),1e3);return()=>clearInterval(v)},[g,Ve]);let mr=oe(async(d,v)=>{if(e)try{await e.approveRuntime(d,v),U(await e.machines())}catch(I){P(I.message)}},[e]);return g==="loading"?l("div",{className:"soba-connect",...u?{"data-theme":u}:{},style:ne,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:ne,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:ie,children:"Your compute"}),N("p",{className:"sc-sub",children:[l(jn,{context:y})," ",k.length>0&&G.length>0?"runs on your connected plan, and on these machines while they are awake.":G.length>0?"runs on the plan you connected. Nothing here is charged to you.":"runs on these machines, while they are awake."]}),l(Qe,{machines:k,hosted:G,onApproveRuntime:mr,onDisconnectHosted:d=>void Bn(d),onPair:()=>p("choose"),busy:W,...y?.app.name?{appName:y.app.name}:{}}),T&&l("p",{className:"sc-error",children:T})]}),g==="choose"&&N("div",{className:"sc-card",children:[l(Io,{context:y}),l("h2",{className:"sc-h",id:ie,children:m==="payment_required"?"Carry on with your own AI":m==="no_compute"?"This run needs a machine":"Connect your AI"}),l("p",{className:"sc-p",children:"Use compute you already have."}),A&&Ee.length>0&&N(Qn,{children:[l("div",{className:"sc-opts",children:Ee.map(d=>{let v=Ie[d.id];return N("button",{type:"button",className:"sc-opt",onClick:()=>le(d.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:d.label})}),(()=>{let I=Y(d.id);return I?l("span",{className:`sc-opt-has sc-opt-has-${I.tone}`,children:I.text}):at===d.id?l("span",{className:"sc-opt-last",children:"last used"}):l(Dt,{className:"sc-opt-go"})})()]},d.id)})}),N("p",{className:"sc-opt-note",children:["Your accounts stay there. ",Sr(y)," never sees them."]})]}),(!A||Ee.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."}),T&&l("p",{className:"sc-error",children:T}),A&&y?.show_code===!0&&l("div",{className:"sc-opt-alt",children:l("button",{type:"button",className:"sc-alt-link",onClick:()=>p("code"),children:"I have a code"})})]}),g==="launch"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>p("choose")}),l("p",{className:"sc-head-title",children:"Soba App"})]}),l(Yn,{mark:ee?.Mark??j,still:F||!Se&&K===null}),l("h2",{className:"sc-h",id:ie,children:F?"No answer from this machine":K==="absent"?"Nothing opened":K===null?"Opening Soba App\u2026":"Approve it on this machine"}),F?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."}):K==="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:K===null?"Approve it there and this page does the rest.":"This page finishes on its own."}),ee&&N("p",{className:"sc-prereq",children:[ee.Mark&&l(ee.Mark,{className:"sc-rt-mark"}),"Needs ",ee.choice.prerequisite]}),N("div",{className:"sc-stack",style:{marginTop:18},children:[l("a",{className:K==="absent"||F?"sc-btn sc-btn-primary":"sc-btn",href:lt??"#",onClick:ct,children:F?"Try again":K==="absent"?"Open Soba App":"Open it again"}),l("p",{className:"sc-note",children:K===null?"Your browser will ask permission first.":"Your browser asks permission the first time."}),ee&&K==="absent"&&l("p",{className:"sc-note",children:l($o,{text:ee.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:()=>p("get"),children:["Get it",l(Dt,{})]})]})]})]}),g==="get"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>p("launch")}),l("p",{className:"sc-head-title",children:"Get Soba App"})]}),l("div",{className:"sc-opts",children:En.map(d=>N("a",{className:"sc-opt",href:`${w}/download/${d.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:d.label})}),l(Dt,{className:"sc-opt-go"})]},d.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:()=>p("choose")}),l("p",{className:"sc-head-title",children:"Soba App"})]}),l("h2",{className:"sc-h",id:ie,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:d=>{d.preventDefault(),qn()},children:[l("input",{className:"sc-input",value:M,onChange:d=>fe(d.target.value),placeholder:"ACDE-F234",autoComplete:"off",autoFocus:!0,"aria-label":"Pairing code"}),T&&l("p",{className:"sc-error",children:T}),l("button",{type:"submit",className:"sc-btn sc-btn-primary",disabled:W||M.length<8,children:W?"Checking\u2026":"Continue"})]})]}),g==="confirm"&&S&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>p("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(Tn,{k:"Code",v:S.user_code}),l(Tn,{k:"Machine",v:S.hostname??"not stated"}),l(Tn,{k:"System",v:[S.platform,S.arch].filter(Boolean).join(" / ")||"not stated"}),l(Tn,{k:"Asked by",v:S.client??"not stated"}),S.labels.length>0&&l(Tn,{k:"Labels",v:S.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."}),T&&l("p",{className:"sc-error",children:T}),N("div",{className:"sc-row",style:{marginTop:16},children:[l("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:()=>void Wn(),disabled:W||Ve!=="live",children:"Approve"}),l("button",{type:"button",className:"sc-btn",onClick:()=>void Fn(),disabled:W||Ve==="answered",children:"No, deny it"})]}),Ve==="live"&&S.expires_at&&N("p",{className:"sc-note",style:{marginTop:10},children:["This code expires in ",Oo(Date.parse(S.expires_at)-ue),"."]})]}),g==="waiting"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>p("choose")}),l("p",{className:"sc-head-title",children:ee?.choice.short??"Soba App"})]}),l(Yn,{mark:ee?.Mark??j}),l("h2",{className:"sc-h",id:ie,children:"Approved. Waiting for it to connect"}),l("p",{className:"sc-p",children:"Nothing more to do here. This page changes when it arrives."}),ae>0&&ue-ae>Lo&&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:ie,children:ut?.label?`${ut.label} is connected`:"Connected"}),N("p",{className:"sc-p",children:[l(jn,{context:y})," will use ",ut?.label?"it":"this machine"," from now on, while it is awake."]}),o&&N(Qn,{children:[l("div",{style:{marginTop:16},children:l(Sn,{machines:k,onApproveRuntime:mr})}),l("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:14},onClick:()=>p("manage"),children:"Done"})]})]}),g==="hosted"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[l(pn,{onClick:()=>p("choose")}),l("p",{className:"sc-head-title",children:"ChatGPT"})]}),be?l(Yn,{mark:Ye,still:!0}):l(Yn,{mark:Ye}),l("h2",{className:"sc-h",id:ie,children:be?"Your browser blocked the window":"Finish signing in to ChatGPT"}),l("p",{className:"sc-p",children:be?"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:[be&&l("a",{className:"sc-btn sc-btn-primary",href:be,target:"soba-connect-plan",rel:"noreferrer",children:"Open the ChatGPT sign-in"}),T&&l("p",{className:"sc-error",children:T}),O>0&&ue-O>To&&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:ie,children:"ChatGPT is connected"}),N("p",{className:"sc-p",children:[l(jn,{context:y})," will run on your ChatGPT plan",G[0]?.account_label?` (${G[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."}),o&&N(Qn,{children:[l("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>p("manage"),children:"Done"}),l("div",{className:"sc-opt-alt",children:l("button",{type:"button",className:"sc-alt-link",onClick:()=>p("choose"),children:"Connect a machine too"})})]})]}),g==="denied"&&N("div",{className:"sc-card",children:[l(Ht,{tone:"off"}),l("h2",{className:"sc-h",id:ie,children:"Declined"}),l("p",{className:"sc-p",children:rn==="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:()=>p("choose"),children:"Back to the start"})]})]})}function Sr(e){return e?.app.name??"this app"}function Ao(e){let n=e?.app.icon_urls;if(n?.length)return n;let t=e?.app.icon_url;return t?[t]:[]}function Pr(e){let n=Ao(e),[t,r]=H([]),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 Io({context:e}){let{icon:n,onError:t,ref:r}=Pr(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}=Pr(e),o=e?.app.mark==="soba";return N("span",{className:"sc-app",children:[o&&l(j,{className:"sc-app-icon"}),!o&&n&&l("img",{className:"sc-app-icon",src:n,alt:"",ref:r,onError:t}),Sr(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 Yn({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 $o({text:e}){return l(Qn,{children:e.split("`").map((n,t)=>t%2===1?l("code",{className:"sc-inline-code",children:n},t):n)})}function Tn({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 Do,useRef as qt}from"react";var Zn=0,Bt=null;function _r(){if(typeof document>"u")return()=>{};Zn===0&&(Bt=document.body.style.overflow,document.body.style.overflow="hidden"),Zn+=1;let e=!1;return()=>{e||(e=!0,Zn-=1,Zn===0&&(document.body.style.overflow=Bt??"",Bt=null))}}import{jsx as Er}from"react/jsx-runtime";function On({open:e,onClose:n,labelledBy:t,theme:r,style:o,children:s}){let a=qt(null),c=qt(null),i=qt(null);return Do(()=>{let u=a.current;if(u){if(!e){u.open&&u.close();return}return u.open||u.showModal(),document.activeElement===u&&c.current?.focus(),_r()}},[e]),Er("dialog",{ref:a,className:"soba-connect sc-modal","aria-labelledby":t,...r?{"data-theme":r}:{},style:o,onCancel:u=>{u.preventDefault(),n()},onPointerDown:u=>{i.current=u.target},onClick:u=>{u.target===u.currentTarget&&i.current===u.currentTarget&&n()},children:Er("div",{className:"sc-modal-sheet",ref:c,tabIndex:-1,children:s})})}import{useEffect as Wt,useRef as Ho}from"react";import{jsx as Uo}from"react/jsx-runtime";var Je=8;function Ft({open:e,onClose:n,anchor:t,label:r,theme:o,style:s,children:a}){let c=Ho(null);return Wt(()=>{let i=c.current;if(!(!i||!(typeof i.showPopover=="function")))try{e?i.showPopover():i.hidePopover()}catch{}},[e]),Wt(()=>{if(!e)return;let i=()=>{let m=c.current,f=t.current;if(!m||!f)return;let b=f.getBoundingClientRect(),g=m.offsetWidth,p=m.offsetHeight,y=window.innerWidth-g-Je,_=Math.max(Je,Math.min(b.right-g,Math.max(Je,y))),k=b.bottom+Je,U=b.top-Je-p,M=k+p>window.innerHeight-Je&&U>Je?U:k;m.style.left=`${Math.round(_)}px`,m.style.top=`${Math.round(M)}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]),Wt(()=>{if(!e)return;let i=m=>{m.key==="Escape"&&n()},u=m=>{let f=m.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]),Uo("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})}function Re(e){let n=`${e.unit}s`;return e.reward==="unlimited"?`Unlimited ${n} on your own AI`:e.reward==="included"&&e.includedUnits!==null?`${qo(e.includedUnits)} ${n} a month once you connect`:e.reward==="credit"&&e.creditMicros>0?`${Bo(e.creditMicros)} back each month you stay connected`:null}function Le(e){return e==="unlimited"||e==="included"}var Rr=new Set(["user-hardware","user-subscription"]),Mr=new Set(["open-weights","frontier"]);function me(e){return e===null||e.length===0?!1:e.every(n=>Rr.has(n))}var Bo=e=>(e/1e6).toLocaleString("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}),qo=e=>e.toLocaleString("en-US");function Gt(e,n){if(!(n===null||n.some(s=>Mr.has(s))))return!1;let r=e.findIndex(s=>Rr.has(s));if(r===-1)return!1;let o=e.findIndex(s=>Mr.has(s));return o===-1||r<o}import{createContext as Wo,useContext as Fo}from"react";var Vt=Wo(null);function q(){let e=Fo(Vt);if(!e)throw new Error("useSoba() must be used inside a <SobaProvider>.");return e}import{createContext as Lr,useContext as Tr}from"react";var zt=Lr(null);function Jn(){return Tr(zt)}var Kt=Lr({context:null,machines:void 0,theme:"light"});function D(){return Tr(Kt)}import{jsx as An}from"react/jsx-runtime";function Go({className:e}){let{theme:n}=D(),t=e?`soba-connect ${e}`:"soba-connect";return An("div",{className:t,"data-theme":n,children:An(jt,{})})}function jt(){let{compute:e}=q();return e.loading&&!e.machines.length?An("p",{className:"sc-note",children:"Loading\u2026"}):e.error&&!e.machines.length?An("p",{className:"sc-error",children:e.error.message}):An(Sn,{machines:e.machines})}import{useCallback as et,useEffect as Yt,useRef as Qt,useState as hn}from"react";import{useId as Vo}from"react";import{jsx as mn,jsxs as Xn}from"react/jsx-runtime";function In({open:e,onOpenChange:n,initialCode:t,onConnected:r,showStatus:o,reason:s}){let{error:a}=q(),c=Jn(),i=D(),u=()=>n(!1),m=Vo(),f=i.context?.background?.trim(),b=f?Ke(f,i.context?.accent):void 0;return Xn(On,{open:e,onClose:u,labelledBy:m,theme:i.theme,style:b,children:[a?Xn("div",{className:"sc-card",children:[mn("h2",{className:"sc-title",id:m,children:"Could not start"}),mn("p",{className:"sc-error",children:a.message})]}):!c&&!i.context?Xn("div",{className:"sc-card",children:[mn("h2",{className:"sc-title",id:m,children:"One moment"}),mn("p",{className:"sc-note",children:"Getting your compute\u2026"})]}):mn(Ut,{client:c,active:e,onClose:u,headingId:m,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}:{}}),Xn("p",{className:"sc-modal-foot",children:[mn(j,{className:"sc-foot-mark"}),"Secured by Soba"]})]})}import{Fragment as Zt,jsx as Ue,jsxs as $n}from"react/jsx-runtime";function Xe({children:e,variant:n,className:t,initialCode:r,onConnected:o,defaultOpen:s,open:a,onOpenChange:c,showConnected:i=!0}){let{compute:u,connect:m}=q(),f=D(),{theme:b}=f,g=Jn(),[p,y]=hn(s??!!r),_=Qt(null),k=a!==void 0,U=!k&&!s&&!r&&m.hasModal,M=k?a:U?m.isOpen:p,fe=O=>{U?O?m.open("manual"):m.close():k||y(O),c?.(O)},S=Qt(M);Yt(()=>{S.current&&!M&&_.current?.focus(),S.current=M},[M]);let se=xn(u.machines),T=i&&se!==null,P=un(se),[W,z]=hn(!1),ae=et(()=>z(!1),[]),[tn,ue]=hn(!1),ke=et(async()=>{ue(!0);try{await u.refresh()}finally{ue(!1)}},[u]),K=Qt(ke);K.current=ke,Yt(()=>{W&&K.current()},[W]);let[xe,Se]=hn(!1),[qe,F]=hn([]),Te=!!f.context?.hosted_available;Yt(()=>{if(!W||!g||!Te)return;let O=!0;return g.hosted().then(pe=>{O&&F(pe.credentials)}).catch(()=>{}),()=>{O=!1}},[W,g,Te]);let[rn,de]=hn(null),We=et(async(O,pe)=>{if(g){de(null);try{await g.approveRuntime(O,pe),await u.refresh()}catch(be){de(be.message)}}},[g,u]),on=et(async O=>{if(g){de(null);try{await g.disconnectHosted(O),F((await g.hosted()).credentials)}catch(pe){de(pe.message)}}},[g]),G=f.context?.background?.trim(),ge=G?Ke(G,f.context?.accent):void 0;return $n(Zt,{children:[Ue("button",{ref:_,type:"button","data-theme":b,className:["sc-btn",T?"sc-btn-connected":"sc-btn-icon",!T&&n==="primary"?"sc-btn-primary":"",t].filter(Boolean).join(" "),...T&&!e?{"aria-haspopup":"dialog","aria-expanded":W,"aria-label":se?`${P.word} on ${je(se)}`:P.word}:{},onClick:()=>{if(T&&!e&&!k&&!s&&!r){z(O=>!O);return}fe(!0)},children:e??(T?$n(Zt,{children:[Ue("span",{className:"sc-pill-tile","aria-hidden":"true",children:Ue(j,{className:P.tone==="busy"?"sc-pill-mark sc-pill-mark-busy":"sc-pill-mark"})}),$n("span",{className:"sc-btn-connected-text",children:[P.word,se&&$n("span",{className:"sc-btn-connected-where",children:[" on ",je(se)]})]}),Ue("i",{className:`sc-dot sc-dot-${P.tone}`,"aria-hidden":"true"})]}):$n(Zt,{children:[Ue(j,{className:"sc-btn-mark"}),"Connect compute"]}))}),Ue(Ft,{open:W,onClose:ae,anchor:_,label:"Your compute",theme:b,...ge?{style:ge}:{},children:Ue(Qe,{machines:u.machines,hosted:qe,onApproveRuntime:(O,pe)=>void We(O,pe),onDisconnectHosted:O=>void on(O),onRefresh:()=>void ke(),refreshing:tn,error:rn,onPair:()=>{z(!1),U?m.open("pair"):(Se(!0),fe(!0))},...f.context?.app.name?{appName:f.context.app.name}:{}})}),!U&&Ue(In,{open:M,onOpenChange:O=>{O||Se(!1),fe(O)},...xe?{showStatus:!1}:{},...r?{initialCode:r}:{},...o?{onConnected:o}:{}})]})}import{jsx as Jt,jsxs as Ko}from"react/jsx-runtime";function zo({initialCode:e,onConnected:n,className:t,showStatus:r=!0}){let{theme:o}=D();return Ko("div",{className:t?`soba-connect ${t}`:"soba-connect","data-theme":o,children:[r&&Jt(jt,{}),Jt("div",{className:"sc-compute-act",children:Jt(Xe,{...e?{initialCode:e}:{},...n?{onConnected:n}:{}})})]})}import{useEffect as Hr,useId as es,useState as er}from"react";import{useCallback as jo,useState as Yo}from"react";function nt(){let[e,n]=Yo(null);return{open:jo(()=>{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 Or,useMemo as Ar}from"react";function en(e){if(!e)return null;if(typeof e=="string")return e;if(typeof Response<"u"&&e instanceof Response)return Ir(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"?Ir(n.status):n.cause&&n.cause!==e?en(n.cause):null}function Ir(e){return e===402?"payment_required":e===409?"no_compute":null}function Xt(...e){let[n,t]=e,{plan:r,compute:o,connect:s}=q(),a=t?.predict??e.length===0,c=Zo(Qo(n),o)??(a?Jo(r,o):null),i=r.plan,u=r.plans,m=Ar(()=>{if(c!=="payment_required")return null;let p=i?.price??0,y=i?.included_units??0;return u.find(_=>_.id!==i?.id&&_.price>p&&(_.included_units===null||_.included_units>y))??null},[c,u,i]),f=Or(async()=>{if(!m)return;if(m.selectable){await r.select(m.id);return}let p=await r.checkout(m.id);window.location.assign(p)},[m,r]),b=s.open,g=Or(()=>{c&&b(c)},[b,c]);return Ar(()=>{if(!c)return null;let p=i?Re({unit:i.unit,reward:i.connected_reward,includedUnits:i.connected_included_units,creditMicros:i.connected_credit*1e6}):null,y=i&&Le(i.connected_reward)?p:null;return{reason:c,...Xo(c,{connectOffer:y,connected:o.connected,online:o.online,machine:kn(o.machines)?.label??null,unit:i?.unit??"message",interval:i?.interval??"month",upgrade:m!==null,resets:r.current?.period_end??null}),connectOffer:y,upgradeTo:m,connect:g,upgrade:f}},[c,i,o,m,g,f,r.current?.period_end])}function Qo(e){let n=en(e);return n==="payment_required"||n==="no_compute"?n:null}function Zo(e,n){return e==="no_compute"&&n.connected&&n.online?null:e}function Jo(e,n){let t=e.plan;return!t||n.loading?null:me(t.route_allow)&&!n.online?"no_compute":e.remaining===0&&t.overage==="stop"?"payment_required":null}function Xo(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 ${$r(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 ${$r(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 $r(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 R,jsxs as ve}from"react/jsx-runtime";function ns(e){let{at:n=.25,className:t,error:r,fallback:o=null}=e,s=e.predict??!("error"in e),{plan:a,compute:c,connect:i}=q(),{theme:u}=D(),[m,f]=er(null),b=es(),g=Tt(i.publishableKey),[p,y]=er(!1);Hr(()=>{y(Ot(g))},[g]);let _=R(nr,{children:o}),k=a.plan;if(!k||a.loading||c.loading)return _;let U=e.allow!==void 0?e.allow:k.route_allow;if(c.connected)return c.online?_:R(Dr,{className:t,theme:u,stalled:!0,children:R(ts,{machine:kn(c.machines)?.label??null,ownCompute:me(U),onConnectAnother:()=>i.open("no_compute")})});let M=(()=>{let P=en(r);return P==="payment_required"||P==="no_compute"})(),fe=k.ask_to_connect!==!1&&Gt(k.route_prefer,U);if(!s&&!M&&!fe)return _;let S=me(U)?os(k.unit,me(k.route_allow)):Le(k.connected_reward)?as(a,k,n):fe?ss(k.unit):null;if(!S||S.dismissible&&p)return _;let se=!S.dismissible&&(!s||S.meter!==null&&S.meter.left===0),T=m??se;return ve(Dr,{className:t,theme:u,children:[ve("div",{className:"sc-nudge-top",children:[ve("div",{className:"sc-nudge-say",children:[R("p",{className:"sc-nudge-title",children:S.title}),R("p",{className:"sc-nudge-detail",children:S.detail}),ve("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more","aria-expanded":T,"aria-controls":b,onClick:()=>f(!T),children:[T?"Hide the details":"How it works",R(ls,{})]})]}),S.dismissible?R("button",{type:"button",className:"sc-nudge-dismiss","aria-label":"Dismiss",title:"Dismiss",onClick:()=>{y(!0),At(g)},children:R(is,{})}):null]}),T?R("ol",{className:"sc-nudge-steps",id:b,children:rs(i.app?.name,Mn(i.connectUrl)).map(P=>ve("li",{children:[P.opens?R("button",{type:"button",className:"sc-step-lead",onClick:()=>i.open("manual"),children:P.lead}):R("strong",{children:P.lead}),P.detail?R("span",{children:P.detail}):null,P.links.length>0?ve("span",{className:"sc-step-links",children:[P.linksLead,P.links.map(W=>R("a",{href:W.href,target:"_blank",rel:"noreferrer noopener",children:W.label},W.href))]}):null]},P.lead))}):null,R(Xe,{variant:"primary"})]})}function Dr({className:e,theme:n,stalled:t,children:r}){return R("div",{className:e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill","data-theme":n,children:R("div",{className:t?"sc-nudge sc-nudge-stalled":"sc-nudge",children:r})})}function ts({machine:e,ownCompute:n,onConnectAnother:t}){let r=nt(),{compute:o}=q(),[s,a]=er(!1),{refresh:c}=o;return Hr(()=>{if(r.launch===null||r.launch==="absent")return;a(!1);let i=setInterval(()=>void c(),3e3),u=setTimeout(()=>{clearInterval(i),a(!0)},2e4);return()=>{clearInterval(i),clearTimeout(u)}},[r.launch,c]),ve(nr,{children:[R("div",{className:"sc-nudge-top",children:ve("div",{className:"sc-nudge-say",children:[ve("p",{className:"sc-nudge-title",children:[e??"Your machine"," can\u2019t be reached"]}),R("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&&R("p",{className:"sc-nudge-note",children:r.note}),s&&R("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"||s)&&R("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more",onClick:t,children:s?"Connect it again":"Connect another machine"})]})}),R("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:r.open,children:"Open Soba App"})]})}function rs(e,n){return[{lead:"Download Soba App",detail:"",linksLead:n?"Get it for":void 0,links:n?En.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}))}]}function os(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 ss(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 as(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=Re({unit:n.unit,reward:n.connected_reward,includedUnits:n.connected_included_units,creditMicros:n.connected_credit*1e6});return s?{title:r===0?`No ${n.unit}s left this month.`:`${r} ${n.unit}${r===1?"":"s"} left this month.`,detail:ve(nr,{children:[s,"."]}),meter:{left:r,of:o}}:null}function is(){return R("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-x",children:R("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 ls(){return R("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-chev",children:R("path",{d:"M4.5 6.5 8 10l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})})}var cs=new Set(["delta","thinking","status","done","error"]);function tt(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"||!cs.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),s}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(),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 u=s.indexOf(`
|
|
3
|
+
`);if(u===-1)break;let m=Br(s.slice(0,u));if(s=s.slice(u+1),t){let f=m.trim()?tt(m):null;f&&(yield f);continue}if(m===""){let f=a.join(`
|
|
4
|
+
`);if(a=[],f==="[DONE]")return;let b=f?tt(f):null;b&&(yield b);continue}Ur(m,a)}}!t&&s&&Ur(Br(s),a);let c=t?s.trim():a.join(`
|
|
5
|
+
`);if(c&&c!=="[DONE]"){let i=tt(c);i&&(yield i)}}finally{r.cancel().catch(()=>{})}}function Ur(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 Br(e){return e.endsWith("\r")?e.slice(0,-1):e}async function us(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{useEffect as ds}from"react";var qr="data-soba-react",Wr=!1;function Dn(){if(Wr||typeof document>"u"||(Wr=!0,document.querySelector(`style[${qr}]`)))return;let e=document.createElement("style");e.setAttribute(qr,""),e.textContent=`.soba-connect {
|
|
6
6
|
--sc-ground: #ffffff;
|
|
7
7
|
--sc-sheet: #ffffff;
|
|
8
8
|
--sc-raised: #f6f6f7;
|
|
@@ -16,6 +16,10 @@ var Ln=class extends Error{status;constructor(n,t){super(n),this.name="ConnectEr
|
|
|
16
16
|
--sc-ok: #22a06b;
|
|
17
17
|
--sc-warn: #b06f14;
|
|
18
18
|
|
|
19
|
+
--sc-tray: var(--sc-raised, #f6f6f7);
|
|
20
|
+
--sc-tray-card: var(--sc-sheet, #ffffff);
|
|
21
|
+
--sc-tray-sunk: var(--sc-raised, #f6f6f7);
|
|
22
|
+
|
|
19
23
|
--sc-font-size: 15px;
|
|
20
24
|
--sc-fs-label: max(11px, calc(var(--sc-font-size) * 0.77));
|
|
21
25
|
|
|
@@ -243,121 +247,182 @@ a.sc-btn {
|
|
|
243
247
|
min-width: 92px;
|
|
244
248
|
}
|
|
245
249
|
|
|
246
|
-
.sc-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
+
.sc-tray {
|
|
251
|
+
display: grid;
|
|
252
|
+
gap: 8px;
|
|
253
|
+
padding: 6px;
|
|
254
|
+
border-radius: 18px;
|
|
255
|
+
background: var(--sc-tray, #f6f6f7);
|
|
250
256
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
margin-top: 0;
|
|
257
|
+
|
|
258
|
+
.sc-group {
|
|
259
|
+
min-width: 0;
|
|
255
260
|
}
|
|
256
261
|
|
|
257
|
-
.sc-
|
|
262
|
+
.sc-group-cap {
|
|
258
263
|
display: flex;
|
|
259
|
-
flex-wrap: wrap;
|
|
260
264
|
align-items: center;
|
|
261
|
-
gap:
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
font-size: var(--sc-fs-small);
|
|
265
|
-
line-height: 1.35;
|
|
266
|
-
color: var(--sc-muted, #6b6b73);
|
|
265
|
+
gap: 4px;
|
|
266
|
+
min-height: 24px;
|
|
267
|
+
padding: 0 2px 3px 12px;
|
|
267
268
|
}
|
|
268
269
|
|
|
269
|
-
.sc-
|
|
270
|
+
.sc-group-title {
|
|
271
|
+
flex: 1;
|
|
272
|
+
min-width: 0;
|
|
273
|
+
margin: 0;
|
|
274
|
+
overflow: hidden;
|
|
275
|
+
text-overflow: ellipsis;
|
|
276
|
+
white-space: nowrap;
|
|
270
277
|
font-size: var(--sc-fs-label);
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
border-radius: var(--sc-r-sm, 6px);
|
|
274
|
-
background: var(--sc-raised, #f6f6f7);
|
|
278
|
+
letter-spacing: 0;
|
|
279
|
+
color: var(--sc-muted, #6b6b73);
|
|
275
280
|
}
|
|
276
281
|
|
|
277
|
-
.sc-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
color: var(--sc-muted, #6b6b73);
|
|
283
|
-
white-space: nowrap;
|
|
282
|
+
.sc-group-card {
|
|
283
|
+
padding: 6px 0 6px 12px;
|
|
284
|
+
border-radius: var(--sc-r-lg, 14px);
|
|
285
|
+
background: var(--sc-tray-card, #ffffff);
|
|
286
|
+
box-shadow: var(--sc-shadow-1);
|
|
284
287
|
}
|
|
285
288
|
|
|
286
|
-
.sc-
|
|
289
|
+
.sc-disc {
|
|
290
|
+
flex: none;
|
|
287
291
|
display: grid;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
292
|
+
place-items: center;
|
|
293
|
+
width: 26px;
|
|
294
|
+
height: 26px;
|
|
295
|
+
padding: 0;
|
|
296
|
+
border: 0;
|
|
297
|
+
border-radius: 50%;
|
|
298
|
+
background: var(--sc-tray-card, #ffffff);
|
|
299
|
+
box-shadow: var(--sc-shadow-1);
|
|
300
|
+
color: var(--sc-muted, #6b6b73);
|
|
301
|
+
cursor: pointer;
|
|
302
|
+
transition: color 120ms ease;
|
|
295
303
|
}
|
|
296
304
|
|
|
297
|
-
.sc-
|
|
298
|
-
|
|
305
|
+
.sc-disc:hover:not(:disabled) {
|
|
306
|
+
color: var(--sc-text, #1a1a1c);
|
|
299
307
|
}
|
|
300
308
|
|
|
301
|
-
.sc-
|
|
302
|
-
|
|
309
|
+
.sc-disc:disabled {
|
|
310
|
+
opacity: 0.6;
|
|
311
|
+
cursor: default;
|
|
303
312
|
}
|
|
304
313
|
|
|
305
|
-
.sc-
|
|
306
|
-
|
|
307
|
-
|
|
314
|
+
.sc-dglyph {
|
|
315
|
+
width: 13px;
|
|
316
|
+
height: 13px;
|
|
308
317
|
}
|
|
309
318
|
|
|
310
|
-
|
|
319
|
+
@keyframes sc-spin {
|
|
320
|
+
to {
|
|
321
|
+
transform: rotate(360deg);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.sc-spin {
|
|
326
|
+
animation: sc-spin 900ms linear infinite;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.sc-mrow {
|
|
330
|
+
display: flex;
|
|
331
|
+
align-items: center;
|
|
332
|
+
gap: 10px;
|
|
333
|
+
min-height: 52px;
|
|
334
|
+
padding: 4px 12px 4px 0;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.sc-mtile {
|
|
311
338
|
position: relative;
|
|
339
|
+
flex: none;
|
|
312
340
|
display: grid;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
341
|
+
place-items: center;
|
|
342
|
+
width: 38px;
|
|
343
|
+
height: 38px;
|
|
344
|
+
border-radius: 12px;
|
|
345
|
+
background: var(--sc-tray-sunk, #f6f6f7);
|
|
346
|
+
box-shadow: inset 0 0 0 1px var(--sc-line, #e9e9eb);
|
|
347
|
+
color: var(--sc-text, #1a1a1c);
|
|
317
348
|
}
|
|
318
349
|
|
|
319
|
-
.sc-
|
|
320
|
-
|
|
350
|
+
.sc-mglyph {
|
|
351
|
+
width: 24px;
|
|
352
|
+
height: 18px;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
.sc-mbadge {
|
|
321
356
|
position: absolute;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
357
|
+
right: 0;
|
|
358
|
+
bottom: 0;
|
|
359
|
+
width: 10px;
|
|
360
|
+
height: 10px;
|
|
361
|
+
border-radius: 50%;
|
|
362
|
+
transform: translate(30%, 30%);
|
|
363
|
+
box-shadow: 0 0 0 2.5px var(--sc-tray-card, #ffffff);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
.sc-mbadge-ok {
|
|
367
|
+
background: var(--sc-ok, #22a06b);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.sc-mbadge-busy {
|
|
371
|
+
background: var(--sc-warn, #b06f14);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.sc-mbadge-off {
|
|
326
375
|
background: var(--sc-line-2, #dcdce0);
|
|
327
376
|
}
|
|
328
377
|
|
|
329
|
-
.sc-
|
|
330
|
-
|
|
378
|
+
.sc-mid {
|
|
379
|
+
display: flex;
|
|
380
|
+
flex: 1;
|
|
381
|
+
min-width: 0;
|
|
382
|
+
flex-direction: column;
|
|
383
|
+
gap: 1px;
|
|
331
384
|
}
|
|
332
385
|
|
|
333
|
-
.sc-
|
|
334
|
-
|
|
335
|
-
|
|
386
|
+
.sc-mname {
|
|
387
|
+
overflow: hidden;
|
|
388
|
+
text-overflow: ellipsis;
|
|
389
|
+
white-space: nowrap;
|
|
390
|
+
font-size: var(--sc-fs-small);
|
|
391
|
+
font-weight: 550;
|
|
336
392
|
}
|
|
337
393
|
|
|
338
|
-
.sc-
|
|
339
|
-
|
|
394
|
+
.sc-mmeta {
|
|
395
|
+
display: flex;
|
|
396
|
+
flex-wrap: wrap;
|
|
397
|
+
align-items: center;
|
|
398
|
+
gap: 1px 6px;
|
|
399
|
+
font-size: var(--sc-fs-label);
|
|
400
|
+
line-height: 1.35;
|
|
401
|
+
color: var(--sc-muted, #6b6b73);
|
|
340
402
|
}
|
|
341
403
|
|
|
342
|
-
.sc-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
404
|
+
.sc-mmeta-sep {
|
|
405
|
+
padding-right: 6px;
|
|
406
|
+
color: var(--sc-line-2, #dcdce0);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
.sc-arow {
|
|
410
|
+
display: flex;
|
|
411
|
+
align-items: center;
|
|
412
|
+
gap: 10px;
|
|
413
|
+
min-height: 30px;
|
|
414
|
+
padding-right: 12px;
|
|
350
415
|
}
|
|
351
416
|
|
|
352
417
|
.sc-runtime-tile {
|
|
353
|
-
width: 22px;
|
|
354
|
-
height: 22px;
|
|
355
418
|
flex: none;
|
|
356
419
|
display: grid;
|
|
357
420
|
place-items: center;
|
|
421
|
+
width: 22px;
|
|
422
|
+
height: 22px;
|
|
358
423
|
border-radius: var(--sc-r-sm, 6px);
|
|
359
424
|
border: 1px solid var(--sc-line, #e9e9eb);
|
|
360
|
-
background: var(--sc-
|
|
425
|
+
background: var(--sc-tray-sunk, #f6f6f7);
|
|
361
426
|
}
|
|
362
427
|
|
|
363
428
|
.sc-runtime-mark {
|
|
@@ -366,16 +431,200 @@ a.sc-btn {
|
|
|
366
431
|
color: var(--sc-text-2, #3f3f46);
|
|
367
432
|
}
|
|
368
433
|
|
|
369
|
-
.sc-
|
|
434
|
+
.sc-aname {
|
|
435
|
+
flex: 1;
|
|
436
|
+
min-width: 0;
|
|
437
|
+
overflow: hidden;
|
|
438
|
+
text-overflow: ellipsis;
|
|
439
|
+
white-space: nowrap;
|
|
440
|
+
font-size: var(--sc-fs-small);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.sc-aversion {
|
|
444
|
+
color: var(--sc-muted, #6b6b73);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.sc-averdict {
|
|
448
|
+
flex: none;
|
|
449
|
+
display: inline-flex;
|
|
450
|
+
align-items: center;
|
|
370
451
|
font-size: var(--sc-fs-label);
|
|
371
452
|
white-space: nowrap;
|
|
453
|
+
color: var(--sc-muted, #6b6b73);
|
|
372
454
|
}
|
|
373
455
|
|
|
374
|
-
.sc-
|
|
456
|
+
.sc-orow {
|
|
457
|
+
display: flex;
|
|
458
|
+
align-items: center;
|
|
459
|
+
gap: 10px;
|
|
460
|
+
min-height: 34px;
|
|
461
|
+
padding-right: 12px;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
.sc-otile {
|
|
465
|
+
flex: none;
|
|
466
|
+
display: grid;
|
|
467
|
+
place-items: center;
|
|
468
|
+
width: 22px;
|
|
469
|
+
height: 22px;
|
|
470
|
+
border-radius: var(--sc-r-sm, 6px);
|
|
471
|
+
background: var(--sc-tray-sunk, #f6f6f7);
|
|
472
|
+
color: var(--sc-muted, #6b6b73);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
.sc-otile .sc-mglyph {
|
|
476
|
+
width: 15px;
|
|
477
|
+
height: 11px;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
.sc-oglyph,
|
|
481
|
+
.sc-omark {
|
|
482
|
+
width: 13px;
|
|
483
|
+
height: 13px;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
.sc-oname {
|
|
487
|
+
flex: 1;
|
|
375
488
|
min-width: 0;
|
|
376
489
|
overflow: hidden;
|
|
377
490
|
text-overflow: ellipsis;
|
|
378
491
|
white-space: nowrap;
|
|
492
|
+
font-size: var(--sc-fs-small);
|
|
493
|
+
color: var(--sc-text-2, #3f3f46);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
.sc-oword {
|
|
497
|
+
flex: none;
|
|
498
|
+
font-size: var(--sc-fs-label);
|
|
499
|
+
color: var(--sc-muted, #6b6b73);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
.sc-pair {
|
|
503
|
+
display: flex;
|
|
504
|
+
align-items: center;
|
|
505
|
+
gap: 10px;
|
|
506
|
+
width: calc(100% + 4px);
|
|
507
|
+
min-height: 34px;
|
|
508
|
+
margin-left: -4px;
|
|
509
|
+
padding: 0 12px 0 4px;
|
|
510
|
+
border: 0;
|
|
511
|
+
border-radius: 8px;
|
|
512
|
+
background: transparent;
|
|
513
|
+
font: inherit;
|
|
514
|
+
font-size: var(--sc-fs-small);
|
|
515
|
+
text-align: left;
|
|
516
|
+
cursor: pointer;
|
|
517
|
+
transition: background-color 120ms ease;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
.sc-pair:hover {
|
|
521
|
+
background: var(--sc-tray-sunk, #f6f6f7);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
.sc-hrow {
|
|
525
|
+
padding-bottom: 2px;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
.sc-row-note {
|
|
529
|
+
margin: 0;
|
|
530
|
+
padding: 2px 12px 4px 0;
|
|
531
|
+
font-size: var(--sc-fs-label);
|
|
532
|
+
line-height: 1.45;
|
|
533
|
+
color: var(--sc-muted, #6b6b73);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
.sc-row-act {
|
|
537
|
+
flex: none;
|
|
538
|
+
padding: 3px 9px;
|
|
539
|
+
border: 1px solid transparent;
|
|
540
|
+
border-radius: var(--sc-r-pill, 999px);
|
|
541
|
+
background: var(--sc-tray-sunk, #f6f6f7);
|
|
542
|
+
font: inherit;
|
|
543
|
+
font-size: var(--sc-fs-label);
|
|
544
|
+
font-weight: 500;
|
|
545
|
+
color: var(--sc-text-2, #3f3f46);
|
|
546
|
+
cursor: pointer;
|
|
547
|
+
white-space: nowrap;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
.sc-row-act:hover:not(:disabled) {
|
|
551
|
+
color: var(--sc-text, #1a1a1c);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
.sc-row-act:disabled {
|
|
555
|
+
opacity: 0.5;
|
|
556
|
+
cursor: default;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
.sc-tray-error {
|
|
560
|
+
margin: 0;
|
|
561
|
+
padding: 0 12px 2px;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.sc-pop {
|
|
565
|
+
position: fixed;
|
|
566
|
+
top: 0;
|
|
567
|
+
left: 0;
|
|
568
|
+
right: auto;
|
|
569
|
+
bottom: auto;
|
|
570
|
+
z-index: 2147483000;
|
|
571
|
+
width: min(92vw, 320px);
|
|
572
|
+
max-width: min(92vw, 320px);
|
|
573
|
+
|
|
574
|
+
max-height: calc(100vh - 24px);
|
|
575
|
+
overflow-y: auto;
|
|
576
|
+
overscroll-behavior: contain;
|
|
577
|
+
margin: 0;
|
|
578
|
+
padding: 0;
|
|
579
|
+
border: 0;
|
|
580
|
+
border-radius: 20px;
|
|
581
|
+
background: var(--sc-tray, #f6f6f7);
|
|
582
|
+
|
|
583
|
+
box-shadow:
|
|
584
|
+
0 0 0 1px var(--sc-line, #e9e9eb),
|
|
585
|
+
var(--sc-shadow-2);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
.sc-pop > .sc-tray {
|
|
589
|
+
background: transparent;
|
|
590
|
+
border-radius: inherit;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
@keyframes sc-pop-in {
|
|
594
|
+
from {
|
|
595
|
+
opacity: 0;
|
|
596
|
+
transform: translateY(-6px) scale(0.98);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
.sc-pop {
|
|
601
|
+
animation: sc-pop-in 120ms cubic-bezier(0.2, 0.8, 0.2, 1);
|
|
602
|
+
transform-origin: top right;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
@media (prefers-reduced-motion: reduce) {
|
|
606
|
+
.sc-pop {
|
|
607
|
+
animation: none;
|
|
608
|
+
}
|
|
609
|
+
.sc-spin {
|
|
610
|
+
animation: none;
|
|
611
|
+
}
|
|
612
|
+
.sc-pair {
|
|
613
|
+
transition: none;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
.sc-compute-act {
|
|
618
|
+
margin-top: 16px;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
.sc-compute-act:first-child {
|
|
622
|
+
margin-top: 0;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
.sc-note + .sc-compute-act,
|
|
626
|
+
.sc-error + .sc-compute-act {
|
|
627
|
+
margin-top: 9px;
|
|
379
628
|
}
|
|
380
629
|
|
|
381
630
|
.soba-connect[data-theme="dark"],
|
|
@@ -402,6 +651,10 @@ a.sc-btn {
|
|
|
402
651
|
--sc-ok: #4cb782;
|
|
403
652
|
--sc-warn: #f2994a;
|
|
404
653
|
|
|
654
|
+
--sc-tray: var(--sc-ground, #0f0f11);
|
|
655
|
+
--sc-tray-card: var(--sc-raised, #1d1d20);
|
|
656
|
+
--sc-tray-sunk: var(--sc-sheet, #161618);
|
|
657
|
+
|
|
405
658
|
--sc-shadow-1: 0 1px 2px rgb(0 0 0 / 34%);
|
|
406
659
|
--sc-shadow-2: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px -12px rgb(0 0 0 / 64%);
|
|
407
660
|
}
|
|
@@ -423,6 +676,10 @@ a.sc-btn {
|
|
|
423
676
|
--sc-ok: #4cb782;
|
|
424
677
|
--sc-warn: #f2994a;
|
|
425
678
|
|
|
679
|
+
--sc-tray: var(--sc-ground, #0f0f11);
|
|
680
|
+
--sc-tray-card: var(--sc-raised, #1d1d20);
|
|
681
|
+
--sc-tray-sunk: var(--sc-sheet, #161618);
|
|
682
|
+
|
|
426
683
|
--sc-shadow-1: 0 1px 2px rgb(0 0 0 / 34%);
|
|
427
684
|
--sc-shadow-2: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px -12px rgb(0 0 0 / 64%);
|
|
428
685
|
}
|
|
@@ -760,22 +1017,6 @@ a.sc-btn {
|
|
|
760
1017
|
box-shadow: none;
|
|
761
1018
|
}
|
|
762
1019
|
|
|
763
|
-
.sc-modal-sheet .sc-machine {
|
|
764
|
-
border: 1px solid var(--sc-line, #e9e9eb);
|
|
765
|
-
border-radius: var(--sc-r, 10px);
|
|
766
|
-
padding: 11px 12px;
|
|
767
|
-
margin-top: 14px;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
.sc-conns {
|
|
771
|
-
display: grid;
|
|
772
|
-
gap: 14px;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
.sc-modal-sheet .sc-machine:first-child {
|
|
776
|
-
margin-top: 0;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
1020
|
.sc-modal-sheet .sc-title {
|
|
780
1021
|
font-size: 17px;
|
|
781
1022
|
font-weight: 600;
|
|
@@ -1015,51 +1256,6 @@ a.sc-btn {
|
|
|
1015
1256
|
color: var(--sc-text, #1a1a1c);
|
|
1016
1257
|
}
|
|
1017
1258
|
|
|
1018
|
-
.sc-conn,
|
|
1019
|
-
.sc-idrow {
|
|
1020
|
-
display: grid;
|
|
1021
|
-
grid-template-columns: auto 1fr auto;
|
|
1022
|
-
align-items: center;
|
|
1023
|
-
gap: 12px;
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
.sc-conn {
|
|
1027
|
-
padding: 10px 12px;
|
|
1028
|
-
border: 1px solid var(--sc-line, #e9e9eb);
|
|
1029
|
-
border-radius: var(--sc-r, 10px);
|
|
1030
|
-
background: var(--sc-sheet, #ffffff);
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
.sc-conn-note {
|
|
1034
|
-
grid-column: 1 / -1;
|
|
1035
|
-
margin: 2px 0 0;
|
|
1036
|
-
font-size: 12px;
|
|
1037
|
-
line-height: 1.4;
|
|
1038
|
-
color: var(--sc-muted, #6b6b73);
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
.sc-conn-action {
|
|
1042
|
-
font: inherit;
|
|
1043
|
-
font-size: var(--sc-fs-small);
|
|
1044
|
-
font-weight: 500;
|
|
1045
|
-
padding: 5px 9px;
|
|
1046
|
-
border: 1px solid transparent;
|
|
1047
|
-
border-radius: var(--sc-r-sm, 6px);
|
|
1048
|
-
background: transparent;
|
|
1049
|
-
color: var(--sc-muted, #6b6b73);
|
|
1050
|
-
cursor: pointer;
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
.sc-conn-action:hover:not(:disabled) {
|
|
1054
|
-
border-color: var(--sc-line-2, #dcdce0);
|
|
1055
|
-
color: var(--sc-text, #1a1a1c);
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
.sc-conn-action:disabled {
|
|
1059
|
-
opacity: 0.5;
|
|
1060
|
-
cursor: default;
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
1259
|
.sc-btn-wide {
|
|
1064
1260
|
width: 100%;
|
|
1065
1261
|
}
|
|
@@ -1204,8 +1400,7 @@ a.sc-btn {
|
|
|
1204
1400
|
}
|
|
1205
1401
|
|
|
1206
1402
|
.sc-result-ok {
|
|
1207
|
-
|
|
1208
|
-
color: var(--sc-text, #1a1a1c);
|
|
1403
|
+
color: var(--sc-ok, #22a06b);
|
|
1209
1404
|
}
|
|
1210
1405
|
|
|
1211
1406
|
.sc-result-off {
|
|
@@ -1329,7 +1524,9 @@ a.sc-btn {
|
|
|
1329
1524
|
.sc-step-lead:focus-visible,
|
|
1330
1525
|
.sc-step-links a:focus-visible,
|
|
1331
1526
|
.sc-alt-link:focus-visible,
|
|
1332
|
-
.sc-
|
|
1527
|
+
.sc-row-act:focus-visible,
|
|
1528
|
+
.sc-disc:focus-visible,
|
|
1529
|
+
.sc-pair:focus-visible,
|
|
1333
1530
|
.sc-input:focus-visible,
|
|
1334
1531
|
.sc-modal-close:focus-visible {
|
|
1335
1532
|
outline: 2px solid var(--sc-accent, #18181b);
|
|
@@ -1380,7 +1577,7 @@ a.sc-btn {
|
|
|
1380
1577
|
max-width: 100%;
|
|
1381
1578
|
min-width: 0;
|
|
1382
1579
|
|
|
1383
|
-
padding:
|
|
1580
|
+
padding: 3px 12px 3px 3px;
|
|
1384
1581
|
border-radius: var(--sc-r-pill, 999px);
|
|
1385
1582
|
border-color: var(--sc-line, #e9e9eb);
|
|
1386
1583
|
|
|
@@ -1404,14 +1601,33 @@ a.sc-btn {
|
|
|
1404
1601
|
transform: translateY(0.5px);
|
|
1405
1602
|
}
|
|
1406
1603
|
|
|
1407
|
-
.sc-
|
|
1604
|
+
.sc-pill-tile {
|
|
1605
|
+
flex: none;
|
|
1606
|
+
display: grid;
|
|
1607
|
+
place-items: center;
|
|
1608
|
+
width: 26px;
|
|
1609
|
+
height: 26px;
|
|
1408
1610
|
border-radius: 50%;
|
|
1611
|
+
background: var(--sc-raised, #f6f6f7);
|
|
1612
|
+
box-shadow: inset 0 0 0 1px var(--sc-line, #e9e9eb);
|
|
1613
|
+
color: var(--sc-text, #1a1a1c);
|
|
1409
1614
|
}
|
|
1410
1615
|
|
|
1411
|
-
.sc-btn-connected:hover .sc-
|
|
1616
|
+
.sc-btn-connected:hover .sc-pill-tile {
|
|
1412
1617
|
background: var(--sc-sheet, #ffffff);
|
|
1413
1618
|
}
|
|
1414
1619
|
|
|
1620
|
+
.sc-pill-mark {
|
|
1621
|
+
width: 16px;
|
|
1622
|
+
height: 16px;
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
1626
|
+
.sc-pill-mark-busy {
|
|
1627
|
+
animation: sc-spin 2400ms linear infinite;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1415
1631
|
.sc-btn-connected .sc-dot {
|
|
1416
1632
|
flex: none;
|
|
1417
1633
|
margin-left: 1px;
|
|
@@ -2409,13 +2625,13 @@ li.sc-plan-row.sc-plan-current {
|
|
|
2409
2625
|
}
|
|
2410
2626
|
}
|
|
2411
2627
|
|
|
2412
|
-
.sc-modal-sheet .sc-
|
|
2628
|
+
.sc-modal-sheet .sc-tray {
|
|
2413
2629
|
animation: sc-arrive 200ms cubic-bezier(0.2, 0.8, 0.2, 1) 60ms both;
|
|
2414
2630
|
}
|
|
2415
2631
|
|
|
2416
2632
|
@media (prefers-reduced-motion: reduce) {
|
|
2417
2633
|
.sc-modal-sheet .sc-card,
|
|
2418
|
-
.sc-modal-sheet .sc-
|
|
2634
|
+
.sc-modal-sheet .sc-tray {
|
|
2419
2635
|
animation: none;
|
|
2420
2636
|
}
|
|
2421
2637
|
.sc-modal-sheet {
|
|
@@ -2440,303 +2656,4 @@ li.sc-plan-row.sc-plan-current {
|
|
|
2440
2656
|
.sc-opt-has-warn {
|
|
2441
2657
|
color: var(--sc-warn, #b06f14);
|
|
2442
2658
|
}
|
|
2443
|
-
|
|
2444
|
-
.bx * {
|
|
2445
|
-
transform-box: view-box;
|
|
2446
|
-
}
|
|
2447
|
-
|
|
2448
|
-
.bx-arc,
|
|
2449
|
-
.bx-st,
|
|
2450
|
-
.bx-z1 path,
|
|
2451
|
-
.bx-z2 path,
|
|
2452
|
-
.bx-ob path {
|
|
2453
|
-
stroke-width: var(--bx-w, 17);
|
|
2454
|
-
}
|
|
2455
|
-
|
|
2456
|
-
.bx[data-expression="thinking"] .bx-arc,
|
|
2457
|
-
.bx[data-expression="paused"] .bx-arc,
|
|
2458
|
-
.bx[data-expression="attention"] .bx-arc,
|
|
2459
|
-
.bx[data-expression="connecting"] .bx-arc,
|
|
2460
|
-
.bx[data-expression="gone"] .bx-arc,
|
|
2461
|
-
.bx[data-expression="snap"] .bx-arc,
|
|
2462
|
-
.bx[data-expression="listening"] .bx-arc,
|
|
2463
|
-
.bx[data-expression="permission"] .bx-arc,
|
|
2464
|
-
.bx[data-expression="ai"] .bx-arc {
|
|
2465
|
-
display: none;
|
|
2466
|
-
}
|
|
2467
|
-
|
|
2468
|
-
@keyframes bx-stream {
|
|
2469
|
-
to {
|
|
2470
|
-
stroke-dashoffset: -62;
|
|
2471
|
-
}
|
|
2472
|
-
}
|
|
2473
|
-
|
|
2474
|
-
.bx-st {
|
|
2475
|
-
animation: bx-stream 0.9s linear infinite;
|
|
2476
|
-
}
|
|
2477
|
-
|
|
2478
|
-
@keyframes bx-think {
|
|
2479
|
-
0%,
|
|
2480
|
-
100% {
|
|
2481
|
-
opacity: 0.26;
|
|
2482
|
-
}
|
|
2483
|
-
33% {
|
|
2484
|
-
opacity: 1;
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
|
|
2488
|
-
.bx-th {
|
|
2489
|
-
opacity: 0.26;
|
|
2490
|
-
animation: bx-think 1.2s ease-in-out infinite;
|
|
2491
|
-
}
|
|
2492
|
-
|
|
2493
|
-
.bx-th2 {
|
|
2494
|
-
animation-delay: 0.4s;
|
|
2495
|
-
}
|
|
2496
|
-
|
|
2497
|
-
.bx-th3 {
|
|
2498
|
-
animation-delay: 0.8s;
|
|
2499
|
-
}
|
|
2500
|
-
|
|
2501
|
-
@keyframes bx-att {
|
|
2502
|
-
0%,
|
|
2503
|
-
80%,
|
|
2504
|
-
100% {
|
|
2505
|
-
transform: rotate(0);
|
|
2506
|
-
}
|
|
2507
|
-
85% {
|
|
2508
|
-
transform: rotate(-8deg);
|
|
2509
|
-
}
|
|
2510
|
-
95% {
|
|
2511
|
-
transform: rotate(8deg);
|
|
2512
|
-
}
|
|
2513
|
-
}
|
|
2514
|
-
|
|
2515
|
-
.bx-at {
|
|
2516
|
-
|
|
2517
|
-
transform-box: fill-box;
|
|
2518
|
-
transform-origin: 50% 100%;
|
|
2519
|
-
animation: bx-att 2s ease-in-out infinite;
|
|
2520
|
-
}
|
|
2521
|
-
|
|
2522
|
-
@keyframes bx-z {
|
|
2523
|
-
0% {
|
|
2524
|
-
opacity: 0;
|
|
2525
|
-
transform: translate(0, 12px);
|
|
2526
|
-
}
|
|
2527
|
-
25%,
|
|
2528
|
-
70% {
|
|
2529
|
-
opacity: 1;
|
|
2530
|
-
transform: translate(0, 0);
|
|
2531
|
-
}
|
|
2532
|
-
100% {
|
|
2533
|
-
opacity: 0;
|
|
2534
|
-
transform: translate(8px, -16px);
|
|
2535
|
-
}
|
|
2536
|
-
}
|
|
2537
|
-
|
|
2538
|
-
.bx-z1 {
|
|
2539
|
-
animation: bx-z 3s ease-in-out infinite;
|
|
2540
|
-
}
|
|
2541
|
-
|
|
2542
|
-
.bx-z2 {
|
|
2543
|
-
animation: bx-z 3s ease-in-out 0.75s infinite;
|
|
2544
|
-
}
|
|
2545
|
-
|
|
2546
|
-
@keyframes bx-orb {
|
|
2547
|
-
to {
|
|
2548
|
-
transform: rotate(360deg);
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
|
|
2552
|
-
.bx-ob {
|
|
2553
|
-
transform-origin: 278px 400px;
|
|
2554
|
-
animation: bx-orb 1.15s cubic-bezier(0.45, 0, 0.55, 1) infinite;
|
|
2555
|
-
}
|
|
2556
|
-
|
|
2557
|
-
@keyframes bx-xa {
|
|
2558
|
-
0% {
|
|
2559
|
-
opacity: 0;
|
|
2560
|
-
transform: translateX(0);
|
|
2561
|
-
}
|
|
2562
|
-
8%,
|
|
2563
|
-
22% {
|
|
2564
|
-
opacity: 1;
|
|
2565
|
-
transform: translateX(0);
|
|
2566
|
-
}
|
|
2567
|
-
45%,
|
|
2568
|
-
100% {
|
|
2569
|
-
opacity: 0;
|
|
2570
|
-
transform: translateX(40px);
|
|
2571
|
-
}
|
|
2572
|
-
}
|
|
2573
|
-
|
|
2574
|
-
.bx-xa {
|
|
2575
|
-
opacity: 0;
|
|
2576
|
-
animation: bx-xa 3.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
|
|
2577
|
-
}
|
|
2578
|
-
|
|
2579
|
-
@keyframes bx-xx {
|
|
2580
|
-
0%,
|
|
2581
|
-
40% {
|
|
2582
|
-
opacity: 0;
|
|
2583
|
-
transform: scale(0.4);
|
|
2584
|
-
}
|
|
2585
|
-
54% {
|
|
2586
|
-
opacity: 1;
|
|
2587
|
-
transform: scale(1.08);
|
|
2588
|
-
}
|
|
2589
|
-
60%,
|
|
2590
|
-
90% {
|
|
2591
|
-
opacity: 1;
|
|
2592
|
-
transform: scale(1);
|
|
2593
|
-
}
|
|
2594
|
-
100% {
|
|
2595
|
-
opacity: 0;
|
|
2596
|
-
transform: scale(1);
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
|
|
2600
|
-
.bx-xx {
|
|
2601
|
-
transform-box: fill-box;
|
|
2602
|
-
transform-origin: center;
|
|
2603
|
-
animation: bx-xx 3.2s ease-out infinite;
|
|
2604
|
-
}
|
|
2605
|
-
|
|
2606
|
-
@keyframes bx-voice {
|
|
2607
|
-
0%,
|
|
2608
|
-
100% {
|
|
2609
|
-
transform: scaleY(0.45);
|
|
2610
|
-
}
|
|
2611
|
-
50% {
|
|
2612
|
-
transform: scaleY(1);
|
|
2613
|
-
}
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
.bx-vb {
|
|
2617
|
-
transform-box: fill-box;
|
|
2618
|
-
transform-origin: center;
|
|
2619
|
-
animation: bx-voice 0.9s ease-in-out infinite;
|
|
2620
|
-
}
|
|
2621
|
-
|
|
2622
|
-
.bx-vb2 {
|
|
2623
|
-
animation-delay: 0.15s;
|
|
2624
|
-
}
|
|
2625
|
-
|
|
2626
|
-
.bx-vb3 {
|
|
2627
|
-
animation-delay: 0.3s;
|
|
2628
|
-
}
|
|
2629
|
-
|
|
2630
|
-
@keyframes bx-wait {
|
|
2631
|
-
0% {
|
|
2632
|
-
opacity: 1;
|
|
2633
|
-
}
|
|
2634
|
-
100% {
|
|
2635
|
-
opacity: 0.15;
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
|
|
2639
|
-
.bx-w {
|
|
2640
|
-
opacity: 0.15;
|
|
2641
|
-
animation: bx-wait 1.2s linear infinite;
|
|
2642
|
-
}
|
|
2643
|
-
|
|
2644
|
-
@keyframes bx-spark {
|
|
2645
|
-
0%,
|
|
2646
|
-
100% {
|
|
2647
|
-
transform: scale(1) rotate(0);
|
|
2648
|
-
}
|
|
2649
|
-
50% {
|
|
2650
|
-
transform: scale(0.7) rotate(22deg);
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
|
|
2654
|
-
.bx-sp {
|
|
2655
|
-
transform-box: fill-box;
|
|
2656
|
-
transform-origin: center;
|
|
2657
|
-
animation: bx-spark 2.6s ease-in-out infinite;
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2660
|
-
.bx-sp2 {
|
|
2661
|
-
animation-delay: -0.87s;
|
|
2662
|
-
}
|
|
2663
|
-
|
|
2664
|
-
.bx-sp3 {
|
|
2665
|
-
animation-delay: -1.73s;
|
|
2666
|
-
}
|
|
2667
|
-
|
|
2668
|
-
@keyframes bx-snap {
|
|
2669
|
-
0%,
|
|
2670
|
-
6% {
|
|
2671
|
-
transform: translateX(90px);
|
|
2672
|
-
opacity: 0;
|
|
2673
|
-
}
|
|
2674
|
-
24% {
|
|
2675
|
-
transform: translateX(-10px);
|
|
2676
|
-
opacity: 1;
|
|
2677
|
-
}
|
|
2678
|
-
30% {
|
|
2679
|
-
transform: translateX(4px);
|
|
2680
|
-
}
|
|
2681
|
-
35%,
|
|
2682
|
-
100% {
|
|
2683
|
-
transform: translateX(0);
|
|
2684
|
-
opacity: 1;
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
|
|
2688
|
-
.bx-snap {
|
|
2689
|
-
animation: bx-snap 3.6s cubic-bezier(0.3, 0, 0.2, 1) infinite;
|
|
2690
|
-
}
|
|
2691
|
-
|
|
2692
|
-
@media (prefers-reduced-motion: reduce) {
|
|
2693
|
-
.bx .bx-st,
|
|
2694
|
-
.bx .bx-th,
|
|
2695
|
-
.bx .bx-at,
|
|
2696
|
-
.bx .bx-z1,
|
|
2697
|
-
.bx .bx-z2,
|
|
2698
|
-
.bx .bx-ob,
|
|
2699
|
-
.bx .bx-xa,
|
|
2700
|
-
.bx .bx-xx,
|
|
2701
|
-
.bx .bx-snap,
|
|
2702
|
-
.bx .bx-vb,
|
|
2703
|
-
.bx .bx-w,
|
|
2704
|
-
.bx .bx-sp {
|
|
2705
|
-
animation: none;
|
|
2706
|
-
}
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
.bx .bx-th,
|
|
2710
|
-
.bx .bx-z1,
|
|
2711
|
-
.bx .bx-z2,
|
|
2712
|
-
.bx .bx-xx,
|
|
2713
|
-
.bx .bx-snap,
|
|
2714
|
-
.bx .bx-w {
|
|
2715
|
-
opacity: 1;
|
|
2716
|
-
transform: none;
|
|
2717
|
-
}
|
|
2718
|
-
}
|
|
2719
|
-
|
|
2720
|
-
[data-version="v1"] .bx .bx-arc {
|
|
2721
|
-
display: revert;
|
|
2722
|
-
}
|
|
2723
|
-
|
|
2724
|
-
[data-version="v1"] .bx .bx-st,
|
|
2725
|
-
[data-version="v1"] .bx .bx-th,
|
|
2726
|
-
[data-version="v1"] .bx .bx-at,
|
|
2727
|
-
[data-version="v1"] .bx .bx-z1,
|
|
2728
|
-
[data-version="v1"] .bx .bx-z2,
|
|
2729
|
-
[data-version="v1"] .bx .bx-ob,
|
|
2730
|
-
[data-version="v1"] .bx .bx-xa,
|
|
2731
|
-
[data-version="v1"] .bx .bx-xx,
|
|
2732
|
-
[data-version="v1"] .bx .bx-snap,
|
|
2733
|
-
[data-version="v1"] .bx .bx-vb,
|
|
2734
|
-
[data-version="v1"] .bx .bx-w,
|
|
2735
|
-
[data-version="v1"] .bx .bx-sp {
|
|
2736
|
-
display: none;
|
|
2737
|
-
}
|
|
2738
|
-
|
|
2739
|
-
[data-version="v1"] .sc-result-ok {
|
|
2740
|
-
color: var(--sc-ok, #22a06b);
|
|
2741
|
-
}
|
|
2742
|
-
`,document.head.appendChild(e)}import{jsx as ge,jsxs as xn}from"react/jsx-runtime";function br(e){if(!e)return null;let n=Be(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 Rs(){return xn("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[ge("path",{d:"M8 5v4",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),ge("circle",{cx:"8",cy:"11.6",r:"0.9",fill:"currentColor"}),ge("circle",{cx:"8",cy:"8",r:"6.4",stroke:"currentColor",strokeWidth:"1.3"})]})}function Ls({error:e,onRetry:n,onDismiss:t,title:r,className:s}){let a=br(e),i=I();return Ms(()=>kn(),[]),a?ge("div",{className:s?`soba-connect ${s}`:"soba-connect","data-theme":i.theme,role:"alert",children:xn("div",{className:"sc-card sc-limit sc-run-error",children:[xn("div",{className:"sc-limit-head",children:[ge("span",{className:"sc-limit-mark sc-run-error-mark","aria-hidden":"true",children:ge(Rs,{})}),xn("div",{children:[ge("h2",{className:"sc-limit-title",children:r??"That run did not finish"}),ge("p",{className:"sc-limit-body sc-run-error-message",children:a})]})]}),(t||n)&&xn("div",{className:"sc-limit-actions",children:[t&&ge("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,children:"Dismiss"}),n&&ge("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:n,children:"Try again"})]})]})}):null}import{useId as Os,useState as yr}from"react";import{jsx as z,jsxs as Un}from"react/jsx-runtime";function Ts({reason:e}){return z("span",{className:"sc-limit-mark","aria-hidden":"true",children:e==="no_compute"?z(Ze,{}):z(V,{})})}function Is(e){let{error:n,variant:t="card",onDismiss:r,className:s}=e,a=Pt(n,{predict:e.predict??!("error"in e)}),i=Os(),u=I();if(!a)return null;let l=z(As,{offer:a,headingId:i,onDismiss:r});return t==="dialog"?z(wn,{open:!0,onClose:()=>r?.(),labelledBy:i,theme:u.theme,children:l}):z("div",{className:s?`soba-connect ${s}`:"soba-connect","data-theme":u.theme,children:l})}function As({offer:e,headingId:n,onDismiss:t}){let{compute:r}=D(),[s,a]=yr(!1),[i,u]=yr(null),l=e.reason==="no_compute"&&r.connected&&!r.online,p=l||e.connectOffer!==null||!r.connected,f=$n();async function g(){a(!0),u(null);try{await e.upgrade()}catch(m){u(m.message)}finally{a(!1)}}return Un("div",{className:"sc-card sc-limit",children:[Un("div",{className:"sc-limit-head",children:[z(Ts,{reason:e.reason}),Un("div",{children:[z("h2",{className:"sc-limit-title",id:n,children:e.title}),z("p",{className:"sc-limit-body",children:e.body})]})]}),i&&z("p",{className:"sc-error",children:i}),l&&f.note&&z("p",{className:"sc-limit-note",children:f.note}),Un("div",{className:"sc-limit-actions",children:[t&&z("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,disabled:s,children:"Not now"}),e.upgradeTo&&z("button",{type:"button",className:p?"sc-btn":"sc-btn sc-btn-primary",onClick:()=>void g(),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}`}),p&&z("button",{type:"button",className:l?"sc-btn":"sc-btn sc-btn-primary",onClick:e.connect,disabled:s,children:l?"Connect another machine":"Connect compute"}),l&&z("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:f.open,disabled:s,children:"Open Soba App"})]})]})}import{useMemo as $s}from"react";function Sn(){let{plan:e,compute:n,connect:t}=D();return $s(()=>{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 i=Hs(s?.trial_ends_at??null),u=r.connected_reward==="included"&&n.connected&&r.connected_included_units!==null,l=u?r.connected_included_units:r.included_units,p=r.connected_reward==="unlimited"&&n.connected,f=l===null,g=e.used??0,m=l===null?null:Math.max(0,l-g),b=l&&l>0?Math.min(100,Math.round(g/l*100)):null,h=l!==null&&g>=l,k=i!==null?"trial":f?"unlimited":h?r.overage==="meter"?"metered":"spent":"within";return{...a,state:k,trialDaysLeft:i,ceiling:l,raised:u,uncounted:p,used:g,remaining:m,percent:b,unlimited:f,reward:Ds(r,u||p,n.connected,()=>t.open("manual")),summary:Us({plan:r,assignment:s,used:g,ceiling:l,trialDaysLeft:i,raised:u,uncounted:p,state:k})}},[e,n.connected,t])}function Ds(e,n,t,r){let s=ve({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:Ce(e.connected_reward)&&!t,open:r}:ie(e.route_allow)&&!t?{line:"Nothing connected yet, so nothing can run.",inForce:!1,required:!0,connected:t,actionable:!0,open:r}:null}function Us(e){let{plan:n,assignment:t,used:r,ceiling:s,trialDaysLeft:a,raised:i,uncounted:u,state:l}=e,p=`${n.unit}${r===1?"":"s"}`,f=u?" Runs your own AI serves do not count toward it.":"";if(l==="trial"&&a!==null){let b=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 ${b}.`}if(l==="unlimited")return`${r.toLocaleString()} ${p} this period. No ceiling on this plan.`;if(l==="metered"){let b=r-(s??0);return n.overage_per_unit>0?`${b.toLocaleString()} past the allowance, billed at $${n.overage_per_unit} a ${n.unit}.${f}`:`${b.toLocaleString()} past the allowance.${f}`}if(l==="spent")return t?.period_end?`Allowance spent. It comes back on ${wr(t.period_end)}.${f}`:`Allowance spent. It comes back at the start of the next period.${f}`;let g=Math.max(0,(s??0)-r),m=i?` Raised from ${(n.included_units??0).toLocaleString()} while your own AI is connected.`:t?.period_end?` Resets ${wr(t.period_end)}.`:"";return`${g.toLocaleString()} of ${(s??0).toLocaleString()} ${n.unit}s left.${m}${f}`}function Hs(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 wr(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}import{Fragment as Bs,jsx as K,jsxs as le}from"react/jsx-runtime";function Rt({heading:e="Current plan",showUsage:n=!0,showName:t=!0,className:r}){let s=Sn(),{theme:a}=I(),i=m=>K("section",{className:r?`soba-connect sc-fill ${r}`:"soba-connect sc-fill","data-theme":a,children:le("div",{className:"sc-card sc-current",children:[e&&K("h2",{className:"sc-section-title",children:e}),m]})});if(s.error)return i(K("p",{className:"sc-error",children:s.error.message}));if(s.loading)return i(K("p",{className:"sc-note",children:"Loading\u2026"}));if(!s.plan)return i(le("div",{className:"sc-current-main",children:[K("p",{className:"sc-current-name",children:"No plan"}),K("p",{className:"sc-sub",children:s.summary})]}));let{plan:u,trialDaysLeft:l,percent:p,unlimited:f,reward:g}=s;return i(le(Bs,{children:[le("div",{className:"sc-current-grid",children:[(t||l!==null)&&le("div",{className:"sc-current-main",children:[t?le("p",{className:"sc-current-name",children:[u.name,l!==null&&le("span",{className:"sc-trial-badge",children:[l," ",l===1?"day":"days"," left"]})]}):l!==null&&K("p",{className:"sc-current-trial",children:le("span",{className:"sc-trial-badge",children:[l," ",l===1?"day":"days"," left"]})}),t&&u.description&&K("p",{className:"sc-sub",children:u.description})]}),n&&le("div",{className:"sc-usage",children:[le("div",{className:"sc-row-between",children:[K("span",{className:"sc-fact-key",children:"Usage"}),K("span",{className:p!==null&&p>=100?"sc-usage-figure sc-usage-over":"sc-usage-figure",children:f?"Unlimited":p===null?"Metered":`${p}% used`})]}),p!==null&&K("div",{className:"sc-meter",role:"presentation",children:p>0&&K("span",{className:p>=100?"sc-meter-fill sc-meter-full":"sc-meter-fill",style:{width:`${p}%`}})}),K("p",{className:"sc-usage-line",children:s.summary})]})]}),g&&le("div",{className:"sc-current-foot",children:[K("p",{className:g.required?"sc-plan-reward-line sc-plan-reward-need":g.inForce?"sc-plan-reward-line":"sc-plan-reward-line sc-plan-reward-open",children:g.required?g.line:g.inForce?`In force: ${qs(g.line)}.`:g.line}),(g.actionable||g.connected)&&K(qe,{})]})]}))}var qs=e=>e.charAt(0).toLowerCase()+e.slice(1);import{useCallback as Fs,useMemo as Ws,useState as vr}from"react";var Gs={"user-hardware":"your own machine","user-subscription":"your own AI subscription","open-weights":"open models we host",frontier:"frontier models"},Vs=new Set(["user-hardware","user-subscription"]);function Lt(e={}){let{plan:n,compute:t,connect:r}=D(),[s,a]=vr(null),[i,u]=vr(null),{featured:l,onSelect:p,successUrl:f,cancelUrl:g}=e,m=Fs(async h=>{a(h.id),u(null);try{if(h.selectable)await n.select(h.id);else if(p)p(h);else{let k=await n.checkout(h.id,{...f?{successUrl:f}:{},...g?{cancelUrl:g}:{}});window.location.assign(k);return}}catch(k){throw u(k.message),k}finally{(h.selectable||p)&&a(null)}},[n,p,f,g]),b=Ws(()=>n.plans.map(h=>{let k=n.current?.plan_id===h.id;return{plan:h,current:k,featured:l===h.id&&!k,price:zs(h),allowance:h.included_units===null?`Unlimited ${h.unit}s`:`${h.included_units.toLocaleString()} ${h.unit}${h.included_units===1?"":"s"}`,allowanceNote:Ks(h),computeLabel:h.route_allow===null?"any compute":h.route_allow.length===0?"no compute":null,compute:(h.route_allow??[]).map(N=>({costClass:N,label:Gs[N]??N,owned:Vs.has(N),runtimes:Qn(N).map(x=>x.id)})),connect:js(h,k,t.connected,()=>r.open("manual")),cta:{label:Ys(h,k,s===h.id),disabled:k||s!==null,busy:s===h.id,take:()=>m(h)}}}),[n.plans,n.current,l,t.connected,r,s,m]);return{offers:b,current:b.find(h=>h.current)??null,loading:n.loading,error:n.error,failed:i}}function zs(e){return e.price===0?{amount:"Free",interval:null,free:!0}:{amount:`$${e.price.toLocaleString()}`,interval:e.interval,free:!1}}function Ks(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 js(e,n,t,r){let s=ve({unit:e.unit,reward:e.connected_reward,includedUnits:e.connected_included_units,creditMicros:e.connected_credit*1e6}),a=ie(e.route_allow)&&!t;if(!s&&!a)return null;let i=Ce(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&&(i||a)&&!t,open:r}}function Ys(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 d,jsxs as E}from"react/jsx-runtime";function Hn(e){return e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill"}function Ot({onSelect:e,successUrl:n,cancelUrl:t,showCompute:r=!0,showConnect:s=!1,variant:a="cards",featured:i,className:u}){let{offers:l,loading:p,error:f,failed:g}=Lt({...i?{featured:i}:{},...e?{onSelect:e}:{},...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}}),{theme:m}=I();if(f)return d("div",{className:Hn(u),"data-theme":m,children:d("div",{className:"sc-card",children:d("p",{className:"sc-error",children:f.message})})});if(p)return d("div",{className:Hn(u),"data-theme":m,children:d("div",{className:"sc-card",children:d("p",{className:"sc-note",children:"Loading plans\u2026"})})});if(l.length===0)return d("div",{className:Hn(u),"data-theme":m,children:d("div",{className:"sc-card",children:d("p",{className:"sc-note",children:"This app has no plans yet."})})});let b={showCompute:r,showConnect:s};return E("div",{className:Hn(u),"data-theme":m,"data-variant":a,children:[a==="rows"?d(Zs,{offers:l,shelf:b}):a==="table"?d(Js,{offers:l,shelf:b}):d(Qs,{offers:l,shelf:b}),g&&d("p",{className:"sc-error",children:g})]})}function Qs({offers:e,shelf:n}){return d("div",{className:"sc-plans",children:e.map(t=>E("div",{className:Cr("sc-plan",t),children:[E("div",{className:"sc-row-between",children:[d("span",{className:"sc-title",children:t.plan.name}),d(Tt,{offer:t})]}),d("p",{className:"sc-sub",children:t.plan.description}),d(It,{price:t.price,free:"forever"}),d(Dt,{offer:t,shelf:n}),d(Nr,{offer:t}),d("div",{className:"sc-plan-band",children:n.showCompute&&d($t,{offer:t})}),d("div",{className:"sc-plan-band",children:d(At,{offer:t})})]},t.plan.id))})}function Zs({offers:e,shelf:n}){return d("ul",{className:"sc-plan-rows",children:e.map(t=>E("li",{className:Cr("sc-plan-row",t),children:[E("div",{className:"sc-row-main",children:[E("span",{className:"sc-row-name",children:[d("span",{className:"sc-title",children:t.plan.name}),d(Tt,{offer:t})]}),t.plan.description&&d("p",{className:"sc-sub",children:t.plan.description}),d(Nr,{offer:t}),n.showCompute&&d($t,{offer:t,inline:!0}),d(At,{offer:t,inline:!0})]}),E("div",{className:"sc-row-side",children:[d(It,{price:t.price,free:"forever",small:!0}),d(Dt,{offer:t,shelf:n})]})]},t.plan.id))})}function Js({offers:e,shelf:n}){let t=e.some(i=>i.plan.overage_per_unit>0),r=e.some(i=>i.plan.trial_days>0),s=e.some(i=>i.connect!==null),a=i=>[i.current?"sc-col-current":"",i.featured?"sc-col-featured":""].filter(Boolean).join(" ")||void 0;return d("div",{className:"sc-table-scroll",children:E("table",{className:"sc-plan-table",children:[d("thead",{children:E("tr",{children:[d("td",{}),e.map(i=>E("th",{scope:"col",className:a(i),children:[E("span",{className:"sc-row-name",children:[d("span",{className:"sc-title",children:i.plan.name}),d(Tt,{offer:i})]}),d(It,{price:i.price,small:!0})]},i.plan.id))]})}),E("tbody",{children:[E("tr",{children:[d("th",{scope:"row",children:"Included"}),e.map(i=>d("td",{className:a(i),children:i.allowance},i.plan.id))]}),t&&E("tr",{children:[d("th",{scope:"row",children:"Then"}),e.map(i=>d("td",{className:a(i),children:i.plan.overage_per_unit>0?`$${i.plan.overage_per_unit} / ${i.plan.unit}`:d("span",{className:"sc-muted-cell",children:"Stops"})},i.plan.id))]}),r&&E("tr",{children:[d("th",{scope:"row",children:"Trial"}),e.map(i=>d("td",{className:a(i),children:i.plan.trial_days>0?`${i.plan.trial_days} days`:d("span",{className:"sc-muted-cell",children:"None"})},i.plan.id))]}),n.showCompute&&E("tr",{children:[d("th",{scope:"row",children:"Runs on"}),e.map(i=>d("td",{className:a(i),children:d($t,{offer:i,bare:!0})},i.plan.id))]}),s&&E("tr",{children:[d("th",{scope:"row",children:"Connect your own"}),e.map(i=>d("td",{className:a(i),children:d(At,{offer:i,bare:!0})},i.plan.id))]}),E("tr",{className:"sc-table-buy",children:[d("td",{}),e.map(i=>d("td",{className:a(i),children:d(Dt,{offer:i,shelf:n})},i.plan.id))]})]})]})})}function Cr(e,n){return[e,n.current?"sc-plan-current":"",n.featured?"sc-plan-featured":""].filter(Boolean).join(" ")}function Tt({offer:e}){return e.current?d("span",{className:"sc-plan-badge",children:"Current"}):e.featured?d("span",{className:"sc-plan-badge-soft",children:"Recommended"}):null}function It({price:e,small:n,free:t}){return E("p",{className:n?"sc-plan-price sc-plan-price-sm":"sc-plan-price",children:[d("span",{className:"sc-plan-amount",children:e.amount}),e.interval?E("span",{className:"sc-plan-interval",children:["/",e.interval]}):t&&d("span",{className:"sc-plan-interval sc-plan-after",children:t})]})}function Nr({offer:e}){return E("p",{className:"sc-plan-allowance",children:[d("span",{className:"sc-plan-figure",children:e.allowance}),d("span",{className:"sc-plan-qualifier",children:e.allowanceNote})]})}function At({offer:e,inline:n,bare:t}){let r=e.connect;if(!r)return t?d("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?E("button",{type:"button",className:`${s} sc-plan-reward-act`,"aria-label":"Connect compute",onClick:r.open,children:[d("span",{className:"sc-reward-said",children:r.line}),E("span",{className:"sc-reward-do","aria-hidden":!0,children:[d(V,{className:"sc-reward-mark"}),"Connect compute"]})]}):d("p",{className:s,children:r.line});return t?a:d("div",{className:n?"sc-plan-reward sc-plan-reward-inline":"sc-plan-reward",children:a})}function $t({offer:e,inline:n,bare:t}){let r=e.computeLabel?d("ul",{className:n?"sc-compute sc-compute-inline":"sc-compute",children:d("li",{children:e.computeLabel})}):d("ul",{className:n?"sc-compute sc-compute-inline":"sc-compute",children:e.compute.map(s=>E("li",{className:s.owned?"sc-compute-own":void 0,children:[s.label,d(Xs,{runtimes:s.runtimes})]},s.costClass))});return t?r:E("div",{className:n?"sc-plan-compute sc-plan-compute-inline":"sc-plan-compute",children:[d("span",{className:"sc-fact-key",children:"Runs on"}),r]})}function Dt({offer:e,shelf:n}){let t=e.connect;return n.showConnect&&t?.actionable?E("button",{type:"button",className:"sc-btn sc-btn-primary sc-btn-icon",onClick:t.open,children:[d(V,{className:"sc-btn-mark"}),"Connect compute"]}):d("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 Xs({runtimes:e}){return e.length===0?null:d("span",{className:"sc-compute-marks",children:e.map(n=>{let t=he[n];return t?d(t,{className:"sc-rt-mark"},n):null})})}import{jsx as Ut,jsxs as kr}from"react/jsx-runtime";function eo({heading:e,plansHeading:n,showUsage:t=!0,showName:r=!0,className:s,...a}){let{plan:i,loading:u}=Sn(),{theme:l}=I(),p=n??(u?"Plans":i?"Change plan":"Choose a plan");return kr("div",{className:s?`soba-connect sc-fill sc-billing ${s}`:"soba-connect sc-fill sc-billing","data-theme":l,children:[Ut(Rt,{...e===void 0?{}:{heading:e},showUsage:t,showName:r}),kr("section",{className:"sc-billing-plans",children:[p&&Ut("h2",{className:"sc-section-title",children:p}),Ut(Ot,{...a})]})]})}import{useState as xr}from"react";import{jsx as Sr,jsxs as to}from"react/jsx-runtime";function no({plan:e,successUrl:n,cancelUrl:t,label:r,className:s}){let{plan:a}=D(),{theme:i}=I(),[u,l]=xr(!1),[p,f]=xr(null);async function g(){l(!0),f(null);try{let m=await a.checkout(e.id,{...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}});window.location.assign(m)}catch(m){f(m.message),l(!1)}}return to("div",{className:s?`soba-connect ${s}`:"soba-connect","data-theme":i,children:[Sr("button",{type:"button",className:"sc-btn sc-btn-primary",disabled:u,onClick:()=>void g(),children:u?"Opening\u2026":r??`Subscribe for $${e.price.toLocaleString()}/${e.interval}`}),p&&Sr("p",{className:"sc-error",children:p})]})}import{useCallback as Ne,useEffect as Fe,useMemo as Pn,useRef as so,useState as Y}from"react";var qn=class{#n;#r=null;#t=null;#e;#s=new Set;constructor(n){this.#e=n,this.#n=n.token??null}get token(){return this.#n}get expiresAt(){return this.#r}get canRefresh(){return!!this.#e.endpoint}get refreshAt(){return!this.canRefresh||this.#r===null?null:Math.max(Date.now()+1e4,this.#r-6e4)}subscribe(n){return this.#s.add(n),()=>this.#s.delete(n)}async ensure(){return this.#n?this.#n:this.refresh()}async refresh(){if(this.#t)return this.#t;let n=this.#e.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.#e.fetchImpl??fetch.bind(globalThis);this.#t=(async()=>{let r=await t(n,{method:"POST",headers:{"content-type":"application/json"},credentials:"same-origin",body:JSON.stringify(this.#e.user?{user:this.#e.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 i=s.expires_in??s.expiresIn;this.#n=a,this.#r=typeof i=="number"?Date.now()+i*1e3:null;for(let u of this.#s)u();return a})();try{return await this.#t}finally{this.#t=null}}};function Pr(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,ro(r,a))}}function ro(e,n){let t=new Headers(e?.headers);return t.set("authorization",`Bearer ${n}`),{...e,headers:t}}import{jsx as Ht,jsxs as lo}from"react/jsx-runtime";var oo="https://www.soba.so",ao=15e3;function io(e){let{children:n,session:t,sessionEndpoint:r,user:s,runEndpoint:a,theme:i,initialMachines:u,initialConnect:l=null,initialPlans:p,initialCurrentPlan:f=null,baseUrl:g=oo,pollMs:m=ao,injectStyles:b=!0,modal:h=!0,fetchImpl:k,onError:N}=e,[x,U]=Y(t??null),[j,S]=Y(null),[O,H]=Y(l),[T,M]=Y(null),[q,G]=Y(l===null),[ce,Me]=Y(u??[]),[_n,Q]=Y(null),[ke,En]=Y(u===void 0),[xe,be]=Y(p??[]),[X,Bn]=Y(f),[tn,We]=Y(null),[Mn,ue]=Y(p===void 0),[se,Ge]=Y(null),[Fn,Re]=Y(!1),Ve=so(N);Ve.current=N;let oe=Ne(y=>{S(y),Ve.current?.(y)},[]);Fe(()=>{b&&kn()},[b]);let R=Pn(()=>new qn({...t?{token:t}:{},...r?{endpoint:r}:{},...s?{user:s}:{},...k?{fetchImpl:k}:{}}),[t,r,s,k]);Fe(()=>{let y=!0,B=R.subscribe(()=>{y&&U(R.token)});return!R.token&&!R.canRefresh?oe(new Error("<SobaProvider> needs a `session` or a `sessionEndpoint`. A browser cannot mint one: that takes your secret key.")):R.ensure().then(()=>y&&U(R.token),pe=>y&&oe(pe)),()=>{y=!1,B()}},[R,oe]),Fe(()=>{j&&(G(!1),En(!1),ue(!1),M(y=>y??j),Q(y=>y??j),We(y=>y??j))},[j]),Fe(()=>{let y=R.refreshAt;if(y===null)return;let B=setTimeout(()=>{R.refresh().catch(pe=>oe(pe))},Math.max(0,y-Date.now()));return()=>clearTimeout(B)},[R,oe,x]);let P=Pn(()=>x?new sn({session:x,baseUrl:g,fetchImpl:Pr(R,k??fetch.bind(globalThis))}):null,[x,g,R,k]);Fe(()=>{if(!P)return;let y=!0;return G(!0),P.context().then(B=>{y&&(H(B),M(null),G(!1))},B=>{y&&(M(B),G(!1))}),()=>{y=!1}},[P]);let Le=Ne(async()=>{if(P)try{let y=await P.machines();Me(Array.isArray(y)?y:[]),Q(null)}catch(y){Q(y)}finally{En(!1)}},[P]),ee=Ne(async()=>{if(P)try{let y=await P.plans();be(y.plans),Bn(y.current),We(null)}catch(y){We(y)}finally{ue(!1)}},[P]);Fe(()=>{P&&ee()},[P,ee]);let rn=Ne(async y=>{if(!P)throw new Error("No session yet.");await P.selectPlan(y),await ee()},[P,ee]),Rn=Ne(async(y,B)=>{if(!P)throw new Error("No session yet.");let pe=await P.checkoutPlan(y,B);if(!pe.url)throw new Error("Checkout could not be started.");return pe.url},[P]),ae=Ne(async()=>{if(!P)throw new Error("No session yet.");await P.leavePlan(),await ee()},[P,ee]);Fe(()=>{if(!P)return;let y=!0;Le();let B=setInterval(()=>{typeof document<"u"&&document.hidden||y&&Le()},m);return()=>{y=!1,clearInterval(B)}},[P,Le,m]);let Se=Ne(async y=>{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:B,...pe}=y,Oe=await(k??fetch.bind(globalThis))(a,{method:"POST",headers:{"content-type":"application/json",accept:"text/event-stream"},credentials:"same-origin",body:JSON.stringify(pe),...B?{signal:B}:{}});if(!Oe.ok){let Z=await Oe.json().catch(()=>null),Te=new Error(Z?.error?.message??`${a} answered ${Oe.status}.`);throw Te.status=Oe.status,Z?.error?.code&&(Te.code=Z.error.code),Z?.error&&(Te.error=Z.error),Te}let F=Mt(Oe);return async function*(){try{yield*F}finally{ee()}}()},[a,k,ee]),ze=Ne((y="manual")=>{h&&(Re(!0),Ge(y))},[h]),Ke=Ne(()=>Ge(null),[]),ne=Pn(()=>X?xe.find(y=>y.id===X.plan_id)??null:null,[xe,X]),de=Pn(()=>ne?ne.connected_reward==="included"&&ce.length>0&&ne.connected_included_units!==null?ne.connected_included_units:ne.included_units:null,[ne,ce]),je=Pn(()=>({session:x,client:P,error:j,plan:{plans:xe,current:X,plan:ne,used:X?.units_used??null,included:de,remaining:de!==null&&X?Math.max(0,de-X.units_used):null,unlimited:ne!==null&&de===null,loading:Mn,error:tn,select:rn,checkout:Rn,leave:ae,refresh:ee},compute:{machines:ce,connected:ce.length>0,online:ce.some(y=>y.state!=="offline"),loading:ke,error:_n,refresh:Le},connect:{app:O?.app??null,command:O?.command??null,connectUrl:O?.connect_url??null,publishableKey:O?.publishable_key??null,loading:q,error:T,open:ze,close:Ke,isOpen:se!==null,hasModal:h},run:Se}),[x,P,j,ne,de,se,ze,Ke,h,ce,ke,_n,Le,xe,X,Mn,tn,rn,Rn,ae,ee,O,q,T,Se]);return Ht(Ct.Provider,{value:P,children:Ht(Nt.Provider,{value:{context:O,machines:ke?void 0:ce,theme:i??O?.theme??"light"},children:lo(vt.Provider,{value:je,children:[n,h&&Fn&&Ht(Cn,{open:se!==null,onOpenChange:y=>Ge(y?se??"manual":null),...se&&se!=="manual"?{reason:se}:{}})]})})})}export{as as ComputeStatus,qe as ConnectButton,us as ConnectCompute,Cn as ConnectModal,ws as ConnectNudge,Ls as RunError,Is as RunLimit,eo as SobaBilling,no as SobaCheckout,Rt as SobaCurrentPlan,Ot as SobaPlans,io as SobaProvider,Es as collectText,kn as injectStyles,Dn as parseEvent,Mt as readEvents,br as runErrorMessage,Be as sobaErrorCode,Sn as useCurrentPlan,Lt as usePlans,Pt as useRunLimit,D as useSoba};
|
|
2659
|
+
`,document.head.appendChild(e)}import{jsx as Ce,jsxs as Hn}from"react/jsx-runtime";function Fr(e){if(!e)return null;let n=en(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 ps(){return Hn("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[Ce("path",{d:"M8 5v4",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),Ce("circle",{cx:"8",cy:"11.6",r:"0.9",fill:"currentColor"}),Ce("circle",{cx:"8",cy:"8",r:"6.4",stroke:"currentColor",strokeWidth:"1.3"})]})}function ms({error:e,onRetry:n,onDismiss:t,title:r,className:o}){let s=Fr(e),a=D();return ds(()=>Dn(),[]),s?Ce("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":a.theme,role:"alert",children:Hn("div",{className:"sc-card sc-limit sc-run-error",children:[Hn("div",{className:"sc-limit-head",children:[Ce("span",{className:"sc-limit-mark sc-run-error-mark","aria-hidden":"true",children:Ce(ps,{})}),Hn("div",{children:[Ce("h2",{className:"sc-limit-title",children:r??"That run did not finish"}),Ce("p",{className:"sc-limit-body sc-run-error-message",children:s})]})]}),(t||n)&&Hn("div",{className:"sc-limit-actions",children:[t&&Ce("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,children:"Dismiss"}),n&&Ce("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:n,children:"Try again"})]})]})}):null}import{useId as hs,useState as Gr}from"react";import{jsx as Q,jsxs as rt}from"react/jsx-runtime";function fs({reason:e}){return Q("span",{className:"sc-limit-mark","aria-hidden":"true",children:e==="no_compute"?Q(Gn,{}):Q(j,{})})}function gs(e){let{error:n,variant:t="card",onDismiss:r,className:o}=e,s=Xt(n,{predict:e.predict??!("error"in e)}),a=hs(),c=D();if(!s)return null;let i=Q(bs,{offer:s,headingId:a,onDismiss:r});return t==="dialog"?Q(On,{open:!0,onClose:()=>r?.(),labelledBy:a,theme:c.theme,children:i}):Q("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":c.theme,children:i})}function bs({offer:e,headingId:n,onDismiss:t}){let{compute:r}=q(),[o,s]=Gr(!1),[a,c]=Gr(null),i=e.reason==="no_compute"&&r.connected&&!r.online,u=i||e.connectOffer!==null||!r.connected,m=nt();async function f(){s(!0),c(null);try{await e.upgrade()}catch(b){c(b.message)}finally{s(!1)}}return rt("div",{className:"sc-card sc-limit",children:[rt("div",{className:"sc-limit-head",children:[Q(fs,{reason:e.reason}),rt("div",{children:[Q("h2",{className:"sc-limit-title",id:n,children:e.title}),Q("p",{className:"sc-limit-body",children:e.body})]})]}),a&&Q("p",{className:"sc-error",children:a}),i&&m.note&&Q("p",{className:"sc-limit-note",children:m.note}),rt("div",{className:"sc-limit-actions",children:[t&&Q("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,disabled:o,children:"Not now"}),e.upgradeTo&&Q("button",{type:"button",className:u?"sc-btn":"sc-btn sc-btn-primary",onClick:()=>void f(),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}`}),u&&Q("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&&Q("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:m.open,disabled:o,children:"Open Soba App"})]})]})}import{useMemo as ys}from"react";function Un(){let{plan:e,compute:n,connect:t}=q();return ys(()=>{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=Cs(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,u=r.connected_reward==="unlimited"&&n.connected,m=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,p=i!==null&&f>=i,y=a!==null?"trial":m?"unlimited":p?r.overage==="meter"?"metered":"spent":"within";return{...s,state:y,trialDaysLeft:a,ceiling:i,raised:c,uncounted:u,used:f,remaining:b,percent:g,unlimited:m,reward:ws(r,c||u,n.connected,()=>t.open("manual")),summary:vs({plan:r,assignment:o,used:f,ceiling:i,trialDaysLeft:a,raised:c,uncounted:u,state:y})}},[e,n.connected,t])}function ws(e,n,t,r){let o=Re({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:Le(e.connected_reward)&&!t,open:r}:me(e.route_allow)&&!t?{line:"Nothing connected yet, so nothing can run.",inForce:!1,required:!0,connected:t,actionable:!0,open:r}:null}function vs(e){let{plan:n,assignment:t,used:r,ceiling:o,trialDaysLeft:s,raised:a,uncounted:c,state:i}=e,u=`${n.unit}${r===1?"":"s"}`,m=c?" Runs your own AI serves do not count toward it.":"";if(i==="trial"&&s!==null){let g=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 ${g}.`}if(i==="unlimited")return`${r.toLocaleString()} ${u} this period. No ceiling on this plan.`;if(i==="metered"){let g=r-(o??0);return n.overage_per_unit>0?`${g.toLocaleString()} past the allowance, billed at $${n.overage_per_unit} a ${n.unit}.${m}`:`${g.toLocaleString()} past the allowance.${m}`}if(i==="spent")return t?.period_end?`Allowance spent. It comes back on ${Vr(t.period_end)}.${m}`:`Allowance spent. It comes back at the start of the next period.${m}`;let f=Math.max(0,(o??0)-r),b=a?` Raised from ${(n.included_units??0).toLocaleString()} while your own AI is connected.`:t?.period_end?` Resets ${Vr(t.period_end)}.`:"";return`${f.toLocaleString()} of ${(o??0).toLocaleString()} ${n.unit}s left.${b}${m}`}function Cs(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 Vr(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}import{Fragment as ks,jsx as Z,jsxs as he}from"react/jsx-runtime";function rr({heading:e="Current plan",showUsage:n=!0,showName:t=!0,className:r}){let o=Un(),{theme:s}=D(),a=b=>Z("section",{className:r?`soba-connect sc-fill ${r}`:"soba-connect sc-fill","data-theme":s,children:he("div",{className:"sc-card sc-current",children:[e&&Z("h2",{className:"sc-section-title",children:e}),b]})});if(o.error)return a(Z("p",{className:"sc-error",children:o.error.message}));if(o.loading)return a(Z("p",{className:"sc-note",children:"Loading\u2026"}));if(!o.plan)return a(he("div",{className:"sc-current-main",children:[Z("p",{className:"sc-current-name",children:"No plan"}),Z("p",{className:"sc-sub",children:o.summary})]}));let{plan:c,trialDaysLeft:i,percent:u,unlimited:m,reward:f}=o;return a(he(ks,{children:[he("div",{className:"sc-current-grid",children:[(t||i!==null)&&he("div",{className:"sc-current-main",children:[t?he("p",{className:"sc-current-name",children:[c.name,i!==null&&he("span",{className:"sc-trial-badge",children:[i," ",i===1?"day":"days"," left"]})]}):i!==null&&Z("p",{className:"sc-current-trial",children:he("span",{className:"sc-trial-badge",children:[i," ",i===1?"day":"days"," left"]})}),t&&c.description&&Z("p",{className:"sc-sub",children:c.description})]}),n&&he("div",{className:"sc-usage",children:[he("div",{className:"sc-row-between",children:[Z("span",{className:"sc-fact-key",children:"Usage"}),Z("span",{className:u!==null&&u>=100?"sc-usage-figure sc-usage-over":"sc-usage-figure",children:m?"Unlimited":u===null?"Metered":`${u}% used`})]}),u!==null&&Z("div",{className:"sc-meter",role:"presentation",children:u>0&&Z("span",{className:u>=100?"sc-meter-fill sc-meter-full":"sc-meter-fill",style:{width:`${u}%`}})}),Z("p",{className:"sc-usage-line",children:o.summary})]})]}),f&&he("div",{className:"sc-current-foot",children:[Z("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: ${Ns(f.line)}.`:f.line}),(f.actionable||f.connected)&&Z(Xe,{})]})]}))}var Ns=e=>e.charAt(0).toLowerCase()+e.slice(1);import{useCallback as xs,useMemo as Ss,useState as zr}from"react";var Ps={"user-hardware":"your own machine","user-subscription":"your own AI subscription","open-weights":"open models we host",frontier:"frontier models"},_s=new Set(["user-hardware","user-subscription"]);function or(e={}){let{plan:n,compute:t,connect:r}=q(),[o,s]=zr(null),[a,c]=zr(null),{featured:i,onSelect:u,successUrl:m,cancelUrl:f}=e,b=xs(async p=>{s(p.id),c(null);try{if(p.selectable)await n.select(p.id);else if(u)u(p);else{let y=await n.checkout(p.id,{...m?{successUrl:m}:{},...f?{cancelUrl:f}:{}});window.location.assign(y);return}}catch(y){throw c(y.message),y}finally{(p.selectable||u)&&s(null)}},[n,u,m,f]),g=Ss(()=>n.plans.map(p=>{let y=n.current?.plan_id===p.id;return{plan:p,current:y,featured:i===p.id&&!y,price:Es(p),allowance:p.included_units===null?`Unlimited ${p.unit}s`:`${p.included_units.toLocaleString()} ${p.unit}${p.included_units===1?"":"s"}`,allowanceNote:Ms(p),computeLabel:p.route_allow===null?"any compute":p.route_allow.length===0?"no compute":null,compute:(p.route_allow??[]).map(_=>({costClass:_,label:Ps[_]??_,owned:_s.has(_),runtimes:yt(_).map(k=>k.id)})),connect:Rs(p,y,t.connected,()=>r.open("manual")),cta:{label:Ls(p,y,o===p.id),disabled:y||o!==null,busy:o===p.id,take:()=>b(p)}}}),[n.plans,n.current,i,t.connected,r,o,b]);return{offers:g,current:g.find(p=>p.current)??null,loading:n.loading,error:n.error,failed:a}}function Es(e){return e.price===0?{amount:"Free",interval:null,free:!0}:{amount:`$${e.price.toLocaleString()}`,interval:e.interval,free:!1}}function Ms(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 Rs(e,n,t,r){let o=Re({unit:e.unit,reward:e.connected_reward,includedUnits:e.connected_included_units,creditMicros:e.connected_credit*1e6}),s=me(e.route_allow)&&!t;if(!o&&!s)return null;let a=Le(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 Ls(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 L}from"react/jsx-runtime";function ot(e){return e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill"}function sr({onSelect:e,successUrl:n,cancelUrl:t,showCompute:r=!0,showConnect:o=!1,variant:s="cards",featured:a,className:c}){let{offers:i,loading:u,error:m,failed:f}=or({...a?{featured:a}:{},...e?{onSelect:e}:{},...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}}),{theme:b}=D();if(m)return h("div",{className:ot(c),"data-theme":b,children:h("div",{className:"sc-card",children:h("p",{className:"sc-error",children:m.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:o};return L("div",{className:ot(c),"data-theme":b,"data-variant":s,children:[s==="rows"?h(Os,{offers:i,shelf:g}):s==="table"?h(As,{offers:i,shelf:g}):h(Ts,{offers:i,shelf:g}),f&&h("p",{className:"sc-error",children:f})]})}function Ts({offers:e,shelf:n}){return h("div",{className:"sc-plans",children:e.map(t=>L("div",{className:Kr("sc-plan",t),children:[L("div",{className:"sc-row-between",children:[h("span",{className:"sc-title",children:t.plan.name}),h(ar,{offer:t})]}),h("p",{className:"sc-sub",children:t.plan.description}),h(ir,{price:t.price,free:"forever"}),h(ur,{offer:t,shelf:n}),h(jr,{offer:t}),h("div",{className:"sc-plan-band",children:n.showCompute&&h(cr,{offer:t})}),h("div",{className:"sc-plan-band",children:h(lr,{offer:t})})]},t.plan.id))})}function Os({offers:e,shelf:n}){return h("ul",{className:"sc-plan-rows",children:e.map(t=>L("li",{className:Kr("sc-plan-row",t),children:[L("div",{className:"sc-row-main",children:[L("span",{className:"sc-row-name",children:[h("span",{className:"sc-title",children:t.plan.name}),h(ar,{offer:t})]}),t.plan.description&&h("p",{className:"sc-sub",children:t.plan.description}),h(jr,{offer:t}),n.showCompute&&h(cr,{offer:t,inline:!0}),h(lr,{offer:t,inline:!0})]}),L("div",{className:"sc-row-side",children:[h(ir,{price:t.price,free:"forever",small:!0}),h(ur,{offer:t,shelf:n})]})]},t.plan.id))})}function As({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 h("div",{className:"sc-table-scroll",children:L("table",{className:"sc-plan-table",children:[h("thead",{children:L("tr",{children:[h("td",{}),e.map(a=>L("th",{scope:"col",className:s(a),children:[L("span",{className:"sc-row-name",children:[h("span",{className:"sc-title",children:a.plan.name}),h(ar,{offer:a})]}),h(ir,{price:a.price,small:!0})]},a.plan.id))]})}),L("tbody",{children:[L("tr",{children:[h("th",{scope:"row",children:"Included"}),e.map(a=>h("td",{className:s(a),children:a.allowance},a.plan.id))]}),t&&L("tr",{children:[h("th",{scope:"row",children:"Then"}),e.map(a=>h("td",{className:s(a),children:a.plan.overage_per_unit>0?`$${a.plan.overage_per_unit} / ${a.plan.unit}`:h("span",{className:"sc-muted-cell",children:"Stops"})},a.plan.id))]}),r&&L("tr",{children:[h("th",{scope:"row",children:"Trial"}),e.map(a=>h("td",{className:s(a),children:a.plan.trial_days>0?`${a.plan.trial_days} days`:h("span",{className:"sc-muted-cell",children:"None"})},a.plan.id))]}),n.showCompute&&L("tr",{children:[h("th",{scope:"row",children:"Runs on"}),e.map(a=>h("td",{className:s(a),children:h(cr,{offer:a,bare:!0})},a.plan.id))]}),o&&L("tr",{children:[h("th",{scope:"row",children:"Connect your own"}),e.map(a=>h("td",{className:s(a),children:h(lr,{offer:a,bare:!0})},a.plan.id))]}),L("tr",{className:"sc-table-buy",children:[h("td",{}),e.map(a=>h("td",{className:s(a),children:h(ur,{offer:a,shelf:n})},a.plan.id))]})]})]})})}function Kr(e,n){return[e,n.current?"sc-plan-current":"",n.featured?"sc-plan-featured":""].filter(Boolean).join(" ")}function ar({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 ir({price:e,small:n,free:t}){return L("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?L("span",{className:"sc-plan-interval",children:["/",e.interval]}):t&&h("span",{className:"sc-plan-interval sc-plan-after",children:t})]})}function jr({offer:e}){return L("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 lr({offer:e,inline:n,bare:t}){let r=e.connect;if(!r)return t?h("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?L("button",{type:"button",className:`${o} sc-plan-reward-act`,"aria-label":"Connect compute",onClick:r.open,children:[h("span",{className:"sc-reward-said",children:r.line}),L("span",{className:"sc-reward-do","aria-hidden":!0,children:[h(j,{className:"sc-reward-mark"}),"Connect compute"]})]}):h("p",{className:o,children:r.line});return t?s:h("div",{className:n?"sc-plan-reward sc-plan-reward-inline":"sc-plan-reward",children:s})}function cr({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(o=>L("li",{className:o.owned?"sc-compute-own":void 0,children:[o.label,h(Is,{runtimes:o.runtimes})]},o.costClass))});return t?r:L("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 ur({offer:e,shelf:n}){let t=e.connect;return n.showConnect&&t?.actionable?L("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 Is({runtimes:e}){return e.length===0?null:h("span",{className:"sc-compute-marks",children:e.map(n=>{let t=Ie[n];return t?h(t,{className:"sc-rt-mark"},n):null})})}import{jsx as dr,jsxs as Yr}from"react/jsx-runtime";function $s({heading:e,plansHeading:n,showUsage:t=!0,showName:r=!0,className:o,...s}){let{plan:a,loading:c}=Un(),{theme:i}=D(),u=n??(c?"Plans":a?"Change plan":"Choose a plan");return Yr("div",{className:o?`soba-connect sc-fill sc-billing ${o}`:"soba-connect sc-fill sc-billing","data-theme":i,children:[dr(rr,{...e===void 0?{}:{heading:e},showUsage:t,showName:r}),Yr("section",{className:"sc-billing-plans",children:[u&&dr("h2",{className:"sc-section-title",children:u}),dr(sr,{...s})]})]})}import{useState as Qr}from"react";import{jsx as Zr,jsxs as Hs}from"react/jsx-runtime";function Ds({plan:e,successUrl:n,cancelUrl:t,label:r,className:o}){let{plan:s}=q(),{theme:a}=D(),[c,i]=Qr(!1),[u,m]=Qr(null);async function f(){i(!0),m(null);try{let b=await s.checkout(e.id,{...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}});window.location.assign(b)}catch(b){m(b.message),i(!1)}}return Hs("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":a,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 Ne,useEffect as Be,useMemo as gn,useRef as nn,useState as J}from"react";var st=class{#n;#r=null;#t=null;#e;#o=new Set;constructor(n){this.#e=n,this.#n=n.token??null}get token(){return this.#n}get expiresAt(){return this.#r}get canRefresh(){return!!this.#e.endpoint}get refreshAt(){return!this.canRefresh||this.#r===null?null:Math.max(Date.now()+1e4,this.#r-6e4)}subscribe(n){return this.#o.add(n),()=>this.#o.delete(n)}async ensure(){return this.#n?this.#n:this.refresh()}async refresh(){if(this.#t)return this.#t;let n=this.#e.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.#e.fetchImpl??fetch.bind(globalThis);this.#t=(async()=>{let r=await t(n,{method:"POST",headers:{"content-type":"application/json"},credentials:"same-origin",body:JSON.stringify(this.#e.user?{user:this.#e.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.#n=s,this.#r=typeof a=="number"?Date.now()+a*1e3:null;for(let c of this.#o)c();return s})();try{return await this.#t}finally{this.#t=null}}},fn=new Map,Jr=new WeakMap,Us=1;function Bs(e){if(e.token||!e.endpoint)return null;let n=0;return e.fetchImpl&&(n=Jr.get(e.fetchImpl)??Us++,Jr.set(e.fetchImpl,n)),JSON.stringify([e.endpoint,e.user??null,n])}function Xr(e){let n=Bs(e);if(!n)return new st(e);let t=fn.get(n)??{holder:new st(e),users:0};return fn.set(n,t),t.holder}function eo(e){for(let n of fn.values())n.holder===e&&n.users++}function no(e){for(let[n,t]of fn)if(t.holder===e){setTimeout(()=>{--t.users<=0&&fn.get(n)===t&&fn.delete(n)},0);return}}function to(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,qs(r,s))}}function qs(e,n){let t=new Headers(e?.headers);return t.set("authorization",`Bearer ${n}`),{...e,headers:t}}import{jsx as pr,jsxs as Vs}from"react/jsx-runtime";var Ws="https://www.soba.so",Fs=3e4;function Gs(e){let{children:n,session:t,sessionEndpoint:r,user:o,runEndpoint:s,theme:a,initialMachines:c,initialConnect:i=null,initialPlans:u,initialCurrentPlan:m=null,baseUrl:f=Ws,pollMs:b=Fs,injectStyles:g=!0,modal:p=!0,fetchImpl:y,onError:_}=e,[k,U]=J(t??null),[M,fe]=J(null),[S,se]=J(i),[T,P]=J(null),[W,z]=J(i===null),[ae,tn]=J(c??[]),[ue,ke]=J(null),[K,xe]=J(c===void 0),[Se,qe]=J(u??[]),[F,Te]=J(m),[rn,de]=J(null),[We,on]=J(u===void 0),[G,ge]=J(null),[O,pe]=J(!1),be=nn(_);be.current=_;let Pe=Ne(w=>{fe(w),be.current?.(w)},[]);Be(()=>{g&&Dn()},[g]);let B=gn(()=>Xr({...t?{token:t}:{},...r?{endpoint:r}:{},...o?{user:o}:{},...y?{fetchImpl:y}:{}}),[t,r,o,y]);Be(()=>{let w=!0;eo(B);let Y=B.subscribe(()=>{w&&U(B.token)});return!B.token&&!B.canRefresh?Pe(new Error("<SobaProvider> needs a `session` or a `sessionEndpoint`. A browser cannot mint one: that takes your secret key.")):B.ensure().then(()=>w&&U(B.token),le=>w&&Pe(le)),()=>{w=!1,Y(),no(B)}},[B,Pe]),Be(()=>{M&&(z(!1),xe(!1),on(!1),P(w=>w??M),ke(w=>w??M),de(w=>w??M))},[M]),Be(()=>{let w=B.refreshAt;if(w===null)return;let Y=()=>{B.refresh().catch(ye=>Pe(ye))},le=()=>{document.hidden||(document.removeEventListener("visibilitychange",le),Y())},ln=setTimeout(()=>{typeof document<"u"&&document.hidden?document.addEventListener("visibilitychange",le):Y()},Math.max(0,w-Date.now()));return()=>{clearTimeout(ln),typeof document<"u"&&document.removeEventListener("visibilitychange",le)}},[B,Pe,k]);let X=nn(i?.machines_url??null),E=gn(()=>{if(!k)return null;let w=new Cn({session:k,baseUrl:f,fetchImpl:to(B,y??fetch.bind(globalThis))});return w.setMachinesUrl(X.current),w},[k,f,B,y]),at=nn(i!==null);Be(()=>{if(!E||at.current)return;let w=!0;return z(!0),E.context().then(Y=>{w&&(se(Y),P(null),z(!1))},Y=>{w&&(P(Y),z(!1))}),()=>{w=!1}},[E]);let sn=Ne(async()=>{if(E)try{let w=await E.machines();tn(Array.isArray(w)?w:[]),ke(null)}catch(w){ke(w)}finally{xe(!1)}},[E]),ne=Ne(async()=>{if(E)try{let w=await E.plans();qe(w.plans),Te(w.current),de(null)}catch(w){de(w)}finally{on(!1)}},[E]),an=nn(!1),[ie,Oe]=J(!1),bn=nn(u!==void 0),_e=nn(!1),yn=Ne(()=>{an.current||(an.current=!0,_e.current&&queueMicrotask(()=>{_e.current&&Oe(!0)}))},[]);Be(()=>(_e.current=!0,an.current&&Oe(!0),()=>{_e.current=!1}),[]),Be(()=>{!E||!ie||bn.current||ne()},[E,ie,ne]);let Fe=Ne(async w=>{if(!E)throw new Error("No session yet.");await E.selectPlan(w),await ne()},[E,ne]),Ge=Ne(async(w,Y)=>{if(!E)throw new Error("No session yet.");let le=await E.checkoutPlan(w,Y);if(!le.url)throw new Error("Checkout could not be started.");return le.url},[E]),it=Ne(async()=>{if(!E)throw new Error("No session yet.");await E.leavePlan(),await ne()},[E,ne]),Bn=nn(c!==void 0);Be(()=>{if(!E)return;let w=De(sn,b,{immediate:!Bn.current});return Bn.current=!1,w},[E,sn,b]);let qn=Ne(async w=>{if(!s)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:Y,...le}=w,ye=await(y??fetch.bind(globalThis))(s,{method:"POST",headers:{"content-type":"application/json",accept:"text/event-stream"},credentials:"same-origin",body:JSON.stringify(le),...Y?{signal:Y}:{}});if(!ye.ok){let Ee=await ye.json().catch(()=>null),ee=new Error(Ee?.error?.message??`${s} answered ${ye.status}.`);throw ee.status=ye.status,Ee?.error?.code&&(ee.code=Ee.error.code),Ee?.error&&(ee.error=Ee.error),ee}let ct=tr(ye);return async function*(){try{yield*ct}finally{an.current&&ne()}}()},[s,y,ne]),Wn=Ne((w="manual")=>{p&&(pe(!0),ge(w))},[p]),Fn=Ne(()=>ge(null),[]),A=gn(()=>F?Se.find(w=>w.id===F.plan_id)??null:null,[Se,F]),te=gn(()=>A?A.connected_reward==="included"&&ae.length>0&&A.connected_included_units!==null?A.connected_included_units:A.included_units:null,[A,ae]),wn=gn(()=>({plans:Se,current:F,plan:A,used:F?.units_used??null,included:te,remaining:te!==null&&F?Math.max(0,te-F.units_used):null,unlimited:A!==null&&te===null,loading:We,error:rn,select:Fe,checkout:Ge,leave:it,refresh:ne}),[Se,F,A,te,We,rn,Fe,Ge,it,ne]),lt=gn(()=>({session:k,client:E,error:M,get plan(){return yn(),wn},compute:{machines:ae,connected:ae.length>0,online:ae.some(w=>w.state!=="offline"),loading:K,error:ue,refresh:sn},connect:{app:S?.app??null,command:S?.command??null,connectUrl:S?.connect_url??null,publishableKey:S?.publishable_key??null,loading:W,error:T,open:Wn,close:Fn,isOpen:G!==null,hasModal:p},run:qn}),[k,E,M,wn,yn,G,Wn,Fn,p,ae,K,ue,sn,S,W,T,qn]);return pr(zt.Provider,{value:E,children:pr(Kt.Provider,{value:{context:S,machines:K?void 0:ae,theme:a??S?.theme??"light"},children:Vs(Vt.Provider,{value:lt,children:[n,p&&O&&pr(In,{open:G!==null,onOpenChange:w=>ge(w?G??"manual":null),...G==="payment_required"||G==="no_compute"?{reason:G}:{},...G==="pair"?{showStatus:!1}:{}})]})})})}export{Go as ComputeStatus,Xe as ConnectButton,zo as ConnectCompute,In as ConnectModal,ns as ConnectNudge,ms as RunError,gs as RunLimit,$s as SobaBilling,Ds as SobaCheckout,rr as SobaCurrentPlan,sr as SobaPlans,Gs as SobaProvider,us as collectText,Dn as injectStyles,tt as parseEvent,tr as readEvents,Fr as runErrorMessage,en as sobaErrorCode,Un as useCurrentPlan,or as usePlans,Xt as useRunLimit,q as useSoba};
|