@elementumai/edk 0.9.11 → 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 (89) hide show
  1. package/README.md +39 -5
  2. package/dist-sdk/src/catalog/factories.d.ts +35 -14
  3. package/dist-sdk/src/catalog/factories.js +64 -13
  4. package/dist-sdk/src/catalog/from-authoring.js +4 -4
  5. package/dist-sdk/src/catalog/index.d.ts +1 -1
  6. package/dist-sdk/src/catalog/org.js +3 -2
  7. package/dist-sdk/src/catalog/token.js +4 -0
  8. package/dist-sdk/src/catalog/types.d.ts +13 -3
  9. package/dist-sdk/src/core/triggers/on-demand.d.ts +4 -28
  10. package/dist-sdk/src/core/triggers/on-demand.js +2 -4
  11. package/dist-sdk/src/engine/entity.d.ts +2 -0
  12. package/dist-sdk/src/engine/logging.d.ts +90 -0
  13. package/dist-sdk/src/engine/logging.js +124 -0
  14. package/dist-sdk/src/engine/progress.d.ts +119 -0
  15. package/dist-sdk/src/engine/progress.js +647 -0
  16. package/dist-sdk/src/engine/pull/result-output.d.ts +24 -0
  17. package/dist-sdk/src/engine/pull/result-output.js +48 -0
  18. package/dist-sdk/src/entities/agent/tools.d.ts +2 -2
  19. package/dist-sdk/src/entities/app/build.d.ts +8 -1
  20. package/dist-sdk/src/entities/app/from-tf.js +4 -4
  21. package/dist-sdk/src/entities/app/to-tf.js +9 -13
  22. package/dist-sdk/src/entities/automation/build.d.ts +11 -16
  23. package/dist-sdk/src/entities/automation/build.js +38 -8
  24. package/dist-sdk/src/entities/automation/catalog-render.js +1 -1
  25. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +1 -2
  26. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +23 -5
  27. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +239 -34
  28. package/dist-sdk/src/entities/automation/from-tf.js +168 -23
  29. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  30. package/dist-sdk/src/entities/automation/module.js +2 -2
  31. package/dist-sdk/src/entities/automation/output-field-types.js +25 -13
  32. package/dist-sdk/src/entities/automation/script-code.d.ts +12 -4
  33. package/dist-sdk/src/entities/automation/script-code.js +659 -101
  34. package/dist-sdk/src/entities/automation/tasks.d.ts +60 -28
  35. package/dist-sdk/src/entities/automation/tasks.js +31 -15
  36. package/dist-sdk/src/entities/automation/to-tf.js +362 -58
  37. package/dist-sdk/src/entities/automation/triggers.d.ts +15 -9
  38. package/dist-sdk/src/entities/automation/triggers.js +4 -2
  39. package/dist-sdk/src/entities/chart/build.d.ts +15 -3
  40. package/dist-sdk/src/entities/chart/build.js +6 -1
  41. package/dist-sdk/src/entities/chart/from-tf.d.ts +8 -2
  42. package/dist-sdk/src/entities/chart/from-tf.js +71 -8
  43. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  44. package/dist-sdk/src/entities/chart/index.js +1 -1
  45. package/dist-sdk/src/entities/chart/printer.js +27 -7
  46. package/dist-sdk/src/entities/chart/to-tf.js +56 -2
  47. package/dist-sdk/src/entities/datamine/from-tf.js +11 -1
  48. package/dist-sdk/src/entities/element/build.d.ts +6 -5
  49. package/dist-sdk/src/entities/element/from-tf.js +3 -2
  50. package/dist-sdk/src/entities/element/module.js +1 -0
  51. package/dist-sdk/src/entities/element/to-tf.d.ts +3 -0
  52. package/dist-sdk/src/entities/element/to-tf.js +9 -1
  53. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  54. package/dist-sdk/src/entities/field/from-tf.js +73 -1
  55. package/dist-sdk/src/entities/field/metadata.d.ts +18 -0
  56. package/dist-sdk/src/entities/field/metadata.js +34 -0
  57. package/dist-sdk/src/entities/relationship/build.d.ts +17 -6
  58. package/dist-sdk/src/entities/relationship/column-contract.d.ts +24 -0
  59. package/dist-sdk/src/entities/relationship/column-contract.js +41 -0
  60. package/dist-sdk/src/entities/relationship/from-tf.js +19 -34
  61. package/dist-sdk/src/entities/relationship/to-tf.js +15 -2
  62. package/dist-sdk/src/entities/shared/context.d.ts +6 -3
  63. package/dist-sdk/src/entities/shared/context.js +19 -1
  64. package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
  65. package/dist-sdk/src/entities/shared/filters/index.js +28 -0
  66. package/dist-sdk/src/entities/shared/filters/print.js +2 -0
  67. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +8 -1
  68. package/dist-sdk/src/entities/shared/filters/tf-codec.js +10 -6
  69. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  70. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -0
  71. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +36 -23
  72. package/dist-sdk/src/entities/skill/module.js +1 -0
  73. package/dist-sdk/src/entities/skill/to-tf.d.ts +1 -1
  74. package/dist-sdk/src/entities/skill/to-tf.js +17 -0
  75. package/dist-sdk/src/entities/skill/tools.d.ts +38 -12
  76. package/dist-sdk/src/entities/skill/tools.js +2 -1
  77. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +8 -12
  78. package/dist-sdk/src/entities/skill-tool/from-tf.js +28 -44
  79. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +4 -0
  80. package/dist-sdk/src/entities/skill-tool/to-tf.js +45 -7
  81. package/dist-sdk/src/entities/table/build.js +10 -2
  82. package/dist-sdk/src/entities/view/to-tf.js +5 -7
  83. package/dist-sdk/src/entities/widget/build.d.ts +26 -0
  84. package/dist-sdk/src/entities/widget/from-tf.js +30 -5
  85. package/dist-sdk/src/entities/widget/to-tf.js +111 -7
  86. package/dist-sdk/src/graph/types.d.ts +5 -0
  87. package/package.json +1 -1
  88. package/dist-sdk/src/core/types/platform.d.ts +0 -2
  89. package/dist-sdk/src/core/types/platform.js +0 -1
@@ -63,6 +63,9 @@ export function printSkillV2(skill, opts) {
63
63
  lines.push(" */");
64
64
  lines.push("");
65
65
  lines.push(`import { ${[...factories, "skill"].sort().join(", ")} } from ${JSON.stringify(sdkPackageSpecifier("agents/skills"))};`);
66
+ if (skill.tools.some((tool) => tool.typeKey === "searchTable" && tool.target?.kind === "tableOwned")) {
67
+ lines.push(`import { tableSearchTableRef } from ${JSON.stringify(sdkPackageSpecifier("catalog"))};`);
68
+ }
66
69
  if (usesUnsafePlatformId)
67
70
  lines.push(`import { unsafePlatformId } from ${JSON.stringify(sdkPackageSpecifier("core"))};`);
68
71
  lines.push(`import catalog from "@catalog";`);
@@ -130,6 +133,11 @@ function fieldOwnerRef(tool, appRefName, foreignAppRefNames, foreignElementRefNa
130
133
  // exists to satisfy NormalizedSkillTool.target's now-optional type.
131
134
  if (tool.target === undefined || tool.target.kind === "self")
132
135
  return { kind: "catalog", expr: `catalog.${appRefName}` };
136
+ if (tool.target.kind === "tableOwned" && tool.searchTableOwnerRefName !== undefined) {
137
+ return { kind: "table", expr: `catalog.tables${safeMember(tool.searchTableOwnerRefName)}.columns` };
138
+ }
139
+ if (tool.target.kind === "tableOwned")
140
+ return { kind: "raw", entityType: "app", name: tool.searchTableOwnerName ?? "", refName: tool.searchTableOwnerRefName ?? "" };
133
141
  if (tool.target.kind === "unresolved") {
134
142
  return { kind: "raw", entityType: "app", name: tool.target.uuid, refName: tool.target.uuid };
135
143
  }
@@ -177,18 +185,7 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
177
185
  ? ` automation: unsafePlatformId(${quote(tool.automationRawId)}),`
178
186
  : ` automation: catalog.${appRefName}.automations${safeMember(tool.automationKey ?? "")},`);
179
187
  const inputs = tool.inputs ?? [];
180
- const missingRequired = tool.missingRequiredInputs ?? [];
181
- if (inputs.length > 0 || missingRequired.length > 0) {
182
- // `missingRequiredInputs` names REQUIRED trigger parameters this tool
183
- // has no real mapping for on the platform — `AutomationToolV2` demands
184
- // every one be present, but there is no real data to print for them
185
- // (see skill-tool/from-tf.ts's doc comment: inventing an entry here
186
- // would get faithfully re-serialized to HCL by `elementum build` and
187
- // propose writing fake data onto a live tool). Print only the REAL
188
- // captured entries, verbatim, and — only when a required one is still
189
- // missing — cast the whole (possibly empty) object so the file still
190
- // compiles; the cast changes nothing about what gets built, since an
191
- // empty/absent `inputs` already round-trips to the same wire shape.
188
+ if (inputs.length > 0) {
192
189
  lines.push(" inputs: {");
193
190
  for (const input of inputs) {
194
191
  const parts = [];
@@ -200,10 +197,7 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
200
197
  parts.push(`required: ${input.required}`);
201
198
  lines.push(` ${safeKey(input.parameterName)}: { ${parts.join(", ")} },`);
202
199
  }
203
- const cast = missingRequired.length > 0
204
- ? ` as any /* TODO: automation requires input(s) for ${missingRequired.map((n) => quote(n)).join(", ")} — this tool has no mapping configured on the platform; add real inputs and remove this cast before deploying */`
205
- : "";
206
- lines.push(` }${cast},`);
200
+ lines.push(" },");
207
201
  }
208
202
  if (tool.outputs !== undefined && tool.outputs.length > 0) {
209
203
  lines.push(" outputs: {");
@@ -237,6 +231,10 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
237
231
  const entityKind = tool.typeKey === "searchTable" ? "element" : "app";
238
232
  lines.push(` ${entityKind}: unsafePlatformId(${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 */,`);
239
233
  }
234
+ else if (tool.target?.kind === "tableOwned") {
235
+ // Table-owned search tables intentionally have no target aspect in the
236
+ // platform response. Do not manufacture an empty unsafePlatformId.
237
+ }
240
238
  else if (tool.target !== undefined) {
241
239
  // Board issue #42: the target can be a foreign APP or a foreign
242
240
  // ELEMENT — each stub carries the right `__kind` and is looked up
@@ -272,17 +270,30 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
272
270
  else {
273
271
  const targetNameOrUuid = tool.target?.kind === "foreignApp" || tool.target?.kind === "foreignElement"
274
272
  ? tool.target.name
275
- : tool.target?.kind === "unresolved" ? tool.target.uuid : undefined;
273
+ : tool.target?.kind === "tableOwned"
274
+ ? tool.searchTableOwnerName
275
+ : tool.target?.kind === "unresolved" ? tool.target.uuid : undefined;
276
276
  const parent = tool.target?.kind === "self"
277
277
  ? appRefName
278
278
  : tool.target?.kind === "foreignApp" || tool.target?.kind === "foreignElement"
279
279
  ? tool.target.refName ?? targetNameOrUuid ?? ""
280
+ : tool.target?.kind === "tableOwned"
281
+ ? tool.searchTableOwnerRefName ?? targetNameOrUuid ?? ""
282
+ : targetNameOrUuid ?? "";
283
+ const lookupParent = tool.target?.kind === "self"
284
+ ? appRefName
285
+ : tool.target?.kind === "tableOwned"
286
+ ? tool.searchTableOwnerName ?? targetNameOrUuid ?? ""
280
287
  : targetNameOrUuid ?? "";
281
- const lookupParent = tool.target?.kind === "self" ? appRefName : targetNameOrUuid ?? "";
282
288
  const typedTable = tool.searchTableName === undefined
283
289
  ? undefined
284
290
  : foreignSearchTableRefsByName?.get(searchTableLookupKey(lookupParent, tool.searchTableName));
285
- if (typedTable !== undefined) {
291
+ if (tool.target?.kind === "tableOwned") {
292
+ const owner = tool.searchTableOwnerRefName ?? parent;
293
+ const ownerName = tool.searchTableOwnerName;
294
+ lines.push(` table: tableSearchTableRef({ name: ${quote(tool.searchTableName ?? "")}, parent: ${quote(owner)}${ownerName !== undefined ? `, parentName: ${quote(ownerName)}` : ""} }),`);
295
+ }
296
+ else if (typedTable !== undefined) {
286
297
  lines.push(` table: catalog.${typedTable.ownerRefName}.searchTables${safeMember(typedTable.tableKey)},`);
287
298
  }
288
299
  else {
@@ -322,10 +333,12 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
322
333
  ? [`field: catalog.${resolvedRaw.ownerRefName}.fields.${resolvedRaw.fieldKey}`]
323
334
  : owner.kind === "catalog"
324
335
  ? [`field: ${owner.expr}.fields.${f.key}`]
325
- : [
326
- `field: { __kind: "field", refName: ${quote(f.key)}, name: ${quote(f.name ?? f.key)}, fieldType: "TEXT", ` +
327
- `parent: ${quote(owner.refName)}, parentKind: ${quote(owner.entityType)}, parentName: ${quote(owner.name)}${owner.namespace !== undefined ? `, parentNamespace: ${quote(owner.namespace)}` : ""} }`,
328
- ];
336
+ : owner.kind === "table"
337
+ ? [`field: ${owner.expr}${safeMember(f.key)}`]
338
+ : [
339
+ `field: { __kind: "field", refName: ${quote(f.key)}, name: ${quote(f.name ?? f.key)}, fieldType: "TEXT", ` +
340
+ `parent: ${quote(owner.refName)}, parentKind: ${quote(owner.entityType)}, parentName: ${quote(owner.name)}${owner.namespace !== undefined ? `, parentNamespace: ${quote(owner.namespace)}` : ""} }`,
341
+ ];
329
342
  parts.push(`name: ${quote(f.name ?? "")}`);
330
343
  parts.push(`description: ${quote(f.description ?? "")}`);
331
344
  if ((tool.typeKey === "createRecord" || tool.typeKey === "updateRecord") && f.required !== undefined) {
@@ -89,6 +89,7 @@ export const skillModule = {
89
89
  ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
90
90
  ...(opts.foreignElementRefNames !== undefined && { foreignElementRefNames: opts.foreignElementRefNames }),
91
91
  ...(opts.foreignFieldRefsById !== undefined && { foreignFieldRefsById: opts.foreignFieldRefsById }),
92
+ ...(opts.foreignTableRefsById !== undefined && { foreignTableRefsById: opts.foreignTableRefsById }),
92
93
  ...(opts.foreignSearchTableRefsByName !== undefined && {
93
94
  foreignSearchTableRefsByName: opts.foreignSearchTableRefsByName,
94
95
  }),
@@ -12,7 +12,7 @@
12
12
  * `properties`, plus typed discovery/routing fields. Access policy
13
13
  * (user_ids/group_ids) is not authored yet.
14
14
  */
15
- import type { OrgRefLookup, WorkspaceAspect } from "../../engine/build/context.js";
15
+ import { type OrgRefLookup, type WorkspaceAspect } from "../../engine/build/context.js";
16
16
  import { type DeployableEntity } from "../../engine/entity.js";
17
17
  import { type TfBlock } from "../../engine/tf/index.js";
18
18
  import type { AppServiceAccount } from "../service-account/build.js";
@@ -12,6 +12,7 @@
12
12
  * `properties`, plus typed discovery/routing fields. Access policy
13
13
  * (user_ids/group_ids) is not authored yet.
14
14
  */
15
+ import { workspaceAspectKey } from "../../engine/build/context.js";
15
16
  import { EntityTfError } from "../../engine/entity.js";
16
17
  import { appScopedResourceLabel, expr, sanitizeName, tsLabelToTfLabel } from "../../engine/tf/index.js";
17
18
  import { skillToolToTf } from "../skill-tool/to-tf.js";
@@ -117,6 +118,22 @@ export function skillToTf(entity, ctx) {
117
118
  foreignFieldRef: (t, l, o, n) => ctx.orgRefs.foreignField(t, l, o, n),
118
119
  workspaceAspects: ctx.workspaceAspects,
119
120
  serviceAccountRef: (_label, serviceAccountName) => serviceAccountValue(serviceAccountName, ctx),
121
+ tableSearchTableRef: (label, tableRefName, tableName, searchTableName) => {
122
+ const tableLabel = sanitizeName(tableRefName);
123
+ const tableId = expr.dataAttr("elementum_table", tableLabel, ["id"]);
124
+ ctx.orgRefs.rawLookup("elementum_table", tableLabel, tableName);
125
+ ctx.orgRefs.rawLookup("elementum_search_table", label, searchTableName, { table_id: tableId });
126
+ return expr.dataAttr("elementum_search_table", label, ["id"]);
127
+ },
128
+ tableColumnRef: (tableRefName, tableName, columnName) => {
129
+ const sibling = ctx.workspaceAspects?.get(workspaceAspectKey("table", tableRefName));
130
+ if (sibling !== undefined) {
131
+ return expr.resourceAttr("elementum_table", sibling.tfLabel, ["field_ids", { index: columnName }]);
132
+ }
133
+ const tableLabel = sanitizeName(tableRefName);
134
+ ctx.orgRefs.rawLookup("elementum_table", tableLabel, tableName);
135
+ return expr.dataAttr("elementum_table", tableLabel, ["field_ids", { index: columnName }]);
136
+ },
120
137
  diagnostics: ctx.diagnostics,
121
138
  });
122
139
  if (tool !== undefined)
@@ -9,9 +9,9 @@
9
9
  * Search/record fields require `name` + `description` (matching the v1 skill
10
10
  * serializer, which always emits them).
11
11
  */
12
- import type { AgentRef, AppCatalogRef, AutomationCatalogRef, ElementCatalogRef, FieldRef, SearchTableRef } from "../../catalog/index.js";
12
+ import type { AgentRef, AppCatalogRef, AutomationCatalogRef, ElementCatalogRef, FieldRef, SearchTableRef, TableColumnRef, TableOwnedSearchTableRef } from "../../catalog/index.js";
13
13
  import type { UnsafePlatformId } from "../../core/platform-id.js";
14
- import type { AgentToolRunAs, RunAutomationOptionalInput, RunAutomationOutput, RunAutomationToolV2 } from "../agent/tools.js";
14
+ import type { AgentToolRunAs, OutputBagOf, RunAutomationOptionalInput, RunAutomationOutput, RunAutomationOutputs, TriggerBagOf } from "../agent/tools.js";
15
15
  declare const skillToolBrand: unique symbol;
16
16
  /** A closed factory result; arbitrary records cannot be added to a skill's tool list. */
17
17
  export type SkillTool = Record<string, unknown> & {
@@ -47,6 +47,13 @@ export interface SkillSearchRawIdField {
47
47
  readonly description: string;
48
48
  }
49
49
  export type SkillSearchFieldInput<Target extends ToolTarget = ToolTarget> = SkillSearchField<Target> | SkillSearchRawIdField;
50
+ /** A table-owned search field is a table column, not an aspect field. */
51
+ export interface SkillTableSearchField {
52
+ readonly field: TableColumnRef;
53
+ readonly name: string;
54
+ readonly description: string;
55
+ }
56
+ export type SkillTableSearchFieldInput = SkillTableSearchField | SkillSearchRawIdField;
50
57
  /** A runtime value supplied by the agent for a search filter variable. */
51
58
  export interface SkillFilterVariable {
52
59
  /** Stable platform identifier referenced by the filter JSON. */
@@ -78,13 +85,23 @@ interface CommonToolOptions {
78
85
  readonly startMessage?: string;
79
86
  readonly runAs?: AgentToolRunAs;
80
87
  }
81
- export type AutomationToolV2<A extends AutomationCatalogRef = AutomationCatalogRef> = RunAutomationToolV2<A> & {
88
+ export type SkillAutomationInputs<T> = [keyof T] extends [never] ? {
89
+ readonly [key: string]: never;
90
+ } : {
91
+ readonly [K in keyof T]?: RunAutomationOptionalInput;
92
+ };
93
+ export type AutomationToolV2<A extends AutomationCatalogRef = AutomationCatalogRef> = CommonToolOptions & {
94
+ readonly automation: A;
82
95
  readonly status?: SkillToolStatus;
96
+ readonly inputs?: SkillAutomationInputs<TriggerBagOf<A>>;
97
+ readonly outputs?: RunAutomationOutputs<OutputBagOf<A>>;
83
98
  };
84
99
  /**
85
- * Run an on-demand automation with input/output record keys constrained by
86
- * the selected automation's generated catalog type. Required trigger params
87
- * must be mapped and output keys autocomplete, matching agentRunAutomation.
100
+ * Run an on-demand automation as a skill tool.
101
+ *
102
+ * Unlike agent tools, skill tools on the platform derive execution parameters
103
+ * directly from the on-demand trigger at runtime and do not require tool-level
104
+ * input bindings. Input and output mappings remain optional.
88
105
  *
89
106
  * When ei exported a bare `automation_id` UUID (no in-stream automation
90
107
  * resource), pass `unsafePlatformId(...)` so rebuild keeps that tool.
@@ -104,19 +121,28 @@ export type SkillSearchRecordsToolOptions<Target extends ToolTarget = ToolTarget
104
121
  readonly filterVariables?: readonly SkillFilterVariable[];
105
122
  };
106
123
  export declare function skillSearchRecords<Target extends ToolTarget>(opts: SkillSearchRecordsToolOptions<Target>): SkillTool;
107
- /**
108
- * A search-table tool targets the ELEMENT that owns the search table — never an
109
- * app. See `search-table/build.ts`'s `SearchTableOwner`: an app's backing
110
- * Snowflake table is hybrid, which Cortex cannot index.
111
- */
124
+ /** A search-table tool over an element-owned index targets its owning ELEMENT. */
112
125
  export type SkillSearchTableToolV2<Target extends ElementCatalogRef = ElementCatalogRef> = CommonToolOptions & TargetOption<Target> & {
113
- readonly table: SearchTableRef;
126
+ readonly table: SearchTableRef & {
127
+ readonly __variant?: "snowflake" | "linked";
128
+ };
114
129
  readonly queryDescription: string;
115
130
  readonly fields: readonly SkillSearchFieldInput<Target>[];
116
131
  /** Maximum number of records the search returns. */
117
132
  readonly limit?: number;
118
133
  readonly filterVariables?: readonly SkillFilterVariable[];
119
134
  };
135
+ /** A table-owned search-table tool has no target aspect on the platform wire. */
136
+ export type SkillTableOwnedSearchTableToolV2 = CommonToolOptions & {
137
+ readonly app?: never;
138
+ readonly element?: never;
139
+ readonly table: TableOwnedSearchTableRef;
140
+ readonly queryDescription: string;
141
+ readonly fields: readonly SkillTableSearchFieldInput[];
142
+ readonly limit?: number;
143
+ readonly filterVariables?: readonly SkillFilterVariable[];
144
+ };
145
+ export declare function skillSearchTable(opts: SkillTableOwnedSearchTableToolV2): SkillTool;
120
146
  export declare function skillSearchTable<Target extends ElementCatalogRef>(opts: SkillSearchTableToolV2<Target>): SkillTool;
121
147
  export type SkillCreateRecordToolV2<Target extends ToolTarget = ToolTarget> = CommonToolOptions & TargetOption<Target> & {
122
148
  readonly fields?: readonly SkillRecordFieldInput<Target>[];
@@ -108,10 +108,11 @@ export function skillSearchRecords(opts) {
108
108
  });
109
109
  }
110
110
  export function skillSearchTable(opts) {
111
+ const target = "app" in opts && opts.app !== undefined ? opts.app : "element" in opts && opts.element !== undefined ? opts.element : undefined;
111
112
  return tool({
112
113
  searchTable: {
113
114
  ...common(opts),
114
- aspectId: targetOf(opts),
115
+ ...(target !== undefined ? { aspectId: target } : {}),
115
116
  searchTableId: opts.table,
116
117
  queryDescription: opts.queryDescription,
117
118
  fields: opts.fields.map(searchFieldToken),
@@ -30,6 +30,10 @@ export interface NormalizedFilterVariable {
30
30
  }
31
31
  export type NormalizedSkillToolTarget = {
32
32
  readonly kind: "self";
33
+ }
34
+ /** Table-owned search tables have no target aspect on the platform wire. */
35
+ | {
36
+ readonly kind: "tableOwned";
33
37
  } | {
34
38
  /** A foreign app via `data.elementum_app.<label>` — `name` from the stream's data block. */
35
39
  readonly kind: "foreignApp";
@@ -77,6 +81,10 @@ export interface NormalizedSkillTool {
77
81
  readonly searchTableKey?: string;
78
82
  /** Foreign table lookup name when search_table_id is data.elementum_search_table. */
79
83
  readonly searchTableName?: string;
84
+ /** Display name of the owning organization table for a table-owned search table. */
85
+ readonly searchTableOwnerName?: string;
86
+ /** Canonical catalog refName of the owning organization table, when known. */
87
+ readonly searchTableOwnerRefName?: string;
80
88
  readonly inputs?: readonly {
81
89
  readonly parameterName: string;
82
90
  readonly displayName?: string;
@@ -89,18 +97,6 @@ export interface NormalizedSkillTool {
89
97
  readonly description?: string;
90
98
  }[];
91
99
  readonly runAs?: AgentToolRunAs;
92
- /**
93
- * Names of the target automation's REQUIRED onDemand trigger parameters
94
- * that this tool's own `inputs` (above) has no mapping for — the platform
95
- * doesn't enforce that binding at tool-creation time, so a live tool can
96
- * genuinely have none (edk#483: a Deloitte "sentiment-analysis" skill hit
97
- * this). `AutomationToolV2` requires every such parameter to be mapped, so
98
- * the printer needs this to know a type-only escape hatch is required —
99
- * but the escape hatch must NOT be confused with authored data: unlike
100
- * `inputs`, this is never fed into `skillToTf`/round-tripped to HCL. See
101
- * `printTool`'s handling of `typeKey === "automation"`.
102
- */
103
- readonly missingRequiredInputs?: readonly string[];
104
100
  }
105
101
  export interface SkillToolOwner {
106
102
  /** The owning app's resource type + tfLabel. */
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { EntityTfError } from "../../engine/entity.js";
8
8
  import { dataRefLabel, optionalString, resourceRefLabel } from "../../engine/pull/context.js";
9
- import { isTfExpr, scopedLabelToBagKey } from "../../engine/tf/index.js";
9
+ import { isTfExpr, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
10
10
  import { dataAspectDisplayName, dataAspectRefName } from "../shared/aspect-target-from-tf.js";
11
11
  import { resolveToolFieldKey } from "../shared/tool-field-ref.js";
12
12
  import { KNOWN_SKILL_TOOL_ATTRS, SKILL_TOOL_SUB_TYPE_BY_RESOURCE, UNAUTHORABLE_SKILL_TOOL_ATTRS, } from "./types.js";
@@ -148,47 +148,6 @@ export function skillToolFromTf(block, owner, ctx) {
148
148
  ...(typeof rec["required"] === "boolean" && { required: rec["required"] }),
149
149
  });
150
150
  }
151
- // The tool's own `inputs` attribute can be genuinely absent even when the
152
- // target automation's onDemand trigger declares required parameters —
153
- // the platform doesn't enforce that binding at tool-creation time (a
154
- // live Deloitte "sentiment-analysis" skill hit this: a `run_automation`
155
- // tool with zero `inputs` targeting an automation whose trigger requires
156
- // one). `AutomationToolV2` (entities/agent/tools.ts) requires every such
157
- // parameter to be mapped, so printing nothing here would emit a
158
- // `skillAutomation({...})` call that can't compile (edk#483). This must
159
- // NOT be "fixed" by inventing an `inputs` entry that isn't really on the
160
- // platform — `elementum build` re-serializes whatever `inputs` prints
161
- // straight back to HCL, so a fabricated entry becomes a genuine plan
162
- // diff proposing to write fake data onto a live tool (caught live: a
163
- // rebuilt `run_automation` tool proposed adding an `inputs` block with a
164
- // literal "TODO: ..." description). Only RECORD which required
165
- // parameters are unmapped; `printTool` (print-skill-v2.ts) decides how
166
- // to keep the generated file compiling without asserting any of this as
167
- // real authored data.
168
- const mappedParams = new Set(inputs.map((i) => i.parameterName));
169
- // Found by following the trigger's OWN `automation` reference (mirrors
170
- // `automationFromTfDocument`'s `references(block.attrs.automation, ...)`
171
- // in entities/automation/from-tf.ts) rather than guessing that the
172
- // trigger shares its automation's Terraform label — that label equality
173
- // holds by observed export convention, not by contract, and a silent
174
- // miss here would reproduce the exact tsc-failing call this fix is for,
175
- // with no diagnostic to explain why.
176
- const trigger = automationLabel === undefined
177
- ? undefined
178
- : ctx.resourcesOfType?.("elementum_on_demand_trigger").find((block) => {
179
- const ref = block.attrs["automation"];
180
- return isTfExpr(ref) && ref.$expr === "resource-attr" && ref.type === "elementum_automation" && ref.label === automationLabel;
181
- });
182
- const missingRequiredInputs = [];
183
- for (const item of Array.isArray(trigger?.attrs["parameters"]) ? trigger.attrs["parameters"] : []) {
184
- if (typeof item !== "object" || item === null || Array.isArray(item) || isTfExpr(item))
185
- continue;
186
- const rec = item;
187
- if (rec["required"] !== true || typeof rec["name"] !== "string" || mappedParams.has(rec["name"]))
188
- continue;
189
- ctx.diagnostics.push(`${where}: target automation's onDemand trigger requires "${rec["name"]}", but this tool has no input mapping for it — printed source will need a human-authored inputs entry before this tool can be adopted`);
190
- missingRequiredInputs.push(rec["name"]);
191
- }
192
151
  const outputs = [];
193
152
  for (const item of Array.isArray(attrs["outputs"]) ? attrs["outputs"] : []) {
194
153
  if (typeof item !== "object" || item === null || Array.isArray(item) || isTfExpr(item))
@@ -212,11 +171,13 @@ export function skillToolFromTf(block, owner, ctx) {
212
171
  : { automationKey: scopedLabelToBagKey(owner.ownerTfLabel, automationLabel) }),
213
172
  ...(inputs.length > 0 && { inputs }),
214
173
  ...(outputs.length > 0 && { outputs }),
215
- ...(missingRequiredInputs.length > 0 && { missingRequiredInputs }),
216
174
  };
217
175
  }
218
176
  let searchTableKey;
219
177
  let searchTableName;
178
+ let tableOwnedSearchTable = false;
179
+ let searchTableOwnerName;
180
+ let searchTableOwnerRefName;
220
181
  if (subType.typeKey === "searchTable") {
221
182
  const value = attrs["search_table_id"];
222
183
  const resourceTypes = ["elementum_ai_search_table", "elementum_linked_ai_search_table", "elementum_table_search_table"];
@@ -224,6 +185,7 @@ export function skillToolFromTf(block, owner, ctx) {
224
185
  .map((type) => ({ type, label: resourceRefLabel(value, type) }))
225
186
  .find((candidate) => candidate.label !== undefined);
226
187
  if (matched?.label !== undefined) {
188
+ tableOwnedSearchTable = matched.type === "elementum_table_search_table";
227
189
  // A managed or linked search table is owned by an ELEMENT, so its label
228
190
  // carries the `elements_<ns>_` prefix — decoding it with app scope leaves
229
191
  // the prefix in place and camel-cases the whole label into a bag key that
@@ -235,6 +197,17 @@ export function skillToolFromTf(block, owner, ctx) {
235
197
  }
236
198
  else if (isTfExpr(value) && value.$expr === "data-attr" && value.type === "elementum_search_table") {
237
199
  searchTableName = ctx.dataName(value.type, value.label);
200
+ // The generic search-table data source is used for both aspect-owned and
201
+ // table-owned tables. The presence of table_id is the only portable
202
+ // discriminator available in the HCL stream.
203
+ tableOwnedSearchTable = ctx.dataAttrs?.(value.type, value.label)?.["table_id"] !== undefined;
204
+ const tableLabel = dataRefLabel(ctx.dataAttrs?.(value.type, value.label)?.["table_id"], "elementum_table");
205
+ if (tableLabel !== undefined) {
206
+ searchTableOwnerName = ctx.dataName("elementum_table", tableLabel);
207
+ if (searchTableOwnerName !== undefined) {
208
+ searchTableOwnerRefName = [...(ctx.foreignTableRefsById?.values() ?? [])].find((identity) => identity.name === searchTableOwnerName)?.tableRefName ?? tfLabelToTsLabel(sanitizeName(searchTableOwnerName));
209
+ }
210
+ }
238
211
  if (searchTableName === undefined) {
239
212
  ctx.diagnostics.push(`${where}: search_table_id references data.${value.type}.${value.label} without a matching name lookup; skipped`);
240
213
  return undefined;
@@ -256,7 +229,16 @@ export function skillToolFromTf(block, owner, ctx) {
256
229
  let fieldScopeLabel = owner.ownerTfLabel;
257
230
  let fieldScope = "app";
258
231
  const selfLabel = resourceRefLabel(targetAttr, owner.appType);
259
- if (selfLabel === owner.appLabel) {
232
+ if (subType.typeKey === "searchTable" && targetAttr === "") {
233
+ if (tableOwnedSearchTable) {
234
+ target = { kind: "tableOwned" };
235
+ }
236
+ else {
237
+ ctx.diagnostics.push(`${where}: empty target_id is only valid for a table-owned search table; skipped`);
238
+ return undefined;
239
+ }
240
+ }
241
+ else if (selfLabel === owner.appLabel) {
260
242
  target = { kind: "self" };
261
243
  }
262
244
  else if (isTfExpr(targetAttr) && targetAttr.$expr === "data-attr" && targetAttr.type === "elementum_app") {
@@ -391,6 +373,8 @@ export function skillToolFromTf(block, owner, ctx) {
391
373
  }),
392
374
  ...(searchTableKey !== undefined && { searchTableKey }),
393
375
  ...(searchTableName !== undefined && { searchTableName }),
376
+ ...(searchTableOwnerName !== undefined && { searchTableOwnerName }),
377
+ ...(searchTableOwnerRefName !== undefined && { searchTableOwnerRefName }),
394
378
  ...(typeof attrs["result_limit"] === "number" && { limit: attrs["result_limit"] }),
395
379
  ...(handleDescription !== undefined && { handleDescription }),
396
380
  };
@@ -32,6 +32,10 @@ export interface SkillToolToTfContext {
32
32
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
33
33
  /** Records an app-scoped service-account lookup by name. */
34
34
  serviceAccountRef?(tfLabel: string, name: string): TfValue | void;
35
+ /** Records a table-owned search-table data lookup for a pulled public ref. */
36
+ tableSearchTableRef?(tfLabel: string, tableRefName: string, tableName: string, searchTableName: string): TfValue | void;
37
+ /** Resolves a table-column token for a table-owned search tool. */
38
+ tableColumnRef?(tableRefName: string, tableName: string, columnName: string): TfValue | void;
35
39
  /** App-local automations whose publish resource will be emitted in this build. */
36
40
  readonly activeAutomationRefNames?: ReadonlySet<string>;
37
41
  /** Degradations land here — reported by the caller, never silent. */
@@ -238,24 +238,56 @@ export function skillToolToTf(entry, ctx) {
238
238
  const block = { kind: "resource", type: subType.resourceType, label: tfLabel, attrs };
239
239
  return { block, address: `${subType.resourceType}.${tfLabel}` };
240
240
  }
241
- if (inner.aspectId === undefined) {
241
+ if (inner.aspectId === undefined && typeKey !== "searchTable") {
242
242
  ctx.diagnostics.push(`${where}: no target aspect token; dropped`);
243
243
  return undefined;
244
244
  }
245
- const target = targetIdValue(inner.aspectId, ctx);
246
- attrs["target_id"] = target.value;
245
+ const aspectId = inner.aspectId;
246
+ const target = aspectId === undefined ? undefined : targetIdValue(aspectId, ctx);
247
+ if (target !== undefined)
248
+ attrs["target_id"] = target.value;
249
+ else
250
+ attrs["target_id"] = "";
247
251
  if (typeKey === "searchTable") {
248
252
  const table = inner.searchTableId;
249
253
  if (table?.refName === undefined || table.refName === "") {
250
254
  ctx.diagnostics.push(`${where}: no search table token; dropped`);
251
255
  return undefined;
252
256
  }
253
- if (table.parent !== undefined && table.parent !== "" && table.parent !== target.refName) {
257
+ if (target !== undefined && table.parent !== undefined && table.parent !== "" && table.parent !== target.refName) {
254
258
  ctx.diagnostics.push(`${where}: search table belongs to "${table.parent}", not target "${target.refName}"; dropped`);
255
259
  return undefined;
256
260
  }
257
- if (target.localTfLabel === undefined) {
258
- const targetName = inner.aspectId.name ?? inner.aspectId.refName ?? table.parent;
261
+ if (target === undefined) {
262
+ if (table.__variant !== "table") {
263
+ ctx.diagnostics.push(`${where}: missing target aspect is only valid for a table-owned search table; dropped`);
264
+ return undefined;
265
+ }
266
+ const workspaceTable = table.parent === undefined
267
+ ? undefined
268
+ : ctx.workspaceAspects?.get(workspaceAspectKey("table", table.parent));
269
+ if (workspaceTable !== undefined) {
270
+ attrs["search_table_id"] = expr.resourceAttr("elementum_table_search_table", `tables_${workspaceTable.tfLabel}_${tsLabelToTfLabel(table.refName)}`, ["id"]);
271
+ }
272
+ else if (ctx.tableSearchTableRef !== undefined && table.parent !== undefined && table.parent !== "") {
273
+ const lookup = ctx.tableSearchTableRef(`${sanitizeName(table.parent)}_${sanitizeName(table.name ?? table.refName)}`, table.parent, table.parentName ?? table.parent, table.name ?? table.refName);
274
+ if (lookup !== undefined)
275
+ attrs["search_table_id"] = lookup;
276
+ else {
277
+ ctx.diagnostics.push(`${where}: table-owned search table lookup could not be materialized; dropped`);
278
+ return undefined;
279
+ }
280
+ }
281
+ else if (table.__unsafe === "platformId" && typeof table.value === "string" && table.value !== "") {
282
+ attrs["search_table_id"] = table.value;
283
+ }
284
+ else {
285
+ ctx.diagnostics.push(`${where}: table-owned search table has no portable lookup; dropped`);
286
+ return undefined;
287
+ }
288
+ }
289
+ else if (target.localTfLabel === undefined) {
290
+ const targetName = aspectId?.name ?? aspectId?.refName ?? table.parent;
259
291
  const lookupLabel = sanitizeName(`${targetName}_${table.name ?? table.refName}`);
260
292
  ctx.foreignFieldRef("elementum_search_table", lookupLabel, target.value, table.name ?? table.refName);
261
293
  attrs["search_table_id"] = expr.dataAttr("elementum_search_table", lookupLabel, ["id"]);
@@ -295,7 +327,13 @@ export function skillToolToTf(entry, ctx) {
295
327
  ? f.fieldId
296
328
  : f.fieldId === undefined
297
329
  ? undefined
298
- : fieldRefValue(f.fieldId, where, ctx, target);
330
+ : target === undefined && f.fieldId.__unsafe === "platformId" && typeof f.fieldId.value === "string"
331
+ ? f.fieldId.value
332
+ : target === undefined && f.fieldId.__kind === "tableColumn" && ctx.tableColumnRef !== undefined
333
+ ? ctx.tableColumnRef(f.fieldId.parent ?? "", f.fieldId.parentName ?? f.fieldId.parent ?? "", f.fieldId.name ?? f.fieldId.refName ?? "")
334
+ : target === undefined
335
+ ? undefined
336
+ : fieldRefValue(f.fieldId, where, ctx, target);
299
337
  if (ref === undefined)
300
338
  continue;
301
339
  fieldValues.push({
@@ -80,18 +80,26 @@ export function table(opts) {
80
80
  return {
81
81
  ...initial,
82
82
  ref(refName) {
83
+ const parentName = opts.name ?? opts.handle ?? refName;
84
+ const columnNames = Object.fromEntries(Object.entries(opts.columns ?? {}).map(([colKey, col]) => [colKey, col.name ?? colKey]));
83
85
  const columns = Object.fromEntries(Object.entries(opts.columns ?? {}).map(([key, column]) => [key, {
84
86
  __kind: "tableColumn",
85
87
  refName: key,
86
88
  parent: refName,
89
+ parentName,
87
90
  name: column.name,
88
91
  ...(column.kind === "cloud" ? { fieldType: "snowflake" in column.cloud ? column.cloud.snowflake.type : column.cloud.bigQuery.type } : {}),
89
92
  ...(column.tags !== undefined ? { tags: column.tags } : {}),
90
93
  }]));
91
94
  const datamines = Object.fromEntries(Object.entries(opts.datamines ?? {}).map(([key, datamine]) => [key, {
92
- __kind: "datamine", refName: key, parent: refName, name: datamine.name,
95
+ __kind: "datamine",
96
+ refName: key,
97
+ parent: refName,
98
+ parentName,
99
+ name: datamine.name,
100
+ columnNames,
93
101
  }]));
94
- return { __kind: "table", refName, name: opts.name ?? opts.handle ?? refName, columns, datamines };
102
+ return { __kind: "table", refName, name: parentName, columns, datamines };
95
103
  },
96
104
  def(refName) {
97
105
  return entityFor(opts, refName);
@@ -270,13 +270,11 @@ function layoutToTf(stageKey, layout, ownerRefName, ownerTfLabel, scope, objectI
270
270
  display_location: section.displayLocation ?? "CENTER",
271
271
  display_order: section.displayOrder ?? 0,
272
272
  };
273
- // Mirrors ei's exporter (hcl_app.go): true is the platform default and is
274
- // NEVER emitted; only an explicit false is written. Always emitting a
275
- // value here (like the other three) would force `false` on every section
276
- // whose sideNavItem was never captured (i.e. is really `true`), planning
277
- // a spurious change on every build.
278
- if (section.sideNavItem === false)
279
- sec.side_nav_item = false;
273
+ // Always emit side_nav_item (match hcl_app.go export). Omitting the true
274
+ // platform default inside a RequiresReplace sections list plans
275
+ // known→unknown and forces cannot_update replaces (Cloud Builder intake).
276
+ // Authored omit means true — same default discovery uses for nil API values.
277
+ sec.side_nav_item = section.sideNavItem ?? true;
280
278
  if (wireType === GROUP_SECTION_WIRE_TYPE) {
281
279
  sec.name = section.name ?? "";
282
280
  if (section.icon !== undefined)
@@ -11,17 +11,43 @@ export interface WidgetButtonStyle {
11
11
  /**
12
12
  * Lists matching records from `target` on this object's record page.
13
13
  *
14
+ * Shipped authoring fields today: `type`, `name`, `target`, `columns`, `rows`.
14
15
  * The widget only names the target and display columns. The platform finds
15
16
  * rows through an authored `relationships[]` join on **this** app/element
16
17
  * whose columns join comparable stored values (TEXT→TEXT, or this object's
17
18
  * `relationField` → related title/id). Do not join system `"id"` (HANDLE)
18
19
  * to a child `relationField`. A child `relationField` / dynamic dropdown
19
20
  * with `autoRelate` stores an instance link; it does not populate this widget.
21
+ * Prefer TEXT, PICKLIST, and similar short scalars as display columns;
22
+ * RICH_TEXT / longtext cells often render blank inline and force click-in.
23
+ * Authored `columns` seed the Everyone Display Settings table-state default.
24
+ * Show/Hide Columns (ColumnOrder) and Just Me are not an EDK surface.
25
+ *
26
+ * TRACKING — planned App knobs, **NOT YET SUPPORTED**. They are documented
27
+ * here so authors see the desired surface at this type. They are **not**
28
+ * live optional props (that would silently no-op on build/apply).
29
+ *
30
+ * - `removeLabel?: string` — rename the unlink/Remove row-menu action
31
+ * (e.g. `"Unlink"`). Today Remove only unlinks the related row.
32
+ * - `allowDelete?: boolean` — optional related-row **true delete** of the
33
+ * related record (not just unlink). Today Delete lives on the related
34
+ * record's own detail ⋮ menu, not this widget.
35
+ *
36
+ * Blocked on platform GraphQL `DisplayWidgetRelatedAspect` plus its
37
+ * create/update inputs, which currently expose only
38
+ * `aspect` / `columns` / `filter` / `name` / `rows` / `sort`. Stay draft
39
+ * until those fields land and EDK can bind them through HCL
40
+ * (pull → plan → apply).
20
41
  */
21
42
  export interface RelatedRecordsWidget<Target extends AppOrElementRef = AppOrElementRef> {
22
43
  readonly type: "relatedRecords";
23
44
  readonly name: string;
24
45
  readonly target: Target;
46
+ /**
47
+ * Display columns for the record-page table. Create/update also seeds the
48
+ * organization (Everyone) Display Settings table-state default. Show/Hide
49
+ * Columns (ColumnOrder) and Just Me preferences are not authored here.
50
+ */
25
51
  readonly columns?: readonly (FieldRef | RecordIdentityRef<Target>)[];
26
52
  readonly rows?: number;
27
53
  }