@elementumai/edk 0.12.0 → 0.13.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 (224) hide show
  1. package/README.md +8 -2
  2. package/dist-sdk/src/catalog/factories.d.ts +7 -1
  3. package/dist-sdk/src/catalog/factories.js +10 -2
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +1 -1
  6. package/dist-sdk/src/catalog/org.js +79 -34
  7. package/dist-sdk/src/catalog/token.js +5 -0
  8. package/dist-sdk/src/catalog/types.d.ts +12 -1
  9. package/dist-sdk/src/catalog/types.js +3 -0
  10. package/dist-sdk/src/core/system-fields.d.ts +1 -1
  11. package/dist-sdk/src/core/system-fields.js +1 -1
  12. package/dist-sdk/src/core/types/app.d.ts +6 -0
  13. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  14. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  15. package/dist-sdk/src/engine/coverage-gaps.js +4 -0
  16. package/dist-sdk/src/engine/ei/run.d.ts +8 -0
  17. package/dist-sdk/src/engine/ei/run.js +46 -7
  18. package/dist-sdk/src/engine/pull/authored-address.js +42 -6
  19. package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
  20. package/dist-sdk/src/engine/pull/authored-root.js +306 -0
  21. package/dist-sdk/src/engine/pull/context.d.ts +34 -0
  22. package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
  23. package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
  24. package/dist-sdk/src/engine/pull/org.d.ts +1 -0
  25. package/dist-sdk/src/engine/pull/org.js +2 -0
  26. package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
  27. package/dist-sdk/src/engine/pull/partition.js +43 -0
  28. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
  29. package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
  30. package/dist-sdk/src/engine/pull/ref-only.d.ts +4 -0
  31. package/dist-sdk/src/engine/pull/ref-only.js +7 -1
  32. package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
  33. package/dist-sdk/src/engine/pull/source-resources.js +110 -0
  34. package/dist-sdk/src/engine/pull/stream-root.d.ts +159 -0
  35. package/dist-sdk/src/engine/pull/stream-root.js +579 -0
  36. package/dist-sdk/src/engine/workspace/authoring-layout.js +16 -2
  37. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
  38. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
  39. package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
  40. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
  41. package/dist-sdk/src/entities/access-policy/from-tf.js +17 -5
  42. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
  43. package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
  44. package/dist-sdk/src/entities/agent/build.d.ts +52 -1
  45. package/dist-sdk/src/entities/agent/build.js +34 -0
  46. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +70 -1
  47. package/dist-sdk/src/entities/agent/from-tf.d.ts +36 -1
  48. package/dist-sdk/src/entities/agent/from-tf.js +289 -2
  49. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  50. package/dist-sdk/src/entities/agent/module.js +1 -0
  51. package/dist-sdk/src/entities/agent/to-tf.d.ts +11 -11
  52. package/dist-sdk/src/entities/agent/to-tf.js +179 -17
  53. package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
  54. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  55. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
  56. package/dist-sdk/src/entities/app/build.d.ts +33 -13
  57. package/dist-sdk/src/entities/app/build.js +14 -12
  58. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  59. package/dist-sdk/src/entities/app/from-tf.js +7 -9
  60. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  61. package/dist-sdk/src/entities/app/index.js +1 -0
  62. package/dist-sdk/src/entities/app/module.js +3 -0
  63. package/dist-sdk/src/entities/app/stage-keys.d.ts +2 -2
  64. package/dist-sdk/src/entities/app/stage-keys.js +3 -3
  65. package/dist-sdk/src/entities/app/to-tf.js +1 -0
  66. package/dist-sdk/src/entities/approval-chain/build.d.ts +46 -11
  67. package/dist-sdk/src/entities/approval-chain/build.js +120 -8
  68. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +24 -2
  69. package/dist-sdk/src/entities/approval-chain/from-tf.js +148 -6
  70. package/dist-sdk/src/entities/approval-chain/index.d.ts +4 -1
  71. package/dist-sdk/src/entities/approval-chain/index.js +4 -1
  72. package/dist-sdk/src/entities/approval-chain/module.js +23 -5
  73. package/dist-sdk/src/entities/approval-chain/printer.d.ts +1 -1
  74. package/dist-sdk/src/entities/approval-chain/printer.js +91 -5
  75. package/dist-sdk/src/entities/approval-chain/steps-tf.d.ts +77 -0
  76. package/dist-sdk/src/entities/approval-chain/steps-tf.js +255 -0
  77. package/dist-sdk/src/entities/approval-chain/steps.d.ts +71 -0
  78. package/dist-sdk/src/entities/approval-chain/steps.js +83 -0
  79. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +16 -6
  80. package/dist-sdk/src/entities/approval-chain/to-tf.js +37 -4
  81. package/dist-sdk/src/entities/automation/build.d.ts +10 -1
  82. package/dist-sdk/src/entities/automation/build.js +70 -27
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +21 -5
  84. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -5
  85. package/dist-sdk/src/entities/automation/from-tf.js +665 -112
  86. package/dist-sdk/src/entities/automation/index.d.ts +2 -1
  87. package/dist-sdk/src/entities/automation/index.js +1 -0
  88. package/dist-sdk/src/entities/automation/module.d.ts +4 -3
  89. package/dist-sdk/src/entities/automation/module.js +45 -12
  90. package/dist-sdk/src/entities/automation/refs-read.d.ts +19 -0
  91. package/dist-sdk/src/entities/automation/refs-read.js +48 -0
  92. package/dist-sdk/src/entities/automation/slack-message-refs.d.ts +9 -0
  93. package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
  94. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +23 -3
  95. package/dist-sdk/src/entities/automation/system-ref-name.js +86 -4
  96. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +11 -0
  97. package/dist-sdk/src/entities/automation/task-output-labels.js +23 -0
  98. package/dist-sdk/src/entities/automation/tasks.d.ts +29 -4
  99. package/dist-sdk/src/entities/automation/tasks.js +34 -11
  100. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -1
  101. package/dist-sdk/src/entities/automation/to-tf.js +563 -103
  102. package/dist-sdk/src/entities/automation/triggers.d.ts +0 -8
  103. package/dist-sdk/src/entities/automation/triggers.js +26 -11
  104. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
  105. package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
  106. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  107. package/dist-sdk/src/entities/chart/from-tf.js +3 -0
  108. package/dist-sdk/src/entities/chart/to-tf.js +19 -2
  109. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +3 -1
  110. package/dist-sdk/src/entities/dashboard/from-tf.js +42 -2
  111. package/dist-sdk/src/entities/dashboard/to-tf.js +9 -1
  112. package/dist-sdk/src/entities/dashboard-widget-order/module.d.ts +10 -0
  113. package/dist-sdk/src/entities/dashboard-widget-order/module.js +25 -0
  114. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +31 -0
  115. package/dist-sdk/src/entities/dashboard-widget-order/order.js +102 -0
  116. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -0
  117. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +44 -5
  118. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
  119. package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
  120. package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
  121. package/dist-sdk/src/entities/element/build.js +2 -1
  122. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  123. package/dist-sdk/src/entities/element/from-tf.js +4 -7
  124. package/dist-sdk/src/entities/element/module.js +5 -0
  125. package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
  126. package/dist-sdk/src/entities/element/system-fields.js +23 -0
  127. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  128. package/dist-sdk/src/entities/field/build.d.ts +9 -0
  129. package/dist-sdk/src/entities/field/from-tf.d.ts +52 -1
  130. package/dist-sdk/src/entities/field/from-tf.js +212 -14
  131. package/dist-sdk/src/entities/field/module.js +4 -0
  132. package/dist-sdk/src/entities/field/to-tf.d.ts +5 -1
  133. package/dist-sdk/src/entities/field/to-tf.js +33 -12
  134. package/dist-sdk/src/entities/org/category.js +1 -0
  135. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  136. package/dist-sdk/src/entities/org/index.js +1 -0
  137. package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
  138. package/dist-sdk/src/entities/org/voice-auth.js +33 -0
  139. package/dist-sdk/src/entities/organization/build.d.ts +3 -0
  140. package/dist-sdk/src/entities/organization/build.js +2 -0
  141. package/dist-sdk/src/entities/organization/index.d.ts +1 -0
  142. package/dist-sdk/src/entities/organization/index.js +1 -0
  143. package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
  144. package/dist-sdk/src/entities/organization/to-tf.js +59 -1
  145. package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
  146. package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
  147. package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
  148. package/dist-sdk/src/entities/phone-service/build.js +1 -0
  149. package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
  150. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
  151. package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
  152. package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
  153. package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
  154. package/dist-sdk/src/entities/relationship/from-tf.js +9 -4
  155. package/dist-sdk/src/entities/relationship/module.js +2 -2
  156. package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
  157. package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
  158. package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
  159. package/dist-sdk/src/entities/role/build.d.ts +3 -4
  160. package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
  161. package/dist-sdk/src/entities/role/permission-levels.js +78 -0
  162. package/dist-sdk/src/entities/role/to-tf.js +32 -2
  163. package/dist-sdk/src/entities/search-table/build.d.ts +9 -3
  164. package/dist-sdk/src/entities/search-table/build.js +4 -4
  165. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  166. package/dist-sdk/src/entities/search-table/to-tf.js +20 -2
  167. package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
  168. package/dist-sdk/src/entities/service-account/module.js +4 -1
  169. package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
  170. package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
  171. package/dist-sdk/src/entities/service-account/role-membership-check.d.ts +20 -0
  172. package/dist-sdk/src/entities/service-account/role-membership-check.js +80 -0
  173. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  174. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +36 -0
  175. package/dist-sdk/src/entities/shared/context.d.ts +14 -1
  176. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  177. package/dist-sdk/src/entities/shared/filters/index.d.ts +97 -15
  178. package/dist-sdk/src/entities/shared/filters/index.js +30 -7
  179. package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
  180. package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
  181. package/dist-sdk/src/entities/shared/filters/print.d.ts +2 -0
  182. package/dist-sdk/src/entities/shared/filters/print.js +19 -6
  183. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +16 -7
  184. package/dist-sdk/src/entities/shared/filters/tf-codec.js +25 -5
  185. package/dist-sdk/src/entities/shared/filters/types.d.ts +4 -0
  186. package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
  187. package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
  188. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +1 -1
  189. package/dist-sdk/src/entities/shared/tool-field-ref.js +3 -2
  190. package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
  191. package/dist-sdk/src/entities/sla/build.d.ts +96 -0
  192. package/dist-sdk/src/entities/sla/build.js +124 -0
  193. package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
  194. package/dist-sdk/src/entities/sla/from-tf.js +164 -0
  195. package/dist-sdk/src/entities/sla/index.d.ts +1 -0
  196. package/dist-sdk/src/entities/sla/index.js +1 -0
  197. package/dist-sdk/src/entities/sla/module.d.ts +4 -0
  198. package/dist-sdk/src/entities/sla/module.js +73 -0
  199. package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
  200. package/dist-sdk/src/entities/sla/printer.js +84 -0
  201. package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
  202. package/dist-sdk/src/entities/sla/to-tf.js +81 -0
  203. package/dist-sdk/src/entities/table/build.d.ts +7 -2
  204. package/dist-sdk/src/entities/table/build.js +22 -1
  205. package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
  206. package/dist-sdk/src/entities/table/from-tf.js +89 -14
  207. package/dist-sdk/src/entities/table/index.d.ts +1 -1
  208. package/dist-sdk/src/entities/table/to-tf.js +41 -2
  209. package/dist-sdk/src/entities/task/from-tf.js +3 -2
  210. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +6 -4
  211. package/dist-sdk/src/entities/view/custom-view-validate.js +36 -18
  212. package/dist-sdk/src/entities/view/from-tf.js +16 -4
  213. package/dist-sdk/src/entities/view/to-tf.js +66 -47
  214. package/dist-sdk/src/entities/visual-flow/module.js +52 -1
  215. package/dist-sdk/src/entities/widget/from-tf.js +19 -8
  216. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +49 -4
  217. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  218. package/dist-sdk/src/graph/index.d.ts +9 -0
  219. package/dist-sdk/src/graph/index.js +8 -0
  220. package/dist-sdk/src/graph/modules.js +13 -1
  221. package/dist-sdk/src/graph/resource-types.d.ts +47 -0
  222. package/dist-sdk/src/graph/resource-types.js +62 -0
  223. package/dist-sdk/src/graph/types.d.ts +113 -6
  224. package/package.json +7 -4
@@ -17,13 +17,15 @@
17
17
  */
18
18
  import { typedCoverageGap } from "../../engine/coverage-gaps.js";
19
19
  import { workspaceAspectKey } from "../../engine/build/context.js";
20
+ import { filterToTf } from "../access-policy/to-tf.js";
21
+ import { authoredFieldKeysFromPayload, fieldRefToTfValue } from "../field/to-tf.js";
20
22
  import { EntityTfError } from "../../engine/entity.js";
21
23
  import { appScopedResourceLabel, expr, sanitizeName, tsLabelToTfLabel } from "../../engine/tf/index.js";
22
24
  import { a2aSkillToTf } from "../agent-a2a-skill/to-tf.js";
23
25
  import { agentToolLabelSuffixes, assertUniqueToolAddresses, toolName, toolToTf } from "../agent-tool/to-tf.js";
24
26
  import { APP_RESOURCE_TYPE } from "../app/module.js";
25
27
  import { CONNECTOR_ORG_BAG } from "../org/connector.js";
26
- import { resolveForeignRef } from "../shared/foreign-ref.js";
28
+ import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
27
29
  import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
28
30
  import { SKILL_RESOURCE_TYPE } from "../skill/module.js";
29
31
  import { AGENT_RESOURCE_TYPE } from "./module.js";
@@ -248,17 +250,16 @@ function toSortableAgents(entities) {
248
250
  return out;
249
251
  }
250
252
  /**
251
- * Mirrors ei's cross-agent a2a-skill-name disambiguation
252
- * (`cmd/elementum/export/imports.go`'s `a2aNames` counting map over
253
- * `app.AllAgents()`): a same-app, same-named a2a skill on two different
254
- * agents is not a collision on the platform — ei's exporter gives the
255
- * first occurrence of a sanitized name the bare label, each later
256
- * occurrence `_1`, `_2`, …
253
+ * The cross-agent a2a-skill-name numbering that ei's export copies
254
+ * (`a2aSkillImportBlocks` in `cmd/elementum/export/imports.go`, over one
255
+ * app's own agents only, edk#2508): a same-app, same-named a2a skill on two
256
+ * different agents is not a collision on the platform — the first agent to
257
+ * use a sanitized name gets the bare label, each later agent `_1`, `_2`, …
257
258
  *
258
259
  * The order is shared with ei: agent name by UTF-16 code unit, then (for
259
260
  * identical names) refName here and the agent's own label in ei, whose `_N`
260
- * tails sort alike. The Go comparator is in the a2a loop of
261
- * `cmd/elementum/export/imports.go` (`compareUTF16`, `agentChildParts`),
261
+ * tails sort alike. The Go comparator is in `a2aSkillImportBlocks`
262
+ * (`compareUTF16`, `agentChildParts`),
262
263
  * and the two must stay in sync; changing one without the other moves
263
264
  * `agent_id` and replaces skills on the first plan after a pull (edk#1728).
264
265
  * Before edk#1728 ei walked agents in id order.
@@ -278,8 +279,7 @@ function toSortableAgents(entities) {
278
279
  * cross-agent counter), so an intra-agent duplicate still collides on one
279
280
  * address instead of silently acquiring a distinct label — that's a real
280
281
  * authoring mistake (two skills with the identical name on ONE agent),
281
- * still caught and dropped by `agentToTf`'s existing
282
- * `seenA2ASkillAddresses` check. Only DIFFERENT agents reusing a name are
282
+ * a build error from `agentToTf`'s `seenA2ASkillAddresses` check. Only DIFFERENT agents reusing a name are
283
283
  * the #294 case this disambiguates.
284
284
  */
285
285
  export function computeA2ASkillLabelSuffixes(siblingAgents) {
@@ -336,24 +336,181 @@ function skillIdValue(token, ctx) {
336
336
  throw new EntityTfError(`agent skillAccess: foreign skill "${name}" has no owning app identity; use the skill token from its generated app catalog`);
337
337
  }
338
338
  const sibling = ctx.workspaceAspects?.get(workspaceAspectKey("app", token.parent));
339
+ // A skill of a sibling app authored in this build: reference its resource,
340
+ // so a first apply creates the skill before the agent. A data lookup would
341
+ // be read before the skill exists and fail "Agentic Skill Not Found" (edk#2919).
342
+ if (sibling !== undefined && sibling.managedChildRefNames?.get("skill")?.has(refName) === true) {
343
+ return expr.resourceAttr(SKILL_RESOURCE_TYPE, appScopedResourceLabel(sibling.tfLabel, tsLabelToTfLabel(refName)), ["id"]);
344
+ }
339
345
  let appId;
340
346
  let ownerTfLabel;
347
+ // An app outside this build is looked up by its namespace, as ei's export
348
+ // does: `data "elementum_app" "<namespace>"` and
349
+ // `data "elementum_agentic_skill" "<namespace>_<skill>"` (edk#2919). That
350
+ // is an app authored here but left out of a scoped build (the pull's
351
+ // build-vs-export check builds only the pulled app), a ref-only
352
+ // dependency stub whose catalog records the namespace, or a pulled literal
353
+ // token that kept the namespace ei looked the owner up by.
354
+ const ownerNamespace = sibling === undefined
355
+ ? ctx.outOfScopeApps?.get(token.parent)?.namespace ?? (token.parentNamespace !== "" ? token.parentNamespace : undefined)
356
+ : undefined;
341
357
  if (sibling !== undefined) {
342
358
  ownerTfLabel = sibling.tfLabel;
343
359
  appId = expr.resourceAttr(APP_RESOURCE_TYPE, sibling.tfLabel, ["id"]);
344
360
  }
345
361
  else {
346
- ownerTfLabel = sanitizeName(token.parentName);
347
- ctx.orgRefs.foreignApp(ownerTfLabel, token.parentName);
362
+ ownerTfLabel = sanitizeName(ownerNamespace ?? token.parentName);
363
+ ctx.orgRefs.foreignApp(ownerTfLabel, token.parentName, ownerNamespace);
348
364
  appId = expr.dataAttr(APP_RESOURCE_TYPE, ownerTfLabel, ["id"]);
349
365
  }
350
366
  // A skill name is only unique within its owning app. Scope the Terraform
351
367
  // label too, or same-named skills from two foreign apps would collapse to
352
368
  // one data block and both references would silently resolve to its last owner.
353
- const tfLabel = appScopedResourceLabel(ownerTfLabel, sanitizeName(name));
369
+ const tfLabel = ownerNamespace !== undefined
370
+ ? `${ownerTfLabel}_${sanitizeName(name)}`
371
+ : appScopedResourceLabel(ownerTfLabel, sanitizeName(name));
354
372
  ctx.orgRefs.foreignSkill(tfLabel, name, appId);
355
373
  return expr.dataAttr(SKILL_RESOURCE_TYPE, tfLabel, ["id"]);
356
374
  }
375
+ const ELEMENT_RESOURCE_TYPE = "elementum_element";
376
+ function dropdownAspect(token, kind, where, ctx) {
377
+ const refName = token.refName ?? "";
378
+ if (refName === "") {
379
+ throw new EntityTfError(`${where}: dynamic dropdown aspect has no refName`);
380
+ }
381
+ if (kind === "app" && refName === ctx.appRefName) {
382
+ const self = ctx.workspaceAspects?.get(workspaceAspectKey("app", refName));
383
+ return {
384
+ value: expr.resourceAttr(APP_RESOURCE_TYPE, ctx.appTfLabel, ["id"]),
385
+ localTfLabel: ctx.appTfLabel,
386
+ fieldOwnership: authoredFieldKeysFromPayload(self?.streamRootEntity?.payload),
387
+ };
388
+ }
389
+ const sibling = ctx.workspaceAspects?.get(workspaceAspectKey(kind, refName));
390
+ if (sibling !== undefined) {
391
+ const resourceType = kind === "element" ? ELEMENT_RESOURCE_TYPE : APP_RESOURCE_TYPE;
392
+ return {
393
+ value: expr.resourceAttr(resourceType, sibling.tfLabel, ["id"]),
394
+ localTfLabel: sibling.tfLabel,
395
+ fieldOwnership: authoredFieldKeysFromPayload(sibling.streamRootEntity?.payload),
396
+ };
397
+ }
398
+ const name = token.name ?? refName;
399
+ if (name === "") {
400
+ throw new EntityTfError(`${where}: dynamic dropdown ${kind} "${refName}" has no name to look up`);
401
+ }
402
+ const tfLabel = sanitizeName(token.namespace ?? name);
403
+ if (kind === "element") {
404
+ ctx.orgRefs.foreignElement(tfLabel, name, token.namespace);
405
+ return { value: expr.dataAttr(ELEMENT_RESOURCE_TYPE, tfLabel, ["id"]), foreignTfLabel: tfLabel };
406
+ }
407
+ ctx.orgRefs.foreignApp(tfLabel, name, token.namespace);
408
+ return { value: expr.dataAttr(APP_RESOURCE_TYPE, tfLabel, ["id"]), foreignTfLabel: tfLabel };
409
+ }
410
+ function dropdownFieldValue(field, aspect, where, ctx) {
411
+ const refName = field.refName ?? "";
412
+ if (refName === "") {
413
+ throw new EntityTfError(`${where}: dynamic dropdown field has no refName`);
414
+ }
415
+ if (field.parent !== undefined && (field.parent !== aspect.refName || (field.parentKind ?? "app") !== aspect.kind)) {
416
+ throw new EntityTfError(`${where}: field "${refName}" belongs to ${field.parentKind ?? "app"} "${field.parent}", not ${aspect.kind} "${aspect.refName}"`);
417
+ }
418
+ if (aspect.localTfLabel !== undefined) {
419
+ const value = fieldRefToTfValue(field.fieldType ?? "", refName, aspect.localTfLabel, aspect.kind, aspect.fieldOwnership);
420
+ if (value === undefined) {
421
+ throw new EntityTfError(`${where}: field "${refName}" has no terraform address on ${aspect.kind} "${aspect.refName}"`);
422
+ }
423
+ return value;
424
+ }
425
+ const fieldName = field.name ?? refName;
426
+ const ownerLabel = aspect.foreignTfLabel;
427
+ if (ownerLabel === undefined) {
428
+ throw new EntityTfError(`${where}: field "${refName}" has no lookup address on ${aspect.kind} "${aspect.refName}"`);
429
+ }
430
+ const dataLabel = foreignFieldDataLabel(aspect.kind, ownerLabel, fieldName);
431
+ ctx.orgRefs.foreignField("elementum_field", dataLabel, aspect.value, fieldName);
432
+ return expr.dataAttr("elementum_field", dataLabel, ["id"]);
433
+ }
434
+ function systemSkillValue(skill, where, ctx, withDropdowns) {
435
+ if (typeof skill.enabled !== "boolean") {
436
+ throw new EntityTfError(`${where}: enabled must be a boolean`);
437
+ }
438
+ const value = { enabled: skill.enabled };
439
+ if (skill.description !== undefined)
440
+ value["description"] = skill.description;
441
+ if (!withDropdowns)
442
+ return value;
443
+ if (skill.dynamicDropdowns === undefined)
444
+ return value;
445
+ value["dynamic_dropdowns"] = skill.dynamicDropdowns.map((row, index) => {
446
+ const rowWhere = `${where} dynamic dropdown ${index + 1}`;
447
+ const app = row.app;
448
+ const element = row.element;
449
+ if ((app === undefined) === (element === undefined)) {
450
+ throw new EntityTfError(`${rowWhere}: set exactly one of app or element`);
451
+ }
452
+ const kind = app !== undefined ? "app" : "element";
453
+ const token = app ?? element;
454
+ if (token === undefined)
455
+ throw new EntityTfError(`${rowWhere}: set exactly one of app or element`);
456
+ const aspect = dropdownAspect(token, kind, rowWhere, ctx);
457
+ const field = row.field;
458
+ if (field === undefined)
459
+ throw new EntityTfError(`${rowWhere}: field is required`);
460
+ if (typeof row.multiple !== "boolean")
461
+ throw new EntityTfError(`${rowWhere}: multiple must be a boolean`);
462
+ const fieldName = row.fieldName ?? field.name ?? field.refName ?? "";
463
+ if (fieldName === "")
464
+ throw new EntityTfError(`${rowWhere}: field has no name`);
465
+ const aspectRef = {
466
+ refName: token.refName ?? "",
467
+ kind,
468
+ value: aspect.value,
469
+ localTfLabel: aspect.localTfLabel,
470
+ foreignTfLabel: aspect.foreignTfLabel,
471
+ fieldOwnership: aspect.fieldOwnership,
472
+ };
473
+ const dropdown = {
474
+ aspect_id: aspect.value,
475
+ field: fieldName,
476
+ field_id: dropdownFieldValue(field, aspectRef, rowWhere, ctx),
477
+ multiple: row.multiple,
478
+ };
479
+ if (row.filter !== undefined) {
480
+ const local = aspect.localTfLabel !== undefined;
481
+ // An in-workspace aspect addresses its own fields as resources and
482
+ // system-field locals. A data-source aspect has neither: its fields go
483
+ // through foreignField (`ownerFieldsThroughForeign`) and come out as
484
+ // `data.elementum_field` lookups, while `ownerRefName` stays the real
485
+ // refName so `filter.textOption` still sees them as this aspect's.
486
+ dropdown["filter"] = filterToTf(row.filter, `${rowWhere} filter`, {
487
+ ownerTfLabel: local ? aspect.localTfLabel ?? "" : aspect.foreignTfLabel ?? aspectRef.refName,
488
+ ownerRefName: aspectRef.refName,
489
+ scope: kind,
490
+ objectId: aspect.value,
491
+ diagnostics: ctx.diagnostics,
492
+ fieldAddresses: aspect.fieldOwnership,
493
+ ...(local ? {} : { resolvePicklistLiterals: false, ownerFieldsThroughForeign: true }),
494
+ foreignField: (_fieldToken, fieldWhere) => dropdownFieldValue(_fieldToken, aspectRef, fieldWhere, ctx),
495
+ });
496
+ }
497
+ return dropdown;
498
+ });
499
+ return value;
500
+ }
501
+ function systemSkillsValue(config, where, ctx) {
502
+ const value = {};
503
+ if (config.askUserQuestion !== undefined) {
504
+ value["ask_user_question"] = systemSkillValue(config.askUserQuestion, `${where} askUserQuestion`, ctx, true);
505
+ }
506
+ if (config.approvals !== undefined) {
507
+ value["approvals"] = systemSkillValue(config.approvals, `${where} approvals`, ctx, false);
508
+ }
509
+ if (Object.keys(value).length === 0) {
510
+ throw new EntityTfError(`${where}: systemSkillsConfig has neither askUserQuestion nor approvals`);
511
+ }
512
+ return value;
513
+ }
357
514
  /** `elementum_agent` + one tool resource per implemented tool, in ei's dialect. */
358
515
  export function agentToTf(entity, ctx) {
359
516
  if (entity.kind !== "agent") {
@@ -457,6 +614,9 @@ export function agentToTf(entity, ctx) {
457
614
  ctx.diagnostics.push(`${where}: ${knob} is not carried by the terraform path yet; dropped (apply leaves the agent's live ${knob} unchanged)`);
458
615
  }
459
616
  }
617
+ if (elementum.systemSkillsConfig !== undefined) {
618
+ attrs["system_skills_config"] = systemSkillsValue(elementum.systemSkillsConfig, where, ctx);
619
+ }
460
620
  const skillAccess = elementum.skillAccessConfig;
461
621
  if (skillAccess !== undefined) {
462
622
  const mode = skillAccess.mode ?? "NONE";
@@ -522,7 +682,7 @@ export function agentToTf(entity, ctx) {
522
682
  // disambiguates that case with a numeric suffix rather than rejecting it
523
683
  // (see computeA2ASkillLabelSuffixes). A collision within THIS agent's own
524
684
  // a2aSkills list (the same name twice on one agent) is a real authoring
525
- // mistake, not a cross-agent scoping gap — still caught and dropped below.
685
+ // mistake, not a cross-agent scoping gap — a build error below.
526
686
  const a2aSkillLabelSuffixes = computeA2ASkillLabelSuffixes(ctx.siblingEntities ?? [entity]);
527
687
  const seenA2ASkillAddresses = new Set();
528
688
  payload.a2aSkills?.forEach((entry) => {
@@ -536,8 +696,10 @@ export function agentToTf(entity, ctx) {
536
696
  if (skill === undefined)
537
697
  return;
538
698
  if (seenA2ASkillAddresses.has(skill.address)) {
539
- ctx.diagnostics.push(`${where}: a2a skill "${entry.name}" collides with another skill's label (${skill.address}) — names must be unique per agent; dropped`);
540
- return;
699
+ // Dropping it would delete a live skill on the next apply (edk#2508).
700
+ throw new EntityTfError(`${where}: two a2a skills named like ${JSON.stringify(entry.name)} both get the address ${skill.address} ` +
701
+ "(the label lowercases a name, splits camelCase and turns spaces, hyphens and other punctuation into `_`, so names such as \"AskBot\" and \"Ask Bot\" share one). " +
702
+ "A2A skill names must be unique per agent; rename one of them.");
541
703
  }
542
704
  seenA2ASkillAddresses.add(skill.address);
543
705
  blocks.push(skill.block);
@@ -441,6 +441,12 @@ function executeWorkflowFromTf(block, name, where, owner, ctx) {
441
441
  : undefined;
442
442
  if (autoLabel === undefined) {
443
443
  ctx.diagnostics.push(`${where}: automation_id is not an automation/workflow_publish resource reference (${JSON.stringify(autoRef)}); skipped`);
444
+ if (typeof autoRef === "string" && block.type !== undefined && block.label !== undefined) {
445
+ // A raw id: the export left the automation out, so no source can manage
446
+ // the tool. Release an earlier adoption rather than destroy it (#2525).
447
+ ctx.skipped.push(`${block.type}.${block.label}`);
448
+ ctx.releaseIfManaged?.push(`${block.type}.${block.label}`);
449
+ }
444
450
  return undefined;
445
451
  }
446
452
  const inputs = [];
@@ -68,8 +68,8 @@ export declare function agentToolBareLabel(agentBareTfLabel: string, toolName: s
68
68
  * tool's order is part of its address. Pull pins every tool ei suffixed
69
69
  * (agentFromTf), so a pulled agent rebuilds its exported labels even when ei
70
70
  * counted a tool pull doesn't print. Every known tool kind counts, implemented
71
- * or not, as in ei. Parity holds within one agent only: ei's counter spans
72
- * the whole app and is keyed on the agent's display name (edk#2000).
71
+ * or not, as in ei. ei counts per agent too, keyed on the agent's label, so
72
+ * another agent's tools never shift these (edk#2000).
73
73
  */
74
74
  export declare function agentToolLabelSuffixes(agentBareTfLabel: string, tools: readonly Record<string, unknown>[]): readonly string[];
75
75
  /** A tool entry's (`{ createRecord: { name, ... } }`) platform name, or "". */
@@ -178,8 +178,8 @@ export function agentToolBareLabel(agentBareTfLabel, toolName, labelSuffix) {
178
178
  * tool's order is part of its address. Pull pins every tool ei suffixed
179
179
  * (agentFromTf), so a pulled agent rebuilds its exported labels even when ei
180
180
  * counted a tool pull doesn't print. Every known tool kind counts, implemented
181
- * or not, as in ei. Parity holds within one agent only: ei's counter spans
182
- * the whole app and is keyed on the agent's display name (edk#2000).
181
+ * or not, as in ei. ei counts per agent too, keyed on the agent's label, so
182
+ * another agent's tools never shift these (edk#2000).
183
183
  */
184
184
  export function agentToolLabelSuffixes(agentBareTfLabel, tools) {
185
185
  return collisionLabelSuffixes(tools.map((entry) => {
@@ -30,6 +30,7 @@ import type { AppRole, RoleUserRef } from "../role/build.js";
30
30
  import type { GroupRef } from "../../catalog/index.js";
31
31
  import type { AppServiceAccount } from "../service-account/build.js";
32
32
  import type { Filter } from "../shared/filters/types.js";
33
+ import type { FilterFieldToken } from "../shared/filters/index.js";
33
34
  import { type DisplayBlock } from "./display-blocks.js";
34
35
  import type { CalculationInclude, Expr, ExprContext, ExprType } from "../field/calc.js";
35
36
  import { type UnsafePlatformId } from "../../core/platform-id.js";
@@ -116,6 +117,17 @@ export interface AppField {
116
117
  * field even when its display name is changed.
117
118
  */
118
119
  readonly tags?: readonly string[];
120
+ /**
121
+ * Natural bag key when this field was re-keyed off a reserved system key
122
+ * (#1871). Build uses it as the terraform child part so the live address
123
+ * does not move. When renaming an already-applied field (for example
124
+ * `closedAt` → `closedAtCustom`), set this to the original key
125
+ * (`resourceKey: "closedAt"`). A brand-new field needs no `resourceKey`.
126
+ * A bag key that already was `closedAtCustom` because the label was
127
+ * `closed_at_custom` must not set it. Pull stamps this automatically
128
+ * when it re-keys.
129
+ */
130
+ readonly resourceKey?: string;
119
131
  /**
120
132
  * Legacy selection values (`PICKLIST` / `MULTI_PICKLIST`). New authoring
121
133
  * should use `config.static.values` on `dropdownField`/`multiSelectField`;
@@ -341,7 +353,7 @@ export interface AppListView extends ManagedViewSharing {
341
353
  * row filters, and field tokens are resolved to deployed field IDs during
342
354
  * Terraform generation. Pulled provider-native filters also round-trip.
343
355
  */
344
- readonly filter?: Filter;
356
+ readonly filter?: Filter<FilterFieldToken, unknown>;
345
357
  /** Ordered, typed field sorts using the platform's managed-view Sort contract. */
346
358
  readonly sort?: ManagedViewSort;
347
359
  }
@@ -351,7 +363,7 @@ export interface AppAgentView extends ManagedViewSharing {
351
363
  readonly agent: AgentRef;
352
364
  readonly allowRecordCreation?: boolean;
353
365
  /** Provider-native filter object; pulled values round-trip verbatim. */
354
- readonly filter?: Filter;
366
+ readonly filter?: Filter<FilterFieldToken, unknown>;
355
367
  /** Ordered, typed field sorts using the platform's managed-view Sort contract. */
356
368
  readonly sort?: ManagedViewSort;
357
369
  readonly displayOrder?: number;
@@ -373,7 +385,7 @@ export interface AppCustomView extends ManagedViewSharing {
373
385
  readonly agent?: AgentRef;
374
386
  readonly allowRecordCreation?: boolean;
375
387
  /** Provider-native filter object; pulled values round-trip verbatim. */
376
- readonly filter?: Filter;
388
+ readonly filter?: Filter<FilterFieldToken, unknown>;
377
389
  /** Ordered, typed field sorts using the platform's managed-view Sort contract. */
378
390
  readonly sort?: ManagedViewSort;
379
391
  readonly displayOrder?: number;
@@ -393,7 +405,7 @@ export interface AppCalendarView extends ManagedViewSharing {
393
405
  readonly displayByField?: AppViewFieldRef;
394
406
  readonly allowRecordCreation?: boolean;
395
407
  /** Provider-native filter object; pulled values round-trip verbatim. */
396
- readonly filter?: Filter;
408
+ readonly filter?: Filter<FilterFieldToken, unknown>;
397
409
  /** Ordered, typed field sorts using the platform's managed-view Sort contract. */
398
410
  readonly sort?: ManagedViewSort;
399
411
  }
@@ -416,7 +428,7 @@ export interface AppDashboardView extends ManagedViewSharing {
416
428
  /** Stable key from the sibling `dashboards` bag. */
417
429
  readonly dashboard: DashboardRef;
418
430
  readonly allowRecordCreation?: boolean;
419
- readonly filter?: Filter;
431
+ readonly filter?: Filter<FilterFieldToken, unknown>;
420
432
  readonly sort?: ManagedViewSort;
421
433
  }
422
434
  /** One group in the immutable new-record form (`elementum_record_create_form`). */
@@ -509,8 +521,10 @@ interface AppV2OptionsBase<F extends Record<string, AppField> = Record<string, A
509
521
  /**
510
522
  * Overrides for the platform's auto-provisioned system fields (ID, Title,
511
523
  * Status, Stage, and the audit fields). Omit entirely when the app keeps
512
- * every deploy default. The canonical keys are reserved — a custom field
513
- * under `fields:` may not reuse them.
524
+ * every deploy default. System-field keys are reserved: a custom field
525
+ * under `fields:` may not use them (#1871). Pull re-keys a colliding
526
+ * custom field to `<key>Custom` and keeps its terraform address on the
527
+ * natural key.
514
528
  */
515
529
  readonly systemFields?: AppSystemFields;
516
530
  /**
@@ -589,13 +603,15 @@ interface AppV2OptionsBase<F extends Record<string, AppField> = Record<string, A
589
603
  */
590
604
  export declare function serializeField(field: AppField, refName?: string, owner?: string): AspectFieldInput;
591
605
  /**
592
- * Reject a custom `fields:` bag key that is ALSO authored under
593
- * `systemFields` — the same slot provisioned twice. Keys not present in
594
- * systemFields stay legal as ordinary fields (existing workspaces key
595
- * plain fields `title` etc.); full reservation of the canonical keys is
596
- * deferred until system-field ref tokens land on `ref().fields`.
606
+ * Reject a custom `fields:` bag key that matches a reserved system-field key
607
+ * (`closedAt`, `title`, `status`, …). Authors rename the custom field (for
608
+ * example to `closedAtCustom`) and, when the field is already applied, set
609
+ * `resourceKey` to the original key (`resourceKey: "closedAt"`) so the
610
+ * terraform address stays put. A brand-new field needs no `resourceKey`.
611
+ * Pull re-keys a colliding custom field the same way and stamps
612
+ * `resourceKey` automatically (#1871 / Q1 A).
597
613
  */
598
- export declare function assertNoSystemKeyCollision(builder: string, name: string, fields: Record<string, AppField>, systemFields: AppSystemFields | undefined): void;
614
+ export declare function assertNoSystemKeyCollision(builder: string, name: string, fields: Record<string, AppField>, reservedKeys?: ReadonlySet<string>): void;
599
615
  /**
600
616
  * Serialize the AUTHORED system-field overrides into tagged compose entries
601
617
  * (the same wire shape a system field carries on pull). Only authored keys
@@ -658,6 +674,10 @@ export type SystemFieldRefs<Parent extends string = string> = {
658
674
  * fields round out the bag via {@link SystemFieldRefs} — a finite union of
659
675
  * literal keys, deliberately NOT a wide `Record<string, FieldRef>`.
660
676
  *
677
+ * Custom `fields:` keys may not collide with {@link SystemFieldKey} (#1871);
678
+ * {@link assertNoSystemKeyCollision} rejects them at build, and pull re-keys
679
+ * a colliding custom field to `<key>Custom`. The intersection stays exact.
680
+ *
661
681
  * That distinction is load-bearing, not style: a wide `string`-keyed index
662
682
  * signature anywhere in this intersection poisons `RecordShape`
663
683
  * (`entities/field/record-shape.ts`) when `DeepRef`
@@ -1,5 +1,5 @@
1
1
  import { slimTokens, viewType } from "../../catalog/index.js";
2
- import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEYS, SYSTEM_FIELD_REQUIRED, SYSTEM_FIELD_TAG_BY_KEY, WRITABLE_SYSTEM_TAG_NAMES, } from "../../core/system-fields.js";
2
+ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEYS, SYSTEM_FIELD_KEY_SET, SYSTEM_FIELD_REQUIRED, SYSTEM_FIELD_TAG_BY_KEY, WRITABLE_SYSTEM_TAG_NAMES, } from "../../core/system-fields.js";
3
3
  import { serializeDisplayBlocks } from "./display-blocks.js";
4
4
  import { assertCalculatedFieldRoot } from "../field/calc/runtime.js";
5
5
  import { assertAttachmentMediaTypes } from "../field/media-types.js";
@@ -269,6 +269,7 @@ export function serializeField(field, refName, owner) {
269
269
  // the existing id for an update; create lets the server assign one.
270
270
  name: field.name,
271
271
  ...(refName !== undefined ? { __refName: refName } : {}),
272
+ ...(field.resourceKey !== undefined ? { __resourceKey: field.resourceKey } : {}),
272
273
  ...(field.columnName !== undefined ? { columnName: field.columnName } : {}),
273
274
  ...(field.required !== undefined ? { required: field.required } : {}),
274
275
  ...(field.requiredOnClose !== undefined ? { requiredOnClose: field.requiredOnClose } : {}),
@@ -344,18 +345,18 @@ export function serializeField(field, refName, owner) {
344
345
  return { [key]: base };
345
346
  }
346
347
  /**
347
- * Reject a custom `fields:` bag key that is ALSO authored under
348
- * `systemFields` — the same slot provisioned twice. Keys not present in
349
- * systemFields stay legal as ordinary fields (existing workspaces key
350
- * plain fields `title` etc.); full reservation of the canonical keys is
351
- * deferred until system-field ref tokens land on `ref().fields`.
348
+ * Reject a custom `fields:` bag key that matches a reserved system-field key
349
+ * (`closedAt`, `title`, `status`, …). Authors rename the custom field (for
350
+ * example to `closedAtCustom`) and, when the field is already applied, set
351
+ * `resourceKey` to the original key (`resourceKey: "closedAt"`) so the
352
+ * terraform address stays put. A brand-new field needs no `resourceKey`.
353
+ * Pull re-keys a colliding custom field the same way and stamps
354
+ * `resourceKey` automatically (#1871 / Q1 A).
352
355
  */
353
- export function assertNoSystemKeyCollision(builder, name, fields, systemFields) {
354
- if (systemFields === undefined)
355
- return;
356
+ export function assertNoSystemKeyCollision(builder, name, fields, reservedKeys = SYSTEM_FIELD_KEY_SET) {
356
357
  for (const key of Object.keys(fields)) {
357
- if (systemFields[key] !== undefined) {
358
- throw new Error(`${builder} "${name}": fields.${key} collides with the authored systemFields.${key} override — one slot, one author.`);
358
+ if (reservedKeys.has(key)) {
359
+ throw new Error(`${builder} "${name}": fields.${key} uses a reserved system-field key — rename the custom field (for example to ${key}Custom). If the field is already applied, also set resourceKey: "${key}" so the terraform address stays on the live field; a brand-new field needs no resourceKey.`);
359
360
  }
360
361
  }
361
362
  }
@@ -537,6 +538,7 @@ export function app(opts) {
537
538
  ...("dynamicSource" in field && field.dynamicSource === true ? { dynamicSource: true } : {}),
538
539
  ...(field.options !== undefined ? { options: picklistOptionLabels(field.options) } : {}),
539
540
  ...(field.tags !== undefined ? { tags: field.tags } : {}),
541
+ ...(field.resourceKey !== undefined ? { resourceKey: field.resourceKey } : {}),
540
542
  };
541
543
  }
542
544
  for (const key of SYSTEM_FIELD_KEYS) {
@@ -627,7 +629,7 @@ export function app(opts) {
627
629
  return makeRef(refName);
628
630
  },
629
631
  def(refName) {
630
- assertNoSystemKeyCollision("app", opts.name, opts.fields, opts.systemFields);
632
+ assertNoSystemKeyCollision("app", opts.name, opts.fields);
631
633
  const displayBlocks = serializeDisplayBlocks(opts.displayBlocks, "LAYOUT");
632
634
  const recordCreateDisplayBlocks = serializeDisplayBlocks(opts.recordCreateDisplayBlocks, "CREATE");
633
635
  const payload = {
@@ -29,6 +29,7 @@ export interface AppFromTfViewBlocks {
29
29
  readonly relationshipBlocks: readonly TfBlock[];
30
30
  readonly dashboardBlocks: readonly TfBlock[];
31
31
  readonly dashboardWidgetBlocks: readonly TfBlock[];
32
+ readonly dashboardWidgetOrderBlocks?: readonly TfBlock[];
32
33
  readonly widgetBlocks: readonly TfBlock[];
33
34
  }
34
35
  export declare function appFromTf(appBlock: TfBlock, fieldBlocks: readonly TfBlock[], ctx: FromTfContext, viewBlocks?: AppFromTfViewBlocks, accessPolicyBlocks?: readonly TfBlock[], roleBlocks?: readonly TfBlock[], serviceAccountBlocks?: readonly TfBlock[]): AppFromTfResult;
@@ -15,7 +15,7 @@ import { tfLabelToTsLabel } from "../../engine/tf/index.js";
15
15
  import { accessPolicyBlocksInLabelOrder, accessPolicyFromTf } from "../access-policy/from-tf.js";
16
16
  import { dynamicLayoutCompanionWidgetLabels, dynamicLayoutsFromTf, } from "../dynamic-layout/from-tf.js";
17
17
  import { dashboardsFromTf } from "../dashboard/from-tf.js";
18
- import { fieldFromTf } from "../field/from-tf.js";
18
+ import { fieldsFromTf } from "../field/from-tf.js";
19
19
  import { optionsFromTf } from "../field/options.js";
20
20
  import { recordCreateFormFromTf } from "../record-create-form/from-tf.js";
21
21
  import { relationshipsFromTf } from "../relationship/from-tf.js";
@@ -145,11 +145,8 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
145
145
  // --- System-field attributes/config → tagged NormalizedField entries.
146
146
  const fields = [];
147
147
  const owner = { type: APP_RESOURCE_TYPE, label, scope: "app", refName };
148
- const customFields = fieldBlocks.flatMap((block) => {
149
- const entry = fieldFromTf(block, owner, ctx);
150
- return entry === undefined ? [] : [entry];
151
- });
152
- const hasCustomStatusField = customFields.some((field) => field.key === "status");
148
+ // Custom fields in the live field order, keys claimed two-pass (#1871 B1, edk#2920).
149
+ const customFields = fieldsFromTf(fieldBlocks, owner, ctx);
153
150
  const systemConfig = systemFieldConfigFromTf(attrs["system_field_config"], `app "${label}"`, ctx);
154
151
  const titleName = optionalString(attrs, "title_field_name", `app "${label}"`, ctx);
155
152
  if (titleName !== undefined || titleFieldDescription !== undefined || systemConfig.has("title")) {
@@ -161,8 +158,9 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
161
158
  }
162
159
  const statusName = optionalString(attrs, "status_field_name", `app "${label}"`, ctx) ?? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.status;
163
160
  const statusOptions = optionsFromTf(attrs["status_options"], `app "${label}" status_options`, ctx);
164
- if (!hasCustomStatusField
165
- && (statusName !== DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.status || statusOptions !== undefined || statusFieldDescription !== undefined || systemConfig.has("status"))) {
161
+ // Custom status-keyed fields re-key to statusCustom (#1871); the platform
162
+ // status override is independent and may also print. Round-trip proof: S1.
163
+ if (statusName !== DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.status || statusOptions !== undefined || statusFieldDescription !== undefined || systemConfig.has("status")) {
166
164
  const flags = systemConfig.get("status");
167
165
  fields.push({
168
166
  key: "status",
@@ -219,7 +217,7 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
219
217
  const fieldKeys = new Set(fields.map((field) => field.key));
220
218
  // Every field reference pull writes keeps an unextracted field as its platform id (#1736, #1966).
221
219
  const fieldKeysByName = fieldKeysByDisplayName(fields);
222
- const dashboards = dashboardsFromTf(viewBlocks.dashboardBlocks, viewBlocks.dashboardWidgetBlocks, { type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, ownerRefName: refName, scope: "app", ownerType: "APP_ASPECT", fieldKeys, fieldKeysByName, unextractedFieldIds }, ctx);
220
+ const dashboards = dashboardsFromTf(viewBlocks.dashboardBlocks, viewBlocks.dashboardWidgetBlocks, { type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, ownerRefName: refName, scope: "app", ownerType: "APP_ASPECT", fieldKeys, fieldKeysByName, unextractedFieldIds }, ctx, viewBlocks.dashboardWidgetOrderBlocks);
223
221
  const unextracted = { type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "app", fieldKeys, fieldKeysByName, unextractedFieldIds };
224
222
  const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, customViews, viewOrder, deleteDefaultListView } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, viewBlocks.agentViewBlocks, viewBlocks.managedViewOrderBlocks, {
225
223
  type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "app",
@@ -17,6 +17,7 @@ export { attachmentField, booleanField, calculatedField, dateField, dateTimeFiel
17
17
  export { asc, desc, sortBy, type SortDirection, type SortOrder } from "../shared/types/common.js";
18
18
  export { calc, dateDifUnit, dateTimeTruncPrecision, field, orderByDirection, predicateOp, weekdayMode, type ConcatExprType, type DateDifUnit, type DateTimeTruncPrecision, type Expr, type ExprType, type FieldRefExprType, type OrderByDirection, type Predicate, type PredicateOp, type StringAggOptions, type StringAggOrderBy, type WeekdayMode, } from "../field/calc.js";
19
19
  export { agentEvaluation, type AgentEvaluationConfigured, type AgentEvaluationOptions, } from "../agent-evaluation/index.js";
20
+ export { sla, slaTimeUnit, slaWeekDay, type SlaConfigured, type SlaOptions, type SlaTarget, type SlaTimeUnit, type SlaWeekDay, } from "../sla/index.js";
20
21
  export { phoneService, callerAccessMode, type CallerAccessMode, type E164PhoneNumber, type PhoneServiceConfigured, type PhoneServiceNumber, type PhoneServiceOptions, type PhoneServiceRegistration, } from "../phone-service/index.js";
21
22
  export { preservePulledCalculation } from "./deserializer/pulled-expression.js";
22
23
  export { groupId, userId, type AccessPolicyGroupRef, type AccessPolicyOptions, type AccessPolicyPrincipalRef, type AccessPolicyUserRef, type GroupId, type UserId } from "../access-policy/build.js";
@@ -7,6 +7,7 @@ export { attachmentField, booleanField, calculatedField, dateField, dateTimeFiel
7
7
  export { asc, desc, sortBy } from "../shared/types/common.js";
8
8
  export { calc, dateDifUnit, dateTimeTruncPrecision, field, orderByDirection, predicateOp, weekdayMode, } from "../field/calc.js";
9
9
  export { agentEvaluation, } from "../agent-evaluation/index.js";
10
+ export { sla, slaTimeUnit, slaWeekDay, } from "../sla/index.js";
10
11
  export { phoneService, callerAccessMode, } from "../phone-service/index.js";
11
12
  export { preservePulledCalculation } from "./deserializer/pulled-expression.js";
12
13
  export { groupId, userId } from "../access-policy/build.js";
@@ -28,6 +28,7 @@ function extractAppStreamRoot(stream, ctx) {
28
28
  const relationshipBlocks = stream.byKind.get("relationship") ?? [];
29
29
  const dashboardBlocks = stream.byKind.get("dashboard") ?? [];
30
30
  const dashboardWidgetBlocks = stream.byKind.get("dashboard-widget") ?? [];
31
+ const dashboardWidgetOrderBlocks = stream.byKind.get("dashboard-widget-order") ?? [];
31
32
  const widgetBlocks = stream.byKind.get("widget") ?? [];
32
33
  const accessPolicyBlocks = stream.byKind.get("access-policy") ?? [];
33
34
  const roleBlocks = stream.byKind.get("role") ?? [];
@@ -49,6 +50,7 @@ function extractAppStreamRoot(stream, ctx) {
49
50
  relationshipBlocks,
50
51
  dashboardBlocks,
51
52
  dashboardWidgetBlocks,
53
+ dashboardWidgetOrderBlocks,
52
54
  widgetBlocks,
53
55
  }, accessPolicyBlocks, roleBlocks, serviceAccountBlocks);
54
56
  return {
@@ -78,6 +80,7 @@ export const appModule = {
78
80
  diagnostics: ctx.diagnostics,
79
81
  workspaceAspects: ctx.workspaceAspects,
80
82
  ...(ctx.outOfScopeApps !== undefined && { outOfScopeApps: ctx.outOfScopeApps }),
83
+ ...(ctx.optionIds !== undefined && { optionIds: ctx.optionIds }),
81
84
  });
82
85
  return {
83
86
  blocks: result.blocks,
@@ -12,8 +12,8 @@ export declare function stageKeyFromPicklistValue(pv: PicklistValueWire): AppSta
12
12
  /**
13
13
  * Every tf-label handle that authored source or pull can use for a stage,
14
14
  * mapped to the stage's real `stage_ids_by_key` key (#1136). A layout bag key,
15
- * a dynamic-layout `stage`, an approval chain `stage` or a visual-flow
16
- * `stage` resolves through this map. Handles:
15
+ * a dynamic-layout `stage`, an approval chain `stage`, a visual-flow
16
+ * `stage` or an SLA clock's `stages` entry resolves through this map. Handles:
17
17
  * - the real key itself, when it is a tf label. This covers renamed stages
18
18
  * (`legacy_key` for "Renamed stage") and keys such as `foo__bar` that are
19
19
  * legal tf labels but not the slug;
@@ -14,8 +14,8 @@ export function stageKeyFromPicklistValue(pv) {
14
14
  /**
15
15
  * Every tf-label handle that authored source or pull can use for a stage,
16
16
  * mapped to the stage's real `stage_ids_by_key` key (#1136). A layout bag key,
17
- * a dynamic-layout `stage`, an approval chain `stage` or a visual-flow
18
- * `stage` resolves through this map. Handles:
17
+ * a dynamic-layout `stage`, an approval chain `stage`, a visual-flow
18
+ * `stage` or an SLA clock's `stages` entry resolves through this map. Handles:
19
19
  * - the real key itself, when it is a tf label. This covers renamed stages
20
20
  * (`legacy_key` for "Renamed stage") and keys such as `foo__bar` that are
21
21
  * legal tf labels but not the slug;
@@ -105,7 +105,7 @@ function stageHandleBindings(stages, diagnostics) {
105
105
  const lost = lostTo.get(stage.key);
106
106
  if (bound.has(stage.key) || reported.has(stage.key) || lost === undefined)
107
107
  continue;
108
- diagnostics?.push(`systemFields.stage: stage "${stage.key}" has no handle of its own: its handle "${lost.handle}" is stage "${lost.owner}"'s key. Source cannot reference "${stage.key}", so pull leaves its layouts, dynamic layouts, approval chains and flows unmanaged (each one warned) instead of binding them to "${lost.owner}". Rename one of the stages so each has its own handle.`);
108
+ diagnostics?.push(`systemFields.stage: stage "${stage.key}" has no handle of its own: its handle "${lost.handle}" is stage "${lost.owner}"'s key. Source cannot reference "${stage.key}", so pull leaves its layouts, dynamic layouts, approval chains, flows and SLA clocks unmanaged (each one warned) instead of binding them to "${lost.owner}". Rename one of the stages so each has its own handle.`);
109
109
  }
110
110
  return { byHandle, fallbackLost };
111
111
  }
@@ -345,6 +345,7 @@ export function appToTf(entity, ctx) {
345
345
  objectId,
346
346
  orgRefs: ctx.orgRefs,
347
347
  diagnostics: ctx.diagnostics,
348
+ ...(ctx.optionIds !== undefined && { optionIds: ctx.optionIds }),
348
349
  appRefName: ctx.appRefName,
349
350
  serviceAccounts: payload.serviceAccounts,
350
351
  fieldAddresses,