@autonomaai/api-schemas 1.0.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.
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@autonomaai/api-schemas",
3
+ "version": "1.0.0",
4
+ "description": "Unified API schemas and OpenAPI specifications for autonoma services",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "lint": "echo 'lint skipped'",
10
+ "test": "echo 'tests skipped'"
11
+ },
12
+ "keywords": [
13
+ "openapi",
14
+ "api-schema",
15
+ "typescript",
16
+ "trading",
17
+ "mcp",
18
+ "standardization"
19
+ ],
20
+ "author": "autonoma Team",
21
+ "license": "MIT",
22
+ "dependencies": {
23
+ "ajv": "^8.12.0",
24
+ "ajv-formats": "^2.1.1"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^20.0.0",
28
+ "typescript": "^5.2.0"
29
+ },
30
+ "peerDependencies": {
31
+ "typescript": ">=4.0.0"
32
+ },
33
+ "files": [
34
+ "dist/**/*",
35
+ "src/**/*",
36
+ "openapi.yaml",
37
+ "docs/**/*",
38
+ "README.md"
39
+ ],
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/autonoma/autonoma"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ }
47
+ }
@@ -0,0 +1,12 @@
1
+ // Global type declarations for Node.js environment
2
+ declare namespace NodeJS {
3
+ interface ProcessEnv {
4
+ [key: string]: string | undefined;
5
+ }
6
+
7
+ interface Process {
8
+ env: ProcessEnv;
9
+ }
10
+ }
11
+
12
+ declare const process: NodeJS.Process;
package/src/index.ts ADDED
@@ -0,0 +1,159 @@
1
+ /**
2
+ * autonoma API Schemas
3
+ *
4
+ * Unified API schemas and validation utilities for all autonoma services.
5
+ *
6
+ * This package normalizes API contracts across:
7
+ * - Hummingbot MCP Server
8
+ * - Backend API
9
+ * - Market Maker Agent
10
+ * - Data Collector
11
+ * - RAG Service
12
+ */
13
+
14
+ // Export validation utilities
15
+ export * from './validators';
16
+
17
+ // Export schema migration helpers
18
+ export {
19
+ migrateLegacyExecuteSignal,
20
+ convertToLegacyFormat,
21
+ createValidationMiddleware,
22
+ generatePythonValidator
23
+ } from './validators';
24
+
25
+ // Export validation result types
26
+ export type {
27
+ ValidationResult,
28
+ ValidationError
29
+ } from './validators';
30
+
31
+ // Export validation functions
32
+ export {
33
+ validateSuccessResponse,
34
+ validateErrorResponse,
35
+ validateCreateControllerRequest,
36
+ validateController,
37
+ validateTradingSignal,
38
+ validateExecuteSignalRequest
39
+ } from './validators';
40
+
41
+ // Version and metadata
42
+ export const API_SCHEMA_VERSION = '1.0.0';
43
+ export const SUPPORTED_FORMATS = ['openapi-3.0.3', 'json-schema-draft-07'];
44
+
45
+ // Schema format constants
46
+ export const SCHEMAS = {
47
+ OPENAPI_SPEC: 'openapi.yaml',
48
+ JSON_SCHEMAS: 'schemas/',
49
+ GENERATED_TYPES: 'generated-types.ts'
50
+ } as const;
51
+
52
+ // Endpoint normalization mappings
53
+ export const ENDPOINT_MIGRATIONS = {
54
+ LEGACY_EXECUTE_SIGNAL: '/trading/execute-signal',
55
+ LEGACY_CONTROLLER_SIGNAL: '/trading/{controller_id}/signal',
56
+ UNIFIED_EXECUTE_SIGNAL: '/trading/signals/execute'
57
+ } as const;
58
+
59
+ // Common error codes
60
+ export const ERROR_CODES = {
61
+ VALIDATION_FAILED: 'VALIDATION_FAILED',
62
+ CONTROLLER_NOT_FOUND: 'CONTROLLER_NOT_FOUND',
63
+ INVALID_SIGNAL: 'INVALID_SIGNAL',
64
+ EXCHANGE_ERROR: 'EXCHANGE_ERROR',
65
+ UNAUTHORIZED: 'UNAUTHORIZED',
66
+ RATE_LIMITED: 'RATE_LIMITED',
67
+ INTERNAL_ERROR: 'INTERNAL_ERROR'
68
+ } as const;
69
+
70
+ // Standard HTTP status codes
71
+ export const HTTP_STATUS = {
72
+ OK: 200,
73
+ CREATED: 201,
74
+ BAD_REQUEST: 400,
75
+ UNAUTHORIZED: 401,
76
+ FORBIDDEN: 403,
77
+ NOT_FOUND: 404,
78
+ CONFLICT: 409,
79
+ RATE_LIMITED: 429,
80
+ INTERNAL_ERROR: 500,
81
+ SERVICE_UNAVAILABLE: 503
82
+ } as const;
83
+
84
+ /**
85
+ * Create a standardized success response
86
+ */
87
+ export function createSuccessResponse<T = any>(
88
+ message: string,
89
+ data?: T,
90
+ additionalFields?: Record<string, any>
91
+ ) {
92
+ return {
93
+ success: true,
94
+ message,
95
+ timestamp: new Date().toISOString(),
96
+ ...(data !== undefined && { data }),
97
+ ...additionalFields
98
+ };
99
+ }
100
+
101
+ /**
102
+ * Create a standardized error response
103
+ */
104
+ export function createErrorResponse(
105
+ error: string,
106
+ detail?: string,
107
+ errorCode?: string,
108
+ additionalFields?: Record<string, any>
109
+ ) {
110
+ return {
111
+ success: false,
112
+ error,
113
+ ...(detail && { detail }),
114
+ ...(errorCode && { error_code: errorCode }),
115
+ timestamp: new Date().toISOString(),
116
+ ...additionalFields
117
+ };
118
+ }
119
+
120
+ /**
121
+ * Check if a response follows the standardized format
122
+ */
123
+ export function isStandardizedResponse(response: any): boolean {
124
+ return (
125
+ typeof response === 'object' &&
126
+ response !== null &&
127
+ typeof response.success === 'boolean' &&
128
+ typeof response.timestamp === 'string'
129
+ );
130
+ }
131
+
132
+ /**
133
+ * Normalize a legacy response to the standardized format
134
+ */
135
+ export function normalizeLegacyResponse(response: any): any {
136
+ // Already standardized
137
+ if (isStandardizedResponse(response)) {
138
+ return response;
139
+ }
140
+
141
+ // Handle common legacy patterns
142
+ if (response.status === 'success' || response.success === true) {
143
+ return createSuccessResponse(
144
+ response.message || 'Operation completed successfully',
145
+ response.data || response.result || response
146
+ );
147
+ }
148
+
149
+ if (response.status === 'error' || response.error) {
150
+ return createErrorResponse(
151
+ response.error || response.message || 'Operation failed',
152
+ response.detail || response.description,
153
+ response.error_code || response.code
154
+ );
155
+ }
156
+
157
+ // Default: treat as successful data response
158
+ return createSuccessResponse('Operation completed successfully', response);
159
+ }