@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
@@ -1,7 +1,7 @@
1
1
  import { dataRefLabel, optionalBoolean, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { bareChildResourceLabel, isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
3
3
  import { AUTOMATION_RESOURCE_TYPE } from "../automation/types.js";
4
- import { fieldKeyFromTfRef } from "../field/from-tf.js";
4
+ import { decodeForeignDataField, fieldKeyFromTfRef } from "../field/from-tf.js";
5
5
  import { SUB_TYPE_BY_RESOURCE } from "../field/types.js";
6
6
  import { WIDGET_RESOURCE_TYPE } from "./module.js";
7
7
  import { filterFromTf } from "../access-policy/from-tf.js";
@@ -217,13 +217,36 @@ function widgetFieldRef(value, target, owner, ctx) {
217
217
  if (targetLabel !== undefined) {
218
218
  const key = fieldKeyFromTfRef(value, targetLabel, targetScope);
219
219
  if (key !== undefined) {
220
- return { kind: "field", key, name: key, ...(typeof target !== "string" && { parent: target.key }), fieldType: "TEXT" };
220
+ // HANDLE system field (`local.<target>_id_field_id`) round-trips as
221
+ // recordIdentity(target) — same catalog token widgets author with.
222
+ if (key === "id" && typeof target !== "string" && (target.kind === "app" || target.kind === "element")) {
223
+ return { kind: "recordIdentity", key: "id", name: "Record ID", target };
224
+ }
225
+ const fieldType = isTfExpr(value) && value.$expr === "resource-attr"
226
+ ? (SUB_TYPE_BY_RESOURCE.get(value.type)?.authoringType ?? "TEXT")
227
+ : "TEXT";
228
+ return { kind: "field", key, name: key, ...(typeof target !== "string" && { parent: target.key }), fieldType };
221
229
  }
222
230
  }
223
231
  const dataLabel = dataRefLabel(value, "elementum_field");
232
+ if (dataLabel !== undefined && typeof target !== "string") {
233
+ const decoded = decodeForeignDataField(dataLabel, {
234
+ key: target.key,
235
+ name: target.name,
236
+ namespace: target.namespace,
237
+ kind: target.kind,
238
+ }, ctx);
239
+ return {
240
+ kind: "field",
241
+ key: decoded.key,
242
+ name: decoded.name,
243
+ parent: target.key,
244
+ fieldType: decoded.fieldType ?? "TEXT",
245
+ };
246
+ }
224
247
  if (dataLabel !== undefined) {
225
248
  const name = ctx.dataName("elementum_field", dataLabel) ?? tfLabelToTsLabel(dataLabel);
226
- return { kind: "field", key: tfLabelToTsLabel(dataLabel), name, ...(typeof target !== "string" && { parent: target.key }), fieldType: "TEXT" };
249
+ return { kind: "field", key: tfLabelToTsLabel(dataLabel), name, fieldType: "TEXT" };
227
250
  }
228
251
  if (isTfExpr(value) && value.$expr === "resource-attr" && value.path.length === 1 && value.path[0] === "id") {
229
252
  const identityTarget = recordIdentityTarget(value.type, target);
@@ -251,8 +274,10 @@ function automationRef(value, owner) {
251
274
  return undefined;
252
275
  return {
253
276
  kind: "automation",
254
- key: scopedLabelToBagKey(owner.ownerTfLabel, label, owner.scope),
255
- name: scopedLabelToBagKey(owner.ownerTfLabel, label, owner.scope),
277
+ // Automations keep the `apps_` prefix on elements; decoding with the
278
+ // widget owner's element scope leaves `apps…` in the bag key.
279
+ key: scopedLabelToBagKey(owner.ownerTfLabel, label, "app"),
280
+ name: scopedLabelToBagKey(owner.ownerTfLabel, label, "app"),
256
281
  parent: owner.ownerRefName,
257
282
  };
258
283
  }
@@ -1,7 +1,8 @@
1
1
  import { workspaceAspectKey } from "../../engine/build/context.js";
2
2
  import { resolveForeignRef } from "../shared/foreign-ref.js";
3
- import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
3
+ import { appScopedResourceLabel, expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
4
4
  import { AUTOMATION_RESOURCE_TYPE } from "../automation/types.js";
5
+ import { fieldMetadataFromEntries } from "../field/metadata.js";
5
6
  import { fieldRefToTfValue } from "../field/to-tf.js";
6
7
  import { WIDGET_RESOURCE_TYPE } from "./module.js";
7
8
  import { filterToTf } from "../access-policy/to-tf.js";
@@ -130,12 +131,15 @@ function resolveAspect(value, where, opts) {
130
131
  const kind = value?.__kind === "element" ? "element" : "app";
131
132
  const refName = value?.refName ?? "";
132
133
  if (kind === opts.scope && refName === opts.ownerRefName) {
133
- return { value: opts.objectId, kind, refName, tfLabel: opts.ownerTfLabel, managed: true };
134
+ return { value: opts.objectId, kind, refName, tfLabel: opts.ownerTfLabel, name: value?.name ?? refName, managed: true };
134
135
  }
135
136
  const sibling = opts.workspaceAspects?.get(workspaceAspectKey(kind, refName));
136
137
  if (sibling !== undefined) {
137
138
  const type = kind === "app" ? "elementum_app" : "elementum_element";
138
- return { value: expr.resourceAttr(type, sibling.tfLabel, ["id"]), kind, refName, tfLabel: sibling.tfLabel, managed: true };
139
+ const payloadName = typeof sibling.streamRootEntity?.payload === "object" && sibling.streamRootEntity.payload !== null
140
+ ? sibling.streamRootEntity.payload.name
141
+ : undefined;
142
+ return { value: expr.resourceAttr(type, sibling.tfLabel, ["id"]), kind, refName, tfLabel: sibling.tfLabel, name: value?.name ?? payloadName, managed: true };
139
143
  }
140
144
  const name = value?.name ?? refName;
141
145
  if (name === "") {
@@ -149,14 +153,29 @@ function resolveAspect(value, where, opts) {
149
153
  kind,
150
154
  refName,
151
155
  tfLabel: foreign.tfLabel,
156
+ name,
152
157
  managed: false,
153
158
  };
154
159
  }
160
+ /**
161
+ * listView-parity system column: managed target → `local.<tfLabel>_<key>_field_id`.
162
+ * Returns the TF value when `key` is a system field on this managed target;
163
+ * otherwise undefined (caller treats non-system strings as raw platform ids).
164
+ */
165
+ function resolveManagedSystemColumn(key, target) {
166
+ if (!target.managed || target.tfLabel === undefined || target.kind === undefined)
167
+ return undefined;
168
+ return fieldRefToTfValue("HANDLE", key, target.tfLabel, target.kind);
169
+ }
155
170
  function resolveColumns(columns, target, where, opts) {
156
171
  const out = [];
157
172
  for (const [index, value] of (columns ?? []).entries()) {
158
173
  if (typeof value === "string") {
159
- out.push(value);
174
+ // Bare system keys ("id", "title", …) resolve to the handle/title field
175
+ // id — same as listView — never the aspect resource `.id`. Other strings
176
+ // stay as raw platform field ids (extract / adopt).
177
+ const systemColumn = resolveManagedSystemColumn(value, target);
178
+ out.push(systemColumn ?? value);
160
179
  continue;
161
180
  }
162
181
  if (value != null && value.__kind === "recordIdentity") {
@@ -171,7 +190,15 @@ function resolveColumns(columns, target, where, opts) {
171
190
  opts.diagnostics.push(`${where}[${index}]: record identity target does not match widget target; dropped`);
172
191
  continue;
173
192
  }
174
- out.push(target.value);
193
+ // Platform widget columns expect field UUIDs. `recordIdentity` is the
194
+ // HANDLE system field — emit local.<target>_id_field_id like listView's
195
+ // `"id"` column, never the aspect resource `.id` (GraphQL rejects that).
196
+ const handleColumn = resolveManagedSystemColumn("id", identityTarget);
197
+ if (handleColumn === undefined) {
198
+ opts.diagnostics.push(`${where}[${index}]: record identity needs a managed app/element target so the handle field id is available; dropped`);
199
+ continue;
200
+ }
201
+ out.push(handleColumn);
175
202
  continue;
176
203
  }
177
204
  if (value == null) {
@@ -188,7 +215,8 @@ function resolveColumns(columns, target, where, opts) {
188
215
  continue;
189
216
  }
190
217
  if (target.managed && target.kind !== undefined && target.tfLabel !== undefined) {
191
- const direct = fieldRefToTfValue(value.fieldType ?? "", refName, target.tfLabel, target.kind);
218
+ const column = resolveManagedColumn(value, refName, target, opts);
219
+ const direct = fieldRefToTfValue(column.fieldType, column.refName, target.tfLabel, target.kind);
192
220
  if (direct !== undefined) {
193
221
  out.push(direct);
194
222
  continue;
@@ -256,7 +284,83 @@ function resolveAutomation(value, where, opts) {
256
284
  opts.diagnostics.push(`${where}: foreign automation references require a provider data lookup with app_id; use a raw id until that data-source tranche lands`);
257
285
  return undefined;
258
286
  }
259
- return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(refName), opts.scope), ["id"]);
287
+ // Automations always use `appScopedResourceLabel` (`apps_<owner>_…`), even
288
+ // when the owner is an element. `scopedResourceLabel(..., opts.scope)` would
289
+ // mint `elements_…` here and plan an undeclared resource.
290
+ return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, appScopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(refName)), ["id"]);
291
+ }
292
+ function resolveManagedColumn(value, refName, target, opts) {
293
+ const meta = siblingFieldMetadata(target, opts);
294
+ const recovered = recoverManagedColumnRef(refName, value, target, meta);
295
+ return {
296
+ refName: recovered,
297
+ fieldType: meta.get(recovered)?.fieldType ?? value.fieldType ?? "",
298
+ };
299
+ }
300
+ function siblingFieldMetadata(target, opts) {
301
+ const out = new Map();
302
+ if (target.kind === undefined || target.refName === undefined)
303
+ return out;
304
+ const sibling = opts.workspaceAspects?.get(workspaceAspectKey(target.kind, target.refName));
305
+ const payload = sibling?.streamRootEntity?.payload;
306
+ for (const [key, info] of fieldMetadataFromEntries(payload?.fields)) {
307
+ out.set(key, { fieldType: info.fieldType, name: info.name });
308
+ }
309
+ if (target.kind === "element") {
310
+ if (!out.has("title"))
311
+ out.set("title", { fieldType: "TEXT", name: "Title" });
312
+ if (!out.has("id"))
313
+ out.set("id", { fieldType: "HANDLE", name: "ID" });
314
+ }
315
+ return out;
316
+ }
317
+ function recoverManagedColumnRef(refName, value, target, meta) {
318
+ if (meta.has(refName))
319
+ return refName;
320
+ if (target.kind === "element" && (refName === "title" || refName === "id"))
321
+ return refName;
322
+ let tf;
323
+ try {
324
+ tf = tsLabelToTfLabel(refName);
325
+ }
326
+ catch {
327
+ return refName;
328
+ }
329
+ for (const prefix of managedColumnOwnerPrefixes(target, value)) {
330
+ if (tf.startsWith(prefix) && tf.length > prefix.length) {
331
+ const key = tfLabelToTsLabel(tf.slice(prefix.length));
332
+ if (meta.has(key) || (target.kind === "element" && (key === "title" || key === "id")))
333
+ return key;
334
+ }
335
+ }
336
+ const display = value.name;
337
+ if (display !== undefined) {
338
+ const lower = display.toLowerCase();
339
+ for (const [key, info] of meta) {
340
+ if (info.name.toLowerCase() === lower)
341
+ return key;
342
+ }
343
+ }
344
+ return refName;
345
+ }
346
+ function managedColumnOwnerPrefixes(target, _value) {
347
+ const kind = target.kind;
348
+ const ownerType = kind === "element" ? "elementum_element" : kind === "app" ? "elementum_app" : undefined;
349
+ const slugs = [
350
+ target.name !== undefined && target.name !== "" ? sanitizeName(target.name) : undefined,
351
+ target.tfLabel,
352
+ target.refName !== undefined && target.refName !== "" ? tsLabelToTfLabel(target.refName) : undefined,
353
+ target.refName !== undefined && target.refName !== "" ? sanitizeName(target.refName) : undefined,
354
+ ].filter((slug) => typeof slug === "string" && slug !== "");
355
+ const prefixes = [];
356
+ for (const slug of slugs) {
357
+ if (ownerType !== undefined)
358
+ prefixes.push(`${ownerType}_${slug}_`);
359
+ if (kind !== undefined)
360
+ prefixes.push(`${kind}_${slug}_`);
361
+ prefixes.push(`${slug}_`);
362
+ }
363
+ return [...new Set(prefixes)].sort((a, b) => b.length - a.length);
260
364
  }
261
365
  function resolveOwnerField(value, where, opts) {
262
366
  if (typeof value === "string")
@@ -329,6 +329,11 @@ export interface PrintOwnFileOptions {
329
329
  readonly ownerRefName: string;
330
330
  readonly fieldKey: string;
331
331
  }>;
332
+ /** Platform table id → canonical table catalog identity. */
333
+ readonly foreignTableRefsById?: ReadonlyMap<string, {
334
+ readonly tableRefName: string;
335
+ readonly name: string;
336
+ }>;
332
337
  /**
333
338
  * `JSON.stringify([aspect display name, search-table display name])` →
334
339
  * pulled catalog identity. Names are scoped by aspect to avoid collisions.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementumai/edk",
3
- "version": "0.9.11",
3
+ "version": "0.9.12",
4
4
  "description": "Elementum Development Kit — statically typed SDK for building Elementum apps, automations, and agents",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1,2 +0,0 @@
1
- /** Re-export — canonical home is `src/entities/shared/types/platform.ts`. */
2
- export type { Attachment, Employee, Group, Manager, DropdownValue, DynamicDropdownValue, RecordId, RichText, User, } from "../../entities/shared/types/platform.js";
@@ -1 +0,0 @@
1
- export {};