@segmentstream/ontology 0.197.0 → 0.198.0

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 (60) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/dist/analyze.d.ts +2 -0
  3. package/dist/analyze.js +17 -0
  4. package/dist/bin/check.js +12 -0
  5. package/dist/bin/migrate.js +1 -1
  6. package/dist/connection.d.ts +109 -6
  7. package/dist/connection.js +132 -17
  8. package/dist/diagnostics.d.ts +3 -3
  9. package/dist/diagnostics.js +2 -0
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.js +1 -1
  12. package/dist/manifest.d.ts +28 -0
  13. package/dist/manifest.js +6 -0
  14. package/dist/migrate/apply.d.ts +7 -1
  15. package/dist/migrate/apply.js +12 -3
  16. package/dist/migrate/model.d.ts +8 -0
  17. package/dist/migrate/plan.js +14 -1
  18. package/dist/owned-workflows.d.ts +10 -0
  19. package/dist/owned-workflows.js +16 -0
  20. package/dist/runtime/owner-departures.d.ts +35 -0
  21. package/dist/runtime/owner-departures.js +64 -0
  22. package/dist/runtime/pipeline.d.ts +15 -1
  23. package/dist/runtime/pipeline.js +67 -1
  24. package/dist/runtime/principals.d.ts +17 -2
  25. package/dist/runtime/principals.js +33 -2
  26. package/dist/runtime/service-binding.js +17 -3
  27. package/dist/runtime/workflow-starts.d.ts +108 -8
  28. package/dist/runtime/workflow-starts.js +276 -49
  29. package/dist/service/agent/attachments.js +27 -6
  30. package/dist/service/agent/authentication.d.ts +5 -0
  31. package/dist/service/agent/authentication.js +1 -1
  32. package/dist/service/agent/task-caller.d.ts +4 -2
  33. package/dist/service/agent/task-caller.js +4 -2
  34. package/dist/service/authentication.d.ts +7 -0
  35. package/dist/service/authentication.js +12 -0
  36. package/dist/service/chat/envelope.d.ts +7 -0
  37. package/dist/service/chat/envelope.js +15 -0
  38. package/dist/service/config.d.ts +6 -0
  39. package/dist/service/connections.d.ts +17 -2
  40. package/dist/service/connections.js +21 -1
  41. package/dist/service/errors.js +27 -1
  42. package/dist/service/member-files.js +6 -0
  43. package/dist/service/operations.d.ts +8 -0
  44. package/dist/service/operations.js +11 -4
  45. package/dist/service/owned-connections.d.ts +80 -0
  46. package/dist/service/owned-connections.js +488 -0
  47. package/dist/service/runtime-contract.d.ts +22 -0
  48. package/dist/service/schemas.d.ts +2 -0
  49. package/dist/service/service.js +23 -2
  50. package/dist/service/workflow-errors.d.ts +18 -1
  51. package/dist/service/workflow-errors.js +51 -2
  52. package/dist/service/workflows.d.ts +24 -0
  53. package/dist/service/workflows.js +360 -50
  54. package/dist/start-recovery-contract.d.ts +17 -1
  55. package/dist/start-recovery-contract.js +11 -1
  56. package/dist/start-recovery.js +4 -1
  57. package/dist/storage/tables.d.ts +15 -0
  58. package/dist/storage/tables.js +21 -0
  59. package/dist/workflow.d.ts +20 -2
  60. package/package.json +1 -1
@@ -22,5 +22,15 @@ export const RECOVERY_RETRY_MS = [
22
22
  ];
23
23
  /** Coverage the arming request keeps back from the run's horizon, for the start's own latency. */
24
24
  export const RECOVERY_COVERAGE_MARGIN_MS = 5_000;
25
- /** The sweeps one run makes at most; rows still pending then are left for an operator's sweep. */
25
+ /**
26
+ * The sweeps one run makes at most. Rows still pending then are left for an operator's sweep, except
27
+ * in an ontology that declares an owned workflow, whose last sweep arms another recovery run.
28
+ */
26
29
  export const RECOVERY_MAX_SWEEPS = 32;
30
+ /**
31
+ * How long one sweep of an ontology that declares an owned workflow starts rows, batch after batch,
32
+ * so that a cron's rows for thousands of owners drain in a few sweeps. It stays below the 30-second
33
+ * lease a sweep holds on a row, so that a row whose start failed is not taken again in the same
34
+ * sweep. Every other ontology's sweep starts one batch.
35
+ */
36
+ export const RECOVERY_SWEEP_BUDGET_MS = 20_000;
@@ -71,7 +71,10 @@ delays = {}) {
71
71
  else {
72
72
  await sleep(confirmMs);
73
73
  }
74
- outcome = await recoverStartsStep({ before });
74
+ outcome = await recoverStartsStep({
75
+ before,
76
+ ...(report.sweeps + 1 >= RECOVERY_MAX_SWEEPS ? { last: true } : {}),
77
+ });
75
78
  report = add(report, outcome);
76
79
  if (outcome.waiting === 0) {
77
80
  break;
@@ -45,6 +45,21 @@ export declare const NIL_RECORD_ID = "00000000-0000-0000-0000-000000000000";
45
45
  * uniqueness per trigger, action and record is a unique index that reads null as the nil uuid.
46
46
  */
47
47
  export declare const WORKFLOW_STARTS_DDL: ReadonlyArray<string>;
48
+ /**
49
+ * Reported by `readRuntimeTables` when `_workflow_starts` has the run owner columns below, which a
50
+ * migration adds only for an ontology that declares an owned workflow. Not a table.
51
+ */
52
+ export declare const WORKFLOW_START_OWNERS = "_workflow_starts.owner_id";
53
+ /**
54
+ * The owner of each start of an owned workflow, a workflow listing an owned connection: the record
55
+ * the run belongs to (`owner_entity`, `owner_id`) and its call kind (`owner_call`, `interactive` or
56
+ * `background`), which the start copies into the run's attributes. A cron writes one row per
57
+ * eligible owner, with `fire_key` its scheduled minute; the unique index makes a repeated delivery
58
+ * of the cron write no second row for an owner. `action_id` stays required: a cron row's is derived
59
+ * from its trigger, minute and owner, so every key of the table names it. Rows without an owner,
60
+ * of every other workflow, leave the columns null.
61
+ */
62
+ export declare const WORKFLOW_START_OWNERS_DDL: ReadonlyArray<string>;
48
63
  /** The prompts workflows hand the app's agent with `agentTask`, beside the workflow starts. */
49
64
  export declare const AGENT_TASKS_TABLE = "_agent_tasks";
50
65
  /**
@@ -238,6 +238,27 @@ export const WORKFLOW_STARTS_DDL = [
238
238
  owner text,target_hash text,deadline timestamptz,drained_generation bigint,resume_phase text
239
239
  )`,
240
240
  ];
241
+ /**
242
+ * Reported by `readRuntimeTables` when `_workflow_starts` has the run owner columns below, which a
243
+ * migration adds only for an ontology that declares an owned workflow. Not a table.
244
+ */
245
+ export const WORKFLOW_START_OWNERS = `${WORKFLOW_STARTS_TABLE}.owner_id`;
246
+ /**
247
+ * The owner of each start of an owned workflow, a workflow listing an owned connection: the record
248
+ * the run belongs to (`owner_entity`, `owner_id`) and its call kind (`owner_call`, `interactive` or
249
+ * `background`), which the start copies into the run's attributes. A cron writes one row per
250
+ * eligible owner, with `fire_key` its scheduled minute; the unique index makes a repeated delivery
251
+ * of the cron write no second row for an owner. `action_id` stays required: a cron row's is derived
252
+ * from its trigger, minute and owner, so every key of the table names it. Rows without an owner,
253
+ * of every other workflow, leave the columns null.
254
+ */
255
+ export const WORKFLOW_START_OWNERS_DDL = [
256
+ `ALTER TABLE "${WORKFLOW_STARTS_TABLE}" ADD COLUMN IF NOT EXISTS "owner_entity" text, ` +
257
+ `ADD COLUMN IF NOT EXISTS "owner_id" text, ADD COLUMN IF NOT EXISTS "owner_call" text, ` +
258
+ `ADD COLUMN IF NOT EXISTS "fire_key" text`,
259
+ `CREATE UNIQUE INDEX IF NOT EXISTS "${WORKFLOW_STARTS_TABLE}_fire" ON "${WORKFLOW_STARTS_TABLE}" ` +
260
+ `("trigger", "fire_key", "owner_id") WHERE "fire_key" IS NOT NULL`,
261
+ ];
241
262
  /** The prompts workflows hand the app's agent with `agentTask`, beside the workflow starts. */
242
263
  export const AGENT_TASKS_TABLE = "_agent_tasks";
243
264
  /**
@@ -301,6 +301,17 @@ export interface WorkflowRunContext {
301
301
  readonly kind: "platform";
302
302
  readonly userId: string | null;
303
303
  };
304
+ /**
305
+ * The record the run belongs to, fixed when it started: for a run of a workflow that lists an
306
+ * owned connection, the user it runs for. The run acts as that user and its owned connections'
307
+ * calls use that user's credentials. Absent on a run with no owner, which acts as the workflow's
308
+ * user. For logging and for input to the run's own steps; no API takes it to choose a credential
309
+ * or a principal.
310
+ */
311
+ readonly owner?: {
312
+ readonly entity: "user";
313
+ readonly id: string;
314
+ };
304
315
  }
305
316
  /** The function a workflow runs: a `"use workflow"` function of the decoded input. */
306
317
  export type WorkflowFunction<Input> = (input: Input, context: WorkflowRunContext) => Promise<unknown>;
@@ -312,7 +323,8 @@ export interface WorkflowOptions<S extends AnyInputSchema | undefined = undefine
312
323
  /**
313
324
  * The declared role whose permissions the workflow's runs hold: exactly its permissions, with
314
325
  * the built-in `member`'s while the ontology declares one. Its runs act as the workflow's own
315
- * service user.
326
+ * service user. A run that has an owner, of a workflow listing an owned connection, acts as its
327
+ * owner instead, with the owner's own roles; the role is what a run with no owner holds.
316
328
  */
317
329
  readonly role: string;
318
330
  /** A `Schema.Struct` of the workflow's input. Omitted means `{}`. */
@@ -324,7 +336,13 @@ export interface WorkflowOptions<S extends AnyInputSchema | undefined = undefine
324
336
  * app, the CLI or another workflow.
325
337
  */
326
338
  readonly triggers?: ReadonlyArray<WorkflowTrigger>;
327
- /** Connections a step calls directly, each listed in `defineOntology({ connections })`. */
339
+ /**
340
+ * Connections a step calls directly, each listed in `defineOntology({ connections })`. Listing an
341
+ * owned connection (`owner: "user"`) makes the workflow owned: a cron starts one run for each
342
+ * user who connected every owned connection listed and allowed its background use, and each run
343
+ * acts as that user. List every owned connection the runs use, also one only an action the
344
+ * workflow calls declares.
345
+ */
328
346
  readonly connections?: ReadonlyArray<AnyConnectionHandle>;
329
347
  }
330
348
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.197.0",
3
+ "version": "0.198.0",
4
4
  "description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",