@elevasis/core 0.15.1 → 0.16.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 (68) hide show
  1. package/dist/index.d.ts +1662 -23
  2. package/dist/index.js +171 -24
  3. package/dist/organization-model/index.d.ts +1662 -23
  4. package/dist/organization-model/index.js +171 -24
  5. package/dist/test-utils/index.d.ts +711 -10
  6. package/dist/test-utils/index.js +159 -16
  7. package/package.json +7 -3
  8. package/src/__tests__/publish.test.ts +14 -13
  9. package/src/__tests__/template-core-compatibility.test.ts +4 -4
  10. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +305 -201
  11. package/src/auth/multi-tenancy/index.ts +3 -0
  12. package/src/auth/multi-tenancy/theme-presets.ts +45 -0
  13. package/src/auth/multi-tenancy/types.ts +57 -83
  14. package/src/auth/multi-tenancy/users/api-schemas.ts +165 -194
  15. package/src/business/acquisition/activity-events.ts +1 -1
  16. package/src/business/acquisition/api-schemas.ts +1196 -1177
  17. package/src/business/acquisition/crm-state-actions.test.ts +139 -139
  18. package/src/business/acquisition/types.ts +381 -390
  19. package/src/business/crm/api-schemas.ts +40 -0
  20. package/src/business/crm/index.ts +1 -0
  21. package/src/business/deals/api-schemas.ts +79 -0
  22. package/src/business/deals/index.ts +1 -0
  23. package/src/business/projects/types.ts +124 -88
  24. package/src/execution/core/runner-types.ts +61 -80
  25. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-tools.ts +105 -104
  26. package/src/execution/engine/tools/integration/server/adapters/instantly/instantly-tools.ts +1474 -1473
  27. package/src/execution/engine/tools/integration/server/adapters/millionverifier/millionverifier-tools.ts +103 -102
  28. package/src/execution/engine/tools/integration/server/adapters/signature-api/signature-api-tools.ts +182 -179
  29. package/src/execution/engine/tools/integration/server/adapters/stripe/stripe-tools.ts +310 -309
  30. package/src/execution/engine/tools/integration/tool.ts +255 -253
  31. package/src/execution/engine/tools/lead-service-types.ts +895 -894
  32. package/src/execution/engine/tools/messages.ts +43 -0
  33. package/src/execution/engine/tools/platform/acquisition/types.ts +2 -1
  34. package/src/execution/engine/tools/platform/email/types.ts +97 -96
  35. package/src/execution/engine/tools/types.ts +234 -233
  36. package/src/execution/engine/workflow/types.ts +195 -193
  37. package/src/execution/external/api-schemas.ts +40 -0
  38. package/src/execution/external/index.ts +1 -0
  39. package/src/knowledge/README.md +32 -0
  40. package/src/knowledge/__tests__/queries.test.ts +504 -0
  41. package/src/knowledge/format.ts +99 -0
  42. package/src/knowledge/index.ts +5 -0
  43. package/src/knowledge/queries.ts +256 -0
  44. package/src/organization-model/__tests__/defaults.test.ts +172 -172
  45. package/src/organization-model/__tests__/foundation.test.ts +7 -7
  46. package/src/organization-model/__tests__/icons.test.ts +27 -0
  47. package/src/organization-model/__tests__/knowledge.test.ts +214 -0
  48. package/src/organization-model/contracts.ts +17 -15
  49. package/src/organization-model/defaults.ts +74 -19
  50. package/src/organization-model/domains/knowledge.ts +53 -0
  51. package/src/organization-model/domains/navigation.ts +416 -399
  52. package/src/organization-model/domains/shared.ts +6 -5
  53. package/src/organization-model/foundation.ts +10 -6
  54. package/src/organization-model/graph/build.ts +209 -182
  55. package/src/organization-model/graph/schema.ts +37 -34
  56. package/src/organization-model/graph/types.ts +47 -31
  57. package/src/organization-model/icons.ts +81 -0
  58. package/src/organization-model/index.ts +8 -3
  59. package/src/organization-model/organization-model.mdx +1 -1
  60. package/src/organization-model/published.ts +103 -86
  61. package/src/organization-model/schema.ts +90 -85
  62. package/src/organization-model/types.ts +40 -33
  63. package/src/platform/index.ts +23 -27
  64. package/src/platform/registry/index.ts +0 -4
  65. package/src/platform/registry/resource-registry.ts +0 -77
  66. package/src/platform/registry/serialized-types.ts +148 -219
  67. package/src/platform/registry/stats-types.ts +60 -60
  68. package/src/reference/_generated/contracts.md +1265 -1154
@@ -1,233 +1,234 @@
1
- /**
2
- * Tool definitions
3
- *
4
- * Tool interface used by agents and workflows.
5
- * Provides a universal interface for AI systems to interact with tools.
6
- */
7
-
8
- import { z } from 'zod'
9
- import { ExecutionError } from '../base/errors'
10
- import type { ExecutionContext } from '../base/types'
11
- import type { IterationContext } from '../agent/core/types'
12
-
13
- /**
14
- * Options for tool execution
15
- * Provides named parameters for better API clarity and extensibility
16
- */
17
- export interface ToolExecutionOptions {
18
- /** Tool input (validated against inputSchema before execution) */
19
- input: unknown
20
-
21
- /** Execution context with multi-tenant isolation and observability (optional for simple tools, required for platform/integration tools) */
22
- executionContext?: ExecutionContext
23
-
24
- /** Full iteration context for advanced tools (provides access to memoryManager, toolRegistry, logger, etc.) */
25
- iterationContext?: IterationContext
26
-
27
- /** Abort signal for timeout/cancellation -- forward to fetch() calls for clean cancellation */
28
- signal?: AbortSignal
29
- }
30
-
31
- /**
32
- * Tool interface for AI systems
33
- *
34
- * Used by:
35
- * - Agents: For agentic tool use (reasoning loop selects and executes tools)
36
- * - Workflows: For workflow step tool invocation (future)
37
- * - Platform tools: createApprovalTool(), createSchedulerTool()
38
- * - Integration tools: External API calls (Gmail, Slack, etc.)
39
- */
40
- export interface Tool {
41
- // Required fields
42
- name: string // Unique identifier (e.g., 'web_search', 'calculator')
43
- description: string // What the tool does (used by LLM for selection)
44
-
45
- // I/O validation (both required for complete type safety)
46
- inputSchema: z.ZodSchema // Input validation schema
47
- outputSchema: z.ZodSchema // Output validation schema
48
-
49
- // Execution
50
- execute: (options: ToolExecutionOptions) => Promise<unknown>
51
-
52
- // Timeout (optional) -- per-tool override in ms, defaults to DEFAULT_TOOL_TIMEOUT (300_000 / 5min) in executor
53
- timeout?: number
54
- }
55
-
56
- /**
57
- * Tool definition (for LLM communication)
58
- * Universal format for tool specifications sent to LLMs
59
- */
60
- export interface ToolDefinition {
61
- name: string // Unique identifier
62
- description: string // LLM-readable purpose
63
- inputSchema: unknown // JSON Schema
64
- }
65
-
66
- /**
67
- * Tooling error types
68
- * Used across platform tools and integration tools
69
- */
70
- export type ToolingErrorType =
71
- // Platform tool errors
72
- | 'service_unavailable'
73
- | 'permission_denied'
74
-
75
- // Integration tool errors
76
- | 'adapter_not_found'
77
- | 'method_not_found'
78
- | 'tool_not_found'
79
- | 'credentials_missing'
80
- | 'credentials_invalid'
81
- | 'rate_limit_exceeded'
82
- | 'server_unavailable'
83
- | 'auth_error'
84
- | 'api_error'
85
- | 'validation_error'
86
- | 'network_error'
87
- | 'timeout_error'
88
- | 'unknown_error'
89
-
90
- /**
91
- * Tooling error class
92
- * Provides structured error information for tool failures across all tool types
93
- *
94
- * Severity mapping:
95
- * - critical: credentials_missing, credentials_invalid, permission_denied, auth_error,
96
- * adapter_not_found, method_not_found, tool_not_found
97
- * - info: validation_error
98
- * - warning: All other types (retryable transient errors)
99
- *
100
- * Category: tool (tool execution errors)
101
- */
102
- export class ToolingError extends ExecutionError {
103
- readonly type = 'tooling_error' as const
104
- readonly category = 'tool' as const
105
-
106
- constructor(
107
- public readonly errorType: ToolingErrorType,
108
- message: string,
109
- public readonly details?: unknown
110
- ) {
111
- super(message, { type: errorType, details })
112
- }
113
-
114
- /**
115
- * Derive severity based on error type
116
- */
117
- get severity(): 'critical' | 'warning' | 'info' {
118
- // Critical: Authentication, authorization, and configuration errors
119
- if (
120
- [
121
- 'credentials_missing',
122
- 'credentials_invalid',
123
- 'permission_denied',
124
- 'auth_error',
125
- 'adapter_not_found',
126
- 'method_not_found',
127
- 'tool_not_found'
128
- ].includes(this.errorType)
129
- ) {
130
- return 'critical'
131
- }
132
-
133
- // Info: Validation errors (user input errors)
134
- if (this.errorType === 'validation_error') {
135
- return 'info'
136
- }
137
-
138
- // Warning: Transient failures (retryable)
139
- return 'warning'
140
- }
141
-
142
- /**
143
- * Check if error is retryable
144
- */
145
- override isRetryable(): boolean {
146
- return [
147
- 'service_unavailable',
148
- 'rate_limit_exceeded',
149
- 'api_error',
150
- 'network_error',
151
- 'timeout_error',
152
- 'server_unavailable'
153
- ].includes(this.errorType)
154
- }
155
-
156
- /**
157
- * Convert to JSON for logging
158
- */
159
- toJSON() {
160
- return {
161
- name: this.name,
162
- type: this.errorType,
163
- message: this.message,
164
- severity: this.severity,
165
- category: this.category,
166
- details: this.details
167
- }
168
- }
169
- }
170
-
171
- // Factory functions for common error types
172
-
173
- /** Platform tool errors */
174
- export function serviceUnavailable(serviceName: string, details?: unknown): ToolingError {
175
- return new ToolingError('service_unavailable', `${serviceName} is unavailable`, details)
176
- }
177
-
178
- export function permissionDenied(operation: string): ToolingError {
179
- return new ToolingError('permission_denied', `Permission denied: ${operation}`)
180
- }
181
-
182
- /** Integration tool errors */
183
- export function adapterNotFound(adapterId: string): ToolingError {
184
- return new ToolingError('adapter_not_found', `Integration adapter not found: ${adapterId}`)
185
- }
186
-
187
- export function methodNotFound(methodName: string): ToolingError {
188
- return new ToolingError('method_not_found', `Method not found: ${methodName}`)
189
- }
190
-
191
- export function toolNotFound(toolName: string): ToolingError {
192
- return new ToolingError('tool_not_found', `Tool not found: ${toolName}`)
193
- }
194
-
195
- export function credentialsMissing(integrationName: string): ToolingError {
196
- return new ToolingError('credentials_missing', `No credentials found for ${integrationName}`)
197
- }
198
-
199
- export function credentialsInvalid(integrationName: string): ToolingError {
200
- return new ToolingError('credentials_invalid', `Credentials expired or invalid for ${integrationName}`)
201
- }
202
-
203
- export function rateLimitExceeded(service: string): ToolingError {
204
- return new ToolingError('rate_limit_exceeded', `Rate limit exceeded for ${service}`)
205
- }
206
-
207
- export function serverUnavailable(serverName: string): ToolingError {
208
- return new ToolingError('server_unavailable', `${serverName} is unavailable`)
209
- }
210
-
211
- export function authError(message: string): ToolingError {
212
- return new ToolingError('auth_error', message)
213
- }
214
-
215
- export function apiError(message: string, details?: unknown): ToolingError {
216
- return new ToolingError('api_error', message, details)
217
- }
218
-
219
- export function validationError(message: string): ToolingError {
220
- return new ToolingError('validation_error', message)
221
- }
222
-
223
- export function networkError(message: string): ToolingError {
224
- return new ToolingError('network_error', message)
225
- }
226
-
227
- export function timeoutError(operation: string): ToolingError {
228
- return new ToolingError('timeout_error', `Operation timed out: ${operation}`)
229
- }
230
-
231
- export function unknownError(message: string, details?: unknown): ToolingError {
232
- return new ToolingError('unknown_error', message, details)
233
- }
1
+ /**
2
+ * Tool definitions
3
+ *
4
+ * Tool interface used by agents and workflows.
5
+ * Provides a universal interface for AI systems to interact with tools.
6
+ */
7
+
8
+ import { z } from 'zod'
9
+ import { ExecutionError } from '../base/errors'
10
+ import type { ExecutionContext } from '../base/types'
11
+ import type { IterationContext } from '../agent/core/types'
12
+
13
+ /**
14
+ * Options for tool execution
15
+ * Provides named parameters for better API clarity and extensibility
16
+ */
17
+ export interface ToolExecutionOptions {
18
+ /** Tool input (validated against inputSchema before execution) */
19
+ input: unknown
20
+
21
+ /** Execution context with multi-tenant isolation and observability (optional for simple tools, required for platform/integration tools) */
22
+ executionContext?: ExecutionContext
23
+
24
+ /** Full iteration context for advanced tools (provides access to memoryManager, toolRegistry, logger, etc.) */
25
+ iterationContext?: IterationContext
26
+
27
+ /** Abort signal for timeout/cancellation -- forward to fetch() calls for clean cancellation */
28
+ signal?: AbortSignal
29
+ }
30
+
31
+ /**
32
+ * Tool interface for AI systems
33
+ *
34
+ * Used by:
35
+ * - Agents: For agentic tool use (reasoning loop selects and executes tools)
36
+ * - Workflows: For workflow step tool invocation (future)
37
+ * - Platform tools: createApprovalTool(), createSchedulerTool()
38
+ * - Integration tools: External API calls (Gmail, Slack, etc.)
39
+ */
40
+ export interface Tool {
41
+ // Required fields
42
+ name: string // Unique identifier (e.g., 'web_search', 'calculator')
43
+ description: string // What the tool does (used by LLM for selection)
44
+
45
+ // I/O validation (both required for complete type safety)
46
+ inputSchema: z.ZodSchema // Input validation schema
47
+ outputSchema: z.ZodSchema // Output validation schema
48
+
49
+ // Execution
50
+ execute: (options: ToolExecutionOptions) => Promise<unknown>
51
+
52
+ // Timeout (optional) -- per-tool override in ms, defaults to DEFAULT_TOOL_TIMEOUT (300_000 / 5min) in executor
53
+ timeout?: number
54
+ }
55
+
56
+ /**
57
+ * Tool definition (for LLM communication)
58
+ * Universal format for tool specifications sent to LLMs
59
+ */
60
+ export interface ToolDefinition {
61
+ name: string // Unique identifier
62
+ description: string // LLM-readable purpose
63
+ inputSchema: unknown // JSON Schema
64
+ }
65
+
66
+ /**
67
+ * Tooling error types
68
+ * Used across platform tools and integration tools
69
+ */
70
+ export type ToolingErrorType =
71
+ // Platform tool errors
72
+ | 'service_unavailable'
73
+ | 'permission_denied'
74
+ | 'platform_internal'
75
+
76
+ // Integration tool errors
77
+ | 'adapter_not_found'
78
+ | 'method_not_found'
79
+ | 'tool_not_found'
80
+ | 'credentials_missing'
81
+ | 'credentials_invalid'
82
+ | 'rate_limit_exceeded'
83
+ | 'server_unavailable'
84
+ | 'auth_error'
85
+ | 'api_error'
86
+ | 'validation_error'
87
+ | 'network_error'
88
+ | 'timeout_error'
89
+ | 'unknown_error'
90
+
91
+ /**
92
+ * Tooling error class
93
+ * Provides structured error information for tool failures across all tool types
94
+ *
95
+ * Severity mapping:
96
+ * - critical: credentials_missing, credentials_invalid, permission_denied, auth_error,
97
+ * adapter_not_found, method_not_found, tool_not_found
98
+ * - info: validation_error
99
+ * - warning: All other types (retryable transient errors)
100
+ *
101
+ * Category: tool (tool execution errors)
102
+ */
103
+ export class ToolingError extends ExecutionError {
104
+ readonly type = 'tooling_error' as const
105
+ readonly category = 'tool' as const
106
+
107
+ constructor(
108
+ public readonly errorType: ToolingErrorType,
109
+ message: string,
110
+ public readonly details?: unknown
111
+ ) {
112
+ super(message, { type: errorType, details })
113
+ }
114
+
115
+ /**
116
+ * Derive severity based on error type
117
+ */
118
+ get severity(): 'critical' | 'warning' | 'info' {
119
+ // Critical: Authentication, authorization, and configuration errors
120
+ if (
121
+ [
122
+ 'credentials_missing',
123
+ 'credentials_invalid',
124
+ 'permission_denied',
125
+ 'auth_error',
126
+ 'adapter_not_found',
127
+ 'method_not_found',
128
+ 'tool_not_found'
129
+ ].includes(this.errorType)
130
+ ) {
131
+ return 'critical'
132
+ }
133
+
134
+ // Info: Validation errors (user input errors)
135
+ if (this.errorType === 'validation_error') {
136
+ return 'info'
137
+ }
138
+
139
+ // Warning: Transient failures (retryable)
140
+ return 'warning'
141
+ }
142
+
143
+ /**
144
+ * Check if error is retryable
145
+ */
146
+ override isRetryable(): boolean {
147
+ return [
148
+ 'service_unavailable',
149
+ 'rate_limit_exceeded',
150
+ 'api_error',
151
+ 'network_error',
152
+ 'timeout_error',
153
+ 'server_unavailable'
154
+ ].includes(this.errorType)
155
+ }
156
+
157
+ /**
158
+ * Convert to JSON for logging
159
+ */
160
+ toJSON() {
161
+ return {
162
+ name: this.name,
163
+ type: this.errorType,
164
+ message: this.message,
165
+ severity: this.severity,
166
+ category: this.category,
167
+ details: this.details
168
+ }
169
+ }
170
+ }
171
+
172
+ // Factory functions for common error types
173
+
174
+ /** Platform tool errors */
175
+ export function serviceUnavailable(serviceName: string, details?: unknown): ToolingError {
176
+ return new ToolingError('service_unavailable', `${serviceName} is unavailable`, details)
177
+ }
178
+
179
+ export function permissionDenied(operation: string): ToolingError {
180
+ return new ToolingError('permission_denied', `Permission denied: ${operation}`)
181
+ }
182
+
183
+ /** Integration tool errors */
184
+ export function adapterNotFound(adapterId: string): ToolingError {
185
+ return new ToolingError('adapter_not_found', `Integration adapter not found: ${adapterId}`)
186
+ }
187
+
188
+ export function methodNotFound(methodName: string): ToolingError {
189
+ return new ToolingError('method_not_found', `Method not found: ${methodName}`)
190
+ }
191
+
192
+ export function toolNotFound(toolName: string): ToolingError {
193
+ return new ToolingError('tool_not_found', `Tool not found: ${toolName}`)
194
+ }
195
+
196
+ export function credentialsMissing(integrationName: string): ToolingError {
197
+ return new ToolingError('credentials_missing', `No credentials found for ${integrationName}`)
198
+ }
199
+
200
+ export function credentialsInvalid(integrationName: string): ToolingError {
201
+ return new ToolingError('credentials_invalid', `Credentials expired or invalid for ${integrationName}`)
202
+ }
203
+
204
+ export function rateLimitExceeded(service: string): ToolingError {
205
+ return new ToolingError('rate_limit_exceeded', `Rate limit exceeded for ${service}`)
206
+ }
207
+
208
+ export function serverUnavailable(serverName: string): ToolingError {
209
+ return new ToolingError('server_unavailable', `${serverName} is unavailable`)
210
+ }
211
+
212
+ export function authError(message: string): ToolingError {
213
+ return new ToolingError('auth_error', message)
214
+ }
215
+
216
+ export function apiError(message: string, details?: unknown): ToolingError {
217
+ return new ToolingError('api_error', message, details)
218
+ }
219
+
220
+ export function validationError(message: string): ToolingError {
221
+ return new ToolingError('validation_error', message)
222
+ }
223
+
224
+ export function networkError(message: string): ToolingError {
225
+ return new ToolingError('network_error', message)
226
+ }
227
+
228
+ export function timeoutError(operation: string): ToolingError {
229
+ return new ToolingError('timeout_error', `Operation timed out: ${operation}`)
230
+ }
231
+
232
+ export function unknownError(message: string, details?: unknown): ToolingError {
233
+ return new ToolingError('unknown_error', message, details)
234
+ }