@elementumai/edk 0.8.1 → 0.8.2-alpha.6

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 (74) hide show
  1. package/README.md +166 -34
  2. package/dist-sdk/src/catalog/factories.js +18 -2
  3. package/dist-sdk/src/catalog/from-authoring.js +13 -1
  4. package/dist-sdk/src/catalog/org.js +51 -44
  5. package/dist-sdk/src/catalog/token.js +4 -0
  6. package/dist-sdk/src/catalog/types.d.ts +15 -0
  7. package/dist-sdk/src/core/types/app.d.ts +14 -8
  8. package/dist-sdk/src/engine/build/context.d.ts +40 -0
  9. package/dist-sdk/src/engine/build/context.js +11 -1
  10. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  11. package/dist-sdk/src/engine/tf/index.js +2 -2
  12. package/dist-sdk/src/engine/tf/labels.d.ts +29 -20
  13. package/dist-sdk/src/engine/tf/labels.js +32 -28
  14. package/dist-sdk/src/engine/tf/parse.d.ts +15 -0
  15. package/dist-sdk/src/engine/tf/parse.js +162 -0
  16. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +19 -1
  17. package/dist-sdk/src/entities/access-policy/from-tf.js +4 -6
  18. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +12 -5
  19. package/dist-sdk/src/entities/access-policy/to-tf.js +21 -6
  20. package/dist-sdk/src/entities/agent/build.d.ts +2 -0
  21. package/dist-sdk/src/entities/agent/build.js +1 -0
  22. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +60 -2
  23. package/dist-sdk/src/entities/agent/from-tf.d.ts +12 -7
  24. package/dist-sdk/src/entities/agent/from-tf.js +22 -15
  25. package/dist-sdk/src/entities/agent/module.js +7 -3
  26. package/dist-sdk/src/entities/agent/to-tf.d.ts +46 -1
  27. package/dist-sdk/src/entities/agent/to-tf.js +102 -8
  28. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.d.ts +17 -0
  29. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.js +64 -0
  30. package/dist-sdk/src/entities/agent-a2a-skill/module.d.ts +4 -0
  31. package/dist-sdk/src/entities/agent-a2a-skill/module.js +14 -0
  32. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.d.ts +40 -0
  33. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.js +47 -0
  34. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +7 -2
  35. package/dist-sdk/src/entities/agent-tool/to-tf.js +86 -26
  36. package/dist-sdk/src/entities/app/build.d.ts +35 -7
  37. package/dist-sdk/src/entities/app/build.js +19 -8
  38. package/dist-sdk/src/entities/app/from-tf.js +0 -7
  39. package/dist-sdk/src/entities/app/module.js +1 -0
  40. package/dist-sdk/src/entities/app/to-tf.js +13 -1
  41. package/dist-sdk/src/entities/automation/build.js +14 -6
  42. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +27 -4
  43. package/dist-sdk/src/entities/automation/filter.d.ts +22 -0
  44. package/dist-sdk/src/entities/automation/filter.js +42 -1
  45. package/dist-sdk/src/entities/automation/from-tf.js +127 -11
  46. package/dist-sdk/src/entities/automation/to-tf.js +176 -18
  47. package/dist-sdk/src/entities/element/build.d.ts +26 -8
  48. package/dist-sdk/src/entities/element/build.js +44 -3
  49. package/dist-sdk/src/entities/element/from-tf.js +10 -11
  50. package/dist-sdk/src/entities/element/module.js +1 -0
  51. package/dist-sdk/src/entities/element/to-tf.js +5 -0
  52. package/dist-sdk/src/entities/field/build.d.ts +9 -5
  53. package/dist-sdk/src/entities/field/calc/runtime.js +2 -2
  54. package/dist-sdk/src/entities/field/from-tf.js +10 -10
  55. package/dist-sdk/src/entities/field/to-tf.d.ts +35 -18
  56. package/dist-sdk/src/entities/field/to-tf.js +110 -6
  57. package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -0
  58. package/dist-sdk/src/entities/shared/tool-field-ref.js +15 -0
  59. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +97 -8
  60. package/dist-sdk/src/entities/skill/module.js +1 -0
  61. package/dist-sdk/src/entities/skill/to-tf.d.ts +26 -0
  62. package/dist-sdk/src/entities/skill/to-tf.js +63 -3
  63. package/dist-sdk/src/entities/skill/tools.d.ts +12 -5
  64. package/dist-sdk/src/entities/skill/tools.js +26 -1
  65. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +19 -2
  66. package/dist-sdk/src/entities/skill-tool/from-tf.js +97 -8
  67. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +11 -1
  68. package/dist-sdk/src/entities/skill-tool/to-tf.js +143 -27
  69. package/dist-sdk/src/entities/skill-tool/types.d.ts +5 -7
  70. package/dist-sdk/src/entities/skill-tool/types.js +47 -11
  71. package/dist-sdk/src/entities/view/to-tf.js +6 -0
  72. package/dist-sdk/src/graph/modules.js +2 -0
  73. package/dist-sdk/src/graph/types.d.ts +22 -2
  74. package/package.json +12 -7
@@ -10,21 +10,98 @@
10
10
  * - cross-app target → a name-keyed `data.elementum_app` lookup whose
11
11
  * label derives from the app NAME (ei's sanitize rule);
12
12
  * - tool fields → the field resource's ref (`elementum_*_field.<label>.id`),
13
- * derivable purely from the FieldRef token (fieldType + refName).
13
+ * derivable purely from the FieldRef token (fieldType + refName); a field
14
+ * owned by a DIFFERENT app/element resolves via a `data.elementum_field`
15
+ * lookup instead (`parentKind`/`parentName` on the token — see
16
+ * `FieldRef`'s doc comment in `src/catalog/types.ts`).
14
17
  */
15
18
  import { appScopedResourceLabel, expr, sanitizeName, tsLabelToTfLabel } from "../../engine/tf/index.js";
16
19
  import { EntityTfError } from "../../engine/entity.js";
17
20
  import { fieldRefToTfValue } from "../field/to-tf.js";
18
21
  import { TOOL_SUB_TYPE_BY_TYPE_KEY } from "./types.js";
19
- /** authoring FieldRef token → the field resource address, derived purely from the token. */
20
- function fieldRefValue(token, where, ctx) {
22
+ /** authoring AspectRef token → its resolved target (self resource ref or foreign data ref). */
23
+ function resolveTarget(token, ctx) {
24
+ const refName = token.refName ?? "";
25
+ const kind = token.__kind === "element" ? "element" : "app";
26
+ if (kind === "app" && refName === ctx.appRefName) {
27
+ return { value: expr.resourceAttr("elementum_app", ctx.appTfLabel, ["id"]), refName, kind, isSelf: true };
28
+ }
29
+ // ei derives foreign-app/foreign-element data labels from the display NAME.
30
+ const name = token.name ?? refName;
31
+ const tfLabel = sanitizeName(name);
32
+ // Board issue #42: an aspect token can be an element, not just an app —
33
+ // must emit `data.elementum_element`, never `data.elementum_app`, or the
34
+ // provider looks up the wrong resource type entirely.
35
+ if (kind === "element") {
36
+ ctx.foreignElementRef(tfLabel, name);
37
+ return { value: expr.dataAttr("elementum_element", tfLabel, ["id"]), refName, kind, isSelf: false, foreignTfLabel: tfLabel };
38
+ }
39
+ ctx.foreignAppRef(tfLabel, name);
40
+ return { value: expr.dataAttr("elementum_app", tfLabel, ["id"]), refName, kind, isSelf: false, foreignTfLabel: tfLabel };
41
+ }
42
+ /**
43
+ * A field belonging to the tool's target aspect, when that target is
44
+ * foreign to the tool's owning app — resolved via a `data.elementum_field`
45
+ * lookup keyed by the TARGET's already-resolved id (never re-derived from
46
+ * the field token's own `parentKind`/`parentName`, which would let a field
47
+ * from some unrelated third aspect silently pair with this target's id;
48
+ * see `resolveFieldForTarget`) + the field's display name. Same pattern as
49
+ * `automation/to-tf.ts`'s `crossAppFieldToTf` and `field/to-tf.ts`'s
50
+ * `resolveRelatedLabelField`.
51
+ */
52
+ function foreignTargetFieldRefValue(token, refName, target, ctx) {
53
+ const fieldName = token.name ?? refName;
54
+ const fieldLabel = `${target.kind}_${target.foreignTfLabel}_${tsLabelToTfLabel(refName)}`;
55
+ ctx.foreignFieldRef("elementum_field", fieldLabel, target.value, fieldName);
56
+ return expr.dataAttr("elementum_field", fieldLabel, ["id"]);
57
+ }
58
+ /**
59
+ * authoring FieldRef token → the field resource address, resolved against
60
+ * the tool's ACTUAL target aspect (`resolveTarget`'s result) — not just the
61
+ * tool's owning app. A tool's fields are attributes of the record it
62
+ * creates/searches/updates, so a field whose `parent` doesn't match the
63
+ * target (by refName AND kind — an app and a foreign element can share a
64
+ * refName) is an authoring error the platform would otherwise reject
65
+ * opaquely at apply ("field is not valid on target aspect"); `target`
66
+ * absent (defensive: only possible for `searchTable`'s optional-aspect
67
+ * shape, which doesn't use this field path) falls back to the tool's own
68
+ * app as before.
69
+ */
70
+ function fieldRefValue(token, where, ctx, target) {
21
71
  const refName = token.refName ?? "";
22
72
  if (refName === "") {
23
73
  ctx.diagnostics.push(`${where}: field token has no refName; dropped`);
24
74
  return undefined;
25
75
  }
26
- if (token.parent !== undefined && token.parent !== ctx.appRefName) {
27
- ctx.diagnostics.push(`${where}: field token "${refName}" belongs to app "${token.parent}", not this workspace's config — cross-app field refs are not supported on the terraform path yet; dropped`);
76
+ if (target !== undefined) {
77
+ // `parentKind` is stamped ALONGSIDE a FOREIGN `parent` by `appCatalog`/
78
+ // `elementCatalog` (see `FieldRef`'s doc comment) — but a field's own
79
+ // `.ref()` on ITS OWN app/element stamps `parent` (as a self-reference)
80
+ // without `parentKind` at all (a real, common shape — see e.g.
81
+ // `__tests__/extract/update-record-tool.test.ts`'s fixture literals), so
82
+ // only a parent naming something OTHER than the tool's owning app is
83
+ // genuinely ambiguous. Defaulting `parentKind` to "app" THERE instead of
84
+ // failing loudly is the same silent-miss failure mode
85
+ // `automation/to-tf.ts`'s `crossAppFieldToTf` guards against: an element
86
+ // field with a missing kind stamp would validate (and later resolve) as
87
+ // if it belonged to an app of the same refName.
88
+ if (token.parent !== undefined && token.parent !== ctx.appRefName && token.parentKind === undefined) {
89
+ ctx.diagnostics.push(`${where}: field "${refName}" has a parent ("${token.parent}") but no parentKind — incomplete foreign-field provenance; dropped`);
90
+ return undefined;
91
+ }
92
+ const parent = token.parent ?? ctx.appRefName;
93
+ const parentKind = token.parentKind ?? "app";
94
+ if (parent !== target.refName || parentKind !== target.kind) {
95
+ ctx.diagnostics.push(`${where}: field "${refName}" belongs to ${parentKind} "${parent}", not the tool's target ${target.kind} "${target.refName}" — a tool's fields must belong to its own target aspect; dropped`);
96
+ return undefined;
97
+ }
98
+ if (!target.isSelf)
99
+ return foreignTargetFieldRefValue(token, refName, target, ctx);
100
+ // Falls through to the same-app resource-address resolution below —
101
+ // `target.isSelf` already proved this target IS ctx.appTfLabel.
102
+ }
103
+ else if (token.parent !== undefined && (token.parent !== ctx.appRefName || token.parentKind === "element")) {
104
+ ctx.diagnostics.push(`${where}: field "${refName}" belongs to "${token.parent}", not this tool's app; dropped`);
28
105
  return undefined;
29
106
  }
30
107
  // Delegates to field/to-tf.ts's shared resolver (system-field local alias
@@ -37,24 +114,6 @@ function fieldRefValue(token, where, ctx) {
37
114
  }
38
115
  return value;
39
116
  }
40
- /** authoring AspectRef token → target_id value (self resource ref or foreign data ref). */
41
- function targetIdValue(token, ctx) {
42
- if (token.__kind !== "element" && (token.refName ?? "") === ctx.appRefName) {
43
- return expr.resourceAttr("elementum_app", ctx.appTfLabel, ["id"]);
44
- }
45
- // ei derives foreign-app/foreign-element data labels from the display NAME.
46
- const name = token.name ?? token.refName ?? "";
47
- const tfLabel = sanitizeName(name);
48
- // Board issue #42: an aspect token can be an element, not just an app —
49
- // must emit `data.elementum_element`, never `data.elementum_app`, or the
50
- // provider looks up the wrong resource type entirely.
51
- if (token.__kind === "element") {
52
- ctx.foreignElementRef(tfLabel, name);
53
- return expr.dataAttr("elementum_element", tfLabel, ["id"]);
54
- }
55
- ctx.foreignAppRef(tfLabel, name);
56
- return expr.dataAttr("elementum_app", tfLabel, ["id"]);
57
- }
58
117
  /**
59
118
  * One authored tool entry (`{ createRecord: {...} }`) → its resource block;
60
119
  * undefined = degraded with a diagnostic (unimplemented sub-type, missing
@@ -147,8 +206,9 @@ export function toolToTf(entry, ctx) {
147
206
  ctx.diagnostics.push(`${where}: no target aspect token; dropped`);
148
207
  return undefined;
149
208
  }
150
- if (inner.aspectId !== undefined)
151
- attrs["target_id"] = targetIdValue(inner.aspectId, ctx);
209
+ const target = inner.aspectId !== undefined ? resolveTarget(inner.aspectId, ctx) : undefined;
210
+ if (target !== undefined)
211
+ attrs["target_id"] = target.value;
152
212
  if (typeKey === "updateRecord") {
153
213
  if (inner.handleDescription === undefined || inner.handleDescription === "") {
154
214
  // The provider requires a non-empty handle_description and rejects an
@@ -187,7 +247,7 @@ export function toolToTf(entry, ctx) {
187
247
  ? f.fieldId
188
248
  : f.fieldId === undefined
189
249
  ? undefined
190
- : fieldRefValue(f.fieldId, where, ctx);
250
+ : fieldRefValue(f.fieldId, where, ctx, target);
191
251
  if (ref === undefined)
192
252
  continue;
193
253
  fieldValues.push({
@@ -98,13 +98,19 @@ export interface AppField {
98
98
  */
99
99
  readonly expression?: Expr<ExprType>;
100
100
  /**
101
- * `RELATION` only — raw platform ids of the related aspect/field
102
- * (`elementum_relation_field.related_object_id`/`related_label_field_id`),
103
- * not catalog tokens: a non-recursive export never discovers the related
104
- * aspect's own identity, so there's nothing to resolve them against.
101
+ * `RELATION` only — the related object/field
102
+ * (`elementum_relation_field.related_object_id`/`related_label_field_id`).
103
+ * Accepts a catalog token (`AspectRef`/`FieldRef`) or a raw platform id. A
104
+ * token naming a SIBLING app/element authored in the same build resolves
105
+ * to a direct resource reference and does NOT need to already exist on
106
+ * the platform; only a token naming something genuinely outside this
107
+ * workspace needs that. Pulling a RELATION field back always yields raw
108
+ * ids: a non-recursive export never discovers the related object's own
109
+ * identity, so there's nothing to resolve a token against on the extract
110
+ * side.
105
111
  */
106
- readonly relatedAspectId?: string;
107
- readonly relatedLabelFieldId?: string;
112
+ readonly relatedObject?: AspectRef | string;
113
+ readonly relatedLabelField?: FieldRef | string;
108
114
  /** `RELATION` only. Defaults to `true` on the platform. */
109
115
  readonly autoRelate?: boolean;
110
116
  }
@@ -253,6 +259,8 @@ export interface AppV2Options<F extends Record<string, AppField> = Record<string
253
259
  readonly cloudLink?: CloudLinkRef;
254
260
  /** Cloud-backing options (Snowflake-only); applied on create only. */
255
261
  readonly cloudOptions?: AppCloudOptions;
262
+ /** Enables the record-view comments panel. Platform default is `false`. */
263
+ readonly commentsEnabled?: boolean;
256
264
  /** Fields keyed by ref name. At least one required by the compose API. */
257
265
  readonly fields: F;
258
266
  /**
@@ -284,7 +292,11 @@ export interface AppV2Options<F extends Record<string, AppField> = Record<string
284
292
  readonly listViews?: Readonly<Record<string, AppListView>>;
285
293
  /** Display order of `listViews` (by key). Defaults to declaration order. */
286
294
  readonly viewOrder?: readonly string[];
287
- /** App-level sharing & row-level-security policies (`elementum_access_policy`), in declaration order. */
295
+ /**
296
+ * App-level sharing & row-level-security policies (`elementum_access_policy`), in declaration order.
297
+ * Creating the app also has the platform mint a separate creator policy
298
+ * (the creating user, typically `whereTrue`) that is not authored here.
299
+ */
288
300
  readonly accessPolicies?: readonly AccessPolicyOptions[];
289
301
  }
290
302
  /**
@@ -365,4 +377,20 @@ export interface AppConfigured<F extends Record<string, AppField> = Record<strin
365
377
  ref(refName: string): AppRef<F, R>;
366
378
  def(refName: string): DeployableEntity;
367
379
  }
380
+ /**
381
+ * Build a v2 app entity: org-owned, compose-body payload. Exposes
382
+ * `.ref(refName)` and `.def(refName)`.
383
+ *
384
+ * Elements author through `defineElement` (`@elementumai/edk/elements`,
385
+ * `src/elements/build.ts`) instead — a dedicated builder/printer, since a
386
+ * *linked* element's cloud mapping (Cloud Link + Database + Schema + Table,
387
+ * vs. a *standard* element's Elementum-managed table) has no equivalent on an
388
+ * app. `defineApp`'s `type` no longer accepts `"ELEMENT"`.
389
+ */
390
+ /**
391
+ * The GraphQL API constrains an aspect handle to letters only, either case, no
392
+ * digits (ultron aspects schema: `handle: String @NotEmpty @Pattern(regexp:
393
+ * "[a-zA-Z]*")`). Mirror that rule here rather than inventing a stricter one.
394
+ */
395
+ export declare const APP_HANDLE_RE: RegExp;
368
396
  export declare function defineApp<F extends Record<string, AppField>, R extends Record<string, FieldRef> = Record<never, never>>(opts: AppV2Options<F, R>): AppConfigured<F, R>;
@@ -171,10 +171,10 @@ export function serializeField(field, refName) {
171
171
  base.format = field.qrFormat;
172
172
  }
173
173
  if (key === "relation") {
174
- if (field.relatedAspectId !== undefined)
175
- base.relatedAspectId = field.relatedAspectId;
176
- if (field.relatedLabelFieldId !== undefined)
177
- base.relatedLabelFieldId = field.relatedLabelFieldId;
174
+ if (field.relatedObject !== undefined)
175
+ base.relatedObject = field.relatedObject;
176
+ if (field.relatedLabelField !== undefined)
177
+ base.relatedLabelField = field.relatedLabelField;
178
178
  if (field.autoRelate !== undefined)
179
179
  base.autoRelate = field.autoRelate;
180
180
  }
@@ -246,18 +246,24 @@ export function serializeSystemFields(overrides) {
246
246
  * vs. a *standard* element's Elementum-managed table) has no equivalent on an
247
247
  * app. `defineApp`'s `type` no longer accepts `"ELEMENT"`.
248
248
  */
249
+ /**
250
+ * The GraphQL API constrains an aspect handle to letters only, either case, no
251
+ * digits (ultron aspects schema: `handle: String @NotEmpty @Pattern(regexp:
252
+ * "[a-zA-Z]*")`). Mirror that rule here rather than inventing a stricter one.
253
+ */
254
+ export const APP_HANDLE_RE = /^[a-zA-Z]+$/;
249
255
  /**
250
256
  * Client-side validation for `defineApp` — the authoring-time home for app
251
257
  * validation rules, so a malformed definition fails at define time rather than
252
258
  * as an opaque platform error during apply. App-specific on purpose: elements
253
259
  * carry their own equivalent in `src/elements/build.ts`.
254
260
  *
255
- * - `handle` — uppercase letters only (A–Z), when provided (it's optional)
261
+ * - `handle` — letters only (a–z, A–Z), when provided (it's optional)
256
262
  * - `namespace` — lowercase letters only (a–z), when provided
257
263
  */
258
264
  function validateAppOptions(opts) {
259
- if (opts.handle !== undefined && !/^[A-Z]+$/.test(opts.handle)) {
260
- throw new Error(`defineApp "${opts.name}": handle "${opts.handle}" must be uppercase letters only (A–Z).`);
265
+ if (opts.handle !== undefined && !APP_HANDLE_RE.test(opts.handle)) {
266
+ throw new Error(`defineApp "${opts.name}": handle "${opts.handle}" must contain only letters (a–z, A–Z).`);
261
267
  }
262
268
  if (opts.namespace !== undefined && !/^[a-z]+$/.test(opts.namespace)) {
263
269
  throw new Error(`defineApp "${opts.name}": namespace "${opts.namespace}" must be lowercase letters only (a–z).`);
@@ -296,6 +302,8 @@ export function defineApp(opts) {
296
302
  refName: bagKey,
297
303
  name: field.name,
298
304
  parent: refName,
305
+ parentKind: kind,
306
+ parentName: opts.name,
299
307
  fieldType: field.type,
300
308
  ...(field.options !== undefined ? { options: picklistOptionLabels(field.options) } : {}),
301
309
  ...(field.tags !== undefined ? { tags: field.tags } : {}),
@@ -316,6 +324,8 @@ export function defineApp(opts) {
316
324
  refName: key,
317
325
  name: override?.name ?? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[key],
318
326
  parent: refName,
327
+ parentKind: kind,
328
+ parentName: opts.name,
319
329
  fieldType: SYSTEM_FIELD_TAG_TO_TYPE[tag],
320
330
  tags: [tag],
321
331
  ...(override !== undefined && "options" in override ? { options: picklistOptionLabels(override.options) } : {}),
@@ -325,7 +335,7 @@ export function defineApp(opts) {
325
335
  // so other entities can reference them by typed handle, but excluded from `def()` payload.
326
336
  if (opts.readonlyFields !== undefined) {
327
337
  for (const [bagKey, ref] of Object.entries(opts.readonlyFields)) {
328
- fields[bagKey] = { ...ref, refName: bagKey, parent: refName };
338
+ fields[bagKey] = { ...ref, refName: bagKey, parent: refName, parentKind: kind, parentName: opts.name };
329
339
  }
330
340
  }
331
341
  // `fields` is built loosely (`Record<string, FieldRef>`) since the loop
@@ -349,6 +359,7 @@ export function defineApp(opts) {
349
359
  ...(opts.color !== undefined ? { color: opts.color } : {}),
350
360
  ...(opts.cloudLink !== undefined ? { cloudLinkId: opts.cloudLink } : {}), // token → id at deploy
351
361
  ...(opts.cloudOptions !== undefined ? { cloudOptions: opts.cloudOptions } : {}),
362
+ ...(opts.commentsEnabled !== undefined ? { commentsEnabled: opts.commentsEnabled } : {}),
352
363
  fields: [
353
364
  ...serializeSystemFields(opts.systemFields),
354
365
  ...Object.entries(opts.fields).map(([bagKey, field]) => serializeField(field, bagKey)),
@@ -59,14 +59,7 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
59
59
  const titleFieldDescription = optionalString(attrs, "title_field_description", `app "${label}"`, ctx);
60
60
  const idFieldDescription = optionalString(attrs, "id_field_description", `app "${label}"`, ctx);
61
61
  const statusFieldDescription = optionalString(attrs, "status_field_description", `app "${label}"`, ctx);
62
- // Captured on the normalized shape (same as the wire normalize) but not yet
63
- // authorable — defineApp has no slot and build won't re-emit it.
64
- // Platform default is false. Only loud-warn when true — a rebuilt stream
65
- // would drop a real enablement (no authoring slot yet).
66
62
  const commentsEnabled = typeof attrs["comments_enabled"] === "boolean" ? attrs["comments_enabled"] : undefined;
67
- if (commentsEnabled === true) {
68
- ctx.diagnostics.push(`app "${label}": comments_enabled has no authoring slot yet; a rebuilt stream will omit it`);
69
- }
70
63
  // --- Org data references (category / cloud link).
71
64
  let category;
72
65
  if (attrs["category_id"] !== undefined) {
@@ -47,6 +47,7 @@ export const appModule = {
47
47
  appTfLabel: ctx.appTfLabel,
48
48
  orgRefs: ctx.orgRefs,
49
49
  diagnostics: ctx.diagnostics,
50
+ workspaceAspects: ctx.workspaceAspects,
50
51
  });
51
52
  return {
52
53
  blocks: result.blocks,
@@ -68,6 +68,8 @@ export function appToTf(entity, ctx) {
68
68
  appAttrs["icon"] = payload.icon;
69
69
  if (payload.color !== undefined)
70
70
  appAttrs["color"] = payload.color;
71
+ if (payload.commentsEnabled !== undefined)
72
+ appAttrs["comments_enabled"] = payload.commentsEnabled;
71
73
  const categoryName = payload.category?.name;
72
74
  if (categoryName !== undefined && categoryName !== "") {
73
75
  const category = ctx.orgRefs.byName(CATEGORY_ORG_BAG, categoryName);
@@ -177,7 +179,14 @@ export function appToTf(entity, ctx) {
177
179
  continue;
178
180
  }
179
181
  // Custom field → one `elementum_*_field` resource (entities/field).
180
- const field = fieldToTf(typeKey, inner, { ownerTfLabel: ctx.appTfLabel, objectId, diagnostics: ctx.diagnostics, orgRefs: ctx.orgRefs });
182
+ const field = fieldToTf(typeKey, inner, {
183
+ ownerTfLabel: ctx.appTfLabel,
184
+ appRefName: ctx.appRefName,
185
+ objectId,
186
+ diagnostics: ctx.diagnostics,
187
+ orgRefs: ctx.orgRefs,
188
+ workspaceAspects: ctx.workspaceAspects,
189
+ });
181
190
  if (field === undefined)
182
191
  continue;
183
192
  blocks.push(field.block);
@@ -197,6 +206,9 @@ export function appToTf(entity, ctx) {
197
206
  });
198
207
  blocks.push(...viewBlocks);
199
208
  // --- Access policy pass (entities/access-policy), owner passed in.
209
+ // Authored entries only. Creating an app also has the platform mint a
210
+ // creator policy (userIds = [you]) that is NOT in this payload — pull
211
+ // will see it; we never emit it here.
200
212
  for (const [index, entry] of (payload.accessPolicies ?? []).entries()) {
201
213
  const { block } = accessPolicyToTf(entry, index, {
202
214
  ownerTfLabel: ctx.appTfLabel,
@@ -132,18 +132,23 @@ const RECORD_BEARING_TASK_KEYS = new Set(["recordSearch", "createRecord", "findR
132
132
  * Forward output-name rewrites, the inverse of the deserializer's read-side
133
133
  * normalization (`applyOutputNameInverseRewrites` in
134
134
  * `materialize/ref-deserializer.ts` — keep the two in sync):
135
- * - recordSearch: `totalCount` → the platform's `count`.
135
+ * - recordSearch: `totalCount` → the platform's `Records Size`.
136
136
  * - aiAgent: `result` / `result.<field>` → the platform's
137
137
  * `ai_agent_task_response` (text) / `ai_agent_task_structured_output.<field>` (json).
138
138
  * - record-bearing tasks: the read path reinjects a `.record` hop on the id
139
- * accessor (wire `recordId` → source `record.recordId`); collapse it back to
140
- * the platform's flat `recordId` on write.
139
+ * accessor; collapse it back to the platform's flat wire key on write
140
+ * (recordSearch: `First found record id`; createRecord/findRelatedRecords:
141
+ * `Record` — confirmed live via `ei refs` against a real createRecord/
142
+ * findRelatedRecords task: neither exposes a `recordId` key at all;
143
+ * `Record` (type ASPECT_RECORD_ID) is the one that does, matching the
144
+ * provider's own schema docs for `relate_to_record_reference`
145
+ * ("From create task: `elementum_create_record_task.my_task.refs["Record"]`")).
141
146
  * - single-scalar-output tasks (see `OUTPUT_KEY_WIRE_NAME`): `output` →
142
147
  * the platform's actual output name for that task kind.
143
148
  */
144
149
  function rewriteForwardTaskRefName(taskKey, name) {
145
150
  if (taskKey === "recordSearch" && name === "totalCount") {
146
- return "count";
151
+ return "Records Size";
147
152
  }
148
153
  if (taskKey === "aiAgent") {
149
154
  const segs = name.split(".");
@@ -153,8 +158,11 @@ function rewriteForwardTaskRefName(taskKey, name) {
153
158
  return "ai_agent_task_response";
154
159
  return ["ai_agent_task_structured_output", ...segs.slice(1).map((s) => s.toLowerCase())].join(".");
155
160
  }
156
- if (taskKey && RECORD_BEARING_TASK_KEYS.has(taskKey) && name === "record.recordId") {
157
- return "recordId";
161
+ if (taskKey === "recordSearch" && name === "record.recordId") {
162
+ return "First found record id";
163
+ }
164
+ if (taskKey && RECORD_BEARING_TASK_KEYS.has(taskKey) && taskKey !== "recordSearch" && name === "record.recordId") {
165
+ return "Record";
158
166
  }
159
167
  const wireOutputKey = taskKey ? OUTPUT_KEY_WIRE_NAME[taskKey] : undefined;
160
168
  if (wireOutputKey) {
@@ -33,6 +33,7 @@
33
33
  import { camelCase } from "../../../../pull/util.js";
34
34
  import { sdkPackageSpecifier } from "../../../internal/sdk-package.js";
35
35
  import { isRefExpr } from "../../shared/filters/ast.js";
36
+ import { UNRESOLVED_REFERENCE_MARKER } from "../filter.js";
36
37
  // ---------------------------------------------------------------------------
37
38
  // Factory name mapping — v1 AST `factory` → v2 factory function name.
38
39
  //
@@ -840,8 +841,20 @@ function printRef(ref, state, refCtx) {
840
841
  // Pure-string multi-part: plain literal concatenation is safe.
841
842
  return parts.join(" + ");
842
843
  }
843
- case "field":
844
- return `catalog.${ref.appHandle}.fields${safeMember(ref.fieldKey)}`;
844
+ case "field": {
845
+ if (ref.foreign === undefined)
846
+ return `catalog.${ref.appHandle}.fields${safeMember(ref.fieldKey)}`;
847
+ // Same treatment as the "app" case just below: a foreign field already
848
+ // pulled into this workspace (board issue #40, app-only) resolves to a
849
+ // typed token; otherwise a literal stub (field type is unconfirmed —
850
+ // ei's `elementum_field` data source doesn't expose it).
851
+ const foreignRefName = ref.foreign.entityType === "app" ? state.foreignAppRefNames?.get(ref.foreign.name) : undefined;
852
+ if (foreignRefName !== undefined)
853
+ return `catalog.${foreignRefName}.fields${safeMember(ref.fieldKey)}`;
854
+ return (`{ __kind: "field", refName: ${quote(ref.fieldKey)}, name: ${quote(ref.foreign.fieldName ?? ref.fieldKey)}, fieldType: "TEXT", ` +
855
+ `parent: ${quote(ref.appHandle)}, parentKind: ${quote(ref.foreign.entityType)}, parentName: ${quote(ref.foreign.name)} } ` +
856
+ `// TODO: foreign field — type unconfirmed (ei's elementum_field data source doesn't expose it) and refName is a best-effort guess; verify against "${ref.foreign.name}"`);
857
+ }
845
858
  case "userField":
846
859
  return `catalog.users.fields${safeMember(ref.fieldKey)}`;
847
860
  case "app": {
@@ -1000,13 +1013,23 @@ function printFilter(f, state) {
1000
1013
  */
1001
1014
  function printFilterField(left, state) {
1002
1015
  if (left.kind === "field") {
1003
- return `catalog.${left.appHandle}.fields${safeMember(left.fieldKey)}`;
1016
+ return printRef(left, state, DEFAULT_CTX);
1004
1017
  }
1005
1018
  if (left.kind === "userField") {
1006
1019
  return `catalog.users.fields${safeMember(left.fieldKey)}`;
1007
1020
  }
1008
1021
  if (left.kind === "unresolved") {
1009
- return `${quote(left.uuid)} as any /* TODO: unresolved field */`;
1022
+ // A field placeholder (hint === "field") legitimately round-trips
1023
+ // through the field_id wire slot on rebuild (filter.ts's leftDescriptor).
1024
+ // Anything else stood in for a left_value/REFERENCE position that isn't
1025
+ // a field at all (e.g. a workflow-variable reference) - mark it so
1026
+ // leftDescriptor routes it through the left_value/REFERENCE slot
1027
+ // instead, reproducing the original raw reference string verbatim
1028
+ // rather than corrupting it into a field_id (#290).
1029
+ if (left.hint === "field") {
1030
+ return `${quote(left.uuid)} as any /* TODO: unresolved field */`;
1031
+ }
1032
+ return `${quote(`${UNRESOLVED_REFERENCE_MARKER}${left.uuid}`)} as any /* TODO: unresolved ${left.hint} - re-express with a typed ref when possible */`;
1010
1033
  }
1011
1034
  return printRef(left, state, DEFAULT_CTX);
1012
1035
  }
@@ -49,6 +49,28 @@ export type FilterValue = Primitive | Ref<unknown> | FieldRef | UserFieldRef | C
49
49
  export declare function currentUser(type?: "id" | "email" | "domain"): CurrentUserFilterValue;
50
50
  /** Either side of a filter: a catalog field token, or a task/trigger/… output ref. */
51
51
  export type LeftRef = FieldRef | UserFieldRef | Ref<unknown>;
52
+ /**
53
+ * Marker prefix a pulled filter's left side carries when the pull-time
54
+ * deserializer couldn't decode its `left_value`/REFERENCE shape to a typed
55
+ * ref (e.g. a `variable.<uuid>` reference to a not-yet-authorable workflow
56
+ * variable — see `from-tf.ts`'s `decodeReferenceString`). Distinct from an
57
+ * unresolved FIELD placeholder (a bare uuid, no prefix), which legitimately
58
+ * round-trips through the `{ field }`/`field_id` wire slot below — a
59
+ * left_value/REFERENCE position never does, so silently routing it through
60
+ * `{ field }` would rebuild a structurally different filter than the one
61
+ * `ei` exported. `leftDescriptor` routes this marker through the SAME
62
+ * `leftValue`/REFERENCE wire slot instead, reproducing the original raw
63
+ * `value_reference` string verbatim (#290) rather than either corrupting it
64
+ * (routing to `field`) or refusing to build it (a single bad automation
65
+ * file throwing during `elementum build`'s jiti discovery aborts discovery
66
+ * for the WHOLE workspace, not just this app — confirmed in
67
+ * `engine/build/build.ts`'s `discoverOwnFileChildren`, which deliberately
68
+ * treats any load failure as fatal rather than risk a silently-missing
69
+ * entity planning as a destroy — so throwing here would trade "one
70
+ * automation invisible" for "the entire org can no longer build," a much
71
+ * worse regression).
72
+ */
73
+ export declare const UNRESOLVED_REFERENCE_MARKER = "__edkUnresolvedReference::";
52
74
  /** Match every record (the minimal valid filter). */
53
75
  export declare function whereTrue(): Filter;
54
76
  /** Match no record. */
@@ -7,6 +7,28 @@ export function currentUser(type = "id") {
7
7
  function isCurrentUserValue(value) {
8
8
  return typeof value === "object" && value !== null && !isRef(value) && value.__kind === "currentUser";
9
9
  }
10
+ /**
11
+ * Marker prefix a pulled filter's left side carries when the pull-time
12
+ * deserializer couldn't decode its `left_value`/REFERENCE shape to a typed
13
+ * ref (e.g. a `variable.<uuid>` reference to a not-yet-authorable workflow
14
+ * variable — see `from-tf.ts`'s `decodeReferenceString`). Distinct from an
15
+ * unresolved FIELD placeholder (a bare uuid, no prefix), which legitimately
16
+ * round-trips through the `{ field }`/`field_id` wire slot below — a
17
+ * left_value/REFERENCE position never does, so silently routing it through
18
+ * `{ field }` would rebuild a structurally different filter than the one
19
+ * `ei` exported. `leftDescriptor` routes this marker through the SAME
20
+ * `leftValue`/REFERENCE wire slot instead, reproducing the original raw
21
+ * `value_reference` string verbatim (#290) rather than either corrupting it
22
+ * (routing to `field`) or refusing to build it (a single bad automation
23
+ * file throwing during `elementum build`'s jiti discovery aborts discovery
24
+ * for the WHOLE workspace, not just this app — confirmed in
25
+ * `engine/build/build.ts`'s `discoverOwnFileChildren`, which deliberately
26
+ * treats any load failure as fatal rather than risk a silently-missing
27
+ * entity planning as a destroy — so throwing here would trade "one
28
+ * automation invisible" for "the entire org can no longer build," a much
29
+ * worse regression).
30
+ */
31
+ export const UNRESOLVED_REFERENCE_MARKER = "__edkUnresolvedReference::";
10
32
  /**
11
33
  * True when `left` is a genuine `Ref` (task/trigger/… output) rather than a
12
34
  * field. Note this is *not* "is a `FieldRef`" — an unresolved-field
@@ -32,11 +54,30 @@ function leftDescriptor(left, defaultType, leftType) {
32
54
  },
33
55
  };
34
56
  }
57
+ const rawLeft = left;
58
+ if (typeof rawLeft === "string" && rawLeft.startsWith(UNRESOLVED_REFERENCE_MARKER)) {
59
+ return {
60
+ leftValue: {
61
+ type: "REFERENCE",
62
+ realType: leftType ?? defaultType,
63
+ // Raw pass-through, recognized by to-tf.ts's filterReferenceToTf -
64
+ // bypasses the typed TRIGGER/TASK/FOR_EACH dispatch entirely since
65
+ // there is no typed ref to dispatch on, only the original wire
66
+ // string preserved verbatim from pull.
67
+ value: { __rawFilterReference: rawLeft.slice(UNRESOLVED_REFERENCE_MARKER.length) },
68
+ },
69
+ };
70
+ }
35
71
  return { field: left };
36
72
  }
37
73
  /** The value type to compare against — from the FieldRef's fieldType, or the operator's (possibly overridden) default when the LHS is a Ref. */
38
74
  function leftValueType(left, defaultType, leftType) {
39
- return isRefLeft(left) ? (leftType ?? defaultType) : fieldTypeToValueType(left.fieldType);
75
+ if (isRefLeft(left))
76
+ return leftType ?? defaultType;
77
+ const rawLeft = left;
78
+ if (typeof rawLeft === "string" && rawLeft.startsWith(UNRESOLVED_REFERENCE_MARKER))
79
+ return leftType ?? defaultType;
80
+ return fieldTypeToValueType(left.fieldType);
40
81
  }
41
82
  /** Map a filter value to the platform's `Value` wire shape, typed `vt`. */
42
83
  function value(vt, v) {