@robosystems/client 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/client/client.gen.d.ts +2 -0
  2. package/client/client.gen.js +153 -0
  3. package/client/index.d.ts +7 -0
  4. package/client/index.js +15 -0
  5. package/client/types.gen.d.ts +122 -0
  6. package/client/types.gen.js +4 -0
  7. package/client/utils.gen.d.ts +45 -0
  8. package/client/utils.gen.js +296 -0
  9. package/client.gen.d.ts +12 -0
  10. package/client.gen.js +8 -0
  11. package/core/auth.gen.d.ts +18 -0
  12. package/core/auth.gen.js +18 -0
  13. package/core/bodySerializer.gen.d.ts +17 -0
  14. package/core/bodySerializer.gen.js +57 -0
  15. package/core/params.gen.d.ts +33 -0
  16. package/core/params.gen.js +92 -0
  17. package/core/pathSerializer.gen.d.ts +33 -0
  18. package/core/pathSerializer.gen.js +123 -0
  19. package/core/types.gen.d.ts +78 -0
  20. package/core/types.gen.js +4 -0
  21. package/extensions/OperationClient.d.js +45 -0
  22. package/extensions/OperationClient.d.ts +64 -0
  23. package/extensions/OperationClient.js +297 -0
  24. package/extensions/OperationClient.ts +322 -0
  25. package/extensions/QueryClient.d.js +22 -0
  26. package/extensions/QueryClient.d.ts +50 -0
  27. package/extensions/QueryClient.js +245 -0
  28. package/extensions/QueryClient.ts +283 -0
  29. package/extensions/SSEClient.d.js +35 -0
  30. package/extensions/SSEClient.d.ts +48 -0
  31. package/extensions/SSEClient.js +166 -0
  32. package/extensions/SSEClient.ts +189 -0
  33. package/extensions/config.d.js +25 -0
  34. package/extensions/config.d.ts +32 -0
  35. package/extensions/config.js +66 -0
  36. package/extensions/config.ts +91 -0
  37. package/extensions/hooks.d.js +80 -0
  38. package/extensions/hooks.d.ts +110 -0
  39. package/extensions/hooks.js +435 -0
  40. package/extensions/hooks.ts +438 -0
  41. package/extensions/index.d.js +35 -0
  42. package/extensions/index.d.ts +46 -0
  43. package/extensions/index.js +118 -0
  44. package/extensions/index.ts +123 -0
  45. package/package.json +3 -2
  46. package/prepare.js +10 -0
  47. package/sdk.gen.d.ts +1145 -0
  48. package/sdk.gen.js +2436 -0
  49. package/types.gen.d.ts +5712 -0
  50. package/types.gen.js +3 -0
@@ -0,0 +1,166 @@
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
+
9
+
10
+
11
+
12
+ export enum EventType {
13
+ OPERATION_STARTED = 'operation_started',
14
+ OPERATION_PROGRESS = 'operation_progress',
15
+ OPERATION_COMPLETED = 'operation_completed',
16
+ OPERATION_ERROR = 'operation_error',
17
+ OPERATION_CANCELLED = 'operation_cancelled',
18
+ DATA_CHUNK = 'data_chunk',
19
+ METADATA = 'metadata',
20
+ HEARTBEAT = 'heartbeat',
21
+ QUEUE_UPDATE = 'queue_update',
22
+ }
23
+
24
+ export class SSEClient {
25
+ private config
26
+ private eventSource?
27
+ private reconnectAttempts = 0
28
+ private lastEventId?
29
+ private closed = false
30
+ private listeners void>> = new Map()
31
+
32
+ constructor(config) {
33
+ this.config = {
34
+ maxRetries,
35
+ retryDelay,
36
+ heartbeatInterval,
37
+ ...config,
38
+ }
39
+ }
40
+
41
+ async connect(operationId, fromSequence = 0) {
42
+ return new Promise((resolve, reject) => {
43
+ const url = `${this.config.baseUrl}/v1/operations/${operationId}/stream?from_sequence=${fromSequence}`
44
+
45
+ this.eventSource = new EventSource(url, {
46
+ withCredentials.config.credentials === 'include',
47
+ })
48
+
49
+ const connectionTimeout = setTimeout(() => {
50
+ reject(new Error('Connection timeout'))
51
+ this.close()
52
+ }, 10000)
53
+
54
+ this.eventSource.onopen = () => {
55
+ clearTimeout(connectionTimeout)
56
+ this.reconnectAttempts = 0
57
+ this.emit('connected', null)
58
+ resolve()
59
+ }
60
+
61
+ this.eventSource.onerror = (error) => {
62
+ clearTimeout(connectionTimeout)
63
+ if (!this.closed) {
64
+ this.handleError(error, operationId, fromSequence)
65
+ }
66
+ }
67
+
68
+ this.eventSource.onmessage = (event) => {
69
+ this.handleMessage(event)
70
+ }
71
+
72
+ // Set up specific event listeners
73
+ Object.values(EventType).forEach((eventType) => {
74
+ this.eventSource!.addEventListener(eventType, (event) => {
75
+ this.handleTypedEvent(eventType, event)
76
+ })
77
+ })
78
+ })
79
+ }
80
+
81
+ private handleMessage(event) {
82
+ try {
83
+ const data = JSON.parse(event.data)
84
+ const sseEvent = {
85
+ event.type || 'message',
86
+ data,
87
+ id.lastEventId,
88
+ timestamp Date(),
89
+ }
90
+
91
+ this.lastEventId = event.lastEventId
92
+ this.emit('event', sseEvent)
93
+ } catch (error) {
94
+ this.emit('parse_error', { error, rawData.data })
95
+ }
96
+ }
97
+
98
+ private handleTypedEvent(eventType, event) {
99
+ try {
100
+ const data = JSON.parse(event.data)
101
+ this.lastEventId = event.lastEventId
102
+ this.emit(eventType, data)
103
+
104
+ // Check for completion events
105
+ if (
106
+ eventType === EventType.OPERATION_COMPLETED ||
107
+ eventType === EventType.OPERATION_ERROR ||
108
+ eventType === EventType.OPERATION_CANCELLED
109
+ ) {
110
+ this.close()
111
+ }
112
+ } catch (error) {
113
+ this.emit('parse_error', { error, rawData.data })
114
+ }
115
+ }
116
+
117
+ private async handleError(error, operationId, fromSequence) {
118
+ if (this.closed) return
119
+
120
+ if (this.reconnectAttempts {
121
+ const resumeFrom = this.lastEventId ? parseInt(this.lastEventId) + 1
122
+ this.connect(operationId, resumeFrom).catch(() => {
123
+ // Error handled in connect
124
+ })
125
+ }, delay)
126
+ } else {
127
+ this.emit('max_retries_exceeded', error)
128
+ this.close()
129
+ }
130
+ }
131
+
132
+ on(event, listener) {
133
+ if (!this.listeners.has(event)) {
134
+ this.listeners.set(event, new Set())
135
+ }
136
+ this.listeners.get(event)!.add(listener)
137
+ }
138
+
139
+ off(event, listener) {
140
+ const listeners = this.listeners.get(event)
141
+ if (listeners) {
142
+ listeners.delete(listener)
143
+ }
144
+ }
145
+
146
+ private emit(event, data) {
147
+ const listeners = this.listeners.get(event)
148
+ if (listeners) {
149
+ listeners.forEach((listener) => listener(data))
150
+ }
151
+ }
152
+
153
+ close() {
154
+ this.closed = true
155
+ if (this.eventSource) {
156
+ this.eventSource.close()
157
+ this.eventSource = undefined
158
+ }
159
+ this.emit('closed', null)
160
+ this.listeners.clear()
161
+ }
162
+
163
+ isConnected() {
164
+ return this.eventSource !== undefined && this.eventSource.readyState === EventSource.OPEN
165
+ }
166
+ }
@@ -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,25 @@
1
+ /**
2
+ * Configuration for SDK extensions
3
+ * Provides centralized configuration for CORS, credentials, and other settings
4
+ */
5
+
6
+ /**
7
+ * Set global configuration for SDK extensions
8
+ * @param config Partial configuration to merge with defaults
9
+ */
10
+ export declare function setSDKExtensionsConfig(config);
11
+ /**
12
+ * Get current SDK extensions configuration
13
+ * @returns Current configuration
14
+ */
15
+ export declare function getSDKExtensionsConfig();
16
+ /**
17
+ * Reset configuration to defaults
18
+ */
19
+ export declare function resetSDKExtensionsConfig();
20
+ /**
21
+ * Get configuration for a specific environment
22
+ * @param env Environment name (production, staging, development)
23
+ * @returns Environment-specific configuration
24
+ */
25
+ export declare function getEnvironmentConfig(env? | 'staging' | 'development');
@@ -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,66 @@
1
+ 'use client'
2
+
3
+ /**
4
+ * Configuration for SDK extensions
5
+ * Provides centralized configuration for CORS, credentials, and other settings
6
+ */
7
+
8
+
9
+
10
+ // Default configuration
11
+ const defaultConfig = {
12
+ baseUrl.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
13
+ credentials,
14
+ timeout,
15
+ maxRetries,
16
+ retryDelay,
17
+ }
18
+
19
+ // Global configuration singleton
20
+ let globalConfig = { ...defaultConfig }
21
+
22
+ /**
23
+ * Set global configuration for SDK extensions
24
+ * @param config Partial configuration to merge with defaults
25
+ */
26
+ export function setSDKExtensionsConfig(config) {
27
+ globalConfig = {
28
+ ...globalConfig,
29
+ ...config,
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Get current SDK extensions configuration
35
+ * @returns Current configuration
36
+ */
37
+ export function getSDKExtensionsConfig() {
38
+ return { ...globalConfig }
39
+ }
40
+
41
+ /**
42
+ * Reset configuration to defaults
43
+ */
44
+ export function resetSDKExtensionsConfig() {
45
+ globalConfig = { ...defaultConfig }
46
+ }
47
+
48
+ /**
49
+ * Get configuration for a specific environment
50
+ * @param env Environment name (production, staging, development)
51
+ * @returns Environment-specific configuration
52
+ */
53
+ export function getEnvironmentConfig(
54
+ env | 'staging' | 'development' = 'development'
55
+ ) {
56
+ const baseConfigs> = {
57
+ production,
58
+ staging,
59
+ development,
60
+ }
61
+
62
+ return {
63
+ ...defaultConfig,
64
+ ...baseConfigs[env],
65
+ }
66
+ }
@@ -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,80 @@
1
+ import { OperationProgress, OperationResult } from './OperationClient';
2
+ import { OperationClient } from './OperationClient';
3
+ import { 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);
19
+ /**
20
+ * Hook for streaming large query results
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const { stream, isStreaming, error, cancel } = useStreamingQuery('graph_123')
25
+ *
26
+ * const handleStream = async () => {
27
+ * const iterator = stream('MATCH (n) RETURN n')
28
+ * for await (const batch of iterator) {
29
+ * console.log('Received batch:', batch)
30
+ * }
31
+ * }
32
+ * ```
33
+ */
34
+ export declare function useStreamingQuery(graphId);
35
+ /**
36
+ * Hook for monitoring long-running operations
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * const { monitor, status, progress, error, result } = useOperation()
41
+ *
42
+ * const handleBackup = async () => {
43
+ * const { operation_id } = await createBackup({ ... })
44
+ * const result = await monitor(operation_id)
45
+ * console.log('Backup completed:', result)
46
+ * }
47
+ * ```
48
+ */
49
+ export declare function useOperation(operationId?);
50
+ /**
51
+ * Hook for monitoring multiple operations concurrently
52
+ *
53
+ * @example
54
+ * ```tsx
55
+ * const { monitorAll, results, allCompleted, hasErrors } = useMultipleOperations()
56
+ *
57
+ * const handleMultiple = async () => {
58
+ * const operations = await Promise.all([
59
+ * createBackup(...),
60
+ * createExport(...),
61
+ * ])
62
+ *
63
+ * const results = await monitorAll(operations.map(op => op.operation_id))
64
+ * }
65
+ * ```
66
+ */
67
+ export declare function useMultipleOperations();
68
+ /**
69
+ * Hook that provides access to all SDK extension clients
70
+ * Useful when you need direct access to the underlying clients
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * const clients = useSDKClients()
75
+ *
76
+ * // Direct access to clients
77
+ * const result = await clients.query.query('graph_123', 'MATCH (n) RETURN n')
78
+ * ```
79
+ */
80
+ export declare function useSDKClients();