@uru-intelligence/app 2.1.6 → 2.2.4

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 (43) hide show
  1. package/README.md +463 -14
  2. package/dist/background-jobs.d.ts +11 -0
  3. package/dist/background-jobs.js +571 -0
  4. package/dist/dampers.d.ts +24 -1
  5. package/dist/dampers.js +3 -0
  6. package/dist/dataset-boundary.js +38 -1
  7. package/dist/dataset-row.d.ts +9 -0
  8. package/dist/dataset-row.js +11 -0
  9. package/dist/datasets.d.ts +2 -1
  10. package/dist/datasets.js +82 -28
  11. package/dist/errors.js +5 -4
  12. package/dist/examples/customer-workflows/approved-external-write.d.ts +50 -0
  13. package/dist/examples/customer-workflows/approved-external-write.js +162 -0
  14. package/dist/examples/customer-workflows/file-processor.d.ts +46 -0
  15. package/dist/examples/customer-workflows/file-processor.js +53 -0
  16. package/dist/examples/customer-workflows/job-coordinator.d.ts +5 -0
  17. package/dist/examples/customer-workflows/job-coordinator.js +1 -0
  18. package/dist/examples/customer-workflows/review-only-draft.d.ts +38 -0
  19. package/dist/examples/customer-workflows/review-only-draft.js +48 -0
  20. package/dist/examples/customer-workflows/scheduled-collector.d.ts +46 -0
  21. package/dist/examples/customer-workflows/scheduled-collector.js +343 -0
  22. package/dist/files.js +4 -1
  23. package/dist/index.d.ts +6 -3
  24. package/dist/index.js +20 -7
  25. package/dist/invocations.d.ts +11 -1
  26. package/dist/invocations.js +72 -4
  27. package/dist/job-run.d.ts +90 -0
  28. package/dist/job-run.js +229 -0
  29. package/dist/jobs.d.ts +3 -3
  30. package/dist/jobs.js +39 -11
  31. package/dist/runtime.d.ts +8 -4
  32. package/dist/runtime.js +27 -7
  33. package/dist/transport-deadline.d.ts +0 -1
  34. package/dist/transport-deadline.js +0 -27
  35. package/dist/transport-invocation.d.ts +23 -4
  36. package/dist/transport-invocation.js +114 -29
  37. package/dist/transport-retry.d.ts +68 -0
  38. package/dist/transport-retry.js +245 -0
  39. package/dist/transport.d.ts +5 -20
  40. package/dist/transport.js +54 -33
  41. package/dist/types.d.ts +203 -4
  42. package/dist/uploads.js +158 -19
  43. package/package.json +34 -9
package/README.md CHANGED
@@ -53,7 +53,8 @@ const page = await uru.datasets.queryRows('sales', {
53
53
  sort: [{ field: 'closed_at', direction: 'desc' }],
54
54
  });
55
55
 
56
- // Actions: run a declared capability and decode its result, or throw.
56
+ // Actions: run a declared capability, wait until it ends, and decode its
57
+ // result, or throw.
57
58
  const summary = await uru.actions.run('summarize', { region: 'emea' }, {
58
59
  decodeResult: value => {
59
60
  if (typeof value !== 'string') {
@@ -76,6 +77,305 @@ and `URU_RUNTIME_TOKEN`. The Uru runtime injects all three. A missing binding
76
77
  throws `UruAppRuntimeError` naming the binding, rather than failing later at a
77
78
  request that could never have worked.
78
79
 
80
+ ## Recoverable background jobs
81
+
82
+ Use `createUruBackgroundJobCoordinator` when a caller must recover after a
83
+ lost start response or a process restart. It uses the existing `job`,
84
+ `jobStatus`, and `cancelJob` operations. It does not own job state.
85
+
86
+ The caller supplies a durable store scoped to the Gem and the viewer, not to one
87
+ deployment: a job started before a new release of the Gem stays in the store,
88
+ and the next release observes, waits on, cancels and resumes it. Each record
89
+ keeps the deployment that saved it, for your own audit. Its
90
+ `create` operation must insert only when the key is absent. Its three update
91
+ operations must be atomic and must preserve the saved request. The helper saves
92
+ the idempotency key, input, timeout, and absolute deadline before it starts a
93
+ job. If the store fails, no job starts.
94
+
95
+ ```ts
96
+ import {
97
+ createUruBackgroundJobCoordinator,
98
+ createUruServerContext,
99
+ } from '@uru-intelligence/app';
100
+
101
+ const uru = createUruServerContext(process.env);
102
+ const deploymentId = process.env.URU_DEPLOYMENT_ID;
103
+ if (!deploymentId) throw new Error('Missing deployment id');
104
+
105
+ const jobs = createUruBackgroundJobCoordinator({
106
+ app: uru.app,
107
+ deploymentId,
108
+ store: jobStore,
109
+ });
110
+
111
+ const request = {
112
+ capabilityName: 'sync_orders',
113
+ idempotencyKey: `orders:${batchId}`,
114
+ input: { batchId, source: 'orders' },
115
+ deadlineAt: Date.now() + 30 * 60 * 1000,
116
+ timeoutMs: 25_000,
117
+ };
118
+
119
+ const started = await jobs.start(request);
120
+ if (started.response.pending) {
121
+ const outcome = await jobs.wait(request.idempotencyKey);
122
+ if (outcome.kind === 'complete') {
123
+ showResult(outcome.status.result);
124
+ }
125
+ }
126
+
127
+ // Every lifecycle method accepts the same local AbortSignal and callbacks.
128
+ const requestSignal = new AbortController().signal;
129
+ const callOptions = { signal: requestSignal };
130
+ await jobs.observe(request.idempotencyKey, callOptions);
131
+ await jobs.wait(request.idempotencyKey, callOptions);
132
+ await jobs.cancel(request.idempotencyKey, callOptions);
133
+ await jobs.resume(request.idempotencyKey, callOptions);
134
+ ```
135
+
136
+ After a lost start response, call `resume` with the same key. The helper sends
137
+ the saved input, key, and timeout again. The server uses that key to return the
138
+ same accepted work. It does not create a new logical request. While the caller's
139
+ store keeps the saved row, the helper refuses changed input, timeout, or
140
+ deadline for that key. The deadline is local. The helper does not send it to
141
+ the server. If the caller deletes the row, the helper cannot enforce the saved
142
+ request identity or deadline.
143
+
144
+ `wait` stops at the saved deadline and honors the server's retry hint. Its
145
+ `AbortSignal` stops local waiting only. Call `cancel` to ask the server to stop
146
+ the job. A cancel acknowledgement is not proof that the job has stopped; read
147
+ the returned status until it is terminal. Status and result access still follow
148
+ the server's current job-status contract. This helper cannot recover a result
149
+ that the server no longer exposes.
150
+
151
+ ## Customer job patterns
152
+
153
+ The examples below use the coordinator above and small Gem-owned handlers. Each
154
+ caller supplies a durable store. It saves one request before dispatch. After a
155
+ restart, resume with the same key. Keep the original input and deadline.
156
+
157
+ The package includes all four examples under
158
+ `@uru-intelligence/app/examples/customer-workflows/*`. These are runnable
159
+ JavaScript modules with TypeScript declarations. They do not require this
160
+ repository.
161
+
162
+ ### Scheduled collector
163
+
164
+ Declare a program job with a schedule in `uru.json`. The schedule owns recurring
165
+ starts. A manual catch-up request can use the coordinator too. Give that request
166
+ a saved id and one fixed deadline:
167
+
168
+ ```json
169
+ {
170
+ "capabilities": {
171
+ "jobs": {
172
+ "collect_orders": {
173
+ "handler": { "module": "src/jobs.ts", "export": "collectOrders" },
174
+ "input": { "sourceId": "orders" },
175
+ "schedule": { "cron": "0 * * * *", "timeZone": "America/Chicago" }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ ```
181
+
182
+ ```ts
183
+ const key = `collector:${sourceId}:${requestId}`;
184
+ const request = {
185
+ capabilityName: "collect_orders",
186
+ idempotencyKey: key,
187
+ input: { sourceId },
188
+ deadlineAt,
189
+ timeoutMs: 25_000,
190
+ };
191
+ const started = await jobs.start(request);
192
+ // After a restart, use jobs.resume(key). Do not make a new key.
193
+ ```
194
+
195
+ The installed collector keeps provider order ids in customer fields. Each new
196
+ order uses a null row id, so Uru creates its UUID. Before the first run, create
197
+ one `collector_state` row with `{ sourceId: "orders", nextCursor: null }`.
198
+ The handler queries that row and uses its Uru UUID for each cursor update. It
199
+ never uses `sourceId` as a Dataset row id.
200
+
201
+ This example reads an append-only source. Each source order id must occur once.
202
+ A source that sends later order changes needs a durable map from each source id
203
+ to its Uru row UUID.
204
+
205
+ ```ts
206
+ import { collectScheduledOrders } from
207
+ "@uru-intelligence/app/examples/customer-workflows/scheduled-collector";
208
+
209
+ export const collectOrders = (input, checkpoint, signal) =>
210
+ collectScheduledOrders(uru, input, checkpoint, signal, readOrdersPage);
211
+ ```
212
+
213
+ Declare and grant the `collector_state` and `collected_orders` Datasets before
214
+ the Build. Create exactly one state row for each source before its schedule can
215
+ run. `readOrdersPage` is Gem code for an approved read connection. Keep provider
216
+ cursors private. Uru owns recurrence and run status. The private Dataset cursor
217
+ carries collection position across runs, so no second local scheduler is needed.
218
+
219
+ Store the input cursor, an explicit sequence, and the cumulative page count in
220
+ each page step result. Checkpoint the same sequence and count after the step.
221
+ The checkpoint is stored as JSON data, where object key order is not a page
222
+ order. On recovery, sort validated steps by their sequence. Use the newest
223
+ step's cumulative count, even when the separate cursor checkpoint was lost.
224
+ Reject a saved step gap. The first saved step must be page 1.
225
+
226
+ ### Review-only draft
227
+
228
+ Create a draft output and stop at review. This path writes no external service.
229
+ Give each draft a stable id:
230
+
231
+ ```ts
232
+ const key = `review-draft:${draftId}`;
233
+ const started = await jobs.start({
234
+ capabilityName: "save_review_draft",
235
+ idempotencyKey: key,
236
+ input: { draftId, markdown },
237
+ deadlineAt,
238
+ timeoutMs: 25_000,
239
+ });
240
+ // In the program job, save the output inside a named step.
241
+ const output = await uru.jobs.step("save review draft", async step => {
242
+ if (signal.aborted) return { kind: "canceled" };
243
+ const created = await uru.files.createOutput({
244
+ name: `${draftId}.md`,
245
+ contentType: "text/markdown",
246
+ content: new TextEncoder().encode(markdown),
247
+ idempotencyKey: step.idempotencyKey,
248
+ signal,
249
+ });
250
+ return { kind: "review_required", outputId: created.outputId };
251
+ });
252
+ if (output.kind === "review_required") {
253
+ await uru.jobs.checkpoint({
254
+ draftId,
255
+ phase: output.kind,
256
+ outputId: output.outputId,
257
+ });
258
+ }
259
+ return output;
260
+ ```
261
+
262
+ Keep `draftId` fixed while recovering the same draft. The named step keeps its
263
+ write key across attempts of the same job run, so a lost response does not
264
+ create a second file. A person must review the output before a separate
265
+ capability can send or publish it.
266
+
267
+ ### File processor
268
+
269
+ Pass a Uru file id, not a URL or file bytes from the browser. `files.read`
270
+ checks access. Save processed bytes with a key tied to the file and processor
271
+ version:
272
+
273
+ ```ts
274
+ const key = `file:${fileId}:processor:${processorVersion}`;
275
+ const started = await jobs.start({
276
+ capabilityName: "process_file",
277
+ idempotencyKey: key,
278
+ input: { fileId, processorVersion },
279
+ deadlineAt,
280
+ timeoutMs: 25_000,
281
+ });
282
+ // In the program job, put the output write in a named step.
283
+ const file = await uru.files.read(fileId, { signal });
284
+ const processed = await transformFile(file, signal);
285
+ const output = await uru.jobs.step("write processed file", async step => {
286
+ if (signal.aborted) return { kind: "canceled" };
287
+ const created = await uru.files.createOutput({
288
+ name: processed.name,
289
+ contentType: processed.contentType,
290
+ content: processed.content,
291
+ idempotencyKey: step.idempotencyKey,
292
+ signal,
293
+ });
294
+ return { kind: "complete", outputId: created.outputId };
295
+ });
296
+ if (output.kind === "complete") {
297
+ await uru.jobs.checkpoint({
298
+ fileId,
299
+ processorVersion,
300
+ phase: output.kind,
301
+ outputId: output.outputId,
302
+ });
303
+ }
304
+ ```
305
+
306
+ If the output response is lost, rerun with the same file id, processor version,
307
+ and job key. Do not use a new key to repeat the same processing request.
308
+
309
+ ### Approved external write
310
+
311
+ Load the approved intent from a trusted server after a person confirms the
312
+ exact target and payload. The server loader must verify the authenticated actor
313
+ and every approved field. Do not use a browser value or a writable Dataset row
314
+ as proof of approval. The job must name the exact bound tool role and operation.
315
+ Uru checks current connection access and Tool Approval when it runs that action.
316
+
317
+ The app package job runtime does not expose a verified actor ID to Gem code.
318
+ Your app must inject a trusted loader that can verify the actor and current
319
+ approval. If it cannot, the loader must return no intent and the write must
320
+ stop. This package example does not provide approval storage.
321
+
322
+ ```ts
323
+ const intent = await loadApprovedIntentForAuthenticatedActor(approvalId);
324
+ if (!intent) throw new Error("No approved intent");
325
+ const key = `external-write:${intent.approvalId}`;
326
+ const started = await jobs.start({
327
+ capabilityName: "send_approved_update",
328
+ idempotencyKey: key,
329
+ input: {
330
+ approvalId: intent.approvalId,
331
+ approvedByActorId: intent.approvedByActorId,
332
+ targetId: intent.targetId,
333
+ payload: intent.payload,
334
+ },
335
+ deadlineAt: intent.deadlineAt,
336
+ timeoutMs: 25_000,
337
+ });
338
+ // If the reply is lost, call jobs.resume(key). Do not start a new request.
339
+ ```
340
+
341
+ Bind the same trusted server check to the published job handler. The handler
342
+ reads the saved step before it checks renewed approval. A saved result survives
343
+ revocation. A new or incomplete step must pass the server check before it calls
344
+ the provider.
345
+
346
+ ```ts
347
+ import { createUruServerContext } from "@uru-intelligence/app";
348
+ import { createSendApprovedUpdateHandler } from "./approved-external-write.js";
349
+ import { loadApprovedIntentForJobActor } from "./trusted-approval-server.js";
350
+
351
+ export const sendApprovedUpdate = createSendApprovedUpdateHandler(
352
+ createUruServerContext,
353
+ (env) => (approvalId, signal) =>
354
+ loadApprovedIntentForJobActor(env, approvalId, signal),
355
+ );
356
+ ```
357
+
358
+ `loadApprovedIntentForJobActor` is app-owned code. It must read a server-owned
359
+ approval record, resolve the actor from the trusted job run, and verify that
360
+ actor may use the approval. The returned target and payload must match the
361
+ approved record. The runtime environment has the job run id, but it has no
362
+ verified actor id. Do not treat an actor id in job input as proof. Do not grant
363
+ Gem code write access to the approval record. A loader without trusted actor
364
+ data must return no intent. The loader must accept the job's abort signal and
365
+ stop its request when the job is canceled. Check the signal again after the
366
+ lookup. A cancellation before the provider call is canceled, not an unknown
367
+ provider result. Use the action start event to find this boundary. After that
368
+ event, keep an uncertain provider result open.
369
+
370
+ If the provider result is unknown, keep that result open. Check the same Uru
371
+ run and provider before a person approves another request. Never use a new key
372
+ to force an uncertain write to complete.
373
+
374
+ The executable source examples test these patterns against this repository's
375
+ package source. This does not prove an installed npm version. After the
376
+ protected npm release, install the exact published version in a clean Gem and
377
+ repeat the checks before claiming installed-package support.
378
+
79
379
  ## Program job handlers
80
380
 
81
381
  A Gem can declare a job that runs code from its published source:
@@ -122,7 +422,91 @@ export async function syncOrders(
122
422
  `saveNextBatch` is Gem code. Check `signal.aborted` before each external write.
123
423
  Make writes safe to repeat. Keep progress messages and checkpoints small. Do
124
424
  not put secrets or source rows in them. A progress update does not complete a
125
- job. The handler completes the job when it returns.
425
+ job. The handler completes the job when it returns. Each progress update and
426
+ checkpoint also tells Uru the job is alive.
427
+
428
+ ### A job that survives a lost machine
429
+
430
+ Uru runs a lost job attempt again from its start, under the same job run, with
431
+ the last checkpoint. Put the job's writes in `jobs.step` so that the next
432
+ attempt can run safely.
433
+
434
+ Uru also runs the job again when the handler throws a temporary answer from
435
+ Uru after the SDK's own resends ran out: a 408, 429 or 503 that does not say
436
+ `retryable: false`, or a 502 or 504 that no server answered. This needs a job
437
+ that is still retryable (see below), an attempt left (three in all), and no
438
+ cancel. Any other answer ends the job: a 500, a 403, 404, 409 or 422, or an
439
+ error from your own code.
440
+
441
+ On the next attempt:
442
+
443
+ - Steps that finished return their saved results and do not run again.
444
+ - The step that was cut short runs again from its start. Its actions, job
445
+ starts and Dataset row writes send the same keys, and so does a file output
446
+ that passes `step.idempotencyKey`, so Uru answers each one from its first
447
+ run and nothing is written twice.
448
+ - Everything else runs again: reads, code outside a step, and every HTTP
449
+ request your code sends to another service. Give such a request
450
+ `step.idempotencyKey` when the service accepts one.
451
+
452
+ A step runs once per job run: its result is saved in the checkpoint, and the
453
+ next attempt returns the saved result without running the step. Inside a step,
454
+ each action, job start and Dataset row write gets a default key that the job
455
+ run owns (`uru-job:<run id>:...`). A step that was cut short runs again from
456
+ its start and sends the same keys in the same order, so Uru answers each call
457
+ from its first run instead of running it twice, and the job stays retryable.
458
+
459
+ Outside a step, a call gets a random key, and a write there ends the job's
460
+ automatic retry. A job that resumes from its own checkpoint does not make the
461
+ same calls again, so Uru cannot tell which earlier call a later one repeats.
462
+
463
+ ```ts
464
+ const ids = await uru.jobs.step('load', async () => {
465
+ const page = await uru.datasets.queryRows('invoices', { where: [] });
466
+ return page.rows.map(row => row.id);
467
+ });
468
+ for (const id of ids) {
469
+ await uru.jobs.step(`send ${id}`, async step => {
470
+ await uru.actions.run('send_invoice', { id }, { signal });
471
+ await uru.files.createOutput({
472
+ name: `${id}.txt`,
473
+ contentType: 'text/plain',
474
+ content: new TextEncoder().encode(`Sent ${id}`),
475
+ idempotencyKey: step.idempotencyKey,
476
+ });
477
+ });
478
+ }
479
+ ```
480
+
481
+ - `actions.run` returns when the action has ended. An action that takes
482
+ longer than the server's short wait answers pending; `actions.run` then
483
+ reads its status until it ends, and returns its result or throws its
484
+ failure. Pass the handler's `signal`, so a canceled job stops waiting. Do
485
+ not give a write a short `timeoutMs`: it bounds the whole wait, and when it
486
+ ends the call throws while the action goes on.
487
+ - Give each step its own name, and run steps one at a time. While a step runs,
488
+ make only that step's calls.
489
+ - A step must make the same calls in the same order each time it runs. Save
490
+ your own checkpoint between steps, not inside one: Uru refuses
491
+ `jobs.checkpoint` while a step runs. Use `jobs.progress` inside a step.
492
+ - A call sent again under its key must carry the same input, or Uru refuses
493
+ it with a conflict. Make a time, a random id or a Dataset revision you pin
494
+ in a step of its own, and pass the saved result to the call: the next
495
+ attempt reuses it.
496
+ - Return small JSON from a step: ids and counts, not rows or files. The
497
+ checkpoint, with every saved step, must stay under 64 KB. The handler's
498
+ `checkpoint` holds the saved steps under `$uruSteps`; a checkpoint you save
499
+ keeps them, also when you save a changed copy of the one you received.
500
+ - `step.idempotencyKey` is the same on every attempt of the run. Use it for
501
+ one write of the step: a file output, or a request to an external API that
502
+ takes an idempotency key.
503
+ - A call that Uru cannot replay ends the job's automatic retry before it is
504
+ sent: an endpoint, `sqlWrite`, or a write with a key the run does not own
505
+ (a call outside a step, your own `idempotencyKey`, or
506
+ `dampers.defaultIdempotencyKeys: false`).
507
+ A lost attempt after such a call fails, so a person can check what it wrote.
508
+ - Uru cannot see an HTTP request the job sends to another service. Give that
509
+ service `step.idempotencyKey` when it accepts one.
126
510
 
127
511
  For a browser calling a public Gem page's runtime, build the client directly:
128
512
 
@@ -147,16 +531,57 @@ const response = await app.query('summary', {}, { onStatus: event => render(even
147
531
  Surface them. A Gem that hides expensive work behind a spinner is a Gem whose
148
532
  users cannot tell a slow query from a blocked budget.
149
533
  - **Server-side Datasets.** Read with `queryRows`; write with `insertRows`,
150
- `upsertRows`, `deleteRows`, `restoreRows` and `sqlWrite`. Totals, counts and
151
- top-N summaries must come from the server, never from one fetched page.
534
+ `upsertRows`, `upsertRowViews`, `deleteRows`, `restoreRows` and `sqlWrite`.
535
+ Totals, counts and top-N summaries must come from the server, never from one
536
+ fetched page.
152
537
  - **Retry and refresh controls, on by default.** Each invocation gets a unique
153
538
  idempotency key. Its HTTP retries keep that key. Equal calls from separate
154
- clients or later calls remain separate operations. The client also backs off
539
+ clients or later calls remain separate operations. Inside a program job's
540
+ step the key belongs to the job run instead, so a later attempt that runs
541
+ the step again sends it again (see "A job that survives a lost machine"). The client also backs off
155
542
  on HTTP 429 and throttles `forceRefresh` per capability. Override these
156
543
  controls through `dampers`; see `UruRunawayDamperOptions`. Supply an explicit
157
544
  `idempotencyKey` when your application retries the same logical operation.
158
545
  A custom retry wait can accept the optional `AbortSignal` to stop its own
159
546
  work. The SDK still bounds the call when that wait ignores the signal.
547
+ - **Calls ride out a restarting server.** When Uru gives no answer (a failed
548
+ or reset connection, a reply cut off after its headers, HTTP 502 or 504, or
549
+ a 503 without an Uru error code),
550
+ the client sends the call again after about 0.5, 1, 2, 4, 8, 8 and 8
551
+ seconds, each stretched by up to twice for jitter: about a minute in all.
552
+ Each wait reports a `reconnecting` status event. An action or a job start
553
+ sends the same body with the same key, so the server replays the first run
554
+ instead of running it twice. A query sends a new key each time. Job status
555
+ reads, job cancels, `jobs.progress` and `jobs.checkpoint` are always sent
556
+ again. A Dataset row write is sent again with its key (each call gets one
557
+ when you give none). An endpoint and a server function are never sent
558
+ again, because they have no stored result to replay. `sqlWrite` is not sent
559
+ again either. It still sends a key: if your code sends the same statement
560
+ again with the same `idempotencyKey`, Uru returns the first result with
561
+ `replayed: true` and does not run the statement again, so the statement
562
+ never writes twice. The same key with another statement fails, and a
563
+ refusal stays saved under the key, so give a new attempt a new key. A
564
+ statement over 2 or more Datasets that fails with `partial_write` saved
565
+ some Datasets and not others: do not send it again with a new key, which
566
+ writes the saved Datasets again. The caller's
567
+ `signal` and `timeoutMs` end the waits. Set `dampers.maxTransportRetries` to
568
+ `0` to turn resends off.
569
+ - **Job writes ride out a short database stall.** A Dataset row write with a
570
+ key, `jobs.progress` and `jobs.checkpoint` are also sent again when Uru
571
+ answers that it cannot serve the call now: HTTP 408, 429 or 503. They use
572
+ the same waits, or the answer's `Retry-After` when that is longer. When the
573
+ `Retry-After` is longer than the wait time that is left, the call throws
574
+ that answer at once and never sends before the server allows. A row
575
+ write sends the same key each time, so the server joins the first command
576
+ and never writes twice. Every other answer is final and is never sent
577
+ again: a 500, 403, 404, 409, 422 or any other status, an error body with
578
+ `retryable: false`, or a setup failure that a resend cannot fix. When the
579
+ resends run out, the call throws `UruAppRuntimeError` with the last status.
580
+ - **How long a call can take.** All the waits of one call add up to at most
581
+ 63 seconds. A send that gets no answer counts as lost after 30 seconds, so
582
+ in the worst case (8 sends that each run 30 seconds) a Dataset row write,
583
+ `jobs.progress` or `jobs.checkpoint` returns or throws after about 5
584
+ minutes. A fast temporary answer ends it after about a minute.
160
585
 
161
586
  ## Transport values
162
587
 
@@ -174,7 +599,7 @@ before either action. `timeoutMs`, when set, must be an integer from 1,000 to
174
599
  Pass an `AbortSignal` as `signal` to cancel a capability call, job status read,
175
600
  or job cancel request. The signal is local to the SDK and is never sent in the
176
601
  JSON body. When `timeoutMs` is set, it also bounds the network request, response
177
- body read, and any 429 retry wait.
602
+ body read, any 429 retry wait and any resend wait.
178
603
 
179
604
  Response diagnostics use the same JSON rules. Invalid diagnostics in a success
180
605
  response cause `UruAppRuntimeError`. An HTTP error keeps its original status and
@@ -223,6 +648,16 @@ the decoder's row type. Dataset writes accept the result decoder as their third
223
648
  argument. A decoder error is the caller's error and propagates unchanged. A
224
649
  transport or platform failure remains `UruAppRuntimeError`.
225
650
 
651
+ Native Dataset V2 rows keep customer fields in `row.fields`. The row's `id`,
652
+ `rowVersion`, `createdAt`, `updatedAt`, and `deleted` values are Uru metadata.
653
+ Use `datasetRowForMutation(row)` with `upsertRowViews` to keep row identity
654
+ separate from customer data. This saves a customer field named `id` without
655
+ changing the native row id. It also sends `rowVersion` as the row precondition.
656
+ Pass the page's `revision` as `expectedDatasetRevision` when it must match the
657
+ read. Use flat `upsertRows` calls only when the customer schema has no field
658
+ named `id`. A customer field named `fields` is read or
659
+ edited as `row.fields.fields`, because `row.fields` is the customer-field map.
660
+
226
661
  Capability and job-status envelopes can omit `result` or return `null` while
227
662
  work is pending. The client preserves both forms without calling the decoder.
228
663
  Typed callers must still handle an absent or null result.
@@ -259,6 +694,13 @@ Output reads and writes are limited to 10 MiB. Later approved releases of the
259
694
  same Gem can read its outputs in the same environment. Preview builds cannot
260
695
  create unattended outputs. Every request checks current access.
261
696
 
697
+ A person can delete an output's Library file forever. The output then stays in
698
+ `listOutputs` with the `fileId` it had and `fileDeleted: true`, and
699
+ `readOutput` throws `UruAppRuntimeError` with `status` 410. Show such an
700
+ output as deleted. `createOutput` with the idempotency key of that output also
701
+ throws with `status` 410 and writes nothing: to write the file again, use a new
702
+ idempotency key.
703
+
262
704
  ## Errors
263
705
 
264
706
  Transport and platform failures throw `UruAppRuntimeError`. Decoder failures
@@ -291,9 +733,10 @@ platform's runtime contract moves, this package moves with it — additively whe
291
733
  it can, and in a major version where it cannot. Pin an exact version if you need
292
734
  a build to be reproducible; Uru's own Gem templates do.
293
735
 
294
- The public surface is `createUruServerContext`, `createUruAppRuntimeClient`,
295
- `UruAppRuntimeError`, and the exported types. Nothing else is API, even if you
296
- can reach it.
736
+ The public surface includes `createUruServerContext`,
737
+ `createUruAppRuntimeClient`, `createUruBackgroundJobCoordinator`,
738
+ `createUruUploadsContext`, `UruAppRuntimeError`, and the exported types.
739
+ Nothing else is API, even if you can reach it.
297
740
 
298
741
  ## Documentation
299
742
 
@@ -315,15 +758,21 @@ an `idempotencyKey` to reject changes made since that read:
315
758
  ```ts
316
759
  const page = await uru.datasets.queryRows('contacts', { limit: 1 });
317
760
  if (page.revision === undefined) throw new Error('Native revision required');
318
- await uru.datasets.upsertRows('contacts', [{ id: rowId, name: 'Updated' }],
761
+ const saved = page.rows[0];
762
+ if (!saved) throw new Error('Contact row required');
763
+ await uru.datasets.upsertRowViews('contacts', [
764
+ { rowId: saved.id, expectedRowVersion: saved.rowVersion ?? null,
765
+ fields: { ...saved.fields, name: 'Updated' } },
766
+ ],
319
767
  undefined, { expectedDatasetRevision: page.revision, idempotencyKey: saveId });
320
768
  ```
321
769
 
322
770
  Keep the key for that save across retries. Hosted Gems scope it to the verified
323
- Gem and viewer. A repeated request can report a conflict if preparing the row
324
- would now produce different values. Read the saved record before retrying;
325
- confirm the intended fields were saved or ask the user to resolve the conflict.
326
- Never assign a new key merely to bypass a conflict. Browser conditional saves
771
+ Gem and viewer. A repeated request with the same key and the same rows returns
772
+ the first result, even after the first send was saved and the revision moved
773
+ on. The same key with different rows is a conflict. Read the saved record
774
+ before retrying; confirm the intended fields were saved or ask the user to
775
+ resolve the conflict. Never assign a new key merely to bypass a conflict. Browser conditional saves
327
776
  require a built Gem runtime, including GitHub previews. External datasets do
328
777
  not supply a native revision and remain read-only.
329
778
 
@@ -0,0 +1,11 @@
1
+ import type { CreateUruBackgroundJobCoordinatorOptions, UruBackgroundJobCoordinator } from "./types.js";
2
+ /**
3
+ * Coordinate the released `job`, `jobStatus`, and `cancelJob` operations.
4
+ * The store saves request identity and control intent only; the server remains
5
+ * authoritative for execution state and results.
6
+ *
7
+ * A record keeps the deployment that saved it, for the caller's audit only.
8
+ * The coordinator of a later release of the same Gem observes, waits on,
9
+ * cancels and resumes it through its own client.
10
+ */
11
+ export declare const createUruBackgroundJobCoordinator: (options: CreateUruBackgroundJobCoordinatorOptions) => UruBackgroundJobCoordinator;