@elementumai/edk 0.9.18 → 0.9.19

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 (125) hide show
  1. package/README.md +8 -3
  2. package/dist-sdk/src/catalog/factories.d.ts +11 -0
  3. package/dist-sdk/src/catalog/factories.js +6 -0
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +2 -2
  6. package/dist-sdk/src/catalog/org.d.ts +39 -1
  7. package/dist-sdk/src/catalog/org.js +460 -50
  8. package/dist-sdk/src/catalog/types.d.ts +10 -0
  9. package/dist-sdk/src/catalog/types.js +2 -0
  10. package/dist-sdk/src/engine/pull/ref-only.js +54 -20
  11. package/dist-sdk/src/engine/pull/result-output.d.ts +2 -0
  12. package/dist-sdk/src/engine/pull/result-output.js +1 -1
  13. package/dist-sdk/src/engine/tf/expr.js +38 -13
  14. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  15. package/dist-sdk/src/engine/tf/index.js +2 -2
  16. package/dist-sdk/src/engine/tf/labels.d.ts +2 -0
  17. package/dist-sdk/src/engine/tf/labels.js +4 -0
  18. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  19. package/dist-sdk/src/engine/tf/parse.js +105 -6
  20. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  21. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  22. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  23. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  24. package/dist-sdk/src/entities/access-policy/to-tf.js +11 -4
  25. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -1
  26. package/dist-sdk/src/entities/app/build.d.ts +10 -0
  27. package/dist-sdk/src/entities/app/build.js +0 -13
  28. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +6 -1
  29. package/dist-sdk/src/entities/app/from-tf.js +4 -3
  30. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  31. package/dist-sdk/src/entities/app/index.js +1 -0
  32. package/dist-sdk/src/entities/app/module.js +13 -0
  33. package/dist-sdk/src/entities/app/to-tf.js +2 -0
  34. package/dist-sdk/src/entities/automation/build.d.ts +2 -1
  35. package/dist-sdk/src/entities/automation/build.js +27 -0
  36. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +6 -0
  37. package/dist-sdk/src/entities/automation/from-tf.js +135 -26
  38. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  39. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  40. package/dist-sdk/src/entities/automation/module.js +56 -0
  41. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  42. package/dist-sdk/src/entities/automation/system-ref-name.js +44 -0
  43. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +15 -0
  44. package/dist-sdk/src/entities/automation/task-output-labels.js +38 -0
  45. package/dist-sdk/src/entities/automation/tasks.d.ts +29 -2
  46. package/dist-sdk/src/entities/automation/to-tf.js +158 -84
  47. package/dist-sdk/src/entities/automation/types.js +1 -0
  48. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  49. package/dist-sdk/src/entities/chart/module.js +3 -1
  50. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  51. package/dist-sdk/src/entities/chart/printer.js +26 -16
  52. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  53. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  54. package/dist-sdk/src/entities/chart/to-tf.js +12 -10
  55. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  56. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  57. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  58. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  59. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  60. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +51 -2
  61. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  62. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  63. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  64. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  65. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  66. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  67. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  68. package/dist-sdk/src/entities/element/build.d.ts +8 -0
  69. package/dist-sdk/src/entities/element/build.js +1 -0
  70. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  71. package/dist-sdk/src/entities/element/from-tf.js +6 -2
  72. package/dist-sdk/src/entities/element/index.d.ts +1 -0
  73. package/dist-sdk/src/entities/element/index.js +1 -0
  74. package/dist-sdk/src/entities/element/module.js +2 -0
  75. package/dist-sdk/src/entities/element/to-tf.js +12 -0
  76. package/dist-sdk/src/entities/field/from-tf.d.ts +2 -0
  77. package/dist-sdk/src/entities/field/from-tf.js +11 -0
  78. package/dist-sdk/src/entities/field/to-tf.js +13 -9
  79. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  80. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  81. package/dist-sdk/src/entities/relationship/to-tf.d.ts +8 -0
  82. package/dist-sdk/src/entities/relationship/to-tf.js +19 -10
  83. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -2
  84. package/dist-sdk/src/entities/shared/filters/index.d.ts +23 -2
  85. package/dist-sdk/src/entities/shared/filters/index.js +24 -1
  86. package/dist-sdk/src/entities/shared/filters/print.js +14 -2
  87. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +23 -3
  88. package/dist-sdk/src/entities/shared/filters/tf-codec.js +46 -14
  89. package/dist-sdk/src/entities/shared/filters/types.d.ts +13 -4
  90. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  91. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  92. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  93. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  94. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  95. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  96. package/dist-sdk/src/entities/skill/build.js +3 -0
  97. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  98. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +21 -0
  99. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  100. package/dist-sdk/src/entities/skill/from-tf.js +4 -9
  101. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  102. package/dist-sdk/src/entities/skill/index.js +1 -0
  103. package/dist-sdk/src/entities/skill/module.js +1 -0
  104. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  105. package/dist-sdk/src/entities/skill/to-tf.js +5 -2
  106. package/dist-sdk/src/entities/skill-tool/to-tf.js +2 -1
  107. package/dist-sdk/src/entities/table/to-tf.js +3 -3
  108. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -0
  109. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +224 -0
  110. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +36 -0
  111. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +288 -0
  112. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +121 -0
  113. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  114. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -1
  115. package/dist-sdk/src/entities/view/from-tf.js +42 -7
  116. package/dist-sdk/src/entities/view/to-tf.d.ts +10 -1
  117. package/dist-sdk/src/entities/view/to-tf.js +30 -1
  118. package/dist-sdk/src/entities/view/types.js +2 -0
  119. package/dist-sdk/src/entities/widget/to-tf.js +2 -2
  120. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +25 -8
  121. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  122. package/dist-sdk/src/graph/index.d.ts +43 -0
  123. package/dist-sdk/src/graph/index.js +9 -0
  124. package/dist-sdk/src/graph/types.d.ts +78 -0
  125. package/package.json +2 -1
@@ -4,6 +4,7 @@ import { renderAutomationCatalogEntry } from "./catalog-render.js";
4
4
  import { preserveAuthoredAutomationPullMeta, printAutomationV2WithScriptFiles, SCRIPT_FILES_DIR } from "./deserializer/print-automation.js";
5
5
  import { automationFromTf, automationOwnedAddresses, UnsupportedMultiTriggerError } from "./from-tf.js";
6
6
  import { scriptFileRefs } from "./script-code.js";
7
+ import { TASK_OUTPUT_REFERENCE_NAMES } from "./task-output-labels.js";
7
8
  import { automationToTf } from "./to-tf.js";
8
9
  import { ALL_AUTOMATION_SUB_TYPES, AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE, } from "./types.js";
9
10
  function isConfigured(value) {
@@ -237,4 +238,59 @@ export const automationModule = {
237
238
  stubRef: automationStubRef,
238
239
  refFromAuthoring: automationRefFromAuthoring,
239
240
  },
241
+ roundtrip: {
242
+ referenceAliases: [],
243
+ managedLookupAttributes: [{
244
+ lookupType: AUTOMATION_RESOURCE_TYPE,
245
+ attribute: "parameter_ids",
246
+ ownerType: "elementum_on_demand_trigger",
247
+ ownerReference: "automation",
248
+ }],
249
+ taskOutputReferenceNames: TASK_OUTPUT_REFERENCE_NAMES,
250
+ recordFieldOutputKeys: [{ nameAttribute: "name", ownerAttribute: "object_id" }],
251
+ computedReferenceMaps: [{
252
+ resourceType: "elementum_on_demand_trigger",
253
+ attribute: "filter_refs",
254
+ listAttribute: "parameters",
255
+ nameAttribute: "name",
256
+ value: (name) => `trigger.${onDemandFilterRefName(name)}`,
257
+ }],
258
+ exportedAttributeLocals: [{
259
+ resourceType: "elementum_variable_task",
260
+ attribute: "variable_id",
261
+ localPrefix: "edk_variable_id_",
262
+ }],
263
+ },
240
264
  };
265
+ /** The provider's `normalizeOnDemandFilterRefName`, which computes `filter_refs` at plan time. */
266
+ export function onDemandFilterRefName(name) {
267
+ const runes = [...name];
268
+ const isWordRune = (rune) => /^[\p{L}\p{Nd}]$/u.test(rune);
269
+ // Go's unicode.ToUpper/ToLower map one rune to one rune; JS case mapping
270
+ // can expand (ß → SS, İ → i + U+0307). An expanded upper case keeps the
271
+ // rune; an expanded lower case keeps its first rune (İ → i).
272
+ const toUpper = (rune) => {
273
+ const upper = rune.toUpperCase();
274
+ return [...upper].length === 1 ? upper : rune;
275
+ };
276
+ const toLower = (rune) => [...rune.toLowerCase()][0] ?? rune;
277
+ if (runes.length === 0)
278
+ return "";
279
+ if (runes.every(isWordRune))
280
+ return toLower(runes[0]) + runes.slice(1).join("");
281
+ let normalized = "";
282
+ let nextIsUpper = false;
283
+ for (const rune of runes) {
284
+ if (!isWordRune(rune)) {
285
+ nextIsUpper = true;
286
+ }
287
+ else if (nextIsUpper) {
288
+ normalized += toUpper(rune);
289
+ nextIsUpper = false;
290
+ }
291
+ else {
292
+ normalized += toLower(rune);
293
+ }
294
+ }
295
+ return normalized;
296
+ }
@@ -0,0 +1,16 @@
1
+ import { type SystemFieldKey } from "../../core/system-fields.js";
2
+ /**
3
+ * System fields the provider cannot rename. Their ref names are always built
4
+ * from DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, whatever the app authored.
5
+ */
6
+ export declare const PROVIDER_FIXED_SYSTEM_FIELD_KEYS: ReadonlySet<SystemFieldKey>;
7
+ /** The refs-map key a build emits for a record field display name plus wire suffix. */
8
+ export declare function recordFieldWireRefName(fieldName: string, wireSuffix: string): string;
9
+ /**
10
+ * Whether decoding `wireName` as `<key><wireSuffix>` is lossless: a build of
11
+ * the typed path must emit a key the live refs map resolves identically.
12
+ * Older organizations name audit fields "Closed by" / "Created on"; decoding
13
+ * those to a typed key would rebuild as "Closed By" / "Created At", which is a
14
+ * different (missing) map key.
15
+ */
16
+ export declare function systemRefNameRoundTrips(key: SystemFieldKey, wireSuffix: string, wireName: string): boolean;
@@ -0,0 +1,44 @@
1
+ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES } from "../../core/system-fields.js";
2
+ /**
3
+ * System fields the provider cannot rename. Their ref names are always built
4
+ * from DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, whatever the app authored.
5
+ */
6
+ export const PROVIDER_FIXED_SYSTEM_FIELD_KEYS = new Set([
7
+ "stage",
8
+ "createdAt",
9
+ "createdBy",
10
+ "updatedAt",
11
+ "updatedBy",
12
+ "closedAt",
13
+ "closedBy",
14
+ ]);
15
+ /** Ref keys the provider publishes under both spellings (see withAuditEmailRefAliases). */
16
+ const PROVIDER_ALIASED_REF_NAMES = new Map([
17
+ ["Created by Email", "Created By Email"],
18
+ ["Created By Email", "Created by Email"],
19
+ ["Updated by Manager Email", "Updated By Manager Email"],
20
+ ["Updated By Manager Email", "Updated by Manager Email"],
21
+ ]);
22
+ /** The refs-map key a build emits for a record field display name plus wire suffix. */
23
+ export function recordFieldWireRefName(fieldName, wireSuffix) {
24
+ const refName = `${fieldName}${wireSuffix}`;
25
+ // Email audit refs have historically varied in the capitalization of "by"
26
+ // between organizations. The provider exposes both spellings as aliases,
27
+ // so author the established lowercase wire name consistently.
28
+ return /^(Created|Updated) By (?:Manager )?Email$/.test(refName)
29
+ ? refName.replace(/ By(?= (?:Manager )?Email$)/, " by")
30
+ : refName;
31
+ }
32
+ /**
33
+ * Whether decoding `wireName` as `<key><wireSuffix>` is lossless: a build of
34
+ * the typed path must emit a key the live refs map resolves identically.
35
+ * Older organizations name audit fields "Closed by" / "Created on"; decoding
36
+ * those to a typed key would rebuild as "Closed By" / "Created At", which is a
37
+ * different (missing) map key.
38
+ */
39
+ export function systemRefNameRoundTrips(key, wireSuffix, wireName) {
40
+ if (!PROVIDER_FIXED_SYSTEM_FIELD_KEYS.has(key))
41
+ return true;
42
+ const emitted = recordFieldWireRefName(DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[key], wireSuffix);
43
+ return emitted === wireName || PROVIDER_ALIASED_REF_NAMES.get(emitted) === wireName;
44
+ }
@@ -0,0 +1,15 @@
1
+ /** userSearch authoring output → provider refs-map key (as exported from live user-search tasks). */
2
+ export declare const USER_SEARCH_REF_WIRE_NAMES: Readonly<Record<string, string>>;
3
+ /**
4
+ * Task-own outputs whose WorkflowTaskReference name (what an exported
5
+ * envelope and a calculation mustache carry) differs from the provider
6
+ * refs-map key, per resource type. Captured live with `ei refs --from-remote`
7
+ * and matching mobius' `shared.json` label tables.
8
+ */
9
+ export declare const TASK_OUTPUT_REFERENCE_NAMES: Readonly<Record<string, Readonly<Record<string, string>>>>;
10
+ /**
11
+ * A record-bearing task's whole-record output (ASPECT_RECORD). The bare
12
+ * `.record` accessor otherwise builds the ASPECT_RECORD_ID `Record` key a
13
+ * `record_reference` needs; a field-mapped input needs the record itself.
14
+ */
15
+ export declare const WHOLE_RECORD_REF_WIRE_NAMES: Readonly<Record<string, string>>;
@@ -0,0 +1,38 @@
1
+ /** userSearch authoring output → provider refs-map key (as exported from live user-search tasks). */
2
+ export const USER_SEARCH_REF_WIRE_NAMES = {
3
+ "user.id": "User's Id",
4
+ "user.name": "User's Name",
5
+ "user.email": "User's Email",
6
+ "user.managerName": "Manager Name",
7
+ "user.managerEmail": "Manager Email",
8
+ users: "All found users",
9
+ };
10
+ /**
11
+ * Task-own outputs whose WorkflowTaskReference name (what an exported
12
+ * envelope and a calculation mustache carry) differs from the provider
13
+ * refs-map key, per resource type. Captured live with `ei refs --from-remote`
14
+ * and matching mobius' `shared.json` label tables.
15
+ */
16
+ export const TASK_OUTPUT_REFERENCE_NAMES = {
17
+ elementum_record_search_task: {
18
+ "Records Size": "count",
19
+ "First found record id": "recordId",
20
+ },
21
+ elementum_user_group_search_task: {
22
+ "Groups Size": "count",
23
+ "First found group": "group",
24
+ ID: "group.id",
25
+ Name: "group.name",
26
+ "All found groups": "groups",
27
+ },
28
+ };
29
+ /**
30
+ * A record-bearing task's whole-record output (ASPECT_RECORD). The bare
31
+ * `.record` accessor otherwise builds the ASPECT_RECORD_ID `Record` key a
32
+ * `record_reference` needs; a field-mapped input needs the record itself.
33
+ */
34
+ export const WHOLE_RECORD_REF_WIRE_NAMES = {
35
+ recordSearch: "First found record",
36
+ createRecord: "Created record",
37
+ updateField: "Updated record",
38
+ };
@@ -603,8 +603,35 @@ export interface UserSearchOptions {
603
603
  /** Pre-built wire filter over user attributes. */
604
604
  readonly filter: Filter;
605
605
  }
606
- export declare function userSearch(opts: UserSearchOptions): ActionDef<RecordSearchOutput>;
607
- export declare function userGroupSearch(opts: UserSearchOptions): ActionDef<RecordSearchOutput>;
606
+ /** The first user a user search found. */
607
+ export interface FoundUserShape {
608
+ readonly id: string;
609
+ readonly name: string;
610
+ readonly email: string;
611
+ readonly managerName: string;
612
+ readonly managerEmail: string;
613
+ }
614
+ /** Outputs of a user search (the platform's "User's Id", "Manager Email", "All found users", …). */
615
+ export interface UserSearchOutput {
616
+ readonly user: FoundUserShape;
617
+ readonly users: readonly unknown[];
618
+ }
619
+ export declare function userSearch(opts: UserSearchOptions): ActionDef<UserSearchOutput>;
620
+ export interface UserGroupShape {
621
+ readonly id: string;
622
+ readonly name: string;
623
+ }
624
+ /** Platform output names of a user-group search (`task.<id>.count`, `.group.id`, `.groups`). */
625
+ export interface UserGroupSearchOutput {
626
+ readonly count: number;
627
+ readonly group: UserGroupShape;
628
+ readonly groups: readonly UserGroupShape[];
629
+ }
630
+ export interface UserGroupSearchOptions {
631
+ /** Pre-built wire filter over user-group attributes (`catalog.userGroups.fields`). */
632
+ readonly filter: Filter;
633
+ }
634
+ export declare function userGroupSearch(opts: UserGroupSearchOptions): ActionDef<UserGroupSearchOutput>;
608
635
  export interface SaveAttachmentOptions {
609
636
  readonly record: ValueOrRef<unknown>;
610
637
  readonly file: ValueOrRef<unknown>;
@@ -6,7 +6,7 @@ import { workspaceAspectKey } from "../../engine/build/context.js";
6
6
  import { SEARCH_TABLE_RESOURCE_TYPES } from "../search-table/types.js";
7
7
  import { fieldRefToTfValue } from "../field/to-tf.js";
8
8
  import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
9
- import { resolveForeignRef } from "../shared/foreign-ref.js";
9
+ import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
10
10
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
11
11
  import { referenceValueTypeForField } from "../shared/filters/index.js";
12
12
  import { API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES } from "./output-key-wire-name.js";
@@ -16,7 +16,9 @@ import { FILE_READER_SUB_TYPE_BY_RESOURCE, FILE_READER_SUB_TYPE_BY_TYPE_KEY } fr
16
16
  import { UNRESOLVED_FIELD_MARKER } from "../shared/ref.js";
17
17
  import { TABLE_RESOURCE_TYPE } from "../table/module.js";
18
18
  import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE } from "./types.js";
19
+ import { TASK_OUTPUT_REFERENCE_NAMES, USER_SEARCH_REF_WIRE_NAMES } from "./task-output-labels.js";
19
20
  import { onDemandTriggerRefKey } from "./value-ref-tf.js";
21
+ import { PROVIDER_FIXED_SYSTEM_FIELD_KEYS, recordFieldWireRefName } from "./system-ref-name.js";
20
22
  import { taskTfLabel } from "./task-label.js";
21
23
  import { isOnDemandRecordType } from "../shared/types/field-types.js";
22
24
  function scopedLabel(appTfLabel, label) {
@@ -103,6 +105,7 @@ const TASK_RESOURCES = {
103
105
  aiTransform: "elementum_ai_transform_task",
104
106
  saveAttachment: "elementum_save_attachment_task",
105
107
  userSearch: "elementum_user_search_task",
108
+ userGroupSearch: "elementum_user_group_search_task",
106
109
  calculation: "elementum_calculation_task",
107
110
  executeScript: "elementum_execute_script_task",
108
111
  documentModel: "elementum_file_reader_task",
@@ -115,6 +118,7 @@ const TASK_RESOURCES = {
115
118
  // on `taskRefs` entries and the dedicated emission branch in `emitTasks`.
116
119
  unimplementedTask: "elementum_unmanaged_task_reference",
117
120
  };
121
+ const USER_SEARCH_PATH_BY_WIRE_NAME = new Map(Object.entries(USER_SEARCH_REF_WIRE_NAMES).map(([path, wire]) => [wire, path]));
118
122
  const CONFIG_ATTRS = {
119
123
  aspectId: "object_id",
120
124
  relatedAspectId: "object_id",
@@ -317,15 +321,8 @@ function foreignRootLookup(kind, identity) {
317
321
  lookupValue: identity.name,
318
322
  };
319
323
  }
320
- /**
321
- * Validates and derives the shared naming for a cross-app/element/task field
322
- * token — the `data.elementum_field` label {@link crossAppFieldToTf} emits,
323
- * and the matching `<fieldLabel>_options_by_label` local a foreign PICKLIST
324
- * field's option-label lookup (in {@link picklistFilterValueToTf}) resolves
325
- * against. Kept as one function so the two call sites can never drift apart
326
- * on how the label is built.
327
- */
328
- function foreignFieldNaming(value) {
324
+ /** Validates a cross-app/element/task field token's owner provenance. */
325
+ function foreignFieldProvenance(value) {
329
326
  const parent = value.parent;
330
327
  if (parent === undefined)
331
328
  throw new EntityTfError(`field ref "${value.refName}" has no parent`);
@@ -344,14 +341,7 @@ function foreignFieldNaming(value) {
344
341
  }
345
342
  const fieldName = value.name ?? value.refName;
346
343
  const ownerKind = value.parentKind === "task" ? "task" : value.parentKind === "element" ? "element" : "app";
347
- const resolved = foreignRootLookup(ownerKind, {
348
- name: value.parentName,
349
- namespace: value.parentNamespace,
350
- });
351
- const ownerType = resolved.resourceType;
352
- const ownerLabel = resolved.tfLabel;
353
- const fieldLabel = `${value.parentKind}_${ownerLabel}_${tsLabelToTfLabel(value.refName)}`;
354
- return { fieldName, ownerType, ownerLabel, ownerParentName: value.parentName, fieldLabel };
344
+ return { fieldName, ownerKind, ownerParentName: value.parentName };
355
345
  }
356
346
  /**
357
347
  * Registers the `<fieldLabel>_options_by_label` local — a for-expression
@@ -393,17 +383,29 @@ function crossAppFieldToTf(value, ctx, dataBlocks) {
393
383
  return fieldValue;
394
384
  }
395
385
  }
396
- const { fieldName, fieldLabel } = foreignFieldNaming(value);
397
- const ownerKind = value.parentKind === "task" ? "task" : value.parentKind === "element" ? "element" : "app";
386
+ return expr.dataAttr("elementum_field", registerForeignFieldLookup(value, ctx, dataBlocks), ["id"]);
387
+ }
388
+ /**
389
+ * Registers the `data.elementum_field` lookup (and its owner root lookup) for
390
+ * a genuinely foreign field, plus the matching `<label>_options_by_label`
391
+ * local, and returns the lookup label. The one place both a foreign field's
392
+ * id ({@link crossAppFieldToTf}) and its option-label local
393
+ * ({@link picklistFilterValueToTf}) get their label, so the two never drift.
394
+ */
395
+ function registerForeignFieldLookup(value, ctx, dataBlocks) {
396
+ const { fieldName, ownerKind, ownerParentName } = foreignFieldProvenance(value);
397
+ let fieldLabel;
398
398
  if (ctx.orgRefs !== undefined) {
399
- const owner = resolveForeignRef(ownerKind, { name: value.parentName, namespace: value.parentNamespace }, ctx.orgRefs, ctx.diagnostics, `automation field "${value.refName}" owner`);
399
+ const owner = resolveForeignRef(ownerKind, { name: ownerParentName, namespace: value.parentNamespace }, ctx.orgRefs, ctx.diagnostics, `automation field "${value.refName}" owner`);
400
+ fieldLabel = foreignFieldDataLabel(ownerKind, owner.tfLabel, fieldName);
400
401
  ctx.orgRefs.foreignField("elementum_field", fieldLabel, owner.value, fieldName);
401
402
  }
402
403
  else {
403
404
  const resolved = foreignRootLookup(ownerKind, {
404
- name: value.parentName,
405
+ name: ownerParentName,
405
406
  namespace: value.parentNamespace,
406
407
  });
408
+ fieldLabel = foreignFieldDataLabel(ownerKind, resolved.tfLabel, fieldName);
407
409
  const objectId = expr.dataAttr(resolved.resourceType, resolved.tfLabel, ["id"]);
408
410
  dataBlocks.set(`${resolved.resourceType}.${resolved.tfLabel}`, {
409
411
  kind: "data",
@@ -419,7 +421,7 @@ function crossAppFieldToTf(value, ctx, dataBlocks) {
419
421
  });
420
422
  }
421
423
  registerForeignOptionsByLabelLocal(fieldLabel, ctx);
422
- return expr.dataAttr("elementum_field", fieldLabel, ["id"]);
424
+ return fieldLabel;
423
425
  }
424
426
  /**
425
427
  * Resolve an automation token as a managed definition (same stream root or a
@@ -549,6 +551,7 @@ function tokenToTf(value, ctx, dataBlocks) {
549
551
  return expr.dataAttr("elementum_user", label, ["id"]);
550
552
  }
551
553
  case "userField":
554
+ case "userGroupField":
552
555
  return value.refName;
553
556
  case "task": {
554
557
  const sibling = ctx.workspaceAspects?.get(workspaceAspectKey("task", value.refName));
@@ -1020,31 +1023,18 @@ function calculationTaskMustache(taskRefKey, name, refs) {
1020
1023
  `"}}`,
1021
1024
  ];
1022
1025
  }
1023
- /**
1024
- * Task-own outputs whose calc-engine reference name differs from the
1025
- * refs-map key. Keys are the display labels the refs map uses (and that
1026
- * `build.ts`'s `rewriteForwardTaskRefName` already rewrote authoring names
1027
- * into); values are the underlying reference names — captured live with
1028
- * `ei refs --from-remote` against a real record-search task, and matching
1029
- * mobius' `shared.json` `aspect_records_search` label table.
1030
- */
1031
- const CALCULATION_TASK_OUTPUT_REF_NAME = {
1032
- elementum_record_search_task: {
1033
- "Records Size": "count",
1034
- "First found record id": "recordId",
1035
- },
1036
- };
1037
1026
  function calculationTaskRefName(targetType, name, taskRefKey, refs) {
1038
1027
  const segments = name.split(".");
1039
1028
  if (segments[0] === "record" && segments.length >= 2) {
1040
1029
  const suffix = segments.slice(2).join(".");
1030
+ const fieldKey = segments[1];
1041
1031
  return [
1042
1032
  "record.",
1043
- calculationRecordFieldId(segments[1], calculationFieldScope(taskRefKey, refs)),
1033
+ calculationRawFieldId(fieldKey) ?? calculationRecordFieldId(fieldKey, calculationFieldScope(taskRefKey, refs)),
1044
1034
  suffix.length > 0 ? `.${suffix}` : "",
1045
1035
  ];
1046
1036
  }
1047
- const refName = CALCULATION_TASK_OUTPUT_REF_NAME[targetType]?.[name] ?? name;
1037
+ const refName = TASK_OUTPUT_REFERENCE_NAMES[targetType]?.[name] ?? name;
1048
1038
  if (refName.includes('"')) {
1049
1039
  throw new EntityTfError(`calculation task output name "${refName}" contains a double quote`);
1050
1040
  }
@@ -1070,6 +1060,33 @@ function calculationFieldScope(taskRefKey, refs) {
1070
1060
  ?? refs.owner.workspaceAspects?.get(workspaceAspectKey("element", taskApp));
1071
1061
  return { appRefName: taskApp, appTfLabel: aspect?.tfLabel ?? refs.owner.appTfLabel, fieldAddresses };
1072
1062
  }
1063
+ const FOUND_RECORD_TASK_TYPES = new Set([
1064
+ "elementum_record_search_task",
1065
+ "elementum_create_record_task",
1066
+ "elementum_find_related_records_task",
1067
+ ]);
1068
+ /**
1069
+ * A short-form `task.<id>.<name>` value reference addresses a found record's
1070
+ * field by its platform reference name `record.<fieldId>` (as ei exports it),
1071
+ * not by the refs-map display label. Undefined when the field's id cannot be
1072
+ * resolved in this build, which keeps the display-label form.
1073
+ */
1074
+ function foundRecordFieldReferenceName(targetType, name, taskRefKey, refs) {
1075
+ const segments = name.split(".");
1076
+ const addressesRecordFields = FOUND_RECORD_TASK_TYPES.has(targetType) || targetType === TASK_RESOURCES.updateField;
1077
+ if (!addressesRecordFields || segments[0] !== "record" || segments.length < 2)
1078
+ return undefined;
1079
+ if (segments[1] === "recordId")
1080
+ return undefined;
1081
+ try {
1082
+ return calculationTaskRefName(targetType, name, taskRefKey, refs).filter((part) => part !== "");
1083
+ }
1084
+ catch (error) {
1085
+ if (error instanceof EntityTfError)
1086
+ return undefined;
1087
+ throw error;
1088
+ }
1089
+ }
1073
1090
  function calculationTriggerMustache(name, refs) {
1074
1091
  const parts = name.split(".");
1075
1092
  if (parts[0] !== "record" || parts.length < 2) {
@@ -1084,11 +1101,16 @@ function calculationTriggerMustache(name, refs) {
1084
1101
  `${suffixPart}"}}`,
1085
1102
  ];
1086
1103
  }
1087
- function calculationRecordFieldId(fieldKey, scope) {
1104
+ /** A field id that is already on the wire (pulled raw UUID / unresolved marker) needs no aspect to resolve. */
1105
+ function calculationRawFieldId(fieldKey) {
1088
1106
  if (fieldKey.startsWith(UNRESOLVED_FIELD_MARKER))
1089
1107
  return fieldKey.slice(UNRESOLVED_FIELD_MARKER.length);
1090
- if (isUuid(fieldKey))
1091
- return fieldKey;
1108
+ return isUuid(fieldKey) ? fieldKey : undefined;
1109
+ }
1110
+ function calculationRecordFieldId(fieldKey, scope) {
1111
+ const raw = calculationRawFieldId(fieldKey);
1112
+ if (raw !== undefined)
1113
+ return raw;
1092
1114
  const address = scope.fieldAddresses.get(fieldKey);
1093
1115
  if (address !== undefined)
1094
1116
  return addressExpr(address, ["id"]);
@@ -1167,15 +1189,6 @@ const FIELD_REF_SUFFIX_TO_WIRE = {
1167
1189
  "employee.manager.email": " Manager Email",
1168
1190
  "employee.manager.name": " Manager Name",
1169
1191
  };
1170
- const PROVIDER_FIXED_SYSTEM_FIELD_KEYS = new Set([
1171
- "stage",
1172
- "createdAt",
1173
- "createdBy",
1174
- "updatedAt",
1175
- "updatedBy",
1176
- "closedAt",
1177
- "closedBy",
1178
- ]);
1179
1192
  function wireRefName(name, ctx) {
1180
1193
  const known = TS_TRIGGER_REF_TO_WIRE[name];
1181
1194
  if (known !== undefined)
@@ -1222,13 +1235,7 @@ function wireRefName(name, ctx) {
1222
1235
  if (wireSuffix === undefined) {
1223
1236
  throw new EntityTfError(`automation reference "${name}" has unsupported record-field path "${suffix}"`);
1224
1237
  }
1225
- // Email audit refs have historically varied in the capitalization of
1226
- // "by" between organizations. The provider exposes both spellings as
1227
- // aliases, so author the established lowercase wire name consistently.
1228
- const refName = `${fieldName}${wireSuffix}`;
1229
- return /^(Created|Updated) By (?:Manager )?Email$/.test(refName)
1230
- ? refName.replace(/ By(?= (?:Manager )?Email$)/, " by")
1231
- : refName;
1238
+ return recordFieldWireRefName(fieldName, wireSuffix);
1232
1239
  }
1233
1240
  // A webhook trigger's body/headers refs (ctx.trigger.body["X"]) can only
1234
1241
  // type-check against DeepRefs<WebhookTriggerOutput>, so parts[0] being
@@ -1269,8 +1276,14 @@ const RECORD_COLLECTION_TASK_WIRE_TYPES = new Set([
1269
1276
  const TS_FOR_EACH_GENERIC_SEGMENT_TO_WIRE = {
1270
1277
  iteration: "Iteration",
1271
1278
  };
1272
- function forEachCompactFilterName(name) {
1273
- return name === "recordId" ? "item" : name;
1279
+ function forEachCompactFilterName(name, isRecordCollection) {
1280
+ if (name === "recordId")
1281
+ return "item";
1282
+ // A plain-list loop's whole item is ForEachReference name "" on the
1283
+ // platform; provider Read renders it as `for_each.<id>.`.
1284
+ if (name === "item" && !isRecordCollection)
1285
+ return "";
1286
+ return name;
1274
1287
  }
1275
1288
  function forEachWireRefName(name, ctx, isRecordCollection) {
1276
1289
  // A recordSearch collection's whole item and branded record identity both
@@ -1756,6 +1769,10 @@ function unwrapDefault(value) {
1756
1769
  const values = Object.values(value);
1757
1770
  return values.length === 1 ? values[0] : value;
1758
1771
  }
1772
+ /** `options` is filled only from picklistValues, so a related-record dropdown is a PICKLIST with none. */
1773
+ function isOptionBearingPicklist(metadata) {
1774
+ return metadata?.fieldType === "PICKLIST" && (metadata.options?.length ?? 0) > 0;
1775
+ }
1759
1776
  function filterReferenceToTf(value, refs, role = "value", realType, operator) {
1760
1777
  // Raw pass-through for a filter left side the pull-time deserializer
1761
1778
  // couldn't decode to a typed ref (filter.ts's leftDescriptor, matching the
@@ -1781,17 +1798,9 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
1781
1798
  const address = refs.owner.fieldAddresses.get(fieldKey);
1782
1799
  const suffix = parts.slice(2).join(".");
1783
1800
  let wireSuffix = suffix === "recordId" ? "10000001-2000-4000-a000-800000000000" : suffix;
1784
- // A bare reference to a PICKLIST field (STATUS/STAGE included —
1785
- // `serializeSystemFields` wire-wraps both as a picklist too) has no
1786
- // valid suffix-less wire form — confirmed live via the platform's
1787
- // own switch-case editor, which always sends an explicit `.id`
1788
- // (compare by the chosen option's real id) or `.label` (compare by
1789
- // display text, unvalidated) and never a bare `record.<fieldId>`.
1790
- // Comparisons stay ambiguous (eq/in/…). Null-checks are equivalent
1791
- // for `.id` and `.label` when no option is selected, so
1792
- // `isNull`/`isNotNull` on a bare Dropdown emit the platform editor's
1793
- // `.id` + uuid shape — the Accept `isNotNull(record.dropdown)` form.
1794
- if (suffix.length === 0 && refs.owner.fieldMetadata.get(fieldKey)?.fieldType === "PICKLIST") {
1801
+ // An option-bearing picklist has no bare wire form. The platform editor
1802
+ // sends `.id` or `.label`, and a null-check emits `.id`.
1803
+ if (suffix.length === 0 && isOptionBearingPicklist(refs.owner.fieldMetadata.get(fieldKey))) {
1795
1804
  if (operator === "is_null") {
1796
1805
  wireSuffix = "id";
1797
1806
  }
@@ -1919,12 +1928,45 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
1919
1928
  },
1920
1929
  });
1921
1930
  }
1931
+ const ambiguousRecordField = recordRefKeyIsAmbiguous(value.name, wireName, value.taskRefKey, refs)
1932
+ ? foundRecordFieldReferenceName(task.type, value.name, value.taskRefKey, refs)
1933
+ : undefined;
1934
+ if (ambiguousRecordField !== undefined) {
1935
+ return expr.jsonencode({
1936
+ fieldType: (realType ?? "TEXT").toUpperCase(),
1937
+ multiple: false,
1938
+ taskReference: {
1939
+ name: expr.template(ambiguousRecordField),
1940
+ taskId: expr.resourceAttr(task.type, task.label, ["id"]),
1941
+ },
1942
+ });
1943
+ }
1944
+ // A field id the workspace cannot resolve (a foreign element's field)
1945
+ // has no display label to key `refs` by; only the envelope names it.
1946
+ const unresolvedFieldId = wireName.split(".")[1];
1947
+ if (wireName.startsWith("record.") && unresolvedFieldId !== undefined && isUuid(unresolvedFieldId)) {
1948
+ return expr.jsonencode({
1949
+ fieldType: (realType ?? "TEXT").toUpperCase(),
1950
+ multiple: false,
1951
+ taskReference: {
1952
+ name: wireName,
1953
+ taskId: expr.resourceAttr(task.type, task.label, ["id"]),
1954
+ },
1955
+ });
1956
+ }
1922
1957
  return expr.resourceAttr(task.type, task.label, ["refs", { index: wireName }]);
1923
1958
  }
1959
+ const recordFieldName = foundRecordFieldReferenceName(task.type, value.name, value.taskRefKey, refs);
1960
+ // The short form addresses user-search outputs by path; only `.refs`
1961
+ // is keyed by their display labels.
1962
+ const shortName = task.type === TASK_RESOURCES.userSearch
1963
+ ? USER_SEARCH_PATH_BY_WIRE_NAME.get(wireName) ?? wireName
1964
+ : wireName;
1924
1965
  return expr.template([
1925
1966
  "task.",
1926
1967
  expr.resourceAttr(task.type, task.label, ["id"]),
1927
- `.${wireName}`,
1968
+ ".",
1969
+ ...(recordFieldName ?? [shortName]),
1928
1970
  ]);
1929
1971
  }
1930
1972
  case "FOR_EACH": {
@@ -1936,7 +1978,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
1936
1978
  return expr.template([
1937
1979
  "for_each.",
1938
1980
  expr.resourceAttr(task.type, task.label, ["id"]),
1939
- `.${forEachCompactFilterName(value.name)}`,
1981
+ `.${forEachCompactFilterName(value.name, refs.recordItemForEachRefKeys.has(value.forEachTaskRefKey))}`,
1940
1982
  ]);
1941
1983
  }
1942
1984
  case "VALUE":
@@ -2019,15 +2061,10 @@ function picklistFilterValueToTf(value, field, refs) {
2019
2061
  if (field.parent !== undefined && (field.parent !== refs.owner.appRefName || field.parentKind === "element")) {
2020
2062
  // A foreign field's options-by-label local is sourced from
2021
2063
  // `data.elementum_field.<label>.options` (issue #353) rather than an
2022
- // owned resource's `options` attribute — `crossAppFieldToTf` registers
2023
- // both the data block and the matching local; reuse the SAME naming
2024
- // (`foreignFieldNaming`) so this reference always lines up with
2025
- // whatever label that registration used, then make sure the data block
2026
- // (and local) actually gets registered even when nothing else in this
2027
- // payload resolves the field's id.
2028
- const naming = foreignFieldNaming(field);
2029
- crossAppFieldToTf(field, refs.owner, refs.dataBlocks);
2030
- return expr.local(naming.fieldLabel + "_options_by_label", [{ index: value }]);
2064
+ // owned resource's `options` attribute. Registering here also covers a
2065
+ // payload where nothing else resolves the field's id.
2066
+ const fieldLabel = registerForeignFieldLookup(field, refs.owner, refs.dataBlocks);
2067
+ return expr.local(fieldLabel + "_options_by_label", [{ index: value }]);
2031
2068
  }
2032
2069
  const localName = field.tags?.includes("STATUS")
2033
2070
  ? `${refs.owner.appTfLabel}_status_options_by_label`
@@ -2047,9 +2084,14 @@ function triggerRecordFieldPath(reference) {
2047
2084
  function fieldFromFilterLeftValue(value, refs) {
2048
2085
  if (isObject(value) && value.type === "FIELD")
2049
2086
  return token(value.value ?? value.field);
2050
- if (!isObject(value) || !isObject(value.value) || value.value.type?.toString().toUpperCase() !== "TRIGGER") {
2087
+ if (!isObject(value) || !isObject(value.value))
2088
+ return undefined;
2089
+ const referenceType = value.value.type?.toString().toUpperCase();
2090
+ const ownAppTask = referenceType === "TASK" &&
2091
+ typeof value.value.taskRefKey === "string" &&
2092
+ taskSearchesOwnerApp(value.value.taskRefKey, refs);
2093
+ if (referenceType !== "TRIGGER" && !ownAppTask)
2051
2094
  return undefined;
2052
- }
2053
2095
  const parsed = triggerRecordFieldPath(value.value);
2054
2096
  if (parsed === undefined)
2055
2097
  return undefined;
@@ -2067,16 +2109,48 @@ function fieldFromFilterLeftValue(value, refs) {
2067
2109
  return undefined;
2068
2110
  return { __kind: "field", refName, ...metadata };
2069
2111
  }
2112
+ function taskSearchesOwnerApp(taskRefKey, refs) {
2113
+ const task = refs.tasks.get(taskRefKey);
2114
+ if (task === undefined || !FOUND_RECORD_TASK_TYPES.has(task.type))
2115
+ return false;
2116
+ const taskApp = refs.recordFieldContext?.taskAppRefNameByRefKey?.[taskRefKey];
2117
+ return taskApp === undefined || taskApp === refs.owner.appRefName;
2118
+ }
2119
+ /**
2120
+ * `refs` is keyed by display label, so a drilled-down record field (the
2121
+ * Stage field's `.id` is "Stage ID") can share its key with another field's
2122
+ * own label (a custom "Stage ID" text field) on the same app.
2123
+ */
2124
+ function recordRefKeyIsAmbiguous(name, wireName, taskRefKey, refs) {
2125
+ const segments = name.split(".");
2126
+ if (segments[0] !== "record" || segments.length < 3)
2127
+ return false;
2128
+ const taskApp = refs.recordFieldContext?.taskAppRefNameByRefKey?.[taskRefKey];
2129
+ const fieldNames = taskApp === undefined || taskApp === refs.owner.appRefName
2130
+ ? refs.owner.fieldNames
2131
+ : fieldNamesForAppRefName(refs.fieldNamesByAppRefName, taskApp);
2132
+ for (const [fieldKey, fieldName] of fieldNames ?? []) {
2133
+ if (fieldKey !== segments[1] && fieldName === wireName)
2134
+ return true;
2135
+ }
2136
+ return false;
2137
+ }
2070
2138
  function filterToTf(value, refs) {
2071
2139
  return serializeFilterToTf(value, {
2072
2140
  field: (field) => valueToTf(field, refs),
2073
2141
  fieldFromLeftValue: (left) => fieldFromFilterLeftValue(left, refs),
2074
2142
  reference: (reference, role, realType, operator) => filterReferenceToTf(reference, refs, role ?? "value", realType, operator),
2075
2143
  referenceRealType: (reference, _role, authored) => {
2144
+ if (!isObject(reference) || reference.type?.toString().toUpperCase() !== "TRIGGER")
2145
+ return authored;
2076
2146
  const parsed = triggerRecordFieldPath(reference);
2077
2147
  if (parsed === undefined)
2078
2148
  return authored;
2079
2149
  const metadata = refs.owner.fieldMetadata.get(parsed.fieldKey);
2150
+ // A suffix-less option picklist is a UUID. A bare dynamic dropdown is stored as text.
2151
+ if (parsed.suffix === "" && metadata?.fieldType === "PICKLIST" && !isOptionBearingPicklist(metadata)) {
2152
+ return authored;
2153
+ }
2080
2154
  const inferred = referenceValueTypeForField(metadata?.fieldType, parsed.suffix);
2081
2155
  if (inferred === undefined)
2082
2156
  return authored;
@@ -76,6 +76,7 @@ export const TASK_SUB_TYPES = [
76
76
  { typeKey: "addWatcher", resourceType: "elementum_add_watcher_task", implemented: true },
77
77
  { typeKey: "saveAttachment", resourceType: "elementum_save_attachment_task", implemented: true },
78
78
  { typeKey: "userSearch", resourceType: "elementum_user_search_task", implemented: true },
79
+ { typeKey: "userGroupSearch", resourceType: "elementum_user_group_search_task", implemented: true },
79
80
  { typeKey: "aspectRecordFieldLocking", resourceType: "elementum_aspect_record_field_locking_task", implemented: true },
80
81
  { typeKey: "initiateCall", resourceType: "elementum_initiate_call_task", implemented: true },
81
82
  // Operators (branching) — later phases: