@elementumai/edk 0.9.18 → 0.9.20

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 (219) hide show
  1. package/README.md +154 -9
  2. package/dist-sdk/src/catalog/factories.d.ts +35 -1
  3. package/dist-sdk/src/catalog/factories.js +36 -0
  4. package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
  5. package/dist-sdk/src/catalog/from-authoring.js +34 -9
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +2 -2
  8. package/dist-sdk/src/catalog/org.d.ts +39 -1
  9. package/dist-sdk/src/catalog/org.js +460 -50
  10. package/dist-sdk/src/catalog/render.js +6 -6
  11. package/dist-sdk/src/catalog/token.js +7 -0
  12. package/dist-sdk/src/catalog/types.d.ts +44 -1
  13. package/dist-sdk/src/catalog/types.js +13 -0
  14. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  15. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  16. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  17. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  18. package/dist-sdk/src/engine/ei/run.js +1132 -0
  19. package/dist-sdk/src/engine/logging.d.ts +17 -0
  20. package/dist-sdk/src/engine/logging.js +18 -0
  21. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  22. package/dist-sdk/src/engine/pull/ref-only.js +64 -27
  23. package/dist-sdk/src/engine/pull/result-output.d.ts +8 -0
  24. package/dist-sdk/src/engine/pull/result-output.js +88 -4
  25. package/dist-sdk/src/engine/tf/expr.js +39 -14
  26. package/dist-sdk/src/engine/tf/index.d.ts +3 -3
  27. package/dist-sdk/src/engine/tf/index.js +2 -2
  28. package/dist-sdk/src/engine/tf/labels.d.ts +8 -0
  29. package/dist-sdk/src/engine/tf/labels.js +13 -0
  30. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  31. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  32. package/dist-sdk/src/engine/tf/parse.js +197 -10
  33. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  34. package/dist-sdk/src/engine/tf/render.js +41 -7
  35. package/dist-sdk/src/engine/validation.d.ts +39 -0
  36. package/dist-sdk/src/engine/validation.js +85 -0
  37. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  40. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  41. package/dist-sdk/src/entities/access-policy/to-tf.js +16 -6
  42. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  43. package/dist-sdk/src/entities/agent/build.js +40 -5
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  45. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +29 -6
  50. package/dist-sdk/src/entities/app/build.d.ts +98 -19
  51. package/dist-sdk/src/entities/app/build.js +51 -19
  52. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
  53. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  54. package/dist-sdk/src/entities/app/from-tf.js +11 -5
  55. package/dist-sdk/src/entities/app/index.d.ts +6 -5
  56. package/dist-sdk/src/entities/app/index.js +2 -0
  57. package/dist-sdk/src/entities/app/module.js +18 -2
  58. package/dist-sdk/src/entities/app/to-tf.js +21 -11
  59. package/dist-sdk/src/entities/automation/build.d.ts +49 -6
  60. package/dist-sdk/src/entities/automation/build.js +163 -19
  61. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  62. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +320 -39
  63. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  64. package/dist-sdk/src/entities/automation/from-tf.js +563 -74
  65. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  66. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  67. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  68. package/dist-sdk/src/entities/automation/index.js +1 -1
  69. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  70. package/dist-sdk/src/entities/automation/module.js +93 -8
  71. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  72. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  73. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  74. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  75. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  76. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  77. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  78. package/dist-sdk/src/entities/automation/system-ref-name.js +48 -0
  79. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -0
  80. package/dist-sdk/src/entities/automation/task-output-labels.js +47 -0
  81. package/dist-sdk/src/entities/automation/tasks.d.ts +53 -4
  82. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  83. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  84. package/dist-sdk/src/entities/automation/to-tf.js +647 -167
  85. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  86. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  87. package/dist-sdk/src/entities/automation/types.js +1 -0
  88. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  89. package/dist-sdk/src/entities/chart/module.js +3 -1
  90. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  91. package/dist-sdk/src/entities/chart/printer.js +26 -16
  92. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  93. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  94. package/dist-sdk/src/entities/chart/to-tf.js +21 -12
  95. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  96. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  97. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  98. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  99. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  100. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +72 -30
  101. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  102. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  103. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  104. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  105. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  106. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  107. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  108. package/dist-sdk/src/entities/element/build.d.ts +33 -13
  109. package/dist-sdk/src/entities/element/build.js +5 -1
  110. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -0
  111. package/dist-sdk/src/entities/element/from-tf.js +64 -3
  112. package/dist-sdk/src/entities/element/index.d.ts +5 -2
  113. package/dist-sdk/src/entities/element/index.js +2 -0
  114. package/dist-sdk/src/entities/element/module.js +11 -3
  115. package/dist-sdk/src/entities/element/to-tf.js +20 -2
  116. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  117. package/dist-sdk/src/entities/field/build.js +3 -0
  118. package/dist-sdk/src/entities/field/from-tf.d.ts +3 -0
  119. package/dist-sdk/src/entities/field/from-tf.js +50 -1
  120. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  121. package/dist-sdk/src/entities/field/media-types.js +30 -0
  122. package/dist-sdk/src/entities/field/module.js +1 -0
  123. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  124. package/dist-sdk/src/entities/field/to-tf.js +142 -22
  125. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  126. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  127. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  128. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  129. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  130. package/dist-sdk/src/entities/portal/build.js +37 -0
  131. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  132. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  133. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  134. package/dist-sdk/src/entities/portal/index.js +1 -0
  135. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  136. package/dist-sdk/src/entities/portal/module.js +28 -0
  137. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  138. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  139. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  140. package/dist-sdk/src/entities/portal/types.js +1 -0
  141. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  142. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  143. package/dist-sdk/src/entities/relationship/module.js +2 -0
  144. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  145. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  146. package/dist-sdk/src/entities/relationship/to-tf.d.ts +10 -0
  147. package/dist-sdk/src/entities/relationship/to-tf.js +31 -13
  148. package/dist-sdk/src/entities/search-table/module.js +1 -0
  149. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  150. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  151. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  152. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  153. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  154. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  155. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  156. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  157. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  158. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  159. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  160. package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -2
  161. package/dist-sdk/src/entities/shared/filters/index.d.ts +25 -2
  162. package/dist-sdk/src/entities/shared/filters/index.js +38 -5
  163. package/dist-sdk/src/entities/shared/filters/print.js +31 -3
  164. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +25 -3
  165. package/dist-sdk/src/entities/shared/filters/tf-codec.js +51 -15
  166. package/dist-sdk/src/entities/shared/filters/types.d.ts +22 -5
  167. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  168. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  169. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  170. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  171. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  172. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  173. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  174. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  175. package/dist-sdk/src/entities/skill/build.js +3 -0
  176. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  177. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +23 -1
  178. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  179. package/dist-sdk/src/entities/skill/from-tf.js +70 -22
  180. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  181. package/dist-sdk/src/entities/skill/index.js +1 -0
  182. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  183. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  184. package/dist-sdk/src/entities/skill/module.js +1 -0
  185. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  186. package/dist-sdk/src/entities/skill/to-tf.js +19 -6
  187. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  188. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  189. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  190. package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -6
  191. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  192. package/dist-sdk/src/entities/table/catalog.js +66 -0
  193. package/dist-sdk/src/entities/table/module.js +2 -1
  194. package/dist-sdk/src/entities/table/to-tf.js +5 -5
  195. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +89 -0
  196. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +277 -0
  197. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +51 -0
  198. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +360 -0
  199. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +151 -0
  200. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  201. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -3
  202. package/dist-sdk/src/entities/view/from-tf.js +161 -14
  203. package/dist-sdk/src/entities/view/module.js +30 -3
  204. package/dist-sdk/src/entities/view/to-tf.d.ts +24 -2
  205. package/dist-sdk/src/entities/view/to-tf.js +95 -9
  206. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  207. package/dist-sdk/src/entities/view/types.js +17 -15
  208. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  209. package/dist-sdk/src/entities/widget/build.js +11 -1
  210. package/dist-sdk/src/entities/widget/to-tf.js +36 -10
  211. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +38 -10
  212. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  213. package/dist-sdk/src/graph/index.d.ts +54 -0
  214. package/dist-sdk/src/graph/index.js +30 -0
  215. package/dist-sdk/src/graph/modules.js +2 -0
  216. package/dist-sdk/src/graph/types.d.ts +133 -2
  217. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  218. package/dist-sdk/src/internal/sdk-package.js +1 -0
  219. package/package.json +11 -1
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Pull: blocks layouts → normalized values the printer turns back into source.
3
+ * `elementum_agent_view.layout` → `agentViews.<key>.layout`;
4
+ * `elementum_custom_view.layout` → `customViews.<key>.layout` (see
5
+ * `viewBlocksFromTf`). References become typed markers at the per-block id
6
+ * positions, inside nested filters and inside actions; raw platform ids there
7
+ * become `unsafePlatformId(...)`. A layout this cannot represent makes the
8
+ * whole view unmanaged (skipped), never silently dropped: the code owns the
9
+ * layout, so a dropped detail would be cleared on the next apply.
10
+ */
11
+ import { isTfExpr } from "../../engine/tf/index.js";
12
+ import { AGENT_VIEW_SPEC_FILTER_PROPS, AGENT_VIEW_SPEC_ID_PROPS } from "./agent-view-layout.js";
13
+ const PLATFORM_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
14
+ const ATTACHMENT_URL = /^\/api\/v1\/attachments\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;
15
+ const FILTER_PROPS = new Set(AGENT_VIEW_SPEC_FILTER_PROPS);
16
+ const ID_PROPS = AGENT_VIEW_SPEC_ID_PROPS;
17
+ const LAYOUT_STRING_ATTRS = {
18
+ header: "header",
19
+ sub_header: "subHeader",
20
+ background_color: "backgroundColor",
21
+ primary_color: "primaryColor",
22
+ font_family: "fontFamily",
23
+ };
24
+ const KNOWN_LAYOUT_ATTRS = new Set(["image_url", "custom_view", ...Object.keys(LAYOUT_STRING_ATTRS)]);
25
+ class Unrepresentable extends Error {
26
+ }
27
+ export function agentViewLayoutFromTf(value, opts) {
28
+ try {
29
+ return { ok: true, layout: decodeLayout(value, opts) };
30
+ }
31
+ catch (error) {
32
+ if (error instanceof Unrepresentable)
33
+ return { ok: false, reason: error.message };
34
+ throw error;
35
+ }
36
+ }
37
+ function decodeLayout(value, opts) {
38
+ const attrs = plain(value);
39
+ if (attrs === undefined)
40
+ throw new Unrepresentable("layout is not an object");
41
+ const unknown = Object.keys(attrs).filter((key) => !KNOWN_LAYOUT_ATTRS.has(key));
42
+ if (unknown.length > 0)
43
+ throw new Unrepresentable(`layout has unhandled attributes: ${unknown.sort().join(", ")}`);
44
+ const layout = {};
45
+ const imageUrl = attrs["image_url"];
46
+ if (imageUrl !== undefined) {
47
+ if (typeof imageUrl !== "string")
48
+ throw new Unrepresentable("layout.image_url is not a string");
49
+ const attachment = ATTACHMENT_URL.exec(imageUrl)?.[1];
50
+ layout.image = attachment !== undefined ? { attachment } : { url: imageUrl };
51
+ }
52
+ for (const [attr, key] of Object.entries(LAYOUT_STRING_ATTRS)) {
53
+ const v = attrs[attr];
54
+ if (v === undefined)
55
+ continue;
56
+ if (typeof v !== "string")
57
+ throw new Unrepresentable(`layout.${attr} is not a string`);
58
+ const normalized = key === "backgroundColor" || key === "primaryColor"
59
+ ? normalizeColor(v)
60
+ : key === "fontFamily" ? normalizeFont(v) : v;
61
+ if (normalized !== undefined)
62
+ layout[key] = normalized;
63
+ }
64
+ const customView = attrs["custom_view"];
65
+ if (customView !== undefined) {
66
+ if (!isTfExpr(customView) || customView.$expr !== "jsonencode")
67
+ throw new Unrepresentable("layout.custom_view is not a jsonencode(...) expression");
68
+ layout.customView = decodeSpec(customView.value, opts);
69
+ }
70
+ return layout;
71
+ }
72
+ /** A blocks layout (the value inside `jsonencode(...)`) → plain JSON with `AgentViewSpecMarker` objects at reference positions. */
73
+ export function viewBlocksFromTf(value, opts) {
74
+ try {
75
+ return { ok: true, layout: decodeSpec(value, opts, "layout") };
76
+ }
77
+ catch (error) {
78
+ if (error instanceof Unrepresentable)
79
+ return { ok: false, reason: error.message };
80
+ throw error;
81
+ }
82
+ }
83
+ function decodeSpec(value, opts, root = "custom_view") {
84
+ const spec = plain(value);
85
+ if (spec === undefined)
86
+ throw new Unrepresentable(`${root} is not an object`);
87
+ const out = {};
88
+ for (const [key, child] of Object.entries(spec)) {
89
+ if (key !== "elements") {
90
+ out[key] = literal(child, `${root}.${key}`);
91
+ continue;
92
+ }
93
+ const elements = plain(child);
94
+ if (elements === undefined)
95
+ throw new Unrepresentable(`${root}.elements is not an object`);
96
+ const outElements = {};
97
+ for (const [id, rawElement] of Object.entries(elements)) {
98
+ const element = plain(rawElement);
99
+ if (element === undefined)
100
+ throw new Unrepresentable(`${root}.elements.${id} is not an object`);
101
+ const type = typeof element["type"] === "string" ? element["type"] : "";
102
+ const outElement = {};
103
+ for (const [elKey, elValue] of Object.entries(element)) {
104
+ const where = `${root}.elements.${id}.${elKey}`;
105
+ outElement[elKey] = elKey === "props"
106
+ ? decodeProps(type, elValue, where, opts)
107
+ : elKey === "on" ? deepSourceMarkers(elValue, where, opts) : literal(elValue, where);
108
+ }
109
+ outElements[id] = outElement;
110
+ }
111
+ out["elements"] = outElements;
112
+ }
113
+ return out;
114
+ }
115
+ function decodeProps(type, value, where, opts) {
116
+ const props = plain(value);
117
+ if (props === undefined)
118
+ return literal(value, where);
119
+ const idProps = ID_PROPS[type] ?? {};
120
+ const out = {};
121
+ for (const [key, child] of Object.entries(props)) {
122
+ const propWhere = `${where}.${key}`;
123
+ const kind = idProps[key];
124
+ if (kind !== undefined && (isTfExpr(child) || (typeof child === "string" && child !== ""))) {
125
+ out[key] = kind === "field" ? fieldMarker(child, propWhere, opts) : appMarker(child, propWhere, opts);
126
+ }
127
+ else if (FILTER_PROPS.has(key)) {
128
+ out[key] = deepRefs(child, propWhere, opts);
129
+ }
130
+ else if (type === "ButtonBlock" && key === "buttons" && Array.isArray(child)) {
131
+ out[key] = child.map((item, i) => {
132
+ const button = plain(item);
133
+ if (button === undefined)
134
+ return literal(item, `${propWhere}[${i}]`);
135
+ return Object.fromEntries(Object.entries(button).map(([bKey, bValue]) => [
136
+ bKey,
137
+ bKey === "viewId" && typeof bValue === "string" && bValue !== ""
138
+ ? unsafe(bValue)
139
+ : bKey === "onPress"
140
+ ? deepSourceMarkers(bValue, `${propWhere}[${i}].${bKey}`, opts)
141
+ : literal(bValue, `${propWhere}[${i}].${bKey}`),
142
+ ]));
143
+ });
144
+ }
145
+ else {
146
+ out[key] = literal(child, propWhere);
147
+ }
148
+ }
149
+ return out;
150
+ }
151
+ function deepRefs(value, where, opts) {
152
+ if (isTfExpr(value)) {
153
+ return sourceRef(value, opts) ?? fieldMarker(value, where, opts);
154
+ }
155
+ if (isPlatformId(value))
156
+ return unsafe(value);
157
+ if (Array.isArray(value))
158
+ return value.map((item, i) => deepRefs(item, `${where}[${i}]`, opts));
159
+ const rec = plain(value);
160
+ if (rec !== undefined)
161
+ return Object.fromEntries(Object.entries(rec).map(([key, child]) => [key, deepRefs(child, `${where}.${key}`, opts)]));
162
+ return value;
163
+ }
164
+ /**
165
+ * Actions (`on` events, button `onPress`): only app or element references may
166
+ * appear. A platform id export could not resolve becomes unsafePlatformId(...);
167
+ * other strings stay plain.
168
+ */
169
+ function deepSourceMarkers(value, where, opts) {
170
+ if (isTfExpr(value)) {
171
+ const ref = sourceRef(value, opts);
172
+ if (ref === undefined)
173
+ throw new Unrepresentable(`${where} holds a reference the EDK cannot represent inside an action`);
174
+ return ref;
175
+ }
176
+ if (isPlatformId(value))
177
+ return unsafe(value);
178
+ if (Array.isArray(value))
179
+ return value.map((item, i) => deepSourceMarkers(item, `${where}[${i}]`, opts));
180
+ const rec = plain(value);
181
+ if (rec !== undefined)
182
+ return Object.fromEntries(Object.entries(rec).map(([key, child]) => [key, deepSourceMarkers(child, `${where}.${key}`, opts)]));
183
+ return value;
184
+ }
185
+ // Any non-empty string at an id position — a platform id, or a value the
186
+ // platform accepted that is not one — prints as unsafePlatformId(...), which
187
+ // build passes through unchanged, so pull → build round-trips exactly. An
188
+ // empty id stays a plain "" (unsafePlatformId rejects it).
189
+ function appMarker(value, where, opts) {
190
+ if (typeof value === "string")
191
+ return unsafe(value);
192
+ const ref = sourceRef(value, opts);
193
+ if (ref === undefined)
194
+ throw new Unrepresentable(`${where} references an app the EDK cannot represent here`);
195
+ return ref;
196
+ }
197
+ /** The owner, or another app or element through its data lookup. */
198
+ function sourceRef(value, opts) {
199
+ if (opts.isOwnApp(value))
200
+ return { __specRef: "app" };
201
+ return opts.foreignSource?.(value);
202
+ }
203
+ function fieldMarker(value, where, opts) {
204
+ if (typeof value === "string")
205
+ return unsafe(value);
206
+ // Checked first: the owner's resolver reports a foreign lookup as unknown.
207
+ const foreign = opts.foreignField?.(value);
208
+ if (foreign !== undefined)
209
+ return foreign;
210
+ const key = opts.fieldKey(value);
211
+ if (key === undefined)
212
+ throw new Unrepresentable(`${where} references a field the EDK cannot represent here`);
213
+ return PLATFORM_ID.test(key) ? unsafe(key) : { __specRef: "field", key };
214
+ }
215
+ /** Plain JSON outside the id positions: any reference here is unrepresentable. */
216
+ function literal(value, where) {
217
+ if (isTfExpr(value))
218
+ throw new Unrepresentable(`${where} holds a reference outside the custom view's id props`);
219
+ if (Array.isArray(value))
220
+ return value.map((item, i) => literal(item, `${where}[${i}]`));
221
+ const rec = plain(value);
222
+ if (rec !== undefined)
223
+ return Object.fromEntries(Object.entries(rec).map(([key, child]) => [key, literal(child, `${where}.${key}`)]));
224
+ return value;
225
+ }
226
+ const HEX_COLOR = /^#?[0-9a-fA-F]{3,8}$/;
227
+ const FONT_FAMILIES = new Set(["sans", "serif", "mono"]);
228
+ /**
229
+ * The page renders only hex colours (with or without '#'), so pull mirrors the
230
+ * provider's normalization: '#'-prefix a bare hex, and treat anything else as
231
+ * unset (the platform ignores it).
232
+ */
233
+ function normalizeColor(color) {
234
+ const trimmed = color.trim();
235
+ if (!HEX_COLOR.test(trimmed))
236
+ return undefined;
237
+ return trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
238
+ }
239
+ /** An unknown font renders as system, the default. */
240
+ function normalizeFont(font) {
241
+ return FONT_FAMILIES.has(font) ? font : undefined;
242
+ }
243
+ function unsafe(id) {
244
+ return { __specRef: "unsafe", id };
245
+ }
246
+ function isPlatformId(value) {
247
+ return typeof value === "string" && PLATFORM_ID.test(value);
248
+ }
249
+ function plain(value) {
250
+ return value !== null && typeof value === "object" && !Array.isArray(value) && !isTfExpr(value)
251
+ ? value
252
+ : undefined;
253
+ }
254
+ /** Own-app field bag keys a pulled layout references (for hoisting their consts). */
255
+ export function collectAgentViewLayoutFieldKeys(layout) {
256
+ const keys = [];
257
+ const walk = (value) => {
258
+ if (Array.isArray(value)) {
259
+ value.forEach(walk);
260
+ return;
261
+ }
262
+ if (value === null || typeof value !== "object")
263
+ return;
264
+ const rec = value;
265
+ if (rec["__specRef"] === "field" && typeof rec["key"] === "string") {
266
+ keys.push(rec["key"]);
267
+ return;
268
+ }
269
+ Object.values(rec).forEach(walk);
270
+ };
271
+ walk(layout?.customView);
272
+ return keys;
273
+ }
274
+ /** Own field bag keys a pulled blocks layout references (for hoisting their consts). */
275
+ export function collectViewBlocksFieldKeys(layout) {
276
+ return collectAgentViewLayoutFieldKeys(layout === undefined ? undefined : { customView: layout });
277
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Build: blocks layouts → HCL. `agentViews.<key>.layout` → the `layout`
3
+ * attribute of `elementum_agent_view` (its custom view is a blocks layout);
4
+ * `customViews.<key>.layout` → the `layout` attribute of
5
+ * `elementum_custom_view` (see `viewBlocksToTf`). Platform ids resolve from
6
+ * typed references at the per-block id positions, inside nested filters and
7
+ * inside actions; a structurally broken layout fails the build, because
8
+ * dropping it would make apply clear the live one.
9
+ */
10
+ import type { OrgRefLookup, WorkspaceAspect } from "../../engine/build/context.js";
11
+ import { type ChildResourceScope, type TfValue } from "../../engine/tf/index.js";
12
+ export interface AgentViewLayoutToTfOptions {
13
+ readonly ownerRefName: string;
14
+ /** The view owner's kind; an agent view's owner is always an app. */
15
+ readonly ownerKind?: "app" | "element";
16
+ readonly ownerTfLabel: string;
17
+ readonly scope: ChildResourceScope;
18
+ readonly objectId: TfValue;
19
+ readonly diagnostics: string[];
20
+ readonly fieldAddresses?: ReadonlyMap<string, string>;
21
+ readonly orgRefs?: OrgRefLookup;
22
+ readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
23
+ /** Resolves an own-app field reference (view/to-tf's field resolver). */
24
+ readonly resolveField: (ref: unknown, where: string) => TfValue | undefined;
25
+ }
26
+ /** Wire shape of an authored layout (the public type, unchecked). */
27
+ export interface AppAgentViewLayoutWire {
28
+ readonly image?: {
29
+ readonly attachment?: unknown;
30
+ readonly url?: unknown;
31
+ };
32
+ readonly header?: string;
33
+ readonly subHeader?: string;
34
+ readonly branding?: {
35
+ readonly backgroundColor?: string;
36
+ readonly primaryColor?: string;
37
+ readonly fontFamily?: string;
38
+ };
39
+ readonly customView?: unknown;
40
+ }
41
+ export declare function agentViewLayoutToTf(layout: AppAgentViewLayoutWire, where: string, opts: AgentViewLayoutToTfOptions): TfValue;
42
+ export interface ViewBlocksToTfPolicy {
43
+ /**
44
+ * Warn about blocks the agent view admin UI's JSON editor will not re-apply
45
+ * (its managed-view authoring policy). The Custom view builder has no such
46
+ * policy.
47
+ */
48
+ readonly editorPolicy: boolean;
49
+ }
50
+ /** A blocks layout → its HCL value (wrap it in `jsonencode`). */
51
+ export declare function viewBlocksToTf(spec: unknown, where: string, opts: AgentViewLayoutToTfOptions, policy: ViewBlocksToTfPolicy): TfValue;