@elementumai/edk 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/README.md +7 -7
  2. package/dist-sdk/src/catalog/org.d.ts +7 -5
  3. package/dist-sdk/src/catalog/org.js +14 -9
  4. package/dist-sdk/src/catalog/token.js +4 -0
  5. package/dist-sdk/src/core/types/app.d.ts +22 -0
  6. package/dist-sdk/src/engine/build/context.d.ts +8 -0
  7. package/dist-sdk/src/engine/build/source-context.d.ts +3 -4
  8. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  9. package/dist-sdk/src/engine/coverage-gaps.js +3 -0
  10. package/dist-sdk/src/engine/ei/state.d.ts +48 -0
  11. package/dist-sdk/src/engine/ei/state.js +91 -0
  12. package/dist-sdk/src/engine/pull/authored-address.d.ts +100 -0
  13. package/dist-sdk/src/engine/pull/authored-address.js +360 -0
  14. package/dist-sdk/src/engine/pull/context.d.ts +59 -0
  15. package/dist-sdk/src/engine/tf/expr.d.ts +7 -0
  16. package/dist-sdk/src/engine/tf/expr.js +62 -18
  17. package/dist-sdk/src/engine/tf/index.d.ts +1 -1
  18. package/dist-sdk/src/engine/tf/index.js +1 -1
  19. package/dist-sdk/src/engine/tf/labels.d.ts +10 -2
  20. package/dist-sdk/src/engine/tf/labels.js +15 -2
  21. package/dist-sdk/src/engine/tf/parse.js +19 -6
  22. package/dist-sdk/src/engine/workspace/backend.d.ts +34 -0
  23. package/dist-sdk/src/engine/workspace/backend.js +104 -0
  24. package/dist-sdk/src/engine/workspace/generated-file.d.ts +3 -0
  25. package/dist-sdk/src/engine/workspace/generated-file.js +6 -0
  26. package/dist-sdk/src/engine/workspace/loader.js +2 -2
  27. package/dist-sdk/src/entities/agent-tool/to-tf.js +1 -1
  28. package/dist-sdk/src/entities/app/build.d.ts +36 -4
  29. package/dist-sdk/src/entities/app/build.js +67 -4
  30. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +12 -0
  31. package/dist-sdk/src/entities/app/from-tf.js +13 -9
  32. package/dist-sdk/src/entities/app/module.js +3 -1
  33. package/dist-sdk/src/entities/app/stage-keys.d.ts +82 -0
  34. package/dist-sdk/src/entities/app/stage-keys.js +160 -0
  35. package/dist-sdk/src/entities/app/to-tf.js +21 -21
  36. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +9 -1
  37. package/dist-sdk/src/entities/approval-chain/from-tf.js +31 -3
  38. package/dist-sdk/src/entities/approval-chain/module.js +12 -4
  39. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +1 -0
  40. package/dist-sdk/src/entities/approval-chain/to-tf.js +6 -1
  41. package/dist-sdk/src/entities/automation/build.d.ts +2 -0
  42. package/dist-sdk/src/entities/automation/build.js +25 -17
  43. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +3 -0
  44. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +5 -3
  45. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +127 -31
  46. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  47. package/dist-sdk/src/entities/automation/from-tf.js +172 -27
  48. package/dist-sdk/src/entities/automation/module.js +123 -37
  49. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +21 -0
  50. package/dist-sdk/src/entities/automation/output-key-wire-name.js +38 -0
  51. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -1
  52. package/dist-sdk/src/entities/automation/to-tf.js +191 -33
  53. package/dist-sdk/src/entities/automation/triggers.d.ts +2 -0
  54. package/dist-sdk/src/entities/automation/triggers.js +1 -0
  55. package/dist-sdk/src/entities/chart/from-tf.d.ts +6 -0
  56. package/dist-sdk/src/entities/chart/from-tf.js +9 -1
  57. package/dist-sdk/src/entities/dashboard/from-tf.js +51 -4
  58. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  59. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +48 -4
  60. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +2 -0
  61. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -2
  62. package/dist-sdk/src/entities/element/build.js +1 -1
  63. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -6
  64. package/dist-sdk/src/entities/element/from-tf.js +23 -7
  65. package/dist-sdk/src/entities/element/module.js +5 -3
  66. package/dist-sdk/src/entities/element/to-tf.d.ts +3 -2
  67. package/dist-sdk/src/entities/element/to-tf.js +36 -25
  68. package/dist-sdk/src/entities/field/allow-list.d.ts +18 -0
  69. package/dist-sdk/src/entities/field/allow-list.js +42 -0
  70. package/dist-sdk/src/entities/field/build.d.ts +38 -3
  71. package/dist-sdk/src/entities/field/build.js +7 -2
  72. package/dist-sdk/src/entities/field/from-tf.js +252 -76
  73. package/dist-sdk/src/entities/field/module.d.ts +6 -0
  74. package/dist-sdk/src/entities/field/module.js +24 -2
  75. package/dist-sdk/src/entities/field/options.d.ts +2 -0
  76. package/dist-sdk/src/entities/field/order.d.ts +25 -0
  77. package/dist-sdk/src/entities/field/order.js +74 -0
  78. package/dist-sdk/src/entities/field/to-tf.d.ts +6 -0
  79. package/dist-sdk/src/entities/field/to-tf.js +87 -0
  80. package/dist-sdk/src/entities/field/types.d.ts +5 -0
  81. package/dist-sdk/src/entities/field/types.js +8 -0
  82. package/dist-sdk/src/entities/relationship/build.d.ts +3 -3
  83. package/dist-sdk/src/entities/relationship/from-tf.js +4 -2
  84. package/dist-sdk/src/entities/relationship/to-tf.js +3 -1
  85. package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +8 -3
  86. package/dist-sdk/src/entities/service-account/workspace-owner.js +12 -4
  87. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +5 -0
  88. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +13 -0
  89. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -0
  90. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +1 -1
  91. package/dist-sdk/src/entities/skill/to-tf.js +19 -14
  92. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  93. package/dist-sdk/src/entities/skill-tool/from-tf.js +3 -0
  94. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +6 -1
  95. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -1
  96. package/dist-sdk/src/entities/task/build.js +1 -1
  97. package/dist-sdk/src/entities/task/module.js +2 -1
  98. package/dist-sdk/src/entities/task/to-tf.js +4 -0
  99. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +11 -0
  100. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +13 -38
  101. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +29 -0
  102. package/dist-sdk/src/entities/view/custom-view-validate.js +292 -0
  103. package/dist-sdk/src/entities/view/from-tf.d.ts +2 -0
  104. package/dist-sdk/src/entities/view/from-tf.js +40 -6
  105. package/dist-sdk/src/entities/view/module.js +4 -1
  106. package/dist-sdk/src/entities/view/to-tf.d.ts +6 -0
  107. package/dist-sdk/src/entities/view/to-tf.js +25 -9
  108. package/dist-sdk/src/entities/view/types.d.ts +6 -0
  109. package/dist-sdk/src/entities/view/types.js +6 -0
  110. package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +2 -1
  111. package/dist-sdk/src/entities/visual-flow/from-tf.js +11 -2
  112. package/dist-sdk/src/entities/visual-flow/module.js +15 -5
  113. package/dist-sdk/src/entities/visual-flow/to-tf.d.ts +2 -0
  114. package/dist-sdk/src/entities/visual-flow/to-tf.js +1 -1
  115. package/dist-sdk/src/entities/widget/build.d.ts +8 -1
  116. package/dist-sdk/src/entities/widget/from-tf.js +12 -6
  117. package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
  118. package/dist-sdk/src/entities/widget/to-tf.js +16 -0
  119. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +8 -2
  120. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  121. package/dist-sdk/src/graph/index.d.ts +9 -2
  122. package/dist-sdk/src/graph/index.js +4 -0
  123. package/dist-sdk/src/graph/modules.js +2 -1
  124. package/dist-sdk/src/graph/types.d.ts +72 -3
  125. package/package.json +2 -17
@@ -35,11 +35,12 @@ import { sdkPackageSpecifier } from "../../../internal/sdk-package.js";
35
35
  import { safeIdentifier } from "../../../internal/safe-identifier.js";
36
36
  import { isRefExpr } from "../../shared/filters/ast.js";
37
37
  import { printFilter as printCanonicalFilter } from "../../shared/filters/print.js";
38
- import { isUuid } from "../../../engine/tf/labels.js";
38
+ import { isUuid, sanitizeName, tfLabelToTsLabel } from "../../../engine/tf/labels.js";
39
39
  import { UNRESOLVED_FIELD_MARKER } from "../../shared/ref.js";
40
40
  import { UNRESOLVED_REFERENCE_MARKER } from "../filter.js";
41
41
  import { INJECTED_TS_IGNORE, scriptFileText } from "../script-code.js";
42
42
  import { isRequiredSecret } from "../tasks.js";
43
+ import { canonicalImportId } from "../../../engine/pull/authored-address.js";
43
44
  import { unresolvedReferenceComment } from "../../../engine/pull/ref-only.js";
44
45
  // ---------------------------------------------------------------------------
45
46
  // Factory name mapping — decoded task `factory` → v2 factory function name.
@@ -141,14 +142,20 @@ function revisionAtLeast(a, b) {
141
142
  function stateWorkflowRevision(context) {
142
143
  if (context?.platformId === undefined || context.stateResources === undefined)
143
144
  return undefined;
145
+ const want = canonicalImportId(context.platformId);
146
+ if (want === "")
147
+ return undefined;
144
148
  for (const resource of context.stateResources) {
145
- if (resource.type !== "elementum_workflow_publish")
149
+ if (resource.mode !== "managed" || resource.module !== undefined || resource.type !== "elementum_workflow_publish")
146
150
  continue;
147
- for (const instance of resource.instances ?? []) {
148
- const attrs = instance.attributes;
149
- if (attrs?.id === context.platformId && typeof attrs.workflow_revision === "string")
150
- return attrs.workflow_revision;
151
- }
151
+ const attrs = resource.instances?.[0]?.attributes;
152
+ const id = attrs?.id;
153
+ const revision = attrs?.workflow_revision;
154
+ if (typeof id !== "string" || canonicalImportId(id) !== want)
155
+ continue;
156
+ if (typeof revision !== "string" || revision === "")
157
+ continue;
158
+ return revision;
152
159
  }
153
160
  return undefined;
154
161
  }
@@ -161,9 +168,17 @@ function stateWorkflowRevision(context) {
161
168
  * least the baseline — the state revision, or the freshly printed live revision
162
169
  * when state has no entry yet (adoption is about to import it). An older
163
170
  * authored token is replaced by that baseline. Without readable state the
164
- * pre-#1590 behaviour (always keep authored) is unchanged.
171
+ * pre-#1590 behaviour (always keep authored) is unchanged. With no existing
172
+ * source, a publish already bound in state keeps the state revision: the
173
+ * export prints `1.0.<live version>`, which Read never writes back (#1902).
165
174
  */
166
175
  export function preserveAuthoredAutomationRevision(freshSource, existingSource, context) {
176
+ if (existingSource === undefined) {
177
+ const bound = stateWorkflowRevision(context);
178
+ if (bound === undefined || !REVISION_PROPERTY.test(freshSource))
179
+ return freshSource;
180
+ return freshSource.replace(REVISION_PROPERTY, (_line, prefix) => `${prefix}${JSON.stringify(bound)},`);
181
+ }
167
182
  const authored = REVISION_PROPERTY.exec(existingSource)?.[3];
168
183
  if (authored === undefined || authored === "")
169
184
  return freshSource;
@@ -503,7 +518,8 @@ export function preserveAuthoredAutomationDescription(freshSource, existingSourc
503
518
  }
504
519
  /** Pull merge: preserve authored revision + description across live reprint. */
505
520
  export function preserveAuthoredAutomationPullMeta(freshSource, existingSource, context) {
506
- return preserveAuthoredAutomationDescription(preserveAuthoredAutomationRevision(freshSource, existingSource, context), existingSource);
521
+ const revised = preserveAuthoredAutomationRevision(freshSource, existingSource, context);
522
+ return existingSource === undefined ? revised : preserveAuthoredAutomationDescription(revised, existingSource);
507
523
  }
508
524
  function emptyImports() {
509
525
  return {
@@ -654,7 +670,7 @@ function printAutomation(ast, opts, externalScripts) {
654
670
  }
655
671
  body.push(` app: catalog.${appRefName},`);
656
672
  if (ast.serviceAccountName !== undefined) {
657
- body.push(` serviceAccount: serviceAccountRef({ app: catalog.${appRefName}, name: ${quote(ast.serviceAccountName)} }),`);
673
+ body.push(` serviceAccount: serviceAccountRef({ app: catalog.${ast.serviceAccountAppRefName ?? appRefName}, name: ${quote(ast.serviceAccountName)} }),`);
658
674
  }
659
675
  body.push(` status: automationStatus.${automationStatusKey(ast.status)},`);
660
676
  body.push(` actions: actions()`);
@@ -882,6 +898,7 @@ function printTrigger(trigger, state) {
882
898
  `app: ${printRef(trigger.app, state, DEFAULT_CTX)}`,
883
899
  ...(approvalChain !== undefined ? [`approvalChain: ${approvalChain}`] : []),
884
900
  `status: ${quote(trigger.status)}`,
901
+ ...(trigger.filter ? [`filter: ${printFilter(trigger.filter, state)}`] : []),
885
902
  ];
886
903
  return `${approvalProcessStatusUpdated}({\n ${parts.join(",\n ")}\n })`;
887
904
  }
@@ -1387,7 +1404,7 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
1387
1404
  const parentRef = target?.refName ?? assignment?.foreignOwnerName ?? "task";
1388
1405
  const parentName = target?.name ?? assignment?.foreignOwnerName ?? parentRef;
1389
1406
  const fieldName = assignment?.foreignFieldName ?? fieldKey;
1390
- const fieldType = assignment?.foreignFieldType ?? "TEXT";
1407
+ const fieldType = assignment?.foreignFieldType ?? unconfirmedFieldType(assignment?.value);
1391
1408
  fieldExpr = (`{ __kind: "field", refName: ${quote(fieldKey)}, name: ${quote(fieldName)}, fieldType: ${quote(fieldType)}, ` +
1392
1409
  `parent: ${quote(parentRef)}, parentKind: "task", parentName: ${quote(parentName)} }`);
1393
1410
  }
@@ -1395,7 +1412,7 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
1395
1412
  !target.inCatalog &&
1396
1413
  assignment?.foreignOwnerNamespace !== undefined &&
1397
1414
  !fieldKey.startsWith(UNRESOLVED_FIELD_MARKER)) {
1398
- const fieldType = assignment.foreignFieldType ?? "TEXT";
1415
+ const fieldType = assignment.foreignFieldType ?? unconfirmedFieldType(assignment.value);
1399
1416
  const parentName = assignment.foreignOwnerName ?? target.name ?? target.refName;
1400
1417
  fieldExpr = (`{ __kind: "field", refName: ${quote(fieldKey)}, name: ${quote(assignment.foreignFieldName ?? fieldKey)}, fieldType: ${quote(fieldType)}, ` +
1401
1418
  `parent: ${quote(target.refName)}, parentKind: ${quote(target.kind)}, parentName: ${quote(parentName)}, ` +
@@ -1416,12 +1433,25 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
1416
1433
  const foreignOwner = assignment?.foreignOwnerName;
1417
1434
  const foreignKind = assignment?.foreignEntityType;
1418
1435
  if ((foreignKind === "app" || foreignKind === "element") && foreignOwner !== undefined && foreignOwner !== "" && !isUuid(rawKey) && assignment?.foreignFieldType !== undefined) {
1419
- fieldExpr = `catalog.${foreignOwner}.fields${safeMember(rawKey)}`;
1436
+ const ownerKey = workspaceAspectRefName(state, foreignKind, foreignOwner, assignment.foreignOwnerNamespace)
1437
+ ?? namespaceCatalogKey(assignment.foreignOwnerNamespace)
1438
+ ?? foreignOwner;
1439
+ fieldExpr = `catalog.${ownerKey}.fields${safeMember(rawKey)}`;
1420
1440
  }
1421
1441
  else if (!isUuid(rawKey)) {
1422
- // A bag key with no known owner and type is not a TEXT field. Inventing
1423
- // one makes the next build address elementum_text_field.
1424
- fieldExpr = `/* unresolved field ${quote(rawKey)} */ null`;
1442
+ const platformFieldId = assignment?.platformFieldId;
1443
+ if (platformFieldId !== undefined && isUuid(platformFieldId)) {
1444
+ // The key was rewritten from a platform id whose owner is not in
1445
+ // this workspace. Keep that id. A null field fails to load, and a
1446
+ // guessed TEXT stub builds elementum_text_field.
1447
+ state.imports.usesUnsafePlatformId = true;
1448
+ fieldExpr = `unsafePlatformId(${quote(platformFieldId)})`;
1449
+ }
1450
+ else {
1451
+ // A bag key with no known owner and type is not a TEXT field. Inventing
1452
+ // one makes the next build address elementum_text_field.
1453
+ fieldExpr = `/* unresolved field ${quote(rawKey)} */ null`;
1454
+ }
1425
1455
  }
1426
1456
  else {
1427
1457
  state.imports.usesUnsafePlatformId = true;
@@ -1434,6 +1464,15 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
1434
1464
  });
1435
1465
  return `[\n${lines.join("\n")}\n${pad}]`;
1436
1466
  }
1467
+ /**
1468
+ * The type a foreign field stub prints with when ei's data source can't
1469
+ * confirm it. Only a Multi-Select takes an array value, so an array (a
1470
+ * `jsonencode([...])` value, including the `[]` clear) prints as one;
1471
+ * anything else keeps the TEXT guess (#1707).
1472
+ */
1473
+ function unconfirmedFieldType(value) {
1474
+ return Array.isArray(value) ? "MULTI_PICKLIST" : "TEXT";
1475
+ }
1437
1476
  /**
1438
1477
  * The task's primary target, used to resolve `values:` field keys to
1439
1478
  * `<target>.fields.<key>` tokens (or inline field stubs for tasks).
@@ -1455,11 +1494,14 @@ function taskPrimaryTarget(args, state) {
1455
1494
  return { kind: "task", refName, name: v.name ?? refName, inCatalog: foreignRefName !== undefined };
1456
1495
  }
1457
1496
  if (v.entityType === "element") {
1458
- const foreignRefName = v.name !== undefined ? state.foreignElementRefNames?.get(v.name) : undefined;
1459
- return { kind: "element", refName: foreignRefName ?? v.appHandle, name: v.name, inCatalog: v.name === undefined || foreignRefName !== undefined };
1497
+ const foreignRefName = workspaceAspectRefName(state, "element", v.name, v.namespace);
1498
+ const refName = foreignRefName ?? namespaceCatalogKey(v.namespace) ?? v.appHandle;
1499
+ return { kind: "element", refName, name: v.name, inCatalog: v.name === undefined || foreignRefName !== undefined };
1460
1500
  }
1461
- const foreignRefName = v.name !== undefined ? state.foreignAppRefNames?.get(v.name) : undefined;
1462
- const refName = foreignRefName ?? catalogOwnerHandle(state, v.appHandle);
1501
+ const foreignRefName = workspaceAspectRefName(state, "app", v.name, v.namespace);
1502
+ const refName = foreignRefName
1503
+ ?? (v.entityType === "app" ? namespaceCatalogKey(v.namespace) : undefined)
1504
+ ?? catalogOwnerHandle(state, v.appHandle);
1463
1505
  return { kind: "app", refName, name: v.name, inCatalog: v.entityType === undefined || v.name === undefined || foreignRefName !== undefined };
1464
1506
  }
1465
1507
  const aspectId = typeof v === "string"
@@ -1483,6 +1525,65 @@ function taskPrimaryTarget(args, state) {
1483
1525
  }
1484
1526
  return undefined;
1485
1527
  }
1528
+ /**
1529
+ * The workspace catalog key for a foreign app/element ref: by namespace, then
1530
+ * display name. A namespace-only data block's ref carries the namespace as
1531
+ * its name, so the name map alone misses it.
1532
+ */
1533
+ function workspaceAspectRefName(state, kind, name, namespace) {
1534
+ const namespaces = kind === "app" ? state.foreignAppRefNamespaces : state.foreignElementRefNamespaces;
1535
+ const names = kind === "app" ? state.foreignAppRefNames : state.foreignElementRefNames;
1536
+ return (namespace !== undefined ? namespaces?.get(namespace) : undefined)
1537
+ ?? (name !== undefined ? names?.get(name) : undefined);
1538
+ }
1539
+ /**
1540
+ * A foreign field's owner as a workspace catalog key.
1541
+ *
1542
+ * A known kind searches only that kind. An unknown kind (`ownerKindUnknown`)
1543
+ * is a raw field id the registry named by catalog key and did not classify.
1544
+ * That key is a namespace-map or name-map value, not a display name. Joining
1545
+ * it there first keeps an app whose display name equals the element ref from
1546
+ * being chosen ahead of a renamed element's namespace-map entry.
1547
+ */
1548
+ function workspaceFieldOwnerRefName(state, foreign, appHandle) {
1549
+ const knownKind = foreign.entityType === "element" ? "element" : "app";
1550
+ if (!foreign.ownerKindUnknown) {
1551
+ return workspaceAspectRefName(state, knownKind, foreign.name, foreign.namespace)
1552
+ ?? (isWorkspaceAspectRefName(state, knownKind, appHandle) ? appHandle : undefined);
1553
+ }
1554
+ const elementOwnsKey = isWorkspaceAspectRefName(state, "element", appHandle);
1555
+ const appOwnsKey = isWorkspaceAspectRefName(state, "app", appHandle);
1556
+ if (elementOwnsKey !== appOwnsKey)
1557
+ return appHandle;
1558
+ if (foreign.namespace !== undefined) {
1559
+ const elementRef = state.foreignElementRefNamespaces?.get(foreign.namespace);
1560
+ const appRef = state.foreignAppRefNamespaces?.get(foreign.namespace);
1561
+ if (elementRef !== undefined && appRef === undefined)
1562
+ return elementRef;
1563
+ if (appRef !== undefined && elementRef === undefined)
1564
+ return appRef;
1565
+ }
1566
+ for (const kind of ["app", "element"]) {
1567
+ const found = workspaceAspectRefName(state, kind, foreign.name, foreign.namespace)
1568
+ ?? (isWorkspaceAspectRefName(state, kind, appHandle) ? appHandle : undefined);
1569
+ if (found !== undefined)
1570
+ return found;
1571
+ }
1572
+ return undefined;
1573
+ }
1574
+ /**
1575
+ * An app's or element's catalog key is its sanitized namespace (its stream
1576
+ * label), so a foreign target that is not on disk yet still has a stable key.
1577
+ */
1578
+ function namespaceCatalogKey(namespace) {
1579
+ return namespace === undefined || namespace === "" ? undefined : tfLabelToTsLabel(sanitizeName(namespace));
1580
+ }
1581
+ /** The pulled field registry names a field's owner by its catalog key, not its platform name. */
1582
+ function isWorkspaceAspectRefName(state, kind, refName) {
1583
+ const namespaces = kind === "app" ? state.foreignAppRefNamespaces : state.foreignElementRefNamespaces;
1584
+ const names = kind === "app" ? state.foreignAppRefNames : state.foreignElementRefNames;
1585
+ return [...(namespaces?.values() ?? []), ...(names?.values() ?? [])].includes(refName);
1586
+ }
1486
1587
  // ---------------------------------------------------------------------------
1487
1588
  // Argument value printer — dispatches on runtime shape
1488
1589
  // ---------------------------------------------------------------------------
@@ -1677,14 +1778,11 @@ function printRef(ref, state, refCtx) {
1677
1778
  // pulled into this workspace (board issue #40, app-only) resolves to a
1678
1779
  // typed token; otherwise a literal stub (field type is unconfirmed —
1679
1780
  // ei's `elementum_field` data source doesn't expose it).
1680
- const namespace = ref.foreign.namespace;
1681
- const foreignRefName = ref.foreign.entityType === "element"
1682
- ? (namespace !== undefined ? state.foreignElementRefNamespaces?.get(namespace) : undefined) ?? state.foreignElementRefNames?.get(ref.foreign.name)
1781
+ const foreignRefName = ref.foreign.entityType === "element" || ref.foreign.entityType === "app"
1782
+ ? workspaceFieldOwnerRefName(state, ref.foreign, ref.appHandle)
1683
1783
  : ref.foreign.entityType === "task"
1684
1784
  ? state.foreignTaskRefNames?.get(ref.foreign.name)
1685
- : ref.foreign.entityType === "app"
1686
- ? (namespace !== undefined ? state.foreignAppRefNamespaces?.get(namespace) : undefined) ?? state.foreignAppRefNames?.get(ref.foreign.name)
1687
- : undefined;
1785
+ : undefined;
1688
1786
  if (ref.foreign.entityType === "task") {
1689
1787
  const parentRef = foreignRefName ?? ref.appHandle;
1690
1788
  const fieldType = ref.foreign.fieldType ?? "TEXT";
@@ -1716,13 +1814,11 @@ function printRef(ref, state, refCtx) {
1716
1814
  if (ref.entityType === undefined || ref.name === undefined) {
1717
1815
  return `catalog.${catalogOwnerHandle(state, ref.appHandle)}`;
1718
1816
  }
1719
- const foreignRefName = ref.entityType === "element"
1720
- ? state.foreignElementRefNames?.get(ref.name)
1817
+ const foreignRefName = ref.entityType === "element" || ref.entityType === "app"
1818
+ ? workspaceAspectRefName(state, ref.entityType, ref.name, ref.namespace)
1721
1819
  : ref.entityType === "task"
1722
1820
  ? state.foreignTaskRefNames?.get(ref.name)
1723
- : ref.entityType === "app"
1724
- ? state.foreignAppRefNames?.get(ref.name)
1725
- : undefined;
1821
+ : undefined;
1726
1822
  if (foreignRefName !== undefined)
1727
1823
  return `catalog.${foreignRefName}`;
1728
1824
  const namespace = ref.namespace !== undefined ? `, namespace: ${quote(ref.namespace)}` : "";
@@ -1,4 +1,5 @@
1
1
  import { EntityTfError } from "../../engine/entity.js";
2
+ import { type FromTfContext } from "../../engine/pull/context.js";
2
3
  import { type ChildResourceScope, type TfBlock, type TfDocument, type TfValue } from "../../engine/tf/index.js";
3
4
  import type { AutomationAst } from "./deserializer/ast.js";
4
5
  export interface AutomationFromTfResult {
@@ -13,6 +14,14 @@ export interface AutomationFromTfResult {
13
14
  }[];
14
15
  /** Non-fatal issues found while extracting (edk#785: a task anchored to the trigger because its real parent is unsupported). */
15
16
  readonly diagnostics?: readonly string[];
17
+ /**
18
+ * The export embeds a stringified ValueReference envelope whose task,
19
+ * trigger, or variable is not in this automation, so source cannot
20
+ * reproduce it (edk#1646 / #1798). Envelopes that decode to a ctx
21
+ * reference don't set this: the adoption gate checks those like any
22
+ * other value.
23
+ */
24
+ readonly stringifiedValueReferences?: boolean;
16
25
  }
17
26
  interface DecodeContext {
18
27
  readonly appRefName: string;
@@ -68,6 +77,10 @@ interface DecodeContext {
68
77
  readonly procedureKeysByDiscriminator?: ReadonlyMap<string, string>;
69
78
  /** Group name → org.ts's `org.groups` key, for static recipients (edk#1412). See `FromTfContext.groupKeysByName`. */
70
79
  readonly groupKeysByName?: ReadonlyMap<string, string>;
80
+ /** Set when this automation's export contains a stringified ValueReference envelope that does not resolve. */
81
+ readonly stringifiedValueReferences?: {
82
+ unresolved: boolean;
83
+ };
71
84
  }
72
85
  /**
73
86
  * The same outputs as seen from a CALCULATION formula, which addresses a
@@ -97,8 +110,8 @@ export declare function inferredPublishOutputType(value: TfValue, ctx: DecodeCon
97
110
  * conditions that make real extraction fail (zero triggers, an
98
111
  * unrecognized task kind) so it over-collects rather than under-collects.
99
112
  * More than one trigger throws {@link UnsupportedMultiTriggerError}. The
100
- * stream extractor records that as a fatal validation, excludes these
101
- * addresses, and continues so every multi-trigger automation is reported.
113
+ * stream extractor soft-skips those automations (diagnostic + skipped +
114
+ * releaseIfManaged), so the rest of the app can still adopt (#1785).
102
115
  * A false positive
103
116
  * here just leaves one more resource unmanaged; a false negative would
104
117
  * silently destroy a live automation on apply.
@@ -107,15 +120,23 @@ export declare function automationOwnedAddresses(doc: TfDocument, automationLabe
107
120
  /**
108
121
  * EDK does not author multi-trigger automations; apps should keep one
109
122
  * trigger and call the shared logic with a run-automation action. Stream
110
- * extraction records every one of these and continues. Direct
111
- * `automationFromTf` still throws. Callers that turn other extract failures
112
- * into soft skips must not treat this as one of those skips.
123
+ * extraction soft-skips every one of these (warn + skip + releaseIfManaged)
124
+ * so the rest of the app can still adopt (#1785). Direct `automationFromTf`
125
+ * still throws so callers that need a hard signal can catch it.
113
126
  */
114
127
  export declare class UnsupportedMultiTriggerError extends EntityTfError {
115
128
  readonly automationName: string;
116
129
  readonly triggerCount: number;
117
130
  constructor(automationName: string, triggerCount: number);
118
131
  }
132
+ /**
133
+ * A bare service_account_id belongs to an app this export does not contain.
134
+ * Pull cannot print a serviceAccountRef until that app is in the workspace,
135
+ * and printing nothing would clear the live account.
136
+ */
137
+ export declare class UnresolvedForeignServiceAccountError extends EntityTfError {
138
+ constructor(automationLabel: string);
139
+ }
119
140
  /**
120
141
  * #1320: a task reads the current item of a loop that doesn't enclose it.
121
142
  * Pull skips the automation like any other exclusion, and additionally
@@ -154,6 +175,7 @@ export interface AutomationFromTfContext {
154
175
  readonly foreignTaskRefNames?: ReadonlyMap<string, string>;
155
176
  readonly procedureKeysByDiscriminator?: ReadonlyMap<string, string>;
156
177
  readonly groupKeysByName?: ReadonlyMap<string, string>;
178
+ readonly serviceAccountsById?: FromTfContext["serviceAccountsById"];
157
179
  }
158
180
  export interface AutomationGraphFromTfResult {
159
181
  readonly automation?: AutomationAst;
@@ -177,5 +199,5 @@ export declare function automationFromTf(doc: TfDocument, automationLabel: strin
177
199
  }>, foreignTableRefsById?: ReadonlyMap<string, {
178
200
  readonly tableRefName: string;
179
201
  readonly name: string;
180
- }>, picklistOptionLabelById?: ReadonlyMap<string, string>, fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>, foreignAppRefNames?: ReadonlyMap<string, string>, foreignElementRefNames?: ReadonlyMap<string, string>, procedureKeysByDiscriminator?: ReadonlyMap<string, string>, foreignTaskRefNames?: ReadonlyMap<string, string>, groupKeysByName?: ReadonlyMap<string, string>): AutomationFromTfResult;
202
+ }>, picklistOptionLabelById?: ReadonlyMap<string, string>, fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>, foreignAppRefNames?: ReadonlyMap<string, string>, foreignElementRefNames?: ReadonlyMap<string, string>, procedureKeysByDiscriminator?: ReadonlyMap<string, string>, foreignTaskRefNames?: ReadonlyMap<string, string>, groupKeysByName?: ReadonlyMap<string, string>, serviceAccountsById?: FromTfContext["serviceAccountsById"]): AutomationFromTfResult;
181
203
  export {};