@robosystems/client 0.1.15 → 0.1.17
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/extensions/hooks.d.ts +1 -1
- package/package.json +48 -6
- package/sdk/client/client.gen.d.ts +2 -0
- package/sdk/client/client.gen.js +153 -0
- package/sdk/client/client.gen.ts +200 -0
- package/sdk/client/index.d.ts +7 -0
- package/sdk/client/index.js +15 -0
- package/sdk/client/index.ts +25 -0
- package/sdk/client/types.gen.d.ts +122 -0
- package/sdk/client/types.gen.js +4 -0
- package/sdk/client/types.gen.ts +233 -0
- package/sdk/client/utils.gen.d.ts +45 -0
- package/sdk/client/utils.gen.js +296 -0
- package/sdk/client/utils.gen.ts +419 -0
- package/sdk/client.gen.d.ts +12 -0
- package/sdk/client.gen.js +8 -0
- package/sdk/client.gen.ts +18 -0
- package/sdk/core/auth.gen.d.ts +18 -0
- package/sdk/core/auth.gen.js +18 -0
- package/sdk/core/auth.gen.ts +42 -0
- package/sdk/core/bodySerializer.gen.d.ts +17 -0
- package/sdk/core/bodySerializer.gen.js +57 -0
- package/sdk/core/bodySerializer.gen.ts +90 -0
- package/sdk/core/params.gen.d.ts +33 -0
- package/sdk/core/params.gen.js +92 -0
- package/sdk/core/params.gen.ts +153 -0
- package/sdk/core/pathSerializer.gen.d.ts +33 -0
- package/sdk/core/pathSerializer.gen.js +123 -0
- package/sdk/core/pathSerializer.gen.ts +181 -0
- package/sdk/core/types.gen.d.ts +78 -0
- package/sdk/core/types.gen.js +4 -0
- package/sdk/core/types.gen.ts +121 -0
- package/sdk/index.d.ts +2 -0
- package/sdk/index.js +19 -0
- package/sdk/index.ts +3 -0
- package/sdk/sdk.gen.d.ts +1249 -0
- package/sdk/sdk.gen.js +2572 -0
- package/sdk/sdk.gen.ts +2585 -0
- package/sdk/types.gen.d.ts +6347 -0
- package/sdk/types.gen.js +3 -0
- package/sdk/types.gen.ts +6852 -0
- package/sdk-extensions/OperationClient.d.ts +64 -0
- package/sdk-extensions/OperationClient.js +251 -0
- package/sdk-extensions/OperationClient.ts +322 -0
- package/sdk-extensions/QueryClient.d.ts +50 -0
- package/sdk-extensions/QueryClient.js +190 -0
- package/sdk-extensions/QueryClient.ts +283 -0
- package/sdk-extensions/README.md +672 -0
- package/sdk-extensions/SSEClient.d.ts +48 -0
- package/sdk-extensions/SSEClient.js +148 -0
- package/sdk-extensions/SSEClient.ts +189 -0
- package/sdk-extensions/config.d.ts +32 -0
- package/sdk-extensions/config.js +74 -0
- package/sdk-extensions/config.ts +91 -0
- package/sdk-extensions/hooks.d.ts +110 -0
- package/sdk-extensions/hooks.js +371 -0
- package/sdk-extensions/hooks.ts +438 -0
- package/sdk-extensions/index.d.ts +46 -0
- package/sdk-extensions/index.js +110 -0
- package/sdk-extensions/index.ts +123 -0
- package/sdk.gen.d.ts +210 -104
- package/sdk.gen.js +409 -287
- package/sdk.gen.ts +404 -282
- package/types.gen.d.ts +1218 -567
- package/types.gen.ts +1236 -566
- package/openapi-ts.config.js +0 -9
- package/prepare.js +0 -220
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SSEClient = exports.EventType = void 0;
|
|
5
|
+
var EventType;
|
|
6
|
+
(function (EventType) {
|
|
7
|
+
EventType["OPERATION_STARTED"] = "operation_started";
|
|
8
|
+
EventType["OPERATION_PROGRESS"] = "operation_progress";
|
|
9
|
+
EventType["OPERATION_COMPLETED"] = "operation_completed";
|
|
10
|
+
EventType["OPERATION_ERROR"] = "operation_error";
|
|
11
|
+
EventType["OPERATION_CANCELLED"] = "operation_cancelled";
|
|
12
|
+
EventType["DATA_CHUNK"] = "data_chunk";
|
|
13
|
+
EventType["METADATA"] = "metadata";
|
|
14
|
+
EventType["HEARTBEAT"] = "heartbeat";
|
|
15
|
+
EventType["QUEUE_UPDATE"] = "queue_update";
|
|
16
|
+
})(EventType || (exports.EventType = EventType = {}));
|
|
17
|
+
class SSEClient {
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.reconnectAttempts = 0;
|
|
20
|
+
this.closed = false;
|
|
21
|
+
this.listeners = new Map();
|
|
22
|
+
this.config = {
|
|
23
|
+
maxRetries: 5,
|
|
24
|
+
retryDelay: 1000,
|
|
25
|
+
heartbeatInterval: 30000,
|
|
26
|
+
...config,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async connect(operationId, fromSequence = 0) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const url = `${this.config.baseUrl}/v1/operations/${operationId}/stream?from_sequence=${fromSequence}`;
|
|
32
|
+
this.eventSource = new EventSource(url, {
|
|
33
|
+
withCredentials: this.config.credentials === 'include',
|
|
34
|
+
});
|
|
35
|
+
const connectionTimeout = setTimeout(() => {
|
|
36
|
+
reject(new Error('Connection timeout'));
|
|
37
|
+
this.close();
|
|
38
|
+
}, 10000);
|
|
39
|
+
this.eventSource.onopen = () => {
|
|
40
|
+
clearTimeout(connectionTimeout);
|
|
41
|
+
this.reconnectAttempts = 0;
|
|
42
|
+
this.emit('connected', null);
|
|
43
|
+
resolve();
|
|
44
|
+
};
|
|
45
|
+
this.eventSource.onerror = (error) => {
|
|
46
|
+
clearTimeout(connectionTimeout);
|
|
47
|
+
if (!this.closed) {
|
|
48
|
+
this.handleError(error, operationId, fromSequence);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
this.eventSource.onmessage = (event) => {
|
|
52
|
+
this.handleMessage(event);
|
|
53
|
+
};
|
|
54
|
+
// Set up specific event listeners
|
|
55
|
+
Object.values(EventType).forEach((eventType) => {
|
|
56
|
+
this.eventSource.addEventListener(eventType, (event) => {
|
|
57
|
+
this.handleTypedEvent(eventType, event);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
handleMessage(event) {
|
|
63
|
+
try {
|
|
64
|
+
const data = JSON.parse(event.data);
|
|
65
|
+
const sseEvent = {
|
|
66
|
+
event: event.type || 'message',
|
|
67
|
+
data,
|
|
68
|
+
id: event.lastEventId,
|
|
69
|
+
timestamp: new Date(),
|
|
70
|
+
};
|
|
71
|
+
this.lastEventId = event.lastEventId;
|
|
72
|
+
this.emit('event', sseEvent);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
this.emit('parse_error', { error, rawData: event.data });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
handleTypedEvent(eventType, event) {
|
|
79
|
+
try {
|
|
80
|
+
const data = JSON.parse(event.data);
|
|
81
|
+
this.lastEventId = event.lastEventId;
|
|
82
|
+
this.emit(eventType, data);
|
|
83
|
+
// Check for completion events
|
|
84
|
+
if (eventType === EventType.OPERATION_COMPLETED ||
|
|
85
|
+
eventType === EventType.OPERATION_ERROR ||
|
|
86
|
+
eventType === EventType.OPERATION_CANCELLED) {
|
|
87
|
+
this.close();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
this.emit('parse_error', { error, rawData: event.data });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async handleError(error, operationId, fromSequence) {
|
|
95
|
+
if (this.closed)
|
|
96
|
+
return;
|
|
97
|
+
if (this.reconnectAttempts < this.config.maxRetries) {
|
|
98
|
+
this.reconnectAttempts++;
|
|
99
|
+
const delay = this.config.retryDelay * Math.pow(2, this.reconnectAttempts - 1);
|
|
100
|
+
this.emit('reconnecting', {
|
|
101
|
+
attempt: this.reconnectAttempts,
|
|
102
|
+
delay,
|
|
103
|
+
lastEventId: this.lastEventId,
|
|
104
|
+
});
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
const resumeFrom = this.lastEventId ? parseInt(this.lastEventId) + 1 : fromSequence;
|
|
107
|
+
this.connect(operationId, resumeFrom).catch(() => {
|
|
108
|
+
// Error handled in connect
|
|
109
|
+
});
|
|
110
|
+
}, delay);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
this.emit('max_retries_exceeded', error);
|
|
114
|
+
this.close();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
on(event, listener) {
|
|
118
|
+
if (!this.listeners.has(event)) {
|
|
119
|
+
this.listeners.set(event, new Set());
|
|
120
|
+
}
|
|
121
|
+
this.listeners.get(event).add(listener);
|
|
122
|
+
}
|
|
123
|
+
off(event, listener) {
|
|
124
|
+
const listeners = this.listeners.get(event);
|
|
125
|
+
if (listeners) {
|
|
126
|
+
listeners.delete(listener);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
emit(event, data) {
|
|
130
|
+
const listeners = this.listeners.get(event);
|
|
131
|
+
if (listeners) {
|
|
132
|
+
listeners.forEach((listener) => listener(data));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
close() {
|
|
136
|
+
this.closed = true;
|
|
137
|
+
if (this.eventSource) {
|
|
138
|
+
this.eventSource.close();
|
|
139
|
+
this.eventSource = undefined;
|
|
140
|
+
}
|
|
141
|
+
this.emit('closed', null);
|
|
142
|
+
this.listeners.clear();
|
|
143
|
+
}
|
|
144
|
+
isConnected() {
|
|
145
|
+
return this.eventSource !== undefined && this.eventSource.readyState === EventSource.OPEN;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.SSEClient = SSEClient;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Core SSE (Server-Sent Events) client for RoboSystems API
|
|
5
|
+
* Provides automatic reconnection, event replay, and type-safe event handling
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface SSEConfig {
|
|
9
|
+
baseUrl: string
|
|
10
|
+
credentials?: 'include' | 'same-origin' | 'omit'
|
|
11
|
+
headers?: Record<string, string>
|
|
12
|
+
maxRetries?: number
|
|
13
|
+
retryDelay?: number
|
|
14
|
+
heartbeatInterval?: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface SSEEvent {
|
|
18
|
+
event: string
|
|
19
|
+
data: any
|
|
20
|
+
id?: string
|
|
21
|
+
retry?: number
|
|
22
|
+
timestamp: Date
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export enum EventType {
|
|
26
|
+
OPERATION_STARTED = 'operation_started',
|
|
27
|
+
OPERATION_PROGRESS = 'operation_progress',
|
|
28
|
+
OPERATION_COMPLETED = 'operation_completed',
|
|
29
|
+
OPERATION_ERROR = 'operation_error',
|
|
30
|
+
OPERATION_CANCELLED = 'operation_cancelled',
|
|
31
|
+
DATA_CHUNK = 'data_chunk',
|
|
32
|
+
METADATA = 'metadata',
|
|
33
|
+
HEARTBEAT = 'heartbeat',
|
|
34
|
+
QUEUE_UPDATE = 'queue_update',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class SSEClient {
|
|
38
|
+
private config: SSEConfig
|
|
39
|
+
private eventSource?: EventSource
|
|
40
|
+
private reconnectAttempts: number = 0
|
|
41
|
+
private lastEventId?: string
|
|
42
|
+
private closed: boolean = false
|
|
43
|
+
private listeners: Map<string, Set<(data: any) => void>> = new Map()
|
|
44
|
+
|
|
45
|
+
constructor(config: SSEConfig) {
|
|
46
|
+
this.config = {
|
|
47
|
+
maxRetries: 5,
|
|
48
|
+
retryDelay: 1000,
|
|
49
|
+
heartbeatInterval: 30000,
|
|
50
|
+
...config,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async connect(operationId: string, fromSequence: number = 0): Promise<void> {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
const url = `${this.config.baseUrl}/v1/operations/${operationId}/stream?from_sequence=${fromSequence}`
|
|
57
|
+
|
|
58
|
+
this.eventSource = new EventSource(url, {
|
|
59
|
+
withCredentials: this.config.credentials === 'include',
|
|
60
|
+
} as any)
|
|
61
|
+
|
|
62
|
+
const connectionTimeout = setTimeout(() => {
|
|
63
|
+
reject(new Error('Connection timeout'))
|
|
64
|
+
this.close()
|
|
65
|
+
}, 10000)
|
|
66
|
+
|
|
67
|
+
this.eventSource.onopen = () => {
|
|
68
|
+
clearTimeout(connectionTimeout)
|
|
69
|
+
this.reconnectAttempts = 0
|
|
70
|
+
this.emit('connected', null)
|
|
71
|
+
resolve()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.eventSource.onerror = (error) => {
|
|
75
|
+
clearTimeout(connectionTimeout)
|
|
76
|
+
if (!this.closed) {
|
|
77
|
+
this.handleError(error, operationId, fromSequence)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.eventSource.onmessage = (event) => {
|
|
82
|
+
this.handleMessage(event)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Set up specific event listeners
|
|
86
|
+
Object.values(EventType).forEach((eventType) => {
|
|
87
|
+
this.eventSource!.addEventListener(eventType, (event: any) => {
|
|
88
|
+
this.handleTypedEvent(eventType, event)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private handleMessage(event: MessageEvent): void {
|
|
95
|
+
try {
|
|
96
|
+
const data = JSON.parse(event.data)
|
|
97
|
+
const sseEvent: SSEEvent = {
|
|
98
|
+
event: event.type || 'message',
|
|
99
|
+
data,
|
|
100
|
+
id: event.lastEventId,
|
|
101
|
+
timestamp: new Date(),
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.lastEventId = event.lastEventId
|
|
105
|
+
this.emit('event', sseEvent)
|
|
106
|
+
} catch (error) {
|
|
107
|
+
this.emit('parse_error', { error, rawData: event.data })
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private handleTypedEvent(eventType: string, event: MessageEvent): void {
|
|
112
|
+
try {
|
|
113
|
+
const data = JSON.parse(event.data)
|
|
114
|
+
this.lastEventId = event.lastEventId
|
|
115
|
+
this.emit(eventType, data)
|
|
116
|
+
|
|
117
|
+
// Check for completion events
|
|
118
|
+
if (
|
|
119
|
+
eventType === EventType.OPERATION_COMPLETED ||
|
|
120
|
+
eventType === EventType.OPERATION_ERROR ||
|
|
121
|
+
eventType === EventType.OPERATION_CANCELLED
|
|
122
|
+
) {
|
|
123
|
+
this.close()
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
this.emit('parse_error', { error, rawData: event.data })
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private async handleError(error: any, operationId: string, fromSequence: number): Promise<void> {
|
|
131
|
+
if (this.closed) return
|
|
132
|
+
|
|
133
|
+
if (this.reconnectAttempts < this.config.maxRetries!) {
|
|
134
|
+
this.reconnectAttempts++
|
|
135
|
+
const delay = this.config.retryDelay! * Math.pow(2, this.reconnectAttempts - 1)
|
|
136
|
+
|
|
137
|
+
this.emit('reconnecting', {
|
|
138
|
+
attempt: this.reconnectAttempts,
|
|
139
|
+
delay,
|
|
140
|
+
lastEventId: this.lastEventId,
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
setTimeout(() => {
|
|
144
|
+
const resumeFrom = this.lastEventId ? parseInt(this.lastEventId) + 1 : fromSequence
|
|
145
|
+
this.connect(operationId, resumeFrom).catch(() => {
|
|
146
|
+
// Error handled in connect
|
|
147
|
+
})
|
|
148
|
+
}, delay)
|
|
149
|
+
} else {
|
|
150
|
+
this.emit('max_retries_exceeded', error)
|
|
151
|
+
this.close()
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
on(event: string, listener: (data: any) => void): void {
|
|
156
|
+
if (!this.listeners.has(event)) {
|
|
157
|
+
this.listeners.set(event, new Set())
|
|
158
|
+
}
|
|
159
|
+
this.listeners.get(event)!.add(listener)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
off(event: string, listener: (data: any) => void): void {
|
|
163
|
+
const listeners = this.listeners.get(event)
|
|
164
|
+
if (listeners) {
|
|
165
|
+
listeners.delete(listener)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private emit(event: string, data: any): void {
|
|
170
|
+
const listeners = this.listeners.get(event)
|
|
171
|
+
if (listeners) {
|
|
172
|
+
listeners.forEach((listener) => listener(data))
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
close(): void {
|
|
177
|
+
this.closed = true
|
|
178
|
+
if (this.eventSource) {
|
|
179
|
+
this.eventSource.close()
|
|
180
|
+
this.eventSource = undefined
|
|
181
|
+
}
|
|
182
|
+
this.emit('closed', null)
|
|
183
|
+
this.listeners.clear()
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
isConnected(): boolean {
|
|
187
|
+
return this.eventSource !== undefined && this.eventSource.readyState === EventSource.OPEN
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for SDK extensions
|
|
3
|
+
* Provides centralized configuration for CORS, credentials, and other settings
|
|
4
|
+
*/
|
|
5
|
+
export interface SDKExtensionsConfig {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
credentials?: 'include' | 'same-origin' | 'omit';
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
maxRetries?: number;
|
|
11
|
+
retryDelay?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Set global configuration for SDK extensions
|
|
15
|
+
* @param config Partial configuration to merge with defaults
|
|
16
|
+
*/
|
|
17
|
+
export declare function setSDKExtensionsConfig(config: Partial<SDKExtensionsConfig>): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get current SDK extensions configuration
|
|
20
|
+
* @returns Current configuration
|
|
21
|
+
*/
|
|
22
|
+
export declare function getSDKExtensionsConfig(): SDKExtensionsConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Reset configuration to defaults
|
|
25
|
+
*/
|
|
26
|
+
export declare function resetSDKExtensionsConfig(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get configuration for a specific environment
|
|
29
|
+
* @param env Environment name (production, staging, development)
|
|
30
|
+
* @returns Environment-specific configuration
|
|
31
|
+
*/
|
|
32
|
+
export declare function getEnvironmentConfig(env?: 'production' | 'staging' | 'development'): SDKExtensionsConfig;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.setSDKExtensionsConfig = setSDKExtensionsConfig;
|
|
5
|
+
exports.getSDKExtensionsConfig = getSDKExtensionsConfig;
|
|
6
|
+
exports.resetSDKExtensionsConfig = resetSDKExtensionsConfig;
|
|
7
|
+
exports.getEnvironmentConfig = getEnvironmentConfig;
|
|
8
|
+
// Default configuration
|
|
9
|
+
const defaultConfig = {
|
|
10
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
|
|
11
|
+
credentials: 'include',
|
|
12
|
+
timeout: 30000,
|
|
13
|
+
maxRetries: 3,
|
|
14
|
+
retryDelay: 1000,
|
|
15
|
+
};
|
|
16
|
+
// Global configuration singleton
|
|
17
|
+
let globalConfig = { ...defaultConfig };
|
|
18
|
+
/**
|
|
19
|
+
* Set global configuration for SDK extensions
|
|
20
|
+
* @param config Partial configuration to merge with defaults
|
|
21
|
+
*/
|
|
22
|
+
function setSDKExtensionsConfig(config) {
|
|
23
|
+
globalConfig = {
|
|
24
|
+
...globalConfig,
|
|
25
|
+
...config,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get current SDK extensions configuration
|
|
30
|
+
* @returns Current configuration
|
|
31
|
+
*/
|
|
32
|
+
function getSDKExtensionsConfig() {
|
|
33
|
+
return { ...globalConfig };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reset configuration to defaults
|
|
37
|
+
*/
|
|
38
|
+
function resetSDKExtensionsConfig() {
|
|
39
|
+
globalConfig = { ...defaultConfig };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get configuration for a specific environment
|
|
43
|
+
* @param env Environment name (production, staging, development)
|
|
44
|
+
* @returns Environment-specific configuration
|
|
45
|
+
*/
|
|
46
|
+
function getEnvironmentConfig(env = 'development') {
|
|
47
|
+
const baseConfigs = {
|
|
48
|
+
production: {
|
|
49
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'https://api.robosystems.ai',
|
|
50
|
+
credentials: 'include',
|
|
51
|
+
timeout: 60000,
|
|
52
|
+
maxRetries: 5,
|
|
53
|
+
retryDelay: 2000,
|
|
54
|
+
},
|
|
55
|
+
staging: {
|
|
56
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'https://staging-api.robosystems.ai',
|
|
57
|
+
credentials: 'include',
|
|
58
|
+
timeout: 45000,
|
|
59
|
+
maxRetries: 3,
|
|
60
|
+
retryDelay: 1500,
|
|
61
|
+
},
|
|
62
|
+
development: {
|
|
63
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
|
|
64
|
+
credentials: 'include',
|
|
65
|
+
timeout: 30000,
|
|
66
|
+
maxRetries: 3,
|
|
67
|
+
retryDelay: 1000,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
...defaultConfig,
|
|
72
|
+
...baseConfigs[env],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for SDK extensions
|
|
5
|
+
* Provides centralized configuration for CORS, credentials, and other settings
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface SDKExtensionsConfig {
|
|
9
|
+
baseUrl?: string
|
|
10
|
+
credentials?: 'include' | 'same-origin' | 'omit'
|
|
11
|
+
headers?: Record<string, string>
|
|
12
|
+
timeout?: number
|
|
13
|
+
maxRetries?: number
|
|
14
|
+
retryDelay?: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Default configuration
|
|
18
|
+
const defaultConfig: SDKExtensionsConfig = {
|
|
19
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
|
|
20
|
+
credentials: 'include',
|
|
21
|
+
timeout: 30000,
|
|
22
|
+
maxRetries: 3,
|
|
23
|
+
retryDelay: 1000,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Global configuration singleton
|
|
27
|
+
let globalConfig: SDKExtensionsConfig = { ...defaultConfig }
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Set global configuration for SDK extensions
|
|
31
|
+
* @param config Partial configuration to merge with defaults
|
|
32
|
+
*/
|
|
33
|
+
export function setSDKExtensionsConfig(config: Partial<SDKExtensionsConfig>) {
|
|
34
|
+
globalConfig = {
|
|
35
|
+
...globalConfig,
|
|
36
|
+
...config,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get current SDK extensions configuration
|
|
42
|
+
* @returns Current configuration
|
|
43
|
+
*/
|
|
44
|
+
export function getSDKExtensionsConfig(): SDKExtensionsConfig {
|
|
45
|
+
return { ...globalConfig }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Reset configuration to defaults
|
|
50
|
+
*/
|
|
51
|
+
export function resetSDKExtensionsConfig() {
|
|
52
|
+
globalConfig = { ...defaultConfig }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get configuration for a specific environment
|
|
57
|
+
* @param env Environment name (production, staging, development)
|
|
58
|
+
* @returns Environment-specific configuration
|
|
59
|
+
*/
|
|
60
|
+
export function getEnvironmentConfig(
|
|
61
|
+
env: 'production' | 'staging' | 'development' = 'development'
|
|
62
|
+
): SDKExtensionsConfig {
|
|
63
|
+
const baseConfigs: Record<string, Partial<SDKExtensionsConfig>> = {
|
|
64
|
+
production: {
|
|
65
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'https://api.robosystems.ai',
|
|
66
|
+
credentials: 'include',
|
|
67
|
+
timeout: 60000,
|
|
68
|
+
maxRetries: 5,
|
|
69
|
+
retryDelay: 2000,
|
|
70
|
+
},
|
|
71
|
+
staging: {
|
|
72
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'https://staging-api.robosystems.ai',
|
|
73
|
+
credentials: 'include',
|
|
74
|
+
timeout: 45000,
|
|
75
|
+
maxRetries: 3,
|
|
76
|
+
retryDelay: 1500,
|
|
77
|
+
},
|
|
78
|
+
development: {
|
|
79
|
+
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
|
|
80
|
+
credentials: 'include',
|
|
81
|
+
timeout: 30000,
|
|
82
|
+
maxRetries: 3,
|
|
83
|
+
retryDelay: 1000,
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
...defaultConfig,
|
|
89
|
+
...baseConfigs[env],
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { OperationProgress, OperationResult } from './OperationClient';
|
|
2
|
+
import { OperationClient } from './OperationClient';
|
|
3
|
+
import type { QueryOptions, QueryResult } from './QueryClient';
|
|
4
|
+
import { QueryClient } from './QueryClient';
|
|
5
|
+
/**
|
|
6
|
+
* Hook for executing Cypher queries with loading states and error handling
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const { execute, loading, error, data } = useQuery('graph_123')
|
|
11
|
+
*
|
|
12
|
+
* const handleSearch = async () => {
|
|
13
|
+
* const result = await execute('MATCH (n:Company) RETURN n LIMIT 10')
|
|
14
|
+
* console.log(result.data)
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function useQuery(graphId: string): {
|
|
19
|
+
execute: (query: string, parameters?: Record<string, any>, options?: QueryOptions) => Promise<QueryResult | null>;
|
|
20
|
+
query: (cypher: string, parameters?: Record<string, any>) => Promise<any[]>;
|
|
21
|
+
loading: boolean;
|
|
22
|
+
error: Error;
|
|
23
|
+
data: QueryResult;
|
|
24
|
+
queuePosition: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Hook for streaming large query results
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* const { stream, isStreaming, error, cancel } = useStreamingQuery('graph_123')
|
|
32
|
+
*
|
|
33
|
+
* const handleStream = async () => {
|
|
34
|
+
* const iterator = stream('MATCH (n) RETURN n')
|
|
35
|
+
* for await (const batch of iterator) {
|
|
36
|
+
* console.log('Received batch:', batch)
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function useStreamingQuery(graphId: string): {
|
|
42
|
+
stream: (query: string, parameters?: Record<string, any>, chunkSize?: number) => AsyncIterableIterator<any[]>;
|
|
43
|
+
isStreaming: boolean;
|
|
44
|
+
error: Error;
|
|
45
|
+
rowsReceived: number;
|
|
46
|
+
cancel: () => void;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Hook for monitoring long-running operations
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* const { monitor, status, progress, error, result } = useOperation<BackupResult>()
|
|
54
|
+
*
|
|
55
|
+
* const handleBackup = async () => {
|
|
56
|
+
* const { operation_id } = await createBackup({ ... })
|
|
57
|
+
* const result = await monitor(operation_id)
|
|
58
|
+
* console.log('Backup completed:', result)
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function useOperation<T = any>(operationId?: string): {
|
|
63
|
+
monitor: (id: string, timeout?: number) => Promise<OperationResult<T> | null>;
|
|
64
|
+
cancel: (id: string) => Promise<void>;
|
|
65
|
+
status: "completed" | "error" | "idle" | "running";
|
|
66
|
+
progress: OperationProgress;
|
|
67
|
+
error: Error;
|
|
68
|
+
result: OperationResult<T>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Hook for monitoring multiple operations concurrently
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```tsx
|
|
75
|
+
* const { monitorAll, results, allCompleted, hasErrors } = useMultipleOperations()
|
|
76
|
+
*
|
|
77
|
+
* const handleMultiple = async () => {
|
|
78
|
+
* const operations = await Promise.all([
|
|
79
|
+
* createBackup(...),
|
|
80
|
+
* createExport(...),
|
|
81
|
+
* ])
|
|
82
|
+
*
|
|
83
|
+
* const results = await monitorAll(operations.map(op => op.operation_id))
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function useMultipleOperations<T = any>(): {
|
|
88
|
+
monitorAll: (operationIds: string[]) => Promise<Map<string, OperationResult<T>>>;
|
|
89
|
+
results: Map<string, OperationResult<T>>;
|
|
90
|
+
errors: Map<string, Error>;
|
|
91
|
+
loading: boolean;
|
|
92
|
+
allCompleted: boolean;
|
|
93
|
+
hasErrors: boolean;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Hook that provides access to all SDK extension clients
|
|
97
|
+
* Useful when you need direct access to the underlying clients
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```tsx
|
|
101
|
+
* const clients = useSDKClients()
|
|
102
|
+
*
|
|
103
|
+
* // Direct access to clients
|
|
104
|
+
* const result = await clients.query.query('graph_123', 'MATCH (n) RETURN n')
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function useSDKClients(): {
|
|
108
|
+
query: QueryClient | null;
|
|
109
|
+
operations: OperationClient | null;
|
|
110
|
+
};
|