@elementumai/edk 0.9.10 → 0.9.12

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 (124) hide show
  1. package/README.md +39 -5
  2. package/dist-sdk/src/catalog/factories.d.ts +42 -14
  3. package/dist-sdk/src/catalog/factories.js +77 -14
  4. package/dist-sdk/src/catalog/from-authoring.js +4 -4
  5. package/dist-sdk/src/catalog/index.d.ts +2 -2
  6. package/dist-sdk/src/catalog/index.js +1 -1
  7. package/dist-sdk/src/catalog/org.js +3 -2
  8. package/dist-sdk/src/catalog/token.js +4 -0
  9. package/dist-sdk/src/catalog/types.d.ts +32 -5
  10. package/dist-sdk/src/catalog/types.js +1 -0
  11. package/dist-sdk/src/core/triggers/on-demand.d.ts +4 -28
  12. package/dist-sdk/src/core/triggers/on-demand.js +2 -4
  13. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  14. package/dist-sdk/src/engine/entity.d.ts +2 -0
  15. package/dist-sdk/src/engine/logging.d.ts +90 -0
  16. package/dist-sdk/src/engine/logging.js +124 -0
  17. package/dist-sdk/src/engine/progress.d.ts +119 -0
  18. package/dist-sdk/src/engine/progress.js +647 -0
  19. package/dist-sdk/src/engine/pull/result-output.d.ts +24 -0
  20. package/dist-sdk/src/engine/pull/result-output.js +48 -0
  21. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +3 -3
  22. package/dist-sdk/src/entities/access-policy/from-tf.js +27 -8
  23. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +13 -0
  24. package/dist-sdk/src/entities/access-policy/to-tf.js +34 -3
  25. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +13 -7
  26. package/dist-sdk/src/entities/agent/tools.d.ts +2 -2
  27. package/dist-sdk/src/entities/agent-tool/to-tf.js +13 -0
  28. package/dist-sdk/src/entities/app/build.d.ts +22 -2
  29. package/dist-sdk/src/entities/app/build.js +6 -0
  30. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +13 -3
  31. package/dist-sdk/src/entities/app/from-tf.js +10 -7
  32. package/dist-sdk/src/entities/app/to-tf.js +14 -14
  33. package/dist-sdk/src/entities/automation/build.d.ts +11 -16
  34. package/dist-sdk/src/entities/automation/build.js +38 -8
  35. package/dist-sdk/src/entities/automation/catalog-render.js +1 -1
  36. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +1 -2
  37. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +23 -5
  38. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +239 -34
  39. package/dist-sdk/src/entities/automation/from-tf.js +276 -19
  40. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  41. package/dist-sdk/src/entities/automation/module.js +3 -2
  42. package/dist-sdk/src/entities/automation/output-field-types.js +25 -13
  43. package/dist-sdk/src/entities/automation/script-code.d.ts +12 -4
  44. package/dist-sdk/src/entities/automation/script-code.js +659 -101
  45. package/dist-sdk/src/entities/automation/tasks.d.ts +60 -28
  46. package/dist-sdk/src/entities/automation/tasks.js +48 -15
  47. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  48. package/dist-sdk/src/entities/automation/to-tf.js +514 -103
  49. package/dist-sdk/src/entities/automation/triggers.d.ts +15 -9
  50. package/dist-sdk/src/entities/automation/triggers.js +4 -2
  51. package/dist-sdk/src/entities/automation/types.js +1 -0
  52. package/dist-sdk/src/entities/chart/build.d.ts +15 -3
  53. package/dist-sdk/src/entities/chart/build.js +6 -1
  54. package/dist-sdk/src/entities/chart/from-tf.d.ts +8 -2
  55. package/dist-sdk/src/entities/chart/from-tf.js +71 -8
  56. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  57. package/dist-sdk/src/entities/chart/index.js +1 -1
  58. package/dist-sdk/src/entities/chart/printer.js +27 -7
  59. package/dist-sdk/src/entities/chart/to-tf.js +56 -2
  60. package/dist-sdk/src/entities/dashboard/from-tf.js +11 -2
  61. package/dist-sdk/src/entities/datamine/from-tf.js +11 -1
  62. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -1
  63. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +8 -0
  64. package/dist-sdk/src/entities/dynamic-layout/dialect.js +12 -0
  65. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +7 -0
  66. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +64 -10
  67. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +54 -6
  68. package/dist-sdk/src/entities/element/build.d.ts +8 -0
  69. package/dist-sdk/src/entities/element/from-tf.js +4 -3
  70. package/dist-sdk/src/entities/element/module.js +1 -0
  71. package/dist-sdk/src/entities/element/to-tf.d.ts +4 -1
  72. package/dist-sdk/src/entities/element/to-tf.js +28 -2
  73. package/dist-sdk/src/entities/field/build.d.ts +10 -1
  74. package/dist-sdk/src/entities/field/build.js +2 -1
  75. package/dist-sdk/src/entities/field/calc/index.js +7 -7
  76. package/dist-sdk/src/entities/field/calc/runtime.d.ts +19 -0
  77. package/dist-sdk/src/entities/field/calc/runtime.js +32 -0
  78. package/dist-sdk/src/entities/field/calc/types.d.ts +6 -0
  79. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  80. package/dist-sdk/src/entities/field/from-tf.js +73 -1
  81. package/dist-sdk/src/entities/field/metadata.d.ts +18 -0
  82. package/dist-sdk/src/entities/field/metadata.js +34 -0
  83. package/dist-sdk/src/entities/file-reader/to-tf.js +10 -2
  84. package/dist-sdk/src/entities/relationship/build.d.ts +27 -9
  85. package/dist-sdk/src/entities/relationship/column-contract.d.ts +24 -0
  86. package/dist-sdk/src/entities/relationship/column-contract.js +41 -0
  87. package/dist-sdk/src/entities/relationship/from-tf.js +33 -48
  88. package/dist-sdk/src/entities/relationship/to-tf.d.ts +1 -0
  89. package/dist-sdk/src/entities/relationship/to-tf.js +33 -2
  90. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  91. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +21 -0
  92. package/dist-sdk/src/entities/shared/context.d.ts +6 -3
  93. package/dist-sdk/src/entities/shared/context.js +19 -1
  94. package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
  95. package/dist-sdk/src/entities/shared/filters/index.js +28 -0
  96. package/dist-sdk/src/entities/shared/filters/print.js +2 -0
  97. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +8 -1
  98. package/dist-sdk/src/entities/shared/filters/tf-codec.js +10 -6
  99. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  100. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -0
  101. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +52 -27
  102. package/dist-sdk/src/entities/skill/module.js +1 -0
  103. package/dist-sdk/src/entities/skill/to-tf.d.ts +1 -1
  104. package/dist-sdk/src/entities/skill/to-tf.js +17 -0
  105. package/dist-sdk/src/entities/skill/tools.d.ts +48 -12
  106. package/dist-sdk/src/entities/skill/tools.js +12 -1
  107. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +15 -12
  108. package/dist-sdk/src/entities/skill-tool/from-tf.js +50 -46
  109. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +4 -0
  110. package/dist-sdk/src/entities/skill-tool/to-tf.js +66 -7
  111. package/dist-sdk/src/entities/table/build.js +10 -2
  112. package/dist-sdk/src/entities/table/catalog-render.js +2 -1
  113. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  114. package/dist-sdk/src/entities/view/to-tf.d.ts +7 -0
  115. package/dist-sdk/src/entities/view/to-tf.js +39 -12
  116. package/dist-sdk/src/entities/widget/build.d.ts +43 -7
  117. package/dist-sdk/src/entities/widget/from-tf.d.ts +1 -1
  118. package/dist-sdk/src/entities/widget/from-tf.js +162 -23
  119. package/dist-sdk/src/entities/widget/to-tf.d.ts +17 -0
  120. package/dist-sdk/src/entities/widget/to-tf.js +150 -6
  121. package/dist-sdk/src/graph/types.d.ts +13 -0
  122. package/package.json +1 -1
  123. package/dist-sdk/src/core/types/platform.d.ts +0 -2
  124. package/dist-sdk/src/core/types/platform.js +0 -1
@@ -11,7 +11,7 @@
11
11
  import type { ApprovalChainRef, AppOrElementRef, DatamineRef, FieldRef } from "../../catalog/index.js";
12
12
  import type { UnsafePlatformId } from "../../core/platform-id.js";
13
13
  import type { RecordShape } from "../field/record-shape.js";
14
- import { type InferTriggerType, type OnDemandTriggerOptions, type TriggerInputFieldDef, type TriggerInputSchema } from "../../core/triggers/on-demand.js";
14
+ import { type InferTriggerType, type TriggerInputFieldDef, type TriggerInputSchema } from "../../core/triggers/on-demand.js";
15
15
  import type { TriggerFieldTypeAlias } from "../shared/types/field-types.js";
16
16
  import type { Filter } from "./filter.js";
17
17
  import { type TriggerChain } from "./build.js";
@@ -71,7 +71,7 @@ type NormalizeSpec<S extends TriggerInputSchemaSpec> = {
71
71
  type: S[K];
72
72
  } : Extract<S[K], TriggerInputFieldDef>;
73
73
  };
74
- export declare function onDemand<S extends TriggerInputSchemaSpec, Options extends OnDemandTriggerOptions = Record<string, never>>(schema: S, options?: Options & Record<Exclude<keyof Options, keyof OnDemandTriggerOptions>, never>): TriggerChain<InferTriggerType<NormalizeSpec<S> & TriggerInputSchema, Options>>;
74
+ export declare function onDemand<S extends TriggerInputSchemaSpec>(schema: S): TriggerChain<InferTriggerType<NormalizeSpec<S> & TriggerInputSchema>>;
75
75
  export interface WebhookTriggerOptions {
76
76
  readonly authenticated?: boolean;
77
77
  /** Pre-built wire custom-response envelope. */
@@ -148,8 +148,11 @@ export interface DataMineTriggerOptions {
148
148
  readonly fireOnAlert?: boolean;
149
149
  readonly fireOnRecovery?: boolean;
150
150
  }
151
+ export interface DataMineTriggerOutput {
152
+ readonly record: Record<string, unknown>;
153
+ }
151
154
  /** Fires when a data mine meets/no longer meets requirements. */
152
- export declare function dataMine(opts: DataMineTriggerOptions): TriggerChain<Record<string, unknown>>;
155
+ export declare function dataMine(opts: DataMineTriggerOptions): TriggerChain<DataMineTriggerOutput>;
153
156
  export interface EmailReceivedTriggerOptions {
154
157
  readonly emailAliasId: string;
155
158
  }
@@ -179,17 +182,20 @@ export interface CommentAddedTriggerOutput<A extends AppOrElementRef = AppOrElem
179
182
  }
180
183
  /** Fires when a comment is added to a record on the given aspect. */
181
184
  export declare function commentAdded<A extends AppOrElementRef>(opts: CommentAddedTriggerOptions<A>): TriggerChain<CommentAddedTriggerOutput<A>>;
182
- export type ConversationEndConversationType = "A2A" | "VOICE" | "EMAIL" | "SLACK" | "TEAMS";
183
- export interface ConversationEndTriggerOptions {
184
- readonly app: AppOrElementRef;
185
+ export type ConversationEndConversationType = "A2A" | "ELEMENTUM_UI" | "VOICE" | "EMAIL" | "SLACK" | "TEAMS";
186
+ export interface ConversationEndTriggerOptions<A extends AppOrElementRef = AppOrElementRef> {
187
+ readonly app: A;
185
188
  readonly conversationType: ConversationEndConversationType;
189
+ readonly filter?: Filter;
186
190
  }
187
- export interface ConversationEndTriggerOutput {
188
- readonly record: Record<string, unknown>;
191
+ export interface ConversationEndTriggerOutput<A extends AppOrElementRef = AppOrElementRef> {
192
+ readonly record: RecordShape<A>;
189
193
  readonly transcript: string;
194
+ /** True when the conversation ended due to timeout. */
195
+ readonly timeoutReached?: boolean;
190
196
  }
191
197
  /** Fires when a conversation of the selected type ends on the given aspect. */
192
- export declare function conversationEnd(opts: ConversationEndTriggerOptions): TriggerChain<ConversationEndTriggerOutput>;
198
+ export declare function conversationEnd<A extends AppOrElementRef>(opts: ConversationEndTriggerOptions<A>): TriggerChain<ConversationEndTriggerOutput<A>>;
193
199
  export interface SlackMessageTriggerOutput {
194
200
  /** Slack thread id when the inbound message is part of a thread. */
195
201
  readonly threadId: string;
@@ -64,10 +64,10 @@ export function schedule(opts) {
64
64
  },
65
65
  });
66
66
  }
67
- export function onDemand(schema, options) {
67
+ export function onDemand(schema) {
68
68
  const normalized = Object.fromEntries(Object.entries(schema).map(([k, v]) => [k, typeof v === "string" ? { type: v } : v]));
69
69
  return chainableTrigger({
70
- wire: serializeOnDemandTrigger(normalized, options),
70
+ wire: serializeOnDemandTrigger(normalized),
71
71
  __params: Object.entries(normalized).map(([name, def]) => ({ name, required: def.required ?? false })),
72
72
  });
73
73
  }
@@ -180,8 +180,10 @@ export function conversationEnd(opts) {
180
180
  aspectId: opts.app,
181
181
  conversationType: opts.conversationType,
182
182
  type: "CONVERSATION_END",
183
+ ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
183
184
  },
184
185
  },
186
+ __recordApp: opts.app.refName,
185
187
  });
186
188
  }
187
189
  /** Fires when a Slack message is received. */
@@ -35,6 +35,7 @@ export const TRIGGER_SUB_TYPES = [
35
35
  { typeKey: "conversationEnd", resourceType: "elementum_agent_conversation_ended_trigger", implemented: true },
36
36
  { typeKey: "slackMessage", resourceType: "elementum_slack_message_trigger", implemented: true },
37
37
  { typeKey: "survey", resourceType: "elementum_survey_trigger", implemented: true },
38
+ { typeKey: "schedule", resourceType: "elementum_schedule_trigger", implemented: true },
38
39
  ];
39
40
  /**
40
41
  * Task kinds. All rows are implemented as of `aiFileAnalysis` (the last
@@ -1,6 +1,7 @@
1
1
  import { type AppCatalogRef, type AppOrElementRef, type ChartRef, type FieldRef, type TableColumnRef, type TableRef } from "../../catalog/index.js";
2
2
  import type { DeployableEntity, EntityDeployOptions } from "../../engine/entity.js";
3
3
  import type { Filter } from "../shared/filters/types.js";
4
+ import type { UnsafePlatformId } from "../../core/platform-id.js";
4
5
  import type { ChartAggregation, ChartColumnValueType, ChartJoinType, ChartType } from "./types.js";
5
6
  export { chartAggregation, chartColumnValueType, chartJoinType, chartType, type ChartAggregation, type ChartColumnValueType, type ChartJoinType, type ChartType, } from "./types.js";
6
7
  export type ChartDatasourceRef = AppOrElementRef | TableRef;
@@ -14,6 +15,16 @@ export type ChartFieldFor<Datasource> = Datasource extends {
14
15
  interface ChartColumnBase {
15
16
  readonly name?: string;
16
17
  }
18
+ /**
19
+ * Pull-only escape hatch for UI charts backed by a synthetic query datasource.
20
+ * The platform owns this shape; new charts should use typed subscriptions.
21
+ */
22
+ export interface ChartOpaqueSubscription {
23
+ readonly kind: "opaque";
24
+ readonly datasourceId: UnsafePlatformId;
25
+ readonly attributes: Readonly<Record<string, unknown>>;
26
+ }
27
+ export declare function __pulledChartSubscription(opts: Omit<ChartOpaqueSubscription, "kind">): ChartOpaqueSubscription;
17
28
  export type ChartColumn<Datasource extends ChartDatasourceRef = ChartDatasourceRef> = (ChartColumnBase & {
18
29
  readonly field?: ChartFieldFor<Datasource>;
19
30
  readonly aggregation: ChartAggregation;
@@ -27,9 +38,9 @@ export type ChartColumn<Datasource extends ChartDatasourceRef = ChartDatasourceR
27
38
  readonly aggregation?: never;
28
39
  readonly expression?: never;
29
40
  });
30
- export interface ChartGroupBy<Datasource extends ChartDatasourceRef = ChartDatasourceRef> {
41
+ export type ChartGroupBy<Datasource extends ChartDatasourceRef = ChartDatasourceRef> = {
31
42
  readonly field: ChartFieldFor<Datasource>;
32
- }
43
+ };
33
44
  declare const chartJoinBrand: unique symbol;
34
45
  export interface ChartJoin<From extends ChartDatasourceRef = ChartDatasourceRef, To extends ChartDatasourceRef = ChartDatasourceRef> {
35
46
  readonly [chartJoinBrand]: {
@@ -64,6 +75,7 @@ export interface ChartSubscription<Datasource extends ChartDatasourceRef = Chart
64
75
  readonly limit?: string;
65
76
  readonly tags?: readonly string[];
66
77
  }
78
+ export type ChartSubscriptionInput = ChartSubscription | ChartOpaqueSubscription;
67
79
  /** Build a chart subscription while preserving datasource/field ownership. */
68
80
  export declare function chartSubscription<const Datasource extends ChartDatasourceRef>(opts: Omit<ChartSubscription<Datasource>, typeof chartSubscriptionBrand | "columns" | "groupBy" | "joins"> & {
69
81
  readonly columns: readonly ChartColumn<NoInfer<Datasource>>[];
@@ -85,7 +97,7 @@ export interface DefineChartOptions<AppRefName extends string = string> extends
85
97
  readonly type: ChartType;
86
98
  readonly target?: number;
87
99
  readonly properties?: ChartProperties;
88
- readonly subscriptions: readonly ChartSubscription[];
100
+ readonly subscriptions: readonly ChartSubscriptionInput[];
89
101
  }
90
102
  export interface ChartConfigured<AppRefName extends string = string> {
91
103
  ref<const RefName extends string>(refName: RefName): ChartRef<AppRefName, RefName>;
@@ -1,5 +1,8 @@
1
1
  import { slimTokens, } from "../../catalog/index.js";
2
2
  export { chartAggregation, chartColumnValueType, chartJoinType, chartType, } from "./types.js";
3
+ export function __pulledChartSubscription(opts) {
4
+ return { kind: "opaque", ...opts };
5
+ }
3
6
  /** Define an ownership-checked join used by a chart subscription. */
4
7
  export function chartJoin(opts) {
5
8
  const { from: _from, ...wire } = opts;
@@ -18,7 +21,9 @@ function validateChart(refName, opts) {
18
21
  if (opts.subscriptions.length === 0)
19
22
  fail("at least one subscription is required");
20
23
  for (const [index, subscription] of opts.subscriptions.entries()) {
21
- if (subscription.columns.length === 0)
24
+ if ("kind" in subscription && subscription.kind === "opaque")
25
+ continue;
26
+ if (!("columns" in subscription) || subscription.columns.length === 0)
22
27
  fail(`subscriptions[${index}] must include at least one column`);
23
28
  }
24
29
  }
@@ -1,5 +1,5 @@
1
1
  import { type FromTfContext } from "../../engine/pull/context.js";
2
- import { type TfBlock } from "../../engine/tf/index.js";
2
+ import { type TfBlock, type TfValue } from "../../engine/tf/index.js";
3
3
  import type { Filter } from "../shared/filters/types.js";
4
4
  import type { ChartProperties } from "./build.js";
5
5
  export interface NormalizedChartDatasource {
@@ -33,6 +33,7 @@ export interface NormalizedChartJoin {
33
33
  readonly type?: string;
34
34
  }
35
35
  export interface NormalizedChartSubscription {
36
+ readonly kind?: "typed";
36
37
  readonly datasource: NormalizedChartDatasource;
37
38
  readonly columns: readonly NormalizedChartColumn[];
38
39
  readonly groupBy?: readonly NormalizedChartGroupBy[];
@@ -41,13 +42,18 @@ export interface NormalizedChartSubscription {
41
42
  readonly limit?: string;
42
43
  readonly tags?: readonly string[];
43
44
  }
45
+ export interface NormalizedChartOpaqueSubscription {
46
+ readonly kind: "opaque";
47
+ readonly datasourceId: string;
48
+ readonly attributes: Readonly<Record<string, TfValue>>;
49
+ }
44
50
  export interface NormalizedChart {
45
51
  readonly refName: string;
46
52
  readonly name: string;
47
53
  readonly type: string;
48
54
  readonly target?: number;
49
55
  readonly properties?: ChartProperties;
50
- readonly subscriptions: readonly NormalizedChartSubscription[];
56
+ readonly subscriptions: readonly (NormalizedChartSubscription | NormalizedChartOpaqueSubscription)[];
51
57
  }
52
58
  export declare function chartFromTf(block: TfBlock, opts: {
53
59
  readonly appLabel: string;
@@ -1,7 +1,7 @@
1
1
  import { dataRefLabel, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
3
3
  import { FIELD_RESOURCE_TYPES } from "../field/types.js";
4
- import { fieldKeyFromTfRef } from "../field/from-tf.js";
4
+ import { fieldKeyFromTfValue } from "../field/from-tf.js";
5
5
  import { filterFromTf } from "../shared/filters/tf-codec.js";
6
6
  import { CHART_RESOURCE_TYPE } from "./types.js";
7
7
  const APP_RESOURCE_TYPE = "elementum_app";
@@ -73,7 +73,7 @@ function indexedField(value) {
73
73
  }
74
74
  function fieldFromTf(value, datasource, ctx, where) {
75
75
  if (value !== undefined && (datasource.kind === "app" || datasource.kind === "element")) {
76
- const refName = fieldKeyFromTfRef(value, datasource.tfLabel, datasource.kind);
76
+ const refName = fieldKeyFromTfValue(value, datasource.refName, datasource.tfLabel, datasource.kind, ctx);
77
77
  if (refName !== undefined)
78
78
  return { kind: "field", parentKind: datasource.kind, parentRefName: datasource.refName, refName };
79
79
  }
@@ -132,7 +132,62 @@ function fieldFromTf(value, datasource, ctx, where) {
132
132
  function stringList(value) {
133
133
  return Array.isArray(value) && value.every((item) => typeof item === "string") ? value : undefined;
134
134
  }
135
+ function opaqueSubscriptionFromTf(value, where, ctx) {
136
+ const rec = plainObject(value);
137
+ const datasourceId = rec?.["datasource_id"];
138
+ const withValue = rec?.["with"];
139
+ const decodedWith = withValue === undefined ? undefined : decodeJson(withValue);
140
+ const columns = rec?.["columns"];
141
+ const columnNames = Array.isArray(columns)
142
+ ? columns.map((column) => plainObject(column)?.["name"]).filter((name) => typeof name === "string")
143
+ : [];
144
+ const hasUiRoles = columnNames.includes("Label") && (columnNames.includes("Value") || columnNames.includes("Series"));
145
+ if (typeof datasourceId !== "string" || decodedWith === undefined || plainObject(decodedWith)?.["statement"] === undefined || !hasUiRoles)
146
+ return undefined;
147
+ const attributes = {};
148
+ for (const [key, item] of Object.entries(rec)) {
149
+ if (key === "datasource_id")
150
+ continue;
151
+ if (key === "columns" && Array.isArray(item)) {
152
+ attributes[key] = item.map((column) => {
153
+ const columnObject = plainObject(column);
154
+ if (columnObject === undefined)
155
+ return column;
156
+ return {
157
+ ...columnObject,
158
+ ...(columnObject["expression"] !== undefined ? { expression: decodeJson(columnObject["expression"]) } : {}),
159
+ };
160
+ });
161
+ }
162
+ else if (key === "sort" || key === "with" || key === "filter") {
163
+ attributes[key] = decodeJson(item) ?? item;
164
+ }
165
+ else if (key === "group_bys" && Array.isArray(item)) {
166
+ attributes[key] = item.map((group) => {
167
+ const groupObject = plainObject(group);
168
+ return groupObject === undefined ? group : { ...groupObject, ...(groupObject["expression"] !== undefined ? { expression: decodeJson(groupObject["expression"]) } : {}) };
169
+ });
170
+ }
171
+ else if (key === "joins" && Array.isArray(item)) {
172
+ attributes[key] = item.map((join) => {
173
+ const joinObject = plainObject(join);
174
+ return joinObject === undefined ? join : {
175
+ ...joinObject,
176
+ ...(joinObject["left_expression"] !== undefined ? { left_expression: decodeJson(joinObject["left_expression"]) } : {}),
177
+ ...(joinObject["right_expression"] !== undefined ? { right_expression: decodeJson(joinObject["right_expression"]) } : {}),
178
+ };
179
+ });
180
+ }
181
+ else
182
+ attributes[key] = item;
183
+ }
184
+ ctx.diagnostics.push(`${where}: preserved UI chart synthetic datasource as an opaque pull-only subscription`);
185
+ return { kind: "opaque", datasourceId, attributes };
186
+ }
135
187
  function parseSubscription(value, appLabel, appRefName, ctx, where) {
188
+ const opaque = opaqueSubscriptionFromTf(value, where, ctx);
189
+ if (opaque !== undefined)
190
+ return opaque;
136
191
  const rec = plainObject(value);
137
192
  if (rec === undefined) {
138
193
  ctx.diagnostics.push(`${where}: subscription is not an object; skipped`);
@@ -153,13 +208,13 @@ function parseSubscription(value, appLabel, appRefName, ctx, where) {
153
208
  ctx.diagnostics.push(`${where}.columns[${index}]: not an object; subscription skipped`);
154
209
  return undefined;
155
210
  }
156
- if (column["expression"] !== undefined) {
157
- ctx.diagnostics.push(`${where}.columns[${index}]: expression columns are not authorable; subscription skipped`);
158
- return undefined;
159
- }
160
211
  const field = column["column_id"] !== undefined ? fieldFromTf(column["column_id"], datasource, ctx, `${where}.columns[${index}].column_id`) : undefined;
161
212
  if (column["column_id"] !== undefined && field === undefined)
213
+ continue;
214
+ if (column["expression"] !== undefined) {
215
+ ctx.diagnostics.push(`${where}.columns[${index}].expression: unsupported chart expression; subscription skipped`);
162
216
  return undefined;
217
+ }
163
218
  columns.push({
164
219
  ...(field !== undefined ? { field } : {}),
165
220
  ...(typeof column["aggregation"] === "string" ? { aggregation: column["aggregation"] } : {}),
@@ -168,13 +223,21 @@ function parseSubscription(value, appLabel, appRefName, ctx, where) {
168
223
  ...(typeof column["value_type"] === "string" ? { valueType: column["value_type"] } : {}),
169
224
  });
170
225
  }
226
+ if (columns.length === 0) {
227
+ ctx.diagnostics.push(`${where}: no resolvable columns remain; subscription skipped`);
228
+ return undefined;
229
+ }
171
230
  const rawGroupBys = rec["group_bys"];
172
231
  const groupBy = Array.isArray(rawGroupBys) ? [] : undefined;
173
232
  if (groupBy !== undefined && Array.isArray(rawGroupBys))
174
233
  for (const [index, value] of rawGroupBys.entries()) {
175
234
  const group = plainObject(value);
176
- if (group === undefined || group["expression"] !== undefined || group["column_id"] === undefined) {
177
- ctx.diagnostics.push(`${where}.group_bys[${index}]: only typed field groupings are authorable; subscription skipped`);
235
+ if (group === undefined || (group["column_id"] === undefined && group["expression"] === undefined)) {
236
+ ctx.diagnostics.push(`${where}.group_bys[${index}]: grouping must contain a typed field or supported expression; subscription skipped`);
237
+ return undefined;
238
+ }
239
+ if (group["expression"] !== undefined) {
240
+ ctx.diagnostics.push(`${where}.group_bys[${index}].expression: unsupported chart expression; subscription skipped`);
178
241
  return undefined;
179
242
  }
180
243
  const field = fieldFromTf(group["column_id"], datasource, ctx, `${where}.group_bys[${index}].column_id`);
@@ -1,4 +1,4 @@
1
- export { chartAggregation, chartColumnValueType, chartJoin, chartJoinType, chartSubscription, chartType, defineChart, type ChartAggregation, type ChartColumn, type ChartColumnValueType, type ChartConfigured, type ChartDatasourceRef, type ChartFieldFor, type ChartGroupBy, type ChartJoin, type ChartJoinType, type ChartProperties, type ChartSubscription, type ChartType, type DefineChartOptions, } from "./build.js";
1
+ export { chartAggregation, chartColumnValueType, chartJoin, chartJoinType, chartSubscription, chartType, __pulledChartSubscription, defineChart, type ChartAggregation, type ChartColumn, type ChartColumnValueType, type ChartConfigured, type ChartDatasourceRef, type ChartFieldFor, type ChartGroupBy, type ChartJoin, type ChartJoinType, type ChartOpaqueSubscription, type ChartSubscriptionInput, type ChartProperties, type ChartSubscription, type ChartType, type DefineChartOptions, } from "./build.js";
2
2
  export { dashboardChartWidget, dashboardRecordsWidget, dashboardWidgetSize, type DashboardChartWidget, type DashboardWidgetSize, } from "../dashboard/build.js";
3
3
  export * as filter from "../shared/filters/index.js";
4
4
  export { type Filter } from "../shared/filters/index.js";
@@ -1,3 +1,3 @@
1
- export { chartAggregation, chartColumnValueType, chartJoin, chartJoinType, chartSubscription, chartType, defineChart, } from "./build.js";
1
+ export { chartAggregation, chartColumnValueType, chartJoin, chartJoinType, chartSubscription, chartType, __pulledChartSubscription, defineChart, } from "./build.js";
2
2
  export { dashboardChartWidget, dashboardRecordsWidget, dashboardWidgetSize, } from "../dashboard/build.js";
3
3
  export * as filter from "../shared/filters/index.js";
@@ -17,6 +17,17 @@ function fieldExpr(value) {
17
17
  ? `catalog.tables${member(value.parentRefName)}.columns${member(value.refName)}`
18
18
  : `catalog${member(value.parentRefName)}.fields${member(value.refName)}`;
19
19
  }
20
+ function printOpaqueSubscription(subscription) {
21
+ const attrs = Object.entries(subscription.attributes)
22
+ .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
23
+ .join(", ");
24
+ return [
25
+ " __pulledChartSubscription({",
26
+ ` datasourceId: unsafePlatformId(${quote(subscription.datasourceId)}),`,
27
+ ` attributes: { ${attrs} },`,
28
+ " }),",
29
+ ];
30
+ }
20
31
  function printColumn(column) {
21
32
  const parts = [];
22
33
  if (column.field !== undefined)
@@ -65,20 +76,25 @@ function printSubscription(subscription) {
65
76
  }
66
77
  export function printChart(chart, opts) {
67
78
  const imports = ["chartSubscription", "chartType", "defineChart"];
68
- if (chart.subscriptions.some((subscription) => subscription.columns.some((column) => column.aggregation !== undefined)))
79
+ if (chart.subscriptions.some((subscription) => subscription.kind === "opaque"))
80
+ imports.push("__pulledChartSubscription");
81
+ if (chart.subscriptions.some((subscription) => subscription.kind !== "opaque" && subscription.columns.some((column) => column.aggregation !== undefined)))
69
82
  imports.push("chartAggregation");
70
- if (chart.subscriptions.some((subscription) => subscription.columns.some((column) => column.valueType !== undefined)))
83
+ if (chart.subscriptions.some((subscription) => subscription.kind !== "opaque" && subscription.columns.some((column) => column.valueType !== undefined)))
71
84
  imports.push("chartColumnValueType");
72
- if (chart.subscriptions.some((subscription) => (subscription.joins?.length ?? 0) > 0))
85
+ if (chart.subscriptions.some((subscription) => subscription.kind !== "opaque" && (subscription.joins?.length ?? 0) > 0))
73
86
  imports.push("chartJoin");
74
- if (chart.subscriptions.some((subscription) => subscription.joins?.some((join) => join.type !== undefined) === true))
87
+ if (chart.subscriptions.some((subscription) => subscription.kind !== "opaque" && subscription.joins?.some((join) => join.type !== undefined) === true))
75
88
  imports.push("chartJoinType");
76
- if (chart.subscriptions.some((subscription) => subscription.filter !== undefined))
89
+ if (chart.subscriptions.some((subscription) => subscription.kind !== "opaque" && subscription.filter !== undefined))
77
90
  imports.push("filter");
78
91
  const lines = [
79
92
  "/** Auto-generated by EDK pull. Hand-edit freely. */",
80
93
  `import { ${imports.sort().join(", ")} } from ${quote(sdkPackageSpecifier("charts"))};`,
81
94
  'import catalog from "@catalog";',
95
+ ...(chart.subscriptions.some((subscription) => subscription.kind === "opaque")
96
+ ? [`import { unsafePlatformId } from ${quote(sdkPackageSpecifier("core"))};`]
97
+ : []),
82
98
  "",
83
99
  "const chart = defineChart({",
84
100
  ` app: catalog${member(opts.appRefName)},`,
@@ -97,8 +113,12 @@ export function printChart(chart, opts) {
97
113
  lines.push(` properties: { ${parts.join(", ")} },`);
98
114
  }
99
115
  lines.push(" subscriptions: [");
100
- for (const subscription of chart.subscriptions)
101
- lines.push(...printSubscription(subscription));
116
+ for (const subscription of chart.subscriptions) {
117
+ if (subscription.kind === "opaque")
118
+ lines.push(...printOpaqueSubscription(subscription));
119
+ else
120
+ lines.push(...printSubscription(subscription));
121
+ }
102
122
  lines.push(" ],", "});", "", "export default chart;", "");
103
123
  return lines.join("\n");
104
124
  }
@@ -3,6 +3,7 @@ import { EntityTfError } from "../../engine/entity.js";
3
3
  import { expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
4
4
  import { fieldRefToTfValue } from "../field/to-tf.js";
5
5
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
6
+ import { isUnsafePlatformId } from "../../core/platform-id.js";
6
7
  import { CHART_RESOURCE_TYPE } from "./types.js";
7
8
  const APP_RESOURCE_TYPE = "elementum_app";
8
9
  const TABLE_RESOURCE_TYPE = "elementum_table";
@@ -70,13 +71,66 @@ function columnToTf(column, datasource, opts, where) {
70
71
  return out;
71
72
  }
72
73
  function filterToTf(value, datasource, opts, where) {
73
- return expr.jsonencode(serializeFilterToTf(value, {
74
+ return serializeFilterToTf(value, {
74
75
  field: (field) => fieldId(field, datasource, opts, `${where}.field`),
75
76
  aspect: () => datasource.id,
76
77
  reference: () => { throw new EntityTfError(`${where}: runtime reference values are not supported in chart filters`); },
77
- }));
78
+ });
79
+ }
80
+ function opaqueSubscriptionToTf(subscription, where) {
81
+ if (!isUnsafePlatformId(subscription.datasourceId)) {
82
+ throw new EntityTfError(`${where}: opaque chart datasource must use unsafePlatformId(...)`);
83
+ }
84
+ const out = { datasource_id: subscription.datasourceId.value };
85
+ for (const [key, value] of Object.entries(subscription.attributes ?? {})) {
86
+ if (key === "sort" || key === "with" || key === "filter") {
87
+ out[key] = expr.jsonencode(value);
88
+ continue;
89
+ }
90
+ if (key === "columns" && Array.isArray(value)) {
91
+ out[key] = value.map((column) => {
92
+ if (typeof column !== "object" || column === null)
93
+ return column;
94
+ const item = column;
95
+ return {
96
+ ...item,
97
+ ...(item["expression"] !== undefined ? { expression: expr.jsonencode(item["expression"]) } : {}),
98
+ };
99
+ });
100
+ continue;
101
+ }
102
+ if (key === "group_bys" && Array.isArray(value)) {
103
+ out[key] = value.map((group) => {
104
+ if (typeof group !== "object" || group === null)
105
+ return group;
106
+ const item = group;
107
+ return {
108
+ ...item,
109
+ ...(item["expression"] !== undefined ? { expression: expr.jsonencode(item["expression"]) } : {}),
110
+ };
111
+ });
112
+ continue;
113
+ }
114
+ if (key === "joins" && Array.isArray(value)) {
115
+ out[key] = value.map((join) => {
116
+ if (typeof join !== "object" || join === null)
117
+ return join;
118
+ const item = join;
119
+ return {
120
+ ...item,
121
+ ...(item["left_expression"] !== undefined ? { left_expression: expr.jsonencode(item["left_expression"]) } : {}),
122
+ ...(item["right_expression"] !== undefined ? { right_expression: expr.jsonencode(item["right_expression"]) } : {}),
123
+ };
124
+ });
125
+ continue;
126
+ }
127
+ out[key] = value;
128
+ }
129
+ return out;
78
130
  }
79
131
  function subscriptionToTf(subscription, opts, where) {
132
+ if (subscription.kind === "opaque")
133
+ return opaqueSubscriptionToTf(subscription, where);
80
134
  const datasource = datasourceId(subscription.datasource, opts, `${where}.datasource`);
81
135
  const out = {
82
136
  datasource_id: datasource.id,
@@ -7,6 +7,7 @@ import { DASHBOARD_WIDGET_RESOURCE_TYPE } from "../dashboard-widget/module.js";
7
7
  import { DASHBOARD_RESOURCE_TYPE } from "./module.js";
8
8
  import { CHART_RESOURCE_TYPE } from "../chart/types.js";
9
9
  import { dashboardWidgetSize } from "./build.js";
10
+ import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
10
11
  const KNOWN_DASHBOARD_ATTRS = new Set(["name", "owner_id", "owner_type", "favorite", "tags"]);
11
12
  export function dashboardsFromTf(blocks, widgetBlocks, owner, ctx) {
12
13
  const dashboards = [];
@@ -93,8 +94,16 @@ function aspectRef(value, owner, ctx) {
93
94
  if (resourceLabel !== undefined)
94
95
  return { kind, key: tfLabelToTsLabel(resourceLabel), name: tfLabelToTsLabel(resourceLabel) };
95
96
  const dataLabel = dataRefLabel(value, type);
96
- if (dataLabel !== undefined)
97
- return { kind, key: tfLabelToTsLabel(dataLabel), name: ctx.dataName(type, dataLabel) ?? tfLabelToTsLabel(dataLabel) };
97
+ if (dataLabel !== undefined) {
98
+ // Same namespace-only foreign-target shape widget/from-tf.ts resolves
99
+ // via the shared helper - a guessed tfLabel-derived name matches
100
+ // nothing on the platform and breaks elementum build/plan.
101
+ // printDashboardTargetRef always emits appRef()/elementRef() regardless
102
+ // of provenance, so catalogRef (widget's raw-literal-vs-factory-call
103
+ // switch) has no printer to gate here - only key/name/namespace matter.
104
+ const resolved = resolveDataAspectTarget(ctx, kind, dataLabel);
105
+ return { kind, key: resolved.key, name: resolved.name, ...(resolved.namespace !== undefined ? { namespace: resolved.namespace } : {}) };
106
+ }
98
107
  }
99
108
  return undefined;
100
109
  }
@@ -1,7 +1,7 @@
1
1
  import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
3
3
  import { EntityTfError } from "../../engine/entity.js";
4
- import { isTfExpr, tfLabelToTsLabel } from "../../engine/tf/index.js";
4
+ import { isTfExpr, snakeSlug, tfLabelToTsLabel } from "../../engine/tf/index.js";
5
5
  import { filterFromTf } from "../shared/filters/tf-codec.js";
6
6
  const KNOWN_DATAMINE_ATTRS = new Set([
7
7
  "id",
@@ -94,6 +94,16 @@ function tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, ctx
94
94
  if (key !== undefined)
95
95
  return key;
96
96
  }
97
+ // Older `ei tables export` versions emitted table datamine filters through
98
+ // the generic field data source (`data.elementum_field.<table>_<column>.id`)
99
+ // even though the field belongs to the table. Resolve that legacy shape by
100
+ // its stable table/column label so the pulled datamine remains authorable.
101
+ if (isTfExpr(value) && value.$expr === "data-attr" && value.type === "elementum_field" && value.label.startsWith(`${tableTfLabel}_`) && value.path[0] === "id") {
102
+ const columnSlug = value.label.slice(tableTfLabel.length + 1);
103
+ const match = [...columnKeyByName.entries()].find(([name]) => snakeSlug(name) === columnSlug);
104
+ if (match !== undefined)
105
+ return match[1];
106
+ }
97
107
  const fieldLabel = dataRefLabel(value, "elementum_field");
98
108
  if (fieldLabel !== undefined) {
99
109
  const attrs = ctx.dataAttrs?.("elementum_field", fieldLabel);
@@ -1,4 +1,4 @@
1
- import type { AppOrElementRef, AutomationRef } from "../../catalog/index.js";
1
+ import type { AgentRef, AppOrElementRef, AutomationRef } from "../../catalog/index.js";
2
2
  import type { AppViewFieldRef } from "../app/build.js";
3
3
  export type DynamicLayoutTypedValue = {
4
4
  readonly string: string;
@@ -78,6 +78,7 @@ export interface DynamicLayoutComponentVariantMap {
78
78
  readonly icon?: string;
79
79
  readonly color?: string;
80
80
  readonly collapsible?: boolean;
81
+ readonly agent?: AgentRef;
81
82
  readonly defaultCollapsed?: boolean;
82
83
  readonly hidden?: boolean;
83
84
  readonly className?: string;
@@ -2,3 +2,11 @@ export declare const DYNAMIC_LAYOUT_FIELD_COMPONENT_WIRE_KEY_BY_PUBLIC_KEY: Read
2
2
  export declare const DYNAMIC_LAYOUT_FIELD_COMPONENT_KEYS: ReadonlySet<string>;
3
3
  export declare function dynamicLayoutFieldComponentWireKey(publicKey: string): string;
4
4
  export declare const DYNAMIC_LAYOUT_COMPARISON_KEYS: ReadonlySet<string>;
5
+ /**
6
+ * Dynamic-layout automation buttons are runnable only after a parameterless
7
+ * run-automation display widget exists for the selected automation. App Admin
8
+ * creates that widget as a save side effect; EDK emits an explicit companion
9
+ * resource instead so OpenTofu owns the complete contract.
10
+ */
11
+ export declare const DYNAMIC_LAYOUT_ACTION_WIDGET_NAME_PREFIX = "EDK dynamic layout action ";
12
+ export declare function dynamicLayoutActionWidgetName(layoutKey: string, componentId: string): string;
@@ -1,3 +1,4 @@
1
+ import { splitCamelCase } from "../../engine/tf/labels.js";
1
2
  /**
2
3
  * Public field-component keys are listed exhaustively against the authoring
3
4
  * variant map. Adding a field component there without adding it here is a
@@ -45,3 +46,14 @@ export const DYNAMIC_LAYOUT_COMPARISON_KEYS = new Set([
45
46
  "equals", "notEquals", "greaterThan", "greaterThanOrEqual", "lessThan", "lessThanOrEqual",
46
47
  "contains", "notContains", "in", "notIn", "empty", "notEmpty",
47
48
  ]);
49
+ /**
50
+ * Dynamic-layout automation buttons are runnable only after a parameterless
51
+ * run-automation display widget exists for the selected automation. App Admin
52
+ * creates that widget as a save side effect; EDK emits an explicit companion
53
+ * resource instead so OpenTofu owns the complete contract.
54
+ */
55
+ export const DYNAMIC_LAYOUT_ACTION_WIDGET_NAME_PREFIX = "EDK dynamic layout action ";
56
+ export function dynamicLayoutActionWidgetName(layoutKey, componentId) {
57
+ const words = (value) => splitCamelCase(value.replace(/[_-]+/g, " ")).toLowerCase();
58
+ return `${DYNAMIC_LAYOUT_ACTION_WIDGET_NAME_PREFIX}${words(layoutKey)} ${words(componentId)}`;
59
+ }
@@ -8,3 +8,10 @@ export interface DynamicLayoutOwner {
8
8
  readonly ownerTfLabel: string;
9
9
  }
10
10
  export declare function dynamicLayoutsFromTf(blocks: readonly TfBlock[], owner: DynamicLayoutOwner, ctx: FromTfContext): NormalizedDynamicLayout[];
11
+ /**
12
+ * Widget resource labels referenced by dynamic-layout automation buttons.
13
+ * The label is the companion widget's stable Terraform identity; its display
14
+ * name is mutable and cannot safely distinguish generated from authored
15
+ * widgets during pull.
16
+ */
17
+ export declare function dynamicLayoutCompanionWidgetLabels(blocks: readonly TfBlock[]): ReadonlySet<string>;