@robosystems/core 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.
- package/LICENSE +21 -0
- package/README.md +252 -0
- package/actions/entity-actions.d.ts +8 -0
- package/actions/entity-actions.js +16 -0
- package/actions/graph-actions.d.ts +3 -0
- package/actions/graph-actions.js +13 -0
- package/auth-components/AppSwitcher.d.ts +6 -0
- package/auth-components/AppSwitcher.js +28 -0
- package/auth-components/AuthGuard.d.ts +7 -0
- package/auth-components/AuthGuard.js +31 -0
- package/auth-components/AuthProvider.d.ts +9 -0
- package/auth-components/AuthProvider.js +565 -0
- package/auth-components/SessionWarningDialog.d.ts +1 -0
- package/auth-components/SessionWarningDialog.js +51 -0
- package/auth-components/SignInForm.d.ts +20 -0
- package/auth-components/SignInForm.js +139 -0
- package/auth-components/SignUpForm.d.ts +15 -0
- package/auth-components/SignUpForm.js +167 -0
- package/auth-components/TurnstileWidget.d.ts +99 -0
- package/auth-components/TurnstileWidget.js +224 -0
- package/auth-components/index.d.ts +6 -0
- package/auth-components/index.js +6 -0
- package/auth-core/cleanup.d.ts +44 -0
- package/auth-core/cleanup.js +157 -0
- package/auth-core/client.d.ts +121 -0
- package/auth-core/client.js +767 -0
- package/auth-core/config.d.ts +19 -0
- package/auth-core/config.js +56 -0
- package/auth-core/hooks.d.ts +19 -0
- package/auth-core/hooks.js +63 -0
- package/auth-core/index.d.ts +6 -0
- package/auth-core/index.js +6 -0
- package/auth-core/sso.d.ts +42 -0
- package/auth-core/sso.js +281 -0
- package/auth-core/token-storage.d.ts +58 -0
- package/auth-core/token-storage.js +177 -0
- package/auth-core/types.d.ts +145 -0
- package/auth-core/types.js +1 -0
- package/components/EntitySelector.d.ts +44 -0
- package/components/EntitySelector.js +64 -0
- package/components/EntitySelectorCore.d.ts +45 -0
- package/components/EntitySelectorCore.js +67 -0
- package/components/GraphSelectorCore.d.ts +21 -0
- package/components/GraphSelectorCore.js +39 -0
- package/components/PageLayout.d.ts +8 -0
- package/components/PageLayout.js +5 -0
- package/components/RepositoryGuard.d.ts +68 -0
- package/components/RepositoryGuard.js +91 -0
- package/components/console/ConsoleContent.d.ts +4 -0
- package/components/console/ConsoleContent.js +612 -0
- package/components/console/ConsoleMarkdown.d.ts +11 -0
- package/components/console/ConsoleMarkdown.js +49 -0
- package/components/console/ProgressiveText.d.ts +6 -0
- package/components/console/ProgressiveText.js +21 -0
- package/components/console/graphAwareConfig.d.ts +70 -0
- package/components/console/graphAwareConfig.js +411 -0
- package/components/console/index.d.ts +6 -0
- package/components/console/index.js +4 -0
- package/components/console/types.d.ts +84 -0
- package/components/console/types.js +1 -0
- package/components/graph-filters.d.ts +75 -0
- package/components/graph-filters.js +111 -0
- package/components/index.d.ts +10 -0
- package/components/index.js +9 -0
- package/components/repositories/ActiveSubscriptions.d.ts +26 -0
- package/components/repositories/ActiveSubscriptions.js +103 -0
- package/components/repositories/BrowseRepositories.d.ts +11 -0
- package/components/repositories/BrowseRepositories.js +184 -0
- package/components/repositories/index.d.ts +2 -0
- package/components/repositories/index.js +2 -0
- package/components/search/SearchContent.d.ts +4 -0
- package/components/search/SearchContent.js +168 -0
- package/components/search/index.d.ts +2 -0
- package/components/search/index.js +1 -0
- package/components/search/types.d.ts +15 -0
- package/components/search/types.js +1 -0
- package/contexts/entity-context.d.ts +28 -0
- package/contexts/entity-context.js +89 -0
- package/contexts/graph-context.d.ts +27 -0
- package/contexts/graph-context.js +128 -0
- package/contexts/index.d.ts +5 -0
- package/contexts/index.js +5 -0
- package/contexts/org-context.d.ts +25 -0
- package/contexts/org-context.js +64 -0
- package/contexts/service-offerings-context.d.ts +45 -0
- package/contexts/service-offerings-context.js +98 -0
- package/contexts/sidebar-context.d.ts +18 -0
- package/contexts/sidebar-context.js +44 -0
- package/hooks/index.d.ts +6 -0
- package/hooks/index.js +6 -0
- package/hooks/use-api-error.d.ts +3 -0
- package/hooks/use-api-error.js +24 -0
- package/hooks/use-media-query.d.ts +1 -0
- package/hooks/use-media-query.js +21 -0
- package/hooks/use-streaming-query.d.ts +22 -0
- package/hooks/use-streaming-query.js +142 -0
- package/hooks/use-toast.d.ts +37 -0
- package/hooks/use-toast.js +117 -0
- package/hooks/use-user-limits.d.ts +12 -0
- package/hooks/use-user-limits.js +73 -0
- package/hooks/use-user.d.ts +11 -0
- package/hooks/use-user.js +39 -0
- package/index.d.ts +29 -0
- package/index.js +77 -0
- package/lib/entity-cookie.d.ts +10 -0
- package/lib/entity-cookie.js +38 -0
- package/lib/graph-cookie.d.ts +11 -0
- package/lib/graph-cookie.js +62 -0
- package/lib/graph-tiers.d.ts +41 -0
- package/lib/graph-tiers.js +107 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/sidebar-cookie.d.ts +11 -0
- package/lib/sidebar-cookie.js +42 -0
- package/library/colors.d.ts +4 -0
- package/library/colors.js +41 -0
- package/library/components/ClassificationPicker.d.ts +8 -0
- package/library/components/ClassificationPicker.js +55 -0
- package/library/components/ElementBrowser.d.ts +11 -0
- package/library/components/ElementBrowser.js +106 -0
- package/library/components/ElementDetail.d.ts +7 -0
- package/library/components/ElementDetail.js +97 -0
- package/library/components/LibraryHierarchy.d.ts +13 -0
- package/library/components/LibraryHierarchy.js +380 -0
- package/library/components/TaxonomySidebar.d.ts +6 -0
- package/library/components/TaxonomySidebar.js +45 -0
- package/library/index.d.ts +8 -0
- package/library/index.js +7 -0
- package/package.json +37 -0
- package/research/CoverageCard.d.ts +12 -0
- package/research/CoverageCard.js +15 -0
- package/research/CoverageGrid.d.ts +6 -0
- package/research/CoverageGrid.js +9 -0
- package/research/CoverageHistory.d.ts +5 -0
- package/research/CoverageHistory.js +7 -0
- package/research/ResearchArticle.d.ts +15 -0
- package/research/ResearchArticle.js +26 -0
- package/research/catalog.d.ts +14 -0
- package/research/catalog.js +42 -0
- package/research/index.d.ts +6 -0
- package/research/index.js +9 -0
- package/research/types.d.ts +38 -0
- package/research/types.js +4 -0
- package/task-monitoring/hooks.d.ts +26 -0
- package/task-monitoring/hooks.js +126 -0
- package/task-monitoring/index.d.ts +5 -0
- package/task-monitoring/index.js +7 -0
- package/task-monitoring/operationErrors.d.ts +82 -0
- package/task-monitoring/operationErrors.js +251 -0
- package/task-monitoring/operationHooks.d.ts +117 -0
- package/task-monitoring/operationHooks.js +536 -0
- package/task-monitoring/operationMonitor.d.ts +78 -0
- package/task-monitoring/operationMonitor.js +200 -0
- package/task-monitoring/operationTypes.d.ts +236 -0
- package/task-monitoring/operationTypes.js +60 -0
- package/task-monitoring/taskMonitor.d.ts +14 -0
- package/task-monitoring/taskMonitor.js +132 -0
- package/task-monitoring/types.d.ts +31 -0
- package/task-monitoring/types.js +1 -0
- package/theme/flowbite-theme.d.ts +758 -0
- package/theme/flowbite-theme.js +765 -0
- package/theme/index.d.ts +1 -0
- package/theme/index.js +1 -0
- package/types/entity.d.ts +19 -0
- package/types/index.d.ts +2 -0
- package/types/index.js +1 -0
- package/types/user.d.ts +6 -0
- package/ui-components/ConfirmModal.d.ts +41 -0
- package/ui-components/ConfirmModal.js +19 -0
- package/ui-components/EmptyState.d.ts +22 -0
- package/ui-components/EmptyState.js +10 -0
- package/ui-components/LoadingState.d.ts +27 -0
- package/ui-components/LoadingState.js +12 -0
- package/ui-components/Logo.d.ts +28 -0
- package/ui-components/Logo.js +95 -0
- package/ui-components/Spinner.d.ts +37 -0
- package/ui-components/Spinner.js +48 -0
- package/ui-components/StatCard.d.ts +21 -0
- package/ui-components/StatCard.js +10 -0
- package/ui-components/api-keys/ApiKeyDisplay.d.ts +13 -0
- package/ui-components/api-keys/ApiKeyDisplay.js +7 -0
- package/ui-components/api-keys/ApiKeyTable.d.ts +9 -0
- package/ui-components/api-keys/ApiKeyTable.js +17 -0
- package/ui-components/api-keys/ApiKeysCard.d.ts +6 -0
- package/ui-components/api-keys/ApiKeysCard.js +97 -0
- package/ui-components/api-keys/CreateApiKeyModal.d.ts +11 -0
- package/ui-components/api-keys/CreateApiKeyModal.js +47 -0
- package/ui-components/api-keys/SecureApiKeyField.d.ts +13 -0
- package/ui-components/api-keys/SecureApiKeyField.js +64 -0
- package/ui-components/api-keys/index.d.ts +5 -0
- package/ui-components/api-keys/index.js +5 -0
- package/ui-components/chat/ChatHeader.d.ts +12 -0
- package/ui-components/chat/ChatHeader.js +5 -0
- package/ui-components/chat/ChatInputArea.d.ts +16 -0
- package/ui-components/chat/ChatInputArea.js +9 -0
- package/ui-components/chat/ChatMessage.d.ts +7 -0
- package/ui-components/chat/ChatMessage.js +24 -0
- package/ui-components/chat/DeepResearchToggle.d.ts +8 -0
- package/ui-components/chat/DeepResearchToggle.js +13 -0
- package/ui-components/chat/index.d.ts +9 -0
- package/ui-components/chat/index.js +8 -0
- package/ui-components/chat/types.d.ts +23 -0
- package/ui-components/chat/types.js +51 -0
- package/ui-components/forms/PasswordRequirements.d.ts +10 -0
- package/ui-components/forms/PasswordRequirements.js +15 -0
- package/ui-components/forms/SettingsCard.d.ts +11 -0
- package/ui-components/forms/SettingsCard.js +5 -0
- package/ui-components/forms/SettingsFormField.d.ts +18 -0
- package/ui-components/forms/SettingsFormField.js +17 -0
- package/ui-components/forms/StatusAlert.d.ts +8 -0
- package/ui-components/forms/StatusAlert.js +7 -0
- package/ui-components/forms/index.d.ts +4 -0
- package/ui-components/forms/index.js +4 -0
- package/ui-components/index.d.ts +13 -0
- package/ui-components/index.js +18 -0
- package/ui-components/layout/CoreNavbar.d.ts +14 -0
- package/ui-components/layout/CoreNavbar.js +53 -0
- package/ui-components/layout/CoreSidebar.d.ts +28 -0
- package/ui-components/layout/CoreSidebar.js +62 -0
- package/ui-components/layout/LandingFooter.d.ts +28 -0
- package/ui-components/layout/LandingFooter.js +34 -0
- package/ui-components/layout/PageContainer.d.ts +8 -0
- package/ui-components/layout/PageContainer.js +17 -0
- package/ui-components/layout/PageHeader.d.ts +23 -0
- package/ui-components/layout/PageHeader.js +12 -0
- package/ui-components/layout/SettingsContainer.d.ts +10 -0
- package/ui-components/layout/SettingsContainer.js +9 -0
- package/ui-components/layout/ThemeToggle.d.ts +4 -0
- package/ui-components/layout/ThemeToggle.js +6 -0
- package/ui-components/layout/index.d.ts +7 -0
- package/ui-components/layout/index.js +7 -0
- package/ui-components/settings/GeneralInformationCard.d.ts +12 -0
- package/ui-components/settings/GeneralInformationCard.js +72 -0
- package/ui-components/settings/PasswordInformationCard.d.ts +10 -0
- package/ui-components/settings/PasswordInformationCard.js +167 -0
- package/ui-components/settings/SettingsPageHeader.d.ts +7 -0
- package/ui-components/settings/SettingsPageHeader.js +6 -0
- package/ui-components/settings/index.d.ts +3 -0
- package/ui-components/settings/index.js +3 -0
- package/ui-components/support/SupportModal.d.ts +15 -0
- package/ui-components/support/SupportModal.js +74 -0
- package/ui-components/support/index.d.ts +2 -0
- package/ui-components/support/index.js +1 -0
- package/ui-components/types/index.d.ts +39 -0
- package/ui-components/types/index.js +1 -0
- package/utils/index.d.ts +31 -0
- package/utils/index.js +38 -0
- package/utils/turnstile-config.d.ts +11 -0
- package/utils/turnstile-config.js +19 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation Monitor - SSE-based monitoring for unified backend operations
|
|
3
|
+
* Replaces the polling-based TaskMonitor with EventSource streaming
|
|
4
|
+
*
|
|
5
|
+
* Uses SDK extensions when available (@robosystems/client v0.1.21+)
|
|
6
|
+
* No fallback - fails fast if SDK extensions not available
|
|
7
|
+
*/
|
|
8
|
+
import { client } from '@robosystems/client';
|
|
9
|
+
// Import SDK extensions - check at runtime
|
|
10
|
+
const getSDKExtensions = async () => {
|
|
11
|
+
try {
|
|
12
|
+
return await import('@robosystems/client/clients');
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.error('SDK extensions not available:', error);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export class OperationMonitor {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.activeOperations = new Map();
|
|
22
|
+
this.operationResults = new Map();
|
|
23
|
+
}
|
|
24
|
+
static getInstance() {
|
|
25
|
+
if (!OperationMonitor.instance) {
|
|
26
|
+
OperationMonitor.instance = new OperationMonitor();
|
|
27
|
+
}
|
|
28
|
+
return OperationMonitor.instance;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Monitor an operation using SSE streaming
|
|
32
|
+
*/
|
|
33
|
+
async monitorOperation({ operationId, onProgress, onComplete, onError, onEvent, timeout = 300000, // 5 minutes default
|
|
34
|
+
}) {
|
|
35
|
+
// Get SDK extensions at runtime
|
|
36
|
+
const sdkExtensions = await getSDKExtensions();
|
|
37
|
+
// Require SDK extensions - fail fast if not available
|
|
38
|
+
if (!(sdkExtensions === null || sdkExtensions === void 0 ? void 0 : sdkExtensions.OperationClient)) {
|
|
39
|
+
throw new Error('SDK extensions not available. Please install @robosystems/client with extensions support.');
|
|
40
|
+
}
|
|
41
|
+
return this.monitorWithSDKExtensions({
|
|
42
|
+
operationId,
|
|
43
|
+
onProgress,
|
|
44
|
+
onComplete,
|
|
45
|
+
onError,
|
|
46
|
+
onEvent,
|
|
47
|
+
timeout,
|
|
48
|
+
}, sdkExtensions);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Cancel operation monitoring (does not cancel the operation itself)
|
|
52
|
+
*/
|
|
53
|
+
cancelOperation(operationId) {
|
|
54
|
+
try {
|
|
55
|
+
const eventSource = this.activeOperations.get(operationId);
|
|
56
|
+
if (eventSource) {
|
|
57
|
+
eventSource.close();
|
|
58
|
+
this.activeOperations.delete(operationId);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error('Failed to cancel operation:', error);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get cached operation status/result
|
|
70
|
+
*/
|
|
71
|
+
getOperationStatus(operationId) {
|
|
72
|
+
if (this.operationResults.has(operationId)) {
|
|
73
|
+
return this.operationResults.get(operationId);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const config = client.getConfig();
|
|
77
|
+
const baseUrl = config.baseUrl || 'http://localhost:8000';
|
|
78
|
+
// This would need to be implemented as a sync call or return cached data only
|
|
79
|
+
// For now, just return cached results
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error('Failed to get operation status:', error);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Clean up operation monitoring resources
|
|
89
|
+
*/
|
|
90
|
+
cleanupOperation(operationId) {
|
|
91
|
+
const eventSource = this.activeOperations.get(operationId);
|
|
92
|
+
if (eventSource) {
|
|
93
|
+
eventSource.close();
|
|
94
|
+
this.activeOperations.delete(operationId);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Monitor operation using SDK extensions
|
|
99
|
+
*/
|
|
100
|
+
async monitorWithSDKExtensions(options, sdkExtensions) {
|
|
101
|
+
var _a, _b, _c;
|
|
102
|
+
const { OperationClient, extractTokenFromSDKClient } = sdkExtensions;
|
|
103
|
+
const { getToken } = await import('../auth-core/token-storage');
|
|
104
|
+
const config = client.getConfig();
|
|
105
|
+
const jwtToken = getToken() || extractTokenFromSDKClient();
|
|
106
|
+
// Create operation client with proper configuration
|
|
107
|
+
const operationClient = new OperationClient({
|
|
108
|
+
baseUrl: config.baseUrl || 'http://localhost:8000',
|
|
109
|
+
credentials: 'include',
|
|
110
|
+
token: jwtToken,
|
|
111
|
+
maxRetries: 3,
|
|
112
|
+
retryDelay: 1000,
|
|
113
|
+
});
|
|
114
|
+
try {
|
|
115
|
+
const result = await operationClient.monitorOperation(options.operationId, {
|
|
116
|
+
onProgress: (progress) => {
|
|
117
|
+
var _a, _b, _c, _d;
|
|
118
|
+
(_a = options.onProgress) === null || _a === void 0 ? void 0 : _a.call(options, {
|
|
119
|
+
percent: progress.progressPercent || 0,
|
|
120
|
+
message: progress.message || '',
|
|
121
|
+
current_step: (_c = (_b = progress.details) === null || _b === void 0 ? void 0 : _b.current_step) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
122
|
+
total_steps: (_d = progress.details) === null || _d === void 0 ? void 0 : _d.total_steps,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
onEvent: (event) => {
|
|
126
|
+
var _a;
|
|
127
|
+
(_a = options.onEvent) === null || _a === void 0 ? void 0 : _a.call(options, {
|
|
128
|
+
event: event.type,
|
|
129
|
+
data: event.data,
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
timeout: options.timeout,
|
|
133
|
+
});
|
|
134
|
+
// Map OperationResult (success: boolean) to status string
|
|
135
|
+
const status = result.success
|
|
136
|
+
? 'completed'
|
|
137
|
+
: result.error === 'Operation cancelled'
|
|
138
|
+
? 'cancelled'
|
|
139
|
+
: 'failed';
|
|
140
|
+
// Normalize to documented shape
|
|
141
|
+
const normalizedResult = {
|
|
142
|
+
operation_id: options.operationId,
|
|
143
|
+
status,
|
|
144
|
+
result: result.result,
|
|
145
|
+
error: result.error,
|
|
146
|
+
};
|
|
147
|
+
// Store normalized result in cache
|
|
148
|
+
this.operationResults.set(options.operationId, normalizedResult);
|
|
149
|
+
// Handle different success/failure states properly
|
|
150
|
+
if (status === 'completed') {
|
|
151
|
+
(_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options, result.result || {});
|
|
152
|
+
}
|
|
153
|
+
else if (status === 'failed') {
|
|
154
|
+
(_b = options.onError) === null || _b === void 0 ? void 0 : _b.call(options, result.error || 'Operation failed');
|
|
155
|
+
}
|
|
156
|
+
else if (status === 'cancelled') {
|
|
157
|
+
(_c = options.onError) === null || _c === void 0 ? void 0 : _c.call(options, result.error || 'Operation cancelled');
|
|
158
|
+
}
|
|
159
|
+
return normalizedResult;
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
operationClient.closeAll();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Clean up all active operations
|
|
167
|
+
*/
|
|
168
|
+
cleanup() {
|
|
169
|
+
for (const [, eventSource] of this.activeOperations.entries()) {
|
|
170
|
+
eventSource.close();
|
|
171
|
+
}
|
|
172
|
+
this.activeOperations.clear();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Get list of active operation IDs
|
|
176
|
+
*/
|
|
177
|
+
getActiveOperations() {
|
|
178
|
+
return Array.from(this.activeOperations.keys());
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Clear operation results cache
|
|
182
|
+
*/
|
|
183
|
+
clearCache() {
|
|
184
|
+
this.operationResults.clear();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Export singleton instance and convenience functions
|
|
188
|
+
export const operationMonitor = OperationMonitor.getInstance();
|
|
189
|
+
export const monitorOperation = (options) => {
|
|
190
|
+
return operationMonitor.monitorOperation(options);
|
|
191
|
+
};
|
|
192
|
+
export const cancelOperation = (operationId) => {
|
|
193
|
+
return operationMonitor.cancelOperation(operationId);
|
|
194
|
+
};
|
|
195
|
+
export const getOperationStatus = (operationId) => {
|
|
196
|
+
return operationMonitor.getOperationStatus(operationId);
|
|
197
|
+
};
|
|
198
|
+
export const getActiveOperations = () => {
|
|
199
|
+
return operationMonitor.getActiveOperations();
|
|
200
|
+
};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types for the unified SSE operation system
|
|
3
|
+
*/
|
|
4
|
+
export interface Operation {
|
|
5
|
+
operation_id: string;
|
|
6
|
+
status: OperationStatus;
|
|
7
|
+
created_at: string;
|
|
8
|
+
updated_at?: string;
|
|
9
|
+
completed_at?: string;
|
|
10
|
+
error?: string;
|
|
11
|
+
result?: any;
|
|
12
|
+
metadata?: OperationMetadata;
|
|
13
|
+
}
|
|
14
|
+
export type OperationStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
15
|
+
export interface OperationMetadata {
|
|
16
|
+
operation_type: string;
|
|
17
|
+
graph_id?: string;
|
|
18
|
+
user_id?: string;
|
|
19
|
+
request_id?: string;
|
|
20
|
+
duration_ms?: number;
|
|
21
|
+
credits_used?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface SSEEvent<T = any> {
|
|
24
|
+
event: string;
|
|
25
|
+
data: T;
|
|
26
|
+
id?: string;
|
|
27
|
+
retry?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface OperationStartedEvent {
|
|
30
|
+
operation_id: string;
|
|
31
|
+
operation_type: string;
|
|
32
|
+
message?: string;
|
|
33
|
+
timestamp: string;
|
|
34
|
+
}
|
|
35
|
+
export interface OperationProgressEvent {
|
|
36
|
+
operation_id: string;
|
|
37
|
+
progress_percent: number;
|
|
38
|
+
message: string;
|
|
39
|
+
current_step?: number;
|
|
40
|
+
total_steps?: number;
|
|
41
|
+
timestamp: string;
|
|
42
|
+
}
|
|
43
|
+
export interface OperationCompletedEvent {
|
|
44
|
+
operation_id: string;
|
|
45
|
+
result: any;
|
|
46
|
+
duration_ms: number;
|
|
47
|
+
credits_used?: number;
|
|
48
|
+
timestamp: string;
|
|
49
|
+
}
|
|
50
|
+
export interface OperationErrorEvent {
|
|
51
|
+
operation_id: string;
|
|
52
|
+
error: string;
|
|
53
|
+
code?: string;
|
|
54
|
+
details?: any;
|
|
55
|
+
timestamp: string;
|
|
56
|
+
}
|
|
57
|
+
export interface OperationCancelledEvent {
|
|
58
|
+
operation_id: string;
|
|
59
|
+
reason?: string;
|
|
60
|
+
timestamp: string;
|
|
61
|
+
}
|
|
62
|
+
export interface CreateGraphRequest {
|
|
63
|
+
graph_type: 'generic' | 'company';
|
|
64
|
+
graph_name: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
company_name?: string;
|
|
67
|
+
company_identifier?: string;
|
|
68
|
+
company_identifier_type?: 'ein' | 'name';
|
|
69
|
+
metadata?: Record<string, any>;
|
|
70
|
+
}
|
|
71
|
+
export interface CreateGraphResponse {
|
|
72
|
+
graph_id: string;
|
|
73
|
+
graph_type: 'generic' | 'company';
|
|
74
|
+
status: 'created' | 'pending';
|
|
75
|
+
operation_id?: string;
|
|
76
|
+
created_at: string;
|
|
77
|
+
metadata?: Record<string, any>;
|
|
78
|
+
}
|
|
79
|
+
export interface ExecuteQueryRequest {
|
|
80
|
+
query: string;
|
|
81
|
+
parameters?: Record<string, any>;
|
|
82
|
+
mode?: 'auto' | 'sync' | 'async' | 'stream';
|
|
83
|
+
chunk_size?: number;
|
|
84
|
+
timeout?: number;
|
|
85
|
+
test_mode?: boolean;
|
|
86
|
+
}
|
|
87
|
+
export interface ExecuteQueryResponse {
|
|
88
|
+
data?: any[];
|
|
89
|
+
columns?: string[];
|
|
90
|
+
row_count?: number;
|
|
91
|
+
execution_time_ms?: number;
|
|
92
|
+
status?: 'queued';
|
|
93
|
+
operation_id?: string;
|
|
94
|
+
queue_position?: number;
|
|
95
|
+
estimated_wait_seconds?: number;
|
|
96
|
+
}
|
|
97
|
+
export interface QueryChunkEvent {
|
|
98
|
+
chunk_number: number;
|
|
99
|
+
total_chunks?: number;
|
|
100
|
+
rows: any[];
|
|
101
|
+
columns?: string[];
|
|
102
|
+
has_more: boolean;
|
|
103
|
+
}
|
|
104
|
+
export interface DataImportRequest {
|
|
105
|
+
graph_id: string;
|
|
106
|
+
source_type: 'csv' | 'json' | 'parquet' | 's3';
|
|
107
|
+
source_uri: string;
|
|
108
|
+
target_table: string;
|
|
109
|
+
mapping?: Record<string, string>;
|
|
110
|
+
options?: DataImportOptions;
|
|
111
|
+
}
|
|
112
|
+
export interface DataImportOptions {
|
|
113
|
+
batch_size?: number;
|
|
114
|
+
skip_errors?: boolean;
|
|
115
|
+
validate?: boolean;
|
|
116
|
+
transform?: string;
|
|
117
|
+
}
|
|
118
|
+
export interface DataImportResponse {
|
|
119
|
+
operation_id: string;
|
|
120
|
+
status: 'started' | 'queued';
|
|
121
|
+
estimated_rows?: number;
|
|
122
|
+
estimated_duration_ms?: number;
|
|
123
|
+
}
|
|
124
|
+
export interface DataImportProgressEvent {
|
|
125
|
+
operation_id: string;
|
|
126
|
+
rows_processed: number;
|
|
127
|
+
total_rows: number;
|
|
128
|
+
errors_count: number;
|
|
129
|
+
progress_percent: number;
|
|
130
|
+
current_batch?: number;
|
|
131
|
+
total_batches?: number;
|
|
132
|
+
}
|
|
133
|
+
export interface BackupRequest {
|
|
134
|
+
graph_id: string;
|
|
135
|
+
backup_type: 'full' | 'incremental';
|
|
136
|
+
destination?: string;
|
|
137
|
+
include_metadata?: boolean;
|
|
138
|
+
}
|
|
139
|
+
export interface BackupResponse {
|
|
140
|
+
operation_id: string;
|
|
141
|
+
backup_id?: string;
|
|
142
|
+
status: 'started' | 'queued';
|
|
143
|
+
estimated_size_mb?: number;
|
|
144
|
+
}
|
|
145
|
+
export interface RestoreRequest {
|
|
146
|
+
backup_id: string;
|
|
147
|
+
target_graph_id?: string;
|
|
148
|
+
restore_type: 'full' | 'schema_only' | 'data_only';
|
|
149
|
+
}
|
|
150
|
+
export interface RestoreResponse {
|
|
151
|
+
operation_id: string;
|
|
152
|
+
status: 'started' | 'queued';
|
|
153
|
+
new_graph_id?: string;
|
|
154
|
+
}
|
|
155
|
+
export interface GetOperationStatusRequest {
|
|
156
|
+
operation_id: string;
|
|
157
|
+
}
|
|
158
|
+
export interface GetOperationStatusResponse {
|
|
159
|
+
operation: Operation;
|
|
160
|
+
events?: OperationEvent[];
|
|
161
|
+
}
|
|
162
|
+
export interface CancelOperationRequest {
|
|
163
|
+
operation_id: string;
|
|
164
|
+
reason?: string;
|
|
165
|
+
}
|
|
166
|
+
export interface CancelOperationResponse {
|
|
167
|
+
success: boolean;
|
|
168
|
+
message?: string;
|
|
169
|
+
}
|
|
170
|
+
export interface ListOperationsRequest {
|
|
171
|
+
graph_id?: string;
|
|
172
|
+
status?: OperationStatus;
|
|
173
|
+
operation_type?: string;
|
|
174
|
+
limit?: number;
|
|
175
|
+
offset?: number;
|
|
176
|
+
since?: string;
|
|
177
|
+
}
|
|
178
|
+
export interface ListOperationsResponse {
|
|
179
|
+
operations: Operation[];
|
|
180
|
+
total_count: number;
|
|
181
|
+
has_more: boolean;
|
|
182
|
+
}
|
|
183
|
+
export type OperationEvent = {
|
|
184
|
+
type: 'started';
|
|
185
|
+
data: OperationStartedEvent;
|
|
186
|
+
} | {
|
|
187
|
+
type: 'progress';
|
|
188
|
+
data: OperationProgressEvent;
|
|
189
|
+
} | {
|
|
190
|
+
type: 'completed';
|
|
191
|
+
data: OperationCompletedEvent;
|
|
192
|
+
} | {
|
|
193
|
+
type: 'error';
|
|
194
|
+
data: OperationErrorEvent;
|
|
195
|
+
} | {
|
|
196
|
+
type: 'cancelled';
|
|
197
|
+
data: OperationCancelledEvent;
|
|
198
|
+
} | {
|
|
199
|
+
type: 'query_chunk';
|
|
200
|
+
data: QueryChunkEvent;
|
|
201
|
+
} | {
|
|
202
|
+
type: 'import_progress';
|
|
203
|
+
data: DataImportProgressEvent;
|
|
204
|
+
};
|
|
205
|
+
export declare function isOperationStarted(event: OperationEvent): event is {
|
|
206
|
+
type: 'started';
|
|
207
|
+
data: OperationStartedEvent;
|
|
208
|
+
};
|
|
209
|
+
export declare function isOperationProgress(event: OperationEvent): event is {
|
|
210
|
+
type: 'progress';
|
|
211
|
+
data: OperationProgressEvent;
|
|
212
|
+
};
|
|
213
|
+
export declare function isOperationCompleted(event: OperationEvent): event is {
|
|
214
|
+
type: 'completed';
|
|
215
|
+
data: OperationCompletedEvent;
|
|
216
|
+
};
|
|
217
|
+
export declare function isOperationError(event: OperationEvent): event is {
|
|
218
|
+
type: 'error';
|
|
219
|
+
data: OperationErrorEvent;
|
|
220
|
+
};
|
|
221
|
+
export declare function isOperationCancelled(event: OperationEvent): event is {
|
|
222
|
+
type: 'cancelled';
|
|
223
|
+
data: OperationCancelledEvent;
|
|
224
|
+
};
|
|
225
|
+
export declare function isQueryChunk(event: OperationEvent): event is {
|
|
226
|
+
type: 'query_chunk';
|
|
227
|
+
data: QueryChunkEvent;
|
|
228
|
+
};
|
|
229
|
+
export declare function isImportProgress(event: OperationEvent): event is {
|
|
230
|
+
type: 'import_progress';
|
|
231
|
+
data: DataImportProgressEvent;
|
|
232
|
+
};
|
|
233
|
+
export declare function isOperationActive(status: OperationStatus): boolean;
|
|
234
|
+
export declare function isOperationTerminal(status: OperationStatus): boolean;
|
|
235
|
+
export declare function getOperationDuration(operation: Operation): number | null;
|
|
236
|
+
export declare function formatOperationStatus(status: OperationStatus): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types for the unified SSE operation system
|
|
3
|
+
*/
|
|
4
|
+
// ============================================
|
|
5
|
+
// Helper Type Guards
|
|
6
|
+
// ============================================
|
|
7
|
+
export function isOperationStarted(event) {
|
|
8
|
+
return event.type === 'started';
|
|
9
|
+
}
|
|
10
|
+
export function isOperationProgress(event) {
|
|
11
|
+
return event.type === 'progress';
|
|
12
|
+
}
|
|
13
|
+
export function isOperationCompleted(event) {
|
|
14
|
+
return event.type === 'completed';
|
|
15
|
+
}
|
|
16
|
+
export function isOperationError(event) {
|
|
17
|
+
return event.type === 'error';
|
|
18
|
+
}
|
|
19
|
+
export function isOperationCancelled(event) {
|
|
20
|
+
return event.type === 'cancelled';
|
|
21
|
+
}
|
|
22
|
+
export function isQueryChunk(event) {
|
|
23
|
+
return event.type === 'query_chunk';
|
|
24
|
+
}
|
|
25
|
+
export function isImportProgress(event) {
|
|
26
|
+
return event.type === 'import_progress';
|
|
27
|
+
}
|
|
28
|
+
// ============================================
|
|
29
|
+
// Utility Functions
|
|
30
|
+
// ============================================
|
|
31
|
+
export function isOperationActive(status) {
|
|
32
|
+
return status === 'pending' || status === 'running';
|
|
33
|
+
}
|
|
34
|
+
export function isOperationTerminal(status) {
|
|
35
|
+
return status === 'completed' || status === 'failed' || status === 'cancelled';
|
|
36
|
+
}
|
|
37
|
+
export function getOperationDuration(operation) {
|
|
38
|
+
if (!operation.created_at || !operation.completed_at) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const start = new Date(operation.created_at).getTime();
|
|
42
|
+
const end = new Date(operation.completed_at).getTime();
|
|
43
|
+
return end - start;
|
|
44
|
+
}
|
|
45
|
+
export function formatOperationStatus(status) {
|
|
46
|
+
switch (status) {
|
|
47
|
+
case 'pending':
|
|
48
|
+
return 'Pending';
|
|
49
|
+
case 'running':
|
|
50
|
+
return 'Running';
|
|
51
|
+
case 'completed':
|
|
52
|
+
return 'Completed';
|
|
53
|
+
case 'failed':
|
|
54
|
+
return 'Failed';
|
|
55
|
+
case 'cancelled':
|
|
56
|
+
return 'Cancelled';
|
|
57
|
+
default:
|
|
58
|
+
return 'Unknown';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TaskPollingOptions, TaskStatusResponse } from './types';
|
|
2
|
+
export declare class TaskMonitor {
|
|
3
|
+
private static instance;
|
|
4
|
+
private activeTasks;
|
|
5
|
+
static getInstance(): TaskMonitor;
|
|
6
|
+
pollTask({ taskId, onProgress, onComplete, onError, pollInterval, maxAttempts, }: TaskPollingOptions): Promise<TaskStatusResponse>;
|
|
7
|
+
cancelTask(taskId: string): Promise<boolean>;
|
|
8
|
+
cancelAllTasks(): void;
|
|
9
|
+
getActiveTasks(): string[];
|
|
10
|
+
}
|
|
11
|
+
export declare const taskMonitor: TaskMonitor;
|
|
12
|
+
export declare const pollTaskStatus: (options: TaskPollingOptions) => Promise<TaskStatusResponse>;
|
|
13
|
+
export declare const cancelTask: (taskId: string) => Promise<boolean>;
|
|
14
|
+
export declare const getActiveTasks: () => string[];
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import * as SDK from '@robosystems/client';
|
|
2
|
+
export class TaskMonitor {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.activeTasks = new Map();
|
|
5
|
+
}
|
|
6
|
+
static getInstance() {
|
|
7
|
+
if (!TaskMonitor.instance) {
|
|
8
|
+
TaskMonitor.instance = new TaskMonitor();
|
|
9
|
+
}
|
|
10
|
+
return TaskMonitor.instance;
|
|
11
|
+
}
|
|
12
|
+
async pollTask({ taskId, onProgress, onComplete, onError, pollInterval = 2000, maxAttempts = 150, // 5 minutes at 2s intervals
|
|
13
|
+
}) {
|
|
14
|
+
let attempts = 0;
|
|
15
|
+
const abortController = new AbortController();
|
|
16
|
+
this.activeTasks.set(taskId, abortController);
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const poll = async () => {
|
|
19
|
+
try {
|
|
20
|
+
if (abortController.signal.aborted) {
|
|
21
|
+
this.activeTasks.delete(taskId);
|
|
22
|
+
reject(new Error('Task polling was cancelled'));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
attempts++;
|
|
26
|
+
const response = await SDK.getOperationStatus({
|
|
27
|
+
path: { operation_id: taskId },
|
|
28
|
+
});
|
|
29
|
+
if (!response.data) {
|
|
30
|
+
throw new Error('No data received from task status endpoint');
|
|
31
|
+
}
|
|
32
|
+
const status = response.data;
|
|
33
|
+
switch (status.status) {
|
|
34
|
+
case 'pending':
|
|
35
|
+
case 'in_progress':
|
|
36
|
+
case 'retrying':
|
|
37
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress(status);
|
|
38
|
+
if (attempts < maxAttempts && !abortController.signal.aborted) {
|
|
39
|
+
setTimeout(poll, pollInterval);
|
|
40
|
+
}
|
|
41
|
+
else if (attempts >= maxAttempts) {
|
|
42
|
+
this.activeTasks.delete(taskId);
|
|
43
|
+
const timeoutError = new Error(`Task polling timeout after ${attempts} attempts`);
|
|
44
|
+
onError === null || onError === void 0 ? void 0 : onError(timeoutError.message);
|
|
45
|
+
reject(timeoutError);
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
case 'completed':
|
|
49
|
+
this.activeTasks.delete(taskId);
|
|
50
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete(status.details || status);
|
|
51
|
+
resolve(status);
|
|
52
|
+
break;
|
|
53
|
+
case 'failed': {
|
|
54
|
+
this.activeTasks.delete(taskId);
|
|
55
|
+
const failureError = new Error(status.message || 'Task failed without error message');
|
|
56
|
+
onError === null || onError === void 0 ? void 0 : onError(failureError.message);
|
|
57
|
+
reject(failureError);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'cancelled': {
|
|
61
|
+
this.activeTasks.delete(taskId);
|
|
62
|
+
const cancelError = new Error('Task was cancelled');
|
|
63
|
+
onError === null || onError === void 0 ? void 0 : onError(cancelError.message);
|
|
64
|
+
reject(cancelError);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
// Handle unknown status as in_progress
|
|
69
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress(status);
|
|
70
|
+
if (attempts < maxAttempts && !abortController.signal.aborted) {
|
|
71
|
+
setTimeout(poll, pollInterval);
|
|
72
|
+
}
|
|
73
|
+
else if (attempts >= maxAttempts) {
|
|
74
|
+
this.activeTasks.delete(taskId);
|
|
75
|
+
const unknownError = new Error(`Unknown task status: ${status.status}`);
|
|
76
|
+
onError === null || onError === void 0 ? void 0 : onError(unknownError.message);
|
|
77
|
+
reject(unknownError);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
this.activeTasks.delete(taskId);
|
|
83
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
84
|
+
console.error('Task polling error:', error);
|
|
85
|
+
onError === null || onError === void 0 ? void 0 : onError(errorMessage);
|
|
86
|
+
reject(error);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
// Start polling
|
|
90
|
+
poll();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async cancelTask(taskId) {
|
|
94
|
+
try {
|
|
95
|
+
// Cancel local polling
|
|
96
|
+
const abortController = this.activeTasks.get(taskId);
|
|
97
|
+
if (abortController) {
|
|
98
|
+
abortController.abort();
|
|
99
|
+
this.activeTasks.delete(taskId);
|
|
100
|
+
}
|
|
101
|
+
// Cancel task on server
|
|
102
|
+
await SDK.cancelOperation({
|
|
103
|
+
path: { operation_id: taskId },
|
|
104
|
+
});
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.error('Failed to cancel task:', error);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
cancelAllTasks() {
|
|
113
|
+
for (const [, abortController] of this.activeTasks.entries()) {
|
|
114
|
+
abortController.abort();
|
|
115
|
+
}
|
|
116
|
+
this.activeTasks.clear();
|
|
117
|
+
}
|
|
118
|
+
getActiveTasks() {
|
|
119
|
+
return Array.from(this.activeTasks.keys());
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Utility functions for easier usage
|
|
123
|
+
export const taskMonitor = TaskMonitor.getInstance();
|
|
124
|
+
export const pollTaskStatus = (options) => {
|
|
125
|
+
return taskMonitor.pollTask(options);
|
|
126
|
+
};
|
|
127
|
+
export const cancelTask = (taskId) => {
|
|
128
|
+
return taskMonitor.cancelTask(taskId);
|
|
129
|
+
};
|
|
130
|
+
export const getActiveTasks = () => {
|
|
131
|
+
return taskMonitor.getActiveTasks();
|
|
132
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface TaskStatusResponse {
|
|
2
|
+
status: TaskStatus;
|
|
3
|
+
progress?: number;
|
|
4
|
+
step?: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
details?: any;
|
|
7
|
+
result?: any;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
export type TaskStatus = 'pending' | 'in_progress' | 'completed' | 'failed' | 'cancelled' | 'retrying';
|
|
11
|
+
export interface TaskPollingOptions {
|
|
12
|
+
taskId: string;
|
|
13
|
+
onProgress?: (status: TaskStatusResponse) => void;
|
|
14
|
+
onComplete?: (result: any) => void;
|
|
15
|
+
onError?: (error: string) => void;
|
|
16
|
+
pollInterval?: number;
|
|
17
|
+
maxAttempts?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface TaskMonitorState {
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
progress: number | null;
|
|
22
|
+
currentStep: string | null;
|
|
23
|
+
error: string | null;
|
|
24
|
+
taskId: string | null;
|
|
25
|
+
result: any | null;
|
|
26
|
+
}
|
|
27
|
+
export interface TaskCreateResponse {
|
|
28
|
+
task_id: string;
|
|
29
|
+
status: TaskStatus;
|
|
30
|
+
message?: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|