@elementumai/edk 0.9.18 → 0.9.19
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 +8 -3
- package/dist-sdk/src/catalog/factories.d.ts +11 -0
- package/dist-sdk/src/catalog/factories.js +6 -0
- package/dist-sdk/src/catalog/index.d.ts +2 -2
- package/dist-sdk/src/catalog/index.js +2 -2
- package/dist-sdk/src/catalog/org.d.ts +39 -1
- package/dist-sdk/src/catalog/org.js +460 -50
- package/dist-sdk/src/catalog/types.d.ts +10 -0
- package/dist-sdk/src/catalog/types.js +2 -0
- package/dist-sdk/src/engine/pull/ref-only.js +54 -20
- package/dist-sdk/src/engine/pull/result-output.d.ts +2 -0
- package/dist-sdk/src/engine/pull/result-output.js +1 -1
- package/dist-sdk/src/engine/tf/expr.js +38 -13
- 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 +2 -0
- package/dist-sdk/src/engine/tf/labels.js +4 -0
- package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
- package/dist-sdk/src/engine/tf/parse.js +105 -6
- package/dist-sdk/src/engine/workspace/loader.js +49 -12
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
- package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
- package/dist-sdk/src/entities/access-policy/to-tf.js +11 -4
- package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -1
- package/dist-sdk/src/entities/app/build.d.ts +10 -0
- package/dist-sdk/src/entities/app/build.js +0 -13
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +6 -1
- package/dist-sdk/src/entities/app/from-tf.js +4 -3
- package/dist-sdk/src/entities/app/index.d.ts +1 -0
- package/dist-sdk/src/entities/app/index.js +1 -0
- package/dist-sdk/src/entities/app/module.js +13 -0
- package/dist-sdk/src/entities/app/to-tf.js +2 -0
- package/dist-sdk/src/entities/automation/build.d.ts +2 -1
- package/dist-sdk/src/entities/automation/build.js +27 -0
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +6 -0
- package/dist-sdk/src/entities/automation/from-tf.js +135 -26
- package/dist-sdk/src/entities/automation/index.d.ts +1 -1
- package/dist-sdk/src/entities/automation/module.d.ts +2 -0
- package/dist-sdk/src/entities/automation/module.js +56 -0
- package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
- package/dist-sdk/src/entities/automation/system-ref-name.js +44 -0
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +15 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +38 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +29 -2
- package/dist-sdk/src/entities/automation/to-tf.js +158 -84
- package/dist-sdk/src/entities/automation/types.js +1 -0
- package/dist-sdk/src/entities/chart/from-tf.js +33 -17
- package/dist-sdk/src/entities/chart/module.js +3 -1
- package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
- package/dist-sdk/src/entities/chart/printer.js +26 -16
- package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
- package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
- package/dist-sdk/src/entities/chart/to-tf.js +12 -10
- package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
- package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
- package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
- package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +51 -2
- package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
- package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
- package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
- package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
- package/dist-sdk/src/entities/element/build.d.ts +8 -0
- package/dist-sdk/src/entities/element/build.js +1 -0
- package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
- package/dist-sdk/src/entities/element/from-tf.js +6 -2
- package/dist-sdk/src/entities/element/index.d.ts +1 -0
- package/dist-sdk/src/entities/element/index.js +1 -0
- package/dist-sdk/src/entities/element/module.js +2 -0
- package/dist-sdk/src/entities/element/to-tf.js +12 -0
- package/dist-sdk/src/entities/field/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/field/from-tf.js +11 -0
- package/dist-sdk/src/entities/field/to-tf.js +13 -9
- package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
- package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
- package/dist-sdk/src/entities/relationship/to-tf.d.ts +8 -0
- package/dist-sdk/src/entities/relationship/to-tf.js +19 -10
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -2
- package/dist-sdk/src/entities/shared/filters/index.d.ts +23 -2
- package/dist-sdk/src/entities/shared/filters/index.js +24 -1
- package/dist-sdk/src/entities/shared/filters/print.js +14 -2
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +23 -3
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +46 -14
- package/dist-sdk/src/entities/shared/filters/types.d.ts +13 -4
- package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
- package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
- package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
- package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
- package/dist-sdk/src/entities/skill/access-policy.js +101 -0
- package/dist-sdk/src/entities/skill/build.d.ts +3 -0
- package/dist-sdk/src/entities/skill/build.js +3 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +21 -0
- package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill/from-tf.js +4 -9
- package/dist-sdk/src/entities/skill/index.d.ts +2 -0
- package/dist-sdk/src/entities/skill/index.js +1 -0
- package/dist-sdk/src/entities/skill/module.js +1 -0
- package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/skill/to-tf.js +5 -2
- package/dist-sdk/src/entities/skill-tool/to-tf.js +2 -1
- package/dist-sdk/src/entities/table/to-tf.js +3 -3
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -0
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +224 -0
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +36 -0
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +288 -0
- package/dist-sdk/src/entities/view/agent-view-layout.d.ts +121 -0
- package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
- package/dist-sdk/src/entities/view/from-tf.d.ts +3 -1
- package/dist-sdk/src/entities/view/from-tf.js +42 -7
- package/dist-sdk/src/entities/view/to-tf.d.ts +10 -1
- package/dist-sdk/src/entities/view/to-tf.js +30 -1
- package/dist-sdk/src/entities/view/types.js +2 -0
- package/dist-sdk/src/entities/widget/to-tf.js +2 -2
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +25 -8
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/index.d.ts +43 -0
- package/dist-sdk/src/graph/index.js +9 -0
- package/dist-sdk/src/graph/types.d.ts +78 -0
- package/package.json +2 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { EntityTfError } from "../../engine/entity.js";
|
|
2
|
+
import { dataRefLabel } from "../../engine/pull/context.js";
|
|
3
|
+
import { expr, sanitizeName, tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
4
|
+
function object(value) {
|
|
5
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
/** Validate the complete policy before emitting any access-changing configuration. */
|
|
8
|
+
export function normalizeSkillAccessPolicy(value) {
|
|
9
|
+
if (!object(value))
|
|
10
|
+
throw new EntityTfError("skill accessPolicy must contain portable users or groups");
|
|
11
|
+
for (const key of Object.keys(value))
|
|
12
|
+
if (key !== "users" && key !== "groups")
|
|
13
|
+
throw new EntityTfError(`skill accessPolicy has unsupported key ${JSON.stringify(key)}`);
|
|
14
|
+
const out = {};
|
|
15
|
+
for (const key of ["users", "groups"]) {
|
|
16
|
+
const entries = value[key];
|
|
17
|
+
if (entries === undefined)
|
|
18
|
+
continue;
|
|
19
|
+
if (!Array.isArray(entries))
|
|
20
|
+
throw new EntityTfError(`skill accessPolicy.${key} must be a list of portable references`);
|
|
21
|
+
if (key === "users") {
|
|
22
|
+
const users = new Map();
|
|
23
|
+
for (const entry of entries) {
|
|
24
|
+
if (!object(entry) || entry.__kind !== "user" || typeof entry.email !== "string" || !/^[^\s@]+@[^\s@]+$/.test(entry.email)) {
|
|
25
|
+
throw new EntityTfError("skill accessPolicy.users requires userRef(email); raw IDs and other principal kinds are unsupported");
|
|
26
|
+
}
|
|
27
|
+
users.set(entry.email, { __kind: "user", email: entry.email });
|
|
28
|
+
}
|
|
29
|
+
out.users = [...users.values()];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const groups = new Map();
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
if (!object(entry) || entry.__kind !== "group" || typeof entry.refName !== "string" || entry.refName.trim() === "" || typeof entry.name !== "string" || entry.name.trim() === "") {
|
|
35
|
+
throw new EntityTfError("skill accessPolicy.groups requires an org.groups reference; raw IDs and other principal kinds are unsupported");
|
|
36
|
+
}
|
|
37
|
+
const previous = groups.get(entry.refName);
|
|
38
|
+
if (previous !== undefined && previous.name !== entry.name)
|
|
39
|
+
throw new EntityTfError(`skill accessPolicy.groups has conflicting names for ${JSON.stringify(entry.refName)}`);
|
|
40
|
+
groups.set(entry.refName, { __kind: "group", refName: entry.refName, name: entry.name });
|
|
41
|
+
}
|
|
42
|
+
out.groups = [...groups.values()];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return Object.keys(out).length === 0 ? { users: [], groups: [] } : out;
|
|
46
|
+
}
|
|
47
|
+
export function skillAccessPolicyToTf(value, orgRefs) {
|
|
48
|
+
const policy = normalizeSkillAccessPolicy(value);
|
|
49
|
+
const out = {};
|
|
50
|
+
const labels = new Map();
|
|
51
|
+
if (policy.users !== undefined)
|
|
52
|
+
out.user_ids = policy.users.map((user) => {
|
|
53
|
+
const label = sanitizeName(user.email.split("@", 1)[0]);
|
|
54
|
+
const previous = labels.get(label);
|
|
55
|
+
if (previous !== undefined && previous !== user.email)
|
|
56
|
+
throw new EntityTfError(`skill accessPolicy.users has colliding email lookup label ${JSON.stringify(label)}`);
|
|
57
|
+
labels.set(label, user.email);
|
|
58
|
+
orgRefs.rawLookup("elementum_user", label, user.email);
|
|
59
|
+
return expr.dataAttr("elementum_user", label, ["id"]);
|
|
60
|
+
});
|
|
61
|
+
if (policy.groups !== undefined)
|
|
62
|
+
out.group_ids = policy.groups.map((group) => {
|
|
63
|
+
const resolved = orgRefs.byTsLabel("groups", group.refName);
|
|
64
|
+
if (resolved === undefined)
|
|
65
|
+
throw new EntityTfError(`skill accessPolicy group ${JSON.stringify(group.refName)} is not in org.ts`);
|
|
66
|
+
return resolved.managed
|
|
67
|
+
? expr.resourceAttr("elementum_group", resolved.tfLabel, ["id"])
|
|
68
|
+
: expr.dataAttr("elementum_group", resolved.tfLabel, ["id"]);
|
|
69
|
+
});
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
/** Any unresolved principal blocks pull; dropping even one could broaden access on the next apply. */
|
|
73
|
+
export function skillAccessPolicyFromTf(attrs, ctx) {
|
|
74
|
+
if (attrs.user_ids === undefined && attrs.group_ids === undefined)
|
|
75
|
+
return undefined;
|
|
76
|
+
const policy = {};
|
|
77
|
+
for (const [key, type, output] of [["user_ids", "elementum_user", "users"], ["group_ids", "elementum_group", "groups"]]) {
|
|
78
|
+
const values = attrs[key];
|
|
79
|
+
if (values === undefined)
|
|
80
|
+
continue;
|
|
81
|
+
if (!Array.isArray(values))
|
|
82
|
+
throw new EntityTfError(`skill access policy ${key} must be a list; refusing to omit a restriction`);
|
|
83
|
+
const users = [];
|
|
84
|
+
const groups = [];
|
|
85
|
+
for (const value of values) {
|
|
86
|
+
const label = dataRefLabel(value, type);
|
|
87
|
+
const identity = label === undefined ? undefined : ctx.dataName(type, label);
|
|
88
|
+
if (label === undefined || identity === undefined || identity.trim() === "")
|
|
89
|
+
throw new EntityTfError(`skill access policy ${key} contains an unresolved principal; refusing to omit a restriction`);
|
|
90
|
+
if (output === "users")
|
|
91
|
+
users.push({ __kind: "user", email: identity });
|
|
92
|
+
else
|
|
93
|
+
groups.push({ __kind: "group", refName: tfLabelToTsLabel(label), name: identity });
|
|
94
|
+
}
|
|
95
|
+
if (output === "users")
|
|
96
|
+
policy.users = users;
|
|
97
|
+
else
|
|
98
|
+
policy.groups = groups;
|
|
99
|
+
}
|
|
100
|
+
return normalizeSkillAccessPolicy(policy);
|
|
101
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CatalogRef, SkillRef } from "../../catalog/index.js";
|
|
2
2
|
import type { DeployableEntity, EntityDeployOptions } from "../../engine/entity.js";
|
|
3
3
|
import type { SkillTool } from "./tools.js";
|
|
4
|
+
import { type SkillAccessPolicy } from "./access-policy.js";
|
|
4
5
|
export interface SkillInputSpec {
|
|
5
6
|
/** Optional explicit field name (defaults to the record key when using an object shape). */
|
|
6
7
|
readonly name?: string;
|
|
@@ -29,6 +30,8 @@ export type SkillV2Options = EntityDeployOptions & {
|
|
|
29
30
|
readonly properties?: Record<string, unknown>;
|
|
30
31
|
/** Typed discovery signals used when routing user requests to this skill. */
|
|
31
32
|
readonly discovery?: SkillDiscoveryOptions;
|
|
33
|
+
/** Restrict visibility to portable users/group members. Omission or empty lists removes an existing policy; no policy is open to otherwise-authorized users. */
|
|
34
|
+
readonly accessPolicy?: SkillAccessPolicy;
|
|
32
35
|
readonly tools?: readonly SkillTool[];
|
|
33
36
|
} & ({
|
|
34
37
|
/**
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { slimTokens } from "../../catalog/index.js";
|
|
14
14
|
import { deriveSkillInstructions, } from "./input-coverage.js";
|
|
15
|
+
import { normalizeSkillAccessPolicy } from "./access-policy.js";
|
|
15
16
|
/**
|
|
16
17
|
* `name` is a free-text display name, like an agent's — confirmed against
|
|
17
18
|
* the platform's actual create/update path, which only rejects a blank
|
|
@@ -74,6 +75,7 @@ export function skill(opts) {
|
|
|
74
75
|
throw new Error("skill discovery.routingPriority must be a finite number from -100 to 100");
|
|
75
76
|
}
|
|
76
77
|
const normalizedInputs = normalizeInputs(opts.inputs);
|
|
78
|
+
const accessPolicy = opts.accessPolicy === undefined ? undefined : normalizeSkillAccessPolicy(opts.accessPolicy);
|
|
77
79
|
const normalizedLookups = normalizeLookups(opts.lookups);
|
|
78
80
|
const instructions = deriveSkillInstructions(opts.instructions, normalizedInputs, normalizedLookups);
|
|
79
81
|
if (instructions.trim() === "") {
|
|
@@ -98,6 +100,7 @@ export function skill(opts) {
|
|
|
98
100
|
type: "CUSTOM",
|
|
99
101
|
...(opts.properties !== undefined ? { properties: opts.properties } : {}),
|
|
100
102
|
...(opts.discovery !== undefined ? { discovery: opts.discovery } : {}),
|
|
103
|
+
...(accessPolicy !== undefined ? { accessPolicy } : {}),
|
|
101
104
|
},
|
|
102
105
|
tools: opts.tools ?? [],
|
|
103
106
|
}),
|
|
@@ -16,10 +16,13 @@ import type { NormalizedSkill } from "../from-tf.js";
|
|
|
16
16
|
export interface PrintSkillV2Options {
|
|
17
17
|
/** The owning app's refName — `parent:` and the catalog token root. */
|
|
18
18
|
readonly appRefName: string;
|
|
19
|
+
/** Relative import of the workspace's portable org catalog. */
|
|
20
|
+
readonly orgImportPath?: string;
|
|
19
21
|
/**
|
|
20
22
|
* Set for a cross-org clone: a foreign-app tool target was resolved
|
|
21
23
|
* against the SOURCE org, so it's flagged as a TODO for manual review
|
|
22
|
-
* instead of silently carried over
|
|
24
|
+
* instead of silently carried over. Access-policy groups require explicit
|
|
25
|
+
* destination review and print a build-blocking placeholder — same treatment as agent tools
|
|
23
26
|
* (`src/entities/agent/deserializer/print-agent-v2.ts`).
|
|
24
27
|
*/
|
|
25
28
|
readonly crossOrg?: boolean;
|
|
@@ -46,6 +46,7 @@ export function printSkillV2(skill, opts) {
|
|
|
46
46
|
const factories = [
|
|
47
47
|
...new Set([
|
|
48
48
|
...skill.tools.map((t) => TOOL_FACTORY_BY_TYPE_KEY[t.typeKey]).filter(Boolean),
|
|
49
|
+
...((skill.accessPolicy?.users?.length ?? 0) > 0 ? ["userRef"] : []),
|
|
49
50
|
...(skill.tools.some((t) => t.runAs !== undefined && "serviceAccount" in t.runAs)
|
|
50
51
|
? ["serviceAccountRef"]
|
|
51
52
|
: []),
|
|
@@ -68,6 +69,8 @@ export function printSkillV2(skill, opts) {
|
|
|
68
69
|
if (skill.tools.some((tool) => tool.typeKey === "searchTable" && tool.target?.kind === "tableOwned")) {
|
|
69
70
|
lines.push(`import { tableSearchTableRef } from ${JSON.stringify(sdkPackageSpecifier("catalog"))};`);
|
|
70
71
|
}
|
|
72
|
+
if ((skill.accessPolicy?.groups?.length ?? 0) > 0)
|
|
73
|
+
lines.push(`import { org } from ${quote(opts.orgImportPath ?? "../../../org.js")};`);
|
|
71
74
|
if (usesUnsafePlatformId)
|
|
72
75
|
lines.push(`import { unsafePlatformId } from ${JSON.stringify(sdkPackageSpecifier("core"))};`);
|
|
73
76
|
lines.push(`import catalog from "@catalog";`);
|
|
@@ -115,6 +118,24 @@ export function printSkillV2(skill, opts) {
|
|
|
115
118
|
if (skill.discovery !== undefined) {
|
|
116
119
|
lines.push(` discovery: ${JSON.stringify(skill.discovery)},`);
|
|
117
120
|
}
|
|
121
|
+
if (skill.accessPolicy !== undefined) {
|
|
122
|
+
lines.push(" accessPolicy: {");
|
|
123
|
+
if (skill.accessPolicy.users !== undefined)
|
|
124
|
+
lines.push(` users: [${skill.accessPolicy.users.map((user) => `userRef(${quote(user.email)})`).join(", ")}],`);
|
|
125
|
+
if (skill.accessPolicy.groups !== undefined) {
|
|
126
|
+
if (crossOrg && skill.accessPolicy.groups.length > 0) {
|
|
127
|
+
lines.push(" groups: [");
|
|
128
|
+
for (const group of skill.accessPolicy.groups) {
|
|
129
|
+
lines.push(` TODO_DESTINATION_GROUP, // TODO: cross-org clone — verify the destination group's membership, then replace with org.groups.<key> for source group ${quote(group.name)}.`);
|
|
130
|
+
}
|
|
131
|
+
lines.push(" ],");
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
lines.push(` groups: [${skill.accessPolicy.groups.map((group) => `org.groups${safeMember(group.refName)}`).join(", ")}],`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
lines.push(" },");
|
|
138
|
+
}
|
|
118
139
|
if (skill.tools.length > 0) {
|
|
119
140
|
lines.push(" tools: [");
|
|
120
141
|
for (const tool of skill.tools) {
|
|
@@ -9,6 +9,7 @@ import { type FromTfContext } from "../../engine/pull/context.js";
|
|
|
9
9
|
import { type TfBlock } from "../../engine/tf/index.js";
|
|
10
10
|
import { type NormalizedSkillTool } from "../skill-tool/from-tf.js";
|
|
11
11
|
import { type SkillInputDefinition, type SkillLookupDefinition } from "./input-coverage.js";
|
|
12
|
+
import { type SkillAccessPolicy } from "./access-policy.js";
|
|
12
13
|
export interface NormalizedSkillDiscovery {
|
|
13
14
|
readonly routingPriority?: number;
|
|
14
15
|
readonly aliases?: readonly string[];
|
|
@@ -28,6 +29,7 @@ export interface NormalizedSkill {
|
|
|
28
29
|
readonly status?: "ACTIVE" | "INACTIVE";
|
|
29
30
|
readonly properties?: Record<string, unknown>;
|
|
30
31
|
readonly discovery?: NormalizedSkillDiscovery;
|
|
32
|
+
readonly accessPolicy?: SkillAccessPolicy;
|
|
31
33
|
readonly tools: readonly NormalizedSkillTool[];
|
|
32
34
|
}
|
|
33
35
|
export interface SkillFromTfResult {
|
|
@@ -12,6 +12,7 @@ import { skillToolFromTf } from "../skill-tool/from-tf.js";
|
|
|
12
12
|
import { APP_RESOURCE_TYPE } from "../app/module.js";
|
|
13
13
|
import { analyzeSkillInputCoverage, decomposeSkillInstructions, skillCoverageGapDiagnostics, skillCoverageReportLines, } from "./input-coverage.js";
|
|
14
14
|
import { SKILL_RESOURCE_TYPE } from "./module.js";
|
|
15
|
+
import { skillAccessPolicyFromTf } from "./access-policy.js";
|
|
15
16
|
/** Attributes `skillFromTf` understands — anything else is dialect growth, reported loudly. */
|
|
16
17
|
const KNOWN_SKILL_ATTRS = new Set([
|
|
17
18
|
"owner_id",
|
|
@@ -28,9 +29,6 @@ const KNOWN_SKILL_ATTRS = new Set([
|
|
|
28
29
|
"positive_keywords",
|
|
29
30
|
"negative_keywords",
|
|
30
31
|
"depends_on",
|
|
31
|
-
]);
|
|
32
|
-
/** Dialect attrs with no authoring slot yet — reported by name, skill still pulled. */
|
|
33
|
-
const UNAUTHORABLE_SKILL_ATTRS = new Set([
|
|
34
32
|
"user_ids",
|
|
35
33
|
"group_ids",
|
|
36
34
|
]);
|
|
@@ -61,12 +59,7 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
|
|
|
61
59
|
for (const key of Object.keys(attrs)) {
|
|
62
60
|
if (KNOWN_SKILL_ATTRS.has(key))
|
|
63
61
|
continue;
|
|
64
|
-
|
|
65
|
-
ctx.diagnostics.push(`${where}: ${key} has no authoring slot on the terraform path yet; a rebuilt stream will omit it`);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
ctx.diagnostics.push(`${where}: unhandled attribute "${key}" — the export dialect grew; extend skillFromTf deliberately`);
|
|
69
|
-
}
|
|
62
|
+
ctx.diagnostics.push(`${where}: unhandled attribute "${key}" — the export dialect grew; extend skillFromTf deliberately`);
|
|
70
63
|
}
|
|
71
64
|
const ownerType = attrs["owner_type"];
|
|
72
65
|
if (ownerType !== "APP_ASPECT") {
|
|
@@ -86,6 +79,7 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
|
|
|
86
79
|
}
|
|
87
80
|
}
|
|
88
81
|
const status = optionalString(attrs, "status", where, ctx);
|
|
82
|
+
const accessPolicy = skillAccessPolicyFromTf(attrs, ctx);
|
|
89
83
|
const routingPriority = attrs["routing_priority"];
|
|
90
84
|
if (routingPriority !== undefined && typeof routingPriority !== "number") {
|
|
91
85
|
ctx.diagnostics.push(`${where}: routing_priority must be a number; dropped`);
|
|
@@ -132,6 +126,7 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
|
|
|
132
126
|
...((status === "ACTIVE" || status === "INACTIVE") && { status }),
|
|
133
127
|
...(properties !== undefined && { properties }),
|
|
134
128
|
...(Object.keys(discovery).length > 0 && { discovery }),
|
|
129
|
+
...(accessPolicy !== undefined && { accessPolicy }),
|
|
135
130
|
tools,
|
|
136
131
|
},
|
|
137
132
|
};
|
|
@@ -4,5 +4,7 @@
|
|
|
4
4
|
* reference position. Standalone from v1.
|
|
5
5
|
*/
|
|
6
6
|
export { skill, type SkillConfigured, type SkillDiscoveryOptions, type SkillInputSpec, type SkillInputsOption, type SkillLookupSpec, type SkillLookupsOption, type SkillV2Options, } from "./build.js";
|
|
7
|
+
export { type SkillAccessPolicy, type SkillUserRef } from "./access-policy.js";
|
|
8
|
+
export { userRef } from "../role/build.js";
|
|
7
9
|
export { serviceAccountRef, type AgentToolRunAs, type ServiceAccountRef, } from "../agent/run-as.js";
|
|
8
10
|
export { skillAutomation, skillCreateRecord, skillRunAgent, skillSearchRecords, skillSearchTable, skillUpdateRecord, type SkillRecordField, type SkillRecordFieldInput, type SkillRecordRawIdField, type SkillSearchField, type SkillSearchFieldInput, type SkillSearchRawIdField, type SkillToolStatus, type SkillTool, } from "./tools.js";
|
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
* reference position. Standalone from v1.
|
|
5
5
|
*/
|
|
6
6
|
export { skill, } from "./build.js";
|
|
7
|
+
export { userRef } from "../role/build.js";
|
|
7
8
|
export { serviceAccountRef, } from "../agent/run-as.js";
|
|
8
9
|
export { skillAutomation, skillCreateRecord, skillRunAgent, skillSearchRecords, skillSearchTable, skillUpdateRecord, } from "./tools.js";
|
|
@@ -85,6 +85,7 @@ export const skillModule = {
|
|
|
85
85
|
refName: skill.refName,
|
|
86
86
|
source: printSkillV2(skill, {
|
|
87
87
|
appRefName: opts.appRefName,
|
|
88
|
+
orgImportPath: opts.orgImportPath,
|
|
88
89
|
...(opts.crossOrg !== undefined && { crossOrg: opts.crossOrg }),
|
|
89
90
|
...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
|
|
90
91
|
...(opts.foreignElementRefNames !== undefined && { foreignElementRefNames: opts.foreignElementRefNames }),
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* repo — not `pristine-refactor`'s older, generic single-tool-resource
|
|
10
10
|
* shape): `owner_id`/`owner_type` as the owning app's resource ref +
|
|
11
11
|
* `"APP_ASPECT"`, `name`/`description`/`instructions`/`status`/`type`/
|
|
12
|
-
* `properties`,
|
|
13
|
-
*
|
|
12
|
+
* `properties`, typed discovery/routing fields, and portable access-policy
|
|
13
|
+
* user/group references.
|
|
14
14
|
*/
|
|
15
15
|
import { type OrgRefLookup, type WorkspaceAspect } from "../../engine/build/context.js";
|
|
16
16
|
import { type DeployableEntity } from "../../engine/entity.js";
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* repo — not `pristine-refactor`'s older, generic single-tool-resource
|
|
10
10
|
* shape): `owner_id`/`owner_type` as the owning app's resource ref +
|
|
11
11
|
* `"APP_ASPECT"`, `name`/`description`/`instructions`/`status`/`type`/
|
|
12
|
-
* `properties`,
|
|
13
|
-
*
|
|
12
|
+
* `properties`, typed discovery/routing fields, and portable access-policy
|
|
13
|
+
* user/group references.
|
|
14
14
|
*/
|
|
15
15
|
import { workspaceAspectKey } from "../../engine/build/context.js";
|
|
16
16
|
import { EntityTfError } from "../../engine/entity.js";
|
|
@@ -20,6 +20,7 @@ import { APP_RESOURCE_TYPE } from "../app/module.js";
|
|
|
20
20
|
import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
|
|
21
21
|
import { analyzeSkillInputCoverage, coverageToolsFromWire, skillCoverageGapDiagnostics, skillCoverageReportLines, } from "./input-coverage.js";
|
|
22
22
|
import { SKILL_RESOURCE_TYPE } from "./module.js";
|
|
23
|
+
import { skillAccessPolicyToTf } from "./access-policy.js";
|
|
23
24
|
function serviceAccountValue(name, ctx) {
|
|
24
25
|
const matches = Object.entries(ctx.serviceAccounts ?? {}).filter(([, account]) => `${account.firstName} ${account.lastName}`.trim() === name);
|
|
25
26
|
if (matches.length > 1) {
|
|
@@ -92,6 +93,8 @@ export function skillToTf(entity, ctx) {
|
|
|
92
93
|
if (elementum.properties !== undefined) {
|
|
93
94
|
attrs["properties"] = JSON.stringify(elementum.properties);
|
|
94
95
|
}
|
|
96
|
+
if (elementum.accessPolicy !== undefined)
|
|
97
|
+
Object.assign(attrs, skillAccessPolicyToTf(elementum.accessPolicy, ctx.orgRefs));
|
|
95
98
|
const discovery = elementum.discovery;
|
|
96
99
|
if (discovery?.routingPriority !== undefined)
|
|
97
100
|
attrs["routing_priority"] = discovery.routingPriority;
|
|
@@ -10,6 +10,7 @@ import { workspaceAspectKey } from "../../engine/build/context.js";
|
|
|
10
10
|
import { automationRunTargetResourceAttr } from "../automation/to-tf.js";
|
|
11
11
|
import { appScopedResourceLabel, childPartFromScopedLabel, expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
12
12
|
import { fieldRefToTfValue } from "../field/to-tf.js";
|
|
13
|
+
import { foreignFieldDataLabel } from "../shared/foreign-ref.js";
|
|
13
14
|
import { encodeOptionalHandleDescription } from "../shared/handle-description.js";
|
|
14
15
|
import { SKILL_TOOL_SUB_TYPE_BY_TYPE_KEY } from "./types.js";
|
|
15
16
|
function serviceAccountIdValue(token, where, ctx) {
|
|
@@ -103,7 +104,7 @@ function targetIdValue(token, ctx) {
|
|
|
103
104
|
function foreignTargetFieldRefValue(token, refName, target, ctx) {
|
|
104
105
|
const fieldName = token.name ?? refName;
|
|
105
106
|
const ownerLabel = target.foreignTfLabel ?? sanitizeName(target.refName);
|
|
106
|
-
const fieldLabel =
|
|
107
|
+
const fieldLabel = foreignFieldDataLabel(target.kind, ownerLabel, fieldName);
|
|
107
108
|
ctx.foreignFieldRef("elementum_field", fieldLabel, target.value, fieldName);
|
|
108
109
|
return expr.dataAttr("elementum_field", fieldLabel, ["id"]);
|
|
109
110
|
}
|
|
@@ -6,7 +6,7 @@ import { categoryIdExpr, missingCategoryDiagnostic } from "../org/category-ref.j
|
|
|
6
6
|
import { CLOUD_LINK_ORG_BAG } from "../org/cloud-link.js";
|
|
7
7
|
import { tableDataminesToTf, } from "../datamine/to-tf.js";
|
|
8
8
|
import { fieldRefToTfValue } from "../field/to-tf.js";
|
|
9
|
-
import { resolveForeignRef } from "../shared/foreign-ref.js";
|
|
9
|
+
import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
|
|
10
10
|
import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
|
|
11
11
|
import { TABLE_RESOURCE_TYPE } from "./module.js";
|
|
12
12
|
function tableColumnName(column) {
|
|
@@ -96,8 +96,8 @@ function fieldId(value, orgRefs, ownRef, ownLabel, ownColumnNames, workspaceAspe
|
|
|
96
96
|
return resolved;
|
|
97
97
|
}
|
|
98
98
|
const parentName = ref.parentName ?? parent;
|
|
99
|
-
const owner = resolveForeignRef(kind, { name: parentName }, orgRefs, diagnostics, "table field owner");
|
|
100
|
-
const label =
|
|
99
|
+
const owner = resolveForeignRef(kind, { name: parentName, namespace: ref.parentNamespace }, orgRefs, diagnostics, "table field owner");
|
|
100
|
+
const label = foreignFieldDataLabel(kind, owner.tfLabel, ref.name ?? ref.refName ?? "field");
|
|
101
101
|
orgRefs.foreignField("elementum_field", label, owner.value, ref.name ?? ref.refName ?? "");
|
|
102
102
|
return expr.dataAttr("elementum_field", label, ["id"]);
|
|
103
103
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pull: `elementum_agent_view.layout` → the normalized layout the printer
|
|
3
|
+
* turns back into `agentViews.<key>.layout`. References inside the custom
|
|
4
|
+
* view become typed markers at the per-block id positions; raw platform ids
|
|
5
|
+
* there become `unsafePlatformId(...)`. A layout this cannot represent makes
|
|
6
|
+
* the whole view unmanaged (skipped), never silently dropped: the code owns
|
|
7
|
+
* the layout, so a dropped detail would be cleared on the next apply.
|
|
8
|
+
*/
|
|
9
|
+
import { type TfValue } from "../../engine/tf/index.js";
|
|
10
|
+
/** A typed reference inside a pulled custom view. */
|
|
11
|
+
export type AgentViewSpecMarker = {
|
|
12
|
+
readonly __specRef: "app";
|
|
13
|
+
} | {
|
|
14
|
+
readonly __specRef: "field";
|
|
15
|
+
readonly key: string;
|
|
16
|
+
} | {
|
|
17
|
+
readonly __specRef: "unsafe";
|
|
18
|
+
readonly id: string;
|
|
19
|
+
};
|
|
20
|
+
export interface NormalizedAgentViewLayout {
|
|
21
|
+
readonly image?: {
|
|
22
|
+
readonly attachment: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly url: string;
|
|
25
|
+
};
|
|
26
|
+
readonly header?: string;
|
|
27
|
+
readonly subHeader?: string;
|
|
28
|
+
readonly backgroundColor?: string;
|
|
29
|
+
readonly primaryColor?: string;
|
|
30
|
+
readonly fontFamily?: string;
|
|
31
|
+
/** Plain JSON with `AgentViewSpecMarker` objects at reference positions. */
|
|
32
|
+
readonly customView?: unknown;
|
|
33
|
+
}
|
|
34
|
+
export interface AgentViewLayoutFromTfOptions {
|
|
35
|
+
/** True when the value references the owning app (`elementum_app.<owner>.id`). */
|
|
36
|
+
readonly isOwnApp: (value: TfValue) => boolean;
|
|
37
|
+
/** Resolves a field reference to its bag key, a system field key, or a raw id. */
|
|
38
|
+
readonly fieldKey: (value: TfValue) => string | undefined;
|
|
39
|
+
}
|
|
40
|
+
export type AgentViewLayoutFromTfResult = {
|
|
41
|
+
readonly ok: true;
|
|
42
|
+
readonly layout: NormalizedAgentViewLayout;
|
|
43
|
+
} | {
|
|
44
|
+
readonly ok: false;
|
|
45
|
+
readonly reason: string;
|
|
46
|
+
};
|
|
47
|
+
export declare function agentViewLayoutFromTf(value: TfValue, opts: AgentViewLayoutFromTfOptions): AgentViewLayoutFromTfResult;
|
|
48
|
+
/** Own-app field bag keys a pulled layout references (for hoisting their consts). */
|
|
49
|
+
export declare function collectAgentViewLayoutFieldKeys(layout: NormalizedAgentViewLayout | undefined): string[];
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pull: `elementum_agent_view.layout` → the normalized layout the printer
|
|
3
|
+
* turns back into `agentViews.<key>.layout`. References inside the custom
|
|
4
|
+
* view become typed markers at the per-block id positions; raw platform ids
|
|
5
|
+
* there become `unsafePlatformId(...)`. A layout this cannot represent makes
|
|
6
|
+
* the whole view unmanaged (skipped), never silently dropped: the code owns
|
|
7
|
+
* the layout, so a dropped detail would be cleared on the next apply.
|
|
8
|
+
*/
|
|
9
|
+
import { isTfExpr } from "../../engine/tf/index.js";
|
|
10
|
+
import { AGENT_VIEW_SPEC_FILTER_PROPS, AGENT_VIEW_SPEC_ID_PROPS } from "./agent-view-layout.js";
|
|
11
|
+
const PLATFORM_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
12
|
+
const ATTACHMENT_URL = /^\/api\/v1\/attachments\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;
|
|
13
|
+
const FILTER_PROPS = new Set(AGENT_VIEW_SPEC_FILTER_PROPS);
|
|
14
|
+
const ID_PROPS = AGENT_VIEW_SPEC_ID_PROPS;
|
|
15
|
+
const LAYOUT_STRING_ATTRS = {
|
|
16
|
+
header: "header",
|
|
17
|
+
sub_header: "subHeader",
|
|
18
|
+
background_color: "backgroundColor",
|
|
19
|
+
primary_color: "primaryColor",
|
|
20
|
+
font_family: "fontFamily",
|
|
21
|
+
};
|
|
22
|
+
const KNOWN_LAYOUT_ATTRS = new Set(["image_url", "custom_view", ...Object.keys(LAYOUT_STRING_ATTRS)]);
|
|
23
|
+
class Unrepresentable extends Error {
|
|
24
|
+
}
|
|
25
|
+
export function agentViewLayoutFromTf(value, opts) {
|
|
26
|
+
try {
|
|
27
|
+
return { ok: true, layout: decodeLayout(value, opts) };
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof Unrepresentable)
|
|
31
|
+
return { ok: false, reason: error.message };
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function decodeLayout(value, opts) {
|
|
36
|
+
const attrs = plain(value);
|
|
37
|
+
if (attrs === undefined)
|
|
38
|
+
throw new Unrepresentable("layout is not an object");
|
|
39
|
+
const unknown = Object.keys(attrs).filter((key) => !KNOWN_LAYOUT_ATTRS.has(key));
|
|
40
|
+
if (unknown.length > 0)
|
|
41
|
+
throw new Unrepresentable(`layout has unhandled attributes: ${unknown.sort().join(", ")}`);
|
|
42
|
+
const layout = {};
|
|
43
|
+
const imageUrl = attrs["image_url"];
|
|
44
|
+
if (imageUrl !== undefined) {
|
|
45
|
+
if (typeof imageUrl !== "string")
|
|
46
|
+
throw new Unrepresentable("layout.image_url is not a string");
|
|
47
|
+
const attachment = ATTACHMENT_URL.exec(imageUrl)?.[1];
|
|
48
|
+
layout.image = attachment !== undefined ? { attachment } : { url: imageUrl };
|
|
49
|
+
}
|
|
50
|
+
for (const [attr, key] of Object.entries(LAYOUT_STRING_ATTRS)) {
|
|
51
|
+
const v = attrs[attr];
|
|
52
|
+
if (v === undefined)
|
|
53
|
+
continue;
|
|
54
|
+
if (typeof v !== "string")
|
|
55
|
+
throw new Unrepresentable(`layout.${attr} is not a string`);
|
|
56
|
+
const normalized = key === "backgroundColor" || key === "primaryColor"
|
|
57
|
+
? normalizeColor(v)
|
|
58
|
+
: key === "fontFamily" ? normalizeFont(v) : v;
|
|
59
|
+
if (normalized !== undefined)
|
|
60
|
+
layout[key] = normalized;
|
|
61
|
+
}
|
|
62
|
+
const customView = attrs["custom_view"];
|
|
63
|
+
if (customView !== undefined) {
|
|
64
|
+
if (!isTfExpr(customView) || customView.$expr !== "jsonencode")
|
|
65
|
+
throw new Unrepresentable("layout.custom_view is not a jsonencode(...) expression");
|
|
66
|
+
layout.customView = decodeSpec(customView.value, opts);
|
|
67
|
+
}
|
|
68
|
+
return layout;
|
|
69
|
+
}
|
|
70
|
+
function decodeSpec(value, opts) {
|
|
71
|
+
const spec = plain(value);
|
|
72
|
+
if (spec === undefined)
|
|
73
|
+
throw new Unrepresentable("custom_view is not an object");
|
|
74
|
+
const out = {};
|
|
75
|
+
for (const [key, child] of Object.entries(spec)) {
|
|
76
|
+
if (key !== "elements") {
|
|
77
|
+
out[key] = literal(child, `custom_view.${key}`);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const elements = plain(child);
|
|
81
|
+
if (elements === undefined)
|
|
82
|
+
throw new Unrepresentable("custom_view.elements is not an object");
|
|
83
|
+
const outElements = {};
|
|
84
|
+
for (const [id, rawElement] of Object.entries(elements)) {
|
|
85
|
+
const element = plain(rawElement);
|
|
86
|
+
if (element === undefined)
|
|
87
|
+
throw new Unrepresentable(`custom_view.elements.${id} is not an object`);
|
|
88
|
+
const type = typeof element["type"] === "string" ? element["type"] : "";
|
|
89
|
+
const outElement = {};
|
|
90
|
+
for (const [elKey, elValue] of Object.entries(element)) {
|
|
91
|
+
const where = `custom_view.elements.${id}.${elKey}`;
|
|
92
|
+
outElement[elKey] = elKey === "props" ? decodeProps(type, elValue, where, opts) : literal(elValue, where);
|
|
93
|
+
}
|
|
94
|
+
outElements[id] = outElement;
|
|
95
|
+
}
|
|
96
|
+
out["elements"] = outElements;
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
function decodeProps(type, value, where, opts) {
|
|
101
|
+
const props = plain(value);
|
|
102
|
+
if (props === undefined)
|
|
103
|
+
return literal(value, where);
|
|
104
|
+
const idProps = ID_PROPS[type] ?? {};
|
|
105
|
+
const out = {};
|
|
106
|
+
for (const [key, child] of Object.entries(props)) {
|
|
107
|
+
const propWhere = `${where}.${key}`;
|
|
108
|
+
const kind = idProps[key];
|
|
109
|
+
if (kind !== undefined && (isTfExpr(child) || (typeof child === "string" && child !== ""))) {
|
|
110
|
+
out[key] = kind === "field" ? fieldMarker(child, propWhere, opts) : appMarker(child, propWhere, opts);
|
|
111
|
+
}
|
|
112
|
+
else if (FILTER_PROPS.has(key)) {
|
|
113
|
+
out[key] = deepRefs(child, propWhere, opts);
|
|
114
|
+
}
|
|
115
|
+
else if (type === "ButtonBlock" && key === "buttons" && Array.isArray(child)) {
|
|
116
|
+
out[key] = child.map((item, i) => {
|
|
117
|
+
const button = plain(item);
|
|
118
|
+
if (button === undefined)
|
|
119
|
+
return literal(item, `${propWhere}[${i}]`);
|
|
120
|
+
return Object.fromEntries(Object.entries(button).map(([bKey, bValue]) => [
|
|
121
|
+
bKey,
|
|
122
|
+
bKey === "viewId" && typeof bValue === "string" && bValue !== "" ? unsafe(bValue) : literal(bValue, `${propWhere}[${i}].${bKey}`),
|
|
123
|
+
]));
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
out[key] = literal(child, propWhere);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
function deepRefs(value, where, opts) {
|
|
133
|
+
if (isTfExpr(value)) {
|
|
134
|
+
if (opts.isOwnApp(value))
|
|
135
|
+
return { __specRef: "app" };
|
|
136
|
+
return fieldMarker(value, where, opts);
|
|
137
|
+
}
|
|
138
|
+
if (isPlatformId(value))
|
|
139
|
+
return unsafe(value);
|
|
140
|
+
if (Array.isArray(value))
|
|
141
|
+
return value.map((item, i) => deepRefs(item, `${where}[${i}]`, opts));
|
|
142
|
+
const rec = plain(value);
|
|
143
|
+
if (rec !== undefined)
|
|
144
|
+
return Object.fromEntries(Object.entries(rec).map(([key, child]) => [key, deepRefs(child, `${where}.${key}`, opts)]));
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
// Any non-empty string at an id position — a platform id, or a value the
|
|
148
|
+
// platform accepted that is not one — prints as unsafePlatformId(...), which
|
|
149
|
+
// build passes through unchanged, so pull → build round-trips exactly. An
|
|
150
|
+
// empty id stays a plain "" (unsafePlatformId rejects it).
|
|
151
|
+
function appMarker(value, where, opts) {
|
|
152
|
+
if (typeof value === "string")
|
|
153
|
+
return unsafe(value);
|
|
154
|
+
if (opts.isOwnApp(value))
|
|
155
|
+
return { __specRef: "app" };
|
|
156
|
+
throw new Unrepresentable(`${where} references an app the EDK cannot represent here`);
|
|
157
|
+
}
|
|
158
|
+
function fieldMarker(value, where, opts) {
|
|
159
|
+
if (typeof value === "string")
|
|
160
|
+
return unsafe(value);
|
|
161
|
+
const key = opts.fieldKey(value);
|
|
162
|
+
if (key === undefined)
|
|
163
|
+
throw new Unrepresentable(`${where} references a field the EDK cannot represent here`);
|
|
164
|
+
return PLATFORM_ID.test(key) ? unsafe(key) : { __specRef: "field", key };
|
|
165
|
+
}
|
|
166
|
+
/** Plain JSON outside the id positions: any reference here is unrepresentable. */
|
|
167
|
+
function literal(value, where) {
|
|
168
|
+
if (isTfExpr(value))
|
|
169
|
+
throw new Unrepresentable(`${where} holds a reference outside the custom view's id props`);
|
|
170
|
+
if (Array.isArray(value))
|
|
171
|
+
return value.map((item, i) => literal(item, `${where}[${i}]`));
|
|
172
|
+
const rec = plain(value);
|
|
173
|
+
if (rec !== undefined)
|
|
174
|
+
return Object.fromEntries(Object.entries(rec).map(([key, child]) => [key, literal(child, `${where}.${key}`)]));
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
const HEX_COLOR = /^#?[0-9a-fA-F]{3,8}$/;
|
|
178
|
+
const FONT_FAMILIES = new Set(["sans", "serif", "mono"]);
|
|
179
|
+
/**
|
|
180
|
+
* The page renders only hex colours (with or without '#'), so pull mirrors the
|
|
181
|
+
* provider's normalization: '#'-prefix a bare hex, and treat anything else as
|
|
182
|
+
* unset (the platform ignores it).
|
|
183
|
+
*/
|
|
184
|
+
function normalizeColor(color) {
|
|
185
|
+
const trimmed = color.trim();
|
|
186
|
+
if (!HEX_COLOR.test(trimmed))
|
|
187
|
+
return undefined;
|
|
188
|
+
return trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
|
|
189
|
+
}
|
|
190
|
+
/** An unknown font renders as system, the default. */
|
|
191
|
+
function normalizeFont(font) {
|
|
192
|
+
return FONT_FAMILIES.has(font) ? font : undefined;
|
|
193
|
+
}
|
|
194
|
+
function unsafe(id) {
|
|
195
|
+
return { __specRef: "unsafe", id };
|
|
196
|
+
}
|
|
197
|
+
function isPlatformId(value) {
|
|
198
|
+
return typeof value === "string" && PLATFORM_ID.test(value);
|
|
199
|
+
}
|
|
200
|
+
function plain(value) {
|
|
201
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && !isTfExpr(value)
|
|
202
|
+
? value
|
|
203
|
+
: undefined;
|
|
204
|
+
}
|
|
205
|
+
/** Own-app field bag keys a pulled layout references (for hoisting their consts). */
|
|
206
|
+
export function collectAgentViewLayoutFieldKeys(layout) {
|
|
207
|
+
const keys = [];
|
|
208
|
+
const walk = (value) => {
|
|
209
|
+
if (Array.isArray(value)) {
|
|
210
|
+
value.forEach(walk);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (value === null || typeof value !== "object")
|
|
214
|
+
return;
|
|
215
|
+
const rec = value;
|
|
216
|
+
if (rec["__specRef"] === "field" && typeof rec["key"] === "string") {
|
|
217
|
+
keys.push(rec["key"]);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
Object.values(rec).forEach(walk);
|
|
221
|
+
};
|
|
222
|
+
walk(layout?.customView);
|
|
223
|
+
return keys;
|
|
224
|
+
}
|