@elementumai/edk 0.9.6 → 0.9.9

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 +34 -3
  2. package/dist-sdk/src/catalog/factories.d.ts +26 -6
  3. package/dist-sdk/src/catalog/factories.js +41 -6
  4. package/dist-sdk/src/catalog/from-authoring.js +27 -33
  5. package/dist-sdk/src/catalog/index.d.ts +2 -2
  6. package/dist-sdk/src/catalog/index.js +2 -2
  7. package/dist-sdk/src/catalog/org.js +93 -42
  8. package/dist-sdk/src/catalog/token.js +10 -0
  9. package/dist-sdk/src/catalog/types.d.ts +42 -3
  10. package/dist-sdk/src/catalog/types.js +5 -0
  11. package/dist-sdk/src/core/index.d.ts +2 -2
  12. package/dist-sdk/src/core/index.js +1 -1
  13. package/dist-sdk/src/core/platform-id.d.ts +2 -0
  14. package/dist-sdk/src/core/platform-id.js +4 -0
  15. package/dist-sdk/src/core/system-fields.d.ts +18 -0
  16. package/dist-sdk/src/core/system-fields.js +21 -0
  17. package/dist-sdk/src/core/triggers/on-demand.d.ts +27 -24
  18. package/dist-sdk/src/core/triggers/on-demand.js +33 -12
  19. package/dist-sdk/src/core/types/app.d.ts +14 -9
  20. package/dist-sdk/src/core/types/aspect-category.d.ts +1 -0
  21. package/dist-sdk/src/core/types/aspect-category.js +1 -0
  22. package/dist-sdk/src/core/types/platform.d.ts +1 -1
  23. package/dist-sdk/src/engine/build/context.d.ts +24 -8
  24. package/dist-sdk/src/engine/build/source-context.d.ts +14 -17
  25. package/dist-sdk/src/engine/build/source-context.js +1 -1
  26. package/dist-sdk/src/engine/pull/context.d.ts +18 -0
  27. package/dist-sdk/src/engine/pull/org.d.ts +4 -0
  28. package/dist-sdk/src/engine/pull/org.js +17 -2
  29. package/dist-sdk/src/engine/pull/procedure-refs.d.ts +16 -0
  30. package/dist-sdk/src/engine/pull/procedure-refs.js +69 -0
  31. package/dist-sdk/src/engine/pull/ref-only.d.ts +14 -0
  32. package/dist-sdk/src/engine/pull/ref-only.js +35 -2
  33. package/dist-sdk/src/engine/tf/expr.js +1 -1
  34. package/dist-sdk/src/engine/workspace/authoring-layout.d.ts +15 -0
  35. package/dist-sdk/src/engine/workspace/authoring-layout.js +33 -1
  36. package/dist-sdk/src/engine/workspace/loader.d.ts +40 -0
  37. package/dist-sdk/src/engine/workspace/loader.js +328 -0
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +4 -0
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +24 -4
  40. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +7 -0
  41. package/dist-sdk/src/entities/access-policy/to-tf.js +11 -3
  42. package/dist-sdk/src/entities/agent/build.d.ts +54 -8
  43. package/dist-sdk/src/entities/agent/build.js +36 -1
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +144 -3
  45. package/dist-sdk/src/entities/agent/from-tf.d.ts +7 -6
  46. package/dist-sdk/src/entities/agent/from-tf.js +176 -5
  47. package/dist-sdk/src/entities/agent/index.d.ts +2 -2
  48. package/dist-sdk/src/entities/agent/index.js +1 -1
  49. package/dist-sdk/src/entities/agent/module.js +1 -0
  50. package/dist-sdk/src/entities/agent/to-tf.d.ts +5 -4
  51. package/dist-sdk/src/entities/agent/to-tf.js +186 -11
  52. package/dist-sdk/src/entities/agent/tools.d.ts +16 -5
  53. package/dist-sdk/src/entities/agent/tools.js +13 -1
  54. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +16 -0
  55. package/dist-sdk/src/entities/agent-tool/from-tf.js +39 -6
  56. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -0
  57. package/dist-sdk/src/entities/agent-tool/to-tf.js +12 -12
  58. package/dist-sdk/src/entities/agent-tool/types.js +1 -0
  59. package/dist-sdk/src/entities/app/build.d.ts +44 -24
  60. package/dist-sdk/src/entities/app/build.js +18 -8
  61. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +15 -0
  62. package/dist-sdk/src/entities/app/display-blocks-to-layout.d.ts +45 -0
  63. package/dist-sdk/src/entities/app/display-blocks-to-layout.js +98 -0
  64. package/dist-sdk/src/entities/app/display-blocks-to-record-create-form.d.ts +55 -0
  65. package/dist-sdk/src/entities/app/display-blocks-to-record-create-form.js +99 -0
  66. package/dist-sdk/src/entities/app/from-tf.js +79 -14
  67. package/dist-sdk/src/entities/app/index.d.ts +3 -2
  68. package/dist-sdk/src/entities/app/index.js +2 -1
  69. package/dist-sdk/src/entities/app/to-tf.js +30 -6
  70. package/dist-sdk/src/entities/automation/build.d.ts +37 -18
  71. package/dist-sdk/src/entities/automation/build.js +121 -12
  72. package/dist-sdk/src/entities/automation/catalog-render.js +5 -2
  73. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +8 -10
  74. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +2 -0
  75. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +103 -20
  76. package/dist-sdk/src/entities/automation/from-tf.d.ts +10 -1
  77. package/dist-sdk/src/entities/automation/from-tf.js +1165 -91
  78. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  79. package/dist-sdk/src/entities/automation/module.js +15 -5
  80. package/dist-sdk/src/entities/automation/operators.d.ts +2 -2
  81. package/dist-sdk/src/entities/automation/operators.js +1 -0
  82. package/dist-sdk/src/entities/automation/output-field-types.d.ts +17 -0
  83. package/dist-sdk/src/entities/automation/output-field-types.js +45 -0
  84. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +20 -4
  85. package/dist-sdk/src/entities/automation/output-key-wire-name.js +33 -6
  86. package/dist-sdk/src/entities/automation/script-code.d.ts +1 -1
  87. package/dist-sdk/src/entities/automation/script-code.js +168 -36
  88. package/dist-sdk/src/entities/automation/task-label.d.ts +2 -0
  89. package/dist-sdk/src/entities/automation/task-label.js +18 -0
  90. package/dist-sdk/src/entities/automation/tasks.d.ts +159 -45
  91. package/dist-sdk/src/entities/automation/tasks.js +60 -47
  92. package/dist-sdk/src/entities/automation/to-tf.d.ts +7 -1
  93. package/dist-sdk/src/entities/automation/to-tf.js +816 -87
  94. package/dist-sdk/src/entities/automation/triggers.d.ts +14 -5
  95. package/dist-sdk/src/entities/automation/triggers.js +1 -1
  96. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +78 -0
  97. package/dist-sdk/src/entities/automation/value-ref-tf.js +193 -0
  98. package/dist-sdk/src/entities/dashboard/from-tf.js +1 -1
  99. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +1 -0
  100. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +1 -1
  101. package/dist-sdk/src/entities/element/build.d.ts +30 -7
  102. package/dist-sdk/src/entities/element/build.js +7 -3
  103. package/dist-sdk/src/entities/element/from-tf.js +7 -3
  104. package/dist-sdk/src/entities/element/index.d.ts +3 -2
  105. package/dist-sdk/src/entities/element/index.js +3 -2
  106. package/dist-sdk/src/entities/element/to-tf.js +49 -8
  107. package/dist-sdk/src/entities/field/build.d.ts +94 -3
  108. package/dist-sdk/src/entities/field/build.js +82 -3
  109. package/dist-sdk/src/entities/field/from-tf.d.ts +6 -0
  110. package/dist-sdk/src/entities/field/from-tf.js +104 -1
  111. package/dist-sdk/src/entities/field/locals.js +6 -7
  112. package/dist-sdk/src/entities/field/module.js +1 -0
  113. package/dist-sdk/src/entities/field/options.d.ts +2 -0
  114. package/dist-sdk/src/entities/field/options.js +12 -2
  115. package/dist-sdk/src/entities/field/record-shape.d.ts +12 -15
  116. package/dist-sdk/src/entities/field/to-tf.d.ts +13 -3
  117. package/dist-sdk/src/entities/field/to-tf.js +191 -56
  118. package/dist-sdk/src/entities/field/types.js +2 -0
  119. package/dist-sdk/src/entities/org/category-ref.d.ts +5 -0
  120. package/dist-sdk/src/entities/org/category-ref.js +12 -0
  121. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -3
  122. package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +1 -0
  123. package/dist-sdk/src/entities/record-create-form/to-tf.js +18 -13
  124. package/dist-sdk/src/entities/relationship/from-tf.js +100 -7
  125. package/dist-sdk/src/entities/role/from-tf.js +10 -4
  126. package/dist-sdk/src/entities/search-table/build.d.ts +1 -1
  127. package/dist-sdk/src/entities/search-table/from-tf.d.ts +1 -0
  128. package/dist-sdk/src/entities/search-table/from-tf.js +6 -0
  129. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  130. package/dist-sdk/src/entities/search-table/to-tf.js +3 -3
  131. package/dist-sdk/src/entities/search-table/types.js +1 -0
  132. package/dist-sdk/src/entities/service-account/from-tf.js +10 -4
  133. package/dist-sdk/src/entities/service-account/to-tf.d.ts +2 -1
  134. package/dist-sdk/src/entities/service-account/to-tf.js +7 -0
  135. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +9 -0
  136. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +39 -0
  137. package/dist-sdk/src/entities/shared/filters/ast.d.ts +24 -1
  138. package/dist-sdk/src/entities/shared/filters/ast.js +4 -0
  139. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +13 -2
  140. package/dist-sdk/src/entities/shared/filters/tf-codec.js +14 -8
  141. package/dist-sdk/src/entities/shared/handle-description.d.ts +12 -0
  142. package/dist-sdk/src/entities/shared/handle-description.js +20 -0
  143. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +5 -3
  144. package/dist-sdk/src/entities/shared/tool-field-ref.js +11 -16
  145. package/dist-sdk/src/entities/shared/types/common.d.ts +7 -5
  146. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -1
  147. package/dist-sdk/src/entities/shared/types/field-types.js +5 -8
  148. package/dist-sdk/src/entities/shared/types/platform.d.ts +15 -2
  149. package/dist-sdk/src/entities/skill/build.d.ts +51 -2
  150. package/dist-sdk/src/entities/skill/build.js +65 -8
  151. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +1 -1
  152. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +79 -18
  153. package/dist-sdk/src/entities/skill/from-tf.d.ts +11 -0
  154. package/dist-sdk/src/entities/skill/from-tf.js +47 -5
  155. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  156. package/dist-sdk/src/entities/skill/index.js +1 -1
  157. package/dist-sdk/src/entities/skill/input-coverage.d.ts +89 -0
  158. package/dist-sdk/src/entities/skill/input-coverage.js +327 -0
  159. package/dist-sdk/src/entities/skill/module.js +2 -0
  160. package/dist-sdk/src/entities/skill/to-tf.d.ts +9 -25
  161. package/dist-sdk/src/entities/skill/to-tf.js +29 -40
  162. package/dist-sdk/src/entities/skill/tools.d.ts +12 -2
  163. package/dist-sdk/src/entities/skill/tools.js +3 -6
  164. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +19 -0
  165. package/dist-sdk/src/entities/skill-tool/from-tf.js +50 -14
  166. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +9 -7
  167. package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -23
  168. package/dist-sdk/src/entities/table/to-tf.js +21 -5
  169. package/dist-sdk/src/entities/task/to-tf.js +3 -2
  170. package/dist-sdk/src/entities/view/from-tf.js +36 -10
  171. package/dist-sdk/src/entities/view/to-tf.d.ts +2 -0
  172. package/dist-sdk/src/entities/view/to-tf.js +49 -30
  173. package/dist-sdk/src/entities/visual-flow/from-tf.js +6 -2
  174. package/dist-sdk/src/entities/widget/from-tf.js +2 -2
  175. package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
  176. package/dist-sdk/src/entities/widget/to-tf.js +52 -23
  177. package/dist-sdk/src/graph/index.d.ts +19 -1
  178. package/dist-sdk/src/graph/index.js +20 -0
  179. package/dist-sdk/src/graph/types.d.ts +22 -0
  180. package/package.json +11 -5
@@ -10,10 +10,10 @@
10
10
  * app_id as the owning app's resource ref, the connector as a
11
11
  * `data.elementum_ai_provider_connector` ref, agent-prefixed tool labels.
12
12
  * `skillAccess` emits `skill_access_config` (confirmed live against the
13
- * provider's `elementum_agent` schema). Authoring knobs the terraform
14
- * dialect still doesn't carry (temperature, reasoningEffort,
15
- * startingActions, …) degrade through `diagnostics` — reported, never
16
- * silent (plan §4.3).
13
+ * provider's `elementum_agent` schema). `startingActions` emit
14
+ * `starting_actions` (issue #760). Authoring knobs the terraform dialect
15
+ * still doesn't carry (temperature, reasoningEffort, …) degrade through
16
+ * `diagnostics` — reported, never silent (plan §4.3).
17
17
  */
18
18
  import { workspaceAspectKey } from "../../engine/build/context.js";
19
19
  import { EntityTfError } from "../../engine/entity.js";
@@ -30,19 +30,149 @@ import { AGENT_RESOURCE_TYPE } from "./module.js";
30
30
  * Config knobs `agent` accepts that the terraform dialect does not
31
31
  * carry (yet). `runAs`/`agentAuthentication`/`a2aStreaming`/
32
32
  * `conversationIdleTimeout` moved out of this list in issue #170,
33
- * `a2aCreateRecordEnabled` in issue #215 — they're now emitted (see the
34
- * attrs assembly below); the encoders below still drop a value that
35
- * doesn't fit the terraform-path shape, diagnosed individually rather
36
- * than through this blanket list.
33
+ * `a2aCreateRecordEnabled` in issue #215, `startingActions` in issue
34
+ * #760 — they're now emitted (see the attrs assembly below); the
35
+ * encoders below still drop a value that doesn't fit the terraform-path
36
+ * shape, diagnosed individually rather than through this blanket list.
37
37
  */
38
38
  const UNSUPPORTED_AGENT_KNOBS = [
39
39
  "temperature",
40
40
  "reasoningEffort",
41
- "startingActions",
42
41
  "avatarAttachmentId",
43
42
  "managedById",
44
43
  "serviceAccountId",
45
44
  ];
45
+ const STARTING_ACTION_VARIABLE_TYPES = new Set(["TEXT", "NUMBER", "SELECT"]);
46
+ function startingActionValidationValue(validation, variableKey, where, diagnostics) {
47
+ const value = {};
48
+ if (validation.minLength !== undefined) {
49
+ if (typeof validation.minLength === "number" && Number.isSafeInteger(validation.minLength)) {
50
+ value["min_length"] = validation.minLength;
51
+ }
52
+ else {
53
+ diagnostics.push(`${where}: starting action variable "${variableKey}" has non-integer validation minLength ${JSON.stringify(validation.minLength)}; dropped`);
54
+ }
55
+ }
56
+ if (validation.maxLength !== undefined) {
57
+ if (typeof validation.maxLength === "number" && Number.isSafeInteger(validation.maxLength)) {
58
+ value["max_length"] = validation.maxLength;
59
+ }
60
+ else {
61
+ diagnostics.push(`${where}: starting action variable "${variableKey}" has non-integer validation maxLength ${JSON.stringify(validation.maxLength)}; dropped`);
62
+ }
63
+ }
64
+ if (typeof validation.pattern === "string" && validation.pattern !== "")
65
+ value["pattern"] = validation.pattern;
66
+ if (typeof validation.errorMessage === "string" && validation.errorMessage !== "") {
67
+ value["error_message"] = validation.errorMessage;
68
+ }
69
+ return Object.keys(value).length > 0 ? value : undefined;
70
+ }
71
+ function startingActionVariableValue(variable, where, diagnostics) {
72
+ if (typeof variable.key !== "string" || variable.key === "") {
73
+ diagnostics.push(`${where}: starting action variable is missing key; dropped`);
74
+ return undefined;
75
+ }
76
+ if (typeof variable.label !== "string" || variable.label === "") {
77
+ diagnostics.push(`${where}: starting action variable "${variable.key}" is missing label; dropped`);
78
+ return undefined;
79
+ }
80
+ if (typeof variable.type !== "string" || !STARTING_ACTION_VARIABLE_TYPES.has(variable.type)) {
81
+ diagnostics.push(`${where}: starting action variable "${variable.key}" has unrecognized type ${JSON.stringify(variable.type)}; dropped`);
82
+ return undefined;
83
+ }
84
+ const value = {
85
+ key: variable.key,
86
+ label: variable.label,
87
+ type: variable.type,
88
+ };
89
+ if (variable.required === true)
90
+ value["required"] = true;
91
+ if (typeof variable.placeholder === "string" && variable.placeholder !== "") {
92
+ value["placeholder"] = variable.placeholder;
93
+ }
94
+ let options;
95
+ if (variable.options !== undefined && variable.options.length > 0) {
96
+ if (variable.type !== "SELECT") {
97
+ diagnostics.push(`${where}: starting action variable "${variable.key}" is type ${variable.type} but has options (only SELECT carries options); dropped`);
98
+ }
99
+ else {
100
+ const encoded = [];
101
+ for (const option of variable.options) {
102
+ if (typeof option.label !== "string" || typeof option.value !== "string") {
103
+ diagnostics.push(`${where}: starting action variable "${variable.key}" has an unrecognized option; dropped`);
104
+ continue;
105
+ }
106
+ encoded.push({ label: option.label, value: option.value });
107
+ }
108
+ if (encoded.length > 0)
109
+ options = encoded;
110
+ }
111
+ }
112
+ if (variable.type === "SELECT" && options === undefined) {
113
+ diagnostics.push(`${where}: starting action variable "${variable.key}" is type SELECT but has no valid options; dropped`);
114
+ return undefined;
115
+ }
116
+ if (options !== undefined)
117
+ value["options"] = options;
118
+ if (variable.validation !== undefined) {
119
+ const validation = startingActionValidationValue(variable.validation, variable.key, where, diagnostics);
120
+ if (validation !== undefined)
121
+ value["validation"] = validation;
122
+ }
123
+ return value;
124
+ }
125
+ function startingActionValue(action, where, diagnostics) {
126
+ if (typeof action.name !== "string" || action.name === "") {
127
+ diagnostics.push(`${where}: starting action is missing name; dropped`);
128
+ return undefined;
129
+ }
130
+ if (typeof action.prompt !== "string") {
131
+ diagnostics.push(`${where}: starting action "${action.name}" is missing prompt; dropped`);
132
+ return undefined;
133
+ }
134
+ if (typeof action.order !== "number" || !Number.isSafeInteger(action.order)) {
135
+ diagnostics.push(`${where}: starting action "${action.name}" is missing integer order; dropped`);
136
+ return undefined;
137
+ }
138
+ const value = {
139
+ name: action.name,
140
+ prompt: action.prompt,
141
+ order: action.order,
142
+ };
143
+ if (action.enabled === false)
144
+ value["enabled"] = false;
145
+ if (typeof action.icon === "string" && action.icon !== "")
146
+ value["icon"] = action.icon;
147
+ if (action.variables !== undefined && action.variables.length > 0) {
148
+ const variables = [];
149
+ for (const variable of action.variables) {
150
+ const encoded = startingActionVariableValue(variable, where, diagnostics);
151
+ if (encoded !== undefined)
152
+ variables.push(encoded);
153
+ }
154
+ if (variables.length > 0)
155
+ value["variables"] = variables;
156
+ }
157
+ return value;
158
+ }
159
+ /**
160
+ * Empty `variables`/`options` are OMITTED throughout, matching ei's exporter
161
+ * (`cmd/elementum/export/hcl_agent.go` only sets them when non-empty) —
162
+ * emitting `[]` here would break build-vs-export fidelity. The provider
163
+ * carries the other half of that contract: both attributes are
164
+ * Optional+Computed with an empty-list default, so an omitted list plans
165
+ * clean against the concrete list its Read hydrates.
166
+ */
167
+ function startingActionsValue(actions, where, diagnostics) {
168
+ const encoded = [];
169
+ for (const action of actions) {
170
+ const value = startingActionValue(action, where, diagnostics);
171
+ if (value !== undefined)
172
+ encoded.push(value);
173
+ }
174
+ return encoded.length > 0 ? encoded : undefined;
175
+ }
46
176
  /**
47
177
  * `runAs` authoring is the opaque object shape shared with agent-tool's
48
178
  * `runAs` (the remaining agent-level portion of board item B28(d));
@@ -215,13 +345,52 @@ export function agentToTf(entity, ctx) {
215
345
  }
216
346
  const payload = entity.payload;
217
347
  const elementum = payload?.agent?.elementum;
218
- if (payload === null || typeof payload !== "object" || elementum === undefined) {
219
- throw new EntityTfError(`agent "${entity.refName}" has no agent.elementum payload — was it built with agent?`);
348
+ const bedrock = payload?.agent?.bedrock;
349
+ if (payload === null || typeof payload !== "object" || (elementum === undefined && bedrock === undefined)) {
350
+ throw new EntityTfError(`agent "${entity.refName}" has no agent payload — was it built with agent or bedrockAgent?`);
220
351
  }
221
352
  // The bag key IS the label (the stable naming contract) — the agent's
222
353
  // refName comes from its file name, exactly like an app's.
223
354
  const agentBareTfLabel = tsLabelToTfLabel(entity.refName);
224
355
  const tfLabel = appScopedResourceLabel(ctx.appTfLabel, agentBareTfLabel);
356
+ if (bedrock !== undefined) {
357
+ const name = bedrock.name ?? "";
358
+ const where = `agent "${name}"`;
359
+ const attrs = {
360
+ app_id: expr.resourceAttr(APP_RESOURCE_TYPE, ctx.appTfLabel, ["id"]),
361
+ type: "bedrock",
362
+ name,
363
+ description: bedrock.description ?? "",
364
+ instructions: bedrock.instructions ?? "",
365
+ bedrock_agent_arn: bedrock.agentAliasArn ?? "",
366
+ };
367
+ if (bedrock.firstMessage !== undefined) {
368
+ attrs["first_message"] = bedrock.firstMessage;
369
+ }
370
+ const connector = bedrock.aiProviderConnectorId;
371
+ if (connector === undefined) {
372
+ ctx.diagnostics.push(`${where}: no provider connector token for bedrock agent`);
373
+ }
374
+ else {
375
+ const tsLabel = connector.parent !== undefined
376
+ ? `${connector.parent}.${connector.refName ?? ""}`
377
+ : (connector.refName ?? "");
378
+ const resolved = ctx.orgRefs.byTsLabel(CONNECTOR_ORG_BAG, tsLabel);
379
+ if (resolved === undefined) {
380
+ ctx.diagnostics.push(`${where}: connector token "${tsLabel}" is not in the org catalog — re-run \`elementum pull org --data-only\``);
381
+ }
382
+ else {
383
+ attrs["ai_provider_connector_id"] = expr.dataAttr("elementum_ai_provider_connector", resolved.tfLabel, ["id"]);
384
+ }
385
+ }
386
+ return {
387
+ blocks: [{ kind: "resource", type: AGENT_RESOURCE_TYPE, label: tfLabel, attrs }],
388
+ address: `${AGENT_RESOURCE_TYPE}.${tfLabel}`,
389
+ };
390
+ }
391
+ if (elementum === undefined) {
392
+ throw new EntityTfError(`agent "${entity.refName}" has no agent payload — was it built with agent or bedrockAgent?`);
393
+ }
225
394
  const name = elementum.name ?? "";
226
395
  const where = `agent "${name}"`;
227
396
  const attrs = {
@@ -248,6 +417,11 @@ export function agentToTf(entity, ctx) {
248
417
  attrs["a2a_streaming"] = elementum.a2aStreaming;
249
418
  if (elementum.a2aCreateRecordEnabled !== undefined)
250
419
  attrs["a2a_create_record_enabled"] = elementum.a2aCreateRecordEnabled;
420
+ if (elementum.startingActions !== undefined) {
421
+ const value = startingActionsValue(elementum.startingActions, where, ctx.diagnostics);
422
+ if (value !== undefined)
423
+ attrs["starting_actions"] = value;
424
+ }
251
425
  const connector = elementum.aiProviderConnectorId;
252
426
  if (connector === undefined) {
253
427
  ctx.diagnostics.push(`${where}: no connector token — the platform will pick a default model`);
@@ -285,6 +459,7 @@ export function agentToTf(entity, ctx) {
285
459
  appRefName: ctx.appRefName,
286
460
  appTfLabel: ctx.appTfLabel,
287
461
  agentBareTfLabel,
462
+ activeAutomationRefNames: ctx.activeAutomationRefNames,
288
463
  foreignAppRef: (l, n, ns) => ctx.orgRefs.foreignApp(l, n, ns),
289
464
  foreignElementRef: (l, n, ns) => ctx.orgRefs.foreignElement(l, n, ns),
290
465
  foreignAutomationRef: (l, n, owner) => {
@@ -52,6 +52,14 @@ export interface AgentSearchRawIdField {
52
52
  readonly description: string;
53
53
  }
54
54
  export type AgentSearchFieldInput<Target extends ToolTarget = ToolTarget> = AgentSearchField<Target> | AgentSearchRawIdField;
55
+ /** A runtime value supplied by the agent for a search filter variable. */
56
+ export interface AgentFilterVariable {
57
+ /** Stable platform identifier referenced by the filter JSON. */
58
+ readonly id: UnsafePlatformId;
59
+ readonly name: string;
60
+ readonly description: string;
61
+ readonly required: boolean;
62
+ }
55
63
  /** A typed target field exposed through a search-table tool's newer fields dialect. */
56
64
  export interface AgentSearchTableField<Target extends ElementCatalogRef = ElementCatalogRef> {
57
65
  readonly field: FieldRef<Target["refName"]>;
@@ -141,6 +149,7 @@ interface CommonToolOptions {
141
149
  export type SearchRecordsToolOptions<Target extends ToolTarget = ToolTarget> = CommonToolOptions & TargetOption<Target> & {
142
150
  readonly queryDescription: string;
143
151
  readonly fields?: readonly AgentSearchFieldInput<Target>[];
152
+ readonly filterVariables?: readonly AgentFilterVariable[];
144
153
  /** Pre-built wire `Filter` (may embed `FieldRef` tokens — resolved at deploy). */
145
154
  readonly filter?: Filter;
146
155
  /** Pre-built wire `Sort` (`{ orders: [{ field, direction }] }`). */
@@ -172,6 +181,7 @@ type SearchTableFieldDialect<Target extends ElementCatalogRef> = {
172
181
  export type SearchTableToolV2<Target extends ElementCatalogRef = ElementCatalogRef> = CommonToolOptions & TargetOption<Target> & {
173
182
  readonly table: SearchTableRef;
174
183
  readonly queryDescription: string;
184
+ readonly filterVariables?: readonly AgentFilterVariable[];
175
185
  readonly filter?: Filter;
176
186
  readonly limit?: number;
177
187
  } & SearchTableFieldDialect<Target>;
@@ -183,12 +193,13 @@ export declare function agentCreateRecord<Target extends ToolTarget>(opts: Creat
183
193
  export type UpdateRecordToolV2<Target extends ToolTarget = ToolTarget> = CommonToolOptions & TargetOption<Target> & {
184
194
  readonly fields?: readonly AgentRecordFieldInput<Target>[];
185
195
  /**
186
- * How the agent should identify which record to update — the provider
187
- * requires this (there's no way to infer it) and rejects an empty value
188
- * at apply with an opaque "Unable to validate" error, so it's required
189
- * here instead. Example: "Identify the ticket by its ID or subject line."
196
+ * How the agent should identify which record to update. Omit entirely
197
+ * when there's no description; the platform accepts that. An explicit
198
+ * empty string is always a mistake, never a valid value - it rejects that
199
+ * at apply with an opaque "Unable to validate" error.
200
+ * Example: "Identify the ticket by its ID or subject line."
190
201
  */
191
- readonly handleDescription: string;
202
+ readonly handleDescription?: string;
192
203
  };
193
204
  export declare function agentUpdateRecord<Target extends ToolTarget>(opts: UpdateRecordToolV2<Target>): AgentTool;
194
205
  type RelatedTargetOption<Target extends ToolTarget> = Target extends {
@@ -1,7 +1,16 @@
1
1
  import { isValidToolName } from "../agent-tool/types.js";
2
+ import { assertHandleDescriptionNotEmpty } from "../shared/handle-description.js";
2
3
  function targetOf(opts) {
3
4
  return ("app" in opts && opts.app !== undefined ? opts.app : opts.element);
4
5
  }
6
+ function filterVariableToken(variable) {
7
+ return {
8
+ id: variable.id.value,
9
+ name: variable.name,
10
+ description: variable.description,
11
+ required: variable.required,
12
+ };
13
+ }
5
14
  function serializeRunAs(runAs) {
6
15
  if ("currentUser" in runAs)
7
16
  return { currentUser: true };
@@ -109,6 +118,7 @@ export function agentSearchRecords(opts) {
109
118
  aspectId: targetOf(opts),
110
119
  queryDescription: opts.queryDescription,
111
120
  ...(opts.fields !== undefined ? { fields: opts.fields.map(searchFieldToken) } : {}),
121
+ ...(opts.filterVariables !== undefined ? { filterVariables: opts.filterVariables.map(filterVariableToken) } : {}),
112
122
  ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
113
123
  ...(opts.sort !== undefined ? { sort: opts.sort } : {}),
114
124
  ...(opts.limit !== undefined ? { limit: opts.limit } : {}),
@@ -126,6 +136,7 @@ export function agentSearchTable(opts) {
126
136
  // legacy `return_fields` dialects while both carry typed FieldRefs.
127
137
  ...(opts.fields !== undefined ? { searchTableFields: opts.fields.map(searchTableFieldToken) } : {}),
128
138
  ...(opts.returnFields !== undefined ? { returnFields: opts.returnFields.map(returnFieldToken) } : {}),
139
+ ...(opts.filterVariables !== undefined ? { filterVariables: opts.filterVariables.map(filterVariableToken) } : {}),
129
140
  ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
130
141
  ...(opts.limit !== undefined ? { limit: opts.limit } : {}),
131
142
  },
@@ -141,12 +152,13 @@ export function agentCreateRecord(opts) {
141
152
  });
142
153
  }
143
154
  export function agentUpdateRecord(opts) {
155
+ assertHandleDescriptionNotEmpty(opts.handleDescription, "agentUpdateRecord");
144
156
  return tool({
145
157
  updateRecord: {
146
158
  ...common(opts),
147
159
  aspectId: targetOf(opts),
148
160
  ...(opts.fields !== undefined ? { fields: opts.fields.map(recordFieldToken) } : {}),
149
- handleDescription: opts.handleDescription,
161
+ ...(opts.handleDescription !== undefined ? { handleDescription: opts.handleDescription } : {}),
150
162
  },
151
163
  });
152
164
  }
@@ -40,6 +40,12 @@ export interface NormalizedSearchTableReturnField {
40
40
  readonly name?: string;
41
41
  readonly displayName?: string;
42
42
  }
43
+ export interface NormalizedFilterVariable {
44
+ readonly id: string;
45
+ readonly name: string;
46
+ readonly description: string;
47
+ readonly required: boolean;
48
+ }
43
49
  export type NormalizedToolTarget = {
44
50
  readonly kind: "self";
45
51
  } | {
@@ -50,6 +56,15 @@ export type NormalizedToolTarget = {
50
56
  /** A foreign ELEMENT via `data.elementum_element.<label>` — `name` from the stream's data block (board issue #42). */
51
57
  readonly kind: "foreignElement";
52
58
  readonly name: string;
59
+ } | {
60
+ /**
61
+ * `target_id` didn't resolve to any portable reference at export
62
+ * time (ei fell back to a bare platform UUID — board issue #648).
63
+ * Kept, not dropped, so the tool's other data survives the pull; the
64
+ * printer marks it with a TODO instead of silently losing the tool.
65
+ */
66
+ readonly kind: "unresolved";
67
+ readonly uuid: string;
53
68
  };
54
69
  export interface NormalizedExecuteWorkflowInput {
55
70
  /** The published workflow's declared trigger parameter name. */
@@ -78,6 +93,7 @@ export interface NormalizedAgentTool {
78
93
  readonly target?: NormalizedToolTarget;
79
94
  /** createRecord/searchAspect/updateRecord only; searchTable ids are upgraded later by recursive pull. */
80
95
  readonly fields?: readonly NormalizedToolField[];
96
+ readonly filterVariables?: readonly NormalizedFilterVariable[];
81
97
  /** searchTable's newer field shape (field_id/name/description) — mutually exclusive with `returnFields`. */
82
98
  readonly searchTableFields?: readonly NormalizedSearchTableField[];
83
99
  /** searchTable's legacy field shape (field_id/name/display_name) — mutually exclusive with `searchTableFields`. */
@@ -8,6 +8,7 @@ import { EntityTfError } from "../../engine/entity.js";
8
8
  import { dataRefLabel, optionalString, resourceRefLabel } from "../../engine/pull/context.js";
9
9
  import { isTfExpr, scopedLabelToBagKey, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
10
10
  import { resolveToolFieldKey } from "../shared/tool-field-ref.js";
11
+ import { dataAspectDisplayName } from "../shared/aspect-target-from-tf.js";
11
12
  import { KNOWN_TOOL_ATTRS, TOOL_SUB_TYPE_BY_RESOURCE } from "./types.js";
12
13
  function runAsFromTf(attrs, owner, where, ctx) {
13
14
  const value = optionalString(attrs, "run_as", where, ctx);
@@ -167,6 +168,7 @@ export function toolFromTf(block, owner, ctx) {
167
168
  fieldScope = resolved.fieldScope;
168
169
  }
169
170
  let fields;
171
+ let filterVariables;
170
172
  let searchTableFields;
171
173
  const rawFields = attrs["fields"];
172
174
  if (Array.isArray(rawFields)) {
@@ -199,7 +201,7 @@ export function toolFromTf(block, owner, ctx) {
199
201
  continue;
200
202
  }
201
203
  const rec = item;
202
- const fieldKey = resolveToolFieldKey(rec["field_id"], fieldScopeLabel, fieldScope);
204
+ const fieldKey = resolveToolFieldKey(rec["field_id"], fieldScopeLabel, fieldScope, ctx);
203
205
  // A field on a foreign/out-of-scope aspect has no field resource ei
204
206
  // can reference — it falls back to a bare platform id, confirmed
205
207
  // live (board issue #169). Preserve it (raw-id TODO placeholder)
@@ -224,6 +226,27 @@ export function toolFromTf(block, owner, ctx) {
224
226
  else if (rawFields !== undefined) {
225
227
  ctx.diagnostics.push(`${where}: fields is not a list; dropped`);
226
228
  }
229
+ const rawFilterVariables = attrs["filter_variables"];
230
+ if (Array.isArray(rawFilterVariables)) {
231
+ filterVariables = [];
232
+ for (const item of rawFilterVariables) {
233
+ if (typeof item !== "object" || item === null || Array.isArray(item) || isTfExpr(item)) {
234
+ ctx.diagnostics.push(`${where}: filter_variables item has an unrecognized shape; dropped`);
235
+ continue;
236
+ }
237
+ const rec = item;
238
+ if (typeof rec["id"] !== "string" || rec["id"] === "" || typeof rec["name"] !== "string" || typeof rec["description"] !== "string" || typeof rec["required"] !== "boolean") {
239
+ ctx.diagnostics.push(`${where}: filter_variables item is missing a required attribute; dropped`);
240
+ continue;
241
+ }
242
+ filterVariables.push({ id: rec["id"], name: rec["name"], description: rec["description"], required: rec["required"] });
243
+ }
244
+ if (filterVariables.length === 0)
245
+ filterVariables = undefined;
246
+ }
247
+ else if (rawFilterVariables !== undefined) {
248
+ ctx.diagnostics.push(`${where}: filter_variables is not a list; dropped`);
249
+ }
227
250
  // The provider export normalizes searchTable field_id to a raw platform id.
228
251
  // Preserve it here; the recursive pull printer can upgrade known ids using
229
252
  // the target element's dependency field registry.
@@ -253,9 +276,6 @@ export function toolFromTf(block, owner, ctx) {
253
276
  else if (rawReturnFields !== undefined) {
254
277
  ctx.diagnostics.push(`${where}: return_fields is not a list; dropped`);
255
278
  }
256
- if (subType.typeKey === "searchAspect" && attrs["filter_variables"] !== undefined) {
257
- ctx.diagnostics.push(`${where}: filter_variables are not supported on the terraform path yet; a rebuilt stream will omit them`);
258
- }
259
279
  let searchTableKey;
260
280
  let searchTableName;
261
281
  if (subType.typeKey === "searchTable") {
@@ -300,6 +320,7 @@ export function toolFromTf(block, owner, ctx) {
300
320
  ...(target !== undefined && { target }),
301
321
  ...(relatedTarget !== undefined && { relatedTarget }),
302
322
  ...(fields !== undefined && { fields }),
323
+ ...(filterVariables !== undefined && { filterVariables }),
303
324
  ...(searchTableFields !== undefined && { searchTableFields }),
304
325
  ...(returnFields !== undefined && { returnFields }),
305
326
  ...((subType.typeKey === "searchAspect" || subType.typeKey === "searchTable") && {
@@ -307,7 +328,12 @@ export function toolFromTf(block, owner, ctx) {
307
328
  }),
308
329
  ...(typeof attrs["result_limit"] === "number" && { limit: attrs["result_limit"] }),
309
330
  ...(subType.typeKey === "updateRecord" && {
310
- handleDescription: optionalString(attrs, "handle_description", where, ctx) ?? "",
331
+ // A live "" is not reconstructable any more than a missing attribute
332
+ // is - agentUpdateRecord's own assertHandleDescriptionNotEmpty throws
333
+ // on an explicit "", so printing one straight into an
334
+ // agentUpdateRecord({...}) call would crash the next time this source
335
+ // loads. Collapse it to undefined here so the printer never sees it.
336
+ handleDescription: optionalString(attrs, "handle_description", where, ctx) || undefined,
311
337
  }),
312
338
  ...(searchTableKey !== undefined && { searchTableKey }),
313
339
  ...(searchTableName !== undefined && { searchTableName }),
@@ -327,13 +353,20 @@ function aspectTargetFromTf(value, attrName, owner, ctx, where) {
327
353
  ]) {
328
354
  if (!isTfExpr(value) || value.$expr !== "data-attr" || value.type !== type)
329
355
  continue;
330
- const name = ctx.dataName(type, value.label);
356
+ const name = dataAspectDisplayName(ctx, scope, value.label);
331
357
  if (name === undefined) {
332
358
  ctx.diagnostics.push(`${where}: ${attrName} references data.${type}.${value.label} but the stream has no such data block; skipped`);
333
359
  return undefined;
334
360
  }
335
361
  return { target: { kind, name }, fieldScopeLabel: value.label, fieldScope: scope };
336
362
  }
363
+ if (typeof value === "string") {
364
+ // No portable reference was available at export time (ei fell back to
365
+ // the raw platform UUID) — keep the tool with an unresolved target
366
+ // instead of dropping it entirely (board issue #648).
367
+ ctx.diagnostics.push(`${where}: ${attrName} could not be resolved to a portable reference ("${value}"); kept as unresolved`);
368
+ return { target: { kind: "unresolved", uuid: value }, fieldScopeLabel: owner.ownerTfLabel, fieldScope: "app" };
369
+ }
337
370
  ctx.diagnostics.push(`${where}: ${attrName} has an unrecognized shape (${JSON.stringify(value)}); skipped`);
338
371
  return undefined;
339
372
  }
@@ -36,6 +36,8 @@ export interface ToolToTfContext {
36
36
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
37
37
  /** Records an app-scoped service-account lookup by name. */
38
38
  serviceAccountRef?(tfLabel: string, name: string): TfValue | void;
39
+ /** App-local automations whose publish resource will be emitted in this build. */
40
+ readonly activeAutomationRefNames?: ReadonlySet<string>;
39
41
  /** Degradations land here — reported by the caller, never silent. */
40
42
  readonly diagnostics: string[];
41
43
  }
@@ -13,9 +13,10 @@
13
13
  * `data.elementum_field` lookup when the typed target is foreign.
14
14
  */
15
15
  import { workspaceAspectKey } from "../../engine/build/context.js";
16
+ import { automationRunTargetResourceAttr } from "../automation/to-tf.js";
16
17
  import { appScopedResourceLabel, expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
17
- import { EntityTfError } from "../../engine/entity.js";
18
18
  import { fieldRefToTfValue } from "../field/to-tf.js";
19
+ import { encodeOptionalHandleDescription } from "../shared/handle-description.js";
19
20
  import { TOOL_SUB_TYPE_BY_TYPE_KEY } from "./types.js";
20
21
  function serviceAccountIdValue(token, where, ctx) {
21
22
  if (token.__kind !== "serviceAccount" || token.name === undefined || token.name === "") {
@@ -229,9 +230,7 @@ export function toolToTf(entry, ctx) {
229
230
  attrs["automation_id"] = expr.dataAttr("elementum_automation", dataLabel, ["id"]);
230
231
  }
231
232
  else {
232
- // The automation and workflow-publish resources carry the same platform
233
- // id. Reference the publish block so Terraform sequences publication.
234
- attrs["automation_id"] = expr.resourceAttr("elementum_workflow_publish", appScopedResourceLabel(ctx.appTfLabel, autoTfLabel), ["id"]);
233
+ attrs["automation_id"] = automationRunTargetResourceAttr(ctx.appTfLabel, typeof auto?.refName === "string" && auto.refName !== "" ? auto.refName : autoTfLabel, ctx.activeAutomationRefNames);
235
234
  }
236
235
  if (inner.inputs !== undefined && inner.inputs.length > 0) {
237
236
  attrs["inputs"] = inner.inputs.map((i) => ({
@@ -306,14 +305,7 @@ export function toolToTf(entry, ctx) {
306
305
  attrs["related_target_id"] = resolveTarget(inner.relatedAspectId, ctx).value;
307
306
  }
308
307
  if (typeKey === "updateRecord") {
309
- if (inner.handleDescription === undefined || inner.handleDescription === "") {
310
- // The provider requires a non-empty handle_description and rejects an
311
- // empty one at apply with an opaque "Unable to validate" error — fail
312
- // loud at build time instead (same discipline as the tool-name check).
313
- throw new EntityTfError(`${where}: agentUpdateRecord requires a non-empty \`handleDescription\` — the platform ` +
314
- `uses it to identify which record to update and rejects an empty value at apply.`);
315
- }
316
- attrs["handle_description"] = inner.handleDescription;
308
+ encodeOptionalHandleDescription(attrs, inner.handleDescription);
317
309
  }
318
310
  if (typeKey === "searchAspect" || typeKey === "searchTable") {
319
311
  attrs["query_description"] = inner.queryDescription ?? "";
@@ -323,6 +315,14 @@ export function toolToTf(entry, ctx) {
323
315
  ctx.diagnostics.push(`${where}: filter/sort are not supported on the terraform path yet; dropped`);
324
316
  }
325
317
  }
318
+ if ((typeKey === "searchAspect" || typeKey === "searchTable") && inner.filterVariables !== undefined && inner.filterVariables.length > 0) {
319
+ attrs["filter_variables"] = inner.filterVariables.map((variable) => ({
320
+ id: typeof variable.id === "string" ? variable.id : variable.id?.value ?? "",
321
+ name: variable.name ?? "",
322
+ description: variable.description ?? "",
323
+ required: variable.required ?? false,
324
+ }));
325
+ }
326
326
  if (typeKey === "searchTable") {
327
327
  const table = inner.searchTableId;
328
328
  if (table?.refName === undefined || table.refName === "") {
@@ -81,6 +81,7 @@ export const KNOWN_TOOL_ATTRS = {
81
81
  "query_description",
82
82
  "result_limit",
83
83
  "fields",
84
+ "filter_variables",
84
85
  "return_fields",
85
86
  ]),
86
87
  relateRecord: new Set([