@soba-so/mcp 0.0.3 → 0.0.5

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.
Files changed (2) hide show
  1. package/dist/mcp.mjs +364 -155
  2. package/package.json +1 -1
package/dist/mcp.mjs CHANGED
@@ -1,13 +1,28 @@
1
1
  #!/usr/bin/env node
2
- var u=class extends Error{constructor(e,r){super(r);this.status=e;this.name="ApiError"}},c=class{constructor(t,e){this.token=t;this.baseUrl=e}get(t){return this.call("GET",t)}post(t,e){return this.call("POST",t,e)}patch(t,e){return this.call("PATCH",t,e)}async call(t,e,r){let s=await fetch(`${this.baseUrl}${e}`,{method:t,headers:{authorization:`Bearer ${this.token}`,...r===void 0?{}:{"content-type":"application/json"}},body:r===void 0?void 0:JSON.stringify(r)}),o=await s.text(),i=null;try{i=o?JSON.parse(o):null}catch{throw new u(s.status,`${t} ${e} did not return json (${o.slice(0,120)})`)}if(!s.ok){let l=i?.error;throw new u(s.status,typeof l=="string"?l:`${t} ${e} failed with ${s.status}`)}return i}};var y=36e5,b=24*y,B={returnAfterMs:24*y,expiryMs:30*b,uniquenessMs:365*b};var H=10*6e4;var M=864e5,E=30,ee={abandonedAfterMs:E*M};var re=30*24*60*60*1e3;var oe=5*60*1e3;var _e=60*6e4;var T="https://soba.so/skill",ve=`npx skills add ${T}`;var w=`Soba is the LLM layer for an application whose users bring their own compute.
2
+ var u=class extends Error{constructor(e,r){super(r);this.status=e;this.name="ApiError"}},c=class{constructor(t,e){this.token=t;this.baseUrl=e}get(t){return this.call("GET",t)}post(t,e){return this.call("POST",t,e)}patch(t,e){return this.call("PATCH",t,e)}async call(t,e,r){let s=await fetch(`${this.baseUrl}${e}`,{method:t,headers:{authorization:`Bearer ${this.token}`,...r===void 0?{}:{"content-type":"application/json"}},body:r===void 0?void 0:JSON.stringify(r)}),o=await s.text(),i=null;try{i=o?JSON.parse(o):null}catch{throw new u(s.status,`${t} ${e} did not return json (${o.slice(0,120)})`)}if(!s.ok){let l=i?.error;throw new u(s.status,typeof l=="string"?l:`${t} ${e} failed with ${s.status}`)}return i}};var w=36e5,b=24*w,$={returnAfterMs:24*w,expiryMs:30*b,uniquenessMs:365*b};var H=10*6e4;var M=864e5,E=30,ee={abandonedAfterMs:E*M};var re=30*24*60*60*1e3;var oe=5*60*1e3;var _e=60*6e4;var T="https://soba.so/skill",xe=`npx skills add ${T}`;var y=`Soba is the LLM layer for an application whose users bring their own compute.
3
3
  Requests go to Soba instead of to a model provider; Soba routes each one to the
4
4
  machine or plan belonging to the user it names, meters it, and bills for it.
5
5
 
6
- ## The two edits
6
+ ## How an integration is shaped
7
7
 
8
- Two edits make a Soba app work. Everything after them makes it worth having, and
9
- an app that stops at two has nowhere for a run to land \u2014 so do these first, then
10
- keep going.
8
+ Every app, whatever it is \u2014 a chat, one AI button, a background job with a
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.
18
+
19
+ Each surface has a component and a hook. **Mount the component**; build from
20
+ the hook only when the person asks for their own markup, and then show
21
+ everything the component would (see "Component or hook"). The integration is
22
+ finished when every surface in the required list exists, not when the first
23
+ request succeeds.
24
+
25
+ ## The server
11
26
 
12
27
  ### 1. Point every LLM call site at Soba
13
28
 
@@ -16,7 +31,8 @@ keep going.
16
31
 
17
32
  An OpenAI client already speaks this, so on most projects the base URL is the
18
33
  only line that changes. Prompts, tools, streaming and error handling stay
19
- exactly as they are.
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.
20
36
 
21
37
  Pass the signed-in user's id as the \`user\` field on every request.
22
38
 
@@ -27,26 +43,48 @@ is the one line in the integration that must not be guessed at: if the project's
27
43
  auth is not obvious, read it until it is, or stop and ask. A wrong id here does
28
44
  not throw \u2014 it silently pairs runs to the wrong person.
29
45
 
30
- ### Where the key comes from
46
+ **Derive it from something that outlives the database.** A primary key minted
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\`.
53
+
54
+ ### 2. Where the key comes from
31
55
 
32
- If \`.env.local\` already sets \`SOBA_KEY\`, use it. Otherwise run this from the
33
- project root:
56
+ If \`.env.local\` already sets \`SOBA_KEY\`, use it. Otherwise sign the terminal in,
57
+ from the project root:
34
58
 
35
59
  \`\`\`bash
36
- npx -y @soba-so/cli login
60
+ npx -y @soba-so/cli login --no-link
37
61
  \`\`\`
38
62
 
39
- It opens the person's browser, they pick the app, and it writes \`SOBA_KEY\` (a
40
- development key, for this machine) and \`SOBA_PROD_KEY\` (production) into
41
- \`.env.local\`, adding that file to \`.gitignore\` if git would commit it. The key
42
- never passes through you. Tell the person to approve in the browser before you
43
- run it; it waits up to fifteen minutes for them, so give the command a long
44
- timeout or run it in the background. Add \`--headless\` where no browser can
45
- open, and pass the link it prints on to the person.
63
+ It opens the person's browser once, they approve, and the terminal keeps a token
64
+ of its own; no key passes through you. Tell the person to approve before you run
65
+ it; it waits up to fifteen minutes, so give the command a long timeout or run it
66
+ in the background. Add \`--headless\` where no browser can open, and pass the
67
+ link it prints on to the person.
68
+
69
+ Then find out which app this project is. \`npx -y @soba-so/cli apps\` lists
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:
72
+
73
+ \`\`\`bash
74
+ npx -y @soba-so/cli link --workspace "<workspace>" --app "<app>"
75
+ npx -y @soba-so/cli link --workspace "<workspace>" --new "<name>" # a new app
76
+ \`\`\`
77
+
78
+ That writes \`SOBA_KEY\` (a development key, for this machine), \`SOBA_PROD_KEY\`
79
+ (production) and \`SOBA_APP_ID\` into \`.env.local\`, adding that file to
80
+ \`.gitignore\` if git would commit it. With nobody at the terminal the CLI never
81
+ waits on a question: a choice it needs ends the command with the flag to pass.
82
+ Every command is on \`https://soba.so/docs/reference/cli\`.
46
83
 
47
84
  \`.env.local\` is right for Next.js, Vite and most Node servers. Where the code
48
85
  that holds the key reads a different file, pass that file with \`--env-file\`
49
- instead, from the project root, so the key lands where the server will look:
86
+ to \`link\` instead, from the project root, so the key lands where the server
87
+ will look:
50
88
 
51
89
  | Server | File |
52
90
  |---|---|
@@ -69,133 +107,277 @@ doing it.
69
107
  If you cannot run commands but have a \`soba_create_key\` tool, call it: the
70
108
  secret is returned once and nothing can show it again, so write it into
71
109
  \`.env.local\` in the same step. Failing both, ask the person to run the command
72
- above themselves. Do not leave \`SOBA_KEY\`
73
- empty and do not invent a value; both fail at the first request, and the first
74
- fails as an auth error rather than as a missing variable.
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.
75
113
 
76
114
  Put \`SOBA_KEY\` in \`.env.local\` (or the server's own file, above), and check
77
- that file is gitignored before writing it. Never in \`.env\`, never in \`.env.example\`, never in anything
78
- tracked, and never echoed back to the terminal.
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.
79
117
 
80
- ### 2. Mount the connect component
118
+ ### 3. The session route
81
119
 
82
- On the page where a user manages their own account, so they can connect a
83
- machine of their own:
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.
84
125
 
85
- \`\`\`jsx
86
- import { SobaProvider, ConnectCompute } from "@soba-so/react";
126
+ ### 4. Pass Soba's answer through
87
127
 
88
- // Wherever a user manages their own account.
89
- <SobaProvider sessionEndpoint="/api/soba/session">
90
- <ConnectCompute />
91
- </SobaProvider>
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
+ }
92
143
  \`\`\`
93
144
 
94
- Back it with \`POST /api/soba/session\`, a route in the customer's own app that
95
- proxies \`POST /v1/end_users/session\` using the secret key and the same
96
- server-resolved user id. It returns a short-lived \`est_\` credential. The
97
- browser never sees \`SOBA_KEY\`.
145
+ A route that streams has to do this before the first byte is written: create
146
+ the completion (or start the run) first, and only then return the stream. In
147
+ the browser, keep the parsed body (\`setError(await res.json())\`) rather than
148
+ its text; that object is what the surfaces read. Branch on the code, never on
149
+ the message.
98
150
 
99
- Alongside it, \`<ComputeStatus />\`: asleep, offline, signed out of its CLI, or
100
- serving a run right now. When the compute is the user's own machine, the state of
101
- that machine is user-facing: they are the only one who can do anything about it.
151
+ ### 5. Which API
102
152
 
103
- If there is no settings page yet, build one. Do not point the connect return URL
104
- at a page that does not render \`<ConnectCompute />\`.
153
+ \`chat/completions\` is stateless and the caller owns the loop, so it reaches
154
+ models. Reaching a user's own Claude or ChatGPT subscription means letting Soba
155
+ own the loop instead:
105
156
 
106
- ## The rest of the components, which are not optional in practice
157
+ \`\`\`js
158
+ import { Soba } from "@soba-so/sdk";
159
+ import { sobaUserId } from "@soba-so/sdk/identity";
107
160
 
108
- A settings page is where somebody checks on a machine they already attached. It
109
- is not where they decide to attach one, because nobody visits it wondering
110
- whether to. An app that mounts only \`<ConnectCompute />\` there has nowhere for a
111
- run to land until a user happens to wander in, and meets \`no_compute\` first.
161
+ const soba = new Soba({ apiKey: process.env.SOBA_KEY });
112
162
 
113
- Put the decision where it is made. All of these come from \`@soba-so/react\`, and
114
- all of them raise the same modal \u2014 the provider mounts exactly one, so an app
115
- with all of them cannot put two pairings on screen at once.
163
+ const run = await soba.run({
164
+ user: sobaUserId(session.user.username),
165
+ model: "auto",
166
+ prompt: "Summarise everything I saved this week",
167
+ tools: [listNotes, readNote], // your code, executed in your app
168
+ });
169
+ \`\`\`
116
170
 
117
- | Component | Where |
118
- |---|---|
119
- | \`<ModelPicker />\` | In the composer, beside the send button. Which of THEIR models answers |
120
- | \`<RunLimit />\` | Where a run just failed for a reason the user can fix. Render it in the place the answer was going to be |
121
- | \`<RunError />\` | Beside it, for every other failure. The two never both speak |
122
- | \`<ConnectNudge />\` | While the allowance is running down and they still have a choice |
123
- | \`<SobaBilling />\` | The current plan, then the grid. The billing page you probably want |
124
- | \`<SobaPlans showConnect />\` | A pricing page with no current-plan card on it |
125
- | \`<SobaCurrentPlan />\` | The card alone, when composing the page yourself |
126
- | \`<SobaCheckout />\` | Takes the payment and grants the entitlement |
127
- | \`<SobaGate feature="workspaces" />\` | Around anything a plan limits \u2014 a "New workspace" button, an export. Shows it while allowed, otherwise the reason and the plans |
171
+ Tools passed to a run execute in the app's own process, so they can read the
172
+ app's own data. The model asks for data by calling them; the data does not
173
+ travel in the prompt.
128
174
 
129
- A gate draws the button; it does not secure the action. On the server, ask
130
- before you create: \`soba.users.check(user, "workspaces", { use: 1 })\` answers
131
- \`{ allowed, reason }\` and counts the use in the same call, so two requests for
132
- the last one cannot both get it. Record use you did not ask about with
133
- \`soba.users.track(user, "workspaces", -1)\` when one is deleted.
175
+ ## The browser: one provider, a surface for each moment
134
176
 
135
- Prices, allowances and the connected reward come from the plan objects, so
136
- changing them later is not a deploy. Pass \`showConnect\` only on a page with no
137
- current-plan card: a bring-your-own plan would otherwise state a requirement with
138
- no way to meet it.
177
+ Everything below reads from \`<SobaProvider sessionEndpoint="/api/soba/session">\`.
178
+ Mount it where a surface is, with \`sessionCacheKey\` set to the signed-in user's
179
+ id so reloads, navigations, tabs and other providers on the page share one
180
+ session. Never in a root layout that also renders the login page or marketing
181
+ pages: there is nobody there to mint a session for. A navbar's provider goes
182
+ in the layout that draws the signed-in navbar. All the components raise the
183
+ same pairing modal \u2014 the provider mounts exactly one, so an app with every
184
+ surface cannot put two pairings on screen at once.
139
185
 
140
- ## Components or hooks: decide this by looking at the repo
186
+ | Surface | Component | Hook (for your own markup) |
187
+ |---|---|---|
188
+ | **The settings page** | \`<ComputeSettings />\`, alone | \`useCompute()\` + \`useConnectButton()\` |
189
+ | **Above every control that starts a run** | \`<ConnectNudge />\` | \`useConnectNudge()\` |
190
+ | **Where a run's result appears**, when it failed | \`<RunLimit error={error} />\` then \`<RunError error={error} />\` | \`useRunLimit(error)\` + \`runErrorMessage(error)\` |
191
+ | **The signed-in navbar**, when AI only works on their compute | \`<ConnectButton />\` | \`useConnectButton()\`; its panel from \`useCompute()\` and \`useMachineRuns()\` |
192
+ | **The composer**, in an app with one | \`<ModelPicker />\` beside send | \`useModel()\` |
193
+ | **Billing and pricing** | \`<SobaBilling />\`, or \`<SobaCurrentPlan />\` + \`<SobaPlans />\`, \`<SobaCheckout />\`, \`<RedeemCode />\` | \`useCurrentPlan()\`, \`usePlans()\`, \`useCheckout()\`, \`useRedeemCode()\` |
194
+ | **Anything a plan limits** | \`<SobaGate feature="\u2026" />\` | \`useFeature()\`, plus the server check below |
195
+
196
+ **Required in every app: the first three.** The navbar follows from how the
197
+ app's AI is paid for (below); the composer, billing and gates follow from what
198
+ the app has \u2014 a model choice to offer, plans to sell, features to limit \u2014 and
199
+ the plans themselves are the person's to decide, not yours.
200
+
201
+ What each surface is for, and the mistakes it exists to prevent:
202
+
203
+ - **Navbar, when the AI only works on their compute.** Add \`<ConnectButton />\`
204
+ to the signed-in navbar when nothing can run until a user connects \u2014 a
205
+ bring-your-own plan, a route that only allows their machine or their
206
+ subscription, an app on a development key. There, connecting is a
207
+ prerequisite rather than an offer, so the door belongs on every page: it
208
+ says "Connect compute" until something is attached, then names the machine
209
+ and its state, and once connected it is a pill that opens a popover with the
210
+ machines and what they are running. An app whose runs fall back to compute
211
+ it pays for does not need it; settings, the nudge and the run limit already
212
+ meet the person where connecting matters. Wherever it is used, it lives in
213
+ the header and only there \u2014 a popover pill is wrong inside a page.
214
+ - **Settings.** A settings page is where somebody checks on a machine they
215
+ already attached, not where they decide to attach one. \`<ComputeSettings />\`
216
+ draws it as rows of that page in its own type: each machine, which agent the
217
+ app's runs go to there, and whether it is awake, asleep or serving, with
218
+ "Connect compute" or "Connect another computer". Nothing else from the
219
+ package goes on that page \u2014 \`<ConnectButton />\` or \`<ComputeStatus />\` beside
220
+ it draws the same machine twice. (\`<ConnectCompute />\` is its older name.) If
221
+ there is no settings page, build one, and do not point the connect return URL
222
+ at a page that does not render it.
223
+ - **Above each run-starting control.** Not only a chat composer: every "Tidy",
224
+ "Summarise", "Draft", "Generate", every form that kicks off a job \u2014 find each
225
+ call site from step 1 and the control that triggers it. \`<ConnectNudge />\`
226
+ stands there before anything is pressed and speaks only when it can help:
227
+ nothing connected and nothing else can serve, a paired machine gone quiet, or
228
+ an allowance running down that connecting would lift. It draws nothing
229
+ otherwise.
230
+ - **The result's place.** When a run fails, \`<RunLimit error={error} />\`
231
+ renders where the answer was going to be: for \`no_compute\` the way to connect
232
+ (or wake the machine), for \`payment_required\` the plan to upgrade to. It goes
233
+ quiet by itself once a machine is online, so a refusal from before connecting
234
+ is never shown as the answer to connecting. \`<RunError error={error} />\`
235
+ beside it says every other failure in a sentence; the two never both speak.
236
+
237
+ ### One run-starting control, written both ways
238
+
239
+ The same button in any app, as components:
141
240
 
142
- Both halves ship. **Every component above is one rendering of an exported hook,
143
- and the components derive nothing of their own** \u2014 so what you build from a hook
144
- and what we draw cannot disagree. Which half to reach for is not a matter of
145
- taste, and not a question to ask the person. Open the files first:
241
+ \`\`\`jsx
242
+ "use client";
243
+ import { ConnectNudge, RunError, RunLimit } from "@soba-so/react";
244
+
245
+ function TidyButton({ noteId }) {
246
+ const [error, setError] = useState(null);
247
+
248
+ async function tidy() {
249
+ setError(null);
250
+ const res = await fetch("/api/tidy", { method: "POST", body: JSON.stringify({ noteId }) });
251
+ if (!res.ok) return setError(await res.json()); // Soba's body, per step 4
252
+ // \u2026read the result as the app already does
253
+ }
254
+
255
+ return (
256
+ <>
257
+ <ConnectNudge />
258
+ <button onClick={tidy}>Tidy</button>
259
+ <RunLimit error={error} />
260
+ <RunError error={error} />
261
+ </>
262
+ );
263
+ }
264
+ \`\`\`
146
265
 
147
- **The app has no surface for this yet** \u2014 no settings page, no pricing page, a
148
- composer with nothing in its footer \u2014 then **mount the component.** It brings
149
- its own stylesheet, reads from the provider, and there is nothing left to
150
- decide. Do not build a settings page by hand so that you can fill it with hooks.
266
+ And built from the hooks, in the app's own components (\`Your\u2026\` below stands for
267
+ whatever the app already draws banners, buttons and cards with), saying
268
+ everything the components would:
151
269
 
152
- **The app already has its own** \u2014 a chat composer with its own controls, a
153
- billing page in its own cards, a design system, Tailwind classes everywhere,
154
- anything that plainly belongs to somebody's product \u2014 then **import the hook and
155
- keep their markup.** Our CSS will not match the screen it lands on, and a card
156
- of ours in the middle of their chat reads as something the assistant said. The
157
- rules are ours; the pixels stay theirs.
270
+ \`\`\`jsx
271
+ import { runErrorMessage, useConnectNudge, useRunLimit } from "@soba-so/react";
272
+
273
+ function TidyButton({ noteId }) {
274
+ const [error, setError] = useState(null);
275
+ const nudge = useConnectNudge(); // before: is anything in the way?
276
+ const limit = useRunLimit(error); // after: the way out of a refusal
277
+ const message = runErrorMessage(error); // after: every other failure
278
+
279
+ return (
280
+ <>
281
+ {nudge.visible && (
282
+ <YourBanner title={nudge.title} detail={nudge.detail} steps={nudge.steps}
283
+ onAction={nudge.open} onDismiss={nudge.dismissible ? nudge.dismiss : undefined} />
284
+ )}
285
+ <YourButton onClick={tidy}>Tidy</YourButton>
286
+ {limit ? (
287
+ <YourCard title={limit.title} body={limit.body}
288
+ onConnect={limit.connect}
289
+ onUpgrade={limit.upgradeTo ? limit.upgrade : undefined} />
290
+ ) : message ? (
291
+ <p className="error">{message}</p>
292
+ ) : null}
293
+ </>
294
+ );
295
+ }
296
+ \`\`\`
158
297
 
159
- | Component | Hook | What the hook decides |
298
+ Both halves are inside a provider. In a chat, the nudge stands above the
299
+ composer and the limit and error render in the message that failed; see "The
300
+ chat stays theirs".
301
+
302
+ ## Component or hook
303
+
304
+ Both halves ship, and **the component is the answer.** Mount it even when the
305
+ app already has its own composer, its own billing cards, its own design system
306
+ and Tailwind everywhere. Do not look at the repo's styling and decide to
307
+ rebuild one of these from its hook.
308
+
309
+ The reason is that the components are not just markup. The vendor configures
310
+ them in the Soba dashboard: the model picker's layout (by provider, one list,
311
+ custom only), which of Automatic, Fast and Best are offered, search, the agents'
312
+ marks and the line under each choice, the connect popup's look and theme. The
313
+ component reads all of that from the provider and draws it. A hand-built copy
314
+ reads none of it, so every setting the vendor changes in the dashboard silently
315
+ does nothing in their app, and nobody finds out until they compare the two.
316
+
317
+ What that looks like in practice, from a real integration: an app with its own
318
+ Tailwind composer took \`useModel()\` and rendered it as a native
319
+ \`<select>\` \u2014 no marks, no descriptions, no submenu per agent, a flat list
320
+ where the dashboard said "by provider". It worked, and it was wrong.
321
+
322
+ The components fit a foreign screen on purpose: \`className\` on each one for
323
+ placement and size, \`theme\` on \`<SobaProvider>\` (or the dashboard) for
324
+ light and dark, \`<ComputeSettings />\` inherits the page's type, and
325
+ \`<ModelPicker />\` is a pill beside a send button, not a card. If one still
326
+ clashes, say so to the person and leave the component in.
327
+
328
+ **Reach for a hook only when the person asks for their own markup**, or for a
329
+ decision no component draws (\`useMachineRuns()\`, \`useOpenSobaConnect()\`,
330
+ gating a server action on \`useFeature()\`). Every component is one rendering of
331
+ an exported hook and derives nothing of its own, and a surface built from a
332
+ hook must still show everything the component shows. Each line in the last
333
+ column is something a hand-built copy has dropped:
334
+
335
+ | Component | Hook | Built from the hook, it must still show |
160
336
  |---|---|---|
161
- | \`<ModelPicker />\` | \`useModel()\` | Which models this person could be answered by, the one in force, and the two fields to put on the run |
162
- | \`<RunLimit />\` | \`useRunLimit()\` | The two failures a person can act on, and the offer that answers each |
163
- | \`<RunError />\` | \`runErrorMessage()\` | What to say about a failure, or null when it is not this one's to say |
164
- | \`<ConnectNudge />\` | \`useConnectNudge()\` | Whether there is anything worth saying at all, which of four reasons, and how big |
165
- | \`<ComputeStatus />\` | \`useCompute()\` | The machines in words, and "nothing connected" versus "we have not looked yet" |
166
- | \`<ConnectButton />\` | \`useConnectButton()\` | What the control says once something is attached, and what pressing it means |
167
- | \`<SobaPlans />\` | \`usePlans()\` | The catalogue as decisions: price, allowance, compute, the connect row, one \`take()\` per plan |
168
- | \`<SobaCurrentPlan />\` | \`useCurrentPlan()\` | The allowance arithmetic and the one sentence that is true of it |
169
- | \`<SobaCheckout />\` | \`useCheckout()\` | The session, the label, and the rule that nothing is granted in the browser |
170
- | \`<SobaGate />\` | \`useFeature()\` | Whether this person may use a feature, and why not: no plan, plan ended, not included, limit reached |
171
-
172
- \`<ConnectCompute />\`, \`<SobaBilling />\` and \`<ConnectModal />\` are compositions
173
- of the above and have no rule of their own. \`<ConnectPill />\` is the half of
174
- \`<ConnectButton />\` that reports \u2014 the mark, the state and the machine, with no
175
- popover under it and no flow behind it \u2014 for an app putting the readout in its
176
- own header and opening its own panel. Pressing it is yours to wire; everything
177
- it says is \`connectSays\`. \`<SobaProvider>\` is needed either way: the hooks
178
- read from it, so a hook with no provider above it is the one mistake this split
179
- invites.
180
-
181
- Two belong to no component of their own. \`useOpenSobaConnect()\` brings the
337
+ | \`<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()\` |
338
+ | \`<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 |
339
+ | \`<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"\` |
340
+ | \`<ConnectNudge />\` | \`useConnectNudge()\` | Nothing unless \`visible\`. \`title\`, \`detail\`, the \`meter\`, the \`steps\` and \`stalled\`; a dismiss only when \`dismissible\`; the action is \`open()\` |
341
+ | \`<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 |
342
+ | \`<RunError />\` | \`runErrorMessage()\` | Its sentence as given, nothing when it is null, and never beside a \`<RunLimit />\` that is speaking |
343
+ | \`<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 |
344
+ | \`<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 |
345
+ | \`<SobaCurrentPlan />\` | \`useCurrentPlan()\` | \`summary\`; used and remaining as a meter unless \`unlimited\`; \`trialDaysLeft\`, \`periodEnd\` and the \`reward\` when there are any |
346
+ | \`<SobaCheckout />\` | \`useCheckout()\` | \`label\` on the button, \`busy\` and \`error\`, and \`buy()\`. Nothing is granted in the browser |
347
+ | \`<SobaGate />\` | \`useFeature()\` | The children while allowed; otherwise the reason it is not and the plans that would allow it |
348
+ | \`<RedeemCode />\` | \`useRedeemCode()\` | A field and an Apply that call \`redeem()\`, \`busy\`, \`error\` as given, and the \`reward\` once it lands |
349
+
350
+ \`<SobaBilling />\` and \`<ConnectModal />\` are compositions of the above and
351
+ have no rule of their own. \`<ConnectPill />\` is the half of \`<ConnectButton />\`
352
+ that reports \u2014 the mark, the state and the machine, with no popover under it
353
+ and no flow behind it. It is for an app whose person asked for their own panel;
354
+ otherwise the header gets \`<ConnectButton />\`, panel included. Pressing the pill
355
+ is yours to wire, and it still opens Soba's flow through
356
+ \`useSoba().connect.open()\`; everything it says is \`connectSays\`.
357
+ \`<SobaProvider>\` is needed either way: the hooks read from it, so a hook with no
358
+ provider above it is the one mistake this split invites.
359
+
360
+ A gate draws the button; it does not secure the action. On the server, ask
361
+ before you create: \`soba.users.check(user, "workspaces", { use: 1 })\` answers
362
+ \`{ allowed, reason }\` and counts the use in the same call, so two requests for
363
+ the last one cannot both get it. Record use you did not ask about with
364
+ \`soba.users.track(user, "workspaces", -1)\` when one is deleted. Prices,
365
+ allowances and the connected reward come from the plan objects, so changing
366
+ them later is not a deploy. Pass \`showConnect\` to \`<SobaPlans />\` only on a page
367
+ with no current-plan card: a bring-your-own plan would otherwise state a
368
+ requirement with no way to meet it.
369
+
370
+ Three belong to no component of their own. \`useOpenSobaConnect()\` brings the
182
371
  Soba app forward on this person's machine and hands back the one honest thing a
183
372
  page can say about having tried \u2014 a browser cannot tell whether a \`soba://\`
184
373
  link was answered, and a page that claims it worked is guessing.
185
374
  \`useMachineRuns()\` is the "Running now" list out of \`<ConnectButton />\`'s
186
375
  panel with no panel around it: what this person's machines are running FOR THIS
187
- APP, and \`stop(runId)\` to end one as the person whose machine it is on. The app
188
- that started that run sees it finish with \`reason: "stopped_by_user"\`, which is
189
- the point: a surface built on this is a kill switch its owner holds, not a
190
- request to somebody's server.
191
-
376
+ APP, and \`stop(runId)\` to end one as the person whose machine it is on; the app
377
+ that started that run sees it finish with \`reason: "stopped_by_user"\`.
192
378
  \`useRedeemCode()\` is a promo code field's behaviour: \`redeem(code)\` gives the
193
- user what the app's reward hands out \u2014 AI usage on top of their plan, a plan for
194
- some days, or a discount at their next checkout \u2014 and re-reads their plan, so
195
- the allowance on screen moves without a reload. Its \`error\` is a sentence ready
196
- to show. Put the field where somebody arrives with a code, usually the billing
197
- page. \`<RedeemCode />\` is that field already drawn \u2014 an input and an Apply
198
- button \u2014 for an app with no billing page of its own to put one in.
379
+ user what the app's reward hands out and re-reads their plan, so the allowance
380
+ on screen moves without a reload; \`<RedeemCode />\` is that field already drawn.
199
381
 
200
382
  \`useSoba()\` is the raw provider state. Reach for a named hook first and use
201
383
  this one for what no hook covers \u2014 \`run()\`, \`connect.open()\`,
@@ -222,9 +404,10 @@ and import the answer:
222
404
  is only true once the account has been read. Said while the first request is
223
405
  in flight, or after it failed, it tells a person with a paired laptop that it
224
406
  has vanished. \`useCompute().view\` is the four-way answer.
225
- - **A match on an error message.** \`useRunLimit\` and \`runErrorMessage\` read the
226
- CODE. Messages are prose we rewrite, and matching on them breaks on a copy
227
- edit.
407
+ - **A match on an error message, or an error line of your own for a refusal.**
408
+ \`useRunLimit\` and \`runErrorMessage\` read the CODE. Messages are prose we
409
+ rewrite, matching on them breaks on a copy edit, and Soba's own refusal text
410
+ names internal ids no user should see.
228
411
  - **Words for a cost class.** \`tierLabel(tier)\` is the one glossary for the five
229
412
  economics this product is about. Four hand-written copies in this repo
230
413
  disagreed with each other, and three reported somebody's own API key as
@@ -235,33 +418,54 @@ and import the answer:
235
418
 
236
419
  Read \`https://soba.so/docs/components\` for each hook's full shape.
237
420
 
238
- ## Reaching Claude Code and Codex
239
-
240
- \`chat/completions\` is stateless and the caller owns the agent loop, so it
241
- reaches models. Reaching a user's own Claude or ChatGPT subscription means
242
- letting Soba own the loop instead:
243
-
244
- \`\`\`js
245
- import { Soba } from "@soba-so/sdk";
246
- import { sobaUserId } from "@soba-so/sdk/identity";
247
-
248
- const soba = new Soba({ apiKey: process.env.SOBA_KEY });
249
-
250
- const run = await soba.run({
251
- // Derived from something that outlives your database. A primary key
252
- // minted at sign-up is not: reset it and the same person arrives as
253
- // somebody new, stranded from the machine they paired.
254
- // https://soba.so/docs/identity
255
- user: sobaUserId(session.user.username),
256
- model: "auto",
257
- prompt: "Summarise everything I saved this week",
258
- tools: [listNotes, readNote], // your code, executed in your app
259
- });
260
- \`\`\`
261
-
262
- Tools passed to a run execute in the customer's own process, so they can read
263
- the app's own data. The model asks for data by calling them; the data does not
264
- travel in the prompt.
421
+ ## The chat stays theirs
422
+
423
+ There is no chat component, on purpose. An app built on Soba already has its own
424
+ composer and its own messages, and they are the product. Keep every line of
425
+ that markup. What Soba adds goes INTO it, and these are the things a chat on
426
+ Soba has to handle \u2014 check each one against the code, not against memory:
427
+
428
+ **In the composer**
429
+
430
+ - \`<ModelPicker />\` in the composer's footer, beside the send button. The
431
+ component, per the section above, not a copy.
432
+ - Spread \`useModel().run\` onto the request, and have the route forward
433
+ \`model\` and \`runtime\` both.
434
+ - Send becomes Stop while a run is going. Stop aborts the request's
435
+ \`signal\`, and a run the person stopped is not an error to show. Neither is
436
+ \`reason: "stopped_by_user"\`, which is the machine's owner stopping it
437
+ from their side.
438
+ - \`<ConnectNudge />\` above the composer. It draws nothing until it has
439
+ something to say.
440
+ - Images, only if the composer already takes them: forward each message's
441
+ \`images\` and the runtimes that can see them will.
442
+
443
+ **In the messages**
444
+
445
+ - \`delta\` text is appended as it arrives. \`thinking\` is the running total
446
+ and REPLACES what is shown \u2014 appending it repeats every sentence. Fold it
447
+ away by default.
448
+ - \`status\` events are what the agent is doing: show \`message\`, and
449
+ \`toolInput\` beside it when there is one. \`state: "interrupted"\` means
450
+ the person's machine went offline mid-run and \`"resumed"\` that it came
451
+ back; say so in the answer, because the run goes on either way.
452
+ - A failed run renders \`<RunLimit />\` where the answer was going to be, and
453
+ \`<RunError />\` beside it for everything else. Branch on the \`reason\`
454
+ code, never the message. Offer Retry only when \`retryable\` is not false.
455
+ - Copy on every answer, on hover, copying the text as written (markdown, not
456
+ rendered HTML). Retry on the last one.
457
+ - \`done\` carries \`usage\` and \`tier\`. If the app shows what answered,
458
+ word the tier with \`tierLabel()\`.
459
+
460
+ **Across turns**
461
+
462
+ - \`done\` and \`error\` carry a \`session\`. Send it back as \`resume\`
463
+ on the next run, and have the route forward it, so a follow-up continues the
464
+ agent's conversation instead of starting a new one with the whole transcript
465
+ pasted in.
466
+
467
+ An app with no chat at all gets one built in its own components and styles,
468
+ the same way it would build any other screen \u2014 with everything above in it.
265
469
 
266
470
  ## Proving it
267
471
 
@@ -279,7 +483,12 @@ curl https://api.soba.so/v1/chat/completions \\
279
483
  A curl is evidence the credential works. It is NOT evidence the app is
280
484
  integrated \u2014 the dashboard's integrate step ticks on a request arriving from the
281
485
  real call site, and it cannot tell a curl from a deployment. Do not send one to
282
- make a checklist go green.
486
+ make a checklist go green. Before calling the integration done, walk the
487
+ required surfaces as a signed-in user with nothing connected: settings says
488
+ "Connect compute", the nudge stands above each run-starting control when
489
+ connecting would help, pressing one shows the limit card where the result
490
+ would have been (and the navbar says "Connect compute", where there is one) \u2014
491
+ then connect, and each of them goes quiet.
283
492
 
284
493
  ## A new project rather than an existing one
285
494
 
@@ -287,7 +496,7 @@ There is no separate procedure for this and no question to ask the person: look
287
496
  at the directory. If there is no app yet, run \`npx create-soba@latest\` and let
288
497
  it write one \u2014 it ships a correct \`/api/soba/session\`, which is the security
289
498
  boundary of the whole integration, and a plausible hand-written one is the
290
- failure mode that matters. Then the two edits above are already done and what
499
+ failure mode that matters. Then the server half is already done and what
291
500
  remains is the key.
292
501
 
293
502
  ## What is not yours to do
@@ -325,14 +534,14 @@ Start with \`soba_status\`.
325
534
  What the codebase steps actually involve, so you are not working from memory
326
535
  there either:
327
536
 
328
- ${w}`}],_=new Map(p.map(n=>[n.name,n]));function a(n){process.stderr.write(`soba-mcp: ${n}
329
- `)}function x(n){process.stdout.write(`${JSON.stringify(n)}
330
- `)}function k(n){let t="",e=new Set,r=!1,s=o=>{e.add(o),o.finally(()=>{e.delete(o),r&&e.size===0&&process.exit(0)})};process.stdin.setEncoding("utf8"),process.stdin.on("data",o=>{t+=o;let i=t.indexOf(`
537
+ ${y}`}],_=new Map(p.map(n=>[n.name,n]));function a(n){process.stderr.write(`soba-mcp: ${n}
538
+ `)}function k(n){process.stdout.write(`${JSON.stringify(n)}
539
+ `)}function v(n){let t="",e=new Set,r=!1,s=o=>{e.add(o),o.finally(()=>{e.delete(o),r&&e.size===0&&process.exit(0)})};process.stdin.setEncoding("utf8"),process.stdin.on("data",o=>{t+=o;let i=t.indexOf(`
331
540
  `);for(;i!==-1;){let l=t.slice(0,i).trim();t=t.slice(i+1),l&&s(I(l,n)),i=t.indexOf(`
332
- `)}}),process.stdin.on("end",()=>{r=!0,e.size===0&&process.exit(0),setTimeout(()=>process.exit(0),1e4).unref()})}async function I(n,t){let e;try{e=JSON.parse(n)}catch{a("ignored a line that was not json");return}let r=e.id===void 0||e.id===null;try{let s=await t(e.method,e.params??{});r||x({jsonrpc:"2.0",id:e.id,result:s})}catch(s){if(r)return;let o=s instanceof Error?s.message:String(s),i=o==="method not found"?-32601:-32603;x({jsonrpc:"2.0",id:e.id,error:{code:i,message:o}})}}var v={type:"object",properties:{},additionalProperties:!1};function S(n){let t=n.steps.map(r=>`${r.done?"[x]":"[ ]"} ${r.title} \u2014 ${r.state}`),e=n.complete?"Every step is done. Nothing here needs you again.":`Next: ${n.next}. Call soba_next_step for what to do.`;return`${t.join(`
541
+ `)}}),process.stdin.on("end",()=>{r=!0,e.size===0&&process.exit(0),setTimeout(()=>process.exit(0),1e4).unref()})}async function I(n,t){let e;try{e=JSON.parse(n)}catch{a("ignored a line that was not json");return}let r=e.id===void 0||e.id===null;try{let s=await t(e.method,e.params??{});r||k({jsonrpc:"2.0",id:e.id,result:s})}catch(s){if(r)return;let o=s instanceof Error?s.message:String(s),i=o==="method not found"?-32601:-32603;k({jsonrpc:"2.0",id:e.id,error:{code:i,message:o}})}}var x={type:"object",properties:{},additionalProperties:!1};function S(n){let t=n.steps.map(r=>`${r.done?"[x]":"[ ]"} ${r.title} \u2014 ${r.state}`),e=n.complete?"Every step is done. Nothing here needs you again.":`Next: ${n.next}. Call soba_next_step for what to do.`;return`${t.join(`
333
542
  `)}
334
543
 
335
- ${e}`}function P(n,t){return n.steps.find(e=>e.id===t)}var m=[{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:v,run:async n=>S(await n.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:v,run:async n=>{let t=await n.get("/v1/manage/progress");if(t.complete)return"Setup is complete. There is nothing to do.";let e=P(t,t.next);return e?e.effect==="human"?e.id==="price"?`Next: ${e.title}
544
+ ${e}`}function P(n,t){return n.steps.find(e=>e.id===t)}var h=[{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:x,run:async n=>S(await n.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:x,run:async n=>{let t=await n.get("/v1/manage/progress");if(t.complete)return"Setup is complete. There is nothing to do.";let e=P(t,t.next);return e?e.effect==="human"?e.id==="price"?`Next: ${e.title}
336
545
 
337
546
  ${e.lede}
338
547
 
@@ -352,4 +561,4 @@ When you are done, call soba_status to confirm it registered.`:S(t)}},{name:"sob
352
561
 
353
562
  SOBA_KEY=${e.key}
354
563
 
355
- 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(n,t)=>(await n.patch("/v1/manage/app",{connect_return_url:t.url}),`Connect now returns to ${t.url}.`)},{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.",inputSchema:{type:"object",properties:{name:{type:"string"},description:{type:"string"},price:{type:"number",description:"Dollars a month. 0 is a free plan."},unit:{type:"string",enum:["run","token","cost"],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","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","token","credit","task",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"]}},required:["name","price","route_prefer"],additionalProperties:!1},run:async(n,t)=>{let e=await n.post("/v1/manage/plans",t);return`Created the plan "${e.name}"${e.id?` (${e.id})`:""}.`}},{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(n,t)=>(await n.post("/v1/manage/rewards/give",t),`Gave ${t.user} the reward ${t.reward}.`)}],A=new Map(m.map(n=>[n.name,n]));var O="https://soba.so",U="2025-06-18",N="0.0.3";function L(n){let t={token:process.env.SOBA_MANAGEMENT_KEY??null,baseUrl:process.env.SOBA_MANAGE_URL??O};for(let e=0;e<n.length;e++){let r=n[e];r==="--token"?t.token=n[++e]??null:r?.startsWith("--token=")?t.token=r.slice(8):r==="--url"?t.baseUrl=n[++e]??t.baseUrl:r?.startsWith("--url=")&&(t.baseUrl=r.slice(6))}return t.baseUrl=t.baseUrl.replace(/\/+$/,""),t}var h=L(process.argv.slice(2)),g=h.token;g||(a("no management key. Pass --token mk_soba_\u2026 or set SOBA_MANAGEMENT_KEY."),a("Mint one in your Soba dashboard, on the Set up page."),process.exit(2));g.startsWith("mk_soba_")||(a("that is not a management key. It starts with mk_soba_, and sk_soba_ is a"),a("different credential \u2014 your app's secret key. Do not paste that here."),process.exit(2));var D=new c(g,h.baseUrl);k(async(n,t)=>{switch(n){case"initialize":return{protocolVersion:U,capabilities:{tools:{},prompts:{}},serverInfo:{name:"soba",version:N},instructions:"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:p.map(e=>({name:e.name,title:e.title,description:e.description}))};case"prompts/get":{let e=typeof t.name=="string"?t.name:"",r=_.get(e);if(!r)throw new Error(`no such prompt: ${e}`);return{description:r.description,messages:[{role:"user",content:{type:"text",text:r.text}}]}}case"tools/list":return{tools:m.map(e=>({name:e.name,title:e.title,description:e.description,inputSchema:e.inputSchema}))};case"tools/call":{let e=typeof t.name=="string"?t.name:"",r=A.get(e);if(!r)return f(`no such tool: ${e}`);let s=t.arguments??{};try{return{content:[{type:"text",text:await r.run(D,s)}]}}catch(o){return o instanceof u?f(F(o)):f(o instanceof Error?o.message:String(o))}}default:throw new Error("method not found")}});function f(n){return{content:[{type:"text",text:n}],isError:!0}}function F(n){return n.status===401?"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.":n.message}a(`ready \u2014 ${m.length} tools, ${p.length} prompt against ${h.baseUrl}`);
564
+ 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(n,t)=>(await n.patch("/v1/manage/app",{connect_return_url:t.url}),`Connect now returns to ${t.url}.`)},{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.",inputSchema:{type:"object",properties:{name:{type:"string"},description:{type:"string"},price:{type:"number",description:"Dollars a month. 0 is a free plan."},unit:{type:"string",enum:["run","token","cost"],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","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","token","credit","task",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"]}},required:["name","price","route_prefer"],additionalProperties:!1},run:async(n,t)=>{let e=await n.post("/v1/manage/plans",t);return`Created the plan "${e.name}"${e.id?` (${e.id})`:""}.`}},{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(n,t)=>(await n.post("/v1/manage/rewards/give",t),`Gave ${t.user} the reward ${t.reward}.`)}],A=new Map(h.map(n=>[n.name,n]));var O="https://soba.so",L="2025-06-18",N="0.0.5";function U(n){let t={token:process.env.SOBA_MANAGEMENT_KEY??null,baseUrl:process.env.SOBA_MANAGE_URL??O};for(let e=0;e<n.length;e++){let r=n[e];r==="--token"?t.token=n[++e]??null:r?.startsWith("--token=")?t.token=r.slice(8):r==="--url"?t.baseUrl=n[++e]??t.baseUrl:r?.startsWith("--url=")&&(t.baseUrl=r.slice(6))}return t.baseUrl=t.baseUrl.replace(/\/+$/,""),t}var f=U(process.argv.slice(2)),g=f.token;g||(a("no management key. Pass --token mk_soba_\u2026 or set SOBA_MANAGEMENT_KEY."),a("Mint one in your Soba dashboard, on the Set up page."),process.exit(2));g.startsWith("mk_soba_")||(a("that is not a management key. It starts with mk_soba_, and sk_soba_ is a"),a("different credential \u2014 your app's secret key. Do not paste that here."),process.exit(2));var D=new c(g,f.baseUrl);v(async(n,t)=>{switch(n){case"initialize":return{protocolVersion:L,capabilities:{tools:{},prompts:{}},serverInfo:{name:"soba",version:N},instructions:"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:p.map(e=>({name:e.name,title:e.title,description:e.description}))};case"prompts/get":{let e=typeof t.name=="string"?t.name:"",r=_.get(e);if(!r)throw new Error(`no such prompt: ${e}`);return{description:r.description,messages:[{role:"user",content:{type:"text",text:r.text}}]}}case"tools/list":return{tools:h.map(e=>({name:e.name,title:e.title,description:e.description,inputSchema:e.inputSchema}))};case"tools/call":{let e=typeof t.name=="string"?t.name:"",r=A.get(e);if(!r)return m(`no such tool: ${e}`);let s=t.arguments??{};try{return{content:[{type:"text",text:await r.run(D,s)}]}}catch(o){return o instanceof u?m(F(o)):m(o instanceof Error?o.message:String(o))}}default:throw new Error("method not found")}});function m(n){return{content:[{type:"text",text:n}],isError:!0}}function F(n){return n.status===401?"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.":n.message}a(`ready \u2014 ${h.length} tools, ${p.length} prompt against ${f.baseUrl}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soba-so/mcp",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
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",