@somewhere-cloud/cli 0.38.155 → 0.38.157

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 (142) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/commands/docs.js +1 -1
  3. package/dist/lib/bundle.js +286 -188
  4. package/dist/lib/bundle.js.map +3 -3
  5. package/npm-shrinkwrap.json +2 -2
  6. package/package.json +2 -3
  7. package/dist/docs/adopt.md +0 -39
  8. package/dist/docs/analytics.md +0 -161
  9. package/dist/docs/api-reference.md +0 -339
  10. package/dist/docs/api-surface.md +0 -2067
  11. package/dist/docs/app-mcp.md +0 -162
  12. package/dist/docs/architecture-patterns.md +0 -334
  13. package/dist/docs/auth-client.md +0 -531
  14. package/dist/docs/billing.md +0 -76
  15. package/dist/docs/browser.md +0 -639
  16. package/dist/docs/calendar.md +0 -298
  17. package/dist/docs/changes.md +0 -323
  18. package/dist/docs/cli.md +0 -407
  19. package/dist/docs/common-mistakes.md +0 -199
  20. package/dist/docs/connect-agent.md +0 -72
  21. package/dist/docs/cors.md +0 -114
  22. package/dist/docs/cron.md +0 -167
  23. package/dist/docs/database-engine.md +0 -167
  24. package/dist/docs/declared-data.md +0 -1656
  25. package/dist/docs/declared-files.md +0 -475
  26. package/dist/docs/deploy-intelligence.md +0 -188
  27. package/dist/docs/deploy.md +0 -733
  28. package/dist/docs/design-system.md +0 -273
  29. package/dist/docs/dev-environments.md +0 -496
  30. package/dist/docs/domain-ownership.md +0 -31
  31. package/dist/docs/domains.md +0 -370
  32. package/dist/docs/feedback.md +0 -88
  33. package/dist/docs/file-tools.md +0 -116
  34. package/dist/docs/functions.md +0 -489
  35. package/dist/docs/getting-started.md +0 -238
  36. package/dist/docs/github.md +0 -95
  37. package/dist/docs/google-calendar.md +0 -212
  38. package/dist/docs/groups.md +0 -836
  39. package/dist/docs/guarantees.md +0 -58
  40. package/dist/docs/handled-for-you.md +0 -224
  41. package/dist/docs/inspect.md +0 -171
  42. package/dist/docs/limits.md +0 -68
  43. package/dist/docs/live-data.md +0 -197
  44. package/dist/docs/live.md +0 -92
  45. package/dist/docs/local-dev.md +0 -30
  46. package/dist/docs/migration-supabase.md +0 -58
  47. package/dist/docs/payments.md +0 -1102
  48. package/dist/docs/portability.md +0 -194
  49. package/dist/docs/postgres.md +0 -301
  50. package/dist/docs/pricing-comparison.md +0 -42
  51. package/dist/docs/pricing.md +0 -39
  52. package/dist/docs/project-groups.md +0 -107
  53. package/dist/docs/projects.md +0 -380
  54. package/dist/docs/recipe-ai-agent.md +0 -112
  55. package/dist/docs/recipe-ai-features.md +0 -227
  56. package/dist/docs/recipe-ai-receipts.md +0 -783
  57. package/dist/docs/recipe-background-jobs.md +0 -369
  58. package/dist/docs/recipe-booking.md +0 -348
  59. package/dist/docs/recipe-csv-import.md +0 -390
  60. package/dist/docs/recipe-ecommerce.md +0 -127
  61. package/dist/docs/recipe-email.md +0 -282
  62. package/dist/docs/recipe-escalation.md +0 -133
  63. package/dist/docs/recipe-file-uploads.md +0 -159
  64. package/dist/docs/recipe-import-app.md +0 -110
  65. package/dist/docs/recipe-login.md +0 -457
  66. package/dist/docs/recipe-multi-chat.md +0 -198
  67. package/dist/docs/recipe-paid-api.md +0 -161
  68. package/dist/docs/recipe-pdfs.md +0 -205
  69. package/dist/docs/recipe-push-notifications.md +0 -107
  70. package/dist/docs/recipe-seo.md +0 -200
  71. package/dist/docs/recipe-signed-in-app.md +0 -330
  72. package/dist/docs/render.md +0 -99
  73. package/dist/docs/rooms.md +0 -554
  74. package/dist/docs/sdk.md +0 -287
  75. package/dist/docs/sdks.md +0 -24
  76. package/dist/docs/search.md +0 -199
  77. package/dist/docs/security-model.md +0 -168
  78. package/dist/docs/setup.md +0 -212
  79. package/dist/docs/smoke.md +0 -102
  80. package/dist/docs/speed.md +0 -298
  81. package/dist/docs/sql-compatibility.md +0 -96
  82. package/dist/docs/sw.agent.md +0 -248
  83. package/dist/docs/sw.ai.md +0 -1291
  84. package/dist/docs/sw.auth.md +0 -1811
  85. package/dist/docs/sw.billing.md +0 -171
  86. package/dist/docs/sw.db.md +0 -2128
  87. package/dist/docs/sw.email.md +0 -661
  88. package/dist/docs/sw.endpoint.md +0 -187
  89. package/dist/docs/sw.env.md +0 -303
  90. package/dist/docs/sw.fetch.md +0 -115
  91. package/dist/docs/sw.fs.md +0 -424
  92. package/dist/docs/sw.groups.md +0 -836
  93. package/dist/docs/sw.image.md +0 -69
  94. package/dist/docs/sw.jobs.md +0 -520
  95. package/dist/docs/sw.logs.md +0 -61
  96. package/dist/docs/sw.mail.md +0 -106
  97. package/dist/docs/sw.notifications.md +0 -78
  98. package/dist/docs/sw.push.md +0 -161
  99. package/dist/docs/sw.rateLimit.md +0 -67
  100. package/dist/docs/sw.web.md +0 -128
  101. package/dist/docs/tasks.md +0 -269
  102. package/dist/docs/test.md +0 -220
  103. package/dist/docs/tool-reference-account.md +0 -7
  104. package/dist/docs/tool-reference-ai.md +0 -121
  105. package/dist/docs/tool-reference-analytics.md +0 -37
  106. package/dist/docs/tool-reference-api.md +0 -19
  107. package/dist/docs/tool-reference-artifacts.md +0 -35
  108. package/dist/docs/tool-reference-auth.md +0 -163
  109. package/dist/docs/tool-reference-browser.md +0 -114
  110. package/dist/docs/tool-reference-code.md +0 -26
  111. package/dist/docs/tool-reference-connect.md +0 -21
  112. package/dist/docs/tool-reference-cron.md +0 -48
  113. package/dist/docs/tool-reference-db.md +0 -282
  114. package/dist/docs/tool-reference-domains.md +0 -107
  115. package/dist/docs/tool-reference-email.md +0 -55
  116. package/dist/docs/tool-reference-env.md +0 -19
  117. package/dist/docs/tool-reference-feedback.md +0 -56
  118. package/dist/docs/tool-reference-fs.md +0 -265
  119. package/dist/docs/tool-reference-github.md +0 -57
  120. package/dist/docs/tool-reference-groups.md +0 -85
  121. package/dist/docs/tool-reference-help.md +0 -29
  122. package/dist/docs/tool-reference-jobs.md +0 -39
  123. package/dist/docs/tool-reference-live.md +0 -48
  124. package/dist/docs/tool-reference-logs.md +0 -16
  125. package/dist/docs/tool-reference-payments.md +0 -44
  126. package/dist/docs/tool-reference-project.md +0 -706
  127. package/dist/docs/tool-reference-push.md +0 -78
  128. package/dist/docs/tool-reference-rate-limit.md +0 -18
  129. package/dist/docs/tool-reference-search.md +0 -68
  130. package/dist/docs/tool-reference-security.md +0 -42
  131. package/dist/docs/tool-reference-smoke.md +0 -17
  132. package/dist/docs/tool-reference-stock-photos.md +0 -20
  133. package/dist/docs/tool-reference-tasks.md +0 -73
  134. package/dist/docs/tool-reference-telegram.md +0 -32
  135. package/dist/docs/tool-reference-usage.md +0 -9
  136. package/dist/docs/tool-reference-web.md +0 -71
  137. package/dist/docs/tool-reference-webhooks.md +0 -9
  138. package/dist/docs/troubleshooting.md +0 -411
  139. package/dist/docs/typed-functions.md +0 -94
  140. package/dist/docs/verify-before-deploy.md +0 -67
  141. package/dist/docs/vs-supabase.md +0 -75
  142. package/dist/docs/vs-vercel.md +0 -103
@@ -1,227 +0,0 @@
1
- # Recipe — AI features: suggest a title
2
-
3
- A signed-in user writes a note and asks for a title. Your function calls a
4
- model with `sw.ai.chat`, with no provider key, and the page shows the
5
- suggestion or says plainly that none is available. Then pick the next
6
- capability from the table at the end.
7
-
8
- ## Choose the shape and the model
9
-
10
- - **A chatbot, tools or several steps:** start from `recipe-ai-agent`, which
11
- runs `sw.agent` with conversation history and tools. Don't assemble that
12
- loop from single calls.
13
- - **A label, routing choice or score:** use `sw.ai.evaluate` (`sw.ai` →
14
- `typed-decisions`). Text uses Jev; images use Clef-flash.
15
- - **One prose answer from one input,** such as a title or a summary: one
16
- `sw.ai.chat` call, as in this recipe.
17
-
18
- Choose the model for each call with two questions: is the task easy, and is
19
- a person waiting? If either answer is yes, use a fast model. If the task is
20
- hard and nobody is waiting, use a reasoning model and run the call in a job
21
- (`recipe-background-jobs`).
22
-
23
- - **Fast:** omit `provider` and `model`. That's the free default. It uses
24
- your account's included AI allowance and refuses instead of charging when
25
- the allowance is used up.
26
- - **Reasoning:** choose a `complete` entry in `ai_catalog` whose `label`
27
- says reasoning, and pass its `provider` and `model`. That's the paid path:
28
- it uses eligible included allowance, then prepaid balance, and counts toward
29
- the project's AI spend cap. Calls using your own provider key are billed by
30
- that provider and sit outside this cap.
31
-
32
- `ai_catalog` lists which models are available now, with each one's price and
33
- notes; the supplier's documentation has the rest. Tell the app's owner your
34
- choice and its trade-off in one sentence, for example: "Titles use the free
35
- default model because someone is waiting and the task is easy; when the
36
- included allowance runs out, suggestions pause instead of charging."
37
-
38
- ## 1. The function
39
-
40
- ```ts
41
- // api/suggest-title.ts — POST { text } → { title }
42
- export default sw.endpoint({
43
- auth: 'none', // the handler applies its own access check below
44
- handler: async ({ request }, sw) => {
45
- if (request.method !== 'POST') {
46
- return new Response('Use POST.', { status: 405, headers: { Allow: 'POST' } });
47
- }
48
-
49
- const user = await sw.auth.fromRequest(request);
50
- if (!user) {
51
- return Response.json({ error: 'Sign in to get a suggestion.' }, { status: 401 });
52
- }
53
-
54
- const input: unknown = await request.json().catch(() => null);
55
- const text = typeof input === 'object' && input !== null && 'text' in input ? input.text : undefined;
56
- if (typeof text !== 'string' || !text.trim() || text.length > 4000) {
57
- return Response.json({ error: 'Send up to 4,000 characters of text.' }, { status: 400 });
58
- }
59
-
60
- // 20 per hour per user is this example's choice. It runs before any model call.
61
- const allowance = await sw.rateLimit.check(`suggest-title:${user.id}`, 20, 3600);
62
- if (!allowance.allowed) {
63
- return Response.json({ error: 'Too many suggestions. Try again later.' }, { status: 429 });
64
- }
65
-
66
- const unavailable = (code: string) =>
67
- Response.json({ error: 'No suggestion right now. Try again later.', code }, { status: 503 });
68
- try {
69
- // No provider or model: the free default.
70
- const reply = await sw.ai.chat({
71
- system: 'Reply with one short title for the text. No quotes.',
72
- messages: [{ role: 'user', content: text }],
73
- });
74
- const title = reply.text.trim();
75
- return title ? Response.json({ title }) : unavailable('EMPTY_SUGGESTION');
76
- } catch (error) {
77
- const code = error instanceof Error && 'code' in error ? String(error.code) : '';
78
- const status = error instanceof Error && 'status' in error ? Number(error.status) : 0;
79
- // A plan or project limit (402, 429) or the model provider (5xx).
80
- if (status === 402 || status === 429 || status >= 500) {
81
- try {
82
- await sw.logs.warn('Title suggestion unavailable', { code, status });
83
- } catch (logError) {
84
- console.error('Could not write AI availability log.', logError);
85
- }
86
- return unavailable(code);
87
- }
88
- throw error; // Other failures reach the platform's normal error handling.
89
- }
90
- },
91
- });
92
- ```
93
-
94
- The checks run in order: sign-in, input, then this user's limit, so a
95
- signed-out or oversized request never reaches a model.
96
-
97
- When the model can't answer, the function says so with 503 and keeps the
98
- platform's `code` in the response for you. It also writes the code and status
99
- to your project's logs without including the user's text. If logging fails,
100
- the same unavailable response still reaches the page. The page never shows
101
- billing details. The free
102
- default answers 429 for each of its limits: `RATE_LIMITED` for its request
103
- limit, which is shared across the owner's projects, `AI_ALLOWANCE_EXHAUSTED`
104
- for the included allowance and `AI_SPEND_CAP_REACHED` for the project's
105
- monthly cap. A provider failure answers 5xx. On the paid path a balance
106
- refusal answers 402. When the project reaches its spend cap, the platform also
107
- writes one line to the project's logs and emails you, once that month.
108
-
109
- Nothing retries the model call, and nothing switches to a paid model. Any
110
- other error is thrown again, so the platform logs it as a function error
111
- instead of hiding a bug behind "unavailable". `sw.ai` → `error-codes` lists
112
- every code.
113
-
114
- ## 2. Call it from the page
115
-
116
- ```ts
117
- // src/services/suggest-title.ts
118
- import { auth } from './auth';
119
-
120
- export type Suggestion =
121
- | { kind: 'title'; title: string } // the model's suggestion
122
- | { kind: 'refused'; error: string } // sign in, shorten the text, or wait
123
- | { kind: 'unavailable' }; // no suggestion this time
124
-
125
- export async function suggestTitle(text: string): Promise<Suggestion> {
126
- let response: Response;
127
- try {
128
- response = await auth.fetch('/api/suggest-title', {
129
- method: 'POST',
130
- headers: { 'content-type': 'application/json' },
131
- body: JSON.stringify({ text }),
132
- });
133
- } catch {
134
- return { kind: 'unavailable' };
135
- }
136
- const result: unknown = await response.json().catch(() => null);
137
- const fields = typeof result === 'object' && result !== null ? result : {};
138
- if (response.ok && 'title' in fields && typeof fields.title === 'string' && fields.title) {
139
- return { kind: 'title', title: fields.title };
140
- }
141
- if ([400, 401, 429].includes(response.status) && 'error' in fields && typeof fields.error === 'string') {
142
- return { kind: 'refused', error: fields.error };
143
- }
144
- return { kind: 'unavailable' };
145
- }
146
- ```
147
-
148
- ```tsx
149
- // src/pages/TitleSuggestion.tsx
150
- import { useState } from 'react';
151
- import { suggestTitle, type Suggestion } from '../services/suggest-title';
152
-
153
- export function TitleSuggestion() {
154
- const [text, setText] = useState('');
155
- const [pending, setPending] = useState(false);
156
- const [result, setResult] = useState<Suggestion | null>(null);
157
-
158
- async function suggest() {
159
- setPending(true);
160
- setResult(null);
161
- setResult(await suggestTitle(text)); // never throws: every outcome is a Suggestion
162
- setPending(false);
163
- }
164
-
165
- return (
166
- <section className="panel" aria-labelledby="suggest-title-heading">
167
- <h2 id="suggest-title-heading">Name your note</h2>
168
- <div className="field">
169
- <label htmlFor="note-text">
170
- Note <span className="hint">{text.length}/4,000</span>
171
- </label>
172
- <textarea id="note-text" rows={6} maxLength={4000} value={text} onChange={(event) => setText(event.target.value)} />
173
- </div>
174
- <button className="button" onClick={suggest} disabled={pending || !text.trim()}>
175
- {pending ? 'Suggesting…' : 'Suggest a title'}
176
- </button>
177
- <div aria-live="polite">
178
- {result?.kind === 'title' && <p>Suggested title: <strong>{result.title}</strong></p>}
179
- {result?.kind === 'refused' && <p className="error" role="alert">{result.error}</p>}
180
- {result?.kind === 'unavailable' && (
181
- <p className="muted">Suggestions aren't available right now. Your note is unchanged; try again later.</p>
182
- )}
183
- </div>
184
- </section>
185
- );
186
- }
187
- ```
188
-
189
- Render `<TitleSuggestion />` inside `SignedInLayout` on the starter's
190
- `src/pages/HomePage.tsx`. It uses the starter's `.panel`, `.field`,
191
- `.button`, `.hint`, `.error` and `.muted` classes, so it carries your
192
- `tokens.css` look.
193
-
194
- - **`title`**: show it as a suggestion. The user's note isn't changed until
195
- they choose to use it.
196
- - **`refused`**: show the function's message. The user can sign in again,
197
- shorten the note, or wait for their hourly limit.
198
- - **`unavailable`**: say that suggestions aren't available right now. Never
199
- show a made-up title or billing terms. The user can press the button again
200
- later; nothing retries on its own.
201
-
202
- ## 3. Check it
203
-
204
- ```bash
205
- somewhere typecheck
206
- somewhere deploy
207
- ```
208
-
209
- Sign in, write a few sentences and press **Suggest a title**. The button reads
210
- "Suggesting…", then the panel shows the title. Each suggestion uses the
211
- included AI allowance. `ai_catalog` → `free_complete_default.limits` shows the
212
- default's request and token limits.
213
-
214
- ## 4. Going further
215
-
216
- | Need | Use |
217
- |---|---|
218
- | A validated object instead of text | `sw.ai` → `structured-output-responseschema` |
219
- | Streaming | `stream: true` on `provider: 'anthropic'` only; the free default refuses it. Today the whole answer arrives as one event-stream payload: `sw.ai` → `cost-on-the-result-settled-or-pending-openai-and-anthropic-completions` |
220
- | Search a user's own documents by meaning | `sw.ai` → `search-a-users-documents` |
221
- | Bill your own Anthropic or OpenAI account | `sw.ai` → `provider-credentials-optional-byok` |
222
- | Background work at about half the token price | `service_tier: 'flex'` on `provider: 'openai'`, run in a job: `sw.ai` → `flex-service-tier-50-discount`; `recipe-background-jobs` |
223
- | Conversations and per-user memory | `sw.ai` → `conversation-history-all-providers`, `per-user-memory-swaiusermemory` |
224
- | Check text before you use it | `sw.ai` → `content-moderation` |
225
- | Images, speech and transcription | `sw.ai` → `image-generation-models`, `text-to-speech`, `other-ai-surfaces-also-on-swai` |
226
- | The project's monthly AI spend cap | `sw.ai` → `monthly-ai-spend-cap-per-project` |
227
- | Every model, price and capability | `ai_catalog` (`sw.ai` → `catalog-discovery`) |