@elevasis/core 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/index.js +195 -3
  2. package/dist/organization-model/index.js +195 -3
  3. package/package.json +1 -1
  4. package/src/__tests__/template-foundations-compatibility.test.ts +95 -14
  5. package/src/auth/multi-tenancy/types.ts +2 -1
  6. package/src/execution/engine/__tests__/fixtures/test-agents.ts +4 -4
  7. package/src/execution/engine/index.ts +5 -19
  8. package/src/execution/engine/tools/platform/index.ts +9 -33
  9. package/src/execution/engine/tools/registry.ts +109 -2
  10. package/src/execution/engine/tools/tool-maps.ts +88 -0
  11. package/src/organization-model/README.md +19 -4
  12. package/src/organization-model/__tests__/graph.test.ts +612 -0
  13. package/src/organization-model/__tests__/resolve.test.ts +208 -0
  14. package/src/organization-model/defaults.ts +1 -1
  15. package/src/organization-model/organization-graph.mdx +262 -0
  16. package/src/organization-model/organization-model.mdx +257 -0
  17. package/src/organization-model/resolve.ts +26 -2
  18. package/src/organization-model/schema.ts +203 -1
  19. package/src/platform/constants/versions.ts +1 -1
  20. package/src/platform/registry/__tests__/resource-registry.integration.test.ts +24 -0
  21. package/src/platform/registry/__tests__/resource-registry.test.ts +63 -0
  22. package/src/platform/registry/resource-registry.ts +98 -10
  23. package/src/projects/api-schemas.ts +2 -1
  24. package/src/reference/_generated/contracts.md +1044 -0
  25. package/src/reference/glossary.md +88 -0
  26. package/src/server.ts +2 -3
  27. package/src/execution/engine/tools/platform/resource-invocation/__tests__/edge-cases.test.ts +0 -507
  28. package/src/execution/engine/tools/platform/resource-invocation/__tests__/resource-invocation-service.test.ts +0 -500
  29. package/src/execution/engine/tools/platform/resource-invocation/__tests__/tool.test.ts +0 -555
  30. package/src/execution/engine/tools/platform/resource-invocation/dynamic-tool.ts +0 -94
  31. package/src/execution/engine/tools/platform/resource-invocation/index.ts +0 -14
  32. package/src/execution/engine/tools/platform/resource-invocation/resource-invocation-service.ts +0 -147
  33. package/src/execution/engine/tools/platform/resource-invocation/tool.ts +0 -115
  34. package/src/execution/engine/tools/platform/resource-invocation/types.ts +0 -31
@@ -0,0 +1,1044 @@
1
+ ---
2
+ title: Reference Contracts
3
+ description: Auto-generated TypeScript contracts for SDK consumers. Do not edit manually.
4
+ ---
5
+
6
+ > **Auto-generated** from source types. Do not edit manually. Run `node scripts/monorepo/generate-scaffold-contracts.js` to regenerate.
7
+
8
+ ## Organization Model
9
+
10
+ ### `OrganizationModel`
11
+
12
+ ```typescript
13
+ export type OrganizationModel = z.infer<typeof OrganizationModelSchema>
14
+ ```
15
+
16
+ ### `OrganizationModelBranding`
17
+
18
+ ```typescript
19
+ export type OrganizationModelBranding = z.infer<typeof OrganizationModelBrandingSchema>
20
+ ```
21
+
22
+ ### `OrganizationModelCrm`
23
+
24
+ ```typescript
25
+ export type OrganizationModelCrm = z.infer<typeof OrganizationModelCrmSchema>
26
+ ```
27
+
28
+ ### `OrganizationModelLeadGen`
29
+
30
+ ```typescript
31
+ export type OrganizationModelLeadGen = z.infer<typeof OrganizationModelLeadGenSchema>
32
+ ```
33
+
34
+ ### `OrganizationModelDelivery`
35
+
36
+ ```typescript
37
+ export type OrganizationModelDelivery = z.infer<typeof OrganizationModelDeliverySchema>
38
+ ```
39
+
40
+ ### `OrganizationModelFeatures`
41
+
42
+ ```typescript
43
+ export type OrganizationModelFeatures = z.infer<typeof OrganizationModelFeaturesSchema>
44
+ ```
45
+
46
+ ### `OrganizationModelFeatureKey`
47
+
48
+ ```typescript
49
+ export type OrganizationModelFeatureKey = z.infer<typeof FeatureKeySchema>
50
+ ```
51
+
52
+ ### `OrganizationModelNavigation`
53
+
54
+ ```typescript
55
+ export type OrganizationModelNavigation = z.infer<typeof OrganizationModelNavigationSchema>
56
+ ```
57
+
58
+ ### `OrganizationModelSurface`
59
+
60
+ ```typescript
61
+ export type OrganizationModelSurface = z.infer<typeof SurfaceDefinitionSchema>
62
+ ```
63
+
64
+ ### `OrganizationModelSemanticDomain`
65
+
66
+ ```typescript
67
+ export type OrganizationModelSemanticDomain = z.infer<typeof SemanticDomainSchema>
68
+ ```
69
+
70
+ ### `OrganizationModelResourceMapping`
71
+
72
+ ```typescript
73
+ export type OrganizationModelResourceMapping = z.infer<typeof ResourceMappingSchema>
74
+ ```
75
+
76
+ ### `DeepPartial`
77
+
78
+ ```typescript
79
+ export type DeepPartial<T> = T extends Array<infer U>
80
+ ? Array<DeepPartial<U>>
81
+ : T extends object
82
+ ? { [K in keyof T]?: DeepPartial<T[K]> }
83
+ : T
84
+ ```
85
+
86
+ ## Feature System
87
+
88
+ ### `FeatureNavLink`
89
+
90
+ ```typescript
91
+ export interface FeatureNavLink {
92
+ label: string
93
+ link: string
94
+ featureKey?: string
95
+ onClick?: () => void
96
+ links?: FeatureNavLink[]
97
+ }
98
+ ```
99
+
100
+ ### `FeatureNavEntry`
101
+
102
+ ```typescript
103
+ export interface FeatureNavEntry {
104
+ label: string
105
+ icon: ComponentType
106
+ link?: string
107
+ featureKey?: string
108
+ requiresAdmin?: boolean
109
+ dataOnboardingTourId?: string
110
+ links?: FeatureNavLink[]
111
+ }
112
+ ```
113
+
114
+ ### `FeatureSidebarComponent`
115
+
116
+ ```typescript
117
+ export type FeatureSidebarComponent = ComponentType
118
+ ```
119
+
120
+ ### `FeatureModule`
121
+
122
+ ```typescript
123
+ export interface FeatureModule {
124
+ /** Unique stable identifier for this feature (e.g. `'crm'`, `'delivery'`). */
125
+ key: string
126
+ /** Feature key used for access-flag gating in the organization model. */
127
+ accessFeatureKey: OrganizationModelFeatureKey
128
+ /**
129
+ * Semantic domain identifiers contributed by this feature.
130
+ * Merged with surface-derived domain IDs during resolution.
131
+ */
132
+ domainIds?: OrganizationModelSemanticDomain['id'][]
133
+ /**
134
+ * Capability identifiers contributed by this feature.
135
+ * Merged into `ResolvedFeatureSemantics.capabilityIds` at resolution time.
136
+ * Not queried at runtime — kept for semantic graph completeness so that
137
+ * capability membership is fully represented in the resolved model even when
138
+ * a surface does not declare it directly.
139
+ */
140
+ capabilityIds?: string[]
141
+ /** Top-level navigation entry rendered in the app shell when this feature is enabled. */
142
+ navEntry?: FeatureNavEntry
143
+ /** Sidebar component rendered when a matching subshell route is active. */
144
+ sidebar?: FeatureSidebarComponent
145
+ /** Route path prefixes that activate this feature's sidebar and subshell context. */
146
+ subshellRoutes?: string[]
147
+ /**
148
+ * Operations-only bridge surface connecting this feature to the organization graph.
149
+ * Ignored by all other features. Only one manifest in the registry should set this.
150
+ */
151
+ organizationGraph?: OrganizationGraphFeatureBridge
152
+ }
153
+ ```
154
+
155
+ ### `ResolvedFeatureAccess`
156
+
157
+ ```typescript
158
+ export interface ResolvedFeatureAccess {
159
+ featureKey: string
160
+ enabled: boolean
161
+ }
162
+ ```
163
+
164
+ ### `ResolvedFeatureSemantics`
165
+
166
+ ```typescript
167
+ export interface ResolvedFeatureSemantics {
168
+ domainIds: OrganizationModelSemanticDomain['id'][]
169
+ capabilityIds: string[]
170
+ surfaceIds: string[]
171
+ surfaces: OrganizationModelSurface[]
172
+ }
173
+ ```
174
+
175
+ ### `ResolvedFeatureModule`
176
+
177
+ ```typescript
178
+ export interface ResolvedFeatureModule extends FeatureModule {
179
+ access: ResolvedFeatureAccess
180
+ semantics: ResolvedFeatureSemantics
181
+ }
182
+ ```
183
+
184
+ ### `ShellNavPlacement`
185
+
186
+ ```typescript
187
+ export type ShellNavPlacement = 'primary' | 'bottom'
188
+ ```
189
+
190
+ ### `ShellNavSource`
191
+
192
+ ```typescript
193
+ export type ShellNavSource = 'app' | 'feature'
194
+ ```
195
+
196
+ ### `ResolvedShellNavItem`
197
+
198
+ ```typescript
199
+ export interface ResolvedShellNavItem extends FeatureNavEntry {
200
+ placement: ShellNavPlacement
201
+ source: ShellNavSource
202
+ accessFeatureKey?: string
203
+ }
204
+ ```
205
+
206
+ ### `ResolvedShellModel`
207
+
208
+ ```typescript
209
+ export interface ResolvedShellModel {
210
+ navItems: ResolvedShellNavItem[]
211
+ }
212
+ ```
213
+
214
+ ### `AppShellOverrides`
215
+
216
+ ```typescript
217
+ export interface AppShellOverrides {
218
+ primaryNavItems?: FeatureNavEntry[]
219
+ bottomNavItems?: FeatureNavEntry[]
220
+ }
221
+ ```
222
+
223
+ ### `ShellRouteMatchStatus`
224
+
225
+ ```typescript
226
+ export type ShellRouteMatchStatus = 'matched' | 'hidden' | 'unmatched'
227
+ ```
228
+
229
+ ### `ResolvedShellRouteMatch`
230
+
231
+ ```typescript
232
+ export interface ResolvedShellRouteMatch {
233
+ status: ShellRouteMatchStatus
234
+ path: string
235
+ feature?: ResolvedFeatureModule
236
+ navItem?: ResolvedShellNavItem
237
+ navLink?: FeatureNavLink
238
+ }
239
+ ```
240
+
241
+ ### `ShellRuntime`
242
+
243
+ ```typescript
244
+ export interface ShellRuntime {
245
+ resolveRoute: (path: string) => ResolvedShellRouteMatch
246
+ }
247
+ ```
248
+
249
+ ### `OrganizationGraphFeatureBridge`
250
+
251
+ ```typescript
252
+ export interface OrganizationGraphFeatureBridge {
253
+ surfaceId: string
254
+ }
255
+ ```
256
+
257
+ ### `OrganizationGraphContextValue`
258
+
259
+ ```typescript
260
+ export interface OrganizationGraphContextValue {
261
+ available: boolean
262
+ surfaceId?: string
263
+ surfacePath?: string
264
+ surfaceType?: OrganizationModelSurface['surfaceType']
265
+ featureKey?: OrganizationModelFeatureKey
266
+ }
267
+ ```
268
+
269
+ ### `ElevasisFeaturesProviderProps`
270
+
271
+ ```typescript
272
+ export interface ElevasisFeaturesProviderProps {
273
+ features: FeatureModule[]
274
+ organizationModel?: OrganizationModel
275
+ appShellOverrides?: AppShellOverrides
276
+ timeRange?: TimeRange
277
+ operationsApiUrl?: string
278
+ operationsSSEManager?: SSEConnectionManagerLike
279
+ disabledSubsectionPaths?: string[]
280
+ children: ReactNode
281
+ }
282
+ ```
283
+
284
+ ### `ElevasisFeaturesContextValue`
285
+
286
+ ```typescript
287
+ export interface ElevasisFeaturesContextValue {
288
+ shellModel: ResolvedShellModel
289
+ shellRuntime: ShellRuntime
290
+ enabledResolvedFeatures: ResolvedFeatureModule[]
291
+ resolvedFeatures: ResolvedFeatureModule[]
292
+ organizationGraph: OrganizationGraphContextValue
293
+ organizationModel?: OrganizationModel
294
+ timeRange?: TimeRange
295
+ operationsApiUrl?: string
296
+ operationsSSEManager?: SSEConnectionManagerLike
297
+ disabledSubsectionPaths: string[]
298
+ isFeatureEnabled: (key: string) => boolean
299
+ getResolvedFeature: (key: string) => ResolvedFeatureModule | undefined
300
+ }
301
+ ```
302
+
303
+ ## Resource Registry
304
+
305
+ ### `ResourceStatus`
306
+
307
+ ```typescript
308
+ /**
309
+ * Resource Registry type definitions
310
+ */
311
+
312
+ import type { IntegrationType } from '../../execution/engine/tools/integration'
313
+ import type { ResourceDomain } from './domains'
314
+
315
+ // ============================================================================
316
+ // Core Resource Type Definitions
317
+ // ============================================================================
318
+
319
+ /**
320
+ * Environment/deployment status for resources
321
+ */
322
+ export type ResourceStatus = 'dev' | 'prod'
323
+
324
+ /**
325
+ * All resource types in the platform
326
+ * Used as the discriminator field in ResourceDefinition
327
+ */
328
+ ```
329
+
330
+ ### `ResourceType`
331
+
332
+ ```typescript
333
+ /**
334
+ * All resource types in the platform
335
+ * Used as the discriminator field in ResourceDefinition
336
+ */
337
+ export type ResourceType = 'agent' | 'workflow' | 'trigger' | 'integration' | 'external' | 'human'
338
+
339
+ /**
340
+ * Executable resource types (subset of ResourceType)
341
+ * These resources can be directly executed by the execution engine
342
+ */
343
+ ```
344
+
345
+ ### `ExecutableResourceType`
346
+
347
+ ```typescript
348
+ /**
349
+ * Executable resource types (subset of ResourceType)
350
+ * These resources can be directly executed by the execution engine
351
+ */
352
+ export type ExecutableResourceType = 'workflow' | 'agent'
353
+
354
+ // ============================================================================
355
+ // Base Resource Interface
356
+ // ============================================================================
357
+
358
+ /**
359
+ * Base interface for ALL platform resources
360
+ * Shared by both executable (agents, workflows) and non-executable (triggers, integrations, etc.) resources
361
+ */
362
+ ```
363
+
364
+ ### `ResourceDefinition`
365
+
366
+ ```typescript
367
+ /**
368
+ * Base interface for ALL platform resources
369
+ * Shared by both executable (agents, workflows) and non-executable (triggers, integrations, etc.) resources
370
+ */
371
+ export interface ResourceDefinition {
372
+ /** Unique resource identifier */
373
+ resourceId: string
374
+
375
+ /** Display name */
376
+ name: string
377
+
378
+ /** Purpose and functionality description */
379
+ description: string
380
+
381
+ /** Version for change tracking and evolution */
382
+ version: string
383
+
384
+ /** Resource type discriminator */
385
+ type: ResourceType
386
+
387
+ /** Environment/deployment status */
388
+ status: ResourceStatus
389
+
390
+ /** Domain tags for filtering and organization */
391
+ domains?: ResourceDomain[]
392
+
393
+ /** Whether the agent supports multi-turn sessions (agents only) */
394
+ sessionCapable?: boolean
395
+
396
+ /** Whether the resource is local (monorepo) or remote (externally deployed) */
397
+ origin?: 'local' | 'remote'
398
+
399
+ /** Whether this resource is archived and should be excluded from registration and deployment */
400
+ archived?: boolean
401
+ }
402
+ ```
403
+
404
+ ### `DomainDefinition`
405
+
406
+ ```typescript
407
+ /** Unique resource identifier */
408
+ resourceId: string
409
+
410
+ /** Display name */
411
+ name: string
412
+
413
+ /** Purpose and functionality description */
414
+ description: string
415
+
416
+ /** Version for change tracking and evolution */
417
+ version: string
418
+
419
+ /** Resource type discriminator */
420
+ type: ResourceType
421
+
422
+ /** Environment/deployment status */
423
+ status: ResourceStatus
424
+
425
+ /** Domain tags for filtering and organization */
426
+ domains?: ResourceDomain[]
427
+
428
+ /** Whether the agent supports multi-turn sessions (agents only) */
429
+ sessionCapable?: boolean
430
+
431
+ /** Whether the resource is local (monorepo) or remote (externally deployed) */
432
+ origin?: 'local' | 'remote'
433
+
434
+ /** Whether this resource is archived and should be excluded from registration and deployment */
435
+ archived?: boolean
436
+ }
437
+
438
+ // ============================================================================
439
+ // Domain Definition Types
440
+ // ============================================================================
441
+
442
+ /**
443
+ * Domain definition for Command View filtering
444
+ *
445
+ * Domains are organizational metadata for UI filtering/grouping.
446
+ * No execution impact - purely for visualization.
447
+ *
448
+ * @example
449
+ * {
450
+ * id: 'support',
451
+ * name: 'Customer Support',
452
+ * description: 'Ticket triage, knowledge base, escalations',
453
+ * color: 'green',
454
+ * icon: 'IconHeadset'
455
+ * }
456
+ */
457
+ export interface DomainDefinition {
458
+ /** Unique identifier (e.g., 'support') */
459
+ id: string
460
+ /** Display name (e.g., 'Customer Support') */
461
+ name: string
462
+ /** Purpose description */
463
+ description: string
464
+ /** Optional Mantine color for UI (e.g., 'blue', 'green', 'orange') */
465
+ color?: string
466
+ /** Optional Tabler icon name (e.g., 'IconHeadset') */
467
+ icon?: string
468
+ }
469
+ ```
470
+
471
+ ### `ResourceList`
472
+
473
+ ```typescript
474
+ /** Unique identifier (e.g., 'support') */
475
+ id: string
476
+ /** Display name (e.g., 'Customer Support') */
477
+ name: string
478
+ /** Purpose description */
479
+ description: string
480
+ /** Optional Mantine color for UI (e.g., 'blue', 'green', 'orange') */
481
+ color?: string
482
+ /** Optional Tabler icon name (e.g., 'IconHeadset') */
483
+ icon?: string
484
+ }
485
+
486
+ /**
487
+ * Resource list for organization
488
+ * Returns ResourceDefinition metadata (not full definitions)
489
+ */
490
+ export interface ResourceList {
491
+ workflows: ResourceDefinition[]
492
+ agents: ResourceDefinition[]
493
+ total: number
494
+ organizationName: string
495
+ environment?: 'dev' | 'prod'
496
+ }
497
+ ```
498
+
499
+ ### `WebhookProviderType`
500
+
501
+ ```typescript
502
+ /** Webhook provider identifiers */
503
+ export type WebhookProviderType = 'cal-com' | 'stripe' | 'signature-api' | 'instantly' | 'apify'
504
+
505
+ /** Webhook trigger configuration */
506
+ ```
507
+
508
+ ### `WebhookTriggerConfig`
509
+
510
+ ```typescript
511
+ /** Webhook trigger configuration */
512
+ export interface WebhookTriggerConfig {
513
+ /** Provider identifier */
514
+ provider: WebhookProviderType
515
+ /** Event type for documentation (not used for matching - workflow handles routing) */
516
+ event?: string
517
+ /** Optional filtering (e.g., specific form ID for Fillout) */
518
+ filter?: Record<string, string>
519
+ /** References credential in credentials table for per-org webhook secrets */
520
+ credentialName?: string
521
+ }
522
+ ```
523
+
524
+ ### `ScheduleTriggerConfig`
525
+
526
+ ```typescript
527
+ /** Provider identifier */
528
+ provider: WebhookProviderType
529
+ /** Event type for documentation (not used for matching - workflow handles routing) */
530
+ event?: string
531
+ /** Optional filtering (e.g., specific form ID for Fillout) */
532
+ filter?: Record<string, string>
533
+ /** References credential in credentials table for per-org webhook secrets */
534
+ credentialName?: string
535
+ }
536
+
537
+ /** Schedule trigger configuration */
538
+ export interface ScheduleTriggerConfig {
539
+ /** Cron expression (e.g., '0 6 * * *') */
540
+ cron: string
541
+ /** Optional timezone (default: UTC) */
542
+ timezone?: string
543
+ }
544
+ ```
545
+
546
+ ### `EventTriggerConfig`
547
+
548
+ ```typescript
549
+ /** Cron expression (e.g., '0 6 * * *') */
550
+ cron: string
551
+ /** Optional timezone (default: UTC) */
552
+ timezone?: string
553
+ }
554
+
555
+ /** Event trigger configuration */
556
+ export interface EventTriggerConfig {
557
+ /** Internal event type */
558
+ eventType: string
559
+ /** Event source */
560
+ source?: string
561
+ }
562
+ ```
563
+
564
+ ### `TriggerConfig`
565
+
566
+ ```typescript
567
+ /** Internal event type */
568
+ eventType: string
569
+ /** Event source */
570
+ source?: string
571
+ }
572
+
573
+ /** Union of all trigger configs */
574
+ export type TriggerConfig = WebhookTriggerConfig | ScheduleTriggerConfig | EventTriggerConfig
575
+
576
+ // ============================================================================
577
+ // Trigger Definition
578
+ // ============================================================================
579
+
580
+ /**
581
+ * Trigger metadata - entry points that initiate resource execution
582
+ *
583
+ * Triggers represent how executions start: webhooks from external services,
584
+ * scheduled cron jobs, platform events, or manual user actions.
585
+ *
586
+ * BREAKING CHANGES (2025-11-30):
587
+ * - Now extends ResourceDefinition (inherits: resourceId, name, description, version, type, status, domains)
588
+ * - Field renames: `id` -> `resourceId` (inherited), `type` -> `triggerType`
589
+ * - Relationship rename: `invokes` -> `triggers` (unified vocabulary)
590
+ * - New required fields: `version` (inherited), `type: 'trigger'` (inherited)
591
+ * - triggers object now includes `externalResources` option
592
+ *
593
+ * @example
594
+ * // TriggerDefinition - metadata only
595
+ * {
596
+ * resourceId: 'trigger-new-order',
597
+ * type: 'trigger',
598
+ * triggerType: 'webhook',
599
+ * name: 'New Order',
600
+ * description: 'Webhook from Shopify on new orders',
601
+ * version: '1.0.0',
602
+ * status: 'prod',
603
+ * webhookPath: '/webhooks/shopify/orders'
604
+ * }
605
+ *
606
+ * // Relationships declared in ResourceRelationships (not on TriggerDefinition):
607
+ * // relationships: {
608
+ * // 'trigger-new-order': { triggers: { workflows: ['order-fulfillment-workflow'] } }
609
+ * // }
610
+ */
611
+ ```
612
+
613
+ ### `TriggerDefinition`
614
+
615
+ ```typescript
616
+ /**
617
+ * Trigger metadata - entry points that initiate resource execution
618
+ *
619
+ * Triggers represent how executions start: webhooks from external services,
620
+ * scheduled cron jobs, platform events, or manual user actions.
621
+ *
622
+ * BREAKING CHANGES (2025-11-30):
623
+ * - Now extends ResourceDefinition (inherits: resourceId, name, description, version, type, status, domains)
624
+ * - Field renames: `id` -> `resourceId` (inherited), `type` -> `triggerType`
625
+ * - Relationship rename: `invokes` -> `triggers` (unified vocabulary)
626
+ * - New required fields: `version` (inherited), `type: 'trigger'` (inherited)
627
+ * - triggers object now includes `externalResources` option
628
+ *
629
+ * @example
630
+ * // TriggerDefinition - metadata only
631
+ * {
632
+ * resourceId: 'trigger-new-order',
633
+ * type: 'trigger',
634
+ * triggerType: 'webhook',
635
+ * name: 'New Order',
636
+ * description: 'Webhook from Shopify on new orders',
637
+ * version: '1.0.0',
638
+ * status: 'prod',
639
+ * webhookPath: '/webhooks/shopify/orders'
640
+ * }
641
+ *
642
+ * // Relationships declared in ResourceRelationships (not on TriggerDefinition):
643
+ * // relationships: {
644
+ * // 'trigger-new-order': { triggers: { workflows: ['order-fulfillment-workflow'] } }
645
+ * // }
646
+ */
647
+ export interface TriggerDefinition extends ResourceDefinition {
648
+ /** Resource type discriminator (narrowed from base union) */
649
+ type: 'trigger'
650
+
651
+ /** Trigger mechanism type (renamed from 'type' to avoid collision with base type discriminator) */
652
+ triggerType: 'webhook' | 'schedule' | 'manual' | 'event'
653
+
654
+ /** Type-specific configuration */
655
+ config?: TriggerConfig
656
+
657
+ // Legacy fields (deprecated, use config instead)
658
+ /** For webhook triggers: path like '/webhooks/shopify/orders' */
659
+ webhookPath?: string
660
+ /** For schedule triggers: cron expression like '0 6 * * *' */
661
+ schedule?: string
662
+ /** For event triggers: event type like 'low-stock-alert' */
663
+ eventType?: string
664
+
665
+ // NOTE: What this trigger starts is declared in ResourceRelationships, not here
666
+ // This prevents duplication - triggers are forward-declared in relationships
667
+ }
668
+ ```
669
+
670
+ ### `IntegrationDefinition`
671
+
672
+ ```typescript
673
+ /** Resource type discriminator (narrowed from base union) */
674
+ type: 'trigger'
675
+
676
+ /** Trigger mechanism type (renamed from 'type' to avoid collision with base type discriminator) */
677
+ triggerType: 'webhook' | 'schedule' | 'manual' | 'event'
678
+
679
+ /** Type-specific configuration */
680
+ config?: TriggerConfig
681
+
682
+ // Legacy fields (deprecated, use config instead)
683
+ /** For webhook triggers: path like '/webhooks/shopify/orders' */
684
+ webhookPath?: string
685
+ /** For schedule triggers: cron expression like '0 6 * * *' */
686
+ schedule?: string
687
+ /** For event triggers: event type like 'low-stock-alert' */
688
+ eventType?: string
689
+
690
+ // NOTE: What this trigger starts is declared in ResourceRelationships, not here
691
+ // This prevents duplication - triggers are forward-declared in relationships
692
+ }
693
+
694
+ /**
695
+ * Integration metadata - external service connections
696
+ *
697
+ * References credentials table for actual connection. No connection status
698
+ * stored here (queried at runtime from credentials table).
699
+ *
700
+ * BREAKING CHANGES (2025-11-30):
701
+ * - Now extends ResourceDefinition (inherits: resourceId, name, description, version, type, status, domains)
702
+ * - Field renames: `id` -> `resourceId` (inherited)
703
+ * - New required field: `status` (inherited) - organizations must add status to all integrations
704
+ * - New required field: `version` (inherited) - organizations must add version to all integrations
705
+ * - New required field: `type: 'integration'` (inherited) - resource type discriminator
706
+ *
707
+ * @example
708
+ * {
709
+ * resourceId: 'integration-shopify-prod',
710
+ * type: 'integration',
711
+ * provider: 'shopify',
712
+ * credentialName: 'shopify-prod',
713
+ * name: 'Shopify Production',
714
+ * description: 'E-commerce platform',
715
+ * version: '1.0.0',
716
+ * status: 'prod'
717
+ * }
718
+ */
719
+ export interface IntegrationDefinition extends ResourceDefinition {
720
+ /** Resource type discriminator (narrowed from base union) */
721
+ type: 'integration'
722
+
723
+ /** Integration provider type */
724
+ provider: IntegrationType
725
+ /** References credentials table (e.g., 'shopify-prod', 'zendesk-api') */
726
+ credentialName: string
727
+ }
728
+ ```
729
+
730
+ ### `RelationshipDeclaration`
731
+
732
+ ```typescript
733
+ /** Resource type discriminator (narrowed from base union) */
734
+ type: 'integration'
735
+
736
+ /** Integration provider type */
737
+ provider: IntegrationType
738
+ /** References credentials table (e.g., 'shopify-prod', 'zendesk-api') */
739
+ credentialName: string
740
+ }
741
+
742
+ /**
743
+ * Explicit resource relationship declaration
744
+ *
745
+ * Single-direction only - Command View derives reverse relationships.
746
+ * Agents/workflows declare what they trigger and use.
747
+ *
748
+ * @example
749
+ * {
750
+ * triggers: { workflows: ['order-fulfillment-workflow'] },
751
+ * uses: { integrations: ['integration-shopify-prod', 'integration-postgres'] }
752
+ * }
753
+ */
754
+ export interface RelationshipDeclaration {
755
+ /** Resources this resource triggers */
756
+ triggers?: {
757
+ /** Agent resourceIds this resource triggers */
758
+ agents?: string[]
759
+ /** Workflow resourceIds this resource triggers */
760
+ workflows?: string[]
761
+ }
762
+ /** Integrations this resource uses */
763
+ uses?: {
764
+ /** Integration IDs this resource uses */
765
+ integrations?: string[]
766
+ }
767
+ }
768
+ ```
769
+
770
+ ### `ResourceRelationships`
771
+
772
+ ```typescript
773
+ /** Resources this resource triggers */
774
+ triggers?: {
775
+ /** Agent resourceIds this resource triggers */
776
+ agents?: string[]
777
+ /** Workflow resourceIds this resource triggers */
778
+ workflows?: string[]
779
+ }
780
+ /** Integrations this resource uses */
781
+ uses?: {
782
+ /** Integration IDs this resource uses */
783
+ integrations?: string[]
784
+ }
785
+ }
786
+
787
+ /**
788
+ * Resource relationships map
789
+ * Maps resourceId to its relationship declarations
790
+ *
791
+ * @example
792
+ * {
793
+ * 'order-processor-agent': {
794
+ * triggers: { workflows: ['order-fulfillment-workflow'] },
795
+ * uses: { integrations: ['integration-shopify-prod'] }
796
+ * }
797
+ * }
798
+ */
799
+ export type ResourceRelationships = Record<string, RelationshipDeclaration>
800
+
801
+ // ============================================================================
802
+ // External Resource Types
803
+ // ============================================================================
804
+
805
+ /**
806
+ * External platform type
807
+ * Supported third-party automation platforms
808
+ */
809
+ ```
810
+
811
+ ### `ExternalPlatform`
812
+
813
+ ```typescript
814
+ /**
815
+ * External platform type
816
+ * Supported third-party automation platforms
817
+ */
818
+ export type ExternalPlatform = 'n8n' | 'make' | 'zapier' | 'other'
819
+
820
+ /**
821
+ * External automation resource metadata
822
+ *
823
+ * Represents workflows/automations running on third-party platforms
824
+ * (n8n, Make, Zapier, etc.) for visualization in Command View.
825
+ *
826
+ * NOTE: This is metadata ONLY for visualization. No execution logic,
827
+ * no API integration with external platforms, no status syncing.
828
+ *
829
+ * BREAKING CHANGES (2025-11-30):
830
+ * - Now extends ResourceDefinition (inherits: resourceId, name, description, version, type, status, domains)
831
+ * - Field renames: `id` -> `resourceId` (inherited)
832
+ * - New required field: `version` (inherited) - organizations must add version to all external resources
833
+ * - New required field: `type: 'external'` (inherited) - resource type discriminator
834
+ * - REMOVED FIELD: `triggeredBy` - per relationship-consolidation design, all relationships are forward-only declarations
835
+ *
836
+ * @example
837
+ * {
838
+ * resourceId: 'external-n8n-order-sync',
839
+ * type: 'external',
840
+ * version: '1.0.0',
841
+ * platform: 'n8n',
842
+ * name: 'Shopify Order Sync',
843
+ * description: 'Legacy n8n workflow for syncing Shopify orders',
844
+ * status: 'prod',
845
+ * platformUrl: 'https://n8n.client.com/workflow/123',
846
+ * triggers: { workflows: ['order-fulfillment-workflow'] },
847
+ * uses: { integrations: ['integration-shopify-prod'] }
848
+ * }
849
+ */
850
+ ```
851
+
852
+ ### `ExternalResourceDefinition`
853
+
854
+ ```typescript
855
+ /**
856
+ * External automation resource metadata
857
+ *
858
+ * Represents workflows/automations running on third-party platforms
859
+ * (n8n, Make, Zapier, etc.) for visualization in Command View.
860
+ *
861
+ * NOTE: This is metadata ONLY for visualization. No execution logic,
862
+ * no API integration with external platforms, no status syncing.
863
+ *
864
+ * BREAKING CHANGES (2025-11-30):
865
+ * - Now extends ResourceDefinition (inherits: resourceId, name, description, version, type, status, domains)
866
+ * - Field renames: `id` -> `resourceId` (inherited)
867
+ * - New required field: `version` (inherited) - organizations must add version to all external resources
868
+ * - New required field: `type: 'external'` (inherited) - resource type discriminator
869
+ * - REMOVED FIELD: `triggeredBy` - per relationship-consolidation design, all relationships are forward-only declarations
870
+ *
871
+ * @example
872
+ * {
873
+ * resourceId: 'external-n8n-order-sync',
874
+ * type: 'external',
875
+ * version: '1.0.0',
876
+ * platform: 'n8n',
877
+ * name: 'Shopify Order Sync',
878
+ * description: 'Legacy n8n workflow for syncing Shopify orders',
879
+ * status: 'prod',
880
+ * platformUrl: 'https://n8n.client.com/workflow/123',
881
+ * triggers: { workflows: ['order-fulfillment-workflow'] },
882
+ * uses: { integrations: ['integration-shopify-prod'] }
883
+ * }
884
+ */
885
+ export interface ExternalResourceDefinition extends ResourceDefinition {
886
+ /** Resource type discriminator (narrowed from base union) */
887
+ type: 'external'
888
+
889
+ /** Platform type */
890
+ platform: ExternalPlatform
891
+
892
+ // Optional platform-specific metadata
893
+ /** Link to external platform (e.g., n8n workflow editor URL) */
894
+ platformUrl?: string
895
+ /** Platform's internal ID/reference */
896
+ externalId?: string
897
+
898
+ /** What this external resource triggers (external -> internal) */
899
+ triggers?: {
900
+ /** Elevasis workflow resourceIds this external automation triggers */
901
+ workflows?: string[]
902
+ /** Elevasis agent resourceIds this external automation triggers */
903
+ agents?: string[]
904
+ }
905
+
906
+ /** Integrations this external resource uses (shared credentials) */
907
+ uses?: {
908
+ /** Integration IDs this external automation uses */
909
+ integrations?: string[]
910
+ }
911
+
912
+ // NOTE: triggeredBy field removed - per relationship-consolidation design,
913
+ // all relationships are forward-only declarations. Graph edges are built
914
+ // from forward declarations only.
915
+ }
916
+ ```
917
+
918
+ ### `HumanCheckpointDefinition`
919
+
920
+ ```typescript
921
+ /** Resource type discriminator (narrowed from base union) */
922
+ type: 'external'
923
+
924
+ /** Platform type */
925
+ platform: ExternalPlatform
926
+
927
+ // Optional platform-specific metadata
928
+ /** Link to external platform (e.g., n8n workflow editor URL) */
929
+ platformUrl?: string
930
+ /** Platform's internal ID/reference */
931
+ externalId?: string
932
+
933
+ /** What this external resource triggers (external -> internal) */
934
+ triggers?: {
935
+ /** Elevasis workflow resourceIds this external automation triggers */
936
+ workflows?: string[]
937
+ /** Elevasis agent resourceIds this external automation triggers */
938
+ agents?: string[]
939
+ }
940
+
941
+ /** Integrations this external resource uses (shared credentials) */
942
+ uses?: {
943
+ /** Integration IDs this external automation uses */
944
+ integrations?: string[]
945
+ }
946
+
947
+ // NOTE: triggeredBy field removed - per relationship-consolidation design,
948
+ // all relationships are forward-only declarations. Graph edges are built
949
+ // from forward declarations only.
950
+ }
951
+
952
+ /**
953
+ * Human Checkpoint definition - human decision points in automation
954
+ *
955
+ * Represents where human judgment is deployed in the automation landscape.
956
+ * Tasks with matching command_queue_group are routed to this checkpoint.
957
+ *
958
+ * BREAKING CHANGES (2025-11-30):
959
+ * - Now extends ResourceDefinition (inherits: resourceId, name, description, version, type, status, domains)
960
+ * - Field renames: `id` -> `resourceId` (inherited)
961
+ * - description is now REQUIRED (was optional) - organizations must add description to all human checkpoints
962
+ * - New required field: `version` (inherited) - organizations must add version to all human checkpoints
963
+ * - New required field: `type: 'human'` (inherited) - resource type discriminator
964
+ *
965
+ * @example
966
+ * {
967
+ * resourceId: 'sales-approval',
968
+ * type: 'human',
969
+ * name: 'Sales Approval Queue',
970
+ * description: 'High-value order approvals for sales team',
971
+ * version: '1.0.0',
972
+ * status: 'prod',
973
+ * requestedBy: { agents: ['order-processor-agent'] },
974
+ * routesTo: { agents: ['order-fulfillment-agent'] }
975
+ * }
976
+ */
977
+ export interface HumanCheckpointDefinition extends ResourceDefinition {
978
+ /** Resource type discriminator (narrowed from base union) */
979
+ type: 'human'
980
+
981
+ /** Resources that create tasks for this checkpoint */
982
+ requestedBy?: {
983
+ /** Agent resourceIds that request approval here */
984
+ agents?: string[]
985
+ /** Workflow resourceIds that request approval here */
986
+ workflows?: string[]
987
+ }
988
+
989
+ /** Resources that receive approved decisions */
990
+ routesTo?: {
991
+ /** Agent resourceIds that handle approved tasks */
992
+ agents?: string[]
993
+ /** Workflow resourceIds that handle approved tasks */
994
+ workflows?: string[]
995
+ }
996
+ }
997
+ ```
998
+
999
+ ## Deployment Spec
1000
+
1001
+ ### `DeploymentSpec`
1002
+
1003
+ ```typescript
1004
+ /** Supabase Storage path: "{orgId}/{deploymentId}/bundle.js" */
1005
+ storagePath: string
1006
+ /** Deployment record ID */
1007
+ deploymentId: string
1008
+ /** OS temp path to bundle -- set after first download, used by worker threads */
1009
+ cachedTempPath?: string
1010
+ /** Platform tool name -> credential name mapping */
1011
+ toolCredentials?: Record<string, string>
1012
+ /** SDK version used to deploy this bundle */
1013
+ sdkVersion?: string
1014
+ /** Deployment version (semver) of the deployed bundle */
1015
+ deploymentVersion?: string
1016
+ }
1017
+
1018
+ /**
1019
+ * Organization-specific resource collection
1020
+ *
1021
+ * Complete manifest of all automation resources for an organization.
1022
+ * Used by ResourceRegistry for discovery and Command View for visualization.
1023
+ */
1024
+ export interface DeploymentSpec {
1025
+ /** Deployment version (semver) */
1026
+ version: string
1027
+ /** Workflow definitions */
1028
+ workflows?: WorkflowDefinition[]
1029
+ /** Agent definitions */
1030
+ agents?: AgentDefinition[]
1031
+
1032
+ // Resource Manifest fields (optional for backwards compatibility)
1033
+ /** Trigger definitions - entry points that initiate executions */
1034
+ triggers?: TriggerDefinition[]
1035
+ /** Integration definitions - external service connections */
1036
+ integrations?: IntegrationDefinition[]
1037
+ /** Explicit relationship declarations between resources */
1038
+ relationships?: ResourceRelationships
1039
+ /** External automation resources (n8n, Make, Zapier, etc.) */
1040
+ externalResources?: ExternalResourceDefinition[]
1041
+ /** Human checkpoint definitions - human decision points in automation */
1042
+ humanCheckpoints?: HumanCheckpointDefinition[]
1043
+ }
1044
+ ```