@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.
- package/README.md +166 -34
- package/dist-sdk/src/catalog/factories.js +18 -2
- package/dist-sdk/src/catalog/from-authoring.js +13 -1
- package/dist-sdk/src/catalog/org.js +51 -44
- package/dist-sdk/src/catalog/token.js +4 -0
- package/dist-sdk/src/catalog/types.d.ts +15 -0
- package/dist-sdk/src/core/types/app.d.ts +14 -8
- package/dist-sdk/src/engine/build/context.d.ts +40 -0
- package/dist-sdk/src/engine/build/context.js +11 -1
- package/dist-sdk/src/engine/tf/index.d.ts +2 -2
- package/dist-sdk/src/engine/tf/index.js +2 -2
- package/dist-sdk/src/engine/tf/labels.d.ts +29 -20
- package/dist-sdk/src/engine/tf/labels.js +32 -28
- package/dist-sdk/src/engine/tf/parse.d.ts +15 -0
- package/dist-sdk/src/engine/tf/parse.js +162 -0
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +19 -1
- package/dist-sdk/src/entities/access-policy/from-tf.js +4 -6
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +12 -5
- package/dist-sdk/src/entities/access-policy/to-tf.js +21 -6
- package/dist-sdk/src/entities/agent/build.d.ts +2 -0
- package/dist-sdk/src/entities/agent/build.js +1 -0
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +60 -2
- package/dist-sdk/src/entities/agent/from-tf.d.ts +12 -7
- package/dist-sdk/src/entities/agent/from-tf.js +22 -15
- package/dist-sdk/src/entities/agent/module.js +7 -3
- package/dist-sdk/src/entities/agent/to-tf.d.ts +46 -1
- package/dist-sdk/src/entities/agent/to-tf.js +102 -8
- package/dist-sdk/src/entities/agent-a2a-skill/from-tf.d.ts +17 -0
- package/dist-sdk/src/entities/agent-a2a-skill/from-tf.js +64 -0
- package/dist-sdk/src/entities/agent-a2a-skill/module.d.ts +4 -0
- package/dist-sdk/src/entities/agent-a2a-skill/module.js +14 -0
- package/dist-sdk/src/entities/agent-a2a-skill/to-tf.d.ts +40 -0
- package/dist-sdk/src/entities/agent-a2a-skill/to-tf.js +47 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +7 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +86 -26
- package/dist-sdk/src/entities/app/build.d.ts +35 -7
- package/dist-sdk/src/entities/app/build.js +19 -8
- package/dist-sdk/src/entities/app/from-tf.js +0 -7
- package/dist-sdk/src/entities/app/module.js +1 -0
- package/dist-sdk/src/entities/app/to-tf.js +13 -1
- package/dist-sdk/src/entities/automation/build.js +14 -6
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +27 -4
- package/dist-sdk/src/entities/automation/filter.d.ts +22 -0
- package/dist-sdk/src/entities/automation/filter.js +42 -1
- package/dist-sdk/src/entities/automation/from-tf.js +127 -11
- package/dist-sdk/src/entities/automation/to-tf.js +176 -18
- package/dist-sdk/src/entities/element/build.d.ts +26 -8
- package/dist-sdk/src/entities/element/build.js +44 -3
- package/dist-sdk/src/entities/element/from-tf.js +10 -11
- package/dist-sdk/src/entities/element/module.js +1 -0
- package/dist-sdk/src/entities/element/to-tf.js +5 -0
- package/dist-sdk/src/entities/field/build.d.ts +9 -5
- package/dist-sdk/src/entities/field/calc/runtime.js +2 -2
- package/dist-sdk/src/entities/field/from-tf.js +10 -10
- package/dist-sdk/src/entities/field/to-tf.d.ts +35 -18
- package/dist-sdk/src/entities/field/to-tf.js +110 -6
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -0
- package/dist-sdk/src/entities/shared/tool-field-ref.js +15 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +97 -8
- package/dist-sdk/src/entities/skill/module.js +1 -0
- package/dist-sdk/src/entities/skill/to-tf.d.ts +26 -0
- package/dist-sdk/src/entities/skill/to-tf.js +63 -3
- package/dist-sdk/src/entities/skill/tools.d.ts +12 -5
- package/dist-sdk/src/entities/skill/tools.js +26 -1
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +19 -2
- package/dist-sdk/src/entities/skill-tool/from-tf.js +97 -8
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +11 -1
- package/dist-sdk/src/entities/skill-tool/to-tf.js +143 -27
- package/dist-sdk/src/entities/skill-tool/types.d.ts +5 -7
- package/dist-sdk/src/entities/skill-tool/types.js +47 -11
- package/dist-sdk/src/entities/view/to-tf.js +6 -0
- package/dist-sdk/src/graph/modules.js +2 -0
- package/dist-sdk/src/graph/types.d.ts +22 -2
- package/package.json +12 -7
|
@@ -14,10 +14,67 @@
|
|
|
14
14
|
* aren't authored yet, so there's nothing to emit for them.
|
|
15
15
|
*/
|
|
16
16
|
import { EntityTfError } from "../../engine/entity.js";
|
|
17
|
-
import { appScopedResourceLabel, expr, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
17
|
+
import { appScopedResourceLabel, expr, sanitizeName, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
18
18
|
import { skillToolToTf } from "../skill-tool/to-tf.js";
|
|
19
19
|
import { APP_RESOURCE_TYPE } from "../app/module.js";
|
|
20
20
|
import { SKILL_RESOURCE_TYPE } from "./module.js";
|
|
21
|
+
function toSortableSkills(entities) {
|
|
22
|
+
const out = [];
|
|
23
|
+
for (const entity of entities) {
|
|
24
|
+
if (entity.kind !== "skill")
|
|
25
|
+
continue;
|
|
26
|
+
const payload = entity.payload;
|
|
27
|
+
out.push({ refName: entity.refName, name: payload?.skill?.name ?? "", tools: payload?.tools ?? [] });
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Mirrors ei's cross-skill tool-name disambiguation (`cmd/elementum/export/
|
|
33
|
+
* imports.go`'s `skillNames`/`toolNames` counting maps) — a same-app,
|
|
34
|
+
* same-named tool on two different skills is not a collision on the
|
|
35
|
+
* platform: ei's exporter walks `app.Skills` (each skill's tools in turn)
|
|
36
|
+
* and gives the first occurrence of a sanitized tool name the bare label,
|
|
37
|
+
* each later occurrence `_1`, `_2`, … Board issue #310's live capture
|
|
38
|
+
* (2026-08-18, against a deliberately-collided app) confirmed the walk
|
|
39
|
+
* order is ascending by the skill's display NAME — not creation order, not
|
|
40
|
+
* authoring-file order. Ordering of tools WITHIN one skill wasn't
|
|
41
|
+
* observable live (each capture skill carried only one tool); authored
|
|
42
|
+
* array order is assumed there pending a capture that can confirm it.
|
|
43
|
+
*
|
|
44
|
+
* Returns suffixes ("" for the first occurrence, "_1", "_2", … after)
|
|
45
|
+
* keyed by `${skillRefName}#${toolIndex}` — the tool's position in its own
|
|
46
|
+
* skill's authored `tools` array, NOT a global index.
|
|
47
|
+
*/
|
|
48
|
+
export function computeToolLabelSuffixes(siblingSkills) {
|
|
49
|
+
// refName tie-breaker (stable, unique per app): two skills can't share a
|
|
50
|
+
// display name in practice — ei's exporter has never demonstrated a tie —
|
|
51
|
+
// but sort() is not guaranteed stable across engines, so a same-name pair
|
|
52
|
+
// could otherwise silently swap which one gets the bare label between
|
|
53
|
+
// runs. refName (the authoring filename) is always unique within an app,
|
|
54
|
+
// making the overall ordering deterministic even in that case.
|
|
55
|
+
const sorted = toSortableSkills(siblingSkills).sort((a, b) => {
|
|
56
|
+
if (a.name < b.name)
|
|
57
|
+
return -1;
|
|
58
|
+
if (a.name > b.name)
|
|
59
|
+
return 1;
|
|
60
|
+
return a.refName < b.refName ? -1 : a.refName > b.refName ? 1 : 0;
|
|
61
|
+
});
|
|
62
|
+
const counts = new Map();
|
|
63
|
+
const suffixes = new Map();
|
|
64
|
+
for (const skill of sorted) {
|
|
65
|
+
skill.tools.forEach((entry, index) => {
|
|
66
|
+
const typeKey = Object.keys(entry)[0];
|
|
67
|
+
if (typeKey === undefined)
|
|
68
|
+
return;
|
|
69
|
+
const inner = entry[typeKey];
|
|
70
|
+
const base = sanitizeName(inner?.name ?? "");
|
|
71
|
+
const count = counts.get(base) ?? 0;
|
|
72
|
+
counts.set(base, count + 1);
|
|
73
|
+
suffixes.set(`${skill.refName}#${index}`, count > 0 ? `_${count}` : "");
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return suffixes;
|
|
77
|
+
}
|
|
21
78
|
/** `elementum_agentic_skill` + one tool resource per implemented tool, in the platform's dialect. */
|
|
22
79
|
export function skillToTf(entity, ctx) {
|
|
23
80
|
if (entity.kind !== "skill") {
|
|
@@ -42,18 +99,21 @@ export function skillToTf(entity, ctx) {
|
|
|
42
99
|
if (elementum.properties !== undefined) {
|
|
43
100
|
attrs["properties"] = JSON.stringify(elementum.properties);
|
|
44
101
|
}
|
|
102
|
+
const toolLabelSuffixes = computeToolLabelSuffixes(ctx.siblingEntities ?? [entity]);
|
|
45
103
|
const blocks = [{ kind: "resource", type: SKILL_RESOURCE_TYPE, label: tfLabel, attrs }];
|
|
46
|
-
|
|
104
|
+
(payload.tools ?? []).forEach((entry, index) => {
|
|
47
105
|
const tool = skillToolToTf(entry, {
|
|
48
106
|
appRefName: ctx.appRefName,
|
|
49
107
|
appTfLabel: ctx.appTfLabel,
|
|
50
108
|
skillTfLabel: tfLabel,
|
|
109
|
+
labelSuffix: toolLabelSuffixes.get(`${entity.refName}#${index}`) ?? "",
|
|
51
110
|
foreignAppRef: (l, n) => ctx.orgRefs.foreignApp(l, n),
|
|
52
111
|
foreignElementRef: (l, n) => ctx.orgRefs.foreignElement(l, n),
|
|
112
|
+
foreignFieldRef: (t, l, o, n) => ctx.orgRefs.foreignField(t, l, o, n),
|
|
53
113
|
diagnostics: ctx.diagnostics,
|
|
54
114
|
});
|
|
55
115
|
if (tool !== undefined)
|
|
56
116
|
blocks.push(tool.block);
|
|
57
|
-
}
|
|
117
|
+
});
|
|
58
118
|
return { blocks, address: `${SKILL_RESOURCE_TYPE}.${tfLabel}` };
|
|
59
119
|
}
|
|
@@ -9,7 +9,8 @@
|
|
|
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, AspectRef,
|
|
12
|
+
import type { AgentRef, AspectRef, AutomationCatalogRef, FieldRef, SearchTableRef } from "../../catalog/index.js";
|
|
13
|
+
import type { AgentToolRunAs, RunAutomationToolV2 } from "../agent/tools.js";
|
|
13
14
|
/** A handle-form skill tool: an `AgenticSkillToolCreateInput` with ref tokens. */
|
|
14
15
|
export type SkillTool = Record<string, unknown>;
|
|
15
16
|
export type SkillToolStatus = "ACTIVE" | "INACTIVE";
|
|
@@ -52,11 +53,17 @@ interface CommonToolOptions {
|
|
|
52
53
|
readonly description: string;
|
|
53
54
|
readonly status?: SkillToolStatus;
|
|
54
55
|
readonly startMessage?: string;
|
|
56
|
+
readonly runAs?: AgentToolRunAs;
|
|
55
57
|
}
|
|
56
|
-
export
|
|
57
|
-
readonly
|
|
58
|
-
}
|
|
59
|
-
|
|
58
|
+
export type AutomationToolV2<A extends AutomationCatalogRef = AutomationCatalogRef> = RunAutomationToolV2<A> & {
|
|
59
|
+
readonly status?: SkillToolStatus;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Run an on-demand automation with input/output record keys constrained by
|
|
63
|
+
* the selected automation's generated catalog type. Required trigger params
|
|
64
|
+
* must be mapped and output keys autocomplete, matching agentRunAutomation.
|
|
65
|
+
*/
|
|
66
|
+
export declare function skillAutomation<A extends AutomationCatalogRef>(opts: AutomationToolV2<A>): SkillTool;
|
|
60
67
|
export interface SkillSearchAspectToolV2 extends CommonToolOptions {
|
|
61
68
|
readonly aspect: AspectRef;
|
|
62
69
|
readonly queryDescription: string;
|
|
@@ -12,6 +12,7 @@ function common(opts) {
|
|
|
12
12
|
description: opts.description,
|
|
13
13
|
status: opts.status ?? "ACTIVE",
|
|
14
14
|
...(opts.startMessage !== undefined ? { startMessage: opts.startMessage } : {}),
|
|
15
|
+
...(opts.runAs !== undefined ? { runAs: opts.runAs } : {}),
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
function searchFieldToken(f) {
|
|
@@ -49,8 +50,32 @@ function recordFieldToken(f) {
|
|
|
49
50
|
...(f.defaultValue !== undefined ? { defaultValue: f.defaultValue } : {}),
|
|
50
51
|
};
|
|
51
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Run an on-demand automation with input/output record keys constrained by
|
|
55
|
+
* the selected automation's generated catalog type. Required trigger params
|
|
56
|
+
* must be mapped and output keys autocomplete, matching agentRunAutomation.
|
|
57
|
+
*/
|
|
52
58
|
export function skillAutomation(opts) {
|
|
53
|
-
|
|
59
|
+
const inputEntries = Object.entries((opts.inputs ?? {}));
|
|
60
|
+
const inputs = inputEntries.map(([parameterName, spec]) => ({
|
|
61
|
+
parameterName,
|
|
62
|
+
displayName: spec.name ?? parameterName,
|
|
63
|
+
description: spec.description,
|
|
64
|
+
...(spec.required !== undefined ? { required: spec.required } : {}),
|
|
65
|
+
}));
|
|
66
|
+
const outputEntries = Object.entries((opts.outputs ?? {}));
|
|
67
|
+
const outputs = outputEntries.map(([workflowPropertyName, spec]) => ({
|
|
68
|
+
workflowPropertyName,
|
|
69
|
+
displayName: spec?.name ?? workflowPropertyName,
|
|
70
|
+
}));
|
|
71
|
+
return {
|
|
72
|
+
automation: {
|
|
73
|
+
...common(opts),
|
|
74
|
+
automationId: opts.automation,
|
|
75
|
+
...(inputs.length > 0 ? { inputs } : {}),
|
|
76
|
+
...(outputs.length > 0 ? { outputs } : {}),
|
|
77
|
+
},
|
|
78
|
+
};
|
|
54
79
|
}
|
|
55
80
|
export function skillSearchAspect(opts) {
|
|
56
81
|
return {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { type FromTfContext } from "../../engine/pull/context.js";
|
|
8
8
|
import { type TfBlock } from "../../engine/tf/index.js";
|
|
9
|
+
import type { AgentToolRunAs } from "../agent/tools.js";
|
|
9
10
|
export interface NormalizedSkillToolField {
|
|
10
11
|
/** The field's bag key in the TARGET aspect's `fields: {}` (bijective image of its label). Mutually exclusive with `rawFieldId`. */
|
|
11
12
|
readonly key?: string;
|
|
@@ -32,16 +33,32 @@ export type NormalizedSkillToolTarget = {
|
|
|
32
33
|
readonly name: string;
|
|
33
34
|
};
|
|
34
35
|
export interface NormalizedSkillTool {
|
|
35
|
-
readonly typeKey: "createRecord" | "searchAspect";
|
|
36
|
+
readonly typeKey: "createRecord" | "searchAspect" | "updateRecord" | "runAgent" | "automation";
|
|
36
37
|
readonly name: string;
|
|
37
38
|
readonly description: string;
|
|
38
39
|
/** Present only when it differs from the default ("ACTIVE"). */
|
|
39
40
|
readonly status?: "INACTIVE";
|
|
40
41
|
readonly startMessage?: string;
|
|
41
|
-
readonly target
|
|
42
|
+
readonly target?: NormalizedSkillToolTarget;
|
|
42
43
|
readonly fields?: readonly NormalizedSkillToolField[];
|
|
43
44
|
readonly queryDescription?: string;
|
|
44
45
|
readonly limit?: number;
|
|
46
|
+
readonly handleDescription?: string;
|
|
47
|
+
readonly targetAgentKey?: string;
|
|
48
|
+
readonly workerTaskPrompt?: string;
|
|
49
|
+
readonly automationKey?: string;
|
|
50
|
+
readonly inputs?: readonly {
|
|
51
|
+
readonly parameterName: string;
|
|
52
|
+
readonly displayName?: string;
|
|
53
|
+
readonly description?: string;
|
|
54
|
+
readonly required?: boolean;
|
|
55
|
+
}[];
|
|
56
|
+
readonly outputs?: readonly {
|
|
57
|
+
readonly workflowPropertyName: string;
|
|
58
|
+
readonly displayName?: string;
|
|
59
|
+
readonly description?: string;
|
|
60
|
+
}[];
|
|
61
|
+
readonly runAs?: AgentToolRunAs;
|
|
45
62
|
}
|
|
46
63
|
export interface SkillToolOwner {
|
|
47
64
|
/** The owning app's resource type + tfLabel. */
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { EntityTfError } from "../../engine/entity.js";
|
|
8
8
|
import { optionalString, resourceRefLabel } from "../../engine/pull/context.js";
|
|
9
|
-
import { isTfExpr } from "../../engine/tf/index.js";
|
|
9
|
+
import { isTfExpr, scopedLabelToBagKey } from "../../engine/tf/index.js";
|
|
10
10
|
import { resolveToolFieldKey } from "../shared/tool-field-ref.js";
|
|
11
11
|
import { KNOWN_SKILL_TOOL_ATTRS, SKILL_TOOL_SUB_TYPE_BY_RESOURCE, UNAUTHORABLE_SKILL_TOOL_ATTRS, } from "./types.js";
|
|
12
12
|
/**
|
|
@@ -43,6 +43,96 @@ export function skillToolFromTf(block, owner, ctx) {
|
|
|
43
43
|
ctx.diagnostics.push(`${where}: skill_id does not reference ${owner.skillType}.${owner.skillLabel}; skipped`);
|
|
44
44
|
return undefined;
|
|
45
45
|
}
|
|
46
|
+
const startMessage = optionalString(attrs, "start_message", where, ctx);
|
|
47
|
+
const status = optionalString(attrs, "status", where, ctx);
|
|
48
|
+
let runAs;
|
|
49
|
+
const runAsValue = optionalString(attrs, "run_as", where, ctx);
|
|
50
|
+
if (runAsValue === "current_user")
|
|
51
|
+
runAs = { currentUser: true };
|
|
52
|
+
else if (runAsValue === "publisher")
|
|
53
|
+
runAs = { publisher: true };
|
|
54
|
+
else if (runAsValue === "service_account") {
|
|
55
|
+
const serviceAccountId = optionalString(attrs, "service_account_id", where, ctx);
|
|
56
|
+
if (serviceAccountId !== undefined && serviceAccountId !== "") {
|
|
57
|
+
runAs = { serviceAccount: { serviceAccount: serviceAccountId } };
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
ctx.diagnostics.push(`${where}: run_as is service_account but service_account_id is missing; dropped`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (runAsValue !== undefined) {
|
|
64
|
+
ctx.diagnostics.push(`${where}: unsupported run_as ${JSON.stringify(runAsValue)}; dropped`);
|
|
65
|
+
}
|
|
66
|
+
const common = {
|
|
67
|
+
name,
|
|
68
|
+
description: optionalString(attrs, "description", where, ctx) ?? "",
|
|
69
|
+
...(status === "INACTIVE" && { status: "INACTIVE" }),
|
|
70
|
+
...(startMessage !== undefined && { startMessage }),
|
|
71
|
+
...(runAs !== undefined && { runAs }),
|
|
72
|
+
};
|
|
73
|
+
if (subType.typeKey === "runAgent") {
|
|
74
|
+
const targetLabel = resourceRefLabel(attrs["target_agent_id"], "elementum_agent");
|
|
75
|
+
if (targetLabel === undefined) {
|
|
76
|
+
ctx.diagnostics.push(`${where}: target_agent_id is not an elementum_agent resource reference; skipped`);
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
typeKey: "runAgent",
|
|
81
|
+
...common,
|
|
82
|
+
targetAgentKey: scopedLabelToBagKey(owner.ownerTfLabel, targetLabel),
|
|
83
|
+
workerTaskPrompt: optionalString(attrs, "worker_task_prompt", where, ctx) ?? "",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (subType.typeKey === "automation") {
|
|
87
|
+
const automation = attrs["automation_id"];
|
|
88
|
+
const automationLabel = isTfExpr(automation) &&
|
|
89
|
+
automation.$expr === "resource-attr" &&
|
|
90
|
+
(automation.type === "elementum_workflow_publish" || automation.type === "elementum_automation")
|
|
91
|
+
? automation.label
|
|
92
|
+
: undefined;
|
|
93
|
+
if (automationLabel === undefined) {
|
|
94
|
+
ctx.diagnostics.push(`${where}: automation_id is not an automation/workflow_publish resource reference; skipped`);
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
const inputs = [];
|
|
98
|
+
for (const item of Array.isArray(attrs["inputs"]) ? attrs["inputs"] : []) {
|
|
99
|
+
if (typeof item !== "object" || item === null || Array.isArray(item) || isTfExpr(item))
|
|
100
|
+
continue;
|
|
101
|
+
const rec = item;
|
|
102
|
+
if (typeof rec["parameter_name"] !== "string" || rec["parameter_name"] === "") {
|
|
103
|
+
ctx.diagnostics.push(`${where}: inputs item has no parameter_name; dropped`);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
inputs.push({
|
|
107
|
+
parameterName: rec["parameter_name"],
|
|
108
|
+
...(typeof rec["display_name"] === "string" && { displayName: rec["display_name"] }),
|
|
109
|
+
...(typeof rec["description"] === "string" && { description: rec["description"] }),
|
|
110
|
+
...(typeof rec["required"] === "boolean" && { required: rec["required"] }),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const outputs = [];
|
|
114
|
+
for (const item of Array.isArray(attrs["outputs"]) ? attrs["outputs"] : []) {
|
|
115
|
+
if (typeof item !== "object" || item === null || Array.isArray(item) || isTfExpr(item))
|
|
116
|
+
continue;
|
|
117
|
+
const rec = item;
|
|
118
|
+
if (typeof rec["workflow_property_name"] !== "string" || rec["workflow_property_name"] === "") {
|
|
119
|
+
ctx.diagnostics.push(`${where}: outputs item has no workflow_property_name; dropped`);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
outputs.push({
|
|
123
|
+
workflowPropertyName: rec["workflow_property_name"],
|
|
124
|
+
...(typeof rec["display_name"] === "string" && { displayName: rec["display_name"] }),
|
|
125
|
+
...(typeof rec["description"] === "string" && { description: rec["description"] }),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
typeKey: "automation",
|
|
130
|
+
...common,
|
|
131
|
+
automationKey: scopedLabelToBagKey(owner.ownerTfLabel, automationLabel),
|
|
132
|
+
...(inputs.length > 0 && { inputs }),
|
|
133
|
+
...(outputs.length > 0 && { outputs }),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
46
136
|
// Target: the owning app's resource ref = self; a data.elementum_app ref =
|
|
47
137
|
// a foreign app, resolved to its display name via the stream's data block.
|
|
48
138
|
const targetAttr = attrs["target_id"];
|
|
@@ -109,7 +199,8 @@ export function skillToolFromTf(block, owner, ctx) {
|
|
|
109
199
|
// "Not used by search tools" — it's platform-generated noise (see
|
|
110
200
|
// to-tf.ts), so it's excluded here too rather than echoed into
|
|
111
201
|
// authored source.
|
|
112
|
-
...(subType.typeKey === "createRecord"
|
|
202
|
+
...((subType.typeKey === "createRecord" || subType.typeKey === "updateRecord") &&
|
|
203
|
+
typeof rec["required"] === "boolean" && { required: rec["required"] }),
|
|
113
204
|
});
|
|
114
205
|
}
|
|
115
206
|
if (fields.length === 0)
|
|
@@ -124,19 +215,17 @@ export function skillToolFromTf(block, owner, ctx) {
|
|
|
124
215
|
if (subType.typeKey === "searchAspect" && attrs["filter_variables"] !== undefined) {
|
|
125
216
|
ctx.diagnostics.push(`${where}: filter_variables are not supported on the terraform path yet; a rebuilt stream will omit them`);
|
|
126
217
|
}
|
|
127
|
-
const startMessage = optionalString(attrs, "start_message", where, ctx);
|
|
128
|
-
const status = optionalString(attrs, "status", where, ctx);
|
|
129
218
|
return {
|
|
130
219
|
typeKey: subType.typeKey,
|
|
131
|
-
|
|
132
|
-
description: optionalString(attrs, "description", where, ctx) ?? "",
|
|
133
|
-
...(status === "INACTIVE" && { status }),
|
|
134
|
-
...(startMessage !== undefined && { startMessage }),
|
|
220
|
+
...common,
|
|
135
221
|
target,
|
|
136
222
|
...(fields !== undefined && { fields }),
|
|
137
223
|
...(subType.typeKey === "searchAspect" && {
|
|
138
224
|
queryDescription: optionalString(attrs, "query_description", where, ctx) ?? "",
|
|
139
225
|
}),
|
|
140
226
|
...(typeof attrs["result_limit"] === "number" && { limit: attrs["result_limit"] }),
|
|
227
|
+
...(subType.typeKey === "updateRecord" && {
|
|
228
|
+
handleDescription: optionalString(attrs, "handle_description", where, ctx) ?? "",
|
|
229
|
+
}),
|
|
141
230
|
};
|
|
142
231
|
}
|
|
@@ -6,17 +6,27 @@
|
|
|
6
6
|
* (`skill_id`) — this module never names the skill or app resource types.
|
|
7
7
|
* Mirrors `entities/agent-tool/to-tf.ts`.
|
|
8
8
|
*/
|
|
9
|
-
import { type TfBlock } from "../../engine/tf/index.js";
|
|
9
|
+
import { type TfBlock, type TfValue } from "../../engine/tf/index.js";
|
|
10
10
|
export interface SkillToolToTfContext {
|
|
11
11
|
/** The owning app's refName + tfLabel (namespace) — self-target detection + app_id. */
|
|
12
12
|
readonly appRefName: string;
|
|
13
13
|
readonly appTfLabel: string;
|
|
14
14
|
/** The owning skill's tfLabel. */
|
|
15
15
|
readonly skillTfLabel: string;
|
|
16
|
+
/**
|
|
17
|
+
* Cross-skill disambiguation suffix ("", "_1", "_2", …) — mirrors ei's
|
|
18
|
+
* own tool-name collision handling across different skills in the same
|
|
19
|
+
* app (board issue #310). Computed by the caller (`skillToTf`) via
|
|
20
|
+
* `computeToolLabelSuffixes`; empty when absent (single-skill contexts,
|
|
21
|
+
* most unit tests).
|
|
22
|
+
*/
|
|
23
|
+
readonly labelSuffix?: string;
|
|
16
24
|
/** Records a foreign-app data lookup for data.tf; returns its tfLabel. */
|
|
17
25
|
foreignAppRef(tfLabel: string, name: string): void;
|
|
18
26
|
/** Records a foreign-ELEMENT data lookup for data.tf (board issue #42). */
|
|
19
27
|
foreignElementRef(tfLabel: string, name: string): void;
|
|
28
|
+
/** Records a `data.elementum_field` lookup for a field owned by a foreign app/element. */
|
|
29
|
+
foreignFieldRef(type: string, tfLabel: string, objectId: TfValue, name: string): void;
|
|
20
30
|
/** Degradations land here — reported by the caller, never silent. */
|
|
21
31
|
readonly diagnostics: string[];
|
|
22
32
|
}
|
|
@@ -6,12 +6,72 @@
|
|
|
6
6
|
* (`skill_id`) — this module never names the skill or app resource types.
|
|
7
7
|
* Mirrors `entities/agent-tool/to-tf.ts`.
|
|
8
8
|
*/
|
|
9
|
-
import { appScopedResourceLabel, expr, sanitizeName } from "../../engine/tf/index.js";
|
|
9
|
+
import { appScopedResourceLabel, expr, sanitizeName, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
10
10
|
import { fieldRefToTfValue } from "../field/to-tf.js";
|
|
11
11
|
import { SKILL_TOOL_SUB_TYPE_BY_TYPE_KEY } from "./types.js";
|
|
12
|
-
/** authoring
|
|
13
|
-
function
|
|
12
|
+
/** authoring AspectRef token → its resolved target (self resource ref or foreign data ref). */
|
|
13
|
+
function resolveTarget(token, ctx) {
|
|
14
14
|
const refName = token.refName ?? "";
|
|
15
|
+
const kind = token.__kind === "element" ? "element" : "app";
|
|
16
|
+
if (kind === "app" && refName === ctx.appRefName) {
|
|
17
|
+
return { value: expr.resourceAttr("elementum_app", ctx.appTfLabel, ["id"]), refName, kind, isSelf: true };
|
|
18
|
+
}
|
|
19
|
+
// ei derives foreign-app/foreign-element data labels from the display NAME.
|
|
20
|
+
const name = token.name ?? refName;
|
|
21
|
+
const tfLabel = sanitizeName(name);
|
|
22
|
+
// Board issue #42: an aspect token can be an element, not just an app.
|
|
23
|
+
if (kind === "element") {
|
|
24
|
+
ctx.foreignElementRef(tfLabel, name);
|
|
25
|
+
return { value: expr.dataAttr("elementum_element", tfLabel, ["id"]), refName, kind, isSelf: false, foreignTfLabel: tfLabel };
|
|
26
|
+
}
|
|
27
|
+
ctx.foreignAppRef(tfLabel, name);
|
|
28
|
+
return { value: expr.dataAttr("elementum_app", tfLabel, ["id"]), refName, kind, isSelf: false, foreignTfLabel: tfLabel };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A field belonging to the tool's target aspect, when that target is
|
|
32
|
+
* foreign to the tool's owning app — resolved via a `data.elementum_field`
|
|
33
|
+
* lookup keyed by the TARGET's already-resolved id (never re-derived from
|
|
34
|
+
* the field token's own `parentKind`/`parentName`) + the field's display
|
|
35
|
+
* name. Mirrors `agent-tool/to-tf.ts`'s `foreignTargetFieldRefValue`.
|
|
36
|
+
*/
|
|
37
|
+
function foreignTargetFieldRefValue(token, refName, target, ctx) {
|
|
38
|
+
const fieldName = token.name ?? refName;
|
|
39
|
+
const fieldLabel = `${target.kind}_${target.foreignTfLabel}_${tsLabelToTfLabel(refName)}`;
|
|
40
|
+
ctx.foreignFieldRef("elementum_field", fieldLabel, target.value, fieldName);
|
|
41
|
+
return expr.dataAttr("elementum_field", fieldLabel, ["id"]);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* authoring FieldRef token → the field resource address, resolved against
|
|
45
|
+
* the tool's ACTUAL target aspect, not just the tool's owning app — see
|
|
46
|
+
* `agent-tool/to-tf.ts`'s identical `fieldRefValue` for the full rationale.
|
|
47
|
+
*/
|
|
48
|
+
function fieldRefValue(token, where, ctx, target) {
|
|
49
|
+
const refName = token.refName ?? "";
|
|
50
|
+
if (target !== undefined) {
|
|
51
|
+
// `parentKind` is stamped ALONGSIDE a FOREIGN `parent` by `appCatalog`/
|
|
52
|
+
// `elementCatalog` (see `FieldRef`'s doc comment) — but a field's own
|
|
53
|
+
// `.ref()` on ITS OWN app/element stamps `parent` (as a self-reference)
|
|
54
|
+
// without `parentKind` at all (a real, common shape — see
|
|
55
|
+
// `agent-tool/to-tf.ts`'s identical check for the full rationale), so
|
|
56
|
+
// only a parent naming something OTHER than the tool's owning app is
|
|
57
|
+
// genuinely ambiguous.
|
|
58
|
+
if (token.parent !== undefined && token.parent !== ctx.appRefName && token.parentKind === undefined) {
|
|
59
|
+
ctx.diagnostics.push(`${where}: field "${refName}" has a parent ("${token.parent}") but no parentKind — incomplete foreign-field provenance; dropped`);
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
const parent = token.parent ?? ctx.appRefName;
|
|
63
|
+
const parentKind = token.parentKind ?? "app";
|
|
64
|
+
if (parent !== target.refName || parentKind !== target.kind) {
|
|
65
|
+
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`);
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
if (!target.isSelf)
|
|
69
|
+
return foreignTargetFieldRefValue(token, refName, target, ctx);
|
|
70
|
+
}
|
|
71
|
+
else if (token.parent !== undefined && (token.parent !== ctx.appRefName || token.parentKind === "element")) {
|
|
72
|
+
ctx.diagnostics.push(`${where}: field "${refName}" belongs to "${token.parent}", not this tool's app; dropped`);
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
15
75
|
const authoringType = token.fieldType ?? "";
|
|
16
76
|
// appTfLabel, not appRefName: fieldRefToTfValue builds a terraform address
|
|
17
77
|
// (resource label prefix / local name), and the two differ whenever an
|
|
@@ -22,28 +82,8 @@ function fieldRefValue(token, where, ctx) {
|
|
|
22
82
|
ctx.diagnostics.push(`${where}: field token "${refName}" has no terraform field resource mapping (fieldType ${JSON.stringify(authoringType)}); dropped`);
|
|
23
83
|
return undefined;
|
|
24
84
|
}
|
|
25
|
-
if (token.parent !== undefined && token.parent !== ctx.appRefName) {
|
|
26
|
-
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`);
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
85
|
return ref;
|
|
30
86
|
}
|
|
31
|
-
/** authoring AspectRef token → target_id value (self resource ref or foreign data ref). */
|
|
32
|
-
function targetIdValue(token, ctx) {
|
|
33
|
-
if (token.__kind !== "element" && (token.refName ?? "") === ctx.appRefName) {
|
|
34
|
-
return expr.resourceAttr("elementum_app", ctx.appTfLabel, ["id"]);
|
|
35
|
-
}
|
|
36
|
-
// ei derives foreign-app/foreign-element data labels from the display NAME.
|
|
37
|
-
const name = token.name ?? token.refName ?? "";
|
|
38
|
-
const tfLabel = sanitizeName(name);
|
|
39
|
-
// Board issue #42: an aspect token can be an element, not just an app.
|
|
40
|
-
if (token.__kind === "element") {
|
|
41
|
-
ctx.foreignElementRef(tfLabel, name);
|
|
42
|
-
return expr.dataAttr("elementum_element", tfLabel, ["id"]);
|
|
43
|
-
}
|
|
44
|
-
ctx.foreignAppRef(tfLabel, name);
|
|
45
|
-
return expr.dataAttr("elementum_app", tfLabel, ["id"]);
|
|
46
|
-
}
|
|
47
87
|
/**
|
|
48
88
|
* One authored tool entry (`{ createRecord: {...} }`) → its resource block;
|
|
49
89
|
* undefined = degraded with a diagnostic (unimplemented sub-type, missing
|
|
@@ -70,7 +110,7 @@ export function skillToolToTf(entry, ctx) {
|
|
|
70
110
|
return undefined;
|
|
71
111
|
}
|
|
72
112
|
const where = `skill tool "${name}"`;
|
|
73
|
-
const tfLabel = appScopedResourceLabel(ctx.appTfLabel, sanitizeName(name));
|
|
113
|
+
const tfLabel = appScopedResourceLabel(ctx.appTfLabel, `${sanitizeName(name)}${ctx.labelSuffix ?? ""}`);
|
|
74
114
|
const attrs = {
|
|
75
115
|
skill_id: expr.resourceAttr("elementum_agentic_skill", ctx.skillTfLabel, ["id"]),
|
|
76
116
|
app_id: expr.resourceAttr("elementum_app", ctx.appTfLabel, ["id"]),
|
|
@@ -80,11 +120,87 @@ export function skillToolToTf(entry, ctx) {
|
|
|
80
120
|
};
|
|
81
121
|
if (inner.startMessage !== undefined)
|
|
82
122
|
attrs["start_message"] = inner.startMessage;
|
|
123
|
+
if (inner.runAs?.["currentUser"] === true) {
|
|
124
|
+
attrs["run_as"] = "current_user";
|
|
125
|
+
}
|
|
126
|
+
else if (inner.runAs?.["publisher"] === true) {
|
|
127
|
+
attrs["run_as"] = "publisher";
|
|
128
|
+
}
|
|
129
|
+
else if (inner.runAs?.["serviceAccount"] !== undefined) {
|
|
130
|
+
const serviceAccount = inner.runAs["serviceAccount"];
|
|
131
|
+
if (typeof serviceAccount.serviceAccount === "string" && serviceAccount.serviceAccount !== "") {
|
|
132
|
+
attrs["run_as"] = "service_account";
|
|
133
|
+
attrs["service_account_id"] = serviceAccount.serviceAccount;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
ctx.diagnostics.push(`${where}: service-account runAs has no service account id; dropped`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (inner.runAs !== undefined) {
|
|
140
|
+
ctx.diagnostics.push(`${where}: runAs ${JSON.stringify(inner.runAs)} is not supported; dropped`);
|
|
141
|
+
}
|
|
142
|
+
if (typeKey === "automation") {
|
|
143
|
+
const automation = inner.automationId;
|
|
144
|
+
const automationTfLabel = typeof automation?.refName === "string" && automation.refName !== ""
|
|
145
|
+
? tsLabelToTfLabel(automation.refName)
|
|
146
|
+
: typeof automation?.name === "string" && automation.name !== ""
|
|
147
|
+
? sanitizeName(automation.name)
|
|
148
|
+
: undefined;
|
|
149
|
+
if (automationTfLabel === undefined) {
|
|
150
|
+
ctx.diagnostics.push(`${where}: no target automation token; dropped`);
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
if (automation?.parent !== undefined && automation.parent !== ctx.appRefName) {
|
|
154
|
+
ctx.diagnostics.push(`${where}: cross-app automation targets are not supported; dropped`);
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
attrs["automation_id"] = expr.resourceAttr("elementum_workflow_publish", appScopedResourceLabel(ctx.appTfLabel, automationTfLabel), ["id"]);
|
|
158
|
+
if (inner.inputs !== undefined && inner.inputs.length > 0) {
|
|
159
|
+
attrs["inputs"] = inner.inputs.map((input) => ({
|
|
160
|
+
parameter_name: input.parameterName ?? "",
|
|
161
|
+
...(input.displayName !== undefined && input.displayName !== input.parameterName && { display_name: input.displayName }),
|
|
162
|
+
...(input.description !== undefined && input.description !== "" && { description: input.description }),
|
|
163
|
+
required: input.required ?? false,
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
if (inner.outputs !== undefined && inner.outputs.length > 0) {
|
|
167
|
+
attrs["outputs"] = inner.outputs.map((output) => ({
|
|
168
|
+
workflow_property_name: output.workflowPropertyName ?? "",
|
|
169
|
+
...(output.displayName !== undefined && output.displayName !== output.workflowPropertyName && { display_name: output.displayName }),
|
|
170
|
+
...(output.description !== undefined && output.description !== "" && { description: output.description }),
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
const block = { kind: "resource", type: subType.resourceType, label: tfLabel, attrs };
|
|
174
|
+
return { block, address: `${subType.resourceType}.${tfLabel}` };
|
|
175
|
+
}
|
|
176
|
+
if (typeKey === "runAgent") {
|
|
177
|
+
const target = inner.targetAgentId;
|
|
178
|
+
if (target?.refName === undefined || target.refName === "") {
|
|
179
|
+
ctx.diagnostics.push(`${where}: no target agent token; dropped`);
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
if (target.parent !== undefined && target.parent !== ctx.appRefName) {
|
|
183
|
+
ctx.diagnostics.push(`${where}: cross-app target agents are not supported; dropped`);
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
attrs["target_agent_id"] = expr.resourceAttr("elementum_agent", appScopedResourceLabel(ctx.appTfLabel, tsLabelToTfLabel(target.refName)), ["id"]);
|
|
187
|
+
attrs["worker_task_prompt"] = inner.workerTaskPrompt ?? "";
|
|
188
|
+
const block = { kind: "resource", type: subType.resourceType, label: tfLabel, attrs };
|
|
189
|
+
return { block, address: `${subType.resourceType}.${tfLabel}` };
|
|
190
|
+
}
|
|
83
191
|
if (inner.aspectId === undefined) {
|
|
84
192
|
ctx.diagnostics.push(`${where}: no target aspect token; dropped`);
|
|
85
193
|
return undefined;
|
|
86
194
|
}
|
|
87
|
-
|
|
195
|
+
const target = resolveTarget(inner.aspectId, ctx);
|
|
196
|
+
attrs["target_id"] = target.value;
|
|
197
|
+
if (typeKey === "updateRecord") {
|
|
198
|
+
if (inner.handleDescription === undefined || inner.handleDescription === "") {
|
|
199
|
+
ctx.diagnostics.push(`${where}: no handleDescription; dropped`);
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
attrs["handle_description"] = inner.handleDescription;
|
|
203
|
+
}
|
|
88
204
|
if (typeKey === "searchAspect") {
|
|
89
205
|
attrs["query_description"] = inner.queryDescription ?? "";
|
|
90
206
|
if (inner.limit !== undefined)
|
|
@@ -100,7 +216,7 @@ export function skillToolToTf(entry, ctx) {
|
|
|
100
216
|
? f.fieldId
|
|
101
217
|
: f.fieldId === undefined
|
|
102
218
|
? undefined
|
|
103
|
-
: fieldRefValue(f.fieldId, where, ctx);
|
|
219
|
+
: fieldRefValue(f.fieldId, where, ctx, target);
|
|
104
220
|
if (ref === undefined)
|
|
105
221
|
continue;
|
|
106
222
|
fieldValues.push({
|
|
@@ -116,7 +232,7 @@ export function skillToolToTf(entry, ctx) {
|
|
|
116
232
|
// search tools was a bug in the exporter itself — cmd/elementum's
|
|
117
233
|
// hcl_skill.go was fabricating it from Go's zero-value default
|
|
118
234
|
// rather than an actually-discovered value; fixed 2026-08-11.)
|
|
119
|
-
...(typeKey !== "searchAspect" && { required: f.required ?? false }),
|
|
235
|
+
...(typeKey !== "searchAspect" && typeKey !== "searchTable" && { required: f.required ?? false }),
|
|
120
236
|
});
|
|
121
237
|
if (f.defaultValue !== undefined) {
|
|
122
238
|
ctx.diagnostics.push(`${where}: field default values are not supported on the terraform path yet; dropped`);
|
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
* name/description/status) — so per-sub-type knowledge is one ROW here,
|
|
5
5
|
* exactly like `entities/agent-tool/types.ts` (which this mirrors).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* resource", and adoption scopes ONLY the implemented ones — an adopted type
|
|
10
|
-
* the printer can't reconstruct would plan as a destroy on rebuild.
|
|
7
|
+
* Search-table support stays coupled to the underlying AI search-table graph
|
|
8
|
+
* module; every other provider skill-tool resource is implemented end to end.
|
|
11
9
|
*
|
|
12
10
|
* Note the wire key for the automation tool is `automation`, not agent-tool's
|
|
13
11
|
* `executeWorkflow` — confirmed against the live provider schema
|
|
@@ -31,9 +29,9 @@ export declare const IMPLEMENTED_SKILL_TOOL_RESOURCE_TYPES: readonly string[];
|
|
|
31
29
|
export declare const ALL_SKILL_TOOL_RESOURCE_TYPES: readonly string[];
|
|
32
30
|
/**
|
|
33
31
|
* Attributes `skillToolFromTf` understands per implemented sub-type — growth
|
|
34
|
-
* is reported loudly. `run_as
|
|
35
|
-
*
|
|
36
|
-
*
|
|
32
|
+
* is reported loudly. Shared permissions (`run_as` and
|
|
33
|
+
* `service_account_id`) are included in every implemented row so pull never
|
|
34
|
+
* drops a tool's execution identity.
|
|
37
35
|
*/
|
|
38
36
|
export declare const KNOWN_SKILL_TOOL_ATTRS: Readonly<Record<string, ReadonlySet<string>>>;
|
|
39
37
|
/** Known provider attrs with no authoring slot yet — reported by name, tool still pulled. */
|