@elevasis/sdk 0.1.0 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -1,79 +1,5 @@
1
1
  import { z } from 'zod';
2
2
 
3
- /**
4
- * Error categories for observability grouping and classification.
5
- * Used to categorize errors in the execution_errors table metadata.
6
- */
7
- type ExecutionErrorCategory = 'llm' | 'tool' | 'workflow' | 'agent' | 'validation' | 'system';
8
- /**
9
- * Abstract base class for all execution engine errors.
10
- * Enforces contract for execution_errors table insertion with explicit type,
11
- * severity, category, and context properties.
12
- *
13
- * All execution engine errors MUST extend this class to ensure proper error
14
- * tracking and observability in the execution_errors table.
15
- *
16
- * @example
17
- * ```typescript
18
- * export class MyExecutionError extends ExecutionError {
19
- * readonly type = 'my_execution_error' as const
20
- * readonly severity = 'warning' as const
21
- * readonly category = 'workflow' as const
22
- *
23
- * constructor(message: string, context?: Record<string, unknown>) {
24
- * super(message, context)
25
- * }
26
- * }
27
- * ```
28
- */
29
- declare abstract class ExecutionError extends Error {
30
- /**
31
- * Error type identifier for execution_errors table.
32
- * Should be a unique, snake_case string that identifies this specific error class.
33
- * Used for filtering, aggregation, and error-specific handling in observability systems.
34
- */
35
- abstract readonly type: string;
36
- /**
37
- * Error severity level for execution_errors table.
38
- * - critical: System failures, auth issues, resource exhaustion - execution cannot continue
39
- * - warning: Transient failures, configuration errors - execution may retry or requires user correction
40
- * - info: Validation failures, expected user errors - user/developer action needed
41
- */
42
- abstract readonly severity: 'critical' | 'warning' | 'info';
43
- /**
44
- * Error category for observability grouping.
45
- * Used to categorize errors in dashboards and analytics.
46
- */
47
- abstract readonly category: ExecutionErrorCategory;
48
- /**
49
- * Additional context/metadata for the error.
50
- * Stored in execution_errors.metadata JSONB column.
51
- */
52
- readonly context?: Record<string, unknown>;
53
- /**
54
- * @param message - Human-readable error message
55
- * @param context - Additional context/metadata for observability
56
- */
57
- constructor(message: string, context?: Record<string, unknown>);
58
- /**
59
- * Indicates whether this error type is retryable.
60
- * Default: false (safe default - only retry when explicitly safe to do so)
61
- *
62
- * Subclasses should override to return true for retryable scenarios:
63
- * - Network/infrastructure errors (exponential backoff)
64
- * - Rate limiting (linear backoff)
65
- * - Service availability (exponential backoff)
66
- * - Circuit breaker (circuit breaker's own delay)
67
- *
68
- * DO NOT retry:
69
- * - Authentication/authorization errors
70
- * - Validation errors
71
- * - Configuration errors
72
- * - Resource exhaustion errors
73
- */
74
- isRetryable(): boolean;
75
- }
76
-
77
3
  /**
78
4
  * Workflow-specific logging types
79
5
  */
@@ -363,6 +289,232 @@ interface FormSchema {
363
289
  layout?: 'vertical' | 'horizontal' | 'grid';
364
290
  }
365
291
 
292
+ /**
293
+ * Command View Types
294
+ *
295
+ * Unified type definitions for the Command View graph visualization.
296
+ * These types are used by both backend serialization and frontend rendering.
297
+ *
298
+ * Command View shows the resource graph: agents, workflows, triggers, integrations,
299
+ * external resources, and human checkpoints with their relationships.
300
+ */
301
+
302
+ /**
303
+ * Extended agent metadata for Command View
304
+ * Includes model and capability information for graph display
305
+ */
306
+ interface CommandViewAgent extends ResourceDefinition {
307
+ type: 'agent';
308
+ modelProvider: string;
309
+ modelId: string;
310
+ toolCount: number;
311
+ hasKnowledgeMap: boolean;
312
+ hasMemory: boolean;
313
+ sessionCapable: boolean;
314
+ }
315
+ /**
316
+ * Extended workflow metadata for Command View
317
+ * Includes step information for graph display
318
+ */
319
+ interface CommandViewWorkflow extends ResourceDefinition {
320
+ type: 'workflow';
321
+ stepCount: number;
322
+ entryPoint: string;
323
+ }
324
+ /**
325
+ * Relationship types between resources
326
+ *
327
+ * - triggers: Resource initiates/starts another resource (orange)
328
+ * - uses: Resource uses an integration (teal)
329
+ * - approval: Resource requires human approval (yellow)
330
+ */
331
+ type RelationshipType = 'triggers' | 'uses' | 'approval';
332
+ /**
333
+ * Command View edge (relationship between resources)
334
+ */
335
+ interface CommandViewEdge {
336
+ id: string;
337
+ source: string;
338
+ target: string;
339
+ relationship: RelationshipType;
340
+ label?: string;
341
+ }
342
+ /**
343
+ * Command View data structure
344
+ * Complete graph data for visualization
345
+ *
346
+ * Backend serializes this once at startup and serves it via /command-view endpoint.
347
+ * Frontend consumes this directly for graph rendering.
348
+ */
349
+ interface CommandViewData {
350
+ workflows: CommandViewWorkflow[];
351
+ agents: CommandViewAgent[];
352
+ triggers: TriggerDefinition[];
353
+ integrations: IntegrationDefinition[];
354
+ externalResources: ExternalResourceDefinition[];
355
+ humanCheckpoints: HumanCheckpointDefinition[];
356
+ edges: CommandViewEdge[];
357
+ domainDefinitions?: DomainDefinition[];
358
+ }
359
+
360
+ /**
361
+ * Serialized Registry Types
362
+ *
363
+ * Pre-computed JSON-safe types for API responses and Command View.
364
+ * Serialization happens once at API startup, enabling instant response times.
365
+ */
366
+
367
+ /**
368
+ * Serialized form field for API responses
369
+ */
370
+ interface SerializedFormField {
371
+ name: string;
372
+ label: string;
373
+ type: FormFieldType;
374
+ defaultValue?: unknown;
375
+ required?: boolean;
376
+ placeholder?: string;
377
+ description?: string;
378
+ options?: Array<{
379
+ label: string;
380
+ value: string | number;
381
+ }>;
382
+ min?: number;
383
+ max?: number;
384
+ }
385
+ /**
386
+ * Serialized form schema for API responses
387
+ */
388
+ interface SerializedFormSchema {
389
+ title?: string;
390
+ description?: string;
391
+ fields: SerializedFormField[];
392
+ layout?: 'vertical' | 'horizontal' | 'grid';
393
+ }
394
+ /**
395
+ * Serialized execution form schema for API responses
396
+ */
397
+ interface SerializedExecutionFormSchema extends SerializedFormSchema {
398
+ fieldMappings?: Record<string, string>;
399
+ submitButton?: {
400
+ label?: string;
401
+ loadingLabel?: string;
402
+ confirmMessage?: string;
403
+ };
404
+ }
405
+ /**
406
+ * Serialized schedule config for API responses
407
+ */
408
+ interface SerializedScheduleConfig {
409
+ enabled: boolean;
410
+ defaultSchedule?: string;
411
+ allowedPatterns?: string[];
412
+ }
413
+ /**
414
+ * Serialized webhook config for API responses
415
+ */
416
+ interface SerializedWebhookConfig {
417
+ enabled: boolean;
418
+ payloadSchema?: unknown;
419
+ }
420
+ /**
421
+ * Serialized execution interface for API responses
422
+ */
423
+ interface SerializedExecutionInterface {
424
+ form: SerializedExecutionFormSchema;
425
+ schedule?: SerializedScheduleConfig;
426
+ webhook?: SerializedWebhookConfig;
427
+ }
428
+ /**
429
+ * Serialized agent definition (JSON-safe)
430
+ * Result of serializeDefinition(AgentDefinition)
431
+ */
432
+ interface SerializedAgentDefinition {
433
+ config: {
434
+ resourceId: string;
435
+ name: string;
436
+ description: string;
437
+ version: string;
438
+ type: 'agent';
439
+ status: 'dev' | 'prod';
440
+ systemPrompt: string;
441
+ constraints?: {
442
+ maxIterations?: number;
443
+ timeout?: number;
444
+ maxSessionMemoryKeys?: number;
445
+ maxMemoryTokens?: number;
446
+ };
447
+ sessionCapable?: boolean;
448
+ memoryPreferences?: string;
449
+ };
450
+ modelConfig: {
451
+ provider: string;
452
+ model: string;
453
+ apiKey: string;
454
+ temperature: number;
455
+ maxTokens: number;
456
+ topP?: number;
457
+ modelOptions?: Record<string, unknown>;
458
+ };
459
+ contract: {
460
+ inputSchema: object;
461
+ outputSchema?: object;
462
+ };
463
+ tools: Array<{
464
+ name: string;
465
+ description: string;
466
+ inputSchema?: object;
467
+ outputSchema?: object;
468
+ }>;
469
+ knowledgeMap?: {
470
+ nodeCount: number;
471
+ nodes: Array<{
472
+ id: string;
473
+ description: string;
474
+ loaded: boolean;
475
+ hasPrompt: boolean;
476
+ }>;
477
+ };
478
+ metricsConfig?: object;
479
+ interface?: SerializedExecutionInterface;
480
+ }
481
+ /**
482
+ * Serialized workflow definition (JSON-safe)
483
+ * Result of serializeDefinition(WorkflowDefinition)
484
+ */
485
+ interface SerializedWorkflowDefinition {
486
+ config: {
487
+ resourceId: string;
488
+ name: string;
489
+ description: string;
490
+ version: string;
491
+ type: 'workflow';
492
+ status: 'dev' | 'prod';
493
+ };
494
+ entryPoint: string;
495
+ steps: Array<{
496
+ id: string;
497
+ name: string;
498
+ description: string;
499
+ inputSchema?: object;
500
+ outputSchema?: object;
501
+ next: {
502
+ type: 'linear' | 'conditional';
503
+ target?: string;
504
+ routes?: Array<{
505
+ target: string;
506
+ }>;
507
+ default?: string;
508
+ } | null;
509
+ }>;
510
+ contract: {
511
+ inputSchema: object;
512
+ outputSchema?: object;
513
+ };
514
+ metricsConfig?: object;
515
+ interface?: SerializedExecutionInterface;
516
+ }
517
+
366
518
  /**
367
519
  * Model Configuration
368
520
  * Centralized model information, configuration, options, constraints, and validation
@@ -525,16 +677,16 @@ interface WorkflowStepDefinition {
525
677
  description: string;
526
678
  }
527
679
  type StepHandler = (input: unknown, context: ExecutionContext) => Promise<unknown>;
528
- declare enum StepType {
680
+ declare enum StepType$1 {
529
681
  LINEAR = "linear",
530
682
  CONDITIONAL = "conditional"
531
683
  }
532
684
  interface LinearNext {
533
- type: StepType.LINEAR;
685
+ type: StepType$1.LINEAR;
534
686
  target: string;
535
687
  }
536
688
  interface ConditionalNext {
537
- type: StepType.CONDITIONAL;
689
+ type: StepType$1.CONDITIONAL;
538
690
  routes: Array<{
539
691
  condition: (data: unknown) => boolean;
540
692
  target: string;
@@ -924,6 +1076,157 @@ interface OrganizationResources {
924
1076
  /** Human checkpoint definitions - human decision points in automation */
925
1077
  humanCheckpoints?: HumanCheckpointDefinition[];
926
1078
  }
1079
+ /**
1080
+ * Organization Registry type
1081
+ */
1082
+ type OrganizationRegistry = Record<string, OrganizationResources>;
1083
+ declare class ResourceRegistry {
1084
+ private registry;
1085
+ /**
1086
+ * Pre-serialized organization data cache
1087
+ * Computed once at construction, never invalidated (static registry)
1088
+ */
1089
+ private serializedCache;
1090
+ constructor(registry: OrganizationRegistry);
1091
+ /**
1092
+ * Validates registry on construction
1093
+ * - Checks for duplicate resourceIds within organizations
1094
+ * - Validates model configurations against constraints
1095
+ * - Validates ExecutionInterface matches inputSchema
1096
+ * @throws Error if validation fails
1097
+ */
1098
+ private validateRegistry;
1099
+ /**
1100
+ * Validates relationship declarations reference valid resources
1101
+ * Runs at API server startup - fails fast in development
1102
+ * @throws Error if validation fails
1103
+ */
1104
+ private validateRelationships;
1105
+ /**
1106
+ * Get a resource definition by ID
1107
+ * Returns full definition (WorkflowDefinition or AgentDefinition)
1108
+ * Check definition.config.type to determine if it's a workflow or agent
1109
+ */
1110
+ getResourceDefinition(organizationName: string, resourceId: string): WorkflowDefinition | AgentDefinition | null;
1111
+ /**
1112
+ * List all resources for an organization
1113
+ * Returns ResourceDefinition metadata (not full definitions)
1114
+ *
1115
+ * Environment filtering (automatic):
1116
+ * - Development: Returns all resources (dev + prod)
1117
+ * - Production: Returns only prod resources (filters out dev)
1118
+ */
1119
+ listResourcesForOrganization(organizationName: string, environment?: ResourceStatus): ResourceList;
1120
+ /**
1121
+ * List all resources from all organizations
1122
+ * NOTE: For debugging only - returns raw registry data
1123
+ */
1124
+ listAllResources(): OrganizationRegistry;
1125
+ /**
1126
+ * Get triggers for an organization
1127
+ * @param organizationName - Organization name
1128
+ * @returns Array of trigger definitions (empty if none defined)
1129
+ */
1130
+ getTriggers(organizationName: string): TriggerDefinition[];
1131
+ /**
1132
+ * Get integrations for an organization
1133
+ * @param organizationName - Organization name
1134
+ * @returns Array of integration definitions (empty if none defined)
1135
+ */
1136
+ getIntegrations(organizationName: string): IntegrationDefinition[];
1137
+ /**
1138
+ * Get resource relationships for an organization
1139
+ * @param organizationName - Organization name
1140
+ * @returns Resource relationships map (undefined if none defined)
1141
+ */
1142
+ getRelationships(organizationName: string): ResourceRelationships | undefined;
1143
+ /**
1144
+ * Get a specific trigger by ID
1145
+ * @param organizationName - Organization name
1146
+ * @param triggerId - Trigger ID
1147
+ * @returns Trigger definition or null if not found
1148
+ */
1149
+ getTrigger(organizationName: string, triggerId: string): TriggerDefinition | null;
1150
+ /**
1151
+ * Get a specific integration by ID
1152
+ * @param organizationName - Organization name
1153
+ * @param integrationId - Integration ID
1154
+ * @returns Integration definition or null if not found
1155
+ */
1156
+ getIntegration(organizationName: string, integrationId: string): IntegrationDefinition | null;
1157
+ /**
1158
+ * Get external resources for an organization
1159
+ * @param organizationName - Organization name
1160
+ * @returns Array of external resource definitions (empty if none defined)
1161
+ */
1162
+ getExternalResources(organizationName: string): ExternalResourceDefinition[];
1163
+ /**
1164
+ * Get a specific external resource by ID
1165
+ * @param organizationName - Organization name
1166
+ * @param externalId - External resource ID
1167
+ * @returns External resource definition or null if not found
1168
+ */
1169
+ getExternalResource(organizationName: string, externalId: string): ExternalResourceDefinition | null;
1170
+ /**
1171
+ * Get human checkpoints for an organization
1172
+ * @param organizationName - Organization name
1173
+ * @returns Array of human checkpoint definitions (empty if none defined)
1174
+ */
1175
+ getHumanCheckpoints(organizationName: string): HumanCheckpointDefinition[];
1176
+ /**
1177
+ * Get a specific human checkpoint by ID
1178
+ * @param organizationName - Organization name
1179
+ * @param humanCheckpointId - Human checkpoint ID
1180
+ * @returns Human checkpoint definition or null if not found
1181
+ */
1182
+ getHumanCheckpoint(organizationName: string, humanCheckpointId: string): HumanCheckpointDefinition | null;
1183
+ /**
1184
+ * Get serialized resource definition (instant lookup)
1185
+ * Use for API responses - returns pre-computed JSON-safe structure
1186
+ *
1187
+ * @param organizationName - Organization name
1188
+ * @param resourceId - Resource ID
1189
+ * @returns Serialized definition or null if not found
1190
+ */
1191
+ getSerializedDefinition(organizationName: string, resourceId: string): SerializedAgentDefinition | SerializedWorkflowDefinition | null;
1192
+ /**
1193
+ * Get resource list for organization (instant lookup)
1194
+ * Use for /resources endpoint - returns pre-computed ResourceDefinition array
1195
+ *
1196
+ * @param organizationName - Organization name
1197
+ * @returns Resource list with workflows, agents, and total count
1198
+ */
1199
+ getResourceList(organizationName: string): {
1200
+ workflows: ResourceDefinition[];
1201
+ agents: ResourceDefinition[];
1202
+ total: number;
1203
+ };
1204
+ /**
1205
+ * Get Command View data for organization (instant lookup)
1206
+ * Use for /command-view endpoint - returns complete graph data
1207
+ *
1208
+ * @param organizationName - Organization name
1209
+ * @returns Command View data with nodes and edges
1210
+ */
1211
+ getCommandViewData(organizationName: string): CommandViewData;
1212
+ /**
1213
+ * List resources that have UI interfaces configured
1214
+ * Used by Execution Runner Catalog UI
1215
+ *
1216
+ * @param organizationName - Organization name
1217
+ * @param environment - Optional environment filter ('dev' or 'prod')
1218
+ * @returns Array of resources with interfaces
1219
+ */
1220
+ listExecutable(organizationName: string, environment?: 'dev' | 'prod'): Array<{
1221
+ resourceId: string;
1222
+ resourceName: string;
1223
+ resourceType: 'workflow' | 'agent';
1224
+ description?: string;
1225
+ status: 'dev' | 'prod';
1226
+ version: string;
1227
+ interface: SerializedExecutionInterface;
1228
+ }>;
1229
+ }
927
1230
 
928
1231
  /**
929
1232
  * MetricsCollector
@@ -1162,44 +1465,6 @@ interface Tool {
1162
1465
  * Used across platform tools and integration tools
1163
1466
  */
1164
1467
  type ToolingErrorType = 'service_unavailable' | 'permission_denied' | 'adapter_not_found' | 'method_not_found' | 'tool_not_found' | 'credentials_missing' | 'credentials_invalid' | 'rate_limit_exceeded' | 'server_unavailable' | 'auth_error' | 'api_error' | 'validation_error' | 'network_error' | 'timeout_error' | 'unknown_error';
1165
- /**
1166
- * Tooling error class
1167
- * Provides structured error information for tool failures across all tool types
1168
- *
1169
- * Severity mapping:
1170
- * - critical: credentials_missing, credentials_invalid, permission_denied, auth_error,
1171
- * adapter_not_found, method_not_found, tool_not_found
1172
- * - info: validation_error
1173
- * - warning: All other types (retryable transient errors)
1174
- *
1175
- * Category: tool (tool execution errors)
1176
- */
1177
- declare class ToolingError extends ExecutionError {
1178
- readonly errorType: ToolingErrorType;
1179
- readonly details?: unknown | undefined;
1180
- readonly type: "tooling_error";
1181
- readonly category: "tool";
1182
- constructor(errorType: ToolingErrorType, message: string, details?: unknown | undefined);
1183
- /**
1184
- * Derive severity based on error type
1185
- */
1186
- get severity(): 'critical' | 'warning' | 'info';
1187
- /**
1188
- * Check if error is retryable
1189
- */
1190
- isRetryable(): boolean;
1191
- /**
1192
- * Convert to JSON for logging
1193
- */
1194
- toJSON(): {
1195
- name: string;
1196
- type: ToolingErrorType;
1197
- message: string;
1198
- severity: "critical" | "warning" | "info";
1199
- category: "tool";
1200
- details: unknown;
1201
- };
1202
- }
1203
1468
 
1204
1469
  /**
1205
1470
  * Supported integration types
@@ -1274,6 +1539,17 @@ interface DomainDefinition {
1274
1539
  /** Optional Tabler icon name (e.g., 'IconHeadset') */
1275
1540
  icon?: string;
1276
1541
  }
1542
+ /**
1543
+ * Resource list for organization
1544
+ * Returns ResourceDefinition metadata (not full definitions)
1545
+ */
1546
+ interface ResourceList {
1547
+ workflows: ResourceDefinition[];
1548
+ agents: ResourceDefinition[];
1549
+ total: number;
1550
+ organizationName: string;
1551
+ environment?: 'dev' | 'prod';
1552
+ }
1277
1553
  /** Webhook provider identifiers */
1278
1554
  type WebhookProviderType = 'cal-com' | 'fillout' | 'stripe' | 'signature-api' | 'instantly' | 'test';
1279
1555
  /** Webhook trigger configuration */
@@ -1545,6 +1821,20 @@ declare const DOMAINS: {
1545
1821
  */
1546
1822
  type ResourceDomain = (typeof DOMAINS)[keyof typeof DOMAINS];
1547
1823
 
1824
+ /**
1825
+ * Registry Validation Utilities
1826
+ *
1827
+ * Centralized validation logic for ResourceRegistry.
1828
+ * All validation runs at API startup - fails fast in development.
1829
+ */
1830
+
1831
+ declare class RegistryValidationError extends Error {
1832
+ readonly orgName: string;
1833
+ readonly resourceId: string | null;
1834
+ readonly field: string | null;
1835
+ constructor(orgName: string, resourceId: string | null, field: string | null, message: string);
1836
+ }
1837
+
1548
1838
  /**
1549
1839
  * Project configuration for an external developer project.
1550
1840
  * Defined in elevas.config.ts at the project root.
@@ -1557,5 +1847,31 @@ interface ElevasConfig {
1557
1847
  };
1558
1848
  }
1559
1849
 
1560
- export { ExecutionError, StepType, ToolingError };
1850
+ /**
1851
+ * Runtime values for SDK developers.
1852
+ *
1853
+ * These are standalone definitions (not re-exported from @repo/core)
1854
+ * to avoid pulling in the entire execution engine dependency tree (~3.5MB).
1855
+ * Values are identical to their @repo/core counterparts.
1856
+ */
1857
+ /** Step connection type for multi-step workflows */
1858
+ declare enum StepType {
1859
+ LINEAR = "linear",
1860
+ CONDITIONAL = "conditional"
1861
+ }
1862
+ /** Base error class for execution errors */
1863
+ declare class ExecutionError extends Error {
1864
+ readonly type: string;
1865
+ readonly context?: Record<string, unknown>;
1866
+ constructor(message: string, context?: Record<string, unknown>);
1867
+ isRetryable(): boolean;
1868
+ }
1869
+ /** Error thrown from tool execution handlers */
1870
+ declare class ToolingError extends ExecutionError {
1871
+ readonly errorType: string;
1872
+ readonly details?: unknown;
1873
+ constructor(errorType: string, message: string, details?: unknown);
1874
+ }
1875
+
1876
+ export { ExecutionError, RegistryValidationError, ResourceRegistry, StepType, ToolingError };
1561
1877
  export type { AgentConfig, AgentConstraints, AgentDefinition, ConditionalNext, Contract, DomainDefinition, ElevasConfig, EventTriggerConfig, ExecutionContext, ExecutionInterface, ExecutionMetadata, FormField, FormFieldType, FormSchema, IntegrationDefinition, LLMModel, LinearNext, ModelConfig, NextConfig, OrganizationResources, ResourceDefinition, ResourceDomain, ResourceMetricsConfig, ResourceStatus, ResourceType, ScheduleTriggerConfig, StepHandler, Tool, ToolExecutionOptions, ToolingErrorType, TriggerConfig, TriggerDefinition, WebhookProviderType, WebhookTriggerConfig, WorkflowConfig, WorkflowDefinition, WorkflowStep };