@alexkroman1/aai-cli 0.13.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -15
- package/dist/{_bundler-CgBw5Bcu.mjs → _bundler-B6v31ROV.mjs} +1 -1
- package/dist/_console-audio.d.ts +18 -0
- package/dist/{_dev-server-BNq5OnUJ.mjs → _dev-server-GoEXEVpA.mjs} +2 -2
- package/dist/_resource-commands.d.ts +34 -2
- package/dist/{_slug-api-DJuwYZ6T.mjs → _slug-api-BnmTHtjd.mjs} +1 -1
- package/dist/{_studio-BH05zugt.mjs → _studio-B5m4jBTD.mjs} +14 -9
- package/dist/_studio.d.ts +16 -4
- package/dist/_target-bundle.d.ts +2 -0
- package/dist/{_templates-Bv-rd0SO.mjs → _templates-BVMVsQh0.mjs} +10 -6
- package/dist/_templates.d.ts +9 -2
- package/dist/{build-B37oBfEv.mjs → build-CKhanHVv.mjs} +28 -32
- package/dist/cli-workflow.d.ts +7 -0
- package/dist/cli.mjs +213 -181
- package/dist/{client-bundler-D4SeZJ8E.mjs → client-bundler-DZ_Zoznn.mjs} +2 -1
- package/dist/client-bundler.d.ts +7 -1
- package/dist/client-bundler.mjs +1 -1
- package/dist/{console-D6OOjjeJ.mjs → console-Dxq26Adz.mjs} +14 -10
- package/dist/{delete-Br0EOH0g.mjs → delete-DwXCHzTl.mjs} +8 -8
- package/dist/delete.d.ts +4 -3
- package/dist/{deploy-CLUH5cv2.mjs → deploy-CbA8Ibiu.mjs} +2 -2
- package/dist/{dev-ZVuyPLUk.mjs → dev-BWBDbUEb.mjs} +1 -1
- package/dist/{init-x3FsKl2q.mjs → init-CidslZZz.mjs} +1 -1
- package/dist/{logs-BfRq1HX9.mjs → logs-CnPK-Prw.mjs} +25 -3
- package/dist/scaffold/CLAUDE.md +52 -52
- package/dist/scaffold/agent-guide/AGENT-API.md +20 -20
- package/dist/scaffold/agent-guide/HOSTING.md +32 -33
- package/dist/scaffold/agent-guide/PIPELINE-TUNING.md +44 -47
- package/dist/scaffold/agent-guide/PROVIDERS.md +54 -57
- package/dist/scaffold/agent-guide/TESTING-EVALS.md +31 -31
- package/dist/scaffold/agent-guide/TOOLS.md +86 -87
- package/dist/scaffold/agent-guide/UI.md +59 -58
- package/dist/scaffold/agent-guide/WORKFLOWS.md +129 -127
- package/dist/scaffold/package.json +4 -4
- package/dist/scaffold/vitest.config.ts +3 -3
- package/dist/{secret-Db1UWLSZ.mjs → secret-DPdPEet2.mjs} +2 -2
- package/dist/{studio-DAoJApzD.mjs → studio-COjK25Rl.mjs} +23 -24
- package/dist/studio.d.ts +5 -4
- package/dist/templates/call-audit-workflow/agent.eval.test.ts +6 -6
- package/dist/templates/call-audit-workflow/agent.test.ts +2 -2
- package/dist/templates/document-redline-workflow/agent.eval.test.ts +14 -17
- package/dist/templates/home-assistant-agent/agent.test.ts +0 -1
- package/dist/templates/link-digest-workflow/agent.eval.test.ts +2 -2
- package/dist/templates/link-digest-workflow/agent.test.ts +24 -25
- package/dist/templates/medication-safety-agent/agent.test.ts +15 -18
- package/dist/templates/medication-safety-agent/fda.test.ts +16 -17
- package/dist/templates/medication-safety-agent/fda.ts +7 -0
- package/dist/templates/medication-safety-agent/tools/check_drug_interaction.ts +61 -53
- package/dist/templates/medication-safety-agent/tools/medication_lookup.ts +42 -32
- package/dist/templates/meeting-recap-agent/agent.eval.test.ts +29 -16
- package/dist/templates/podcast-digest-workflow/agent.eval.test.ts +3 -3
- package/dist/templates/podcast-digest-workflow/agent.test.ts +17 -17
- package/dist/templates/research-handoff-agent/agent.eval.test.ts +22 -15
- package/dist/templates/research-handoff-agent/agent.test.ts +2 -15
- package/dist/templates/research-planner-agent/agent.test.ts +22 -17
- package/dist/templates/research-planner-agent/shared.ts +122 -93
- package/dist/templates/retail-orders-agent/shared.ts +2 -2
- package/dist/templates/retail-orders-agent/tools/get_order_details.ts +1 -1
- package/dist/templates/spoken-summary-workflow/agent.eval.test.ts +6 -6
- package/dist/templates/spoken-summary-workflow/agent.test.ts +2 -2
- package/dist/templates/transcription-workflow/agent.eval.test.ts +3 -3
- package/dist/templates/transcription-workflow/agent.test.ts +2 -1
- package/dist/templates/transcription-workflow/recover.test.ts +4 -7
- package/dist/templates/web-research-agent/agent.test.ts +4 -3
- package/dist/templates/word-game-agent/agent.test.ts +11 -5
- package/package.json +6 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Workflows — durable runs, steps and workflow apps
|
|
2
2
|
|
|
3
|
-
Part of the aai authoring guide. Start with the core guide (`AGENT_GUIDE.md`
|
|
4
|
-
|
|
3
|
+
Part of the aai authoring guide. Start with the core guide (`AGENT_GUIDE.md` in
|
|
4
|
+
the SDK, `CLAUDE.md` in the scaffold); this file is the reference for
|
|
5
5
|
`workflow()`, `workflowApp()`, step code in `workflows/*.ts` and the page that
|
|
6
6
|
drives a run. Session tools that START a run are in `TOOLS.md`.
|
|
7
7
|
|
|
@@ -28,10 +28,10 @@ export default workflowApp({
|
|
|
28
28
|
});
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
That is the whole declaration, and the fields it does NOT take are the point:
|
|
32
|
-
|
|
33
|
-
`maxSteps`, `syncState`, `stt`/`llm`/`tts`/`s2s` and every voice knob
|
|
34
|
-
|
|
31
|
+
That is the whole declaration, and the fields it does NOT take are the point: a
|
|
32
|
+
workflow app has no session and no LLM loop, so `systemPrompt`, `tools`,
|
|
33
|
+
`maxSteps`, `syncState`, `stt`/`llm`/`tts`/`s2s` and every voice knob are
|
|
34
|
+
**compile errors** here, not fields that quietly do nothing. `greeting` and
|
|
35
35
|
`requiredEnv` stay. `workflowApp()` is `agent({ mode: "workflow-app", … })` with
|
|
36
36
|
the discriminant already set — same definition object out, so `aai build`,
|
|
37
37
|
`aai dev` and `aai publish` treat it like any other agent.
|
|
@@ -39,8 +39,8 @@ the discriminant already set — same definition object out, so `aai build`,
|
|
|
39
39
|
Reach for it when the user asks for something that outlives a request: an
|
|
40
40
|
overnight job, an upload that takes minutes, anything waiting on a third-party
|
|
41
41
|
callback. Reach for `agent()` when someone is on the line — a voice agent can
|
|
42
|
-
also START a workflow from a tool (`ctx.workflows.start(def, input)`) and
|
|
43
|
-
|
|
42
|
+
also START a workflow from a tool (`ctx.workflows.start(def, input)`) and answer
|
|
43
|
+
the turn, which is the other shape.
|
|
44
44
|
|
|
45
45
|
**Runs are DURABLE on the platform with no setup.** A deployed app's runs live
|
|
46
46
|
on the platform's own database, so they survive a restart, a redeploy and an
|
|
@@ -49,23 +49,23 @@ idle sandbox. There is nothing to enable.
|
|
|
49
49
|
Under `aai dev` without a `DATABASE_URL` they live in the process that started
|
|
50
50
|
them — you can submit the form, watch the run and read its result, and
|
|
51
51
|
everything in flight is lost when that process goes away. That is the honest
|
|
52
|
-
tradeoff, and it is what
|
|
53
|
-
|
|
52
|
+
tradeoff, and it is what lets you build a workflow app before provisioning
|
|
53
|
+
anything.
|
|
54
54
|
|
|
55
55
|
**A workflow UPLOAD is durable with no setup either**, and this paragraph used
|
|
56
56
|
to say the opposite. An upload's record is a platform row and its bytes are
|
|
57
|
-
platform storage, so `api.upload`, `<FileField>` and the file-taking form
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
in `TOOLS.md`.
|
|
57
|
+
platform storage, so `api.upload`, `<FileField>` and the file-taking form hooks
|
|
58
|
+
outlive the sandbox exactly as the runs reading them do — a deployed app needs
|
|
59
|
+
no database of its own for either half. Under `aai dev` they are as temporary as
|
|
60
|
+
the runs above: the bytes go to a per-process temporary directory that a restart
|
|
61
|
+
abandons. There is no `ctx.db` at all — see "Persisting data" in `TOOLS.md`.
|
|
63
62
|
|
|
64
63
|
### Workflow bodies live in `workflows/`
|
|
65
64
|
|
|
66
|
-
A body is an ordinary exported async function of its input and a
|
|
67
|
-
There is no directive and no compile step of its own — the
|
|
68
|
-
`workflows/` like any other source file — and durability
|
|
65
|
+
A body is an ordinary exported async function of its input and a
|
|
66
|
+
`WorkflowContext`. There is no directive and no compile step of its own — the
|
|
67
|
+
agent bundle compiles `workflows/` like any other source file — and durability
|
|
68
|
+
is a method call:
|
|
69
69
|
|
|
70
70
|
```ts
|
|
71
71
|
import type { WorkflowContext } from "@alexkroman1/aai";
|
|
@@ -97,18 +97,18 @@ async function file(_digest: { url: string }) {
|
|
|
97
97
|
|
|
98
98
|
`ctx.step(name, fn)` runs `fn` once, journals what it returned, and on every
|
|
99
99
|
later replay returns the journaled value without running it again. The step
|
|
100
|
-
functions themselves are ordinary functions — which is also what lets a spec
|
|
101
|
-
one directly, with no engine in the path.
|
|
100
|
+
functions themselves are ordinary functions — which is also what lets a spec
|
|
101
|
+
call one directly, with no engine in the path.
|
|
102
102
|
|
|
103
103
|
**Type the body's input from the SCHEMA, not by hand.** The example above writes
|
|
104
104
|
`input: { url: string }`, which is fine only while the workflow declares no
|
|
105
105
|
input schema. Once it does, a hand-written parameter is unchecked: `run` takes
|
|
106
106
|
its input as a function PARAMETER, so it is contravariant, and a body declaring
|
|
107
|
-
a wider shape — or the same shape with one field's optionality or default
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
a wider shape — or the same shape with one field's optionality or default wrong
|
|
108
|
+
— is assignable and compiles. A `z.number().default(5)` against a body that
|
|
109
|
+
writes `input.limit ?? 3` is the sharp version: the schema guarantees `limit` is
|
|
110
|
+
there, the `??` is dead, and the two numbers disagree with nothing to report it.
|
|
111
|
+
`WorkflowInputOf<typeof theDef>` reads the declaration instead.
|
|
112
112
|
|
|
113
113
|
**Reaching for it needs one thing that is not obvious: ANNOTATE the def.** The
|
|
114
114
|
obvious spelling does not compile —
|
|
@@ -162,8 +162,8 @@ them:
|
|
|
162
162
|
- **The body replays from the top on every resume**, so it holds no live handle
|
|
163
163
|
and makes no undurable decision — no `Date.now()`, no `Math.random()`, no
|
|
164
164
|
`crypto.randomUUID()`, no `fetch`. The three commonest have methods of their
|
|
165
|
-
own (`ctx.now()`, `ctx.random()`, `ctx.uuid()` — see below); anything else
|
|
166
|
-
inside a `ctx.step`, whose result is journaled and returned unchanged on
|
|
165
|
+
own (`ctx.now()`, `ctx.random()`, `ctx.uuid()` — see below); anything else
|
|
166
|
+
goes inside a `ctx.step`, whose result is journaled and returned unchanged on
|
|
167
167
|
replay.
|
|
168
168
|
- **A step's arguments and return value cross a queue**, so they must be
|
|
169
169
|
JSON-shaped and small. Put bytes in storage and pass the key.
|
|
@@ -180,8 +180,8 @@ share a name: the journal keys an entry by `(name, occurrence)`, so two sites
|
|
|
180
180
|
alias onto one counter and read each other's journaled results. Nothing detects
|
|
181
181
|
it.
|
|
182
182
|
|
|
183
|
-
**Per-step retries are an argument, not a property.** Pass
|
|
184
|
-
|
|
183
|
+
**Per-step retries are an argument, not a property.** Pass `{ maxAttempts }`
|
|
184
|
+
where a step deserves more patience than the default three:
|
|
185
185
|
|
|
186
186
|
```ts no-check
|
|
187
187
|
const digest = await ctx.step("summarize", () => summarize(input.url), {
|
|
@@ -189,8 +189,8 @@ const digest = await ctx.step("summarize", () => summarize(input.url), {
|
|
|
189
189
|
});
|
|
190
190
|
```
|
|
191
191
|
|
|
192
|
-
**And a step body can read which attempt it is on**, so a step may degrade
|
|
193
|
-
than fail — a smaller model on the last try beats a failed run:
|
|
192
|
+
**And a step body can read which attempt it is on**, so a step may degrade
|
|
193
|
+
rather than fail — a smaller model on the last try beats a failed run:
|
|
194
194
|
|
|
195
195
|
```ts
|
|
196
196
|
import { stepInfo } from "@alexkroman1/aai/step";
|
|
@@ -236,18 +236,18 @@ export async function chargeFlow(input: { amount: number }, ctx: WorkflowContext
|
|
|
236
236
|
and the same value after a resume, so a retried request is recognisably the same
|
|
237
237
|
request rather than a second one. `ctx.random()` draws one float per CALL, so a
|
|
238
238
|
loop is correct as written; a BULK draw belongs in a step
|
|
239
|
-
(`ctx.step("jitter", () => Array.from({ length: 1000 }, Math.random))`), which
|
|
240
|
-
one journal entry instead of a thousand.
|
|
239
|
+
(`ctx.step("jitter", () => Array.from({ length: 1000 }, Math.random))`), which
|
|
240
|
+
is one journal entry instead of a thousand.
|
|
241
241
|
|
|
242
242
|
Two rules:
|
|
243
243
|
|
|
244
|
-
- **Call them from the BODY, never inside a `ctx.step`** — the engine refuses
|
|
245
|
-
there and the message names the fix. Inside a step there is nothing to
|
|
246
|
-
step's internals are not replayed, only its result, so a plain
|
|
247
|
-
a step body is already durable and is what to write.
|
|
244
|
+
- **Call them from the BODY, never inside a `ctx.step`** — the engine refuses
|
|
245
|
+
one there and the message names the fix. Inside a step there is nothing to
|
|
246
|
+
fix: a step's internals are not replayed, only its result, so a plain
|
|
247
|
+
`Date.now()` in a step body is already durable and is what to write.
|
|
248
248
|
- **A `ctx.uuid()` is not a hook TOKEN.** `ctx.waitFor`'s token has to be
|
|
249
|
-
DERIVED from the run's own input, because whoever signals is usually a tool
|
|
250
|
-
a tool cannot see the body's local variables. See below.
|
|
249
|
+
DERIVED from the run's own input, because whoever signals is usually a tool
|
|
250
|
+
and a tool cannot see the body's local variables. See below.
|
|
251
251
|
|
|
252
252
|
### Waiting: `ctx.sleep` and `ctx.waitFor`
|
|
253
253
|
|
|
@@ -258,7 +258,8 @@ brings the run back — so a long wait costs nothing while it runs.
|
|
|
258
258
|
platform it is durable with no setup, and a self-hosted deployment with a
|
|
259
259
|
`DATABASE_URL` is durable too — the wait outlives the body, the worker and the
|
|
260
260
|
process. Under `aai dev` without a `DATABASE_URL` the store is memory, so a wait
|
|
261
|
-
lives only as long as the dev server. The boot line reports which one is in
|
|
261
|
+
lives only as long as the dev server. The boot line reports which one is in
|
|
262
|
+
play.
|
|
262
263
|
|
|
263
264
|
```ts no-check
|
|
264
265
|
// A label, then a duration in milliseconds or an absolute Date.
|
|
@@ -275,29 +276,30 @@ if (approval === undefined) return { published: false, reason: "nobody approved"
|
|
|
275
276
|
|
|
276
277
|
Five things worth knowing:
|
|
277
278
|
|
|
278
|
-
- **A wait's NAME is its identity, exactly like a step's.** A sleep's `label`
|
|
279
|
-
a `waitFor`'s token are what the journal keys the wait on
|
|
279
|
+
- **A wait's NAME is its identity, exactly like a step's.** A sleep's `label`
|
|
280
|
+
and a `waitFor`'s token are what the journal keys the wait on
|
|
280
281
|
(`sleep!<label>#<occurrence>`, `hook!<token>#<occurrence>`), so make a label a
|
|
281
282
|
string literal, give two call sites two labels, and let a loop reuse one — the
|
|
282
283
|
occurrence count separates the iterations. This is what makes a wait behind an
|
|
283
|
-
`if` safe: the body can reach a different NUMBER of waits on two walks and
|
|
284
|
-
one still finds its own record.
|
|
284
|
+
`if` safe: the body can reach a different NUMBER of waits on two walks and
|
|
285
|
+
each one still finds its own record.
|
|
285
286
|
- **A hook's token must be DERIVED, not random.** Whoever signals is usually a
|
|
286
|
-
tool, and a tool cannot see the body's local variables — so export one
|
|
287
|
-
that computes the token from the run's own input and import it in
|
|
288
|
-
Derive it from something that identifies the RUN rather than the
|
|
289
|
-
token is held for the life of its run, so two runs deriving the same
|
|
290
|
-
second one failing.
|
|
287
|
+
tool, and a tool cannot see the body's local variables — so export one
|
|
288
|
+
function that computes the token from the run's own input and import it in
|
|
289
|
+
both places. Derive it from something that identifies the RUN rather than the
|
|
290
|
+
caller: a token is held for the life of its run, so two runs deriving the same
|
|
291
|
+
one is the second one failing.
|
|
291
292
|
- **`timeoutMs` resolves `undefined` when the window closes unanswered.** A
|
|
292
|
-
closing window is an outcome to branch on, not a failure, and the engine
|
|
293
|
-
the hook as it shuts so a late answer cannot change what already
|
|
293
|
+
closing window is an outcome to branch on, not a failure, and the engine
|
|
294
|
+
closes the hook as it shuts so a late answer cannot change what already
|
|
295
|
+
happened.
|
|
294
296
|
- **Racing two independent waits WORKS** (the run suspends once, on the
|
|
295
297
|
earliest), but a deadline ON a wait is `timeoutMs`: it CLOSES the hook before
|
|
296
298
|
the body continues, so a late signal cannot change a window already timed out.
|
|
297
|
-
- **`ctx.workflows.wakeUp(runId, { correlationIds: [id] })`** ends a sleep
|
|
298
|
-
which is how a "send it now" tool cuts a scheduled wait short. Naming
|
|
299
|
-
wakes every outstanding SLEEP and deliberately not a `waitFor`
|
|
300
|
-
cutting a schedule short cannot also close an approval window.
|
|
299
|
+
- **`ctx.workflows.wakeUp(runId, { correlationIds: [id] })`** ends a sleep
|
|
300
|
+
early, which is how a "send it now" tool cuts a scheduled wait short. Naming
|
|
301
|
+
no ids wakes every outstanding SLEEP and deliberately not a `waitFor`
|
|
302
|
+
deadline, so cutting a schedule short cannot also close an approval window.
|
|
301
303
|
- **A SUSPEND is not free, so `ctx.sleep` is not a `setTimeout`.** A wait costs
|
|
302
304
|
a journal write to record it, a queued delivery to bring the run back, and a
|
|
303
305
|
fresh WALK of the body — measured on a deployed agent at roughly a second of
|
|
@@ -307,11 +309,12 @@ Five things worth knowing:
|
|
|
307
309
|
whole cost.
|
|
308
310
|
|
|
309
311
|
So a sub-second pause is not what this is for. For a short backoff inside a
|
|
310
|
-
step, use an ordinary timer (`sleep` from `@alexkroman1/aai/internal`) — a
|
|
311
|
-
body may not call `ctx.sleep` anyway, and the engine refuses one that
|
|
312
|
-
`ctx.sleep` for a wait you want to SURVIVE the process, which is the
|
|
313
|
-
timer cannot do. A body that polls in a loop pays the suspend per
|
|
314
|
-
which is the strongest argument for the next section: park on the
|
|
312
|
+
step, use an ordinary timer (`sleep` from `@alexkroman1/aai/internal`) — a
|
|
313
|
+
step body may not call `ctx.sleep` anyway, and the engine refuses one that
|
|
314
|
+
does. Use `ctx.sleep` for a wait you want to SURVIVE the process, which is the
|
|
315
|
+
thing a timer cannot do. A body that polls in a loop pays the suspend per
|
|
316
|
+
iteration, which is the strongest argument for the next section: park on the
|
|
317
|
+
callback.
|
|
315
318
|
|
|
316
319
|
#### A third-party callback is an OPTIMIZATION over a reconciling read
|
|
317
320
|
|
|
@@ -323,9 +326,9 @@ already paid for:
|
|
|
323
326
|
|
|
324
327
|
- **Mint it with `stepWebhookUrl(token)`, from inside the step that hands it
|
|
325
328
|
over.** That is the step-side half of `ctx.workflows.publicWebhookUrl` — the
|
|
326
|
-
tool-side one needs a `ToolContext`, which a step is not handed. It THROWS
|
|
327
|
-
the deployment cannot mint one, which a step should catch and treat as
|
|
328
|
-
callback": a run must not fail over a missing optimization. And note
|
|
329
|
+
tool-side one needs a `ToolContext`, which a step is not handed. It THROWS
|
|
330
|
+
when the deployment cannot mint one, which a step should catch and treat as
|
|
331
|
+
"no callback": a run must not fail over a missing optimization. And note
|
|
329
332
|
`requireStepEnv("AAI_PUBLIC_BASE_URL")` is NOT a substitute — the public base
|
|
330
333
|
URL is a boot parameter of the deployment, not one of the agent's own secrets,
|
|
331
334
|
so that read is `undefined` in production precisely where the value exists.
|
|
@@ -335,22 +338,22 @@ already paid for:
|
|
|
335
338
|
— it runs once, on first execution, never on a replay — and answer
|
|
336
339
|
`{ id, callback }`.
|
|
337
340
|
- **Keep the poll as the TIMEOUT arm.** A webhook is one HTTP POST from a third
|
|
338
|
-
party with no delivery guarantee you control: the sender gives up after its
|
|
339
|
-
retry budget, a deployment may not know its public URL, and a delivery
|
|
340
|
-
lands before your body reaches its wait is answered `404` and dropped. So
|
|
341
|
-
the state before you park and again after, give the wait a `timeoutMs`,
|
|
342
|
-
an unanswered window fall through to the read.
|
|
341
|
+
party with no delivery guarantee you control: the sender gives up after its
|
|
342
|
+
own retry budget, a deployment may not know its public URL, and a delivery
|
|
343
|
+
that lands before your body reaches its wait is answered `404` and dropped. So
|
|
344
|
+
read the state before you park and again after, give the wait a `timeoutMs`,
|
|
345
|
+
and let an unanswered window fall through to the read.
|
|
343
346
|
- **Wait for the EDGE, not the answer.** Treat the payload as "something
|
|
344
347
|
happened, go look" and get the fact from the far side's own API under your own
|
|
345
|
-
credential. That is what makes an unauthenticated callback route safe: a
|
|
346
|
-
delivery on a guessed token costs one extra read and changes no
|
|
347
|
-
route authorizes on the TOKEN and reads no other header, so a
|
|
348
|
-
auth-header option is ignored.
|
|
348
|
+
credential. That is what makes an unauthenticated callback route safe: a
|
|
349
|
+
forged delivery on a guessed token costs one extra read and changes no
|
|
350
|
+
outcome. The route authorizes on the TOKEN and reads no other header, so a
|
|
351
|
+
sender's own auth-header option is ignored.
|
|
349
352
|
- **One token, ONE `waitFor` per run.** A token is claimed for the life of its
|
|
350
|
-
run and given back when the run goes terminal, so a second `ctx.waitFor` on
|
|
351
|
-
same token — a wait written inside a loop — THROWS. A throw is not a
|
|
352
|
-
so a body with a `catch` will treat it as a failed run and start
|
|
353
|
-
Park once, outside the loop.
|
|
353
|
+
run and given back when the run goes terminal, so a second `ctx.waitFor` on
|
|
354
|
+
the same token — a wait written inside a loop — THROWS. A throw is not a
|
|
355
|
+
suspend, so a body with a `catch` will treat it as a failed run and start
|
|
356
|
+
compensating. Park once, outside the loop.
|
|
354
357
|
- **You cannot test it under `aai dev` without a tunnel.** `publicUrl` there is
|
|
355
358
|
`http://localhost:<backend port>`, which no third party can reach — so the
|
|
356
359
|
delivery never arrives and the run silently takes the fallback.
|
|
@@ -362,9 +365,9 @@ Steps are ordinary exported functions, so a spec imports and calls them. The
|
|
|
362
365
|
BODY needs an engine, and there are two, for two different questions.
|
|
363
366
|
|
|
364
367
|
**"What did the body ask for?"** — `createWorkflowContext` from
|
|
365
|
-
`@alexkroman1/aai-runtime/testing`. It runs the steps and records the names,
|
|
366
|
-
|
|
367
|
-
|
|
368
|
+
`@alexkroman1/aai-runtime/testing`. It runs the steps and records the names, the
|
|
369
|
+
retry policies and the sleeps, over one walk with no journal. Nothing replays,
|
|
370
|
+
so a spec built on it must not claim to test durability.
|
|
368
371
|
|
|
369
372
|
```ts no-check
|
|
370
373
|
import { createWorkflowContext } from "@alexkroman1/aai-runtime/testing";
|
|
@@ -414,8 +417,8 @@ Three more things it can do, each the thing a durable body is written for:
|
|
|
414
417
|
second run sees.
|
|
415
418
|
|
|
416
419
|
Stub the steps' collaborators at the seams they really use — a step's HTTP goes
|
|
417
|
-
through the published `stepFetch` slot, so a model call and a page fetch are
|
|
418
|
-
answered there. `stubGatewayRoute` composes the two:
|
|
420
|
+
through the published `stepFetch` slot, so a model call and a page fetch are
|
|
421
|
+
BOTH answered there. `stubGatewayRoute` composes the two:
|
|
419
422
|
|
|
420
423
|
```ts no-check
|
|
421
424
|
import { stubGatewayRoute } from "@alexkroman1/aai-runtime/testing";
|
|
@@ -496,16 +499,16 @@ and a second later all N ask again.
|
|
|
496
499
|
**Reach for the raw call when the failure is not simply a failure** — a `404`
|
|
497
500
|
that means "already deleted", a `4xx` whose body decides which advice to print.
|
|
498
501
|
Then classify it yourself: `throwStepError(err)`, `throwFatalStepError(err)` to
|
|
499
|
-
stop outright, `toStepError(cause, message)` to build the error without
|
|
500
|
-
or `throwFfmpegStepError(err)` for a media failure, whose default runs
|
|
501
|
-
way (only a `timeout` or an `aborted` is worth another attempt).
|
|
502
|
+
stop outright, `toStepError(cause, message)` to build the error without
|
|
503
|
+
throwing, or `throwFfmpegStepError(err)` for a media failure, whose default runs
|
|
504
|
+
the other way (only a `timeout` or an `aborted` is worth another attempt).
|
|
502
505
|
|
|
503
506
|
**Why the split exists, since the wrapped call is what you usually want:**
|
|
504
507
|
importing from here is the OPT-IN, and `/step` is not written only for a step:
|
|
505
|
-
`mapConcurrent` bounds a rate-limited call anywhere, `stepFetch` is an
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
508
|
+
`mapConcurrent` bounds a rate-limited call anywhere, `stepFetch` is an ordinary
|
|
509
|
+
HTTP client, and your specs drive exported steps directly. None of those callers
|
|
510
|
+
has a retry budget to burn, so none should meet a vocabulary whose whole subject
|
|
511
|
+
is one. A step pays nothing for the extra import line.
|
|
509
512
|
|
|
510
513
|
### Media, big files, and transcription from a step
|
|
511
514
|
|
|
@@ -516,15 +519,14 @@ bundling rule as `/step` — import them there, never through the root barrel:
|
|
|
516
519
|
recording, or `stepTranscribeUpload` → `stepTranscribeSubmit` →
|
|
517
520
|
`stepTranscribePoll` for a long one, plus `Transcript`, `TranscribeError` and
|
|
518
521
|
the `TRANSCRIBE_*` limits. (There is no `/transcribe` subpath; transcription
|
|
519
|
-
lives on `/step` with the other step primitives.) Wrap each in `orFail`
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
until its attempts run out.
|
|
522
|
+
lives on `/step` with the other step primitives.) Wrap each in `orFail` as
|
|
523
|
+
above: a provider refusal — a container it will not read, a recording with no
|
|
524
|
+
speech — arrives with `retryable: false`, and unclassified a step re-uploads
|
|
525
|
+
the same bytes until its attempts run out.
|
|
524
526
|
- **`@alexkroman1/aai/ffmpeg`** — `transcodeToWav(bytes, { sampleRate })`,
|
|
525
527
|
`runFfmpeg(args)`, `probeMedia(source)` for duration and stream info, and
|
|
526
|
-
`FfmpegError`/`isFfmpegError`. Under `aai dev` it needs ffmpeg on your PATH;
|
|
527
|
-
|
|
528
|
+
`FfmpegError`/`isFfmpegError`. Under `aai dev` it needs ffmpeg on your PATH; a
|
|
529
|
+
`missing-binary` failure says so and carries the install line.
|
|
528
530
|
- **`@alexkroman1/aai/step-files`** — for a recording too big to hold in memory.
|
|
529
531
|
`readUploadToFile(uploadId, path)` streams an upload to disk,
|
|
530
532
|
`writeUploadFromFile(path)` streams one back, and `withTempDir(work)` gives
|
|
@@ -582,20 +584,19 @@ sentence a person can act on. `podcast-digest-workflow` is the worked example.
|
|
|
582
584
|
|
|
583
585
|
A run reaches a device holding `WS /inbox?client=<id>` open: a tool passes
|
|
584
586
|
`sessionClientId(ctx)` to the run, and a step's `stepNotifyClient` throws a
|
|
585
|
-
retryable error until the device acks. Test: `stubClientInbox`.
|
|
586
|
-
|
|
587
|
-
`
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
id; `useInbox({ onNotice })` holds the inbox (busy mid-call) and plays notices;
|
|
587
|
+
retryable error until the device acks. Test: `stubClientInbox`. `?client=` also
|
|
588
|
+
makes a device one conversation across connects (self-hosted): `sessionContext`,
|
|
589
|
+
`onSessionEnd`, `stepClientTranscript`; its id is the only key. A page is a
|
|
590
|
+
device too: `mountClient({ client: "auto" })` keeps a per-browser id;
|
|
591
|
+
`useInbox({ onNotice })` holds the inbox (busy mid-call) and plays notices;
|
|
591
592
|
`useClientId()`/`useSessionId()` read the ids. Also: `useTapToTalk`,
|
|
592
593
|
`useConversationLog`, `useRoute`, `createStoredValue`.
|
|
593
594
|
|
|
594
595
|
### A step's HTTP: use `stepFetch`, not `fetch`
|
|
595
596
|
|
|
596
597
|
Any outbound request from a step goes through `stepFetch` (also
|
|
597
|
-
`@alexkroman1/aai/step`). Not a style preference: `fetch` is the wrong call
|
|
598
|
-
|
|
598
|
+
`@alexkroman1/aai/step`). Not a style preference: `fetch` is the wrong call from
|
|
599
|
+
a step, for a reason the call site does not show:
|
|
599
600
|
|
|
600
601
|
```ts no-check
|
|
601
602
|
import { multipartBody, stepFetch, StepTransportError } from "@alexkroman1/aai/step";
|
|
@@ -629,14 +630,14 @@ connection, sharing one flow-control window: fine for small JSON, pathological
|
|
|
629
630
|
for `mapConcurrent` over large bodies (8 concurrent 17.66 MB uploads: `fetch`
|
|
630
631
|
landed 14 of 16 at p50 8094ms, HTTP/1.1 16 of 16 at p50 3037ms).
|
|
631
632
|
|
|
632
|
-
**The two it lost matter more than the latency.** On
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
633
|
+
**The two it lost matter more than the latency.** On HTTP/2 a capacity limit
|
|
634
|
+
arrives as a _stream reset_ — `NGHTTP2_ENHANCE_YOUR_CALM` — and a stream error
|
|
635
|
+
carries no HTTP status, so `isTransientStatus` and `retryAfter` cannot see it.
|
|
636
|
+
Every sibling in the batch then retries in lockstep into the same reset,
|
|
637
|
+
exhausts the step's attempts, and fails the run with `TypeError: fetch failed`,
|
|
638
|
+
whose real cause is two `cause` hops down where nothing prints it. Over HTTP/1.1
|
|
639
|
+
the identical limit arrives as `503` with `retry-after`, which your retry policy
|
|
640
|
+
already reads.
|
|
640
641
|
|
|
641
642
|
Three rules come with it:
|
|
642
643
|
|
|
@@ -651,9 +652,9 @@ Three rules come with it:
|
|
|
651
652
|
`cause` chain, and `err.codes` is what to branch on (`ECONNRESET`,
|
|
652
653
|
`ETIMEDOUT`, …).
|
|
653
654
|
- **Test it with `stubStepFetch`** (`@alexkroman1/aai-runtime/testing`), not
|
|
654
|
-
`vi.stubGlobal("fetch", …)`. The global stub passes — an unpublished slot
|
|
655
|
-
back to it — while asserting a path production does not take, and it
|
|
656
|
-
the request body as bytes.
|
|
655
|
+
`vi.stubGlobal("fetch", …)`. The global stub passes — an unpublished slot
|
|
656
|
+
falls back to it — while asserting a path production does not take, and it
|
|
657
|
+
cannot see the request body as bytes.
|
|
657
658
|
|
|
658
659
|
`stepGenerate` already goes through this, so a step that only calls a model gets
|
|
659
660
|
it for free.
|
|
@@ -661,9 +662,9 @@ it for free.
|
|
|
661
662
|
### A step can SPEAK, and store the file it made
|
|
662
663
|
|
|
663
664
|
A workflow whose answer is a FILE — a summary read aloud, a rendered image, a
|
|
664
|
-
generated PDF — needs two things a first draft reaches for and misses.
|
|
665
|
-
|
|
666
|
-
|
|
665
|
+
generated PDF — needs two things a first draft reaches for and misses. Both are
|
|
666
|
+
on `@alexkroman1/aai/step`, and `spoken-summary-workflow` shows the whole round
|
|
667
|
+
trip.
|
|
667
668
|
|
|
668
669
|
```ts
|
|
669
670
|
import { stepSpeak, stepWriteUpload } from "@alexkroman1/aai/step";
|
|
@@ -740,7 +741,8 @@ search wrote it, and one of them had a `catch` for this exact failure — which
|
|
|
740
741
|
never ran, because a `catch` cannot see a returned value. DuckDuckGo refuses
|
|
741
742
|
often enough that the empty answer is routine, and to the model "no results" and
|
|
742
743
|
"the search was blocked" are different facts: told the first, it concludes the
|
|
743
|
-
pages do not exist and tries again with different words until its budget is
|
|
744
|
+
pages do not exist and tries again with different words until its budget is
|
|
745
|
+
gone.
|
|
744
746
|
|
|
745
747
|
An UNTYPED call (`await fetchJson(url)`) stays loose and needs no narrowing —
|
|
746
748
|
naming a shape is what asks the compiler to make you handle the failure.
|
|
@@ -748,9 +750,9 @@ naming a shape is what asks the compiler to make you handle the failure.
|
|
|
748
750
|
### The page
|
|
749
751
|
|
|
750
752
|
A workflow app's `client.tsx` mounts with `mountPage()` rather than
|
|
751
|
-
`mountClient()` — there is no session to build, so no socket, no audio graph
|
|
752
|
-
|
|
753
|
-
|
|
753
|
+
`mountClient()` — there is no session to build, so no socket, no audio graph and
|
|
754
|
+
no microphone request. Everything else is the same file, React and Tailwind
|
|
755
|
+
included.
|
|
754
756
|
|
|
755
757
|
```tsx no-check
|
|
756
758
|
import { createWorkflowApi, mountPage, useWorkflowRun } from "@alexkroman1/aai-ui";
|
|
@@ -784,11 +786,11 @@ export function App() {
|
|
|
784
786
|
mountPage({ name: "Link Digest", component: App });
|
|
785
787
|
```
|
|
786
788
|
|
|
787
|
-
`api.start()` resolves as soon as the RUN EXISTS, not when it finishes — that
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
789
|
+
`api.start()` resolves as soon as the RUN EXISTS, not when it finishes — that is
|
|
790
|
+
the whole mechanism. The `runId` is the entire client state, so it survives a
|
|
791
|
+
reload, a different device, or `curl`. Note the workflow is named by the key it
|
|
792
|
+
has in `workflows` above (`"digest"`); nothing else records that string, so a
|
|
793
|
+
rename there is a 400 here rather than a compile error.
|
|
792
794
|
|
|
793
795
|
The same routes are scriptable, which is the other half of having an API:
|
|
794
796
|
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"publish:agent": "aai publish"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@alexkroman1/aai": "^0.
|
|
19
|
-
"@alexkroman1/aai-cli": "^0.
|
|
20
|
-
"@alexkroman1/aai-runtime": "^0.
|
|
21
|
-
"@alexkroman1/aai-ui": "^0.
|
|
18
|
+
"@alexkroman1/aai": "^0.14.1",
|
|
19
|
+
"@alexkroman1/aai-cli": "^0.14.1",
|
|
20
|
+
"@alexkroman1/aai-runtime": "^0.14.1",
|
|
21
|
+
"@alexkroman1/aai-ui": "^0.14.1",
|
|
22
22
|
"react": "^19.3.0",
|
|
23
23
|
"react-dom": "^19.3.0",
|
|
24
24
|
"tailwindcss": "^4.0.0",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineAgentTestConfig } from "@alexkroman1/aai/testing/vite";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* The agent plugin (`virtual:aai/agent`), `globals: true
|
|
5
|
-
*
|
|
6
|
-
* to it: `defineAgentTestConfig({ test: { testTimeout: 10_000 } })`.
|
|
4
|
+
* The agent plugin (`virtual:aai/agent`), `globals: true`, a pinned reporter,
|
|
5
|
+
* and spies, env and global stubs undone after every test — each argued for
|
|
6
|
+
* where it lives, in the SDK. Pass overrides to add to it: `defineAgentTestConfig({ test: { testTimeout: 10_000 } })`.
|
|
7
7
|
*/
|
|
8
8
|
export default defineAgentTestConfig();
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { a as ok, n as fail, t as CliError } from "./_output-DBP9Op_d.mjs";
|
|
3
3
|
import { i as unwrapCancel, t as defaultUi } from "./_ui-Coe0zwmm.mjs";
|
|
4
4
|
import { _ as writeFileAtomic, p as readTextIfPresent } from "./_utils-BVLdBvdT.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import { n as secretRequest, t as REAL_PLATFORM } from "./_slug-api-
|
|
5
|
+
import { m as isStringArray, p as checkedResponse } from "./_studio-B5m4jBTD.mjs";
|
|
6
|
+
import { n as secretRequest, t as REAL_PLATFORM } from "./_slug-api-BnmTHtjd.mjs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { isRecord, plural } from "@alexkroman1/aai/utils";
|
|
9
9
|
import fs from "node:fs/promises";
|
|
@@ -4,9 +4,8 @@ import { n as fmtUrl, t as defaultUi } from "./_ui-Coe0zwmm.mjs";
|
|
|
4
4
|
import { l as formatCappedList } from "./_utils-BVLdBvdT.mjs";
|
|
5
5
|
import { s as updateProjectConfig } from "./_config-mq1I5Cva.mjs";
|
|
6
6
|
import { i as resolveServerEnv } from "./_server-common-CVXIeWrY.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { a as publishStudioProject, c as studioProjectUrl, f as checkedResponse, i as projectNameFromDir, n as fetchStudioProject, o as pushStudioSource, r as listStudioProjects, s as studioProjectApiUrl, t as collectSourceFiles, u as apiRequest } from "./_studio-BH05zugt.mjs";
|
|
7
|
+
import { layerScaffold } from "./_templates-BVMVsQh0.mjs";
|
|
8
|
+
import { a as projectNameFromDir, c as studioProjectApiUrl, i as listStudioProjects, l as studioProjectUrl, n as collectSourceFiles, o as publishStudioProject, p as checkedResponse, r as fetchStudioProject, s as pushStudioSource, t as REAL_STUDIO_DEPS } from "./_studio-B5m4jBTD.mjs";
|
|
10
9
|
import { existsSync } from "node:fs";
|
|
11
10
|
import path from "node:path";
|
|
12
11
|
import { isRecord, omitUndefined, plural } from "@alexkroman1/aai/utils";
|
|
@@ -26,9 +25,9 @@ import { isPathInside } from "@alexkroman1/aai-runtime/internal";
|
|
|
26
25
|
* in-sandbox deploy the Publish button runs. There is no other path to
|
|
27
26
|
* production.
|
|
28
27
|
*/
|
|
29
|
-
async function executeList(opts, ui = defaultUi) {
|
|
30
|
-
const { serverUrl, apiKey } = await resolveDeployTarget(opts.cwd, opts.server);
|
|
31
|
-
const projects = await listStudioProjects(serverUrl, apiKey);
|
|
28
|
+
async function executeList(opts, ui = defaultUi, deps = REAL_STUDIO_DEPS) {
|
|
29
|
+
const { serverUrl, apiKey } = await deps.resolveDeployTarget(opts.cwd, opts.server);
|
|
30
|
+
const projects = await listStudioProjects(serverUrl, apiKey, deps.apiRequest);
|
|
32
31
|
if (projects.length === 0) ui.log.info("No studio projects yet. Push one with `aai push`, or create one in the studio.");
|
|
33
32
|
for (const name of projects) ui.log.message(`${name} ${fmtUrl(studioProjectUrl(serverUrl, name))}`);
|
|
34
33
|
return ok({ projects });
|
|
@@ -59,16 +58,16 @@ async function materializeFiles(dir, files) {
|
|
|
59
58
|
* effort: the list is a second request on an already-failing path, and its
|
|
60
59
|
* own failure must not replace the 404 the user needs to see.
|
|
61
60
|
*/
|
|
62
|
-
async function notFoundHint(serverUrl, apiKey) {
|
|
63
|
-
const projects = await listStudioProjects(serverUrl, apiKey).catch(() => null);
|
|
61
|
+
async function notFoundHint(serverUrl, apiKey, deps) {
|
|
62
|
+
const projects = await listStudioProjects(serverUrl, apiKey, deps.apiRequest).catch(() => null);
|
|
64
63
|
if (projects === null) return "Run `aai list` to see your projects.";
|
|
65
64
|
if (projects.length === 0) return "This login has no studio projects at all. If yours are in the studio, the CLI is linked to a different account — run `aai login` again, approve it in a browser signed in to the account that owns the project, then `aai list`.";
|
|
66
65
|
return `Your projects: ${formatCappedList(projects)}.`;
|
|
67
66
|
}
|
|
68
|
-
async function executePull(opts, ui = defaultUi) {
|
|
69
|
-
const { serverUrl, apiKey } = await resolveDeployTarget(opts.cwd, opts.server);
|
|
70
|
-
const remote = await fetchStudioProject(serverUrl, apiKey, opts.project);
|
|
71
|
-
if (!remote) throw new CliError("not_found", `No studio project named "${opts.project}".`, await notFoundHint(serverUrl, apiKey));
|
|
67
|
+
async function executePull(opts, ui = defaultUi, deps = REAL_STUDIO_DEPS) {
|
|
68
|
+
const { serverUrl, apiKey } = await deps.resolveDeployTarget(opts.cwd, opts.server);
|
|
69
|
+
const remote = await fetchStudioProject(serverUrl, apiKey, opts.project, deps.apiRequest);
|
|
70
|
+
if (!remote) throw new CliError("not_found", `No studio project named "${opts.project}".`, await notFoundHint(serverUrl, apiKey, deps));
|
|
72
71
|
const target = path.resolve(opts.cwd, opts.dir ?? opts.project);
|
|
73
72
|
if ((await readdir(target).catch(() => [])).length > 0 && !opts.force) throw new CliError("dir_not_empty", `${target} is not empty.`, "Pull into a fresh directory, or pass --force to overwrite files in place.");
|
|
74
73
|
await materializeFiles(target, remote.files);
|
|
@@ -93,8 +92,8 @@ async function executePull(opts, ui = defaultUi) {
|
|
|
93
92
|
* The shared push core: collect local source, resolve (or mint) the linked
|
|
94
93
|
* project, sync atomically, record the new fast-forward token.
|
|
95
94
|
*/
|
|
96
|
-
async function pushProject(opts, ui) {
|
|
97
|
-
const { config, serverUrl, apiKey } = await resolveDeployTarget(opts.cwd, opts.server);
|
|
95
|
+
async function pushProject(opts, ui, deps) {
|
|
96
|
+
const { config, serverUrl, apiKey } = await deps.resolveDeployTarget(opts.cwd, opts.server);
|
|
98
97
|
const { files, warnings } = await collectSourceFiles(opts.cwd);
|
|
99
98
|
for (const warning of warnings) ui.log.warn(warning);
|
|
100
99
|
if (Object.keys(files).length === 0) throw new Error("Nothing to push — this directory has no project files.");
|
|
@@ -108,7 +107,7 @@ async function pushProject(opts, ui) {
|
|
|
108
107
|
if (!project) {
|
|
109
108
|
project = slug ?? projectNameFromDir(opts.cwd) ?? void 0;
|
|
110
109
|
if (!project) throw new Error(`Can't derive a project name from ${path.basename(opts.cwd)} — rename the directory or run \`aai pull <project>\` to link an existing one.`);
|
|
111
|
-
const existing = await fetchStudioProject(serverUrl, apiKey, project);
|
|
110
|
+
const existing = await fetchStudioProject(serverUrl, apiKey, project, deps.apiRequest);
|
|
112
111
|
if (existing && !opts.force) throw new CliError("project_exists", `Your studio already has a project named "${project}".`, `Run \`aai pull ${project}\` to link this directory to it, or \`aai push --force\` to overwrite it.`);
|
|
113
112
|
baseHash = existing?.sourceHash;
|
|
114
113
|
slug ??= existing?.deployedSlug;
|
|
@@ -116,7 +115,7 @@ async function pushProject(opts, ui) {
|
|
|
116
115
|
const result = await pushStudioSource(serverUrl, apiKey, project, {
|
|
117
116
|
files,
|
|
118
117
|
...omitUndefined({ baseHash: opts.force ? void 0 : baseHash })
|
|
119
|
-
});
|
|
118
|
+
}, deps.apiRequest);
|
|
120
119
|
await updateProjectConfig(opts.cwd, {
|
|
121
120
|
serverUrl,
|
|
122
121
|
studioProject: project,
|
|
@@ -133,8 +132,8 @@ async function pushProject(opts, ui) {
|
|
|
133
132
|
warnings
|
|
134
133
|
};
|
|
135
134
|
}
|
|
136
|
-
async function executePush(opts, ui = defaultUi) {
|
|
137
|
-
const pushed = await pushProject(opts, ui);
|
|
135
|
+
async function executePush(opts, ui = defaultUi, deps = REAL_STUDIO_DEPS) {
|
|
136
|
+
const pushed = await pushProject(opts, ui, deps);
|
|
138
137
|
const url = studioProjectUrl(pushed.serverUrl, pushed.project);
|
|
139
138
|
ui.log.success(`${pushed.created ? "Created" : "Synced"} studio project ${pushed.project} — ${fmtUrl(url)}`);
|
|
140
139
|
return ok({
|
|
@@ -163,11 +162,11 @@ async function executePush(opts, ui = defaultUi) {
|
|
|
163
162
|
* server-side, a project with nothing deployed resolves to an empty target set
|
|
164
163
|
* and the record write is the whole operation.
|
|
165
164
|
*/
|
|
166
|
-
async function syncEnvSecrets(cwd, serverUrl, apiKey, project, ui) {
|
|
165
|
+
async function syncEnvSecrets(cwd, serverUrl, apiKey, project, ui, request) {
|
|
167
166
|
const env = await resolveServerEnv(cwd);
|
|
168
167
|
const names = Object.keys(env);
|
|
169
168
|
if (names.length === 0) return [];
|
|
170
|
-
await
|
|
169
|
+
await request(`${studioProjectApiUrl(serverUrl, project)}/secret`, {
|
|
171
170
|
apiKey,
|
|
172
171
|
action: "secret",
|
|
173
172
|
method: "PUT",
|
|
@@ -176,17 +175,17 @@ async function syncEnvSecrets(cwd, serverUrl, apiKey, project, ui) {
|
|
|
176
175
|
ui.log.info(`Synced ${names.length} ${plural(names.length, "secret")} from .env`);
|
|
177
176
|
return names;
|
|
178
177
|
}
|
|
179
|
-
async function executePublish(opts, ui = defaultUi) {
|
|
178
|
+
async function executePublish(opts, ui = defaultUi, deps = REAL_STUDIO_DEPS) {
|
|
180
179
|
const { assertTypechecks } = await import("./_typecheck-gate-CcX2gLJZ.mjs");
|
|
181
180
|
await assertTypechecks(opts.cwd, {
|
|
182
181
|
skip: opts.skipTypecheck,
|
|
183
182
|
ui
|
|
184
183
|
});
|
|
185
|
-
const pushed = await pushProject(opts, ui);
|
|
184
|
+
const pushed = await pushProject(opts, ui, deps);
|
|
186
185
|
const { project, serverUrl, apiKey } = pushed;
|
|
187
|
-
await syncEnvSecrets(opts.cwd, serverUrl, apiKey, project, ui);
|
|
186
|
+
await syncEnvSecrets(opts.cwd, serverUrl, apiKey, project, ui, deps.apiRequest);
|
|
188
187
|
ui.log.step(`Publishing ${project} (builds in the project's sandbox)…`);
|
|
189
|
-
const result = checkedResponse(await publishStudioProject(serverUrl, apiKey, project, { skipTypecheck: opts.skipTypecheck }), (value) => isRecord(value) && typeof value.slug === "string" && typeof value.output === "string", `the publish route at ${serverUrl}`);
|
|
188
|
+
const result = checkedResponse(await publishStudioProject(serverUrl, apiKey, project, { skipTypecheck: opts.skipTypecheck }, deps.apiRequest), (value) => isRecord(value) && typeof value.slug === "string" && typeof value.output === "string", `the publish route at ${serverUrl}`);
|
|
190
189
|
if (result.output.trim()) ui.log.message(result.output.trim());
|
|
191
190
|
await updateProjectConfig(opts.cwd, {
|
|
192
191
|
serverUrl,
|