@elementumai/edk 0.8.0-preview.11 → 0.8.2-alpha.5

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 (180) hide show
  1. package/README.md +510 -324
  2. package/dist-sdk/src/catalog/ai-provider-models.d.ts +30 -0
  3. package/dist-sdk/src/catalog/ai-provider-models.js +63 -0
  4. package/dist-sdk/src/catalog/factories.d.ts +56 -3
  5. package/dist-sdk/src/catalog/factories.js +83 -4
  6. package/dist-sdk/src/catalog/from-authoring.js +19 -2
  7. package/dist-sdk/src/catalog/index.d.ts +3 -2
  8. package/dist-sdk/src/catalog/index.js +3 -2
  9. package/dist-sdk/src/catalog/org.d.ts +1 -1
  10. package/dist-sdk/src/catalog/org.js +134 -50
  11. package/dist-sdk/src/catalog/render.d.ts +13 -1
  12. package/dist-sdk/src/catalog/render.js +21 -4
  13. package/dist-sdk/src/catalog/token.js +18 -0
  14. package/dist-sdk/src/catalog/types.d.ts +75 -3
  15. package/dist-sdk/src/catalog/types.js +3 -0
  16. package/dist-sdk/src/core/system-fields.d.ts +2 -0
  17. package/dist-sdk/src/core/system-fields.js +2 -0
  18. package/dist-sdk/src/core/types/ai-provider.d.ts +10 -23
  19. package/dist-sdk/src/core/types/ai-provider.js +1 -25
  20. package/dist-sdk/src/core/types/app.d.ts +26 -1
  21. package/dist-sdk/src/engine/build/context.d.ts +58 -0
  22. package/dist-sdk/src/engine/build/context.js +11 -1
  23. package/dist-sdk/src/engine/build/source-context.d.ts +45 -0
  24. package/dist-sdk/src/engine/build/source-context.js +23 -0
  25. package/dist-sdk/src/engine/pull/context.d.ts +15 -0
  26. package/dist-sdk/src/engine/pull/org.d.ts +10 -0
  27. package/dist-sdk/src/engine/pull/org.js +34 -4
  28. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  29. package/dist-sdk/src/engine/tf/index.js +2 -2
  30. package/dist-sdk/src/engine/tf/labels.d.ts +54 -0
  31. package/dist-sdk/src/engine/tf/labels.js +75 -0
  32. package/dist-sdk/src/engine/tf/parse.d.ts +15 -0
  33. package/dist-sdk/src/engine/tf/parse.js +162 -0
  34. package/dist-sdk/src/entities/access-policy/build.d.ts +26 -0
  35. package/dist-sdk/src/entities/access-policy/build.js +7 -0
  36. package/dist-sdk/src/entities/access-policy/filter.d.ts +61 -0
  37. package/dist-sdk/src/entities/access-policy/filter.js +83 -0
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +66 -0
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +187 -0
  40. package/dist-sdk/src/entities/access-policy/module.d.ts +3 -0
  41. package/dist-sdk/src/entities/access-policy/module.js +17 -0
  42. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +43 -0
  43. package/dist-sdk/src/entities/access-policy/to-tf.js +164 -0
  44. package/dist-sdk/src/entities/access-policy/types.d.ts +4 -0
  45. package/dist-sdk/src/entities/access-policy/types.js +10 -0
  46. package/dist-sdk/src/entities/agent/build.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent/build.js +1 -0
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +38 -3
  49. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +257 -32
  50. package/dist-sdk/src/entities/agent/from-tf.d.ts +29 -9
  51. package/dist-sdk/src/entities/agent/from-tf.js +146 -19
  52. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  53. package/dist-sdk/src/entities/agent/module.js +14 -4
  54. package/dist-sdk/src/entities/agent/to-tf.d.ts +46 -1
  55. package/dist-sdk/src/entities/agent/to-tf.js +160 -14
  56. package/dist-sdk/src/entities/agent/tools.d.ts +88 -9
  57. package/dist-sdk/src/entities/agent/tools.js +46 -7
  58. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.d.ts +17 -0
  59. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.js +64 -0
  60. package/dist-sdk/src/entities/agent-a2a-skill/module.d.ts +4 -0
  61. package/dist-sdk/src/entities/agent-a2a-skill/module.js +14 -0
  62. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.d.ts +40 -0
  63. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.js +47 -0
  64. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +51 -4
  65. package/dist-sdk/src/entities/agent-tool/from-tf.js +131 -35
  66. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +11 -4
  67. package/dist-sdk/src/entities/agent-tool/to-tf.js +176 -30
  68. package/dist-sdk/src/entities/agent-tool/types.d.ts +5 -4
  69. package/dist-sdk/src/entities/agent-tool/types.js +38 -6
  70. package/dist-sdk/src/entities/app/build.d.ts +91 -13
  71. package/dist-sdk/src/entities/app/build.js +63 -5
  72. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +3 -0
  73. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -1
  74. package/dist-sdk/src/entities/app/from-tf.js +32 -22
  75. package/dist-sdk/src/entities/app/index.d.ts +4 -1
  76. package/dist-sdk/src/entities/app/index.js +2 -1
  77. package/dist-sdk/src/entities/app/module.js +10 -2
  78. package/dist-sdk/src/entities/app/to-tf.d.ts +5 -0
  79. package/dist-sdk/src/entities/app/to-tf.js +45 -4
  80. package/dist-sdk/src/entities/automation/build.d.ts +57 -13
  81. package/dist-sdk/src/entities/automation/build.js +62 -42
  82. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +25 -8
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +16 -1
  84. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +206 -47
  85. package/dist-sdk/src/entities/automation/filter.d.ts +37 -3
  86. package/dist-sdk/src/entities/automation/filter.js +54 -3
  87. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -27
  88. package/dist-sdk/src/entities/automation/from-tf.js +1344 -222
  89. package/dist-sdk/src/entities/automation/index.d.ts +4 -0
  90. package/dist-sdk/src/entities/automation/index.js +4 -0
  91. package/dist-sdk/src/entities/automation/module.js +29 -32
  92. package/dist-sdk/src/entities/automation/operators.d.ts +29 -2
  93. package/dist-sdk/src/entities/automation/operators.js +27 -1
  94. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +19 -0
  95. package/dist-sdk/src/entities/automation/output-key-wire-name.js +24 -0
  96. package/dist-sdk/src/entities/automation/script-code.d.ts +10 -21
  97. package/dist-sdk/src/entities/automation/script-code.js +272 -5
  98. package/dist-sdk/src/entities/automation/tasks.d.ts +125 -19
  99. package/dist-sdk/src/entities/automation/tasks.js +83 -15
  100. package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -29
  101. package/dist-sdk/src/entities/automation/to-tf.js +1291 -230
  102. package/dist-sdk/src/entities/automation/triggers.d.ts +9 -1
  103. package/dist-sdk/src/entities/automation/types.d.ts +29 -4
  104. package/dist-sdk/src/entities/automation/types.js +76 -46
  105. package/dist-sdk/src/entities/element/build.d.ts +44 -13
  106. package/dist-sdk/src/entities/element/build.js +45 -3
  107. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -1
  108. package/dist-sdk/src/entities/element/from-tf.js +28 -14
  109. package/dist-sdk/src/entities/element/index.d.ts +4 -1
  110. package/dist-sdk/src/entities/element/index.js +2 -1
  111. package/dist-sdk/src/entities/element/module.js +4 -1
  112. package/dist-sdk/src/entities/element/to-tf.js +26 -3
  113. package/dist-sdk/src/entities/field/build.d.ts +61 -14
  114. package/dist-sdk/src/entities/field/build.js +10 -0
  115. package/dist-sdk/src/entities/field/calc/runtime.js +4 -0
  116. package/dist-sdk/src/entities/field/from-tf.d.ts +5 -3
  117. package/dist-sdk/src/entities/field/from-tf.js +118 -7
  118. package/dist-sdk/src/entities/field/module.js +3 -2
  119. package/dist-sdk/src/entities/field/to-tf.d.ts +46 -11
  120. package/dist-sdk/src/entities/field/to-tf.js +166 -17
  121. package/dist-sdk/src/entities/field/types.d.ts +26 -0
  122. package/dist-sdk/src/entities/field/types.js +34 -12
  123. package/dist-sdk/src/entities/file-reader/build.d.ts +108 -50
  124. package/dist-sdk/src/entities/file-reader/build.js +23 -23
  125. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.d.ts +6 -0
  126. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +109 -0
  127. package/dist-sdk/src/entities/file-reader/from-tf.d.ts +13 -0
  128. package/dist-sdk/src/entities/file-reader/from-tf.js +172 -0
  129. package/dist-sdk/src/entities/file-reader/index.d.ts +8 -3
  130. package/dist-sdk/src/entities/file-reader/index.js +7 -2
  131. package/dist-sdk/src/entities/file-reader/module.d.ts +3 -0
  132. package/dist-sdk/src/entities/file-reader/module.js +115 -0
  133. package/dist-sdk/src/entities/file-reader/to-tf.d.ts +14 -0
  134. package/dist-sdk/src/entities/file-reader/to-tf.js +84 -0
  135. package/dist-sdk/src/entities/file-reader/types.d.ts +32 -0
  136. package/dist-sdk/src/entities/file-reader/types.js +30 -0
  137. package/dist-sdk/src/entities/org/ai-provider.d.ts +13 -0
  138. package/dist-sdk/src/entities/org/ai-provider.js +46 -0
  139. package/dist-sdk/src/entities/org/connector.d.ts +8 -1
  140. package/dist-sdk/src/entities/org/connector.js +12 -14
  141. package/dist-sdk/src/entities/org/group.js +10 -1
  142. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  143. package/dist-sdk/src/entities/org/index.js +1 -0
  144. package/dist-sdk/src/entities/org/user.js +10 -1
  145. package/dist-sdk/src/entities/shared/filters/ast.d.ts +59 -9
  146. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  147. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +17 -0
  148. package/dist-sdk/src/entities/shared/tool-field-ref.js +46 -0
  149. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -1
  150. package/dist-sdk/src/entities/shared/types/field-types.js +9 -0
  151. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +19 -0
  152. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +128 -11
  153. package/dist-sdk/src/entities/skill/from-tf.js +4 -3
  154. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  155. package/dist-sdk/src/entities/skill/module.js +7 -1
  156. package/dist-sdk/src/entities/skill/to-tf.d.ts +26 -0
  157. package/dist-sdk/src/entities/skill/to-tf.js +65 -4
  158. package/dist-sdk/src/entities/skill/tools.d.ts +37 -8
  159. package/dist-sdk/src/entities/skill/tools.js +43 -1
  160. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +34 -4
  161. package/dist-sdk/src/entities/skill-tool/from-tf.js +128 -18
  162. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +13 -1
  163. package/dist-sdk/src/entities/skill-tool/to-tf.js +164 -25
  164. package/dist-sdk/src/entities/skill-tool/types.d.ts +5 -7
  165. package/dist-sdk/src/entities/skill-tool/types.js +47 -11
  166. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -2
  167. package/dist-sdk/src/entities/view/from-tf.js +11 -9
  168. package/dist-sdk/src/entities/view/to-tf.d.ts +9 -7
  169. package/dist-sdk/src/entities/view/to-tf.js +39 -18
  170. package/dist-sdk/src/entities/view/types.d.ts +1 -1
  171. package/dist-sdk/src/entities/view/types.js +1 -1
  172. package/dist-sdk/src/graph/deferred-catalog-render.d.ts +0 -5
  173. package/dist-sdk/src/graph/deferred-catalog-render.js +1 -20
  174. package/dist-sdk/src/graph/index.d.ts +8 -0
  175. package/dist-sdk/src/graph/index.js +13 -9
  176. package/dist-sdk/src/graph/modules.js +8 -1
  177. package/dist-sdk/src/graph/types.d.ts +98 -4
  178. package/package.json +49 -16
  179. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +0 -76
  180. package/dist-sdk/src/entities/automation/value-ref-tf.js +0 -190
@@ -2,7 +2,9 @@
2
2
  * printAgentV2 — pulled agent rendering for the terraform path (M3).
3
3
  * Consumes the `NormalizedAgent` that `agentFromTf` produces and emits an
4
4
  * `apps/<app>/agents/<refName>.ts` authoring file: `defineAgent` with the
5
- * connector as an `org.connectors` token, tool targets as `catalog` tokens
5
+ * connector as a `catalog.aiProviders.<provider>.models.<model>` token (the
6
+ * generated org-root barrel re-exports `org.aiProviders`, so this file needs
7
+ * no separate relative `org.js` import), tool targets as `catalog` tokens
6
8
  * (self-app) or a TODO literal (foreign apps — their catalog may not exist
7
9
  * in this workspace), and tool fields as `catalog.<app>.fields.<key>`.
8
10
  *
@@ -13,17 +15,36 @@ import { sdkPackageSpecifier } from "../../../internal/sdk-package.js";
13
15
  const TOOL_FACTORY_BY_TYPE_KEY = {
14
16
  createRecord: "agentCreateRecord",
15
17
  searchAspect: "agentSearchAspect",
18
+ updateRecord: "agentUpdateRecord",
16
19
  executeWorkflow: "agentRunAutomation",
20
+ searchTable: "agentSearchTable",
17
21
  };
22
+ /**
23
+ * A safe placeholder `ConnectorRef` literal (board issue — a property-access
24
+ * chain like `catalog.aiProviders.TODO_PROVIDER.models.TODO_CONNECTOR` looks
25
+ * like a TODO but ISN'T one: `TODO_PROVIDER` is never a real catalog key, so
26
+ * evaluating that expression throws the moment ANYTHING loads the file (a
27
+ * build, `edk pull org --data-only`'s catalog-regen bootstrap, …) instead of
28
+ * failing with the intended "needs manual review" diagnostic. A plain
29
+ * `ConnectorRef`-shaped object literal — the same pattern `foreignApp`/
30
+ * `foreignSkill` stubs already use — loads safely; `agentToTf`'s org-catalog
31
+ * lookup then degrades it to a clear build-time diagnostic instead
32
+ * ("connector token ... is not in the org catalog"), exactly like an
33
+ * unresolved foreignApp/foreignSkill token does.
34
+ */
35
+ const TODO_CONNECTOR_TOKEN = '{ __kind: "connector", refName: "TODO_CONNECTOR", name: "TODO_CONNECTOR", parent: "TODO_PROVIDER" }';
36
+ /** A connector's compound "<provider>.<model>" key → its catalog token path. */
37
+ function printConnectorToken(connectorKey) {
38
+ const [providerKey, modelKey] = connectorKey.split(".");
39
+ if (providerKey === undefined || modelKey === undefined) {
40
+ return `${TODO_CONNECTOR_TOKEN} /* TODO: unrecognized connector key "${connectorKey}" */`;
41
+ }
42
+ return `catalog.aiProviders.${providerKey}.models.${modelKey}`;
43
+ }
18
44
  export function printAgentV2(agent, opts) {
19
- const { appRefName, orgImportPath } = opts;
45
+ const { appRefName } = opts;
46
+ const crossOrg = opts.crossOrg === true;
20
47
  const factories = [...new Set(agent.tools.map((t) => TOOL_FACTORY_BY_TYPE_KEY[t.typeKey]).filter(Boolean))].sort();
21
- const usesCatalog = agent.tools.some((t) => t.target?.kind === "self" || (t.fields !== undefined && t.fields.length > 0) || t.typeKey === "executeWorkflow") ||
22
- (agent.skillAccess !== undefined &&
23
- [
24
- ...(agent.skillAccess.mode === "CUSTOM" ? agent.skillAccess.skills : []),
25
- ...(agent.skillAccess.preloadedSkills ?? []),
26
- ].some((s) => s.kind === "self"));
27
48
  const lines = [];
28
49
  lines.push("/**");
29
50
  lines.push(` * ${agent.name}`);
@@ -33,21 +54,35 @@ export function printAgentV2(agent, opts) {
33
54
  lines.push(" */");
34
55
  lines.push("");
35
56
  lines.push(`import { ${[...factories, "defineAgent"].sort().join(", ")} } from "${sdkPackageSpecifier("agents")}";`);
36
- if (usesCatalog)
37
- lines.push(`import catalog from "@catalog";`);
38
- if (agent.connectorKey !== undefined)
39
- lines.push(`import { org } from ${quote(orgImportPath)};`);
57
+ // Always needed: `connector:` is required and always a catalog.aiProviders
58
+ // token (or the TODO placeholder), and the barrel already re-exports
59
+ // org.aiProviders — no separate relative org.js import is needed here.
60
+ lines.push(`import catalog from "@catalog";`);
40
61
  lines.push("");
41
62
  lines.push(`const ${agent.refName} = defineAgent({`);
42
63
  lines.push(` name: ${quote(agent.name)},`);
43
64
  lines.push(` parent: ${quote(appRefName)},`);
44
- if (agent.connectorKey !== undefined) {
45
- lines.push(` connector: org.connectors.${agent.connectorKey},`);
65
+ const connectorMatchesDestination = agent.connectorKey !== undefined && (opts.destinationConnectorKeys?.has(agent.connectorKey) ?? false);
66
+ if (opts.connectorKeyOverride !== undefined) {
67
+ // Interactively confirmed by the caller — print directly, uncommented,
68
+ // regardless of which TODO path this would otherwise have taken.
69
+ lines.push(` connector: ${printConnectorToken(opts.connectorKeyOverride)},`);
70
+ }
71
+ else if (agent.connectorKey !== undefined && crossOrg && !connectorMatchesDestination) {
72
+ // Resolved, but against the SOURCE org's catalog, and no same-named
73
+ // connector was found in the destination — flag for manual review
74
+ // rather than carry over a token that doesn't exist there.
75
+ lines.push(` connector: ${TODO_CONNECTOR_TOKEN}, // TODO: cross-org clone — connector "${agent.connectorKey}" was resolved in the SOURCE org; verify/replace with the destination org's catalog.aiProviders.<provider>.models.<model>`);
76
+ }
77
+ else if (agent.connectorKey !== undefined) {
78
+ // Either same-org, or cross-org with a same-named connector confirmed
79
+ // present in the destination org.
80
+ lines.push(` connector: ${printConnectorToken(agent.connectorKey)},`);
46
81
  }
47
82
  else {
48
83
  // No connector in the stream — the platform defaulted the model. There
49
84
  // is no token to print; the author picks one (connector is required).
50
- lines.push(` connector: org.connectors.TODO_CONNECTOR, // TODO: no connector in the export — pick one`);
85
+ lines.push(` connector: ${TODO_CONNECTOR_TOKEN}, // TODO: no connector in the export — pick one`);
51
86
  }
52
87
  lines.push(` description: ${quote(agent.description)},`);
53
88
  lines.push(` instructions: ${quote(agent.instructions)},`);
@@ -56,12 +91,31 @@ export function printAgentV2(agent, opts) {
56
91
  if (agent.maxLength !== undefined)
57
92
  lines.push(` maxLength: ${String(agent.maxLength)},`);
58
93
  if (agent.skillAccess !== undefined) {
59
- lines.push(...printSkillAccess(agent.skillAccess, appRefName).map((l) => ` ${l}`));
94
+ lines.push(...printSkillAccess(agent.skillAccess, appRefName, crossOrg).map((l) => ` ${l}`));
95
+ }
96
+ if (agent.runAs !== undefined)
97
+ lines.push(` runAs: ${printRunAs(agent.runAs)},`);
98
+ if (agent.agentAuthentication !== undefined) {
99
+ lines.push(...printAgentAuthentication(agent.agentAuthentication).map((l) => ` ${l}`));
100
+ }
101
+ if (agent.conversationIdleTimeout !== undefined) {
102
+ lines.push(` conversationIdleTimeout: ${quote(agent.conversationIdleTimeout)},`);
103
+ }
104
+ if (agent.a2aStreaming !== undefined)
105
+ lines.push(` a2aStreaming: ${String(agent.a2aStreaming)},`);
106
+ if (agent.a2aCreateRecordEnabled !== undefined)
107
+ lines.push(` a2aCreateRecordEnabled: ${String(agent.a2aCreateRecordEnabled)},`);
108
+ if (agent.a2aSkills !== undefined && agent.a2aSkills.length > 0) {
109
+ lines.push(" a2aSkills: [");
110
+ for (const skill of agent.a2aSkills) {
111
+ lines.push(...printA2ASkill(skill).map((l) => ` ${l}`));
112
+ }
113
+ lines.push(" ],");
60
114
  }
61
115
  if (agent.tools.length > 0) {
62
116
  lines.push(" tools: [");
63
117
  for (const tool of agent.tools) {
64
- lines.push(...printTool(tool, appRefName).map((l) => ` ${l}`));
118
+ lines.push(...printTool(tool, appRefName, crossOrg, opts.foreignAppRefNames, opts.foreignElementRefNames).map((l) => ` ${l}`));
65
119
  }
66
120
  lines.push(" ],");
67
121
  }
@@ -79,14 +133,31 @@ function safeMember(name) {
79
133
  function safeKey(name) {
80
134
  return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) ? name : quote(name);
81
135
  }
82
- function printSkillRefToken(ref, appRefName) {
136
+ /**
137
+ * A skill reference line, INCLUDING its trailing comma (and, cross-org, a
138
+ * trailing TODO comment) — the comma must precede the comment or it gets
139
+ * swallowed into commented-out text and silently drops the array separator,
140
+ * same failure mode as a manually-mistyped `,/ TODO` comment marker.
141
+ */
142
+ function printSkillRefToken(ref, appRefName, crossOrg) {
83
143
  if (ref.kind === "self")
84
- return `catalog.${appRefName}.skills.${ref.key}`;
144
+ return `catalog.${appRefName}.skills.${ref.key},`;
145
+ if (ref.kind === "unresolved") {
146
+ // No name, no data block - nothing to build a real token from. Round-trips
147
+ // the exact raw id via `unresolvedId`, the same escape ApprovalChainRef
148
+ // already uses for its own no-data-lookup case. `name` is required by
149
+ // SkillRef's shape even though there's no real display name to put there;
150
+ // the raw id fills both slots, same as `refName`.
151
+ return `{ __kind: "skill", refName: ${quote(ref.id)}, name: ${quote(ref.id)}, unresolvedId: ${quote(ref.id)} }, // TODO: this skill isn't resolvable from the export (no name, no data block) - identify it manually and replace with a real catalog.<app>.skills.<key> token`;
152
+ }
85
153
  // The foreign app's catalog may not exist in this workspace — a literal
86
154
  // token compiles and deploys; swap for a catalog token when available.
87
- return `{ __kind: "skill", refName: ${quote(ref.name)}, name: ${quote(ref.name)} }`;
155
+ const todo = crossOrg
156
+ ? ` // TODO: cross-org clone — "${ref.name}" was resolved in the SOURCE org; verify it exists (with this name) in the destination org`
157
+ : "";
158
+ return `{ __kind: "skill", refName: ${quote(ref.name)}, name: ${quote(ref.name)} },${todo}`;
88
159
  }
89
- function printSkillAccess(access, appRefName) {
160
+ function printSkillAccess(access, appRefName, crossOrg) {
90
161
  const hasPreloaded = access.preloadedSkills !== undefined && access.preloadedSkills.length > 0;
91
162
  if (access.mode !== "CUSTOM" && !hasPreloaded) {
92
163
  return [`skillAccess: { mode: ${quote(access.mode)} },`];
@@ -95,19 +166,89 @@ function printSkillAccess(access, appRefName) {
95
166
  if (access.mode === "CUSTOM") {
96
167
  lines.push(` skills: [`);
97
168
  for (const ref of access.skills)
98
- lines.push(` ${printSkillRefToken(ref, appRefName)},`);
169
+ lines.push(` ${printSkillRefToken(ref, appRefName, crossOrg)}`);
99
170
  lines.push(` ],`);
100
171
  }
101
172
  if (hasPreloaded) {
102
173
  lines.push(` preloadedSkills: [`);
103
174
  for (const ref of access.preloadedSkills)
104
- lines.push(` ${printSkillRefToken(ref, appRefName)},`);
175
+ lines.push(` ${printSkillRefToken(ref, appRefName, crossOrg)}`);
105
176
  lines.push(` ],`);
106
177
  }
107
178
  lines.push(`},`);
108
179
  return lines;
109
180
  }
110
- function printTool(tool, appRefName) {
181
+ /** `AgentToolRunAs` is opaque — `agentFromTf` only ever produces `{ currentUser: true }` today. */
182
+ function printRunAs(runAs) {
183
+ if (runAs["currentUser"] !== undefined)
184
+ return `{ currentUser: ${String(runAs["currentUser"])} }`;
185
+ if (runAs["publisher"] !== undefined)
186
+ return `{ publisher: ${String(runAs["publisher"])} }`;
187
+ const serviceAccount = runAs["serviceAccount"];
188
+ if (serviceAccount?.serviceAccount !== undefined) {
189
+ return `{ serviceAccount: { serviceAccount: ${quote(String(serviceAccount.serviceAccount))} } }`;
190
+ }
191
+ return JSON.stringify(runAs);
192
+ }
193
+ function printAgentAuthentication(auth) {
194
+ const { jwt } = auth;
195
+ const lines = [
196
+ `agentAuthentication: {`,
197
+ ` jwt: {`,
198
+ ` enabled: ${String(jwt.enabled)},`,
199
+ ` headerName: ${quote(jwt.headerName)},`,
200
+ ` emailAddressClaimName: ${quote(jwt.emailAddressClaimName)},`,
201
+ ];
202
+ const keySource = "jwks" in jwt.keySource
203
+ ? `{ jwks: { jwksUrl: ${quote(jwt.keySource.jwks.jwksUrl)} } }`
204
+ : `{ plainText: { plainTextKeyValuePem: ${quote(jwt.keySource.plainText.plainTextKeyValuePem)} } }`;
205
+ lines.push(` keySource: ${keySource},`);
206
+ if (jwt.requiredClaims !== undefined && jwt.requiredClaims.length > 0) {
207
+ lines.push(` requiredClaims: [`);
208
+ for (const claim of jwt.requiredClaims) {
209
+ lines.push(` { claimName: ${quote(claim.claimName)}, acceptableValues: [${claim.acceptableValues.map(quote).join(", ")}] },`);
210
+ }
211
+ lines.push(` ],`);
212
+ }
213
+ lines.push(` },`);
214
+ lines.push(`},`);
215
+ return lines;
216
+ }
217
+ /**
218
+ * One A2A skill → its object-literal lines, same multi-line style `printTool`
219
+ * uses for factory calls — pure metadata (no catalog tokens), same shape
220
+ * `serializeA2ASkill` (build.ts) expects back.
221
+ */
222
+ function printA2ASkill(skill) {
223
+ const lines = ["{"];
224
+ lines.push(` name: ${quote(skill.name)},`);
225
+ lines.push(` description: ${quote(skill.description)},`);
226
+ if (skill.tags !== undefined && skill.tags.length > 0)
227
+ lines.push(` tags: [${skill.tags.map(quote).join(", ")}],`);
228
+ if (skill.examples !== undefined && skill.examples.length > 0)
229
+ lines.push(` examples: [${skill.examples.map(quote).join(", ")}],`);
230
+ if (skill.inputModes !== undefined && skill.inputModes.length > 0)
231
+ lines.push(` inputModes: [${skill.inputModes.map(quote).join(", ")}],`);
232
+ if (skill.outputModes !== undefined && skill.outputModes.length > 0)
233
+ lines.push(` outputModes: [${skill.outputModes.map(quote).join(", ")}],`);
234
+ lines.push("},");
235
+ return lines;
236
+ }
237
+ function fieldOwnerRef(tool, appRefName, foreignAppRefNames, foreignElementRefNames) {
238
+ if (tool.target === undefined || tool.target.kind === "self")
239
+ return { kind: "catalog", expr: `catalog.${appRefName}` };
240
+ if (tool.target.kind === "foreignApp") {
241
+ const foreignRefName = foreignAppRefNames?.get(tool.target.name);
242
+ return foreignRefName !== undefined
243
+ ? { kind: "catalog", expr: `catalog.${foreignRefName}` }
244
+ : { kind: "raw", entityType: "app", name: tool.target.name };
245
+ }
246
+ const foreignRefName = foreignElementRefNames?.get(tool.target.name);
247
+ return foreignRefName !== undefined
248
+ ? { kind: "catalog", expr: `catalog.${foreignRefName}` }
249
+ : { kind: "raw", entityType: "element", name: tool.target.name };
250
+ }
251
+ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElementRefNames) {
111
252
  const factory = TOOL_FACTORY_BY_TYPE_KEY[tool.typeKey] ?? "agentSearchAspect";
112
253
  const lines = [`${factory}({`];
113
254
  lines.push(` name: ${quote(tool.name)},`);
@@ -149,26 +290,110 @@ function printTool(tool, appRefName) {
149
290
  lines.push(` aspect: catalog.${appRefName},`);
150
291
  }
151
292
  else if (tool.target !== undefined && tool.target.kind === "foreignApp") {
152
- // The foreign app's catalog may not exist in this workspace — a literal
153
- // token compiles and deploys; swap for a catalog token when available.
154
- lines.push(` aspect: { __kind: "app", refName: ${quote(tool.target.name)}, name: ${quote(tool.target.name)} },`);
293
+ const foreignRefName = foreignAppRefNames?.get(tool.target.name);
294
+ if (foreignRefName !== undefined) {
295
+ // The dependency is already pulled into this workspace (board issue
296
+ // #40) — a typed token, not a stub, so tsc catches drift if the
297
+ // foreign app's fields change out from under this tool.
298
+ lines.push(` aspect: catalog.${foreignRefName},`);
299
+ }
300
+ else {
301
+ // The foreign app's catalog may not exist in this workspace — a literal
302
+ // token compiles and deploys; swap for a catalog token when available
303
+ // (\`edk pull app\` reports missing dependencies like this one).
304
+ const todo = crossOrg
305
+ ? ` // TODO: cross-org clone — "${tool.target.name}" was resolved in the SOURCE org; verify it exists (with this name) in the destination org`
306
+ : "";
307
+ lines.push(` aspect: { __kind: "app", refName: ${quote(tool.target.name)}, name: ${quote(tool.target.name)} },${todo}`);
308
+ }
309
+ }
310
+ else if (tool.target !== undefined && tool.target.kind === "foreignElement") {
311
+ // Board issue #42: an aspect target can be an element, not just an app —
312
+ // same treatment as foreignApp, distinct stub `__kind`.
313
+ const foreignRefName = foreignElementRefNames?.get(tool.target.name);
314
+ if (foreignRefName !== undefined) {
315
+ lines.push(` aspect: catalog.${foreignRefName},`);
316
+ }
317
+ else {
318
+ const todo = crossOrg
319
+ ? ` // TODO: cross-org clone — "${tool.target.name}" was resolved in the SOURCE org; verify it exists (with this name) in the destination org`
320
+ : "";
321
+ lines.push(` aspect: { __kind: "element", refName: ${quote(tool.target.name)}, name: ${quote(tool.target.name)} },${todo}`);
322
+ }
155
323
  }
156
- if (tool.typeKey === "searchAspect") {
324
+ if (tool.typeKey === "searchAspect" || tool.typeKey === "searchTable") {
157
325
  lines.push(` queryDescription: ${quote(tool.queryDescription ?? "")},`);
158
326
  if (tool.limit !== undefined)
159
327
  lines.push(` limit: ${tool.limit},`);
160
328
  }
329
+ if (tool.typeKey === "updateRecord" && tool.handleDescription !== undefined) {
330
+ lines.push(` handleDescription: ${quote(tool.handleDescription)},`);
331
+ }
332
+ if (tool.typeKey === "searchTable" && tool.searchTableId !== undefined) {
333
+ // Always a raw platform id — see NormalizedAgentTool.searchTableId's
334
+ // comment; ei never exports a resolvable reference for this attribute.
335
+ lines.push(` table: ${quote(tool.searchTableId)}, // TODO: raw search table id - ei's export never resolves this to a reference`);
336
+ }
161
337
  if (tool.fields !== undefined && tool.fields.length > 0) {
338
+ const owner = fieldOwnerRef(tool, appRefName, foreignAppRefNames, foreignElementRefNames);
162
339
  lines.push(" fields: [");
163
340
  for (const f of tool.fields) {
164
- const parts = [`field: catalog.${appRefName}.fields.${f.key}`];
341
+ // A foreign/out-of-scope aspect's field has no field resource ei can
342
+ // reference — it falls back to a bare platform id (board issue #169);
343
+ // print the raw-id shape (AgentSearchRawIdField/AgentRecordRawIdField)
344
+ // instead of a catalog token.
345
+ const isRaw = f.key === undefined;
346
+ // A field always belongs to the tool's TARGET, not necessarily the
347
+ // owning app — `owner` (self/foreign-resolved/foreign-unresolved)
348
+ // mirrors the `aspect:` resolution just above.
349
+ const parts = isRaw
350
+ ? [`fieldId: ${quote(f.rawFieldId ?? "")}`]
351
+ : owner.kind === "catalog"
352
+ ? [`field: ${owner.expr}.fields.${f.key}`]
353
+ : [
354
+ `field: { __kind: "field", refName: ${quote(f.key)}, name: ${quote(f.name ?? f.key)}, fieldType: "TEXT", ` +
355
+ `parent: ${quote(owner.name)}, parentKind: ${quote(owner.entityType)}, parentName: ${quote(owner.name)} }`,
356
+ ];
165
357
  if (f.name !== undefined)
166
358
  parts.push(`name: ${quote(f.name)}`);
167
- if (f.description !== undefined)
168
- parts.push(`description: ${quote(f.description)}`);
359
+ // Always emit description (backfill "") so pulled source satisfies
360
+ // AgentSearchField / AgentRecordField's required description.
361
+ parts.push(`description: ${quote(f.description ?? "")}`);
169
362
  if (f.required !== undefined)
170
363
  parts.push(`required: ${f.required}`);
171
- lines.push(` { ${parts.join(", ")} },`);
364
+ const todo = isRaw
365
+ ? " // TODO: raw platform field id - the field belongs to a foreign/out-of-scope aspect ei can't resolve to a reference"
366
+ : owner.kind === "raw"
367
+ ? ` // TODO: foreign field — type unconfirmed (ei's elementum_field data source doesn't expose it) and refName is a best-effort guess; verify against "${owner.name}"`
368
+ : "";
369
+ lines.push(` { ${parts.join(", ")} },${todo}`);
370
+ }
371
+ lines.push(" ],");
372
+ }
373
+ // searchTable's own field shapes: field_id is always a raw platform id
374
+ // (see NormalizedSearchTableField's comment), so these print as `fieldId:`
375
+ // literals rather than `field: catalog....` tokens.
376
+ if (tool.searchTableFields !== undefined && tool.searchTableFields.length > 0) {
377
+ lines.push(" fields: [");
378
+ for (const f of tool.searchTableFields) {
379
+ const parts = [`fieldId: ${quote(f.fieldId)}`];
380
+ if (f.name !== undefined)
381
+ parts.push(`name: ${quote(f.name)}`);
382
+ if (f.description !== undefined)
383
+ parts.push(`description: ${quote(f.description)}`);
384
+ lines.push(` { ${parts.join(", ")} }, // TODO: raw search table field id - ei's export never resolves this to a reference`);
385
+ }
386
+ lines.push(" ],");
387
+ }
388
+ if (tool.returnFields !== undefined && tool.returnFields.length > 0) {
389
+ lines.push(" returnFields: [");
390
+ for (const f of tool.returnFields) {
391
+ const parts = [`fieldId: ${quote(f.fieldId)}`];
392
+ if (f.name !== undefined)
393
+ parts.push(`name: ${quote(f.name)}`);
394
+ if (f.displayName !== undefined)
395
+ parts.push(`displayName: ${quote(f.displayName)}`);
396
+ lines.push(` { ${parts.join(", ")} }, // TODO: raw search table field id - ei's export never resolves this to a reference`);
172
397
  }
173
398
  lines.push(" ],");
174
399
  }
@@ -1,20 +1,33 @@
1
1
  /**
2
2
  * Agent extraction (M3, plan §4.3): `agentFromTf` turns an
3
3
  * `elementum_agent` block + its tool blocks (delegated to
4
- * `entities/agent-tool/from-tf.ts`) into the normalized shape
5
- * `printAgentV2` consumes. Platform ids come only from the stream's import
6
- * blocks and stay data-side — they never reach printed source.
4
+ * `entities/agent-tool/from-tf.ts`) + its a2a-skill blocks (delegated to
5
+ * `entities/agent-a2a-skill/from-tf.ts`, issue #68) into the normalized
6
+ * shape `printAgentV2` consumes. Platform ids come only from the stream's
7
+ * import blocks and stay data-side — they never reach printed source.
7
8
  */
8
9
  import { type FromTfContext } from "../../engine/pull/context.js";
9
10
  import { type TfBlock } from "../../engine/tf/index.js";
11
+ import { type NormalizedA2ASkill } from "../agent-a2a-skill/from-tf.js";
10
12
  import { type NormalizedAgentTool } from "../agent-tool/from-tf.js";
11
- /** A resolved skill reference: this app's own skill (by catalog key) or a foreign app's (by name only). */
13
+ import type { AgentAuthentication } from "./build.js";
14
+ import type { AgentToolRunAs } from "./tools.js";
15
+ /**
16
+ * A resolved skill reference: this app's own skill (by catalog key), a
17
+ * foreign app's (by name only), or a raw platform id the export carries with
18
+ * no way to resolve it further at all — confirmed live: a `skill_ids` entry
19
+ * can be a bare UUID literal with neither a resource ref into this stream
20
+ * nor a `data.elementum_agentic_skill` block backing it anywhere in the export.
21
+ */
12
22
  export type NormalizedSkillRef = {
13
23
  readonly kind: "self";
14
24
  readonly key: string;
15
25
  } | {
16
26
  readonly kind: "foreign";
17
27
  readonly name: string;
28
+ } | {
29
+ readonly kind: "unresolved";
30
+ readonly id: string;
18
31
  };
19
32
  export type NormalizedSkillAccess = {
20
33
  readonly mode: "NONE" | "ALL" | "ALL_APP";
@@ -32,10 +45,16 @@ export interface NormalizedAgent {
32
45
  readonly instructions: string;
33
46
  readonly firstMessage?: string;
34
47
  readonly maxLength?: number;
35
- /** org.ts `connectors` bag key (the data label's tsLabel image), when pinned. */
48
+ /** org.ts `aiProviders.<provider>.models.<model>` compound key ("<provider>.<model>"), when pinned. */
36
49
  readonly connectorKey?: string;
37
50
  readonly skillAccess?: NormalizedSkillAccess;
51
+ readonly runAs?: AgentToolRunAs;
52
+ readonly agentAuthentication?: AgentAuthentication;
53
+ readonly conversationIdleTimeout?: string;
54
+ readonly a2aStreaming?: boolean;
55
+ readonly a2aCreateRecordEnabled?: boolean;
38
56
  readonly tools: readonly NormalizedAgentTool[];
57
+ readonly a2aSkills?: readonly NormalizedA2ASkill[];
39
58
  }
40
59
  export interface AgentFromTfResult {
41
60
  readonly agent?: NormalizedAgent;
@@ -43,8 +62,9 @@ export interface AgentFromTfResult {
43
62
  readonly skippedReason?: string;
44
63
  }
45
64
  /**
46
- * The `elementum_agent` block + its tool blocks → the normalized agent.
47
- * Tool blocks belonging to OTHER agents are skipped with a diagnostic (the
48
- * caller partitions per-agent by agent_id, but stays defensive).
65
+ * The `elementum_agent` block + its tool blocks + its a2a-skill blocks →
66
+ * the normalized agent. Blocks belonging to OTHER agents are skipped with a
67
+ * diagnostic (the caller partitions per-agent by agent_id, but stays
68
+ * defensive).
49
69
  */
50
- export declare function agentFromTf(agentBlock: TfBlock, toolBlocks: readonly TfBlock[], appLabel: string, ctx: FromTfContext): AgentFromTfResult;
70
+ export declare function agentFromTf(agentBlock: TfBlock, toolBlocks: readonly TfBlock[], appLabel: string, _appRefName: string, ctx: FromTfContext, a2aSkillBlocks?: readonly TfBlock[]): AgentFromTfResult;