@segmentstream/ontology 0.118.0 → 0.120.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.120.0
4
+
5
+ A chat post whose delivery did not happen and spent its idempotency key, a message the provider
6
+ refused or a replay of one, now answers `422 action_rejected` with `key_consumed: true`, so a client
7
+ sends it again with a new key. Any other failure keeps meaning: retry with the same key.
8
+ `ActionRejected` takes `keyConsumed: true` for any action whose key a refusal spends.
9
+
10
+ ## 0.119.0
11
+
12
+ A trigger can run one action without a workflow file. List it in `defineOntology({ triggers })`
13
+ with `runs` (the action), `role` and `input`: `cron(...)`, `after(...)` or `webhook(...)`. Each
14
+ is published as a workflow of its name with its own user, runs and permissions, and each run
15
+ performs the action once as that user in one step the Workflow SDK retries when it fails. A
16
+ webhook's `input` maps the delivery to the action's input, or returns `null` to skip it.
17
+ Workflow manifest entries of such triggers carry `action: { entity, action }`.
18
+
19
+ A failed or cancelled run can be retried: the ontology service starts a new run of the same
20
+ workflow with the failed run's input, recording `retryOf`, for a caller holding
21
+ `workflow:<name>:start`. Workspace Editors retry from the console's run page and with
22
+ `segmentstream workflow run retry RUN --workflow NAME`.
23
+
3
24
  ## 0.118.0
4
25
 
5
26
  A reply the agent holds for review is linked to its chat: `agent_review` gains `agentChat`, the
package/dist/analyze.d.ts CHANGED
@@ -15,7 +15,7 @@ import { type FeedbackOptions, type ResolvedFeedback } from "./feedback-config.j
15
15
  import { type ModelMetricManifest, type WorkflowManifest } from "./manifest.js";
16
16
  import type { ModelMetrics } from "./metric.js";
17
17
  import { type EarlierMetricsField } from "./legacy.js";
18
- import { type AnyWorkflow } from "./workflow.js";
18
+ import { type AnyWorkflow, type WorkflowTrigger } from "./workflow.js";
19
19
  import { type ResolvedToolset, type Toolset } from "./toolset.js";
20
20
  /** The input of `defineOntology` and `check`. */
21
21
  export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = ReadonlyArray<AnyEntity>, Metrics extends ModelMetrics = ModelMetrics> extends EarlierMetricsField<Metrics> {
@@ -42,6 +42,13 @@ export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = Read
42
42
  * one declared role. At most 50.
43
43
  */
44
44
  readonly workflows?: ReadonlyArray<AnyWorkflow>;
45
+ /**
46
+ * Triggers that each run one action, retried, without a workflow of their own:
47
+ * `webhook(name, { runs, role, input })`, `after(name, target, { runs, role, input })` and
48
+ * `cron(name, expression, { runs, role, input })`. Each is published as a workflow named like it,
49
+ * with its own workflow user holding `role`; names are unique among workflows and triggers.
50
+ */
51
+ readonly triggers?: ReadonlyArray<WorkflowTrigger>;
45
52
  /**
46
53
  * The built-in role every active app user holds. Its permissions default to `["*:read"]`: members
47
54
  * read everything and run only what other roles grant them.
package/dist/analyze.js CHANGED
@@ -6,6 +6,7 @@ import { BLOB_UPLOAD_ANNOTATION } from "./blob.js";
6
6
  import { isBlobAccept, MAX_BLOB_BYTES } from "./blob.js";
7
7
  import { isAction } from "./action.js";
8
8
  import { CONNECTION_KEY, isConnection } from "./connection.js";
9
+ import { actionNames, isActionHandle, triggerRunsWorkflows } from "./trigger-actions.js";
9
10
  import { isEntity } from "./entity.js";
10
11
  import { QUERY_METRICS_ROUTE, LEGACY_MEMBER_NAME, ENTITY_ID, GENERATED_ACTIONS, GENERATED_UPSERT_PREFIX, HISTORY_SUFFIX, MCP_METRIC_TOOLS, MCP_READ_TOOLS, MCP_TOOL_NAME_MAX_LENGTH, MEMBER_ROLE, FEEDBACK_REPORTER_ROLE, GUEST_ROLE, mcpToolName, RESERVED_ENTITY_NAMES, RESERVED_MEMBER_NAMES, RESERVED_RELATIONSHIP_NAMES, SNAKE_CASE_NAME, SYSTEM_PROPERTIES, humanize, isSystemProperty, toCamelCase, } from "./names.js";
11
12
  import { REFERENCE_ANNOTATION, propertyDefinition, propertyOptionNames, unknownPropertyOptions, referenceTarget, } from "./property.js";
@@ -273,8 +274,14 @@ export function analyze(config, options = {}) {
273
274
  checkToolNames(resolved, report, toolsets);
274
275
  checkWarehouseSource(resolved, report);
275
276
  const metrics = resolveModelMetrics({ metrics: config.metrics, entities: resolved, report });
277
+ const triggerRuns = triggerRunsWorkflows(original.triggers, original.workflows);
278
+ for (const problem of triggerRuns.problems) {
279
+ report(problem.code, problem.path, problem.message);
280
+ }
276
281
  const workflows = resolveWorkflows({
277
- workflows: original.workflows,
282
+ workflows: triggerRuns.workflows.length === 0 || !Array.isArray(original.workflows ?? [])
283
+ ? original.workflows
284
+ : [...(original.workflows ?? []), ...triggerRuns.workflows],
278
285
  entities: resolved,
279
286
  roles,
280
287
  scope,
@@ -597,6 +604,27 @@ function resolveWorkflows(input) {
597
604
  }
598
605
  });
599
606
  }
607
+ // A trigger listed in defineOntology({ triggers }) is published as a workflow that runs its
608
+ // action; a trigger in a workflow's own triggers starts that workflow and runs nothing.
609
+ const runs = candidate.runs === undefined ? undefined : resolveTriggerRuns(candidate.runs, entities);
610
+ if (candidate.runs !== undefined && runs === undefined) {
611
+ const named = isActionHandle(candidate.runs) ? actionNames(candidate.runs) : undefined;
612
+ report("trigger_runs_invalid", `triggers.${String(candidate.name)}.runs`, named === undefined
613
+ ? "runs names an action by its handle, such as Lead.actions.notify."
614
+ : `the ontology has no action ${named.entity}.${named.action}.`);
615
+ valid = false;
616
+ }
617
+ if (candidate.runs === undefined && Array.isArray(candidate.triggers)) {
618
+ for (const trigger of candidate.triggers) {
619
+ if (isWorkflowTrigger(trigger) &&
620
+ (trigger.runs !== undefined ||
621
+ trigger.role !== undefined)) {
622
+ report("trigger_runs_invalid", `${path}.triggers.${String(trigger.name)}`, "a trigger in a workflow's triggers starts the workflow; list a trigger that runs an " +
623
+ "action, with runs and role, in defineOntology({ triggers }).");
624
+ valid = false;
625
+ }
626
+ }
627
+ }
600
628
  const kinds = new Set((Array.isArray(candidate.triggers) ? candidate.triggers : [])
601
629
  .filter(isWorkflowTrigger)
602
630
  .map((trigger) => trigger.kind));
@@ -625,6 +653,7 @@ function resolveWorkflows(input) {
625
653
  input: jsonSchema,
626
654
  connections,
627
655
  triggers,
656
+ ...(runs === undefined ? {} : { action: runs }),
628
657
  });
629
658
  }
630
659
  });
@@ -760,6 +789,17 @@ function resolveWebhookTrigger(trigger, at, scope) {
760
789
  ...(trigger.connection === undefined ? {} : { connection: trigger.connection.key }),
761
790
  };
762
791
  }
792
+ /** The wire names of the action a trigger runs, `undefined` when the ontology has no such action. */
793
+ function resolveTriggerRuns(runs, entities) {
794
+ if (!isActionHandle(runs)) {
795
+ return undefined;
796
+ }
797
+ const names = actionNames(runs);
798
+ const entity = entities.find((candidate) => candidate.name === names.entity);
799
+ return entity?.actions.some((action) => action.name === names.action) === true
800
+ ? names
801
+ : undefined;
802
+ }
763
803
  /**
764
804
  * A cron trigger's manifest form, without its name: the expression normalized and the input in
765
805
  * wire form. `undefined` after reporting a problem.
@@ -1,10 +1,10 @@
1
1
  import { Schema } from "effect";
2
- export declare const DIAGNOSTIC_CODES: readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"];
2
+ export declare const DIAGNOSTIC_CODES: readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"];
3
3
  export type DiagnosticCode = (typeof DIAGNOSTIC_CODES)[number];
4
4
  /** A problem `check` found in an ontology definition. */
5
5
  export declare const Diagnostic: Schema.Struct<{
6
6
  readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
7
- readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
7
+ readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
8
8
  /** Where the problem is, for example `lead.properties.status.options[1]`. */
9
9
  readonly path: Schema.String;
10
10
  readonly message: Schema.String;
@@ -14,7 +14,7 @@ declare const InvalidOntology_base: Schema.Class<InvalidOntology, Schema.TaggedS
14
14
  readonly message: Schema.String;
15
15
  readonly diagnostics: Schema.$Array<Schema.Struct<{
16
16
  readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
17
- readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
17
+ readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
18
18
  /** Where the problem is, for example `lead.properties.status.options[1]`. */
19
19
  readonly path: Schema.String;
20
20
  readonly message: Schema.String;
@@ -80,6 +80,7 @@ export const DIAGNOSTIC_CODES = [
80
80
  "invalid-trigger",
81
81
  "trigger_action_unknown",
82
82
  "trigger_function_async",
83
+ "trigger_runs_invalid",
83
84
  "workflow_trigger_limit_exceeded",
84
85
  "workflow_webhook_duplicate",
85
86
  "workflow_webhook_input_invalid",
package/dist/errors.d.ts CHANGED
@@ -58,6 +58,12 @@ declare const ActionRejected_base: Schema.Class<ActionRejected, Schema.TaggedStr
58
58
  readonly live: Schema.Int;
59
59
  readonly max: Schema.Int;
60
60
  }>]>>;
61
+ /**
62
+ * The request's idempotency key is spent on an operation that did not happen, such as a message
63
+ * the provider refused: the same key is refused again, and a new attempt takes a new key. Absent,
64
+ * a client that is unsure whether its request took effect retries with the same key.
65
+ */
66
+ readonly keyConsumed: Schema.optionalKey<Schema.Literal<true>>;
61
67
  }>, import("effect/Cause").YieldableError>;
62
68
  /**
63
69
  * An action refused the request for a business reason. The message is written for the caller and is
package/dist/errors.js CHANGED
@@ -35,6 +35,12 @@ export class ActionRejected extends Schema.TaggedError()("ActionRejected", {
35
35
  cause: Schema.optionalKey(Schema.Unknown),
36
36
  batch: Schema.optionalKey(BatchErrorDetails),
37
37
  limit: Schema.optionalKey(LimitErrorDetails),
38
+ /**
39
+ * The request's idempotency key is spent on an operation that did not happen, such as a message
40
+ * the provider refused: the same key is refused again, and a new attempt takes a new key. Absent,
41
+ * a client that is unsure whether its request took effect retries with the same key.
42
+ */
43
+ keyConsumed: Schema.optionalKey(Schema.Literal(true)),
38
44
  }) {
39
45
  }
40
46
  /**