@somewhere-cloud/cli 0.38.153 → 0.38.155

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 (147) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/docs/adopt.md +39 -0
  3. package/dist/docs/analytics.md +161 -0
  4. package/dist/docs/api-reference.md +339 -0
  5. package/dist/docs/api-surface.md +2067 -0
  6. package/dist/docs/app-mcp.md +162 -0
  7. package/dist/docs/architecture-patterns.md +334 -0
  8. package/dist/docs/auth-client.md +531 -0
  9. package/dist/docs/billing.md +76 -0
  10. package/dist/docs/browser.md +639 -0
  11. package/dist/docs/calendar.md +298 -0
  12. package/dist/docs/changes.md +323 -0
  13. package/dist/docs/cli.md +407 -0
  14. package/dist/docs/common-mistakes.md +199 -0
  15. package/dist/docs/connect-agent.md +72 -0
  16. package/dist/docs/cors.md +114 -0
  17. package/dist/docs/cron.md +167 -0
  18. package/dist/docs/database-engine.md +167 -0
  19. package/dist/docs/declared-data.md +1656 -0
  20. package/dist/docs/declared-files.md +475 -0
  21. package/dist/docs/deploy-intelligence.md +188 -0
  22. package/dist/docs/deploy.md +733 -0
  23. package/dist/docs/design-system.md +273 -0
  24. package/dist/docs/dev-environments.md +496 -0
  25. package/dist/docs/domain-ownership.md +31 -0
  26. package/dist/docs/domains.md +370 -0
  27. package/dist/docs/feedback.md +88 -0
  28. package/dist/docs/file-tools.md +116 -0
  29. package/dist/docs/functions.md +489 -0
  30. package/dist/docs/getting-started.md +238 -0
  31. package/dist/docs/github.md +95 -0
  32. package/dist/docs/google-calendar.md +212 -0
  33. package/dist/docs/groups.md +836 -0
  34. package/dist/docs/guarantees.md +58 -0
  35. package/dist/docs/handled-for-you.md +224 -0
  36. package/dist/docs/inspect.md +171 -0
  37. package/dist/docs/limits.md +68 -0
  38. package/dist/docs/live-data.md +197 -0
  39. package/dist/docs/live.md +92 -0
  40. package/dist/docs/local-dev.md +30 -0
  41. package/dist/docs/migration-supabase.md +58 -0
  42. package/dist/docs/payments.md +1102 -0
  43. package/dist/docs/portability.md +194 -0
  44. package/dist/docs/postgres.md +301 -0
  45. package/dist/docs/pricing-comparison.md +42 -0
  46. package/dist/docs/pricing.md +39 -0
  47. package/dist/docs/project-groups.md +107 -0
  48. package/dist/docs/projects.md +380 -0
  49. package/dist/docs/recipe-ai-agent.md +112 -0
  50. package/dist/docs/recipe-ai-features.md +227 -0
  51. package/dist/docs/recipe-ai-receipts.md +783 -0
  52. package/dist/docs/recipe-background-jobs.md +369 -0
  53. package/dist/docs/recipe-booking.md +348 -0
  54. package/dist/docs/recipe-csv-import.md +390 -0
  55. package/dist/docs/recipe-ecommerce.md +127 -0
  56. package/dist/docs/recipe-email.md +282 -0
  57. package/dist/docs/recipe-escalation.md +133 -0
  58. package/dist/docs/recipe-file-uploads.md +159 -0
  59. package/dist/docs/recipe-import-app.md +110 -0
  60. package/dist/docs/recipe-login.md +457 -0
  61. package/dist/docs/recipe-multi-chat.md +198 -0
  62. package/dist/docs/recipe-paid-api.md +161 -0
  63. package/dist/docs/recipe-pdfs.md +205 -0
  64. package/dist/docs/recipe-push-notifications.md +107 -0
  65. package/dist/docs/recipe-seo.md +200 -0
  66. package/dist/docs/recipe-signed-in-app.md +330 -0
  67. package/dist/docs/render.md +99 -0
  68. package/dist/docs/rooms.md +554 -0
  69. package/dist/docs/sdk.md +287 -0
  70. package/dist/docs/sdks.md +24 -0
  71. package/dist/docs/search.md +199 -0
  72. package/dist/docs/security-model.md +168 -0
  73. package/dist/docs/setup.md +212 -0
  74. package/dist/docs/smoke.md +102 -0
  75. package/dist/docs/speed.md +298 -0
  76. package/dist/docs/sql-compatibility.md +96 -0
  77. package/dist/docs/sw.agent.md +248 -0
  78. package/dist/docs/sw.ai.md +1291 -0
  79. package/dist/docs/sw.auth.md +1811 -0
  80. package/dist/docs/sw.billing.md +171 -0
  81. package/dist/docs/sw.db.md +2128 -0
  82. package/dist/docs/sw.email.md +661 -0
  83. package/dist/docs/sw.endpoint.md +187 -0
  84. package/dist/docs/sw.env.md +303 -0
  85. package/dist/docs/sw.fetch.md +115 -0
  86. package/dist/docs/sw.fs.md +424 -0
  87. package/dist/docs/sw.groups.md +836 -0
  88. package/dist/docs/sw.image.md +69 -0
  89. package/dist/docs/sw.jobs.md +520 -0
  90. package/dist/docs/sw.logs.md +61 -0
  91. package/dist/docs/sw.mail.md +106 -0
  92. package/dist/docs/sw.notifications.md +78 -0
  93. package/dist/docs/sw.push.md +161 -0
  94. package/dist/docs/sw.rateLimit.md +67 -0
  95. package/dist/docs/sw.web.md +128 -0
  96. package/dist/docs/tasks.md +269 -0
  97. package/dist/docs/test.md +220 -0
  98. package/dist/docs/tool-reference-account.md +7 -0
  99. package/dist/docs/tool-reference-ai.md +121 -0
  100. package/dist/docs/tool-reference-analytics.md +37 -0
  101. package/dist/docs/tool-reference-api.md +19 -0
  102. package/dist/docs/tool-reference-artifacts.md +35 -0
  103. package/dist/docs/tool-reference-auth.md +163 -0
  104. package/dist/docs/tool-reference-browser.md +114 -0
  105. package/dist/docs/tool-reference-code.md +26 -0
  106. package/dist/docs/tool-reference-connect.md +21 -0
  107. package/dist/docs/tool-reference-cron.md +48 -0
  108. package/dist/docs/tool-reference-db.md +282 -0
  109. package/dist/docs/tool-reference-domains.md +107 -0
  110. package/dist/docs/tool-reference-email.md +55 -0
  111. package/dist/docs/tool-reference-env.md +19 -0
  112. package/dist/docs/tool-reference-feedback.md +56 -0
  113. package/dist/docs/tool-reference-fs.md +265 -0
  114. package/dist/docs/tool-reference-github.md +57 -0
  115. package/dist/docs/tool-reference-groups.md +85 -0
  116. package/dist/docs/tool-reference-help.md +29 -0
  117. package/dist/docs/tool-reference-jobs.md +39 -0
  118. package/dist/docs/tool-reference-live.md +48 -0
  119. package/dist/docs/tool-reference-logs.md +16 -0
  120. package/dist/docs/tool-reference-payments.md +44 -0
  121. package/dist/docs/tool-reference-project.md +706 -0
  122. package/dist/docs/tool-reference-push.md +78 -0
  123. package/dist/docs/tool-reference-rate-limit.md +18 -0
  124. package/dist/docs/tool-reference-search.md +68 -0
  125. package/dist/docs/tool-reference-security.md +42 -0
  126. package/dist/docs/tool-reference-smoke.md +17 -0
  127. package/dist/docs/tool-reference-stock-photos.md +20 -0
  128. package/dist/docs/tool-reference-tasks.md +73 -0
  129. package/dist/docs/tool-reference-telegram.md +32 -0
  130. package/dist/docs/tool-reference-usage.md +9 -0
  131. package/dist/docs/tool-reference-web.md +71 -0
  132. package/dist/docs/tool-reference-webhooks.md +9 -0
  133. package/dist/docs/troubleshooting.md +411 -0
  134. package/dist/docs/typed-functions.md +94 -0
  135. package/dist/docs/verify-before-deploy.md +67 -0
  136. package/dist/docs/vs-supabase.md +75 -0
  137. package/dist/docs/vs-vercel.md +103 -0
  138. package/dist/lib/bundle.js +303 -221
  139. package/dist/lib/bundle.js.map +3 -3
  140. package/dist/types/lib/test-session.d.ts +8 -0
  141. package/npm-shrinkwrap.json +2 -2
  142. package/package.json +3 -2
  143. package/runtime/DECLARED-DATA-VENDOR.json +5 -5
  144. package/runtime/PLATFORM-SOURCE.json +1 -1
  145. package/runtime/SOURCE-LINT-VENDOR.json +2 -2
  146. package/runtime/declared-data.cjs +37 -19
  147. package/runtime/source-lint.cjs +1 -1
@@ -0,0 +1,107 @@
1
+ # Project groups
2
+
3
+ A group is a developer-owned collection of projects that share members and a
4
+ design theme — organize related apps and widen access in one grant instead of
5
+ adding collaborators to each project separately.
6
+
7
+ ## The model
8
+
9
+ - One group per project. Adding a project already in another group returns
10
+ 409 GROUP_CONFLICT — remove it from the old group first.
11
+ - Effective access = union of project owner, direct collaborator, and group
12
+ member. When the same user appears at more than one level, the most
13
+ permissive role wins.
14
+ - Groups do not transfer ownership or affect billing. Work always bills the
15
+ project's owner.
16
+
17
+ ## Roles
18
+
19
+ Both owners and editors can manage group membership, change
20
+ the shared theme and delete the group. Adding a project also requires editor
21
+ access to that project. The group’s creator remains its owner and cannot be
22
+ removed through the member-removal route.
23
+
24
+ ## Effective role on member projects
25
+
26
+ A group member's role grants access to ALL of the group's projects —
27
+ effective role on a project = MAX(direct collaborator role, group role).
28
+ Every group member is at least an editor: read + write, including deploy,
29
+ promote, restore, and database writes. Project OWNERSHIP never comes from a
30
+ group — billing and delete stay with the project owner regardless of
31
+ group membership.
32
+
33
+ ## Membership invites
34
+
35
+ Sending new group invitations is unavailable. The API answers
36
+ 410 GONE and stores or sends nothing. Existing members keep their access,
37
+ and invitations already sent can still be listed, revoked and accepted.
38
+
39
+ group_invite_list({ group_id }) → { invites: [{ email, role,
40
+ invited_at, expires_at }] } — pending invites only.
41
+
42
+ group_invite_accept({ group_id, token })
43
+ → { accepted: true, group_id }
44
+ The caller must be signed in as the invited email with a verified
45
+ email. Errors: EMAIL_NOT_VERIFIED, INVITE_INVALID, INVITE_USED,
46
+ INVITE_EXPIRED, INVITE_WRONG_ACCOUNT, GROUP_NOT_FOUND.
47
+
48
+ group_invite_revoke({ group_id, email }) → { revoked: true }
49
+ Revokes a PENDING invite only — an accepted invite is membership,
50
+ not an invite. 404 NOT_FOUND if there's no pending invite for that
51
+ email.
52
+
53
+ ## Removing an accepted member
54
+
55
+ Use the REST route below, or the MCP `api` tool with the same DELETE call
56
+ and `confirm: true` after approving the removal.
57
+
58
+ DELETE /v1/groups/:id/members/:user_id → { removed: true, group_id,
59
+ user_id }
60
+ Any group member can remove another member. The group’s creator
61
+ cannot be removed through this route.
62
+ 404 NOT_FOUND if that user isn't an accepted member.
63
+
64
+ ## Create and organize
65
+
66
+ group_create({ name, description? })
67
+ → { id, owner_id, name, description, created_at, updated_at,
68
+ role: 'owner', project_count: 0 }
69
+
70
+ group_add_project({ group_id, project_id }) → 409 GROUP_CONFLICT if taken
71
+
72
+ group_get({ group_id })
73
+ → { ...group, projects: [{id,name,subdomain,status}],
74
+ members: [{user_id,role}], design_tokens: {} }
75
+
76
+ For group_add_project, project_id accepts a project UUID, slug or subdomain.
77
+ You must belong to the group and have editor access to the project.
78
+
79
+ group_remove_project({ group_id, project_id }) requires the project UUID from
80
+ project_list or project_get. A group member or a project editor can detach it;
81
+ the project stays live. group_list() returns all groups you own or belong to,
82
+ with your role and each group’s project_count.
83
+
84
+ Example flow:
85
+ 1. group_create({ name: "Acme Suite" }) — save the returned id
86
+ 2. project_list() — find the UUID for each project to add
87
+ 3. group_add_project({ group_id, project_id })
88
+ 4. group_get({ group_id }) — verify the roster and token shape
89
+
90
+ ## The shared theme
91
+
92
+ A group carries design_tokens (a flat JSON object, 64 KB max). For example,
93
+ `{ "--brand": "#0a7" }` defines a CSS custom property on every member
94
+ project's served HTML. Use it in your CSS with `color: var(--brand)`.
95
+ The theme is inserted before the project's own styles, so a later project
96
+ value can override the group default. Pages using the Tailwind v4 browser
97
+ runtime also receive the tokens in `@theme`.
98
+
99
+ GET /v1/groups/:id/tokens → { tokens, updated_at }
100
+ PUT /v1/groups/:id/tokens body: { tokens: { ... } } (owner or editor)
101
+
102
+ ## Deleting a group
103
+
104
+ Any group member can call group_delete({ group_id }). It removes the group,
105
+ its membership and shared theme, and detaches its projects. The projects stay
106
+ live. A caller without membership receives 403 FORBIDDEN.
107
+ REST: DELETE /v1/groups/:id
@@ -0,0 +1,380 @@
1
+ # Projects — Full Lifecycle
2
+
3
+ Every app on the platform is a project. A project owns:
4
+ - a subdomain (https://{subdomain}.somewhere.site)
5
+ - a database
6
+ - a file store
7
+ - environment variables
8
+ - deployed functions and static files
9
+
10
+ Create one with `project_create({ name })`. The project starts live at its URL
11
+ with the same starter `somewhere init` writes: a React + TypeScript app with
12
+ sign-up, sign-in and sign-out, styled views and design tokens. The response
13
+ returns the starter's project contract, file map and skill index, so a session
14
+ without a local folder starts with the same context as one that ran
15
+ `somewhere init`. With `starter: "none"` the project starts empty. The first
16
+ `project_deploy({ project_id, base_release_id: null, files })` compiles your
17
+ source into an immutable release and serves it at the project URL.
18
+
19
+ To change a live project, read it first and edit against what you read.
20
+ `project_export({ project_id })` returns every source file and the
21
+ `active_release_id` that is serving. Pass that value as `base_release_id`:
22
+
23
+ `project_patch({ project_id, base_release_id, path: 'index.html', find: '<h1>Pricing</h1>', replace: '<h1>Plans</h1>' })`
24
+
25
+ The patch changes that one file and keeps every other file. If another deploy
26
+ landed after your read, it returns `409 STALE_RELEASE_BASE` and nothing
27
+ changes: read again and retry. A full `project_deploy` replaces static files
28
+ and keeps omitted functions by default. Use `project_patch` for edits.
29
+
30
+ Next: `project_view_urls` for the live URLs, `deploy_status` to confirm which
31
+ release is serving, `project_deploys` for history, and `project_rollback` to
32
+ move back one release. The `deploy` topic covers full replacement in detail.
33
+
34
+ ## Reusing a deleted name
35
+
36
+ A deleted project's name stays reserved to the account that owned it when it was deleted; another account cannot reclaim that deletion's reservation. A live project can still be transferred with its name; if it is later deleted, that deletion reserves the name to its then-current owner. A retained deleted project cannot change owner, and deletion cancels pending transfer invitations. That account can create a replacement once the host-keyed cache lifetime plus a late-fill allowance has passed since deletion (two hours today). Before then, creation shows the availability time rounded up to the next minute. The allowance covers requests still in flight or briefly using a stale route; it is directional, not a deadline on every old request.
37
+
38
+ The replacement has a new project id and inherits no platform-held data, files, users, sessions, secrets or domain attachments. Reusing the name continues the same web address: browsers that visited the old app keep what the address stored in them, outside services set up to call the address keep calling it, and for a short while after reuse a visitor may still be served a file from the old app at that address.
39
+
40
+ Reusing the name ends recovery of the old project under that name, including support recovery during its retention window. Deleting the owning account does not release its reservation; registering again with the same email creates a different account.
41
+
42
+ ## project_create({ name, subdomain?, description?, starter?, starter_ui? })
43
+ Creates a project and deploys the `somewhere init` starter as its first
44
+ release. If subdomain is omitted, one is generated from the name. Subdomains
45
+ must be globally unique, 3–32 chars, [a-z0-9-]. Returns
46
+ `{ id, name, subdomain, url, starter }`.
47
+
48
+ `starter` takes the `somewhere init --features` modules: `"auth"` (the
49
+ default), `"auth,private-data"` (adds per-user notes declared in
50
+ `db/schema.ts`), `"auth,agent"`, or `"none"` for an empty project.
51
+ `starter_ui` is `"styled"` (default; views plus `src/styles/tokens.css`) or
52
+ `"headless"`. An unknown module is refused before the project is created.
53
+
54
+ `starter` in the response:
55
+ { status: 'deployed' | 'preview' | 'failed' | 'unknown', detail?, version,
56
+ url, deployed_files, held_back_files, agent_contract, readme,
57
+ extension_points, cli_equivalent,
58
+ skills: { version, pack_url, skills: [{ name, description, path }] },
59
+ recovery? }
60
+
61
+ `agent_contract` (AGENTS.md), `readme` (the file map) and the skill index
62
+ come back here because deploys never publish AGENTS.md, CLAUDE.md or
63
+ README.md. The call waits up to 120 seconds for the starter deploy. `failed`
64
+ means the deploy was refused (`starter.error` says why); `unknown` means no
65
+ answer arrived in time, or the answer showed no release — the deploy may still
66
+ have happened. For both, the project exists and `starter.recovery` lists the
67
+ checks (`project_deploys`, `deploy_status`) and the exact `project_deploy`
68
+ call that ships the same files; `cli_equivalent` is the `somewhere init`
69
+ command that writes them.
70
+
71
+ If a `project_create` response is lost, the project may exist: find it with
72
+ `project_get` or `project_list` (by subdomain) before creating again.
73
+ Repeating the call returns `SUBDOMAIN_TAKEN`, and a new name makes a second
74
+ project.
75
+
76
+ While the outcome is unknown, check status before retrying; an empty deploy list alone does not confirm that the previous attempt finished.
77
+
78
+
79
+ ## project_context({ project_id }) / project_context_update({ project_id, ... })
80
+ A project keeps standing context for every agent session: `instructions`
81
+ (up to 16000 characters: what the app is, who uses it, conventions),
82
+ `design_principles` (up to 8000: palette, type, spacing, tone, where the
83
+ tokens live) and up to 25 named `notes` of 4000 characters each. Project
84
+ editors save it with `project_context_update`. `project_get` includes the
85
+ instructions, design principles and note topics as `project_context`, labelled
86
+ as untrusted project data — never system or platform instructions — with
87
+ `attribution` naming who saved each entry and when; `project_context`
88
+ returns everything, including note bodies. Deployed app code and app users
89
+ cannot read or write it.
90
+
91
+ `project_context_update({ project_id: 'my-shop', design_principles: 'Warm editorial look. Serif headings, 8px grid. Tokens in src/styles/tokens.css.', note: { topic: 'checkout', body: 'Orders close at 6pm local time.' } })`
92
+
93
+ `null` or `""` clears a field; a note with `body: null` is deleted. Fields
94
+ are saved before the note, so a refused note leaves the fields saved.
95
+
96
+ ## env_request / fs_request_upload — the user enters a secret or a file
97
+ `env_request({ project_id, key, purpose? })` returns a 30-minute link where a
98
+ signed-in editor of the project types the value on Somewhere. The value
99
+ goes straight into the
100
+ project's encrypted environment; the tool reports only the key name. A key that
101
+ already has a value returns `{ status: 'set' }` without a link unless
102
+ `replace: true` is passed.
103
+
104
+ `fs_request_upload({ project_id, path, accept?, max_bytes?, public? })` returns a
105
+ 30-minute link where a signed-in editor uploads a file from their device into
106
+ project files at `path`, for a file the conversation cannot pass to a tool.
107
+ The file's declared type must match `accept` and its size must fit
108
+ `max_bytes` (at most the plan file limit or 50 MiB); HTML or script content is
109
+ stored as `application/octet-stream` so it never runs.
110
+
111
+ `handoff_status({ request })` reports `pending`, `set`, `uploaded` (with the
112
+ stored path, size, type and version) or `expired`.
113
+
114
+ ## project_list()
115
+ Returns every project on your account, newest first. Each row:
116
+ { id, name, subdomain, status, state, address, created_at,
117
+ last_deployed_at, latest_screenshot_url, favicon_url }
118
+
119
+ `state` is the platform's one answer to "is this app live":
120
+ { code: "live" | "publishing" | "temporary" | "offline" | "paused" | "not_deployed",
121
+ label, detail, expires_at }
122
+ `label` and `detail` are plain sentences to show a person as they are.
123
+ `publishing` means a first version is on its way: the address answers within
124
+ seconds, and the state turns `live` once it does. `live` always means the address
125
+ answers. `address` is `null` while the state is `publishing` or `not_deployed`.
126
+ `temporary` means live on a temporary account; `expires_at` says when it goes
127
+ unless it is kept (claimed). `offline` means nothing is published now (for
128
+ example after `project_undeploy`); `paused` means the plan ended. `address` is
129
+ the URL people open: the first verified custom domain, else the
130
+ `*.somewhere.site` address. `project_get` returns the same two fields.
131
+
132
+ The list fields are ready to render without per-project metadata calls.
133
+ `latest_screenshot_url` and `favicon_url` are null until the project has the
134
+ corresponding live-release asset. The screenshot URL is a temporary signed
135
+ capability that an image element can render; the favicon URL is public.
136
+
137
+ ## Account overview: GET /v1/account/overview
138
+ One read for an account home, the same for every caller:
139
+ { account: { id, email, name, plan, trial, temporary_expires_at, ai_tools },
140
+ apps: [{ id, name, state, address, is_owner, last_changed_at }],
141
+ apps_truncated,
142
+ needs_you: [{ kind, title, detail, due_at, project_id,
143
+ action: { label, url? | method + path } }] }
144
+ `apps` carry the same `state` and `address` as `project_list`, most
145
+ recently deployed first. `needs_you` is decided and ordered by the platform:
146
+ `keep_apps` (a temporary account's apps go at `due_at` unless the person
147
+ saves an account; `action.url` is their link), `accept_transfer` (someone
148
+ offered this person an app), `finish_domain` (a custom domain whose DNS is
149
+ not in place; `action` is the verify call). Show `title`, `detail` and
150
+ `action.label` as they are; `action.url` is a page for the person,
151
+ `action.method` + `action.path` an API call.
152
+
153
+ `last_visit_at` is when the person was last here (their own browser reading
154
+ this overview at least 30 minutes earlier; `null` on a first visit), and each
155
+ app then carries `since_last_visit: { changed, failed_changes }`: whether a new
156
+ version went live since, and how many changes failed since. Keys, agents and the
157
+ CLI read the same answer without moving the window.
158
+ `ai_tools` is the list of AI tools the person said they use (from `claude`,
159
+ `chatgpt`, `claude-code`, `codex`, `cursor`, `opencode`; `[]` when not chosen).
160
+ The signed-in person sets it with `PATCH /v1/auth/platform-me { "ai_tools": ["claude", "cursor"] }`.
161
+
162
+ Page views for every app in that list, in one call:
163
+ `GET /v1/account/pageviews?days=7` (or `30`, `90`) →
164
+ { days, apps: [{ project_id, views }] }, most viewed first.
165
+ Counted as in the `analytics` topic (HTML page loads, no bots or previews).
166
+
167
+ ## Project overview: GET /v1/projects/{id}/overview
168
+ One read for a project home:
169
+ { project: { id, name, state, address, is_owner }, abilities,
170
+ live_version: { id, version, published_at } | null,
171
+ last_change: { kind, at } | null,
172
+ errors_24h: { total, top_codes: [{ code, count }] },
173
+ needs_you: [ ... same item shape as the account overview ... ] }
174
+ `errors_24h` is the same count as `GET /v1/errors/stats` for the last day.
175
+ `needs_you` here can also hold `fix_deploy`: the newest deploy failed after the
176
+ live release (or before any), with its code and message in `detail` and
177
+ `GET /v1/deploy/failure/{id}` as its `action`.
178
+ A connected agent's key (from a connect code) may read `GET /v1/projects/{id}`
179
+ and this overview for the projects in its connection, so it sees state,
180
+ address and its own `abilities`; nothing else in the account. A temporary
181
+ account's key may read `GET /v1/account/overview` for its own account.
182
+
183
+ ## project_get({ project_id, include_overview? })
184
+ Single project record + tier + deploy state, `state`, `address`, and
185
+ `abilities`: what this caller may do on this project, so no caller ranks
186
+ roles itself:
187
+ { deploy, publish, rollback, manage_domains, manage_secrets,
188
+ manage_collaborators, delete:
189
+ { allowed: true } | { allowed: false, reason, message } }
190
+ Each is judged by the checks that the matching request meets (deploy,
191
+ promote, rollback, domain add, env, collaborator invite, project delete)
192
+ for this credential, and a refused one carries the code and message that
193
+ request would answer with. `live_release: { id, version } | null` is the
194
+ release serving the app now; pass its `id` as `base_release_id` to deploy over
195
+ it. Plus `project_context`
196
+ (instructions, design principles, note topics) when the project's editors have
197
+ saved any.
198
+
199
+ Reading a project includes `project_overview` when the active release has
200
+ a source map. It summarizes the entry files, pages, API routes, tables and job handlers. Use
201
+ `docs_query` for a route, symbol or file. Older maps indicate when declared
202
+ tables and route auth are missing. A redeploy includes both.
203
+ `project_overview_status` explains when the overview is unavailable.
204
+ Pass `include_overview: false` to skip the source map read.
205
+
206
+ The dashboard's project Monitoring view also shows Page views: 7/30-day totals, top paths, and referrer hosts.
207
+
208
+ ## project_view_urls({ project_id })
209
+ Returns the project's URLs and current version. The bare subdomain
210
+ and every attached custom domain serve the immutable release named by
211
+ `active_release_id`. Browser verification uses that public live URL.
212
+
213
+ ## project_deploy({ project_id, base_release_id, files, functions?, binary_files? })
214
+ Full replacement from authored source. The platform compiles the source
215
+ into one immutable release and moves `active_release_id` to that exact
216
+ release only after publication succeeds. Pass `base_release_id: null` on a
217
+ project with no source. For a live project, use the `active_release_id` from
218
+ the source export you edited. See the deploy topic for the
219
+ exact semantics and when to choose project_patch instead.
220
+
221
+ ## project_patch({ project_id, base_release_id, path, content? | find?+replace?, delete_files? })
222
+ Single-file edit, served live. Two modes — `content` rewrites the
223
+ whole file; `find`+`replace` does a server-side substring substitute
224
+ (~200 bytes on the wire, preferred for tweaks). Unchanged files are
225
+ preserved. Pass the current release as `base_release_id`, including dry
226
+ runs: `deploy_status` returns it as `active_release_id` (`retained_release_id`
227
+ after an undeploy), and `project_export` returns the same id with the source
228
+ when you also need to read the file. `delete_files` removes paths.
229
+ See the deploy topic for the full shape.
230
+
231
+ ## project_rollback({ project_id })
232
+ Move `active_release_id` to the previous retained release. This changes
233
+ the serving pointer; it does not rebuild or mutate either release.
234
+
235
+ ## project_deploys({ project_id })
236
+ Deploy history, up to 150 successful releases plus 20 failed attempts
237
+ interleaved by time, each tagged with `status`:
238
+ { deploys: [
239
+ { status: "success", version, promoted_at, is_live, deployed_by, commit_sha, ... },
240
+ { status: "rejected", version, reason, message, at, is_live: false },
241
+ ] }
242
+ Each version shows the user-supplied note given when it was deployed or patched, if any.
243
+ A successful entry's `rollback_available` describes build availability, not source availability or schema-safe activation.
244
+ Each successful entry also carries `can_restore`: `{ allowed: true }` (with a
245
+ `restore` action) or `{ allowed: false, reason, message }`, the code and words
246
+ `project_restore_version` would answer with (`FORBIDDEN`, `RELEASE_IS_LIVE`,
247
+ `ROLLBACK_UNAVAILABLE`, `RESTORE_LOCKED`). Restoring needs editor access.
248
+ This history is the project's release resource: the response's `live_release`
249
+ names the version serving the app now.
250
+ A rejected entry's `version` is the version it would have become
251
+ (may be `null`); it never went live.
252
+
253
+ ## project_restore_version({ project_id, version })
254
+ Restore a specific past version as the live version.
255
+
256
+ ## project_undeploy({ project_id })
257
+ Take the project off the public subdomain. Files and database stay.
258
+ Reverse with project_deploy. While the project is undeployed, a deploy
259
+ that names no `base_release_id` is accepted against the retained release.
260
+
261
+ ## project_archive({ project_id }) / project_unarchive({ project_id })
262
+ Hide from the project list and revoke the subdomain. Data preserved.
263
+ Use for old projects you don't want cluttering project_list but might
264
+ revive later.
265
+
266
+ ## project_rename({ project_id, name?, description? })
267
+ Changes the display name or description. The app keeps its address.
268
+
269
+ ## Change the app address
270
+
271
+ The owner of a claimed project can change its Somewhere address in
272
+ **Settings → App address** or with `PATCH /v1/projects/{project_id}/hostname`.
273
+ Send `{"subdomain":"my-clean-name"}` using a developer key and the project ID.
274
+ The response includes the project's `id`, `subdomain`, and new `url`.
275
+ Use that URL and keep the same project ID for future deploys.
276
+
277
+ The old address redirects to the new one for 30 days, including the path
278
+ and query. Update any integration that calls the old address before then.
279
+
280
+ ## project_export({ project_id })
281
+ Pull every file in a project (static + functions) in one call — works
282
+ from any MCP client. Pair with project_deploy to write back. (CLI:
283
+ somewhere pull <id> does the same to disk.)
284
+
285
+ ## project_transfer({ project_id, to_email })
286
+ Invite an existing platform account with a verified email to take ownership.
287
+ Ownership changes only when the recipient explicitly accepts the invitation.
288
+ Before sending the invitation, tell the current owner: “When the transfer is accepted, your connected keys and database connection will be disconnected, and we recommend changing the database password with your provider because only that fully ends access through the old connection string. The app’s environment variables go with it, so remove or change any secret you put there before transferring.”
289
+ If the live deployment contains the connection string, disconnect the database and deploy once before transferring. Older deployments stay in the project history. After transfer, versions that still carry the old database connection cannot be restored. Deploy their source as a new version if you need it.
290
+ Includes the project's data, files, functions, and env vars. Payment callbacks remain tied to the original payment owner: pending payment callbacks tied to the
291
+ previous owner stop when the project changes owner. The new owner cannot view
292
+ their delivery history or retry them.
293
+
294
+ ## project_delete({ project_id }) → project_delete_confirm({ project_id, code })
295
+ Two-step. The first call is a successful response,
296
+ { ok: true, status: "needs_confirmation", confirmation_code }: issuing
297
+ that code is the whole result of this step. (`code` carries the same
298
+ value for callers already reading it.) Pass that code to project_delete_confirm
299
+ within 10 minutes only after human authorization. Before confirmation,
300
+ nothing changes. Confirmation immediately takes the project and its
301
+ hostnames offline, blocks new project effects, and frees its custom
302
+ domains and email sending setup at once (domains claimed or bought stay in
303
+ the account, unattached). It retains its database, files, functions, and
304
+ environment variables for 30 days, then permanently erases them. Recovery
305
+ during the retention period requires support and does not bring back domain
306
+ connections or sending setup.
307
+
308
+ ## deploy_status({ project_id })
309
+ Returns deploy metadata including the active release, current version,
310
+ last-deploy timestamp, and file counts on every plan. Use it to verify the
311
+ intended immutable release is the serving authority. Preview details require
312
+ hosted-preview read access; without it, `preview_comparison` is
313
+ `unavailable` and comparison values are null. That means preview was not
314
+ inspected, not that it is empty or synchronized with production.
315
+ It reports release metadata only. It does not run or report access, permission
316
+ or data checks. The checks a deploy ran appear in that deploy's own output, such as its
317
+ `warnings` and `smoke` result.
318
+
319
+ ## What NOT to do
320
+ - Don't call project_deploy when you only want to change one file —
321
+ use project_patch. project_deploy fully replaces static files (any
322
+ file you omit is deleted), but functions you omit are merge-preserved,
323
+ NOT deleted — and the deploy warns you, naming each preserved function.
324
+ Pass replace_functions:true only when you actually intend to drop them.
325
+ - Don't call project_delete in a script without surfacing the
326
+ confirmation code to a human first.
327
+
328
+ ## Outbound webhook subscriptions — the raw-body signature
329
+
330
+ Subscribe a URL to one event with `PUT /v1/webhooks/<event>` (developer
331
+ key; body `{ project_id, url, enabled?, secret? }`); list with `GET
332
+ /v1/webhooks?project_id=…`. Events the platform sends today: account
333
+ lifecycle (`user_signup`, `user_login`, `user_updated`, `user_deleted`,
334
+ `user_banned`, `user_unbanned`, `password_reset`, `password_changed`,
335
+ `email_verified`, `google_linked`), sessions (`session_created`,
336
+ `session_revoked`), email (`email_bounced`, `email_complained`),
337
+ `deploy_complete`, `ingest_complete` and `ingest_failed`. Other names the
338
+ registry accepts have no sender. Deliveries and redrives: `webhook_deliveries_list`,
339
+ `webhook_delivery_redrive`.
340
+
341
+ Wire format (from the sender): the JSON body is
342
+ `{ id, event, project_id, timestamp, source, data }` — `timestamp` is an ISO
343
+ string, `id` is the stable event ID, and `source` is `"live"` or `"test"`, `data` is the event
344
+ payload. Headers: `X-Somewhere-Event`, `X-Somewhere-Project`,
345
+ `X-Somewhere-Event-Id`, `X-Somewhere-Delivery-Id`, `X-Somewhere-Attempt`
346
+ (and `X-Somewhere-Retry: 1` on retries). When the subscription has a secret,
347
+ `X-Somewhere-Signature` is the hex HMAC-SHA256 of the RAW body bytes with
348
+ that secret — no timestamp, no `t=`/`v1=` prefix. Verify the raw body,
349
+ then use its `id` to deduplicate the event in your storage. The same event
350
+ keeps this ID and the same signed bytes across retries and manual redrives.
351
+ `X-Somewhere-Event-Id` mirrors the ID for troubleshooting; use the signed
352
+ body value for deduplication. This differs from the project auth-webhook drain
353
+ (`auth_webhook_set`), which signs `t={ms},v1={hex}` over
354
+ `${ms}.${rawBody}` — verify each surface with its own scheme.
355
+
356
+ Older stored deliveries keep their original signed body and may lack `id`.
357
+ Use the developer webhook delivery history to reconcile those before processing.
358
+ Neither an unsigned header nor a body hash distinguishes every older event.
359
+
360
+ Retries and redrives retain the signature made when the event was created.
361
+ After rotating a subscription secret, keep the previous verification key for
362
+ retained deliveries you may retry or redrive. New events use the new secret.
363
+
364
+ Setup: store the same secret you passed to `PUT /v1/webhooks/<event>` with
365
+ `somewhere env set WEBHOOK_SECRET <secret>` and read it as
366
+ `sw.env.WEBHOOK_SECRET`. Verification only — what you do after is your
367
+ app's contract:
368
+
369
+ ```ts
370
+ export default async function (req: Request, sw: SomewhereRuntimeContext): Promise<Response> {
371
+ const raw = await req.text();
372
+ const expected = await sw.crypto.hmacSha256Hex(raw, sw.env.WEBHOOK_SECRET);
373
+ const received = req.headers.get('X-Somewhere-Signature') ?? '';
374
+ if (!sw.crypto.timingSafeEqual(expected, received)) return new Response('bad signature', { status: 401 });
375
+ const { id, event, project_id, timestamp, source, data } = JSON.parse(raw);
376
+ // Verified. For new events, id is inside the signed body.
377
+ // Make your next action idempotent on that id in your own storage.
378
+ return new Response('ok');
379
+ }
380
+ ```
@@ -0,0 +1,112 @@
1
+ # Recipe — AI agent with tool calls
2
+
3
+ Build a chatbot that holds conversation history, looks things up in
4
+ your project's database, and answers grounded questions. Uses
5
+ bounded inline `sw.agent.run` with tools and server-side conversation history.
6
+ See `sw.agent` for durable execution, hooks, and limits.
7
+
8
+ ## Database schema
9
+
10
+ ```ts
11
+ // db/schema.ts — deploy this declaration with the app source.
12
+ import { schema, table, id, text, timestamp, owner } from 'somewhere/db'
13
+
14
+ export default schema({
15
+ knowledge: table({
16
+ id: id({ uuid: true }),
17
+ title: text(),
18
+ body: text(),
19
+ created_at: timestamp({ default: 'now' }),
20
+ }, {
21
+ scope: owner(),
22
+ indexes: [['title']],
23
+ }),
24
+ })
25
+ ```
26
+
27
+ ## Function: api/chat.ts
28
+
29
+ The generated runtime types infer the inputs to each `sw.endpoint` handler.
30
+ Deploy this raw source with the schema above.
31
+
32
+ ```ts
33
+ // api/chat.ts
34
+ export default sw.endpoint({
35
+ auth: 'required',
36
+ handler: async ({ request: req }, sw) => {
37
+ if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 })
38
+ let body: unknown
39
+ try { body = await req.json() } catch { return new Response('Invalid JSON', { status: 400 }) }
40
+ if (!body || typeof body !== 'object' || Array.isArray(body)
41
+ || !('message' in body) || typeof body.message !== 'string' || !body.message.trim()
42
+ || !('conversation_id' in body) || typeof body.conversation_id !== 'string' || !body.conversation_id.trim()) {
43
+ return new Response('Message and conversation_id required', { status: 400 })
44
+ }
45
+ const result = await sw.agent.run({
46
+ conversation_id: body.conversation_id,
47
+ messages: [{ role: 'user', content: body.message }],
48
+ system: 'Use lookup_knowledge to ground your answers. If nothing matches, say so.',
49
+ maxSteps: 4,
50
+ maxSpendCents: 25,
51
+ tools: {
52
+ lookup_knowledge: {
53
+ description: 'Search this signed-in user’s knowledge rows.',
54
+ inputSchema: { type: 'object', properties: { query: { type: 'string' } }, required: ['query'] },
55
+ execute: async (input) => {
56
+ if (typeof input.query !== 'string') throw new Error('Query required')
57
+ const rows = await sw.db.from('knowledge', {
58
+ columns: ['id', 'title', 'body'],
59
+ where: { $or: [{ title: { contains: input.query } }, { body: { contains: input.query } }] },
60
+ limit: 5,
61
+ })
62
+ return rows.data
63
+ },
64
+ },
65
+ },
66
+ })
67
+ return Response.json({ reply: result.text ?? '', completion_reason: result.completion_reason })
68
+ },
69
+ });
70
+ ```
71
+
72
+ ## Conversation and data ownership
73
+
74
+ After `requireUser(req)`, inline agent model calls derive the verified user
75
+ from that same request. Reuse `conversation_id` on later turns to replay that
76
+ user’s server-side conversation. The declared owner scope on `sw.db.from`
77
+ uses that same verified request user; do not switch this tool to server-wide
78
+ data access. This recipe is inline; do not turn it into a durable callback by
79
+ assuming the original request and its closures will still be present.
80
+ A bounded run can stop without a final answer; expose `completion_reason`.
81
+
82
+ ## Ground each message in the current state
83
+
84
+ An agent that changes something (a page, a row, a setting) can claim a change
85
+ it never made: with its own earlier replies in the conversation and no fresh
86
+ facts, a model may answer "done" without calling the tool. Read the current
87
+ state on the server and put it at the start of each person message, for
88
+ example `Current state: {...}` followed by what they typed, and tell the model
89
+ in `system` to trust that line over the earlier conversation and to say a
90
+ change happened only when the tool reported it. Forced tool choice is not a
91
+ substitute: some models refuse it (`MODEL_CAPABILITY_UNSUPPORTED`).
92
+
93
+ ## Variations
94
+
95
+ - **Structured output instead of tool-use:** pass `response_schema`
96
+ and read `result.parsed`. The free default makes no repair call on parse failure.
97
+ - **Free model:** omit `provider` and `model` to use
98
+ `gpt-6-luna` — no activation required, rate-limited and
99
+ capped, but free to the user.
100
+ - **Meaning-based knowledge lookup:** create an index once with
101
+ `search_index_create`, then `search_upsert` whenever a knowledge row
102
+ changes and query it through `sw.search`. Use `ai_embed` only when the
103
+ agent needs custom vectors or clustering outside the managed search index.
104
+ - **Voice input:** run uploaded audio through `sw.ai.transcribe` or the
105
+ `ai_transcribe` MCP tool, then pass the returned text into this same chat
106
+ handler.
107
+ - **Generated visual output:** use `sw.ai.generateImage` or
108
+ `ai_generate_image` when the product asks the agent for a hero, thumbnail,
109
+ social card, or other visual asset; store reusable output in the project's
110
+ files.
111
+
112
+ Related topics: `sw.ai`, `sw.auth`, `sw.db`, `search`.