@elementumai/edk 0.9.14 → 0.9.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist-sdk/pull/util.d.ts +0 -15
  2. package/dist-sdk/pull/util.js +44 -5
  3. package/dist-sdk/src/catalog/factories.d.ts +4 -2
  4. package/dist-sdk/src/catalog/factories.js +4 -0
  5. package/dist-sdk/src/catalog/from-authoring.js +5 -1
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +1 -1
  8. package/dist-sdk/src/catalog/token.js +2 -2
  9. package/dist-sdk/src/catalog/types.d.ts +7 -2
  10. package/dist-sdk/src/core/types/app.d.ts +4 -4
  11. package/dist-sdk/src/engine/build/context.d.ts +5 -4
  12. package/dist-sdk/src/engine/build/source-context.d.ts +2 -0
  13. package/dist-sdk/src/engine/build/source-context.js +16 -0
  14. package/dist-sdk/src/engine/progress.d.ts +19 -1
  15. package/dist-sdk/src/engine/progress.js +33 -5
  16. package/dist-sdk/src/engine/pull/context.d.ts +9 -1
  17. package/dist-sdk/src/engine/pull/ref-only.d.ts +6 -2
  18. package/dist-sdk/src/engine/pull/ref-only.js +14 -3
  19. package/dist-sdk/src/engine/workspace/loader.js +23 -2
  20. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +1 -1
  21. package/dist-sdk/src/entities/access-policy/from-tf.js +47 -12
  22. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +5 -3
  23. package/dist-sdk/src/entities/access-policy/to-tf.js +23 -1
  24. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +6 -0
  25. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +50 -4
  26. package/dist-sdk/src/entities/agent/from-tf.d.ts +1 -0
  27. package/dist-sdk/src/entities/agent/from-tf.js +18 -3
  28. package/dist-sdk/src/entities/agent/module.js +1 -0
  29. package/dist-sdk/src/entities/agent/to-tf.js +15 -0
  30. package/dist-sdk/src/entities/agent/tools.d.ts +98 -5
  31. package/dist-sdk/src/entities/agent/tools.js +12 -3
  32. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +15 -0
  33. package/dist-sdk/src/entities/agent-tool/from-tf.js +47 -4
  34. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +9 -0
  35. package/dist-sdk/src/entities/agent-tool/to-tf.js +82 -25
  36. package/dist-sdk/src/entities/app/build.d.ts +2 -2
  37. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +4 -4
  38. package/dist-sdk/src/entities/app/module.js +8 -0
  39. package/dist-sdk/src/entities/app/to-tf.js +1 -0
  40. package/dist-sdk/src/entities/approval-chain/build.d.ts +8 -1
  41. package/dist-sdk/src/entities/approval-chain/build.js +3 -0
  42. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +2 -1
  43. package/dist-sdk/src/entities/approval-chain/from-tf.js +20 -7
  44. package/dist-sdk/src/entities/approval-chain/printer.js +13 -2
  45. package/dist-sdk/src/entities/approval-chain/to-tf.js +3 -0
  46. package/dist-sdk/src/entities/automation/build.d.ts +19 -12
  47. package/dist-sdk/src/entities/automation/build.js +36 -13
  48. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +4 -0
  49. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +19 -0
  50. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +222 -65
  51. package/dist-sdk/src/entities/automation/from-tf.d.ts +86 -6
  52. package/dist-sdk/src/entities/automation/from-tf.js +360 -63
  53. package/dist-sdk/src/entities/automation/index.d.ts +3 -2
  54. package/dist-sdk/src/entities/automation/index.js +3 -2
  55. package/dist-sdk/src/entities/automation/module.js +21 -16
  56. package/dist-sdk/src/entities/automation/output-field-types.d.ts +5 -0
  57. package/dist-sdk/src/entities/automation/output-field-types.js +12 -0
  58. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +20 -0
  59. package/dist-sdk/src/entities/automation/output-key-wire-name.js +22 -0
  60. package/dist-sdk/src/entities/automation/script-code.d.ts +32 -0
  61. package/dist-sdk/src/entities/automation/script-code.js +72 -5
  62. package/dist-sdk/src/entities/automation/tasks.d.ts +60 -24
  63. package/dist-sdk/src/entities/automation/tasks.js +33 -14
  64. package/dist-sdk/src/entities/automation/to-tf.d.ts +0 -2
  65. package/dist-sdk/src/entities/automation/to-tf.js +123 -46
  66. package/dist-sdk/src/entities/automation/triggers.d.ts +5 -2
  67. package/dist-sdk/src/entities/automation/types.d.ts +2 -0
  68. package/dist-sdk/src/entities/automation/types.js +5 -0
  69. package/dist-sdk/src/entities/automation/workflow-output.d.ts +35 -0
  70. package/dist-sdk/src/entities/automation/workflow-output.js +53 -0
  71. package/dist-sdk/src/entities/chart/build.d.ts +3 -3
  72. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  73. package/dist-sdk/src/entities/chart/from-tf.js +20 -13
  74. package/dist-sdk/src/entities/chart/to-tf.js +7 -5
  75. package/dist-sdk/src/entities/dashboard/from-tf.js +1 -1
  76. package/dist-sdk/src/entities/dashboard/to-tf.js +1 -0
  77. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +3 -2
  78. package/dist-sdk/src/entities/element/build.d.ts +11 -8
  79. package/dist-sdk/src/entities/element/build.js +14 -5
  80. package/dist-sdk/src/entities/element/locals.d.ts +2 -2
  81. package/dist-sdk/src/entities/element/locals.js +6 -2
  82. package/dist-sdk/src/entities/element/system-fields.d.ts +4 -0
  83. package/dist-sdk/src/entities/element/system-fields.js +12 -0
  84. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  85. package/dist-sdk/src/entities/field/build.d.ts +2 -2
  86. package/dist-sdk/src/entities/field/from-tf.js +82 -4
  87. package/dist-sdk/src/entities/field/to-tf.d.ts +1 -1
  88. package/dist-sdk/src/entities/field/to-tf.js +11 -4
  89. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -2
  90. package/dist-sdk/src/entities/relationship/from-tf.js +8 -5
  91. package/dist-sdk/src/entities/relationship/to-tf.js +13 -3
  92. package/dist-sdk/src/entities/search-table/from-tf.js +6 -6
  93. package/dist-sdk/src/entities/search-table/module.js +2 -2
  94. package/dist-sdk/src/entities/search-table/types.d.ts +1 -0
  95. package/dist-sdk/src/entities/search-table/types.js +1 -0
  96. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +3 -3
  97. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +10 -6
  98. package/dist-sdk/src/entities/shared/filters/ast.d.ts +4 -2
  99. package/dist-sdk/src/entities/shared/filters/index.d.ts +12 -2
  100. package/dist-sdk/src/entities/shared/filters/index.js +17 -1
  101. package/dist-sdk/src/entities/shared/filters/print.js +25 -11
  102. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
  103. package/dist-sdk/src/entities/shared/filters/tf-codec.js +39 -7
  104. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +1 -1
  105. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
  106. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +6 -0
  107. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +47 -18
  108. package/dist-sdk/src/entities/skill/module.js +10 -0
  109. package/dist-sdk/src/entities/skill/to-tf.js +19 -0
  110. package/dist-sdk/src/entities/skill/tools.d.ts +29 -7
  111. package/dist-sdk/src/entities/skill/tools.js +6 -2
  112. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +18 -0
  113. package/dist-sdk/src/entities/skill-tool/from-tf.js +77 -4
  114. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
  115. package/dist-sdk/src/entities/skill-tool/to-tf.js +90 -46
  116. package/dist-sdk/src/entities/task/module.js +1 -1
  117. package/dist-sdk/src/entities/view/from-tf.js +30 -9
  118. package/dist-sdk/src/entities/view/to-tf.js +18 -10
  119. package/dist-sdk/src/entities/widget/from-tf.js +3 -3
  120. package/dist-sdk/src/entities/widget/to-tf.js +1 -0
  121. package/dist-sdk/src/graph/index.d.ts +15 -0
  122. package/dist-sdk/src/graph/index.js +19 -0
  123. package/dist-sdk/src/graph/types.d.ts +37 -1
  124. package/package.json +2 -1
@@ -88,6 +88,7 @@ export const skillModule = {
88
88
  ...(opts.crossOrg !== undefined && { crossOrg: opts.crossOrg }),
89
89
  ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
90
90
  ...(opts.foreignElementRefNames !== undefined && { foreignElementRefNames: opts.foreignElementRefNames }),
91
+ ...(opts.foreignTaskRefNames !== undefined && { foreignTaskRefNames: opts.foreignTaskRefNames }),
91
92
  ...(opts.foreignFieldRefsById !== undefined && { foreignFieldRefsById: opts.foreignFieldRefsById }),
92
93
  ...(opts.foreignTableRefsById !== undefined && { foreignTableRefsById: opts.foreignTableRefsById }),
93
94
  ...(opts.foreignSearchTableRefsByName !== undefined && {
@@ -108,6 +109,15 @@ export const skillModule = {
108
109
  ...(ctx.activeAutomationRefNames !== undefined && { activeAutomationRefNames: ctx.activeAutomationRefNames }),
109
110
  }),
110
111
  },
112
+ roundtrip: {
113
+ referenceAliases: [],
114
+ stringSuffixAliases: [
115
+ {
116
+ attribute: "instructions",
117
+ suffix: "\n\n## Lookup Notes\n\n- No lookup tools are required.",
118
+ },
119
+ ],
120
+ },
111
121
  catalog: {
112
122
  participates: true,
113
123
  refKind: "skill",
@@ -115,6 +115,7 @@ export function skillToTf(entity, ctx) {
115
115
  ...(ctx.activeAutomationRefNames !== undefined && { activeAutomationRefNames: ctx.activeAutomationRefNames }),
116
116
  foreignAppRef: (l, n, ns) => ctx.orgRefs.foreignApp(l, n, ns),
117
117
  foreignElementRef: (l, n, ns) => ctx.orgRefs.foreignElement(l, n, ns),
118
+ foreignTaskRef: (l, n) => ctx.orgRefs.rawLookup("elementum_task", l, n),
118
119
  foreignFieldRef: (t, l, o, n) => ctx.orgRefs.foreignField(t, l, o, n),
119
120
  workspaceAspects: ctx.workspaceAspects,
120
121
  serviceAccountRef: (_label, serviceAccountName) => serviceAccountValue(serviceAccountName, ctx),
@@ -125,6 +126,24 @@ export function skillToTf(entity, ctx) {
125
126
  ctx.orgRefs.rawLookup("elementum_search_table", label, searchTableName, { table_id: tableId });
126
127
  return expr.dataAttr("elementum_search_table", label, ["id"]);
127
128
  },
129
+ foreignAutomationRef: (tfLabel, parentKind, _parentRefName, parentName, automationName) => {
130
+ // sanitizeName(parentName), not the refName: ei labels the export
131
+ // from the owner's DISPLAY name, and sanitizeName doesn't split a
132
+ // capital before a digit the way reversing a refName would need
133
+ // (same lesson as #1095's table-owned search-table label fix).
134
+ const parentType = parentKind === "element" ? "elementum_element" : "elementum_app";
135
+ const parentLabel = sanitizeName(parentName);
136
+ // ei labels a foreign automation data block `${lookup.Label}_${SanitizeName(name)}`
137
+ // (imports.go), not the bare automation label - a bare label both
138
+ // diverges from the pulled state (plan diff) and collides in
139
+ // ctx.orgRefs.rawLookup's `${type}.${label}` registry key across apps.
140
+ const automationLabel = `${parentLabel}_${tfLabel}`;
141
+ ctx.orgRefs.rawLookup(parentType, parentLabel, parentName);
142
+ ctx.orgRefs.rawLookup("elementum_automation", automationLabel, automationName, {
143
+ app_id: expr.dataAttr(parentType, parentLabel, ["id"]),
144
+ });
145
+ return expr.dataAttr("elementum_automation", automationLabel, ["id"]);
146
+ },
128
147
  tableColumnRef: (tableRefName, tableName, columnName) => {
129
148
  const sibling = ctx.workspaceAspects?.get(workspaceAspectKey("table", tableRefName));
130
149
  if (sibling !== undefined) {
@@ -9,7 +9,7 @@
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, TableColumnRef, TableOwnedSearchTableRef } from "../../catalog/index.js";
12
+ import type { AgentRef, AppCatalogRef, AutomationCatalogRef, ElementCatalogRef, FieldRef, SearchTableRef, TableColumnRef, TableOwnedSearchTableRef, TaskCatalogRef } from "../../catalog/index.js";
13
13
  import type { UnsafePlatformId } from "../../core/platform-id.js";
14
14
  import type { AgentToolRunAs, OutputBagOf, RunAutomationOptionalInput, RunAutomationOutput, RunAutomationOutputs, TriggerBagOf } from "../agent/tools.js";
15
15
  declare const skillToolBrand: unique symbol;
@@ -18,15 +18,23 @@ export type SkillTool = Record<string, unknown> & {
18
18
  readonly [skillToolBrand]: "SkillTool";
19
19
  };
20
20
  export type SkillToolStatus = "ACTIVE" | "INACTIVE";
21
- type ToolTarget = AppCatalogRef | ElementCatalogRef;
21
+ type ToolTarget = AppCatalogRef | ElementCatalogRef | TaskCatalogRef;
22
22
  type TargetOption<Target extends ToolTarget> = Target extends {
23
23
  readonly __kind: "app";
24
24
  } ? {
25
25
  readonly app: Target;
26
26
  readonly element?: never;
27
- } : {
27
+ readonly task?: never;
28
+ } : Target extends {
29
+ readonly __kind: "element";
30
+ } ? {
28
31
  readonly app?: never;
29
32
  readonly element: Target;
33
+ readonly task?: never;
34
+ } : {
35
+ readonly app?: never;
36
+ readonly element?: never;
37
+ readonly task: Target;
30
38
  };
31
39
  export interface SkillSearchField<Target extends ToolTarget = ToolTarget> {
32
40
  readonly field: FieldRef<Target["refName"]>;
@@ -123,11 +131,25 @@ export type SkillSearchRecordsToolOptions<Target extends ToolTarget = ToolTarget
123
131
  export declare function skillSearchRecords<Target extends ToolTarget>(opts: SkillSearchRecordsToolOptions<Target>): SkillTool;
124
132
  /** A search-table tool over an element-owned index targets its owning ELEMENT. */
125
133
  export type SkillSearchTableToolV2<Target extends ElementCatalogRef = ElementCatalogRef> = CommonToolOptions & TargetOption<Target> & {
126
- readonly table: SearchTableRef & {
134
+ /**
135
+ * The search table itself, or (pull-fidelity fallback, mirroring
136
+ * `fieldId`/`id` elsewhere in this file) a raw platform id when the
137
+ * search table's own identity has no portable lookup at all - the
138
+ * target aspect can still resolve fine even though the search table
139
+ * doesn't (live-confirmed on sanofi/eu, mirrors agent-tool's identical
140
+ * fallback, #1099/#1176).
141
+ */
142
+ readonly table: (SearchTableRef & {
127
143
  readonly __variant?: "snowflake" | "linked";
128
- };
144
+ }) | UnsafePlatformId;
129
145
  readonly queryDescription: string;
130
- readonly fields: readonly SkillSearchFieldInput<Target>[];
146
+ /**
147
+ * Optional, like `skillCreateRecord`/`skillUpdateRecord`'s `fields?` — a
148
+ * pulled tool whose search table has no portable lookup also has no
149
+ * resolvable field list to print (live-confirmed on sanofi/eu: a raw-id
150
+ * `table` with zero fields), so this can't be required (#1180 review).
151
+ */
152
+ readonly fields?: readonly SkillSearchFieldInput<Target>[];
131
153
  /** Maximum number of records the search returns. */
132
154
  readonly limit?: number;
133
155
  readonly filterVariables?: readonly SkillFilterVariable[];
@@ -138,7 +160,7 @@ export type SkillTableOwnedSearchTableToolV2 = CommonToolOptions & {
138
160
  readonly element?: never;
139
161
  readonly table: TableOwnedSearchTableRef;
140
162
  readonly queryDescription: string;
141
- readonly fields: readonly SkillTableSearchFieldInput[];
163
+ readonly fields?: readonly SkillTableSearchFieldInput[];
142
164
  readonly limit?: number;
143
165
  readonly filterVariables?: readonly SkillFilterVariable[];
144
166
  };
@@ -1,7 +1,11 @@
1
1
  import { isValidToolName } from "../agent-tool/types.js";
2
2
  import { assertHandleDescriptionNotEmpty } from "../shared/handle-description.js";
3
3
  function targetOf(opts) {
4
- return ("app" in opts && opts.app !== undefined ? opts.app : opts.element);
4
+ return ("app" in opts && opts.app !== undefined
5
+ ? opts.app
6
+ : "element" in opts && opts.element !== undefined
7
+ ? opts.element
8
+ : opts.task);
5
9
  }
6
10
  function filterVariableToken(variable) {
7
11
  return {
@@ -115,7 +119,7 @@ export function skillSearchTable(opts) {
115
119
  ...(target !== undefined ? { aspectId: target } : {}),
116
120
  searchTableId: opts.table,
117
121
  queryDescription: opts.queryDescription,
118
- fields: opts.fields.map(searchFieldToken),
122
+ fields: (opts.fields ?? []).map(searchFieldToken),
119
123
  ...(opts.limit !== undefined ? { limit: opts.limit } : {}),
120
124
  ...(opts.filterVariables !== undefined ? { filterVariables: opts.filterVariables.map(filterVariableToken) } : {}),
121
125
  },
@@ -46,6 +46,12 @@ export type NormalizedSkillToolTarget = {
46
46
  readonly name: string;
47
47
  readonly refName?: string;
48
48
  readonly namespace?: string;
49
+ } | {
50
+ /** A foreign TASK via `data.elementum_task.<label>` — `name` from the stream's data block. */
51
+ readonly kind: "foreignTask";
52
+ readonly name: string;
53
+ readonly refName?: string;
54
+ readonly namespace?: string;
49
55
  } | {
50
56
  /**
51
57
  * `target_id` didn't resolve to any portable reference at export
@@ -78,6 +84,13 @@ export interface NormalizedSkillTool {
78
84
  * (out-of-stream automation). Printed as `unsafePlatformId(...)`.
79
85
  */
80
86
  readonly automationRawId?: string;
87
+ /** Display name of a foreign (cross-app/element) automation_id reference. */
88
+ readonly automationForeignName?: string;
89
+ /** Display name of the foreign automation's owning app/element. */
90
+ readonly automationForeignParentName?: string;
91
+ /** Canonical catalog refName of the owning app/element, when known. */
92
+ readonly automationForeignParentRefName?: string;
93
+ readonly automationForeignParentKind?: "app" | "element";
81
94
  readonly searchTableKey?: string;
82
95
  /** Foreign table lookup name when search_table_id is data.elementum_search_table. */
83
96
  readonly searchTableName?: string;
@@ -85,6 +98,11 @@ export interface NormalizedSkillTool {
85
98
  readonly searchTableOwnerName?: string;
86
99
  /** Canonical catalog refName of the owning organization table, when known. */
87
100
  readonly searchTableOwnerRefName?: string;
101
+ /**
102
+ * Bare `search_table_id` UUID when the search table itself has no
103
+ * portable lookup at all (not even a name). Printed as `unsafePlatformId(...)`.
104
+ */
105
+ readonly searchTableRawId?: string;
88
106
  readonly inputs?: readonly {
89
107
  readonly parameterName: string;
90
108
  readonly displayName?: string;
@@ -7,7 +7,7 @@
7
7
  import { EntityTfError } from "../../engine/entity.js";
8
8
  import { dataRefLabel, optionalString, resourceRefLabel } from "../../engine/pull/context.js";
9
9
  import { isTfExpr, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
10
- import { dataAspectDisplayName, dataAspectRefName } from "../shared/aspect-target-from-tf.js";
10
+ import { dataAspectDisplayName, dataAspectRefName, resolveDataAspectTarget } 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";
13
13
  /**
@@ -128,7 +128,42 @@ export function skillToolFromTf(block, owner, ctx) {
128
128
  ? automation.label
129
129
  : undefined;
130
130
  const automationRawId = typeof automation === "string" && automation !== "" ? automation : undefined;
131
- if (automationLabel === undefined && automationRawId === undefined) {
131
+ // A foreign (cross-app/element) automation reference - the resource-attr
132
+ // branch above only recognizes a same-workspace managed automation.
133
+ // Live-confirmed on sanofi/eu: "PO Change Request" skill's
134
+ // "Change_Address" tool targets an automation owned by a *different*
135
+ // app. Resolve the owner the same way target_id's foreignApp/
136
+ // foreignElement branches do above (#1177).
137
+ let automationForeignName;
138
+ let automationForeignParentName;
139
+ let automationForeignParentRefName;
140
+ let automationForeignParentKind;
141
+ if (automationLabel === undefined &&
142
+ automationRawId === undefined &&
143
+ isTfExpr(automation) &&
144
+ automation.$expr === "data-attr" &&
145
+ automation.type === "elementum_automation") {
146
+ const automationName = ctx.dataName(automation.type, automation.label);
147
+ if (automationName === undefined) {
148
+ ctx.diagnostics.push(`${where}: automation_id references data.${automation.type}.${automation.label} but the stream has no matching name lookup; skipped`);
149
+ return undefined;
150
+ }
151
+ const ownerAttrs = ctx.dataAttrs?.(automation.type, automation.label);
152
+ const appOwnerLabel = dataRefLabel(ownerAttrs?.["app_id"], "elementum_app");
153
+ const elementOwnerLabel = appOwnerLabel === undefined ? dataRefLabel(ownerAttrs?.["app_id"], "elementum_element") : undefined;
154
+ const ownerKind = appOwnerLabel !== undefined ? "app" : elementOwnerLabel !== undefined ? "element" : undefined;
155
+ const ownerLabel = appOwnerLabel ?? elementOwnerLabel;
156
+ if (ownerKind === undefined || ownerLabel === undefined) {
157
+ ctx.diagnostics.push(`${where}: automation_id references data.${automation.type}.${automation.label}, whose owner app_id isn't a recognized app/element reference; skipped`);
158
+ return undefined;
159
+ }
160
+ const resolvedOwner = resolveDataAspectTarget(ctx, ownerKind, ownerLabel);
161
+ automationForeignName = automationName;
162
+ automationForeignParentName = resolvedOwner.name;
163
+ automationForeignParentRefName = resolvedOwner.key;
164
+ automationForeignParentKind = ownerKind;
165
+ }
166
+ if (automationLabel === undefined && automationRawId === undefined && automationForeignName === undefined) {
132
167
  ctx.diagnostics.push(`${where}: automation_id is not an automation/workflow_publish resource reference; skipped`);
133
168
  return undefined;
134
169
  }
@@ -168,7 +203,14 @@ export function skillToolFromTf(block, owner, ctx) {
168
203
  ...common,
169
204
  ...(automationRawId !== undefined
170
205
  ? { automationRawId }
171
- : { automationKey: scopedLabelToBagKey(owner.ownerTfLabel, automationLabel) }),
206
+ : automationForeignName !== undefined
207
+ ? {
208
+ automationForeignName,
209
+ ...(automationForeignParentName !== undefined && { automationForeignParentName }),
210
+ ...(automationForeignParentRefName !== undefined && { automationForeignParentRefName }),
211
+ ...(automationForeignParentKind !== undefined && { automationForeignParentKind }),
212
+ }
213
+ : { automationKey: scopedLabelToBagKey(owner.ownerTfLabel, automationLabel) }),
172
214
  ...(inputs.length > 0 && { inputs }),
173
215
  ...(outputs.length > 0 && { outputs }),
174
216
  };
@@ -178,6 +220,7 @@ export function skillToolFromTf(block, owner, ctx) {
178
220
  let tableOwnedSearchTable = false;
179
221
  let searchTableOwnerName;
180
222
  let searchTableOwnerRefName;
223
+ let searchTableRawId;
181
224
  if (subType.typeKey === "searchTable") {
182
225
  const value = attrs["search_table_id"];
183
226
  const resourceTypes = ["elementum_ai_search_table", "elementum_linked_ai_search_table", "elementum_table_search_table"];
@@ -213,6 +256,17 @@ export function skillToolFromTf(block, owner, ctx) {
213
256
  return undefined;
214
257
  }
215
258
  }
259
+ else if (typeof value === "string" && value !== "") {
260
+ // The search table's own identity couldn't be resolved to a name or a
261
+ // local resource at all - ei's own export already fell back to a raw
262
+ // UUID here (live-confirmed on sanofi/eu: the "PO Change Request"
263
+ // skill's "New_AddressSearch" tool). Round-trip it as
264
+ // unsafePlatformId() instead of silently dropping a live tool - a
265
+ // rebuild-and-plan on the dropped tool would otherwise DESTROY it.
266
+ // Mirrors agent-tool/from-tf.ts's identical fallback (#1099).
267
+ ctx.diagnostics.push(`${where}: search_table_id could not be resolved to a portable reference ("${value}"); kept as unresolved`);
268
+ searchTableRawId = value;
269
+ }
216
270
  else {
217
271
  ctx.diagnostics.push(`${where}: search_table_id is not a supported search-table resource reference; skipped`);
218
272
  return undefined;
@@ -238,7 +292,7 @@ export function skillToolFromTf(block, owner, ctx) {
238
292
  return undefined;
239
293
  }
240
294
  }
241
- else if (selfLabel === owner.appLabel) {
295
+ else if (owner.appLabel !== undefined && selfLabel === owner.appLabel) {
242
296
  target = { kind: "self" };
243
297
  }
244
298
  else if (isTfExpr(targetAttr) && targetAttr.$expr === "data-attr" && targetAttr.type === "elementum_app") {
@@ -277,6 +331,24 @@ export function skillToolFromTf(block, owner, ctx) {
277
331
  fieldScopeLabel = targetAttr.label;
278
332
  fieldScope = "element";
279
333
  }
334
+ else if (isTfExpr(targetAttr) && targetAttr.$expr === "data-attr" && targetAttr.type === "elementum_task") {
335
+ const taskName = dataAspectDisplayName(ctx, "task", targetAttr.label);
336
+ if (taskName === undefined) {
337
+ ctx.diagnostics.push(`${where}: target_id references data.elementum_task.${targetAttr.label} but the stream has no such data block; skipped`);
338
+ return undefined;
339
+ }
340
+ const attrs = ctx.dataAttrs?.("elementum_task", targetAttr.label);
341
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
342
+ const refName = dataAspectRefName(ctx, "task", targetAttr.label, taskName);
343
+ target = {
344
+ kind: "foreignTask",
345
+ name: taskName,
346
+ ...(refName !== undefined && { refName }),
347
+ ...(namespace !== undefined && { namespace }),
348
+ };
349
+ fieldScopeLabel = targetAttr.label;
350
+ fieldScope = "task";
351
+ }
280
352
  else if (typeof targetAttr === "string") {
281
353
  // No portable reference was available at export time (ei fell back to
282
354
  // the raw platform UUID) — keep the tool with an unresolved target
@@ -375,6 +447,7 @@ export function skillToolFromTf(block, owner, ctx) {
375
447
  ...(searchTableName !== undefined && { searchTableName }),
376
448
  ...(searchTableOwnerName !== undefined && { searchTableOwnerName }),
377
449
  ...(searchTableOwnerRefName !== undefined && { searchTableOwnerRefName }),
450
+ ...(searchTableRawId !== undefined && { searchTableRawId }),
378
451
  ...(typeof attrs["result_limit"] === "number" && { limit: attrs["result_limit"] }),
379
452
  ...(handleDescription !== undefined && { handleDescription }),
380
453
  };
@@ -26,6 +26,8 @@ export interface SkillToolToTfContext {
26
26
  foreignAppRef(tfLabel: string, name: string, namespace?: string): void;
27
27
  /** Records a foreign-ELEMENT data lookup for data.tf (board issue #42). */
28
28
  foreignElementRef(tfLabel: string, name: string, namespace?: string): void;
29
+ /** Records a foreign-TASK data lookup for data.tf. */
30
+ foreignTaskRef?(tfLabel: string, name: string, namespace?: string): void;
29
31
  /** Records an object-scoped data lookup owned by a foreign app/element. */
30
32
  foreignFieldRef(type: string, tfLabel: string, objectId: TfValue, name: string): void;
31
33
  /** App/element roots authored in this same workspace. */
@@ -34,6 +36,12 @@ export interface SkillToolToTfContext {
34
36
  serviceAccountRef?(tfLabel: string, name: string): TfValue | void;
35
37
  /** Records a table-owned search-table data lookup for a pulled public ref. */
36
38
  tableSearchTableRef?(tfLabel: string, tableRefName: string, tableName: string, searchTableName: string): TfValue | void;
39
+ /**
40
+ * Records a cross-app/element automation data lookup (a `runAutomation`
41
+ * skill/agent tool targeting an automation this workspace doesn't own),
42
+ * returning the resolved `.id`. Live-confirmed on sanofi/eu (#1177).
43
+ */
44
+ foreignAutomationRef?(tfLabel: string, parentKind: "app" | "element", parentRefName: string, parentName: string, automationName: string): TfValue | void;
37
45
  /** Resolves a table-column token for a table-owned search tool. */
38
46
  tableColumnRef?(tableRefName: string, tableName: string, columnName: string): TfValue | void;
39
47
  /** App-local automations whose publish resource will be emitted in this build. */
@@ -45,7 +45,7 @@ function targetIdValue(token, ctx) {
45
45
  return { value: token.value, refName: token.value, kind: "app" };
46
46
  }
47
47
  const refName = token.refName ?? "";
48
- const kind = token.__kind === "element" ? "element" : "app";
48
+ const kind = token.__kind === "element" ? "element" : token.__kind === "task" ? "task" : "app";
49
49
  if (kind === "app" && refName === ctx.appRefName) {
50
50
  return {
51
51
  value: expr.resourceAttr("elementum_app", ctx.appTfLabel, ["id"]),
@@ -56,7 +56,7 @@ function targetIdValue(token, ctx) {
56
56
  }
57
57
  const sibling = ctx.workspaceAspects?.get(workspaceAspectKey(kind, refName));
58
58
  if (sibling !== undefined) {
59
- const resourceType = kind === "element" ? "elementum_element" : "elementum_app";
59
+ const resourceType = kind === "element" ? "elementum_element" : kind === "task" ? "elementum_task" : "elementum_app";
60
60
  return {
61
61
  value: expr.resourceAttr(resourceType, sibling.tfLabel, ["id"]),
62
62
  refName,
@@ -76,6 +76,15 @@ function targetIdValue(token, ctx) {
76
76
  foreignTfLabel: tfLabel,
77
77
  };
78
78
  }
79
+ if (kind === "task") {
80
+ ctx.foreignTaskRef?.(tfLabel, name, token.namespace);
81
+ return {
82
+ value: expr.dataAttr("elementum_task", tfLabel, ["id"]),
83
+ refName,
84
+ kind,
85
+ foreignTfLabel: tfLabel,
86
+ };
87
+ }
79
88
  ctx.foreignAppRef(tfLabel, name, token.namespace);
80
89
  return {
81
90
  value: expr.dataAttr("elementum_app", tfLabel, ["id"]),
@@ -115,7 +124,7 @@ function fieldRefValue(token, where, ctx, target) {
115
124
  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`);
116
125
  return undefined;
117
126
  }
118
- if (target.localTfLabel === undefined) {
127
+ if (target.localTfLabel === undefined || target.kind === "task") {
119
128
  return foreignTargetFieldRefValue(token, refName, target, ctx);
120
129
  }
121
130
  const authoringType = token.fieldType ?? "";
@@ -197,13 +206,32 @@ export function skillToolToTf(entry, ctx) {
197
206
  return undefined;
198
207
  }
199
208
  if (automation?.parent !== undefined && automation.parent !== ctx.appRefName) {
200
- ctx.diagnostics.push(`${where}: cross-app automation targets are not supported; dropped`);
201
- return undefined;
209
+ // A genuinely foreign (cross-app/element) automation reference -
210
+ // live-confirmed on sanofi/eu: "PO Change Request" skill's
211
+ // "Change_Address" tool. Resolve it the same way a foreign search
212
+ // table/field does elsewhere in this file, via a caller-supplied
213
+ // lookup callback (#1177).
214
+ if (ctx.foreignAutomationRef !== undefined &&
215
+ typeof automation.parentName === "string" && automation.parentName !== "" &&
216
+ typeof automation.name === "string" && automation.name !== "") {
217
+ const lookup = ctx.foreignAutomationRef(automationTfLabel, automation.parentKind ?? "app", automation.parent, automation.parentName, automation.name);
218
+ if (lookup === undefined) {
219
+ ctx.diagnostics.push(`${where}: foreign automation lookup could not be materialized; dropped`);
220
+ return undefined;
221
+ }
222
+ attrs["automation_id"] = lookup;
223
+ }
224
+ else {
225
+ ctx.diagnostics.push(`${where}: cross-app automation targets are not supported; dropped`);
226
+ return undefined;
227
+ }
228
+ }
229
+ else {
230
+ const automationRefName = typeof automation?.refName === "string" && automation.refName !== ""
231
+ ? automation.refName
232
+ : automationTfLabel;
233
+ attrs["automation_id"] = automationRunTargetResourceAttr(ctx.appTfLabel, automationRefName, ctx.activeAutomationRefNames);
202
234
  }
203
- const automationRefName = typeof automation?.refName === "string" && automation.refName !== ""
204
- ? automation.refName
205
- : automationTfLabel;
206
- attrs["automation_id"] = automationRunTargetResourceAttr(ctx.appTfLabel, automationRefName, ctx.activeAutomationRefNames);
207
235
  }
208
236
  if (inner.inputs !== undefined && inner.inputs.length > 0) {
209
237
  attrs["inputs"] = inner.inputs.map((input) => ({
@@ -250,56 +278,72 @@ export function skillToolToTf(entry, ctx) {
250
278
  attrs["target_id"] = "";
251
279
  if (typeKey === "searchTable") {
252
280
  const table = inner.searchTableId;
253
- if (table?.refName === undefined || table.refName === "") {
254
- ctx.diagnostics.push(`${where}: no search table token; dropped`);
255
- return undefined;
281
+ // The search table itself (not its owner - that's the __variant/parent
282
+ // fallback below) has no portable lookup at all: unsafePlatformId()
283
+ // round-trips it as a raw id directly, before the refName check below,
284
+ // which would otherwise treat this escape as "no search table token"
285
+ // and drop a live tool. Scoped to a token with NO refName - one that
286
+ // still carries a refName has a real portable lookup available and
287
+ // must go through the normal parent-mismatch check + resolution below,
288
+ // not be short-circuited here just because it also happens to carry an
289
+ // __unsafe marker. Independent of whether a target aspect resolved -
290
+ // the target can still be fine even though the search table isn't
291
+ // (mirrors agent-tool/to-tf.ts's identical fix, #1099/#1176).
292
+ if (table?.__unsafe === "platformId" && table.refName === undefined && typeof table.value === "string" && table.value !== "") {
293
+ attrs["search_table_id"] = table.value;
256
294
  }
257
- if (target !== undefined && table.parent !== undefined && table.parent !== "" && table.parent !== target.refName) {
258
- ctx.diagnostics.push(`${where}: search table belongs to "${table.parent}", not target "${target.refName}"; dropped`);
295
+ else if (table?.refName === undefined || table.refName === "") {
296
+ ctx.diagnostics.push(`${where}: no search table token; dropped`);
259
297
  return undefined;
260
298
  }
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`);
299
+ else {
300
+ if (target !== undefined && table.parent !== undefined && table.parent !== "" && table.parent !== target.refName) {
301
+ ctx.diagnostics.push(`${where}: search table belongs to "${table.parent}", not target "${target.refName}"; dropped`);
264
302
  return undefined;
265
303
  }
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;
304
+ if (target === undefined) {
305
+ if (table.__variant !== "table") {
306
+ ctx.diagnostics.push(`${where}: missing target aspect is only valid for a table-owned search table; dropped`);
307
+ return undefined;
308
+ }
309
+ const workspaceTable = table.parent === undefined
310
+ ? undefined
311
+ : ctx.workspaceAspects?.get(workspaceAspectKey("table", table.parent));
312
+ if (workspaceTable !== undefined) {
313
+ attrs["search_table_id"] = expr.resourceAttr("elementum_table_search_table", `tables_${workspaceTable.tfLabel}_${tsLabelToTfLabel(table.refName)}`, ["id"]);
314
+ }
315
+ else if (ctx.tableSearchTableRef !== undefined && table.parent !== undefined && table.parent !== "") {
316
+ const lookup = ctx.tableSearchTableRef(`${sanitizeName(table.parent)}_${sanitizeName(table.name ?? table.refName)}`, table.parent, table.parentName ?? table.parent, table.name ?? table.refName);
317
+ if (lookup !== undefined)
318
+ attrs["search_table_id"] = lookup;
319
+ else {
320
+ ctx.diagnostics.push(`${where}: table-owned search table lookup could not be materialized; dropped`);
321
+ return undefined;
322
+ }
323
+ }
324
+ else if (table.__unsafe === "platformId" && typeof table.value === "string" && table.value !== "") {
325
+ attrs["search_table_id"] = table.value;
326
+ }
276
327
  else {
277
- ctx.diagnostics.push(`${where}: table-owned search table lookup could not be materialized; dropped`);
328
+ ctx.diagnostics.push(`${where}: table-owned search table has no portable lookup; dropped`);
278
329
  return undefined;
279
330
  }
280
331
  }
281
- else if (table.__unsafe === "platformId" && typeof table.value === "string" && table.value !== "") {
282
- attrs["search_table_id"] = table.value;
332
+ else if (target.localTfLabel === undefined) {
333
+ const targetName = aspectId?.name ?? aspectId?.refName ?? table.parent;
334
+ const lookupLabel = sanitizeName(`${targetName}_${table.name ?? table.refName}`);
335
+ ctx.foreignFieldRef("elementum_search_table", lookupLabel, target.value, table.name ?? table.refName);
336
+ attrs["search_table_id"] = expr.dataAttr("elementum_search_table", lookupLabel, ["id"]);
283
337
  }
284
338
  else {
285
- ctx.diagnostics.push(`${where}: table-owned search table has no portable lookup; dropped`);
286
- return undefined;
339
+ const resourceType = table.__variant === "linked"
340
+ ? "elementum_linked_ai_search_table"
341
+ : table.__variant === "table"
342
+ ? "elementum_table_search_table"
343
+ : "elementum_ai_search_table";
344
+ attrs["search_table_id"] = expr.resourceAttr(resourceType, scopedResourceLabel(target.localTfLabel, tsLabelToTfLabel(table.refName), target.kind === "element" ? "element" : "app"), ["id"]);
287
345
  }
288
346
  }
289
- else if (target.localTfLabel === undefined) {
290
- const targetName = aspectId?.name ?? aspectId?.refName ?? table.parent;
291
- const lookupLabel = sanitizeName(`${targetName}_${table.name ?? table.refName}`);
292
- ctx.foreignFieldRef("elementum_search_table", lookupLabel, target.value, table.name ?? table.refName);
293
- attrs["search_table_id"] = expr.dataAttr("elementum_search_table", lookupLabel, ["id"]);
294
- }
295
- else {
296
- const resourceType = table.__variant === "linked"
297
- ? "elementum_linked_ai_search_table"
298
- : table.__variant === "table"
299
- ? "elementum_table_search_table"
300
- : "elementum_ai_search_table";
301
- attrs["search_table_id"] = expr.resourceAttr(resourceType, scopedResourceLabel(target.localTfLabel, tsLabelToTfLabel(table.refName), target.kind), ["id"]);
302
- }
303
347
  }
304
348
  if (typeKey === "updateRecord") {
305
349
  encodeOptionalHandleDescription(attrs, inner.handleDescription);
@@ -6,7 +6,7 @@ function extract(stream, ctx) { const blocks = stream.byKind.get("task") ?? [];
6
6
  throw new Error(`expected exactly one ${TASK_RESOURCE_TYPE}, found ${blocks.length}`); return { instance: taskFromTf(blocks[0], ctx) }; }
7
7
  export const taskModule = {
8
8
  kind: "task", stream: { role: "streamRoot", exportVerb: "tasks" }, authoring: { unit: "ownFile", bag: "tasks" }, parents: [{ parent: "org", child: "task" }],
9
- resource: { shape: "single", resourceType: TASK_RESOURCE_TYPE, adoptable: true }, data: { participates: true, lookupAttr: "name", referencedByBuild: false },
9
+ resource: { shape: "single", resourceType: TASK_RESOURCE_TYPE, adoptable: true }, data: { participates: true, lookupAttr: "name", referencedByBuild: true, referenceLookups: [{ strategy: "rootNamespace", compatibilityFallback: "name" }] },
10
10
  lifecycle: { participates: true, extractStreamRoot: extract, toTf: (entity, ctx) => taskToTf(entity, { orgRefs: ctx.orgRefs, diagnostics: ctx.diagnostics }) },
11
11
  canvas: { participates: true, label: "Tasks", glyph: "☑", component: "appDetail" }, catalog: NO_CATALOG,
12
12
  };