@elementumai/edk 0.9.5 → 0.9.7

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 (97) hide show
  1. package/README.md +31 -1
  2. package/dist-sdk/src/catalog/factories.d.ts +12 -3
  3. package/dist-sdk/src/catalog/factories.js +9 -6
  4. package/dist-sdk/src/catalog/org.js +26 -13
  5. package/dist-sdk/src/catalog/types.d.ts +22 -1
  6. package/dist-sdk/src/core/index.d.ts +1 -1
  7. package/dist-sdk/src/core/system-fields.d.ts +4 -0
  8. package/dist-sdk/src/core/system-fields.js +15 -0
  9. package/dist-sdk/src/core/types/app.d.ts +14 -9
  10. package/dist-sdk/src/core/types/platform.d.ts +1 -1
  11. package/dist-sdk/src/engine/build/context.d.ts +4 -0
  12. package/dist-sdk/src/engine/pull/context.d.ts +9 -0
  13. package/dist-sdk/src/engine/pull/ref-only.d.ts +14 -0
  14. package/dist-sdk/src/engine/pull/ref-only.js +35 -2
  15. package/dist-sdk/src/entities/access-policy/from-tf.js +14 -2
  16. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +6 -0
  17. package/dist-sdk/src/entities/access-policy/to-tf.js +4 -1
  18. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +18 -1
  19. package/dist-sdk/src/entities/agent/module.js +1 -0
  20. package/dist-sdk/src/entities/agent/to-tf.d.ts +1 -0
  21. package/dist-sdk/src/entities/agent/to-tf.js +1 -0
  22. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +9 -0
  23. package/dist-sdk/src/entities/agent-tool/from-tf.js +10 -2
  24. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -0
  25. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -3
  26. package/dist-sdk/src/entities/app/build.d.ts +42 -22
  27. package/dist-sdk/src/entities/app/build.js +12 -5
  28. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +10 -0
  29. package/dist-sdk/src/entities/app/from-tf.js +71 -8
  30. package/dist-sdk/src/entities/app/index.d.ts +3 -2
  31. package/dist-sdk/src/entities/app/index.js +2 -1
  32. package/dist-sdk/src/entities/app/to-tf.js +16 -0
  33. package/dist-sdk/src/entities/automation/build.d.ts +31 -19
  34. package/dist-sdk/src/entities/automation/build.js +85 -7
  35. package/dist-sdk/src/entities/automation/catalog-render.js +5 -2
  36. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +5 -3
  37. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +26 -12
  38. package/dist-sdk/src/entities/automation/from-tf.js +364 -31
  39. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  40. package/dist-sdk/src/entities/automation/module.js +2 -2
  41. package/dist-sdk/src/entities/automation/operators.d.ts +2 -2
  42. package/dist-sdk/src/entities/automation/operators.js +1 -0
  43. package/dist-sdk/src/entities/automation/output-field-types.d.ts +17 -0
  44. package/dist-sdk/src/entities/automation/output-field-types.js +45 -0
  45. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +8 -0
  46. package/dist-sdk/src/entities/automation/output-key-wire-name.js +16 -0
  47. package/dist-sdk/src/entities/automation/script-code.js +153 -25
  48. package/dist-sdk/src/entities/automation/tasks.d.ts +100 -37
  49. package/dist-sdk/src/entities/automation/tasks.js +44 -43
  50. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -1
  51. package/dist-sdk/src/entities/automation/to-tf.js +454 -58
  52. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +78 -0
  53. package/dist-sdk/src/entities/automation/value-ref-tf.js +193 -0
  54. package/dist-sdk/src/entities/element/build.js +1 -0
  55. package/dist-sdk/src/entities/element/index.d.ts +2 -1
  56. package/dist-sdk/src/entities/element/index.js +2 -1
  57. package/dist-sdk/src/entities/field/build.d.ts +94 -3
  58. package/dist-sdk/src/entities/field/build.js +82 -3
  59. package/dist-sdk/src/entities/field/from-tf.js +92 -1
  60. package/dist-sdk/src/entities/field/locals.js +6 -7
  61. package/dist-sdk/src/entities/field/options.d.ts +2 -0
  62. package/dist-sdk/src/entities/field/options.js +12 -2
  63. package/dist-sdk/src/entities/field/record-shape.d.ts +12 -15
  64. package/dist-sdk/src/entities/field/to-tf.d.ts +12 -2
  65. package/dist-sdk/src/entities/field/to-tf.js +172 -51
  66. package/dist-sdk/src/entities/field/types.js +2 -0
  67. package/dist-sdk/src/entities/record-create-form/to-tf.js +5 -8
  68. package/dist-sdk/src/entities/relationship/from-tf.js +91 -9
  69. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +9 -0
  70. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +39 -0
  71. package/dist-sdk/src/entities/shared/filters/ast.d.ts +18 -1
  72. package/dist-sdk/src/entities/shared/filters/ast.js +1 -0
  73. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +6 -1
  74. package/dist-sdk/src/entities/shared/filters/tf-codec.js +6 -4
  75. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +5 -3
  76. package/dist-sdk/src/entities/shared/tool-field-ref.js +11 -16
  77. package/dist-sdk/src/entities/shared/types/common.d.ts +7 -5
  78. package/dist-sdk/src/entities/shared/types/platform.d.ts +15 -2
  79. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +1 -1
  80. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +44 -15
  81. package/dist-sdk/src/entities/skill/from-tf.js +11 -1
  82. package/dist-sdk/src/entities/skill/input-coverage.d.ts +68 -0
  83. package/dist-sdk/src/entities/skill/input-coverage.js +184 -0
  84. package/dist-sdk/src/entities/skill/module.js +2 -0
  85. package/dist-sdk/src/entities/skill/to-tf.d.ts +3 -0
  86. package/dist-sdk/src/entities/skill/to-tf.js +7 -2
  87. package/dist-sdk/src/entities/skill/tools.d.ts +10 -1
  88. package/dist-sdk/src/entities/skill/tools.js +0 -5
  89. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +19 -0
  90. package/dist-sdk/src/entities/skill-tool/from-tf.js +40 -11
  91. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +4 -2
  92. package/dist-sdk/src/entities/skill-tool/to-tf.js +24 -16
  93. package/dist-sdk/src/entities/table/to-tf.js +18 -1
  94. package/dist-sdk/src/entities/view/to-tf.js +8 -3
  95. package/dist-sdk/src/entities/visual-flow/from-tf.js +6 -2
  96. package/dist-sdk/src/graph/types.d.ts +3 -0
  97. package/package.json +2 -1
@@ -2,6 +2,7 @@ import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
3
  import { filterFromTf } from "../access-policy/from-tf.js";
4
4
  import { fieldKeyFromTfRef } from "../field/from-tf.js";
5
+ import { dataAspectDisplayName, dataAspectRefName } from "../shared/aspect-target-from-tf.js";
5
6
  import { SUB_TYPE_BY_RESOURCE } from "../field/types.js";
6
7
  import { RELATIONSHIP_RESOURCE_TYPE } from "./module.js";
7
8
  const KNOWN_ATTRS = new Set(["object_id", "related_object_id", "columns", "filter"]);
@@ -51,15 +52,49 @@ function relationshipFromTf(block, owner, ctx) {
51
52
  columns.push({ field, relatedField });
52
53
  }
53
54
  const key = scopedLabelToBagKey(owner.ownerTfLabel, block.label ?? "", owner.scope);
54
- const filter = block.attrs["filter"] !== undefined
55
- ? filterFromTf(block.attrs["filter"], {
56
- type: ownerResourceType,
57
- label: owner.label,
58
- ownerRefName: owner.ownerRefName,
59
- ownerTfLabel: owner.ownerTfLabel,
60
- scope: owner.scope,
61
- }, `${where}.filter`)
62
- : undefined;
55
+ let filter;
56
+ if (block.attrs["filter"] !== undefined) {
57
+ const ownerFilterOwner = { type: ownerResourceType, label: owner.label, ownerRefName: owner.ownerRefName, ownerTfLabel: owner.ownerTfLabel, scope: owner.scope };
58
+ try {
59
+ // A relationship's filter can reference a field on its own owner
60
+ // (row-level filtering keyed off the owner's own field - the
61
+ // existing, already-tested case) - try that first so existing
62
+ // behavior is unchanged.
63
+ filter = filterFromTf(block.attrs["filter"], ownerFilterOwner, `${where}.filter`);
64
+ }
65
+ catch (ownerErr) {
66
+ // ... but it can equally reference a field on the TARGET (e.g. a
67
+ // target-scoped system-field local like `<targetTfLabel>_status_field_id`,
68
+ // restricting which of the target's records are related) (edk#650).
69
+ // Only "app"/"element" targets carry a resolvable field scope here -
70
+ // a table target has no fallback, since table columns never go
71
+ // through this `_field` resource-attr path anyway.
72
+ const targetFilterOwner = target.kind === "app" || target.kind === "element"
73
+ ? {
74
+ type: target.kind === "element" ? "elementum_element" : "elementum_app",
75
+ label: target.tfLabel ?? target.key,
76
+ ownerRefName: target.key,
77
+ ownerTfLabel: target.tfLabel ?? target.key,
78
+ scope: target.kind,
79
+ }
80
+ : undefined;
81
+ try {
82
+ if (targetFilterOwner === undefined)
83
+ throw ownerErr;
84
+ filter = filterFromTf(block.attrs["filter"], targetFilterOwner, `${where}.filter`);
85
+ }
86
+ catch (targetErr) {
87
+ // Never let one unreconstructable filter reference crash the whole
88
+ // app pull - diagnose and drop the relationship, same as the other
89
+ // unresolvable cases in this function (e.g. `related_object_id is
90
+ // not resolvable`), rather than risk silently rebuilding it with no
91
+ // filter at all.
92
+ const err = targetErr ?? ownerErr;
93
+ ctx.diagnostics.push(`${where}.filter: ${err instanceof Error ? err.message : String(err)}; skipped`);
94
+ return undefined;
95
+ }
96
+ }
97
+ }
63
98
  return { key, target, columns, ...(filter !== undefined && { filter }) };
64
99
  }
65
100
  function targetRef(value, owner, ctx) {
@@ -79,6 +114,21 @@ function targetRef(value, owner, ctx) {
79
114
  return { kind, key: tfLabelToTsLabel(resourceLabel), name: tfLabelToTsLabel(resourceLabel), tfLabel: resourceLabel, managed: true };
80
115
  const dataLabel = dataRefLabel(value, type);
81
116
  if (dataLabel !== undefined) {
117
+ if (kind === "app" || kind === "element") {
118
+ const displayName = dataAspectDisplayName(ctx, kind, dataLabel);
119
+ const refName = dataAspectRefName(ctx, kind, dataLabel, displayName);
120
+ const attrs = ctx.dataAttrs?.(type, dataLabel);
121
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
122
+ return {
123
+ kind,
124
+ key: refName ?? tfLabelToTsLabel(dataLabel),
125
+ name: displayName ?? refName ?? tfLabelToTsLabel(dataLabel),
126
+ tfLabel: dataLabel,
127
+ managed: false,
128
+ ...(namespace !== undefined ? { namespace } : {}),
129
+ ...(refName !== undefined ? { catalogRef: true } : {}),
130
+ };
131
+ }
82
132
  const name = ctx.dataName(type, dataLabel) ?? tfLabelToTsLabel(dataLabel);
83
133
  return { kind, key: tfLabelToTsLabel(dataLabel), name, tfLabel: dataLabel, managed: false };
84
134
  }
@@ -100,7 +150,39 @@ function relatedFieldRef(value, target, ctx) {
100
150
  }
101
151
  const dataLabel = dataRefLabel(value, "elementum_field");
102
152
  if (dataLabel !== undefined) {
153
+ const resolved = ctx.foreignFieldRefsByDataAddress?.get(`elementum_field.${dataLabel}`);
154
+ if (resolved !== undefined && resolved.ownerRefName === target.key) {
155
+ return {
156
+ kind: target.kind === "table" ? "tableColumn" : "field",
157
+ key: resolved.fieldKey,
158
+ name: ctx.dataName("elementum_field", dataLabel) ?? resolved.fieldName ?? resolved.fieldKey,
159
+ parent: resolved.ownerRefName,
160
+ fieldType: resolved.fieldType ?? "TEXT",
161
+ catalogRef: true,
162
+ ...(resolved.ownerKind !== undefined ? { parentKind: resolved.ownerKind } : {}),
163
+ ...(resolved.ownerName !== undefined ? { parentName: resolved.ownerName } : {}),
164
+ ...(resolved.ownerNamespace !== undefined ? { parentNamespace: resolved.ownerNamespace } : {}),
165
+ };
166
+ }
103
167
  const name = ctx.dataName("elementum_field", dataLabel) ?? tfLabelToTsLabel(dataLabel);
168
+ // The target may already be a full on-disk catalog rather than a ref-only
169
+ // dependency from this one export stream. Resolve the exported field's
170
+ // display name against that catalog before falling back to the data label;
171
+ // the latter is an exporter implementation label, not a public field key.
172
+ const catalogFieldKey = ctx.fieldNamesByOwnerRefName?.get(target.key)?.get(name.toLowerCase());
173
+ if (catalogFieldKey !== undefined) {
174
+ return {
175
+ kind: target.kind === "table" ? "tableColumn" : "field",
176
+ key: catalogFieldKey,
177
+ name,
178
+ parent: target.key,
179
+ fieldType: "TEXT",
180
+ catalogRef: true,
181
+ ...(target.kind === "app" || target.kind === "element" ? { parentKind: target.kind } : {}),
182
+ parentName: target.name,
183
+ ...(target.namespace !== undefined ? { parentNamespace: target.namespace } : {}),
184
+ };
185
+ }
104
186
  return { kind: target.kind === "table" ? "tableColumn" : "field", key: tfLabelToTsLabel(dataLabel), name, parent: target.key, fieldType: "TEXT" };
105
187
  }
106
188
  const scope = target.kind === "element" ? "element" : "app";
@@ -0,0 +1,9 @@
1
+ import type { FromTfContext } from "../../engine/pull/context.js";
2
+ /**
3
+ * Resolve a foreign app/element data lookup to its display name. Ref-only
4
+ * lookups are intentionally namespace-only, so fall back through the
5
+ * recursive pull's namespace -> refName and display-name -> refName maps.
6
+ */
7
+ export declare function dataAspectDisplayName(ctx: FromTfContext, kind: "app" | "element", label: string): string | undefined;
8
+ /** Resolve the stable pulled catalog key for the same foreign lookup. */
9
+ export declare function dataAspectRefName(ctx: FromTfContext, kind: "app" | "element", label: string, displayName?: string): string | undefined;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Resolve a foreign app/element data lookup to its display name. Ref-only
3
+ * lookups are intentionally namespace-only, so fall back through the
4
+ * recursive pull's namespace -> refName and display-name -> refName maps.
5
+ */
6
+ export function dataAspectDisplayName(ctx, kind, label) {
7
+ const type = kind === "app" ? "elementum_app" : "elementum_element";
8
+ const direct = ctx.dataName(type, label);
9
+ if (direct !== undefined)
10
+ return direct;
11
+ const attrs = ctx.dataAttrs?.(type, label);
12
+ if (typeof attrs?.name === "string")
13
+ return attrs.name;
14
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
15
+ if (namespace === undefined)
16
+ return undefined;
17
+ const refName = kind === "app"
18
+ ? ctx.foreignAppRefNamespaces?.get(namespace)
19
+ : ctx.foreignElementRefNamespaces?.get(namespace);
20
+ if (refName === undefined)
21
+ return undefined;
22
+ const names = kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames;
23
+ return [...(names?.entries() ?? [])].find(([, candidateRefName]) => candidateRefName === refName)?.[0];
24
+ }
25
+ /** Resolve the stable pulled catalog key for the same foreign lookup. */
26
+ export function dataAspectRefName(ctx, kind, label, displayName) {
27
+ const type = kind === "app" ? "elementum_app" : "elementum_element";
28
+ const attrs = ctx.dataAttrs?.(type, label);
29
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
30
+ const byNamespace = kind === "app" ? ctx.foreignAppRefNamespaces : ctx.foreignElementRefNamespaces;
31
+ if (namespace !== undefined) {
32
+ const refName = byNamespace?.get(namespace);
33
+ if (refName !== undefined)
34
+ return refName;
35
+ }
36
+ const name = displayName ?? dataAspectDisplayName(ctx, kind, label);
37
+ const byName = kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames;
38
+ return name === undefined ? undefined : byName?.get(name);
39
+ }
@@ -60,8 +60,11 @@ export interface FieldRefAst {
60
60
  readonly entityType: "app" | "element";
61
61
  /** The owner's display name — resolves a same-name local catalog entry, same convention as `AppRefAst.name`. */
62
62
  readonly name: string;
63
+ /** Stable namespace for a portable inline fieldRef owner lookup. */
64
+ readonly namespace?: string;
63
65
  /** The field's OWN display name (the `data.elementum_field` block's `name` attr), when the stream carried it — used for the raw stub's `name:` when the owner isn't locally resolvable. */
64
66
  readonly fieldName?: string;
67
+ readonly fieldType?: string;
65
68
  };
66
69
  }
67
70
  /** Reference to a fixed platform user-directory attribute. */
@@ -134,6 +137,20 @@ export interface TableRefAst {
134
137
  /** Display name from a `data.elementum_table` lookup, when the export carried it. */
135
138
  readonly name?: string;
136
139
  }
140
+ /**
141
+ * Reference to one column of an org-owned table:
142
+ * `catalog.tables.<tableHandle>.columns.<columnKey>`. Exports address a column
143
+ * by DISPLAY name (`field_ids["PK Location ID"]`), so `name` is the round-trip
144
+ * authority and `columnKey` is only the catalog bag key derived from it.
145
+ */
146
+ export interface TableColumnRefAst {
147
+ readonly kind: "tableColumn";
148
+ readonly tableHandle: string;
149
+ readonly columnKey: string;
150
+ readonly name: string;
151
+ /** Display name from a `data.elementum_table` lookup, when the export carried it. */
152
+ readonly tableName?: string;
153
+ }
137
154
  /**
138
155
  * Reference to an org-level AI provider connector, nested under its owning
139
156
  * provider (`catalog.aiProviders.<provider>.models.<model>`) — connectors
@@ -221,7 +238,7 @@ export type RefExpr =
221
238
  | {
222
239
  kind: "template";
223
240
  parts: readonly (string | RefExpr)[];
224
- } | FieldRefAst | UserFieldRefAst | AppRefAst | AgentRefAst | AutomationRefAst | DocumentModelRefAst | DocumentModelFieldRefAst | ApprovalChainRefAst | DatamineRefAst | TableRefAst | ConnectorRefAst | CloudLinkRefAst | PhoneServiceRefAst | UserRefAst | UnresolvedRefAst
241
+ } | FieldRefAst | UserFieldRefAst | AppRefAst | AgentRefAst | AutomationRefAst | DocumentModelRefAst | DocumentModelFieldRefAst | ApprovalChainRefAst | DatamineRefAst | TableRefAst | TableColumnRefAst | ConnectorRefAst | CloudLinkRefAst | PhoneServiceRefAst | UserRefAst | UnresolvedRefAst
225
242
  /** Preserved terraform local expression for round-trip (e.g. status option ids by label). */
226
243
  | {
227
244
  kind: "localRef";
@@ -62,6 +62,7 @@ export function isRefExpr(value) {
62
62
  kind === "approvalChain" ||
63
63
  kind === "datamine" ||
64
64
  kind === "table" ||
65
+ kind === "tableColumn" ||
65
66
  kind === "connector" ||
66
67
  kind === "phoneService" ||
67
68
  kind === "user" ||
@@ -84,7 +84,12 @@ export type TfFilter = Readonly<{
84
84
  export interface FilterToTfCodec {
85
85
  readonly field: (value: unknown) => TfValue;
86
86
  readonly aspect?: (value: unknown) => TfValue;
87
- readonly reference: (value: unknown) => TfValue;
87
+ /**
88
+ * `role` distinguishes filter left_value (switch-case comparisons) from
89
+ * right-hand `value`/`values` references — provider Read / ei use different
90
+ * wire forms for TASK refs in each slot (#490).
91
+ */
92
+ readonly reference: (value: unknown, role?: "left" | "value", realType?: string) => TfValue;
88
93
  readonly literal?: (value: TfValue, field: unknown | undefined, valueType: string) => TfValue;
89
94
  readonly fieldFromLeftValue?: (value: unknown) => unknown | undefined;
90
95
  }
@@ -44,7 +44,7 @@ function withLeft(filter, codec) {
44
44
  if (filter.field_id !== undefined)
45
45
  return { field_id: filter.field_id };
46
46
  if (filter.leftValue !== undefined) {
47
- const value = wireFilterValueToTf(filter.leftValue, undefined, codec);
47
+ const value = wireFilterValueToTf(filter.leftValue, undefined, codec, "left");
48
48
  if (value.type === "field" && value.field_id !== undefined)
49
49
  return { left_value: { field_id: value.field_id } };
50
50
  if (value.type === "reference" && value.value_reference !== undefined)
@@ -156,7 +156,7 @@ function filterValueToWire(value) {
156
156
  ...(value.required !== undefined && { required: value.required }),
157
157
  };
158
158
  }
159
- function wireFilterValueToTf(value, field, codec) {
159
+ function wireFilterValueToTf(value, field, codec, role = "value") {
160
160
  if (value === null || typeof value !== "object" || isTfExpr(value)) {
161
161
  throw new EntityTfError("invalid wire filter value");
162
162
  }
@@ -177,11 +177,13 @@ function wireFilterValueToTf(value, field, codec) {
177
177
  const reference = raw.value ?? raw.valueReference ?? raw.value_reference;
178
178
  if (reference === undefined)
179
179
  throw new EntityTfError("reference filter value requires value");
180
+ // ei export always writes an explicit `multiple = false` on scalar text
181
+ // references. Omitting it plans null-vs-false drift after pull.
180
182
  return {
181
183
  type,
182
- value_reference: codec.reference(reference),
184
+ value_reference: codec.reference(reference, role, String(raw.realType ?? raw.real_type ?? "TEXT")),
183
185
  real_type: String(raw.realType ?? raw.real_type ?? "TEXT").toLowerCase(),
184
- ...(typeof raw.multiple === "boolean" && { multiple: raw.multiple }),
186
+ multiple: typeof raw.multiple === "boolean" ? raw.multiple : false,
185
187
  };
186
188
  }
187
189
  if (type === "field") {
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * A tool's `field_id` value → the TARGET aspect's field bag key. Shared by
3
3
  * `agent-tool`/`skill-tool` from-tf (neither owns the other, so this lives in
4
- * the cross-entity commons rather than either module). Two shapes: a
4
+ * the cross-entity commons rather than either module). Three shapes: a
5
5
  * `resource-attr` to the field's own resource (custom fields, which have a
6
- * dedicated `elementum_<type>_field` block), or a `local.<aspect>_<key>_
6
+ * dedicated `elementum_<type>_field` block), a ref-only
7
+ * `data.elementum_field` lookup on a recursively pulled target, or a `local.<aspect>_<key>_
7
8
  * field_id` reference (system fields - title/status/closedBy/…, which have
8
9
  * no resource of their own). Same recognition `automation/from-tf.ts`'s
9
10
  * `decodeValue` already does for record-path field refs.
@@ -13,5 +14,6 @@
13
14
  * the owning app: a field on a foreign aspect is scoped under that aspect's
14
15
  * own label, not the caller's.
15
16
  */
17
+ import type { FromTfContext } from "../../engine/pull/context.js";
16
18
  import { type ChildResourceScope, type TfValue } from "../../engine/tf/index.js";
17
- export declare function resolveToolFieldKey(fieldRef: TfValue | undefined, scopeTfLabel: string, scope?: ChildResourceScope): string | undefined;
19
+ export declare function resolveToolFieldKey(fieldRef: TfValue | undefined, scopeTfLabel: string, scope?: ChildResourceScope, ctx?: Pick<FromTfContext, "dataAttrs" | "foreignFieldRefsByDataAddress">): string | undefined;
@@ -1,27 +1,22 @@
1
- /**
2
- * A tool's `field_id` value → the TARGET aspect's field bag key. Shared by
3
- * `agent-tool`/`skill-tool` from-tf (neither owns the other, so this lives in
4
- * the cross-entity commons rather than either module). Two shapes: a
5
- * `resource-attr` to the field's own resource (custom fields, which have a
6
- * dedicated `elementum_<type>_field` block), or a `local.<aspect>_<key>_
7
- * field_id` reference (system fields - title/status/closedBy/…, which have
8
- * no resource of their own). Same recognition `automation/from-tf.ts`'s
9
- * `decodeValue` already does for record-path field refs.
10
- *
11
- * `scopeTfLabel`/`scope` identify the tool's RESOLVED target aspect (self,
12
- * or a foreign app/element per `target_id` — board issue #169), not always
13
- * the owning app: a field on a foreign aspect is scoped under that aspect's
14
- * own label, not the caller's.
15
- */
16
1
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
17
2
  import { SUB_TYPE_BY_RESOURCE as FIELD_SUB_TYPE_BY_RESOURCE } from "../field/types.js";
18
- export function resolveToolFieldKey(fieldRef, scopeTfLabel, scope = "app") {
3
+ export function resolveToolFieldKey(fieldRef, scopeTfLabel, scope = "app", ctx) {
19
4
  if (fieldRef === undefined)
20
5
  return undefined;
21
6
  if (isTfExpr(fieldRef) && fieldRef.$expr === "resource-attr" && FIELD_SUB_TYPE_BY_RESOURCE.has(fieldRef.type)) {
22
7
  return scopedLabelToBagKey(scopeTfLabel, fieldRef.label, scope);
23
8
  }
24
9
  if (isTfExpr(fieldRef) && fieldRef.$expr === "data-attr" && fieldRef.type === "elementum_field") {
10
+ const fieldAttrs = ctx?.dataAttrs?.("elementum_field", fieldRef.label);
11
+ const objectId = fieldAttrs?.object_id;
12
+ const ownerType = scope === "element" ? "elementum_element" : "elementum_app";
13
+ const addressesResolvedToSameTarget = objectId !== undefined && isTfExpr(objectId) && objectId.$expr === "data-attr" &&
14
+ objectId.type === ownerType && objectId.label === scopeTfLabel && objectId.path.join(".") === "id";
15
+ if (addressesResolvedToSameTarget) {
16
+ const refOnlyField = ctx?.foreignFieldRefsByDataAddress?.get(`elementum_field.${fieldRef.label}`);
17
+ if (refOnlyField !== undefined)
18
+ return refOnlyField.fieldKey;
19
+ }
25
20
  // The reverse of `agent-tool`/`skill-tool` to-tf's
26
21
  // `foreignTargetFieldRefValue`: a CUSTOM field on the tool's target
27
22
  // aspect, resolved via a `data.elementum_field` lookup rather than a
@@ -2,6 +2,8 @@
2
2
  * Shared types used across automations, agents, and other EDK domains.
3
3
  */
4
4
  import type { AppField } from "../../../core/types/app.js";
5
+ import type { FieldRef } from "../../../catalog/types.js";
6
+ import type { UnsafePlatformId } from "../../../core/platform-id.js";
5
7
  import type { Ref, ValueOrRef } from "../ref.js";
6
8
  import type { Attachment } from "./platform.js";
7
9
  export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE";
@@ -79,14 +81,14 @@ export interface MultipartBody {
79
81
  export type ApiBody = JsonBody | FormBody | CustomBody | MultipartBody;
80
82
  export type SortDirection = "ASC" | "DESC";
81
83
  /** One sort clause (field id + direction). Use {@link asc}, {@link desc}, or {@link sortBy}. */
82
- export interface SortOrder {
83
- field: AppField;
84
+ export interface SortOrder<Field = AppField> {
85
+ field: Field;
84
86
  direction: SortDirection;
85
87
  }
86
- export declare function asc(field: AppField): SortOrder;
87
- export declare function desc(field: AppField): SortOrder;
88
+ export declare function asc<Field extends AppField | FieldRef | UnsafePlatformId>(field: Field): SortOrder<Field>;
89
+ export declare function desc<Field extends AppField | FieldRef | UnsafePlatformId>(field: Field): SortOrder<Field>;
88
90
  /** Multi-field sort (order is significant). Serializes to `Sort.orders` for Mobius. */
89
- export declare function sortBy(...orders: SortOrder[]): readonly SortOrder[];
91
+ export declare function sortBy<Field>(...orders: SortOrder<Field>[]): readonly SortOrder<Field>[];
90
92
  /**
91
93
  * Serialize an authored `SortOrder | readonly SortOrder[]` to the
92
94
  * platform's `Sort` JSON shape: `{ orders: [{ field: <id>, direction }] }`.
@@ -39,8 +39,21 @@ export interface RichText {
39
39
  readonly plainText: string;
40
40
  readonly html: string;
41
41
  }
42
- /** A selected picklist option. `MULTI_PICKLIST` fields expose an array of these. */
43
- export interface PicklistValue {
42
+ /** A selected Dropdown option. Multi-Select fields expose an array of these. */
43
+ export interface DropdownValue {
44
44
  readonly id: string;
45
45
  readonly label: string;
46
46
  }
47
+ declare const recordIdBrand: unique symbol;
48
+ /** Platform record identity (wire type ASPECT_RECORD_ID). */
49
+ export type RecordId = string & {
50
+ readonly [recordIdBrand]: "recordId";
51
+ };
52
+ /**
53
+ * A dynamically sourced Dropdown selection. It retains the normal Dropdown
54
+ * option id/label and also exposes the selected source record's identity.
55
+ */
56
+ export interface DynamicDropdownValue extends DropdownValue {
57
+ readonly recordId: RecordId;
58
+ }
59
+ export {};
@@ -10,7 +10,7 @@
10
10
  * AST-based `printSkillV2` in `print-skill.ts` — same precedent as
11
11
  * `entities/agent/deserializer/print-agent.ts` vs. `print-agent-v2.ts`.
12
12
  *
13
- * Platform ids never reach printed source.
13
+ * Unresolved field and automation platform ids print as `unsafePlatformId(...)`.
14
14
  */
15
15
  import type { NormalizedSkill } from "../from-tf.js";
16
16
  export interface PrintSkillV2Options {
@@ -10,7 +10,7 @@
10
10
  * AST-based `printSkillV2` in `print-skill.ts` — same precedent as
11
11
  * `entities/agent/deserializer/print-agent.ts` vs. `print-agent-v2.ts`.
12
12
  *
13
- * Platform ids never reach printed source.
13
+ * Unresolved field and automation platform ids print as `unsafePlatformId(...)`.
14
14
  */
15
15
  import { quote } from "../../../../pull/util.js";
16
16
  import { sdkPackageSpecifier } from "../../../internal/sdk-package.js";
@@ -50,7 +50,8 @@ export function printSkillV2(skill, opts) {
50
50
  : []),
51
51
  ]),
52
52
  ].sort();
53
- const usesUnsafePlatformId = skill.tools.some((tool) => tool.fields?.some((field) => field.rawFieldId !== undefined && !opts.foreignFieldRefsById?.has(field.rawFieldId)) === true);
53
+ const usesUnsafePlatformId = skill.tools.some((tool) => tool.automationRawId !== undefined ||
54
+ tool.fields?.some((field) => field.rawFieldId !== undefined && !opts.foreignFieldRefsById?.has(field.rawFieldId)) === true);
54
55
  const lines = [];
55
56
  lines.push("/**");
56
57
  lines.push(` * ${skill.name}`);
@@ -95,12 +96,23 @@ function fieldOwnerRef(tool, appRefName, foreignAppRefNames, foreignElementRefNa
95
96
  // exists to satisfy NormalizedSkillTool.target's now-optional type.
96
97
  if (tool.target === undefined || tool.target.kind === "self")
97
98
  return { kind: "catalog", expr: `catalog.${appRefName}` };
99
+ if (tool.target.kind === "unresolved") {
100
+ return { kind: "raw", entityType: "app", name: tool.target.uuid, refName: tool.target.uuid };
101
+ }
98
102
  const entityKind = tool.target.kind === "foreignElement" ? "element" : "app";
99
103
  const refNames = tool.target.kind === "foreignElement" ? foreignElementRefNames : foreignAppRefNames;
100
- const foreignRefName = refNames?.get(tool.target.name);
104
+ const foreignRefName = tool.target.refName ?? refNames?.get(tool.target.name);
101
105
  return foreignRefName !== undefined
102
- ? { kind: "catalog", expr: `catalog.${foreignRefName}` }
103
- : { kind: "raw", entityType: entityKind, name: tool.target.name };
106
+ ? refNames?.get(tool.target.name) !== undefined
107
+ ? { kind: "catalog", expr: `catalog.${foreignRefName}` }
108
+ : {
109
+ kind: "raw",
110
+ entityType: entityKind,
111
+ name: tool.target.name,
112
+ refName: foreignRefName,
113
+ ...(tool.target.namespace !== undefined && { namespace: tool.target.namespace }),
114
+ }
115
+ : { kind: "raw", entityType: entityKind, name: tool.target.name, refName: tool.target.name };
104
116
  }
105
117
  function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElementRefNames, foreignFieldRefsById, foreignSearchTableRefsByName) {
106
118
  const factory = TOOL_FACTORY_BY_TYPE_KEY[tool.typeKey] ?? "skillSearchRecords";
@@ -108,9 +120,9 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
108
120
  const targetRefName = tool.target?.kind === "self"
109
121
  ? appRefName
110
122
  : tool.target?.kind === "foreignElement"
111
- ? foreignElementRefNames?.get(tool.target.name)
123
+ ? tool.target.refName ?? foreignElementRefNames?.get(tool.target.name)
112
124
  : tool.target?.kind === "foreignApp"
113
- ? foreignAppRefNames?.get(tool.target.name)
125
+ ? tool.target.refName ?? foreignAppRefNames?.get(tool.target.name)
114
126
  : undefined;
115
127
  lines.push(` name: ${quote(tool.name)},`);
116
128
  lines.push(` description: ${quote(tool.description)},`);
@@ -127,7 +139,9 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
127
139
  return lines;
128
140
  }
129
141
  if (tool.typeKey === "automation") {
130
- lines.push(` automation: catalog.${appRefName}.automations${safeMember(tool.automationKey ?? "")},`);
142
+ lines.push(tool.automationRawId !== undefined
143
+ ? ` automation: unsafePlatformId(${quote(tool.automationRawId)}),`
144
+ : ` automation: catalog.${appRefName}.automations${safeMember(tool.automationKey ?? "")},`);
131
145
  const inputs = tool.inputs ?? [];
132
146
  const missingRequired = tool.missingRequiredInputs ?? [];
133
147
  if (inputs.length > 0 || missingRequired.length > 0) {
@@ -179,17 +193,24 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
179
193
  // element.)
180
194
  lines.push(` ${tool.typeKey === "searchTable" ? "element" : "app"}: catalog.${appRefName},`);
181
195
  }
196
+ else if (tool.target?.kind === "unresolved") {
197
+ // Export couldn't resolve target_id to any portable app/element
198
+ // reference (board issue #648) — keep the raw platform id visible and
199
+ // cast past the type system instead of silently dropping the tool.
200
+ const entityKind = tool.typeKey === "searchTable" ? "element" : "app";
201
+ lines.push(` ${entityKind}: ${quote(tool.target.uuid)} as any /* TODO: unresolved ${entityKind} - export couldn't resolve target_id to a portable reference; replace with a real ref before deploying */,`);
202
+ }
182
203
  else if (tool.target !== undefined) {
183
204
  // Board issue #42: the target can be a foreign APP or a foreign
184
205
  // ELEMENT — each stub carries the right `__kind` and is looked up
185
206
  // against its own map, never conflated.
186
207
  const entityKind = tool.target.kind === "foreignElement" ? "element" : "app";
187
208
  const refNames = tool.target.kind === "foreignElement" ? foreignElementRefNames : foreignAppRefNames;
188
- const foreignRefName = refNames?.get(tool.target.name);
189
- if (foreignRefName !== undefined) {
209
+ const catalogRefName = refNames?.get(tool.target.name);
210
+ if (catalogRefName !== undefined) {
190
211
  // The dependency is already pulled into this workspace (board issue
191
212
  // #40) — a typed token, not a stub.
192
- lines.push(` ${entityKind}: catalog.${foreignRefName},`);
213
+ lines.push(` ${entityKind}: catalog.${catalogRefName},`);
193
214
  }
194
215
  else {
195
216
  // The foreign app/element's catalog may not exist in this workspace —
@@ -199,7 +220,7 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
199
220
  const todo = crossOrg
200
221
  ? ` // TODO: cross-org clone — "${tool.target.name}" was resolved in the SOURCE org; verify it exists (with this name) in the destination org`
201
222
  : "";
202
- lines.push(` ${entityKind}: { __kind: ${quote(entityKind)}, refName: ${quote(tool.target.name)}, name: ${quote(tool.target.name)} },${todo}`);
223
+ lines.push(` ${entityKind}: { __kind: ${quote(entityKind)}, refName: ${quote(tool.target.refName ?? tool.target.name)}, name: ${quote(tool.target.name)}${tool.target.namespace !== undefined ? `, namespace: ${quote(tool.target.namespace)}` : ""} },${todo}`);
203
224
  }
204
225
  }
205
226
  if (tool.typeKey === "searchAspect") {
@@ -212,10 +233,18 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
212
233
  lines.push(` table: catalog.${targetRefName ?? appRefName}.searchTables${safeMember(tool.searchTableKey)},`);
213
234
  }
214
235
  else {
215
- const parent = tool.target?.kind === "self" ? appRefName : tool.target?.name ?? "";
236
+ const targetNameOrUuid = tool.target?.kind === "foreignApp" || tool.target?.kind === "foreignElement"
237
+ ? tool.target.name
238
+ : tool.target?.kind === "unresolved" ? tool.target.uuid : undefined;
239
+ const parent = tool.target?.kind === "self"
240
+ ? appRefName
241
+ : tool.target?.kind === "foreignApp" || tool.target?.kind === "foreignElement"
242
+ ? tool.target.refName ?? targetNameOrUuid ?? ""
243
+ : targetNameOrUuid ?? "";
244
+ const lookupParent = tool.target?.kind === "self" ? appRefName : targetNameOrUuid ?? "";
216
245
  const typedTable = tool.searchTableName === undefined
217
246
  ? undefined
218
- : foreignSearchTableRefsByName?.get(searchTableLookupKey(parent, tool.searchTableName));
247
+ : foreignSearchTableRefsByName?.get(searchTableLookupKey(lookupParent, tool.searchTableName));
219
248
  if (typedTable !== undefined) {
220
249
  lines.push(` table: catalog.${typedTable.ownerRefName}.searchTables${safeMember(typedTable.tableKey)},`);
221
250
  }
@@ -251,7 +280,7 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
251
280
  ? [`field: ${owner.expr}.fields.${f.key}`]
252
281
  : [
253
282
  `field: { __kind: "field", refName: ${quote(f.key)}, name: ${quote(f.name ?? f.key)}, fieldType: "TEXT", ` +
254
- `parent: ${quote(owner.name)}, parentKind: ${quote(owner.entityType)}, parentName: ${quote(owner.name)} }`,
283
+ `parent: ${quote(owner.refName)}, parentKind: ${quote(owner.entityType)}, parentName: ${quote(owner.name)}${owner.namespace !== undefined ? `, parentNamespace: ${quote(owner.namespace)}` : ""} }`,
255
284
  ];
256
285
  parts.push(`name: ${quote(f.name ?? "")}`);
257
286
  parts.push(`description: ${quote(f.description ?? "")}`);
@@ -10,6 +10,7 @@ import { optionalString, resourceRefLabel } from "../../engine/pull/context.js";
10
10
  import { scopedLabelToBagKey } from "../../engine/tf/index.js";
11
11
  import { skillToolFromTf } from "../skill-tool/from-tf.js";
12
12
  import { APP_RESOURCE_TYPE } from "../app/module.js";
13
+ import { analyzeSkillInputCoverage, skillCoverageGapDiagnostics, skillCoverageReportLines, } from "./input-coverage.js";
13
14
  import { SKILL_RESOURCE_TYPE } from "./module.js";
14
15
  /** Attributes `skillFromTf` understands — anything else is dialect growth, reported loudly. */
15
16
  const KNOWN_SKILL_ATTRS = new Set([
@@ -82,12 +83,21 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
82
83
  if (tool !== undefined)
83
84
  tools.push(tool);
84
85
  }
86
+ const instructions = optionalString(attrs, "instructions", where, ctx) ?? "";
87
+ const coverageTools = tools.map((tool) => ({
88
+ name: tool.name,
89
+ fields: (tool.fields ?? []).flatMap((field) => field.name ?? field.key ?? []),
90
+ inputs: (tool.inputs ?? []).map((input) => input.parameterName),
91
+ }));
92
+ const coverage = analyzeSkillInputCoverage(name, instructions, coverageTools);
93
+ ctx.reports?.push(...skillCoverageReportLines(coverage));
94
+ ctx.diagnostics.push(...skillCoverageGapDiagnostics(coverage));
85
95
  return {
86
96
  skill: {
87
97
  refName: scopedLabelToBagKey(appLabel, label),
88
98
  name,
89
99
  description: optionalString(attrs, "description", where, ctx) ?? "",
90
- instructions: optionalString(attrs, "instructions", where, ctx) ?? "",
100
+ instructions,
91
101
  ...((status === "ACTIVE" || status === "INACTIVE") && { status }),
92
102
  ...(properties !== undefined && { properties }),
93
103
  tools,
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Skill input-coverage analysis.
3
+ *
4
+ * The platform's current skill contract keeps the form schema and lookup
5
+ * bindings in the instructions Markdown while tool fields/inputs are
6
+ * structured resources. This module compares those two real sources instead
7
+ * of inventing a second persisted schema. The headings and list shape match
8
+ * the skill generator contract:
9
+ *
10
+ * ## Input Schema
11
+ * - field_name (required): description
12
+ *
13
+ * ## Lookup Notes
14
+ * - field_name: resolve_field_name (source_table)
15
+ */
16
+ export interface SkillCoverageTool {
17
+ readonly name: string;
18
+ readonly fields: readonly string[];
19
+ readonly inputs: readonly string[];
20
+ }
21
+ export type SkillCoverageTarget = {
22
+ readonly kind: "lookup";
23
+ readonly tool: string;
24
+ } | {
25
+ readonly kind: "field";
26
+ readonly tool: string;
27
+ readonly name: string;
28
+ } | {
29
+ readonly kind: "input";
30
+ readonly tool: string;
31
+ readonly name: string;
32
+ };
33
+ export interface SkillCoverageBinding {
34
+ readonly input: string;
35
+ readonly targets: readonly SkillCoverageTarget[];
36
+ }
37
+ export type SkillCoverageGap = {
38
+ readonly kind: "input-schema-missing";
39
+ } | {
40
+ readonly kind: "missing-field";
41
+ readonly input: string;
42
+ } | {
43
+ readonly kind: "missing-lookup-tool";
44
+ readonly input: string;
45
+ readonly tool: string;
46
+ } | {
47
+ readonly kind: "unbound-lookup";
48
+ readonly input: string;
49
+ readonly tool: string;
50
+ } | {
51
+ readonly kind: "leftover-tool";
52
+ readonly tool: string;
53
+ };
54
+ export interface SkillInputCoverageReport {
55
+ readonly skill: string;
56
+ readonly inputs: readonly string[];
57
+ readonly tools: readonly string[];
58
+ readonly bindings: readonly SkillCoverageBinding[];
59
+ readonly gaps: readonly SkillCoverageGap[];
60
+ }
61
+ /** Compare instruction-declared form variables with the deployed tool surface. */
62
+ export declare function analyzeSkillInputCoverage(skill: string, instructions: string, coverageTools: readonly SkillCoverageTool[]): SkillInputCoverageReport;
63
+ /** Informational coverage lines emitted on stderr and in JSON `reports`. */
64
+ export declare function skillCoverageReportLines(report: SkillInputCoverageReport): string[];
65
+ /** Only actionable gaps; these remain warnings and JSON `diagnostics`. */
66
+ export declare function skillCoverageGapDiagnostics(report: SkillInputCoverageReport): string[];
67
+ /** Convert a skill def() payload's closed tool envelopes to analyzer input. */
68
+ export declare function coverageToolsFromWire(entries: readonly Record<string, unknown>[]): SkillCoverageTool[];