@elementumai/edk 0.9.6 → 0.9.9

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 (180) hide show
  1. package/README.md +34 -3
  2. package/dist-sdk/src/catalog/factories.d.ts +26 -6
  3. package/dist-sdk/src/catalog/factories.js +41 -6
  4. package/dist-sdk/src/catalog/from-authoring.js +27 -33
  5. package/dist-sdk/src/catalog/index.d.ts +2 -2
  6. package/dist-sdk/src/catalog/index.js +2 -2
  7. package/dist-sdk/src/catalog/org.js +93 -42
  8. package/dist-sdk/src/catalog/token.js +10 -0
  9. package/dist-sdk/src/catalog/types.d.ts +42 -3
  10. package/dist-sdk/src/catalog/types.js +5 -0
  11. package/dist-sdk/src/core/index.d.ts +2 -2
  12. package/dist-sdk/src/core/index.js +1 -1
  13. package/dist-sdk/src/core/platform-id.d.ts +2 -0
  14. package/dist-sdk/src/core/platform-id.js +4 -0
  15. package/dist-sdk/src/core/system-fields.d.ts +18 -0
  16. package/dist-sdk/src/core/system-fields.js +21 -0
  17. package/dist-sdk/src/core/triggers/on-demand.d.ts +27 -24
  18. package/dist-sdk/src/core/triggers/on-demand.js +33 -12
  19. package/dist-sdk/src/core/types/app.d.ts +14 -9
  20. package/dist-sdk/src/core/types/aspect-category.d.ts +1 -0
  21. package/dist-sdk/src/core/types/aspect-category.js +1 -0
  22. package/dist-sdk/src/core/types/platform.d.ts +1 -1
  23. package/dist-sdk/src/engine/build/context.d.ts +24 -8
  24. package/dist-sdk/src/engine/build/source-context.d.ts +14 -17
  25. package/dist-sdk/src/engine/build/source-context.js +1 -1
  26. package/dist-sdk/src/engine/pull/context.d.ts +18 -0
  27. package/dist-sdk/src/engine/pull/org.d.ts +4 -0
  28. package/dist-sdk/src/engine/pull/org.js +17 -2
  29. package/dist-sdk/src/engine/pull/procedure-refs.d.ts +16 -0
  30. package/dist-sdk/src/engine/pull/procedure-refs.js +69 -0
  31. package/dist-sdk/src/engine/pull/ref-only.d.ts +14 -0
  32. package/dist-sdk/src/engine/pull/ref-only.js +35 -2
  33. package/dist-sdk/src/engine/tf/expr.js +1 -1
  34. package/dist-sdk/src/engine/workspace/authoring-layout.d.ts +15 -0
  35. package/dist-sdk/src/engine/workspace/authoring-layout.js +33 -1
  36. package/dist-sdk/src/engine/workspace/loader.d.ts +40 -0
  37. package/dist-sdk/src/engine/workspace/loader.js +328 -0
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +4 -0
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +24 -4
  40. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +7 -0
  41. package/dist-sdk/src/entities/access-policy/to-tf.js +11 -3
  42. package/dist-sdk/src/entities/agent/build.d.ts +54 -8
  43. package/dist-sdk/src/entities/agent/build.js +36 -1
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +144 -3
  45. package/dist-sdk/src/entities/agent/from-tf.d.ts +7 -6
  46. package/dist-sdk/src/entities/agent/from-tf.js +176 -5
  47. package/dist-sdk/src/entities/agent/index.d.ts +2 -2
  48. package/dist-sdk/src/entities/agent/index.js +1 -1
  49. package/dist-sdk/src/entities/agent/module.js +1 -0
  50. package/dist-sdk/src/entities/agent/to-tf.d.ts +5 -4
  51. package/dist-sdk/src/entities/agent/to-tf.js +186 -11
  52. package/dist-sdk/src/entities/agent/tools.d.ts +16 -5
  53. package/dist-sdk/src/entities/agent/tools.js +13 -1
  54. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +16 -0
  55. package/dist-sdk/src/entities/agent-tool/from-tf.js +39 -6
  56. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -0
  57. package/dist-sdk/src/entities/agent-tool/to-tf.js +12 -12
  58. package/dist-sdk/src/entities/agent-tool/types.js +1 -0
  59. package/dist-sdk/src/entities/app/build.d.ts +44 -24
  60. package/dist-sdk/src/entities/app/build.js +18 -8
  61. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +15 -0
  62. package/dist-sdk/src/entities/app/display-blocks-to-layout.d.ts +45 -0
  63. package/dist-sdk/src/entities/app/display-blocks-to-layout.js +98 -0
  64. package/dist-sdk/src/entities/app/display-blocks-to-record-create-form.d.ts +55 -0
  65. package/dist-sdk/src/entities/app/display-blocks-to-record-create-form.js +99 -0
  66. package/dist-sdk/src/entities/app/from-tf.js +79 -14
  67. package/dist-sdk/src/entities/app/index.d.ts +3 -2
  68. package/dist-sdk/src/entities/app/index.js +2 -1
  69. package/dist-sdk/src/entities/app/to-tf.js +30 -6
  70. package/dist-sdk/src/entities/automation/build.d.ts +37 -18
  71. package/dist-sdk/src/entities/automation/build.js +121 -12
  72. package/dist-sdk/src/entities/automation/catalog-render.js +5 -2
  73. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +8 -10
  74. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +2 -0
  75. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +103 -20
  76. package/dist-sdk/src/entities/automation/from-tf.d.ts +10 -1
  77. package/dist-sdk/src/entities/automation/from-tf.js +1165 -91
  78. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  79. package/dist-sdk/src/entities/automation/module.js +15 -5
  80. package/dist-sdk/src/entities/automation/operators.d.ts +2 -2
  81. package/dist-sdk/src/entities/automation/operators.js +1 -0
  82. package/dist-sdk/src/entities/automation/output-field-types.d.ts +17 -0
  83. package/dist-sdk/src/entities/automation/output-field-types.js +45 -0
  84. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +20 -4
  85. package/dist-sdk/src/entities/automation/output-key-wire-name.js +33 -6
  86. package/dist-sdk/src/entities/automation/script-code.d.ts +1 -1
  87. package/dist-sdk/src/entities/automation/script-code.js +168 -36
  88. package/dist-sdk/src/entities/automation/task-label.d.ts +2 -0
  89. package/dist-sdk/src/entities/automation/task-label.js +18 -0
  90. package/dist-sdk/src/entities/automation/tasks.d.ts +159 -45
  91. package/dist-sdk/src/entities/automation/tasks.js +60 -47
  92. package/dist-sdk/src/entities/automation/to-tf.d.ts +7 -1
  93. package/dist-sdk/src/entities/automation/to-tf.js +816 -87
  94. package/dist-sdk/src/entities/automation/triggers.d.ts +14 -5
  95. package/dist-sdk/src/entities/automation/triggers.js +1 -1
  96. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +78 -0
  97. package/dist-sdk/src/entities/automation/value-ref-tf.js +193 -0
  98. package/dist-sdk/src/entities/dashboard/from-tf.js +1 -1
  99. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +1 -0
  100. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +1 -1
  101. package/dist-sdk/src/entities/element/build.d.ts +30 -7
  102. package/dist-sdk/src/entities/element/build.js +7 -3
  103. package/dist-sdk/src/entities/element/from-tf.js +7 -3
  104. package/dist-sdk/src/entities/element/index.d.ts +3 -2
  105. package/dist-sdk/src/entities/element/index.js +3 -2
  106. package/dist-sdk/src/entities/element/to-tf.js +49 -8
  107. package/dist-sdk/src/entities/field/build.d.ts +94 -3
  108. package/dist-sdk/src/entities/field/build.js +82 -3
  109. package/dist-sdk/src/entities/field/from-tf.d.ts +6 -0
  110. package/dist-sdk/src/entities/field/from-tf.js +104 -1
  111. package/dist-sdk/src/entities/field/locals.js +6 -7
  112. package/dist-sdk/src/entities/field/module.js +1 -0
  113. package/dist-sdk/src/entities/field/options.d.ts +2 -0
  114. package/dist-sdk/src/entities/field/options.js +12 -2
  115. package/dist-sdk/src/entities/field/record-shape.d.ts +12 -15
  116. package/dist-sdk/src/entities/field/to-tf.d.ts +13 -3
  117. package/dist-sdk/src/entities/field/to-tf.js +191 -56
  118. package/dist-sdk/src/entities/field/types.js +2 -0
  119. package/dist-sdk/src/entities/org/category-ref.d.ts +5 -0
  120. package/dist-sdk/src/entities/org/category-ref.js +12 -0
  121. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -3
  122. package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +1 -0
  123. package/dist-sdk/src/entities/record-create-form/to-tf.js +18 -13
  124. package/dist-sdk/src/entities/relationship/from-tf.js +100 -7
  125. package/dist-sdk/src/entities/role/from-tf.js +10 -4
  126. package/dist-sdk/src/entities/search-table/build.d.ts +1 -1
  127. package/dist-sdk/src/entities/search-table/from-tf.d.ts +1 -0
  128. package/dist-sdk/src/entities/search-table/from-tf.js +6 -0
  129. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  130. package/dist-sdk/src/entities/search-table/to-tf.js +3 -3
  131. package/dist-sdk/src/entities/search-table/types.js +1 -0
  132. package/dist-sdk/src/entities/service-account/from-tf.js +10 -4
  133. package/dist-sdk/src/entities/service-account/to-tf.d.ts +2 -1
  134. package/dist-sdk/src/entities/service-account/to-tf.js +7 -0
  135. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +9 -0
  136. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +39 -0
  137. package/dist-sdk/src/entities/shared/filters/ast.d.ts +24 -1
  138. package/dist-sdk/src/entities/shared/filters/ast.js +4 -0
  139. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +13 -2
  140. package/dist-sdk/src/entities/shared/filters/tf-codec.js +14 -8
  141. package/dist-sdk/src/entities/shared/handle-description.d.ts +12 -0
  142. package/dist-sdk/src/entities/shared/handle-description.js +20 -0
  143. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +5 -3
  144. package/dist-sdk/src/entities/shared/tool-field-ref.js +11 -16
  145. package/dist-sdk/src/entities/shared/types/common.d.ts +7 -5
  146. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -1
  147. package/dist-sdk/src/entities/shared/types/field-types.js +5 -8
  148. package/dist-sdk/src/entities/shared/types/platform.d.ts +15 -2
  149. package/dist-sdk/src/entities/skill/build.d.ts +51 -2
  150. package/dist-sdk/src/entities/skill/build.js +65 -8
  151. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +1 -1
  152. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +79 -18
  153. package/dist-sdk/src/entities/skill/from-tf.d.ts +11 -0
  154. package/dist-sdk/src/entities/skill/from-tf.js +47 -5
  155. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  156. package/dist-sdk/src/entities/skill/index.js +1 -1
  157. package/dist-sdk/src/entities/skill/input-coverage.d.ts +89 -0
  158. package/dist-sdk/src/entities/skill/input-coverage.js +327 -0
  159. package/dist-sdk/src/entities/skill/module.js +2 -0
  160. package/dist-sdk/src/entities/skill/to-tf.d.ts +9 -25
  161. package/dist-sdk/src/entities/skill/to-tf.js +29 -40
  162. package/dist-sdk/src/entities/skill/tools.d.ts +12 -2
  163. package/dist-sdk/src/entities/skill/tools.js +3 -6
  164. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +19 -0
  165. package/dist-sdk/src/entities/skill-tool/from-tf.js +50 -14
  166. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +9 -7
  167. package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -23
  168. package/dist-sdk/src/entities/table/to-tf.js +21 -5
  169. package/dist-sdk/src/entities/task/to-tf.js +3 -2
  170. package/dist-sdk/src/entities/view/from-tf.js +36 -10
  171. package/dist-sdk/src/entities/view/to-tf.d.ts +2 -0
  172. package/dist-sdk/src/entities/view/to-tf.js +49 -30
  173. package/dist-sdk/src/entities/visual-flow/from-tf.js +6 -2
  174. package/dist-sdk/src/entities/widget/from-tf.js +2 -2
  175. package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
  176. package/dist-sdk/src/entities/widget/to-tf.js +52 -23
  177. package/dist-sdk/src/graph/index.d.ts +19 -1
  178. package/dist-sdk/src/graph/index.js +20 -0
  179. package/dist-sdk/src/graph/types.d.ts +22 -0
  180. package/package.json +11 -5
@@ -7,6 +7,7 @@
7
7
  import { EntityTfError } from "../../engine/entity.js";
8
8
  import { dataRefLabel, optionalString, resourceRefLabel } from "../../engine/pull/context.js";
9
9
  import { isTfExpr, scopedLabelToBagKey } from "../../engine/tf/index.js";
10
+ import { dataAspectDisplayName, dataAspectRefName } from "../shared/aspect-target-from-tf.js";
10
11
  import { resolveToolFieldKey } from "../shared/tool-field-ref.js";
11
12
  import { KNOWN_SKILL_TOOL_ATTRS, SKILL_TOOL_SUB_TYPE_BY_RESOURCE, UNAUTHORABLE_SKILL_TOOL_ATTRS, } from "./types.js";
12
13
  /**
@@ -126,7 +127,8 @@ export function skillToolFromTf(block, owner, ctx) {
126
127
  (automation.type === "elementum_workflow_publish" || automation.type === "elementum_automation")
127
128
  ? automation.label
128
129
  : undefined;
129
- if (automationLabel === undefined) {
130
+ const automationRawId = typeof automation === "string" && automation !== "" ? automation : undefined;
131
+ if (automationLabel === undefined && automationRawId === undefined) {
130
132
  ctx.diagnostics.push(`${where}: automation_id is not an automation/workflow_publish resource reference; skipped`);
131
133
  return undefined;
132
134
  }
@@ -171,10 +173,12 @@ export function skillToolFromTf(block, owner, ctx) {
171
173
  // holds by observed export convention, not by contract, and a silent
172
174
  // miss here would reproduce the exact tsc-failing call this fix is for,
173
175
  // with no diagnostic to explain why.
174
- const trigger = ctx.resourcesOfType?.("elementum_on_demand_trigger").find((block) => {
175
- const ref = block.attrs["automation"];
176
- return isTfExpr(ref) && ref.$expr === "resource-attr" && ref.type === "elementum_automation" && ref.label === automationLabel;
177
- });
176
+ const trigger = automationLabel === undefined
177
+ ? undefined
178
+ : ctx.resourcesOfType?.("elementum_on_demand_trigger").find((block) => {
179
+ const ref = block.attrs["automation"];
180
+ return isTfExpr(ref) && ref.$expr === "resource-attr" && ref.type === "elementum_automation" && ref.label === automationLabel;
181
+ });
178
182
  const missingRequiredInputs = [];
179
183
  for (const item of Array.isArray(trigger?.attrs["parameters"]) ? trigger.attrs["parameters"] : []) {
180
184
  if (typeof item !== "object" || item === null || Array.isArray(item) || isTfExpr(item))
@@ -203,7 +207,9 @@ export function skillToolFromTf(block, owner, ctx) {
203
207
  return {
204
208
  typeKey: "automation",
205
209
  ...common,
206
- automationKey: scopedLabelToBagKey(owner.ownerTfLabel, automationLabel),
210
+ ...(automationRawId !== undefined
211
+ ? { automationRawId }
212
+ : { automationKey: scopedLabelToBagKey(owner.ownerTfLabel, automationLabel) }),
207
213
  ...(inputs.length > 0 && { inputs }),
208
214
  ...(outputs.length > 0 && { outputs }),
209
215
  ...(missingRequiredInputs.length > 0 && { missingRequiredInputs }),
@@ -254,25 +260,48 @@ export function skillToolFromTf(block, owner, ctx) {
254
260
  target = { kind: "self" };
255
261
  }
256
262
  else if (isTfExpr(targetAttr) && targetAttr.$expr === "data-attr" && targetAttr.type === "elementum_app") {
257
- const appName = ctx.dataName("elementum_app", targetAttr.label);
263
+ const appName = dataAspectDisplayName(ctx, "app", targetAttr.label);
258
264
  if (appName === undefined) {
259
265
  ctx.diagnostics.push(`${where}: target_id references data.elementum_app.${targetAttr.label} but the stream has no such data block; skipped`);
260
266
  return undefined;
261
267
  }
262
- target = { kind: "foreignApp", name: appName };
268
+ const attrs = ctx.dataAttrs?.("elementum_app", targetAttr.label);
269
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
270
+ const refName = dataAspectRefName(ctx, "app", targetAttr.label, appName);
271
+ target = {
272
+ kind: "foreignApp",
273
+ name: appName,
274
+ ...(refName !== undefined && { refName }),
275
+ ...(namespace !== undefined && { namespace }),
276
+ };
263
277
  fieldScopeLabel = targetAttr.label;
264
278
  }
265
279
  else if (isTfExpr(targetAttr) && targetAttr.$expr === "data-attr" && targetAttr.type === "elementum_element") {
266
280
  // Board issue #42: an aspect target can be an element, not just an app.
267
- const elementName = ctx.dataName("elementum_element", targetAttr.label);
281
+ const elementName = dataAspectDisplayName(ctx, "element", targetAttr.label);
268
282
  if (elementName === undefined) {
269
283
  ctx.diagnostics.push(`${where}: target_id references data.elementum_element.${targetAttr.label} but the stream has no such data block; skipped`);
270
284
  return undefined;
271
285
  }
272
- target = { kind: "foreignElement", name: elementName };
286
+ const attrs = ctx.dataAttrs?.("elementum_element", targetAttr.label);
287
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
288
+ const refName = dataAspectRefName(ctx, "element", targetAttr.label, elementName);
289
+ target = {
290
+ kind: "foreignElement",
291
+ name: elementName,
292
+ ...(refName !== undefined && { refName }),
293
+ ...(namespace !== undefined && { namespace }),
294
+ };
273
295
  fieldScopeLabel = targetAttr.label;
274
296
  fieldScope = "element";
275
297
  }
298
+ else if (typeof targetAttr === "string") {
299
+ // No portable reference was available at export time (ei fell back to
300
+ // the raw platform UUID) — keep the tool with an unresolved target
301
+ // instead of dropping it entirely (board issue #648).
302
+ ctx.diagnostics.push(`${where}: target_id could not be resolved to a portable reference ("${targetAttr}"); kept as unresolved`);
303
+ target = { kind: "unresolved", uuid: targetAttr };
304
+ }
276
305
  else {
277
306
  ctx.diagnostics.push(`${where}: target_id has an unrecognized shape (${JSON.stringify(targetAttr)}); skipped`);
278
307
  return undefined;
@@ -287,7 +316,7 @@ export function skillToolFromTf(block, owner, ctx) {
287
316
  continue;
288
317
  }
289
318
  const rec = item;
290
- const fieldKey = resolveToolFieldKey(rec["field_id"], fieldScopeLabel, fieldScope);
319
+ const fieldKey = resolveToolFieldKey(rec["field_id"], fieldScopeLabel, fieldScope, ctx);
291
320
  // A field on a foreign/out-of-scope aspect has no field resource ei
292
321
  // can reference — it falls back to a bare platform id, confirmed live
293
322
  // (board issue #169). Preserve it (raw-id TODO placeholder) rather
@@ -323,6 +352,15 @@ export function skillToolFromTf(block, owner, ctx) {
323
352
  if ((subType.typeKey === "searchAspect" || subType.typeKey === "searchTable") && attrs["filter_variables"] !== undefined) {
324
353
  ctx.diagnostics.push(`${where}: filter_variables are not supported on the terraform path yet; a rebuilt stream will omit them`);
325
354
  }
355
+ let handleDescription;
356
+ if (subType.typeKey === "updateRecord") {
357
+ // A live "" is not a reconstructable value any more than a missing
358
+ // attribute is - skillUpdateRecord's own assertHandleDescriptionNotEmpty
359
+ // throws on an explicit "", so printing one straight into a
360
+ // skillUpdateRecord({...}) call would crash the next time this source
361
+ // loads. Collapse it to undefined here so the printer never sees it.
362
+ handleDescription = optionalString(attrs, "handle_description", where, ctx) || undefined;
363
+ }
326
364
  return {
327
365
  typeKey: subType.typeKey,
328
366
  ...common,
@@ -334,8 +372,6 @@ export function skillToolFromTf(block, owner, ctx) {
334
372
  ...(searchTableKey !== undefined && { searchTableKey }),
335
373
  ...(searchTableName !== undefined && { searchTableName }),
336
374
  ...(typeof attrs["result_limit"] === "number" && { limit: attrs["result_limit"] }),
337
- ...(subType.typeKey === "updateRecord" && {
338
- handleDescription: optionalString(attrs, "handle_description", where, ctx) ?? "",
339
- }),
375
+ ...(handleDescription !== undefined && { handleDescription }),
340
376
  };
341
377
  }
@@ -14,24 +14,26 @@ export interface SkillToolToTfContext {
14
14
  readonly appTfLabel: string;
15
15
  /** The owning skill's tfLabel. */
16
16
  readonly skillTfLabel: string;
17
+ /** The owning skill's bare label, included in every child tool address. */
18
+ readonly skillBareTfLabel?: string;
17
19
  /**
18
- * Cross-skill disambiguation suffix ("", "_1", "_2", …) — mirrors ei's
19
- * own tool-name collision handling across different skills in the same
20
- * app (board issue #310). Computed by the caller (`skillToTf`) via
21
- * `computeToolLabelSuffixes`; empty when absent (single-skill contexts,
22
- * most unit tests).
20
+ * Same-skill duplicate suffix ("", "_1", "_2", …). The unique parent
21
+ * skill label handles cross-skill identity; this only protects against
22
+ * repeated tool names within one skill.
23
23
  */
24
24
  readonly labelSuffix?: string;
25
25
  /** Records a foreign-app data lookup for data.tf; returns its tfLabel. */
26
- foreignAppRef(tfLabel: string, name: string): void;
26
+ foreignAppRef(tfLabel: string, name: string, namespace?: string): void;
27
27
  /** Records a foreign-ELEMENT data lookup for data.tf (board issue #42). */
28
- foreignElementRef(tfLabel: string, name: string): void;
28
+ foreignElementRef(tfLabel: string, name: string, namespace?: string): void;
29
29
  /** Records an object-scoped data lookup owned by a foreign app/element. */
30
30
  foreignFieldRef(type: string, tfLabel: string, objectId: TfValue, name: string): void;
31
31
  /** App/element roots authored in this same workspace. */
32
32
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
33
33
  /** Records an app-scoped service-account lookup by name. */
34
34
  serviceAccountRef?(tfLabel: string, name: string): TfValue | void;
35
+ /** App-local automations whose publish resource will be emitted in this build. */
36
+ readonly activeAutomationRefNames?: ReadonlySet<string>;
35
37
  /** Degradations land here — reported by the caller, never silent. */
36
38
  readonly diagnostics: string[];
37
39
  }
@@ -7,8 +7,10 @@
7
7
  * Mirrors `entities/agent-tool/to-tf.ts`.
8
8
  */
9
9
  import { workspaceAspectKey } from "../../engine/build/context.js";
10
- import { appScopedResourceLabel, expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
10
+ import { automationRunTargetResourceAttr } from "../automation/to-tf.js";
11
+ import { appScopedResourceLabel, childPartFromScopedLabel, expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
11
12
  import { fieldRefToTfValue } from "../field/to-tf.js";
13
+ import { encodeOptionalHandleDescription } from "../shared/handle-description.js";
12
14
  import { SKILL_TOOL_SUB_TYPE_BY_TYPE_KEY } from "./types.js";
13
15
  function serviceAccountIdValue(token, where, ctx) {
14
16
  if (token.__kind !== "serviceAccount" || token.name === undefined || token.name === "") {
@@ -49,12 +51,11 @@ function targetIdValue(token, ctx) {
49
51
  localTfLabel: sibling.tfLabel,
50
52
  };
51
53
  }
52
- // ei derives foreign-app/foreign-element data labels from the display NAME.
53
54
  const name = token.name ?? refName;
54
- const tfLabel = sanitizeName(name);
55
+ const tfLabel = sanitizeName(token.namespace ?? name);
55
56
  // Board issue #42: an aspect token can be an element, not just an app.
56
57
  if (kind === "element") {
57
- ctx.foreignElementRef(tfLabel, name);
58
+ ctx.foreignElementRef(tfLabel, name, token.namespace);
58
59
  return {
59
60
  value: expr.dataAttr("elementum_element", tfLabel, ["id"]),
60
61
  refName,
@@ -62,7 +63,7 @@ function targetIdValue(token, ctx) {
62
63
  foreignTfLabel: tfLabel,
63
64
  };
64
65
  }
65
- ctx.foreignAppRef(tfLabel, name);
66
+ ctx.foreignAppRef(tfLabel, name, token.namespace);
66
67
  return {
67
68
  value: expr.dataAttr("elementum_app", tfLabel, ["id"]),
68
69
  refName,
@@ -140,7 +141,8 @@ export function skillToolToTf(entry, ctx) {
140
141
  return undefined;
141
142
  }
142
143
  const where = `skill tool "${name}"`;
143
- const tfLabel = appScopedResourceLabel(ctx.appTfLabel, `${sanitizeName(name)}${ctx.labelSuffix ?? ""}`);
144
+ const skillBareTfLabel = ctx.skillBareTfLabel ?? childPartFromScopedLabel(ctx.appTfLabel, ctx.skillTfLabel, "app");
145
+ const tfLabel = appScopedResourceLabel(ctx.appTfLabel, `${skillBareTfLabel}_${sanitizeName(name)}${ctx.labelSuffix ?? ""}`);
144
146
  const attrs = {
145
147
  skill_id: expr.resourceAttr("elementum_agentic_skill", ctx.skillTfLabel, ["id"]),
146
148
  app_id: expr.resourceAttr("elementum_app", ctx.appTfLabel, ["id"]),
@@ -168,20 +170,28 @@ export function skillToolToTf(entry, ctx) {
168
170
  }
169
171
  if (typeKey === "automation") {
170
172
  const automation = inner.automationId;
171
- const automationTfLabel = typeof automation?.refName === "string" && automation.refName !== ""
172
- ? tsLabelToTfLabel(automation.refName)
173
- : typeof automation?.name === "string" && automation.name !== ""
174
- ? sanitizeName(automation.name)
175
- : undefined;
176
- if (automationTfLabel === undefined) {
177
- ctx.diagnostics.push(`${where}: no target automation token; dropped`);
178
- return undefined;
173
+ if (automation?.__unsafe === "platformId" && typeof automation.value === "string" && automation.value !== "") {
174
+ attrs["automation_id"] = automation.value;
179
175
  }
180
- if (automation?.parent !== undefined && automation.parent !== ctx.appRefName) {
181
- ctx.diagnostics.push(`${where}: cross-app automation targets are not supported; dropped`);
182
- return undefined;
176
+ else {
177
+ const automationTfLabel = typeof automation?.refName === "string" && automation.refName !== ""
178
+ ? tsLabelToTfLabel(automation.refName)
179
+ : typeof automation?.name === "string" && automation.name !== ""
180
+ ? sanitizeName(automation.name)
181
+ : undefined;
182
+ if (automationTfLabel === undefined) {
183
+ ctx.diagnostics.push(`${where}: no target automation token; dropped`);
184
+ return undefined;
185
+ }
186
+ if (automation?.parent !== undefined && automation.parent !== ctx.appRefName) {
187
+ ctx.diagnostics.push(`${where}: cross-app automation targets are not supported; dropped`);
188
+ return undefined;
189
+ }
190
+ const automationRefName = typeof automation?.refName === "string" && automation.refName !== ""
191
+ ? automation.refName
192
+ : automationTfLabel;
193
+ attrs["automation_id"] = automationRunTargetResourceAttr(ctx.appTfLabel, automationRefName, ctx.activeAutomationRefNames);
183
194
  }
184
- attrs["automation_id"] = expr.resourceAttr("elementum_workflow_publish", appScopedResourceLabel(ctx.appTfLabel, automationTfLabel), ["id"]);
185
195
  if (inner.inputs !== undefined && inner.inputs.length > 0) {
186
196
  attrs["inputs"] = inner.inputs.map((input) => ({
187
197
  parameter_name: input.parameterName ?? "",
@@ -247,11 +257,7 @@ export function skillToolToTf(entry, ctx) {
247
257
  }
248
258
  }
249
259
  if (typeKey === "updateRecord") {
250
- if (inner.handleDescription === undefined || inner.handleDescription === "") {
251
- ctx.diagnostics.push(`${where}: no handleDescription; dropped`);
252
- return undefined;
253
- }
254
- attrs["handle_description"] = inner.handleDescription;
260
+ encodeOptionalHandleDescription(attrs, inner.handleDescription);
255
261
  }
256
262
  if (typeKey === "searchAspect" || typeKey === "searchTable") {
257
263
  attrs["query_description"] = inner.queryDescription ?? "";
@@ -2,6 +2,7 @@ import { workspaceAspectKey, } from "../../engine/build/context.js";
2
2
  import { EntityTfError } from "../../engine/entity.js";
3
3
  import { expr, sanitizeName, tsLabelToTfLabel, } from "../../engine/tf/index.js";
4
4
  import { CATEGORY_ORG_BAG } from "../org/category.js";
5
+ import { categoryIdExpr, missingCategoryDiagnostic } from "../org/category-ref.js";
5
6
  import { CLOUD_LINK_ORG_BAG } from "../org/cloud-link.js";
6
7
  import { tableDataminesToTf, } from "../datamine/to-tf.js";
7
8
  import { fieldRefToTfValue } from "../field/to-tf.js";
@@ -24,6 +25,9 @@ function aspectId(ref, orgRefs, workspaceAspects, diagnostics, where = "table as
24
25
  return ref;
25
26
  const name = ref.name ?? ref.refName ?? "";
26
27
  if (ref.__kind === "table") {
28
+ const local = workspaceAspects?.get(workspaceAspectKey("table", ref.refName ?? ""));
29
+ if (local !== undefined)
30
+ return expr.resourceAttr(TABLE_RESOURCE_TYPE, local.tfLabel, ["id"]);
27
31
  return resolveForeignRef("table", { name }, orgRefs, diagnostics, where).value;
28
32
  }
29
33
  if (ref.__kind === "element") {
@@ -41,6 +45,9 @@ function aspectId(ref, orgRefs, workspaceAspects, diagnostics, where = "table as
41
45
  throw new EntityTfError(`table source must be an app, element, table, or raw id`);
42
46
  }
43
47
  function fieldId(value, orgRefs, ownRef, ownLabel, ownColumnNames, workspaceAspects, diagnostics) {
48
+ if (value === undefined || value === null) {
49
+ throw new EntityTfError(`table column source is missing — usually org.tables.<source>.columns.<key> did not resolve (re-pull the source table, or check the catalog column key)`);
50
+ }
44
51
  if (typeof value === "string")
45
52
  return value;
46
53
  if (value !== null &&
@@ -60,8 +67,19 @@ function fieldId(value, orgRefs, ownRef, ownLabel, ownColumnNames, workspaceAspe
60
67
  { index: name },
61
68
  ]);
62
69
  }
70
+ // A column of a table this same build owns resolves straight to that
71
+ // table's `field_ids`. `ref.parent` is the source table's refName, not its
72
+ // display name, so the foreign path below would look it up under a name
73
+ // the platform has never heard of.
74
+ const sibling = workspaceAspects?.get(workspaceAspectKey("table", ref.parent ?? ""));
75
+ if (sibling !== undefined) {
76
+ return expr.resourceAttr(TABLE_RESOURCE_TYPE, sibling.tfLabel, [
77
+ "field_ids",
78
+ { index: ref.name ?? ref.refName ?? "" },
79
+ ]);
80
+ }
63
81
  const tableLabel = sanitizeName(ref.parent ?? "table");
64
- orgRefs.rawLookup("elementum_table", tableLabel, ref.parent ?? "");
82
+ orgRefs.rawLookup("elementum_table", tableLabel, ref.parentName ?? ref.parent ?? "");
65
83
  const fieldLabel = sanitizeName(`${ref.parent ?? "table"}_${ref.refName ?? ref.name ?? "field"}`);
66
84
  orgRefs.foreignField("elementum_field", fieldLabel, expr.dataAttr("elementum_table", tableLabel, ["id"]), ref.name ?? ref.refName ?? "");
67
85
  return expr.dataAttr("elementum_field", fieldLabel, ["id"]);
@@ -109,10 +127,8 @@ export function tableToTf(entity, ctx) {
109
127
  ? ctx.orgRefs.byTsLabel(CATEGORY_ORG_BAG, categoryRefName)
110
128
  : undefined;
111
129
  if (category === undefined)
112
- throw new EntityTfError(`table ${JSON.stringify(p.name)}: category ${JSON.stringify(categoryRefName ?? "")} is not in the org catalog`);
113
- attrs["category_id"] = expr.dataAttr("elementum_category", category.tfLabel, [
114
- "id",
115
- ]);
130
+ throw new EntityTfError(`table ${JSON.stringify(p.name)}: ${missingCategoryDiagnostic(categoryRefName ?? "")}`);
131
+ attrs["category_id"] = categoryIdExpr(category);
116
132
  if (p.source !== undefined)
117
133
  attrs["source_id"] = aspectId(p.source, ctx.orgRefs, ctx.workspaceAspects, ctx.diagnostics, "table source");
118
134
  for (const key of ["description", "icon", "color"])
@@ -1,6 +1,7 @@
1
1
  import { EntityTfError } from "../../engine/entity.js";
2
2
  import { expr } from "../../engine/tf/index.js";
3
3
  import { CATEGORY_ORG_BAG } from "../org/category.js";
4
+ import { categoryIdExpr, missingCategoryDiagnostic } from "../org/category-ref.js";
4
5
  import { CLOUD_LINK_ORG_BAG } from "../org/cloud-link.js";
5
6
  import { TASK_RESOURCE_TYPE } from "./module.js";
6
7
  export function taskToTf(entity, ctx) {
@@ -13,9 +14,9 @@ export function taskToTf(entity, ctx) {
13
14
  const categoryRefName = p.category?.refName;
14
15
  const category = categoryRefName ? ctx.orgRefs.byTsLabel(CATEGORY_ORG_BAG, categoryRefName) : undefined;
15
16
  if (category === undefined)
16
- ctx.diagnostics.push(`task ${JSON.stringify(p.name)}: category ${JSON.stringify(categoryRefName ?? "")} is not in the org catalog`);
17
+ ctx.diagnostics.push(`task ${JSON.stringify(p.name)}: ${missingCategoryDiagnostic(categoryRefName ?? "")}`);
17
18
  else
18
- attrs["category_id"] = expr.dataAttr("elementum_category", category.tfLabel, ["id"]);
19
+ attrs["category_id"] = categoryIdExpr(category);
19
20
  if (p.cloudLink?.refName) {
20
21
  const link = ctx.orgRefs.byTsLabel(CLOUD_LINK_ORG_BAG, p.cloudLink.refName);
21
22
  if (link === undefined)
@@ -8,18 +8,19 @@
8
8
  import { optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
9
9
  import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
10
10
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
11
- import { fieldKeyFromTfRef } from "../field/from-tf.js";
11
+ import { fieldKeyFromTfValue } from "../field/from-tf.js";
12
12
  import { DASHBOARD_RESOURCE_TYPE } from "../dashboard/module.js";
13
13
  import { filterFromTf, principalList } from "../access-policy/from-tf.js";
14
14
  import { listViewDensity, } from "./build.js";
15
15
  import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, GROUP_SECTION_WIRE_TYPE, KNOWN_AGENT_VIEW_ATTRS, KNOWN_CALENDAR_VIEW_ATTRS, KNOWN_DASHBOARD_VIEW_ATTRS, KNOWN_KANBAN_VIEW_ATTRS, KNOWN_LAYOUT_ATTRS, KNOWN_LAYOUT_SECTION_ATTRS, KNOWN_LIST_VIEW_ATTRS, KNOWN_MANAGED_VIEW_ORDER_ATTRS, LIST_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, SECTION_TYPE_FROM_WIRE, SYSTEM_FIELD_KEY_BY_ID_ATTR, UPDATE_SECTION_WIRE_TYPE, } from "./types.js";
16
- function viewFilter(value, owner, where) {
16
+ function viewFilter(value, owner, where, ctx) {
17
17
  return value === undefined ? undefined : filterFromTf(value, {
18
18
  type: owner.type,
19
19
  label: owner.label,
20
20
  ownerRefName: tfLabelToTsLabel(owner.label),
21
21
  ownerTfLabel: owner.ownerTfLabel,
22
22
  scope: owner.scope ?? "app",
23
+ foreignFieldRefsById: ctx.foreignFieldRefsById,
23
24
  }, `${where}.filter`);
24
25
  }
25
26
  /** All three view resource kinds → the normalized shapes the app printer consumes. */
@@ -104,7 +105,7 @@ function dashboardViewFromTf(block, owner, ctx) {
104
105
  const sort = managedViewSortFromTf(attrs["sort"], owner, where, ctx);
105
106
  const userIds = principalList(attrs["user_ids"], "elementum_user", `${where}: user_ids`, ctx);
106
107
  const groupIds = principalList(attrs["group_ids"], "elementum_group", `${where}: group_ids`, ctx);
107
- const filter = viewFilter(attrs["filter"], owner, where);
108
+ const filter = viewFilter(attrs["filter"], owner, where, ctx);
108
109
  return {
109
110
  key: scopedLabelToBagKey(owner.ownerTfLabel, label, scope),
110
111
  name: optionalString(attrs, "name", where, ctx) ?? "",
@@ -161,7 +162,7 @@ function typedFieldViewFromTf(block, owner, resourceType, knownAttrs, includeAll
161
162
  const sort = managedViewSortFromTf(attrs["sort"], owner, where, ctx);
162
163
  const userIds = principalList(attrs["user_ids"], "elementum_user", `${where}: user_ids`, ctx);
163
164
  const groupIds = principalList(attrs["group_ids"], "elementum_group", `${where}: group_ids`, ctx);
164
- const filter = viewFilter(attrs["filter"], owner, where);
165
+ const filter = viewFilter(attrs["filter"], owner, where, ctx);
165
166
  return {
166
167
  key: scopedLabelToBagKey(owner.ownerTfLabel, label, scope),
167
168
  name: optionalString(attrs, "name", where, ctx) ?? "",
@@ -197,7 +198,7 @@ function agentViewFromTf(block, owner, ctx) {
197
198
  const sort = managedViewSortFromTf(attrs["sort"], owner, where, ctx);
198
199
  const userIds = principalList(attrs["user_ids"], "elementum_user", `${where}: user_ids`, ctx);
199
200
  const groupIds = principalList(attrs["group_ids"], "elementum_group", `${where}: group_ids`, ctx);
200
- const filter = viewFilter(attrs["filter"], owner, where);
201
+ const filter = viewFilter(attrs["filter"], owner, where, ctx);
201
202
  return {
202
203
  key: scopedLabelToBagKey(owner.ownerTfLabel, label, scope),
203
204
  name: optionalString(attrs, "name", where, ctx) ?? "",
@@ -220,8 +221,33 @@ function layoutFromTf(block, owner, ctx) {
220
221
  ctx.diagnostics.push(`${where}: object_id does not reference ${owner.type}.${owner.label}; skipped`);
221
222
  return undefined;
222
223
  }
223
- const stageKey = stageKeyFromTf(attrs["stage_id"], owner.label);
224
224
  const scope = owner.scope ?? "app";
225
+ // Elements carry no stage_ids_by_key at all (see element/locals.ts) - an
226
+ // element's stage_id is always "" (build-side, see view/to-tf.ts's
227
+ // layoutToTf) or the platform's own Initiate stage id (a live pull) -
228
+ // neither resolves through stageKeyFromTf. But an element has exactly one
229
+ // possible layout, so "which stage" is never actually ambiguous the way
230
+ // it is for apps: always use the synthetic "layout" key, deterministically,
231
+ // with no diagnostic - matching both elementToTf's own bag key and the
232
+ // bridge's ei-side resource label convention (hcl_app.go's generateLayoutIR:
233
+ // "<prefix>_layout", a fixed suffix, not stage-name-derived) so a re-adopt
234
+ // resolves to the SAME terraform address instead of planning a replace.
235
+ if (scope === "element") {
236
+ const sectionsAttr = attrs["sections"];
237
+ const sections = [];
238
+ if (Array.isArray(sectionsAttr)) {
239
+ for (const item of sectionsAttr) {
240
+ const section = sectionFromTf(item, owner.label, owner.ownerTfLabel, scope, where, ctx);
241
+ if (section !== undefined)
242
+ sections.push(section);
243
+ }
244
+ }
245
+ else if (sectionsAttr !== undefined) {
246
+ ctx.diagnostics.push(`${where}: sections is not a list; dropped`);
247
+ }
248
+ return { stageKey: "layout", sections };
249
+ }
250
+ const stageKey = stageKeyFromTf(attrs["stage_id"], owner.label);
225
251
  const labelStageKey = scopedLabelToBagKey(owner.ownerTfLabel, label, scope);
226
252
  const canInferStageKey = typeof attrs["stage_id"] === "string" && owner.stageKeys?.has(labelStageKey) === true;
227
253
  if (stageKey === undefined && !canInferStageKey) {
@@ -296,6 +322,9 @@ function sectionFromTf(raw, ownerLabel, ownerTfLabel, scope, where, ctx) {
296
322
  }
297
323
  /** A `field_ids`/`columns` entry → a system-field key or a custom field's bag key. */
298
324
  function fieldRefFromTf(v, ownerLabel, ownerTfLabel, scope, ctx) {
325
+ const fieldKey = fieldKeyFromTfValue(v, tfLabelToTsLabel(ownerLabel), ownerTfLabel, scope, ctx);
326
+ if (fieldKey !== undefined)
327
+ return fieldKey;
299
328
  if (!isTfExpr(v)) {
300
329
  ctx.diagnostics.push(`field reference has an unrecognized (non-expression) shape; dropped`);
301
330
  return undefined;
@@ -308,9 +337,6 @@ function fieldRefFromTf(v, ownerLabel, ownerTfLabel, scope, ctx) {
308
337
  }
309
338
  // Custom field ref resolution is shared with agent-tool's field refs
310
339
  // (src/entities/agent-tool/from-tf.ts) via entities/field/from-tf.ts.
311
- const fieldKey = fieldKeyFromTfRef(v, ownerTfLabel, scope);
312
- if (fieldKey !== undefined)
313
- return fieldKey;
314
340
  ctx.diagnostics.push(`field reference ${JSON.stringify(v)} does not resolve to a known field; dropped`);
315
341
  return undefined;
316
342
  }
@@ -350,7 +376,7 @@ function listViewFromTf(block, owner, ctx) {
350
376
  // reported non-null) on ANY list view with either attribute set. Round-
351
377
  // round-tripping both values avoids ever manufacturing that diff. Filters
352
378
  // and sorts decode through their shared typed codecs.
353
- const filter = viewFilter(attrs["filter"], owner, where);
379
+ const filter = viewFilter(attrs["filter"], owner, where, ctx);
354
380
  const sort = managedViewSortFromTf(attrs["sort"], owner, where, ctx);
355
381
  const density = listViewDensityFromTf(attrs["density"], where, ctx);
356
382
  const userIds = principalList(attrs["user_ids"], "elementum_user", `${where}: user_ids`, ctx);
@@ -99,6 +99,8 @@ export interface ViewToTfOptions {
99
99
  /** Declared sibling dashboard keys, for fail-fast dashboard-view references. */
100
100
  readonly dashboardKeys?: ReadonlySet<string>;
101
101
  readonly orgRefs?: OrgRefLookup;
102
+ /** Known emitted field addresses keyed by field bag key, for robust reference resolution. */
103
+ readonly fieldAddresses?: ReadonlyMap<string, string>;
102
104
  /** Degradations land here — reported by the caller, never silent. */
103
105
  readonly diagnostics: string[];
104
106
  }