@segmentstream/ontology 0.117.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.119.0
4
+
5
+ A trigger can run one action without a workflow file. List it in `defineOntology({ triggers })`
6
+ with `runs` (the action), `role` and `input`: `cron(...)`, `after(...)` or `webhook(...)`. Each
7
+ is published as a workflow of its name with its own user, runs and permissions, and each run
8
+ performs the action once as that user in one step the Workflow SDK retries when it fails. A
9
+ webhook's `input` maps the delivery to the action's input, or returns `null` to skip it.
10
+ Workflow manifest entries of such triggers carry `action: { entity, action }`.
11
+
12
+ A failed or cancelled run can be retried: the ontology service starts a new run of the same
13
+ workflow with the failed run's input, recording `retryOf`, for a caller holding
14
+ `workflow:<name>:start`. Workspace Editors retry from the console's run page and with
15
+ `segmentstream workflow run retry RUN --workflow NAME`.
16
+
17
+ ## 0.118.0
18
+
19
+ A reply the agent holds for review is linked to its chat: `agent_review` gains `agentChat`, the
20
+ chat's `agent_chat` record when the registry has it (a group the agent is in, or a person's private
21
+ chat in the inbox), whose inverse on `agent_chat` is `reviews`. `agent_chat` `find` with
22
+ `where: { reviews: { some: { status: "pending" } } }` lists the chats where replies wait for staff.
23
+ `chatKind` now comes from that record, or from the chat's id, so a reply held in a Slack channel is
24
+ a group's and its approval reaches the channel. A workspace relationship whose inverse on
25
+ `agent_chat` is `reviews` must be renamed.
26
+
3
27
  ## 0.117.0
4
28
 
5
29
  Staff reply in the inbox: `agent_chat.postMessage({ chat: <record id>, text, idempotencyKey })` to a
@@ -53,6 +53,7 @@ export declare const AgentReview: import("./entity.js").Entity<"agent_review", {
53
53
  }, {
54
54
  readonly person: import("./relationship.js").OneRelationship<false, false, "user">;
55
55
  readonly decidedBy: import("./relationship.js").OneRelationship<true, false, "user">;
56
+ readonly agentChat: import("./relationship.js").OneRelationship<true, false, "agent_chat">;
56
57
  }, import("./entity.js").InvocableActions<{
57
58
  readonly approve: import("./action.js").Action<Schema.Struct<{
58
59
  readonly review: Schema.Codec<string, string, never, never>;
@@ -93,5 +94,6 @@ export declare const AgentReview: import("./entity.js").Entity<"agent_review", {
93
94
  readonly decidedAt: string | null;
94
95
  readonly personId: string;
95
96
  readonly decidedById: string | null;
97
+ readonly agentChatId: string | null;
96
98
  }>, Readonly<Record<never, never>>, "actions">;
97
99
  export type AgentReview = typeof AgentReview.Type;
@@ -134,6 +134,14 @@ export const AgentReview = entity("agent_review", {
134
134
  phrase: ["was decided by", "decided"],
135
135
  description: "The member who approved or rejected the reply.",
136
136
  }),
137
+ agentChat: rel.one("agent_chat", {
138
+ optional: true,
139
+ inverse: "reviews",
140
+ onDelete: "setNull",
141
+ phrase: ["was held in", "holds"],
142
+ description: "The chat the reply was held in, as the agent_chat registry has it: a group the agent " +
143
+ "is in, or a person's private chat in the inbox. Empty when the chat is not registered.",
144
+ }),
137
145
  },
138
146
  indexes: [{ properties: ["status"] }],
139
147
  }).actions((self) => ({
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",