@somewhere-cloud/cli 0.38.155 → 0.38.156

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 +4 -1
  2. package/dist/commands/docs.js +1 -1
  3. package/dist/lib/bundle.js +276 -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,96 +0,0 @@
1
- # SQL compatibility — what Postgres code ports, and what doesn't
2
-
3
- Use familiar SQL for joins, JSON and full-text search, and commit related
4
- writes in atomic batches. The
5
- platform translates the Postgres forms listed below into the project
6
- database's dialect. For semantic search, use `sw.search` without a separate
7
- vector database.
8
-
9
- Translation differs between developer SQL tools and a SQL-mode function's
10
- raw `sw.db.query` or `sw.db.server.query`. The sections below name each
11
- surface and its supported forms. Expression, typing and ordering follow
12
- the project database's dialect.
13
-
14
- ## Common SQL spellings
15
-
16
- - `NOW()` becomes `datetime('now')`
17
- - `TRUE` / `FALSE` become `1` / `0`
18
- - `ILIKE` becomes `LIKE` (case-insensitive for ASCII)
19
- - In migrations, `SERIAL` becomes `INTEGER`; declare
20
- `INTEGER PRIMARY KEY` for generated IDs.
21
- - `BOOLEAN` becomes `INTEGER`
22
- - `$1, $2, …` placeholders become positional `?`
23
- - `col->>'key'` and `col->'key'` become `json_extract(col, '$.key')`
24
-
25
- `RETURNING` works natively on INSERT, UPDATE and DELETE on write-capable
26
- surfaces. In managed projects, `sw.db.server.query` accepts read queries
27
- only; change declared rows through the structured operations. Run schema
28
- changes through `db_migrate` for hand-managed tables or deploy
29
- `db/schema.ts` for declared tables.
30
-
31
- ## Query semantics
32
-
33
- - `SELECT 1 / 0` returns `NULL`; it does not throw a Postgres-style
34
- division-by-zero error. Guard the divisor explicitly when zero is invalid.
35
- - Ascending `ORDER BY` places `NULL` first by default. Add `NULLS LAST`
36
- when that ordering is required.
37
- - `LIKE` is case-insensitive for ASCII by default. Use explicit normalization
38
- when case behavior is part of the application contract.
39
- - Integer operands use integer numeric affinity (`5 / 2` is `2`); use a real
40
- operand such as `2.0` when fractional division is required.
41
-
42
- The database has a 30-second hard query ceiling. The runtime `sw.db.query`
43
- surface does not expose a shorter true-cancellation contract. The external
44
- `db_query timeout_ms` stops the caller waiting; database work already accepted
45
- can continue.
46
-
47
- ## Additional translations in developer SQL tools
48
-
49
- `db_query`, `db_batch`, `db_migrate` and managed
50
- `sw.db.server.query` also translate the following forms, subject to
51
- their read/write permissions. For `sw.db.query` or `sw.db.server.query`
52
- inside a SQL-mode function, write the equivalent form on the right so the
53
- query works through either the project binding or the SQL API:
54
-
55
- - Date math: `created_at > NOW() - INTERVAL '7 days'` → `created_at > datetime('now','-7 days')` (units: second, minute, hour, day, month, year)
56
- - A standalone `SELECT generate_series(1, 10)` → `WITH RECURSIVE s(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM s WHERE n<10) SELECT n FROM s`
57
- - `CREATE TYPE … AS ENUM('a','b')` → `col TEXT CHECK(col IN ('a','b'))` (auto-translated when the CREATE TYPE and the table using it are in the same migration)
58
- - `array_agg(tag)` → `json_group_array(tag)`
59
-
60
- JSONB containment `data @> '{"k":"v"}'` auto-translates to `json_extract(data,'$.k') = 'v'` for the **flat case** — one or more keys whose values are scalar strings or numbers (multiple keys are AND-ed together, matching containment). Nested objects, array values, and boolean/null values are NOT auto-translated — they would risk silently matching the wrong rows, so they fail loud; write the explicit `json_extract` conditions yourself for those.
61
-
62
- ## Forms to replace
63
-
64
- The developer SQL tools reject these forms with a corrective error. Raw
65
- queries through a function's project database binding return the database
66
- error; queries routed through the SQL API receive the corrective error.
67
-
68
- - `DISTINCT ON (user_id) … ORDER BY user_id, created_at DESC` → use
69
- `ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC)`
70
- and keep `rn = 1`.
71
- - `tags TEXT[]` (any array type) → store as JSON text: `tags TEXT DEFAULT '[]'`, query with `WHERE tag IN (SELECT value FROM json_each(tags))`
72
- - `BEGIN; … COMMIT;` in one query → use `sw.db.tx([...])` for declared tables (atomic, all-or-nothing); in a SQL-mode project `sw.db.batch([{ sql, params }, …])` is the raw equivalent
73
- - `GEOMETRY`, `GEOGRAPHY`, `TSVECTOR`, `HSTORE`, `INET`, `BYTEA`, … → use full-text / `sw.search` / `sw.fs`; otherwise move the workload to Postgres
74
-
75
- Arrays are the most common: store them as a JSON text column and unroll with `json_each()` for querying.
76
-
77
- ## Built-in alternatives
78
-
79
- - Full-text search — native: `CREATE VIRTUAL TABLE docs USING fts5(title, body)`, then `WHERE docs MATCH 'term'`. Or `sw.search` for embeddings + ranking.
80
- - Vector / semantic search — `sw.search` (no separate vector database).
81
- - Per-user row security — the structured builder
82
- `sw.db.from/insert/update/remove` on a declared `scoped` table, instead of
83
- CREATE POLICY.
84
-
85
- ## Not available on the managed database
86
-
87
- PL/pgSQL (write logic in your server function), PostGIS, table
88
- partitioning, and custom engine index types (GIN/GiST/BRIN — use an
89
- app-managed index table + FTS5). For genuinely Postgres-only needs you can
90
- attach your own PostgreSQL database and query it alongside `sw.db` —
91
- `docs({ topic: 'postgres' })` — or export and move the workload out entirely.
92
- Either way the platform does not provide a managed Postgres adapter or an
93
- automatic migration service: an attached database is pass-through, and moving
94
- existing data into it is yours to do.
95
-
96
- Related: `database-engine`, `sw.db`, `postgres`, `portability`.
@@ -1,248 +0,0 @@
1
- # Somewhere agent loop — sw.agent
2
-
3
- `sw.agent` runs bounded model-and-tool work in your deployed function.
4
- Use `run` to wait inline; it stays in the current invocation and is not a
5
- resumable background job. Use `start` for checkpointed durable work with
6
- `status` and `cancel`. Durable callbacks re-enter the then-current deployed
7
- function, so a run can cross a deploy; tools and hooks must be recreated there.
8
-
9
- Set `maxSteps` and `maxSpendCents`; spend is checked between billed calls,
10
- so one call can cross the cap. On the project's own provider key the platform
11
- records no cost, so `maxSpendCents` never stops the run: bound it with
12
- `maxSteps` and `maxTokens` (see `sw.ai` → provider credentials). `prepareStep`, `onStepFinish`, and `stopWhen`
13
- control each step. Durable tool calls carry a stable `toolCallId` for your
14
- side-effect deduplication; this does not make side effects exactly once.
15
- Cancellation prevents later steps and cannot undo work already running.
16
-
17
- Start with `recipe-ai-agent`; see `recipe-escalation` and `recipe-multi-chat`
18
- for model escalation and conversation UI. History and compaction use the
19
- `sw.ai` conversation options passed through each step.
20
-
21
- ```js
22
- const result = await sw.agent.run({
23
- prompt: 'Summarize these notes: the delivery arrived, and the invoice is pending.',
24
- maxSteps: 4,
25
- maxSpendCents: 25,
26
- })
27
- console.log(result.text, result.completion_reason)
28
- ```
29
-
30
- ## Calling forms
31
-
32
- ```js
33
- await sw.agent(options) // durable compatibility form
34
- await sw.agent.run(options) // inline: wait for the terminal result
35
- await sw.agent.start(options) // durable: return after creating the run
36
- await sw.agent.status(agentId) // read durable status/result
37
- await sw.agent.cancel(agentId) // request durable cancellation
38
- ```
39
-
40
- The direct call and `.start` both create durable work. They use the same step
41
- engine but intentionally return different limit-field names:
42
-
43
- ```js
44
- const direct = await sw.agent(options)
45
- // { agent_id: string, status: string, max_turns: number }
46
-
47
- const started = await sw.agent.start(options)
48
- // { agent_id: string, status: string, max_steps: number }
49
- ```
50
-
51
- Both durable forms require `options.model`. Use the returned `agent_id` with
52
- `.status` and `.cancel`. `sw.agent.run` may omit a model and use the same
53
- model default as `sw.ai.chat`.
54
-
55
- ## Inline execution: sw.agent.run(options)
56
-
57
- `run` performs model calls and tool calls in the current function invocation,
58
- then returns the terminal model response plus agent metrics:
59
-
60
- ```js
61
- // Enumerable fields added by sw.agent:
62
- result.iterations
63
- result.tool_calls_made
64
- result.total_input_tokens
65
- result.total_output_tokens
66
- result.completion_reason
67
-
68
- // Present but deliberately non-enumerable:
69
- result.steps
70
- result.total_cost_cents
71
- ```
72
-
73
- The rest of the terminal object is the final `sw.ai.chat` response, including
74
- fields such as `text`, `content`, `provider`, `model`, `usage`, and
75
- `stop_reason` when the model response supplies them. Because `steps` and
76
- `total_cost_cents` are non-enumerable, object spread, `Object.keys`, and
77
- `JSON.stringify` omit them even though direct property access works.
78
-
79
- Completion reasons are `model_done`, `output_truncated`, `max_steps`,
80
- `max_turns` when only that limit name was supplied, `stop_when`,
81
- `cost_pending`, or the non-empty string returned by `stopWhen`.
82
- `cost_pending` fires when a spend cap is configured and a delivered step's
83
- cost is still pending: the loop returns that step and issues no further
84
- model request against an unknown total. A pending step makes
85
- `total_cost_cents` null — unknown, not zero — and without a spend cap the
86
- loop may continue with a null aggregate. A partial tool call in truncated model
87
- output is not executed. Reaching an agent step limit returns a terminal result;
88
- it does not throw.
89
-
90
- ## Words as they arrive: onText
91
-
92
- On Claude models, `sw.agent.run({ ..., onText: (text) => ... })` streams each
93
- model call and hands every piece of the answer's text to `onText` as it
94
- arrives. Use it to show the reply while it is still being written. The result
95
- and the bill are the same as without it. A stream that stops early is billed
96
- only after review, never estimated.
97
-
98
- `onToolStart: (name) => ...` streams the same way and is called with a tool's
99
- name as soon as the model starts writing that tool call, before its input has
100
- arrived and before the tool runs. Use it to show each step as it begins. Either
101
- hook turns streaming on; they can be used together or alone.
102
-
103
- ## Durable execution: sw.agent(options) and sw.agent.start(options)
104
-
105
- A durable call stores the initial messages, creates background work, and returns
106
- immediately. The platform invokes the same deployed function for each signed
107
- step callback. Call the same durable form from that handler; the runtime detects
108
- the callback envelope and advances exactly one step instead of creating another
109
- run.
110
-
111
- ```ts
112
- const config: SomewhereAgentDurableOptions = {
113
- model: 'claude-haiku-4-5',
114
- prompt: 'Reconcile yesterday’s orders.',
115
- tools: [
116
- {
117
- name: 'mark_reconciled',
118
- description: 'Mark one order reconciled.',
119
- input_schema: {
120
- type: 'object',
121
- properties: { id: { type: 'string' } },
122
- required: ['id'],
123
- },
124
- execute: async ({ id }, { agentId, turn, toolCallId }) => {
125
- // Use toolCallId as the idempotency identity for external side effects.
126
- return { id, agentId, turn, toolCallId }
127
- },
128
- },
129
- ],
130
- }
131
-
132
- const { agent_id, status, max_steps } = await sw.agent.start(config)
133
- ```
134
-
135
- Tools, callbacks, and credentials are not serialized into the durable
136
- checkpoint; the callback re-enters the deployed function and recreates them.
137
- The tool context carries stable `agentId`, `turn`, and `toolCallId` values
138
- for retry-safe deduplication. Inline runs set `agentId` to `null`; durable runs
139
- use the durable id. A durable run can cross a deploy because callbacks execute
140
- the then-current function code; checkpoint state records every observed
141
- deployment version.
142
-
143
- ## Status and cancellation
144
-
145
- `sw.agent.status(agentId)` reads the durable job and returns its complete job
146
- status payload with a normalized `agent_id` field added:
147
-
148
- ```js
149
- const state = await sw.agent.status(agent_id)
150
- // { ...jobStatus, agent_id: jobStatus.job_id || agent_id }
151
- ```
152
-
153
- The job payload carries the durable status, checkpoint/result or terminal error
154
- when present, and the persisted agent state. See `docs({ topic: 'sw.jobs' })`
155
- for the job status fields.
156
-
157
- `sw.agent.cancel(agentId)` requests cancellation and returns the cancellation
158
- job payload with the same normalized `agent_id` field:
159
-
160
- ```js
161
- const cancelled = await sw.agent.cancel(agent_id)
162
- // { ...cancelJobResult, agent_id: cancelJobResult.job_id || agent_id }
163
- ```
164
-
165
- Cancellation prevents later steps. It cannot undo a tool side effect that
166
- already completed or is already running. Both methods require a non-empty
167
- string id; otherwise they throw `VALIDATION_ERROR` with status 400.
168
-
169
- ## Shared options
170
-
171
- Every execution needs one input source: a non-empty `messages` array, a
172
- `prompt` string, or an `input` string. Messages must be JSON-serializable and
173
- are capped at 128 KiB of serialized text.
174
-
175
- - `provider`, `model`, `system`, `systemPrompt`, `serviceTier`, and
176
- `maxTokens` select the model call. Camel-case `systemPrompt`,
177
- `serviceTier`, and `maxTokens` map to `system`, `service_tier`, and
178
- `max_tokens` unless the snake-case field is already present.
179
- - `conversation_id` and other `sw.ai.chat` history options pass through to
180
- each model call. A conversation may span multiple inline or durable runs;
181
- `agent_id` identifies one durable run only.
182
- - `maxSteps`, `maxIterations`, and `maxTurns` are accepted limit names.
183
- The first defined name in that order wins. The value must be an integer from
184
- 1 through 20; the default is 8.
185
- - `maxSpendCents`, when it is a positive number, is checked before each model
186
- call and again after each billed step: a run whose accumulated cost has
187
- already reached the cap makes no further call, and a completed call that
188
- takes the accumulated cost over the cap stops the run. Either throws
189
- `AI_SPEND_CAP_EXCEEDED` with status 402 and partial metrics on
190
- `error.metrics`. The cap bounds the run, not the price of any single call.
191
-
192
- ## Tools
193
-
194
- `tools` accepts a keyed object or an array. Array entries have this shape:
195
-
196
- ```ts
197
- const tool: SomewhereAgentTool = {
198
- name: 'look_up_order',
199
- description: 'Look up an order by ID.',
200
- inputSchema: {
201
- type: 'object',
202
- properties: { id: { type: 'string' } },
203
- required: ['id'],
204
- },
205
- execute: async (input) => ({ id: input.id }),
206
- };
207
- ```
208
-
209
- Use `inputSchema` or `input_schema` to describe the input. An executor also
210
- receives the tool context as its second argument.
211
-
212
- Tool names must be unique and no longer than 64 characters. Missing schemas
213
- default to an empty object schema. A thrown tool error becomes an
214
- `is_error: true` tool result so the next model step can recover. A missing
215
- tool result and a non-serializable result also become error results. Serialized
216
- tool-result content is truncated after 24,000 characters.
217
-
218
- ## Step callbacks
219
-
220
- - `prepareStep(context)` runs before the model call. `context.stepNumber` is
221
- 0 for a run's first model call (it counts the steps already taken). It may return an object
222
- overriding `messages`, `provider`, `model`, `system`, `tools`,
223
- `toolChoice`, or `maxTokens` for that step; `null` and `undefined`
224
- mean no override.
225
- - `onStepFinish({ step, steps, agentId })` runs after the step trace is recorded.
226
- `agentId` is the durable run's id (`null` for an inline run), so a durable
227
- callback can store per-step data against its run. `step.cost_cents` is this
228
- model call's cost (null while pending); a durable run's stored steps keep it.
229
- - `stopWhen({ step, steps })` may return false, true, or a non-empty
230
- completion-reason string.
231
- - `onStep(event)` is also supported. It receives
232
- `{ agentId, turn, maxTurns, output, toolCalls, done, stopReason }`; its
233
- JSON-serializable return value is stored as `step.on_step`.
234
-
235
- Callback failures throw `AI_PREPARE_STEP_FAILED`, `AI_STEP_HOOK_FAILED`, or
236
- `AI_STOP_CONDITION_FAILED` with status 422. Their `error.metrics` contains
237
- the partial token/tool counts; `steps` and `total_cost_cents` on that metrics
238
- object are non-enumerable.
239
- ## Known inconsistencies
240
-
241
- - The direct `sw.agent(options)` form returns `max_turns`, while
242
- `sw.agent.start(options)` returns `max_steps`. Read the field that matches
243
- the form you called; they are not aliases in the returned object.
244
- - `steps` and `total_cost_cents` exist on inline results and partial error
245
- metrics but are non-enumerable. Direct property access works; object spread,
246
- `Object.keys`, and `JSON.stringify` omit them.
247
-
248
- These are the supported runtime shapes today, not documentation aliases.