@elementumai/edk 0.8.0-preview.11 → 0.8.1

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 (165) hide show
  1. package/README.md +378 -324
  2. package/dist-sdk/src/catalog/ai-provider-models.d.ts +30 -0
  3. package/dist-sdk/src/catalog/ai-provider-models.js +63 -0
  4. package/dist-sdk/src/catalog/factories.d.ts +56 -3
  5. package/dist-sdk/src/catalog/factories.js +65 -2
  6. package/dist-sdk/src/catalog/from-authoring.js +6 -1
  7. package/dist-sdk/src/catalog/index.d.ts +3 -2
  8. package/dist-sdk/src/catalog/index.js +3 -2
  9. package/dist-sdk/src/catalog/org.d.ts +1 -1
  10. package/dist-sdk/src/catalog/org.js +83 -6
  11. package/dist-sdk/src/catalog/render.d.ts +13 -1
  12. package/dist-sdk/src/catalog/render.js +21 -4
  13. package/dist-sdk/src/catalog/token.js +14 -0
  14. package/dist-sdk/src/catalog/types.d.ts +60 -3
  15. package/dist-sdk/src/catalog/types.js +3 -0
  16. package/dist-sdk/src/core/system-fields.d.ts +2 -0
  17. package/dist-sdk/src/core/system-fields.js +2 -0
  18. package/dist-sdk/src/core/types/ai-provider.d.ts +10 -23
  19. package/dist-sdk/src/core/types/ai-provider.js +1 -25
  20. package/dist-sdk/src/core/types/app.d.ts +20 -1
  21. package/dist-sdk/src/engine/build/context.d.ts +18 -0
  22. package/dist-sdk/src/engine/build/source-context.d.ts +45 -0
  23. package/dist-sdk/src/engine/build/source-context.js +23 -0
  24. package/dist-sdk/src/engine/pull/context.d.ts +15 -0
  25. package/dist-sdk/src/engine/pull/org.d.ts +10 -0
  26. package/dist-sdk/src/engine/pull/org.js +34 -4
  27. package/dist-sdk/src/engine/tf/index.d.ts +1 -1
  28. package/dist-sdk/src/engine/tf/index.js +1 -1
  29. package/dist-sdk/src/engine/tf/labels.d.ts +45 -0
  30. package/dist-sdk/src/engine/tf/labels.js +71 -0
  31. package/dist-sdk/src/entities/access-policy/build.d.ts +26 -0
  32. package/dist-sdk/src/entities/access-policy/build.js +7 -0
  33. package/dist-sdk/src/entities/access-policy/filter.d.ts +61 -0
  34. package/dist-sdk/src/entities/access-policy/filter.js +83 -0
  35. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +48 -0
  36. package/dist-sdk/src/entities/access-policy/from-tf.js +189 -0
  37. package/dist-sdk/src/entities/access-policy/module.d.ts +3 -0
  38. package/dist-sdk/src/entities/access-policy/module.js +17 -0
  39. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +36 -0
  40. package/dist-sdk/src/entities/access-policy/to-tf.js +149 -0
  41. package/dist-sdk/src/entities/access-policy/types.d.ts +4 -0
  42. package/dist-sdk/src/entities/access-policy/types.js +10 -0
  43. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +38 -3
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +199 -32
  45. package/dist-sdk/src/entities/agent/from-tf.d.ts +18 -3
  46. package/dist-sdk/src/entities/agent/from-tf.js +135 -15
  47. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  48. package/dist-sdk/src/entities/agent/module.js +8 -2
  49. package/dist-sdk/src/entities/agent/to-tf.js +62 -10
  50. package/dist-sdk/src/entities/agent/tools.d.ts +88 -9
  51. package/dist-sdk/src/entities/agent/tools.js +46 -7
  52. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +51 -4
  53. package/dist-sdk/src/entities/agent-tool/from-tf.js +131 -35
  54. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +4 -2
  55. package/dist-sdk/src/entities/agent-tool/to-tf.js +103 -17
  56. package/dist-sdk/src/entities/agent-tool/types.d.ts +5 -4
  57. package/dist-sdk/src/entities/agent-tool/types.js +38 -6
  58. package/dist-sdk/src/entities/app/build.d.ts +63 -13
  59. package/dist-sdk/src/entities/app/build.js +48 -1
  60. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +3 -0
  61. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -1
  62. package/dist-sdk/src/entities/app/from-tf.js +32 -15
  63. package/dist-sdk/src/entities/app/index.d.ts +4 -1
  64. package/dist-sdk/src/entities/app/index.js +2 -1
  65. package/dist-sdk/src/entities/app/module.js +9 -2
  66. package/dist-sdk/src/entities/app/to-tf.d.ts +5 -0
  67. package/dist-sdk/src/entities/app/to-tf.js +33 -4
  68. package/dist-sdk/src/entities/automation/build.d.ts +57 -13
  69. package/dist-sdk/src/entities/automation/build.js +48 -36
  70. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +25 -8
  71. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +16 -1
  72. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +179 -43
  73. package/dist-sdk/src/entities/automation/filter.d.ts +15 -3
  74. package/dist-sdk/src/entities/automation/filter.js +12 -2
  75. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -27
  76. package/dist-sdk/src/entities/automation/from-tf.js +1229 -223
  77. package/dist-sdk/src/entities/automation/index.d.ts +4 -0
  78. package/dist-sdk/src/entities/automation/index.js +4 -0
  79. package/dist-sdk/src/entities/automation/module.js +29 -32
  80. package/dist-sdk/src/entities/automation/operators.d.ts +29 -2
  81. package/dist-sdk/src/entities/automation/operators.js +27 -1
  82. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +19 -0
  83. package/dist-sdk/src/entities/automation/output-key-wire-name.js +24 -0
  84. package/dist-sdk/src/entities/automation/script-code.d.ts +10 -21
  85. package/dist-sdk/src/entities/automation/script-code.js +272 -5
  86. package/dist-sdk/src/entities/automation/tasks.d.ts +125 -19
  87. package/dist-sdk/src/entities/automation/tasks.js +83 -15
  88. package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -29
  89. package/dist-sdk/src/entities/automation/to-tf.js +1134 -231
  90. package/dist-sdk/src/entities/automation/triggers.d.ts +9 -1
  91. package/dist-sdk/src/entities/automation/types.d.ts +29 -4
  92. package/dist-sdk/src/entities/automation/types.js +76 -46
  93. package/dist-sdk/src/entities/element/build.d.ts +23 -10
  94. package/dist-sdk/src/entities/element/build.js +1 -0
  95. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -1
  96. package/dist-sdk/src/entities/element/from-tf.js +18 -3
  97. package/dist-sdk/src/entities/element/index.d.ts +4 -1
  98. package/dist-sdk/src/entities/element/index.js +2 -1
  99. package/dist-sdk/src/entities/element/module.js +3 -1
  100. package/dist-sdk/src/entities/element/to-tf.js +21 -3
  101. package/dist-sdk/src/entities/field/build.d.ts +56 -13
  102. package/dist-sdk/src/entities/field/build.js +10 -0
  103. package/dist-sdk/src/entities/field/calc/runtime.js +4 -0
  104. package/dist-sdk/src/entities/field/from-tf.d.ts +5 -3
  105. package/dist-sdk/src/entities/field/from-tf.js +118 -7
  106. package/dist-sdk/src/entities/field/module.js +3 -2
  107. package/dist-sdk/src/entities/field/to-tf.d.ts +27 -9
  108. package/dist-sdk/src/entities/field/to-tf.js +62 -17
  109. package/dist-sdk/src/entities/field/types.d.ts +26 -0
  110. package/dist-sdk/src/entities/field/types.js +34 -12
  111. package/dist-sdk/src/entities/file-reader/build.d.ts +108 -50
  112. package/dist-sdk/src/entities/file-reader/build.js +23 -23
  113. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.d.ts +6 -0
  114. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +109 -0
  115. package/dist-sdk/src/entities/file-reader/from-tf.d.ts +13 -0
  116. package/dist-sdk/src/entities/file-reader/from-tf.js +172 -0
  117. package/dist-sdk/src/entities/file-reader/index.d.ts +8 -3
  118. package/dist-sdk/src/entities/file-reader/index.js +7 -2
  119. package/dist-sdk/src/entities/file-reader/module.d.ts +3 -0
  120. package/dist-sdk/src/entities/file-reader/module.js +115 -0
  121. package/dist-sdk/src/entities/file-reader/to-tf.d.ts +14 -0
  122. package/dist-sdk/src/entities/file-reader/to-tf.js +84 -0
  123. package/dist-sdk/src/entities/file-reader/types.d.ts +32 -0
  124. package/dist-sdk/src/entities/file-reader/types.js +30 -0
  125. package/dist-sdk/src/entities/org/ai-provider.d.ts +13 -0
  126. package/dist-sdk/src/entities/org/ai-provider.js +46 -0
  127. package/dist-sdk/src/entities/org/connector.d.ts +8 -1
  128. package/dist-sdk/src/entities/org/connector.js +12 -14
  129. package/dist-sdk/src/entities/org/group.js +10 -1
  130. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  131. package/dist-sdk/src/entities/org/index.js +1 -0
  132. package/dist-sdk/src/entities/org/user.js +10 -1
  133. package/dist-sdk/src/entities/shared/filters/ast.d.ts +44 -9
  134. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  135. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +17 -0
  136. package/dist-sdk/src/entities/shared/tool-field-ref.js +31 -0
  137. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -1
  138. package/dist-sdk/src/entities/shared/types/field-types.js +9 -0
  139. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +19 -0
  140. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +36 -8
  141. package/dist-sdk/src/entities/skill/from-tf.js +4 -3
  142. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  143. package/dist-sdk/src/entities/skill/module.js +6 -1
  144. package/dist-sdk/src/entities/skill/to-tf.js +3 -2
  145. package/dist-sdk/src/entities/skill/tools.d.ts +25 -3
  146. package/dist-sdk/src/entities/skill/tools.js +17 -0
  147. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +15 -2
  148. package/dist-sdk/src/entities/skill-tool/from-tf.js +32 -11
  149. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -0
  150. package/dist-sdk/src/entities/skill-tool/to-tf.js +32 -9
  151. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -2
  152. package/dist-sdk/src/entities/view/from-tf.js +11 -9
  153. package/dist-sdk/src/entities/view/to-tf.d.ts +9 -7
  154. package/dist-sdk/src/entities/view/to-tf.js +33 -18
  155. package/dist-sdk/src/entities/view/types.d.ts +1 -1
  156. package/dist-sdk/src/entities/view/types.js +1 -1
  157. package/dist-sdk/src/graph/deferred-catalog-render.d.ts +0 -5
  158. package/dist-sdk/src/graph/deferred-catalog-render.js +1 -20
  159. package/dist-sdk/src/graph/index.d.ts +8 -0
  160. package/dist-sdk/src/graph/index.js +13 -9
  161. package/dist-sdk/src/graph/modules.js +6 -1
  162. package/dist-sdk/src/graph/types.d.ts +77 -3
  163. package/package.json +42 -14
  164. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +0 -76
  165. package/dist-sdk/src/entities/automation/value-ref-tf.js +0 -190
@@ -9,6 +9,15 @@
9
9
  /**
10
10
  * Map from user-friendly type names (used in the SDK's onDemand input
11
11
  * schema) to the platform's WorkflowFieldType value.
12
+ *
13
+ * `attachmentId` is the odd one out: `elementum_on_demand_trigger`'s own
14
+ * `parameters[].type` terraform attribute (on_demand_trigger_resource.go)
15
+ * only validates a bare "attachment" - there is no "attachment_id" spelling
16
+ * at that layer, unlike every other row here where the wire string is just
17
+ * the WorkflowFieldType name lowercased. automation/to-tf.ts special-cases
18
+ * ATTACHMENT_ID -> "attachment" (and from-tf.ts the inverse) rather than
19
+ * renaming this alias, to avoid a breaking change to authored `onDemand({})`
20
+ * calls that already use `type: "attachmentId"`.
12
21
  */
13
22
  export const FIELD_TYPE_MAP = {
14
23
  text: "TEXT",
@@ -16,5 +16,24 @@ import type { NormalizedSkill } from "../from-tf.js";
16
16
  export interface PrintSkillV2Options {
17
17
  /** The owning app's refName — `parent:` and the catalog token root. */
18
18
  readonly appRefName: string;
19
+ /**
20
+ * Set for a cross-org clone: a foreign-app tool target was resolved
21
+ * against the SOURCE org, so it's flagged as a TODO for manual review
22
+ * instead of silently carried over — same treatment as agent tools
23
+ * (`src/entities/agent/deserializer/print-agent-v2.ts`).
24
+ */
25
+ readonly crossOrg?: boolean;
26
+ /**
27
+ * Name → refName for every app already on disk in this workspace (board
28
+ * issue #40). A foreign-app tool target whose name is a key here prints
29
+ * `catalog.<refName>` instead of the always-safe literal stub.
30
+ */
31
+ readonly foreignAppRefNames?: ReadonlyMap<string, string>;
32
+ /**
33
+ * Same as {@link foreignAppRefNames}, keyed for elements (board issue
34
+ * #42) — a `foreignElement` tool target whose name is a key here prints
35
+ * `catalog.<refName>` instead of the literal stub.
36
+ */
37
+ readonly foreignElementRefNames?: ReadonlyMap<string, string>;
19
38
  }
20
39
  export declare function printSkillV2(skill: NormalizedSkill, opts: PrintSkillV2Options): string;
@@ -20,8 +20,12 @@ const TOOL_FACTORY_BY_TYPE_KEY = {
20
20
  };
21
21
  export function printSkillV2(skill, opts) {
22
22
  const { appRefName } = opts;
23
+ const crossOrg = opts.crossOrg === true;
23
24
  const factories = [...new Set(skill.tools.map((t) => TOOL_FACTORY_BY_TYPE_KEY[t.typeKey]).filter(Boolean))].sort();
24
- const usesCatalog = skill.tools.some((t) => t.target.kind === "self" || (t.fields !== undefined && t.fields.length > 0));
25
+ const usesCatalog = skill.tools.some((t) => t.target.kind === "self" ||
26
+ (t.fields !== undefined && t.fields.length > 0) ||
27
+ (t.target.kind === "foreignApp" && opts.foreignAppRefNames?.has(t.target.name)) ||
28
+ (t.target.kind === "foreignElement" && opts.foreignElementRefNames?.has(t.target.name)));
25
29
  const lines = [];
26
30
  lines.push("/**");
27
31
  lines.push(` * ${skill.name}`);
@@ -47,7 +51,7 @@ export function printSkillV2(skill, opts) {
47
51
  if (skill.tools.length > 0) {
48
52
  lines.push(" tools: [");
49
53
  for (const tool of skill.tools) {
50
- lines.push(...printTool(tool, appRefName).map((l) => ` ${l}`));
54
+ lines.push(...printTool(tool, appRefName, crossOrg, opts.foreignAppRefNames, opts.foreignElementRefNames).map((l) => ` ${l}`));
51
55
  }
52
56
  lines.push(" ],");
53
57
  }
@@ -57,7 +61,7 @@ export function printSkillV2(skill, opts) {
57
61
  lines.push("");
58
62
  return lines.join("\n");
59
63
  }
60
- function printTool(tool, appRefName) {
64
+ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElementRefNames) {
61
65
  const factory = TOOL_FACTORY_BY_TYPE_KEY[tool.typeKey] ?? "skillSearchAspect";
62
66
  const lines = [`${factory}({`];
63
67
  lines.push(` name: ${quote(tool.name)},`);
@@ -70,9 +74,27 @@ function printTool(tool, appRefName) {
70
74
  lines.push(` aspect: catalog.${appRefName},`);
71
75
  }
72
76
  else {
73
- // The foreign app's catalog may not exist in this workspace — a literal
74
- // token compiles and deploys; swap for a catalog token when available.
75
- lines.push(` aspect: { __kind: "app", refName: ${quote(tool.target.name)}, name: ${quote(tool.target.name)} },`);
77
+ // Board issue #42: the target can be a foreign APP or a foreign
78
+ // ELEMENT — each stub carries the right `__kind` and is looked up
79
+ // against its own map, never conflated.
80
+ const entityKind = tool.target.kind === "foreignElement" ? "element" : "app";
81
+ const refNames = tool.target.kind === "foreignElement" ? foreignElementRefNames : foreignAppRefNames;
82
+ const foreignRefName = refNames?.get(tool.target.name);
83
+ if (foreignRefName !== undefined) {
84
+ // The dependency is already pulled into this workspace (board issue
85
+ // #40) — a typed token, not a stub.
86
+ lines.push(` aspect: catalog.${foreignRefName},`);
87
+ }
88
+ else {
89
+ // The foreign app/element's catalog may not exist in this workspace —
90
+ // a literal token compiles and deploys; swap for a catalog token when
91
+ // available (`edk pull app`/`edk pull element` reports missing
92
+ // dependencies like this one).
93
+ const todo = crossOrg
94
+ ? ` // TODO: cross-org clone — "${tool.target.name}" was resolved in the SOURCE org; verify it exists (with this name) in the destination org`
95
+ : "";
96
+ lines.push(` aspect: { __kind: ${quote(entityKind)}, refName: ${quote(tool.target.name)}, name: ${quote(tool.target.name)} },${todo}`);
97
+ }
76
98
  }
77
99
  if (tool.typeKey === "searchAspect") {
78
100
  lines.push(` queryDescription: ${quote(tool.queryDescription ?? "")},`);
@@ -82,12 +104,18 @@ function printTool(tool, appRefName) {
82
104
  if (tool.fields !== undefined && tool.fields.length > 0) {
83
105
  lines.push(" fields: [");
84
106
  for (const f of tool.fields) {
85
- const parts = [`field: catalog.${appRefName}.fields.${f.key}`];
107
+ // A foreign/out-of-scope aspect's field has no field resource ei can
108
+ // reference — it falls back to a bare platform id (board issue #169);
109
+ // print the raw-id shape (SkillSearchRawIdField/SkillRecordRawIdField)
110
+ // instead of a catalog token.
111
+ const isRaw = f.key === undefined;
112
+ const parts = isRaw ? [`fieldId: ${quote(f.rawFieldId ?? "")}`] : [`field: catalog.${appRefName}.fields.${f.key}`];
86
113
  parts.push(`name: ${quote(f.name ?? "")}`);
87
114
  parts.push(`description: ${quote(f.description ?? "")}`);
88
115
  if (tool.typeKey === "createRecord" && f.required !== undefined)
89
116
  parts.push(`required: ${f.required}`);
90
- lines.push(` { ${parts.join(", ")} },`);
117
+ const todo = isRaw ? " // TODO: raw platform field id - the field belongs to a foreign/out-of-scope aspect ei can't resolve to a reference" : "";
118
+ lines.push(` { ${parts.join(", ")} },${todo}`);
91
119
  }
92
120
  lines.push(" ],");
93
121
  }
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { EntityTfError } from "../../engine/entity.js";
9
9
  import { optionalString, resourceRefLabel } from "../../engine/pull/context.js";
10
- import { tfLabelToTsLabel } from "../../engine/tf/index.js";
10
+ import { scopedLabelToBagKey } from "../../engine/tf/index.js";
11
11
  import { skillToolFromTf } from "../skill-tool/from-tf.js";
12
12
  import { APP_RESOURCE_TYPE } from "../app/module.js";
13
13
  import { SKILL_RESOURCE_TYPE } from "./module.js";
@@ -21,6 +21,7 @@ const KNOWN_SKILL_ATTRS = new Set([
21
21
  "status",
22
22
  "type",
23
23
  "properties",
24
+ "depends_on",
24
25
  ]);
25
26
  /** Dialect attrs with no authoring slot yet — reported by name, skill still pulled. */
26
27
  const UNAUTHORABLE_SKILL_ATTRS = new Set([
@@ -74,7 +75,7 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
74
75
  }
75
76
  }
76
77
  const status = optionalString(attrs, "status", where, ctx);
77
- const owner = { appType: APP_RESOURCE_TYPE, appLabel, skillType: SKILL_RESOURCE_TYPE, skillLabel: label };
78
+ const owner = { appType: APP_RESOURCE_TYPE, appLabel, ownerTfLabel: appLabel, skillType: SKILL_RESOURCE_TYPE, skillLabel: label };
78
79
  const tools = [];
79
80
  for (const block of toolBlocks) {
80
81
  const tool = skillToolFromTf(block, owner, ctx);
@@ -83,7 +84,7 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
83
84
  }
84
85
  return {
85
86
  skill: {
86
- refName: tfLabelToTsLabel(label),
87
+ refName: scopedLabelToBagKey(appLabel, label),
87
88
  name,
88
89
  description: optionalString(attrs, "description", where, ctx) ?? "",
89
90
  instructions: optionalString(attrs, "instructions", where, ctx) ?? "",
@@ -4,4 +4,4 @@
4
4
  * reference position. Standalone from v1.
5
5
  */
6
6
  export { defineSkill, type SkillConfigured, type SkillV2Options } from "./build.js";
7
- export { skillAutomation, skillCreateRecord, skillRunAgent, skillSearchAspect, skillSearchTable, skillUpdateRecord, type SkillRecordField, type SkillSearchField, type SkillToolStatus, type SkillTool, } from "./tools.js";
7
+ export { skillAutomation, skillCreateRecord, skillRunAgent, skillSearchAspect, skillSearchTable, skillUpdateRecord, type SkillRecordField, type SkillRecordFieldInput, type SkillRecordRawIdField, type SkillSearchField, type SkillSearchFieldInput, type SkillSearchRawIdField, type SkillToolStatus, type SkillTool, } from "./tools.js";
@@ -83,7 +83,12 @@ export const skillModule = {
83
83
  const skill = item;
84
84
  return {
85
85
  refName: skill.refName,
86
- source: printSkillV2(skill, { appRefName: opts.appRefName }),
86
+ source: printSkillV2(skill, {
87
+ appRefName: opts.appRefName,
88
+ ...(opts.crossOrg !== undefined && { crossOrg: opts.crossOrg }),
89
+ ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
90
+ ...(opts.foreignElementRefNames !== undefined && { foreignElementRefNames: opts.foreignElementRefNames }),
91
+ }),
87
92
  };
88
93
  },
89
94
  toTf: (entity, ctx) => skillToTf(entity, {
@@ -14,7 +14,7 @@
14
14
  * aren't authored yet, so there's nothing to emit for them.
15
15
  */
16
16
  import { EntityTfError } from "../../engine/entity.js";
17
- import { expr, tsLabelToTfLabel } from "../../engine/tf/index.js";
17
+ import { appScopedResourceLabel, expr, tsLabelToTfLabel } from "../../engine/tf/index.js";
18
18
  import { skillToolToTf } from "../skill-tool/to-tf.js";
19
19
  import { APP_RESOURCE_TYPE } from "../app/module.js";
20
20
  import { SKILL_RESOURCE_TYPE } from "./module.js";
@@ -28,7 +28,7 @@ export function skillToTf(entity, ctx) {
28
28
  if (payload === null || typeof payload !== "object" || elementum === undefined) {
29
29
  throw new EntityTfError(`skill "${entity.refName}" has no skill payload — was it built with defineSkill?`);
30
30
  }
31
- const tfLabel = tsLabelToTfLabel(entity.refName);
31
+ const tfLabel = appScopedResourceLabel(ctx.appTfLabel, tsLabelToTfLabel(entity.refName));
32
32
  const name = elementum.name ?? "";
33
33
  const attrs = {
34
34
  owner_id: expr.resourceAttr(APP_RESOURCE_TYPE, ctx.appTfLabel, ["id"]),
@@ -49,6 +49,7 @@ export function skillToTf(entity, ctx) {
49
49
  appTfLabel: ctx.appTfLabel,
50
50
  skillTfLabel: tfLabel,
51
51
  foreignAppRef: (l, n) => ctx.orgRefs.foreignApp(l, n),
52
+ foreignElementRef: (l, n) => ctx.orgRefs.foreignElement(l, n),
52
53
  diagnostics: ctx.diagnostics,
53
54
  });
54
55
  if (tool !== undefined)
@@ -18,6 +18,20 @@ export interface SkillSearchField {
18
18
  readonly name: string;
19
19
  readonly description: string;
20
20
  }
21
+ /**
22
+ * A search-tool field identified by a raw platform id rather than a
23
+ * FieldRef token — the field belongs to a foreign/out-of-scope aspect ei
24
+ * can't resolve to a resource reference (board issue #169; mirrors
25
+ * `entities/agent/tools.ts`'s `AgentSearchRawIdField`). There's no way to
26
+ * author one directly; it only arises from `edk pull app` round-tripping an
27
+ * existing tool.
28
+ */
29
+ export interface SkillSearchRawIdField {
30
+ readonly fieldId: string;
31
+ readonly name: string;
32
+ readonly description: string;
33
+ }
34
+ export type SkillSearchFieldInput = SkillSearchField | SkillSearchRawIdField;
21
35
  export interface SkillRecordField {
22
36
  readonly field: FieldRef;
23
37
  readonly name: string;
@@ -25,6 +39,14 @@ export interface SkillRecordField {
25
39
  readonly required: boolean;
26
40
  readonly defaultValue?: string;
27
41
  }
42
+ /** A create/update-record field identified by a raw platform id — see {@link SkillSearchRawIdField}. */
43
+ export interface SkillRecordRawIdField {
44
+ readonly fieldId: string;
45
+ readonly name: string;
46
+ readonly description: string;
47
+ readonly required: boolean;
48
+ }
49
+ export type SkillRecordFieldInput = SkillRecordField | SkillRecordRawIdField;
28
50
  interface CommonToolOptions {
29
51
  readonly name: string;
30
52
  readonly description: string;
@@ -38,7 +60,7 @@ export declare function skillAutomation(opts: AutomationToolV2): SkillTool;
38
60
  export interface SkillSearchAspectToolV2 extends CommonToolOptions {
39
61
  readonly aspect: AspectRef;
40
62
  readonly queryDescription: string;
41
- readonly fields: readonly SkillSearchField[];
63
+ readonly fields: readonly SkillSearchFieldInput[];
42
64
  /** Maximum number of records the search returns. */
43
65
  readonly limit?: number;
44
66
  }
@@ -54,12 +76,12 @@ export interface SkillSearchTableToolV2 extends CommonToolOptions {
54
76
  export declare function skillSearchTable(opts: SkillSearchTableToolV2): SkillTool;
55
77
  export interface SkillCreateRecordToolV2 extends CommonToolOptions {
56
78
  readonly aspect: AspectRef;
57
- readonly fields: readonly SkillRecordField[];
79
+ readonly fields: readonly SkillRecordFieldInput[];
58
80
  }
59
81
  export declare function skillCreateRecord(opts: SkillCreateRecordToolV2): SkillTool;
60
82
  export interface SkillUpdateRecordToolV2 extends CommonToolOptions {
61
83
  readonly aspect: AspectRef;
62
- readonly fields: readonly SkillRecordField[];
84
+ readonly fields: readonly SkillRecordFieldInput[];
63
85
  readonly handleDescription: string;
64
86
  }
65
87
  export declare function skillUpdateRecord(opts: SkillUpdateRecordToolV2): SkillTool;
@@ -15,6 +15,14 @@ function common(opts) {
15
15
  };
16
16
  }
17
17
  function searchFieldToken(f) {
18
+ if ("fieldId" in f) {
19
+ // Raw platform id fallback — see SkillSearchRawIdField's comment.
20
+ return {
21
+ fieldId: f.fieldId,
22
+ name: f.name,
23
+ description: f.description,
24
+ };
25
+ }
18
26
  return {
19
27
  fieldId: f.field,
20
28
  clientHandle: f.field,
@@ -23,6 +31,15 @@ function searchFieldToken(f) {
23
31
  };
24
32
  }
25
33
  function recordFieldToken(f) {
34
+ if ("fieldId" in f) {
35
+ // Raw platform id fallback — see SkillRecordRawIdField's comment.
36
+ return {
37
+ fieldId: f.fieldId,
38
+ name: f.name,
39
+ description: f.description,
40
+ required: f.required,
41
+ };
42
+ }
26
43
  return {
27
44
  fieldId: f.field,
28
45
  clientHandle: f.field,
@@ -7,8 +7,15 @@
7
7
  import { type FromTfContext } from "../../engine/pull/context.js";
8
8
  import { type TfBlock } from "../../engine/tf/index.js";
9
9
  export interface NormalizedSkillToolField {
10
- /** The field's bag key in the owning app's `fields: {}` (bijective image of its label). */
11
- readonly key: string;
10
+ /** The field's bag key in the TARGET aspect's `fields: {}` (bijective image of its label). Mutually exclusive with `rawFieldId`. */
11
+ readonly key?: string;
12
+ /**
13
+ * Raw platform field id — board issue #169. When the tool's target is a
14
+ * foreign/out-of-scope aspect (not recursively exported), ei has no field
15
+ * resource to reference and falls back to a bare id. Mutually exclusive
16
+ * with `key`; exactly one is always set.
17
+ */
18
+ readonly rawFieldId?: string;
12
19
  readonly name?: string;
13
20
  readonly description?: string;
14
21
  readonly required?: boolean;
@@ -19,6 +26,10 @@ export type NormalizedSkillToolTarget = {
19
26
  /** A foreign app via `data.elementum_app.<label>` — `name` from the stream's data block. */
20
27
  readonly kind: "foreignApp";
21
28
  readonly name: string;
29
+ } | {
30
+ /** A foreign ELEMENT via `data.elementum_element.<label>` — `name` from the stream's data block (board issue #42). */
31
+ readonly kind: "foreignElement";
32
+ readonly name: string;
22
33
  };
23
34
  export interface NormalizedSkillTool {
24
35
  readonly typeKey: "createRecord" | "searchAspect";
@@ -36,6 +47,8 @@ export interface SkillToolOwner {
36
47
  /** The owning app's resource type + tfLabel. */
37
48
  readonly appType: string;
38
49
  readonly appLabel: string;
50
+ /** Namespace tf label for stripping `apps_<ns>_` child labels. */
51
+ readonly ownerTfLabel: string;
39
52
  /** The owning skill's resource type + tfLabel. */
40
53
  readonly skillType: string;
41
54
  readonly skillLabel: string;
@@ -6,8 +6,8 @@
6
6
  */
7
7
  import { EntityTfError } from "../../engine/entity.js";
8
8
  import { optionalString, resourceRefLabel } from "../../engine/pull/context.js";
9
- import { isTfExpr, tfLabelToTsLabel } from "../../engine/tf/index.js";
10
- import { SUB_TYPE_BY_RESOURCE as FIELD_SUB_TYPE_BY_RESOURCE } from "../field/types.js";
9
+ import { isTfExpr } from "../../engine/tf/index.js";
10
+ import { resolveToolFieldKey } from "../shared/tool-field-ref.js";
11
11
  import { KNOWN_SKILL_TOOL_ATTRS, SKILL_TOOL_SUB_TYPE_BY_RESOURCE, UNAUTHORABLE_SKILL_TOOL_ATTRS, } from "./types.js";
12
12
  /**
13
13
  * One tool block → its normalized shape; undefined = skipped with a
@@ -47,6 +47,12 @@ export function skillToolFromTf(block, owner, ctx) {
47
47
  // a foreign app, resolved to its display name via the stream's data block.
48
48
  const targetAttr = attrs["target_id"];
49
49
  let target;
50
+ // The tool's fields are scoped under the RESOLVED target aspect, not
51
+ // always the owning app (board issue #169) — a field on a foreign
52
+ // app/element carries that aspect's own label, mirroring the
53
+ // foreignApp/foreignElement resolution below.
54
+ let fieldScopeLabel = owner.ownerTfLabel;
55
+ let fieldScope = "app";
50
56
  const selfLabel = resourceRefLabel(targetAttr, owner.appType);
51
57
  if (selfLabel === owner.appLabel) {
52
58
  target = { kind: "self" };
@@ -58,6 +64,18 @@ export function skillToolFromTf(block, owner, ctx) {
58
64
  return undefined;
59
65
  }
60
66
  target = { kind: "foreignApp", name: appName };
67
+ fieldScopeLabel = targetAttr.label;
68
+ }
69
+ else if (isTfExpr(targetAttr) && targetAttr.$expr === "data-attr" && targetAttr.type === "elementum_element") {
70
+ // Board issue #42: an aspect target can be an element, not just an app.
71
+ const elementName = ctx.dataName("elementum_element", targetAttr.label);
72
+ if (elementName === undefined) {
73
+ ctx.diagnostics.push(`${where}: target_id references data.elementum_element.${targetAttr.label} but the stream has no such data block; skipped`);
74
+ return undefined;
75
+ }
76
+ target = { kind: "foreignElement", name: elementName };
77
+ fieldScopeLabel = targetAttr.label;
78
+ fieldScope = "element";
61
79
  }
62
80
  else {
63
81
  ctx.diagnostics.push(`${where}: target_id has an unrecognized shape (${JSON.stringify(targetAttr)}); skipped`);
@@ -73,21 +91,24 @@ export function skillToolFromTf(block, owner, ctx) {
73
91
  continue;
74
92
  }
75
93
  const rec = item;
76
- const fieldRef = rec["field_id"];
77
- const fieldLabel = isTfExpr(fieldRef) && fieldRef.$expr === "resource-attr" && FIELD_SUB_TYPE_BY_RESOURCE.has(fieldRef.type)
78
- ? fieldRef.label
79
- : undefined;
80
- if (fieldLabel === undefined) {
94
+ const fieldKey = resolveToolFieldKey(rec["field_id"], fieldScopeLabel, fieldScope);
95
+ // A field on a foreign/out-of-scope aspect has no field resource ei
96
+ // can reference — it falls back to a bare platform id, confirmed live
97
+ // (board issue #169). Preserve it (raw-id TODO placeholder) rather
98
+ // than silently dropping the field.
99
+ const rawFieldId = fieldKey === undefined && typeof rec["field_id"] === "string" && rec["field_id"] !== "" ? rec["field_id"] : undefined;
100
+ if (fieldKey === undefined && rawFieldId === undefined) {
81
101
  ctx.diagnostics.push(`${where}: fields item's field_id is not a field resource reference; dropped`);
82
102
  continue;
83
103
  }
84
104
  fields.push({
85
- key: tfLabelToTsLabel(fieldLabel),
105
+ ...(fieldKey !== undefined ? { key: fieldKey } : { rawFieldId: rawFieldId }),
86
106
  ...(typeof rec["name"] === "string" && { name: rec["name"] }),
87
107
  ...(typeof rec["description"] === "string" && { description: rec["description"] }),
88
- // The provider's own schema docs "required" on search-tool fields as
89
- // "not used by search tools" — always echoed back (usually `false`)
90
- // but never meaningful, so it's excluded from that shape entirely.
108
+ // The provider's own schema docs `required` on search-tool fields as
109
+ // "Not used by search tools" — it's platform-generated noise (see
110
+ // to-tf.ts), so it's excluded here too rather than echoed into
111
+ // authored source.
91
112
  ...(subType.typeKey === "createRecord" && typeof rec["required"] === "boolean" && { required: rec["required"] }),
92
113
  });
93
114
  }
@@ -15,6 +15,8 @@ export interface SkillToolToTfContext {
15
15
  readonly skillTfLabel: string;
16
16
  /** Records a foreign-app data lookup for data.tf; returns its tfLabel. */
17
17
  foreignAppRef(tfLabel: string, name: string): void;
18
+ /** Records a foreign-ELEMENT data lookup for data.tf (board issue #42). */
19
+ foreignElementRef(tfLabel: string, name: string): void;
18
20
  /** Degradations land here — reported by the caller, never silent. */
19
21
  readonly diagnostics: string[];
20
22
  }
@@ -6,14 +6,18 @@
6
6
  * (`skill_id`) — this module never names the skill or app resource types.
7
7
  * Mirrors `entities/agent-tool/to-tf.ts`.
8
8
  */
9
- import { expr, sanitizeName } from "../../engine/tf/index.js";
9
+ import { appScopedResourceLabel, expr, sanitizeName } from "../../engine/tf/index.js";
10
10
  import { fieldRefToTfValue } from "../field/to-tf.js";
11
11
  import { SKILL_TOOL_SUB_TYPE_BY_TYPE_KEY } from "./types.js";
12
12
  /** authoring FieldRef token → the field resource address, via the shared field-ref helper. */
13
13
  function fieldRefValue(token, where, ctx) {
14
14
  const refName = token.refName ?? "";
15
15
  const authoringType = token.fieldType ?? "";
16
- const ref = refName === "" ? undefined : fieldRefToTfValue(authoringType, refName);
16
+ // appTfLabel, not appRefName: fieldRefToTfValue builds a terraform address
17
+ // (resource label prefix / local name), and the two differ whenever an
18
+ // app's authoring ref doesn't match its platform namespace (e.g. a clone).
19
+ // agent-tool/to-tf.ts's equivalent already passes appTfLabel.
20
+ const ref = refName === "" ? undefined : fieldRefToTfValue(authoringType, refName, ctx.appTfLabel);
17
21
  if (ref === undefined) {
18
22
  ctx.diagnostics.push(`${where}: field token "${refName}" has no terraform field resource mapping (fieldType ${JSON.stringify(authoringType)}); dropped`);
19
23
  return undefined;
@@ -26,12 +30,17 @@ function fieldRefValue(token, where, ctx) {
26
30
  }
27
31
  /** authoring AspectRef token → target_id value (self resource ref or foreign data ref). */
28
32
  function targetIdValue(token, ctx) {
29
- if ((token.refName ?? "") === ctx.appRefName) {
33
+ if (token.__kind !== "element" && (token.refName ?? "") === ctx.appRefName) {
30
34
  return expr.resourceAttr("elementum_app", ctx.appTfLabel, ["id"]);
31
35
  }
32
- // ei derives foreign-app data labels from the display NAME.
36
+ // ei derives foreign-app/foreign-element data labels from the display NAME.
33
37
  const name = token.name ?? token.refName ?? "";
34
38
  const tfLabel = sanitizeName(name);
39
+ // Board issue #42: an aspect token can be an element, not just an app.
40
+ if (token.__kind === "element") {
41
+ ctx.foreignElementRef(tfLabel, name);
42
+ return expr.dataAttr("elementum_element", tfLabel, ["id"]);
43
+ }
35
44
  ctx.foreignAppRef(tfLabel, name);
36
45
  return expr.dataAttr("elementum_app", tfLabel, ["id"]);
37
46
  }
@@ -61,9 +70,7 @@ export function skillToolToTf(entry, ctx) {
61
70
  return undefined;
62
71
  }
63
72
  const where = `skill tool "${name}"`;
64
- // Unlike agent tools (labeled `<agent>_<tool>`), the platform labels skill
65
- // tools by name alone, unprefixed — confirmed live against `ei apps export`.
66
- const tfLabel = sanitizeName(name);
73
+ const tfLabel = appScopedResourceLabel(ctx.appTfLabel, sanitizeName(name));
67
74
  const attrs = {
68
75
  skill_id: expr.resourceAttr("elementum_agentic_skill", ctx.skillTfLabel, ["id"]),
69
76
  app_id: expr.resourceAttr("elementum_app", ctx.appTfLabel, ["id"]),
@@ -86,14 +93,30 @@ export function skillToolToTf(entry, ctx) {
86
93
  if (inner.fields !== undefined && inner.fields.length > 0) {
87
94
  const fieldValues = [];
88
95
  for (const f of inner.fields) {
89
- const ref = f.fieldId === undefined ? undefined : fieldRefValue(f.fieldId, where, ctx);
96
+ // A raw-id fallback field (board issue #169) is echoed straight
97
+ // through — ei never resolves it to a reference either, so there's
98
+ // nothing to re-derive.
99
+ const ref = typeof f.fieldId === "string"
100
+ ? f.fieldId
101
+ : f.fieldId === undefined
102
+ ? undefined
103
+ : fieldRefValue(f.fieldId, where, ctx);
90
104
  if (ref === undefined)
91
105
  continue;
92
106
  fieldValues.push({
93
107
  field_id: ref,
94
108
  name: f.name ?? "",
95
109
  description: f.description ?? "",
96
- ...(f.required !== undefined && { required: f.required }),
110
+ // `required` on a searchAspect field is documented by the provider's
111
+ // own schema as "Not used by search tools" — the platform never
112
+ // queries or stores a meaningful value for it there, unlike
113
+ // createRecord's fields, where it's real and must always be emitted
114
+ // (defaulting false) per the agent-tool/to-tf.ts fix of 2026-08-05.
115
+ // (A `required: false` that used to show up in `ei apps export` for
116
+ // search tools was a bug in the exporter itself — cmd/elementum's
117
+ // hcl_skill.go was fabricating it from Go's zero-value default
118
+ // rather than an actually-discovered value; fixed 2026-08-11.)
119
+ ...(typeKey !== "searchAspect" && { required: f.required ?? false }),
97
120
  });
98
121
  if (f.defaultValue !== undefined) {
99
122
  ctx.diagnostics.push(`${where}: field default values are not supported on the terraform path yet; dropped`);
@@ -6,13 +6,17 @@
6
6
  * module never names the app's own resource type.
7
7
  */
8
8
  import { type FromTfContext } from "../../engine/pull/context.js";
9
- import { type TfBlock } from "../../engine/tf/index.js";
9
+ import { type ChildResourceScope, type TfBlock } from "../../engine/tf/index.js";
10
10
  import type { NormalizedLayout, NormalizedListView } from "../app/deserializer/normalize.js";
11
11
  export interface ViewOwner {
12
12
  /** The owner's resource type ("elementum_app") — what `object_id`/`aspect_id` must reference. */
13
13
  readonly type: string;
14
- /** The owner's tfLabel. */
14
+ /** The owner's tfLabel (namespace). */
15
15
  readonly label: string;
16
+ /** Namespace tf label for stripping child label prefixes. */
17
+ readonly ownerTfLabel: string;
18
+ /** App vs element scope for prefix stripping. */
19
+ readonly scope?: ChildResourceScope;
16
20
  /** Stage keys declared by the owning app, used when ei exports a raw stage UUID. */
17
21
  readonly stageKeys?: ReadonlySet<string>;
18
22
  }
@@ -6,7 +6,7 @@
6
6
  * module never names the app's own resource type.
7
7
  */
8
8
  import { optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
9
- import { isTfExpr, tfLabelToTsLabel } from "../../engine/tf/index.js";
9
+ import { isTfExpr, scopedLabelToBagKey } from "../../engine/tf/index.js";
10
10
  import { fieldKeyFromTfRef } from "../field/from-tf.js";
11
11
  import { GROUP_SECTION_WIRE_TYPE, KNOWN_LAYOUT_ATTRS, KNOWN_LAYOUT_SECTION_ATTRS, KNOWN_LIST_VIEW_ATTRS, KNOWN_MANAGED_VIEW_ORDER_ATTRS, LIST_VIEW_RESOURCE_TYPE, SECTION_TYPE_FROM_WIRE, SYSTEM_FIELD_KEY_BY_ID_ATTR, UPDATE_SECTION_WIRE_TYPE, } from "./types.js";
12
12
  /** Report every attribute key not in `known` as dialect growth — shared by all four view/section passes below. */
@@ -56,7 +56,8 @@ function layoutFromTf(block, owner, ctx) {
56
56
  return undefined;
57
57
  }
58
58
  const stageKey = stageKeyFromTf(attrs["stage_id"], owner.label);
59
- const labelStageKey = tfLabelToTsLabel(label);
59
+ const scope = owner.scope ?? "app";
60
+ const labelStageKey = scopedLabelToBagKey(owner.ownerTfLabel, label, scope);
60
61
  const canInferStageKey = typeof attrs["stage_id"] === "string" && owner.stageKeys?.has(labelStageKey) === true;
61
62
  if (stageKey === undefined && !canInferStageKey) {
62
63
  ctx.diagnostics.push(`${where}: stage_id is not a "local.${owner.label}_stage_ids_by_key[...]" reference; using the layout's own label "${label}" as the stage key (may not match the platform's real stage key)`);
@@ -65,7 +66,7 @@ function layoutFromTf(block, owner, ctx) {
65
66
  const sections = [];
66
67
  if (Array.isArray(sectionsAttr)) {
67
68
  for (const item of sectionsAttr) {
68
- const section = sectionFromTf(item, owner.label, where, ctx);
69
+ const section = sectionFromTf(item, owner.label, owner.ownerTfLabel, scope, where, ctx);
69
70
  if (section !== undefined)
70
71
  sections.push(section);
71
72
  }
@@ -83,7 +84,7 @@ function stageKeyFromTf(v, ownerLabel) {
83
84
  const seg = v.path[0];
84
85
  return v.path.length === 1 && typeof seg === "object" && "index" in seg ? seg.index : undefined;
85
86
  }
86
- function sectionFromTf(raw, ownerLabel, where, ctx) {
87
+ function sectionFromTf(raw, ownerLabel, ownerTfLabel, scope, where, ctx) {
87
88
  const rec = plainObject(raw);
88
89
  if (rec === undefined) {
89
90
  ctx.diagnostics.push(`${where}: a sections entry has an unrecognized shape; dropped`);
@@ -114,7 +115,7 @@ function sectionFromTf(raw, ownerLabel, where, ctx) {
114
115
  if (Array.isArray(fieldIds)) {
115
116
  const fields = [];
116
117
  for (const f of fieldIds) {
117
- const key = fieldRefFromTf(f, ownerLabel, ctx);
118
+ const key = fieldRefFromTf(f, ownerLabel, ownerTfLabel, scope, ctx);
118
119
  if (key !== undefined)
119
120
  fields.push(key);
120
121
  }
@@ -127,7 +128,7 @@ function sectionFromTf(raw, ownerLabel, where, ctx) {
127
128
  return section;
128
129
  }
129
130
  /** A `field_ids`/`columns` entry → a system-field key or a custom field's bag key. */
130
- function fieldRefFromTf(v, ownerLabel, ctx) {
131
+ function fieldRefFromTf(v, ownerLabel, ownerTfLabel, scope, ctx) {
131
132
  if (!isTfExpr(v)) {
132
133
  ctx.diagnostics.push(`field reference has an unrecognized (non-expression) shape; dropped`);
133
134
  return undefined;
@@ -140,7 +141,7 @@ function fieldRefFromTf(v, ownerLabel, ctx) {
140
141
  }
141
142
  // Custom field ref resolution is shared with agent-tool's field refs
142
143
  // (src/entities/agent-tool/from-tf.ts) via entities/field/from-tf.ts.
143
- const fieldKey = fieldKeyFromTfRef(v);
144
+ const fieldKey = fieldKeyFromTfRef(v, ownerTfLabel, scope);
144
145
  if (fieldKey !== undefined)
145
146
  return fieldKey;
146
147
  ctx.diagnostics.push(`field reference ${JSON.stringify(v)} does not resolve to a known field; dropped`);
@@ -160,12 +161,13 @@ function listViewFromTf(block, owner, ctx) {
160
161
  ctx.diagnostics.push(`${where}: aspect_id does not reference ${owner.type}.${owner.label}; skipped`);
161
162
  return undefined;
162
163
  }
164
+ const scope = owner.scope ?? "app";
163
165
  const name = optionalString(attrs, "name", where, ctx) ?? "";
164
166
  const columnsAttr = attrs["columns"];
165
167
  const columns = [];
166
168
  if (Array.isArray(columnsAttr)) {
167
169
  for (const c of columnsAttr) {
168
- const key = fieldRefFromTf(c, owner.label, ctx);
170
+ const key = fieldRefFromTf(c, owner.label, owner.ownerTfLabel, scope, ctx);
169
171
  if (key !== undefined)
170
172
  columns.push(key);
171
173
  }
@@ -190,7 +192,7 @@ function listViewFromTf(block, owner, ctx) {
190
192
  ctx.diagnostics.push(`${where}: sort is not a jsonencode(...) expression; dropped`);
191
193
  }
192
194
  return {
193
- key: tfLabelToTsLabel(label),
195
+ key: scopedLabelToBagKey(owner.ownerTfLabel, label, scope),
194
196
  name,
195
197
  columns,
196
198
  ...(typeof attrs["allow_record_creation"] === "boolean" && { allowRecordCreation: attrs["allow_record_creation"] }),