@robosystems/client 0.2.42 → 0.2.44

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 (73) hide show
  1. package/extensions/LedgerClient.d.ts +88 -0
  2. package/extensions/LedgerClient.js +143 -0
  3. package/extensions/LedgerClient.ts +267 -0
  4. package/extensions/ReportClient.d.ts +14 -6
  5. package/extensions/ReportClient.js +19 -15
  6. package/extensions/ReportClient.ts +37 -21
  7. package/extensions/hooks.d.ts +1 -40
  8. package/extensions/hooks.js +0 -134
  9. package/extensions/hooks.ts +0 -156
  10. package/extensions/index.d.ts +2 -24
  11. package/extensions/index.js +1 -65
  12. package/extensions/index.test.ts +4 -38
  13. package/extensions/index.ts +0 -78
  14. package/index.ts +2 -2
  15. package/package.json +1 -1
  16. package/sdk/index.d.ts +2 -2
  17. package/sdk/index.js +11 -4
  18. package/sdk/index.ts +2 -2
  19. package/sdk/sdk.gen.d.ts +51 -9
  20. package/sdk/sdk.gen.js +105 -16
  21. package/sdk/sdk.gen.ts +101 -12
  22. package/sdk/types.gen.d.ts +812 -146
  23. package/sdk/types.gen.ts +844 -128
  24. package/sdk-extensions/LedgerClient.d.ts +88 -0
  25. package/sdk-extensions/LedgerClient.js +143 -0
  26. package/sdk-extensions/LedgerClient.ts +267 -0
  27. package/sdk-extensions/ReportClient.d.ts +14 -6
  28. package/sdk-extensions/ReportClient.js +19 -15
  29. package/sdk-extensions/ReportClient.ts +37 -21
  30. package/sdk-extensions/hooks.d.ts +1 -40
  31. package/sdk-extensions/hooks.js +0 -134
  32. package/sdk-extensions/hooks.ts +0 -156
  33. package/sdk-extensions/index.d.ts +2 -24
  34. package/sdk-extensions/index.js +1 -65
  35. package/sdk-extensions/index.test.ts +4 -38
  36. package/sdk-extensions/index.ts +0 -78
  37. package/sdk.gen.d.ts +51 -9
  38. package/sdk.gen.js +105 -16
  39. package/sdk.gen.ts +101 -12
  40. package/types.gen.d.ts +812 -146
  41. package/types.gen.ts +844 -128
  42. package/extensions/DocumentClient.d.ts +0 -77
  43. package/extensions/DocumentClient.js +0 -136
  44. package/extensions/DocumentClient.ts +0 -232
  45. package/extensions/FileClient.d.ts +0 -57
  46. package/extensions/FileClient.js +0 -246
  47. package/extensions/FileClient.ts +0 -330
  48. package/extensions/GraphClient.d.ts +0 -91
  49. package/extensions/GraphClient.js +0 -244
  50. package/extensions/GraphClient.test.ts +0 -455
  51. package/extensions/GraphClient.ts +0 -371
  52. package/extensions/MaterializationClient.d.ts +0 -61
  53. package/extensions/MaterializationClient.js +0 -157
  54. package/extensions/MaterializationClient.ts +0 -223
  55. package/extensions/TableClient.d.ts +0 -38
  56. package/extensions/TableClient.js +0 -92
  57. package/extensions/TableClient.ts +0 -132
  58. package/sdk-extensions/DocumentClient.d.ts +0 -77
  59. package/sdk-extensions/DocumentClient.js +0 -136
  60. package/sdk-extensions/DocumentClient.ts +0 -232
  61. package/sdk-extensions/FileClient.d.ts +0 -57
  62. package/sdk-extensions/FileClient.js +0 -246
  63. package/sdk-extensions/FileClient.ts +0 -330
  64. package/sdk-extensions/GraphClient.d.ts +0 -91
  65. package/sdk-extensions/GraphClient.js +0 -244
  66. package/sdk-extensions/GraphClient.test.ts +0 -455
  67. package/sdk-extensions/GraphClient.ts +0 -371
  68. package/sdk-extensions/MaterializationClient.d.ts +0 -61
  69. package/sdk-extensions/MaterializationClient.js +0 -157
  70. package/sdk-extensions/MaterializationClient.ts +0 -223
  71. package/sdk-extensions/TableClient.d.ts +0 -38
  72. package/sdk-extensions/TableClient.js +0 -92
  73. package/sdk-extensions/TableClient.ts +0 -132
@@ -1,371 +0,0 @@
1
- 'use client'
2
-
3
- /**
4
- * Graph Management Client
5
- * Provides high-level graph management operations with automatic operation monitoring.
6
- * Supports SSE (Server-Sent Events) for real-time updates with polling fallback.
7
- */
8
-
9
- import { createGraph, getGraphs, getOperationStatus } from '../sdk/sdk.gen'
10
- import type { GraphMetadata, InitialEntityData } from '../sdk/types.gen'
11
- import { OperationClient } from './OperationClient'
12
-
13
- /**
14
- * Error thrown when a graph operation fails (as reported by the server)
15
- * This is distinct from connection/SSE errors
16
- */
17
- export class GraphOperationError extends Error {
18
- constructor(message: string) {
19
- super(message)
20
- this.name = 'GraphOperationError'
21
- }
22
- }
23
-
24
- // API Response Types
25
- interface GraphCreateResponse {
26
- graph_id?: string
27
- operation_id?: string
28
- }
29
-
30
- interface OperationStatusResponse {
31
- status?: 'pending' | 'completed' | 'failed' | string
32
- result?: {
33
- graph_id?: string
34
- }
35
- error?: string
36
- message?: string
37
- }
38
-
39
- interface GraphApiData {
40
- graph_id?: string
41
- id?: string
42
- graph_name?: string
43
- name?: string
44
- description?: string
45
- schema_extensions?: string[]
46
- tags?: string[]
47
- created_at?: string
48
- status?: string
49
- }
50
-
51
- interface GetGraphsResponse {
52
- graphs?: GraphApiData[]
53
- }
54
-
55
- export interface GraphMetadataInput {
56
- graphName: string
57
- description?: string
58
- schemaExtensions?: string[]
59
- tags?: string[]
60
- }
61
-
62
- export interface InitialEntityInput {
63
- name: string
64
- uri: string
65
- category?: string
66
- sic?: string
67
- sicDescription?: string
68
- }
69
-
70
- export interface GraphInfo {
71
- graphId: string
72
- graphName: string
73
- description?: string
74
- schemaExtensions?: string[]
75
- tags?: string[]
76
- createdAt?: string
77
- status?: string
78
- }
79
-
80
- export interface CreateGraphOptions {
81
- createEntity?: boolean
82
- timeout?: number
83
- pollInterval?: number
84
- onProgress?: (message: string) => void
85
- useSSE?: boolean
86
- }
87
-
88
- export class GraphClient {
89
- private operationClient: OperationClient
90
- private config: {
91
- baseUrl: string
92
- credentials?: 'include' | 'same-origin' | 'omit'
93
- headers?: Record<string, string>
94
- token?: string
95
- }
96
-
97
- constructor(config: {
98
- baseUrl: string
99
- credentials?: 'include' | 'same-origin' | 'omit'
100
- headers?: Record<string, string>
101
- token?: string
102
- }) {
103
- this.config = config
104
- this.operationClient = new OperationClient(config)
105
- }
106
-
107
- /**
108
- * Create a graph and wait for completion
109
- *
110
- * Uses SSE (Server-Sent Events) for real-time progress updates with
111
- * automatic fallback to polling if SSE connection fails.
112
- *
113
- * @param metadata - Graph metadata (name, description, etc.)
114
- * @param initialEntity - Optional initial entity to create
115
- * @param options - Additional options including:
116
- * - createEntity: Whether to create the entity node and upload initial data.
117
- * Only applies when initialEntity is provided. Set to false to
118
- * create graph without populating entity data (useful for file-based ingestion).
119
- * Defaults to true.
120
- * - timeout: Maximum time to wait in milliseconds (default: 60000)
121
- * - pollInterval: Time between status checks in milliseconds (default: 2000, for polling fallback)
122
- * - onProgress: Callback for progress updates
123
- * - useSSE: Whether to try SSE first (default: true). Falls back to polling on failure.
124
- * @returns The graph ID when creation completes
125
- */
126
- async createGraphAndWait(
127
- metadata: GraphMetadataInput,
128
- initialEntity?: InitialEntityInput,
129
- options: CreateGraphOptions = {}
130
- ): Promise<string> {
131
- const {
132
- createEntity = true,
133
- timeout = 60000,
134
- pollInterval = 2000,
135
- onProgress,
136
- useSSE = true,
137
- } = options
138
-
139
- if (!this.config.token) {
140
- throw new Error('No API key provided. Set token in config.')
141
- }
142
-
143
- // Build initial entity if provided
144
- let initialEntityData: InitialEntityData | undefined
145
- if (initialEntity) {
146
- initialEntityData = {
147
- name: initialEntity.name,
148
- uri: initialEntity.uri,
149
- category: initialEntity.category,
150
- sic: initialEntity.sic,
151
- sic_description: initialEntity.sicDescription,
152
- }
153
- }
154
-
155
- // Build API metadata
156
- const apiMetadata: GraphMetadata = {
157
- graph_name: metadata.graphName,
158
- description: metadata.description,
159
- schema_extensions: metadata.schemaExtensions || [],
160
- tags: metadata.tags || [],
161
- }
162
-
163
- if (onProgress) {
164
- onProgress(`Creating graph: ${metadata.graphName}`)
165
- }
166
-
167
- // Create graph request - SDK expects options format, not data format
168
- const response = await createGraph({
169
- body: {
170
- metadata: apiMetadata,
171
- initial_entity: initialEntityData || null,
172
- create_entity: createEntity,
173
- },
174
- })
175
-
176
- // Check if we got immediate graph_id
177
- const responseData = response.data as GraphCreateResponse
178
- if (responseData?.graph_id) {
179
- if (onProgress) {
180
- onProgress(`Graph created: ${responseData.graph_id}`)
181
- }
182
- return responseData.graph_id
183
- }
184
-
185
- // Otherwise, we have an operation_id to monitor
186
- if (!responseData?.operation_id) {
187
- throw new Error('No graph_id or operation_id in response')
188
- }
189
-
190
- const operationId = responseData.operation_id
191
-
192
- if (onProgress) {
193
- onProgress(`Graph creation queued (operation: ${operationId})`)
194
- }
195
-
196
- // Try SSE first, fall back to polling
197
- if (useSSE) {
198
- try {
199
- return await this.waitWithSSE(operationId, timeout, onProgress)
200
- } catch (error) {
201
- // Only fall back to polling for SSE connection failures
202
- // If it's a GraphOperationError, the operation actually failed - don't retry with polling
203
- if (error instanceof GraphOperationError) {
204
- throw error
205
- }
206
- // SSE connection failed, fall back to polling
207
- if (onProgress) {
208
- onProgress('SSE unavailable, using polling...')
209
- }
210
- }
211
- }
212
-
213
- // Fallback to polling
214
- return await this.waitWithPolling(operationId, timeout, pollInterval, onProgress)
215
- }
216
-
217
- /**
218
- * Wait for operation completion using SSE stream
219
- */
220
- private async waitWithSSE(
221
- operationId: string,
222
- timeout: number,
223
- onProgress?: (message: string) => void
224
- ): Promise<string> {
225
- const result = await this.operationClient.monitorOperation<{ graph_id?: string }>(operationId, {
226
- timeout,
227
- onProgress: (progress) => {
228
- if (onProgress) {
229
- if (progress.progressPercent !== undefined) {
230
- onProgress(`${progress.message} (${Math.round(progress.progressPercent)}%)`)
231
- } else {
232
- onProgress(progress.message)
233
- }
234
- }
235
- },
236
- })
237
-
238
- if (!result.success) {
239
- throw new GraphOperationError(result.error || 'Graph creation failed')
240
- }
241
-
242
- const graphId = result.result?.graph_id
243
- if (!graphId) {
244
- throw new GraphOperationError('Operation completed but no graph_id in result')
245
- }
246
-
247
- if (onProgress) {
248
- onProgress(`Graph created: ${graphId}`)
249
- }
250
-
251
- return graphId
252
- }
253
-
254
- /**
255
- * Wait for operation completion using polling
256
- */
257
- private async waitWithPolling(
258
- operationId: string,
259
- timeout: number,
260
- pollInterval: number,
261
- onProgress?: (message: string) => void
262
- ): Promise<string> {
263
- const maxAttempts = Math.floor(timeout / pollInterval)
264
-
265
- for (let attempt = 0; attempt < maxAttempts; attempt++) {
266
- await new Promise((resolve) => setTimeout(resolve, pollInterval))
267
-
268
- const statusResponse = await getOperationStatus({
269
- path: { operation_id: operationId },
270
- })
271
-
272
- const statusData = statusResponse.data as OperationStatusResponse
273
- const status = statusData?.status
274
-
275
- if (onProgress) {
276
- onProgress(`Status: ${status} (attempt ${attempt + 1}/${maxAttempts})`)
277
- }
278
-
279
- if (status === 'completed') {
280
- const result = statusData?.result
281
- const graphId = result?.graph_id
282
-
283
- if (graphId) {
284
- if (onProgress) {
285
- onProgress(`Graph created: ${graphId}`)
286
- }
287
- return graphId
288
- } else {
289
- throw new GraphOperationError('Operation completed but no graph_id in result')
290
- }
291
- } else if (status === 'failed') {
292
- const error = statusData?.error || statusData?.message || 'Unknown error'
293
- throw new GraphOperationError(`Graph creation failed: ${error}`)
294
- }
295
- }
296
-
297
- throw new GraphOperationError(`Graph creation timed out after ${timeout}ms`)
298
- }
299
-
300
- /**
301
- * Get information about a graph
302
- */
303
- async getGraphInfo(graphId: string): Promise<GraphInfo> {
304
- if (!this.config.token) {
305
- throw new Error('No API key provided. Set token in config.')
306
- }
307
-
308
- // Use getGraphs to list all graphs and find the one we want
309
- // Note: This is a workaround since there's no dedicated getGraph endpoint yet
310
- const response = await getGraphs()
311
- const graphs = (response.data as GetGraphsResponse)?.graphs || []
312
-
313
- const graph = graphs.find((g) => g.graph_id === graphId || g.id === graphId)
314
-
315
- if (!graph) {
316
- throw new Error(`Graph not found: ${graphId}`)
317
- }
318
-
319
- return {
320
- graphId: graph.graph_id || graph.id,
321
- graphName: graph.graph_name || graph.name,
322
- description: graph.description,
323
- schemaExtensions: graph.schema_extensions,
324
- tags: graph.tags,
325
- createdAt: graph.created_at,
326
- status: graph.status,
327
- }
328
- }
329
-
330
- /**
331
- * List all graphs
332
- */
333
- async listGraphs(): Promise<GraphInfo[]> {
334
- if (!this.config.token) {
335
- throw new Error('No API key provided. Set token in config.')
336
- }
337
-
338
- const response = await getGraphs()
339
- const graphs = (response.data as GetGraphsResponse)?.graphs || []
340
-
341
- return graphs.map((graph) => ({
342
- graphId: graph.graph_id || graph.id,
343
- graphName: graph.graph_name || graph.name,
344
- description: graph.description,
345
- schemaExtensions: graph.schema_extensions,
346
- tags: graph.tags,
347
- createdAt: graph.created_at,
348
- status: graph.status,
349
- }))
350
- }
351
-
352
- /**
353
- * Delete a graph
354
- * Note: This will be implemented when the deleteGraph endpoint is available in the SDK
355
- */
356
- async deleteGraph(_graphId: string): Promise<void> {
357
- throw new Error('deleteGraph is not yet implemented - waiting for SDK endpoint to be generated')
358
- // TODO: Implement when deleteGraph endpoint is available
359
- // const response = await deleteGraph({ path: { graph_id: _graphId } })
360
- // if (response.status !== 200 && response.status !== 204) {
361
- // throw new Error(`Failed to delete graph: ${response.status}`)
362
- // }
363
- }
364
-
365
- /**
366
- * Clean up resources
367
- */
368
- close(): void {
369
- this.operationClient.closeAll()
370
- }
371
- }
@@ -1,61 +0,0 @@
1
- export interface MaterializationOptions {
2
- ignoreErrors?: boolean;
3
- rebuild?: boolean;
4
- force?: boolean;
5
- timeout?: number;
6
- onProgress?: (message: string) => void;
7
- }
8
- export interface MaterializationResult {
9
- status: string;
10
- wasStale: boolean;
11
- staleReason?: string;
12
- tablesMaterialized: string[];
13
- totalRows: number;
14
- executionTimeMs: number;
15
- message: string;
16
- success: boolean;
17
- error?: string;
18
- }
19
- export interface MaterializationStatus {
20
- graphId: string;
21
- isStale: boolean;
22
- staleReason?: string;
23
- staleSince?: string;
24
- lastMaterializedAt?: string;
25
- materializationCount: number;
26
- hoursSinceMaterialization?: number;
27
- message: string;
28
- }
29
- export declare class MaterializationClient {
30
- private config;
31
- private operationClient;
32
- constructor(config: {
33
- baseUrl: string;
34
- credentials?: 'include' | 'same-origin' | 'omit';
35
- headers?: Record<string, string>;
36
- token?: string;
37
- });
38
- /**
39
- * Materialize graph from DuckDB staging tables
40
- *
41
- * Submits a materialization job to Dagster and monitors progress via SSE.
42
- * The operation runs asynchronously on the server but this method waits
43
- * for completion and returns the final result.
44
- */
45
- materialize(graphId: string, options?: MaterializationOptions): Promise<MaterializationResult>;
46
- /**
47
- * Convert SSE operation result to MaterializationResult
48
- */
49
- private convertOperationResult;
50
- /**
51
- * Get current materialization status for the graph
52
- *
53
- * Shows whether the graph is stale (DuckDB has changes not yet in graph database),
54
- * when it was last materialized, and how long since last materialization.
55
- */
56
- status(graphId: string): Promise<MaterializationStatus | null>;
57
- /**
58
- * Close any active SSE connections
59
- */
60
- close(): void;
61
- }
@@ -1,157 +0,0 @@
1
- 'use client';
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MaterializationClient = void 0;
5
- /**
6
- * Materialization Client for RoboSystems API
7
- *
8
- * Manages graph materialization from DuckDB staging tables.
9
- * Submits materialization jobs to Dagster and monitors progress via SSE.
10
- */
11
- const sdk_gen_1 = require("../sdk/sdk.gen");
12
- const OperationClient_1 = require("./OperationClient");
13
- class MaterializationClient {
14
- constructor(config) {
15
- this.config = config;
16
- this.operationClient = new OperationClient_1.OperationClient(config);
17
- }
18
- /**
19
- * Materialize graph from DuckDB staging tables
20
- *
21
- * Submits a materialization job to Dagster and monitors progress via SSE.
22
- * The operation runs asynchronously on the server but this method waits
23
- * for completion and returns the final result.
24
- */
25
- async materialize(graphId, options = {}) {
26
- try {
27
- options.onProgress?.('Submitting materialization job...');
28
- const request = {
29
- ignore_errors: options.ignoreErrors ?? true,
30
- rebuild: options.rebuild ?? false,
31
- force: options.force ?? false,
32
- };
33
- const response = await (0, sdk_gen_1.materializeGraph)({
34
- path: { graph_id: graphId },
35
- body: request,
36
- });
37
- if (response.error || !response.data) {
38
- return {
39
- status: 'failed',
40
- wasStale: false,
41
- tablesMaterialized: [],
42
- totalRows: 0,
43
- executionTimeMs: 0,
44
- message: `Failed to materialize graph: ${response.error}`,
45
- success: false,
46
- error: `Failed to materialize graph: ${response.error}`,
47
- };
48
- }
49
- const queuedResponse = response.data;
50
- const operationId = queuedResponse.operation_id;
51
- options.onProgress?.(`Materialization queued (operation: ${operationId})`);
52
- // Monitor the operation via SSE until completion
53
- const opResult = await this.operationClient.monitorOperation(operationId, {
54
- timeout: (options.timeout ?? 600) * 1000, // Convert to milliseconds, 10 minute default
55
- onProgress: (progress) => {
56
- if (options.onProgress) {
57
- let msg = progress.message;
58
- if (progress.progressPercent !== undefined) {
59
- msg += ` (${progress.progressPercent.toFixed(0)}%)`;
60
- }
61
- options.onProgress(msg);
62
- }
63
- },
64
- });
65
- // Convert operation result to materialization result
66
- return this.convertOperationResult(opResult, options);
67
- }
68
- catch (error) {
69
- return {
70
- status: 'failed',
71
- wasStale: false,
72
- tablesMaterialized: [],
73
- totalRows: 0,
74
- executionTimeMs: 0,
75
- message: error instanceof Error ? error.message : String(error),
76
- success: false,
77
- error: error instanceof Error ? error.message : String(error),
78
- };
79
- }
80
- }
81
- /**
82
- * Convert SSE operation result to MaterializationResult
83
- */
84
- convertOperationResult(opResult, options) {
85
- if (opResult.success) {
86
- // Extract details from SSE completion event result
87
- const sseResult = opResult.result || {};
88
- const tables = sseResult.tables_materialized || [];
89
- const rows = sseResult.total_rows || 0;
90
- const timeMs = sseResult.execution_time_ms || 0;
91
- options.onProgress?.(`✅ Materialization complete: ${tables.length} tables, ` +
92
- `${rows.toLocaleString()} rows in ${timeMs.toFixed(2)}ms`);
93
- return {
94
- status: 'success',
95
- wasStale: sseResult.was_stale || false,
96
- staleReason: sseResult.stale_reason,
97
- tablesMaterialized: tables,
98
- totalRows: rows,
99
- executionTimeMs: timeMs,
100
- message: sseResult.message || 'Graph materialized successfully',
101
- success: true,
102
- };
103
- }
104
- else {
105
- // Operation failed or was cancelled
106
- return {
107
- status: 'failed',
108
- wasStale: false,
109
- tablesMaterialized: [],
110
- totalRows: 0,
111
- executionTimeMs: 0,
112
- message: opResult.error || 'Operation failed',
113
- success: false,
114
- error: opResult.error,
115
- };
116
- }
117
- }
118
- /**
119
- * Get current materialization status for the graph
120
- *
121
- * Shows whether the graph is stale (DuckDB has changes not yet in graph database),
122
- * when it was last materialized, and how long since last materialization.
123
- */
124
- async status(graphId) {
125
- try {
126
- const response = await (0, sdk_gen_1.getMaterializationStatus)({
127
- path: { graph_id: graphId },
128
- });
129
- if (response.error || !response.data) {
130
- console.error('Failed to get materialization status:', response.error);
131
- return null;
132
- }
133
- const status = response.data;
134
- return {
135
- graphId: status.graph_id,
136
- isStale: status.is_stale,
137
- staleReason: status.stale_reason,
138
- staleSince: status.stale_since,
139
- lastMaterializedAt: status.last_materialized_at,
140
- materializationCount: status.materialization_count || 0,
141
- hoursSinceMaterialization: status.hours_since_materialization,
142
- message: status.message,
143
- };
144
- }
145
- catch (error) {
146
- console.error('Failed to get materialization status:', error);
147
- return null;
148
- }
149
- }
150
- /**
151
- * Close any active SSE connections
152
- */
153
- close() {
154
- this.operationClient.closeAll();
155
- }
156
- }
157
- exports.MaterializationClient = MaterializationClient;