@elementumai/edk 0.8.0-preview.11 → 0.8.2-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/README.md +510 -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 +83 -4
  6. package/dist-sdk/src/catalog/from-authoring.js +19 -2
  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 +134 -50
  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 +18 -0
  14. package/dist-sdk/src/catalog/types.d.ts +75 -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 +26 -1
  21. package/dist-sdk/src/engine/build/context.d.ts +58 -0
  22. package/dist-sdk/src/engine/build/context.js +11 -1
  23. package/dist-sdk/src/engine/build/source-context.d.ts +45 -0
  24. package/dist-sdk/src/engine/build/source-context.js +23 -0
  25. package/dist-sdk/src/engine/pull/context.d.ts +15 -0
  26. package/dist-sdk/src/engine/pull/org.d.ts +10 -0
  27. package/dist-sdk/src/engine/pull/org.js +34 -4
  28. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  29. package/dist-sdk/src/engine/tf/index.js +2 -2
  30. package/dist-sdk/src/engine/tf/labels.d.ts +54 -0
  31. package/dist-sdk/src/engine/tf/labels.js +75 -0
  32. package/dist-sdk/src/engine/tf/parse.d.ts +15 -0
  33. package/dist-sdk/src/engine/tf/parse.js +162 -0
  34. package/dist-sdk/src/entities/access-policy/build.d.ts +26 -0
  35. package/dist-sdk/src/entities/access-policy/build.js +7 -0
  36. package/dist-sdk/src/entities/access-policy/filter.d.ts +61 -0
  37. package/dist-sdk/src/entities/access-policy/filter.js +83 -0
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +66 -0
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +187 -0
  40. package/dist-sdk/src/entities/access-policy/module.d.ts +3 -0
  41. package/dist-sdk/src/entities/access-policy/module.js +17 -0
  42. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +43 -0
  43. package/dist-sdk/src/entities/access-policy/to-tf.js +164 -0
  44. package/dist-sdk/src/entities/access-policy/types.d.ts +4 -0
  45. package/dist-sdk/src/entities/access-policy/types.js +10 -0
  46. package/dist-sdk/src/entities/agent/build.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent/build.js +1 -0
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +38 -3
  49. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +257 -32
  50. package/dist-sdk/src/entities/agent/from-tf.d.ts +29 -9
  51. package/dist-sdk/src/entities/agent/from-tf.js +146 -19
  52. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  53. package/dist-sdk/src/entities/agent/module.js +14 -4
  54. package/dist-sdk/src/entities/agent/to-tf.d.ts +46 -1
  55. package/dist-sdk/src/entities/agent/to-tf.js +160 -14
  56. package/dist-sdk/src/entities/agent/tools.d.ts +88 -9
  57. package/dist-sdk/src/entities/agent/tools.js +46 -7
  58. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.d.ts +17 -0
  59. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.js +64 -0
  60. package/dist-sdk/src/entities/agent-a2a-skill/module.d.ts +4 -0
  61. package/dist-sdk/src/entities/agent-a2a-skill/module.js +14 -0
  62. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.d.ts +40 -0
  63. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.js +47 -0
  64. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +51 -4
  65. package/dist-sdk/src/entities/agent-tool/from-tf.js +131 -35
  66. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +11 -4
  67. package/dist-sdk/src/entities/agent-tool/to-tf.js +176 -30
  68. package/dist-sdk/src/entities/agent-tool/types.d.ts +5 -4
  69. package/dist-sdk/src/entities/agent-tool/types.js +38 -6
  70. package/dist-sdk/src/entities/app/build.d.ts +91 -13
  71. package/dist-sdk/src/entities/app/build.js +63 -5
  72. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +3 -0
  73. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -1
  74. package/dist-sdk/src/entities/app/from-tf.js +32 -22
  75. package/dist-sdk/src/entities/app/index.d.ts +4 -1
  76. package/dist-sdk/src/entities/app/index.js +2 -1
  77. package/dist-sdk/src/entities/app/module.js +10 -2
  78. package/dist-sdk/src/entities/app/to-tf.d.ts +5 -0
  79. package/dist-sdk/src/entities/app/to-tf.js +45 -4
  80. package/dist-sdk/src/entities/automation/build.d.ts +57 -13
  81. package/dist-sdk/src/entities/automation/build.js +62 -42
  82. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +25 -8
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +16 -1
  84. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +206 -47
  85. package/dist-sdk/src/entities/automation/filter.d.ts +37 -3
  86. package/dist-sdk/src/entities/automation/filter.js +54 -3
  87. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -27
  88. package/dist-sdk/src/entities/automation/from-tf.js +1344 -222
  89. package/dist-sdk/src/entities/automation/index.d.ts +4 -0
  90. package/dist-sdk/src/entities/automation/index.js +4 -0
  91. package/dist-sdk/src/entities/automation/module.js +29 -32
  92. package/dist-sdk/src/entities/automation/operators.d.ts +29 -2
  93. package/dist-sdk/src/entities/automation/operators.js +27 -1
  94. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +19 -0
  95. package/dist-sdk/src/entities/automation/output-key-wire-name.js +24 -0
  96. package/dist-sdk/src/entities/automation/script-code.d.ts +10 -21
  97. package/dist-sdk/src/entities/automation/script-code.js +272 -5
  98. package/dist-sdk/src/entities/automation/tasks.d.ts +125 -19
  99. package/dist-sdk/src/entities/automation/tasks.js +83 -15
  100. package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -29
  101. package/dist-sdk/src/entities/automation/to-tf.js +1291 -230
  102. package/dist-sdk/src/entities/automation/triggers.d.ts +9 -1
  103. package/dist-sdk/src/entities/automation/types.d.ts +29 -4
  104. package/dist-sdk/src/entities/automation/types.js +76 -46
  105. package/dist-sdk/src/entities/element/build.d.ts +44 -13
  106. package/dist-sdk/src/entities/element/build.js +45 -3
  107. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -1
  108. package/dist-sdk/src/entities/element/from-tf.js +28 -14
  109. package/dist-sdk/src/entities/element/index.d.ts +4 -1
  110. package/dist-sdk/src/entities/element/index.js +2 -1
  111. package/dist-sdk/src/entities/element/module.js +4 -1
  112. package/dist-sdk/src/entities/element/to-tf.js +26 -3
  113. package/dist-sdk/src/entities/field/build.d.ts +61 -14
  114. package/dist-sdk/src/entities/field/build.js +10 -0
  115. package/dist-sdk/src/entities/field/calc/runtime.js +4 -0
  116. package/dist-sdk/src/entities/field/from-tf.d.ts +5 -3
  117. package/dist-sdk/src/entities/field/from-tf.js +118 -7
  118. package/dist-sdk/src/entities/field/module.js +3 -2
  119. package/dist-sdk/src/entities/field/to-tf.d.ts +46 -11
  120. package/dist-sdk/src/entities/field/to-tf.js +166 -17
  121. package/dist-sdk/src/entities/field/types.d.ts +26 -0
  122. package/dist-sdk/src/entities/field/types.js +34 -12
  123. package/dist-sdk/src/entities/file-reader/build.d.ts +108 -50
  124. package/dist-sdk/src/entities/file-reader/build.js +23 -23
  125. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.d.ts +6 -0
  126. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +109 -0
  127. package/dist-sdk/src/entities/file-reader/from-tf.d.ts +13 -0
  128. package/dist-sdk/src/entities/file-reader/from-tf.js +172 -0
  129. package/dist-sdk/src/entities/file-reader/index.d.ts +8 -3
  130. package/dist-sdk/src/entities/file-reader/index.js +7 -2
  131. package/dist-sdk/src/entities/file-reader/module.d.ts +3 -0
  132. package/dist-sdk/src/entities/file-reader/module.js +115 -0
  133. package/dist-sdk/src/entities/file-reader/to-tf.d.ts +14 -0
  134. package/dist-sdk/src/entities/file-reader/to-tf.js +84 -0
  135. package/dist-sdk/src/entities/file-reader/types.d.ts +32 -0
  136. package/dist-sdk/src/entities/file-reader/types.js +30 -0
  137. package/dist-sdk/src/entities/org/ai-provider.d.ts +13 -0
  138. package/dist-sdk/src/entities/org/ai-provider.js +46 -0
  139. package/dist-sdk/src/entities/org/connector.d.ts +8 -1
  140. package/dist-sdk/src/entities/org/connector.js +12 -14
  141. package/dist-sdk/src/entities/org/group.js +10 -1
  142. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  143. package/dist-sdk/src/entities/org/index.js +1 -0
  144. package/dist-sdk/src/entities/org/user.js +10 -1
  145. package/dist-sdk/src/entities/shared/filters/ast.d.ts +59 -9
  146. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  147. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +17 -0
  148. package/dist-sdk/src/entities/shared/tool-field-ref.js +46 -0
  149. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -1
  150. package/dist-sdk/src/entities/shared/types/field-types.js +9 -0
  151. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +19 -0
  152. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +128 -11
  153. package/dist-sdk/src/entities/skill/from-tf.js +4 -3
  154. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  155. package/dist-sdk/src/entities/skill/module.js +7 -1
  156. package/dist-sdk/src/entities/skill/to-tf.d.ts +26 -0
  157. package/dist-sdk/src/entities/skill/to-tf.js +65 -4
  158. package/dist-sdk/src/entities/skill/tools.d.ts +37 -8
  159. package/dist-sdk/src/entities/skill/tools.js +43 -1
  160. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +34 -4
  161. package/dist-sdk/src/entities/skill-tool/from-tf.js +128 -18
  162. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +13 -1
  163. package/dist-sdk/src/entities/skill-tool/to-tf.js +164 -25
  164. package/dist-sdk/src/entities/skill-tool/types.d.ts +5 -7
  165. package/dist-sdk/src/entities/skill-tool/types.js +47 -11
  166. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -2
  167. package/dist-sdk/src/entities/view/from-tf.js +11 -9
  168. package/dist-sdk/src/entities/view/to-tf.d.ts +9 -7
  169. package/dist-sdk/src/entities/view/to-tf.js +39 -18
  170. package/dist-sdk/src/entities/view/types.d.ts +1 -1
  171. package/dist-sdk/src/entities/view/types.js +1 -1
  172. package/dist-sdk/src/graph/deferred-catalog-render.d.ts +0 -5
  173. package/dist-sdk/src/graph/deferred-catalog-render.js +1 -20
  174. package/dist-sdk/src/graph/index.d.ts +8 -0
  175. package/dist-sdk/src/graph/index.js +13 -9
  176. package/dist-sdk/src/graph/modules.js +8 -1
  177. package/dist-sdk/src/graph/types.d.ts +98 -4
  178. package/package.json +49 -16
  179. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +0 -76
  180. package/dist-sdk/src/entities/automation/value-ref-tf.js +0 -190
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { type Ref, type ValueOrRef } from "../../entities/shared/ref.js";
11
11
  import type { WorkflowFieldType } from "../../entities/shared/types/field-types.js";
12
+ import type { AspectRef, FieldRef } from "../../catalog/types.js";
12
13
  import type { CloudLink } from "./cloud-link.js";
13
14
  import type { DisplayBlockBag } from "./display-block.js";
14
15
  import type { SerializedRenderTree } from "../../entities/flow/activities/render-catalog.js";
@@ -171,6 +172,8 @@ export interface NumberAppField<Scope extends FieldScope = "unscoped"> extends A
171
172
  export interface DecimalAppField<Scope extends FieldScope = "unscoped"> extends AspectFieldBase<Scope> {
172
173
  readonly type: "DECIMAL";
173
174
  readonly numericFormat?: AspectNumericFieldFormat;
175
+ /** Display/storage precision (`elementum_decimal_field.decimal_places`). */
176
+ readonly decimalPlaces?: number;
174
177
  }
175
178
  /** BOOLEAN fields. */
176
179
  export interface BooleanAppField<Scope extends FieldScope = "unscoped"> extends AspectFieldBase<Scope> {
@@ -275,6 +278,28 @@ export interface AttachmentAppField<Scope extends FieldScope = "unscoped"> exten
275
278
  readonly type: "ATTACHMENT" | "ATTACHMENT_ID";
276
279
  readonly mediaTypes?: readonly string[];
277
280
  }
281
+ /**
282
+ * RELATION fields (`elementum_relation_field`) - a dynamic dropdown whose
283
+ * options are records from another App/Element/Task, distinct from a
284
+ * static PICKLIST (no fixed `options` list at all). `relatedObject`/
285
+ * `relatedLabelField` accept a catalog token (`AspectRef`/`FieldRef`) or a
286
+ * raw platform id. A token naming a SIBLING app/element authored in the
287
+ * same build resolves to a direct resource reference - Terraform sequences
288
+ * its creation automatically, so it does NOT need to already exist on the
289
+ * platform. Only a token naming something genuinely outside this workspace
290
+ * resolves to a `data` lookup, which does require the target to already be
291
+ * live. Pulling a RELATION field back always yields raw ids regardless: a
292
+ * non-recursive `ei apps export` never discovers the related object's own
293
+ * identity (confirmed live), so there's nothing to resolve a token against
294
+ * on the extract side.
295
+ */
296
+ export interface RelationAppField<Scope extends FieldScope = "unscoped"> extends AspectFieldBase<Scope> {
297
+ readonly type: "RELATION";
298
+ readonly relatedObject: AspectRef | string;
299
+ readonly relatedLabelField: FieldRef | string;
300
+ /** Defaults to `true` on the platform. */
301
+ readonly autoRelate?: boolean;
302
+ }
278
303
  /**
279
304
  * Branded result of the `calc.*` builder. The brand is opaque on the
280
305
  * author surface — agents never construct this directly; they call
@@ -315,7 +340,7 @@ export interface CalculatedAppField<Scope extends FieldScope = "unscoped"> exten
315
340
  * NumberAppField, `picklistValues` on PicklistAppField, etc.) are
316
341
  * statically gated to the right variant.
317
342
  */
318
- export type AppField<Scope extends FieldScope = "unscoped"> = TextAppField<Scope> | HandleAppField<Scope> | NumberAppField<Scope> | DecimalAppField<Scope> | BooleanAppField<Scope> | DateAppField<Scope> | DateTimeAppField<Scope> | HtmlAppField<Scope> | JsonAppField<Scope> | PicklistAppField<Scope> | MultiPicklistAppField<Scope> | UserAppField<Scope> | GroupAppField<Scope> | AttachmentAppField<Scope> | CalculatedAppField<Scope>;
343
+ export type AppField<Scope extends FieldScope = "unscoped"> = TextAppField<Scope> | HandleAppField<Scope> | NumberAppField<Scope> | DecimalAppField<Scope> | BooleanAppField<Scope> | DateAppField<Scope> | DateTimeAppField<Scope> | HtmlAppField<Scope> | JsonAppField<Scope> | PicklistAppField<Scope> | MultiPicklistAppField<Scope> | UserAppField<Scope> | GroupAppField<Scope> | AttachmentAppField<Scope> | RelationAppField<Scope> | CalculatedAppField<Scope>;
319
344
  export interface AppAgent {
320
345
  readonly id: string;
321
346
  readonly name?: string;
@@ -3,6 +3,7 @@
3
3
  * Entity-agnostic by definition — nothing in here may name a resource type.
4
4
  * (The extraction-side twin is src/engine/pull/context.ts.)
5
5
  */
6
+ import type { ChildResourceScope, TfValue } from "../tf/index.js";
6
7
  /**
7
8
  * Org-catalog lookups: recorded tfLabels for the data references entities emit.
8
9
  *
@@ -39,11 +40,68 @@ export interface OrgRefLookup {
39
40
  * `foreignApp`.
40
41
  */
41
42
  foreignSkill(tfLabel: string, name: string): void;
43
+ /**
44
+ * Record an arbitrary data lookup by its EXACT captured label and
45
+ * lookup-attr value, bypassing org.ts bag validation — used when the
46
+ * reference isn't drawn from an org.ts bag at all (a group/user field's
47
+ * round-tripped `default_value`, where ei's own data block label is
48
+ * already known from extraction and must be reproduced byte-for-byte,
49
+ * unlike `byName`'s category precedent which re-derives the label from a
50
+ * hand-authored display name).
51
+ */
52
+ rawLookup(type: string, tfLabel: string, value: string): void;
53
+ /**
54
+ * Record a name-keyed `data.elementum_element` lookup for a FOREIGN
55
+ * element (e.g. a cross-aspect agent-tool target — board issue #42).
56
+ * Same discipline as `foreignApp`, distinct resource type.
57
+ */
58
+ foreignElement(tfLabel: string, name: string): void;
59
+ /**
60
+ * Record a field-lookup data block for a field owned by a FOREIGN (or
61
+ * otherwise not-self-resource) aspect — e.g. a relation field's
62
+ * `related_label_field_id` pointing at a field on a different app/element.
63
+ * `type` is caller-supplied (like `rawLookup`) since the engine layer
64
+ * never names a resource type. Unlike the other `foreign*` methods this
65
+ * data source needs a SECOND attribute (`object_id`, the owning aspect's
66
+ * resolved id expression) — the caller supplies it already resolved,
67
+ * since it's usually the same value also used for the sibling
68
+ * `related_object_id` attribute.
69
+ */
70
+ foreignField(type: string, tfLabel: string, objectId: TfValue, name: string): void;
42
71
  }
72
+ /** A stream root discovered elsewhere in THIS workspace build — kind + tfLabel, keyed by {@link workspaceAspectKey}. */
73
+ export interface WorkspaceAspect {
74
+ readonly kind: ChildResourceScope;
75
+ readonly tfLabel: string;
76
+ }
77
+ /**
78
+ * Key for the `workspaceAspects` map: an app and an element MAY share a
79
+ * refName (the org catalog barrel disambiguates that case by renaming the
80
+ * EXPORTED key, e.g. `catalog.tickets2` — see `src/catalog/org.ts`'s
81
+ * `computeElementKeys` — but each token's own `refName` field is untouched,
82
+ * so `refName` alone is not a unique map key). Keying by kind+refName keeps
83
+ * an app "tickets" and an element "tickets" from colliding.
84
+ */
85
+ export declare function workspaceAspectKey(kind: ChildResourceScope, refName: string): string;
43
86
  export interface ToTfContext {
87
+ /** The owning app's refName — its authoring directory / catalog key. */
88
+ readonly appRefName: string;
44
89
  /** The owning app's tfLabel — its namespace (immutable; ei's namespace-first rule). */
45
90
  readonly appTfLabel: string;
46
91
  readonly orgRefs: OrgRefLookup;
47
92
  /** Degradations land here — reported by the caller, never silent. */
48
93
  readonly diagnostics: string[];
94
+ /**
95
+ * Every app/element stream root discovered in THIS build, keyed by
96
+ * {@link workspaceAspectKey} — lets a cross-aspect reference (e.g. a
97
+ * relation field's `relatedObject`) tell a SIBLING being authored/created
98
+ * in this same build apart from a genuinely foreign aspect that must
99
+ * already exist on the platform. A sibling resolves to a direct resource
100
+ * reference (Terraform sequences creation automatically); only a true
101
+ * foreign reference needs a `data` lookup, which can only ever find
102
+ * something already live. Optional so callers that don't need this (most
103
+ * `ToTfContext` construction sites, including tests) aren't forced to
104
+ * supply it.
105
+ */
106
+ readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
49
107
  }
@@ -3,4 +3,14 @@
3
3
  * Entity-agnostic by definition — nothing in here may name a resource type.
4
4
  * (The extraction-side twin is src/engine/pull/context.ts.)
5
5
  */
6
- export {};
6
+ /**
7
+ * Key for the `workspaceAspects` map: an app and an element MAY share a
8
+ * refName (the org catalog barrel disambiguates that case by renaming the
9
+ * EXPORTED key, e.g. `catalog.tickets2` — see `src/catalog/org.ts`'s
10
+ * `computeElementKeys` — but each token's own `refName` field is untouched,
11
+ * so `refName` alone is not a unique map key). Keying by kind+refName keeps
12
+ * an app "tickets" and an element "tickets" from colliding.
13
+ */
14
+ export function workspaceAspectKey(kind, refName) {
15
+ return `${kind}:${refName}`;
16
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Generic "what file is jiti currently importing, and what's its own
3
+ * untranspiled text" context for `elementum build`'s own-file-child loader.
4
+ *
5
+ * Entity-agnostic on purpose: `engine/` may not import from `entities/`
6
+ * (`__tests__/engine/no-entity-types-in-engine.test.ts`), so this exists
7
+ * purely as plumbing — it knows nothing about automations or any other
8
+ * entity kind. An entity module (e.g. `entities/automation/script-code.ts`)
9
+ * that needs byte-exact access to its own source text — because jiti/Babel's
10
+ * transpile-then-`toString()` round trip would otherwise reformat it —
11
+ * imports {@link currentSourceText} from here (entities/ importing engine/ is
12
+ * the normal direction; only the reverse is forbidden).
13
+ *
14
+ * State lives on `globalThis` (via a `Symbol.for` registry key), not a plain
15
+ * module-scoped variable, for two independent reasons:
16
+ * - `AsyncLocalStorage` was tried first and rejected: jiti's own `.import()`
17
+ * wraps transform + a dynamic `import()` through its own internal
18
+ * scheduling, which does not reliably propagate ALS continuation context
19
+ * through to where the imported module's top-level code actually runs
20
+ * (confirmed empirically — that version silently lost context there).
21
+ * - A plain module-scoped variable has a SEPARATE failure mode: when jiti
22
+ * transforms a `.ts` file that itself imports this module (as opposed to
23
+ * already-compiled `.js`, which jiti can hand off to Node's native
24
+ * loader), jiti may instantiate its OWN, isolated copy of this module —
25
+ * a different module-registry entry than the one `elementum build`'s own
26
+ * (natively-loaded) code holds, so writes through one are invisible to
27
+ * reads through the other. `globalThis` is the one thing guaranteed
28
+ * shared across however many separate module instances end up loaded in
29
+ * the same process.
30
+ *
31
+ * `elementum build`'s own-file-child loader still imports one file at a time
32
+ * in a sequential loop (never concurrently) — see `discoverOwnFileChildren`
33
+ * in `build.ts`. Do not parallelize that loop without revisiting this.
34
+ */
35
+ export interface SourceTextContext {
36
+ readonly filePath: string;
37
+ readonly text: string;
38
+ }
39
+ /**
40
+ * Run `fn` (a jiti module import) with `filePath`'s own text available via
41
+ * {@link currentSourceText} for the duration of the returned promise.
42
+ */
43
+ export declare function withSourceText<T>(filePath: string, text: string, fn: () => Promise<T>): Promise<T>;
44
+ /** The file/text currently being imported via {@link withSourceText}, or undefined outside that context. */
45
+ export declare function currentSourceText(): SourceTextContext | undefined;
@@ -0,0 +1,23 @@
1
+ const GLOBAL_KEY = Symbol.for("elementumEdk.engine.build.currentSourceText");
2
+ function slot() {
3
+ return globalThis;
4
+ }
5
+ /**
6
+ * Run `fn` (a jiti module import) with `filePath`'s own text available via
7
+ * {@link currentSourceText} for the duration of the returned promise.
8
+ */
9
+ export async function withSourceText(filePath, text, fn) {
10
+ const g = slot();
11
+ const previous = g[GLOBAL_KEY];
12
+ g[GLOBAL_KEY] = { filePath, text };
13
+ try {
14
+ return await fn();
15
+ }
16
+ finally {
17
+ g[GLOBAL_KEY] = previous;
18
+ }
19
+ }
20
+ /** The file/text currently being imported via {@link withSourceText}, or undefined outside that context. */
21
+ export function currentSourceText() {
22
+ return slot()[GLOBAL_KEY];
23
+ }
@@ -5,14 +5,29 @@
5
5
  * resource type. (The emission-side twin is src/engine/build/context.ts.)
6
6
  */
7
7
  import { type TfValue } from "../tf/index.js";
8
+ /** A `data-attr` reference recorded on a data block in the same stream. */
9
+ export interface DataRef {
10
+ readonly resourceType: string;
11
+ readonly tfLabel: string;
12
+ }
8
13
  /** Extraction context: stream lookups + the diagnostics sink. */
9
14
  export interface FromTfContext {
10
15
  /** Lookup-attr value of a data block in the same stream: ("elementum_category", "experiments") → "Experiments". */
11
16
  dataName(type: string, label: string): string | undefined;
17
+ /** DataFacet.providerRefAttr's resolved reference on a data block in the same stream (connector's `provider_id` → its owning `elementum_<type>_ai_provider` block). */
18
+ dataRef(type: string, label: string): DataRef | undefined;
12
19
  /** Platform id recorded by the stream's import blocks, by resource address. */
13
20
  importId(address: string): string | undefined;
14
21
  /** Degradations land here — reported by the caller, never silent. */
15
22
  readonly diagnostics: string[];
23
+ /**
24
+ * Resource addresses that must NOT be adopted - nothing in authored
25
+ * source can reproduce them (e.g. a known-but-unimplemented field
26
+ * sub-type). Excluded from adoption's targeted plan even though ei's own
27
+ * export otherwise carries a valid import block for them - see
28
+ * `field/from-tf.ts`'s `implemented` check for the motivating case.
29
+ */
30
+ readonly skipped: string[];
16
31
  }
17
32
  /** `data.<type>.<label>.id` → the label; undefined for any other shape. */
18
33
  export declare function dataRefLabel(v: TfValue | undefined, type: string): string | undefined;
@@ -18,6 +18,11 @@
18
18
  * contract; changing it is an upgrade/migration event.
19
19
  */
20
20
  import type { TfDocument } from "../tf/index.js";
21
+ /** A `data-attr` reference to another org identity's own data block. */
22
+ export interface OrgIdentityRef {
23
+ readonly resourceType: string;
24
+ readonly tfLabel: string;
25
+ }
21
26
  /** One org-owned reference identity from the export stream. */
22
27
  export interface OrgIdentity {
23
28
  /** Authoring token key: tsLabel = the bijective camelCase image of tfLabel. */
@@ -29,11 +34,16 @@ export interface OrgIdentity {
29
34
  readonly name: string;
30
35
  /** The exported terraform label (in-memory provenance; equals tsLabelToTfLabel(tsLabel), never persisted). */
31
36
  readonly tfLabel: string;
37
+ /** The data block's own terraform type — a bag can span multiple types (aiProviders: 10 distinct `elementum_<type>_ai_provider` types). */
38
+ readonly resourceType: string;
39
+ /** DataFacet.providerRefAttr's resolved reference (connector's `provider_id` → its owning `elementum_<type>_ai_provider` block), when the kind has one. */
40
+ readonly providerRef?: OrgIdentityRef;
32
41
  }
33
42
  export interface OrgExtract {
34
43
  readonly cloudLinks: readonly OrgIdentity[];
35
44
  readonly categories: readonly OrgIdentity[];
36
45
  readonly connectors: readonly OrgIdentity[];
46
+ readonly aiProviders: readonly OrgIdentity[];
37
47
  readonly groups: readonly OrgIdentity[];
38
48
  /** The org app directory (namespace → platform id) from locals.org_apps. */
39
49
  readonly apps: Readonly<Record<string, string>>;
@@ -18,7 +18,7 @@
18
18
  * contract; changing it is an upgrade/migration event.
19
19
  */
20
20
  import { DATA_FACET_BY_TYPE } from "../../graph/index.js";
21
- import { tfLabelToTsLabel } from "../tf/index.js";
21
+ import { isTfExpr, tfLabelToTsLabel } from "../tf/index.js";
22
22
  export class OrgExtractError extends Error {
23
23
  constructor(message) {
24
24
  super(message);
@@ -30,21 +30,36 @@ export function extractOrg(doc) {
30
30
  cloudLinks: [],
31
31
  categories: [],
32
32
  connectors: [],
33
+ aiProviders: [],
33
34
  groups: [],
34
35
  };
35
36
  let apps;
36
37
  for (const block of doc.blocks) {
37
38
  if (block.kind === "data") {
38
- const kind = DATA_FACET_BY_TYPE.get(block.type ?? "");
39
+ const type = block.type ?? "";
40
+ const kind = DATA_FACET_BY_TYPE.get(type);
39
41
  const orgBag = kind?.data.participates === true ? kind.data.orgBag : undefined;
40
42
  // A data facet without orgBag (e.g. elementum_user, foreign app) is
41
43
  // app-stream-only — presence here is contract drift like an unknown type.
42
44
  if (orgBag === undefined || kind?.data.participates !== true) {
43
45
  throw new OrgExtractError(`unexpected data source "${block.type}" in org export stream — the M0 contract grew; extend the extractor deliberately`);
44
46
  }
47
+ const tfLabel = requireLabel(block);
45
48
  raw[orgBag].push({
46
49
  name: requireStringAttr(block, kind.data.lookupAttr),
47
- tfLabel: requireLabel(block),
50
+ tfLabel,
51
+ resourceType: type,
52
+ // `provider_id` is a REAL ref only when the connector's provider was
53
+ // also exported (`writeConnectorDataBlocks`, cmd/elementum/export/
54
+ // org_export.go) — otherwise the bridge falls back to a
55
+ // `provider_name` string, or emits neither at all for an orphaned
56
+ // connector (no provider on the platform side). So the attribute's
57
+ // mere absence is a legitimate dialect branch, not contract drift —
58
+ // only demand `requireDataRef`'s shape when the attribute is
59
+ // actually present; malformed-but-present still fails loud.
60
+ providerRef: kind.data.providerRefAttr !== undefined && block.attrs[kind.data.providerRefAttr] !== undefined
61
+ ? requireDataRef(block, kind.data.providerRefAttr, tfLabel)
62
+ : undefined,
48
63
  });
49
64
  continue;
50
65
  }
@@ -65,6 +80,7 @@ export function extractOrg(doc) {
65
80
  cloudLinks: withTsLabels(raw.cloudLinks),
66
81
  categories: withTsLabels(raw.categories),
67
82
  connectors: withTsLabels(raw.connectors),
83
+ aiProviders: withTsLabels(raw.aiProviders),
68
84
  groups: withTsLabels(raw.groups),
69
85
  apps,
70
86
  };
@@ -73,9 +89,23 @@ export function extractOrg(doc) {
73
89
  * lossless, and unique because ei's tfLabels are unique per type. */
74
90
  function withTsLabels(entities) {
75
91
  return entities
76
- .map((e) => ({ tsLabel: tfLabelToTsLabel(e.tfLabel), name: e.name, tfLabel: e.tfLabel }))
92
+ .map((e) => ({
93
+ tsLabel: tfLabelToTsLabel(e.tfLabel),
94
+ name: e.name,
95
+ tfLabel: e.tfLabel,
96
+ resourceType: e.resourceType,
97
+ providerRef: e.providerRef,
98
+ }))
77
99
  .sort((a, b) => a.tsLabel.localeCompare(b.tsLabel));
78
100
  }
101
+ /** A `providerRefAttr` value must be a `data-attr` reference's `.id` — loud otherwise (contract drift, not silent). */
102
+ function requireDataRef(block, attr, tfLabel) {
103
+ const v = block.attrs[attr];
104
+ if (isTfExpr(v) && v.$expr === "data-attr" && v.path.length === 1 && v.path[0] === "id") {
105
+ return { resourceType: v.type, tfLabel: v.label };
106
+ }
107
+ throw new OrgExtractError(`data "${block.type}" "${tfLabel}": expected "${attr}" to be a data source reference, got ${JSON.stringify(v)}`);
108
+ }
79
109
  function requireLabel(block) {
80
110
  if (!block.label) {
81
111
  throw new OrgExtractError(`data "${block.type}" block is missing its label`);
@@ -7,6 +7,6 @@ export type { PathSeg, TfBlock, TfBlockKind, TfDocument, TfExpr, TfValue } from
7
7
  export { expr, isTfExpr } from "./model.js";
8
8
  export { decodeTemplateEscapes, encodeTemplateEscapes, quoteHclString } from "./escape.js";
9
9
  export { parseExpression, parseStringValue, TfExprError } from "./expr.js";
10
- export { assertNoUnsafeIntegers, parseHcl, TfParseError } from "./parse.js";
10
+ export { assertNoUnsafeIntegers, inspectBackendHcl, parseHcl, TfParseError, type BackendHclInspection, } from "./parse.js";
11
11
  export { renderBlock, renderDocument } from "./render.js";
12
- export { isCanonicalTsLabel, sanitizeName, snakeSlug, splitCamelCase, tfLabelToTsLabel, tsLabelToTfLabel } from "./labels.js";
12
+ export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, elementResourceLabelPrefix, elementScopedResourceLabel, isCanonicalTsLabel, isUuid, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, tfLabelToTsLabel, tsLabelToTfLabel, type ChildResourceScope, } from "./labels.js";
@@ -6,6 +6,6 @@
6
6
  export { expr, isTfExpr } from "./model.js";
7
7
  export { decodeTemplateEscapes, encodeTemplateEscapes, quoteHclString } from "./escape.js";
8
8
  export { parseExpression, parseStringValue, TfExprError } from "./expr.js";
9
- export { assertNoUnsafeIntegers, parseHcl, TfParseError } from "./parse.js";
9
+ export { assertNoUnsafeIntegers, inspectBackendHcl, parseHcl, TfParseError, } from "./parse.js";
10
10
  export { renderBlock, renderDocument } from "./render.js";
11
- export { isCanonicalTsLabel, sanitizeName, snakeSlug, splitCamelCase, tfLabelToTsLabel, tsLabelToTfLabel } from "./labels.js";
11
+ export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, elementResourceLabelPrefix, elementScopedResourceLabel, isCanonicalTsLabel, isUuid, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, tfLabelToTsLabel, tsLabelToTfLabel, } from "./labels.js";
@@ -29,3 +29,57 @@ export declare function isCanonicalTsLabel(tsLabel: string): boolean;
29
29
  export declare function snakeSlug(s: string): string;
30
30
  /** Faithful port of ei's SanitizeName: platform name → HCL identifier. */
31
31
  export declare function sanitizeName(name: string): string;
32
+ /** True when `value` has the shape of a platform id (not a validity check — just the wire shape). */
33
+ export declare function isUuid(value: string): boolean;
34
+ /** Scope for child resource labels under a stream root. */
35
+ export type ChildResourceScope = "app" | "element";
36
+ /**
37
+ * Prefix for app-owned child resource labels in a shared `.tf/out/` workspace.
38
+ * Uses the platform namespace (`appTfLabel`), matching ei's `AppResourceName`.
39
+ */
40
+ export declare function appResourceLabelPrefix(appTfLabel: string): string;
41
+ /** Prefix for element-owned children in a shared `.tf/out/` workspace. */
42
+ export declare function elementResourceLabelPrefix(elementTfLabel: string): string;
43
+ /**
44
+ * App-owned child resource label: `apps_<namespace>_<namespace>_<childPart>`, ALWAYS.
45
+ * The owner prefix is prepended unconditionally — never collapsed just because `childPart`
46
+ * already happens to start with `<ns>_` (issue #115: a field named e.g. `sourcingStatus` under
47
+ * app `sourcing` is a real, distinct field from one named `status`, not a re-encoding of it) —
48
+ * to keep the encoding injective. `childPartFromScopedLabel` is its exact inverse (strips
49
+ * `apps_<ns>_` then one more `<ns>_`, unconditionally).
50
+ */
51
+ export declare function appScopedResourceLabel(appTfLabel: string, childPart: string): string;
52
+ /**
53
+ * Element-owned child resource label: `elements_<namespace>_<namespace>_<childPart>`, ALWAYS —
54
+ * same unconditional doubling as {@link appScopedResourceLabel}, for the same reason (issue
55
+ * #115): a field named e.g. `ticketsPriority` under element `tickets` is a real, distinct field
56
+ * from one named `priority`, not a re-encoding of it. A prior version of this function skipped
57
+ * the double when `childPart` already started with `<ns>_`, which collapsed both onto the same
58
+ * label — reported live against a real `tickets` element field pulling ambiguously.
59
+ *
60
+ * One-time upgrade characteristic, not an ongoing bug: this changes the computed address ONLY
61
+ * for a STALE bag key an older (pre-fix) pull already wrote to disk and that was never
62
+ * re-pulled — the old extractor never stripped the namespace, so it left prefixed bag keys
63
+ * (e.g. `ticketsActive`) that now over-double when rebuilt. A field FRESHLY re-extracted with
64
+ * `childPartFromScopedLabel`'s current (also-fixed) stripping round-trips to the exact same
65
+ * address ei already uses — see `__tests__/tf/labels.test.ts`'s "element-prefixed child labels
66
+ * round-trip" block. Re-pull an existing element (`elementum pull element <ns>`) before your
67
+ * next build/plan if it predates this fix; adoption's rename guard (board item 225,
68
+ * `docs/design/rename-label-identity.md`) safely `state mv`s any address that does shift.
69
+ */
70
+ export declare function elementScopedResourceLabel(elementTfLabel: string, childPart: string): string;
71
+ /** Emit a scoped child label for the owning stream root kind. */
72
+ export declare function scopedResourceLabel(ownerTfLabel: string, childPart: string, scope: ChildResourceScope): string;
73
+ /** Strip a scoped child label back to its bare form (no-op when unprefixed). */
74
+ export declare function bareChildResourceLabel(ownerTfLabel: string, scopedLabel: string, scope?: ChildResourceScope): string;
75
+ /**
76
+ * Child part after the owner namespace — bag keys omit the namespace prefix
77
+ * for both apps and elements. Strips `apps_<ns>_`/`elements_<ns>_` then
78
+ * exactly one `<ns>_` — the exact inverse of `appScopedResourceLabel`'s /
79
+ * `elementScopedResourceLabel`'s always-double encoding (issue #115). The
80
+ * `startsWith` check is therefore always true for a well-formed label; it is
81
+ * kept only to no-op on unprefixed input.
82
+ */
83
+ export declare function childPartFromScopedLabel(ownerTfLabel: string, scopedLabel: string, scope: ChildResourceScope): string;
84
+ /** Scoped terraform label → authoring bag key / ref key. */
85
+ export declare function scopedLabelToBagKey(ownerTfLabel: string, scopedLabel: string, scope?: ChildResourceScope): string;
@@ -123,3 +123,78 @@ export function sanitizeName(name) {
123
123
  }
124
124
  return s === "" ? "resource" : s;
125
125
  }
126
+ /** Matches a raw platform id (v4-shaped, case-insensitive) — used to recognize an orphaned reference that round-trips as a bare id rather than a resolved name/label. */
127
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
128
+ /** True when `value` has the shape of a platform id (not a validity check — just the wire shape). */
129
+ export function isUuid(value) {
130
+ return UUID_RE.test(value);
131
+ }
132
+ /**
133
+ * Prefix for app-owned child resource labels in a shared `.tf/out/` workspace.
134
+ * Uses the platform namespace (`appTfLabel`), matching ei's `AppResourceName`.
135
+ */
136
+ export function appResourceLabelPrefix(appTfLabel) {
137
+ return `apps_${appTfLabel}_`;
138
+ }
139
+ /** Prefix for element-owned children in a shared `.tf/out/` workspace. */
140
+ export function elementResourceLabelPrefix(elementTfLabel) {
141
+ return `elements_${elementTfLabel}_`;
142
+ }
143
+ /**
144
+ * App-owned child resource label: `apps_<namespace>_<namespace>_<childPart>`, ALWAYS.
145
+ * The owner prefix is prepended unconditionally — never collapsed just because `childPart`
146
+ * already happens to start with `<ns>_` (issue #115: a field named e.g. `sourcingStatus` under
147
+ * app `sourcing` is a real, distinct field from one named `status`, not a re-encoding of it) —
148
+ * to keep the encoding injective. `childPartFromScopedLabel` is its exact inverse (strips
149
+ * `apps_<ns>_` then one more `<ns>_`, unconditionally).
150
+ */
151
+ export function appScopedResourceLabel(appTfLabel, childPart) {
152
+ return `${appResourceLabelPrefix(appTfLabel)}${appTfLabel}_${childPart}`;
153
+ }
154
+ /**
155
+ * Element-owned child resource label: `elements_<namespace>_<namespace>_<childPart>`, ALWAYS —
156
+ * same unconditional doubling as {@link appScopedResourceLabel}, for the same reason (issue
157
+ * #115): a field named e.g. `ticketsPriority` under element `tickets` is a real, distinct field
158
+ * from one named `priority`, not a re-encoding of it. A prior version of this function skipped
159
+ * the double when `childPart` already started with `<ns>_`, which collapsed both onto the same
160
+ * label — reported live against a real `tickets` element field pulling ambiguously.
161
+ *
162
+ * One-time upgrade characteristic, not an ongoing bug: this changes the computed address ONLY
163
+ * for a STALE bag key an older (pre-fix) pull already wrote to disk and that was never
164
+ * re-pulled — the old extractor never stripped the namespace, so it left prefixed bag keys
165
+ * (e.g. `ticketsActive`) that now over-double when rebuilt. A field FRESHLY re-extracted with
166
+ * `childPartFromScopedLabel`'s current (also-fixed) stripping round-trips to the exact same
167
+ * address ei already uses — see `__tests__/tf/labels.test.ts`'s "element-prefixed child labels
168
+ * round-trip" block. Re-pull an existing element (`elementum pull element <ns>`) before your
169
+ * next build/plan if it predates this fix; adoption's rename guard (board item 225,
170
+ * `docs/design/rename-label-identity.md`) safely `state mv`s any address that does shift.
171
+ */
172
+ export function elementScopedResourceLabel(elementTfLabel, childPart) {
173
+ return `${elementResourceLabelPrefix(elementTfLabel)}${elementTfLabel}_${childPart}`;
174
+ }
175
+ /** Emit a scoped child label for the owning stream root kind. */
176
+ export function scopedResourceLabel(ownerTfLabel, childPart, scope) {
177
+ return scope === "app" ? appScopedResourceLabel(ownerTfLabel, childPart) : elementScopedResourceLabel(ownerTfLabel, childPart);
178
+ }
179
+ /** Strip a scoped child label back to its bare form (no-op when unprefixed). */
180
+ export function bareChildResourceLabel(ownerTfLabel, scopedLabel, scope = "app") {
181
+ const prefix = scope === "app" ? appResourceLabelPrefix(ownerTfLabel) : elementResourceLabelPrefix(ownerTfLabel);
182
+ return scopedLabel.startsWith(prefix) ? scopedLabel.slice(prefix.length) : scopedLabel;
183
+ }
184
+ /**
185
+ * Child part after the owner namespace — bag keys omit the namespace prefix
186
+ * for both apps and elements. Strips `apps_<ns>_`/`elements_<ns>_` then
187
+ * exactly one `<ns>_` — the exact inverse of `appScopedResourceLabel`'s /
188
+ * `elementScopedResourceLabel`'s always-double encoding (issue #115). The
189
+ * `startsWith` check is therefore always true for a well-formed label; it is
190
+ * kept only to no-op on unprefixed input.
191
+ */
192
+ export function childPartFromScopedLabel(ownerTfLabel, scopedLabel, scope) {
193
+ const bare = bareChildResourceLabel(ownerTfLabel, scopedLabel, scope);
194
+ const nsPrefix = `${ownerTfLabel}_`;
195
+ return bare.startsWith(nsPrefix) ? bare.slice(nsPrefix.length) : bare;
196
+ }
197
+ /** Scoped terraform label → authoring bag key / ref key. */
198
+ export function scopedLabelToBagKey(ownerTfLabel, scopedLabel, scope = "app") {
199
+ return tfLabelToTsLabel(childPartFromScopedLabel(ownerTfLabel, scopedLabel, scope));
200
+ }
@@ -24,6 +24,21 @@ export declare function installHcl2JsonRuntime(parser: Hcl2JsonParser): void;
24
24
  export declare class TfParseError extends Error {
25
25
  constructor(message: string);
26
26
  }
27
+ export interface BackendHclInspection {
28
+ readonly type: string;
29
+ }
30
+ /**
31
+ * Validate the dedicated workspace backend source. Credential-bearing keys
32
+ * and the small set of backend-specific locking switches are policy-critical;
33
+ * every other backend argument stays opaque and is preserved verbatim.
34
+ *
35
+ * This deliberately reuses the ONE hcl2json entry point while bypassing the
36
+ * entity expression grammar: OpenTofu backend configuration may contain
37
+ * init-time `var.*`, `local.*`, and nested backend blocks that are not part of
38
+ * ei's entity dialect. The source is projected byte-for-byte after validation;
39
+ * OpenTofu remains the authority for backend-specific arguments.
40
+ */
41
+ export declare function inspectBackendHcl(text: string): Promise<BackendHclInspection>;
27
42
  export declare function parseHcl(text: string): Promise<TfDocument>;
28
43
  /**
29
44
  * Refuse to parse text whose integer literals exceed Number.MAX_SAFE_INTEGER —