@soba-so/mcp 0.0.10 → 0.0.12
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/mcp.mjs +246 -525
- package/package.json +1 -1
package/dist/mcp.mjs
CHANGED
|
@@ -1,542 +1,263 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{readFileSync as Pe}from"node:fs";import Oe from"node:os";import fe from"node:path";var
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import{readFileSync as Pe}from"node:fs";import Oe from"node:os";import fe from"node:path";var y=class extends Error{constructor(n,r){super(r);this.status=n;this.name="ApiError"}},x=class{constructor(t,n){this.token=t;this.baseUrl=n;this.kind=t.startsWith("mk_soba_")?"setup":"account"}kind;get(t){return this.call("GET",t)}post(t,n){return this.call("POST",t,n)}patch(t,n){return this.call("PATCH",t,n)}put(t,n){return this.call("PUT",t,n)}delete(t){return this.call("DELETE",t)}async call(t,n,r){let o=await fetch(`${this.baseUrl}${n}`,{method:t,headers:{authorization:`Bearer ${this.token}`,...r===void 0?{}:{"content-type":"application/json"}},body:r===void 0?void 0:JSON.stringify(r)}),s=await o.text(),l=null;try{l=s?JSON.parse(s):null}catch{throw new y(o.status,`${t} ${n} did not return json (${s.slice(0,120)})`)}if(!o.ok){let u=l?.error,h=u?.message??u;throw new y(o.status,typeof h=="string"?h:`${t} ${n} failed with ${o.status}`)}return l}};var Y=36e5,T=24*Y,qe={returnAfterMs:0,expiryMs:30*T,uniquenessMs:365*T},je={returnAfterMs:24*Y,expiryMs:30*T,uniquenessMs:365*T};var Je=10*6e4;var we=864e5,ye=30,nt={abandonedAfterMs:ye*we};var st=30*24*60*60*1e3;var at=5*60*1e3;function E(e){return[{upTo:null,microsPerUnit:e}]}var R={hobby:2.5*1e6,starter:2.4*1e6,growth:2.3*1e6,scale:2.2*1e6},gt=5e3*1e6;var H="lite";var bt=[{id:"hobby",name:"Hobby",feeMicros:19*1e6,includedActivations:20,seatLimit:2,appLimit:3,bands:E(R.hobby),features:["Set your users' free trial: length, usage and features","3 projects","2 seats","Owner and Member roles","Usage dashboard","Docs support"]},{id:"starter",seatLimit:null,appLimit:null,name:"Starter",feeMicros:199*1e6,includedActivations:100,bands:E(R.starter),features:["Unlimited projects","Unlimited seats","Admin and Billing roles","Cohort and conversion attribution","Email support"]},{id:"growth",seatLimit:null,appLimit:null,name:"Growth",feeMicros:599*1e6,includedActivations:400,bands:E(R.growth),features:["Branded approval screen","Window A/B experimentation","Email support, one business day"]},{id:"scale",seatLimit:null,appLimit:null,name:"Scale",feeMicros:1999*1e6,includedActivations:1500,bands:E(R.scale),features:["Custom roles and audit log","Effective-vs-configured window analytics","Shared channel with an SLA"]}];var wt={hobby:["owner","member"],[H]:["owner","member"]};var Et=60*6e4;var ve="https://soba.so/skill",Mt=`npx skills add ${ve}`;var V=`Soba is the LLM layer for an app whose users bring their own AI. The app sends
|
|
3
|
+
its model calls to Soba, naming the signed-in user, and Soba runs each one on
|
|
4
|
+
that user's own Claude, ChatGPT or local model.
|
|
5
|
+
|
|
6
|
+
This file is the whole procedure and it is short on purpose. Read all of it
|
|
7
|
+
yourself before you edit anything: \`curl -s https://soba.so/skill\`. Do not work
|
|
8
|
+
from a summary of it. Each step links a page with the detail; open that page
|
|
9
|
+
when you reach the step.
|
|
10
|
+
|
|
11
|
+
## Rules
|
|
12
|
+
|
|
13
|
+
Every one of these has been broken by an agent that skimmed.
|
|
14
|
+
|
|
15
|
+
1. **Nobody signed in, no Soba call.** Never make up a user: no anonymous,
|
|
16
|
+
cookie, browser, device or per-visit id, not even "for now". Signed-out
|
|
17
|
+
visitors, guests and demo modes stay on the app's own provider and see no
|
|
18
|
+
Soba UI. If the app has no sign-in, stop and ask (rule 6).
|
|
19
|
+
2. **The user is resolved on the server**, from the app's own session, never
|
|
20
|
+
from the request body, a browser-set header or a query string.
|
|
21
|
+
3. **\`SOBA_KEY\` stays on the server.** Never in client code, never in a
|
|
22
|
+
\`NEXT_PUBLIC_\` or \`VITE_\` variable.
|
|
23
|
+
4. **Soba is not one more entry in the app's model list.** Somebody with a
|
|
24
|
+
computer connected runs on it without choosing anything. Step 5 does this.
|
|
25
|
+
5. **Cover every screen that starts a run.** A second interface kept beside
|
|
26
|
+
the main one (a \`/classic\` route, an old UI, a mobile view, an embed) is in
|
|
27
|
+
scope and gets steps 5 to 7 like the first. "Untouched" in your final report
|
|
28
|
+
is this rule broken.
|
|
29
|
+
6. **Ask before you go beyond adding Soba.** Adding sign-in, building a web UI
|
|
30
|
+
the app did not have, removing the app's own provider, or leaving a screen
|
|
31
|
+
out each need the person's yes first. Say what you found, recommend one
|
|
32
|
+
option, and wait. A note in your final report is not asking.
|
|
33
|
+
7. **Use the packages for what they do.** Do not hand-write the session route,
|
|
34
|
+
the choice between Soba's picker and the app's, or the connect prompt.
|
|
35
|
+
8. **It type-checks and builds before you call it done.** If you could not run
|
|
36
|
+
them, say so plainly.
|
|
37
|
+
|
|
38
|
+
## Before you edit
|
|
39
|
+
|
|
40
|
+
Find, and tell the person in a few lines:
|
|
41
|
+
|
|
42
|
+
- every place the app calls a model (a shared client, a route, a raw \`fetch\`);
|
|
43
|
+
- how people sign in, and what on the server says who they are;
|
|
44
|
+
- every control that starts a run, and where its answer appears. Search for
|
|
45
|
+
every caller of each model route and socket: list each interface that has
|
|
46
|
+
one, old ones included;
|
|
47
|
+
- whether it already charges through Stripe: then step 11 is part of adding
|
|
48
|
+
Soba, not an extra;
|
|
49
|
+
- which kind of app this is:
|
|
50
|
+
- **it has its own AI**: connected users run on theirs, everyone else keeps
|
|
51
|
+
the app's models;
|
|
52
|
+
- **it runs only on the user's AI**: nothing runs until they connect.
|
|
53
|
+
|
|
54
|
+
## 1. Install, and the key
|
|
5
55
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
page \u2014 gets the same two halves:
|
|
10
|
-
|
|
11
|
-
1. **The server**: every LLM call goes through Soba as the signed-in user, a
|
|
12
|
-
session route lets the browser act for that user, and Soba's answer
|
|
13
|
-
(including a refusal) reaches the browser intact.
|
|
14
|
-
2. **The browser**: one \`<SobaProvider>\`, and a surface for each moment
|
|
15
|
-
somebody meets their compute \u2014 the settings page, every control that
|
|
16
|
-
starts a run, the place a run's result appears and, when the app's AI only
|
|
17
|
-
works on the user's own compute, the navbar.
|
|
56
|
+
\`\`\`
|
|
57
|
+
npm install @soba-so/react @soba-so/sdk
|
|
58
|
+
\`\`\`
|
|
18
59
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
request succeeds.
|
|
60
|
+
This file needs \`@soba-so/react\` 0.0.45 and \`@soba-so/sdk\` 0.0.30 or newer.
|
|
61
|
+
Check what was installed: a package manager that holds new releases back for a
|
|
62
|
+
day (recent pnpm does) can hand you older ones, without \`sessionRoute\` or
|
|
63
|
+
\`<SobaComposer>\`. Install those versions by number then.
|
|
24
64
|
|
|
25
|
-
|
|
65
|
+
If \`.env.local\` already sets \`SOBA_KEY\`, use it. Otherwise
|
|
66
|
+
\`npx -y @soba-so/cli login --no-link\`, then \`npx -y @soba-so/cli link\`
|
|
67
|
+
(https://soba.so/docs/reference/cli). Tell the person before the login: it
|
|
68
|
+
opens their browser. A development key reaches only the user's own AI.
|
|
26
69
|
|
|
27
|
-
|
|
70
|
+
Then \`npx -y @soba-so/cli plans\`. If the app has no plan, create the free
|
|
71
|
+
"Bring your own" one: \`npx -y @soba-so/cli plans create --template byo\`. It is
|
|
72
|
+
what new users start on, costs the app nothing and needs no asking. Without a
|
|
73
|
+
plan, nobody has one.
|
|
28
74
|
|
|
29
|
-
|
|
30
|
-
apiKey process.env.SOBA_KEY
|
|
75
|
+
## 2. Who the user is
|
|
31
76
|
|
|
32
|
-
|
|
33
|
-
only line that changes. Prompts, tools, streaming and error handling stay
|
|
34
|
-
exactly as they are. Find every call site \u2014 a shared client, a route that
|
|
35
|
-
builds its own, a raw \`fetch\` to the provider's REST API \u2014 and move all of them.
|
|
77
|
+
One helper, used everywhere a user is named:
|
|
36
78
|
|
|
37
|
-
|
|
79
|
+
\`\`\`ts
|
|
80
|
+
import { sobaUserId } from "@soba-so/sdk/identity";
|
|
81
|
+
const user = sobaUserId(stable);
|
|
82
|
+
\`\`\`
|
|
38
83
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
not throw \u2014 it silently pairs runs to the wrong person.
|
|
84
|
+
\`stable\` is the first of these the app has: the subject from a hosted sign-in
|
|
85
|
+
(Supabase, Clerk, Auth0, Google's \`sub\`); a username nobody can change; the
|
|
86
|
+
app's own row id. Never an email people can change. In another language the
|
|
87
|
+
same value is \`"usr_"\` + the first 12 hex characters of the SHA-256 of the
|
|
88
|
+
stable value, trimmed and lower-cased. https://soba.so/docs/identity
|
|
45
89
|
|
|
46
|
-
|
|
47
|
-
at sign-up (an autoincrement, a random UUID) is not: reset the database and the
|
|
48
|
-
same person arrives as somebody new, stranded from the machine they paired. An
|
|
49
|
-
email is not either, if the app lets people change it. \`sobaUserId(stable)\`
|
|
50
|
-
from \`@soba-so/sdk/identity\` turns a stable value \u2014 a username, an auth
|
|
51
|
-
provider's subject \u2014 into the id; use one helper for it and call it everywhere
|
|
52
|
-
the user is named. See \`https://soba.so/docs/identity\`.
|
|
90
|
+
## 3. The session route
|
|
53
91
|
|
|
54
|
-
|
|
92
|
+
Mount it. You answer only who is signed in.
|
|
55
93
|
|
|
56
|
-
|
|
57
|
-
|
|
94
|
+
\`\`\`ts
|
|
95
|
+
// app/api/soba/session/route.ts
|
|
96
|
+
import { sobaUserId } from "@soba-so/sdk/identity";
|
|
97
|
+
import { sessionRoute } from "@soba-so/sdk/server";
|
|
58
98
|
|
|
59
|
-
|
|
60
|
-
|
|
99
|
+
export const POST = sessionRoute({
|
|
100
|
+
user: async (request) => {
|
|
101
|
+
const session = await auth(); // the app's own sign-in
|
|
102
|
+
return session ? sobaUserId(session.user.id) : null; // null: 401
|
|
103
|
+
},
|
|
104
|
+
});
|
|
61
105
|
\`\`\`
|
|
62
106
|
|
|
63
|
-
It
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
107
|
+
It takes a \`Request\` and returns a \`Response\`, so it works in Next.js, Hono,
|
|
108
|
+
Remix, Workers and Bun; in Express, build the \`Request\` from \`req\`. A server
|
|
109
|
+
that is not JavaScript proxies \`POST https://soba.so/v1/end_users/session\` with
|
|
110
|
+
\`Authorization: Bearer $SOBA_KEY\` and \`{ "user": "<id>" }\`, returns the body as
|
|
111
|
+
it came, and answers 401 when signed out.
|
|
68
112
|
|
|
69
|
-
|
|
70
|
-
theirs by workspace. Ask the person which one, or whether to make a new one, and
|
|
71
|
-
do not guess from the names; then link it:
|
|
113
|
+
## 4. The provider
|
|
72
114
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
npx -y @soba-so/cli link --workspace "<workspace>" --new "<name>" # a new app
|
|
76
|
-
\`\`\`
|
|
115
|
+
Around the signed-in part of the app only, never around the login or marketing
|
|
116
|
+
pages:
|
|
77
117
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
Every command is on \`https://soba.so/docs/reference/cli\`.
|
|
83
|
-
|
|
84
|
-
\`.env.local\` is right for Next.js, Vite and most Node servers. Where the code
|
|
85
|
-
that holds the key reads a different file, pass that file with \`--env-file\`
|
|
86
|
-
to \`link\` instead, from the project root, so the key lands where the server
|
|
87
|
-
will look:
|
|
88
|
-
|
|
89
|
-
| Server | File |
|
|
90
|
-
|---|---|
|
|
91
|
-
| Cloudflare Worker (\`wrangler dev\`) | \`--env-file <worker dir>/.dev.vars\` |
|
|
92
|
-
| A server in a subfolder of a monorepo or an extension repo | \`--env-file <server dir>/.env.local\` |
|
|
93
|
-
|
|
94
|
-
Find the file by reading how that server loads its environment, not by its
|
|
95
|
-
framework's reputation. The CLI adds whatever file it writes to \`.gitignore\`
|
|
96
|
-
if git would commit it.
|
|
97
|
-
|
|
98
|
-
On a host that keeps secrets itself \u2014 \`wrangler secret put SOBA_KEY\`, Vercel's
|
|
99
|
-
or Railway's environment \u2014 production takes \`SOBA_PROD_KEY\`'s value under the
|
|
100
|
-
name \`SOBA_KEY\`. That is the person's to paste; tell them the command.
|
|
101
|
-
|
|
102
|
-
A development key reaches only the user's own AI \u2014 their machine, their
|
|
103
|
-
subscription, their API key. In production, \`SOBA_KEY\` is set to the value of
|
|
104
|
-
\`SOBA_PROD_KEY\` in the host's environment; say so to the person rather than
|
|
105
|
-
doing it.
|
|
106
|
-
|
|
107
|
-
If you cannot run commands but have a \`soba_create_key\` tool, call it: the
|
|
108
|
-
secret is returned once and nothing can show it again, so write it into
|
|
109
|
-
\`.env.local\` in the same step. Failing both, ask the person to run the command
|
|
110
|
-
above themselves. Do not leave \`SOBA_KEY\` empty and do not invent a value; both
|
|
111
|
-
fail at the first request, and the first fails as an auth error rather than as
|
|
112
|
-
a missing variable.
|
|
113
|
-
|
|
114
|
-
Put \`SOBA_KEY\` in \`.env.local\` (or the server's own file, above), and check
|
|
115
|
-
that file is gitignored before writing it. Never in \`.env\`, never in
|
|
116
|
-
\`.env.example\`, never in anything tracked, and never echoed back to the terminal.
|
|
117
|
-
|
|
118
|
-
### 3. The session route
|
|
119
|
-
|
|
120
|
-
\`POST /api/soba/session\`, a route in the app that proxies
|
|
121
|
-
\`POST /v1/end_users/session\` with the secret key and the same server-resolved
|
|
122
|
-
user id, and returns the body as it came (\`{ session, expires_in }\`). It is
|
|
123
|
-
what every surface in the browser runs on, and the browser never sees
|
|
124
|
-
\`SOBA_KEY\`. Signed out, it answers 401.
|
|
125
|
-
|
|
126
|
-
### 4. Pass Soba's answer through
|
|
127
|
-
|
|
128
|
-
A refused run is not an outage: \`no_compute\` (409) means nothing the run could
|
|
129
|
-
use is reachable for this user, \`payment_required\` (402) means the plan's
|
|
130
|
-
allowance is spent. The browser surfaces below turn each into the way out \u2014
|
|
131
|
-
connect a machine, or upgrade \u2014 but only if the refusal reaches them with its
|
|
132
|
-
code. So in every route that calls Soba, return Soba's status and \`error\` body
|
|
133
|
-
as they came, instead of letting the client library's exception become a 500 or
|
|
134
|
-
a string:
|
|
135
|
-
|
|
136
|
-
\`\`\`js
|
|
137
|
-
} catch (err) {
|
|
138
|
-
if (err instanceof OpenAI.APIError) {
|
|
139
|
-
return Response.json({ error: err.error }, { status: err.status });
|
|
140
|
-
}
|
|
141
|
-
throw err;
|
|
142
|
-
}
|
|
118
|
+
\`\`\`tsx
|
|
119
|
+
<SobaProvider sessionEndpoint="/api/soba/session" sessionCacheKey={user.id}>
|
|
120
|
+
{children}
|
|
121
|
+
</SobaProvider>
|
|
143
122
|
\`\`\`
|
|
144
123
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
the message.
|
|
124
|
+
If people are signed in with a token and not a cookie (Supabase in the
|
|
125
|
+
browser, Firebase), add
|
|
126
|
+
\`sessionHeaders={() => ({ authorization: "Bearer " + token })}\` and read it in
|
|
127
|
+
step 3. Do not wrap \`fetch\` for this. Light and dark follow the page.
|
|
150
128
|
|
|
151
|
-
|
|
129
|
+
## 5. Every control that starts a run
|
|
152
130
|
|
|
153
|
-
|
|
154
|
-
models. Reaching a user's own Claude or ChatGPT subscription means letting Soba
|
|
155
|
-
own the loop instead:
|
|
131
|
+
**A composer with a model list:**
|
|
156
132
|
|
|
157
|
-
\`\`\`
|
|
158
|
-
|
|
159
|
-
import { sobaUserId } from "@soba-so/sdk/identity";
|
|
133
|
+
\`\`\`tsx
|
|
134
|
+
const soba = useRef<SobaRun | null>(null);
|
|
160
135
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
user: sobaUserId(session.user.username),
|
|
165
|
-
model: "auto",
|
|
166
|
-
prompt: "Summarise everything I saved this week",
|
|
167
|
-
owners: [session.user.accountId], // whose rows this person may read
|
|
168
|
-
tools: [listNotes, readNote], // your code, executed in your app
|
|
169
|
-
});
|
|
136
|
+
<SobaComposer fallback={appModelList} onRun={(run) => (soba.current = run)}>
|
|
137
|
+
{(modelList) => appComposer({ modelList })}
|
|
138
|
+
</SobaComposer>
|
|
170
139
|
\`\`\`
|
|
171
140
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
id so reloads, navigations, tabs and other providers on the page share one
|
|
202
|
-
session. Never in a root layout that also renders the login page or marketing
|
|
203
|
-
pages: there is nobody there to mint a session for. A navbar's provider goes
|
|
204
|
-
in the layout that draws the signed-in navbar. All the components raise the
|
|
205
|
-
same pairing modal \u2014 the provider mounts exactly one, so an app with every
|
|
206
|
-
surface cannot put two pairings on screen at once.
|
|
207
|
-
|
|
208
|
-
| Surface | Component | Hook (for your own markup) |
|
|
209
|
-
|---|---|---|
|
|
210
|
-
| **The settings page** | \`<ComputeSettings />\`, alone | \`useCompute()\` + \`useConnectButton()\` |
|
|
211
|
-
| **Above every control that starts a run** | \`<ConnectNudge />\` | \`useConnectNudge()\` |
|
|
212
|
-
| **Where a run's result appears**, when it failed | \`<RunLimit error={error} />\` then \`<RunError error={error} />\` | \`useRunLimit(error)\` + \`runErrorMessage(error)\` |
|
|
213
|
-
| **The signed-in navbar**, when AI only works on their compute | \`<ConnectButton />\` | \`useConnectButton()\`; its panel from \`useCompute()\` and \`useMachineRuns()\` |
|
|
214
|
-
| **The composer**, in an app with one | \`<ModelPicker />\` beside send | \`useModel()\` |
|
|
215
|
-
| **Billing and pricing** | \`<SobaBilling />\`, or \`<SobaCurrentPlan />\` + \`<SobaPlans />\`, \`<SobaCheckout />\`, \`<RedeemCode />\` | \`useCurrentPlan()\`, \`usePlans()\`, \`useCheckout()\`, \`useRedeemCode()\` |
|
|
216
|
-
| **Anything a plan limits** | \`<SobaGate feature="\u2026" />\` | \`useFeature()\`, plus the server check below |
|
|
217
|
-
|
|
218
|
-
**Required in every app: the first three.** The navbar follows from how the
|
|
219
|
-
app's AI is paid for (below); the composer, billing and gates follow from what
|
|
220
|
-
the app has \u2014 a model choice to offer, plans to sell, features to limit \u2014 and
|
|
221
|
-
the plans themselves are the person's to decide, not yours.
|
|
222
|
-
|
|
223
|
-
What each surface is for, and the mistakes it exists to prevent:
|
|
224
|
-
|
|
225
|
-
- **Navbar, when the AI only works on their compute.** Add \`<ConnectButton />\`
|
|
226
|
-
to the signed-in navbar when nothing can run until a user connects \u2014 a
|
|
227
|
-
bring-your-own plan, a route that only allows their machine or their
|
|
228
|
-
subscription, an app on a development key. There, connecting is a
|
|
229
|
-
prerequisite rather than an offer, so the door belongs on every page: it
|
|
230
|
-
says "Connect compute" until something is attached, then names the machine
|
|
231
|
-
and its state, and once connected it is a pill that opens a popover with the
|
|
232
|
-
machines and what they are running. An app whose runs fall back to compute
|
|
233
|
-
it pays for does not need it; settings, the nudge and the run limit already
|
|
234
|
-
meet the person where connecting matters. Wherever it is used, it lives in
|
|
235
|
-
the header and only there \u2014 a popover pill is wrong inside a page.
|
|
236
|
-
- **Settings.** A settings page is where somebody checks on a machine they
|
|
237
|
-
already attached, not where they decide to attach one. \`<ComputeSettings />\`
|
|
238
|
-
draws it as rows of that page in its own type: each machine, which agent the
|
|
239
|
-
app's runs go to there, and whether it is awake, asleep or serving, with
|
|
240
|
-
"Connect compute" or "Connect another computer". Nothing else from the
|
|
241
|
-
package goes on that page \u2014 \`<ConnectButton />\` or \`<ComputeStatus />\` beside
|
|
242
|
-
it draws the same machine twice. (\`<ConnectCompute />\` is its older name.) If
|
|
243
|
-
there is no settings page, build one, and do not point the connect return URL
|
|
244
|
-
at a page that does not render it.
|
|
245
|
-
- **Above each run-starting control.** Not only a chat composer: every "Tidy",
|
|
246
|
-
"Summarise", "Draft", "Generate", every form that kicks off a job \u2014 find each
|
|
247
|
-
call site from step 1 and the control that triggers it. \`<ConnectNudge />\`
|
|
248
|
-
stands there before anything is pressed and speaks only when it can help:
|
|
249
|
-
nothing connected and nothing else can serve, a paired machine gone quiet, or
|
|
250
|
-
an allowance running down that connecting would lift. It draws nothing
|
|
251
|
-
otherwise.
|
|
252
|
-
- **The result's place.** When a run fails, \`<RunLimit error={error} />\`
|
|
253
|
-
renders where the answer was going to be: for \`no_compute\` the way to connect
|
|
254
|
-
(or wake the machine), for \`payment_required\` the plan to upgrade to. It goes
|
|
255
|
-
quiet by itself once a machine is online, so a refusal from before connecting
|
|
256
|
-
is never shown as the answer to connecting. \`<RunError error={error} />\`
|
|
257
|
-
beside it says every other failure in a sentence; the two never both speak.
|
|
258
|
-
|
|
259
|
-
### One run-starting control, written both ways
|
|
260
|
-
|
|
261
|
-
The same button in any app, as components:
|
|
262
|
-
|
|
263
|
-
\`\`\`jsx
|
|
264
|
-
"use client";
|
|
265
|
-
import { ConnectNudge, RunError, RunLimit } from "@soba-so/react";
|
|
266
|
-
|
|
267
|
-
function TidyButton({ noteId }) {
|
|
268
|
-
const [error, setError] = useState(null);
|
|
269
|
-
|
|
270
|
-
async function tidy() {
|
|
271
|
-
setError(null);
|
|
272
|
-
const res = await fetch("/api/tidy", { method: "POST", body: JSON.stringify({ noteId }) });
|
|
273
|
-
if (!res.ok) return setError(await res.json()); // Soba's body, per step 4
|
|
274
|
-
// \u2026read the result as the app already does
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return (
|
|
278
|
-
<>
|
|
279
|
-
<ConnectNudge />
|
|
280
|
-
<button onClick={tidy}>Tidy</button>
|
|
281
|
-
<RunLimit error={error} />
|
|
282
|
-
<RunError error={error} />
|
|
283
|
-
</>
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
\`\`\`
|
|
287
|
-
|
|
288
|
-
And built from the hooks, in the app's own components (\`Your\u2026\` below stands for
|
|
289
|
-
whatever the app already draws banners, buttons and cards with), saying
|
|
290
|
-
everything the components would:
|
|
291
|
-
|
|
292
|
-
\`\`\`jsx
|
|
293
|
-
import { runErrorMessage, useConnectNudge, useRunLimit } from "@soba-so/react";
|
|
294
|
-
|
|
295
|
-
function TidyButton({ noteId }) {
|
|
296
|
-
const [error, setError] = useState(null);
|
|
297
|
-
const nudge = useConnectNudge(); // before: is anything in the way?
|
|
298
|
-
const limit = useRunLimit(error); // after: the way out of a refusal
|
|
299
|
-
const message = runErrorMessage(error); // after: every other failure
|
|
300
|
-
|
|
301
|
-
return (
|
|
302
|
-
<>
|
|
303
|
-
{nudge.visible && (
|
|
304
|
-
<YourBanner title={nudge.title} detail={nudge.detail} steps={nudge.steps}
|
|
305
|
-
onAction={nudge.open} onDismiss={nudge.dismissible ? nudge.dismiss : undefined} />
|
|
306
|
-
)}
|
|
307
|
-
<YourButton onClick={tidy}>Tidy</YourButton>
|
|
308
|
-
{limit ? (
|
|
309
|
-
<YourCard title={limit.title} body={limit.body}
|
|
310
|
-
onConnect={limit.connect}
|
|
311
|
-
onUpgrade={limit.upgradeTo ? limit.upgrade : undefined} />
|
|
312
|
-
) : message ? (
|
|
313
|
-
<p className="error">{message}</p>
|
|
314
|
-
) : null}
|
|
315
|
-
</>
|
|
316
|
-
);
|
|
317
|
-
}
|
|
141
|
+
It draws the connect prompt, gives \`modelList\` as Soba's picker to somebody
|
|
142
|
+
connected and as your \`fallback\` to everyone else, and tells you where the run
|
|
143
|
+
goes. \`appModelList\` and \`appComposer\` are the app's own, already there. Put
|
|
144
|
+
\`modelList\` exactly where the app's list was. In an app that runs
|
|
145
|
+
only on the user's AI, leave \`fallback\` out. It is safe signed out, outside the
|
|
146
|
+
provider.
|
|
147
|
+
|
|
148
|
+
Send \`soba.current\` with the request. A value: the server calls Soba with it.
|
|
149
|
+
\`null\`: the app's own provider, as before.
|
|
150
|
+
|
|
151
|
+
**A button or form with no model list** ("Summarise", "Tidy", "Generate"):
|
|
152
|
+
put \`<ConnectNudge offer />\` directly above it, and send the run to Soba when
|
|
153
|
+
\`useCompute().connected\` is true.
|
|
154
|
+
|
|
155
|
+
## 6. The server call
|
|
156
|
+
|
|
157
|
+
\`https://api.soba.so/v1/chat/completions\` is OpenAI's chat completions:
|
|
158
|
+
\`messages\`, \`tools\`, \`stream\`, \`response_format\`, images. It is the only OpenAI
|
|
159
|
+
endpoint; embeddings, speech, images out and the Responses API stay on the
|
|
160
|
+
app's provider. A text step before them (writing an image prompt, a script)
|
|
161
|
+
is a chat call and goes to Soba. https://soba.so/docs/endpoint
|
|
162
|
+
|
|
163
|
+
\`\`\`ts
|
|
164
|
+
const { model, runtime, route, effort } = pick; // soba.current, validated
|
|
165
|
+
const answer = await fetch("https://api.soba.so/v1/chat/completions", {
|
|
166
|
+
method: "POST",
|
|
167
|
+
headers: { authorization: \`Bearer \${process.env.SOBA_KEY}\`, "content-type": "application/json" },
|
|
168
|
+
body: JSON.stringify({ model, soba: { runtime, route, effort }, user, messages, stream: true }),
|
|
169
|
+
});
|
|
318
170
|
\`\`\`
|
|
319
171
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
placement and size, \`theme\` on \`<SobaProvider>\` (or the dashboard) for
|
|
346
|
-
light and dark, \`<ComputeSettings />\` inherits the page's type, and
|
|
347
|
-
\`<ModelPicker />\` is a pill beside a send button, not a card. The header's
|
|
348
|
-
pill takes \`--sc-pill-*\` custom properties, set anywhere above it, and
|
|
349
|
-
\`<ConnectButton />\` also takes a function as children that draws the whole
|
|
350
|
-
control in this app's own markup, still opening the panel when pressed. Use
|
|
351
|
-
that when a recoloured pill would not look like it belongs:
|
|
352
|
-
https://soba.so/docs/components#the-connect-pill. If one still
|
|
353
|
-
clashes, say so to the person and leave the component in.
|
|
354
|
-
|
|
355
|
-
**Reach for a hook only when the person asks for their own markup**, or for a
|
|
356
|
-
decision no component draws (\`useMachineRuns()\`, \`useOpenSobaConnect()\`,
|
|
357
|
-
gating a server action on \`useFeature()\`). Every component is one rendering of
|
|
358
|
-
an exported hook and derives nothing of its own, and a surface built from a
|
|
359
|
-
hook must still show everything the component shows. Each line in the last
|
|
360
|
-
column is something a hand-built copy has dropped:
|
|
361
|
-
|
|
362
|
-
| Component | Hook | Built from the hook, it must still show |
|
|
363
|
-
|---|---|---|
|
|
364
|
-
| \`<ConnectButton />\` | \`useConnectButton()\` | In the header, on every page, when the app needs their compute. \`label\`, which names the machine once one is attached; the state dot from \`state.tone\` with \`state.word\`; disabled when \`canOpen\` is false. Pressing it calls \`open()\`, which raises Soba's connect flow \u2014 never a page of your own. Its panel's machine list and "Running now" with Stop come from \`useCompute()\` and \`useMachineRuns()\` |
|
|
365
|
-
| \`<ComputeSettings />\` | \`useCompute()\` + \`useConnectButton()\` | The settings page's section, as rows in the page's own type: each machine's \`name\`, \`hardware\`, \`runsOn.name\` and \`status.text\` with a dot from \`state.tone\`, \`lastSeen\` instead of the hardware while it is asleep; "Connect compute" with nothing connected and "Connect another computer" with something, both calling \`open()\`. No pill and no popover |
|
|
366
|
-
| \`<ComputeStatus />\` | \`useCompute()\` | All four of \`view\`: loading, error, empty, machines. Each machine's state in words, and \`stalled\` called out. "Nothing connected" only when \`view\` is \`"empty"\` |
|
|
367
|
-
| \`<ConnectNudge />\` | \`useConnectNudge()\` | Nothing unless \`visible\`. \`title\`, \`detail\`, the \`meter\`, the \`steps\` and \`stalled\`; a dismiss only when \`dismissible\`; the action is \`open()\` |
|
|
368
|
-
| \`<RunLimit />\` | \`useRunLimit()\` | In the place the answer was going to be. \`title\` and \`body\`; Connect calling \`connect()\`, with \`connectOffer\` as its line when there is one; Upgrade only when \`upgradeTo\` is, calling \`upgrade()\`. Nothing when it returns null, which includes a \`no_compute\` the person has since fixed by connecting |
|
|
369
|
-
| \`<RunError />\` | \`runErrorMessage()\` | Its sentence as given, nothing when it is null, and never beside a \`<RunLimit />\` that is speaking |
|
|
370
|
-
| \`<ModelPicker />\` | \`useModel()\` | A menu, never a \`<select>\`. Automatic, Fast and Best (the \`auto\` and \`size\` options) each with its \`note\`; the app's models laid out as \`layout\` says (\`providers\`, \`models\`, \`choices\` or \`automatic\`, which is the vendor's dashboard setting); every agent in \`agents\` with its logo, as its own submenu, and an agent with no models (Codex) as a single row; \`providers\` with their marks (\`<ProviderMark />\` draws each), and locked when the plan says so. A search field when \`search\` is on. \`unavailable\` as the reason a stale pick fell back. Nothing at all when \`pickable\` is false. Spread \`run\` onto the request |
|
|
371
|
-
| \`<SobaPlans />\` | \`usePlans()\` | Every offer: price, \`allowance\` and \`allowanceNote\`, \`features\`, the compute it runs on, the connect row, and its \`cta\` calling \`take()\`. The current plan and the featured one marked. \`failed\` when it is set |
|
|
372
|
-
| \`<SobaCurrentPlan />\` | \`useCurrentPlan()\` | \`summary\`; used and remaining as a meter unless \`unlimited\`; \`trialDaysLeft\`, \`periodEnd\` and the \`reward\` when there are any |
|
|
373
|
-
| \`<SobaCheckout />\` | \`useCheckout()\` | \`label\` on the button, \`busy\` and \`error\`, and \`buy()\`. Nothing is granted in the browser |
|
|
374
|
-
| \`<SobaGate />\` | \`useFeature()\` | The children while allowed; otherwise the reason it is not and the plans that would allow it |
|
|
375
|
-
| \`<RedeemCode />\` | \`useRedeemCode()\` | A field and an Apply that call \`redeem()\`, \`busy\`, \`error\` as given, and the \`reward\` once it lands |
|
|
376
|
-
|
|
377
|
-
\`<SobaBilling />\` and \`<ConnectModal />\` are compositions of the above and
|
|
378
|
-
have no rule of their own. \`<ConnectPill />\` is the half of \`<ConnectButton />\`
|
|
379
|
-
that reports \u2014 the mark, the state and the machine, with no popover under it
|
|
380
|
-
and no flow behind it. It is for an app whose person asked for their own panel;
|
|
381
|
-
otherwise the header gets \`<ConnectButton />\`, panel included. Pressing the pill
|
|
382
|
-
is yours to wire, and it still opens Soba's flow through
|
|
383
|
-
\`useSoba().connect.open()\`; everything it says is \`connectSays\`.
|
|
384
|
-
\`<SobaProvider>\` is needed either way: the hooks read from it, so a hook with no
|
|
385
|
-
provider above it is the one mistake this split invites.
|
|
386
|
-
|
|
387
|
-
A gate draws the button; it does not secure the action. On the server, ask
|
|
388
|
-
before you create: \`soba.users.check(user, "workspaces", { use: 1 })\` answers
|
|
389
|
-
\`{ allowed, reason }\` and counts the use in the same call, so two requests for
|
|
390
|
-
the last one cannot both get it. Record use you did not ask about with
|
|
391
|
-
\`soba.users.track(user, "workspaces", -1)\` when one is deleted. Prices,
|
|
392
|
-
allowances and the connected reward come from the plan objects, so changing
|
|
393
|
-
them later is not a deploy. Pass \`showConnect\` to \`<SobaPlans />\` only on a page
|
|
394
|
-
with no current-plan card: a bring-your-own plan would otherwise state a
|
|
395
|
-
requirement with no way to meet it.
|
|
396
|
-
|
|
397
|
-
Three belong to no component of their own. \`useOpenSobaConnect()\` brings the
|
|
398
|
-
Soba app forward on this person's machine and hands back the one honest thing a
|
|
399
|
-
page can say about having tried \u2014 a browser cannot tell whether a \`soba://\`
|
|
400
|
-
link was answered, and a page that claims it worked is guessing.
|
|
401
|
-
\`useRun()\` is for a run started in the browser that must outlive the page: a
|
|
402
|
-
reload, a page switch or a dropped connection only stops the reading, and it
|
|
403
|
-
reads on by itself. It takes your two routes, both returning \`runResponse\`
|
|
404
|
-
from \`@soba-so/sdk\`: one around \`soba.run({ resumable: true })\`, one around
|
|
405
|
-
\`soba.runs.attach\`.
|
|
406
|
-
|
|
407
|
-
\`useMachineRuns()\` is the "Running now" list out of \`<ConnectButton />\`'s
|
|
408
|
-
panel with no panel around it: what this person's machines are running FOR THIS
|
|
409
|
-
APP, and \`stop(runId)\` to end one as the person whose machine it is on; the app
|
|
410
|
-
that started that run sees it finish with \`reason: "stopped_by_user"\`.
|
|
411
|
-
\`useRedeemCode()\` is a promo code field's behaviour: \`redeem(code)\` gives the
|
|
412
|
-
user what the app's reward hands out and re-reads their plan, so the allowance
|
|
413
|
-
on screen moves without a reload; \`<RedeemCode />\` is that field already drawn.
|
|
414
|
-
|
|
415
|
-
\`useSoba()\` is the raw provider state. Reach for a named hook first and use
|
|
416
|
-
this one for what no hook covers \u2014 \`run()\`, \`connect.open()\`,
|
|
417
|
-
\`plan.refresh()\`. A page that reads \`compute.connected\` or \`plan.remaining\`
|
|
418
|
-
straight off it is re-deriving a decision that is already exported, and the two
|
|
419
|
-
copies are how our own apps drifted.
|
|
420
|
-
|
|
421
|
-
### What not to write yourself
|
|
422
|
-
|
|
423
|
-
These are not style preferences. Each one is a judgement this package already
|
|
424
|
-
makes, and each has been got wrong in production \u2014 in our own code, which is why
|
|
425
|
-
they are exported at all. If you find yourself writing one of them, delete it
|
|
426
|
-
and import the answer:
|
|
427
|
-
|
|
428
|
-
- **A list of model names.** The names come off the person's own machine, so a
|
|
429
|
-
list in your code refuses the model they can see on their own screen.
|
|
430
|
-
\`useModel()\` reads it from what they have connected.
|
|
431
|
-
- **A model id on a run without its agent.** Soba applies a person's own agent
|
|
432
|
-
preference only to a run whose model is blank or a size, so a named model
|
|
433
|
-
travelling alone goes to whichever agent is found first. Spread
|
|
434
|
-
\`useModel().run\` whole \u2014 it is \`{ model, runtime? }\` \u2014 and have your route
|
|
435
|
-
forward both fields.
|
|
436
|
-
- **"Nothing connected yet."** That is a claim about somebody's account and it
|
|
437
|
-
is only true once the account has been read. Said while the first request is
|
|
438
|
-
in flight, or after it failed, it tells a person with a paired laptop that it
|
|
439
|
-
has vanished. \`useCompute().view\` is the four-way answer.
|
|
440
|
-
- **A match on an error message, or an error line of your own for a refusal.**
|
|
441
|
-
\`useRunLimit\` and \`runErrorMessage\` read the CODE. Messages are prose we
|
|
442
|
-
rewrite, matching on them breaks on a copy edit, and Soba's own refusal text
|
|
443
|
-
names internal ids no user should see.
|
|
444
|
-
- **Words for a cost class.** \`tierLabel(tier)\` is the one glossary for the five
|
|
445
|
-
economics this product is about. Four hand-written copies in this repo
|
|
446
|
-
disagreed with each other, and three reported somebody's own API key as
|
|
447
|
-
frontier supply the app had paid for.
|
|
448
|
-
- **Where the pick is remembered, or how a stale one is handled.** A model whose
|
|
449
|
-
machine is gone falls back to Automatic and stays picked. \`useModel()\` does
|
|
450
|
-
that and tells you with \`unavailable\`.
|
|
451
|
-
|
|
452
|
-
Read \`https://soba.so/docs/components\` for each hook's full shape.
|
|
453
|
-
|
|
454
|
-
## The chat stays theirs
|
|
455
|
-
|
|
456
|
-
There is no chat component, on purpose. An app built on Soba already has its own
|
|
457
|
-
composer and its own messages, and they are the product. Keep every line of
|
|
458
|
-
that markup. What Soba adds goes INTO it, and these are the things a chat on
|
|
459
|
-
Soba has to handle \u2014 check each one against the code, not against memory:
|
|
460
|
-
|
|
461
|
-
**In the composer**
|
|
462
|
-
|
|
463
|
-
- \`<ModelPicker />\` in the composer's footer, beside the send button. The
|
|
464
|
-
component, per the section above, not a copy.
|
|
465
|
-
- Spread \`useModel().run\` onto the request, and have the route forward
|
|
466
|
-
\`model\` and \`runtime\` both.
|
|
467
|
-
- Send becomes Stop while a run is going. Stop aborts the request's
|
|
468
|
-
\`signal\`, and a run the person stopped is not an error to show. Neither is
|
|
469
|
-
\`reason: "stopped_by_user"\`, which is the machine's owner stopping it
|
|
470
|
-
from their side.
|
|
471
|
-
- \`<ConnectNudge />\` above the composer. It draws nothing until it has
|
|
472
|
-
something to say.
|
|
473
|
-
- Images, only if the composer already takes them: forward each message's
|
|
474
|
-
\`images\` and the runtimes that can see them will.
|
|
475
|
-
|
|
476
|
-
**In the messages**
|
|
477
|
-
|
|
478
|
-
- \`delta\` text is appended as it arrives. \`thinking\` is the running total
|
|
479
|
-
and REPLACES what is shown \u2014 appending it repeats every sentence. Fold it
|
|
480
|
-
away by default.
|
|
481
|
-
- \`status\` events are what the agent is doing: show \`message\`, and
|
|
482
|
-
\`toolInput\` beside it when there is one. \`state: "interrupted"\` means
|
|
483
|
-
the person's machine went offline mid-run and \`"resumed"\` that it came
|
|
484
|
-
back; say so in the answer, because the run goes on either way.
|
|
485
|
-
- A failed run renders \`<RunLimit />\` where the answer was going to be, and
|
|
486
|
-
\`<RunError />\` beside it for everything else. Branch on the \`reason\`
|
|
487
|
-
code, never the message. Offer Retry only when \`retryable\` is not false.
|
|
488
|
-
- Copy on every answer, on hover, copying the text as written (markdown, not
|
|
489
|
-
rendered HTML). Retry on the last one.
|
|
490
|
-
- \`done\` carries \`usage\` and \`tier\`. If the app shows what answered,
|
|
491
|
-
word the tier with \`tierLabel()\`.
|
|
492
|
-
|
|
493
|
-
**Across turns**
|
|
494
|
-
|
|
495
|
-
- \`done\` and \`error\` carry a \`session\`. Send it back as \`resume\`
|
|
496
|
-
on the next run, and have the route forward it, so a follow-up continues the
|
|
497
|
-
agent's conversation instead of starting a new one with the whole transcript
|
|
498
|
-
pasted in.
|
|
499
|
-
|
|
500
|
-
An app with no chat at all gets one built in its own components and styles,
|
|
501
|
-
the same way it would build any other screen \u2014 with everything above in it.
|
|
502
|
-
|
|
503
|
-
## Proving it
|
|
504
|
-
|
|
505
|
-
\`soba/echo\` is answered by Soba itself \u2014 no machine, no metered supply,
|
|
506
|
-
nothing billed \u2014 and still proves the key, the base URL and the \`user\` field:
|
|
507
|
-
|
|
508
|
-
\`\`\`sh
|
|
509
|
-
curl https://api.soba.so/v1/chat/completions \\
|
|
510
|
-
-H "Authorization: Bearer $SOBA_KEY" \\
|
|
511
|
-
-H "Content-Type: application/json" \\
|
|
512
|
-
-d '{ "model": "soba/echo", "user": "usr_123",
|
|
513
|
-
"messages": [{ "role": "user", "content": "ping" }] }'
|
|
172
|
+
- \`user\` is step 2's value, from the session. With no pick, \`model\` is \`"auto"\`.
|
|
173
|
+
- **Send all four fields of the pick.** A picker whose choice stays in the
|
|
174
|
+
browser lies to the user.
|
|
175
|
+
- **Pass Soba's answer back with its status and body unchanged.** A 409
|
|
176
|
+
\`no_compute\` or 402 \`payment_required\` is an answer, not an outage. Do not
|
|
177
|
+
retry it, reword it or turn it into a 500. Step 7 draws it.
|
|
178
|
+
- With an OpenAI SDK: \`baseURL\` and \`apiKey\` as above, \`user\` on the call, and
|
|
179
|
+
the other fields in the body (\`extra_body\` in Python).
|
|
180
|
+
- With the Vercel AI SDK: \`createOpenAICompatible({ name: "soba", baseURL,
|
|
181
|
+
apiKey })\`, \`providerOptions: { soba: { user, runtime, route, effort } }\` and
|
|
182
|
+
\`maxRetries: 0\`. Install the release that matches the project's \`ai\` major.
|
|
183
|
+
Where the SDK drops fields it does not know, add them in the client's
|
|
184
|
+
\`fetch\` option: https://soba.so/docs/implement.md shows how.
|
|
185
|
+
- Tool calls work here with any AI, Claude Code and Codex included: a turn
|
|
186
|
+
that calls one ends with \`tool_calls\`. Do not keep tool chats off the
|
|
187
|
+
person's plan. Work that outlives one request uses \`soba.run()\`:
|
|
188
|
+
https://soba.so/docs/runs
|
|
189
|
+
|
|
190
|
+
## 7. Where the answer appears
|
|
191
|
+
|
|
192
|
+
Keep the failed response's parsed body and draw both. They never both speak.
|
|
193
|
+
|
|
194
|
+
\`\`\`tsx
|
|
195
|
+
<RunLimit error={error} />
|
|
196
|
+
<RunError error={error} />
|
|
514
197
|
\`\`\`
|
|
515
198
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
199
|
+
## 8. Settings
|
|
200
|
+
|
|
201
|
+
\`<ComputeSettings />\`, alone, on the settings page. Required: it is where
|
|
202
|
+
somebody checks on, or removes, the computer they connected. If the app has no
|
|
203
|
+
settings page, add a small page or dialog for it and link it from the account
|
|
204
|
+
menu. That does not need asking first.
|
|
205
|
+
|
|
206
|
+
## 9. The header button
|
|
207
|
+
|
|
208
|
+
\`<ConnectButton />\` in the signed-in navbar, in every app. Signed out, it is
|
|
209
|
+
not rendered.
|
|
210
|
+
|
|
211
|
+
## 10. Prove it
|
|
212
|
+
|
|
213
|
+
1. Run the project's type check and build, in every package you touched.
|
|
214
|
+
2. \`soba/echo\` proves the key and costs nothing:
|
|
215
|
+
\`curl https://api.soba.so/v1/chat/completions -H "Authorization: Bearer $SOBA_KEY" -H "Content-Type: application/json" -d '{"model":"soba/echo","user":"usr_000000000000","messages":[{"role":"user","content":"ping"}]}'\`
|
|
216
|
+
3. Read your diff against the rules above, one by one. For rule 5, search
|
|
217
|
+
again for every caller of each model route and check each has steps 5 to 7.
|
|
218
|
+
4. Tell the person what to click: signed out, no Soba. Signed in, nothing
|
|
219
|
+
connected: the connect prompt above each control and the connect card
|
|
220
|
+
where a refused answer would be. Connected: Soba's picker, their own AI.
|
|
221
|
+
5. Add a short "## Soba" section to AGENTS.md (or CLAUDE.md): AI calls go
|
|
222
|
+
through Soba in <file>, never a provider; where the user comes from;
|
|
223
|
+
where plans link; https://soba.so/skill for new AI features.
|
|
224
|
+
|
|
225
|
+
Then report: what you changed, what you could not run, and anything you left
|
|
226
|
+
for them. Existing plans, prices and production keys are theirs: change none
|
|
227
|
+
of them.
|
|
228
|
+
|
|
229
|
+
## 11. If the app already charges through Stripe
|
|
230
|
+
|
|
231
|
+
Required, not optional: without it nobody's paid tier reaches Soba. The app's
|
|
232
|
+
checkout, webhook, prices and pricing page stay as they are; Soba follows
|
|
233
|
+
the subscription, enforces the plan's AI limits and bills overage.
|
|
234
|
+
|
|
235
|
+
1. Read the tiers from the code: name, price, interval and Stripe price ids
|
|
236
|
+
(test mode). Propose an AI allowance per paid tier; the person may change
|
|
237
|
+
it, and without an answer your proposal stands. Write one
|
|
238
|
+
\`soba-plans/<tier>.json\` each, holding \`"price"\`, \`"included_units"\`,
|
|
239
|
+
\`"route_prefer"\` (https://soba.so/docs/plans) and \`"stripe_prices"\`,
|
|
240
|
+
for \`npx -y @soba-so/cli plans create "<name>" --file <file> --json\`.
|
|
241
|
+
2. Where the app creates the Checkout Session or subscription, add
|
|
242
|
+
\`soba_user: <user id>\` to the subscription's metadata. Soba then links
|
|
243
|
+
it itself; leave the webhook alone. **If a team pays**, use
|
|
244
|
+
\`soba_customer: "team_" + team.id\` and send that \`customer\` on every
|
|
245
|
+
run (\`soba: { customer }\`): https://soba.so/docs/identity
|
|
246
|
+
3. A script that sets the same key on each existing subscriber's Stripe
|
|
247
|
+
customer from the app's database, then calls \`soba.plans.sync()\`. Do
|
|
248
|
+
not run it.
|
|
249
|
+
4. Remove nothing of the app's billing.
|
|
250
|
+
|
|
251
|
+
https://soba.so/docs/stripe
|
|
252
|
+
|
|
253
|
+
## More, when the app needs it
|
|
254
|
+
|
|
255
|
+
- Building your own markup from hooks (\`useModel().run\`, \`useConnectNudge()\`,
|
|
256
|
+
\`useRunLimit()\`), every component and its states: https://soba.so/components
|
|
257
|
+
- The long form of this file, with every option: https://soba.so/docs/implement.md
|
|
258
|
+
- Plans, checkout and limits: https://soba.so/docs/plans
|
|
259
|
+
- Conversations kept on the user's machine: https://soba.so/docs/threads
|
|
260
|
+
- Errors and what each means: https://soba.so/docs/errors`;var L=[{name:"set_up",title:"Set Soba up in this repo",description:"Works through Soba's setup checklist one step at a time, editing this repo and showing you each diff.",text:`Set this project up on Soba, working from the real checklist rather than from memory.
|
|
540
261
|
|
|
541
262
|
The loop, and keep to it:
|
|
542
263
|
|
|
@@ -562,7 +283,7 @@ Three things not to do:
|
|
|
562
283
|
- Do not put the secret key anywhere but \`.env.local\`, and check that file is
|
|
563
284
|
gitignored before you write it. Do not echo it back to the terminal.
|
|
564
285
|
- Do not guess the connect return URL. It has to be a page that actually renders
|
|
565
|
-
\`<
|
|
286
|
+
\`<ComputeSettings />\`; if there isn't one yet, build it first.
|
|
566
287
|
|
|
567
288
|
Start with \`soba_status\`.
|
|
568
289
|
|
|
@@ -571,23 +292,23 @@ Start with \`soba_status\`.
|
|
|
571
292
|
What the codebase steps actually involve, so you are not working from memory
|
|
572
293
|
there either:
|
|
573
294
|
|
|
574
|
-
${
|
|
575
|
-
`)}function
|
|
576
|
-
`)}function
|
|
577
|
-
`);for(;
|
|
578
|
-
`)}}),process.stdin.on("end",()=>{r=!0,n.size===0&&process.exit(0),setTimeout(()=>process.exit(0),1e4).unref()})}async function ke(e,t){let n;try{n=JSON.parse(e)}catch{m("ignored a line that was not json");return}let r=n.id===void 0||n.id===null;try{let o=await t(n.method,n.params??{});r||
|
|
579
|
-
`),
|
|
580
|
-
`).map(
|
|
295
|
+
${V}`}],J=new Map(L.map(e=>[e.name,e]));function m(e){process.stderr.write(`soba-mcp: ${e}
|
|
296
|
+
`)}function z(e){process.stdout.write(`${JSON.stringify(e)}
|
|
297
|
+
`)}function X(e){let t="",n=new Set,r=!1,o=s=>{n.add(s),s.finally(()=>{n.delete(s),r&&n.size===0&&process.exit(0)})};process.stdin.setEncoding("utf8"),process.stdin.on("data",s=>{t+=s;let l=t.indexOf(`
|
|
298
|
+
`);for(;l!==-1;){let u=t.slice(0,l).trim();t=t.slice(l+1),u&&o(ke(u,e)),l=t.indexOf(`
|
|
299
|
+
`)}}),process.stdin.on("end",()=>{r=!0,n.size===0&&process.exit(0),setTimeout(()=>process.exit(0),1e4).unref()})}async function ke(e,t){let n;try{n=JSON.parse(e)}catch{m("ignored a line that was not json");return}let r=n.id===void 0||n.id===null;try{let o=await t(n.method,n.params??{});r||z({jsonrpc:"2.0",id:n.id,result:o})}catch(o){if(r)return;let s=o instanceof Error?o.message:String(o),l=s==="method not found"?-32601:-32603;z({jsonrpc:"2.0",id:n.id,error:{code:l,message:s}})}}import{readFileSync as ue,realpathSync as M}from"node:fs";import b from"node:path";import{spawnSync as Z}from"node:child_process";import{existsSync as Q}from"node:fs";import{appendFile as _e,chmod as Se,readFile as ee,writeFile as Ae}from"node:fs/promises";import I from"node:path";var xe=e=>new RegExp(`^\\s*(?:export\\s+)?${e}\\s*=`);async function te(e,t,n){let r=Q(e),o=r?await ee(e,"utf8"):"",s=o===""?[]:o.replace(/\n$/,"").split(`
|
|
300
|
+
`),l=[];for(let[u,h]of Object.entries(t)){let f=s.findIndex(g=>xe(u).test(g));f===-1?l.push(`${u}=${h}`):s[f]=`${u}=${h}`}l.length>0&&(s.length>0&&s[s.length-1].trim()!==""&&s.push(""),n&&s.push(...n.split(`
|
|
301
|
+
`).map(u=>`# ${u}`)),s.push(...l)),await Ae(e,`${s.join(`
|
|
581
302
|
`)}
|
|
582
|
-
`),r||await Se(e,384).catch(()=>{})}async function
|
|
303
|
+
`),r||await Se(e,384).catch(()=>{})}async function ne(e){let t=I.dirname(e);if(Z("git",["rev-parse","--is-inside-work-tree"],{cwd:t}).status!==0||Z("git",["check-ignore","-q",I.basename(e)],{cwd:t}).status===0)return null;let o=I.join(t,".gitignore"),s=Q(o)?await ee(o,"utf8"):"",l=s===""||s.endsWith(`
|
|
583
304
|
`)?"":`
|
|
584
|
-
`;return await
|
|
585
|
-
`),o}var C={type:"string",description:"The app's id, from soba_list_apps."},d={type:"string",enum:["development","production"]},
|
|
586
|
-
`).map(
|
|
587
|
-
${JSON.stringify(r,null,2)}`}},a("soba_list_workspaces","List workspaces","GET","/workspaces","Your workspaces."),a("soba_create_app","Create an app","POST","/workspaces/:workspace/apps","Makes an app. Counts against the tier's app limit.",{name:i()},["name"]),a("soba_list_keys","List keys","GET","/apps/:app/keys","The app's keys, as previews, and what each may spend a month."),re({name:"soba_create_app_key",title:"Make a key",description:"Makes a secret key and writes it to the project's env file, never into the conversation. development is SOBA_KEY; production is SOBA_PROD_KEY.",route:"/apps/:app/keys",properties:{app:C,environment:d,replace_idle:p("Replace one never used.")},required:["app","environment"],variable:e=>e.environment==="production"?"SOBA_PROD_KEY":"SOBA_KEY"}),re({name:"soba_create_workspace_key",title:"Make a workspace key",description:"Makes a key that makes apps and mints their keys, and writes it to the env file as SOBA_WORKSPACE_KEY. Only when a person asked for one.",route:"/workspaces/:workspace/keys",properties:{workspace:i("From soba_list_workspaces."),name:i()},required:["workspace"],variable:()=>"SOBA_WORKSPACE_KEY"}),a("soba_set_key_cap","Cap a key","PATCH","/apps/:app/keys/:key","The most a key may spend a month, in dollars. Null is no cap.",{key:i("From soba_list_keys."),monthly_cap:c("number")},["monthly_cap"]),a("soba_list_workspace_keys","List workspace keys","GET","/workspaces/:workspace/keys","By name. Never the keys."),a("soba_revoke_workspace_key","Revoke a workspace key","DELETE","/workspaces/:workspace/keys/:key","Anything using it stops at once. Only when a person asked.",{key:i()}),a("soba_get_billing","Read billing","GET","/workspaces/:workspace/billing","Whether the workspace is on a plan (live), its tier, the tiers and what they cost, card and invoices. No plan is needed to use production."),a("soba_go_live","Buy a plan","POST","/workspaces/:workspace/billing/go_live","Only when a person chooses a plan: production works without one, on the workspace's one-time free connected users. Answers with Stripe's page to pay for the plan. Give the person the link: never ask for card details or fill them in. Then call soba_get_billing until live is true.",{tier:i("The one a person chose, from soba_get_billing.")},["tier"]),a("soba_change_card","Change the card","POST","/workspaces/:workspace/billing/card","Answers with Stripe's page. Give the person the link."),a("soba_change_tier","Change the tier","POST","/workspaces/:workspace/billing/tier","Charges the card on file. Tell the person the fee and get a yes first. An owner only.",{tier:i(),confirm_fee:{type:"number",description:"The fee they agreed to."}},["tier","confirm_fee"]),a("soba_cancel_subscription","Cancel the subscription","POST","/workspaces/:workspace/billing/cancel","Ends with the period. Only when a person asked for exactly this.",{confirm:i("The workspace's name, which the person gave you.")},["confirm"]),a("soba_get_stripe","Read the Stripe connection","GET","/workspaces/:workspace/stripe","Whether the workspace's own Stripe is connected, which its users pay into.",{environment:d},["environment"]),a("soba_connect_stripe","Connect Stripe","POST","/workspaces/:workspace/stripe/connect","Answers with Stripe's screen. The person accepts it, signed in to Soba as themselves. Then call soba_get_stripe until connected is true.",{environment:d},["environment"]),a("soba_disconnect_stripe","Disconnect Stripe","DELETE","/workspaces/:workspace/stripe","Nobody can buy a plan after. Only when a person asked for exactly this.",{environment:d,confirm:i("The workspace's name, which the person gave you.")},["environment","confirm"]),a("soba_list_repricing","Subscribers on old prices","GET","/apps/:app/repricing","People still paying a plan's old price, waiting for a decision."),a("soba_decide_repricing","Keep or move subscribers","POST","/apps/:app/repricing","keep leaves them on the old price; move changes what they pay at their next renewal. Tell the person how many and from what to what, and get a yes first.",{old_price:i("From soba_list_repricing."),decision:{type:"string",enum:["keep","move"]},confirm_subscribers:{type:"number",description:"To move: how many they agreed to."}},["old_price","decision"]),a("soba_check_stripe","Check Stripe","POST","/apps/:app/stripe/check","Compares the app's plans with what is in Stripe."),a("soba_restore_stripe_plan","Restore a plan in Stripe","POST","/apps/:app/plans/:plan/stripe/restore","Puts a plan back where it was changed in Stripe directly.",{plan:i()}),a("soba_accept_stripe_change","Leave a change in Stripe","POST","/apps/:app/plans/:plan/stripe/accept","Leaves a change somebody made in Stripe.",{plan:i(),kind:i("As the check reported it.")},["kind"]),a("soba_try_checkout","Try checkout","POST","/apps/:app/plans/:plan/try_checkout","A checkout link for a plan, as a preview buyer. In live mode paying it takes real money.",{plan:i()}),a("soba_set_seats","Set a seat count","PUT","/apps/:app/plans/:plan/seats","Corrects how many seats one user is billed for. Only with a number a person gave you.",{plan:i(),user:i("Your id for them."),quantity:{type:"number"}},["user","quantity"]),a("soba_set_logo","Set a logo from a file","PUT","/apps/:app/logo","The app's icon, or one environment's connect popup logo. PNG, JPEG, GIF, WebP or SVG, up to 2MB.",{file:i("The image's path in this project."),use:{type:"string",enum:["icon","connect_popup"]},environment:{...d,description:"With connect_popup."}},["file"],U),a("soba_set_custom_model_logo","Set a custom model's logo","PUT","/apps/:app/custom_models/:alias/logo","From an image file.",{alias:i(),file:i("The image's path in this project.")},["file"],U),a("soba_set_workspace_logo","Set the workspace's picture","PUT","/workspaces/:workspace/logo","From an image file.",{file:i("The image's path in this project.")},["file"],U),a("soba_update_workspace","Rename the workspace","PATCH","/workspaces/:workspace/settings","Its name, or its picture as an https address or one emoji.",{name:i(),icon:c("string")}),a("soba_transfer_workspace","Transfer the workspace","POST","/workspaces/:workspace/transfer","Hands it over; the owner becomes an admin. Only when the owner asked for exactly this.",{member:i("Their id or email."),confirm:i("The workspace's name, which they gave you.")},["member","confirm"]),a("soba_delete_workspace","Delete the workspace","POST","/workspaces/:workspace/delete","Deletes every app, user, run and key in it. It cannot come back. Only when the owner asked for exactly this and gave you its name.",{confirm:i("The workspace's name, which they gave you.")},["confirm"]),a("soba_update_app","Rename an app","PATCH","/apps/:app","Its name.",{name:i()},["name"]),a("soba_delete_app","Delete an app","DELETE","/apps/:app","Deletes the app and everything that is its. It cannot come back. Only when a person asked for exactly this."),{name:"soba_pair_machine",title:"Pair your machine",description:"A link that pairs the person's own machine with the app, as its first user. They open it and approve it in the Soba app.",credentials:["setup","account"],inputSchema:{type:"object",properties:{app:D.app},additionalProperties:!1},run:async(e,t)=>{let n=e.kind==="setup"?"/v1/manage/pairing":`/v1/apps/${encodeURIComponent(F(t,"app"))}/pairing`,{url:r}=await e.post(n,{});return`Give the person this link, to open and approve themselves: ${r}`}},a("soba_revoke_key","Revoke a key","DELETE","/apps/:app/keys/:key","Anything using it stops at once. Only when a person asked for it.",{key:i("From soba_list_keys.")}),a("soba_list_providers","List providers","GET","/apps/:app/providers","The AI accounts the app pays for, with their models. Keys are never shown."),a("soba_list_provider_services","List known services","GET","/apps/:app/providers/services","OpenAI, Anthropic, Groq and the rest: what soba_add_provider takes as `service`."),a("soba_add_provider","Add a provider","POST","/apps/:app/providers","Adds an AI account the app pays for, used when a user's own AI can't serve a run. This spends the app's money, so only when a person asked.",{service:i("From soba_list_provider_services."),...oe},[],ne),a("soba_update_provider","Change a provider","PATCH","/apps/:app/providers/:provider","Changes what you send. A different host in base_url needs api_key_env with it.",{provider:y,enabled:p(),...oe},[],ne),a("soba_remove_provider","Remove a provider","DELETE","/apps/:app/providers/:provider","Removes it, its key and its models. Only when a person asked for it.",{provider:y}),a("soba_clear_provider_key","Forget a provider's key","DELETE","/apps/:app/providers/:provider/key","Forgets the stored key and keeps the provider. Only when a person asked for it.",{provider:y}),a("soba_order_providers","Order providers","PUT","/apps/:app/providers/order","The order they are tried in, first tried first.",{providers:{type:"array",items:{type:"string"}}},["providers"]),a("soba_list_available_models","What a provider offers","GET","/apps/:app/providers/:provider/available","Asks the provider which models it serves.",{provider:y}),a("soba_set_provider_model","Add or change a model","PUT","/apps/:app/providers/:provider/models","Adds a model to a provider, or changes how users see it. Prices are looked up unless sent.",{provider:y,model:i("The provider's own id for it."),input_per_mtok:{type:"number"},output_per_mtok:{type:"number"},alias:c("string"),label:c("string","The name users see. Needs an alias."),note:c("string"),shown:p("In the model picker."),is_default:p(),tier:{type:["string","null"],enum:["fast","best",null]}},["model"]),a("soba_remove_provider_model","Remove a model","DELETE","/apps/:app/providers/:provider/models","Takes one model off a provider.",{provider:y,model:i()},["model"]),a("soba_list_custom_models","List custom models","GET","/apps/:app/custom_models","The app's own names over models from its providers."),a("soba_set_custom_model","Make or change a custom model","PUT","/apps/:app/custom_models/:alias","One name users pick over one or more models. With a percent on every model (coming to 100) runs are split; without, they are tried in order.",{alias:i("Lowercase and dashes. Fixed once made."),label:i("The name users see."),note:c("string"),icon:c("string"),is_default:p("What a user who picked nothing starts on."),models:{type:"array",items:{type:"object",properties:{provider:i(),model:i(),percent:c("number")},required:["provider","model"]}}}),a("soba_remove_custom_model","Remove a custom model","DELETE","/apps/:app/custom_models/:alias","Takes the name away. Its models stay.",{alias:i()}),a("soba_list_rewards","List rewards","GET","/apps/:app/rewards","Discounts, grants and free plans, with their codes.",{environment:d}),a("soba_create_reward","Create a reward","POST","/apps/:app/rewards","Only with amounts a person gave you.",{environment:d,...se},["environment","name","kind"]),a("soba_update_reward","Change a reward","PATCH","/apps/:app/rewards/:reward","Changes what you send. Only with amounts a person gave you.",{reward:i("Its id or slug."),environment:d,...se}),a("soba_archive_reward","Archive a reward","DELETE","/apps/:app/rewards/:reward","Its codes stop working; who holds it keeps it. Only when a person asked.",{reward:i(),environment:d}),a("soba_give_user_reward","Give a user a reward","POST","/apps/:app/rewards/:reward/give","Once per user per reward. Only when a person asked for that user to get it.",{reward:i(),user:i("Your id for them, or Soba's."),environment:d},["user"]),a("soba_sync_stripe","Put plans in Stripe","POST","/apps/:app/stripe/sync","Puts the app's paid plans into the workspace's connected Stripe now."),a("soba_list_users","List users","GET","/apps/:app/users","The app's users.",{environment:d,...N}),a("soba_get_user","Read a user","GET","/apps/:app/users/:user","Their plan, usage, machines and latest runs.",{user:i("Your id for them, or Soba's."),environment:d}),a("soba_set_user_plan","Put a user on a plan","PATCH","/apps/:app/users/:user","A paid plan given here is a gift: nothing is billed. Null takes their plan away, which leaves them with no limit. Only when a person asked for that user.",{user:i(),plan:c("string","A plan id, or null."),environment:d},["plan"]),a("soba_list_machines","List machines","GET","/apps/:app/machines","Users' machines.",{environment:d,...N}),a("soba_get_machine","Read a machine","GET","/apps/:app/machines/:machine","One machine and the AI on it.",{machine:i()}),a("soba_list_runs","List runs","GET","/apps/:app/runs","Runs with totals, speed and cost. Never what was said in them.",{environment:d,range:i("1d, 7d, 30d, 90d or all."),status:i(),class:i("A cost class."),model:i(),error:i(),...N}),a("soba_get_run","Read a run","GET","/apps/:app/runs/:run","One run.",{run:i()}),a("soba_get_activations","Read activations","GET","/apps/:app/activations","Users activated this period."),a("soba_get_overview","Read the overview","GET","/apps/:app/overview","Users, runs, what was spent and what was saved.",{environment:d}),a("soba_list_members","List members","GET","/workspaces/:workspace/members","Who is in the workspace, and open invites."),a("soba_invite_member","Invite somebody","POST","/workspaces/:workspace/invites","Emails an invitation. Only when a person named who to invite.",{email:i(),role:ie},["email"]),a("soba_revoke_invite","Revoke an invite","DELETE","/workspaces/:workspace/invites/:invite","Its link stops working.",{invite:i()}),a("soba_set_member_role","Change a member's role","PATCH","/workspaces/:workspace/members/:member","Only when a person asked. Owners are changed in the dashboard.",{member:i("Their id or email."),role:ie},["role"]),a("soba_remove_member","Remove a member","DELETE","/workspaces/:workspace/members/:member","Ends their access. Only when a person asked.",{member:i("Their id or email.")})];var P={type:"object",properties:{},additionalProperties:!1},Re=["user-subscription","user-hardware","user-api-key","open-weights","frontier"],k={app:{type:"string",description:"The app's id, from soba_list_apps. Not needed with a setup key."},environment:{type:"string",enum:["development","production"],description:"Which catalogue. Required to create with an account credential; a setup key is development only."}},ce={type:"string",description:"The plan's id, from soba_list_plans."},pe={name:{type:"string"},description:{type:"string"},price:{type:"number",description:"Dollars a month. 0 is a free plan."},unit:{type:"string",enum:["run","task","token","cost","credit"],description:"What both allowances are counted in. `cost` counts hundredths of a cent (10,000 to the dollar); a token or cost overage price is per 1M tokens or per $1."},included_units:{type:["number","null"],description:"Runs a month on AI the app pays for (open-weights, frontier). Null is unlimited."},trial_days:{type:"number"},route_prefer:{type:"array",items:{type:"string",enum:["user-subscription","user-hardware","user-api-key","open-weights","frontier"]},description:"What a run may use, best first. This is also the ceiling: a class left out can never be billed to this app."},max_cost_per_run:{type:["number","null"],description:"Dollars one run may cost."},own_included_units:{type:["number","null"],description:"Runs a month on the user's own AI (their machine, subscription or key), counted apart from included_units. Null is unlimited."},own_unit:{type:["string","null"],enum:["run","task","token","cost","credit",null],description:"What own_included_units counts, when not unit: a hybrid plan gives 200 runs on the user's own AI and 2,000 credits on yours. Null means the same as unit."},connected_reward:{type:"string",enum:["none","included","credit"]},connected_included_units:{type:["number","null"]},connected_credit:{type:["number","null"]},route_allow:{type:"array",items:{type:"string",enum:Re},description:"Classes allowed but not ranked, on top of route_prefer."},overage_per_unit:{type:["number","null"],description:"Dollars past the allowance, on a cost or credit plan."},meter:{type:"boolean",description:"On a run, task or token plan: keep going past the allowance, at cost plus markup_percent."},byo_overage:{type:"string",enum:["stop","meter"],description:"When the own-AI allowance is spent: stop, or continue on AI the app pays for."},markup_percent:{type:"number"},markup_overrides:{type:"object",additionalProperties:{type:"number"},description:"Percent per model vendor, over markup_percent."},credits_per_dollar:{type:"number",description:"Credits $1 of AI cost uses."},credit_price:{type:["number","null"],description:"Dollars per 1,000 credits."},credit_packs:{type:["array","null"],items:{type:"object",properties:{credits:{type:"number"},price:{type:"number"}},required:["credits","price"],additionalProperties:!1}},credit_expiry:{type:"string",enum:["never","month_end"]},task_noun:{type:["string","null"],description:"What the app calls a run, plural."},contact_url:{type:["string","null"],description:'A "Talk to us" link (https:// or mailto:). The price becomes 0.'},features:{type:"array",description:"What the app itself enforces, shown on the pricing card.",items:{type:"object",properties:{id:{type:"string",description:"snake_case; the app's code reads it."},name:{type:"string"},type:{type:"string",enum:["boolean","number","text"]},value:{type:["boolean","number","string","null"],description:"Null is unlimited, on a number."},unit:{type:"string"},resets:{type:"string",enum:["month"]},price:{type:"object",description:"Per-unit pricing (seats). amountMicros is millionths of a dollar.",properties:{amountMicros:{type:"number"},included:{type:"number"}},required:["amountMicros","included"]}},required:["id","name","type","value"]}}},Me={is_default:{type:"boolean",description:"Where new users start. A free plan only."},is_popular:{type:"boolean",description:'Shown as "Most popular".'}};function v(e,t){let{app:n,environment:r,plan:o,...s}=t;if(e.kind==="account"&&(typeof n!="string"||!n))throw new Error("Say which app: pass its id as `app`. soba_list_apps lists them.");return{path:e.kind==="setup"?"/v1/manage/plans":`/v1/apps/${encodeURIComponent(n)}/plans`,fields:s,plan:()=>{if(typeof o!="string"||!o)throw new Error("Say which plan: pass its id as `plan`. soba_list_plans lists them.");return encodeURIComponent(o)}}}function de(e,t){if(t.environment)return{environment:t.environment};if(e.kind==="setup")return{};throw new Error("Say which environment: development or production.")}function he(e){let t=e.steps.map(r=>`${r.done?"[x]":"[ ]"} ${r.title} \u2014 ${r.state}`),n=e.complete?"Every step is done. Nothing here needs you again.":`Next: ${e.next}. Call soba_next_step for what to do.`;return`${t.join(`
|
|
305
|
+
`;return await _e(o,`${l}${I.basename(e)}
|
|
306
|
+
`),o}var C={type:"string",description:"The app's id, from soba_list_apps."},d={type:"string",enum:["development","production"]},a=e=>({type:"string",...e?{description:e}:{}}),c=(e,t)=>({type:[e,"null"],...t?{description:t}:{}}),p=e=>({type:"boolean",...e?{description:e}:{}}),N={limit:{type:"number",description:"Up to 200."},offset:{type:"number"}},F=(e,t)=>{let n=e[t];if(typeof n!="string"||!n)throw new Error(`${t} is required.`);return n};function i(e,t,n,r,o,s={},l=[],u){let h=[...r.matchAll(/:(\w+)/g)].map(f=>f[1]);return{name:e,title:t,description:o,credentials:["account"],inputSchema:{type:"object",properties:{...h.includes("app")?{app:C}:{},...h.includes("workspace")?{workspace:a("The workspace's id, from soba_list_workspaces.")}:{},...s},required:[...new Set([...h,...l])],additionalProperties:!1},run:async(f,g)=>{let S=`/v1${r.replace(/:(\w+)/g,(G,O)=>encodeURIComponent(F(g,O)))}`,A=Object.fromEntries(Object.entries(g).filter(([G,O])=>!h.includes(G)&&O!==void 0));return JSON.stringify(await $(f,n,S,u?u(A):A),null,2)}}}async function $(e,t,n,r){if(t==="GET"||t==="DELETE"){let o=new URLSearchParams(Object.entries(r).map(([l,u])=>[l,String(u)])).toString(),s=o?`${n}?${o}`:n;return t==="GET"?e.get(s):e.delete(s)}return t==="PUT"?e.put(n,r):t==="PATCH"?e.patch(n,r):e.post(n,r)}function re({api_key_env:e,env_file:t,...n}){if(e===void 0)return n;let r=String(e),o=process.env[r];if(!o){let s=b.resolve(typeof t=="string"?t:".env.local");try{o=ue(s,"utf8").split(`
|
|
307
|
+
`).map(u=>u.trim().replace(/^export\s+/,"")).find(u=>u.startsWith(`${r}=`))?.slice(r.length+1).trim().replace(/^(["'])(.*)\1$/,"$2")}catch{}}if(!o)throw new Error(`${r} is not set here or in ${t??".env.local"}. Ask the person to put the key there; do not ask them to paste it to you.`);return{...n,api_key:o}}function Te(e){let t=M(b.resolve(e)),n=M(process.cwd());if(!t.startsWith(n+b.sep))throw new Error("That file is outside this project.");return t}function U({file:e,...t}){let n;try{n=ue(Te(String(e)))}catch(r){throw new Error(`Could not read ${e}: ${r.message}`)}if(n.length>2*1024*1024)throw new Error("That image is over 2MB.");return{...t,data:n.toString("base64")}}function oe(e){return{name:e.name,title:e.title,description:e.description,credentials:["account"],inputSchema:{type:"object",properties:{...e.properties,env_file:a("Default .env.local.")},required:e.required,additionalProperties:!1},run:async(t,{env_file:n,...r})=>{let o=typeof n=="string"?n:".env.local";if(!/^(\.env|\.dev\.vars)/.test(b.basename(o)))throw new Error("env_file must be an .env file or .dev.vars.");let s=b.resolve(o),l=M(b.dirname(s)),u=M(process.cwd());if(l!==u&&!l.startsWith(u+b.sep))throw new Error("env_file must be in this project.");await ne(s);let h=`/v1${e.route.replace(/:(\w+)/g,(S,A)=>encodeURIComponent(F(r,A)))}`,f=Object.fromEntries(Object.entries(r).filter(([S])=>!e.route.includes(`:${S}`))),g=await t.post(h,f);return await te(s,{[e.variable(r)]:g.key},"Soba"),`Made ${g.id} and wrote it to ${o} as ${e.variable(r)}. It was not shown.`}}}var Ee={api_key_env:a("The environment variable holding the key, e.g. OPENAI_API_KEY. Read from this machine; never pass the key itself."),env_file:a("Where that variable is, if not the environment. Default .env.local.")},se={name:a(),base_url:a("https, OpenAI-compatible. Not needed with a service."),cost_class:{type:"string",enum:["frontier","open-weights"]},max_cost_per_run:c("number","Dollars."),...Ee},v=a("From soba_list_providers."),ae={name:a(),kind:{type:"string",enum:["discount","grant","plan"]},discount_type:{type:"string",enum:["percent","fixed"]},amount:c("number","20 is 20%, or dollars when fixed."),duration_months:c("number"),plans:{type:["array","null"],items:{type:"string"}},first_time_only:p(),grants:{type:"array",items:{type:"object",properties:{feature:a(),name:a(),type:{type:"string",enum:["boolean","number","text"]},amount:c("number"),expiry_days:c("number")},required:["feature"]}},plan:a("The plan a plan reward gives, by id."),duration_days:{type:"number"},trigger:{type:"string",enum:["none","signup","first_connect"]},codes:{type:"array",description:"The whole list: one left out is removed.",items:{type:"object",properties:{code:a(),cap:c("number")},required:["code"]}}},ie={type:"string",enum:["admin","member","billing"]};function le(e,t){let{app:n,environment:r,...o}=t;if(e.kind==="setup")return{path:"/v1/manage/settings",environment:r?{environment:r}:{},rest:o};if(typeof n!="string"||!n)throw new Error("Say which app: pass its id as `app`. soba_list_apps lists them.");if(!r)throw new Error("Say which environment: development or production.");return{path:`/v1/apps/${encodeURIComponent(n)}/settings`,environment:{environment:r},rest:o}}var D={app:{...C,description:`${C.description} Not needed with a setup key.`},environment:{...d,description:"Required with an account; a setup key is development."}},ce=[{name:"soba_get_settings",title:"Read the app's settings",description:"Connect popup, model picker, which AI users may connect, and the app's limits, in one environment. The Models, Connect popup, Model picker and Settings pages.",credentials:["setup","account"],inputSchema:{type:"object",properties:D,additionalProperties:!1},run:async(e,t)=>{let n=le(e,t),r=e.kind==="account"?n.environment:{};return JSON.stringify(await $(e,"GET",n.path,r),null,2)}},{name:"soba_update_settings",title:"Change the app's settings",description:"Changes only what you send. connect_popup, model_picker, own_ai, ask_to_connect and connect_return_url belong to one environment; the rest hold in both and need an account.",credentials:["setup","account"],inputSchema:{type:"object",properties:{...D,connect_popup:{type:"object",properties:{theme:{type:"string",enum:["light","dark","system"]},accent:c("string","Hex, like #4F46E5. Null is the default."),background:c("string","Hex. The whole popup follows it."),logo:{type:"string",enum:["favicon","soba","custom","none"]},logo_url:c("string","https. Makes logo custom."),hosted:p(),show_code:p(),button:{type:"string",enum:["solid","outline"],description:"Continue with Soba: filled in the accent, or outlined."}},additionalProperties:!1},model_picker:{type:"object",properties:{users_choose:p("False is no picker."),menu:{type:"string",enum:["submenus","two_panes","tabs","single"]},presets:{type:"object",properties:{automatic:p(),fast:p(),best:p()},additionalProperties:!1},search:p(),effort:p("The Effort row under the models."),effort_style:{type:"string",enum:["switch","list"]},labels:p("False: logos alone for the AIs and providers."),suggested:p("False hides the Suggested group; true brings it back.")},additionalProperties:!1},own_ai:{type:["array","null"],items:{type:"string"},description:"AIs users may connect: claude, chatgpt, gemini, local\u2026 Null is the default (claude, chatgpt). [] turns users' own AI off: no run reaches it."},ask_to_connect:p("Ask to connect before using AI the app pays for."),connect_return_url:c("string"),name:a(),icon:c("string","An https image address or one emoji."),run_limit_minutes:c("number"),max_cost_per_run:c("number","Dollars, over every plan."),route_allow:{type:["array","null"],items:{type:"string"},description:"Cost classes the app may ever run on, over every plan. Null is all."},provider_failover:p("Try another of the app's providers when one fails."),outage_fallback:p("Use the app's providers while Soba is down. Lets a holder of the secret key fetch the provider keys: only when a person asked."),use_soba:p("Use Soba's compute for now, with no provider of the app's own.")},additionalProperties:!1},run:async(e,t)=>{let n=le(e,t),r=await $(e,"PATCH",n.path,{...n.environment,...n.rest});return`Saved. Settings are now:
|
|
308
|
+
${JSON.stringify(r,null,2)}`}},i("soba_list_workspaces","List workspaces","GET","/workspaces","Your workspaces."),i("soba_create_app","Create an app","POST","/workspaces/:workspace/apps","Makes an app. Counts against the tier's app limit.",{name:a()},["name"]),i("soba_list_keys","List keys","GET","/apps/:app/keys","The app's keys, as previews, and what each may spend a month."),oe({name:"soba_create_app_key",title:"Make a key",description:"Makes a secret key and writes it to the project's env file, never into the conversation. development is SOBA_KEY; production is SOBA_PROD_KEY.",route:"/apps/:app/keys",properties:{app:C,environment:d,replace_idle:p("Replace one never used.")},required:["app","environment"],variable:e=>e.environment==="production"?"SOBA_PROD_KEY":"SOBA_KEY"}),oe({name:"soba_create_workspace_key",title:"Make a workspace key",description:"Makes a key that makes apps and mints their keys, and writes it to the env file as SOBA_WORKSPACE_KEY. Only when a person asked for one.",route:"/workspaces/:workspace/keys",properties:{workspace:a("From soba_list_workspaces."),name:a()},required:["workspace"],variable:()=>"SOBA_WORKSPACE_KEY"}),i("soba_set_key_cap","Cap a key","PATCH","/apps/:app/keys/:key","The most a key may spend a month, in dollars. Null is no cap.",{key:a("From soba_list_keys."),monthly_cap:c("number")},["monthly_cap"]),i("soba_list_workspace_keys","List workspace keys","GET","/workspaces/:workspace/keys","By name. Never the keys."),i("soba_revoke_workspace_key","Revoke a workspace key","DELETE","/workspaces/:workspace/keys/:key","Anything using it stops at once. Only when a person asked.",{key:a()}),i("soba_get_billing","Read billing","GET","/workspaces/:workspace/billing","Whether the workspace is on a plan (live), its tier, the tiers and what they cost, card and invoices. No plan is needed to use production."),i("soba_go_live","Buy a plan","POST","/workspaces/:workspace/billing/go_live","Only when a person chooses a plan: production works without one, on the workspace's one-time free connected users. Answers with Stripe's page to pay for the plan. Give the person the link: never ask for card details or fill them in. Then call soba_get_billing until live is true.",{tier:a("The one a person chose, from soba_get_billing.")},["tier"]),i("soba_change_card","Change the card","POST","/workspaces/:workspace/billing/card","Answers with Stripe's page. Give the person the link."),i("soba_change_tier","Change the tier","POST","/workspaces/:workspace/billing/tier","Charges the card on file. Tell the person the fee and get a yes first. An owner only.",{tier:a(),confirm_fee:{type:"number",description:"The fee they agreed to."}},["tier","confirm_fee"]),i("soba_cancel_subscription","Cancel the subscription","POST","/workspaces/:workspace/billing/cancel","Ends with the period. Only when a person asked for exactly this.",{confirm:a("The workspace's name, which the person gave you.")},["confirm"]),i("soba_get_stripe","Read the Stripe connection","GET","/workspaces/:workspace/stripe","Whether the workspace's own Stripe is connected, which its users pay into.",{environment:d},["environment"]),i("soba_connect_stripe","Connect Stripe","POST","/workspaces/:workspace/stripe/connect","Answers with Stripe's screen. The person accepts it, signed in to Soba as themselves. Then call soba_get_stripe until connected is true.",{environment:d},["environment"]),i("soba_disconnect_stripe","Disconnect Stripe","DELETE","/workspaces/:workspace/stripe","Nobody can buy a plan after. Only when a person asked for exactly this.",{environment:d,confirm:a("The workspace's name, which the person gave you.")},["environment","confirm"]),i("soba_list_repricing","Subscribers on old prices","GET","/apps/:app/repricing","People still paying a plan's old price, waiting for a decision."),i("soba_decide_repricing","Keep or move subscribers","POST","/apps/:app/repricing","keep leaves them on the old price; move changes what they pay at their next renewal. Tell the person how many and from what to what, and get a yes first.",{old_price:a("From soba_list_repricing."),decision:{type:"string",enum:["keep","move"]},confirm_subscribers:{type:"number",description:"To move: how many they agreed to."}},["old_price","decision"]),i("soba_check_stripe","Check Stripe","POST","/apps/:app/stripe/check","Compares the app's plans with what is in Stripe."),i("soba_restore_stripe_plan","Restore a plan in Stripe","POST","/apps/:app/plans/:plan/stripe/restore","Puts a plan back where it was changed in Stripe directly.",{plan:a()}),i("soba_accept_stripe_change","Leave a change in Stripe","POST","/apps/:app/plans/:plan/stripe/accept","Leaves a change somebody made in Stripe.",{plan:a(),kind:a("As the check reported it.")},["kind"]),i("soba_try_checkout","Try checkout","POST","/apps/:app/plans/:plan/try_checkout","A checkout link for a plan, as a preview buyer. In live mode paying it takes real money.",{plan:a()}),i("soba_set_seats","Set a seat count","PUT","/apps/:app/plans/:plan/seats","Corrects how many seats one user is billed for. Only with a number a person gave you.",{plan:a(),user:a("Your id for them."),quantity:{type:"number"}},["user","quantity"]),i("soba_set_logo","Set a logo from a file","PUT","/apps/:app/logo","The app's icon, or one environment's connect popup logo. PNG, JPEG, GIF, WebP or SVG, up to 2MB.",{file:a("The image's path in this project."),use:{type:"string",enum:["icon","connect_popup"]},environment:{...d,description:"With connect_popup."}},["file"],U),i("soba_set_custom_model_logo","Set a custom model's logo","PUT","/apps/:app/custom_models/:alias/logo","From an image file.",{alias:a(),file:a("The image's path in this project.")},["file"],U),i("soba_set_workspace_logo","Set the workspace's picture","PUT","/workspaces/:workspace/logo","From an image file.",{file:a("The image's path in this project.")},["file"],U),i("soba_update_workspace","Rename the workspace","PATCH","/workspaces/:workspace/settings","Its name, or its picture as an https address or one emoji.",{name:a(),icon:c("string")}),i("soba_transfer_workspace","Transfer the workspace","POST","/workspaces/:workspace/transfer","Hands it over; the owner becomes an admin. Only when the owner asked for exactly this.",{member:a("Their id or email."),confirm:a("The workspace's name, which they gave you.")},["member","confirm"]),i("soba_delete_workspace","Delete the workspace","POST","/workspaces/:workspace/delete","Deletes every app, user, run and key in it. It cannot come back. Only when the owner asked for exactly this and gave you its name.",{confirm:a("The workspace's name, which they gave you.")},["confirm"]),i("soba_update_app","Rename an app","PATCH","/apps/:app","Its name.",{name:a()},["name"]),i("soba_delete_app","Delete an app","DELETE","/apps/:app","Deletes the app and everything that is its. It cannot come back. Only when a person asked for exactly this."),{name:"soba_pair_machine",title:"Pair your machine",description:"A link that pairs the person's own machine with the app, as its first user. They open it and approve it in the Soba app.",credentials:["setup","account"],inputSchema:{type:"object",properties:{app:D.app},additionalProperties:!1},run:async(e,t)=>{let n=e.kind==="setup"?"/v1/manage/pairing":`/v1/apps/${encodeURIComponent(F(t,"app"))}/pairing`,{url:r}=await e.post(n,{});return`Give the person this link, to open and approve themselves: ${r}`}},i("soba_revoke_key","Revoke a key","DELETE","/apps/:app/keys/:key","Anything using it stops at once. Only when a person asked for it.",{key:a("From soba_list_keys.")}),i("soba_list_providers","List providers","GET","/apps/:app/providers","The AI accounts the app pays for, with their models. Keys are never shown."),i("soba_list_provider_services","List known services","GET","/apps/:app/providers/services","OpenAI, Anthropic, Groq and the rest: what soba_add_provider takes as `service`."),i("soba_add_provider","Add a provider","POST","/apps/:app/providers","Adds an AI account the app pays for, used when a user's own AI can't serve a run. This spends the app's money, so only when a person asked.",{service:a("From soba_list_provider_services."),...se},[],re),i("soba_update_provider","Change a provider","PATCH","/apps/:app/providers/:provider","Changes what you send. A different host in base_url needs api_key_env with it.",{provider:v,enabled:p(),...se},[],re),i("soba_remove_provider","Remove a provider","DELETE","/apps/:app/providers/:provider","Removes it, its key and its models. Only when a person asked for it.",{provider:v}),i("soba_clear_provider_key","Forget a provider's key","DELETE","/apps/:app/providers/:provider/key","Forgets the stored key and keeps the provider. Only when a person asked for it.",{provider:v}),i("soba_order_providers","Order providers","PUT","/apps/:app/providers/order","The order they are tried in, first tried first.",{providers:{type:"array",items:{type:"string"}}},["providers"]),i("soba_list_available_models","What a provider offers","GET","/apps/:app/providers/:provider/available","Asks the provider which models it serves.",{provider:v}),i("soba_set_provider_model","Add or change a model","PUT","/apps/:app/providers/:provider/models","Adds a model to a provider, or changes how users see it. Prices are looked up unless sent.",{provider:v,model:a("The provider's own id for it."),input_per_mtok:{type:"number"},output_per_mtok:{type:"number"},alias:c("string"),label:c("string","The name users see. Needs an alias."),note:c("string"),shown:p("In the model picker."),is_default:p(),tier:{type:["string","null"],enum:["fast","best",null]}},["model"]),i("soba_remove_provider_model","Remove a model","DELETE","/apps/:app/providers/:provider/models","Takes one model off a provider.",{provider:v,model:a()},["model"]),i("soba_list_custom_models","List custom models","GET","/apps/:app/custom_models","The app's own names over models from its providers."),i("soba_set_custom_model","Make or change a custom model","PUT","/apps/:app/custom_models/:alias","One name users pick over one or more models. With a percent on every model (coming to 100) runs are split; without, they are tried in order.",{alias:a("Lowercase and dashes. Fixed once made."),label:a("The name users see."),note:c("string"),icon:c("string"),is_default:p("What a user who picked nothing starts on."),models:{type:"array",items:{type:"object",properties:{provider:a(),model:a(),percent:c("number")},required:["provider","model"]}}}),i("soba_remove_custom_model","Remove a custom model","DELETE","/apps/:app/custom_models/:alias","Takes the name away. Its models stay.",{alias:a()}),i("soba_list_rewards","List rewards","GET","/apps/:app/rewards","Discounts, grants and free plans, with their codes.",{environment:d}),i("soba_create_reward","Create a reward","POST","/apps/:app/rewards","Only with amounts a person gave you.",{environment:d,...ae},["environment","name","kind"]),i("soba_update_reward","Change a reward","PATCH","/apps/:app/rewards/:reward","Changes what you send. Only with amounts a person gave you.",{reward:a("Its id or slug."),environment:d,...ae}),i("soba_archive_reward","Archive a reward","DELETE","/apps/:app/rewards/:reward","Its codes stop working; who holds it keeps it. Only when a person asked.",{reward:a(),environment:d}),i("soba_give_user_reward","Give a user a reward","POST","/apps/:app/rewards/:reward/give","Once per user per reward. Only when a person asked for that user to get it.",{reward:a(),user:a("Your id for them, or Soba's."),environment:d},["user"]),i("soba_sync_stripe","Put plans in Stripe","POST","/apps/:app/stripe/sync","Puts the app's paid plans into the workspace's connected Stripe now."),i("soba_list_users","List users","GET","/apps/:app/users","The app's users.",{environment:d,...N}),i("soba_get_user","Read a user","GET","/apps/:app/users/:user","Their plan, usage, machines and latest runs.",{user:a("Your id for them, or Soba's."),environment:d}),i("soba_set_user_plan","Put a user on a plan","PATCH","/apps/:app/users/:user","A paid plan given here is a gift: nothing is billed. Null takes their plan away, which leaves them with no limit. Only when a person asked for that user.",{user:a(),plan:c("string","A plan id, or null."),environment:d},["plan"]),i("soba_list_machines","List machines","GET","/apps/:app/machines","Users' machines.",{environment:d,...N}),i("soba_get_machine","Read a machine","GET","/apps/:app/machines/:machine","One machine and the AI on it.",{machine:a()}),i("soba_list_runs","List runs","GET","/apps/:app/runs","Runs with totals, speed and cost. Never what was said in them.",{environment:d,range:a("1d, 7d, 30d, 90d or all."),status:a(),class:a("A cost class."),model:a(),error:a(),...N}),i("soba_get_run","Read a run","GET","/apps/:app/runs/:run","One run.",{run:a()}),i("soba_get_activations","Read activations","GET","/apps/:app/activations","Users activated this period."),i("soba_get_overview","Read the overview","GET","/apps/:app/overview","Users, runs, what was spent and what was saved.",{environment:d}),i("soba_list_members","List members","GET","/workspaces/:workspace/members","Who is in the workspace, and open invites."),i("soba_invite_member","Invite somebody","POST","/workspaces/:workspace/invites","Emails an invitation. Only when a person named who to invite.",{email:a(),role:ie},["email"]),i("soba_revoke_invite","Revoke an invite","DELETE","/workspaces/:workspace/invites/:invite","Its link stops working.",{invite:a()}),i("soba_set_member_role","Change a member's role","PATCH","/workspaces/:workspace/members/:member","Only when a person asked. Owners are changed in the dashboard.",{member:a("Their id or email."),role:ie},["role"]),i("soba_remove_member","Remove a member","DELETE","/workspaces/:workspace/members/:member","Ends their access. Only when a person asked.",{member:a("Their id or email.")})];var P={type:"object",properties:{},additionalProperties:!1},Re=["user-subscription","user-hardware","user-api-key","open-weights","frontier"],w={app:{type:"string",description:"The app's id, from soba_list_apps. Not needed with a setup key."},environment:{type:"string",enum:["development","production"],description:"Which catalogue. Required to create with an account credential; a setup key is development only."}},pe={type:"string",description:"The plan's id, from soba_list_plans."},de={name:{type:"string"},description:{type:"string"},price:{type:"number",description:"Dollars a month. 0 is a free plan."},unit:{type:"string",enum:["run","task","token","cost","credit"],description:"What both allowances are counted in. `cost` counts hundredths of a cent (10,000 to the dollar); a token or cost overage price is per 1M tokens or per $1."},included_units:{type:["number","null"],description:"Runs a month on AI the app pays for (open-weights, frontier). Null is unlimited."},trial_days:{type:"number"},route_prefer:{type:"array",items:{type:"string",enum:["user-subscription","user-hardware","user-api-key","open-weights","frontier"]},description:"What a run may use, best first. This is also the ceiling: a class left out can never be billed to this app."},max_cost_per_run:{type:["number","null"],description:"Dollars one run may cost."},own_included_units:{type:["number","null"],description:"Runs a month on the user's own AI (their machine, subscription or key), counted apart from included_units. Null is unlimited."},own_unit:{type:["string","null"],enum:["run","task","token","cost","credit",null],description:"What own_included_units counts, when not unit: a hybrid plan gives 200 runs on the user's own AI and 2,000 credits on yours. Null means the same as unit."},connected_reward:{type:"string",enum:["none","included","credit"]},connected_included_units:{type:["number","null"]},connected_credit:{type:["number","null"]},route_allow:{type:"array",items:{type:"string",enum:Re},description:"Classes allowed but not ranked, on top of route_prefer."},overage_per_unit:{type:["number","null"],description:"Dollars past the allowance, on a cost or credit plan."},meter:{type:"boolean",description:"On a run, task or token plan: keep going past the allowance, at cost plus markup_percent."},byo_overage:{type:"string",enum:["stop","meter"],description:"When the own-AI allowance is spent: stop, or continue on AI the app pays for."},markup_percent:{type:"number"},markup_overrides:{type:"object",additionalProperties:{type:"number"},description:"Percent per model vendor, over markup_percent."},credits_per_dollar:{type:"number",description:"Credits $1 of AI cost uses."},credit_price:{type:["number","null"],description:"Dollars per 1,000 credits."},credit_packs:{type:["array","null"],items:{type:"object",properties:{credits:{type:"number"},price:{type:"number"}},required:["credits","price"],additionalProperties:!1}},credit_expiry:{type:"string",enum:["never","month_end"]},task_noun:{type:["string","null"],description:"What the app calls a run, plural."},contact_url:{type:["string","null"],description:'A "Talk to us" link (https:// or mailto:). The price becomes 0.'},sold_elsewhere:{type:"boolean",description:"True when the app already sells this tier through its own Stripe checkout. Soba then writes no Stripe price for it and opens no checkout; subscriptions are linked with POST /v1/plans/link."},stripe_prices:{type:"array",items:{type:"string"},description:"The app's own Stripe price ids for this tier (price_...). Subscriptions on them link to this plan by themselves when the app's checkout puts soba_user (or a team's soba_customer) in the subscription's or customer's metadata. Implies sold_elsewhere. Existing subscribers link right after saving; soba_sync_stripe_subscriptions reports them."},features:{type:"array",description:"What the app itself enforces, shown on the pricing card.",items:{type:"object",properties:{id:{type:"string",description:"snake_case; the app's code reads it."},name:{type:"string"},type:{type:"string",enum:["boolean","number","text"]},value:{type:["boolean","number","string","null"],description:"Null is unlimited, on a number."},unit:{type:"string"},resets:{type:"string",enum:["month"]},price:{type:"object",description:"Per-unit pricing (seats). amountMicros is millionths of a dollar.",properties:{amountMicros:{type:"number"},included:{type:"number"}},required:["amountMicros","included"]}},required:["id","name","type","value"]}}},Ie={is_default:{type:"boolean",description:"Where new users start. A free plan only."},is_popular:{type:"boolean",description:'Shown as "Most popular".'}};function k(e,t){let{app:n,environment:r,plan:o,...s}=t;if(e.kind==="account"&&(typeof n!="string"||!n))throw new Error("Say which app: pass its id as `app`. soba_list_apps lists them.");return{path:e.kind==="setup"?"/v1/manage/plans":`/v1/apps/${encodeURIComponent(n)}/plans`,fields:s,plan:()=>{if(typeof o!="string"||!o)throw new Error("Say which plan: pass its id as `plan`. soba_list_plans lists them.");return encodeURIComponent(o)}}}function B(e,t){if(t.environment)return{environment:t.environment};if(e.kind==="setup")return{};throw new Error("Say which environment: development or production.")}function he(e){let t=e.steps.map(r=>`${r.done?"[x]":"[ ]"} ${r.title} \u2014 ${r.state}`),n=e.complete?"Every step is done. Nothing here needs you again.":`Next: ${e.next}. Call soba_next_step for what to do.`;return`${t.join(`
|
|
588
309
|
`)}
|
|
589
310
|
|
|
590
|
-
${n}`}function
|
|
311
|
+
${n}`}function Me(e,t){return e.steps.find(n=>n.id===t)}var Ce=[{name:"soba_status",title:"Read the setup checklist",description:"Soba's setup checklist for this app and which steps are done. Call this first, and again after every change, so you are acting on what is true rather than on what you did last.",inputSchema:P,run:async e=>he(await e.get("/v1/manage/progress"))},{name:"soba_next_step",title:"What to do next",description:"The first outstanding step, with an instruction written for you. Do what it says using your own tools \u2014 read the repo, make the edits, show the diff. Then call soba_status again to confirm it took.",inputSchema:P,run:async e=>{let t=await e.get("/v1/manage/progress");if(t.complete)return"Setup is complete. There is nothing to do.";let n=Me(t,t.next);return n?n.effect==="human"?n.id==="price"?`Next: ${n.title}
|
|
591
312
|
|
|
592
313
|
${n.lede}
|
|
593
314
|
|
|
@@ -612,5 +333,5 @@ When you are done, call soba_status to confirm it registered.`:he(t)}},{name:"so
|
|
|
612
333
|
SOBA_KEY=${n.key}
|
|
613
334
|
|
|
614
335
|
This is the only time it exists. Put it in .env.local now.`}},{name:"soba_set_connect_url",title:"Point Connect back at the app",description:"Sets where someone who started pairing in their terminal gets sent to sign in. It must be the public https page that renders <ConnectCompute />. If no such page exists yet, do not guess one \u2014 build the page first.",inputSchema:{type:"object",properties:{url:{type:"string",description:"The https URL of the page. Loopback is allowed in development."}},required:["url"],additionalProperties:!1},run:async(e,t)=>(await e.patch("/v1/manage/app",{connect_return_url:t.url}),`Connect now returns to ${t.url}.`)},{name:"soba_set_model_picker",title:"Set the model picker",description:"Sets the <ModelPicker /> the app's users see, the same card as the dashboard's Model Picker. users_choose false means no picker: every message uses Automatic. menu is how providers are laid out. presets are the rows at the top. Send only what should change; the answer is the whole state after it. A prop in the app's code still wins over this.",inputSchema:{type:"object",properties:{users_choose:{type:"boolean",description:"Whether the app's users get a picker at all."},menu:{type:"string",enum:["submenus","two_panes","tabs","single"],description:"submenus: each provider opens beside the menu. two_panes: providers left, models right. tabs: a tab per provider."},presets:{type:"object",properties:{automatic:{type:"boolean"},fast:{type:"boolean"},best:{type:"boolean"}},additionalProperties:!1,description:"Which of Automatic, Fast and Best head the menu."},search:{type:"boolean",description:"A search field once the list is long enough to need one."},effort:{type:"boolean",description:"An Effort row (Auto, Low, Medium, High, Extra, Max) for models that take it. On by default."},effort_style:{type:"string",enum:["switch","list"],description:"Effort as a row of steps (switch) or rows with a tick (list). Default: list in two_panes and tabs, switch elsewhere."},suggested:{type:"boolean",description:"False hides the Suggested group (every preset off); true brings it back with all three when none is on."},labels:{type:"boolean",description:"False: the AIs and providers as their logos alone, the name on hover. On by default."}},additionalProperties:!1},run:async(e,t)=>{let r=(await e.patch("/v1/manage/app",{model_picker:t})).model_picker;if(!r.users_choose)return"No picker: every message uses Automatic.";let o=["automatic","fast","best"].filter(s=>r.presets[s]);return`Picker on, ${(r.menu??"submenus").replace("_"," ")}. Presets: ${o.length?o.join(", "):"none"}. Search ${r.search?"on":"off"}. Effort ${r.effort!==!1?"on":"off"}${r.effort_style?` (${r.effort_style})`:""}. Labels ${r.labels!==!1?"on":"off"}.`}},{name:"soba_use_soba",title:"Just use Soba for now",description:"Answers the Providers step: Soba supplies the runs no user's AI serves, and the step ticks. The default unless the person asked to use their own model account. Adding a provider later takes over without undoing this.",inputSchema:P,run:async e=>(await e.patch("/v1/manage/app",{compute_skipped:!0}),"Soba will supply those runs. Call soba_status to confirm the step ticked.")},{name:"soba_list_apps",title:"List apps",description:"Every app you can reach, by workspace, with the id the plan tools take.",credentials:["account"],inputSchema:P,run:async e=>{let{data:t}=await e.get("/v1/workspaces"),n=[];for(let r of t){let o=await e.get(`/v1/workspaces/${r.id}/apps`);n.push(`${r.name}:`,...o.data.map(s=>` ${s.name} \u2014 ${s.id}`))}return n.join(`
|
|
615
|
-
`)||"No workspaces."}},{name:"soba_list_plans",title:"List plans",description:"The app's live plans with every field, as JSON. Read this before changing one. A setup key sees its own environment, development.",credentials:["setup","account"],inputSchema:{type:"object",properties:{...
|
|
616
|
-
${JSON.stringify(s,null,2)}`}},{name:"soba_archive_plan",title:"Archive a plan",description:"Takes a plan off sale. Users already on it keep it, and its history stays. Only when a person asked for this plan to go: there is no tool to bring it back.",credentials:["setup","account"],inputSchema:{type:"object",properties:{app:
|
|
336
|
+
`)||"No workspaces."}},{name:"soba_list_plans",title:"List plans",description:"The app's live plans with every field, as JSON. Read this before changing one. A setup key sees its own environment, development.",credentials:["setup","account"],inputSchema:{type:"object",properties:{...w},additionalProperties:!1},run:async(e,t)=>{let{path:n}=k(e,t),r=e.kind==="account"&&t.environment,o=r?`?environment=${encodeURIComponent(String(r))}`:"",{data:s}=await e.get(`${n}${o}`);return s.length?JSON.stringify(s,null,2):"No plans yet."}},{name:"soba_create_free_plan",title:"Create the free plan",description:'Adds the free "Bring your own" plan: unlimited runs on the AI each user connects, at no cost to the app, and the plan new users start on. The default for an app with no plans. Refused if the app already has one.',credentials:["setup","account"],inputSchema:{type:"object",properties:{...w},additionalProperties:!1},run:async(e,t)=>{let{path:n}=k(e,t),r=await e.post(n,{...B(e,t),template:"byo"});return e.kind==="setup"?`Created the plan "${r.name}". Call soba_status to confirm the steps ticked.`:`Created the plan "${r.name}".`}},{name:"soba_create_plan",title:"Create a plan",description:"Creates a plan: the price, the allowance, what a run may fall back to, and what connecting a machine earns back. Only call this with numbers a person gave you. Do not invent a price. A production plan is on sale at once.",credentials:["setup","account"],inputSchema:{type:"object",properties:{...w,...de},required:["name","price","route_prefer"],additionalProperties:!1},run:async(e,t)=>{let{path:n,fields:r}=k(e,t),o=await e.post(n,{...B(e,t),...r}),s=o.environment?` in ${o.environment}`:"";return`Created the plan "${o.name}"${s}${o.id?` (${o.id})`:""}.`}},{name:"soba_update_plan",title:"Change a plan",description:"Changes the fields you send on one plan and leaves the rest. Only with numbers a person gave you. Sending route_prefer also sets the ceiling to it. Sending features replaces the whole list.",credentials:["setup","account"],inputSchema:{type:"object",properties:{app:w.app,plan:pe,...de,...Ie},required:["plan"],additionalProperties:!1},run:async(e,t)=>{let{path:n,fields:r,plan:o}=k(e,t),s=await e.patch(`${n}/${o()}`,r);return`Updated. The plan is now:
|
|
337
|
+
${JSON.stringify(s,null,2)}`}},{name:"soba_archive_plan",title:"Archive a plan",description:"Takes a plan off sale. Users already on it keep it, and its history stays. Only when a person asked for this plan to go: there is no tool to bring it back.",credentials:["setup","account"],inputSchema:{type:"object",properties:{app:w.app,plan:pe},required:["plan"],additionalProperties:!1},run:async(e,t)=>{let{path:n,plan:r}=k(e,t);return await e.delete(`${n}/${r()}`),"Archived."}},{name:"soba_sync_stripe_subscriptions",title:"Link existing Stripe subscriptions",description:"Links every active subscription on the app's plans' stripe_prices to its plan, and lists the ones with no soba_user (or soba_customer) in their metadata, which need soba.plans.link(). Safe to repeat.",credentials:["setup","account"],inputSchema:{type:"object",properties:{app:w.app,environment:w.environment},additionalProperties:!1},run:async(e,t)=>{let{path:n}=k(e,t),r=await e.post(`${n}/sync`,B(e,t));return JSON.stringify(r,null,2)}},{name:"soba_give_reward",title:"Give a user a reward",description:"Gives one user a reward the app already has \u2014 money off, extra AI usage, or a plan for some days. Once per user per reward. Only call this when a person asked for that user to get it.",inputSchema:{type:"object",properties:{reward:{type:"string",description:"The reward's ID, e.g. early_bird."},user:{type:"string",description:"The app's own id for the user."}},required:["reward","user"],additionalProperties:!1},run:async(e,t)=>(await e.post("/v1/manage/rewards/give",t),`Gave ${t.user} the reward ${t.reward}.`)}],me=e=>[...Ce,...ce].filter(t=>(t.credentials??["setup"]).includes(e));var Le="https://soba.so",Ne="2025-06-18",Ue="0.0.12";function De(e){let t={token:process.env.SOBA_MANAGEMENT_KEY??null,baseUrl:process.env.SOBA_MANAGE_URL??Le},n=!1,r=!!process.env.SOBA_MANAGE_URL;for(let o=0;o<e.length;o++){let s=e[o];s==="--token"?t.token=e[++o]??null:s?.startsWith("--token=")?t.token=s.slice(8):s==="--account"?n=!0:s==="--url"?(t.baseUrl=e[++o]??t.baseUrl,r=!0):s?.startsWith("--url=")&&(t.baseUrl=s.slice(6),r=!0)}if(t.token||(t.token=process.env.SOBA_ACCESS_TOKEN||process.env.SOBA_WORKSPACE_KEY||null),!t.token&&n)try{let o=process.env.SOBA_CONFIG_DIR||fe.join(Oe.homedir(),".soba"),s=JSON.parse(Pe(fe.join(o,"cli.json"),"utf8")),l=new URL(s.url).origin;r&&new URL(t.baseUrl).origin!==l&&(m(`this terminal is signed in to ${l}, not ${t.baseUrl}.`),process.exit(2)),t.token=s.token??null,t.baseUrl=l}catch{m("this terminal is not signed in. Run `npx @soba-so/cli login` first."),process.exit(2)}return t.baseUrl=t.baseUrl.replace(/\/+$/,""),t}var j=De(process.argv.slice(2)),W=j.token;W||(m("no management key. Pass --token mk_soba_\u2026 or set SOBA_MANAGEMENT_KEY."),m("Mint one in your Soba dashboard, on the Set up page. Or pass --account to use"),m("this terminal's `soba login`, for plans in any app and environment."),process.exit(2));/^(mk|pat|wk)_soba_/.test(W)||(m("that is not a management key. It starts with mk_soba_ (or pat_/wk_soba_), and sk_soba_ is a"),m("different credential \u2014 your app's secret key. Do not paste that here."),process.exit(2));var _=new x(W,j.baseUrl),K=me(_.kind),$e=new Map(K.map(e=>[e.name,e])),ge=_.kind==="setup"?L:[];X(async(e,t)=>{switch(e){case"initialize":return{protocolVersion:Ne,capabilities:{tools:{},prompts:{}},serverInfo:{name:"soba",version:Ue},instructions:_.kind==="account"?"Soba, in any app you can reach: settings, models, plans, users. Call soba_list_apps for the app, and read what is there before changing it. Prices are a person's to decide, and a production plan is on sale at once: confirm it with them first.":"Soba's setup checklist. Call soba_status first, then soba_next_step, and do what it says with your own tools \u2014 the repo is yours to edit, not this server's. Call soba_status again afterwards to confirm the step registered rather than assuming it did."};case"notifications/initialized":case"notifications/cancelled":return{};case"ping":return{};case"prompts/list":return{prompts:ge.map(n=>({name:n.name,title:n.title,description:n.description}))};case"prompts/get":{let n=typeof t.name=="string"?t.name:"",r=_.kind==="setup"?J.get(n):void 0;if(!r)throw new Error(`no such prompt: ${n}`);return{description:r.description,messages:[{role:"user",content:{type:"text",text:r.text}}]}}case"tools/list":return{tools:K.map(n=>({name:n.name,title:n.title,description:n.description,inputSchema:n.inputSchema}))};case"tools/call":{let n=typeof t.name=="string"?t.name:"",r=$e.get(n);if(!r)return q(`no such tool: ${n}`);let o=t.arguments??{};try{return{content:[{type:"text",text:await r.run(_,o)}]}}catch(s){return s instanceof y?q(Fe(s)):q(s instanceof Error?s.message:String(s))}}default:throw new Error("method not found")}});function q(e){return{content:[{type:"text",text:e}],isError:!0}}function Fe(e){return e.status===401?_.kind==="account"?"Soba refused the credential. It expired or was revoked: run `npx @soba-so/cli login`.":"Soba refused the management key. It may have been revoked, or it may belong to a different app. Mint a new one on the Set up page.":e.message}m(`ready \u2014 ${K.length} tools, ${ge.length} prompt against ${j.baseUrl}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soba-so/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Sets Soba up from inside your coding agent: it reads the checklist, does the next step, and reads it back.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"homepage": "https://soba.so/docs/quickstart",
|