@elevasis/core 0.2.0 → 0.3.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 (44) hide show
  1. package/dist/index.d.ts +60 -103
  2. package/dist/index.js +162 -109
  3. package/dist/organization-model/index.d.ts +60 -103
  4. package/dist/organization-model/index.js +162 -109
  5. package/package.json +1 -1
  6. package/src/README.md +24 -17
  7. package/src/__tests__/template-foundations-compatibility.test.ts +28 -36
  8. package/src/auth/multi-tenancy/types.ts +4 -11
  9. package/src/auth/multi-tenancy/users/api-schemas.ts +1 -1
  10. package/src/business/base-entities.test.ts +481 -0
  11. package/src/business/base-entities.ts +241 -0
  12. package/src/business/delivery/types.ts +1 -1
  13. package/src/business/index.ts +3 -0
  14. package/src/execution/index.ts +3 -6
  15. package/src/index.ts +1 -1
  16. package/src/organization-model/README.md +25 -26
  17. package/src/organization-model/__tests__/graph.test.ts +103 -71
  18. package/src/organization-model/__tests__/resolve.test.ts +20 -29
  19. package/src/organization-model/contracts.ts +3 -0
  20. package/src/organization-model/defaults.ts +40 -6
  21. package/src/organization-model/domains/features.ts +19 -54
  22. package/src/organization-model/domains/navigation.ts +25 -16
  23. package/src/organization-model/domains/shared.ts +1 -10
  24. package/src/organization-model/foundation.ts +96 -0
  25. package/src/organization-model/graph/build.ts +34 -67
  26. package/src/organization-model/graph/schema.ts +2 -4
  27. package/src/organization-model/graph/types.ts +3 -15
  28. package/src/organization-model/index.ts +2 -0
  29. package/src/organization-model/organization-model.mdx +34 -36
  30. package/src/organization-model/published.ts +12 -3
  31. package/src/organization-model/schema.ts +38 -34
  32. package/src/organization-model/types.ts +5 -10
  33. package/src/platform/constants/versions.ts +1 -1
  34. package/src/platform/sse/events.ts +1 -34
  35. package/src/projects/api-schemas.ts +2 -1
  36. package/src/reference/_generated/contracts.md +10 -31
  37. package/src/reference/glossary.md +14 -18
  38. package/src/supabase/database.types.ts +0 -107
  39. package/src/test-utils/rls/RLSTestContext.ts +1 -31
  40. package/src/execution/calibration/__tests__/schemas.test.ts +0 -320
  41. package/src/execution/calibration/index.ts +0 -3
  42. package/src/execution/calibration/schemas.ts +0 -121
  43. package/src/execution/calibration/sse-events.ts +0 -125
  44. package/src/execution/calibration/types.ts +0 -190
@@ -1,121 +0,0 @@
1
- import { z } from 'zod'
2
-
3
- // ============================================================================
4
- // LLM Model Schema
5
- // ============================================================================
6
-
7
- /**
8
- * LLM model validation schema
9
- * Matches LLMModel type from model-info.ts
10
- */
11
- const LLMModelSchema = z.enum([
12
- 'gpt-5',
13
- 'gpt-5.4-mini',
14
- 'gpt-5.4-nano',
15
- 'openrouter/z-ai/glm-5',
16
- 'gemini-3-flash-preview',
17
- 'gemini-3.1-flash-lite-preview',
18
- 'mock'
19
- ])
20
-
21
- // ============================================================================
22
- // Grading Schemas
23
- // ============================================================================
24
-
25
- /**
26
- * Grading criterion schema
27
- * Defines a single criterion for evaluating AI outputs
28
- */
29
- const GradingCriterionSchema = z.object({
30
- name: z.string().min(1),
31
- weight: z.number().min(0).max(1),
32
- description: z.string().min(1),
33
- scoringGuide: z.string().min(1)
34
- })
35
-
36
- /**
37
- * Grading rubric schema
38
- * Collection of criteria with passing threshold
39
- */
40
- const GradingRubricSchema = z.object({
41
- passingThreshold: z.number().min(0).max(1),
42
- criteria: z.array(GradingCriterionSchema).min(1)
43
- })
44
-
45
- // ============================================================================
46
- // Config Variant Schema
47
- // ============================================================================
48
-
49
- /**
50
- * Configuration variant schema
51
- * Defines a test variant with optional overrides
52
- */
53
- const ConfigVariantSchema = z.object({
54
- variantName: z.string().min(1),
55
- definitionOverrides: z.record(z.string(), z.unknown()).optional() // Flexible for agent/workflow overrides
56
- })
57
-
58
- // ============================================================================
59
- // Calibration Project Schemas
60
- // ============================================================================
61
-
62
- /**
63
- * Create calibration project schema
64
- * Validates request body for creating a new calibration project
65
- */
66
- export const CreateCalibrationProjectSchema = z.object({
67
- resourceId: z.string().min(1),
68
- resourceType: z.enum(['agent', 'workflow']),
69
- name: z.string().min(1),
70
- description: z.string().optional()
71
- })
72
-
73
- /**
74
- * Update calibration project schema
75
- * Validates request body for updating an existing calibration project
76
- */
77
- export const UpdateCalibrationProjectSchema = z.object({
78
- name: z.string().min(1).optional(),
79
- description: z.string().optional()
80
- })
81
-
82
- // ============================================================================
83
- // Calibration Run Schemas
84
- // ============================================================================
85
-
86
- /**
87
- * Create calibration run schema
88
- * Validates request body for creating a new calibration run
89
- * Includes refinement for graderModel requirement when gradingRubric is provided
90
- */
91
- export const CreateCalibrationRunSchema = z
92
- .object({
93
- projectId: z.string().uuid(),
94
- name: z.string().min(1),
95
- description: z.string().optional(),
96
- executionMode: z.enum(['single', 'session']).default('single'),
97
- testInputs: z.array(z.unknown()).min(1).max(50), // Min 1, max 50 inputs
98
- configVariants: z.array(ConfigVariantSchema).min(1).max(10), // Min 1, max 10 variants
99
- gradingRubric: GradingRubricSchema.optional(),
100
- graderModel: LLMModelSchema.optional()
101
- })
102
- .refine((data) => !data.gradingRubric || data.graderModel, {
103
- message: 'graderModel is required when gradingRubric is provided'
104
- })
105
-
106
- // ============================================================================
107
- // Exported Schemas
108
- // ============================================================================
109
-
110
- export { GradingRubricSchema, GradingCriterionSchema, ConfigVariantSchema }
111
-
112
- // ============================================================================
113
- // Inferred Types
114
- // ============================================================================
115
-
116
- export type CreateCalibrationProjectInput = z.infer<typeof CreateCalibrationProjectSchema>
117
- export type UpdateCalibrationProjectInput = z.infer<typeof UpdateCalibrationProjectSchema>
118
- export type CreateCalibrationRunInput = z.infer<typeof CreateCalibrationRunSchema>
119
- export type GradingRubricInput = z.infer<typeof GradingRubricSchema>
120
- export type GradingCriterionInput = z.infer<typeof GradingCriterionSchema>
121
- export type ConfigVariantInput = z.infer<typeof ConfigVariantSchema>
@@ -1,125 +0,0 @@
1
- /**
2
- * Calibration SSE Event Types
3
- *
4
- * Shared event type definitions for calibration real-time streaming.
5
- * Used by both the API broadcaster and the command-center UI.
6
- */
7
-
8
- // Single-turn events
9
-
10
- export interface CalibrationExecutionStartedEvent {
11
- type: 'execution-started'
12
- variantName: string
13
- inputIndex: number
14
- timestamp: number
15
- }
16
-
17
- export interface CalibrationExecutionCompletedEvent {
18
- type: 'execution-completed'
19
- variantName: string
20
- inputIndex: number
21
- executionId: string
22
- timestamp: number
23
- }
24
-
25
- export interface CalibrationExecutionFailedEvent {
26
- type: 'execution-failed'
27
- variantName: string
28
- inputIndex?: number
29
- error: string
30
- timestamp: number
31
- }
32
-
33
- // Session events
34
-
35
- export interface CalibrationSessionStartedEvent {
36
- type: 'session-started'
37
- variantName: string
38
- sessionId: string
39
- timestamp: number
40
- }
41
-
42
- export interface CalibrationTurnStartedEvent {
43
- type: 'turn-started'
44
- variantName: string
45
- turnNumber: number
46
- timestamp: number
47
- }
48
-
49
- export interface CalibrationTurnCompletedEvent {
50
- type: 'turn-completed'
51
- variantName: string
52
- turnNumber: number
53
- executionId: string
54
- timestamp: number
55
- }
56
-
57
- export interface CalibrationSessionCompletedEvent {
58
- type: 'session-completed'
59
- variantName: string
60
- sessionId: string
61
- turnCount: number
62
- timestamp: number
63
- }
64
-
65
- // Grading events
66
-
67
- export interface CalibrationGradingStartedEvent {
68
- type: 'grading-started'
69
- variantName: string
70
- timestamp: number
71
- }
72
-
73
- export interface CalibrationGradingCompletedEvent {
74
- type: 'grading-completed'
75
- variantName: string
76
- score: number
77
- timestamp: number
78
- }
79
-
80
- export interface CalibrationGradingFailedEvent {
81
- type: 'grading-failed'
82
- variantName: string
83
- error: string
84
- timestamp: number
85
- }
86
-
87
- // Completion events
88
-
89
- export interface CalibrationCompletedEvent {
90
- type: 'calibration-completed'
91
- summary: { total: number; completed: number; failed: number }
92
- timestamp: number
93
- }
94
-
95
- export interface CalibrationFailedEvent {
96
- type: 'calibration-failed'
97
- error: string
98
- timestamp: number
99
- }
100
-
101
- // Connection event
102
-
103
- export interface CalibrationConnectedEvent {
104
- type: 'connected'
105
- timestamp: number
106
- data?: undefined
107
- }
108
-
109
- /**
110
- * Union of all calibration SSE events
111
- */
112
- export type CalibrationSSEEvent =
113
- | CalibrationExecutionStartedEvent
114
- | CalibrationExecutionCompletedEvent
115
- | CalibrationExecutionFailedEvent
116
- | CalibrationSessionStartedEvent
117
- | CalibrationTurnStartedEvent
118
- | CalibrationTurnCompletedEvent
119
- | CalibrationSessionCompletedEvent
120
- | CalibrationGradingStartedEvent
121
- | CalibrationGradingCompletedEvent
122
- | CalibrationGradingFailedEvent
123
- | CalibrationCompletedEvent
124
- | CalibrationFailedEvent
125
- | CalibrationConnectedEvent
@@ -1,190 +0,0 @@
1
- /**
2
- * Calibration Lab Type Definitions
3
- * Core types for AI model configuration optimization with cost/performance comparison
4
- */
5
-
6
- import type { AgentDefinition } from '../engine/agent/core/types'
7
- import type { WorkflowDefinition } from '../engine/workflow/types'
8
- import type { ExecutionMetricsDetail } from '../../operations/observability/types'
9
-
10
- // ============================================================================
11
- // Calibration Project Types
12
- // ============================================================================
13
-
14
- /**
15
- * Calibration project - groups related optimization runs
16
- * Provides organizational structure for iterative testing
17
- */
18
- export interface CalibrationProject {
19
- id: string
20
- organizationId: string
21
- resourceId: string
22
- resourceType: 'agent' | 'workflow'
23
- name: string
24
- description?: string | null
25
- createdAt: Date
26
- updatedAt: Date
27
- }
28
-
29
- // ============================================================================
30
- // Configuration Variant Types
31
- // ============================================================================
32
-
33
- /**
34
- * Configuration variant for testing
35
- * Defines what to override in the base agent/workflow definition
36
- */
37
- export interface ConfigVariant {
38
- variantName: string
39
- definitionOverrides?: AgentCalibrationOverrides | WorkflowCalibrationOverrides
40
- }
41
-
42
- /**
43
- * Agent definition overrides for calibration
44
- * Excludes identity/metadata fields that should not be modified
45
- */
46
- export type AgentCalibrationOverrides = Omit<
47
- Partial<AgentDefinition>,
48
- 'config' | 'contract' | 'tools' | 'metricsConfig' | 'interface'
49
- >
50
-
51
- /**
52
- * Workflow definition overrides for calibration
53
- * Excludes identity/metadata fields that should not be modified
54
- */
55
- export type WorkflowCalibrationOverrides = Omit<
56
- Partial<WorkflowDefinition>,
57
- 'config' | 'contract' | 'steps' | 'entryPoint' | 'metricsConfig' | 'interface'
58
- >
59
-
60
- // ============================================================================
61
- // Grading System Types
62
- // ============================================================================
63
-
64
- /**
65
- * Grading rubric for LLM-as-judge evaluation
66
- * Defines criteria and passing threshold
67
- */
68
- export interface GradingRubric {
69
- passingThreshold: number // 0-1, e.g., 0.7 means 70% to pass
70
- criteria: GradingCriterion[]
71
- }
72
-
73
- /**
74
- * Individual grading criterion
75
- * Weight should be 0-1, and all weights should sum to 1
76
- */
77
- export interface GradingCriterion {
78
- name: string
79
- weight: number // 0-1, weights should sum to 1
80
- description: string
81
- scoringGuide: string
82
- }
83
-
84
- /**
85
- * Grading result for a single execution or session
86
- * Contains overall score and per-criterion breakdown
87
- */
88
- export interface GradeResult {
89
- score: number // 0-1
90
- passed: boolean
91
- details: Record<string, { score: number; justification: string }>
92
- }
93
-
94
- // ============================================================================
95
- // Result Types
96
- // ============================================================================
97
-
98
- /**
99
- * Single-turn calibration result
100
- * One result per (variant × input) combination
101
- */
102
- export interface SingleCalibrationResult {
103
- executionId: string // Reference to execution_logs
104
- variantName: string
105
- inputIndex: number // Which input from testInputs array (0-based)
106
- appliedOverrides?: AgentCalibrationOverrides | WorkflowCalibrationOverrides
107
- status: 'pending' | 'running' | 'completed' | 'failed'
108
- errorMessage?: string
109
- grade?: GradeResult
110
- gradeError?: string
111
- }
112
-
113
- /**
114
- * Multi-turn session calibration result
115
- * Leverages existing sessions infrastructure
116
- */
117
- export interface SessionCalibrationResult {
118
- sessionId: string // Reference to sessions table
119
- variantName: string
120
- appliedOverrides?: AgentCalibrationOverrides | WorkflowCalibrationOverrides
121
- status: 'pending' | 'running' | 'completed' | 'failed'
122
- errorMessage?: string
123
- turnCount: number
124
- grade?: GradeResult
125
- gradeError?: string
126
- }
127
-
128
- // ============================================================================
129
- // Calibration Run Types
130
- // ============================================================================
131
-
132
- /**
133
- * Calibration run - individual test execution within a project
134
- * Contains configuration, results, and grading information
135
- */
136
- export interface CalibrationRun {
137
- id: string
138
- organizationId: string
139
- projectId: string
140
- name: string
141
- description?: string | null
142
- executionMode: 'single' | 'session'
143
- testInputs: unknown[]
144
- configVariants: ConfigVariant[]
145
- gradingRubric?: GradingRubric | null
146
- graderModel?: string | null
147
- results: (SingleCalibrationResult | SessionCalibrationResult)[]
148
- status: 'pending' | 'running' | 'completed' | 'partial' | 'failed'
149
- createdAt: Date
150
- completedAt?: Date | null
151
- }
152
-
153
- // ============================================================================
154
- // Combined Response Types
155
- // ============================================================================
156
-
157
- /**
158
- * Execution log subset for comparison view
159
- * Contains essential data without full execution context
160
- */
161
- export interface ExecutionLog {
162
- executionId: string
163
- status: 'running' | 'completed' | 'failed'
164
- input: unknown
165
- output: unknown | null
166
- error: CalibrationExecutionError | null
167
- startedAt: string
168
- completedAt: string | null
169
- }
170
-
171
- /**
172
- * Execution error information for calibration display
173
- * Subset of full execution error for UI display purposes
174
- * Named differently from ExecutionError class to avoid type conflicts
175
- */
176
- export interface CalibrationExecutionError {
177
- message: string
178
- category?: string
179
- type?: string
180
- }
181
-
182
- /**
183
- * Combined calibration run data for comparison view
184
- * Single API call returns run + execution logs + metrics
185
- */
186
- export interface CalibrationRunWithFullData {
187
- run: CalibrationRun
188
- logs: Record<string, ExecutionLog> // keyed by executionId
189
- metrics: Record<string, ExecutionMetricsDetail> // keyed by executionId
190
- }