@plasm_lang/vercel-agent 0.3.63
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 +235 -0
- package/agent/.plasm/archives/runs/runs/pr2d5c4a99707b4c19b650553d50229a1d600d28e3d98a9c58f18e5026cecc86ca.json +64 -0
- package/agent/.plasm/archives/runs/runs/pr2e0c0d8ad443c63c82da7435ee1a002b0e0fa718b640263c0a9d3e6e5944812f.json +64 -0
- package/agent/.plasm/archives/runs/runs/pr2faedb8354f40ee6d828e3af07b421fda9ccda973a4f7347fce3639f03a0a869.json +64 -0
- package/agent/.plasm/archives/runs/runs/pr586b47c55547b0702c572bce4255558b22dbe5e682d6359169577e0ea75fe98f.json +64 -0
- package/agent/.plasm/archives/runs/runs/pr76212356445e3b00fcf256835aaec18bac68576324b90d0be92d47f0b4a862a7.json +56 -0
- package/agent/.plasm/archives/runs/runs/pr9ec805d689e00db9270a9539858f2fb7216c24acbfea943d450e37b641149da1.json +64 -0
- package/agent/.plasm/archives/runs/runs/prc3c0c4ba2e28fc94ed6d37b6796e277a7997d9cb3184640d14c35c98bc6d136f.json +64 -0
- package/agent/.plasm/archives/runs/runs/prf04de32522f2fdcb17818907d91bccce7dcaecbd1259041cc448d447b6993244.json +64 -0
- package/agent/.plasm/archives/traces/traces/local/00000000000000000000000000000000/records.ndjson +1 -0
- package/agent/.plasm/archives/traces/traces/local/00000000000000000000000000000000/summary.json +13 -0
- package/agent/.plasm/discovery/manifest.json +126 -0
- package/agent/.plasm/sessions/TGlzdCBwcm9kdWN0cyBmcm9tIHRoZSBleGVjdXRlX3RpbnkgY2F0YWxvZw.json +44 -0
- package/agent/.plasm/sessions/TGlzdCBwcm9kdWN0cyBmcm9tIHRoZSBleGVjdXRlX3RpbnkgY2F0YWxvZw.teaching.tsv +23 -0
- package/agent/.plasm/sessions/bGlzdCBleGVjdXRlX3RpbnkgcHJvZHVjdHM.json +151 -0
- package/agent/.plasm/sessions/bGlzdCBleGVjdXRlX3RpbnkgcHJvZHVjdHM.teaching.tsv +131 -0
- package/agent/.plasm/sessions/bGlzdCBleGVjdXRlX3RpbnkgcHJvZHVjdHMgYXN5bmMgdHJhbnNwb3J0.json +44 -0
- package/agent/.plasm/sessions/bGlzdCBleGVjdXRlX3RpbnkgcHJvZHVjdHMgYXN5bmMgdHJhbnNwb3J0.teaching.tsv +23 -0
- package/agent/.plasm/stubs/.gitkeep +0 -0
- package/agent/.plasm/stubs/execute_tiny.ts +107 -0
- package/agent/agent.ts +52 -0
- package/agent/catalogs/README.md +15 -0
- package/agent/channels/.gitkeep +0 -0
- package/agent/channels/execute-tiny-webhook.ts +59 -0
- package/agent/channels/health.ts +16 -0
- package/agent/hooks/.gitkeep +0 -0
- package/agent/hooks/trace-log.ts +10 -0
- package/agent/instructions.md +25 -0
- package/agent/schedules/.gitkeep +0 -0
- package/agent/schedules/ping.ts +13 -0
- package/agent/skills/.gitkeep +0 -0
- package/agent/skills/plasm-authoring.md +8 -0
- package/agent/subagents/.gitkeep +0 -0
- package/agent/subagents/tiny/agent.ts +28 -0
- package/bin/plasm-agent.mjs +18 -0
- package/package.json +77 -0
- package/scripts/plasm-node.mjs +19 -0
- package/scripts/resolve-ts-extension.mjs +18 -0
- package/src/archive/adapters.ts +27 -0
- package/src/archive/index.ts +99 -0
- package/src/archive/local-run-archive.ts +90 -0
- package/src/archive/local-trace-archive.ts +91 -0
- package/src/archive/paths.ts +15 -0
- package/src/archive/postgres-kv-adapter.ts +72 -0
- package/src/archive/prod-archive-store.ts +143 -0
- package/src/archive/resolve-backend.ts +60 -0
- package/src/archive/run-id.ts +23 -0
- package/src/archive/types.ts +75 -0
- package/src/archive/vercel-blob-adapter.ts +21 -0
- package/src/archive/vercel-kv-adapter.ts +24 -0
- package/src/authoring/channel-dispatch.ts +44 -0
- package/src/authoring/context.ts +34 -0
- package/src/authoring/define-channel.ts +83 -0
- package/src/authoring/define-hook.ts +51 -0
- package/src/authoring/define-schedule.ts +64 -0
- package/src/authoring/define-skill.ts +38 -0
- package/src/authoring/hook-runner.ts +18 -0
- package/src/authoring/schedule-manager.ts +118 -0
- package/src/authoring/slot-loader.ts +253 -0
- package/src/authoring/subagent-loader.ts +121 -0
- package/src/catalog/loader.ts +71 -0
- package/src/cli/build.ts +54 -0
- package/src/cli/dev.ts +60 -0
- package/src/cli/info.ts +12 -0
- package/src/cli/init.ts +372 -0
- package/src/cli/link.ts +68 -0
- package/src/cli/project-root.ts +57 -0
- package/src/define-agent.ts +150 -0
- package/src/dev/client/ansi.ts +36 -0
- package/src/dev/client/http-session.ts +180 -0
- package/src/dev/client/repl.ts +92 -0
- package/src/dev/client/slash.ts +119 -0
- package/src/dev/dev-session.ts +153 -0
- package/src/dev/http.ts +29 -0
- package/src/dev/server.ts +147 -0
- package/src/dev/session-routes.ts +185 -0
- package/src/discovery/project-walker.ts +272 -0
- package/src/engine/connect-auth.ts +135 -0
- package/src/engine/create-host-transport.ts +7 -0
- package/src/engine/fixture-mock-transport.ts +54 -0
- package/src/engine/host-transport-bridge.ts +32 -0
- package/src/engine/host-transport.ts +84 -0
- package/src/engine/napi-binding.ts +265 -0
- package/src/evals/define-eval.ts +56 -0
- package/src/evals/run-eval.ts +136 -0
- package/src/gateway-model.ts +43 -0
- package/src/index.ts +296 -0
- package/src/instrumentation.ts +56 -0
- package/src/load-env.ts +63 -0
- package/src/operator/routes.ts +287 -0
- package/src/operator/types.ts +63 -0
- package/src/operator/ui-shell.ts +134 -0
- package/src/project-info.ts +229 -0
- package/src/runtime/agent-runtime.ts +469 -0
- package/src/runtime/compaction.ts +81 -0
- package/src/runtime/logical-session.ts +72 -0
- package/src/runtime/plasm-agent.ts +199 -0
- package/src/server/plasm-handler.ts +331 -0
- package/src/session-state.ts +135 -0
- package/src/state/define-state.ts +57 -0
- package/src/state/fs-state-adapter.ts +72 -0
- package/src/state/kv-state-adapter.ts +62 -0
- package/src/state/postgres-state-adapter.ts +116 -0
- package/src/stubs/capability-invoke-shape.ts +135 -0
- package/src/stubs/catalog-client.ts +170 -0
- package/src/stubs/catalog-hash.ts +11 -0
- package/src/stubs/catalog-introspection.ts +121 -0
- package/src/stubs/cgs-ts-types.ts +164 -0
- package/src/stubs/domain-parser.ts +203 -0
- package/src/stubs/generator.ts +390 -0
- package/src/stubs/input-type-to-ts.ts +233 -0
- package/src/stubs/plasm-value-emitter.ts +162 -0
- package/src/stubs/program-builder.ts +82 -0
- package/src/stubs/stub-symbols.ts +89 -0
- package/src/symbol-registry.ts +74 -0
- package/src/telemetry/plasm-spans.ts +83 -0
- package/src/tools/descriptions.ts +94 -0
- package/src/tools/format.ts +29 -0
- package/src/tools/harness-tools.ts +65 -0
- package/src/tools/plasm-tools.ts +104 -0
- package/src/workflow/world-bootstrap.ts +52 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/** JSON shape from `PlasmEngine.introspectCatalog()` (post-merge CGS). */
|
|
2
|
+
|
|
3
|
+
export type FieldTypeJson =
|
|
4
|
+
| "boolean"
|
|
5
|
+
| "number"
|
|
6
|
+
| "integer"
|
|
7
|
+
| "uuid"
|
|
8
|
+
| "blob"
|
|
9
|
+
| "string"
|
|
10
|
+
| "select"
|
|
11
|
+
| "multi_select"
|
|
12
|
+
| "date"
|
|
13
|
+
| "array"
|
|
14
|
+
| "json"
|
|
15
|
+
| { entity_ref: { target: string } };
|
|
16
|
+
|
|
17
|
+
export interface NamedValueSchemaJson {
|
|
18
|
+
description?: string;
|
|
19
|
+
field_type: FieldTypeJson;
|
|
20
|
+
value_format?: string;
|
|
21
|
+
allowed_values?: string[];
|
|
22
|
+
string_semantics?: string;
|
|
23
|
+
array_items?: {
|
|
24
|
+
value_ref?: string;
|
|
25
|
+
field_type?: FieldTypeJson;
|
|
26
|
+
allowed_values?: string[];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface InputFieldSchemaJson {
|
|
31
|
+
name: string;
|
|
32
|
+
value_ref?: string;
|
|
33
|
+
input_type?: InputTypeJson;
|
|
34
|
+
required?: boolean;
|
|
35
|
+
description?: string;
|
|
36
|
+
role?: ParameterRoleJson;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type ParameterRoleJson =
|
|
40
|
+
| "filter"
|
|
41
|
+
| "search"
|
|
42
|
+
| "sort"
|
|
43
|
+
| "sort_direction"
|
|
44
|
+
| "response_control"
|
|
45
|
+
| "scope";
|
|
46
|
+
|
|
47
|
+
export type InputTypeJson =
|
|
48
|
+
| { type: "none" }
|
|
49
|
+
| {
|
|
50
|
+
type: "value";
|
|
51
|
+
field_type: FieldTypeJson;
|
|
52
|
+
allowed_values?: string[];
|
|
53
|
+
}
|
|
54
|
+
| {
|
|
55
|
+
type: "object";
|
|
56
|
+
fields: InputFieldSchemaJson[];
|
|
57
|
+
additional_fields?: boolean;
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
type: "array";
|
|
61
|
+
element_type: InputTypeJson;
|
|
62
|
+
min_length?: number;
|
|
63
|
+
max_length?: number;
|
|
64
|
+
}
|
|
65
|
+
| {
|
|
66
|
+
type: "union";
|
|
67
|
+
variants: InputVariantSchemaJson[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export interface InputVariantSchemaJson {
|
|
71
|
+
name: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
constructor_symbol?: string;
|
|
74
|
+
fields: InputFieldSchemaJson[];
|
|
75
|
+
wire: { field: string; value: string };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface InputSchemaJson {
|
|
79
|
+
input_type: InputTypeJson;
|
|
80
|
+
description?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface OutputSchemaJson {
|
|
84
|
+
type: "side_effect" | "entity" | "collection" | "status" | "custom";
|
|
85
|
+
description?: string;
|
|
86
|
+
entity_type?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface CapabilityIntrospectionJson {
|
|
90
|
+
name: string;
|
|
91
|
+
kind: string;
|
|
92
|
+
entity: string;
|
|
93
|
+
invoke_wire_name: string;
|
|
94
|
+
input_schema: InputSchemaJson | null;
|
|
95
|
+
provides: string[];
|
|
96
|
+
output_schema: OutputSchemaJson | null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface EntityFieldIntrospectionJson {
|
|
100
|
+
name: string;
|
|
101
|
+
value_ref: string;
|
|
102
|
+
required: boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface EntityIntrospectionJson {
|
|
106
|
+
name: string;
|
|
107
|
+
id_field: string;
|
|
108
|
+
fields: EntityFieldIntrospectionJson[];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface CatalogIntrospectionJson {
|
|
112
|
+
entry_id: string;
|
|
113
|
+
catalog_cgs_hash: string;
|
|
114
|
+
entities: EntityIntrospectionJson[];
|
|
115
|
+
values: Record<string, NamedValueSchemaJson>;
|
|
116
|
+
capabilities: CapabilityIntrospectionJson[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function parseCatalogIntrospection(json: string): CatalogIntrospectionJson {
|
|
120
|
+
return JSON.parse(json) as CatalogIntrospectionJson;
|
|
121
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CgsCapability,
|
|
3
|
+
CgsEntity,
|
|
4
|
+
CgsField,
|
|
5
|
+
CgsParameter,
|
|
6
|
+
CgsValueDomain,
|
|
7
|
+
ParsedCgsDomain,
|
|
8
|
+
} from "./domain-parser.js";
|
|
9
|
+
|
|
10
|
+
export function valueDomainToTsType(
|
|
11
|
+
domain: CgsValueDomain | undefined,
|
|
12
|
+
entityTypes: Map<string, string>,
|
|
13
|
+
): string {
|
|
14
|
+
if (!domain) return "unknown";
|
|
15
|
+
switch (domain.type) {
|
|
16
|
+
case "string":
|
|
17
|
+
case "uuid":
|
|
18
|
+
case "date":
|
|
19
|
+
return "string";
|
|
20
|
+
case "integer":
|
|
21
|
+
case "number":
|
|
22
|
+
return "number";
|
|
23
|
+
case "boolean":
|
|
24
|
+
return "boolean";
|
|
25
|
+
case "json":
|
|
26
|
+
return "unknown";
|
|
27
|
+
case "entity_ref": {
|
|
28
|
+
const target = domain.target;
|
|
29
|
+
if (target && entityTypes.has(target)) {
|
|
30
|
+
return entityTypes.get(target)!;
|
|
31
|
+
}
|
|
32
|
+
return "string";
|
|
33
|
+
}
|
|
34
|
+
case "select": {
|
|
35
|
+
const allowed = domain.allowedValues ?? [];
|
|
36
|
+
if (!allowed.length) return "string";
|
|
37
|
+
return allowed.map((v) => JSON.stringify(v)).join(" | ");
|
|
38
|
+
}
|
|
39
|
+
case "array":
|
|
40
|
+
return "unknown[]";
|
|
41
|
+
default:
|
|
42
|
+
return "unknown";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function fieldByName(entity: CgsEntity, name: string): CgsField | undefined {
|
|
47
|
+
return entity.fields.find((f) => f.name === name);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function resolveFieldTsType(
|
|
51
|
+
fieldName: string,
|
|
52
|
+
entity: CgsEntity,
|
|
53
|
+
values: Map<string, CgsValueDomain>,
|
|
54
|
+
entityTypes: Map<string, string>,
|
|
55
|
+
/** Wire row JSON uses string ids for entity_ref fields, not nested objects. */
|
|
56
|
+
outputField = false,
|
|
57
|
+
): { type: string; optional: boolean } {
|
|
58
|
+
const field = fieldByName(entity, fieldName);
|
|
59
|
+
if (!field) return { type: "unknown", optional: true };
|
|
60
|
+
const domain = values.get(field.valueRef);
|
|
61
|
+
if (outputField && domain?.type === "entity_ref") {
|
|
62
|
+
return { type: "string", optional: !field.required };
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
type: valueDomainToTsType(domain, entityTypes),
|
|
66
|
+
optional: !field.required,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function entityTypeName(entityName: string): string {
|
|
71
|
+
return entityName.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function buildEntityTypeMap(domain: ParsedCgsDomain): Map<string, string> {
|
|
75
|
+
const out = new Map<string, string>();
|
|
76
|
+
for (const entity of domain.entities) {
|
|
77
|
+
out.set(entity.name, entityTypeName(entity.name));
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function renderEntityType(
|
|
83
|
+
entity: CgsEntity,
|
|
84
|
+
domain: ParsedCgsDomain,
|
|
85
|
+
fieldNames: string[],
|
|
86
|
+
): string {
|
|
87
|
+
const entityTypes = buildEntityTypeMap(domain);
|
|
88
|
+
const lines: string[] = [];
|
|
89
|
+
for (const fieldName of fieldNames) {
|
|
90
|
+
const { type, optional } = resolveFieldTsType(
|
|
91
|
+
fieldName,
|
|
92
|
+
entity,
|
|
93
|
+
domain.values,
|
|
94
|
+
entityTypes,
|
|
95
|
+
true,
|
|
96
|
+
);
|
|
97
|
+
lines.push(`${fieldName}${optional ? "?" : ""}: ${type};`);
|
|
98
|
+
}
|
|
99
|
+
const typeName = entityTypeName(entity.name);
|
|
100
|
+
return `export type ${typeName} = {\n ${lines.join("\n ")}\n};`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function effectiveProvides(cap: CgsCapability, entity: CgsEntity): string[] {
|
|
104
|
+
if (cap.provides.length) return cap.provides;
|
|
105
|
+
const names = entity.fields.map((f) => f.name);
|
|
106
|
+
const idIdx = names.indexOf(entity.idField);
|
|
107
|
+
if (idIdx > 0) {
|
|
108
|
+
names.splice(idIdx, 1);
|
|
109
|
+
names.unshift(entity.idField);
|
|
110
|
+
}
|
|
111
|
+
return names;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function capabilityInputTypeName(cap: CgsCapability): string {
|
|
115
|
+
const base = cap.name
|
|
116
|
+
.split(/[^a-zA-Z0-9]+/)
|
|
117
|
+
.filter(Boolean)
|
|
118
|
+
.map((part) => part[0]!.toUpperCase() + part.slice(1))
|
|
119
|
+
.join("");
|
|
120
|
+
return `${base}Input`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function renderCapabilityInputType(
|
|
124
|
+
cap: CgsCapability,
|
|
125
|
+
entity: CgsEntity,
|
|
126
|
+
domain: ParsedCgsDomain,
|
|
127
|
+
): string | null {
|
|
128
|
+
const entityTypes = buildEntityTypeMap(domain);
|
|
129
|
+
const kind = cap.kind.toLowerCase();
|
|
130
|
+
const lines: string[] = [];
|
|
131
|
+
|
|
132
|
+
if (kind === "get") {
|
|
133
|
+
const idField = fieldByName(entity, entity.idField);
|
|
134
|
+
const idType = idField
|
|
135
|
+
? valueDomainToTsType(domain.values.get(idField.valueRef), entityTypes)
|
|
136
|
+
: "string";
|
|
137
|
+
lines.push(`${entity.idField}: ${idType};`);
|
|
138
|
+
} else {
|
|
139
|
+
for (const param of cap.parameters) {
|
|
140
|
+
const domainRow = domain.values.get(param.valueRef);
|
|
141
|
+
const optional = !param.required;
|
|
142
|
+
lines.push(
|
|
143
|
+
`${param.name}${optional ? "?" : ""}: ${valueDomainToTsType(domainRow, entityTypes)};`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!lines.length) return null;
|
|
149
|
+
return `export type ${capabilityInputTypeName(cap)} = {\n ${lines.join("\n ")}\n};`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function capabilityNeedsInput(cap: CgsCapability): boolean {
|
|
153
|
+
const kind = cap.kind.toLowerCase();
|
|
154
|
+
if (kind === "get") return true;
|
|
155
|
+
return cap.parameters.length > 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function parameterTsType(
|
|
159
|
+
param: CgsParameter,
|
|
160
|
+
domain: ParsedCgsDomain,
|
|
161
|
+
): string {
|
|
162
|
+
const entityTypes = buildEntityTypeMap(domain);
|
|
163
|
+
return valueDomainToTsType(domain.values.get(param.valueRef), entityTypes);
|
|
164
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import yaml from "js-yaml";
|
|
2
|
+
|
|
3
|
+
export interface CgsValueDomain {
|
|
4
|
+
key: string;
|
|
5
|
+
type: string;
|
|
6
|
+
target?: string;
|
|
7
|
+
allowedValues?: string[];
|
|
8
|
+
description?: string;
|
|
9
|
+
stringSemantics?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CgsField {
|
|
13
|
+
name: string;
|
|
14
|
+
valueRef: string;
|
|
15
|
+
required: boolean;
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CgsEntity {
|
|
20
|
+
name: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
idField: string;
|
|
23
|
+
fields: CgsField[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CgsParameter {
|
|
27
|
+
name: string;
|
|
28
|
+
valueRef: string;
|
|
29
|
+
required: boolean;
|
|
30
|
+
role?: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface CgsCapability {
|
|
35
|
+
name: string;
|
|
36
|
+
entity: string;
|
|
37
|
+
kind: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
parameters: CgsParameter[];
|
|
40
|
+
provides: string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ParsedCgsDomain {
|
|
44
|
+
entryId: string;
|
|
45
|
+
authScheme?: string;
|
|
46
|
+
entities: CgsEntity[];
|
|
47
|
+
capabilities: CgsCapability[];
|
|
48
|
+
values: Map<string, CgsValueDomain>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type RawDomain = {
|
|
52
|
+
entry_id?: string;
|
|
53
|
+
auth?: { scheme?: string };
|
|
54
|
+
entities?: Record<
|
|
55
|
+
string,
|
|
56
|
+
{
|
|
57
|
+
description?: string;
|
|
58
|
+
id_field?: string;
|
|
59
|
+
fields?: Record<
|
|
60
|
+
string,
|
|
61
|
+
{
|
|
62
|
+
value_ref?: string;
|
|
63
|
+
required?: boolean;
|
|
64
|
+
description?: string;
|
|
65
|
+
}
|
|
66
|
+
>;
|
|
67
|
+
}
|
|
68
|
+
>;
|
|
69
|
+
capabilities?: Record<
|
|
70
|
+
string,
|
|
71
|
+
{
|
|
72
|
+
description?: string;
|
|
73
|
+
kind?: string;
|
|
74
|
+
entity?: string;
|
|
75
|
+
parameters?: Array<{
|
|
76
|
+
name?: string;
|
|
77
|
+
value_ref?: string;
|
|
78
|
+
required?: boolean;
|
|
79
|
+
role?: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
}>;
|
|
82
|
+
provides?: string[];
|
|
83
|
+
}
|
|
84
|
+
>;
|
|
85
|
+
values?: Record<
|
|
86
|
+
string,
|
|
87
|
+
{
|
|
88
|
+
type?: string;
|
|
89
|
+
target?: string;
|
|
90
|
+
allowed_values?: string[];
|
|
91
|
+
description?: string;
|
|
92
|
+
string_semantics?: string;
|
|
93
|
+
}
|
|
94
|
+
>;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
function asString(value: unknown): string | undefined {
|
|
98
|
+
return typeof value === "string" ? value : undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Parse `domain.yaml` into a CGS-shaped model for stub generation. */
|
|
102
|
+
export function parseCgsDomain(raw: string, fallbackEntryId: string): ParsedCgsDomain {
|
|
103
|
+
const doc = yaml.load(raw) as RawDomain | null;
|
|
104
|
+
if (!doc || typeof doc !== "object") {
|
|
105
|
+
throw new Error("domain.yaml: expected mapping at root");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const entryId = asString(doc.entry_id)?.trim() || fallbackEntryId;
|
|
109
|
+
const authScheme = asString(doc.auth?.scheme);
|
|
110
|
+
|
|
111
|
+
const values = new Map<string, CgsValueDomain>();
|
|
112
|
+
for (const [key, row] of Object.entries(doc.values ?? {})) {
|
|
113
|
+
if (!row || typeof row !== "object") continue;
|
|
114
|
+
const type = asString(row.type);
|
|
115
|
+
if (!type) continue;
|
|
116
|
+
values.set(key, {
|
|
117
|
+
key,
|
|
118
|
+
type,
|
|
119
|
+
target: asString(row.target),
|
|
120
|
+
allowedValues: Array.isArray(row.allowed_values)
|
|
121
|
+
? row.allowed_values.filter((v): v is string => typeof v === "string")
|
|
122
|
+
: undefined,
|
|
123
|
+
description: asString(row.description),
|
|
124
|
+
stringSemantics: asString(row.string_semantics),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const entities: CgsEntity[] = [];
|
|
129
|
+
for (const [name, entity] of Object.entries(doc.entities ?? {})) {
|
|
130
|
+
if (!entity || typeof entity !== "object") continue;
|
|
131
|
+
const fields: CgsField[] = [];
|
|
132
|
+
for (const [fieldName, field] of Object.entries(entity.fields ?? {})) {
|
|
133
|
+
if (!field || typeof field !== "object") continue;
|
|
134
|
+
const valueRef = asString(field.value_ref);
|
|
135
|
+
if (!valueRef) continue;
|
|
136
|
+
fields.push({
|
|
137
|
+
name: fieldName,
|
|
138
|
+
valueRef,
|
|
139
|
+
required: field.required === true,
|
|
140
|
+
description: asString(field.description),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
entities.push({
|
|
144
|
+
name,
|
|
145
|
+
description: asString(entity.description),
|
|
146
|
+
idField: asString(entity.id_field) ?? "id",
|
|
147
|
+
fields,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const capabilities: CgsCapability[] = [];
|
|
152
|
+
for (const [name, cap] of Object.entries(doc.capabilities ?? {})) {
|
|
153
|
+
if (!cap || typeof cap !== "object") continue;
|
|
154
|
+
const entity = asString(cap.entity);
|
|
155
|
+
const kind = asString(cap.kind);
|
|
156
|
+
if (!entity || !kind) continue;
|
|
157
|
+
const parameters: CgsParameter[] = [];
|
|
158
|
+
for (const param of cap.parameters ?? []) {
|
|
159
|
+
if (!param || typeof param !== "object") continue;
|
|
160
|
+
const paramName = asString(param.name);
|
|
161
|
+
const valueRef = asString(param.value_ref);
|
|
162
|
+
if (!paramName || !valueRef) continue;
|
|
163
|
+
parameters.push({
|
|
164
|
+
name: paramName,
|
|
165
|
+
valueRef,
|
|
166
|
+
required: param.required === true,
|
|
167
|
+
role: asString(param.role),
|
|
168
|
+
description: asString(param.description),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
capabilities.push({
|
|
172
|
+
name,
|
|
173
|
+
entity,
|
|
174
|
+
kind,
|
|
175
|
+
description: asString(cap.description),
|
|
176
|
+
parameters,
|
|
177
|
+
provides: Array.isArray(cap.provides)
|
|
178
|
+
? cap.provides.filter((v): v is string => typeof v === "string")
|
|
179
|
+
: [],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return { entryId, authScheme, entities, capabilities, values };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Legacy shape for operator routes (entity/capability counts). */
|
|
187
|
+
export function toLegacyParsedDomain(domain: ParsedCgsDomain): {
|
|
188
|
+
entryId: string;
|
|
189
|
+
authScheme?: string;
|
|
190
|
+
entities: Array<{ name: string }>;
|
|
191
|
+
capabilities: Array<{ name: string; entity: string; kind?: string }>;
|
|
192
|
+
} {
|
|
193
|
+
return {
|
|
194
|
+
entryId: domain.entryId,
|
|
195
|
+
authScheme: domain.authScheme,
|
|
196
|
+
entities: domain.entities.map((e) => ({ name: e.name })),
|
|
197
|
+
capabilities: domain.capabilities.map((c) => ({
|
|
198
|
+
name: c.name,
|
|
199
|
+
entity: c.entity,
|
|
200
|
+
kind: c.kind,
|
|
201
|
+
})),
|
|
202
|
+
};
|
|
203
|
+
}
|