@segmentstream/ontology 0.118.0 → 0.119.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.
@@ -4,7 +4,7 @@ import type { AnyConnectionHandle } from "./connection.js";
4
4
  import type { ActionHandle, AnyStoredEntity } from "./entity.js";
5
5
  import type { Edit } from "./runtime/history.js";
6
6
  import type { Principal } from "./runtime.js";
7
- import type { WebhookSignatureScheme } from "./webhooks.js";
7
+ import type { WebhookDelivery, WebhookSignatureScheme } from "./webhooks.js";
8
8
  /** Marks the values `workflow(…)` returns, so that `check` can tell them from look-alikes. */
9
9
  export declare const WorkflowTypeId: unique symbol;
10
10
  /** Marks the values trigger constructors such as `cron(…)` and `after(…)` return. */
@@ -13,6 +13,18 @@ export declare const WorkflowTriggerTypeId: unique symbol;
13
13
  export declare const MAX_WORKFLOWS = 50;
14
14
  /** The most action triggers, `after(…)`, one ontology may declare across its workflows. */
15
15
  export declare const MAX_ACTION_TRIGGERS = 20;
16
+ /**
17
+ * What a trigger listed in `defineOntology({ triggers })` runs instead of a workflow: one action,
18
+ * in a durable run retried like a step, as the trigger's own workflow user holding `role`. The
19
+ * platform publishes such a trigger as a workflow named like it. A trigger in a workflow's
20
+ * `triggers` starts that workflow and takes neither.
21
+ */
22
+ export interface TriggerRuns {
23
+ /** The action the trigger runs, as its handle: `Lead.actions.notify`. */
24
+ readonly runs?: AnyActionHandle;
25
+ /** The declared role, other than `member`, the runs hold with member's; required with `runs`. */
26
+ readonly role?: string;
27
+ }
16
28
  /**
17
29
  * A cron trigger, `cron(name, expression, { description, input })`: the platform writes it into
18
30
  * the workspace deployment's crons, and each invocation starts the workflow with `input`. Five
@@ -29,11 +41,17 @@ export interface CronTrigger<Name extends string = string, Input = unknown> {
29
41
  readonly cron: string;
30
42
  /** The workflow's input, in TypeScript names; `undefined` when the trigger declares none. */
31
43
  readonly input: Input | undefined;
44
+ /** The action it runs, when listed in `defineOntology({ triggers })`. */
45
+ readonly runs?: AnyActionHandle | undefined;
46
+ readonly role?: string | undefined;
32
47
  }
33
- export interface CronOptions<Input = unknown> {
48
+ export interface CronOptions<Input = unknown> extends TriggerRuns {
34
49
  /** Required, like every declaration: when and why the workflow starts. */
35
50
  readonly description: string;
36
- /** The workflow's input for this trigger. May be omitted when the workflow's input accepts `{}`. */
51
+ /**
52
+ * The workflow's input for this trigger, or the action's input with `runs`. May be omitted when
53
+ * that input accepts `{}`.
54
+ */
37
55
  readonly input?: Input;
38
56
  }
39
57
  /** Declares a cron trigger; list it in `workflow(name, { triggers })`. UTC, five fields. */
@@ -96,6 +114,9 @@ export interface ActionTrigger<Name extends string = string, Input = unknown> {
96
114
  readonly when: TriggerFunction<ActionEvent, unknown, boolean> | undefined;
97
115
  /** The workflow's input, in TypeScript names; omitted means `{}`. */
98
116
  readonly input: TriggerFunction<ActionEvent, unknown, Input> | undefined;
117
+ /** The action it runs, when listed in `defineOntology({ triggers })`; its input is `input`'s. */
118
+ readonly runs?: AnyActionHandle | undefined;
119
+ readonly role?: string | undefined;
99
120
  }
100
121
  /**
101
122
  * Where a webhook's deliveries are checked: a provider's signature format and the workspace secret
@@ -131,8 +152,13 @@ export interface WebhookTrigger<Name extends string = string> {
131
152
  readonly headers: ReadonlyArray<string>;
132
153
  /** The connection whose provider sends to this webhook, when declared. */
133
154
  readonly connection?: AnyConnectionHandle | undefined;
155
+ /** The action it runs, when listed in `defineOntology({ triggers })`. */
156
+ readonly runs?: AnyActionHandle | undefined;
157
+ readonly role?: string | undefined;
158
+ /** With `runs`: the action's input from the delivery, or `null` to skip it. */
159
+ readonly input?: ((delivery: WebhookDelivery) => unknown) | undefined;
134
160
  }
135
- export interface WebhookOptions {
161
+ export interface WebhookOptions extends TriggerRuns {
136
162
  /** Required, like every declaration: what the provider sends and why. */
137
163
  readonly description: string;
138
164
  /**
@@ -150,6 +176,12 @@ export interface WebhookOptions {
150
176
  * console shows the webhook on the connection's page.
151
177
  */
152
178
  readonly connection?: AnyConnectionHandle;
179
+ /**
180
+ * With `runs`: the action's input from the delivery, in TypeScript names, or `null` to skip the
181
+ * delivery without running the action. Synchronous; it runs in the run's step, so it may parse
182
+ * and validate but not call anything.
183
+ */
184
+ readonly input?: (delivery: WebhookDelivery) => unknown;
153
185
  }
154
186
  /**
155
187
  * Declares a webhook trigger; list it in `workflow(name, { input: webhookDelivery, triggers })`.
@@ -161,7 +193,7 @@ export declare function webhook<const Name extends string>(name: Name, options:
161
193
  * `webhook`; other kinds are additions.
162
194
  */
163
195
  export type WorkflowTrigger<Input = unknown> = CronTrigger<string, Input> | ActionTrigger<string, Input> | WebhookTrigger;
164
- export interface AfterOptions<Event, T, Input> {
196
+ export interface AfterOptions<Event, T, Input> extends TriggerRuns {
165
197
  /** Required, like every declaration: which actions start the workflow and why. */
166
198
  readonly description: string;
167
199
  /** Whether the run starts, from the event and the record; synchronous. Omitted means always. */
@@ -264,6 +296,11 @@ export interface Workflow<Name extends string = string, Input = unknown> {
264
296
  readonly run: WorkflowFunction<Input>;
265
297
  readonly triggers: ReadonlyArray<WorkflowTrigger>;
266
298
  readonly connections: ReadonlyArray<AnyConnectionHandle>;
299
+ /**
300
+ * The action a trigger listed in `defineOntology({ triggers })` runs: such a trigger is published
301
+ * as this workflow, and its run function is the platform's, compiled per trigger by the build.
302
+ */
303
+ readonly runs?: AnyActionHandle | undefined;
267
304
  }
268
305
  /** Any workflow, whatever its input. */
269
306
  export type AnyWorkflow = Workflow<string, any>;
package/dist/workflow.js CHANGED
@@ -16,6 +16,14 @@ export function cron(name, expression, options) {
16
16
  description: options.description,
17
17
  cron: expression,
18
18
  input: options.input,
19
+ ...triggerRuns(options),
20
+ };
21
+ }
22
+ /** The `runs` and `role` a trigger was declared with, copied only when declared. */
23
+ function triggerRuns(options) {
24
+ return {
25
+ ...(options?.runs === undefined ? {} : { runs: options.runs }),
26
+ ...(options?.role === undefined ? {} : { role: options.role }),
19
27
  };
20
28
  }
21
29
  /**
@@ -32,6 +40,8 @@ export function webhook(name, options) {
32
40
  ...(options.verification === undefined ? {} : { verification: options.verification }),
33
41
  headers: options.headers ?? [],
34
42
  ...(options.connection === undefined ? {} : { connection: options.connection }),
43
+ ...triggerRuns(options),
44
+ ...(options.input === undefined ? {} : { input: options.input }),
35
45
  };
36
46
  }
37
47
  export function after(name, target, options) {
@@ -46,6 +56,7 @@ export function after(name, target, options) {
46
56
  target,
47
57
  when: options?.when,
48
58
  input: options?.input,
59
+ ...triggerRuns(options),
49
60
  };
50
61
  }
51
62
  /**
@@ -18,6 +18,7 @@ export type { WebhookDelivery, WebhookSignatureScheme } from "./webhooks.js";
18
18
  export type { ActionEvent, ActionTrigger, AfterOptions, AnyActionHandle, AnyWorkflow, ChangedBounds, CronOptions, CronProblem, CronTrigger, TriggerFunction, TriggerRecord, WebhookOptions, WebhookSignature, WebhookVerification, WebhookTrigger, Workflow, WorkflowFunction, WorkflowOptions, WorkflowRunContext, WorkflowTrigger, } from "./workflow.js";
19
19
  export { run, WORKFLOW_BASE_PATH, WorkflowStepRequired } from "./workflow-runtime.js";
20
20
  export { recoverWorkflowStarts, StartRecoveryWorkflowRequired } from "./start-recovery.js";
21
+ export { runTriggerAction, TriggerRunUnsupported, TriggerRunWorkflowRequired, } from "./trigger-run.js";
21
22
  export type { StartRecoveryInput, StartRecoveryOutcome, StartRecoveryReport, } from "./start-recovery.js";
22
23
  export { agentTask, AgentTaskOptionsInvalid, AgentTaskWorkflowRequired, DEFAULT_AGENT_TASK_TIMEOUT_MS, MAX_AGENT_TASK_PROMPT_LENGTH, MAX_AGENT_TASK_TEXT_LENGTH, MAX_AGENT_TASK_TIMEOUT_MS, MAX_LIVE_AGENT_TASKS, MIN_AGENT_TASK_TIMEOUT_MS, } from "./agent-task.js";
23
24
  export type { AgentTaskFailure, AgentTaskOptions, AgentTaskResult } from "./agent-task.js";
package/dist/workflows.js CHANGED
@@ -15,4 +15,5 @@ export { after, changed, cron, cronNeverFires, cronProblem, isWorkflow, isWorkfl
15
15
  export { MAX_WEBHOOK_BODY_BYTES, MAX_META_WEBHOOK_BODY_BYTES, MAX_WEBHOOK_HEADERS, MAX_WEBHOOKS, WEBHOOK_BASE_PATH, WEBHOOK_SIGNATURE_SCHEMES, webhookDelivery, webhookHeaderProblem, webhookPath, } from "./webhooks.js";
16
16
  export { run, WORKFLOW_BASE_PATH, WorkflowStepRequired } from "./workflow-runtime.js";
17
17
  export { recoverWorkflowStarts, StartRecoveryWorkflowRequired } from "./start-recovery.js";
18
+ export { runTriggerAction, TriggerRunUnsupported, TriggerRunWorkflowRequired, } from "./trigger-run.js";
18
19
  export { agentTask, AgentTaskOptionsInvalid, AgentTaskWorkflowRequired, DEFAULT_AGENT_TASK_TIMEOUT_MS, MAX_AGENT_TASK_PROMPT_LENGTH, MAX_AGENT_TASK_TEXT_LENGTH, MAX_AGENT_TASK_TIMEOUT_MS, MAX_LIVE_AGENT_TASKS, MIN_AGENT_TASK_TIMEOUT_MS, } from "./agent-task.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.118.0",
3
+ "version": "0.119.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",