@soba-so/react 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +12 -6
- package/dist/styles.css +6 -0
- package/dist/types.d.ts +23 -0
- package/dist/useMachineRuns.d.ts +24 -0
- package/package.json +8 -9
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export { SobaPlans, type SobaPlansProps } from "./SobaPlans.js";
|
|
|
15
15
|
export { SobaProvider, type SobaProviderProps } from "./SobaProvider.js";
|
|
16
16
|
export { injectStyles } from "./styles.js";
|
|
17
17
|
export { tierLabel } from "./tier.js";
|
|
18
|
-
export type { AgentEvent, AgentEventType, ConnectApi, ConnectContext, CostClass, CurrentPlan, Launch, Machine, MachineState, Message, ModelGroup, ModelOption, ModelOptionKind, PendingCode, Plan, Runtime, RunUsage, } from "./types.js";
|
|
18
|
+
export type { AgentEvent, AgentEventType, ConnectApi, ConnectContext, CostClass, CurrentPlan, Launch, Machine, MachineRun, MachineState, Message, ModelGroup, ModelOption, ModelOptionKind, PendingCode, Plan, Runtime, RunUsage, } from "./types.js";
|
|
19
19
|
export { type CheckoutView, type UseCheckoutOptions, useCheckout } from "./useCheckout.js";
|
|
20
20
|
export { type ComputeMachine, type ComputeRuntime, type ComputeView, useCompute, } from "./useCompute.js";
|
|
21
21
|
export { type ConnectButtonView, connectSays, useConnectButton } from "./useConnectButton.js";
|
|
@@ -26,3 +26,4 @@ export { useOpenSobaConnect } from "./useOpenSobaConnect.js";
|
|
|
26
26
|
export { type PlanCompute, type PlanConnect, type PlanCta, type PlanOffer, type PlanPrice, type PlansOptions, type PlansView, usePlans, } from "./usePlans.js";
|
|
27
27
|
export { type LimitReason, type Offer, sobaErrorCode, useRunLimit } from "./useRunLimit.js";
|
|
28
28
|
export { type RunStream, type WatchOptions, watchRun } from "./watch.js";
|
|
29
|
+
export { type MachineRunsOptions, type MachineRunsView, useMachineRuns } from "./useMachineRuns.js";
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import{useRef as ls,useState as cs}from"react";var In=class extends Error{status;constructor(n,t){super(n),this.name="ConnectError",this.status=t}},ns=5*6e4,Tn=class{session;baseUrl;doFetch;lastMachines=null;machinesUrl=null;gatewayBackUntil=0;constructor(n){this.session=n.session,this.baseUrl=(n.baseUrl??"").replace(/\/+$/,""),this.doFetch=n.fetchImpl??fetch.bind(globalThis)}async context(){let n=await this.request("GET","/v1/connect");return this.setMachinesUrl(n.machines_url),n}setMachinesUrl(n){typeof n=="string"&&/^https?:\/\//.test(n)&&(this.machinesUrl=n)}async machines(){let n=this.lastMachines,t=n?`?v=${encodeURIComponent(n.version)}`:"",r;if(this.machinesUrl&&Date.now()>=this.gatewayBackUntil)try{r=await this.request("GET",`${this.machinesUrl}${t}`)}catch(s){if(s instanceof In&&s.status===401)throw s;this.gatewayBackUntil=Date.now()+ns}if(r??=await this.request("GET",`/v1/machines${t}`),r.unchanged&&n)return n.machines;let o=Array.isArray(r.machines)?r.machines:[];return this.lastMachines=typeof r.version=="string"?{version:r.version,machines:o}:null,o}async runs(){let n=await this.request("GET","/v1/machines/runs");return Array.isArray(n.runs)?n.runs:[]}lookup(n){return this.request("GET",`/v1/device/lookup?code=${encodeURIComponent(n)}`)}approve(n){return this.request("POST","/v1/device/approve",{user_code:n})}claim(n){return this.request("POST","/v1/device/claim",{pairing_nonce:n})}deny(n){return this.request("POST","/v1/device/deny",{user_code:n})}plans(){return this.request("GET","/v1/plans")}selectPlan(n){return this.request("POST","/v1/plans/select",{plan:n})}checkoutPlan(n,t){return this.request("POST","/v1/plans/checkout",{plan:n,...t?.successUrl?{success_url:t.successUrl}:{},...t?.cancelUrl?{cancel_url:t.cancelUrl}:{}})}leavePlan(){return this.request("DELETE","/v1/plans/select")}hosted(){return this.request("GET","/v1/hosted")}startHosted(){return this.request("POST","/v1/hosted/start")}disconnectHosted(n){return this.request("DELETE",n?`/v1/hosted?provider=${encodeURIComponent(n)}`:"/v1/hosted")}approveRuntime(n,t){return this.request("POST","/v1/runtimes/approve",{machine_id:n,runtime_id:t})}preferRuntime(n,t){return this.request("POST","/v1/runtimes/prefer",{machine_id:n,runtime_id:t})}async request(n,t,r){let o=await this.doFetch(/^https?:\/\//.test(t)?t:`${this.baseUrl}${t}`,{method:n,headers:{authorization:`Bearer ${this.session}`,...r?{"content-type":"application/json"}:{}},...r?{body:JSON.stringify(r)}:{}}),s={};try{s=await o.json()}catch{}if(!o.ok){let a=typeof s.error=="string"?s.error:`Request failed (${o.status})`;throw new In(a,o.status)}return s}};function Ln(e){let n=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!n?.[1])return"#ffffff";let t=n[1].length===3?[...n[1]].map(s=>s+s).join(""):n[1],r=s=>{let a=Number.parseInt(t.slice(s*2,s*2+2),16)/255;return a<=.04045?a/12.92:((a+.055)/1.055)**2.4};return .2126*r(0)+.7152*r(1)+.0722*r(2)>.45?"#101012":"#ffffff"}function $t(e){let n=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!n?.[1])return null;let t=n[1].length===3?[...n[1]].map(r=>r+r).join(""):n[1];return[0,1,2].map(r=>Number.parseInt(t.slice(r*2,r*2+2),16))}function kn(e,n,t){let r=$t(e),o=$t(n);return!r||!o?e:`#${r.map((a,c)=>Math.round(a+(o[c]-a)*t)).map(a=>a.toString(16).padStart(2,"0")).join("")}`}function ln(e,n){if(!$t(e))return{};let t=Ln(e),r=n?.trim();return{"--sc-ground":e,"--sc-shell":e,"--sc-sheet":kn(e,t,.07),"--sc-raised":kn(e,t,.13),"--sc-line":kn(e,t,.18),"--sc-line-2":kn(e,t,.28),"--sc-text":t,"--sc-text-2":kn(t,e,.15),"--sc-muted":kn(t,e,.38),...r?{"--sc-accent":r,"--sc-accent-fg":Ln(r)}:{"--sc-accent":t,"--sc-accent-fg":e}}}function An(e){return e.authenticated===!0?{tone:"ok",text:"signed in"}:e.authenticated===!1?{tone:"warn",text:e.auth_hint??"signed out on that machine"}:{tone:"unknown",text:"could not tell"}}function $n(e){let{platform:n,arch:t}=e;if(!n)return null;let r=n==="darwin"||n==="macos",o=r?"Mac":n==="win32"||n==="windows"?"Windows PC":"Linux machine";return r?`${t==="aarch64"||t==="arm64"?"Apple silicon ":""}${o}`:o}function cn(e){return e.find(n=>n.state==="offline")??null}function Dt(e){return e.state==="busy"?{tone:"busy",text:`serving ${e.active} of ${e.capacity}`}:e.state==="online"?{tone:"ok",text:"connected"}:{tone:"off",text:"asleep or offline"}}function V(e){let n=e.label?.trim(),t=e.name?.trim();return n&&(!t||n!==t)?n:(t??n??"").replace(/\.(local|lan|home|internal)$/i,"").replace(/[-_]+/g," ").trim()||n||"This machine"}function mt(e,n){let t=o=>o.state==="busy"?0:o.state==="online"?1:2,r=o=>o.last_seen_at?Date.parse(o.last_seen_at):0;return t(e)-t(n)||r(n)-r(e)}function Ee(e){return[...e].sort(mt)[0]??null}function Ge(e){return e?e.state==="busy"?{tone:"busy",word:"Serving"}:e.state==="online"?{tone:"ok",word:"Connected"}:{tone:"off",word:"Asleep"}:{tone:"off",word:"No compute"}}function Ht(e){return e.state==="online"||e.state==="busy"}function Dn(e){if(!e)return"never seen";let n=Date.parse(e);if(Number.isNaN(n))return"never seen";let t=Date.now()-n,r=6e4;return t<2*r?"just now":t<60*r?`${Math.floor(t/r)} min ago`:t<24*60*r?`${Math.floor(t/(60*r))} hr ago`:`${Math.floor(t/(24*60*r))} days ago`}function ye(e){return e.runtimes.filter(n=>n.id!=="shell"&&!n.quarantined&&!n.absent)}function De(e){let n=a=>a?e.runtimes.find(c=>c.id===a)??null:null;if(e.requested_runtime)return{by:"app",runtimeId:e.requested_runtime,runtime:n(e.requested_runtime)};let t=ye(e),r=t.find(a=>a.id===e.preferred_runtime);if(r)return{by:"you",runtimeId:r.id,runtime:r};let o=a=>a.id==="claude-code"?0:a.id==="codex"?1:2,s=[...t].sort((a,c)=>o(a)-o(c))[0]??null;return{by:"default",runtimeId:s?.id??null,runtime:s}}import{useEffect as Xr,useRef as ts}from"react";import{Fragment as ss,jsx as Ne,jsxs as Ut}from"react/jsx-runtime";function Hn({anchor:e,label:n,options:t,current:r,onClose:o,onPick:s}){let a=ts(null);return Xr(()=>{let i=a.current,l=e.current;if(!i||!l)return;try{typeof i.showPopover=="function"&&i.showPopover()}catch{}let u=l.getBoundingClientRect(),p=i.offsetWidth,y=i.offsetHeight,f=Math.max(8,Math.min(u.right-p,window.innerWidth-p-8)),m=u.bottom+6,w=m+y>window.innerHeight-8&&u.top-6-y>8?u.top-6-y:m;i.style.left=`${Math.round(f)}px`,i.style.top=`${Math.round(w)}px`,i.querySelector('[aria-checked="true"]')?.focus()},[e]),Xr(()=>{let i=l=>{let u=l.target;!u||a.current?.contains(u)||e.current?.contains(u)||o()};return document.addEventListener("pointerdown",i,!0),()=>document.removeEventListener("pointerdown",i,!0)},[e,o]),Ne("div",{ref:a,role:"menu","aria-label":n,className:"sc-menu",popover:"manual",onKeyDown:i=>{let l=[...a.current?.querySelectorAll("[role=menuitemradio]")??[]],u=l.indexOf(document.activeElement);if(i.key==="Escape")i.stopPropagation(),i.nativeEvent.stopImmediatePropagation(),o(),e.current?.focus();else if(i.key==="ArrowDown"||i.key==="ArrowUp"){i.preventDefault();let p=i.key==="ArrowDown"?1:-1;l[(u+p+l.length)%l.length]?.focus()}else i.key==="Tab"&&o()},children:t.map(i=>Ne(rs,{option:i,checked:r===i.id,onClose:o,onPick:s},i.id??""))})}function rs({option:e,checked:n,onClose:t,onPick:r}){return Ut(ss,{children:[e.heading?Ne("div",{className:"sc-menu-head",role:"presentation",children:e.heading}):e.rule?Ne("div",{className:"sc-menu-sep"}):null,Ut("button",{type:"button",role:"menuitemradio","aria-checked":n,className:"sc-menu-item",onClick:()=>n?t():r(e.id),children:[e.glyph,Ut("span",{className:"sc-menu-text",children:[Ne("span",{className:"sc-menu-label",children:e.label}),e.note&&Ne("span",{className:"sc-menu-note",children:e.note})]}),n&&Ne(os,{})]})]})}function os(){return Ne("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:"sc-menu-check",children:Ne("path",{d:"M5 12.5l4.5 4.5L19 7.5",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Cn({open:e}){return Ne("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e?"sc-chev sc-chev-open":"sc-chev",children:Ne("path",{d:"M9 6l6 6-6 6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as we,jsxs as is}from"react/jsx-runtime";function j({className:e}){return is("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:[we("path",{d:"M18.125 7.039A8.6 8.6 0 1 0 18.125 16.961A6 6 0 0 1 18.125 7.039Z",fill:"currentColor"}),we("path",{d:"M19.925 7.039A8.6 8.6 0 0 1 19.925 16.961A6 6 0 0 0 19.925 7.039Z",fill:"currentColor"})]})}function eo({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{fill:"currentColor",d:"M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z"})})}function un({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{fill:"currentColor",d:"M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"})})}function ft({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{d:"M4 5h16v11H4zM9 20h6M12 16v4",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function as({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{d:"M5 7l5 5-5 5M12 18h7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Wt({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{d:"M5 6h14v10H5zM2.5 19.5h19",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}var ze={claude:eo,chatgpt:un,local:ft},no={shell:as};var ce=[{id:"claude",costClass:"user-subscription",short:"Claude Code",label:"Continue with Claude",title:"The Claude plan you already pay for",cost:"Nothing beyond the plan",prerequisite:"Claude Code installed and signed in",hint:"Install it from claude.ai/code, then run `claude` once and sign in.",install:"https://claude.com/product/claude-code",expects:["claude-code"]},{id:"chatgpt",costClass:"user-subscription",short:"Codex",label:"Continue with ChatGPT",title:"The ChatGPT plan you already pay for",cost:"Nothing beyond the plan",prerequisite:"Codex installed and signed in",hint:"Install Codex, then run `codex` once and sign in.",install:"https://learn.chatgpt.com/codex/cli",expects:["codex"]},{id:"local",costClass:"user-hardware",short:"Local models",label:"Use a model on this machine",title:"A model on your own machine",cost:"Free. You bought the hardware",prerequisite:"Ollama running, with a model pulled",hint:"Install Ollama, then `ollama pull` a model before pairing.",install:"https://ollama.com",expects:["ollama","openai-api"]}],to=["claude","chatgpt"];function Bt(){return ce.filter(e=>to.includes(e.id))}function qt(e){return ce.filter(n=>n.costClass===e)}function Ft(e){return ce.find(n=>n.expects.includes(e))??null}import{Fragment as oo,jsx as b,jsxs as O}from"react/jsx-runtime";function dn({machines:e,hosted:n=[],onApproveRuntime:t,onPreferRuntime:r,onDisconnectHosted:o,onPair:s,onRefresh:a,refreshing:c,busy:i,appName:l,error:u,runs:p,runsOpen:y,onToggleRuns:f,markOf:m,loading:w,machineMenu:P,machineNote:R,children:_}){let M=Ee(e),B=e.filter(N=>N.id!==M?.id),I=M&&p?ps(p,M):{};return!M&&n.length===0&&!s?b("p",{className:"sc-note",children:"Nothing connected yet."}):O("div",{className:"sc-tray",children:[M&&O(Nn,{title:"This machine",action:(a||P)&&O("span",{className:"sc-cap-acts",children:[a&&b("button",{type:"button",className:"sc-disc",onClick:a,disabled:c,"aria-label":"Refresh",title:"Refresh",children:b(Ms,{spinning:!!c})}),P]}),children:[b(us,{machine:M,...f?{onToggle:f,open:!!y}:{}}),R]}),M&&f&&y&&b(ms,{machine:M,runs:p??null,...m?{markOf:m}:{}}),M&&b(Nn,{title:"Agents on it",action:b(ks,{machine:M,appName:l,busy:i,...m?{markOf:m}:{},...r?{onPick:N=>r(M.id,N)}:{}}),children:w&&M.runtimes.length===0?b("p",{className:"sc-row-note",children:"Looking\u2026"}):M.runtimes.length>0?M.runtimes.map(N=>b(ws,{runtime:N,serving:I[N.id]??N.serving??0,...m?{mark:m(N)}:{},...t?{onApprove:()=>t(M.id,N.id)}:{}},N.id)):b("p",{className:"sc-row-note",children:"No agent advertised. Install Claude Code, Codex or Ollama on that machine."})}),n.length>0&&b(Nn,{title:n.length>1?"Connected plans":"Connected plan",children:n.map(N=>b(Ns,{credential:N,appName:l,busy:i,...o?{onDisconnect:()=>o(N.provider)}:{}},N.provider))}),(B.length>0||s)&&O(Nn,{title:B.length>0?"Your other machines":M?"Add a machine":"Your machines",children:[B.map(N=>b(ys,{machine:N},N.id)),s&&O("button",{type:"button",className:"sc-pair",onClick:s,children:[b("span",{className:"sc-otile","aria-hidden":"true",children:b(xs,{})}),b("span",{className:"sc-oname",children:e.length>0?"Pair another machine":"Connect a machine"})]})]}),_,u&&b("p",{className:"sc-error sc-tray-error",children:u})]})}function Nn({title:e,action:n,children:t}){return O("section",{className:"sc-group",children:[O("div",{className:"sc-group-cap",children:[b("p",{className:"sc-group-title",children:e}),n]}),b("div",{className:"sc-group-card",children:t})]})}function us({machine:e,onToggle:n,open:t}){let r=Ht(e),o=[r?null:e.pairing_lost?"No longer connected here":"Asleep or offline",$n(e),e.always_on?"always on":null,r&&e.capacity>0?`${e.active} of ${e.capacity} in flight`:Dn(e.last_seen_at)].filter(Boolean),s=O(oo,{children:[O("span",{className:"sc-mtile","aria-hidden":"true",children:[b(ro,{}),b("span",{className:`sc-mbadge sc-mbadge-${Ge(e).tone}`})]}),O("span",{className:"sc-mid",children:[b("span",{className:"sc-mname",children:V(e)}),b("span",{className:"sc-mmeta",children:o.map((a,c)=>O("span",{children:[c>0&&b("span",{className:"sc-mmeta-sep",children:"\xB7"}),a]},a))})]})]});return!n||!r?b("div",{className:"sc-mrow",children:s}):O("button",{type:"button",className:"sc-mrow sc-mrow-btn",onClick:n,"aria-expanded":!!t,title:t?"Hide what it is running":"See what it is running",children:[s,b(Cn,{open:!!t})]})}function ds(e,n){return e.filter(t=>t.machine_id===n.id||t.machine_id===null)}function ps(e,n){let t={};for(let r of e)r.machine_id!==n.id||r.status!=="running"||!r.runtime_id||(t[r.runtime_id]=(t[r.runtime_id]??0)+1);return t}function ms({machine:e,runs:n,markOf:t}){let r=n?ds(n,e):[],o=s=>{if(!s||!t)return null;let a=e.runtimes.find(c=>c.id===s);return a?t(a):null};return b(Nn,{title:"Running now",children:n===null?b("p",{className:"sc-row-note",children:"Looking\u2026"}):r.length===0?b("p",{className:"sc-row-note",children:"Nothing running."}):r.map(s=>{let a=o(s.runtime_id);return b(fs,{run:s,...a?{mark:a}:{}},s.id)})})}function fs({run:e,mark:n}){let t=e.runtime_id?ht(e.runtime_id):null;return O("div",{className:"sc-rrow",children:[b("span",{className:"sc-runtime-tile","aria-hidden":"true",children:n??(t&&b(t,{className:"sc-runtime-mark"}))}),O("span",{className:"sc-mid",children:[O("span",{className:"sc-rtop",children:[b("span",{className:"sc-aname",children:hs(e)}),b("span",{className:"sc-averdict",children:bs(e.started_at)})]}),b("span",{className:"sc-rstep",children:gs(e)})]})]})}function ht(e){let n=Ft(e);return(n?ze[n.id]:null)??no[e]??null}function hs(e){if(e.label)return e.label;if(e.task){let n=e.task.replace(/[_-]+/g," ").trim();return n.charAt(0).toUpperCase()+n.slice(1)}return"A run"}function gs(e){if(e.status==="queued")return"Waiting for a free slot";if(e.step)return e.step;switch(e.phase?.kind){case"thinking":return"Thinking";case"writing":return"Writing";case"tool":return e.phase.tool?`Using ${e.phase.tool}`:"Using a tool";case"approval":return e.phase.tool?`Waiting for you to allow ${e.phase.tool}`:"Waiting for your approval";default:return e.first_output_at?"Working":"Starting"}}function bs(e){let n=Math.max(0,Math.round((Date.now()-new Date(e).getTime())/1e3));if(n<60)return`${n}s`;let t=Math.floor(n/60);return t<60?`${t}m ${String(n%60).padStart(2,"0")}s`:`${Math.floor(t/60)}h ${String(t%60).padStart(2,"0")}m`}function ys({machine:e}){let n=Ge(e);return O("div",{className:"sc-orow",children:[b("span",{className:"sc-otile","aria-hidden":"true",children:b(ro,{})}),b("span",{className:"sc-oname",children:V(e)}),b("span",{className:"sc-oword",children:n.word}),b("span",{className:`sc-dot sc-dot-${n.tone}`,"aria-hidden":"true"})]})}function ws({runtime:e,serving:n=0,mark:t,onApprove:r}){let o=An(e),s=O(oo,{children:[b(vs,{runtime:e,mark:t}),O("span",{className:e.absent?"sc-aname sc-aname-absent":"sc-aname",children:[e.display_name,e.version&&O("span",{className:"sc-aversion",children:[" ",e.version]})]}),n>0?O("span",{className:"sc-averdict",children:[b(Ss,{}),b("span",{className:"sc-aserving",children:n>1?`${n} running`:"running"})]}):e.absent?b("span",{className:"sc-averdict sc-tone-absent",children:"not offered"}):e.quarantined?r?b("button",{type:"button",className:"sc-row-act",onClick:r,children:"Let it serve"}):b("span",{className:"sc-averdict sc-tone-warn",children:"new, not serving yet"}):o.tone==="ok"?O("span",{className:"sc-averdict",children:[b("span",{className:"sc-dot sc-dot-ok","aria-hidden":"true"}),b("span",{className:"sc-sr",children:o.text})]}):b("span",{className:`sc-averdict sc-tone-${o.tone}`,children:o.text})]});return b("div",{className:"sc-arow",children:s})}function vs({runtime:e,mark:n}){if(n)return b("span",{className:"sc-runtime-tile","aria-hidden":"true",children:n});let t=ht(e.id);return b("span",{className:"sc-runtime-tile","aria-hidden":"true",children:t&&b(t,{className:"sc-runtime-mark"})})}function ks({machine:e,appName:n,busy:t,markOf:r,onPick:o}){let s=De(e),a=ye(e),[c,i]=cs(!1),l=ls(null);if(s.by!=="app"&&a.length===0)return null;let u=f=>{if(!f)return null;if(r)return r(f);let m=ht(f.id);return b("span",{className:"sc-runtime-tile","aria-hidden":"true",children:m&&b(m,{className:"sc-runtime-mark"})})},p=f=>{if(!f)return null;if(r)return b("span",{className:"sc-runs-mark",children:r(f)});let m=ht(f.id);return m?b(m,{className:"sc-runs-glyph"}):null},y;return s.by==="app"?y=O("span",{className:"sc-runs-fixed",title:`Set by ${n??"the app"}`,children:[p(s.runtime),s.runtime?.display_name??s.runtimeId]}):!o||a.length<2?y=O("span",{className:"sc-runs-fixed",children:[p(s.runtime),s.runtime?.display_name]}):y=O("button",{ref:l,type:"button",className:"sc-runs-btn","aria-haspopup":"menu","aria-expanded":c,"aria-label":`Runs go to ${s.runtime?.display_name??"the default"}. Change`,disabled:t,onClick:()=>i(f=>!f),children:[p(s.runtime),b("span",{className:"sc-runs-label",children:s.runtime?.display_name}),b(Cn,{open:!0})]}),O("span",{className:"sc-runs-to",children:[b("span",{className:"sc-runs-cap",children:s.by==="app"?`${n??"App"} uses`:"Runs on"}),y,c&&o&&b(Cs,{anchor:l,machine:e,tile:u,onClose:()=>i(!1),onPick:f=>{i(!1),o(f)}})]})}function Cs({anchor:e,machine:n,tile:t,onClose:r,onPick:o}){let s=De(n),a=De({...n,preferred_runtime:null}).runtime,c=s.by==="you"?s.runtimeId:null,i=[{id:null,label:"Automatic",...a?{note:`Uses ${a.display_name}`}:{},glyph:t(a)},...ye(n).map((l,u)=>({id:l.id,label:l.display_name,glyph:t(l),...u===0?{rule:!0}:{}}))];return b(Hn,{anchor:e,label:"Which agent runs go to",options:i,current:c,onClose:r,onPick:o})}function Ns({credential:e,appName:n,busy:t,onDisconnect:r}){return O("div",{className:"sc-hrow",children:[O("div",{className:"sc-orow",children:[b("span",{className:"sc-otile","aria-hidden":"true",children:b(un,{className:"sc-omark"})}),O("span",{className:"sc-mid",children:[b("span",{className:"sc-oname",children:e.provider==="openai-chatgpt"?"ChatGPT plan":e.provider}),b("span",{className:"sc-mmeta",children:e.account_label??"signed in"})]}),r&&b("button",{type:"button",className:"sc-row-act",onClick:r,disabled:t,children:"Disconnect"})]}),r&&O("p",{className:"sc-row-note",children:[n??"This app"," stops using it. To withdraw the grant entirely, remove it in your OpenAI settings."]})]})}function ro(){return O("svg",{viewBox:"0 0 32 24","aria-hidden":"true",focusable:"false",className:"sc-mglyph",children:[b("rect",{x:"4",y:"1.5",width:"24",height:"15",rx:"2.5",fill:"var(--sc-sheet, #ffffff)",stroke:"currentColor",strokeWidth:"2"}),b("rect",{x:"1",y:"19.5",width:"30",height:"2.5",rx:"1.25",fill:"currentColor"})]})}function xs(){return b("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:"sc-oglyph",children:b("path",{d:"M12 5v14M5 12h14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}function Ss(){return O("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:"sc-sglyph sc-spin",children:[b("circle",{cx:"12",cy:"12",r:"9",fill:"none",stroke:"currentColor",strokeWidth:"3",opacity:"0.25"}),b("path",{d:"M12 3a9 9 0 0 1 9 9",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round"})]})}function Ms({spinning:e}){return b("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e?"sc-dglyph sc-spin":"sc-dglyph",children:b("path",{d:"M21 12a9 9 0 1 1-2.64-6.36M21 3v6h-6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as Ps}from"react/jsx-runtime";function Un({machines:e,onApproveRuntime:n}){return Ps(dn,{machines:e,...n?{onApproveRuntime:n}:{}})}var Gt={ready:{arc:!0},serving:{arc:!0,slot:"stream"},paused:{arc:!1,slot:"zzz"},thinking:{arc:!1,slot:"dots"},connecting:{arc:!1,slot:"orbit"},attention:{arc:!1,slot:"bang"},gone:{arc:!1,slot:"cross"},snap:{arc:!1,slot:"snap"},listening:{arc:!1,slot:"bars"},permission:{arc:!1,slot:"ring"},ai:{arc:!1,slot:"sparks"}};var zt="105 162 420 420",Kt="M407.1 308.9 A158 158 0 1 0 407.1 491.1 A116 116 0 0 1 407.1 308.9 Z",pn="M448.5 320 A110 110 0 0 1 448.5 480";import{Fragment as Bn,jsx as S,jsxs as Ke}from"react/jsx-runtime";function Vt({kind:e,size:n=44,className:t}){let r=Gt[e];return Ke("svg",{className:`bx${t?` ${t}`:""}`,"data-expression":e,viewBox:zt,overflow:"visible",width:n,height:n,"aria-hidden":"true",children:[S("path",{d:Kt,fill:"currentColor"}),S("path",{className:"bx-arc",d:pn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),r.slot==="stream"&&S(Rs,{}),r.slot==="zzz"&&S(_s,{}),r.slot==="dots"&&S(Es,{}),r.slot==="bang"&&S(Os,{}),r.slot==="orbit"&&S(Is,{}),r.slot==="cross"&&S(Ts,{}),r.slot==="snap"&&S(Ls,{}),r.slot==="bars"&&S(As,{}),r.slot==="ring"&&S($s,{}),r.slot==="sparks"&&S(Ds,{})]})}function Rs(){return S("path",{className:"bx-st",d:"M475.3 290.3 A150 150 0 0 1 475.3 509.7",fill:"none",stroke:"currentColor",strokeWidth:"15",strokeLinecap:"round",strokeDasharray:"0.1 31"})}function _s(){return Ke(Bn,{children:[S("g",{className:"bx-z1",children:S("path",{d:"M444 372 H496 L444 436 H496",fill:"none",stroke:"currentColor",strokeWidth:"20",strokeLinecap:"round",strokeLinejoin:"round"})}),S("g",{className:"bx-z2",children:S("path",{d:"M492 300 H522 L492 338 H522",fill:"none",stroke:"currentColor",strokeWidth:"15",strokeLinecap:"round",strokeLinejoin:"round"})})]})}function Es(){return Ke(Bn,{children:[S("circle",{className:"bx-th",cx:"463.1",cy:"336.9",r:"21",fill:"currentColor"}),S("circle",{className:"bx-th bx-th2",cx:"483",cy:"400",r:"21",fill:"currentColor"}),S("circle",{className:"bx-th bx-th3",cx:"463.1",cy:"463.1",r:"21",fill:"currentColor"})]})}function Os(){return Ke("g",{className:"bx-at",children:[S("line",{x1:"490",y1:"312",x2:"490",y2:"414",stroke:"currentColor",strokeWidth:"46",strokeLinecap:"round"}),S("circle",{cx:"490",cy:"484",r:"28",fill:"currentColor"})]})}function Is(){return Ke("g",{className:"bx-ob",children:[S("path",{d:pn,fill:"none",stroke:"var(--tile-bg, transparent)",strokeWidth:41,strokeLinecap:"round"}),S("path",{d:pn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})]})}function Ts(){return Ke(Bn,{children:[S("path",{className:"bx-xa",d:pn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),S("g",{className:"bx-xx",children:S("path",{d:"M442 364 L514 436 M514 364 L442 436",fill:"none",stroke:"currentColor",strokeWidth:"24",strokeLinecap:"round"})})]})}function Ls(){return S("path",{className:"bx-snap",d:pn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})}function As(){return Ke("g",{stroke:"currentColor",strokeWidth:"17",strokeLinecap:"round",children:[S("line",{className:"bx-vb",x1:"452",y1:"370",x2:"452",y2:"430"}),S("line",{className:"bx-vb bx-vb2",x1:"482",y1:"330",x2:"482",y2:"470"}),S("line",{className:"bx-vb bx-vb3",x1:"512",y1:"355",x2:"512",y2:"445"})]})}function $s(){return S(Bn,{children:[[450,366],[474,376],[484,400],[474,424],[450,434],[426,424],[416,400],[426,376]].map(([n,t],r)=>S("circle",{className:"bx-w",cx:n,cy:t,r:"11",fill:"currentColor",style:{animationDelay:`${-1.2+r*.15}s`}},r))})}function Ds(){return Ke(Bn,{children:[S("g",{className:"bx-sp",children:S("path",{d:"M460 300 Q465.4 324.6 490 330 Q465.4 335.4 460 360 Q454.6 335.4 430 330 Q454.6 324.6 460 300 Z",fill:"currentColor"})}),S("g",{className:"bx-sp bx-sp2",children:S("path",{d:"M486 356 Q493.92 392.08 530 400 Q493.92 407.92 486 444 Q478.08 407.92 442 400 Q478.08 392.08 486 356 Z",fill:"currentColor"})}),S("g",{className:"bx-sp bx-sp3",children:S("path",{d:"M460 440 Q465.4 464.6 490 470 Q465.4 475.4 460 500 Q454.6 475.4 430 470 Q454.6 464.6 460 440 Z",fill:"currentColor"})})]})}import{useCallback as oe,useEffect as ue,useId as zs,useMemo as Ve,useRef as xn,useState as W}from"react";var qn=[{slug:"mac-arm",label:"macOS, Apple silicon"},{slug:"mac-intel",label:"macOS, Intel"},{slug:"windows",label:"Windows"},{slug:"linux",label:"Linux"}];function Fn(e){if(!e)return"";try{return new URL(e).origin}catch{return""}}function io(e,n){return n<2*6e4?e:n<10*6e4?Math.max(e,6e4):n<30*6e4?Math.max(e,3*6e4):Math.max(e,10*6e4)}var Hs=3e3,Us=2*6e4,gt=Date.now(),bt=new Set,ao=!1;function Ws(){if(ao||typeof window>"u")return;ao=!0;let e=()=>{let t=gt;if(gt=Date.now(),gt-t>Us)for(let r of bt)r()};for(let t of["pointerdown","keydown","wheel","touchstart"])window.addEventListener(t,e,{capture:!0,passive:!0});let n=()=>{if(!document.hidden)for(let t of bt)t()};window.addEventListener("focus",n),document.addEventListener("visibilitychange",n)}function Oe(e,n,t={}){Ws();let r,o=t.immediate===!1?Date.now():0,s=!1,a=!1,c=()=>{a||(r=setTimeout(i,t.idle===!1?n:io(n,Date.now()-gt)))},i=async()=>{if(clearTimeout(r),!(a||s)){if(typeof document>"u"||!document.hidden){s=!0,o=Date.now();try{await e()}catch{}finally{s=!1}}c()}},l=()=>{Date.now()-o>Math.min(n,Hs)&&i()};return bt.add(l),t.immediate===!1?c():i(),()=>{a=!0,clearTimeout(r),bt.delete(l)}}var jt="soba";function lo(){return`${jt}://show`}function Gn(e,n,t){let r=`${jt}://connect?url=${encodeURIComponent(e)}`;return n&&(r+=`&nonce=${encodeURIComponent(n)}`),t&&(r+=`&want=${encodeURIComponent(t)}`),r}function zn(){let e=globalThis.crypto;if(!e?.getRandomValues)return null;let n=e.getRandomValues(new Uint8Array(32)),t="";for(let r of n)t+=String.fromCharCode(r);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var Bs=1600;function Yt(e={}){return Qt(e)}async function Zt(e,n={}){if(typeof window>"u"||typeof document>"u")return"unknown";let t=Qt(n);try{window.location.href=Gn(e,n.nonce,n.want)}catch{return"absent"}return t}async function Jt(e={}){if(typeof window>"u"||typeof document>"u")return"unknown";let n=Qt(e);try{window.location.href=lo()}catch{return"absent"}return n}async function Qt(e){if(typeof window>"u"||typeof document>"u")return"unknown";let n=e.graceMs??Bs,t=document.visibilityState==="visible"&&document.hasFocus(),r=!1,o=()=>{r=!0},s=()=>{document.visibilityState==="hidden"&&(r=!0)};return window.addEventListener("blur",o),window.addEventListener("pagehide",o),document.addEventListener("visibilitychange",s),await new Promise(a=>setTimeout(a,n)),window.removeEventListener("blur",o),window.removeEventListener("pagehide",o),document.removeEventListener("visibilitychange",s),t?r?"opened":"absent":"unknown"}var co="soba.connect.choice",qs=180*24*60*60*1e3;function Xt(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return(n>>>0).toString(36)}function er(e,n){return e?n?`${co}.${e}.${Xt(n)}`:`${co}.${e}`:null}function nr(e){if(!e||typeof localStorage>"u")return null;try{let n=localStorage.getItem(e);if(!n)return null;let t=JSON.parse(n);if(Date.now()-Date.parse(t.at)>qs)return null;let r=ce.find(o=>o.id===t.choice);return r?r.id:null}catch{return null}}function tr(e,n){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({choice:n,at:new Date().toISOString()}))}catch{}}var uo="soba.connect.model",Fs=180*24*60*60*1e3;function rr(e,n){return e?n?`${uo}.${e}.${Xt(n)}`:`${uo}.${e}`:null}function yt(e){if(!e||typeof localStorage>"u")return null;try{let n=localStorage.getItem(e);if(!n)return null;let t=JSON.parse(n);if(Date.now()-Date.parse(t.at)>Fs)return null;let r=t.choice;return typeof r!="string"||!r||r.length>120?null:/^[\w.:@+-]+(\/[\w.:@+-]+)?$/.test(r)?r:null}catch{return null}}function or(e,n){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({choice:n,at:new Date().toISOString()}))}catch{}}var po="soba.connect.dismissed",Gs=30*24*60*60*1e3;function sr(e,n){return e?n?`${po}.${e}.${Xt(n)}`:`${po}.${e}`:null}function ar(e){if(!e||typeof localStorage>"u")return!1;try{let n=localStorage.getItem(e);if(!n)return!1;let t=JSON.parse(n);return Date.now()-Date.parse(t.at)<Gs}catch{return!1}}function ir(e){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({at:new Date().toISOString()}))}catch{}}import{Fragment as kt,jsx as d,jsxs as x}from"react/jsx-runtime";var lr=2e3,Ks=1e4,Vs=9e4,js=6e4;function cr(e,n,t,r=[],o){return e?"code":n&&(t.length>0||r.length>0)?"manage":o?"launch":"choose"}function Ys(e){let n=Math.max(0,Math.round(e/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function pr({client:e,initialCode:n,initialChoice:t,onConnected:r,showStatus:o=!0,initialContext:s=null,initialMachines:a,onClose:c,headingId:i,theme:l,reason:u,active:p=!0}){let y=!!s&&a!==void 0,[f,m]=W(y?cr(n,o,a??[],[],t):"loading"),[w,P]=W(s),[R,_]=W(a??[]),[M,B]=W(n??""),[I,N]=W(null),[F,T]=W(null),[se,X]=W(!1),[ve,K]=W(0),[ae,We]=W(()=>Date.now()),[Y,Me]=W(null),[Xe,de]=W(!1),[pe,ee]=W(!1),[gn,en]=W("browser"),[Le,nn]=W(null),[me,ne]=W([]),[Be,Pe]=W(0),[Ae,qe]=W(null),ie=xn(null),[E,bn]=W(t??null),[v,G]=W(null),te=Ve(()=>{let h=w?.accent?.trim(),C=w?.background?.trim();if(!(!h&&!C))return C?{...ln(C,h),background:C,borderRadius:"inherit"}:{"--sc-accent":h,"--sc-accent-fg":Ln(h)}},[w?.accent,w?.background]),fe=zs(),re=i??fe,Fe=xn(null);ue(()=>{if(!e||y)return;let h=!0;return Promise.all([e.context(),e.machines()]).then(([C,$])=>{h&&(P(C),_($),m(cr(n,o,$)))}).catch(C=>{h&&(T(C.message),m("choose"))}),()=>{h=!1}},[e,n,o,y]),ue(()=>{f!=="loading"||!y||m(cr(n,o,a??[]))},[f,y,n,o,a]),ue(()=>{a&&_(a)},[a]),ue(()=>{s&&P(s)},[s]);let yn=xn(!1),wn=xn(f);wn.current=f;let tn=xn(me);tn.current=me;let rn=!!w?.hosted_available;ue(()=>{!o&&wn.current==="manage"&&m("choose")},[o]),ue(()=>{if(!e||!p||f!=="manage")return;let h=!0,C=Oe(async()=>{try{let $=await e.machines();if(!h)return;_($);let U=!rn||yn.current;$.length===0&&tn.current.length===0&&U&&wn.current==="manage"&&m("choose")}catch{}},Ks,{immediate:!1});return()=>{h=!1,C()}},[f,e,rn,p]);let on=er(w?.publishable_key??null);ue(()=>{G(nr(on))},[on]),ue(()=>{if(!e||!rn)return;let h=!0;return e.hosted().then(C=>{h&&(ne(C.credentials),!yn.current&&(yn.current=!0,C.credentials.length>0&&o&&wn.current==="choose"&&m("manage")))}).catch(()=>{}),()=>{h=!1}},[e,rn,o]),ue(()=>{if(!e||!p||f!=="hosted")return;let h=!0,C=async()=>{try{let _e=await e.hosted();if(!h)return!1;if(ne(_e.credentials),_e.credentials.length>0)return m("hosted_connected"),qe(null),!0}catch{}return!1},$=async()=>{ie.current?.closed&&(ie.current=null,!await C()&&h&&m("choose"))},U=Oe(C,lr,{immediate:!1}),an=setInterval($,400),Ce=_e=>{let On=_e.data;On?.source==="soba"&&On.type==="hosted_result"&&C()};return window.addEventListener("message",Ce),()=>{h=!1,U(),clearInterval(an),window.removeEventListener("message",Ce),ie.current=null}},[e,f,p]);let It=oe(()=>{if(!e)return;let h=window.open("","soba-connect-plan","width=520,height=760,noopener=no");ie.current=h,m("hosted"),Pe(Date.now()),qe(null),T(null),e.startHosted().then(({url:C})=>{if(h&&!h.closed){h.location.href=C;return}qe(C)}).catch(C=>{h?.close(),ie.current=null,T(C.message),m("choose")})},[e]),it=oe(async h=>{if(e){X(!0);try{await e.disconnectHosted(h),ne((await e.hosted()).credentials)}catch(C){T(C.message)}finally{X(!1)}}},[e]);ue(()=>{if(!e||!p||f!=="waiting")return;let h=!0,C=Oe(async()=>{try{let $=await e.machines();if(!h)return;_($);let U=Fe.current;if(!U)return;let an=$.filter(_e=>!U.has(_e.id)),Ce=an.find(_e=>_e.state!=="offline")??an[0];if(Ce){nn(Ce.id),E&&tr(on,E);let _e=ce.find(At=>At.id===E)?.expects??[],On=ye(Ce).find(At=>_e.includes(At.id));On&&e.preferRuntime(Ce.id,On.id).catch(()=>{}),m("connected"),r?.($)}}catch{}},lr,{immediate:!1});return()=>{h=!1,C()}},[f,e,r,E,on,p]);let lt=oe(async()=>{if(e){T(null),X(!0);try{let h=await e.lookup(M);N(h),m("confirm")}catch(h){T(h.message)}finally{X(!1)}}},[e,M]),vn=oe(async()=>{if(e){T(null),X(!0);try{try{Fe.current=new Set((await e.machines()).map(h=>h.id))}catch{Fe.current=new Set(R.map(h=>h.id))}await e.approve(M),m("waiting"),K(Date.now())}catch(h){T(h.message)}finally{X(!1)}}},[e,M,R]),ct=oe(async()=>{if(e){X(!0);try{await e.deny(M),en("browser"),m("denied")}catch(h){T(h.message)}finally{X(!1)}}},[e,M]),q=Ve(()=>w?.connect_url??null,[w]),[Re,he]=W(()=>zn()),sn=Ve(()=>q?Gn(q,Re??void 0,E??void 0):null,[q,Re,E]),ut=Ve(()=>Fn(q),[q]),Tt=oe(h=>{if(R.length===0)return null;let C=ce.find(U=>U.id===h);if(!C)return null;let $=R.flatMap(U=>U.runtimes??[]).filter(U=>C.expects.includes(U.id));return $.length===0?{tone:"dim",text:"not installed"}:$.some(U=>U.authenticated===!0)?{tone:"ok",text:"ready"}:$.every(U=>U.authenticated===!1)?{tone:"warn",text:"needs signing in"}:{tone:"dim",text:"installed"}},[R]),k=oe((h=null)=>{bn(h),T(null),Me(null),de(!1),ee(!1),z.current=!1,he(zn()),m("launch")},[]),z=xn(!!t);ue(()=>{f!=="launch"||!q||z.current||(z.current=!0,de(!0),Zt(q,{...Re?{nonce:Re}:{},...E?{want:E}:{}}).then(Me))},[f,q,Re,E]);let le=oe(()=>{de(!0),Yt().then(Me)},[]),dt=oe(h=>{if(pe){let C=zn();ee(!1),he(C),q&&(h.preventDefault(),window.location.href=Gn(q,C??void 0,E??void 0))}le()},[pe,le,q,E]),ge=Ve(()=>{let h=w?.runtimes;return h?ce.filter(C=>h.includes(C.id)):Bt()},[w?.runtimes]),ke=Ve(()=>{let h=ce.find(C=>C.id===E);return h?{choice:h,Mark:ze[h.id]??null}:null},[E]),$e=Ve(()=>R.find(h=>h.id===Le),[R,Le]);ue(()=>{let h=Re;if(!e||!p||f!=="launch"||!h)return;let C=!1,$=Date.now()+15e4,U=()=>{};return U=Oe(async()=>{if(Date.now()>$){U(),ee(!0);return}try{let an=await e.claim(h);if(C)return;if(an.declined){U(),Me(null),en("machine"),m("denied");return}if(!an.claimed)return;U();try{Fe.current=new Set((await e.machines()).map(Ce=>Ce.id))}catch{Fe.current=new Set(R.map(Ce=>Ce.id))}m("waiting"),K(Date.now())}catch{}},lr,{immediate:!1,idle:!1}),()=>{C=!0,U()}},[e,f,R,Re,p]);let be=Ve(()=>{if(!I)return null;if(I.approved||I.denied)return"answered";let h=I.expires_at?Date.parse(I.expires_at):Number.NaN;return Number.isFinite(h)&&h<=ae?"expired":"live"},[I,ae]);ue(()=>{if(!(f==="confirm"&&be==="live"||f==="waiting"||f==="hosted"))return;let C=setInterval(()=>We(Date.now()),1e3);return()=>clearInterval(C)},[f,be]);let pt=oe(async(h,C)=>{if(e)try{await e.approveRuntime(h,C),_(await e.machines())}catch($){T($.message)}},[e]),Lt=oe(async(h,C)=>{if(e)try{await e.preferRuntime(h,C),_(await e.machines())}catch($){T($.message)}},[e]);return f==="loading"?d("div",{className:"soba-connect",...l?{"data-theme":l}:{},style:te,children:d("div",{className:"sc-card",children:d("p",{className:"sc-note",children:"Loading\u2026"})})}):x("div",{className:"soba-connect",...l?{"data-theme":l}:{},style:te,children:[c&&d("button",{type:"button",className:"sc-modal-close",onClick:c,"aria-label":"Close",children:"\xD7"}),f==="manage"&&x("div",{className:"sc-card",children:[d("h2",{className:"sc-title",id:re,children:"Your compute"}),x("p",{className:"sc-sub",children:[d(wt,{context:w})," ",R.length>0&&me.length>0?"runs on your connected plan, and on these machines while they are awake.":me.length>0?"runs on the plan you connected. Nothing here is charged to you.":"runs on these machines, while they are awake."]}),d(dn,{machines:R,hosted:me,onApproveRuntime:pt,onPreferRuntime:(h,C)=>void Lt(h,C),onDisconnectHosted:h=>void it(h),onPair:()=>m("choose"),busy:se,...w?.app.name?{appName:w.app.name}:{}}),F&&d("p",{className:"sc-error",children:F})]}),f==="choose"&&x("div",{className:"sc-card",children:[d(Js,{context:w}),d("h2",{className:"sc-h",id:re,children:u==="payment_required"?"Carry on with your own AI":u==="no_compute"?"This run needs a machine":"Connect your AI"}),d("p",{className:"sc-p",children:"Use compute you already have."}),q&&ge.length>0&&x(kt,{children:[d("div",{className:"sc-opts",children:ge.map(h=>{let C=ze[h.id];return x("button",{type:"button",className:"sc-opt",onClick:()=>k(h.id),children:[d("span",{className:"sc-opt-tile","aria-hidden":"true",children:C&&d(C,{className:"sc-opt-mark"})}),d("span",{className:"sc-opt-text",children:d("span",{className:"sc-opt-label",children:h.label})}),(()=>{let $=Tt(h.id);return $?d("span",{className:`sc-opt-has sc-opt-has-${$.tone}`,children:$.text}):v===h.id?d("span",{className:"sc-opt-last",children:"last used"}):d(ur,{className:"sc-opt-go"})})()]},h.id)})}),x("p",{className:"sc-opt-note",children:["Your accounts stay there. ",mo(w)," never sees them."]})]}),(!q||ge.length===0)&&d("p",{className:"sc-error",style:{marginTop:16},children:"This app has no publishable key yet, so there is nothing to pair against."}),F&&d("p",{className:"sc-error",children:F}),q&&w?.show_code===!0&&d("div",{className:"sc-opt-alt",children:d("button",{type:"button",className:"sc-alt-link",onClick:()=>m("code"),children:"I have a code"})})]}),f==="launch"&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:"Soba App"})]}),d(vt,{mark:ke?.Mark??j,still:pe||!Xe&&Y===null}),d("h2",{className:"sc-h",id:re,children:pe?"No answer from this machine":Y==="absent"?"Nothing opened":Y===null?"Opening Soba App\u2026":"Approve it on this machine"}),pe?d("p",{className:"sc-p",children:"The Soba app did not answer. It may not be open, or nobody was there. Try again when you are ready."}):Y==="absent"?d("p",{className:"sc-p",children:"Nothing opened on this machine. Open it yourself below, or install it if it is not here yet."}):d("p",{className:"sc-p",children:Y===null?"Approve it there and this page does the rest.":"This page finishes on its own."}),ke&&x("p",{className:"sc-prereq",children:[ke.Mark&&d(ke.Mark,{className:"sc-rt-mark"}),"Needs ",ke.choice.prerequisite]}),x("div",{className:"sc-stack",style:{marginTop:18},children:[d("a",{className:Y==="absent"||pe?"sc-btn sc-btn-primary":"sc-btn",href:sn??"#",onClick:dt,children:pe?"Try again":Y==="absent"?"Open Soba App":"Open it again"}),d("p",{className:"sc-note",children:Y===null?"Your browser will ask permission first.":"Your browser asks permission the first time."}),ke&&Y==="absent"&&d("p",{className:"sc-note",children:d(Qs,{text:ke.choice.hint})}),x("div",{className:"sc-foot-strip",children:[d("span",{children:"Not installed on this machine?"}),x("button",{type:"button",className:"sc-foot-go",onClick:()=>m("get"),children:["Get it",d(ur,{})]})]})]})]}),f==="get"&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("launch")}),d("p",{className:"sc-head-title",children:"Get Soba App"})]}),d("div",{className:"sc-opts",children:qn.map(h=>x("a",{className:"sc-opt",href:`${ut}/download/${h.slug}`,target:"_blank",rel:"noreferrer noopener",children:[d("span",{className:"sc-opt-tile","aria-hidden":"true",children:d(Wt,{className:"sc-opt-mark"})}),d("span",{className:"sc-opt-text",children:d("span",{className:"sc-opt-label",children:h.label})}),d(ur,{className:"sc-opt-go"})]},h.slug))}),d("p",{className:"sc-opt-note",children:"Install it, then come back here and press the row you started with."})]}),f==="code"&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:"Soba App"})]}),d("h2",{className:"sc-h",id:re,children:"Enter the code from that machine"}),d("p",{className:"sc-p",children:"Eight characters, shown by the Soba app once you paste the link."}),x("form",{className:"sc-stack",style:{marginTop:16},onSubmit:h=>{h.preventDefault(),lt()},children:[d("input",{className:"sc-input",value:M,onChange:h=>B(h.target.value),placeholder:"ACDE-F234",autoComplete:"off",autoFocus:!0,"aria-label":"Pairing code"}),F&&d("p",{className:"sc-error",children:F}),d("button",{type:"submit",className:"sc-btn sc-btn-primary",disabled:se||M.length<8,children:se?"Checking\u2026":"Continue"})]})]}),f==="confirm"&&I&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("code")}),d("p",{className:"sc-head-title",children:"Soba App"})]}),d("h2",{className:"sc-title",children:"Attach this machine to your account?"}),x("p",{className:"sc-sub",children:[d(wt,{context:w})," may send your runs to it once you approve. It can never see the account or the keys on it."]}),x("ul",{className:"sc-facts",children:[d(Kn,{k:"Code",v:I.user_code}),d(Kn,{k:"Machine",v:I.hostname??"not stated"}),d(Kn,{k:"System",v:[I.platform,I.arch].filter(Boolean).join(" / ")||"not stated"}),d(Kn,{k:"Asked by",v:I.client??"not stated"}),I.labels.length>0&&d(Kn,{k:"Labels",v:I.labels.join(", ")})]}),d("p",{className:"sc-note",style:{marginTop:12},children:"Every line above is what that machine said about itself. If none of it looks like a computer of yours, say no."}),be==="expired"&&d("p",{className:"sc-error",children:"That code has expired. Ask the machine for a new one. It prints a fresh code each time it starts."}),be==="answered"&&d("p",{className:"sc-error",children:"That code has already been answered. If it was not you, deny the next one."}),F&&d("p",{className:"sc-error",children:F}),x("div",{className:"sc-row",style:{marginTop:16},children:[d("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:()=>void vn(),disabled:se||be!=="live",children:"Approve"}),d("button",{type:"button",className:"sc-btn",onClick:()=>void ct(),disabled:se||be==="answered",children:"No, deny it"})]}),be==="live"&&I.expires_at&&x("p",{className:"sc-note",style:{marginTop:10},children:["This code expires in ",Ys(Date.parse(I.expires_at)-ae),"."]})]}),f==="waiting"&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:ke?.choice.short??"Soba App"})]}),d(vt,{mark:ke?.Mark??j}),d("h2",{className:"sc-h",id:re,children:"Approved. Waiting for it to connect"}),d("p",{className:"sc-p",children:"Nothing more to do here. This page changes when it arrives."}),ve>0&&ae-ve>Vs&&d("p",{className:"sc-note sc-tone-warn",style:{marginTop:14,textAlign:"center"},children:"Still nothing. Look at the Soba app on that machine: it says what it is doing. This keeps watching either way."})]}),f==="connected"&&x("div",{className:"sc-card",children:[d(dr,{tone:"ok"}),d("h2",{className:"sc-h",id:re,children:$e?.label?`${$e.label} is connected`:"Connected"}),x("p",{className:"sc-p",children:[d(wt,{context:w})," will use ",$e?.label?"it":"this machine"," from now on, while it is awake."]}),o&&x(kt,{children:[d("div",{style:{marginTop:16},children:d(Un,{machines:R,onApproveRuntime:pt})}),d("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:14},onClick:()=>m("manage"),children:"Done"})]})]}),f==="hosted"&&x("div",{className:"sc-card",children:[x("div",{className:"sc-head",children:[d(Sn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:"ChatGPT"})]}),Ae?d(vt,{mark:un,still:!0}):d(vt,{mark:un}),d("h2",{className:"sc-h",id:re,children:Ae?"Your browser blocked the window":"Finish signing in to ChatGPT"}),d("p",{className:"sc-p",children:Ae?"Nothing opened. Open the sign-in yourself below. A link you click is allowed where a window we open is not.":"Approve it in the window that opened."}),x("div",{className:"sc-stack",style:{marginTop:18},children:[Ae&&d("a",{className:"sc-btn sc-btn-primary",href:Ae,target:"soba-connect-plan",rel:"noreferrer",children:"Open the ChatGPT sign-in"}),F&&d("p",{className:"sc-error",children:F}),Be>0&&ae-Be>js&&d("p",{className:"sc-note sc-tone-warn",children:"Still nothing. The window may have been closed before it finished, or the sign-in may have been declined. This keeps watching either way."})]})]}),f==="hosted_connected"&&x("div",{className:"sc-card",children:[d(dr,{tone:"ok"}),d("h2",{className:"sc-h",id:re,children:"ChatGPT is connected"}),x("p",{className:"sc-p",children:[d(wt,{context:w})," will run on your ChatGPT plan",me[0]?.account_label?` (${me[0].account_label})`:"",". Nothing more to pay, nothing to install."]}),d("p",{className:"sc-opt-note",style:{textAlign:"center"},children:"It runs on our side, so it has no access to your files or your terminal."}),o&&x(kt,{children:[d("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>m("manage"),children:"Done"}),d("div",{className:"sc-opt-alt",children:d("button",{type:"button",className:"sc-alt-link",onClick:()=>m("choose"),children:"Connect a machine too"})})]})]}),f==="denied"&&x("div",{className:"sc-card",children:[d(dr,{tone:"off"}),d("h2",{className:"sc-h",id:re,children:"Declined"}),d("p",{className:"sc-p",children:gn==="machine"?"Nothing was connected. You can ask again whenever you like.":"That machine was not attached to your account, and the terminal has been told so."}),d("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>m("choose"),children:"Back to the start"})]})]})}function mo(e){return e?.app.name??"this app"}function Zs(e){let n=e?.app.icon_urls;if(n?.length)return n;let t=e?.app.icon_url;return t?[t]:[]}function fo(e){let n=Zs(e),[t,r]=W([]),o=oe(c=>{c&&r(i=>i.includes(c)?i:[...i,c])},[]),s=oe(c=>o(c.currentTarget.getAttribute("src")),[o]),a=oe(c=>{c?.complete&&c.naturalWidth===0&&o(c.getAttribute("src"))},[o]);return{icon:n.find(c=>!t.includes(c)),onError:s,ref:a}}function Js({context:e}){let{icon:n,onError:t,ref:r}=fo(e);return e?.app.mark==="soba"?d(j,{className:"sc-app-mark"}):n?d("img",{className:"sc-app-mark",src:n,alt:"","aria-hidden":"true",ref:r,onError:t}):null}function wt({context:e}){let{icon:n,onError:t,ref:r}=fo(e),o=e?.app.mark==="soba";return x("span",{className:"sc-app",children:[o&&d(j,{className:"sc-app-icon"}),!o&&n&&d("img",{className:"sc-app-icon",src:n,alt:"",ref:r,onError:t}),mo(e)]})}function Sn({onClick:e}){return d("button",{type:"button",className:"sc-head-back",onClick:e,"aria-label":"Back",children:d("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:d("path",{d:"M15 5 8 12l7 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function ur({className:e}){return d("svg",{className:e,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:d("path",{d:"M9 5l7 7-7 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function vt({mark:e,still:n}){return x("span",{className:"sc-waiting","aria-hidden":"true",children:[!n&&d("svg",{className:"sc-waiting-orbit",viewBox:"0 0 100 100","aria-hidden":"true",focusable:"false",children:d("circle",{className:"sc-waiting-arc",cx:"50",cy:"50",r:"46"})}),d(e,{className:"sc-waiting-mark"})]})}function dr({tone:e}){return d("span",{className:`sc-result sc-result-${e}`,"aria-hidden":"true",children:d(Vt,{kind:e==="ok"?"snap":"gone",size:84})})}function Qs({text:e}){return d(kt,{children:e.split("`").map((n,t)=>t%2===1?d("code",{className:"sc-inline-code",children:n},t):n)})}function Kn({k:e,v:n}){return x("li",{className:"sc-fact",children:[d("span",{className:"sc-fact-key",children:e}),d("span",{children:n})]})}import{useEffect as Xs,useRef as fr}from"react";var Ct=0,mr=null;function ho(){if(typeof document>"u")return()=>{};Ct===0&&(mr=document.body.style.overflow,document.body.style.overflow="hidden"),Ct+=1;let e=!1;return()=>{e||(e=!0,Ct-=1,Ct===0&&(document.body.style.overflow=mr??"",mr=null))}}import{jsx as go}from"react/jsx-runtime";function Vn({open:e,onClose:n,labelledBy:t,theme:r,style:o,children:s}){let a=fr(null),c=fr(null),i=fr(null);return Xs(()=>{let l=a.current;if(l){if(!e){l.open&&l.close();return}return l.open||l.showModal(),document.activeElement===l&&c.current?.focus(),ho()}},[e]),go("dialog",{ref:a,className:"soba-connect sc-modal","aria-labelledby":t,...r?{"data-theme":r}:{},style:o,onCancel:l=>{l.preventDefault(),n()},onPointerDown:l=>{i.current=l.target},onClick:l=>{l.target===l.currentTarget&&i.current===l.currentTarget&&n()},children:go("div",{className:"sc-modal-sheet",ref:c,tabIndex:-1,children:s})})}import{useRef as ta,useState as ra}from"react";var ea={"claude-code":{small:"haiku",large:"opus"}};function bo(e){let n=ea[e];return!!(n?.small||n?.large)}var na={haiku:"Haiku",sonnet:"Sonnet",opus:"Opus",fable:"Fable"};function yo(e){return na[e]??e}function hr(e){let n=[...e].sort(mt),t=Ee([...e]),r=t?De(t):null,s=[{id:"auto",kind:"auto",label:"Automatic",model:"auto",...r?.runtime?{note:`Uses ${r.runtime.display_name}`}:{}}];n.some(u=>ye(u).some(p=>bo(p.id)))&&s.push({id:"small",kind:"size",label:"Fast",note:"quick and cheap",model:"small"},{id:"large",kind:"size",label:"Best",note:"the most capable",model:"large"});let c=new Map;for(let u of n)for(let p of ye(u))for(let y of p.models){if(!y)continue;let f=`${p.id}/${y}`,m=c.get(f);if(m){m.machines.add(V(u));continue}c.set(f,{option:{id:f,kind:"named",label:yo(y),model:y,runtime:p.id,runtimeName:p.display_name,costClass:p.cost_class},machines:new Set([V(u)])})}let i=new Set;for(let{machines:u}of c.values())for(let p of u)i.add(p);let l=i.size>1;for(let{option:u,machines:p}of c.values()){let y=l&&p.size===1?[...p][0]:void 0;s.push(y?{...u,machine:y}:u)}return s}function jn(e){let n=[],t=[];for(let r of e){if(r.kind!=="named"){n.push(r);continue}let o=r.runtimeName??r.runtime??"",s=t.find(a=>a.heading===o);s?s.options.push(r):t.push({heading:o,options:[r]})}return n.length?[{heading:null,options:n},...t]:t}function gr(e,n){let t=e.find(o=>o.kind==="auto")??{id:"auto",kind:"auto",label:"Automatic",model:"auto"};if(!n||n==="auto")return{selected:t,unavailable:null};let r=e.find(o=>o.id===n);return r?{selected:r,unavailable:null}:{selected:t,unavailable:n}}function br(e){return e.runtime?{model:e.model,runtime:e.runtime}:{model:e.model}}function Yn(e){return e.length>1}import{jsx as Nt,jsxs as wo}from"react/jsx-runtime";function yr({options:e,selected:n,onPick:t,caption:r,disabled:o,className:s}){let[a,c]=ra(!1),i=ta(null);if(!Yn(e))return null;let l=s?`sc-mp ${s}`:"sc-mp";return wo("span",{className:l,children:[r&&Nt("span",{className:"sc-mp-cap",children:r}),wo("button",{ref:i,type:"button",className:"sc-mp-btn","aria-haspopup":"menu","aria-expanded":a,"aria-label":`Model: ${n.label}. Change`,disabled:o,onClick:()=>c(u=>!u),children:[Nt("span",{className:"sc-mp-label",children:n.label}),Nt(Cn,{open:!0})]}),a&&Nt(Hn,{anchor:i,label:"Which model answers",options:oa(e),current:n.id,onClose:()=>c(!1),onPick:u=>{c(!1),u&&t(u)}})]})}function oa(e){let n=[];for(let t of jn(e))t.options.forEach((r,o)=>{let s=sa(r);n.push({id:r.id,label:r.label,...s?{note:s}:{},...t.heading&&o===0?{heading:t.heading}:{},...!t.heading&&r.kind==="size"&&o===1?{rule:!0}:{}})});return n}function sa(e){return e.kind!=="named"?e.note:e.machine?`on ${e.machine}`:void 0}import{useEffect as wr,useRef as aa}from"react";import{jsx as ia}from"react/jsx-runtime";var mn=8;function vr({open:e,onClose:n,anchor:t,label:r,theme:o,style:s,children:a}){let c=aa(null);return wr(()=>{let i=c.current;if(!(!i||!(typeof i.showPopover=="function")))try{e?i.showPopover():i.hidePopover()}catch{}},[e]),wr(()=>{if(!e)return;let i=()=>{let u=c.current,p=t.current;if(!u||!p)return;let y=p.getBoundingClientRect(),f=u.offsetWidth,m=u.offsetHeight,w=window.innerWidth-f-mn,P=Math.max(mn,Math.min(y.right-f,Math.max(mn,w))),R=y.bottom+mn,_=y.top-mn-m,M=R+m>window.innerHeight-mn&&_>mn?_:R;u.style.left=`${Math.round(P)}px`,u.style.top=`${Math.round(M)}px`};i();let l=requestAnimationFrame(i);return window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{cancelAnimationFrame(l),window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[e,t]),wr(()=>{if(!e)return;let i=u=>{u.key==="Escape"&&n()},l=u=>{let p=u.target;p&&(c.current?.contains(p)||t.current?.contains(p)||n())};return document.addEventListener("keydown",i),document.addEventListener("pointerdown",l,!0),()=>{document.removeEventListener("keydown",i),document.removeEventListener("pointerdown",l,!0)}},[e,n,t]),ia("div",{ref:c,role:"dialog","aria-label":r,className:"soba-connect sc-pop",...o?{"data-theme":o}:{},popover:"manual",hidden:!e,style:s,children:a})}var Zn=new Map,Mn=new Map,vo=!1;function la(){vo||typeof window>"u"||(vo=!0,window.addEventListener("storage",e=>{!e.key||!Zn.has(e.key)||(Mn.set(e.key,yt(e.key)),kr(e.key))}))}function kr(e){for(let n of Zn.get(e)??[])n()}function Jn(e){return e??""}function Cr(e,n){let t=Jn(e);la();let r=Zn.get(t)??new Set;return r.add(n),Zn.set(t,r),()=>{r.delete(n),r.size===0&&Zn.delete(t)}}function xt(e){let n=Jn(e),t=Mn.get(n);if(t!==void 0)return t;let r=e?yt(e):null;return Mn.set(n,r),r}function Nr(){return null}function xr(e,n){xt(e)===null&&(Mn.set(Jn(e),n),kr(Jn(e)))}function Sr(e,n){let t=Jn(e);Mn.get(t)!==n&&(Mn.set(t,n),or(e,n),kr(t))}function He(e){let n=`${e.unit}s`;return e.reward==="unlimited"?`Unlimited ${n} on your own AI`:e.reward==="included"&&e.includedUnits!==null?`${ua(e.includedUnits)} ${n} a month once you connect`:e.reward==="credit"&&e.creditMicros>0?`${ca(e.creditMicros)} back each month you stay connected`:null}function Ue(e){return e==="unlimited"||e==="included"}var Co=new Set(["user-hardware","user-subscription"]),ko=new Set(["open-weights","frontier"]);function xe(e){return e===null||e.length===0?!1:e.every(n=>Co.has(n))}var ca=e=>(e/1e6).toLocaleString("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}),ua=e=>e.toLocaleString("en-US");function Mr(e,n){if(!(n===null||n.some(s=>ko.has(s))))return!1;let r=e.findIndex(s=>Co.has(s));if(r===-1)return!1;let o=e.findIndex(s=>ko.has(s));return o===-1||r<o}import{createContext as No,useContext as xo}from"react";var Pr=No(null);function St(){return xo(Pr)}var Rr=No({context:null,machines:void 0,theme:"light"});function H(){return xo(Rr)}import{useMemo as ma}from"react";import{createContext as da,useContext as pa}from"react";var _r=da(null);function D(){let e=pa(_r);if(!e)throw new Error("useSoba() must be used inside a <SobaProvider>.");return e}function Qn(){let{compute:e}=D();return ma(()=>{let n=e.machines,t=[...n].sort((s,a)=>Ee([s,a])===s?-1:1).map(fa),r=Ee([...n]),o=cn(n);return{view:t.length?"machines":e.loading?"loading":e.error?"error":"empty",machines:t,primary:r?t.find(s=>s.machine.id===r.id)??null:null,connected:e.connected,online:e.online,stalled:e.connected&&!e.online&&o?t.find(s=>s.machine.id===o.id)??null:null,loading:e.loading,error:e.error,refresh:e.refresh}},[e])}function fa(e){let n=De(e);return{machine:e,name:V(e),state:Ge(e),status:Dt(e),hardware:$n(e),lastSeen:e.state==="offline"?Dn(e.last_seen_at):null,runtimes:ye(e).map(t=>({runtime:t,name:t.display_name,auth:An(t),quarantined:!!t.quarantined})),runsOn:{by:n.by,name:n.runtime?.display_name??null}}}import{jsx as Xn}from"react/jsx-runtime";function ha({className:e}){let{theme:n}=H(),t=e?`soba-connect ${e}`:"soba-connect";return Xn("div",{className:t,"data-theme":n,children:Xn(Er,{})})}function Er(){let e=Qn();return e.view==="loading"?Xn("p",{className:"sc-note",children:"Loading\u2026"}):e.view==="error"?Xn("p",{className:"sc-error",children:e.error?.message}):Xn(Un,{machines:e.machines.map(n=>n.machine)})}import{useCallback as nt,useEffect as Rt,useMemo as wa,useRef as Or,useState as je}from"react";import{useId as ga}from"react";import{jsx as Pn,jsxs as Mt}from"react/jsx-runtime";function et({open:e,onOpenChange:n,initialCode:t,onConnected:r,showStatus:o,reason:s}){let{error:a}=D(),c=St(),i=H(),l=()=>n(!1),u=ga(),p=i.context?.background?.trim(),y=p?ln(p,i.context?.accent):void 0;return Mt(Vn,{open:e,onClose:l,labelledBy:u,theme:i.theme,style:y,children:[a?Mt("div",{className:"sc-card",children:[Pn("h2",{className:"sc-title",id:u,children:"Could not start"}),Pn("p",{className:"sc-error",children:a.message})]}):!c&&!i.context?Mt("div",{className:"sc-card",children:[Pn("h2",{className:"sc-title",id:u,children:"One moment"}),Pn("p",{className:"sc-note",children:"Getting your compute\u2026"})]}):Pn(pr,{client:c,active:e,onClose:l,headingId:u,theme:i.theme,initialContext:i.context,...i.machines!==void 0?{initialMachines:i.machines}:{},...t?{initialCode:t}:{},...r?{onConnected:r}:{},...o===void 0?{}:{showStatus:o},...s?{reason:s}:{}}),Mt("p",{className:"sc-modal-foot",children:[Pn(j,{className:"sc-foot-mark"}),"Secured by Soba"]})]})}import{useCallback as ba}from"react";function ya(){let{connect:e}=D(),n=Qn(),t=ba(()=>e.open("manual"),[e]);return{...Pt(n.primary?.machine??null),machine:n.primary,open:t,canOpen:e.hasModal,loading:n.view==="loading"}}function Pt(e){let n=Ge(e);return{label:e?n.word:"Connect compute",ariaLabel:e?`${n.word} on ${V(e)}`:"Connect compute",connected:e!==null,state:n}}import{Fragment as Ir,jsx as Ye,jsxs as tt}from"react/jsx-runtime";function fn({children:e,variant:n,className:t,initialCode:r,onConnected:o,defaultOpen:s,open:a,onOpenChange:c,showConnected:i=!0}){let{compute:l,connect:u}=D(),p=H(),{theme:y}=p,f=St(),[m,w]=je(s??!!r),P=Or(null),R=a!==void 0,_=!R&&!s&&!r&&u.hasModal,M=R?a:_?u.isOpen:m,B=v=>{_?v?u.open("manual"):u.close():R||w(v),c?.(v)},I=Or(M);Rt(()=>{I.current&&!M&&P.current?.focus(),I.current=M},[M]);let[N,F]=je(null),[T,se]=je(!1),X=wa(()=>T&&N?va(l.machines,N):l.machines,[l.machines,T,N]),ve=Ee(X),K=Pt(ve),ae=i&&K.connected,We=K.state,Y=nt(()=>se(!1),[]),[Me,Xe]=je(!1),de=nt(async()=>{Xe(!0);try{await l.refresh()}finally{Xe(!1)}},[l]),pe=Or(de);pe.current=de,Rt(()=>{T&&pe.current()},[T]);let[ee,gn]=je(!1),[en,Le]=je([]),nn=!!p.context?.hosted_available;Rt(()=>{if(!T||!f||!nn)return;let v=!0;return f.hosted().then(G=>{v&&Le(G.credentials)}).catch(()=>{}),()=>{v=!1}},[T,f,nn]);let[me,ne]=je(!1);Rt(()=>{if(!T||!f)return;let v=!0,G=Oe(async()=>{let te=await f.runs();v&&F(te)},3e3);return()=>{v=!1,G()}},[T,f]);let[Be,Pe]=je(null),Ae=nt(async(v,G)=>{if(f){Pe(null);try{await f.approveRuntime(v,G),await l.refresh()}catch(te){Pe(te.message)}}},[f,l]),qe=nt(async(v,G)=>{if(f){Pe(null);try{await f.preferRuntime(v,G),await l.refresh()}catch(te){Pe(te.message)}}},[f,l]),ie=nt(async v=>{if(f){Pe(null);try{await f.disconnectHosted(v),Le((await f.hosted()).credentials)}catch(G){Pe(G.message)}}},[f]),E=p.context?.background?.trim(),bn=E?ln(E,p.context?.accent):void 0;return tt(Ir,{children:[Ye("button",{ref:P,type:"button","data-theme":y,className:["sc-btn",ae?"sc-btn-connected":"sc-btn-icon",!ae&&n==="primary"?"sc-btn-primary":"",t].filter(Boolean).join(" "),...ae&&!e?{"aria-haspopup":"dialog","aria-expanded":T,"aria-label":K.ariaLabel}:{},onClick:()=>{if(ae&&!e&&!R&&!s&&!r){se(v=>!v);return}B(!0)},children:e??(ae?tt(Ir,{children:[Ye("span",{className:"sc-pill-tile","aria-hidden":"true",children:Ye(j,{className:We.tone==="busy"?"sc-pill-mark sc-pill-mark-busy":"sc-pill-mark"})}),tt("span",{className:"sc-btn-connected-text",children:[We.word,ve&&tt("span",{className:"sc-btn-connected-where",children:[" on ",V(ve)]})]}),Ye("i",{className:`sc-dot sc-dot-${We.tone}`,"aria-hidden":"true"})]}):tt(Ir,{children:[Ye(j,{className:"sc-btn-mark"}),"Connect compute"]}))}),Ye(vr,{open:T,onClose:Y,anchor:P,label:"Your compute",theme:y,...bn?{style:bn}:{},children:Ye(dn,{machines:X,hosted:en,onApproveRuntime:(v,G)=>void Ae(v,G),onPreferRuntime:(v,G)=>void qe(v,G),onDisconnectHosted:v=>void ie(v),onRefresh:()=>void de(),refreshing:Me,error:Be,runs:N,runsOpen:me,onToggleRuns:()=>ne(v=>!v),onPair:()=>{se(!1),_?u.open("pair"):(gn(!0),B(!0))},...p.context?.app.name?{appName:p.context.app.name}:{}})}),!_&&Ye(et,{open:M,onOpenChange:v=>{v||gn(!1),B(v)},...ee?{showStatus:!1}:{},...r?{initialCode:r}:{},...o?{onConnected:o}:{}})]})}function va(e,n){return e.map(t=>{if(t.state==="offline")return t;let r=n.filter(o=>o.machine_id===t.id).length;return{...t,active:r,state:r>0?"busy":"online"}})}import{jsx as Tr,jsxs as Ca}from"react/jsx-runtime";function ka({initialCode:e,onConnected:n,className:t,showStatus:r=!0}){let{theme:o}=H();return Ca("div",{className:t?`soba-connect ${t}`:"soba-connect","data-theme":o,children:[r&&Tr(Er,{}),Tr("div",{className:"sc-compute-act",children:Tr(fn,{...e?{initialCode:e}:{},...n?{onConnected:n}:{}})})]})}import{useId as La,useState as Aa}from"react";import{useCallback as Ar,useEffect as _o,useState as Eo}from"react";import{useCallback as Na,useState as xa}from"react";function rt(){let[e,n]=xa(null);return{open:Na(()=>{n(null),Jt().then(n)},[]),launch:e,note:e==="absent"?"Nothing opened here. That machine may be a different computer, or asleep.":null}}import{useCallback as So,useMemo as Mo}from"react";function hn(e){if(!e)return null;if(typeof e=="string")return e;if(typeof Response<"u"&&e instanceof Response)return Po(e.status);let n=e,t=n.error;return typeof t?.code=="string"?t.code:typeof t?.type=="string"?t.type:typeof n.code=="string"?n.code:typeof n.status=="number"?Po(n.status):n.cause&&n.cause!==e?hn(n.cause):null}function Po(e){return e===402?"payment_required":e===409?"no_compute":null}function Lr(...e){let[n,t]=e,{plan:r,compute:o,connect:s}=D(),a=t?.predict??e.length===0,c=Ma(Sa(n),o)??(a?Pa(r,o):null),i=r.plan,l=r.plans,u=Mo(()=>{if(c!=="payment_required")return null;let m=i?.price??0,w=i?.included_units??0;return l.find(P=>P.id!==i?.id&&P.price>m&&(P.included_units===null||P.included_units>w))??null},[c,l,i]),p=So(async()=>{if(!u)return;if(u.selectable){await r.select(u.id);return}let m=await r.checkout(u.id);window.location.assign(m)},[u,r]),y=s.open,f=So(()=>{c&&y(c)},[y,c]);return Mo(()=>{if(!c)return null;let m=i?He({unit:i.unit,reward:i.connected_reward,includedUnits:i.connected_included_units,creditMicros:i.connected_credit*1e6}):null,w=i&&Ue(i.connected_reward)?m:null;return{reason:c,...Ra(c,{connectOffer:w,connected:o.connected,online:o.online,machine:cn(o.machines)?.label??null,unit:i?.unit??"message",interval:i?.interval??"month",upgrade:u!==null,resets:r.current?.period_end??null}),connectOffer:w,upgradeTo:u,connect:f,upgrade:p}},[c,i,o,u,f,p,r.current?.period_end])}function Sa(e){let n=hn(e);return n==="payment_required"||n==="no_compute"?n:null}function Ma(e,n){return e==="no_compute"&&n.connected&&n.online?null:e}function Pa(e,n){let t=e.plan;return!t||n.loading?null:xe(t.route_allow)&&!n.online?"no_compute":e.remaining===0&&t.overage==="stop"?"payment_required":null}function Ra(e,n){if(e==="payment_required"){let t=`No ${n.unit}s left this ${n.interval}`;return n.connectOffer&&!n.connected?{title:t,body:`${n.connectOffer}. Connecting takes a minute and costs nothing.`}:n.connectOffer&&!n.online?{title:t,body:`${n.connectOffer}. Waking ${n.machine??"your machine"} is enough.`}:n.upgrade?{title:t,body:n.resets?`A larger plan carries on now. This one comes back on ${Ro(n.resets)}.`:"A larger plan carries on now, or wait for this one to renew."}:{title:t,body:n.resets?`Your allowance comes back on ${Ro(n.resets)}.`:"Your allowance comes back at the start of the next period."}}return n.connected&&!n.online?{title:`${n.machine??"Your machine"} can't be reached`,body:"This run needs it awake and connected. Open Soba App on that machine, or connect another one."}:{title:"Nothing connected yet",body:"This app runs on AI you already pay for, on a machine of your own. Connect one and this run has somewhere to go."}}function Ro(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}function _a(e){let{plan:n,allowance:t,connected:r,online:o,quiet:s,error:a,predict:c,at:i,waved:l}=e;if(!n)return null;let u=e.allow!==void 0?e.allow:n.route_allow;if(r){if(o)return null;let w=xe(u);return{reason:"stalled",title:`${s??"Your machine"} can\u2019t be reached`,detail:w?"The Soba app there has stopped reporting in, so runs have nowhere to go until it is back.":"The Soba app there has stopped reporting in, so nothing will run on your own AI until it is back.",meter:null,dismissible:!1,atTheWall:!1,ownCompute:w}}let p=hn(a),y=p==="payment_required"||p==="no_compute",f=n.ask_to_connect!==!1&&Mr(n.route_prefer,u);if(!c&&!y&&!f)return null;let m=xe(u)?Ea(n.unit,xe(n.route_allow)):Ue(n.connected_reward)?Ia(t,n,i):f?Oa(n.unit):null;return!m||m.dismissible&&l?null:{...m,dismissible:!!m.dismissible,ownCompute:!1,atTheWall:!m.dismissible&&(!c||m.meter!==null&&m.meter.left===0)}}function $r(e={}){let{at:n=.25,error:t,allow:r}=e,o=e.predict??!(e.errorGiven??t!==void 0),{plan:s,compute:a,connect:c}=D(),i=sr(c.publishableKey),[l,u]=Eo(!1);_o(()=>{u(ar(i))},[i]);let p=Ar(()=>{u(!0),ir(i)},[i]),y=Ar(()=>c.open("manual"),[c]),f=Ar(()=>c.open("no_compute"),[c]),m=rt(),[w,P]=Eo(!1),{refresh:R}=a,{launch:_}=m;_o(()=>{if(_===null||_==="absent")return;P(!1);let F=setInterval(()=>void R(),3e3),T=setTimeout(()=>{clearInterval(F),P(!0)},2e4);return()=>{clearInterval(F),clearTimeout(T)}},[_,R]);let M=Ta(c.app?.name,Fn(c.connectUrl)),B=s.loading||a.loading,I=cn(a.machines),N=B?null:_a({plan:s.plan,allowance:{remaining:s.remaining,included:s.included},connected:a.connected,online:a.online,quiet:I?V(I):null,error:t,predict:o,...r!==void 0?{allow:r}:{},at:n,waved:l});return{reason:N?.reason??null,visible:N!==null,title:N?.title??null,detail:N?.detail??null,meter:N?.meter??null,dismissible:N?.dismissible??!1,dismissed:l,dismiss:p,open:y,atTheWall:N?.atTheWall??!1,steps:M,stalled:N?.reason==="stalled"?{machine:I?V(I):null,ownCompute:N.ownCompute,wake:m.open,launch:m.launch,note:m.note,stuck:w,connectAnother:f}:null,loading:B}}function Ea(e,n){return{reason:"needed",title:n?"This plan runs on your own AI.":`These ${e}s run on your own AI.`,detail:`Connect a machine and your ${e}s run there, free, on access you already have.`,meter:null}}function Oa(e){return{reason:"preferred",title:"This plan prefers your own AI.",detail:`Connect a machine and your ${e}s run there instead, on access you already have.`,meter:null,dismissible:!0}}function Ia(e,n,t){let{remaining:r,included:o}=e;if(r===null||o===null||o===0||r>Math.ceil(o*t))return null;let s=He({unit:n.unit,reward:n.connected_reward,includedUnits:n.connected_included_units,creditMicros:n.connected_credit*1e6});return s?{reason:"running",title:r===0?`No ${n.unit}s left this month.`:`${r} ${n.unit}${r===1?"":"s"} left this month.`,detail:`${s}.`,meter:{left:r,of:o}}:null}function Ta(e,n){return[{lead:"Download Soba App",detail:"",...n?{linksLead:"Get it for"}:{},links:n?qn.map(t=>({label:t.label,href:`${n}/download/${t.slug}`})):[]},{lead:"Connect compute",detail:"Press this, then approve the pairing when the app asks.",opens:!0,links:[]},{lead:"Let your AIs serve",detail:`It finds what is installed on that machine. Allow one, and ${e??"this app"} sends every run there.`,linksLead:"Nothing on it yet?",links:ce.map(t=>({label:t.short,href:t.install}))}]}import{Fragment as Io,jsx as L,jsxs as Ze}from"react/jsx-runtime";function $a(e){let{className:n,fallback:t=null}=e,r=$r({...e.at===void 0?{}:{at:e.at},...e.predict===void 0?{}:{predict:e.predict},...e.allow===void 0?{}:{allow:e.allow},error:e.error,errorGiven:"error"in e}),{connect:o}=D(),{theme:s}=H(),[a,c]=Aa(null),i=La(),l=L(Io,{children:t});if(!r.visible)return l;if(r.stalled)return L(Oo,{className:n,theme:s,stalled:!0,children:L(Da,{title:r.title??"",detail:r.detail??"",stalled:r.stalled})});let u=a??r.atTheWall;return Ze(Oo,{className:n,theme:s,children:[Ze("div",{className:"sc-nudge-top",children:[Ze("div",{className:"sc-nudge-say",children:[L("p",{className:"sc-nudge-title",children:r.title}),L("p",{className:"sc-nudge-detail",children:r.detail}),Ze("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more","aria-expanded":u,"aria-controls":i,onClick:()=>c(!u),children:[u?"Hide the details":"How it works",L(Ua,{})]})]}),r.dismissible?L("button",{type:"button",className:"sc-nudge-dismiss","aria-label":"Dismiss",title:"Dismiss",onClick:r.dismiss,children:L(Ha,{})}):null]}),u?L("ol",{className:"sc-nudge-steps",id:i,children:r.steps.map(p=>Ze("li",{children:[p.opens?L("button",{type:"button",className:"sc-step-lead",onClick:()=>o.open("manual"),children:p.lead}):L("strong",{children:p.lead}),p.detail?L("span",{children:p.detail}):null,p.links.length>0?Ze("span",{className:"sc-step-links",children:[p.linksLead,p.links.map(y=>L("a",{href:y.href,target:"_blank",rel:"noreferrer noopener",children:y.label},y.href))]}):null]},p.lead))}):null,L(fn,{variant:"primary"})]})}function Oo({className:e,theme:n,stalled:t,children:r}){return L("div",{className:e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill","data-theme":n,children:L("div",{className:t?"sc-nudge sc-nudge-stalled":"sc-nudge",children:r})})}function Da({title:e,detail:n,stalled:t}){return Ze(Io,{children:[L("div",{className:"sc-nudge-top",children:Ze("div",{className:"sc-nudge-say",children:[L("p",{className:"sc-nudge-title",children:e}),L("p",{className:"sc-nudge-detail",children:n}),t.note&&L("p",{className:"sc-nudge-note",children:t.note}),t.stuck&&L("p",{className:"sc-nudge-note",children:"The Soba app is open, but this machine still isn\u2019t reporting in. It may no longer be connected to this app."}),(t.launch==="absent"||t.stuck)&&L("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more",onClick:t.connectAnother,children:t.stuck?"Connect it again":"Connect another machine"})]})}),L("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:t.wake,children:"Open Soba App"})]})}function Ha(){return L("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-x",children:L("path",{d:"m4.8 4.8 6.4 6.4M11.2 4.8l-6.4 6.4",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})})}function Ua(){return L("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-chev",children:L("path",{d:"M4.5 6.5 8 10l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})})}var Wa=new Set(["delta","thinking","status","done","error"]);function Rn(e){let n;try{n=JSON.parse(e)}catch{return null}if(!n||typeof n!="object")return null;let t=n,r=t.type==="event"?t.event:t;if(!r||typeof r!="object")return null;let o=r;if(typeof o.type!="string"||!Wa.has(o.type))return null;let s={type:o.type};return typeof o.text=="string"&&(s.text=o.text),typeof o.message=="string"&&(s.message=o.message),typeof o.tool=="string"&&(s.tool=o.tool),typeof o.tier=="string"&&(s.tier=o.tier),o.usage&&typeof o.usage=="object"&&(s.usage=o.usage),typeof o.session=="string"&&(s.session=o.session),typeof o.toolInput=="string"&&(s.toolInput=o.toolInput),o.git&&typeof o.git=="object"&&(s.git=o.git),o.turn&&typeof o.turn=="object"&&typeof o.turn.text=="string"&&(s.turn={text:o.turn.text}),typeof o.reason=="string"&&(s.reason=o.reason),typeof o.retryable=="boolean"&&(s.retryable=o.retryable),(o.state==="interrupted"||o.state==="resumed")&&(s.state=o.state),s}async function*Dr(e){let n=e.body;if(!n)throw new Error("That run response had no body to stream.");let t=(e.headers.get("content-type")??"").includes("ndjson"),r=n.getReader(),o=new TextDecoder,s="",a=[];try{for(;;){let i=await r.read();if(i.done)break;for(s+=o.decode(i.value,{stream:!0});;){let l=s.indexOf(`
|
|
3
|
-
`);if(l===-1)break;let u=
|
|
4
|
-
`);if(a=[],p==="[DONE]")return;let y=p?
|
|
5
|
-
`);if(c&&c!=="[DONE]"){let i=
|
|
2
|
+
import{useRef as ps,useState as so}from"react";var Cn=class extends Error{status;constructor(n,t){super(n),this.name="ConnectError",this.status=t}},ss=5*6e4,Ln=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 Cn&&s.status===401)throw s;this.gatewayBackUntil=Date.now()+ss}if(r??=await this.request("GET",`/v1/machines${t}`),r.unchanged&&n)return n.machines;let o=Array.isArray(r.machines)?r.machines:[];return this.lastMachines=typeof r.version=="string"?{version:r.version,machines:o}:null,o}async runs(){let n=await this.request("GET","/v1/machines/runs");return Array.isArray(n.runs)?n.runs:[]}async stopRun(n){let t=this.machinesUrl?.replace(/\/v1\/machines$/,"");if(!t)throw new Cn("This page can't stop runs yet: it hasn't been told where Soba's gateway is.",501);await this.request("POST",`${t}/v1/runs/${encodeURIComponent(n)}/stop`,{})}lookup(n){return this.request("GET",`/v1/device/lookup?code=${encodeURIComponent(n)}`)}approve(n){return this.request("POST","/v1/device/approve",{user_code:n})}claim(n){return this.request("POST","/v1/device/claim",{pairing_nonce:n})}deny(n){return this.request("POST","/v1/device/deny",{user_code:n})}plans(){return this.request("GET","/v1/plans")}selectPlan(n){return this.request("POST","/v1/plans/select",{plan:n})}checkoutPlan(n,t){return this.request("POST","/v1/plans/checkout",{plan:n,...t?.successUrl?{success_url:t.successUrl}:{},...t?.cancelUrl?{cancel_url:t.cancelUrl}:{}})}leavePlan(){return this.request("DELETE","/v1/plans/select")}hosted(){return this.request("GET","/v1/hosted")}startHosted(){return this.request("POST","/v1/hosted/start")}disconnectHosted(n){return this.request("DELETE",n?`/v1/hosted?provider=${encodeURIComponent(n)}`:"/v1/hosted")}approveRuntime(n,t){return this.request("POST","/v1/runtimes/approve",{machine_id:n,runtime_id:t})}preferRuntime(n,t){return this.request("POST","/v1/runtimes/prefer",{machine_id:n,runtime_id:t})}async request(n,t,r){let o=await this.doFetch(/^https?:\/\//.test(t)?t:`${this.baseUrl}${t}`,{method:n,headers:{authorization:`Bearer ${this.session}`,...r?{"content-type":"application/json"}:{}},...r?{body:JSON.stringify(r)}:{}}),s={};try{s=await o.json()}catch{}if(!o.ok){let a=typeof s.error=="string"?s.error:`Request failed (${o.status})`;throw new Cn(a,o.status)}return s}};function An(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 At(e){let n=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!n?.[1])return null;let t=n[1].length===3?[...n[1]].map(r=>r+r).join(""):n[1];return[0,1,2].map(r=>Number.parseInt(t.slice(r*2,r*2+2),16))}function kn(e,n,t){let r=At(e),o=At(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 an(e,n){if(!At(e))return{};let t=An(e),r=n?.trim();return{"--sc-ground":e,"--sc-shell":e,"--sc-sheet":kn(e,t,.07),"--sc-raised":kn(e,t,.13),"--sc-line":kn(e,t,.18),"--sc-line-2":kn(e,t,.28),"--sc-text":t,"--sc-text-2":kn(t,e,.15),"--sc-muted":kn(t,e,.38),...r?{"--sc-accent":r,"--sc-accent-fg":An(r)}:{"--sc-accent":t,"--sc-accent-fg":e}}}function $n(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 Dn(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 ln(e){return e.find(n=>n.state==="offline")??null}function $t(e){return e.state==="busy"?{tone:"busy",text:`serving ${e.active} of ${e.capacity}`}:e.state==="online"?{tone:"ok",text:"connected"}:{tone:"off",text:"asleep or offline"}}function K(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 ft(e,n){let t=o=>o.state==="busy"?0:o.state==="online"?1:2,r=o=>o.last_seen_at?Date.parse(o.last_seen_at):0;return t(e)-t(n)||r(n)-r(e)}function Ee(e){return[...e].sort(ft)[0]??null}function Ge(e){return e?e.state==="busy"?{tone:"busy",word:"Serving"}:e.state==="online"?{tone:"ok",word:"Connected"}:{tone:"off",word:"Asleep"}:{tone:"off",word:"No compute"}}function Dt(e){return e.state==="online"||e.state==="busy"}function Un(e){if(!e)return"never seen";let n=Date.parse(e);if(Number.isNaN(n))return"never seen";let t=Date.now()-n,r=6e4;return t<2*r?"just now":t<60*r?`${Math.floor(t/r)} min ago`:t<24*60*r?`${Math.floor(t/(60*r))} hr ago`:`${Math.floor(t/(24*60*r))} days ago`}function ye(e){return e.runtimes.filter(n=>n.id!=="shell"&&!n.quarantined&&!n.absent)}function De(e){let n=a=>a?e.runtimes.find(c=>c.id===a)??null:null;if(e.requested_runtime)return{by:"app",runtimeId:e.requested_runtime,runtime:n(e.requested_runtime)};let t=ye(e),r=t.find(a=>a.id===e.preferred_runtime);if(r)return{by:"you",runtimeId:r.id,runtime:r};let o=a=>a.id==="claude-code"?0:a.id==="codex"?1:2,s=[...t].sort((a,c)=>o(a)-o(c))[0]??null;return{by:"default",runtimeId:s?.id??null,runtime:s}}import{useEffect as eo,useRef as as}from"react";import{Fragment as cs,jsx as xe,jsxs as Ut}from"react/jsx-runtime";function Hn({anchor:e,label:n,options:t,current:r,onClose:o,onPick:s}){let a=as(null);return eo(()=>{let i=a.current,l=e.current;if(!i||!l)return;try{typeof i.showPopover=="function"&&i.showPopover()}catch{}let u=l.getBoundingClientRect(),p=i.offsetWidth,y=i.offsetHeight,f=Math.max(8,Math.min(u.right-p,window.innerWidth-p-8)),m=u.bottom+6,w=m+y>window.innerHeight-8&&u.top-6-y>8?u.top-6-y:m;i.style.left=`${Math.round(f)}px`,i.style.top=`${Math.round(w)}px`,i.querySelector('[aria-checked="true"]')?.focus()},[e]),eo(()=>{let i=l=>{let u=l.target;!u||a.current?.contains(u)||e.current?.contains(u)||o()};return document.addEventListener("pointerdown",i,!0),()=>document.removeEventListener("pointerdown",i,!0)},[e,o]),xe("div",{ref:a,role:"menu","aria-label":n,className:"sc-menu",popover:"manual",onKeyDown:i=>{let l=[...a.current?.querySelectorAll("[role=menuitemradio]")??[]],u=l.indexOf(document.activeElement);if(i.key==="Escape")i.stopPropagation(),i.nativeEvent.stopImmediatePropagation(),o(),e.current?.focus();else if(i.key==="ArrowDown"||i.key==="ArrowUp"){i.preventDefault();let p=i.key==="ArrowDown"?1:-1;l[(u+p+l.length)%l.length]?.focus()}else i.key==="Tab"&&o()},children:t.map(i=>xe(is,{option:i,checked:r===i.id,onClose:o,onPick:s},i.id??""))})}function is({option:e,checked:n,onClose:t,onPick:r}){return Ut(cs,{children:[e.heading?xe("div",{className:"sc-menu-head",role:"presentation",children:e.heading}):e.rule?xe("div",{className:"sc-menu-sep"}):null,Ut("button",{type:"button",role:"menuitemradio","aria-checked":n,className:"sc-menu-item",onClick:()=>n?t():r(e.id),children:[e.glyph,Ut("span",{className:"sc-menu-text",children:[xe("span",{className:"sc-menu-label",children:e.label}),e.note&&xe("span",{className:"sc-menu-note",children:e.note})]}),n&&xe(ls,{})]})]})}function ls(){return xe("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:"sc-menu-check",children:xe("path",{d:"M5 12.5l4.5 4.5L19 7.5",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Nn({open:e}){return xe("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e?"sc-chev sc-chev-open":"sc-chev",children:xe("path",{d:"M9 6l6 6-6 6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as we,jsxs as ds}from"react/jsx-runtime";function j({className:e}){return ds("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 no({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 cn({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 ht({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 us({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{d:"M5 7l5 5-5 5M12 18h7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Ht({className:e}){return we("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e,children:we("path",{d:"M5 6h14v10H5zM2.5 19.5h19",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}var ze={claude:no,chatgpt:cn,local:ht},to={shell:us};var ie=[{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"]}],ro=["claude","chatgpt"];function Wt(){return ie.filter(e=>ro.includes(e.id))}function Bt(e){return ie.filter(n=>n.costClass===e)}function qt(e){return ie.find(n=>n.expects.includes(e))??null}import{Fragment as io,jsx as g,jsxs as I}from"react/jsx-runtime";function un({machines:e,hosted:n=[],onApproveRuntime:t,onPreferRuntime:r,onDisconnectHosted:o,onPair:s,onRefresh:a,refreshing:c,busy:i,appName:l,error:u,runs:p,runsOpen:y,onToggleRuns:f,markOf:m,loading:w,machineMenu:M,machineNote:R,children:_,onStopRun:U}){let P=Ee(e),T=e.filter(S=>S.id!==P?.id),E=P&&p?hs(p,P):{};return!P&&n.length===0&&!s?g("p",{className:"sc-note",children:"Nothing connected yet."}):I("div",{className:"sc-tray",children:[P&&I(xn,{title:"This machine",action:(a||M)&&I("span",{className:"sc-cap-acts",children:[a&&g("button",{type:"button",className:"sc-disc",onClick:a,disabled:c,"aria-label":"Refresh",title:"Refresh",children:g(Rs,{spinning:!!c})}),M]}),children:[g(ms,{machine:P,...f?{onToggle:f,open:!!y}:{}}),R]}),P&&f&&y&&g(gs,{machine:P,runs:p??null,...m?{markOf:m}:{},...U?{onStop:U}:{}}),P&&g(xn,{title:"Agents on it",action:g(Ns,{machine:P,appName:l,busy:i,...m?{markOf:m}:{},...r?{onPick:S=>r(P.id,S)}:{}}),children:w&&P.runtimes.length===0?g("p",{className:"sc-row-note",children:"Looking\u2026"}):P.runtimes.length>0?P.runtimes.map(S=>g(ks,{runtime:S,serving:E[S.id]??S.serving??0,...m?{mark:m(S)}:{},...t?{onApprove:()=>t(P.id,S.id)}:{}},S.id)):g("p",{className:"sc-row-note",children:"No agent advertised. Install Claude Code, Codex or Ollama on that machine."})}),n.length>0&&g(xn,{title:n.length>1?"Connected plans":"Connected plan",children:n.map(S=>g(Ss,{credential:S,appName:l,busy:i,...o?{onDisconnect:()=>o(S.provider)}:{}},S.provider))}),(T.length>0||s)&&I(xn,{title:T.length>0?"Your other machines":P?"Add a machine":"Your machines",children:[T.map(S=>g(vs,{machine:S},S.id)),s&&I("button",{type:"button",className:"sc-pair",onClick:s,children:[g("span",{className:"sc-otile","aria-hidden":"true",children:g(Ms,{})}),g("span",{className:"sc-oname",children:e.length>0?"Pair another machine":"Connect a machine"})]})]}),_,u&&g("p",{className:"sc-error sc-tray-error",children:u})]})}function xn({title:e,action:n,children:t}){return I("section",{className:"sc-group",children:[I("div",{className:"sc-group-cap",children:[g("p",{className:"sc-group-title",children:e}),n]}),g("div",{className:"sc-group-card",children:t})]})}function ms({machine:e,onToggle:n,open:t}){let r=Dt(e),o=[r?null:e.pairing_lost?"No longer connected here":"Asleep or offline",Dn(e),e.always_on?"always on":null,r&&e.capacity>0?`${e.active} of ${e.capacity} in flight`:Un(e.last_seen_at)].filter(Boolean),s=I(io,{children:[I("span",{className:"sc-mtile","aria-hidden":"true",children:[g(ao,{}),g("span",{className:`sc-mbadge sc-mbadge-${Ge(e).tone}`})]}),I("span",{className:"sc-mid",children:[g("span",{className:"sc-mname",children:K(e)}),g("span",{className:"sc-mmeta",children:o.map((a,c)=>I("span",{children:[c>0&&g("span",{className:"sc-mmeta-sep",children:"\xB7"}),a]},a))})]})]});return!n||!r?g("div",{className:"sc-mrow",children:s}):I("button",{type:"button",className:"sc-mrow sc-mrow-btn",onClick:n,"aria-expanded":!!t,title:t?"Hide what it is running":"See what it is running",children:[s,g(Nn,{open:!!t})]})}function fs(e,n){return e.filter(t=>t.machine_id===n.id||t.machine_id===null)}function hs(e,n){let t={};for(let r of e)r.machine_id!==n.id||r.status!=="running"||!r.runtime_id||(t[r.runtime_id]=(t[r.runtime_id]??0)+1);return t}function gs({machine:e,runs:n,markOf:t,onStop:r}){let o=n?fs(n,e):[],s=l=>{if(!l||!t)return null;let u=e.runtimes.find(p=>p.id===l);return u?t(u):null},[a,c]=so(new Set),i=async l=>{c(u=>new Set(u).add(l));try{await r?.(l)}catch{c(u=>{let p=new Set(u);return p.delete(l),p})}};return g(xn,{title:"Running now",children:n===null?g("p",{className:"sc-row-note",children:"Looking\u2026"}):o.length===0?g("p",{className:"sc-row-note",children:"Nothing running."}):o.map(l=>{let u=s(l.runtime_id);return g(bs,{run:l,...u?{mark:u}:{},stopping:a.has(l.id),...r?{onStop:()=>void i(l.id)}:{}},l.id)})})}function bs({run:e,mark:n,stopping:t,onStop:r}){let o=e.runtime_id?gt(e.runtime_id):null;return I("div",{className:"sc-rrow",children:[g("span",{className:"sc-runtime-tile","aria-hidden":"true",children:n??(o&&g(o,{className:"sc-runtime-mark"}))}),I("span",{className:"sc-mid",children:[I("span",{className:"sc-rtop",children:[g("span",{className:"sc-aname",children:oo(e)}),g("span",{className:"sc-averdict",children:ws(e.started_at)})]}),g("span",{className:"sc-rstep",children:t?"Stopping\u2026":ys(e)})]}),r&&g("button",{type:"button",className:"sc-disc sc-rstop",onClick:r,disabled:t,"aria-label":`Stop ${oo(e)}`,title:"Stop",children:g(_s,{})})]})}function gt(e){let n=qt(e);return(n?ze[n.id]:null)??to[e]??null}function oo(e){if(e.label)return e.label;if(e.task){let n=e.task.replace(/[_-]+/g," ").trim();return n.charAt(0).toUpperCase()+n.slice(1)}return"A run"}function ys(e){if(e.status==="queued")return"Waiting for a free slot";if(e.step)return e.step;switch(e.phase?.kind){case"thinking":return"Thinking";case"writing":return"Writing";case"tool":return e.phase.tool?`Using ${e.phase.tool}`:"Using a tool";case"approval":return e.phase.tool?`Waiting for you to allow ${e.phase.tool}`:"Waiting for your approval";default:return e.first_output_at?"Working":"Starting"}}function ws(e){let n=Math.max(0,Math.round((Date.now()-new Date(e).getTime())/1e3));if(n<60)return`${n}s`;let t=Math.floor(n/60);return t<60?`${t}m ${String(n%60).padStart(2,"0")}s`:`${Math.floor(t/60)}h ${String(t%60).padStart(2,"0")}m`}function vs({machine:e}){let n=Ge(e);return I("div",{className:"sc-orow",children:[g("span",{className:"sc-otile","aria-hidden":"true",children:g(ao,{})}),g("span",{className:"sc-oname",children:K(e)}),g("span",{className:"sc-oword",children:n.word}),g("span",{className:`sc-dot sc-dot-${n.tone}`,"aria-hidden":"true"})]})}function ks({runtime:e,serving:n=0,mark:t,onApprove:r}){let o=$n(e),s=I(io,{children:[g(Cs,{runtime:e,mark:t}),I("span",{className:e.absent?"sc-aname sc-aname-absent":"sc-aname",children:[e.display_name,e.version&&I("span",{className:"sc-aversion",children:[" ",e.version]})]}),n>0?I("span",{className:"sc-averdict",children:[g(Ps,{}),g("span",{className:"sc-aserving",children:n>1?`${n} running`:"running"})]}):e.absent?g("span",{className:"sc-averdict sc-tone-absent",children:"not offered"}):e.quarantined?r?g("button",{type:"button",className:"sc-row-act",onClick:r,children:"Let it serve"}):g("span",{className:"sc-averdict sc-tone-warn",children:"new, not serving yet"}):o.tone==="ok"?I("span",{className:"sc-averdict",children:[g("span",{className:"sc-dot sc-dot-ok","aria-hidden":"true"}),g("span",{className:"sc-sr",children:o.text})]}):g("span",{className:`sc-averdict sc-tone-${o.tone}`,children:o.text})]});return g("div",{className:"sc-arow",children:s})}function Cs({runtime:e,mark:n}){if(n)return g("span",{className:"sc-runtime-tile","aria-hidden":"true",children:n});let t=gt(e.id);return g("span",{className:"sc-runtime-tile","aria-hidden":"true",children:t&&g(t,{className:"sc-runtime-mark"})})}function Ns({machine:e,appName:n,busy:t,markOf:r,onPick:o}){let s=De(e),a=ye(e),[c,i]=so(!1),l=ps(null);if(s.by!=="app"&&a.length===0)return null;let u=f=>{if(!f)return null;if(r)return r(f);let m=gt(f.id);return g("span",{className:"sc-runtime-tile","aria-hidden":"true",children:m&&g(m,{className:"sc-runtime-mark"})})},p=f=>{if(!f)return null;if(r)return g("span",{className:"sc-runs-mark",children:r(f)});let m=gt(f.id);return m?g(m,{className:"sc-runs-glyph"}):null},y;return s.by==="app"?y=I("span",{className:"sc-runs-fixed",title:`Set by ${n??"the app"}`,children:[p(s.runtime),s.runtime?.display_name??s.runtimeId]}):!o||a.length<2?y=I("span",{className:"sc-runs-fixed",children:[p(s.runtime),s.runtime?.display_name]}):y=I("button",{ref:l,type:"button",className:"sc-runs-btn","aria-haspopup":"menu","aria-expanded":c,"aria-label":`Runs go to ${s.runtime?.display_name??"the default"}. Change`,disabled:t,onClick:()=>i(f=>!f),children:[p(s.runtime),g("span",{className:"sc-runs-label",children:s.runtime?.display_name}),g(Nn,{open:!0})]}),I("span",{className:"sc-runs-to",children:[g("span",{className:"sc-runs-cap",children:s.by==="app"?`${n??"App"} uses`:"Runs on"}),y,c&&o&&g(xs,{anchor:l,machine:e,tile:u,onClose:()=>i(!1),onPick:f=>{i(!1),o(f)}})]})}function xs({anchor:e,machine:n,tile:t,onClose:r,onPick:o}){let s=De(n),a=De({...n,preferred_runtime:null}).runtime,c=s.by==="you"?s.runtimeId:null,i=[{id:null,label:"Automatic",...a?{note:`Uses ${a.display_name}`}:{},glyph:t(a)},...ye(n).map((l,u)=>({id:l.id,label:l.display_name,glyph:t(l),...u===0?{rule:!0}:{}}))];return g(Hn,{anchor:e,label:"Which agent runs go to",options:i,current:c,onClose:r,onPick:o})}function Ss({credential:e,appName:n,busy:t,onDisconnect:r}){return I("div",{className:"sc-hrow",children:[I("div",{className:"sc-orow",children:[g("span",{className:"sc-otile","aria-hidden":"true",children:g(cn,{className:"sc-omark"})}),I("span",{className:"sc-mid",children:[g("span",{className:"sc-oname",children:e.provider==="openai-chatgpt"?"ChatGPT plan":e.provider}),g("span",{className:"sc-mmeta",children:e.account_label??"signed in"})]}),r&&g("button",{type:"button",className:"sc-row-act",onClick:r,disabled:t,children:"Disconnect"})]}),r&&I("p",{className:"sc-row-note",children:[n??"This app"," stops using it. To withdraw the grant entirely, remove it in your OpenAI settings."]})]})}function ao(){return I("svg",{viewBox:"0 0 32 24","aria-hidden":"true",focusable:"false",className:"sc-mglyph",children:[g("rect",{x:"4",y:"1.5",width:"24",height:"15",rx:"2.5",fill:"var(--sc-sheet, #ffffff)",stroke:"currentColor",strokeWidth:"2"}),g("rect",{x:"1",y:"19.5",width:"30",height:"2.5",rx:"1.25",fill:"currentColor"})]})}function Ms(){return g("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:"sc-oglyph",children:g("path",{d:"M12 5v14M5 12h14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}function Ps(){return I("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:"sc-sglyph sc-spin",children:[g("circle",{cx:"12",cy:"12",r:"9",fill:"none",stroke:"currentColor",strokeWidth:"3",opacity:"0.25"}),g("path",{d:"M12 3a9 9 0 0 1 9 9",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round"})]})}function Rs({spinning:e}){return g("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",className:e?"sc-dglyph sc-spin":"sc-dglyph",children:g("path",{d:"M21 12a9 9 0 1 1-2.64-6.36M21 3v6h-6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function _s(){return g("svg",{className:"sc-dglyph",viewBox:"0 0 16 16","aria-hidden":"true",children:g("rect",{x:"4",y:"4",width:"8",height:"8",rx:"1.5",fill:"currentColor"})})}import{jsx as Es}from"react/jsx-runtime";function Wn({machines:e,onApproveRuntime:n}){return Es(un,{machines:e,...n?{onApproveRuntime:n}:{}})}var Ft={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 Gt="105 162 420 420",zt="M407.1 308.9 A158 158 0 1 0 407.1 491.1 A116 116 0 0 1 407.1 308.9 Z",dn="M448.5 320 A110 110 0 0 1 448.5 480";import{Fragment as qn,jsx as x,jsxs as Ve}from"react/jsx-runtime";function Vt({kind:e,size:n=44,className:t}){let r=Ft[e];return Ve("svg",{className:`bx${t?` ${t}`:""}`,"data-expression":e,viewBox:Gt,overflow:"visible",width:n,height:n,"aria-hidden":"true",children:[x("path",{d:zt,fill:"currentColor"}),x("path",{className:"bx-arc",d:dn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"}),r.slot==="stream"&&x(Os,{}),r.slot==="zzz"&&x(Is,{}),r.slot==="dots"&&x(Ts,{}),r.slot==="bang"&&x(Ls,{}),r.slot==="orbit"&&x(As,{}),r.slot==="cross"&&x($s,{}),r.slot==="snap"&&x(Ds,{}),r.slot==="bars"&&x(Us,{}),r.slot==="ring"&&x(Hs,{}),r.slot==="sparks"&&x(Ws,{})]})}function Os(){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 Is(){return Ve(qn,{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 Ts(){return Ve(qn,{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 Ls(){return Ve("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 As(){return Ve("g",{className:"bx-ob",children:[x("path",{d:dn,fill:"none",stroke:"var(--tile-bg, transparent)",strokeWidth:41,strokeLinecap:"round"}),x("path",{d:dn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})]})}function $s(){return Ve(qn,{children:[x("path",{className:"bx-xa",d:dn,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 Ds(){return x("path",{className:"bx-snap",d:dn,fill:"none",stroke:"currentColor",strokeWidth:17,strokeLinecap:"round"})}function Us(){return Ve("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 Hs(){return x(qn,{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 Ws(){return Ve(qn,{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 re,useEffect as le,useId as js,useMemo as Ke,useRef as Sn,useState as q}from"react";var Fn=[{slug:"mac-arm",label:"macOS, Apple silicon"},{slug:"mac-intel",label:"macOS, Intel"},{slug:"windows",label:"Windows"},{slug:"linux",label:"Linux"}];function Gn(e){if(!e)return"";try{return new URL(e).origin}catch{return""}}function uo(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 Bs=3e3,qs=2*6e4,bt=Date.now(),yt=new Set,co=!1;function Fs(){if(co||typeof window>"u")return;co=!0;let e=()=>{let t=bt;if(bt=Date.now(),bt-t>qs)for(let r of yt)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 yt)t()};window.addEventListener("focus",n),document.addEventListener("visibilitychange",n)}function Oe(e,n,t={}){Fs();let r,o=t.immediate===!1?Date.now():0,s=!1,a=!1,c=()=>{a||(r=setTimeout(i,t.idle===!1?n:uo(n,Date.now()-bt)))},i=async()=>{if(clearTimeout(r),!(a||s)){if(typeof document>"u"||!document.hidden){s=!0,o=Date.now();try{await e()}catch{}finally{s=!1}}c()}},l=()=>{Date.now()-o>Math.min(n,Bs)&&i()};return yt.add(l),t.immediate===!1?c():i(),()=>{a=!0,clearTimeout(r),yt.delete(l)}}var Kt="soba";function po(){return`${Kt}://show`}function zn(e,n,t){let r=`${Kt}://connect?url=${encodeURIComponent(e)}`;return n&&(r+=`&nonce=${encodeURIComponent(n)}`),t&&(r+=`&want=${encodeURIComponent(t)}`),r}function Vn(){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 Gs=1600;function jt(e={}){return Jt(e)}async function Yt(e,n={}){if(typeof window>"u"||typeof document>"u")return"unknown";let t=Jt(n);try{window.location.href=zn(e,n.nonce,n.want)}catch{return"absent"}return t}async function Zt(e={}){if(typeof window>"u"||typeof document>"u")return"unknown";let n=Jt(e);try{window.location.href=po()}catch{return"absent"}return n}async function Jt(e){if(typeof window>"u"||typeof document>"u")return"unknown";let n=e.graceMs??Gs,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 mo="soba.connect.choice",zs=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 Xt(e,n){return e?n?`${mo}.${e}.${Qt(n)}`:`${mo}.${e}`:null}function er(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)>zs)return null;let r=ie.find(o=>o.id===t.choice);return r?r.id:null}catch{return null}}function nr(e,n){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({choice:n,at:new Date().toISOString()}))}catch{}}var fo="soba.connect.model",Vs=180*24*60*60*1e3;function tr(e,n){return e?n?`${fo}.${e}.${Qt(n)}`:`${fo}.${e}`:null}function wt(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)>Vs)return null;let r=t.choice;return typeof r!="string"||!r||r.length>120?null:/^[\w.:@+-]+(\/[\w.:@+-]+)?$/.test(r)?r:null}catch{return null}}function rr(e,n){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({choice:n,at:new Date().toISOString()}))}catch{}}var ho="soba.connect.dismissed",Ks=30*24*60*60*1e3;function or(e,n){return e?n?`${ho}.${e}.${Qt(n)}`:`${ho}.${e}`:null}function sr(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)<Ks}catch{return!1}}function ar(e){if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify({at:new Date().toISOString()}))}catch{}}import{Fragment as Ct,jsx as d,jsxs as N}from"react/jsx-runtime";var ir=2e3,Ys=1e4,Zs=9e4,Js=6e4;function lr(e,n,t,r=[],o){return e?"code":n&&(t.length>0||r.length>0)?"manage":o?"launch":"choose"}function Qs(e){let n=Math.max(0,Math.round(e/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function dr({client:e,initialCode:n,initialChoice:t,onConnected:r,showStatus:o=!0,initialContext:s=null,initialMachines:a,onClose:c,headingId:i,theme:l,reason:u,active:p=!0}){let y=!!s&&a!==void 0,[f,m]=q(y?lr(n,o,a??[],[],t):"loading"),[w,M]=q(s),[R,_]=q(a??[]),[U,P]=q(n??""),[T,E]=q(null),[S,W]=q(null),[ve,X]=q(!1),[ke,V]=q(0),[oe,We]=q(()=>Date.now()),[Y,Pe]=q(null),[Qe,ce]=q(!1),[ue,ee]=q(!1),[gn,Xe]=q("browser"),[Le,en]=q(null),[de,ne]=q([]),[Be,pe]=q(0),[Ae,qe]=q(null),se=Sn(null),[O,bn]=q(t??null),[v,F]=q(null),me=Ke(()=>{let h=w?.accent?.trim(),C=w?.background?.trim();if(!(!h&&!C))return C?{...an(C,h),background:C,borderRadius:"inherit"}:{"--sc-accent":h,"--sc-accent-fg":An(h)}},[w?.accent,w?.background]),fe=js(),te=i??fe,Fe=Sn(null);le(()=>{if(!e||y)return;let h=!0;return Promise.all([e.context(),e.machines()]).then(([C,$])=>{h&&(M(C),_($),m(lr(n,o,$)))}).catch(C=>{h&&(W(C.message),m("choose"))}),()=>{h=!1}},[e,n,o,y]),le(()=>{f!=="loading"||!y||m(lr(n,o,a??[]))},[f,y,n,o,a]),le(()=>{a&&_(a)},[a]),le(()=>{s&&M(s)},[s]);let yn=Sn(!1),wn=Sn(f);wn.current=f;let nn=Sn(de);nn.current=de;let tn=!!w?.hosted_available;le(()=>{!o&&wn.current==="manage"&&m("choose")},[o]),le(()=>{if(!e||!p||f!=="manage")return;let h=!0,C=Oe(async()=>{try{let $=await e.machines();if(!h)return;_($);let B=!tn||yn.current;$.length===0&&nn.current.length===0&&B&&wn.current==="manage"&&m("choose")}catch{}},Ys,{immediate:!1});return()=>{h=!1,C()}},[f,e,tn,p]);let rn=Xt(w?.publishable_key??null);le(()=>{F(er(rn))},[rn]),le(()=>{if(!e||!tn)return;let h=!0;return e.hosted().then(C=>{h&&(ne(C.credentials),!yn.current&&(yn.current=!0,C.credentials.length>0&&o&&wn.current==="choose"&&m("manage")))}).catch(()=>{}),()=>{h=!1}},[e,tn,o]),le(()=>{if(!e||!p||f!=="hosted")return;let h=!0,C=async()=>{try{let _e=await e.hosted();if(!h)return!1;if(ne(_e.credentials),_e.credentials.length>0)return m("hosted_connected"),qe(null),!0}catch{}return!1},$=async()=>{se.current?.closed&&(se.current=null,!await C()&&h&&m("choose"))},B=Oe(C,ir,{immediate:!1}),sn=setInterval($,400),Ne=_e=>{let Tn=_e.data;Tn?.source==="soba"&&Tn.type==="hosted_result"&&C()};return window.addEventListener("message",Ne),()=>{h=!1,B(),clearInterval(sn),window.removeEventListener("message",Ne),se.current=null}},[e,f,p]);let Ot=re(()=>{if(!e)return;let h=window.open("","soba-connect-plan","width=520,height=760,noopener=no");se.current=h,m("hosted"),pe(Date.now()),qe(null),W(null),e.startHosted().then(({url:C})=>{if(h&&!h.closed){h.location.href=C;return}qe(C)}).catch(C=>{h?.close(),se.current=null,W(C.message),m("choose")})},[e]),lt=re(async h=>{if(e){X(!0);try{await e.disconnectHosted(h),ne((await e.hosted()).credentials)}catch(C){W(C.message)}finally{X(!1)}}},[e]);le(()=>{if(!e||!p||f!=="waiting")return;let h=!0,C=Oe(async()=>{try{let $=await e.machines();if(!h)return;_($);let B=Fe.current;if(!B)return;let sn=$.filter(_e=>!B.has(_e.id)),Ne=sn.find(_e=>_e.state!=="offline")??sn[0];if(Ne){en(Ne.id),O&&nr(rn,O);let _e=ie.find(Lt=>Lt.id===O)?.expects??[],Tn=ye(Ne).find(Lt=>_e.includes(Lt.id));Tn&&e.preferRuntime(Ne.id,Tn.id).catch(()=>{}),m("connected"),r?.($)}}catch{}},ir,{immediate:!1});return()=>{h=!1,C()}},[f,e,r,O,rn,p]);let ct=re(async()=>{if(e){W(null),X(!0);try{let h=await e.lookup(U);E(h),m("confirm")}catch(h){W(h.message)}finally{X(!1)}}},[e,U]),vn=re(async()=>{if(e){W(null),X(!0);try{try{Fe.current=new Set((await e.machines()).map(h=>h.id))}catch{Fe.current=new Set(R.map(h=>h.id))}await e.approve(U),m("waiting"),V(Date.now())}catch(h){W(h.message)}finally{X(!1)}}},[e,U,R]),ut=re(async()=>{if(e){X(!0);try{await e.deny(U),Xe("browser"),m("denied")}catch(h){W(h.message)}finally{X(!1)}}},[e,U]),G=Ke(()=>w?.connect_url??null,[w]),[Re,he]=q(()=>Vn()),on=Ke(()=>G?zn(G,Re??void 0,O??void 0):null,[G,Re,O]),dt=Ke(()=>Gn(G),[G]),It=re(h=>{if(R.length===0)return null;let C=ie.find(B=>B.id===h);if(!C)return null;let $=R.flatMap(B=>B.runtimes??[]).filter(B=>C.expects.includes(B.id));return $.length===0?{tone:"dim",text:"not installed"}:$.some(B=>B.authenticated===!0)?{tone:"ok",text:"ready"}:$.every(B=>B.authenticated===!1)?{tone:"warn",text:"needs signing in"}:{tone:"dim",text:"installed"}},[R]),k=re((h=null)=>{bn(h),W(null),Pe(null),ce(!1),ee(!1),z.current=!1,he(Vn()),m("launch")},[]),z=Sn(!!t);le(()=>{f!=="launch"||!G||z.current||(z.current=!0,ce(!0),Yt(G,{...Re?{nonce:Re}:{},...O?{want:O}:{}}).then(Pe))},[f,G,Re,O]);let ae=re(()=>{ce(!0),jt().then(Pe)},[]),pt=re(h=>{if(ue){let C=Vn();ee(!1),he(C),G&&(h.preventDefault(),window.location.href=zn(G,C??void 0,O??void 0))}ae()},[ue,ae,G,O]),ge=Ke(()=>{let h=w?.runtimes;return h?ie.filter(C=>h.includes(C.id)):Wt()},[w?.runtimes]),Ce=Ke(()=>{let h=ie.find(C=>C.id===O);return h?{choice:h,Mark:ze[h.id]??null}:null},[O]),$e=Ke(()=>R.find(h=>h.id===Le),[R,Le]);le(()=>{let h=Re;if(!e||!p||f!=="launch"||!h)return;let C=!1,$=Date.now()+15e4,B=()=>{};return B=Oe(async()=>{if(Date.now()>$){B(),ee(!0);return}try{let sn=await e.claim(h);if(C)return;if(sn.declined){B(),Pe(null),Xe("machine"),m("denied");return}if(!sn.claimed)return;B();try{Fe.current=new Set((await e.machines()).map(Ne=>Ne.id))}catch{Fe.current=new Set(R.map(Ne=>Ne.id))}m("waiting"),V(Date.now())}catch{}},ir,{immediate:!1,idle:!1}),()=>{C=!0,B()}},[e,f,R,Re,p]);let be=Ke(()=>{if(!T)return null;if(T.approved||T.denied)return"answered";let h=T.expires_at?Date.parse(T.expires_at):Number.NaN;return Number.isFinite(h)&&h<=oe?"expired":"live"},[T,oe]);le(()=>{if(!(f==="confirm"&&be==="live"||f==="waiting"||f==="hosted"))return;let C=setInterval(()=>We(Date.now()),1e3);return()=>clearInterval(C)},[f,be]);let mt=re(async(h,C)=>{if(e)try{await e.approveRuntime(h,C),_(await e.machines())}catch($){W($.message)}},[e]),Tt=re(async(h,C)=>{if(e)try{await e.preferRuntime(h,C),_(await e.machines())}catch($){W($.message)}},[e]);return f==="loading"?d("div",{className:"soba-connect",...l?{"data-theme":l}:{},style:me,children:d("div",{className:"sc-card",children:d("p",{className:"sc-note",children:"Loading\u2026"})})}):N("div",{className:"soba-connect",...l?{"data-theme":l}:{},style:me,children:[c&&d("button",{type:"button",className:"sc-modal-close",onClick:c,"aria-label":"Close",children:"\xD7"}),f==="manage"&&N("div",{className:"sc-card",children:[d("h2",{className:"sc-title",id:te,children:"Your compute"}),N("p",{className:"sc-sub",children:[d(vt,{context:w})," ",R.length>0&&de.length>0?"runs on your connected plan, and on these machines while they are awake.":de.length>0?"runs on the plan you connected. Nothing here is charged to you.":"runs on these machines, while they are awake."]}),d(un,{machines:R,hosted:de,onApproveRuntime:mt,onPreferRuntime:(h,C)=>void Tt(h,C),onDisconnectHosted:h=>void lt(h),onPair:()=>m("choose"),busy:ve,...w?.app.name?{appName:w.app.name}:{}}),S&&d("p",{className:"sc-error",children:S})]}),f==="choose"&&N("div",{className:"sc-card",children:[d(ea,{context:w}),d("h2",{className:"sc-h",id:te,children:u==="payment_required"?"Carry on with your own AI":u==="no_compute"?"This run needs a machine":"Connect your AI"}),d("p",{className:"sc-p",children:"Use compute you already have."}),G&&ge.length>0&&N(Ct,{children:[d("div",{className:"sc-opts",children:ge.map(h=>{let C=ze[h.id];return N("button",{type:"button",className:"sc-opt",onClick:()=>k(h.id),children:[d("span",{className:"sc-opt-tile","aria-hidden":"true",children:C&&d(C,{className:"sc-opt-mark"})}),d("span",{className:"sc-opt-text",children:d("span",{className:"sc-opt-label",children:h.label})}),(()=>{let $=It(h.id);return $?d("span",{className:`sc-opt-has sc-opt-has-${$.tone}`,children:$.text}):v===h.id?d("span",{className:"sc-opt-last",children:"last used"}):d(cr,{className:"sc-opt-go"})})()]},h.id)})}),N("p",{className:"sc-opt-note",children:["Your accounts stay there. ",go(w)," never sees them."]})]}),(!G||ge.length===0)&&d("p",{className:"sc-error",style:{marginTop:16},children:"This app has no publishable key yet, so there is nothing to pair against."}),S&&d("p",{className:"sc-error",children:S}),G&&w?.show_code===!0&&d("div",{className:"sc-opt-alt",children:d("button",{type:"button",className:"sc-alt-link",onClick:()=>m("code"),children:"I have a code"})})]}),f==="launch"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[d(Mn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:"Soba App"})]}),d(kt,{mark:Ce?.Mark??j,still:ue||!Qe&&Y===null}),d("h2",{className:"sc-h",id:te,children:ue?"No answer from this machine":Y==="absent"?"Nothing opened":Y===null?"Opening Soba App\u2026":"Approve it on this machine"}),ue?d("p",{className:"sc-p",children:"The Soba app did not answer. It may not be open, or nobody was there. Try again when you are ready."}):Y==="absent"?d("p",{className:"sc-p",children:"Nothing opened on this machine. Open it yourself below, or install it if it is not here yet."}):d("p",{className:"sc-p",children:Y===null?"Approve it there and this page does the rest.":"This page finishes on its own."}),Ce&&N("p",{className:"sc-prereq",children:[Ce.Mark&&d(Ce.Mark,{className:"sc-rt-mark"}),"Needs ",Ce.choice.prerequisite]}),N("div",{className:"sc-stack",style:{marginTop:18},children:[d("a",{className:Y==="absent"||ue?"sc-btn sc-btn-primary":"sc-btn",href:on??"#",onClick:pt,children:ue?"Try again":Y==="absent"?"Open Soba App":"Open it again"}),d("p",{className:"sc-note",children:Y===null?"Your browser will ask permission first.":"Your browser asks permission the first time."}),Ce&&Y==="absent"&&d("p",{className:"sc-note",children:d(na,{text:Ce.choice.hint})}),N("div",{className:"sc-foot-strip",children:[d("span",{children:"Not installed on this machine?"}),N("button",{type:"button",className:"sc-foot-go",onClick:()=>m("get"),children:["Get it",d(cr,{})]})]})]})]}),f==="get"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[d(Mn,{onClick:()=>m("launch")}),d("p",{className:"sc-head-title",children:"Get Soba App"})]}),d("div",{className:"sc-opts",children:Fn.map(h=>N("a",{className:"sc-opt",href:`${dt}/download/${h.slug}`,target:"_blank",rel:"noreferrer noopener",children:[d("span",{className:"sc-opt-tile","aria-hidden":"true",children:d(Ht,{className:"sc-opt-mark"})}),d("span",{className:"sc-opt-text",children:d("span",{className:"sc-opt-label",children:h.label})}),d(cr,{className:"sc-opt-go"})]},h.slug))}),d("p",{className:"sc-opt-note",children:"Install it, then come back here and press the row you started with."})]}),f==="code"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[d(Mn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:"Soba App"})]}),d("h2",{className:"sc-h",id:te,children:"Enter the code from that machine"}),d("p",{className:"sc-p",children:"Eight characters, shown by the Soba app once you paste the link."}),N("form",{className:"sc-stack",style:{marginTop:16},onSubmit:h=>{h.preventDefault(),ct()},children:[d("input",{className:"sc-input",value:U,onChange:h=>P(h.target.value),placeholder:"ACDE-F234",autoComplete:"off",autoFocus:!0,"aria-label":"Pairing code"}),S&&d("p",{className:"sc-error",children:S}),d("button",{type:"submit",className:"sc-btn sc-btn-primary",disabled:ve||U.length<8,children:ve?"Checking\u2026":"Continue"})]})]}),f==="confirm"&&T&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[d(Mn,{onClick:()=>m("code")}),d("p",{className:"sc-head-title",children:"Soba App"})]}),d("h2",{className:"sc-title",children:"Attach this machine to your account?"}),N("p",{className:"sc-sub",children:[d(vt,{context:w})," 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:[d(Kn,{k:"Code",v:T.user_code}),d(Kn,{k:"Machine",v:T.hostname??"not stated"}),d(Kn,{k:"System",v:[T.platform,T.arch].filter(Boolean).join(" / ")||"not stated"}),d(Kn,{k:"Asked by",v:T.client??"not stated"}),T.labels.length>0&&d(Kn,{k:"Labels",v:T.labels.join(", ")})]}),d("p",{className:"sc-note",style:{marginTop:12},children:"Every line above is what that machine said about itself. If none of it looks like a computer of yours, say no."}),be==="expired"&&d("p",{className:"sc-error",children:"That code has expired. Ask the machine for a new one. It prints a fresh code each time it starts."}),be==="answered"&&d("p",{className:"sc-error",children:"That code has already been answered. If it was not you, deny the next one."}),S&&d("p",{className:"sc-error",children:S}),N("div",{className:"sc-row",style:{marginTop:16},children:[d("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:()=>void vn(),disabled:ve||be!=="live",children:"Approve"}),d("button",{type:"button",className:"sc-btn",onClick:()=>void ut(),disabled:ve||be==="answered",children:"No, deny it"})]}),be==="live"&&T.expires_at&&N("p",{className:"sc-note",style:{marginTop:10},children:["This code expires in ",Qs(Date.parse(T.expires_at)-oe),"."]})]}),f==="waiting"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[d(Mn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:Ce?.choice.short??"Soba App"})]}),d(kt,{mark:Ce?.Mark??j}),d("h2",{className:"sc-h",id:te,children:"Approved. Waiting for it to connect"}),d("p",{className:"sc-p",children:"Nothing more to do here. This page changes when it arrives."}),ke>0&&oe-ke>Zs&&d("p",{className:"sc-note sc-tone-warn",style:{marginTop:14,textAlign:"center"},children:"Still nothing. Look at the Soba app on that machine: it says what it is doing. This keeps watching either way."})]}),f==="connected"&&N("div",{className:"sc-card",children:[d(ur,{tone:"ok"}),d("h2",{className:"sc-h",id:te,children:$e?.label?`${$e.label} is connected`:"Connected"}),N("p",{className:"sc-p",children:[d(vt,{context:w})," will use ",$e?.label?"it":"this machine"," from now on, while it is awake."]}),o&&N(Ct,{children:[d("div",{style:{marginTop:16},children:d(Wn,{machines:R,onApproveRuntime:mt})}),d("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:14},onClick:()=>m("manage"),children:"Done"})]})]}),f==="hosted"&&N("div",{className:"sc-card",children:[N("div",{className:"sc-head",children:[d(Mn,{onClick:()=>m("choose")}),d("p",{className:"sc-head-title",children:"ChatGPT"})]}),Ae?d(kt,{mark:cn,still:!0}):d(kt,{mark:cn}),d("h2",{className:"sc-h",id:te,children:Ae?"Your browser blocked the window":"Finish signing in to ChatGPT"}),d("p",{className:"sc-p",children:Ae?"Nothing opened. Open the sign-in yourself below. A link you click is allowed where a window we open is not.":"Approve it in the window that opened."}),N("div",{className:"sc-stack",style:{marginTop:18},children:[Ae&&d("a",{className:"sc-btn sc-btn-primary",href:Ae,target:"soba-connect-plan",rel:"noreferrer",children:"Open the ChatGPT sign-in"}),S&&d("p",{className:"sc-error",children:S}),Be>0&&oe-Be>Js&&d("p",{className:"sc-note sc-tone-warn",children:"Still nothing. The window may have been closed before it finished, or the sign-in may have been declined. This keeps watching either way."})]})]}),f==="hosted_connected"&&N("div",{className:"sc-card",children:[d(ur,{tone:"ok"}),d("h2",{className:"sc-h",id:te,children:"ChatGPT is connected"}),N("p",{className:"sc-p",children:[d(vt,{context:w})," will run on your ChatGPT plan",de[0]?.account_label?` (${de[0].account_label})`:"",". Nothing more to pay, nothing to install."]}),d("p",{className:"sc-opt-note",style:{textAlign:"center"},children:"It runs on our side, so it has no access to your files or your terminal."}),o&&N(Ct,{children:[d("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>m("manage"),children:"Done"}),d("div",{className:"sc-opt-alt",children:d("button",{type:"button",className:"sc-alt-link",onClick:()=>m("choose"),children:"Connect a machine too"})})]})]}),f==="denied"&&N("div",{className:"sc-card",children:[d(ur,{tone:"off"}),d("h2",{className:"sc-h",id:te,children:"Declined"}),d("p",{className:"sc-p",children:gn==="machine"?"Nothing was connected. You can ask again whenever you like.":"That machine was not attached to your account, and the terminal has been told so."}),d("button",{type:"button",className:"sc-btn sc-btn-wide",style:{marginTop:16},onClick:()=>m("choose"),children:"Back to the start"})]})]})}function go(e){return e?.app.name??"this app"}function Xs(e){let n=e?.app.icon_urls;if(n?.length)return n;let t=e?.app.icon_url;return t?[t]:[]}function bo(e){let n=Xs(e),[t,r]=q([]),o=re(c=>{c&&r(i=>i.includes(c)?i:[...i,c])},[]),s=re(c=>o(c.currentTarget.getAttribute("src")),[o]),a=re(c=>{c?.complete&&c.naturalWidth===0&&o(c.getAttribute("src"))},[o]);return{icon:n.find(c=>!t.includes(c)),onError:s,ref:a}}function ea({context:e}){let{icon:n,onError:t,ref:r}=bo(e);return e?.app.mark==="soba"?d(j,{className:"sc-app-mark"}):n?d("img",{className:"sc-app-mark",src:n,alt:"","aria-hidden":"true",ref:r,onError:t}):null}function vt({context:e}){let{icon:n,onError:t,ref:r}=bo(e),o=e?.app.mark==="soba";return N("span",{className:"sc-app",children:[o&&d(j,{className:"sc-app-icon"}),!o&&n&&d("img",{className:"sc-app-icon",src:n,alt:"",ref:r,onError:t}),go(e)]})}function Mn({onClick:e}){return d("button",{type:"button",className:"sc-head-back",onClick:e,"aria-label":"Back",children:d("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:d("path",{d:"M15 5 8 12l7 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function cr({className:e}){return d("svg",{className:e,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:d("path",{d:"M9 5l7 7-7 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function kt({mark:e,still:n}){return N("span",{className:"sc-waiting","aria-hidden":"true",children:[!n&&d("svg",{className:"sc-waiting-orbit",viewBox:"0 0 100 100","aria-hidden":"true",focusable:"false",children:d("circle",{className:"sc-waiting-arc",cx:"50",cy:"50",r:"46"})}),d(e,{className:"sc-waiting-mark"})]})}function ur({tone:e}){return d("span",{className:`sc-result sc-result-${e}`,"aria-hidden":"true",children:d(Vt,{kind:e==="ok"?"snap":"gone",size:84})})}function na({text:e}){return d(Ct,{children:e.split("`").map((n,t)=>t%2===1?d("code",{className:"sc-inline-code",children:n},t):n)})}function Kn({k:e,v:n}){return N("li",{className:"sc-fact",children:[d("span",{className:"sc-fact-key",children:e}),d("span",{children:n})]})}import{useEffect as ta,useRef as mr}from"react";var Nt=0,pr=null;function yo(){if(typeof document>"u")return()=>{};Nt===0&&(pr=document.body.style.overflow,document.body.style.overflow="hidden"),Nt+=1;let e=!1;return()=>{e||(e=!0,Nt-=1,Nt===0&&(document.body.style.overflow=pr??"",pr=null))}}import{jsx as wo}from"react/jsx-runtime";function jn({open:e,onClose:n,labelledBy:t,theme:r,style:o,children:s}){let a=mr(null),c=mr(null),i=mr(null);return ta(()=>{let l=a.current;if(l){if(!e){l.open&&l.close();return}return l.open||l.showModal(),document.activeElement===l&&c.current?.focus(),yo()}},[e]),wo("dialog",{ref:a,className:"soba-connect sc-modal","aria-labelledby":t,...r?{"data-theme":r}:{},style:o,onCancel:l=>{l.preventDefault(),n()},onPointerDown:l=>{i.current=l.target},onClick:l=>{l.target===l.currentTarget&&i.current===l.currentTarget&&n()},children:wo("div",{className:"sc-modal-sheet",ref:c,tabIndex:-1,children:s})})}import{useRef as sa,useState as aa}from"react";var ra={"claude-code":{small:"haiku",large:"opus"}};function vo(e){let n=ra[e];return!!(n?.small||n?.large)}var oa={haiku:"Haiku",sonnet:"Sonnet",opus:"Opus",fable:"Fable"};function ko(e){return oa[e]??e}function fr(e){let n=[...e].sort(ft),t=Ee([...e]),r=t?De(t):null,s=[{id:"auto",kind:"auto",label:"Automatic",model:"auto",...r?.runtime?{note:`Uses ${r.runtime.display_name}`}:{}}];n.some(u=>ye(u).some(p=>vo(p.id)))&&s.push({id:"small",kind:"size",label:"Fast",note:"quick and cheap",model:"small"},{id:"large",kind:"size",label:"Best",note:"the most capable",model:"large"});let c=new Map;for(let u of n)for(let p of ye(u))for(let y of p.models){if(!y)continue;let f=`${p.id}/${y}`,m=c.get(f);if(m){m.machines.add(K(u));continue}c.set(f,{option:{id:f,kind:"named",label:ko(y),model:y,runtime:p.id,runtimeName:p.display_name,costClass:p.cost_class},machines:new Set([K(u)])})}let i=new Set;for(let{machines:u}of c.values())for(let p of u)i.add(p);let l=i.size>1;for(let{option:u,machines:p}of c.values()){let y=l&&p.size===1?[...p][0]:void 0;s.push(y?{...u,machine:y}:u)}return s}function Yn(e){let n=[],t=[];for(let r of e){if(r.kind!=="named"){n.push(r);continue}let o=r.runtimeName??r.runtime??"",s=t.find(a=>a.heading===o);s?s.options.push(r):t.push({heading:o,options:[r]})}return n.length?[{heading:null,options:n},...t]:t}function hr(e,n){let t=e.find(o=>o.kind==="auto")??{id:"auto",kind:"auto",label:"Automatic",model:"auto"};if(!n||n==="auto")return{selected:t,unavailable:null};let r=e.find(o=>o.id===n);return r?{selected:r,unavailable:null}:{selected:t,unavailable:n}}function gr(e){return e.runtime?{model:e.model,runtime:e.runtime}:{model:e.model}}function Zn(e){return e.length>1}import{jsx as xt,jsxs as Co}from"react/jsx-runtime";function br({options:e,selected:n,onPick:t,caption:r,disabled:o,className:s}){let[a,c]=aa(!1),i=sa(null);if(!Zn(e))return null;let l=s?`sc-mp ${s}`:"sc-mp";return Co("span",{className:l,children:[r&&xt("span",{className:"sc-mp-cap",children:r}),Co("button",{ref:i,type:"button",className:"sc-mp-btn","aria-haspopup":"menu","aria-expanded":a,"aria-label":`Model: ${n.label}. Change`,disabled:o,onClick:()=>c(u=>!u),children:[xt("span",{className:"sc-mp-label",children:n.label}),xt(Nn,{open:!0})]}),a&&xt(Hn,{anchor:i,label:"Which model answers",options:ia(e),current:n.id,onClose:()=>c(!1),onPick:u=>{c(!1),u&&t(u)}})]})}function ia(e){let n=[];for(let t of Yn(e))t.options.forEach((r,o)=>{let s=la(r);n.push({id:r.id,label:r.label,...s?{note:s}:{},...t.heading&&o===0?{heading:t.heading}:{},...!t.heading&&r.kind==="size"&&o===1?{rule:!0}:{}})});return n}function la(e){return e.kind!=="named"?e.note:e.machine?`on ${e.machine}`:void 0}import{useEffect as yr,useRef as ca}from"react";import{jsx as ua}from"react/jsx-runtime";var pn=8;function wr({open:e,onClose:n,anchor:t,label:r,theme:o,style:s,children:a}){let c=ca(null);return yr(()=>{let i=c.current;if(!(!i||!(typeof i.showPopover=="function")))try{e?i.showPopover():i.hidePopover()}catch{}},[e]),yr(()=>{if(!e)return;let i=()=>{let u=c.current,p=t.current;if(!u||!p)return;let y=p.getBoundingClientRect(),f=u.offsetWidth,m=u.offsetHeight,w=window.innerWidth-f-pn,M=Math.max(pn,Math.min(y.right-f,Math.max(pn,w))),R=y.bottom+pn,_=y.top-pn-m,U=R+m>window.innerHeight-pn&&_>pn?_:R;u.style.left=`${Math.round(M)}px`,u.style.top=`${Math.round(U)}px`};i();let l=requestAnimationFrame(i);return window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{cancelAnimationFrame(l),window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[e,t]),yr(()=>{if(!e)return;let i=u=>{u.key==="Escape"&&n()},l=u=>{let p=u.target;p&&(c.current?.contains(p)||t.current?.contains(p)||n())};return document.addEventListener("keydown",i),document.addEventListener("pointerdown",l,!0),()=>{document.removeEventListener("keydown",i),document.removeEventListener("pointerdown",l,!0)}},[e,n,t]),ua("div",{ref:c,role:"dialog","aria-label":r,className:"soba-connect sc-pop",...o?{"data-theme":o}:{},popover:"manual",hidden:!e,style:s,children:a})}var Jn=new Map,Pn=new Map,No=!1;function da(){No||typeof window>"u"||(No=!0,window.addEventListener("storage",e=>{!e.key||!Jn.has(e.key)||(Pn.set(e.key,wt(e.key)),vr(e.key))}))}function vr(e){for(let n of Jn.get(e)??[])n()}function Qn(e){return e??""}function kr(e,n){let t=Qn(e);da();let r=Jn.get(t)??new Set;return r.add(n),Jn.set(t,r),()=>{r.delete(n),r.size===0&&Jn.delete(t)}}function St(e){let n=Qn(e),t=Pn.get(n);if(t!==void 0)return t;let r=e?wt(e):null;return Pn.set(n,r),r}function Cr(){return null}function Nr(e,n){St(e)===null&&(Pn.set(Qn(e),n),vr(Qn(e)))}function xr(e,n){let t=Qn(e);Pn.get(t)!==n&&(Pn.set(t,n),rr(e,n),vr(t))}function Ue(e){let n=`${e.unit}s`;return e.reward==="unlimited"?`Unlimited ${n} on your own AI`:e.reward==="included"&&e.includedUnits!==null?`${ma(e.includedUnits)} ${n} a month once you connect`:e.reward==="credit"&&e.creditMicros>0?`${pa(e.creditMicros)} back each month you stay connected`:null}function He(e){return e==="unlimited"||e==="included"}var So=new Set(["user-hardware","user-subscription"]),xo=new Set(["open-weights","frontier"]);function Se(e){return e===null||e.length===0?!1:e.every(n=>So.has(n))}var pa=e=>(e/1e6).toLocaleString("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}),ma=e=>e.toLocaleString("en-US");function Sr(e,n){if(!(n===null||n.some(s=>xo.has(s))))return!1;let r=e.findIndex(s=>So.has(s));if(r===-1)return!1;let o=e.findIndex(s=>xo.has(s));return o===-1||r<o}import{createContext as Mo,useContext as Po}from"react";var Mr=Mo(null);function Rn(){return Po(Mr)}var Pr=Mo({context:null,machines:void 0,theme:"light"});function H(){return Po(Pr)}import{useMemo as ga}from"react";import{createContext as fa,useContext as ha}from"react";var Rr=fa(null);function D(){let e=ha(Rr);if(!e)throw new Error("useSoba() must be used inside a <SobaProvider>.");return e}function Xn(){let{compute:e}=D();return ga(()=>{let n=e.machines,t=[...n].sort((s,a)=>Ee([s,a])===s?-1:1).map(ba),r=Ee([...n]),o=ln(n);return{view:t.length?"machines":e.loading?"loading":e.error?"error":"empty",machines:t,primary:r?t.find(s=>s.machine.id===r.id)??null:null,connected:e.connected,online:e.online,stalled:e.connected&&!e.online&&o?t.find(s=>s.machine.id===o.id)??null:null,loading:e.loading,error:e.error,refresh:e.refresh}},[e])}function ba(e){let n=De(e);return{machine:e,name:K(e),state:Ge(e),status:$t(e),hardware:Dn(e),lastSeen:e.state==="offline"?Un(e.last_seen_at):null,runtimes:ye(e).map(t=>({runtime:t,name:t.display_name,auth:$n(t),quarantined:!!t.quarantined})),runsOn:{by:n.by,name:n.runtime?.display_name??null}}}import{jsx as et}from"react/jsx-runtime";function ya({className:e}){let{theme:n}=H(),t=e?`soba-connect ${e}`:"soba-connect";return et("div",{className:t,"data-theme":n,children:et(_r,{})})}function _r(){let e=Xn();return e.view==="loading"?et("p",{className:"sc-note",children:"Loading\u2026"}):e.view==="error"?et("p",{className:"sc-error",children:e.error?.message}):et(Wn,{machines:e.machines.map(n=>n.machine)})}import{useCallback as tt,useEffect as Or,useMemo as xa,useRef as Ir,useState as mn}from"react";import{useId as wa}from"react";import{jsx as _n,jsxs as Mt}from"react/jsx-runtime";function nt({open:e,onOpenChange:n,initialCode:t,onConnected:r,showStatus:o,reason:s}){let{error:a}=D(),c=Rn(),i=H(),l=()=>n(!1),u=wa(),p=i.context?.background?.trim(),y=p?an(p,i.context?.accent):void 0;return Mt(jn,{open:e,onClose:l,labelledBy:u,theme:i.theme,style:y,children:[a?Mt("div",{className:"sc-card",children:[_n("h2",{className:"sc-title",id:u,children:"Could not start"}),_n("p",{className:"sc-error",children:a.message})]}):!c&&!i.context?Mt("div",{className:"sc-card",children:[_n("h2",{className:"sc-title",id:u,children:"One moment"}),_n("p",{className:"sc-note",children:"Getting your compute\u2026"})]}):_n(dr,{client:c,active:e,onClose:l,headingId:u,theme:i.theme,initialContext:i.context,...i.machines!==void 0?{initialMachines:i.machines}:{},...t?{initialCode:t}:{},...r?{onConnected:r}:{},...o===void 0?{}:{showStatus:o},...s?{reason:s}:{}}),Mt("p",{className:"sc-modal-foot",children:[_n(j,{className:"sc-foot-mark"}),"Secured by Soba"]})]})}import{useCallback as va}from"react";function ka(){let{connect:e}=D(),n=Xn(),t=va(()=>e.open("manual"),[e]);return{...Pt(n.primary?.machine??null),machine:n.primary,open:t,canOpen:e.hasModal,loading:n.view==="loading"}}function Pt(e){let n=Ge(e);return{label:e?n.word:"Connect compute",ariaLabel:e?`${n.word} on ${K(e)}`:"Connect compute",connected:e!==null,state:n}}import{useCallback as Ro,useEffect as Ca,useState as Na}from"react";function Er({enabled:e=!0,intervalMs:n=3e3}={}){let t=Rn(),[r,o]=Na(null),s=Ro(async()=>{t&&o(await t.runs())},[t]);Ca(()=>{if(!e||!t)return;let c=!0,i=Oe(async()=>{let l=await t.runs();c&&o(l)},n);return()=>{c=!1,i()}},[e,t,n]);let a=Ro(async c=>{if(!t)throw new Error("Stopping a run needs <SobaProvider>.");await t.stopRun(c),await s().catch(()=>{})},[t,s]);return{runs:r,refresh:s,stop:a}}import{Fragment as Tr,jsx as je,jsxs as rt}from"react/jsx-runtime";function fn({children:e,variant:n,className:t,initialCode:r,onConnected:o,defaultOpen:s,open:a,onOpenChange:c,showConnected:i=!0}){let{compute:l,connect:u}=D(),p=H(),{theme:y}=p,f=Rn(),[m,w]=mn(s??!!r),M=Ir(null),R=a!==void 0,_=!R&&!s&&!r&&u.hasModal,U=R?a:_?u.isOpen:m,P=v=>{_?v?u.open("manual"):u.close():R||w(v),c?.(v)},T=Ir(U);Or(()=>{T.current&&!U&&M.current?.focus(),T.current=U},[U]);let[E,S]=mn(!1),{runs:W,stop:ve}=Er({enabled:E}),X=xa(()=>E&&W?Sa(l.machines,W):l.machines,[l.machines,E,W]),ke=Ee(X),V=Pt(ke),oe=i&&V.connected,We=V.state,Y=tt(()=>S(!1),[]),[Pe,Qe]=mn(!1),ce=tt(async()=>{Qe(!0);try{await l.refresh()}finally{Qe(!1)}},[l]),ue=Ir(ce);ue.current=ce,Or(()=>{E&&ue.current()},[E]);let[ee,gn]=mn(!1),[Xe,Le]=mn([]),en=!!p.context?.hosted_available;Or(()=>{if(!E||!f||!en)return;let v=!0;return f.hosted().then(F=>{v&&Le(F.credentials)}).catch(()=>{}),()=>{v=!1}},[E,f,en]);let[de,ne]=mn(!1),[Be,pe]=mn(null),Ae=tt(async(v,F)=>{if(f){pe(null);try{await f.approveRuntime(v,F),await l.refresh()}catch(me){pe(me.message)}}},[f,l]),qe=tt(async(v,F)=>{if(f){pe(null);try{await f.preferRuntime(v,F),await l.refresh()}catch(me){pe(me.message)}}},[f,l]),se=tt(async v=>{if(f){pe(null);try{await f.disconnectHosted(v),Le((await f.hosted()).credentials)}catch(F){pe(F.message)}}},[f]),O=p.context?.background?.trim(),bn=O?an(O,p.context?.accent):void 0;return rt(Tr,{children:[je("button",{ref:M,type:"button","data-theme":y,className:["sc-btn",oe?"sc-btn-connected":"sc-btn-icon",!oe&&n==="primary"?"sc-btn-primary":"",t].filter(Boolean).join(" "),...oe&&!e?{"aria-haspopup":"dialog","aria-expanded":E,"aria-label":V.ariaLabel}:{},onClick:()=>{if(oe&&!e&&!R&&!s&&!r){S(v=>!v);return}P(!0)},children:e??(oe?rt(Tr,{children:[je("span",{className:"sc-pill-tile","aria-hidden":"true",children:je(j,{className:We.tone==="busy"?"sc-pill-mark sc-pill-mark-busy":"sc-pill-mark"})}),rt("span",{className:"sc-btn-connected-text",children:[We.word,ke&&rt("span",{className:"sc-btn-connected-where",children:[" on ",K(ke)]})]}),je("i",{className:`sc-dot sc-dot-${We.tone}`,"aria-hidden":"true"})]}):rt(Tr,{children:[je(j,{className:"sc-btn-mark"}),"Connect compute"]}))}),je(wr,{open:E,onClose:Y,anchor:M,label:"Your compute",theme:y,...bn?{style:bn}:{},children:je(un,{machines:X,hosted:Xe,onApproveRuntime:(v,F)=>void Ae(v,F),onPreferRuntime:(v,F)=>void qe(v,F),onDisconnectHosted:v=>void se(v),onRefresh:()=>void ce(),refreshing:Pe,error:Be,runs:W,runsOpen:de,onToggleRuns:()=>ne(v=>!v),onStopRun:async v=>{pe(null);try{await ve(v)}catch(F){throw pe(F.message),F}},onPair:()=>{S(!1),_?u.open("pair"):(gn(!0),P(!0))},...p.context?.app.name?{appName:p.context.app.name}:{}})}),!_&&je(nt,{open:U,onOpenChange:v=>{v||gn(!1),P(v)},...ee?{showStatus:!1}:{},...r?{initialCode:r}:{},...o?{onConnected:o}:{}})]})}function Sa(e,n){return e.map(t=>{if(t.state==="offline")return t;let r=n.filter(o=>o.machine_id===t.id).length;return{...t,active:r,state:r>0?"busy":"online"}})}import{jsx as Lr,jsxs as Pa}from"react/jsx-runtime";function Ma({initialCode:e,onConnected:n,className:t,showStatus:r=!0}){let{theme:o}=H();return Pa("div",{className:t?`soba-connect ${t}`:"soba-connect","data-theme":o,children:[r&&Lr(_r,{}),Lr("div",{className:"sc-compute-act",children:Lr(fn,{...e?{initialCode:e}:{},...n?{onConnected:n}:{}})})]})}import{useId as Ha,useState as Wa}from"react";import{useCallback as $r,useEffect as To,useState as Lo}from"react";import{useCallback as Ra,useState as _a}from"react";function ot(){let[e,n]=_a(null);return{open:Ra(()=>{n(null),Zt().then(n)},[]),launch:e,note:e==="absent"?"Nothing opened here. That machine may be a different computer, or asleep.":null}}import{useCallback as _o,useMemo as Eo}from"react";function hn(e){if(!e)return null;if(typeof e=="string")return e;if(typeof Response<"u"&&e instanceof Response)return Oo(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"?Oo(n.status):n.cause&&n.cause!==e?hn(n.cause):null}function Oo(e){return e===402?"payment_required":e===409?"no_compute":null}function Ar(...e){let[n,t]=e,{plan:r,compute:o,connect:s}=D(),a=t?.predict??e.length===0,c=Oa(Ea(n),o)??(a?Ia(r,o):null),i=r.plan,l=r.plans,u=Eo(()=>{if(c!=="payment_required")return null;let m=i?.price??0,w=i?.included_units??0;return l.find(M=>M.id!==i?.id&&M.price>m&&(M.included_units===null||M.included_units>w))??null},[c,l,i]),p=_o(async()=>{if(!u)return;if(u.selectable){await r.select(u.id);return}let m=await r.checkout(u.id);window.location.assign(m)},[u,r]),y=s.open,f=_o(()=>{c&&y(c)},[y,c]);return Eo(()=>{if(!c)return null;let m=i?Ue({unit:i.unit,reward:i.connected_reward,includedUnits:i.connected_included_units,creditMicros:i.connected_credit*1e6}):null,w=i&&He(i.connected_reward)?m:null;return{reason:c,...Ta(c,{connectOffer:w,connected:o.connected,online:o.online,machine:ln(o.machines)?.label??null,unit:i?.unit??"message",interval:i?.interval??"month",upgrade:u!==null,resets:r.current?.period_end??null}),connectOffer:w,upgradeTo:u,connect:f,upgrade:p}},[c,i,o,u,f,p,r.current?.period_end])}function Ea(e){let n=hn(e);return n==="payment_required"||n==="no_compute"?n:null}function Oa(e,n){return e==="no_compute"&&n.connected&&n.online?null:e}function Ia(e,n){let t=e.plan;return!t||n.loading?null:Se(t.route_allow)&&!n.online?"no_compute":e.remaining===0&&t.overage==="stop"?"payment_required":null}function Ta(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 ${Io(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 ${Io(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 Io(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}function La(e){let{plan:n,allowance:t,connected:r,online:o,quiet:s,error:a,predict:c,at:i,waved:l}=e;if(!n)return null;let u=e.allow!==void 0?e.allow:n.route_allow;if(r){if(o)return null;let w=Se(u);return{reason:"stalled",title:`${s??"Your machine"} can\u2019t be reached`,detail:w?"The Soba app there has stopped reporting in, so runs have nowhere to go until it is back.":"The Soba app there has stopped reporting in, so nothing will run on your own AI until it is back.",meter:null,dismissible:!1,atTheWall:!1,ownCompute:w}}let p=hn(a),y=p==="payment_required"||p==="no_compute",f=n.ask_to_connect!==!1&&Sr(n.route_prefer,u);if(!c&&!y&&!f)return null;let m=Se(u)?Aa(n.unit,Se(n.route_allow)):He(n.connected_reward)?Da(t,n,i):f?$a(n.unit):null;return!m||m.dismissible&&l?null:{...m,dismissible:!!m.dismissible,ownCompute:!1,atTheWall:!m.dismissible&&(!c||m.meter!==null&&m.meter.left===0)}}function Dr(e={}){let{at:n=.25,error:t,allow:r}=e,o=e.predict??!(e.errorGiven??t!==void 0),{plan:s,compute:a,connect:c}=D(),i=or(c.publishableKey),[l,u]=Lo(!1);To(()=>{u(sr(i))},[i]);let p=$r(()=>{u(!0),ar(i)},[i]),y=$r(()=>c.open("manual"),[c]),f=$r(()=>c.open("no_compute"),[c]),m=ot(),[w,M]=Lo(!1),{refresh:R}=a,{launch:_}=m;To(()=>{if(_===null||_==="absent")return;M(!1);let S=setInterval(()=>void R(),3e3),W=setTimeout(()=>{clearInterval(S),M(!0)},2e4);return()=>{clearInterval(S),clearTimeout(W)}},[_,R]);let U=Ua(c.app?.name,Gn(c.connectUrl)),P=s.loading||a.loading,T=ln(a.machines),E=P?null:La({plan:s.plan,allowance:{remaining:s.remaining,included:s.included},connected:a.connected,online:a.online,quiet:T?K(T):null,error:t,predict:o,...r!==void 0?{allow:r}:{},at:n,waved:l});return{reason:E?.reason??null,visible:E!==null,title:E?.title??null,detail:E?.detail??null,meter:E?.meter??null,dismissible:E?.dismissible??!1,dismissed:l,dismiss:p,open:y,atTheWall:E?.atTheWall??!1,steps:U,stalled:E?.reason==="stalled"?{machine:T?K(T):null,ownCompute:E.ownCompute,wake:m.open,launch:m.launch,note:m.note,stuck:w,connectAnother:f}:null,loading:P}}function Aa(e,n){return{reason:"needed",title:n?"This plan runs on your own AI.":`These ${e}s run on your own AI.`,detail:`Connect a machine and your ${e}s run there, free, on access you already have.`,meter:null}}function $a(e){return{reason:"preferred",title:"This plan prefers your own AI.",detail:`Connect a machine and your ${e}s run there instead, on access you already have.`,meter:null,dismissible:!0}}function Da(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=Ue({unit:n.unit,reward:n.connected_reward,includedUnits:n.connected_included_units,creditMicros:n.connected_credit*1e6});return s?{reason:"running",title:r===0?`No ${n.unit}s left this month.`:`${r} ${n.unit}${r===1?"":"s"} left this month.`,detail:`${s}.`,meter:{left:r,of:o}}:null}function Ua(e,n){return[{lead:"Download Soba App",detail:"",...n?{linksLead:"Get it for"}:{},links:n?Fn.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:ie.map(t=>({label:t.short,href:t.install}))}]}import{Fragment as $o,jsx as L,jsxs as Ye}from"react/jsx-runtime";function Ba(e){let{className:n,fallback:t=null}=e,r=Dr({...e.at===void 0?{}:{at:e.at},...e.predict===void 0?{}:{predict:e.predict},...e.allow===void 0?{}:{allow:e.allow},error:e.error,errorGiven:"error"in e}),{connect:o}=D(),{theme:s}=H(),[a,c]=Wa(null),i=Ha(),l=L($o,{children:t});if(!r.visible)return l;if(r.stalled)return L(Ao,{className:n,theme:s,stalled:!0,children:L(qa,{title:r.title??"",detail:r.detail??"",stalled:r.stalled})});let u=a??r.atTheWall;return Ye(Ao,{className:n,theme:s,children:[Ye("div",{className:"sc-nudge-top",children:[Ye("div",{className:"sc-nudge-say",children:[L("p",{className:"sc-nudge-title",children:r.title}),L("p",{className:"sc-nudge-detail",children:r.detail}),Ye("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more","aria-expanded":u,"aria-controls":i,onClick:()=>c(!u),children:[u?"Hide the details":"How it works",L(Ga,{})]})]}),r.dismissible?L("button",{type:"button",className:"sc-nudge-dismiss","aria-label":"Dismiss",title:"Dismiss",onClick:r.dismiss,children:L(Fa,{})}):null]}),u?L("ol",{className:"sc-nudge-steps",id:i,children:r.steps.map(p=>Ye("li",{children:[p.opens?L("button",{type:"button",className:"sc-step-lead",onClick:()=>o.open("manual"),children:p.lead}):L("strong",{children:p.lead}),p.detail?L("span",{children:p.detail}):null,p.links.length>0?Ye("span",{className:"sc-step-links",children:[p.linksLead,p.links.map(y=>L("a",{href:y.href,target:"_blank",rel:"noreferrer noopener",children:y.label},y.href))]}):null]},p.lead))}):null,L(fn,{variant:"primary"})]})}function Ao({className:e,theme:n,stalled:t,children:r}){return L("div",{className:e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill","data-theme":n,children:L("div",{className:t?"sc-nudge sc-nudge-stalled":"sc-nudge",children:r})})}function qa({title:e,detail:n,stalled:t}){return Ye($o,{children:[L("div",{className:"sc-nudge-top",children:Ye("div",{className:"sc-nudge-say",children:[L("p",{className:"sc-nudge-title",children:e}),L("p",{className:"sc-nudge-detail",children:n}),t.note&&L("p",{className:"sc-nudge-note",children:t.note}),t.stuck&&L("p",{className:"sc-nudge-note",children:"The Soba app is open, but this machine still isn\u2019t reporting in. It may no longer be connected to this app."}),(t.launch==="absent"||t.stuck)&&L("button",{type:"button",className:"sc-btn sc-btn-quiet sc-nudge-more",onClick:t.connectAnother,children:t.stuck?"Connect it again":"Connect another machine"})]})}),L("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:t.wake,children:"Open Soba App"})]})}function Fa(){return L("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-x",children:L("path",{d:"m4.8 4.8 6.4 6.4M11.2 4.8l-6.4 6.4",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})})}function Ga(){return L("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",className:"sc-nudge-chev",children:L("path",{d:"M4.5 6.5 8 10l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})})}var za=new Set(["delta","thinking","status","done","error"]);function En(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"||!za.has(o.type))return null;let s={type:o.type};return typeof o.text=="string"&&(s.text=o.text),typeof o.message=="string"&&(s.message=o.message),typeof o.tool=="string"&&(s.tool=o.tool),typeof o.tier=="string"&&(s.tier=o.tier),o.usage&&typeof o.usage=="object"&&(s.usage=o.usage),typeof o.session=="string"&&(s.session=o.session),typeof o.toolInput=="string"&&(s.toolInput=o.toolInput),o.git&&typeof o.git=="object"&&(s.git=o.git),o.turn&&typeof o.turn=="object"&&typeof o.turn.text=="string"&&(s.turn={text:o.turn.text}),typeof o.reason=="string"&&(s.reason=o.reason),typeof o.retryable=="boolean"&&(s.retryable=o.retryable),(o.state==="interrupted"||o.state==="resumed")&&(s.state=o.state),s}async function*Ur(e){let n=e.body;if(!n)throw new Error("That run response had no body to stream.");let t=(e.headers.get("content-type")??"").includes("ndjson"),r=n.getReader(),o=new TextDecoder,s="",a=[];try{for(;;){let i=await r.read();if(i.done)break;for(s+=o.decode(i.value,{stream:!0});;){let l=s.indexOf(`
|
|
3
|
+
`);if(l===-1)break;let u=Uo(s.slice(0,l));if(s=s.slice(l+1),t){let p=u.trim()?En(u):null;p&&(yield p);continue}if(u===""){let p=a.join(`
|
|
4
|
+
`);if(a=[],p==="[DONE]")return;let y=p?En(p):null;y&&(yield y);continue}Do(u,a)}}!t&&s&&Do(Uo(s),a);let c=t?s.trim():a.join(`
|
|
5
|
+
`);if(c&&c!=="[DONE]"){let i=En(c);i&&(yield i)}}finally{r.cancel().catch(()=>{})}}function Do(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 Uo(e){return e.endsWith("\r")?e.slice(0,-1):e}async function Va(e){let n="";for await(let t of e)if(t.type==="delta"&&t.text&&(n+=t.text),t.type==="error")throw new Error(t.message??"The run ended with an error.");return n}import{useCallback as Hr,useEffect as Ka,useMemo as Wr,useSyncExternalStore as ja}from"react";function Br(e={}){let{compute:n,connect:t}=D(),{value:r,onChange:o,defaultValue:s,remember:a=!0,user:c}=e,i=r!==void 0,l=a&&!i?tr(t.publishableKey,c):null,u=Hr(_=>kr(l,_),[l]),p=ja(u,Hr(()=>St(l),[l]),Cr),y=Wr(()=>fr(n.machines),[n.machines]),f=Wr(()=>Yn(y),[y]);Ka(()=>{i||!s||Nr(l,s)},[i,s,l]);let m=i?r:p??s??null,{selected:w,unavailable:M}=Wr(()=>hr(y,m??null),[y,m]),R=Hr(_=>{i||xr(l,_),o?.(_)},[i,l,o]);return{options:y,groups:f,selected:w,select:R,run:gr(w),unavailable:M,pickable:Zn(y),loading:n.loading&&!n.machines.length}}import{jsx as Ho}from"react/jsx-runtime";function Ya({caption:e,disabled:n,className:t,...r}){let{theme:o}=H(),{options:s,selected:a,select:c,pickable:i}=Br(r);return i?Ho("span",{className:"soba-connect sc-inline","data-theme":o,children:Ho(br,{options:s,selected:a,onPick:c,...e?{caption:e}:{},...n?{disabled:n}:{},...t?{className:t}:{}})}):null}import{useEffect as Za}from"react";var Wo="data-soba-react",Bo=!1;function st(){if(Bo||typeof document>"u"||(Bo=!0,document.querySelector(`style[${Wo}]`)))return;let e=document.createElement("style");e.setAttribute(Wo,""),e.textContent=`.soba-connect {
|
|
6
6
|
--sc-ground: #ffffff;
|
|
7
7
|
--sc-sheet: #ffffff;
|
|
8
8
|
--sc-raised: #f6f6f7;
|
|
@@ -472,6 +472,12 @@ a.sc-btn {
|
|
|
472
472
|
font-variant-numeric: tabular-nums;
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
+
.sc-rstop {
|
|
476
|
+
align-self: center;
|
|
477
|
+
width: 24px;
|
|
478
|
+
height: 24px;
|
|
479
|
+
}
|
|
480
|
+
|
|
475
481
|
.sc-rstep {
|
|
476
482
|
display: -webkit-box;
|
|
477
483
|
overflow: hidden;
|
|
@@ -3007,7 +3013,7 @@ li.sc-plan-row.sc-plan-current {
|
|
|
3007
3013
|
.sc-opt-has-warn {
|
|
3008
3014
|
color: var(--sc-warn, #b06f14);
|
|
3009
3015
|
}
|
|
3010
|
-
`,document.head.appendChild(e)}import{jsx as Ie,jsxs as st}from"react/jsx-runtime";function Ho(e){if(!e)return null;let n=hn(e);if(n==="payment_required"||n==="no_compute")return null;if(typeof e=="string")return e||null;let t=e,r=t.error?.message;return typeof r=="string"&&r?r:typeof t.message=="string"&&t.message?t.message:"The run ended with an error."}function Ka(){return st("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[Ie("path",{d:"M8 5v4",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),Ie("circle",{cx:"8",cy:"11.6",r:"0.9",fill:"currentColor"}),Ie("circle",{cx:"8",cy:"8",r:"6.4",stroke:"currentColor",strokeWidth:"1.3"})]})}function Va({error:e,onRetry:n,onDismiss:t,title:r,className:o}){let s=Ho(e),a=H();return za(()=>ot(),[]),s?Ie("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":a.theme,role:"alert",children:st("div",{className:"sc-card sc-limit sc-run-error",children:[st("div",{className:"sc-limit-head",children:[Ie("span",{className:"sc-limit-mark sc-run-error-mark","aria-hidden":"true",children:Ie(Ka,{})}),st("div",{children:[Ie("h2",{className:"sc-limit-title",children:r??"That run did not finish"}),Ie("p",{className:"sc-limit-body sc-run-error-message",children:s})]})]}),(t||n)&&st("div",{className:"sc-limit-actions",children:[t&&Ie("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,children:"Dismiss"}),n&&Ie("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:n,children:"Try again"})]})]})}):null}import{useId as ja,useState as Uo}from"react";import{jsx as Z,jsxs as _t}from"react/jsx-runtime";function Ya({reason:e}){return Z("span",{className:"sc-limit-mark","aria-hidden":"true",children:e==="no_compute"?Z(ft,{}):Z(j,{})})}function Za(e){let{error:n,variant:t="card",onDismiss:r,className:o}=e,s=Lr(n,{predict:e.predict??!("error"in e)}),a=ja(),c=H();if(!s)return null;let i=Z(Ja,{offer:s,headingId:a,onDismiss:r});return t==="dialog"?Z(Vn,{open:!0,onClose:()=>r?.(),labelledBy:a,theme:c.theme,children:i}):Z("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":c.theme,children:i})}function Ja({offer:e,headingId:n,onDismiss:t}){let{compute:r}=D(),[o,s]=Uo(!1),[a,c]=Uo(null),i=e.reason==="no_compute"&&r.connected&&!r.online,l=i||e.connectOffer!==null||!r.connected,u=rt();async function p(){s(!0),c(null);try{await e.upgrade()}catch(y){c(y.message)}finally{s(!1)}}return _t("div",{className:"sc-card sc-limit",children:[_t("div",{className:"sc-limit-head",children:[Z(Ya,{reason:e.reason}),_t("div",{children:[Z("h2",{className:"sc-limit-title",id:n,children:e.title}),Z("p",{className:"sc-limit-body",children:e.body})]})]}),a&&Z("p",{className:"sc-error",children:a}),i&&u.note&&Z("p",{className:"sc-limit-note",children:u.note}),_t("div",{className:"sc-limit-actions",children:[t&&Z("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,disabled:o,children:"Not now"}),e.upgradeTo&&Z("button",{type:"button",className:l?"sc-btn":"sc-btn sc-btn-primary",onClick:()=>void p(),disabled:o,children:o?"Opening\u2026":e.upgradeTo.selectable?`Switch to ${e.upgradeTo.name}`:`${e.upgradeTo.name} for $${e.upgradeTo.price.toLocaleString()}/${e.upgradeTo.interval}`}),l&&Z("button",{type:"button",className:i?"sc-btn":"sc-btn sc-btn-primary",onClick:e.connect,disabled:o,children:i?"Connect another machine":"Connect compute"}),i&&Z("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:u.open,disabled:o,children:"Open Soba App"})]})]})}import{useMemo as Qa}from"react";function at(){let{plan:e,compute:n,connect:t}=D();return Qa(()=>{let r=e.plan,o=e.current,s={plan:r,assignment:o,loading:e.loading,error:e.error,periodEnd:o?.period_end?new Date(o.period_end):null};if(!r)return{...s,state:"none",trialDaysLeft:null,ceiling:null,raised:!1,uncounted:!1,used:0,remaining:null,percent:null,unlimited:!1,reward:null,summary:"Nothing is assigned to this account, so runs are bounded by whatever the app allows."};let a=ni(o?.trial_ends_at??null),c=r.connected_reward==="included"&&n.connected&&r.connected_included_units!==null,i=c?r.connected_included_units:r.included_units,l=r.connected_reward==="unlimited"&&n.connected,u=i===null,p=e.used??0,y=i===null?null:Math.max(0,i-p),f=i&&i>0?Math.min(100,Math.round(p/i*100)):null,m=i!==null&&p>=i,w=a!==null?"trial":u?"unlimited":m?r.overage==="meter"?"metered":"spent":"within";return{...s,state:w,trialDaysLeft:a,ceiling:i,raised:c,uncounted:l,used:p,remaining:y,percent:f,unlimited:u,reward:Xa(r,c||l,n.connected,()=>t.open("manual")),summary:ei({plan:r,assignment:o,used:p,ceiling:i,trialDaysLeft:a,raised:c,uncounted:l,state:w})}},[e,n.connected,t])}function Xa(e,n,t,r){let o=He({unit:e.unit,reward:e.connected_reward,includedUnits:e.connected_included_units,creditMicros:e.connected_credit*1e6});return o?{line:o,inForce:n,required:!1,connected:t,actionable:Ue(e.connected_reward)&&!t,open:r}:xe(e.route_allow)&&!t?{line:"Nothing connected yet, so nothing can run.",inForce:!1,required:!0,connected:t,actionable:!0,open:r}:null}function ei(e){let{plan:n,assignment:t,used:r,ceiling:o,trialDaysLeft:s,raised:a,uncounted:c,state:i}=e,l=`${n.unit}${r===1?"":"s"}`,u=c?" Runs your own AI serves do not count toward it.":"";if(i==="trial"&&s!==null){let f=n.price===0?"it continues free":`it is $${n.price.toLocaleString()} a ${n.interval}`;return`${s} ${s===1?"day":"days"} left of your trial, then ${f}.`}if(i==="unlimited")return`${r.toLocaleString()} ${l} this period. No ceiling on this plan.`;if(i==="metered"){let f=r-(o??0);return n.overage_per_unit>0?`${f.toLocaleString()} past the allowance, billed at $${n.overage_per_unit} a ${n.unit}.${u}`:`${f.toLocaleString()} past the allowance.${u}`}if(i==="spent")return t?.period_end?`Allowance spent. It comes back on ${Wo(t.period_end)}.${u}`:`Allowance spent. It comes back at the start of the next period.${u}`;let p=Math.max(0,(o??0)-r),y=a?` Raised from ${(n.included_units??0).toLocaleString()} while your own AI is connected.`:t?.period_end?` Resets ${Wo(t.period_end)}.`:"";return`${p.toLocaleString()} of ${(o??0).toLocaleString()} ${n.unit}s left.${y}${u}`}function ni(e){if(!e)return null;let n=new Date(e).getTime()-Date.now();return Number.isNaN(n)||n<=0?null:Math.max(1,Math.ceil(n/864e5))}function Wo(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}import{Fragment as ri,jsx as J,jsxs as Se}from"react/jsx-runtime";function Br({heading:e="Current plan",showUsage:n=!0,showName:t=!0,className:r}){let o=at(),{theme:s}=H(),a=y=>J("section",{className:r?`soba-connect sc-fill ${r}`:"soba-connect sc-fill","data-theme":s,children:Se("div",{className:"sc-card sc-current",children:[e&&J("h2",{className:"sc-section-title",children:e}),y]})});if(o.error)return a(J("p",{className:"sc-error",children:o.error.message}));if(o.loading)return a(J("p",{className:"sc-note",children:"Loading\u2026"}));if(!o.plan)return a(Se("div",{className:"sc-current-main",children:[J("p",{className:"sc-current-name",children:"No plan"}),J("p",{className:"sc-sub",children:o.summary})]}));let{plan:c,trialDaysLeft:i,percent:l,unlimited:u,reward:p}=o;return a(Se(ri,{children:[Se("div",{className:"sc-current-grid",children:[(t||i!==null)&&Se("div",{className:"sc-current-main",children:[t?Se("p",{className:"sc-current-name",children:[c.name,i!==null&&Se("span",{className:"sc-trial-badge",children:[i," ",i===1?"day":"days"," left"]})]}):i!==null&&J("p",{className:"sc-current-trial",children:Se("span",{className:"sc-trial-badge",children:[i," ",i===1?"day":"days"," left"]})}),t&&c.description&&J("p",{className:"sc-sub",children:c.description})]}),n&&Se("div",{className:"sc-usage",children:[Se("div",{className:"sc-row-between",children:[J("span",{className:"sc-fact-key",children:"Usage"}),J("span",{className:l!==null&&l>=100?"sc-usage-figure sc-usage-over":"sc-usage-figure",children:u?"Unlimited":l===null?"Metered":`${l}% used`})]}),l!==null&&J("div",{className:"sc-meter",role:"presentation",children:l>0&&J("span",{className:l>=100?"sc-meter-fill sc-meter-full":"sc-meter-fill",style:{width:`${l}%`}})}),J("p",{className:"sc-usage-line",children:o.summary})]})]}),p&&Se("div",{className:"sc-current-foot",children:[J("p",{className:p.required?"sc-plan-reward-line sc-plan-reward-need":p.inForce?"sc-plan-reward-line":"sc-plan-reward-line sc-plan-reward-open",children:p.required?p.line:p.inForce?`In force: ${ti(p.line)}.`:p.line}),(p.actionable||p.connected)&&J(fn,{})]})]}))}var ti=e=>e.charAt(0).toLowerCase()+e.slice(1);import{useCallback as oi,useMemo as si,useState as Bo}from"react";var ai={"user-hardware":"your own machine","user-subscription":"your own AI subscription","open-weights":"open models we host",frontier:"frontier models"},ii=new Set(["user-hardware","user-subscription"]);function qr(e={}){let{plan:n,compute:t,connect:r}=D(),[o,s]=Bo(null),[a,c]=Bo(null),{featured:i,onSelect:l,successUrl:u,cancelUrl:p}=e,y=oi(async m=>{s(m.id),c(null);try{if(m.selectable)await n.select(m.id);else if(l)l(m);else{let w=await n.checkout(m.id,{...u?{successUrl:u}:{},...p?{cancelUrl:p}:{}});window.location.assign(w);return}}catch(w){throw c(w.message),w}finally{(m.selectable||l)&&s(null)}},[n,l,u,p]),f=si(()=>n.plans.map(m=>{let w=n.current?.plan_id===m.id;return{plan:m,current:w,featured:i===m.id&&!w,price:li(m),allowance:m.included_units===null?`Unlimited ${m.unit}s`:`${m.included_units.toLocaleString()} ${m.unit}${m.included_units===1?"":"s"}`,allowanceNote:ci(m),computeLabel:m.route_allow===null?"any compute":m.route_allow.length===0?"no compute":null,compute:(m.route_allow??[]).map(P=>({costClass:P,label:ai[P]??P,owned:ii.has(P),runtimes:qt(P).map(R=>R.id)})),connect:ui(m,w,t.connected,()=>r.open("manual")),cta:{label:di(m,w,o===m.id),disabled:w||o!==null,busy:o===m.id,take:()=>y(m)}}}),[n.plans,n.current,i,t.connected,r,o,y]);return{offers:f,current:f.find(m=>m.current)??null,loading:n.loading,error:n.error,failed:a}}function li(e){return e.price===0?{amount:"Free",interval:null,free:!0}:{amount:`$${e.price.toLocaleString()}`,interval:e.interval,free:!1}}function ci(e){let n=[];return e.included_units===null?n.push("No ceiling on this plan"):(n.push(`Included each ${e.interval}`),e.overage==="meter"&&e.overage_per_unit>0?n.push(`then $${e.overage_per_unit} a ${e.unit}`):e.included_units>0&&n.push(`then ${e.unit}s stop`)),e.trial_days>0&&n.push(`${e.trial_days}-day trial`),n.join(" \xB7 ")}function ui(e,n,t,r){let o=He({unit:e.unit,reward:e.connected_reward,includedUnits:e.connected_included_units,creditMicros:e.connected_credit*1e6}),s=xe(e.route_allow)&&!t;if(!o&&!s)return null;let a=Ue(e.connected_reward);return{key:o?"Connect your own":"To use this",line:o??(n?"Nothing connected yet, so nothing can run.":"Runs only on compute you connect."),reward:o!==null,actionable:n&&(a||s)&&!t,open:r}}function di(e,n,t){return n?"Your plan":t?e.selectable?"Switching\u2026":"Opening\u2026":e.selectable?"Choose":`Subscribe for $${e.price.toLocaleString()}/${e.interval}`}import{jsx as g,jsxs as A}from"react/jsx-runtime";function Et(e){return e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill"}function Fr({onSelect:e,successUrl:n,cancelUrl:t,showCompute:r=!0,showConnect:o=!1,variant:s="cards",featured:a,className:c}){let{offers:i,loading:l,error:u,failed:p}=qr({...a?{featured:a}:{},...e?{onSelect:e}:{},...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}}),{theme:y}=H();if(u)return g("div",{className:Et(c),"data-theme":y,children:g("div",{className:"sc-card",children:g("p",{className:"sc-error",children:u.message})})});if(l)return g("div",{className:Et(c),"data-theme":y,children:g("div",{className:"sc-card",children:g("p",{className:"sc-note",children:"Loading plans\u2026"})})});if(i.length===0)return g("div",{className:Et(c),"data-theme":y,children:g("div",{className:"sc-card",children:g("p",{className:"sc-note",children:"This app has no plans yet."})})});let f={showCompute:r,showConnect:o};return A("div",{className:Et(c),"data-theme":y,"data-variant":s,children:[s==="rows"?g(mi,{offers:i,shelf:f}):s==="table"?g(fi,{offers:i,shelf:f}):g(pi,{offers:i,shelf:f}),p&&g("p",{className:"sc-error",children:p})]})}function pi({offers:e,shelf:n}){return g("div",{className:"sc-plans",children:e.map(t=>A("div",{className:qo("sc-plan",t),children:[A("div",{className:"sc-row-between",children:[g("span",{className:"sc-title",children:t.plan.name}),g(Gr,{offer:t})]}),g("p",{className:"sc-sub",children:t.plan.description}),g(zr,{price:t.price,free:"forever"}),g(jr,{offer:t,shelf:n}),g(Fo,{offer:t}),g("div",{className:"sc-plan-band",children:n.showCompute&&g(Vr,{offer:t})}),g("div",{className:"sc-plan-band",children:g(Kr,{offer:t})})]},t.plan.id))})}function mi({offers:e,shelf:n}){return g("ul",{className:"sc-plan-rows",children:e.map(t=>A("li",{className:qo("sc-plan-row",t),children:[A("div",{className:"sc-row-main",children:[A("span",{className:"sc-row-name",children:[g("span",{className:"sc-title",children:t.plan.name}),g(Gr,{offer:t})]}),t.plan.description&&g("p",{className:"sc-sub",children:t.plan.description}),g(Fo,{offer:t}),n.showCompute&&g(Vr,{offer:t,inline:!0}),g(Kr,{offer:t,inline:!0})]}),A("div",{className:"sc-row-side",children:[g(zr,{price:t.price,free:"forever",small:!0}),g(jr,{offer:t,shelf:n})]})]},t.plan.id))})}function fi({offers:e,shelf:n}){let t=e.some(a=>a.plan.overage_per_unit>0),r=e.some(a=>a.plan.trial_days>0),o=e.some(a=>a.connect!==null),s=a=>[a.current?"sc-col-current":"",a.featured?"sc-col-featured":""].filter(Boolean).join(" ")||void 0;return g("div",{className:"sc-table-scroll",children:A("table",{className:"sc-plan-table",children:[g("thead",{children:A("tr",{children:[g("td",{}),e.map(a=>A("th",{scope:"col",className:s(a),children:[A("span",{className:"sc-row-name",children:[g("span",{className:"sc-title",children:a.plan.name}),g(Gr,{offer:a})]}),g(zr,{price:a.price,small:!0})]},a.plan.id))]})}),A("tbody",{children:[A("tr",{children:[g("th",{scope:"row",children:"Included"}),e.map(a=>g("td",{className:s(a),children:a.allowance},a.plan.id))]}),t&&A("tr",{children:[g("th",{scope:"row",children:"Then"}),e.map(a=>g("td",{className:s(a),children:a.plan.overage_per_unit>0?`$${a.plan.overage_per_unit} / ${a.plan.unit}`:g("span",{className:"sc-muted-cell",children:"Stops"})},a.plan.id))]}),r&&A("tr",{children:[g("th",{scope:"row",children:"Trial"}),e.map(a=>g("td",{className:s(a),children:a.plan.trial_days>0?`${a.plan.trial_days} days`:g("span",{className:"sc-muted-cell",children:"None"})},a.plan.id))]}),n.showCompute&&A("tr",{children:[g("th",{scope:"row",children:"Runs on"}),e.map(a=>g("td",{className:s(a),children:g(Vr,{offer:a,bare:!0})},a.plan.id))]}),o&&A("tr",{children:[g("th",{scope:"row",children:"Connect your own"}),e.map(a=>g("td",{className:s(a),children:g(Kr,{offer:a,bare:!0})},a.plan.id))]}),A("tr",{className:"sc-table-buy",children:[g("td",{}),e.map(a=>g("td",{className:s(a),children:g(jr,{offer:a,shelf:n})},a.plan.id))]})]})]})})}function qo(e,n){return[e,n.current?"sc-plan-current":"",n.featured?"sc-plan-featured":""].filter(Boolean).join(" ")}function Gr({offer:e}){return e.current?g("span",{className:"sc-plan-badge",children:"Current"}):e.featured?g("span",{className:"sc-plan-badge-soft",children:"Recommended"}):null}function zr({price:e,small:n,free:t}){return A("p",{className:n?"sc-plan-price sc-plan-price-sm":"sc-plan-price",children:[g("span",{className:"sc-plan-amount",children:e.amount}),e.interval?A("span",{className:"sc-plan-interval",children:["/",e.interval]}):t&&g("span",{className:"sc-plan-interval sc-plan-after",children:t})]})}function Fo({offer:e}){return A("p",{className:"sc-plan-allowance",children:[g("span",{className:"sc-plan-figure",children:e.allowance}),g("span",{className:"sc-plan-qualifier",children:e.allowanceNote})]})}function Kr({offer:e,inline:n,bare:t}){let r=e.connect;if(!r)return t?g("span",{className:"sc-muted-cell",children:"None"}):null;let o=r.reward?"sc-plan-reward-line":"sc-plan-reward-line sc-plan-reward-need",s=r.actionable?A("button",{type:"button",className:`${o} sc-plan-reward-act`,"aria-label":"Connect compute",onClick:r.open,children:[g("span",{className:"sc-reward-said",children:r.line}),A("span",{className:"sc-reward-do","aria-hidden":!0,children:[g(j,{className:"sc-reward-mark"}),"Connect compute"]})]}):g("p",{className:o,children:r.line});return t?s:g("div",{className:n?"sc-plan-reward sc-plan-reward-inline":"sc-plan-reward",children:s})}function Vr({offer:e,inline:n,bare:t}){let r=e.computeLabel?g("ul",{className:n?"sc-compute sc-compute-inline":"sc-compute",children:g("li",{children:e.computeLabel})}):g("ul",{className:n?"sc-compute sc-compute-inline":"sc-compute",children:e.compute.map(o=>A("li",{className:o.owned?"sc-compute-own":void 0,children:[o.label,g(hi,{runtimes:o.runtimes})]},o.costClass))});return t?r:A("div",{className:n?"sc-plan-compute sc-plan-compute-inline":"sc-plan-compute",children:[g("span",{className:"sc-fact-key",children:"Runs on"}),r]})}function jr({offer:e,shelf:n}){let t=e.connect;return n.showConnect&&t?.actionable?A("button",{type:"button",className:"sc-btn sc-btn-primary sc-btn-icon",onClick:t.open,children:[g(j,{className:"sc-btn-mark"}),"Connect compute"]}):g("button",{type:"button",className:e.current?"sc-btn":"sc-btn sc-btn-primary",disabled:e.cta.disabled,onClick:()=>void e.cta.take().catch(()=>{}),children:e.cta.label})}function hi({runtimes:e}){return e.length===0?null:g("span",{className:"sc-compute-marks",children:e.map(n=>{let t=ze[n];return t?g(t,{className:"sc-rt-mark"},n):null})})}import{jsx as Yr,jsxs as Go}from"react/jsx-runtime";function gi({heading:e,plansHeading:n,showUsage:t=!0,showName:r=!0,className:o,...s}){let{plan:a,loading:c}=at(),{theme:i}=H(),l=n??(c?"Plans":a?"Change plan":"Choose a plan");return Go("div",{className:o?`soba-connect sc-fill sc-billing ${o}`:"soba-connect sc-fill sc-billing","data-theme":i,children:[Yr(Br,{...e===void 0?{}:{heading:e},showUsage:t,showName:r}),Go("section",{className:"sc-billing-plans",children:[l&&Yr("h2",{className:"sc-section-title",children:l}),Yr(Fr,{...s})]})]})}import{useCallback as zo,useState as Ko}from"react";function Zr({plan:e,successUrl:n,cancelUrl:t,label:r}){let{plan:o}=D(),[s,a]=Ko(!1),[c,i]=Ko(null),l=zo(()=>o.checkout(e.id,{...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}}),[o,e.id,n,t]),u=zo(async()=>{a(!0),i(null);try{window.location.assign(await l())}catch(p){i(p.message),a(!1)}},[l]);return{label:s?"Opening\u2026":r??`Subscribe for $${e.price.toLocaleString()}/${e.interval}`,busy:s,error:c,buy:u,session:l}}import{jsx as Vo,jsxs as yi}from"react/jsx-runtime";function bi({plan:e,successUrl:n,cancelUrl:t,label:r,className:o}){let{theme:s}=H(),a=Zr({plan:e,...n?{successUrl:n}:{},...t?{cancelUrl:t}:{},...r?{label:r}:{}});return yi("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":s,children:[Vo("button",{type:"button",className:"sc-btn sc-btn-primary",disabled:a.busy,onClick:()=>void a.buy(),children:a.label}),a.error&&Vo("p",{className:"sc-error",children:a.error})]})}import{useCallback as Te,useEffect as Je,useMemo as En,useRef as Qe,useState as Q}from"react";var wi="soba.session:";function jo(e){return!e.cacheKey||!e.endpoint?null:wi+JSON.stringify([e.endpoint,e.user??null,e.cacheKey])}function vi(e){try{let n=globalThis.localStorage?.getItem(e);if(!n)return null;let t=JSON.parse(n);return typeof t.token!="string"||typeof t.expiresAt!="number"?null:{token:t.token,expiresAt:t.expiresAt}}catch{return null}}function ki(e,n){try{n?globalThis.localStorage?.setItem(e,JSON.stringify(n)):globalThis.localStorage?.removeItem(e)}catch{}}var Yo=6e4,Ci=1e4,Ot=class{#e;#n=null;#r=null;#t;#o=new Set;constructor(n){this.#t=n,this.#e=n.token??null;let t=jo(n),r=t&&!this.#e?vi(t):null;r&&r.expiresAt-Yo>Date.now()&&(this.#e=r.token,this.#n=r.expiresAt)}get token(){return this.#e}get expiresAt(){return this.#n}get canRefresh(){return!!this.#t.endpoint}get refreshAt(){return!this.canRefresh||this.#n===null?null:Math.max(Date.now()+Ci,this.#n-Yo)}subscribe(n){return this.#o.add(n),()=>this.#o.delete(n)}async ensure(){return this.#e?this.#e:this.refresh()}async refresh(){if(this.#r)return this.#r;let n=this.#t.endpoint;if(!n)throw new Error("This Soba session cannot be refreshed. Pass `sessionEndpoint` so the provider can mint a new one.");let t=this.#t.fetchImpl??fetch.bind(globalThis);this.#r=(async()=>{let r=await t(n,{method:"POST",headers:{"content-type":"application/json"},credentials:"same-origin",body:JSON.stringify(this.#t.user?{user:this.#t.user}:{})});if(!r.ok)throw new Error(`Could not start a Soba session (${r.status} from ${n}).`);let o=await r.json(),s=o.session??o.token;if(!s)throw new Error(`${n} answered without a \`session\`. See @soba-so/react's README.`);let a=o.expires_in??o.expiresIn;this.#e=s,this.#n=typeof a=="number"?Date.now()+a*1e3:null;let c=jo(this.#t);c&&ki(c,this.#n===null?null:{token:s,expiresAt:this.#n});for(let i of this.#o)i();return s})();try{return await this.#r}finally{this.#r=null}}},_n=new Map,Zo=new WeakMap,Ni=1;function xi(e){if(e.token||!e.endpoint)return null;let n=0;return e.fetchImpl&&(n=Zo.get(e.fetchImpl)??Ni++,Zo.set(e.fetchImpl,n)),JSON.stringify([e.endpoint,e.user??null,n,e.cacheKey??null])}function Jo(e){let n=xi(e);if(!n)return new Ot(e);let t=_n.get(n)??{holder:new Ot(e),users:0};return _n.set(n,t),t.holder}function Qo(e){for(let n of _n.values())n.holder===e&&n.users++}function Xo(e){for(let[n,t]of _n)if(t.holder===e){setTimeout(()=>{--t.users<=0&&_n.get(n)===t&&_n.delete(n)},0);return}}function es(e,n=fetch.bind(globalThis)){return async(t,r)=>{let o=await n(t,r);if(o.status!==401||!e.canRefresh)return o;let s;try{s=await e.refresh()}catch{return o}return n(t,Si(r,s))}}function Si(e,n){let t=new Headers(e?.headers);return t.set("authorization",`Bearer ${n}`),{...e,headers:t}}import{jsx as Jr,jsxs as _i}from"react/jsx-runtime";var Mi="https://www.soba.so",Pi=3e4;function Ri(e){let{children:n,session:t,sessionEndpoint:r,user:o,sessionCacheKey:s,runEndpoint:a,theme:c,initialMachines:i,initialConnect:l=null,initialPlans:u,initialCurrentPlan:p=null,baseUrl:y=Mi,pollMs:f=Pi,injectStyles:m=!0,modal:w=!0,fetchImpl:P,onError:R}=e,[_,M]=Q(t??null),[B,I]=Q(null),[N,F]=Q(l),[T,se]=Q(null),[X,ve]=Q(l===null),[K,ae]=Q(i??[]),[We,Y]=Q(null),[Me,Xe]=Q(i===void 0),[de,pe]=Q(u??[]),[ee,gn]=Q(p),[en,Le]=Q(null),[nn,me]=Q(u===void 0),[ne,Be]=Q(null),[Pe,Ae]=Q(!1),qe=Qe(R);qe.current=R;let ie=Te(k=>{I(k),qe.current?.(k)},[]);Je(()=>{m&&ot()},[m]);let E=En(()=>Jo({...t?{token:t}:{},...r?{endpoint:r}:{},...o?{user:o}:{},...P?{fetchImpl:P}:{},...s?{cacheKey:s}:{}}),[t,r,o,P,s]);Je(()=>{let k=!0;Qo(E);let z=E.subscribe(()=>{k&&M(E.token)});return!E.token&&!E.canRefresh?ie(new Error("<SobaProvider> needs a `session` or a `sessionEndpoint`. A browser cannot mint one: that takes your secret key.")):E.ensure().then(()=>k&&M(E.token),le=>k&&ie(le)),()=>{k=!1,z(),Xo(E)}},[E,ie]),Je(()=>{B&&(ve(!1),Xe(!1),me(!1),se(k=>k??B),Y(k=>k??B),Le(k=>k??B))},[B]),Je(()=>{let k=E.refreshAt;if(k===null)return;let z=()=>{E.refresh().catch(ge=>ie(ge))},le=()=>{document.hidden||(document.removeEventListener("visibilitychange",le),z())},dt=setTimeout(()=>{typeof document<"u"&&document.hidden?document.addEventListener("visibilitychange",le):z()},Math.max(0,k-Date.now()));return()=>{clearTimeout(dt),typeof document<"u"&&document.removeEventListener("visibilitychange",le)}},[E,ie,_]);let bn=Qe(l?.machines_url??null),v=En(()=>{if(!_)return null;let k=new Tn({session:_,baseUrl:y,fetchImpl:es(E,P??fetch.bind(globalThis))});return k.setMachinesUrl(bn.current),k},[_,y,E,P]),G=Qe(l!==null);Je(()=>{if(!v||G.current)return;let k=!0;return ve(!0),v.context().then(z=>{k&&(F(z),se(null),ve(!1))},z=>{k&&(se(z),ve(!1))}),()=>{k=!1}},[v]);let te=Te(async()=>{if(v)try{let k=await v.machines();ae(Array.isArray(k)?k:[]),Y(null)}catch(k){Y(k)}finally{Xe(!1)}},[v]),fe=Te(async()=>{if(v)try{let k=await v.plans();pe(k.plans),gn(k.current),Le(null)}catch(k){Le(k)}finally{me(!1)}},[v]),re=Qe(!1),[Fe,yn]=Q(!1),wn=Qe(u!==void 0),tn=Qe(!1),rn=Te(()=>{re.current||(re.current=!0,tn.current&&queueMicrotask(()=>{tn.current&&yn(!0)}))},[]);Je(()=>(tn.current=!0,re.current&&yn(!0),()=>{tn.current=!1}),[]),Je(()=>{!v||!Fe||wn.current||fe()},[v,Fe,fe]);let on=Te(async k=>{if(!v)throw new Error("No session yet.");await v.selectPlan(k),await fe()},[v,fe]),It=Te(async(k,z)=>{if(!v)throw new Error("No session yet.");let le=await v.checkoutPlan(k,z);if(!le.url)throw new Error("Checkout could not be started.");return le.url},[v]),it=Te(async()=>{if(!v)throw new Error("No session yet.");await v.leavePlan(),await fe()},[v,fe]),lt=Qe(i!==void 0);Je(()=>{if(!v)return;let k=Oe(te,f,{immediate:!lt.current});return lt.current=!1,k},[v,te,f]);let vn=Te((k="manual")=>{w&&(Ae(!0),Be(k))},[w]),ct=Te(()=>Be(null),[]),q=Qe(K);q.current=K;let Re=Te(async k=>{if(!a)throw new Error("Pass `runEndpoint` to <SobaProvider> to start runs from the browser. It is your own route: it holds your secret key, calls soba.run(), and forwards the stream.");let{signal:z,...le}=k,ge=await(P??fetch.bind(globalThis))(a,{method:"POST",headers:{"content-type":"application/json",accept:"text/event-stream"},credentials:"same-origin",body:JSON.stringify(le),...z?{signal:z}:{}});if(!ge.ok){let $e=await ge.json().catch(()=>null),be=new Error($e?.error?.message??`${a} answered ${ge.status}.`);be.status=ge.status,$e?.error?.code&&(be.code=$e.error.code),$e?.error&&(be.error=$e.error);let pt=q.current.length>0&&!q.current.some(Lt=>Lt.state!=="offline");throw ge.status===409&&pt&&vn("no_compute"),be}let ke=Dr(ge);return async function*(){try{yield*ke}finally{re.current&&fe()}}()},[a,P,fe,vn]),he=En(()=>ee?de.find(k=>k.id===ee.plan_id)??null:null,[de,ee]),sn=En(()=>he?he.connected_reward==="included"&&K.length>0&&he.connected_included_units!==null?he.connected_included_units:he.included_units:null,[he,K]),ut=En(()=>({plans:de,current:ee,plan:he,used:ee?.units_used??null,included:sn,remaining:sn!==null&&ee?Math.max(0,sn-ee.units_used):null,unlimited:he!==null&&sn===null,loading:nn,error:en,select:on,checkout:It,leave:it,refresh:fe}),[de,ee,he,sn,nn,en,on,It,it,fe]),Tt=En(()=>({session:_,client:v,error:B,get plan(){return rn(),ut},compute:{machines:K,connected:K.length>0,online:K.some(k=>k.state!=="offline"),loading:Me,error:We,refresh:te},connect:{app:N?.app??null,command:N?.command??null,connectUrl:N?.connect_url??null,publishableKey:N?.publishable_key??null,loading:X,error:T,open:vn,close:ct,isOpen:ne!==null,hasModal:w},run:Re}),[_,v,B,ut,rn,ne,vn,ct,w,K,Me,We,te,N,X,T,Re]);return Jr(Pr.Provider,{value:v,children:Jr(Rr.Provider,{value:{context:N,machines:Me?void 0:K,theme:c??N?.theme??"light"},children:_i(_r.Provider,{value:Tt,children:[n,w&&Pe&&Jr(et,{open:ne!==null,onOpenChange:k=>Be(k?ne??"manual":null),onConnected:()=>{te()},...ne==="payment_required"||ne==="no_compute"?{reason:ne}:{},...ne==="pair"?{showStatus:!1}:{}})]})})})}function Ei(e){return e?Oi[e]??e:null}var Oi={"user-hardware":"your own computer","user-subscription":"your own AI plan","user-api-key":"your own API key","open-weights":"open models we host",frontier:"a frontier model we pay for"};async function Ii(e,n,t){let r=n.local;if(!r?.session||n.after)return null;let o=/\/v1\/runs\/([^/]+)\/events/.exec(e.url)?.[1];if(!o)return null;let s=`http://127.0.0.1:${r.port??47321}/v1/runs/${o}/events`,a=new AbortController,c=()=>a.abort();n.signal?.addEventListener("abort",c);let i=setTimeout(()=>a.abort(),r.timeoutMs??3e3);try{let l=await t(s,{headers:{authorization:`Bearer ${r.session}`,accept:"text/event-stream"},signal:a.signal});return l.ok?{url:s,bearer:r.session,open:l}:null}catch{return null}finally{clearTimeout(i),n.signal?.removeEventListener("abort",c)}}async function*Ti(e){let n=e.body;if(!n)return;let t=n.getReader(),r=new TextDecoder,o="",s=null,a=[];try{for(;;){let c=await t.read();if(c.done)return;o+=r.decode(c.value,{stream:!0});for(let i=o.indexOf(`
|
|
3016
|
+
`,document.head.appendChild(e)}import{jsx as Ie,jsxs as at}from"react/jsx-runtime";function qo(e){if(!e)return null;let n=hn(e);if(n==="payment_required"||n==="no_compute")return null;if(typeof e=="string")return e||null;let t=e,r=t.error?.message;return typeof r=="string"&&r?r:typeof t.message=="string"&&t.message?t.message:"The run ended with an error."}function Ja(){return at("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[Ie("path",{d:"M8 5v4",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),Ie("circle",{cx:"8",cy:"11.6",r:"0.9",fill:"currentColor"}),Ie("circle",{cx:"8",cy:"8",r:"6.4",stroke:"currentColor",strokeWidth:"1.3"})]})}function Qa({error:e,onRetry:n,onDismiss:t,title:r,className:o}){let s=qo(e),a=H();return Za(()=>st(),[]),s?Ie("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":a.theme,role:"alert",children:at("div",{className:"sc-card sc-limit sc-run-error",children:[at("div",{className:"sc-limit-head",children:[Ie("span",{className:"sc-limit-mark sc-run-error-mark","aria-hidden":"true",children:Ie(Ja,{})}),at("div",{children:[Ie("h2",{className:"sc-limit-title",children:r??"That run did not finish"}),Ie("p",{className:"sc-limit-body sc-run-error-message",children:s})]})]}),(t||n)&&at("div",{className:"sc-limit-actions",children:[t&&Ie("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,children:"Dismiss"}),n&&Ie("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:n,children:"Try again"})]})]})}):null}import{useId as Xa,useState as Fo}from"react";import{jsx as Z,jsxs as Rt}from"react/jsx-runtime";function ei({reason:e}){return Z("span",{className:"sc-limit-mark","aria-hidden":"true",children:e==="no_compute"?Z(ht,{}):Z(j,{})})}function ni(e){let{error:n,variant:t="card",onDismiss:r,className:o}=e,s=Ar(n,{predict:e.predict??!("error"in e)}),a=Xa(),c=H();if(!s)return null;let i=Z(ti,{offer:s,headingId:a,onDismiss:r});return t==="dialog"?Z(jn,{open:!0,onClose:()=>r?.(),labelledBy:a,theme:c.theme,children:i}):Z("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":c.theme,children:i})}function ti({offer:e,headingId:n,onDismiss:t}){let{compute:r}=D(),[o,s]=Fo(!1),[a,c]=Fo(null),i=e.reason==="no_compute"&&r.connected&&!r.online,l=i||e.connectOffer!==null||!r.connected,u=ot();async function p(){s(!0),c(null);try{await e.upgrade()}catch(y){c(y.message)}finally{s(!1)}}return Rt("div",{className:"sc-card sc-limit",children:[Rt("div",{className:"sc-limit-head",children:[Z(ei,{reason:e.reason}),Rt("div",{children:[Z("h2",{className:"sc-limit-title",id:n,children:e.title}),Z("p",{className:"sc-limit-body",children:e.body})]})]}),a&&Z("p",{className:"sc-error",children:a}),i&&u.note&&Z("p",{className:"sc-limit-note",children:u.note}),Rt("div",{className:"sc-limit-actions",children:[t&&Z("button",{type:"button",className:"sc-btn sc-btn-quiet",onClick:t,disabled:o,children:"Not now"}),e.upgradeTo&&Z("button",{type:"button",className:l?"sc-btn":"sc-btn sc-btn-primary",onClick:()=>void p(),disabled:o,children:o?"Opening\u2026":e.upgradeTo.selectable?`Switch to ${e.upgradeTo.name}`:`${e.upgradeTo.name} for $${e.upgradeTo.price.toLocaleString()}/${e.upgradeTo.interval}`}),l&&Z("button",{type:"button",className:i?"sc-btn":"sc-btn sc-btn-primary",onClick:e.connect,disabled:o,children:i?"Connect another machine":"Connect compute"}),i&&Z("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:u.open,disabled:o,children:"Open Soba App"})]})]})}import{useMemo as ri}from"react";function it(){let{plan:e,compute:n,connect:t}=D();return ri(()=>{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=ai(o?.trial_ends_at??null),c=r.connected_reward==="included"&&n.connected&&r.connected_included_units!==null,i=c?r.connected_included_units:r.included_units,l=r.connected_reward==="unlimited"&&n.connected,u=i===null,p=e.used??0,y=i===null?null:Math.max(0,i-p),f=i&&i>0?Math.min(100,Math.round(p/i*100)):null,m=i!==null&&p>=i,w=a!==null?"trial":u?"unlimited":m?r.overage==="meter"?"metered":"spent":"within";return{...s,state:w,trialDaysLeft:a,ceiling:i,raised:c,uncounted:l,used:p,remaining:y,percent:f,unlimited:u,reward:oi(r,c||l,n.connected,()=>t.open("manual")),summary:si({plan:r,assignment:o,used:p,ceiling:i,trialDaysLeft:a,raised:c,uncounted:l,state:w})}},[e,n.connected,t])}function oi(e,n,t,r){let o=Ue({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:He(e.connected_reward)&&!t,open:r}:Se(e.route_allow)&&!t?{line:"Nothing connected yet, so nothing can run.",inForce:!1,required:!0,connected:t,actionable:!0,open:r}:null}function si(e){let{plan:n,assignment:t,used:r,ceiling:o,trialDaysLeft:s,raised:a,uncounted:c,state:i}=e,l=`${n.unit}${r===1?"":"s"}`,u=c?" Runs your own AI serves do not count toward it.":"";if(i==="trial"&&s!==null){let f=n.price===0?"it continues free":`it is $${n.price.toLocaleString()} a ${n.interval}`;return`${s} ${s===1?"day":"days"} left of your trial, then ${f}.`}if(i==="unlimited")return`${r.toLocaleString()} ${l} this period. No ceiling on this plan.`;if(i==="metered"){let f=r-(o??0);return n.overage_per_unit>0?`${f.toLocaleString()} past the allowance, billed at $${n.overage_per_unit} a ${n.unit}.${u}`:`${f.toLocaleString()} past the allowance.${u}`}if(i==="spent")return t?.period_end?`Allowance spent. It comes back on ${Go(t.period_end)}.${u}`:`Allowance spent. It comes back at the start of the next period.${u}`;let p=Math.max(0,(o??0)-r),y=a?` Raised from ${(n.included_units??0).toLocaleString()} while your own AI is connected.`:t?.period_end?` Resets ${Go(t.period_end)}.`:"";return`${p.toLocaleString()} of ${(o??0).toLocaleString()} ${n.unit}s left.${y}${u}`}function ai(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 Go(e){let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{day:"numeric",month:"long"})}import{Fragment as li,jsx as J,jsxs as Me}from"react/jsx-runtime";function qr({heading:e="Current plan",showUsage:n=!0,showName:t=!0,className:r}){let o=it(),{theme:s}=H(),a=y=>J("section",{className:r?`soba-connect sc-fill ${r}`:"soba-connect sc-fill","data-theme":s,children:Me("div",{className:"sc-card sc-current",children:[e&&J("h2",{className:"sc-section-title",children:e}),y]})});if(o.error)return a(J("p",{className:"sc-error",children:o.error.message}));if(o.loading)return a(J("p",{className:"sc-note",children:"Loading\u2026"}));if(!o.plan)return a(Me("div",{className:"sc-current-main",children:[J("p",{className:"sc-current-name",children:"No plan"}),J("p",{className:"sc-sub",children:o.summary})]}));let{plan:c,trialDaysLeft:i,percent:l,unlimited:u,reward:p}=o;return a(Me(li,{children:[Me("div",{className:"sc-current-grid",children:[(t||i!==null)&&Me("div",{className:"sc-current-main",children:[t?Me("p",{className:"sc-current-name",children:[c.name,i!==null&&Me("span",{className:"sc-trial-badge",children:[i," ",i===1?"day":"days"," left"]})]}):i!==null&&J("p",{className:"sc-current-trial",children:Me("span",{className:"sc-trial-badge",children:[i," ",i===1?"day":"days"," left"]})}),t&&c.description&&J("p",{className:"sc-sub",children:c.description})]}),n&&Me("div",{className:"sc-usage",children:[Me("div",{className:"sc-row-between",children:[J("span",{className:"sc-fact-key",children:"Usage"}),J("span",{className:l!==null&&l>=100?"sc-usage-figure sc-usage-over":"sc-usage-figure",children:u?"Unlimited":l===null?"Metered":`${l}% used`})]}),l!==null&&J("div",{className:"sc-meter",role:"presentation",children:l>0&&J("span",{className:l>=100?"sc-meter-fill sc-meter-full":"sc-meter-fill",style:{width:`${l}%`}})}),J("p",{className:"sc-usage-line",children:o.summary})]})]}),p&&Me("div",{className:"sc-current-foot",children:[J("p",{className:p.required?"sc-plan-reward-line sc-plan-reward-need":p.inForce?"sc-plan-reward-line":"sc-plan-reward-line sc-plan-reward-open",children:p.required?p.line:p.inForce?`In force: ${ii(p.line)}.`:p.line}),(p.actionable||p.connected)&&J(fn,{})]})]}))}var ii=e=>e.charAt(0).toLowerCase()+e.slice(1);import{useCallback as ci,useMemo as ui,useState as zo}from"react";var di={"user-hardware":"your own machine","user-subscription":"your own AI subscription","open-weights":"open models we host",frontier:"frontier models"},pi=new Set(["user-hardware","user-subscription"]);function Fr(e={}){let{plan:n,compute:t,connect:r}=D(),[o,s]=zo(null),[a,c]=zo(null),{featured:i,onSelect:l,successUrl:u,cancelUrl:p}=e,y=ci(async m=>{s(m.id),c(null);try{if(m.selectable)await n.select(m.id);else if(l)l(m);else{let w=await n.checkout(m.id,{...u?{successUrl:u}:{},...p?{cancelUrl:p}:{}});window.location.assign(w);return}}catch(w){throw c(w.message),w}finally{(m.selectable||l)&&s(null)}},[n,l,u,p]),f=ui(()=>n.plans.map(m=>{let w=n.current?.plan_id===m.id;return{plan:m,current:w,featured:i===m.id&&!w,price:mi(m),allowance:m.included_units===null?`Unlimited ${m.unit}s`:`${m.included_units.toLocaleString()} ${m.unit}${m.included_units===1?"":"s"}`,allowanceNote:fi(m),computeLabel:m.route_allow===null?"any compute":m.route_allow.length===0?"no compute":null,compute:(m.route_allow??[]).map(M=>({costClass:M,label:di[M]??M,owned:pi.has(M),runtimes:Bt(M).map(R=>R.id)})),connect:hi(m,w,t.connected,()=>r.open("manual")),cta:{label:gi(m,w,o===m.id),disabled:w||o!==null,busy:o===m.id,take:()=>y(m)}}}),[n.plans,n.current,i,t.connected,r,o,y]);return{offers:f,current:f.find(m=>m.current)??null,loading:n.loading,error:n.error,failed:a}}function mi(e){return e.price===0?{amount:"Free",interval:null,free:!0}:{amount:`$${e.price.toLocaleString()}`,interval:e.interval,free:!1}}function fi(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 hi(e,n,t,r){let o=Ue({unit:e.unit,reward:e.connected_reward,includedUnits:e.connected_included_units,creditMicros:e.connected_credit*1e6}),s=Se(e.route_allow)&&!t;if(!o&&!s)return null;let a=He(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 gi(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 b,jsxs as A}from"react/jsx-runtime";function _t(e){return e?`soba-connect sc-fill ${e}`:"soba-connect sc-fill"}function Gr({onSelect:e,successUrl:n,cancelUrl:t,showCompute:r=!0,showConnect:o=!1,variant:s="cards",featured:a,className:c}){let{offers:i,loading:l,error:u,failed:p}=Fr({...a?{featured:a}:{},...e?{onSelect:e}:{},...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}}),{theme:y}=H();if(u)return b("div",{className:_t(c),"data-theme":y,children:b("div",{className:"sc-card",children:b("p",{className:"sc-error",children:u.message})})});if(l)return b("div",{className:_t(c),"data-theme":y,children:b("div",{className:"sc-card",children:b("p",{className:"sc-note",children:"Loading plans\u2026"})})});if(i.length===0)return b("div",{className:_t(c),"data-theme":y,children:b("div",{className:"sc-card",children:b("p",{className:"sc-note",children:"This app has no plans yet."})})});let f={showCompute:r,showConnect:o};return A("div",{className:_t(c),"data-theme":y,"data-variant":s,children:[s==="rows"?b(yi,{offers:i,shelf:f}):s==="table"?b(wi,{offers:i,shelf:f}):b(bi,{offers:i,shelf:f}),p&&b("p",{className:"sc-error",children:p})]})}function bi({offers:e,shelf:n}){return b("div",{className:"sc-plans",children:e.map(t=>A("div",{className:Vo("sc-plan",t),children:[A("div",{className:"sc-row-between",children:[b("span",{className:"sc-title",children:t.plan.name}),b(zr,{offer:t})]}),b("p",{className:"sc-sub",children:t.plan.description}),b(Vr,{price:t.price,free:"forever"}),b(Yr,{offer:t,shelf:n}),b(Ko,{offer:t}),b("div",{className:"sc-plan-band",children:n.showCompute&&b(jr,{offer:t})}),b("div",{className:"sc-plan-band",children:b(Kr,{offer:t})})]},t.plan.id))})}function yi({offers:e,shelf:n}){return b("ul",{className:"sc-plan-rows",children:e.map(t=>A("li",{className:Vo("sc-plan-row",t),children:[A("div",{className:"sc-row-main",children:[A("span",{className:"sc-row-name",children:[b("span",{className:"sc-title",children:t.plan.name}),b(zr,{offer:t})]}),t.plan.description&&b("p",{className:"sc-sub",children:t.plan.description}),b(Ko,{offer:t}),n.showCompute&&b(jr,{offer:t,inline:!0}),b(Kr,{offer:t,inline:!0})]}),A("div",{className:"sc-row-side",children:[b(Vr,{price:t.price,free:"forever",small:!0}),b(Yr,{offer:t,shelf:n})]})]},t.plan.id))})}function wi({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 b("div",{className:"sc-table-scroll",children:A("table",{className:"sc-plan-table",children:[b("thead",{children:A("tr",{children:[b("td",{}),e.map(a=>A("th",{scope:"col",className:s(a),children:[A("span",{className:"sc-row-name",children:[b("span",{className:"sc-title",children:a.plan.name}),b(zr,{offer:a})]}),b(Vr,{price:a.price,small:!0})]},a.plan.id))]})}),A("tbody",{children:[A("tr",{children:[b("th",{scope:"row",children:"Included"}),e.map(a=>b("td",{className:s(a),children:a.allowance},a.plan.id))]}),t&&A("tr",{children:[b("th",{scope:"row",children:"Then"}),e.map(a=>b("td",{className:s(a),children:a.plan.overage_per_unit>0?`$${a.plan.overage_per_unit} / ${a.plan.unit}`:b("span",{className:"sc-muted-cell",children:"Stops"})},a.plan.id))]}),r&&A("tr",{children:[b("th",{scope:"row",children:"Trial"}),e.map(a=>b("td",{className:s(a),children:a.plan.trial_days>0?`${a.plan.trial_days} days`:b("span",{className:"sc-muted-cell",children:"None"})},a.plan.id))]}),n.showCompute&&A("tr",{children:[b("th",{scope:"row",children:"Runs on"}),e.map(a=>b("td",{className:s(a),children:b(jr,{offer:a,bare:!0})},a.plan.id))]}),o&&A("tr",{children:[b("th",{scope:"row",children:"Connect your own"}),e.map(a=>b("td",{className:s(a),children:b(Kr,{offer:a,bare:!0})},a.plan.id))]}),A("tr",{className:"sc-table-buy",children:[b("td",{}),e.map(a=>b("td",{className:s(a),children:b(Yr,{offer:a,shelf:n})},a.plan.id))]})]})]})})}function Vo(e,n){return[e,n.current?"sc-plan-current":"",n.featured?"sc-plan-featured":""].filter(Boolean).join(" ")}function zr({offer:e}){return e.current?b("span",{className:"sc-plan-badge",children:"Current"}):e.featured?b("span",{className:"sc-plan-badge-soft",children:"Recommended"}):null}function Vr({price:e,small:n,free:t}){return A("p",{className:n?"sc-plan-price sc-plan-price-sm":"sc-plan-price",children:[b("span",{className:"sc-plan-amount",children:e.amount}),e.interval?A("span",{className:"sc-plan-interval",children:["/",e.interval]}):t&&b("span",{className:"sc-plan-interval sc-plan-after",children:t})]})}function Ko({offer:e}){return A("p",{className:"sc-plan-allowance",children:[b("span",{className:"sc-plan-figure",children:e.allowance}),b("span",{className:"sc-plan-qualifier",children:e.allowanceNote})]})}function Kr({offer:e,inline:n,bare:t}){let r=e.connect;if(!r)return t?b("span",{className:"sc-muted-cell",children:"None"}):null;let o=r.reward?"sc-plan-reward-line":"sc-plan-reward-line sc-plan-reward-need",s=r.actionable?A("button",{type:"button",className:`${o} sc-plan-reward-act`,"aria-label":"Connect compute",onClick:r.open,children:[b("span",{className:"sc-reward-said",children:r.line}),A("span",{className:"sc-reward-do","aria-hidden":!0,children:[b(j,{className:"sc-reward-mark"}),"Connect compute"]})]}):b("p",{className:o,children:r.line});return t?s:b("div",{className:n?"sc-plan-reward sc-plan-reward-inline":"sc-plan-reward",children:s})}function jr({offer:e,inline:n,bare:t}){let r=e.computeLabel?b("ul",{className:n?"sc-compute sc-compute-inline":"sc-compute",children:b("li",{children:e.computeLabel})}):b("ul",{className:n?"sc-compute sc-compute-inline":"sc-compute",children:e.compute.map(o=>A("li",{className:o.owned?"sc-compute-own":void 0,children:[o.label,b(vi,{runtimes:o.runtimes})]},o.costClass))});return t?r:A("div",{className:n?"sc-plan-compute sc-plan-compute-inline":"sc-plan-compute",children:[b("span",{className:"sc-fact-key",children:"Runs on"}),r]})}function Yr({offer:e,shelf:n}){let t=e.connect;return n.showConnect&&t?.actionable?A("button",{type:"button",className:"sc-btn sc-btn-primary sc-btn-icon",onClick:t.open,children:[b(j,{className:"sc-btn-mark"}),"Connect compute"]}):b("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 vi({runtimes:e}){return e.length===0?null:b("span",{className:"sc-compute-marks",children:e.map(n=>{let t=ze[n];return t?b(t,{className:"sc-rt-mark"},n):null})})}import{jsx as Zr,jsxs as jo}from"react/jsx-runtime";function ki({heading:e,plansHeading:n,showUsage:t=!0,showName:r=!0,className:o,...s}){let{plan:a,loading:c}=it(),{theme:i}=H(),l=n??(c?"Plans":a?"Change plan":"Choose a plan");return jo("div",{className:o?`soba-connect sc-fill sc-billing ${o}`:"soba-connect sc-fill sc-billing","data-theme":i,children:[Zr(qr,{...e===void 0?{}:{heading:e},showUsage:t,showName:r}),jo("section",{className:"sc-billing-plans",children:[l&&Zr("h2",{className:"sc-section-title",children:l}),Zr(Gr,{...s})]})]})}import{useCallback as Yo,useState as Zo}from"react";function Jr({plan:e,successUrl:n,cancelUrl:t,label:r}){let{plan:o}=D(),[s,a]=Zo(!1),[c,i]=Zo(null),l=Yo(()=>o.checkout(e.id,{...n?{successUrl:n}:{},...t?{cancelUrl:t}:{}}),[o,e.id,n,t]),u=Yo(async()=>{a(!0),i(null);try{window.location.assign(await l())}catch(p){i(p.message),a(!1)}},[l]);return{label:s?"Opening\u2026":r??`Subscribe for $${e.price.toLocaleString()}/${e.interval}`,busy:s,error:c,buy:u,session:l}}import{jsx as Jo,jsxs as Ni}from"react/jsx-runtime";function Ci({plan:e,successUrl:n,cancelUrl:t,label:r,className:o}){let{theme:s}=H(),a=Jr({plan:e,...n?{successUrl:n}:{},...t?{cancelUrl:t}:{},...r?{label:r}:{}});return Ni("div",{className:o?`soba-connect ${o}`:"soba-connect","data-theme":s,children:[Jo("button",{type:"button",className:"sc-btn sc-btn-primary",disabled:a.busy,onClick:()=>void a.buy(),children:a.label}),a.error&&Jo("p",{className:"sc-error",children:a.error})]})}import{useCallback as Te,useEffect as Ze,useMemo as In,useRef as Je,useState as Q}from"react";var xi="soba.session:";function Qo(e){return!e.cacheKey||!e.endpoint?null:xi+JSON.stringify([e.endpoint,e.user??null,e.cacheKey])}function Si(e){try{let n=globalThis.localStorage?.getItem(e);if(!n)return null;let t=JSON.parse(n);return typeof t.token!="string"||typeof t.expiresAt!="number"?null:{token:t.token,expiresAt:t.expiresAt}}catch{return null}}function Mi(e,n){try{n?globalThis.localStorage?.setItem(e,JSON.stringify(n)):globalThis.localStorage?.removeItem(e)}catch{}}var Xo=6e4,Pi=1e4,Et=class{#e;#n=null;#r=null;#t;#o=new Set;constructor(n){this.#t=n,this.#e=n.token??null;let t=Qo(n),r=t&&!this.#e?Si(t):null;r&&r.expiresAt-Xo>Date.now()&&(this.#e=r.token,this.#n=r.expiresAt)}get token(){return this.#e}get expiresAt(){return this.#n}get canRefresh(){return!!this.#t.endpoint}get refreshAt(){return!this.canRefresh||this.#n===null?null:Math.max(Date.now()+Pi,this.#n-Xo)}subscribe(n){return this.#o.add(n),()=>this.#o.delete(n)}async ensure(){return this.#e?this.#e:this.refresh()}async refresh(){if(this.#r)return this.#r;let n=this.#t.endpoint;if(!n)throw new Error("This Soba session cannot be refreshed. Pass `sessionEndpoint` so the provider can mint a new one.");let t=this.#t.fetchImpl??fetch.bind(globalThis);this.#r=(async()=>{let r=await t(n,{method:"POST",headers:{"content-type":"application/json"},credentials:"same-origin",body:JSON.stringify(this.#t.user?{user:this.#t.user}:{})});if(!r.ok)throw new Error(`Could not start a Soba session (${r.status} from ${n}).`);let o=await r.json(),s=o.session??o.token;if(!s)throw new Error(`${n} answered without a \`session\`. See @soba-so/react's README.`);let a=o.expires_in??o.expiresIn;this.#e=s,this.#n=typeof a=="number"?Date.now()+a*1e3:null;let c=Qo(this.#t);c&&Mi(c,this.#n===null?null:{token:s,expiresAt:this.#n});for(let i of this.#o)i();return s})();try{return await this.#r}finally{this.#r=null}}},On=new Map,es=new WeakMap,Ri=1;function _i(e){if(e.token||!e.endpoint)return null;let n=0;return e.fetchImpl&&(n=es.get(e.fetchImpl)??Ri++,es.set(e.fetchImpl,n)),JSON.stringify([e.endpoint,e.user??null,n,e.cacheKey??null])}function ns(e){let n=_i(e);if(!n)return new Et(e);let t=On.get(n)??{holder:new Et(e),users:0};return On.set(n,t),t.holder}function ts(e){for(let n of On.values())n.holder===e&&n.users++}function rs(e){for(let[n,t]of On)if(t.holder===e){setTimeout(()=>{--t.users<=0&&On.get(n)===t&&On.delete(n)},0);return}}function os(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,Ei(r,s))}}function Ei(e,n){let t=new Headers(e?.headers);return t.set("authorization",`Bearer ${n}`),{...e,headers:t}}import{jsx as Qr,jsxs as Li}from"react/jsx-runtime";var Oi="https://www.soba.so",Ii=3e4;function Ti(e){let{children:n,session:t,sessionEndpoint:r,user:o,sessionCacheKey:s,runEndpoint:a,theme:c,initialMachines:i,initialConnect:l=null,initialPlans:u,initialCurrentPlan:p=null,baseUrl:y=Oi,pollMs:f=Ii,injectStyles:m=!0,modal:w=!0,fetchImpl:M,onError:R}=e,[_,U]=Q(t??null),[P,T]=Q(null),[E,S]=Q(l),[W,ve]=Q(null),[X,ke]=Q(l===null),[V,oe]=Q(i??[]),[We,Y]=Q(null),[Pe,Qe]=Q(i===void 0),[ce,ue]=Q(u??[]),[ee,gn]=Q(p),[Xe,Le]=Q(null),[en,de]=Q(u===void 0),[ne,Be]=Q(null),[pe,Ae]=Q(!1),qe=Je(R);qe.current=R;let se=Te(k=>{T(k),qe.current?.(k)},[]);Ze(()=>{m&&st()},[m]);let O=In(()=>ns({...t?{token:t}:{},...r?{endpoint:r}:{},...o?{user:o}:{},...M?{fetchImpl:M}:{},...s?{cacheKey:s}:{}}),[t,r,o,M,s]);Ze(()=>{let k=!0;ts(O);let z=O.subscribe(()=>{k&&U(O.token)});return!O.token&&!O.canRefresh?se(new Error("<SobaProvider> needs a `session` or a `sessionEndpoint`. A browser cannot mint one: that takes your secret key.")):O.ensure().then(()=>k&&U(O.token),ae=>k&&se(ae)),()=>{k=!1,z(),rs(O)}},[O,se]),Ze(()=>{P&&(ke(!1),Qe(!1),de(!1),ve(k=>k??P),Y(k=>k??P),Le(k=>k??P))},[P]),Ze(()=>{let k=O.refreshAt;if(k===null)return;let z=()=>{O.refresh().catch(ge=>se(ge))},ae=()=>{document.hidden||(document.removeEventListener("visibilitychange",ae),z())},pt=setTimeout(()=>{typeof document<"u"&&document.hidden?document.addEventListener("visibilitychange",ae):z()},Math.max(0,k-Date.now()));return()=>{clearTimeout(pt),typeof document<"u"&&document.removeEventListener("visibilitychange",ae)}},[O,se,_]);let bn=Je(l?.machines_url??null),v=In(()=>{if(!_)return null;let k=new Ln({session:_,baseUrl:y,fetchImpl:os(O,M??fetch.bind(globalThis))});return k.setMachinesUrl(bn.current),k},[_,y,O,M]),F=Je(l!==null);Ze(()=>{if(!v||F.current)return;let k=!0;return ke(!0),v.context().then(z=>{k&&(S(z),ve(null),ke(!1))},z=>{k&&(ve(z),ke(!1))}),()=>{k=!1}},[v]);let me=Te(async()=>{if(v)try{let k=await v.machines();oe(Array.isArray(k)?k:[]),Y(null)}catch(k){Y(k)}finally{Qe(!1)}},[v]),fe=Te(async()=>{if(v)try{let k=await v.plans();ue(k.plans),gn(k.current),Le(null)}catch(k){Le(k)}finally{de(!1)}},[v]),te=Je(!1),[Fe,yn]=Q(!1),wn=Je(u!==void 0),nn=Je(!1),tn=Te(()=>{te.current||(te.current=!0,nn.current&&queueMicrotask(()=>{nn.current&&yn(!0)}))},[]);Ze(()=>(nn.current=!0,te.current&&yn(!0),()=>{nn.current=!1}),[]),Ze(()=>{!v||!Fe||wn.current||fe()},[v,Fe,fe]);let rn=Te(async k=>{if(!v)throw new Error("No session yet.");await v.selectPlan(k),await fe()},[v,fe]),Ot=Te(async(k,z)=>{if(!v)throw new Error("No session yet.");let ae=await v.checkoutPlan(k,z);if(!ae.url)throw new Error("Checkout could not be started.");return ae.url},[v]),lt=Te(async()=>{if(!v)throw new Error("No session yet.");await v.leavePlan(),await fe()},[v,fe]),ct=Je(i!==void 0);Ze(()=>{if(!v)return;let k=Oe(me,f,{immediate:!ct.current});return ct.current=!1,k},[v,me,f]);let vn=Te((k="manual")=>{w&&(Ae(!0),Be(k))},[w]),ut=Te(()=>Be(null),[]),G=Je(V);G.current=V;let Re=Te(async k=>{if(!a)throw new Error("Pass `runEndpoint` to <SobaProvider> to start runs from the browser. It is your own route: it holds your secret key, calls soba.run(), and forwards the stream.");let{signal:z,...ae}=k,ge=await(M??fetch.bind(globalThis))(a,{method:"POST",headers:{"content-type":"application/json",accept:"text/event-stream"},credentials:"same-origin",body:JSON.stringify(ae),...z?{signal:z}:{}});if(!ge.ok){let $e=await ge.json().catch(()=>null),be=new Error($e?.error?.message??`${a} answered ${ge.status}.`);be.status=ge.status,$e?.error?.code&&(be.code=$e.error.code),$e?.error&&(be.error=$e.error);let mt=G.current.length>0&&!G.current.some(Tt=>Tt.state!=="offline");throw ge.status===409&&mt&&vn("no_compute"),be}let Ce=Ur(ge);return async function*(){try{yield*Ce}finally{te.current&&fe()}}()},[a,M,fe,vn]),he=In(()=>ee?ce.find(k=>k.id===ee.plan_id)??null:null,[ce,ee]),on=In(()=>he?he.connected_reward==="included"&&V.length>0&&he.connected_included_units!==null?he.connected_included_units:he.included_units:null,[he,V]),dt=In(()=>({plans:ce,current:ee,plan:he,used:ee?.units_used??null,included:on,remaining:on!==null&&ee?Math.max(0,on-ee.units_used):null,unlimited:he!==null&&on===null,loading:en,error:Xe,select:rn,checkout:Ot,leave:lt,refresh:fe}),[ce,ee,he,on,en,Xe,rn,Ot,lt,fe]),It=In(()=>({session:_,client:v,error:P,get plan(){return tn(),dt},compute:{machines:V,connected:V.length>0,online:V.some(k=>k.state!=="offline"),loading:Pe,error:We,refresh:me},connect:{app:E?.app??null,command:E?.command??null,connectUrl:E?.connect_url??null,publishableKey:E?.publishable_key??null,loading:X,error:W,open:vn,close:ut,isOpen:ne!==null,hasModal:w},run:Re}),[_,v,P,dt,tn,ne,vn,ut,w,V,Pe,We,me,E,X,W,Re]);return Qr(Mr.Provider,{value:v,children:Qr(Pr.Provider,{value:{context:E,machines:Pe?void 0:V,theme:c??E?.theme??"light"},children:Li(Rr.Provider,{value:It,children:[n,w&&pe&&Qr(nt,{open:ne!==null,onOpenChange:k=>Be(k?ne??"manual":null),onConnected:()=>{me()},...ne==="payment_required"||ne==="no_compute"?{reason:ne}:{},...ne==="pair"?{showStatus:!1}:{}})]})})})}function Ai(e){return e?$i[e]??e:null}var $i={"user-hardware":"your own computer","user-subscription":"your own AI plan","user-api-key":"your own API key","open-weights":"open models we host",frontier:"a frontier model we pay for"};async function Di(e,n,t){let r=n.local;if(!r?.session||n.after)return null;let o=/\/v1\/runs\/([^/]+)\/events/.exec(e.url)?.[1];if(!o)return null;let s=`http://127.0.0.1:${r.port??47321}/v1/runs/${o}/events`,a=new AbortController,c=()=>a.abort();n.signal?.addEventListener("abort",c);let i=setTimeout(()=>a.abort(),r.timeoutMs??3e3);try{let l=await t(s,{headers:{authorization:`Bearer ${r.session}`,accept:"text/event-stream"},signal:a.signal});return l.ok?{url:s,bearer:r.session,open:l}:null}catch{return null}finally{clearTimeout(i),n.signal?.removeEventListener("abort",c)}}async function*Ui(e){let n=e.body;if(!n)return;let t=n.getReader(),r=new TextDecoder,o="",s=null,a=[];try{for(;;){let c=await t.read();if(c.done)return;o+=r.decode(c.value,{stream:!0});for(let i=o.indexOf(`
|
|
3011
3017
|
`);i!==-1;i=o.indexOf(`
|
|
3012
3018
|
`)){let l=o.slice(0,i).replace(/\r$/,"");if(o=o.slice(i+1),l==="")a.length&&(yield{id:s,data:a.join(`
|
|
3013
|
-
`)}),s=null,a=[];else if(l.startsWith("id:")){let u=Number(l.slice(3).trim());s=Number.isFinite(u)?u:null}else if(l.startsWith("data:")){let u=l.slice(5);a.push(u.startsWith(" ")?u.slice(1):u)}}}}finally{t.cancel().catch(()=>{})}}var
|
|
3019
|
+
`)}),s=null,a=[];else if(l.startsWith("id:")){let u=Number(l.slice(3).trim());s=Number.isFinite(u)?u:null}else if(l.startsWith("data:")){let u=l.slice(5);a.push(u.startsWith(" ")?u.slice(1):u)}}}}finally{t.cancel().catch(()=>{})}}var Xr=(e,n)=>new Promise(t=>{let r=setTimeout(t,e);n?.addEventListener("abort",()=>{clearTimeout(r),t()})});async function*Hi(e,n={}){let t=n.fetchImpl??fetch.bind(globalThis),r=await Di(e,n,t)??{url:e.url,bearer:e.token,open:null},o=n.maxRetries??6,s=n.after??0,a=0;for(;;){if(n.signal?.aborted)return;let c;try{c=r.open??await t(r.url,{headers:{authorization:`Bearer ${r.bearer}`,accept:"text/event-stream",...s?{"last-event-id":String(s)}:{}},...n.signal?{signal:n.signal}:{}}),r.open=null}catch(i){if(n.signal?.aborted)return;if(++a>o)throw i;await Xr(1e3*a,n.signal);continue}if(c.status===503&&a<o){a++,await Xr(Number(c.headers.get("retry-after")??3)*1e3,n.signal);continue}if(!c.ok){let i=`Could not read this run (${c.status}).`;try{let l=await c.json();l.error?.message&&(i=l.error.message)}catch{}throw new Error(i)}for await(let i of Ui(c)){i.id!==null&&(s=i.id),a=0;let l=En(i.data);if(l&&(yield l,l.type==="done"||l.type==="error"))return}if(n.signal?.aborted)return;if(++a>o)throw new Error("Lost this run's stream and could not get it back.");await Xr(1e3*a,n.signal)}}export{ya as ComputeStatus,fn as ConnectButton,Ma as ConnectCompute,nt as ConnectModal,Ba as ConnectNudge,Ya as ModelPicker,Qa as RunError,ni as RunLimit,ki as SobaBilling,Ci as SobaCheckout,qr as SobaCurrentPlan,Gr as SobaPlans,Ti as SobaProvider,Va as collectText,Pt as connectSays,st as injectStyles,En as parseEvent,Ur as readEvents,qo as runErrorMessage,hn as sobaErrorCode,Ai as tierLabel,Jr as useCheckout,Xn as useCompute,ka as useConnectButton,Dr as useConnectNudge,it as useCurrentPlan,Er as useMachineRuns,Br as useModel,ot as useOpenSobaConnect,Fr as usePlans,Ar as useRunLimit,D as useSoba,Hi as watchRun};
|
package/dist/styles.css
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -35,6 +35,29 @@ export interface Runtime {
|
|
|
35
35
|
quarantined?: boolean;
|
|
36
36
|
first_seen_at?: string;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* ONE RUN ON ONE OF THIS PERSON'S MACHINES, for this app — a row of "Running
|
|
40
|
+
* now". `label` is the app's own name for it (`metadata.label`), `task` its
|
|
41
|
+
* category; `step` the last thing it said it was doing, `phase` what its latest
|
|
42
|
+
* frame was. `machine_id` is null while it waits for a free slot.
|
|
43
|
+
*/
|
|
44
|
+
export interface MachineRun {
|
|
45
|
+
id: string;
|
|
46
|
+
machine_id: string | null;
|
|
47
|
+
status: "queued" | "running";
|
|
48
|
+
label: string | null;
|
|
49
|
+
task: string | null;
|
|
50
|
+
runtime_id: string | null;
|
|
51
|
+
model: string | null;
|
|
52
|
+
cost_class: string | null;
|
|
53
|
+
started_at: string;
|
|
54
|
+
first_output_at: string | null;
|
|
55
|
+
step: string | null;
|
|
56
|
+
phase: {
|
|
57
|
+
kind: "thinking" | "writing" | "tool" | "approval" | "starting";
|
|
58
|
+
tool?: string;
|
|
59
|
+
} | null;
|
|
60
|
+
}
|
|
38
61
|
export interface Machine {
|
|
39
62
|
id: string;
|
|
40
63
|
label: string | null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { MachineRun } from "./types.js";
|
|
2
|
+
export interface MachineRunsOptions {
|
|
3
|
+
/** Read only while true — a list somebody has open. Default true. */
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
/** How often to read it again. Default 3s: a run's step changes on nearly every read. */
|
|
6
|
+
intervalMs?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface MachineRunsView {
|
|
9
|
+
/** This app's runs on this person's machines. `null` until the first read. */
|
|
10
|
+
runs: MachineRun[] | null;
|
|
11
|
+
refresh: () => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Stop one, as the person whose machine it is on — no app server involved.
|
|
14
|
+
* The app reading that run sees it end with `reason: "stopped_by_user"`.
|
|
15
|
+
* Rejects with the gateway's message when it could not be stopped.
|
|
16
|
+
*/
|
|
17
|
+
stop: (runId: string) => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* WHAT THIS PERSON'S MACHINES ARE RUNNING FOR THIS APP, and a way to stop it:
|
|
21
|
+
* the "Running now" list in `<ConnectButton />`'s panel, without the panel.
|
|
22
|
+
* Needs `<SobaProvider>`; outside one, `runs` stays null and `stop` rejects.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useMachineRuns({ enabled, intervalMs }?: MachineRunsOptions): MachineRunsView;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soba-so/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "Connect the AI your users already pay for, from your own React app.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"homepage": "https://soba.so/docs/components",
|
|
@@ -19,18 +19,13 @@
|
|
|
19
19
|
"!dist/**/*.map",
|
|
20
20
|
"README.md"
|
|
21
21
|
],
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "node ../../scripts/build-react.mjs",
|
|
24
|
-
"typecheck": "tsc -p tsconfig.json",
|
|
25
|
-
"prepublishOnly": "node ../../scripts/build-react.mjs"
|
|
26
|
-
},
|
|
27
22
|
"peerDependencies": {
|
|
28
23
|
"react": ">=18"
|
|
29
24
|
},
|
|
30
25
|
"devDependencies": {
|
|
31
|
-
"@soba-so/connect-ui": "workspace:*",
|
|
32
26
|
"@types/react": "^19.0.0",
|
|
33
|
-
"typescript": "^7.0.2"
|
|
27
|
+
"typescript": "^7.0.2",
|
|
28
|
+
"@soba-so/connect-ui": "0.1.0"
|
|
34
29
|
},
|
|
35
30
|
"engines": {
|
|
36
31
|
"node": ">=22"
|
|
@@ -44,5 +39,9 @@
|
|
|
44
39
|
],
|
|
45
40
|
"publishConfig": {
|
|
46
41
|
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "node ../../scripts/build-react.mjs",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
47
46
|
}
|
|
48
|
-
}
|
|
47
|
+
}
|