@onairosofficial/onairos-capacitor 0.1.0 → 0.1.2
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/CAPACITOR_QUICK_START.md +379 -0
- package/CONNECTORS.md +122 -0
- package/LICENSE +194 -10
- package/OnairosofficialOnairosCapacitor.podspec +13 -0
- package/Package.swift +26 -0
- package/README.md +176 -25
- package/dist/onairos.capacitor.esm.js +1 -0
- package/dist/onairos.capacitor.esm.turbopack.js +1 -0
- package/docs/CAPACITOR_INTEGRATION_GUIDE.md +159 -0
- package/docs/CAPACITOR_MOCK_APP_TESTING.md +213 -0
- package/docs/CAPACITOR_SDK_FIXES_SUMMARY.md +65 -0
- package/docs/CROSS_SDK_PARITY.md +239 -0
- package/docs/DATA_FREQUENCY.md +57 -0
- package/docs/DEVELOPER_SDK_CHANGES.md +532 -0
- package/docs/INCIDENT_ENABLETRAINING_PIN_WEB_8.1.9.md +82 -0
- package/docs/ONAIROS_BUTTON_PROPS.md +152 -0
- package/docs/PLATFORM_APIS.md +559 -0
- package/docs/RAW_MEMORIES_API.md +305 -0
- package/docs/RAW_MEMORIES_SDK_UPDATE.md +54 -0
- package/docs/SDK_PARITY_ROLLUP_2026_04_24_to_05_02.md +96 -0
- package/docs/oldFixes.md +216 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosChatGPTNativePlugin.swift +993 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosNetflixNativePlugin.swift +33 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosSpotifyNativePlugin.swift +1082 -0
- package/onairos.d.ts +656 -0
- package/package.json +188 -37
- package/src/OnairosReconnectButton.jsx +272 -0
- package/src/RSA.jsx +57 -0
- package/src/assets/NewLogo.png +0 -0
- package/src/assets/OnairosNewLogo.png +0 -0
- package/src/assets/chatgpt-icon.png +0 -0
- package/src/assets/fire-horse.png +0 -0
- package/src/assets/fire-horse.transparent.png +0 -0
- package/src/assets/latest-firehorse.png +0 -0
- package/src/assets/perplexity.png +0 -0
- package/src/assets/persona.png +0 -0
- package/src/assets/persona1.png +0 -0
- package/src/assets/persona2.png +0 -0
- package/src/assets/persona3.png +0 -0
- package/src/assets/persona4.png +0 -0
- package/src/assets/persona5.png +0 -0
- package/src/capacitorConnectorCatalog.js +38 -0
- package/src/capacitorOAuthConfig.js +52 -0
- package/src/chatgptHostedImport/index.js +303 -0
- package/src/components/AuthButtons.jsx +48 -0
- package/src/components/ConnectChatGPTModal.jsx +666 -0
- package/src/components/ConnectClaudeModal.jsx +610 -0
- package/src/components/ConnectGeminiModal.jsx +639 -0
- package/src/components/ConnectGrokModal.jsx +701 -0
- package/src/components/ConnectPerplexityModal.jsx +726 -0
- package/src/components/DataExplainerScreen.jsx +349 -0
- package/src/components/DataRequest.js +885 -0
- package/src/components/DataRequest.jsx +1055 -0
- package/src/components/EmailAuth.js +1871 -0
- package/src/components/EmailAuth.jsx +2062 -0
- package/src/components/ExtensionInstallPrompt.jsx +142 -0
- package/src/components/GoogleButton.js +133 -0
- package/src/components/LLMConnectorManager.jsx +201 -0
- package/src/components/LoadingPage.jsx +19 -0
- package/src/components/LoadingScreen.jsx +81 -0
- package/src/components/LunarBirthdate.jsx +96 -0
- package/src/components/LunarLoadingPage.jsx +251 -0
- package/src/components/Notification.jsx +21 -0
- package/src/components/OnairosAppButton.jsx +85 -0
- package/src/components/OnairosSSO.jsx +645 -0
- package/src/components/OnairosTrigger.jsx +61 -0
- package/src/components/PerplexityLogo.jsx +43 -0
- package/src/components/PinSetup.js +200 -0
- package/src/components/PinSetup.jsx +228 -0
- package/src/components/SDK_PIN_INTEGRATION_REQUIRED_CHANGES.md +526 -0
- package/src/components/SdkErrorBoundary.jsx +36 -0
- package/src/components/SecuritySetup.js +81 -0
- package/src/components/SessionUserBar.jsx +83 -0
- package/src/components/SignUp.js +123 -0
- package/src/components/TestTelegramButton.js +53 -0
- package/src/components/TrainingComponent.jsx +200 -0
- package/src/components/TrainingScreen.jsx +897 -0
- package/src/components/UniversalOnboarding.js +306 -0
- package/src/components/UniversalOnboarding.jsx +4837 -0
- package/src/components/ValentineLoadingPage.jsx +502 -0
- package/src/components/ValentineModeSelector.jsx +162 -0
- package/src/components/WelcomeScreen.jsx +435 -0
- package/src/components/WrappedLoadingPage.jsx +205 -0
- package/src/components/connectors/ChatGPTConnector.js +348 -0
- package/src/components/connectors/ChatGPTConnector.jsx +348 -0
- package/src/components/connectors/ClaudeConnector.js +44 -0
- package/src/components/connectors/ClaudeConnector.jsx +44 -0
- package/src/components/connectors/GeminiConnector.js +170 -0
- package/src/components/connectors/GeminiConnector.jsx +170 -0
- package/src/components/connectors/GmailConnector.js +148 -0
- package/src/components/connectors/GmailConnector.jsx +148 -0
- package/src/components/connectors/GrokConnector.js +16 -0
- package/src/components/connectors/GrokConnector.jsx +16 -0
- package/src/components/connectors/HingeConnector.js +419 -0
- package/src/components/connectors/HingeConnector.jsx +419 -0
- package/src/components/connectors/InstagramDataConnector.js +726 -0
- package/src/components/connectors/InstagramDataConnector.jsx +726 -0
- package/src/components/connectors/LinkedInConnector.js +4 -0
- package/src/components/connectors/LinkedInConnector.jsx +296 -0
- package/src/components/connectors/PerplexityConnector.jsx +16 -0
- package/src/components/connectors/PinterestConnector.js +208 -0
- package/src/components/connectors/PinterestConnector.jsx +208 -0
- package/src/components/connectors/README.md +292 -0
- package/src/components/connectors/RedditConnector.js +229 -0
- package/src/components/connectors/RedditConnector.jsx +229 -0
- package/src/components/connectors/SephoraConnector.js +482 -0
- package/src/components/connectors/SephoraConnector.jsx +482 -0
- package/src/components/connectors/TikTokConnector.jsx +430 -0
- package/src/components/connectors/YoutubeConnector.js +361 -0
- package/src/components/connectors/YoutubeConnector.jsx +361 -0
- package/src/components/connectors/index.js +50 -0
- package/src/components/icons.jsx +46 -0
- package/src/components/icons.tsx +21 -0
- package/src/components/ui/PageLayout.jsx +1255 -0
- package/src/components/ui/PrimaryButton.jsx +162 -0
- package/src/components/ui/button.jsx +49 -0
- package/src/components/ui/card.jsx +61 -0
- package/src/components/ui/checkbox.jsx +33 -0
- package/src/components/ui/label.jsx +29 -0
- package/src/components/utils/UpdateConnections.js +45 -0
- package/src/components/utils/oauthHelper.js +97 -0
- package/src/config/api-config.js +138 -0
- package/src/deepLink.jsx +38 -0
- package/src/getPin.js +26 -0
- package/src/icons/Avatar.png +0 -0
- package/src/icons/Sentiment.png +0 -0
- package/src/icons/Trait.png +0 -0
- package/src/iframe/DataRequestPage.jsx +285 -0
- package/src/iframe/OnairosButtonIntegration.md +148 -0
- package/src/iframe/components/Box.jsx +56 -0
- package/src/iframe/components/IndividualConnection.jsx +88 -0
- package/src/iframe/dataRequestHandler.js +714 -0
- package/src/iframe/data_request_iframe.html +27 -0
- package/src/iframe/data_request_page.js +47 -0
- package/src/iframe/icons/Avatar.png +1 -0
- package/src/iframe/icons/Avatar2.png +1 -0
- package/src/iframe/icons/Sentiment.png +1 -0
- package/src/iframe/icons/Trait.png +1 -0
- package/src/iframe/icons/onairos_logo.png +0 -0
- package/src/iframe/utils/api.js +57 -0
- package/src/index.js +274 -0
- package/src/laravel/OnairosVue.vue +410 -0
- package/src/laravel/blade-helpers.js +320 -0
- package/src/laravel/vite-plugin.js +179 -0
- package/src/mobile/MobileDataRequestPage.jsx +233 -0
- package/src/mobile/components/MobileBox.jsx +71 -0
- package/src/mobile/components/MobileIndividualConnection.jsx +51 -0
- package/src/mobile/shims/browser-apis.js +78 -0
- package/src/mobile/shims/lucide-shim.js +85 -0
- package/src/nativeConnectors.js +5 -0
- package/src/newUI/EMAIL_VERIFICATION_API_SCHEMA.md +268 -0
- package/src/newUI/PlatformConnectorsStep.tsx +435 -0
- package/src/newUI/PrimaryButton.tsx +213 -0
- package/src/newUI/SignInStep.tsx +194 -0
- package/src/newUI/VerificationStep.tsx +133 -0
- package/src/newUI/WelcomeScreen.tsx +311 -0
- package/src/newUI/services/connectedAccountsService.js +129 -0
- package/src/onairos.capacitor.jsx +15 -0
- package/src/onairos.core.jsx +133 -0
- package/src/onairos.jsx +14 -0
- package/src/onairos.native.jsx +15 -0
- package/src/onairosButton.jsx +9000 -0
- package/src/overlay/CheckBox.jsx +114 -0
- package/src/overlay/IndividualConnection copy.js +86 -0
- package/src/overlay/IndividualConnection.js +191 -0
- package/src/overlay/IndividualConnectionNew.jsx +157 -0
- package/src/overlay/box.js +84 -0
- package/src/overlay/overlay.js +437 -0
- package/src/styles/onairos-scoped-preflight.css +97 -0
- package/src/styles/sdkCssRegistry.js +20 -0
- package/src/styles/styleLoaderInsertShadow.js +69 -0
- package/src/styles/tailwind.capacitor.css +395 -0
- package/src/styles/tailwind.css +395 -0
- package/src/theme/colors.js +40 -0
- package/src/utils/apiKeyValidation.js +341 -0
- package/src/utils/apiResponseLogger.js +316 -0
- package/src/utils/authHeaders.js +275 -0
- package/src/utils/biometrics.js +26 -0
- package/src/utils/bookmarkletUtils.js +28 -0
- package/src/utils/capacitorDetection.js +278 -0
- package/src/utils/capacitorLLMHelper.js +352 -0
- package/src/utils/capacitorPlugins.js +366 -0
- package/src/utils/crossDomainSSO.js +587 -0
- package/src/utils/deepLinking.js +27 -0
- package/src/utils/devLogger.js +46 -0
- package/src/utils/extensionDetection.js +418 -0
- package/src/utils/extractMemory.js +277 -0
- package/src/utils/framerBrandingOverrides.js +40 -0
- package/src/utils/googleWebClientId.js +55 -0
- package/src/utils/overlayHandler.js +224 -0
- package/src/utils/platformDisconnect.js +309 -0
- package/src/utils/pollTrainingStatus.js +200 -0
- package/src/utils/rawMemoriesAccess.js +211 -0
- package/src/utils/resolveBackendAppId.js +47 -0
- package/src/utils/responseFormatter.js +140 -0
- package/src/utils/sdkDebugStorage.js +113 -0
- package/src/utils/sdkInitialization.js +645 -0
- package/src/utils/sessionManager.js +1258 -0
- package/src/utils/startBackgroundTraining.js +100 -0
- package/src/utils/userDataFormatter.js +222 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onairos API Key Validation Utilities
|
|
3
|
+
* Implements standardized API key validation following SDK_API_KEY_VALIDATION.md
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// API Key Types
|
|
7
|
+
// NOTE: Admin keys are NOT supported in client SDK - use developer keys from dashboard.onairos.uk
|
|
8
|
+
export const ApiKeyType = {
|
|
9
|
+
DEVELOPER: 'developer',
|
|
10
|
+
INVALID: 'invalid'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Error Codes
|
|
14
|
+
export const ErrorCodes = {
|
|
15
|
+
MISSING_API_KEY: 'MISSING_API_KEY',
|
|
16
|
+
INVALID_API_KEY_FORMAT: 'INVALID_API_KEY_FORMAT',
|
|
17
|
+
INVALID_API_KEY: 'INVALID_API_KEY',
|
|
18
|
+
API_KEY_EXPIRED: 'API_KEY_EXPIRED',
|
|
19
|
+
DEVELOPER_NOT_FOUND: 'DEVELOPER_NOT_FOUND',
|
|
20
|
+
RATE_LIMIT_EXCEEDED: 'RATE_LIMIT_EXCEEDED',
|
|
21
|
+
INTERNAL_ERROR: 'INTERNAL_ERROR'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// API Endpoints
|
|
25
|
+
export const API_ENDPOINTS = {
|
|
26
|
+
production: 'https://api2.onairos.uk',
|
|
27
|
+
development: 'https://api2.onairos.uk'
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Detect environment based on context
|
|
32
|
+
* @returns {'production' | 'development'}
|
|
33
|
+
*/
|
|
34
|
+
export const detectEnvironment = () => {
|
|
35
|
+
if (typeof window !== 'undefined') {
|
|
36
|
+
// Browser environment
|
|
37
|
+
return window.location.hostname.includes('localhost') ? 'development' : 'production';
|
|
38
|
+
} else {
|
|
39
|
+
// Node.js/React Native environment
|
|
40
|
+
try {
|
|
41
|
+
const nodeEnv = (typeof process !== 'undefined' && process.env && process.env.NODE_ENV) || '';
|
|
42
|
+
return nodeEnv === 'development' ? 'development' : 'production';
|
|
43
|
+
} catch {
|
|
44
|
+
return 'production';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get API key type based on format
|
|
51
|
+
* @param {string} apiKey - API key to validate
|
|
52
|
+
* @returns {string} - API key type
|
|
53
|
+
*/
|
|
54
|
+
export const getApiKeyType = (apiKey) => {
|
|
55
|
+
if (!apiKey || typeof apiKey !== 'string') {
|
|
56
|
+
return ApiKeyType.INVALID;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Check developer key format (admin keys NOT supported in client SDK)
|
|
60
|
+
if (apiKey.length >= 32 && (
|
|
61
|
+
apiKey.startsWith('ona_') ||
|
|
62
|
+
apiKey.startsWith('dev_') ||
|
|
63
|
+
apiKey.startsWith('pk_')
|
|
64
|
+
)) {
|
|
65
|
+
return ApiKeyType.DEVELOPER;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return ApiKeyType.INVALID;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Check if API key is admin key
|
|
73
|
+
* @deprecated Admin keys are NOT supported in client SDK - always returns false
|
|
74
|
+
* @param {string} apiKey - API key to check
|
|
75
|
+
* @returns {boolean} Always returns false
|
|
76
|
+
*/
|
|
77
|
+
export const isAdminKey = (apiKey) => {
|
|
78
|
+
// Admin keys are NOT supported in client SDK
|
|
79
|
+
// All keys must be validated against the backend
|
|
80
|
+
return false;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Validate API key format
|
|
85
|
+
* @param {string} apiKey - API key to validate
|
|
86
|
+
* @returns {object} - Validation result
|
|
87
|
+
*/
|
|
88
|
+
export const validateApiKeyFormat = (apiKey) => {
|
|
89
|
+
if (!apiKey) {
|
|
90
|
+
return {
|
|
91
|
+
isValid: false,
|
|
92
|
+
error: 'API key is required',
|
|
93
|
+
code: ErrorCodes.MISSING_API_KEY,
|
|
94
|
+
keyType: ApiKeyType.INVALID
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const keyType = getApiKeyType(apiKey);
|
|
99
|
+
|
|
100
|
+
if (keyType === ApiKeyType.INVALID) {
|
|
101
|
+
return {
|
|
102
|
+
isValid: false,
|
|
103
|
+
error: 'Invalid API key format',
|
|
104
|
+
message: 'Developer keys must be at least 32 characters and start with \'dev_\', \'pk_\', or \'ona_\'',
|
|
105
|
+
code: ErrorCodes.INVALID_API_KEY_FORMAT,
|
|
106
|
+
keyType: ApiKeyType.INVALID
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
isValid: true,
|
|
112
|
+
keyType: keyType
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Validate API key with backend
|
|
118
|
+
* @param {string} apiKey - API key to validate
|
|
119
|
+
* @param {object} config - Configuration options
|
|
120
|
+
* @returns {Promise<object>} - Validation result
|
|
121
|
+
*/
|
|
122
|
+
export const validateApiKey = async (apiKey, config = {}) => {
|
|
123
|
+
const {
|
|
124
|
+
environment = detectEnvironment(),
|
|
125
|
+
timeout = 30000,
|
|
126
|
+
retryAttempts = 3,
|
|
127
|
+
platform = 'web',
|
|
128
|
+
sdkVersion = '3.4.0'
|
|
129
|
+
} = config;
|
|
130
|
+
|
|
131
|
+
// First validate format
|
|
132
|
+
const formatValidation = validateApiKeyFormat(apiKey);
|
|
133
|
+
if (!formatValidation.isValid) {
|
|
134
|
+
return formatValidation;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// All keys must be validated with backend (no local bypass)
|
|
138
|
+
// Validate with backend
|
|
139
|
+
const baseUrl = (() => {
|
|
140
|
+
try {
|
|
141
|
+
const override = typeof window !== 'undefined' && typeof window.onairosBaseUrl === 'string'
|
|
142
|
+
? window.onairosBaseUrl.trim().replace(/\/$/, '')
|
|
143
|
+
: '';
|
|
144
|
+
if (override) return override;
|
|
145
|
+
} catch (_) {}
|
|
146
|
+
return API_ENDPOINTS[environment] || API_ENDPOINTS.production;
|
|
147
|
+
})();
|
|
148
|
+
|
|
149
|
+
for (let attempt = 1; attempt <= retryAttempts; attempt++) {
|
|
150
|
+
try {
|
|
151
|
+
const controller = new AbortController();
|
|
152
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
153
|
+
|
|
154
|
+
const response = await fetch(`${baseUrl}/dev/validate-apikey`, {
|
|
155
|
+
method: 'POST',
|
|
156
|
+
headers: {
|
|
157
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
158
|
+
'Content-Type': 'application/json',
|
|
159
|
+
'X-SDK-Platform': platform,
|
|
160
|
+
'User-Agent': `OnairosSDK/${sdkVersion}`
|
|
161
|
+
},
|
|
162
|
+
body: JSON.stringify({
|
|
163
|
+
environment,
|
|
164
|
+
sdk_version: sdkVersion,
|
|
165
|
+
platform,
|
|
166
|
+
keyType: formatValidation.keyType,
|
|
167
|
+
timestamp: new Date().toISOString(),
|
|
168
|
+
attempt
|
|
169
|
+
}),
|
|
170
|
+
signal: controller.signal
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
clearTimeout(timeoutId);
|
|
174
|
+
|
|
175
|
+
const data = await response.json();
|
|
176
|
+
|
|
177
|
+
if (response.ok && (data.success || data.valid)) {
|
|
178
|
+
return {
|
|
179
|
+
isValid: true,
|
|
180
|
+
success: true,
|
|
181
|
+
permissions: data.permissions || [],
|
|
182
|
+
rateLimits: data.rateLimits || { remaining: 100, resetTime: Date.now() + 15 * 60 * 1000 },
|
|
183
|
+
keyType: data.keyType || ApiKeyType.DEVELOPER,
|
|
184
|
+
developer: data.developer,
|
|
185
|
+
apiKey: data.apiKey
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Don't retry client errors (4xx)
|
|
190
|
+
if (response.status >= 400 && response.status < 500) {
|
|
191
|
+
return {
|
|
192
|
+
isValid: false,
|
|
193
|
+
success: false,
|
|
194
|
+
error: data.error || 'Client error',
|
|
195
|
+
message: data.message,
|
|
196
|
+
code: data.code || ErrorCodes.INVALID_API_KEY,
|
|
197
|
+
keyType: data.keyType || ApiKeyType.INVALID
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Retry server errors (5xx)
|
|
202
|
+
if (attempt === retryAttempts) {
|
|
203
|
+
return {
|
|
204
|
+
isValid: false,
|
|
205
|
+
success: false,
|
|
206
|
+
error: 'Server error after maximum retries',
|
|
207
|
+
message: `Failed after ${retryAttempts} attempts`,
|
|
208
|
+
code: ErrorCodes.INTERNAL_ERROR,
|
|
209
|
+
keyType: ApiKeyType.INVALID
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
} catch (error) {
|
|
214
|
+
if (error.name === 'AbortError') {
|
|
215
|
+
if (attempt === retryAttempts) {
|
|
216
|
+
return {
|
|
217
|
+
isValid: false,
|
|
218
|
+
success: false,
|
|
219
|
+
error: 'Request timeout',
|
|
220
|
+
message: `Request timed out after ${timeout}ms`,
|
|
221
|
+
code: ErrorCodes.INTERNAL_ERROR,
|
|
222
|
+
keyType: ApiKeyType.INVALID
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
} else if (attempt === retryAttempts) {
|
|
226
|
+
return {
|
|
227
|
+
isValid: false,
|
|
228
|
+
success: false,
|
|
229
|
+
error: 'Network error',
|
|
230
|
+
message: error.message,
|
|
231
|
+
code: ErrorCodes.INTERNAL_ERROR,
|
|
232
|
+
keyType: ApiKeyType.INVALID
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Exponential backoff
|
|
237
|
+
const delay = Math.min(1000 * Math.pow(2, attempt - 1), 5000);
|
|
238
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
isValid: false,
|
|
244
|
+
success: false,
|
|
245
|
+
error: 'Validation failed',
|
|
246
|
+
code: ErrorCodes.INTERNAL_ERROR,
|
|
247
|
+
keyType: ApiKeyType.INVALID
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get error message for error code
|
|
253
|
+
* @param {string} code - Error code
|
|
254
|
+
* @param {object} details - Additional error details
|
|
255
|
+
* @returns {object} - Error information
|
|
256
|
+
*/
|
|
257
|
+
export const getErrorInfo = (code, details = {}) => {
|
|
258
|
+
const errorMap = {
|
|
259
|
+
[ErrorCodes.MISSING_API_KEY]: {
|
|
260
|
+
title: 'API Key Required',
|
|
261
|
+
message: 'No API key provided',
|
|
262
|
+
suggestions: [
|
|
263
|
+
'Provide API key in the configuration',
|
|
264
|
+
'Get API key from Onairos Dashboard',
|
|
265
|
+
'Format: ona_your_api_key_here'
|
|
266
|
+
]
|
|
267
|
+
},
|
|
268
|
+
[ErrorCodes.INVALID_API_KEY_FORMAT]: {
|
|
269
|
+
title: 'Invalid API Key Format',
|
|
270
|
+
message: 'API key format is incorrect',
|
|
271
|
+
suggestions: [
|
|
272
|
+
'Check key format (32+ characters)',
|
|
273
|
+
'Ensure it starts with ona_, dev_, or pk_',
|
|
274
|
+
'Generate new API key if needed'
|
|
275
|
+
]
|
|
276
|
+
},
|
|
277
|
+
[ErrorCodes.INVALID_API_KEY]: {
|
|
278
|
+
title: 'Invalid API Key',
|
|
279
|
+
message: 'API key not found or inactive',
|
|
280
|
+
suggestions: [
|
|
281
|
+
'Verify API key is correct',
|
|
282
|
+
'Check if key has been revoked',
|
|
283
|
+
'Generate new API key'
|
|
284
|
+
]
|
|
285
|
+
},
|
|
286
|
+
[ErrorCodes.API_KEY_EXPIRED]: {
|
|
287
|
+
title: 'API Key Expired',
|
|
288
|
+
message: 'API key has expired',
|
|
289
|
+
suggestions: [
|
|
290
|
+
'Renew API key',
|
|
291
|
+
'Generate new API key',
|
|
292
|
+
'Check expiry settings'
|
|
293
|
+
]
|
|
294
|
+
},
|
|
295
|
+
[ErrorCodes.DEVELOPER_NOT_FOUND]: {
|
|
296
|
+
title: 'Developer Account Inactive',
|
|
297
|
+
message: 'Developer account not found or inactive',
|
|
298
|
+
suggestions: [
|
|
299
|
+
'Contact support',
|
|
300
|
+
'Verify account status',
|
|
301
|
+
'Check developer dashboard'
|
|
302
|
+
]
|
|
303
|
+
},
|
|
304
|
+
[ErrorCodes.RATE_LIMIT_EXCEEDED]: {
|
|
305
|
+
title: 'Rate Limit Exceeded',
|
|
306
|
+
message: 'Too many requests',
|
|
307
|
+
suggestions: [
|
|
308
|
+
'Wait before retrying',
|
|
309
|
+
'Check rate limits',
|
|
310
|
+
'Upgrade plan if needed'
|
|
311
|
+
]
|
|
312
|
+
},
|
|
313
|
+
[ErrorCodes.INTERNAL_ERROR]: {
|
|
314
|
+
title: 'Internal Error',
|
|
315
|
+
message: 'Server error occurred',
|
|
316
|
+
suggestions: [
|
|
317
|
+
'Retry with exponential backoff',
|
|
318
|
+
'Check service status',
|
|
319
|
+
'Contact support if persists'
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
return errorMap[code] || {
|
|
325
|
+
title: 'Unknown Error',
|
|
326
|
+
message: 'An unknown error occurred',
|
|
327
|
+
suggestions: ['Contact support']
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
export default {
|
|
332
|
+
ApiKeyType,
|
|
333
|
+
ErrorCodes,
|
|
334
|
+
API_ENDPOINTS,
|
|
335
|
+
detectEnvironment,
|
|
336
|
+
getApiKeyType,
|
|
337
|
+
isAdminKey,
|
|
338
|
+
validateApiKeyFormat,
|
|
339
|
+
validateApiKey,
|
|
340
|
+
getErrorInfo
|
|
341
|
+
};
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onairos API Response Logger
|
|
3
|
+
*
|
|
4
|
+
* Provides detailed, formatted logging for Onairos API responses
|
|
5
|
+
* with visual indicators, explanatory labels, and formatted tables.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { logOnairosResponse } from '../utils/apiResponseLogger';
|
|
9
|
+
* logOnairosResponse(apiData, endpointUrl, { detailed: true, showRawData: false });
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Content category names for the 16 output scores
|
|
13
|
+
const CONTENT_CATEGORIES = [
|
|
14
|
+
'Technology & Innovation',
|
|
15
|
+
'Entertainment & Media',
|
|
16
|
+
'Health & Wellness',
|
|
17
|
+
'Education & Learning',
|
|
18
|
+
'Finance & Business',
|
|
19
|
+
'Travel & Adventure',
|
|
20
|
+
'Food & Cooking',
|
|
21
|
+
'Sports & Fitness',
|
|
22
|
+
'Arts & Culture',
|
|
23
|
+
'Science & Nature',
|
|
24
|
+
'Fashion & Style',
|
|
25
|
+
'Gaming & Esports',
|
|
26
|
+
'Social & Relationships',
|
|
27
|
+
'Politics & News',
|
|
28
|
+
'DIY & Crafts',
|
|
29
|
+
'Music & Audio'
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get emoji and level label based on score
|
|
34
|
+
* @param {number} score - Score value (0-1 for content prefs, 0-100 for traits)
|
|
35
|
+
* @param {boolean} isPercentage - Whether score is 0-100 scale
|
|
36
|
+
* @returns {{emoji: string, level: string}}
|
|
37
|
+
*/
|
|
38
|
+
function getScoreIndicator(score, isPercentage = false) {
|
|
39
|
+
const normalizedScore = isPercentage ? score / 100 : score;
|
|
40
|
+
|
|
41
|
+
if (normalizedScore >= 0.8) return { emoji: '🔥', level: isPercentage ? 'Exceptional' : 'Very High' };
|
|
42
|
+
if (normalizedScore >= 0.6) return { emoji: '⭐', level: isPercentage ? 'Strong' : 'High' };
|
|
43
|
+
if (normalizedScore >= 0.4) return { emoji: '👍', level: isPercentage ? 'Moderate' : 'Moderate' };
|
|
44
|
+
if (normalizedScore >= 0.2) return { emoji: '📊', level: isPercentage ? 'Developing' : 'Low' };
|
|
45
|
+
return { emoji: '📉', level: isPercentage ? 'Low Priority' : 'Very Low' };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Create visual progress bar
|
|
50
|
+
* @param {number} score - Score value (0-1 for content prefs, 0-100 for traits)
|
|
51
|
+
* @param {boolean} isPercentage - Whether score is 0-100 scale
|
|
52
|
+
* @returns {string} Visual bar representation
|
|
53
|
+
*/
|
|
54
|
+
function createProgressBar(score, isPercentage = false) {
|
|
55
|
+
const normalizedScore = isPercentage ? score / 100 : score;
|
|
56
|
+
// Clamp score between 0 and 1 safely
|
|
57
|
+
const clampedScore = Math.max(0, Math.min(1, normalizedScore));
|
|
58
|
+
const filledBlocks = Math.round(clampedScore * 10);
|
|
59
|
+
const emptyBlocks = 10 - filledBlocks;
|
|
60
|
+
return '█'.repeat(filledBlocks) + '░'.repeat(emptyBlocks);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Log content preference scores with visual formatting
|
|
65
|
+
* @param {Array<Array<number>>} output - 2D array of scores [[0.95], [0.89], ...]
|
|
66
|
+
*/
|
|
67
|
+
function logContentPreferences(output) {
|
|
68
|
+
if (!output || !Array.isArray(output) || output.length === 0) {
|
|
69
|
+
console.log(' ⚠️ No content preferences found');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
console.log(' 🎯 Content Preferences');
|
|
74
|
+
console.log(' 📊 Content Preference Scores (0.0 = Not Interested, 1.0 = Highly Interested)');
|
|
75
|
+
console.log(' ─────────────────────────────────────────────────────────────────────');
|
|
76
|
+
console.log('');
|
|
77
|
+
console.log(' Category Score Visual Interest Level');
|
|
78
|
+
console.log(' ──────────────────────────────────────────────────────────────────────');
|
|
79
|
+
|
|
80
|
+
const scores = output.map((item, index) => {
|
|
81
|
+
const score = Array.isArray(item) ? item[0] : item;
|
|
82
|
+
const category = CONTENT_CATEGORIES[index] || `Category ${index + 1}`;
|
|
83
|
+
const indicator = getScoreIndicator(score);
|
|
84
|
+
const bar = createProgressBar(score);
|
|
85
|
+
|
|
86
|
+
console.log(` ${category.padEnd(28)} ${score.toFixed(3)} ${bar} ${indicator.emoji} ${indicator.level}`);
|
|
87
|
+
|
|
88
|
+
return { category, score };
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Summary statistics
|
|
92
|
+
const avg = scores.reduce((sum, s) => sum + s.score, 0) / scores.length;
|
|
93
|
+
const max = Math.max(...scores.map(s => s.score));
|
|
94
|
+
const min = Math.min(...scores.map(s => s.score));
|
|
95
|
+
const maxCategory = scores.find(s => s.score === max)?.category;
|
|
96
|
+
|
|
97
|
+
console.log('');
|
|
98
|
+
console.log(` 📈 Summary: Avg ${avg.toFixed(3)} | Max ${max.toFixed(3)} (${maxCategory}) | Min ${min.toFixed(3)}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Log personality traits with visual formatting
|
|
103
|
+
* @param {Object} personalityTraits - Personality traits object with positive_traits and traits_to_improve
|
|
104
|
+
*/
|
|
105
|
+
function logPersonalityTraits(personalityTraits) {
|
|
106
|
+
if (!personalityTraits || typeof personalityTraits !== 'object') {
|
|
107
|
+
console.log(' ⚠️ No personality traits found');
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
console.log(' 🧠 Personality Analysis');
|
|
112
|
+
|
|
113
|
+
// Positive traits (strengths)
|
|
114
|
+
if (personalityTraits.positive_traits) {
|
|
115
|
+
console.log(' ✨ Positive Traits (Strengths) - Scale: 0-100');
|
|
116
|
+
console.log(' ─────────────────────────────────────────────────────────────────────');
|
|
117
|
+
console.log('');
|
|
118
|
+
console.log(' Trait Score Visual Level');
|
|
119
|
+
console.log(' ──────────────────────────────────────────────────────────────────────');
|
|
120
|
+
|
|
121
|
+
Object.entries(personalityTraits.positive_traits).forEach(([trait, score]) => {
|
|
122
|
+
const indicator = getScoreIndicator(score, true);
|
|
123
|
+
const bar = createProgressBar(score, true);
|
|
124
|
+
const traitName = trait.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ');
|
|
125
|
+
|
|
126
|
+
console.log(` ${traitName.padEnd(22)} ${score.toFixed(1).padStart(5)} ${bar} ${indicator.emoji} ${indicator.level}`);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
console.log('');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Traits to improve (growth areas)
|
|
133
|
+
if (personalityTraits.traits_to_improve) {
|
|
134
|
+
console.log(' 🎯 Traits to Improve (Growth Areas) - Scale: 0-100');
|
|
135
|
+
console.log(' ─────────────────────────────────────────────────────────────────────');
|
|
136
|
+
console.log('');
|
|
137
|
+
console.log(' Trait Score Visual Priority');
|
|
138
|
+
console.log(' ──────────────────────────────────────────────────────────────────────');
|
|
139
|
+
|
|
140
|
+
Object.entries(personalityTraits.traits_to_improve).forEach(([trait, score]) => {
|
|
141
|
+
const indicator = getScoreIndicator(score, true);
|
|
142
|
+
const bar = createProgressBar(score, true);
|
|
143
|
+
const traitName = trait.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ');
|
|
144
|
+
const priority = score < 40 ? 'Low Priority' : score < 60 ? 'Medium Priority' : 'High Priority';
|
|
145
|
+
|
|
146
|
+
console.log(` ${traitName.padEnd(22)} ${score.toFixed(1).padStart(5)} ${bar} ${indicator.emoji} ${priority}`);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
console.log('');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Log Onairos API response with detailed formatting
|
|
155
|
+
* @param {Object} response - API response object
|
|
156
|
+
* @param {string} endpoint - API endpoint URL
|
|
157
|
+
* @param {Object} options - Logging options { detailed: boolean, showRawData: boolean }
|
|
158
|
+
*/
|
|
159
|
+
export function logOnairosResponse(response, endpoint = 'Unknown', options = {}) {
|
|
160
|
+
const { detailed = true, showRawData = false } = options;
|
|
161
|
+
|
|
162
|
+
console.log('\n🎯 Onairos API Response');
|
|
163
|
+
console.log(` 📡 Endpoint: ${endpoint}`);
|
|
164
|
+
console.log(` ⏰ Timestamp: ${new Date().toISOString()}`);
|
|
165
|
+
console.log(' ═══════════════════════════════════════════════════════════════════════');
|
|
166
|
+
console.log('');
|
|
167
|
+
|
|
168
|
+
if (!response) {
|
|
169
|
+
console.log(' ⚠️ Empty response');
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Log inference results in a proper table format using console.table for better readability
|
|
174
|
+
if (response.InferenceResult) {
|
|
175
|
+
console.group(' 📊 Inference Result');
|
|
176
|
+
|
|
177
|
+
// Content preferences
|
|
178
|
+
if (response.InferenceResult.output && Array.isArray(response.InferenceResult.output) && response.InferenceResult.output.length > 0) {
|
|
179
|
+
console.log(' 🎯 Content Preferences (Scale: 0.0 - 1.0)');
|
|
180
|
+
|
|
181
|
+
const contentTableData = response.InferenceResult.output.map((item, index) => {
|
|
182
|
+
const score = Array.isArray(item) ? item[0] : item;
|
|
183
|
+
const indicator = getScoreIndicator(score);
|
|
184
|
+
return {
|
|
185
|
+
Category: CONTENT_CATEGORIES[index] || `Category ${index + 1}`,
|
|
186
|
+
Score: score.toFixed(3),
|
|
187
|
+
Level: `${indicator.emoji} ${indicator.level}`
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
console.table(contentTableData);
|
|
192
|
+
|
|
193
|
+
// Summary statistics
|
|
194
|
+
const scores = response.InferenceResult.output.map(item => Array.isArray(item) ? item[0] : item);
|
|
195
|
+
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
196
|
+
const max = Math.max(...scores);
|
|
197
|
+
const min = Math.min(...scores);
|
|
198
|
+
const maxIndex = scores.indexOf(max);
|
|
199
|
+
const maxCategory = CONTENT_CATEGORIES[maxIndex] || `Category ${maxIndex + 1}`;
|
|
200
|
+
|
|
201
|
+
console.log(` 📈 Summary: Avg ${avg.toFixed(3)} | Max ${max.toFixed(3)} (${maxCategory}) | Min ${min.toFixed(3)}`);
|
|
202
|
+
console.log('');
|
|
203
|
+
} else {
|
|
204
|
+
console.log(' ⚠️ No content preferences output found');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Personality traits
|
|
208
|
+
if (response.InferenceResult.traits?.personality_traits) {
|
|
209
|
+
console.log(' 🧠 Personality Analysis (Scale: 0 - 100)');
|
|
210
|
+
|
|
211
|
+
const traits = response.InferenceResult.traits.personality_traits;
|
|
212
|
+
const traitsTableData = [];
|
|
213
|
+
|
|
214
|
+
// Add Positive Traits
|
|
215
|
+
if (traits.positive_traits) {
|
|
216
|
+
Object.entries(traits.positive_traits).forEach(([trait, score]) => {
|
|
217
|
+
const indicator = getScoreIndicator(score, true);
|
|
218
|
+
const traitName = trait.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ');
|
|
219
|
+
traitsTableData.push({
|
|
220
|
+
Type: 'Strength ✨',
|
|
221
|
+
Trait: traitName,
|
|
222
|
+
Score: score.toFixed(1),
|
|
223
|
+
Level: `${indicator.emoji} ${indicator.level}`
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Add Traits to Improve
|
|
229
|
+
if (traits.traits_to_improve) {
|
|
230
|
+
Object.entries(traits.traits_to_improve).forEach(([trait, score]) => {
|
|
231
|
+
const indicator = getScoreIndicator(score, true);
|
|
232
|
+
const traitName = trait.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ');
|
|
233
|
+
// For improvement areas, lower score often means higher priority to fix, but here we just show level
|
|
234
|
+
// Adjust logic if "Level" column needs to say "Priority"
|
|
235
|
+
const priority = score < 40 ? 'High Priority' : score < 60 ? 'Medium Priority' : 'Low Priority';
|
|
236
|
+
|
|
237
|
+
traitsTableData.push({
|
|
238
|
+
Type: 'Growth Area 🎯',
|
|
239
|
+
Trait: traitName,
|
|
240
|
+
Score: score.toFixed(1),
|
|
241
|
+
Level: `${indicator.emoji} ${priority}`
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (traitsTableData.length > 0) {
|
|
247
|
+
console.table(traitsTableData);
|
|
248
|
+
} else {
|
|
249
|
+
console.log(' ⚠️ No personality traits data found');
|
|
250
|
+
}
|
|
251
|
+
console.log('');
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
console.groupEnd();
|
|
255
|
+
console.log('');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Log persona information (if present)
|
|
259
|
+
if (response.persona) {
|
|
260
|
+
console.log(' 🎭 Persona Information');
|
|
261
|
+
console.log(` ID: ${response.persona.id}`);
|
|
262
|
+
console.log(` Name: ${response.persona.name}`);
|
|
263
|
+
if (response.persona.description) {
|
|
264
|
+
console.log(` Description: ${response.persona.description}`);
|
|
265
|
+
}
|
|
266
|
+
console.log('');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Log inference metadata (if present)
|
|
270
|
+
if (response.inference_metadata) {
|
|
271
|
+
console.log(' ℹ️ Inference Metadata');
|
|
272
|
+
console.log(` Model Size: ${response.inference_metadata.size_used || 'N/A'}`);
|
|
273
|
+
console.log(` Total Outputs: ${response.inference_metadata.total_outputs || 'N/A'}`);
|
|
274
|
+
if (response.inference_metadata.persona_applied) {
|
|
275
|
+
console.log(` Persona Applied: ${response.inference_metadata.persona_applied}`);
|
|
276
|
+
}
|
|
277
|
+
console.log('');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Log LLM data summary (if present)
|
|
281
|
+
if (response.llmData) {
|
|
282
|
+
console.log(' 💬 LLM Data');
|
|
283
|
+
console.log(` Has LLM Data: ${response.llmData.hasLlmData || false}`);
|
|
284
|
+
console.log(` Total Interactions: ${response.llmData.totalInteractions || 0}`);
|
|
285
|
+
if (response.llmData.platforms) {
|
|
286
|
+
const platforms = Object.keys(response.llmData.platforms).filter(k => response.llmData.platforms[k]);
|
|
287
|
+
console.log(` Platforms: ${platforms.join(', ') || 'None'}`);
|
|
288
|
+
}
|
|
289
|
+
console.log('');
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Show raw data if requested
|
|
293
|
+
if (showRawData) {
|
|
294
|
+
console.log(' 📄 Raw Response Data:');
|
|
295
|
+
console.log(JSON.stringify(response, null, 2));
|
|
296
|
+
console.log('');
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
console.log(' ✅ Response logging complete');
|
|
300
|
+
console.log(' ═══════════════════════════════════════════════════════════════════════\n');
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Simple one-line logging for API responses
|
|
305
|
+
* @param {Object} response - API response object
|
|
306
|
+
* @param {string} endpoint - API endpoint URL
|
|
307
|
+
*/
|
|
308
|
+
export function logOnairosResponseSimple(response, endpoint = 'Unknown') {
|
|
309
|
+
const contentCount = response?.InferenceResult?.output?.length || 0;
|
|
310
|
+
const hasTraits = !!(response?.InferenceResult?.traits?.personality_traits);
|
|
311
|
+
const hasLlm = !!(response?.llmData?.hasLlmData);
|
|
312
|
+
|
|
313
|
+
console.log(`🎯 Onairos Response [${endpoint}]: ${contentCount} content scores, Traits: ${hasTraits}, LLM: ${hasLlm}`);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export default { logOnairosResponse, logOnairosResponseSimple };
|