@elevasis/core 0.49.0 → 0.49.1

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.
@@ -1,295 +1,296 @@
1
- /**
2
- * Registry Serialization Utilities
3
- *
4
- * Pre-serialization logic for ResourceRegistry.
5
- * Converts resource definitions to JSON-safe structures at startup.
6
- */
7
-
8
- import type { DeploymentSpec } from './resource-registry'
9
- import type { ResourceDefinition } from './types'
10
- import type { ResourceEntry } from '../../organization-model/domains/resources'
11
- import type { SystemEntry } from '../../organization-model/domains/systems'
12
- import type {
13
- SerializedOrganizationData,
14
- SerializedAgentDefinition,
15
- SerializedWorkflowDefinition,
16
- CommandViewAgent,
17
- CommandViewWorkflow,
18
- CommandViewEdge
19
- } from './serialized-types'
20
- import { serializeDefinition } from '../../execution/engine/base/serialization'
21
-
22
- function summarizeSystem(system: SystemEntry | undefined): ResourceDefinition['system'] {
23
- if (!system) return undefined
24
-
25
- return {
26
- id: system.id,
27
- title: system.label ?? system.title,
28
- description: system.description,
29
- kind: system.kind,
30
- lifecycle: system.lifecycle
31
- }
32
- }
33
-
34
- function createGovernanceMetadataResolver(resources: DeploymentSpec) {
35
- const resourcesById = new Map(Object.values(resources.organizationModel?.resources ?? {}).map((r) => [r.id, r]))
36
- const systemsById = new Map(Object.values(resources.organizationModel?.systems ?? {}).map((s) => [s.id, s]))
37
-
38
- return (
39
- resourceId: string,
40
- descriptor: ResourceEntry | undefined
41
- ): Pick<ResourceDefinition, 'systemPath' | 'system' | 'governanceStatus'> => {
42
- const resource = descriptor ?? resourcesById.get(resourceId)
43
- if (!resource) return {}
44
-
45
- return {
46
- systemPath: resource.systemPath,
47
- system: summarizeSystem(systemsById.get(resource.systemPath)),
48
- governanceStatus: resource.status
49
- }
50
- }
51
- }
52
-
53
- /**
54
- * Serialize all organization resources
55
- * Called once during ResourceRegistry construction
56
- */
57
- export function serializeAllOrganizations(
58
- registry: Record<string, DeploymentSpec>
59
- ): Map<string, SerializedOrganizationData> {
60
- const cache = new Map<string, SerializedOrganizationData>()
61
- for (const [orgName, resources] of Object.entries(registry)) {
62
- cache.set(orgName, serializeOrganization(resources))
63
- }
64
- return cache
65
- }
66
-
67
- /**
68
- * Serialize single organization's resources
69
- */
70
- export function serializeOrganization(resources: DeploymentSpec): SerializedOrganizationData {
71
- const getGovernanceMetadata = createGovernanceMetadataResolver(resources)
72
-
73
- // Serialize workflows
74
- const workflowDefinitions = new Map<string, SerializedWorkflowDefinition>()
75
- const workflowResources: ResourceDefinition[] = []
76
- const commandViewWorkflows: CommandViewWorkflow[] = []
77
-
78
- for (const workflow of resources.workflows ?? []) {
79
- const resourceId = workflow.config.resourceId
80
- const serialized = serializeDefinition(workflow) as SerializedWorkflowDefinition
81
- workflowDefinitions.set(resourceId, serialized)
82
-
83
- workflowResources.push({
84
- resourceId,
85
- name: workflow.config.name,
86
- description: workflow.config.description,
87
- version: workflow.config.version,
88
- type: 'workflow',
89
- status: workflow.config.status,
90
- links: workflow.config.links,
91
- category: workflow.config.category,
92
- ...getGovernanceMetadata(resourceId, workflow.config.resource)
93
- })
94
-
95
- commandViewWorkflows.push({
96
- resourceId,
97
- name: workflow.config.name,
98
- description: workflow.config.description,
99
- version: workflow.config.version,
100
- type: 'workflow',
101
- status: workflow.config.status,
102
- links: workflow.config.links,
103
- category: workflow.config.category,
104
- ...getGovernanceMetadata(resourceId, workflow.config.resource),
105
- stepCount: Object.keys(workflow.steps).length,
106
- entryPoint: workflow.entryPoint
107
- })
108
- }
109
-
110
- // Serialize agents
111
- const agentDefinitions = new Map<string, SerializedAgentDefinition>()
112
- const agentResources: ResourceDefinition[] = []
113
- const commandViewAgents: CommandViewAgent[] = []
114
-
115
- for (const agent of resources.agents ?? []) {
116
- const resourceId = agent.config.resourceId
117
- const serialized = serializeDefinition(agent) as SerializedAgentDefinition
118
- agentDefinitions.set(resourceId, serialized)
119
-
120
- agentResources.push({
121
- resourceId,
122
- name: agent.config.name,
123
- description: agent.config.description,
124
- version: agent.config.version,
125
- type: 'agent',
126
- status: agent.config.status,
127
- links: agent.config.links,
128
- category: agent.config.category,
129
- ...getGovernanceMetadata(resourceId, agent.config.resource)
130
- })
131
-
132
- commandViewAgents.push({
133
- resourceId,
134
- name: agent.config.name,
135
- description: agent.config.description,
136
- version: agent.config.version,
137
- type: 'agent',
138
- status: agent.config.status,
139
- links: agent.config.links,
140
- category: agent.config.category,
141
- ...getGovernanceMetadata(resourceId, agent.config.resource),
142
- modelProvider: agent.modelConfig.provider,
143
- modelId: agent.modelConfig.model,
144
- toolCount: agent.tools.length,
145
- hasKnowledgeMap: agent.knowledgeMap !== undefined,
146
- hasMemory: agent.config.memoryPreferences !== undefined,
147
- sessionCapable: agent.config.sessionCapable ?? false
148
- })
149
- }
150
-
151
- // Build edges from triggers and relationships
152
- const edges = buildEdges(resources)
153
-
154
- // Pass-through manifest data (already JSON-safe)
155
- const triggers = resources.triggers ?? []
156
- const integrations = resources.integrations ?? []
157
- const externalResources = resources.externalResources ?? []
158
- const humanCheckpoints = resources.humanCheckpoints ?? []
159
-
160
- return {
161
- version: resources.version,
162
- resources: {
163
- workflows: workflowResources,
164
- agents: agentResources,
165
- total: workflowResources.length + agentResources.length
166
- },
167
- definitions: {
168
- workflows: workflowDefinitions,
169
- agents: agentDefinitions
170
- },
171
- commandView: {
172
- workflows: commandViewWorkflows,
173
- agents: commandViewAgents,
174
- triggers,
175
- integrations,
176
- externalResources,
177
- humanCheckpoints,
178
- edges
179
- },
180
- triggers,
181
- integrations,
182
- externalResources,
183
- humanCheckpoints,
184
- relationships: resources.relationships
185
- }
186
- }
187
-
188
- /**
189
- * Build Command View edges from relationships
190
- * NOTE: Trigger relationships are now declared in ResourceRelationships, not on TriggerDefinition
191
- */
192
- export function buildEdges(resources: DeploymentSpec): CommandViewEdge[] {
193
- const edges: CommandViewEdge[] = []
194
- let edgeId = 0
195
-
196
- // All relationship edges (triggers, agents, workflows can all declare relationships)
197
- for (const [resourceId, declaration] of Object.entries(resources.relationships ?? {})) {
198
- for (const agentId of declaration.triggers?.agents ?? []) {
199
- edges.push({
200
- id: `edge-${edgeId++}`,
201
- source: resourceId,
202
- target: agentId,
203
- relationship: 'triggers'
204
- })
205
- }
206
- for (const workflowId of declaration.triggers?.workflows ?? []) {
207
- edges.push({
208
- id: `edge-${edgeId++}`,
209
- source: resourceId,
210
- target: workflowId,
211
- relationship: 'triggers'
212
- })
213
- }
214
- for (const integrationId of declaration.uses?.integrations ?? []) {
215
- edges.push({
216
- id: `edge-${edgeId++}`,
217
- source: resourceId,
218
- target: integrationId,
219
- relationship: 'uses'
220
- })
221
- }
222
- }
223
-
224
- // External Resource edges (forward-only)
225
- for (const external of resources.externalResources ?? []) {
226
- // External -> Internal
227
- for (const workflowId of external.triggers?.workflows ?? []) {
228
- edges.push({
229
- id: `edge-${edgeId++}`,
230
- source: external.resourceId,
231
- target: workflowId,
232
- relationship: 'triggers'
233
- })
234
- }
235
- for (const agentId of external.triggers?.agents ?? []) {
236
- edges.push({
237
- id: `edge-${edgeId++}`,
238
- source: external.resourceId,
239
- target: agentId,
240
- relationship: 'triggers'
241
- })
242
- }
243
-
244
- // External -> Integration
245
- for (const integrationId of external.uses?.integrations ?? []) {
246
- edges.push({
247
- id: `edge-${edgeId++}`,
248
- source: external.resourceId,
249
- target: integrationId,
250
- relationship: 'uses'
251
- })
252
- }
253
- }
254
-
255
- // Human Checkpoint edges
256
- for (const humanCheckpoint of resources.humanCheckpoints ?? []) {
257
- // Agent/Workflow -> ApprovalPoint
258
- for (const agentId of humanCheckpoint.requestedBy?.agents ?? []) {
259
- edges.push({
260
- id: `edge-${edgeId++}`,
261
- source: agentId,
262
- target: humanCheckpoint.resourceId,
263
- relationship: 'approval'
264
- })
265
- }
266
- for (const workflowId of humanCheckpoint.requestedBy?.workflows ?? []) {
267
- edges.push({
268
- id: `edge-${edgeId++}`,
269
- source: workflowId,
270
- target: humanCheckpoint.resourceId,
271
- relationship: 'approval'
272
- })
273
- }
274
-
275
- // ApprovalPoint -> Agent/Workflow
276
- for (const agentId of humanCheckpoint.routesTo?.agents ?? []) {
277
- edges.push({
278
- id: `edge-${edgeId++}`,
279
- source: humanCheckpoint.resourceId,
280
- target: agentId,
281
- relationship: 'triggers'
282
- })
283
- }
284
- for (const workflowId of humanCheckpoint.routesTo?.workflows ?? []) {
285
- edges.push({
286
- id: `edge-${edgeId++}`,
287
- source: humanCheckpoint.resourceId,
288
- target: workflowId,
289
- relationship: 'triggers'
290
- })
291
- }
292
- }
293
-
294
- return edges
295
- }
1
+ /**
2
+ * Registry Serialization Utilities
3
+ *
4
+ * Pre-serialization logic for ResourceRegistry.
5
+ * Converts resource definitions to JSON-safe structures at startup.
6
+ */
7
+
8
+ import type { DeploymentSpec } from './resource-registry'
9
+ import type { ResourceDefinition } from './types'
10
+ import type { ResourceEntry } from '../../organization-model/domains/resources'
11
+ import type { SystemEntry } from '../../organization-model/domains/systems'
12
+ import type {
13
+ SerializedOrganizationData,
14
+ SerializedAgentDefinition,
15
+ SerializedWorkflowDefinition,
16
+ CommandViewAgent,
17
+ CommandViewWorkflow,
18
+ CommandViewEdge
19
+ } from './serialized-types'
20
+ import { serializeDefinition } from '../../execution/engine/base/serialization'
21
+
22
+ function summarizeSystem(system: SystemEntry | undefined): ResourceDefinition['system'] {
23
+ if (!system) return undefined
24
+
25
+ return {
26
+ id: system.id,
27
+ title: system.label ?? system.title,
28
+ description: system.description,
29
+ kind: system.kind,
30
+ lifecycle: system.lifecycle
31
+ }
32
+ }
33
+
34
+ function createGovernanceMetadataResolver(resources: DeploymentSpec) {
35
+ const resourcesById = new Map(Object.values(resources.organizationModel?.resources ?? {}).map((r) => [r.id, r]))
36
+ const systemsById = new Map(Object.values(resources.organizationModel?.systems ?? {}).map((s) => [s.id, s]))
37
+
38
+ return (
39
+ resourceId: string,
40
+ descriptor: ResourceEntry | undefined
41
+ ): Pick<ResourceDefinition, 'systemPath' | 'system' | 'governanceStatus'> => {
42
+ const resource = descriptor ?? resourcesById.get(resourceId)
43
+ if (!resource) return {}
44
+
45
+ return {
46
+ systemPath: resource.systemPath,
47
+ system: summarizeSystem(systemsById.get(resource.systemPath)),
48
+ governanceStatus: resource.status
49
+ }
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Serialize all organization resources
55
+ * Called once during ResourceRegistry construction
56
+ */
57
+ export function serializeAllOrganizations(
58
+ registry: Record<string, DeploymentSpec>
59
+ ): Map<string, SerializedOrganizationData> {
60
+ const cache = new Map<string, SerializedOrganizationData>()
61
+ for (const [orgName, resources] of Object.entries(registry)) {
62
+ cache.set(orgName, serializeOrganization(resources))
63
+ }
64
+ return cache
65
+ }
66
+
67
+ /**
68
+ * Serialize single organization's resources
69
+ */
70
+ export function serializeOrganization(resources: DeploymentSpec): SerializedOrganizationData {
71
+ const getGovernanceMetadata = createGovernanceMetadataResolver(resources)
72
+
73
+ // Serialize workflows
74
+ const workflowDefinitions = new Map<string, SerializedWorkflowDefinition>()
75
+ const workflowResources: ResourceDefinition[] = []
76
+ const commandViewWorkflows: CommandViewWorkflow[] = []
77
+
78
+ for (const workflow of resources.workflows ?? []) {
79
+ const resourceId = workflow.config.resourceId
80
+ const serialized = serializeDefinition(workflow) as SerializedWorkflowDefinition
81
+ workflowDefinitions.set(resourceId, serialized)
82
+
83
+ workflowResources.push({
84
+ resourceId,
85
+ name: workflow.config.name,
86
+ description: workflow.config.description,
87
+ version: workflow.config.version,
88
+ type: 'workflow',
89
+ status: workflow.config.status,
90
+ links: workflow.config.links,
91
+ category: workflow.config.category,
92
+ ...getGovernanceMetadata(resourceId, workflow.config.resource)
93
+ })
94
+
95
+ commandViewWorkflows.push({
96
+ resourceId,
97
+ name: workflow.config.name,
98
+ description: workflow.config.description,
99
+ version: workflow.config.version,
100
+ type: 'workflow',
101
+ status: workflow.config.status,
102
+ links: workflow.config.links,
103
+ category: workflow.config.category,
104
+ ...getGovernanceMetadata(resourceId, workflow.config.resource),
105
+ stepCount: Object.keys(workflow.steps).length,
106
+ entryPoint: workflow.entryPoint
107
+ })
108
+ }
109
+
110
+ // Serialize agents
111
+ const agentDefinitions = new Map<string, SerializedAgentDefinition>()
112
+ const agentResources: ResourceDefinition[] = []
113
+ const commandViewAgents: CommandViewAgent[] = []
114
+
115
+ for (const agent of resources.agents ?? []) {
116
+ const resourceId = agent.config.resourceId
117
+ const serialized = serializeDefinition(agent) as SerializedAgentDefinition
118
+ agentDefinitions.set(resourceId, serialized)
119
+
120
+ agentResources.push({
121
+ resourceId,
122
+ name: agent.config.name,
123
+ description: agent.config.description,
124
+ version: agent.config.version,
125
+ type: 'agent',
126
+ status: agent.config.status,
127
+ links: agent.config.links,
128
+ category: agent.config.category,
129
+ sessionCapable: agent.config.sessionCapable ?? false,
130
+ ...getGovernanceMetadata(resourceId, agent.config.resource)
131
+ })
132
+
133
+ commandViewAgents.push({
134
+ resourceId,
135
+ name: agent.config.name,
136
+ description: agent.config.description,
137
+ version: agent.config.version,
138
+ type: 'agent',
139
+ status: agent.config.status,
140
+ links: agent.config.links,
141
+ category: agent.config.category,
142
+ ...getGovernanceMetadata(resourceId, agent.config.resource),
143
+ modelProvider: agent.modelConfig.provider,
144
+ modelId: agent.modelConfig.model,
145
+ toolCount: agent.tools.length,
146
+ hasKnowledgeMap: agent.knowledgeMap !== undefined,
147
+ hasMemory: agent.config.memoryPreferences !== undefined,
148
+ sessionCapable: agent.config.sessionCapable ?? false
149
+ })
150
+ }
151
+
152
+ // Build edges from triggers and relationships
153
+ const edges = buildEdges(resources)
154
+
155
+ // Pass-through manifest data (already JSON-safe)
156
+ const triggers = resources.triggers ?? []
157
+ const integrations = resources.integrations ?? []
158
+ const externalResources = resources.externalResources ?? []
159
+ const humanCheckpoints = resources.humanCheckpoints ?? []
160
+
161
+ return {
162
+ version: resources.version,
163
+ resources: {
164
+ workflows: workflowResources,
165
+ agents: agentResources,
166
+ total: workflowResources.length + agentResources.length
167
+ },
168
+ definitions: {
169
+ workflows: workflowDefinitions,
170
+ agents: agentDefinitions
171
+ },
172
+ commandView: {
173
+ workflows: commandViewWorkflows,
174
+ agents: commandViewAgents,
175
+ triggers,
176
+ integrations,
177
+ externalResources,
178
+ humanCheckpoints,
179
+ edges
180
+ },
181
+ triggers,
182
+ integrations,
183
+ externalResources,
184
+ humanCheckpoints,
185
+ relationships: resources.relationships
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Build Command View edges from relationships
191
+ * NOTE: Trigger relationships are now declared in ResourceRelationships, not on TriggerDefinition
192
+ */
193
+ export function buildEdges(resources: DeploymentSpec): CommandViewEdge[] {
194
+ const edges: CommandViewEdge[] = []
195
+ let edgeId = 0
196
+
197
+ // All relationship edges (triggers, agents, workflows can all declare relationships)
198
+ for (const [resourceId, declaration] of Object.entries(resources.relationships ?? {})) {
199
+ for (const agentId of declaration.triggers?.agents ?? []) {
200
+ edges.push({
201
+ id: `edge-${edgeId++}`,
202
+ source: resourceId,
203
+ target: agentId,
204
+ relationship: 'triggers'
205
+ })
206
+ }
207
+ for (const workflowId of declaration.triggers?.workflows ?? []) {
208
+ edges.push({
209
+ id: `edge-${edgeId++}`,
210
+ source: resourceId,
211
+ target: workflowId,
212
+ relationship: 'triggers'
213
+ })
214
+ }
215
+ for (const integrationId of declaration.uses?.integrations ?? []) {
216
+ edges.push({
217
+ id: `edge-${edgeId++}`,
218
+ source: resourceId,
219
+ target: integrationId,
220
+ relationship: 'uses'
221
+ })
222
+ }
223
+ }
224
+
225
+ // External Resource edges (forward-only)
226
+ for (const external of resources.externalResources ?? []) {
227
+ // External -> Internal
228
+ for (const workflowId of external.triggers?.workflows ?? []) {
229
+ edges.push({
230
+ id: `edge-${edgeId++}`,
231
+ source: external.resourceId,
232
+ target: workflowId,
233
+ relationship: 'triggers'
234
+ })
235
+ }
236
+ for (const agentId of external.triggers?.agents ?? []) {
237
+ edges.push({
238
+ id: `edge-${edgeId++}`,
239
+ source: external.resourceId,
240
+ target: agentId,
241
+ relationship: 'triggers'
242
+ })
243
+ }
244
+
245
+ // External -> Integration
246
+ for (const integrationId of external.uses?.integrations ?? []) {
247
+ edges.push({
248
+ id: `edge-${edgeId++}`,
249
+ source: external.resourceId,
250
+ target: integrationId,
251
+ relationship: 'uses'
252
+ })
253
+ }
254
+ }
255
+
256
+ // Human Checkpoint edges
257
+ for (const humanCheckpoint of resources.humanCheckpoints ?? []) {
258
+ // Agent/Workflow -> ApprovalPoint
259
+ for (const agentId of humanCheckpoint.requestedBy?.agents ?? []) {
260
+ edges.push({
261
+ id: `edge-${edgeId++}`,
262
+ source: agentId,
263
+ target: humanCheckpoint.resourceId,
264
+ relationship: 'approval'
265
+ })
266
+ }
267
+ for (const workflowId of humanCheckpoint.requestedBy?.workflows ?? []) {
268
+ edges.push({
269
+ id: `edge-${edgeId++}`,
270
+ source: workflowId,
271
+ target: humanCheckpoint.resourceId,
272
+ relationship: 'approval'
273
+ })
274
+ }
275
+
276
+ // ApprovalPoint -> Agent/Workflow
277
+ for (const agentId of humanCheckpoint.routesTo?.agents ?? []) {
278
+ edges.push({
279
+ id: `edge-${edgeId++}`,
280
+ source: humanCheckpoint.resourceId,
281
+ target: agentId,
282
+ relationship: 'triggers'
283
+ })
284
+ }
285
+ for (const workflowId of humanCheckpoint.routesTo?.workflows ?? []) {
286
+ edges.push({
287
+ id: `edge-${edgeId++}`,
288
+ source: humanCheckpoint.resourceId,
289
+ target: workflowId,
290
+ relationship: 'triggers'
291
+ })
292
+ }
293
+ }
294
+
295
+ return edges
296
+ }