@elementumai/edk 0.10.3 → 0.11.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.
Files changed (155) hide show
  1. package/README.md +11 -7
  2. package/dist-sdk/src/catalog/token.js +2 -1
  3. package/dist-sdk/src/core/wire/ref-serializer.js +26 -1
  4. package/dist-sdk/src/engine/build/context.d.ts +4 -0
  5. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  6. package/dist-sdk/src/engine/coverage-gaps.js +3 -0
  7. package/dist-sdk/src/engine/ei/json-stream-reader.d.ts +43 -0
  8. package/dist-sdk/src/engine/ei/json-stream-reader.js +234 -0
  9. package/dist-sdk/src/engine/ei/run.d.ts +22 -0
  10. package/dist-sdk/src/engine/ei/run.js +99 -18
  11. package/dist-sdk/src/engine/ei/saved-plan.d.ts +16 -0
  12. package/dist-sdk/src/engine/ei/saved-plan.js +19 -0
  13. package/dist-sdk/src/engine/ei/state.d.ts +1 -1
  14. package/dist-sdk/src/engine/ei/state.js +17 -4
  15. package/dist-sdk/src/engine/progress.d.ts +3 -1
  16. package/dist-sdk/src/engine/progress.js +7 -3
  17. package/dist-sdk/src/engine/pull/authored-address.d.ts +15 -1
  18. package/dist-sdk/src/engine/pull/authored-address.js +180 -29
  19. package/dist-sdk/src/engine/pull/context.d.ts +52 -7
  20. package/dist-sdk/src/engine/pull/context.js +7 -4
  21. package/dist-sdk/src/engine/tf/index.d.ts +3 -2
  22. package/dist-sdk/src/engine/tf/index.js +3 -2
  23. package/dist-sdk/src/engine/tf/labels.d.ts +22 -0
  24. package/dist-sdk/src/engine/tf/labels.js +50 -0
  25. package/dist-sdk/src/engine/tf/model.d.ts +2 -0
  26. package/dist-sdk/src/engine/tf/model.js +26 -0
  27. package/dist-sdk/src/engine/tf/scan.d.ts +22 -0
  28. package/dist-sdk/src/engine/tf/scan.js +123 -0
  29. package/dist-sdk/src/engine/validation.d.ts +2 -0
  30. package/dist-sdk/src/engine/workspace/loader.d.ts +8 -0
  31. package/dist-sdk/src/engine/workspace/loader.js +20 -0
  32. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +17 -0
  33. package/dist-sdk/src/entities/access-policy/from-tf.js +52 -24
  34. package/dist-sdk/src/entities/access-policy/member-list.d.ts +32 -0
  35. package/dist-sdk/src/entities/access-policy/member-list.js +57 -0
  36. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  37. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +4 -3
  38. package/dist-sdk/src/entities/access-policy/to-tf.js +21 -12
  39. package/dist-sdk/src/entities/agent/build.js +7 -5
  40. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -0
  41. package/dist-sdk/src/entities/agent/from-tf.js +13 -3
  42. package/dist-sdk/src/entities/agent/to-tf.d.ts +13 -11
  43. package/dist-sdk/src/entities/agent/to-tf.js +28 -17
  44. package/dist-sdk/src/entities/agent/tools.d.ts +8 -0
  45. package/dist-sdk/src/entities/agent/tools.js +6 -2
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -2
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +65 -3
  50. package/dist-sdk/src/entities/agent-tool/types.d.ts +12 -8
  51. package/dist-sdk/src/entities/agent-tool/types.js +13 -9
  52. package/dist-sdk/src/entities/app/build.d.ts +11 -0
  53. package/dist-sdk/src/entities/app/build.js +1 -0
  54. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +11 -7
  55. package/dist-sdk/src/entities/app/from-tf.js +19 -9
  56. package/dist-sdk/src/entities/app/to-tf.js +6 -4
  57. package/dist-sdk/src/entities/automation/build.d.ts +2 -7
  58. package/dist-sdk/src/entities/automation/build.js +55 -16
  59. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +7 -4
  60. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +7 -11
  61. package/dist-sdk/src/entities/automation/from-tf.d.ts +23 -1
  62. package/dist-sdk/src/entities/automation/from-tf.js +456 -34
  63. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  64. package/dist-sdk/src/entities/automation/module.d.ts +22 -2
  65. package/dist-sdk/src/entities/automation/module.js +273 -58
  66. package/dist-sdk/src/entities/automation/output-field-types.d.ts +8 -0
  67. package/dist-sdk/src/entities/automation/output-field-types.js +20 -0
  68. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +24 -2
  69. package/dist-sdk/src/entities/automation/output-key-wire-name.js +72 -3
  70. package/dist-sdk/src/entities/automation/run-target.d.ts +59 -0
  71. package/dist-sdk/src/entities/automation/run-target.js +99 -0
  72. package/dist-sdk/src/entities/automation/script-code.d.ts +9 -0
  73. package/dist-sdk/src/entities/automation/script-code.js +24 -3
  74. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +16 -0
  75. package/dist-sdk/src/entities/automation/task-output-labels.js +49 -0
  76. package/dist-sdk/src/entities/automation/tasks.d.ts +20 -8
  77. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -3
  78. package/dist-sdk/src/entities/automation/to-tf.js +171 -58
  79. package/dist-sdk/src/entities/automation/triggers.d.ts +22 -3
  80. package/dist-sdk/src/entities/automation/triggers.js +40 -0
  81. package/dist-sdk/src/entities/automation/types.d.ts +21 -0
  82. package/dist-sdk/src/entities/automation/types.js +26 -0
  83. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +11 -1
  84. package/dist-sdk/src/entities/dashboard/from-tf.js +57 -7
  85. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  86. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +7 -2
  87. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  88. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +65 -19
  89. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +4 -2
  90. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +341 -32
  91. package/dist-sdk/src/entities/element/build.d.ts +10 -0
  92. package/dist-sdk/src/entities/element/build.js +1 -0
  93. package/dist-sdk/src/entities/element/from-tf.js +16 -9
  94. package/dist-sdk/src/entities/element/to-tf.js +6 -4
  95. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  96. package/dist-sdk/src/entities/field/from-tf.js +79 -1
  97. package/dist-sdk/src/entities/field/module.js +7 -0
  98. package/dist-sdk/src/entities/field/to-tf.d.ts +30 -1
  99. package/dist-sdk/src/entities/field/to-tf.js +51 -0
  100. package/dist-sdk/src/entities/file-reader/module.js +3 -3
  101. package/dist-sdk/src/entities/file-reader/to-tf.js +3 -3
  102. package/dist-sdk/src/entities/file-reader/types.d.ts +4 -16
  103. package/dist-sdk/src/entities/file-reader/types.js +7 -0
  104. package/dist-sdk/src/entities/org/group.d.ts +1 -0
  105. package/dist-sdk/src/entities/org/group.js +2 -1
  106. package/dist-sdk/src/entities/record-create-form/from-tf.d.ts +8 -0
  107. package/dist-sdk/src/entities/record-create-form/from-tf.js +10 -2
  108. package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +2 -1
  109. package/dist-sdk/src/entities/record-create-form/to-tf.js +14 -2
  110. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -0
  111. package/dist-sdk/src/entities/relationship/from-tf.js +88 -10
  112. package/dist-sdk/src/entities/relationship/to-tf.d.ts +3 -2
  113. package/dist-sdk/src/entities/relationship/to-tf.js +79 -8
  114. package/dist-sdk/src/entities/role/from-tf.js +24 -7
  115. package/dist-sdk/src/entities/role/to-tf.js +25 -7
  116. package/dist-sdk/src/entities/service-account/from-tf.js +2 -1
  117. package/dist-sdk/src/entities/service-account/module.js +15 -0
  118. package/dist-sdk/src/entities/service-account/to-tf.js +12 -4
  119. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
  120. package/dist-sdk/src/entities/shared/filters/tf-codec.js +12 -7
  121. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -2
  122. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +8 -1
  123. package/dist-sdk/src/entities/skill/from-tf.js +10 -3
  124. package/dist-sdk/src/entities/skill/module.js +44 -2
  125. package/dist-sdk/src/entities/skill/to-tf.d.ts +8 -1
  126. package/dist-sdk/src/entities/skill/to-tf.js +23 -14
  127. package/dist-sdk/src/entities/skill/tools.d.ts +8 -0
  128. package/dist-sdk/src/entities/skill/tools.js +6 -2
  129. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  130. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
  131. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -2
  132. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +10 -2
  133. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +18 -4
  134. package/dist-sdk/src/entities/view/custom-view-validate.js +6 -5
  135. package/dist-sdk/src/entities/view/from-tf.d.ts +68 -0
  136. package/dist-sdk/src/entities/view/from-tf.js +503 -25
  137. package/dist-sdk/src/entities/view/module.js +15 -0
  138. package/dist-sdk/src/entities/view/portable.d.ts +11 -0
  139. package/dist-sdk/src/entities/view/portable.js +47 -0
  140. package/dist-sdk/src/entities/view/to-tf.d.ts +4 -1
  141. package/dist-sdk/src/entities/view/to-tf.js +25 -7
  142. package/dist-sdk/src/entities/view/types.js +1 -1
  143. package/dist-sdk/src/entities/widget/build.d.ts +4 -3
  144. package/dist-sdk/src/entities/widget/from-tf.d.ts +3 -0
  145. package/dist-sdk/src/entities/widget/from-tf.js +100 -3
  146. package/dist-sdk/src/entities/widget/to-tf.d.ts +16 -1
  147. package/dist-sdk/src/entities/widget/to-tf.js +77 -14
  148. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +27 -8
  149. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  150. package/dist-sdk/src/graph/field-resource-types.d.ts +2 -0
  151. package/dist-sdk/src/graph/field-resource-types.js +11 -0
  152. package/dist-sdk/src/graph/index.d.ts +28 -3
  153. package/dist-sdk/src/graph/index.js +12 -2
  154. package/dist-sdk/src/graph/types.d.ts +164 -5
  155. package/package.json +1 -1
@@ -56,6 +56,24 @@ export const OUTPUT_KEY_CANONICAL = {
56
56
  export function matchesOutputWireKey(segment, wireKey) {
57
57
  return segment === wireKey || segment === wireKey.toLowerCase();
58
58
  }
59
+ /**
60
+ * AI completion task outputs: canonical (`service_tasks`) name → refs-map key.
61
+ * The provider's `refs` map is Title-Case (`Response`, `Success`, and
62
+ * aiClassify's `Reason`; see {@link OUTPUT_KEY_WIRE_NAME}), but a switch
63
+ * case's stored envelope names the output in lowercase, so pull prints
64
+ * `.success` and build must index `refs["Success"]` (edk#1730: Sanofi
65
+ * conciergeforfield plan failed with "Invalid index" on `refs["success"]`).
66
+ * Exact canonical names only; a Title-Case key passes through unchanged.
67
+ */
68
+ const AI_COMPLETION_REFS_INDEX = {
69
+ elementum_ai_classify_task: { response: "Response", reason: "Reason", success: "Success" },
70
+ elementum_ai_summarize_task: { response: "Response", success: "Success" },
71
+ elementum_ai_transform_task: { response: "Response", success: "Success" },
72
+ };
73
+ /** refs-map key for one AI completion task output, or undefined when `name` is not one. */
74
+ export function aiCompletionRefsIndex(resourceType, name) {
75
+ return AI_COMPLETION_REFS_INDEX[resourceType]?.[name];
76
+ }
59
77
  /**
60
78
  * apiRequest task outputs in authoring use camelCase segments (`statusCode`,
61
79
  * `file.content`, …) but the provider refs map uses display labels — confirmed
@@ -72,16 +90,67 @@ export const API_TASK_REF_WIRE_NAMES = {
72
90
  };
73
91
  /** Inverse of {@link API_TASK_REF_WIRE_NAMES} for export jsonencode envelopes. */
74
92
  export const API_TASK_REF_AUTHORING_NAMES = Object.fromEntries(Object.entries(API_TASK_REF_WIRE_NAMES).map(([authoring, wire]) => [wire, authoring]));
93
+ /**
94
+ * A JSON-response apiRequest's refs-map keys (edk#2058). JSON is the
95
+ * provider's default `response_type`. Confirmed live: `ei refs --from-remote`
96
+ * on dev/edk "Look Up Shipment" (FETCH_STATUS, response_type JSON, 2026-10-23)
97
+ * lists exactly these three keys, and Josh's Elementum-org state matches. The
98
+ * whole response is `API Response` (OBJECT), not the `Response` in
99
+ * {@link API_TASK_REF_WIRE_NAMES}, so `.response` used to build
100
+ * `refs["Response"]` and fail mid-apply with "Invalid index". FILE and CUSTOM
101
+ * tasks keep {@link API_TASK_REF_WIRE_NAMES} until they are confirmed live.
102
+ */
103
+ const API_TASK_JSON_REF_WIRE_NAMES = {
104
+ response: "API Response",
105
+ textResponse: "API Response (text)",
106
+ statusCode: "API Response Status Code",
107
+ };
108
+ const API_TASK_JSON_REF_AUTHORING_NAMES = Object.fromEntries(Object.entries(API_TASK_JSON_REF_WIRE_NAMES).map(([authoring, wire]) => [wire, authoring]));
109
+ function isJsonApiResponse(responseType) {
110
+ return responseType === undefined || responseType === "JSON";
111
+ }
112
+ /**
113
+ * refs-map key for one apiRequest output, given the task's `response_type`.
114
+ * A JSON task exposes only {@link API_TASK_JSON_REF_WIRE_NAMES}: an accessor
115
+ * or an already-rewritten key resolves, anything else is undefined so build
116
+ * fails instead of indexing a key the provider doesn't have. FILE and CUSTOM
117
+ * keep the {@link API_TASK_REF_WIRE_NAMES} mapping, passing unknown names
118
+ * through.
119
+ */
120
+ export function apiTaskRefsIndex(responseType, name) {
121
+ if (!isJsonApiResponse(responseType))
122
+ return API_TASK_REF_WIRE_NAMES[name] ?? name;
123
+ return API_TASK_JSON_REF_WIRE_NAMES[name] ?? (API_TASK_JSON_REF_AUTHORING_NAMES[name] !== undefined ? name : undefined);
124
+ }
125
+ /**
126
+ * Contract name a workflow output of one apiRequest output carries. On a JSON
127
+ * task only `response` / `textResponse` / `statusCode` (or their refs keys)
128
+ * resolve; anything else is undefined so build fails. FILE and CUSTOM pass
129
+ * the name through unchanged.
130
+ */
131
+ export function apiTaskCanonicalOutputName(responseType, name) {
132
+ if (!isJsonApiResponse(responseType))
133
+ return name;
134
+ const key = apiTaskRefsIndex(responseType, name);
135
+ return key === undefined ? undefined : API_TASK_JSON_REF_AUTHORING_NAMES[key];
136
+ }
137
+ /** The refs-map keys a JSON apiRequest exposes, for build errors. */
138
+ export function apiTaskJsonRefsKeys() {
139
+ return Object.values(API_TASK_JSON_REF_WIRE_NAMES);
140
+ }
75
141
  /**
76
142
  * Resolve a single `elementum_api_task` refs[] wire label (e.g. "File",
77
143
  * "Content Type") to its authoring path segments (e.g. ["file"], ["file",
78
- * "contentType"]) via {@link API_TASK_REF_AUTHORING_NAMES} — some authoring
144
+ * "contentType"]) via {@link API_TASK_REF_AUTHORING_NAMES}, plus
145
+ * {@link API_TASK_JSON_REF_WIRE_NAMES} for a JSON task (absent
146
+ * `response_type` is the provider default, JSON) — some authoring
79
147
  * names are dotted (`file.content`) since they nest under the `file` output.
80
148
  * Returns undefined for a wire label with no known authoring counterpart so
81
149
  * callers can fall back to the generic segment mapping.
82
150
  */
83
- export function apiTaskRefAuthoringPath(wireSegment) {
84
- const authoring = API_TASK_REF_AUTHORING_NAMES[wireSegment];
151
+ export function apiTaskRefAuthoringPath(wireSegment, responseType) {
152
+ const authoring = (isJsonApiResponse(responseType) ? API_TASK_JSON_REF_AUTHORING_NAMES[wireSegment] : undefined) ??
153
+ API_TASK_REF_AUTHORING_NAMES[wireSegment];
85
154
  return authoring !== undefined ? authoring.split(".") : undefined;
86
155
  }
87
156
  /**
@@ -0,0 +1,59 @@
1
+ import { type ChildResourceScope, type TfExpr } from "../../engine/tf/index.js";
2
+ /** A runAutomation target's owner fields, as a catalog token carries them. */
3
+ interface RunTargetOwnerFields {
4
+ readonly parent?: string;
5
+ readonly parentKind?: "app" | "element" | "task";
6
+ }
7
+ /**
8
+ * The app or element that owns an automation token, and whether that is the
9
+ * building automation's own app or element. A token with no `parent` is the
10
+ * caller's own. A same-named automation in another app or element is a
11
+ * different automation (edk#2118).
12
+ */
13
+ export declare function automationTargetOwner(value: RunTargetOwnerFields, ctx: {
14
+ readonly appRefName: string;
15
+ readonly parentScope: "app" | "element";
16
+ }): {
17
+ readonly ownerKind: NonNullable<RunTargetOwnerFields["parentKind"]>;
18
+ readonly isOwn: boolean;
19
+ };
20
+ /**
21
+ * A bare platform-id target whose every input names a raw parameter id is a
22
+ * static run: pull prints a static export with an undiscovered target
23
+ * (`target_automation_id` + `input_mappings[].parameter_id`) as
24
+ * `automation: "<uuid>"` + `inputs[].name: "<uuid>"`. Dynamic mappings name
25
+ * the target's inputs, never a parameter id.
26
+ */
27
+ export declare function bareStaticRunTarget(config: Record<string, unknown>): boolean;
28
+ /** The onDemand trigger's record parameters: they expose only a record ID. */
29
+ export declare function onDemandRecordParamNames(trigger: unknown): ReadonlySet<string>;
30
+ /** An automation payload's on-demand record inputs, for a static runAutomation caller's check (edk#1868). */
31
+ export declare function automationOnDemandRecordInputs(payload: unknown): ReadonlySet<string>;
32
+ /**
33
+ * edk#1868: a static runAutomation mapping into the target's on-demand record
34
+ * input reaches the target as no record, so every task reading it fails at
35
+ * run time. Returns the problem, naming the text-handle workaround, or
36
+ * undefined. `recordInputNames` is known only for a target this build owns.
37
+ */
38
+ export declare function recordInputMappingProblem(target: {
39
+ readonly refName: string;
40
+ readonly name?: string;
41
+ readonly parent?: string;
42
+ }, mappings: readonly unknown[], recordInputNames: ReadonlySet<string> | undefined): string | undefined;
43
+ /** Run-automation targets reference publish for ACTIVE automations, automation for draft/inactive. */
44
+ export declare function automationRunTargetResourceAttr(appTfLabel: string, automationRefName: string, activeAutomationRefNames: ReadonlySet<string> | undefined, scope?: ChildResourceScope, handle?: string): TfExpr;
45
+ /** The publish resource addresses a compiled automation file declares (its own). */
46
+ export declare function automationPublishDeclarations(text: string): string[];
47
+ /**
48
+ * The publish addresses of a compiled automation file's static
49
+ * `runAutomation` targets. A static call to an ACTIVE target names the
50
+ * target's publish: the run task and the caller's publish `depends_on` it
51
+ * (own app or element, `automationToTf`), and the target lookup
52
+ * `data.<automation>.<target>_for_<caller>` `depends_on` it (another app or
53
+ * element in the workspace, `automationTargetToTf`). Nothing else in an
54
+ * automation file names another automation's publish. A target outside the
55
+ * workspace (a lookup by name) or one that is not ACTIVE names no publish and
56
+ * is not tracked.
57
+ */
58
+ export declare function staticRunTargets(text: string): string[];
59
+ export {};
@@ -0,0 +1,99 @@
1
+ import { expr, isUuid } from "../../engine/tf/index.js";
2
+ import { isOnDemandRecordType } from "../shared/types/field-types.js";
3
+ import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE, automationResourceLabel } from "./types.js";
4
+ /**
5
+ * The app or element that owns an automation token, and whether that is the
6
+ * building automation's own app or element. A token with no `parent` is the
7
+ * caller's own. A same-named automation in another app or element is a
8
+ * different automation (edk#2118).
9
+ */
10
+ export function automationTargetOwner(value, ctx) {
11
+ const ownerKind = value.parentKind ?? ctx.parentScope;
12
+ const isOwn = value.parent === undefined ||
13
+ (value.parent === ctx.appRefName && ownerKind === ctx.parentScope);
14
+ return { ownerKind, isOwn };
15
+ }
16
+ /**
17
+ * A bare platform-id target whose every input names a raw parameter id is a
18
+ * static run: pull prints a static export with an undiscovered target
19
+ * (`target_automation_id` + `input_mappings[].parameter_id`) as
20
+ * `automation: "<uuid>"` + `inputs[].name: "<uuid>"`. Dynamic mappings name
21
+ * the target's inputs, never a parameter id.
22
+ */
23
+ export function bareStaticRunTarget(config) {
24
+ return typeof config.targetAutomationId === "string" &&
25
+ Array.isArray(config.inputMappings) &&
26
+ config.inputMappings.length > 0 &&
27
+ config.inputMappings.every((mapping) => mapping !== null && typeof mapping === "object" && "name" in mapping && typeof mapping.name === "string" && isUuid(mapping.name));
28
+ }
29
+ /** The onDemand trigger's record parameters: they expose only a record ID. */
30
+ export function onDemandRecordParamNames(trigger) {
31
+ const inputs = trigger?.onDemand?.inputs;
32
+ if (!Array.isArray(inputs))
33
+ return new Set();
34
+ return new Set(inputs.flatMap((input) => {
35
+ const param = input;
36
+ return typeof param?.name === "string" && isOnDemandRecordType(typeof param.type === "string" ? param.type : undefined) ? [param.name] : [];
37
+ }));
38
+ }
39
+ /** An automation payload's on-demand record inputs, for a static runAutomation caller's check (edk#1868). */
40
+ export function automationOnDemandRecordInputs(payload) {
41
+ return onDemandRecordParamNames(payload?.trigger);
42
+ }
43
+ /**
44
+ * edk#1868: a static runAutomation mapping into the target's on-demand record
45
+ * input reaches the target as no record, so every task reading it fails at
46
+ * run time. Returns the problem, naming the text-handle workaround, or
47
+ * undefined. `recordInputNames` is known only for a target this build owns.
48
+ */
49
+ export function recordInputMappingProblem(target, mappings, recordInputNames) {
50
+ if (recordInputNames === undefined || recordInputNames.size === 0)
51
+ return undefined;
52
+ const mapped = [...new Set(mappings.flatMap((mapping) => {
53
+ const name = mapping?.name;
54
+ return typeof name === "string" && recordInputNames.has(name) ? [name] : [];
55
+ }))];
56
+ if (mapped.length === 0)
57
+ return undefined;
58
+ const label = `${target.name !== undefined && target.name !== "" ? `"${target.name}" ` : ""}(${target.parent !== undefined ? `${target.parent}.` : ""}${target.refName})`;
59
+ const plural = mapped.length > 1;
60
+ return `maps automation ${label}'s on-demand record input${plural ? "s" : ""} ${mapped.map((name) => `"${name}"`).join(", ")}, ` +
61
+ `but the platform passes no record through a runAutomation input: the called automation's tasks that read ${plural ? "them" : "it"} ` +
62
+ `fail at run time ("missing workflow input parameter"). Make ${plural ? "each" : "it"} a text input, pass the record's handle as text, ` +
63
+ "and look the record up with a recordSearch in the called automation.";
64
+ }
65
+ /** Run-automation targets reference publish for ACTIVE automations, automation for draft/inactive. */
66
+ export function automationRunTargetResourceAttr(appTfLabel, automationRefName, activeAutomationRefNames, scope = "app", handle) {
67
+ const label = automationResourceLabel(appTfLabel, automationRefName, scope, handle);
68
+ if (activeAutomationRefNames?.has(automationRefName) === true) {
69
+ return expr.resourceAttr(WORKFLOW_PUBLISH_RESOURCE_TYPE, label, ["id"]);
70
+ }
71
+ return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]);
72
+ }
73
+ const PUBLISH_DECL = new RegExp(`^resource\\s+"${WORKFLOW_PUBLISH_RESOURCE_TYPE}"\\s+"([^"]+)"`, "gm");
74
+ const PUBLISH_REF = new RegExp(`(?<![\\w.])${WORKFLOW_PUBLISH_RESOURCE_TYPE}\\.([a-z0-9_]+)`, "g");
75
+ /** The publish resource addresses a compiled automation file declares (its own). */
76
+ export function automationPublishDeclarations(text) {
77
+ return [...text.matchAll(PUBLISH_DECL)].map((match) => `${WORKFLOW_PUBLISH_RESOURCE_TYPE}.${match[1]}`);
78
+ }
79
+ /**
80
+ * The publish addresses of a compiled automation file's static
81
+ * `runAutomation` targets. A static call to an ACTIVE target names the
82
+ * target's publish: the run task and the caller's publish `depends_on` it
83
+ * (own app or element, `automationToTf`), and the target lookup
84
+ * `data.<automation>.<target>_for_<caller>` `depends_on` it (another app or
85
+ * element in the workspace, `automationTargetToTf`). Nothing else in an
86
+ * automation file names another automation's publish. A target outside the
87
+ * workspace (a lookup by name) or one that is not ACTIVE names no publish and
88
+ * is not tracked.
89
+ */
90
+ export function staticRunTargets(text) {
91
+ const own = new Set(automationPublishDeclarations(text));
92
+ const targets = new Set();
93
+ for (const match of text.matchAll(PUBLISH_REF)) {
94
+ const address = `${WORKFLOW_PUBLISH_RESOURCE_TYPE}.${match[1]}`;
95
+ if (!own.has(address))
96
+ targets.add(address);
97
+ }
98
+ return [...targets].sort();
99
+ }
@@ -114,5 +114,14 @@ export declare function freeIdentifiersLexer(body: string, params: ReadonlySet<s
114
114
  * there's no tracked source (not running under `elementum build`, e.g. an
115
115
  * automation constructed directly in a test) or the name/shape wasn't found
116
116
  * by the scan (falls back to `extractScriptBody`).
117
+ *
118
+ * A body that is not plain JavaScript is also `undefined` (#1927). The
119
+ * verbatim text exists so a pulled body, which is always JavaScript,
120
+ * round-trips byte for byte. A body with type annotations was written by
121
+ * hand, and the runtime that loaded the file has already erased its types
122
+ * from the function itself, so `extractScriptBody` gives the same result in
123
+ * every workspace instead of depending on whether a usable TypeScript
124
+ * compiler happens to resolve. It also runs the closure check, which this
125
+ * path skips.
117
126
  */
118
127
  export declare function tryExtractFromCurrentSource(name: string): string | undefined;
@@ -7,7 +7,8 @@ let packageTsModule;
7
7
  function getTs() {
8
8
  if (packageTsModule === undefined) {
9
9
  try {
10
- packageTsModule = createRequire(import.meta.url)("typescript");
10
+ const loaded = createRequire(import.meta.url)("typescript");
11
+ packageTsModule = hasCompilerApi(loaded) ? loaded : null;
11
12
  }
12
13
  catch {
13
14
  packageTsModule = null;
@@ -26,7 +27,9 @@ function getTs() {
26
27
  ];
27
28
  for (const root of roots) {
28
29
  try {
29
- return createRequire(root)("typescript");
30
+ const loaded = createRequire(root)("typescript");
31
+ if (hasCompilerApi(loaded))
32
+ return loaded;
30
33
  }
31
34
  catch {
32
35
  // Try the next legitimate module root.
@@ -34,6 +37,14 @@ function getTs() {
34
37
  }
35
38
  return undefined;
36
39
  }
40
+ /**
41
+ * TypeScript 7's package entry exposes only its version, not the compiler
42
+ * API (#1927). Treat that package as no TypeScript rather than calling
43
+ * functions it does not have.
44
+ */
45
+ function hasCompilerApi(ts) {
46
+ return typeof ts?.transpileModule === "function" && typeof ts.createSourceFile === "function";
47
+ }
37
48
  /**
38
49
  * Reference a plain-JavaScript script file for `executeScript`'s `code:`.
39
50
  * The path is relative to the automation file that calls it.
@@ -1339,6 +1350,15 @@ const scanCache = new WeakMap();
1339
1350
  * there's no tracked source (not running under `elementum build`, e.g. an
1340
1351
  * automation constructed directly in a test) or the name/shape wasn't found
1341
1352
  * by the scan (falls back to `extractScriptBody`).
1353
+ *
1354
+ * A body that is not plain JavaScript is also `undefined` (#1927). The
1355
+ * verbatim text exists so a pulled body, which is always JavaScript,
1356
+ * round-trips byte for byte. A body with type annotations was written by
1357
+ * hand, and the runtime that loaded the file has already erased its types
1358
+ * from the function itself, so `extractScriptBody` gives the same result in
1359
+ * every workspace instead of depending on whether a usable TypeScript
1360
+ * compiler happens to resolve. It also runs the closure check, which this
1361
+ * path skips.
1342
1362
  */
1343
1363
  export function tryExtractFromCurrentSource(name) {
1344
1364
  const ctx = currentSourceText();
@@ -1349,7 +1369,8 @@ export function tryExtractFromCurrentSource(name) {
1349
1369
  bodies = scanExecuteScriptBodies(ctx.text);
1350
1370
  scanCache.set(ctx, bodies);
1351
1371
  }
1352
- return bodies.get(name);
1372
+ const body = bodies.get(name);
1373
+ return body !== undefined && plainJavaScriptSyntaxError(body) === undefined ? body : undefined;
1353
1374
  }
1354
1375
  /**
1355
1376
  * Scan raw (untranspiled) `.ts` source text for every fluent
@@ -1,5 +1,14 @@
1
+ import type { TaskOutputReference } from "../../graph/types.js";
1
2
  /** userSearch authoring output → provider refs-map key (as exported from live user-search tasks). */
2
3
  export declare const USER_SEARCH_REF_WIRE_NAMES: Readonly<Record<string, string>>;
4
+ /**
5
+ * A user search's refs-map key → the reference an exported value envelope
6
+ * carries: the name and the `fieldType`/`multiple` of the envelope that key
7
+ * holds, as the provider's refs map of a live user-search task lists them
8
+ * (ironman capture, #1701). The build-vs-export comparison reads all of it;
9
+ * the build names the referenceable ones (TASK_OUTPUT_REFERENCE_NAMES below).
10
+ */
11
+ export declare const USER_SEARCH_OUTPUT_REFERENCES: Readonly<Record<string, TaskOutputReference>>;
3
12
  /**
4
13
  * Task-own outputs whose WorkflowTaskReference name (what an exported
5
14
  * envelope and a calculation mustache carry) differs from the provider
@@ -7,6 +16,13 @@ export declare const USER_SEARCH_REF_WIRE_NAMES: Readonly<Record<string, string>
7
16
  * and matching mobius' `shared.json` label tables.
8
17
  */
9
18
  export declare const TASK_OUTPUT_REFERENCE_NAMES: Readonly<Record<string, Readonly<Record<string, string>>>>;
19
+ /**
20
+ * Each {@link TASK_OUTPUT_REFERENCE_NAMES} key with the type of the envelope
21
+ * it holds: the output's contract (`TASK_OUTPUT_CONTRACTS`). The
22
+ * build-vs-export comparison reads an exported envelope as that key only when
23
+ * the envelope is of this type.
24
+ */
25
+ export declare function taskOutputReferences(): Readonly<Record<string, Readonly<Record<string, TaskOutputReference>>>>;
10
26
  /**
11
27
  * A record-bearing task's whole-record output (ASPECT_RECORD). The bare
12
28
  * `.record` accessor otherwise builds the ASPECT_RECORD_ID `Record` key a
@@ -1,3 +1,4 @@
1
+ import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
1
2
  /** userSearch authoring output → provider refs-map key (as exported from live user-search tasks). */
2
3
  export const USER_SEARCH_REF_WIRE_NAMES = {
3
4
  "user.id": "User's Id",
@@ -8,6 +9,24 @@ export const USER_SEARCH_REF_WIRE_NAMES = {
8
9
  users: "All found users",
9
10
  count: "Users Size",
10
11
  };
12
+ /**
13
+ * A user search's refs-map key → the reference an exported value envelope
14
+ * carries: the name and the `fieldType`/`multiple` of the envelope that key
15
+ * holds, as the provider's refs map of a live user-search task lists them
16
+ * (ironman capture, #1701). The build-vs-export comparison reads all of it;
17
+ * the build names the referenceable ones (TASK_OUTPUT_REFERENCE_NAMES below).
18
+ */
19
+ export const USER_SEARCH_OUTPUT_REFERENCES = {
20
+ "Users Size": { name: "count", fieldType: "NUMBER", multiple: false },
21
+ "First found user": { name: "user", fieldType: "USER", multiple: false },
22
+ "All found users": { name: "users", fieldType: "USER", multiple: true },
23
+ "User's Id": { name: "user.id", fieldType: "USER_ID", multiple: false },
24
+ "User's Name": { name: "user.name", fieldType: "TEXT", multiple: false },
25
+ "User's Email": { name: "user.email", fieldType: "TEXT", multiple: false },
26
+ Manager: { name: "user.employee.manager", fieldType: "EMPLOYEE", multiple: false },
27
+ "Manager Name": { name: "user.employee.manager.name", fieldType: "TEXT", multiple: false },
28
+ "Manager Email": { name: "user.employee.manager.email", fieldType: "TEXT", multiple: false },
29
+ };
11
30
  /**
12
31
  * Task-own outputs whose WorkflowTaskReference name (what an exported
13
32
  * envelope and a calculation mustache carry) differs from the provider
@@ -19,6 +38,12 @@ export const TASK_OUTPUT_REFERENCE_NAMES = {
19
38
  "Records Size": "count",
20
39
  "First found record id": "recordId",
21
40
  },
41
+ // The user-search outputs with a contract, so a calculation names `count`,
42
+ // `user.id`, … and not "Users Size" (#1738). The manager outputs have no
43
+ // contract (not referenceable at publish) and keep their refs key.
44
+ elementum_user_search_task: Object.fromEntries(Object.entries(USER_SEARCH_OUTPUT_REFERENCES)
45
+ .filter(([, ref]) => TASK_OUTPUT_CONTRACTS.user_search?.[ref.name] !== undefined)
46
+ .map(([key, ref]) => [key, ref.name])),
22
47
  elementum_user_group_search_task: {
23
48
  "Groups Size": "count",
24
49
  "First found group": "group",
@@ -26,12 +51,36 @@ export const TASK_OUTPUT_REFERENCE_NAMES = {
26
51
  Name: "group.name",
27
52
  "All found groups": "groups",
28
53
  },
54
+ // A JSON apiRequest's refs keys (edk#2058, `ei refs --from-remote`); the
55
+ // send_api_request contract names them response/textResponse/statusCode.
56
+ elementum_api_task: {
57
+ "API Response": "response",
58
+ "API Response (text)": "textResponse",
59
+ "API Response Status Code": "statusCode",
60
+ },
29
61
  // Captured live from a deployed bulk_update_fields task's refs map.
30
62
  elementum_bulk_update_fields_task: {
31
63
  "Records Updated": "recordsUpdated",
32
64
  "All Matching Records Updated": "allMatchingRecordsUpdated",
33
65
  },
34
66
  };
67
+ /**
68
+ * Each {@link TASK_OUTPUT_REFERENCE_NAMES} key with the type of the envelope
69
+ * it holds: the output's contract (`TASK_OUTPUT_CONTRACTS`). The
70
+ * build-vs-export comparison reads an exported envelope as that key only when
71
+ * the envelope is of this type.
72
+ */
73
+ export function taskOutputReferences() {
74
+ return Object.fromEntries(Object.entries(TASK_OUTPUT_REFERENCE_NAMES).map(([taskType, names]) => {
75
+ const executor = RESOURCE_TYPE_TO_EXECUTOR[taskType];
76
+ return [taskType, Object.fromEntries(Object.entries(names).map(([key, name]) => {
77
+ const contract = executor === undefined ? undefined : TASK_OUTPUT_CONTRACTS[executor]?.[name];
78
+ if (contract === undefined)
79
+ throw new Error(`no output contract for ${taskType} output "${name}" (refs key "${key}")`);
80
+ return [key, { name, fieldType: contract.fieldType, multiple: contract.multiple }];
81
+ }))];
82
+ }));
83
+ }
35
84
  /**
36
85
  * A record-bearing task's whole-record output (ASPECT_RECORD). The bare
37
86
  * `.record` accessor otherwise builds the ASPECT_RECORD_ID `Record` key a
@@ -495,7 +495,24 @@ export interface ApiRequestMultipartPart {
495
495
  export interface ApiRequestMultipartBody {
496
496
  readonly parts: readonly ApiRequestMultipartPart[];
497
497
  }
498
- export interface ApiRequestOptions {
498
+ /** elementum_api_task's `response_type` values; the provider default is JSON. */
499
+ export type ApiResponseType = "JSON" | "FILE" | "CUSTOM";
500
+ /**
501
+ * apiRequest outputs for a `responseType`. JSON (also when omitted) has no
502
+ * `.file`, since build rejects it (edk#2058); FILE, CUSTOM or a non-literal
503
+ * type keep every accessor.
504
+ */
505
+ export type ApiRequestOutputs<R extends ApiResponseType = ApiResponseType> = [R] extends ["JSON"] ? {
506
+ response: unknown;
507
+ statusCode?: unknown;
508
+ textResponse?: unknown;
509
+ } : {
510
+ response: unknown;
511
+ file?: unknown;
512
+ statusCode?: unknown;
513
+ textResponse?: unknown;
514
+ };
515
+ export interface ApiRequestOptions<R extends ApiResponseType = ApiResponseType> {
499
516
  readonly url: ValueOrRef<unknown>;
500
517
  readonly method: string;
501
518
  readonly headers?: readonly ApiRequestHeader[];
@@ -513,15 +530,10 @@ export interface ApiRequestOptions {
513
530
  readonly customBody?: ApiRequestCustomBody;
514
531
  /** elementum_api_task's `multipart_body` block (file uploads). Mutually exclusive with `jsonBody`/`formBody`/`customBody`. */
515
532
  readonly multipartBody?: ApiRequestMultipartBody;
516
- readonly responseType?: string;
533
+ readonly responseType?: R;
517
534
  readonly continueOnError?: boolean;
518
535
  }
519
- export declare function apiRequest(opts: ApiRequestOptions): ActionDef<{
520
- response: unknown;
521
- file?: unknown;
522
- statusCode?: unknown;
523
- textResponse?: unknown;
524
- }>;
536
+ export declare function apiRequest<R extends ApiResponseType = "JSON">(opts: ApiRequestOptions<R>): ActionDef<ApiRequestOutputs<R>>;
525
537
  export interface AiSearchTableOptions {
526
538
  readonly table: SearchTableRef | UnsafePlatformId;
527
539
  readonly query: ValueOrRef<unknown>;
@@ -1,6 +1,6 @@
1
1
  import type { DeployableEntity } from "../../engine/entity.js";
2
2
  import { type ValidationFailure } from "../../engine/validation.js";
3
- import { type ChildResourceScope, type TfBlock, type TfExpr, type TfValue } from "../../engine/tf/index.js";
3
+ import { type TfBlock, type TfValue } from "../../engine/tf/index.js";
4
4
  import { type ForeignRootIdentity, type OrgRefLookup, type WorkspaceAspect } from "../../engine/build/context.js";
5
5
  import type { BuildFieldMetadata } from "../../graph/types.js";
6
6
  import type { AppServiceAccount } from "../service-account/build.js";
@@ -33,6 +33,13 @@ export interface AutomationToTfContext {
33
33
  * searched aspect's own `<resource>.<label>.id` to interpolate.
34
34
  */
35
35
  readonly fieldAddressesByAppRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>;
36
+ /**
37
+ * Every app/element authored in the workspace, keyed by
38
+ * `workspaceAspectKey`, including those this build leaves out (pull builds
39
+ * only the pulled root). A calculation over such a sibling's found record
40
+ * addresses the field by data lookup.
41
+ */
42
+ readonly authoredAspectKeys?: ReadonlySet<string>;
36
43
  /** Build-time tolerance for stale labels retained by pulled automations. */
37
44
  readonly allowUnknownPicklistOptions?: boolean;
38
45
  readonly orgRefs?: OrgRefLookup;
@@ -81,8 +88,6 @@ export interface AutomationToTfResult {
81
88
  readonly blocks: readonly TfBlock[];
82
89
  readonly address: string;
83
90
  }
84
- /** Run-automation targets reference publish for ACTIVE automations, automation for draft/inactive. */
85
- export declare function automationRunTargetResourceAttr(appTfLabel: string, automationRefName: string, activeAutomationRefNames: ReadonlySet<string> | undefined, scope?: ChildResourceScope, handle?: string): TfExpr;
86
91
  /**
87
92
  * edk#1499: script-input field mappings read fields off a whole record. A
88
93
  * value that exposes only a record ID (an onDemand record parameter, or