@oxygen-agent/cli 1.1014.1997 → 1.1014.2040

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 (119) hide show
  1. package/README.md +1 -1
  2. package/dist/command-families/tables/options.d.ts +1 -0
  3. package/dist/command-families/tables/register-automation.js +3 -1
  4. package/dist/commands/observability.js +4 -4
  5. package/dist/commands/table-runs.js +10 -0
  6. package/dist/commands/tags.js +2 -2
  7. package/dist/commands/workflows.js +31 -10
  8. package/dist/http-client.d.ts +1 -1
  9. package/dist/http-client.js +1 -1
  10. package/node_modules/@oxygen/formula/dist/cross-row-function.d.ts +13 -0
  11. package/node_modules/@oxygen/formula/dist/cross-row-function.js +1 -0
  12. package/node_modules/@oxygen/formula/dist/{refactor-internals → cross-row-functions}/novelty-score.d.ts +2 -0
  13. package/node_modules/@oxygen/formula/dist/{refactor-internals → cross-row-functions}/novelty-score.js +1 -0
  14. package/node_modules/@oxygen/formula/dist/cross-row-functions.generated.d.ts +3 -0
  15. package/node_modules/@oxygen/formula/dist/cross-row-functions.generated.js +3 -0
  16. package/node_modules/@oxygen/formula/dist/evaluate.d.ts +12 -1
  17. package/node_modules/@oxygen/formula/dist/evaluate.js +28 -3
  18. package/node_modules/@oxygen/recipe-sdk/dist/index.d.ts +2 -0
  19. package/node_modules/@oxygen/shared/dist/capability-discovery.js +1 -1
  20. package/node_modules/@oxygen/shared/dist/cell-format.js +2 -2
  21. package/node_modules/@oxygen/shared/dist/collab.d.ts +1 -1
  22. package/node_modules/@oxygen/shared/dist/contracts/geo.js +1 -1
  23. package/node_modules/@oxygen/shared/dist/dnc-identities.js +1 -1
  24. package/node_modules/@oxygen/shared/dist/error-redaction.d.ts +1 -1
  25. package/node_modules/@oxygen/shared/dist/error-redaction.js +2 -2
  26. package/node_modules/@oxygen/shared/dist/esp-contract.d.ts +133 -0
  27. package/node_modules/@oxygen/shared/dist/esp-contract.js +121 -0
  28. package/node_modules/@oxygen/shared/dist/{geo.js → geo/geo.js} +2 -2
  29. package/node_modules/@oxygen/shared/dist/index.d.ts +6 -5
  30. package/node_modules/@oxygen/shared/dist/index.js +7 -5
  31. package/node_modules/@oxygen/shared/dist/knowledge-bootstrap.js +1 -1
  32. package/node_modules/@oxygen/shared/dist/linkedin-connection-identity.js +1 -1
  33. package/node_modules/@oxygen/shared/dist/{sending-domain-rollout.js → mailboxes/sending-domain-rollout.js} +1 -1
  34. package/node_modules/@oxygen/shared/dist/mcp-event-contract.js +1 -1
  35. package/node_modules/@oxygen/shared/dist/{social-post-metrics-core.d.ts → posts/metrics-core.d.ts} +1 -1
  36. package/node_modules/@oxygen/shared/dist/{social-post-metrics-linkedin.d.ts → posts/metrics-linkedin.d.ts} +1 -1
  37. package/node_modules/@oxygen/shared/dist/{social-post-metrics-linkedin.js → posts/metrics-linkedin.js} +2 -2
  38. package/node_modules/@oxygen/shared/dist/{social-post-metrics-series.d.ts → posts/metrics-series.d.ts} +1 -1
  39. package/node_modules/@oxygen/shared/dist/{social-post-metrics-series.js → posts/metrics-series.js} +1 -1
  40. package/node_modules/@oxygen/shared/dist/{social-post-metrics-x.d.ts → posts/metrics-x.d.ts} +1 -1
  41. package/node_modules/@oxygen/shared/dist/{social-post-metrics-x.js → posts/metrics-x.js} +2 -2
  42. package/node_modules/@oxygen/shared/dist/{social-post-metrics.d.ts → posts/metrics.d.ts} +3 -3
  43. package/node_modules/@oxygen/shared/dist/{social-post-metrics.js → posts/metrics.js} +3 -3
  44. package/node_modules/@oxygen/shared/dist/recipient-provider.d.ts +2 -10
  45. package/node_modules/@oxygen/shared/dist/recipient-provider.js +1 -9
  46. package/node_modules/@oxygen/shared/dist/sequence-internals/esp-policy.d.ts +2 -118
  47. package/node_modules/@oxygen/shared/dist/sequence-internals/esp-policy.js +2 -107
  48. package/node_modules/@oxygen/shared/dist/sequences.d.ts +0 -1
  49. package/node_modules/@oxygen/shared/dist/sequences.js +0 -2
  50. package/node_modules/@oxygen/shared/dist/{native-chat-discovery.d.ts → support/native-chat-discovery.d.ts} +1 -1
  51. package/node_modules/@oxygen/shared/dist/{native-chat-discovery.js → support/native-chat-discovery.js} +1 -1
  52. package/node_modules/@oxygen/shared/dist/suppression-entries.js +1 -1
  53. package/node_modules/@oxygen/shared/dist/table-field-types.d.ts +1 -1
  54. package/node_modules/@oxygen/shared/dist/table-field-types.js +2 -2
  55. package/node_modules/@oxygen/shared/dist/{column-output-fields.js → tables/column-output-fields.js} +4 -4
  56. package/node_modules/@oxygen/shared/dist/{tags.d.ts → tags/tags.d.ts} +1 -1
  57. package/node_modules/@oxygen/shared/dist/{tags.js → tags/tags.js} +1 -1
  58. package/node_modules/@oxygen/shared/dist/ugc-amplification-identity.js +1 -1
  59. package/node_modules/@oxygen/shared/dist/version.generated.d.ts +1 -1
  60. package/node_modules/@oxygen/shared/dist/version.generated.js +1 -1
  61. package/node_modules/@oxygen/shared/dist/workspace-placement-bulk.d.ts +6 -0
  62. package/node_modules/@oxygen/shared/dist/workspace-placement-bulk.js +9 -2
  63. package/node_modules/@oxygen/shared/dist/workspace-placement-schedule.d.ts +44 -0
  64. package/node_modules/@oxygen/shared/dist/workspace-placement-schedule.js +90 -0
  65. package/node_modules/@oxygen/shared/dist/workspace-placement-view.d.ts +24 -0
  66. package/node_modules/@oxygen/shared/dist/workspace-placement-view.js +5 -4
  67. package/node_modules/@oxygen/shared/dist/workspace-placement.d.ts +4 -0
  68. package/node_modules/@oxygen/shared/dist/workspace-placement.js +7 -1
  69. package/node_modules/@oxygen/shared/package.json +0 -25
  70. package/node_modules/@oxygen/workflows/dist/cron.d.ts +42 -0
  71. package/node_modules/@oxygen/workflows/dist/cron.js +271 -0
  72. package/node_modules/@oxygen/workflows/dist/event-dispatch.d.ts +2 -1
  73. package/node_modules/@oxygen/workflows/dist/graph/condition.d.ts +3 -0
  74. package/node_modules/@oxygen/workflows/dist/graph/condition.js +19 -0
  75. package/node_modules/@oxygen/workflows/dist/graph/expression.d.ts +1 -2
  76. package/node_modules/@oxygen/workflows/dist/graph/expression.js +2 -19
  77. package/node_modules/@oxygen/workflows/dist/graph/types.d.ts +4 -3
  78. package/node_modules/@oxygen/workflows/dist/index.d.ts +8 -985
  79. package/node_modules/@oxygen/workflows/dist/index.js +8 -1221
  80. package/node_modules/@oxygen/workflows/dist/manifest-builders.d.ts +73 -0
  81. package/node_modules/@oxygen/workflows/dist/manifest-builders.js +102 -0
  82. package/node_modules/@oxygen/workflows/dist/manifest-guards.d.ts +16 -0
  83. package/node_modules/@oxygen/workflows/dist/manifest-guards.js +34 -0
  84. package/node_modules/@oxygen/workflows/dist/manifest-hash.d.ts +47 -0
  85. package/node_modules/@oxygen/workflows/dist/manifest-hash.js +102 -0
  86. package/node_modules/@oxygen/workflows/dist/manifest-lint.d.ts +17 -0
  87. package/node_modules/@oxygen/workflows/dist/manifest-lint.js +474 -0
  88. package/node_modules/@oxygen/workflows/dist/manifest-types.d.ts +256 -0
  89. package/node_modules/@oxygen/workflows/dist/manifest-types.js +9 -0
  90. package/node_modules/@oxygen/workflows/dist/pure-function.d.ts +17 -0
  91. package/node_modules/@oxygen/workflows/dist/pure-function.js +130 -0
  92. package/node_modules/@oxygen/workflows/dist/refactor-internals/condition-comparison.d.ts +1 -17
  93. package/node_modules/@oxygen/workflows/dist/refactor-internals/condition-comparison.js +1 -93
  94. package/node_modules/@oxygen/workflows/dist/refactor-internals/condition-pattern.d.ts +16 -0
  95. package/node_modules/@oxygen/workflows/dist/refactor-internals/condition-pattern.js +92 -0
  96. package/node_modules/@oxygen/workflows/dist/workflow-schemas.d.ts +545 -0
  97. package/node_modules/@oxygen/workflows/dist/workflow-schemas.js +135 -0
  98. package/node_modules/@oxygen/workflows/package.json +4 -0
  99. package/package.json +1 -1
  100. /package/node_modules/@oxygen/shared/dist/{geo.d.ts → geo/geo.d.ts} +0 -0
  101. /package/node_modules/@oxygen/shared/dist/{sending-domain-rollout.d.ts → mailboxes/sending-domain-rollout.d.ts} +0 -0
  102. /package/node_modules/@oxygen/shared/dist/{attempt-provenance.d.ts → observability/attempt-provenance.d.ts} +0 -0
  103. /package/node_modules/@oxygen/shared/dist/{attempt-provenance.js → observability/attempt-provenance.js} +0 -0
  104. /package/node_modules/@oxygen/shared/dist/{linkedin-mentions.d.ts → posts/linkedin-mentions.d.ts} +0 -0
  105. /package/node_modules/@oxygen/shared/dist/{linkedin-mentions.js → posts/linkedin-mentions.js} +0 -0
  106. /package/node_modules/@oxygen/shared/dist/{linkedin-post-keywords.d.ts → posts/linkedin-post-keywords.d.ts} +0 -0
  107. /package/node_modules/@oxygen/shared/dist/{linkedin-post-keywords.js → posts/linkedin-post-keywords.js} +0 -0
  108. /package/node_modules/@oxygen/shared/dist/{linkedin-post-url.d.ts → posts/linkedin-post-url.d.ts} +0 -0
  109. /package/node_modules/@oxygen/shared/dist/{linkedin-post-url.js → posts/linkedin-post-url.js} +0 -0
  110. /package/node_modules/@oxygen/shared/dist/{social-post-metrics-core.js → posts/metrics-core.js} +0 -0
  111. /package/node_modules/@oxygen/shared/dist/{native-chat.d.ts → support/native-chat.d.ts} +0 -0
  112. /package/node_modules/@oxygen/shared/dist/{native-chat.js → support/native-chat.js} +0 -0
  113. /package/node_modules/@oxygen/shared/dist/{plain-support-events.d.ts → support/plain-support-events.d.ts} +0 -0
  114. /package/node_modules/@oxygen/shared/dist/{plain-support-events.js → support/plain-support-events.js} +0 -0
  115. /package/node_modules/@oxygen/shared/dist/{column-output-fields.d.ts → tables/column-output-fields.d.ts} +0 -0
  116. /package/node_modules/@oxygen/shared/dist/{linkedin-url.d.ts → tables/linkedin-url.d.ts} +0 -0
  117. /package/node_modules/@oxygen/shared/dist/{linkedin-url.js → tables/linkedin-url.js} +0 -0
  118. /package/node_modules/@oxygen/shared/dist/{select-options.d.ts → tables/select-options.d.ts} +0 -0
  119. /package/node_modules/@oxygen/shared/dist/{select-options.js → tables/select-options.js} +0 -0
@@ -0,0 +1,256 @@
1
+ import { DURABLE_RECIPE_COMPILER_VERSION, type JsonSchema, type WorkflowStatus, type WorkflowStepEffect } from "./manifest-validation.js";
2
+ import type { WorkflowGraphManifest } from "./graph/types.js";
3
+ /**
4
+ * v1 workflow, recipe and blueprint manifest shapes and compiler constants.
5
+ * Declarations only; `index.ts` re-exports them.
6
+ */
7
+ export declare const WORKFLOW_COMPILER_VERSION = "oxygen-workflows-v1";
8
+ export declare const BLUEPRINT_VERSION = 1;
9
+ export declare const BLUEPRINT_COMPILER_VERSION = "oxygen-blueprints-v1";
10
+ export declare const MAX_BLUEPRINT_BYTES = 4000000;
11
+ export declare const DEFAULT_WORKFLOW_CRON_TIMEZONE = "UTC";
12
+ export type WorkflowMode = "dry_run" | "live" | "smoke_test";
13
+ export type WorkflowTriggerType = "api" | "webhook" | "cron" | "event";
14
+ export type RecipeRuntime = "durable";
15
+ export type WorkflowEventFilterOp = "eq" | "neq" | "exists" | "not_exists";
16
+ export type WorkflowEventFilter = {
17
+ path: string;
18
+ op: WorkflowEventFilterOp;
19
+ value?: unknown;
20
+ };
21
+ export type WorkflowTriggerManifest = {
22
+ type: "api";
23
+ status?: WorkflowStatus;
24
+ } | {
25
+ type: "webhook";
26
+ trigger_id: string;
27
+ trigger_name?: string | null;
28
+ secret_required?: boolean;
29
+ idempotency_key_path?: string | null;
30
+ status?: WorkflowStatus;
31
+ } | {
32
+ type: "cron";
33
+ cron: string;
34
+ timezone?: string | null;
35
+ metadata?: Record<string, unknown>;
36
+ status?: WorkflowStatus;
37
+ } | {
38
+ type: "event";
39
+ source: string;
40
+ event: string;
41
+ filters?: WorkflowEventFilter[];
42
+ idempotency_key_path?: string | null;
43
+ status?: WorkflowStatus;
44
+ };
45
+ export type WorkflowTransformStepManifest = {
46
+ kind: "transform";
47
+ id: string;
48
+ description?: string;
49
+ run_source: string;
50
+ };
51
+ export type WorkflowToolStepManifest = {
52
+ kind: "tool";
53
+ id: string;
54
+ description?: string;
55
+ tool: string;
56
+ effect: WorkflowStepEffect;
57
+ mode?: WorkflowMode;
58
+ /** Pin this invocation to one active organization integration connection. */
59
+ connection_id?: string;
60
+ payload_source: string;
61
+ max_credits?: number;
62
+ };
63
+ export type WorkflowBranchStepManifest = {
64
+ kind: "branch";
65
+ id: string;
66
+ description?: string;
67
+ condition_source: string;
68
+ then_id: string;
69
+ else_id?: string;
70
+ join_id?: string;
71
+ };
72
+ export type WorkflowStepManifest = WorkflowTransformStepManifest | WorkflowToolStepManifest | WorkflowBranchStepManifest;
73
+ export type RecipeVisualToolStepManifest = {
74
+ kind: "tool";
75
+ id: string;
76
+ label: string;
77
+ description?: string;
78
+ tool: string;
79
+ effect?: WorkflowStepEffect;
80
+ checkpoint_id?: string;
81
+ };
82
+ export type RecipeVisualCodeStepManifest = {
83
+ kind: "step";
84
+ id: string;
85
+ label: string;
86
+ description?: string;
87
+ checkpoint_id?: string;
88
+ };
89
+ export type RecipeVisualBranchStepManifest = {
90
+ kind: "branch";
91
+ id: string;
92
+ label: string;
93
+ description?: string;
94
+ condition_label?: string;
95
+ then_id: string;
96
+ else_id?: string;
97
+ join_id?: string;
98
+ checkpoint_id?: string;
99
+ };
100
+ export type RecipeVisualStepManifest = RecipeVisualToolStepManifest | RecipeVisualCodeStepManifest | RecipeVisualBranchStepManifest;
101
+ export type RecipeVisualPlanManifest = {
102
+ version: 1;
103
+ steps: RecipeVisualStepManifest[];
104
+ };
105
+ export type WorkflowManifest = {
106
+ manifest_version: 1;
107
+ workflow: {
108
+ id: string;
109
+ name: string;
110
+ status?: WorkflowStatus;
111
+ };
112
+ specification?: string;
113
+ trigger?: WorkflowTriggerManifest;
114
+ input_schema?: JsonSchema;
115
+ steps: WorkflowStepManifest[];
116
+ max_credits?: number;
117
+ source_hash: string;
118
+ compiler_version: string;
119
+ created_at: string;
120
+ };
121
+ export type RecipeManifest = {
122
+ manifest_version: 1;
123
+ workflow: {
124
+ id: string;
125
+ name: string;
126
+ status?: WorkflowStatus;
127
+ };
128
+ trigger?: WorkflowTriggerManifest;
129
+ input_schema?: JsonSchema;
130
+ /**
131
+ * Operator-editable recipe settings, distinct from the per-delivery trigger
132
+ * payload. When present, the canvas renders this schema with the same mapped
133
+ * field controls used by tool/action configuration.
134
+ */
135
+ configuration_schema?: JsonSchema;
136
+ configuration?: Record<string, unknown>;
137
+ runtime: RecipeRuntime;
138
+ bundle: string;
139
+ bundle_format: "esm";
140
+ tools_used: string[];
141
+ visual_plan?: RecipeVisualPlanManifest;
142
+ max_credits?: number;
143
+ source_hash: string;
144
+ compiler_version: typeof DURABLE_RECIPE_COMPILER_VERSION;
145
+ created_at: string;
146
+ };
147
+ export type AnyWorkflowManifest = WorkflowManifest | RecipeManifest | WorkflowGraphManifest;
148
+ export type BlueprintColumnInput = {
149
+ key?: string;
150
+ label: string;
151
+ dataType?: string;
152
+ kind?: string;
153
+ semanticType?: string | null;
154
+ definition?: Record<string, unknown>;
155
+ };
156
+ export type BlueprintTable = {
157
+ ref: string;
158
+ name: string;
159
+ description?: string;
160
+ columns: BlueprintColumnInput[];
161
+ metadata?: Record<string, unknown>;
162
+ };
163
+ export type BlueprintColumnGraft = {
164
+ table_ref: string;
165
+ column: BlueprintColumnInput;
166
+ };
167
+ export type BlueprintPromptKind = "ai_column_system" | "scoring_rubric" | "other";
168
+ export type BlueprintPromptTemplate = {
169
+ slug: string;
170
+ name: string;
171
+ description?: string | null;
172
+ kind: BlueprintPromptKind;
173
+ body: string;
174
+ };
175
+ export type BlueprintIntegrationRequirement = {
176
+ kind: string;
177
+ purpose?: string;
178
+ required?: boolean;
179
+ };
180
+ export type BlueprintByokRequirement = {
181
+ kind: "openai" | "anthropic" | "google" | "openrouter" | string;
182
+ required?: boolean;
183
+ };
184
+ export type BlueprintRequires = {
185
+ integrations?: BlueprintIntegrationRequirement[];
186
+ context_keys?: string[];
187
+ byok?: BlueprintByokRequirement[];
188
+ };
189
+ export type BlueprintWorkflow = {
190
+ manifest: AnyWorkflowManifest;
191
+ table_refs?: Record<string, string>;
192
+ prompt_template_slugs?: string[];
193
+ };
194
+ export type Blueprint = {
195
+ blueprint_version: typeof BLUEPRINT_VERSION;
196
+ id: string;
197
+ name: string;
198
+ summary: string;
199
+ tags: string[];
200
+ audience?: string[];
201
+ requires: BlueprintRequires;
202
+ input_schema?: JsonSchema;
203
+ tables: BlueprintTable[];
204
+ column_grafts?: BlueprintColumnGraft[];
205
+ prompt_templates: BlueprintPromptTemplate[];
206
+ workflows: BlueprintWorkflow[];
207
+ exported_at: string;
208
+ exported_from?: {
209
+ oxygen_version?: string;
210
+ };
211
+ source_hash: string;
212
+ compiler_version: typeof BLUEPRINT_COMPILER_VERSION;
213
+ };
214
+ export type WorkflowFunction = (context: Record<string, unknown>) => unknown | Promise<unknown>;
215
+ export type WorkflowDefinition = {
216
+ readonly __oxygen_workflow_definition: true;
217
+ id: string;
218
+ name: string;
219
+ status?: WorkflowStatus;
220
+ specification?: string;
221
+ trigger?: WorkflowTriggerDefinition;
222
+ inputSchema?: JsonSchema;
223
+ maxCredits?: number;
224
+ steps: WorkflowStepDefinition[];
225
+ };
226
+ export type WorkflowTriggerDefinition = WorkflowTriggerManifest;
227
+ export type WorkflowTransformStepDefinition = {
228
+ readonly __oxygen_workflow_step: true;
229
+ kind: "transform";
230
+ id: string;
231
+ description?: string;
232
+ run: WorkflowFunction;
233
+ };
234
+ export type WorkflowToolStepDefinition = {
235
+ readonly __oxygen_workflow_step: true;
236
+ kind: "tool";
237
+ id: string;
238
+ description?: string;
239
+ tool: string;
240
+ effect?: WorkflowStepEffect;
241
+ mode?: WorkflowMode;
242
+ connectionId?: string;
243
+ maxCredits?: number;
244
+ payload: WorkflowFunction;
245
+ };
246
+ export type WorkflowBranchStepDefinition = {
247
+ readonly __oxygen_workflow_step: true;
248
+ kind: "branch";
249
+ id: string;
250
+ description?: string;
251
+ condition: WorkflowFunction;
252
+ then: string;
253
+ else?: string;
254
+ join?: string;
255
+ };
256
+ export type WorkflowStepDefinition = WorkflowTransformStepDefinition | WorkflowToolStepDefinition | WorkflowBranchStepDefinition;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * v1 workflow, recipe and blueprint manifest shapes and compiler constants.
3
+ * Declarations only; `index.ts` re-exports them.
4
+ */
5
+ export const WORKFLOW_COMPILER_VERSION = "oxygen-workflows-v1";
6
+ export const BLUEPRINT_VERSION = 1;
7
+ export const BLUEPRINT_COMPILER_VERSION = "oxygen-blueprints-v1";
8
+ export const MAX_BLUEPRINT_BYTES = 4_000_000;
9
+ export const DEFAULT_WORKFLOW_CRON_TIMEZONE = "UTC";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The v1 pure-function sandbox: runs caller-provided transform code in `node:vm` with a timeout and a JSON-only result.
3
+ */
4
+ /**
5
+ * The ceiling of the legacy synchronous `node:vm` path below. It stays at 10 s
6
+ * (and its callers pass 1 s) when the typed Code node rose to 30 s (repricing
7
+ * 2026-09, decision L4.3; proposal P-49): this path runs on the worker's own
8
+ * event loop, so a long synchronous script would stall every other job and its
9
+ * queue lock renewal. The typed Code node runs in a separate microVM instead.
10
+ */
11
+ export declare const PURE_WORKFLOW_FUNCTION_MAX_TIMEOUT_MS = 10000;
12
+ export declare function runPureWorkflowFunction(input: {
13
+ source: string;
14
+ context: Record<string, unknown>;
15
+ timeoutMs?: number;
16
+ maxOutputBytes?: number;
17
+ }): Promise<unknown>;
@@ -0,0 +1,130 @@
1
+ import { WORKFLOW_CODE_V1_DEFAULT_OUTPUT_BYTES, WORKFLOW_CODE_V1_DEFAULT_TIMEOUT_MS, WORKFLOW_CODE_V1_MAX_OUTPUT_BYTES, WORKFLOW_CODE_V1_MIN_OUTPUT_BYTES, WORKFLOW_CODE_V1_MIN_TIMEOUT_MS } from "./graph/types.js";
2
+ import { validatePureFunctionSource } from "./manifest-validation.js";
3
+ import * as vm from "node:vm";
4
+ /**
5
+ * The v1 pure-function sandbox: runs caller-provided transform code in `node:vm` with a timeout and a JSON-only result.
6
+ */
7
+ /**
8
+ * The ceiling of the legacy synchronous `node:vm` path below. It stays at 10 s
9
+ * (and its callers pass 1 s) when the typed Code node rose to 30 s (repricing
10
+ * 2026-09, decision L4.3; proposal P-49): this path runs on the worker's own
11
+ * event loop, so a long synchronous script would stall every other job and its
12
+ * queue lock renewal. The typed Code node runs in a separate microVM instead.
13
+ */
14
+ export const PURE_WORKFLOW_FUNCTION_MAX_TIMEOUT_MS = 10_000;
15
+ export async function runPureWorkflowFunction(input) {
16
+ const timeoutMs = Math.max(WORKFLOW_CODE_V1_MIN_TIMEOUT_MS, Math.min(input.timeoutMs ?? WORKFLOW_CODE_V1_DEFAULT_TIMEOUT_MS, PURE_WORKFLOW_FUNCTION_MAX_TIMEOUT_MS));
17
+ const maxOutputBytes = Math.max(WORKFLOW_CODE_V1_MIN_OUTPUT_BYTES, Math.min(input.maxOutputBytes ?? WORKFLOW_CODE_V1_DEFAULT_OUTPUT_BYTES, WORKFLOW_CODE_V1_MAX_OUTPUT_BYTES));
18
+ const issues = [];
19
+ validatePureFunctionSource(input.source, "$.source", (path, code, message) => {
20
+ issues.push({ path, code, message });
21
+ });
22
+ if (issues.length > 0) {
23
+ const first = issues[0];
24
+ throw new Error(first ? `${first.code}: ${first.message}` : "Invalid workflow function source.");
25
+ }
26
+ // Cross the host/sandbox boundary as a JSON string, then parse INSIDE the
27
+ // vm context. If we passed the host object directly its prototype chain
28
+ // would point at the host's Object/Function, and the regex token blacklist
29
+ // is trivially bypassed (e.g. "con"+"structor") to reach
30
+ // __oxygen_context.constructor.constructor === host Function — which is
31
+ // not affected by the new context's codeGeneration setting and yields
32
+ // worker-process RCE. Parsing inside the context rebinds the prototype to
33
+ // the sandboxed Object, so the same walk reaches the sandboxed Function,
34
+ // which then trips contextCodeGeneration.strings=false below.
35
+ const context = toJsonValue(input.context, "context");
36
+ const contextJson = JSON.stringify(context);
37
+ const sandbox = Object.create(null);
38
+ sandbox.__oxygen_context_json = contextJson;
39
+ // Shadow dangerous globals on the sandbox surface. Defense-in-depth: the
40
+ // load-bearing block is contextCodeGeneration; this just removes the
41
+ // obvious top-level handles.
42
+ sandbox.Function = undefined;
43
+ sandbox.eval = undefined;
44
+ sandbox.setTimeout = undefined;
45
+ sandbox.setInterval = undefined;
46
+ sandbox.setImmediate = undefined;
47
+ sandbox.queueMicrotask = undefined;
48
+ sandbox.WebAssembly = undefined;
49
+ const script = new vm.Script('"use strict";\n'
50
+ + 'const __oxygen_context = JSON.parse(__oxygen_context_json);\n'
51
+ + `const __oxygen_fn = (${input.source});\n`
52
+ + '__oxygen_fn(__oxygen_context);');
53
+ // Disable dynamic code generation in the sandboxed context. Combined with
54
+ // the JSON re-parse above, this means every prototype-walk path to
55
+ // Function — direct, via context.constructor.constructor, or any other
56
+ // reachable Function instance — throws EvalError when called with source.
57
+ try {
58
+ const result = script.runInNewContext(sandbox, {
59
+ timeout: timeoutMs,
60
+ contextCodeGeneration: {
61
+ strings: false,
62
+ wasm: false,
63
+ },
64
+ });
65
+ const resolved = isPromiseLike(result)
66
+ ? await withTimeout(result, timeoutMs)
67
+ : result;
68
+ return enforceJsonOutput(resolved, maxOutputBytes);
69
+ }
70
+ catch (error) {
71
+ throw normalizeSandboxThrow(error);
72
+ }
73
+ }
74
+ // A throw from inside the vm sandbox is constructed with the sandbox realm's
75
+ // Error, so `error instanceof Error` is false in the host worker — and
76
+ // serializeOxygenError then drops the message and reports a generic
77
+ // "Workflow run failed.", leaving a failing transform/branch undebuggable.
78
+ // Reconstruct a host-realm Error preserving the user's message/name. Host-realm
79
+ // throws (vm timeout, enforceJsonOutput's workflow_output_too_large) already
80
+ // pass instanceof and are returned unchanged.
81
+ function normalizeSandboxThrow(error) {
82
+ if (error instanceof Error)
83
+ return error;
84
+ if (error && typeof error === "object") {
85
+ const record = error;
86
+ const message = typeof record.message === "string" && record.message
87
+ ? record.message
88
+ : "Workflow function threw.";
89
+ const normalized = new Error(message);
90
+ if (typeof record.name === "string" && record.name)
91
+ normalized.name = record.name;
92
+ return normalized;
93
+ }
94
+ return new Error(typeof error === "string" && error ? error : "Workflow function threw a non-error value.");
95
+ }
96
+ function enforceJsonOutput(value, maxOutputBytes) {
97
+ const json = JSON.stringify(value);
98
+ if (json === undefined)
99
+ return null;
100
+ if (Buffer.byteLength(json) > maxOutputBytes) {
101
+ throw new Error("workflow_output_too_large: Workflow function output is too large.");
102
+ }
103
+ return JSON.parse(json);
104
+ }
105
+ function toJsonValue(value, label) {
106
+ const json = JSON.stringify(value);
107
+ if (json === undefined) {
108
+ throw new Error(`${label} must be JSON serializable.`);
109
+ }
110
+ return JSON.parse(json);
111
+ }
112
+ function isPromiseLike(value) {
113
+ return value !== null && typeof value === "object" && "then" in value
114
+ && typeof value.then === "function";
115
+ }
116
+ async function withTimeout(promise, timeoutMs) {
117
+ let timer = null;
118
+ try {
119
+ return await Promise.race([
120
+ promise,
121
+ new Promise((_, reject) => {
122
+ timer = setTimeout(() => reject(new Error("workflow_function_timeout: Workflow function timed out.")), timeoutMs);
123
+ }),
124
+ ]);
125
+ }
126
+ finally {
127
+ if (timer)
128
+ clearTimeout(timer);
129
+ }
130
+ }
@@ -1,18 +1,2 @@
1
- export type WorkflowCompareOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "contains" | "not_contains" | "starts_with" | "ends_with" | "is_empty" | "is_not_empty" | "in" | "not_in" | "matches";
1
+ import type { WorkflowCompareOp } from "../graph/types.js";
2
2
  export declare function compareWorkflowConditionValues(left: unknown, op: WorkflowCompareOp, right: unknown): boolean;
3
- /**
4
- * Compile a `matches` pattern, or return null when it is unsafe or invalid.
5
- *
6
- * Choice: conservative STATIC REJECTION rather than a linear (Thompson NFA)
7
- * matcher. A linear engine would be several hundred lines of new, security-load-
8
- * bearing code in a module the browser also bundles, whereas the patterns real
9
- * GTM authors write (domain suffixes, job-title keywords, ID formats) never need
10
- * the constructs rejected here. Rejected: sources over 200 characters,
11
- * lookaround, backreferences, and a quantified group whose body itself contains
12
- * an unbounded quantifier — the `(a+)+` family that drives catastrophic
13
- * backtracking. Everything else compiles as a normal RegExp.
14
- *
15
- * The linter calls this at authoring time and reports `invalid_condition`, so a
16
- * rejected pattern is a lint error the author sees, not a silent run-time false.
17
- */
18
- export declare function compileConditionPattern(pattern: string): RegExp | null;
@@ -1,3 +1,4 @@
1
+ import { compileConditionPattern } from "./condition-pattern.js";
1
2
  export function compareWorkflowConditionValues(left, op, right) {
2
3
  switch (op) {
3
4
  case "eq":
@@ -119,99 +120,6 @@ function textOf(value) {
119
120
  return "";
120
121
  }
121
122
  }
122
- // ---------------------------------------------------------------------------
123
- // `matches`
124
- // ---------------------------------------------------------------------------
125
- const MAX_CONDITION_PATTERN_LENGTH = 200;
126
- /**
127
- * Compile a `matches` pattern, or return null when it is unsafe or invalid.
128
- *
129
- * Choice: conservative STATIC REJECTION rather than a linear (Thompson NFA)
130
- * matcher. A linear engine would be several hundred lines of new, security-load-
131
- * bearing code in a module the browser also bundles, whereas the patterns real
132
- * GTM authors write (domain suffixes, job-title keywords, ID formats) never need
133
- * the constructs rejected here. Rejected: sources over 200 characters,
134
- * lookaround, backreferences, and a quantified group whose body itself contains
135
- * an unbounded quantifier — the `(a+)+` family that drives catastrophic
136
- * backtracking. Everything else compiles as a normal RegExp.
137
- *
138
- * The linter calls this at authoring time and reports `invalid_condition`, so a
139
- * rejected pattern is a lint error the author sees, not a silent run-time false.
140
- */
141
- export function compileConditionPattern(pattern) {
142
- if (!isSafeRegExpSource(pattern))
143
- return null;
144
- try {
145
- return new RegExp(pattern);
146
- }
147
- catch {
148
- return null;
149
- }
150
- }
151
- function isSafeRegExpSource(source) {
152
- if (!source || source.length > MAX_CONDITION_PATTERN_LENGTH)
153
- return false;
154
- if (/\(\?<?[=!]/.test(source))
155
- return false; // lookahead / lookbehind
156
- if (/\\[1-9]/.test(source))
157
- return false; // backreference
158
- return !hasNestedQuantifier(source);
159
- }
160
- function isUnboundedQuantifier(char) {
161
- // `?` alone is bounded and cannot blow up; `*`, `+` and `{n,m}` can.
162
- return char === "*" || char === "+" || char === "{";
163
- }
164
- function hasNestedQuantifier(source) {
165
- // One frame per open group, plus a base frame for the top level. A frame is
166
- // "quantified" once anything inside it repeats.
167
- const stack = [{ quantified: false }];
168
- let inCharacterClass = false;
169
- let index = 0;
170
- while (index < source.length) {
171
- const char = source[index] ?? "";
172
- if (char === "\\") {
173
- index += 2;
174
- continue;
175
- }
176
- if (inCharacterClass) {
177
- if (char === "]")
178
- inCharacterClass = false;
179
- index += 1;
180
- continue;
181
- }
182
- if (char === "[") {
183
- inCharacterClass = true;
184
- index += 1;
185
- continue;
186
- }
187
- if (char === "(") {
188
- stack.push({ quantified: false });
189
- index += 1;
190
- continue;
191
- }
192
- if (char === ")") {
193
- index += 1;
194
- // Unbalanced ")" — leave it to RegExp construction to reject.
195
- if (stack.length === 1)
196
- continue;
197
- const frame = stack.pop();
198
- const repeated = isUnboundedQuantifier(source[index] ?? "");
199
- if (repeated && frame?.quantified === true)
200
- return true;
201
- const parent = stack[stack.length - 1];
202
- if (parent && (repeated || frame?.quantified === true))
203
- parent.quantified = true;
204
- continue;
205
- }
206
- if (isUnboundedQuantifier(char)) {
207
- const top = stack[stack.length - 1];
208
- if (top)
209
- top.quantified = true;
210
- }
211
- index += 1;
212
- }
213
- return false;
214
- }
215
123
  function matchesPattern(value, pattern) {
216
124
  if (typeof pattern !== "string")
217
125
  return false;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Compile a `matches` pattern, or return null when it is unsafe or invalid.
3
+ *
4
+ * Choice: conservative STATIC REJECTION rather than a linear (Thompson NFA)
5
+ * matcher. A linear engine would be several hundred lines of new, security-load-
6
+ * bearing code in a module the browser also bundles, whereas the patterns real
7
+ * GTM authors write (domain suffixes, job-title keywords, ID formats) never need
8
+ * the constructs rejected here. Rejected: sources over 200 characters,
9
+ * lookaround, backreferences, and a quantified group whose body itself contains
10
+ * an unbounded quantifier — the `(a+)+` family that drives catastrophic
11
+ * backtracking. Everything else compiles as a normal RegExp.
12
+ *
13
+ * The linter calls this at authoring time and reports `invalid_condition`, so a
14
+ * rejected pattern is a lint error the author sees, not a silent run-time false.
15
+ */
16
+ export declare function compileConditionPattern(pattern: string): RegExp | null;
@@ -0,0 +1,92 @@
1
+ // Safe `matches` pattern compilation, shared by run-time condition comparison
2
+ // and the linter. Browser-safe, with no imports.
3
+ const MAX_CONDITION_PATTERN_LENGTH = 200;
4
+ /**
5
+ * Compile a `matches` pattern, or return null when it is unsafe or invalid.
6
+ *
7
+ * Choice: conservative STATIC REJECTION rather than a linear (Thompson NFA)
8
+ * matcher. A linear engine would be several hundred lines of new, security-load-
9
+ * bearing code in a module the browser also bundles, whereas the patterns real
10
+ * GTM authors write (domain suffixes, job-title keywords, ID formats) never need
11
+ * the constructs rejected here. Rejected: sources over 200 characters,
12
+ * lookaround, backreferences, and a quantified group whose body itself contains
13
+ * an unbounded quantifier — the `(a+)+` family that drives catastrophic
14
+ * backtracking. Everything else compiles as a normal RegExp.
15
+ *
16
+ * The linter calls this at authoring time and reports `invalid_condition`, so a
17
+ * rejected pattern is a lint error the author sees, not a silent run-time false.
18
+ */
19
+ export function compileConditionPattern(pattern) {
20
+ if (!isSafeRegExpSource(pattern))
21
+ return null;
22
+ try {
23
+ return new RegExp(pattern);
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ }
29
+ function isSafeRegExpSource(source) {
30
+ if (!source || source.length > MAX_CONDITION_PATTERN_LENGTH)
31
+ return false;
32
+ if (/\(\?<?[=!]/.test(source))
33
+ return false; // lookahead / lookbehind
34
+ if (/\\[1-9]/.test(source))
35
+ return false; // backreference
36
+ return !hasNestedQuantifier(source);
37
+ }
38
+ function isUnboundedQuantifier(char) {
39
+ // `?` alone is bounded and cannot blow up; `*`, `+` and `{n,m}` can.
40
+ return char === "*" || char === "+" || char === "{";
41
+ }
42
+ function hasNestedQuantifier(source) {
43
+ // One frame per open group, plus a base frame for the top level. A frame is
44
+ // "quantified" once anything inside it repeats.
45
+ const stack = [{ quantified: false }];
46
+ let inCharacterClass = false;
47
+ let index = 0;
48
+ while (index < source.length) {
49
+ const char = source[index] ?? "";
50
+ if (char === "\\") {
51
+ index += 2;
52
+ continue;
53
+ }
54
+ if (inCharacterClass) {
55
+ if (char === "]")
56
+ inCharacterClass = false;
57
+ index += 1;
58
+ continue;
59
+ }
60
+ if (char === "[") {
61
+ inCharacterClass = true;
62
+ index += 1;
63
+ continue;
64
+ }
65
+ if (char === "(") {
66
+ stack.push({ quantified: false });
67
+ index += 1;
68
+ continue;
69
+ }
70
+ if (char === ")") {
71
+ index += 1;
72
+ // Unbalanced ")" — leave it to RegExp construction to reject.
73
+ if (stack.length === 1)
74
+ continue;
75
+ const frame = stack.pop();
76
+ const repeated = isUnboundedQuantifier(source[index] ?? "");
77
+ if (repeated && frame?.quantified === true)
78
+ return true;
79
+ const parent = stack[stack.length - 1];
80
+ if (parent && (repeated || frame?.quantified === true))
81
+ parent.quantified = true;
82
+ continue;
83
+ }
84
+ if (isUnboundedQuantifier(char)) {
85
+ const top = stack[stack.length - 1];
86
+ if (top)
87
+ top.quantified = true;
88
+ }
89
+ index += 1;
90
+ }
91
+ return false;
92
+ }