@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.
- package/extensions/LedgerClient.d.ts +88 -0
- package/extensions/LedgerClient.js +143 -0
- package/extensions/LedgerClient.ts +267 -0
- package/extensions/ReportClient.d.ts +14 -6
- package/extensions/ReportClient.js +19 -15
- package/extensions/ReportClient.ts +37 -21
- package/extensions/hooks.d.ts +1 -40
- package/extensions/hooks.js +0 -134
- package/extensions/hooks.ts +0 -156
- package/extensions/index.d.ts +2 -24
- package/extensions/index.js +1 -65
- package/extensions/index.test.ts +4 -38
- package/extensions/index.ts +0 -78
- package/index.ts +2 -2
- package/package.json +1 -1
- package/sdk/index.d.ts +2 -2
- package/sdk/index.js +11 -4
- package/sdk/index.ts +2 -2
- package/sdk/sdk.gen.d.ts +51 -9
- package/sdk/sdk.gen.js +105 -16
- package/sdk/sdk.gen.ts +101 -12
- package/sdk/types.gen.d.ts +812 -146
- package/sdk/types.gen.ts +844 -128
- package/sdk-extensions/LedgerClient.d.ts +88 -0
- package/sdk-extensions/LedgerClient.js +143 -0
- package/sdk-extensions/LedgerClient.ts +267 -0
- package/sdk-extensions/ReportClient.d.ts +14 -6
- package/sdk-extensions/ReportClient.js +19 -15
- package/sdk-extensions/ReportClient.ts +37 -21
- package/sdk-extensions/hooks.d.ts +1 -40
- package/sdk-extensions/hooks.js +0 -134
- package/sdk-extensions/hooks.ts +0 -156
- package/sdk-extensions/index.d.ts +2 -24
- package/sdk-extensions/index.js +1 -65
- package/sdk-extensions/index.test.ts +4 -38
- package/sdk-extensions/index.ts +0 -78
- package/sdk.gen.d.ts +51 -9
- package/sdk.gen.js +105 -16
- package/sdk.gen.ts +101 -12
- package/types.gen.d.ts +812 -146
- package/types.gen.ts +844 -128
- package/extensions/DocumentClient.d.ts +0 -77
- package/extensions/DocumentClient.js +0 -136
- package/extensions/DocumentClient.ts +0 -232
- package/extensions/FileClient.d.ts +0 -57
- package/extensions/FileClient.js +0 -246
- package/extensions/FileClient.ts +0 -330
- package/extensions/GraphClient.d.ts +0 -91
- package/extensions/GraphClient.js +0 -244
- package/extensions/GraphClient.test.ts +0 -455
- package/extensions/GraphClient.ts +0 -371
- package/extensions/MaterializationClient.d.ts +0 -61
- package/extensions/MaterializationClient.js +0 -157
- package/extensions/MaterializationClient.ts +0 -223
- package/extensions/TableClient.d.ts +0 -38
- package/extensions/TableClient.js +0 -92
- package/extensions/TableClient.ts +0 -132
- package/sdk-extensions/DocumentClient.d.ts +0 -77
- package/sdk-extensions/DocumentClient.js +0 -136
- package/sdk-extensions/DocumentClient.ts +0 -232
- package/sdk-extensions/FileClient.d.ts +0 -57
- package/sdk-extensions/FileClient.js +0 -246
- package/sdk-extensions/FileClient.ts +0 -330
- package/sdk-extensions/GraphClient.d.ts +0 -91
- package/sdk-extensions/GraphClient.js +0 -244
- package/sdk-extensions/GraphClient.test.ts +0 -455
- package/sdk-extensions/GraphClient.ts +0 -371
- package/sdk-extensions/MaterializationClient.d.ts +0 -61
- package/sdk-extensions/MaterializationClient.js +0 -157
- package/sdk-extensions/MaterializationClient.ts +0 -223
- package/sdk-extensions/TableClient.d.ts +0 -38
- package/sdk-extensions/TableClient.js +0 -92
- package/sdk-extensions/TableClient.ts +0 -132
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Materialization Client for RoboSystems API
|
|
5
|
-
*
|
|
6
|
-
* Manages graph materialization from DuckDB staging tables.
|
|
7
|
-
* Submits materialization jobs to Dagster and monitors progress via SSE.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { getMaterializationStatus, materializeGraph } from '../sdk.gen'
|
|
11
|
-
import type { MaterializeRequest } from '../types.gen'
|
|
12
|
-
import { OperationClient, type OperationResult } from './OperationClient'
|
|
13
|
-
|
|
14
|
-
export interface MaterializationOptions {
|
|
15
|
-
ignoreErrors?: boolean
|
|
16
|
-
rebuild?: boolean
|
|
17
|
-
force?: boolean
|
|
18
|
-
timeout?: number // Default 10 minutes
|
|
19
|
-
onProgress?: (message: string) => void
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface MaterializationResult {
|
|
23
|
-
status: string
|
|
24
|
-
wasStale: boolean
|
|
25
|
-
staleReason?: string
|
|
26
|
-
tablesMaterialized: string[]
|
|
27
|
-
totalRows: number
|
|
28
|
-
executionTimeMs: number
|
|
29
|
-
message: string
|
|
30
|
-
success: boolean
|
|
31
|
-
error?: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface MaterializationStatus {
|
|
35
|
-
graphId: string
|
|
36
|
-
isStale: boolean
|
|
37
|
-
staleReason?: string
|
|
38
|
-
staleSince?: string
|
|
39
|
-
lastMaterializedAt?: string
|
|
40
|
-
materializationCount: number
|
|
41
|
-
hoursSinceMaterialization?: number
|
|
42
|
-
message: string
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class MaterializationClient {
|
|
46
|
-
private config: {
|
|
47
|
-
baseUrl: string
|
|
48
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
49
|
-
headers?: Record<string, string>
|
|
50
|
-
token?: string
|
|
51
|
-
}
|
|
52
|
-
private operationClient: OperationClient
|
|
53
|
-
|
|
54
|
-
constructor(config: {
|
|
55
|
-
baseUrl: string
|
|
56
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
57
|
-
headers?: Record<string, string>
|
|
58
|
-
token?: string
|
|
59
|
-
}) {
|
|
60
|
-
this.config = config
|
|
61
|
-
this.operationClient = new OperationClient(config)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Materialize graph from DuckDB staging tables
|
|
66
|
-
*
|
|
67
|
-
* Submits a materialization job to Dagster and monitors progress via SSE.
|
|
68
|
-
* The operation runs asynchronously on the server but this method waits
|
|
69
|
-
* for completion and returns the final result.
|
|
70
|
-
*/
|
|
71
|
-
async materialize(
|
|
72
|
-
graphId: string,
|
|
73
|
-
options: MaterializationOptions = {}
|
|
74
|
-
): Promise<MaterializationResult> {
|
|
75
|
-
try {
|
|
76
|
-
options.onProgress?.('Submitting materialization job...')
|
|
77
|
-
|
|
78
|
-
const request: MaterializeRequest = {
|
|
79
|
-
ignore_errors: options.ignoreErrors ?? true,
|
|
80
|
-
rebuild: options.rebuild ?? false,
|
|
81
|
-
force: options.force ?? false,
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const response = await materializeGraph({
|
|
85
|
-
path: { graph_id: graphId },
|
|
86
|
-
body: request,
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
if (response.error || !response.data) {
|
|
90
|
-
return {
|
|
91
|
-
status: 'failed',
|
|
92
|
-
wasStale: false,
|
|
93
|
-
tablesMaterialized: [],
|
|
94
|
-
totalRows: 0,
|
|
95
|
-
executionTimeMs: 0,
|
|
96
|
-
message: `Failed to materialize graph: ${response.error}`,
|
|
97
|
-
success: false,
|
|
98
|
-
error: `Failed to materialize graph: ${response.error}`,
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const queuedResponse = response.data as { operation_id: string; message: string }
|
|
103
|
-
const operationId = queuedResponse.operation_id
|
|
104
|
-
|
|
105
|
-
options.onProgress?.(`Materialization queued (operation: ${operationId})`)
|
|
106
|
-
|
|
107
|
-
// Monitor the operation via SSE until completion
|
|
108
|
-
const opResult = await this.operationClient.monitorOperation(operationId, {
|
|
109
|
-
timeout: (options.timeout ?? 600) * 1000, // Convert to milliseconds, 10 minute default
|
|
110
|
-
onProgress: (progress) => {
|
|
111
|
-
if (options.onProgress) {
|
|
112
|
-
let msg = progress.message
|
|
113
|
-
if (progress.progressPercent !== undefined) {
|
|
114
|
-
msg += ` (${progress.progressPercent.toFixed(0)}%)`
|
|
115
|
-
}
|
|
116
|
-
options.onProgress(msg)
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
// Convert operation result to materialization result
|
|
122
|
-
return this.convertOperationResult(opResult, options)
|
|
123
|
-
} catch (error) {
|
|
124
|
-
return {
|
|
125
|
-
status: 'failed',
|
|
126
|
-
wasStale: false,
|
|
127
|
-
tablesMaterialized: [],
|
|
128
|
-
totalRows: 0,
|
|
129
|
-
executionTimeMs: 0,
|
|
130
|
-
message: error instanceof Error ? error.message : String(error),
|
|
131
|
-
success: false,
|
|
132
|
-
error: error instanceof Error ? error.message : String(error),
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Convert SSE operation result to MaterializationResult
|
|
139
|
-
*/
|
|
140
|
-
private convertOperationResult(
|
|
141
|
-
opResult: OperationResult,
|
|
142
|
-
options: MaterializationOptions
|
|
143
|
-
): MaterializationResult {
|
|
144
|
-
if (opResult.success) {
|
|
145
|
-
// Extract details from SSE completion event result
|
|
146
|
-
const sseResult = opResult.result || {}
|
|
147
|
-
|
|
148
|
-
const tables = sseResult.tables_materialized || []
|
|
149
|
-
const rows = sseResult.total_rows || 0
|
|
150
|
-
const timeMs = sseResult.execution_time_ms || 0
|
|
151
|
-
|
|
152
|
-
options.onProgress?.(
|
|
153
|
-
`✅ Materialization complete: ${tables.length} tables, ` +
|
|
154
|
-
`${rows.toLocaleString()} rows in ${timeMs.toFixed(2)}ms`
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
status: 'success',
|
|
159
|
-
wasStale: sseResult.was_stale || false,
|
|
160
|
-
staleReason: sseResult.stale_reason,
|
|
161
|
-
tablesMaterialized: tables,
|
|
162
|
-
totalRows: rows,
|
|
163
|
-
executionTimeMs: timeMs,
|
|
164
|
-
message: sseResult.message || 'Graph materialized successfully',
|
|
165
|
-
success: true,
|
|
166
|
-
}
|
|
167
|
-
} else {
|
|
168
|
-
// Operation failed or was cancelled
|
|
169
|
-
return {
|
|
170
|
-
status: 'failed',
|
|
171
|
-
wasStale: false,
|
|
172
|
-
tablesMaterialized: [],
|
|
173
|
-
totalRows: 0,
|
|
174
|
-
executionTimeMs: 0,
|
|
175
|
-
message: opResult.error || 'Operation failed',
|
|
176
|
-
success: false,
|
|
177
|
-
error: opResult.error,
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Get current materialization status for the graph
|
|
184
|
-
*
|
|
185
|
-
* Shows whether the graph is stale (DuckDB has changes not yet in graph database),
|
|
186
|
-
* when it was last materialized, and how long since last materialization.
|
|
187
|
-
*/
|
|
188
|
-
async status(graphId: string): Promise<MaterializationStatus | null> {
|
|
189
|
-
try {
|
|
190
|
-
const response = await getMaterializationStatus({
|
|
191
|
-
path: { graph_id: graphId },
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
if (response.error || !response.data) {
|
|
195
|
-
console.error('Failed to get materialization status:', response.error)
|
|
196
|
-
return null
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const status = response.data as any
|
|
200
|
-
|
|
201
|
-
return {
|
|
202
|
-
graphId: status.graph_id,
|
|
203
|
-
isStale: status.is_stale,
|
|
204
|
-
staleReason: status.stale_reason,
|
|
205
|
-
staleSince: status.stale_since,
|
|
206
|
-
lastMaterializedAt: status.last_materialized_at,
|
|
207
|
-
materializationCount: status.materialization_count || 0,
|
|
208
|
-
hoursSinceMaterialization: status.hours_since_materialization,
|
|
209
|
-
message: status.message,
|
|
210
|
-
}
|
|
211
|
-
} catch (error) {
|
|
212
|
-
console.error('Failed to get materialization status:', error)
|
|
213
|
-
return null
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Close any active SSE connections
|
|
219
|
-
*/
|
|
220
|
-
close(): void {
|
|
221
|
-
this.operationClient.closeAll()
|
|
222
|
-
}
|
|
223
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export interface TableInfo {
|
|
2
|
-
tableName: string;
|
|
3
|
-
rowCount: number;
|
|
4
|
-
fileCount: number;
|
|
5
|
-
totalSizeBytes: number;
|
|
6
|
-
s3Location?: string | null;
|
|
7
|
-
}
|
|
8
|
-
export interface TableQueryResult {
|
|
9
|
-
columns: string[];
|
|
10
|
-
rows: any[][];
|
|
11
|
-
rowCount: number;
|
|
12
|
-
executionTimeMs: number;
|
|
13
|
-
success: boolean;
|
|
14
|
-
error?: string;
|
|
15
|
-
}
|
|
16
|
-
export declare class TableClient {
|
|
17
|
-
private config;
|
|
18
|
-
constructor(config: {
|
|
19
|
-
baseUrl: string;
|
|
20
|
-
credentials?: 'include' | 'same-origin' | 'omit';
|
|
21
|
-
headers?: Record<string, string>;
|
|
22
|
-
token?: string;
|
|
23
|
-
});
|
|
24
|
-
/**
|
|
25
|
-
* List all DuckDB staging tables in a graph
|
|
26
|
-
*/
|
|
27
|
-
list(graphId: string): Promise<TableInfo[]>;
|
|
28
|
-
/**
|
|
29
|
-
* Execute SQL query against DuckDB staging tables
|
|
30
|
-
*
|
|
31
|
-
* Example:
|
|
32
|
-
* const result = await client.tables.query(
|
|
33
|
-
* graphId,
|
|
34
|
-
* "SELECT * FROM Entity WHERE entity_type = 'CORPORATION'"
|
|
35
|
-
* )
|
|
36
|
-
*/
|
|
37
|
-
query(graphId: string, sqlQuery: string, limit?: number): Promise<TableQueryResult>;
|
|
38
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.TableClient = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Table Client for RoboSystems API
|
|
7
|
-
*
|
|
8
|
-
* Manages DuckDB staging table operations.
|
|
9
|
-
* Tables provide SQL-queryable staging layer before graph materialization.
|
|
10
|
-
*/
|
|
11
|
-
const sdk_gen_1 = require("../sdk.gen");
|
|
12
|
-
class TableClient {
|
|
13
|
-
constructor(config) {
|
|
14
|
-
this.config = config;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* List all DuckDB staging tables in a graph
|
|
18
|
-
*/
|
|
19
|
-
async list(graphId) {
|
|
20
|
-
try {
|
|
21
|
-
const response = await (0, sdk_gen_1.listTables)({
|
|
22
|
-
path: { graph_id: graphId },
|
|
23
|
-
});
|
|
24
|
-
if (response.error || !response.data) {
|
|
25
|
-
console.error('Failed to list tables:', response.error);
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
const tableData = response.data;
|
|
29
|
-
return (tableData.tables?.map((table) => ({
|
|
30
|
-
tableName: table.table_name,
|
|
31
|
-
rowCount: table.row_count,
|
|
32
|
-
fileCount: table.file_count || 0,
|
|
33
|
-
totalSizeBytes: table.total_size_bytes || 0,
|
|
34
|
-
s3Location: table.s3_location,
|
|
35
|
-
})) || []);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
console.error('Failed to list tables:', error);
|
|
39
|
-
return [];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Execute SQL query against DuckDB staging tables
|
|
44
|
-
*
|
|
45
|
-
* Example:
|
|
46
|
-
* const result = await client.tables.query(
|
|
47
|
-
* graphId,
|
|
48
|
-
* "SELECT * FROM Entity WHERE entity_type = 'CORPORATION'"
|
|
49
|
-
* )
|
|
50
|
-
*/
|
|
51
|
-
async query(graphId, sqlQuery, limit) {
|
|
52
|
-
try {
|
|
53
|
-
const finalQuery = limit !== undefined ? `${sqlQuery.replace(/;?\s*$/, '')} LIMIT ${limit}` : sqlQuery;
|
|
54
|
-
const request = {
|
|
55
|
-
sql: finalQuery,
|
|
56
|
-
};
|
|
57
|
-
const response = await (0, sdk_gen_1.queryTables)({
|
|
58
|
-
path: { graph_id: graphId },
|
|
59
|
-
body: request,
|
|
60
|
-
});
|
|
61
|
-
if (response.error || !response.data) {
|
|
62
|
-
return {
|
|
63
|
-
columns: [],
|
|
64
|
-
rows: [],
|
|
65
|
-
rowCount: 0,
|
|
66
|
-
executionTimeMs: 0,
|
|
67
|
-
success: false,
|
|
68
|
-
error: `Query failed: ${response.error}`,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
const result = response.data;
|
|
72
|
-
return {
|
|
73
|
-
columns: result.columns || [],
|
|
74
|
-
rows: result.rows || [],
|
|
75
|
-
rowCount: result.rows?.length || 0,
|
|
76
|
-
executionTimeMs: result.execution_time_ms || 0,
|
|
77
|
-
success: true,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
return {
|
|
82
|
-
columns: [],
|
|
83
|
-
rows: [],
|
|
84
|
-
rowCount: 0,
|
|
85
|
-
executionTimeMs: 0,
|
|
86
|
-
success: false,
|
|
87
|
-
error: error instanceof Error ? error.message : String(error),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.TableClient = TableClient;
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Table Client for RoboSystems API
|
|
5
|
-
*
|
|
6
|
-
* Manages DuckDB staging table operations.
|
|
7
|
-
* Tables provide SQL-queryable staging layer before graph materialization.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { listTables, queryTables } from '../sdk.gen'
|
|
11
|
-
import type { TableListResponse, TableQueryRequest } from '../types.gen'
|
|
12
|
-
|
|
13
|
-
export interface TableInfo {
|
|
14
|
-
tableName: string
|
|
15
|
-
rowCount: number
|
|
16
|
-
fileCount: number
|
|
17
|
-
totalSizeBytes: number
|
|
18
|
-
s3Location?: string | null
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface TableQueryResult {
|
|
22
|
-
columns: string[]
|
|
23
|
-
rows: any[][]
|
|
24
|
-
rowCount: number
|
|
25
|
-
executionTimeMs: number
|
|
26
|
-
success: boolean
|
|
27
|
-
error?: string
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class TableClient {
|
|
31
|
-
private config: {
|
|
32
|
-
baseUrl: string
|
|
33
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
34
|
-
headers?: Record<string, string>
|
|
35
|
-
token?: string
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
constructor(config: {
|
|
39
|
-
baseUrl: string
|
|
40
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
41
|
-
headers?: Record<string, string>
|
|
42
|
-
token?: string
|
|
43
|
-
}) {
|
|
44
|
-
this.config = config
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* List all DuckDB staging tables in a graph
|
|
49
|
-
*/
|
|
50
|
-
async list(graphId: string): Promise<TableInfo[]> {
|
|
51
|
-
try {
|
|
52
|
-
const response = await listTables({
|
|
53
|
-
path: { graph_id: graphId },
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
if (response.error || !response.data) {
|
|
57
|
-
console.error('Failed to list tables:', response.error)
|
|
58
|
-
return []
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const tableData = response.data as TableListResponse
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
tableData.tables?.map((table) => ({
|
|
65
|
-
tableName: table.table_name,
|
|
66
|
-
rowCount: table.row_count,
|
|
67
|
-
fileCount: table.file_count || 0,
|
|
68
|
-
totalSizeBytes: table.total_size_bytes || 0,
|
|
69
|
-
s3Location: table.s3_location,
|
|
70
|
-
})) || []
|
|
71
|
-
)
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.error('Failed to list tables:', error)
|
|
74
|
-
return []
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Execute SQL query against DuckDB staging tables
|
|
80
|
-
*
|
|
81
|
-
* Example:
|
|
82
|
-
* const result = await client.tables.query(
|
|
83
|
-
* graphId,
|
|
84
|
-
* "SELECT * FROM Entity WHERE entity_type = 'CORPORATION'"
|
|
85
|
-
* )
|
|
86
|
-
*/
|
|
87
|
-
async query(graphId: string, sqlQuery: string, limit?: number): Promise<TableQueryResult> {
|
|
88
|
-
try {
|
|
89
|
-
const finalQuery =
|
|
90
|
-
limit !== undefined ? `${sqlQuery.replace(/;?\s*$/, '')} LIMIT ${limit}` : sqlQuery
|
|
91
|
-
|
|
92
|
-
const request: TableQueryRequest = {
|
|
93
|
-
sql: finalQuery,
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const response = await queryTables({
|
|
97
|
-
path: { graph_id: graphId },
|
|
98
|
-
body: request,
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
if (response.error || !response.data) {
|
|
102
|
-
return {
|
|
103
|
-
columns: [],
|
|
104
|
-
rows: [],
|
|
105
|
-
rowCount: 0,
|
|
106
|
-
executionTimeMs: 0,
|
|
107
|
-
success: false,
|
|
108
|
-
error: `Query failed: ${response.error}`,
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const result = response.data as any
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
columns: result.columns || [],
|
|
116
|
-
rows: result.rows || [],
|
|
117
|
-
rowCount: result.rows?.length || 0,
|
|
118
|
-
executionTimeMs: result.execution_time_ms || 0,
|
|
119
|
-
success: true,
|
|
120
|
-
}
|
|
121
|
-
} catch (error) {
|
|
122
|
-
return {
|
|
123
|
-
columns: [],
|
|
124
|
-
rows: [],
|
|
125
|
-
rowCount: 0,
|
|
126
|
-
executionTimeMs: 0,
|
|
127
|
-
success: false,
|
|
128
|
-
error: error instanceof Error ? error.message : String(error),
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { BulkDocumentUploadResponse, DocumentListResponse, DocumentSection, DocumentUploadResponse, SearchResponse } from '../sdk/types.gen';
|
|
2
|
-
export interface DocumentSearchOptions {
|
|
3
|
-
/** Filter by source type (xbrl_textblock, narrative_section, ixbrl_disclosure, uploaded_doc, memory) */
|
|
4
|
-
sourceType?: string;
|
|
5
|
-
/** Filter by ticker, CIK, or entity name */
|
|
6
|
-
entity?: string;
|
|
7
|
-
/** Filter by SEC form type (10-K, 10-Q) */
|
|
8
|
-
formType?: string;
|
|
9
|
-
/** Filter by section ID (item_1, item_1a, item_7, etc.) */
|
|
10
|
-
section?: string;
|
|
11
|
-
/** Filter by XBRL element qname (e.g., us-gaap:Goodwill) */
|
|
12
|
-
element?: string;
|
|
13
|
-
/** Filter by fiscal year */
|
|
14
|
-
fiscalYear?: number;
|
|
15
|
-
/** Filter filings on or after date (YYYY-MM-DD) */
|
|
16
|
-
dateFrom?: string;
|
|
17
|
-
/** Filter filings on or before date (YYYY-MM-DD) */
|
|
18
|
-
dateTo?: string;
|
|
19
|
-
/** Max results to return (default: 10) */
|
|
20
|
-
size?: number;
|
|
21
|
-
/** Pagination offset */
|
|
22
|
-
offset?: number;
|
|
23
|
-
}
|
|
24
|
-
export interface DocumentUploadOptions {
|
|
25
|
-
/** Optional tags for filtering */
|
|
26
|
-
tags?: string[];
|
|
27
|
-
/** Optional folder/category */
|
|
28
|
-
folder?: string;
|
|
29
|
-
/** Optional external ID for upsert behavior */
|
|
30
|
-
externalId?: string;
|
|
31
|
-
}
|
|
32
|
-
export declare class DocumentClient {
|
|
33
|
-
private config;
|
|
34
|
-
constructor(config: {
|
|
35
|
-
baseUrl: string;
|
|
36
|
-
credentials?: 'include' | 'same-origin' | 'omit';
|
|
37
|
-
headers?: Record<string, string>;
|
|
38
|
-
token?: string;
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* Upload a markdown document for text indexing.
|
|
42
|
-
*
|
|
43
|
-
* The document is sectioned on headings, embedded, and indexed
|
|
44
|
-
* into OpenSearch for full-text and semantic search.
|
|
45
|
-
*/
|
|
46
|
-
upload(graphId: string, title: string, content: string, options?: DocumentUploadOptions): Promise<DocumentUploadResponse>;
|
|
47
|
-
/**
|
|
48
|
-
* Upload multiple markdown documents (max 50 per request).
|
|
49
|
-
*/
|
|
50
|
-
uploadBulk(graphId: string, documents: Array<{
|
|
51
|
-
title: string;
|
|
52
|
-
content: string;
|
|
53
|
-
tags?: string[];
|
|
54
|
-
folder?: string;
|
|
55
|
-
externalId?: string;
|
|
56
|
-
}>): Promise<BulkDocumentUploadResponse>;
|
|
57
|
-
/**
|
|
58
|
-
* Search documents with hybrid (BM25 + kNN) search.
|
|
59
|
-
*/
|
|
60
|
-
search(graphId: string, query: string, options?: DocumentSearchOptions): Promise<SearchResponse>;
|
|
61
|
-
/**
|
|
62
|
-
* Retrieve the full text of a document section by ID.
|
|
63
|
-
*
|
|
64
|
-
* @returns DocumentSection or null if not found.
|
|
65
|
-
*/
|
|
66
|
-
getSection(graphId: string, documentId: string): Promise<DocumentSection | null>;
|
|
67
|
-
/**
|
|
68
|
-
* List indexed documents for a graph.
|
|
69
|
-
*/
|
|
70
|
-
list(graphId: string, sourceType?: string): Promise<DocumentListResponse>;
|
|
71
|
-
/**
|
|
72
|
-
* Delete a document and all its sections.
|
|
73
|
-
*
|
|
74
|
-
* @returns true if deleted, false if not found.
|
|
75
|
-
*/
|
|
76
|
-
delete(graphId: string, documentId: string): Promise<boolean>;
|
|
77
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.DocumentClient = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Document Client for RoboSystems API
|
|
7
|
-
*
|
|
8
|
-
* Upload, search, list, and delete text documents indexed in OpenSearch.
|
|
9
|
-
* Documents are sectioned on markdown headings, embedded for semantic search,
|
|
10
|
-
* and searchable alongside structured graph data.
|
|
11
|
-
*/
|
|
12
|
-
const sdk_gen_1 = require("../sdk/sdk.gen");
|
|
13
|
-
class DocumentClient {
|
|
14
|
-
constructor(config) {
|
|
15
|
-
this.config = config;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Upload a markdown document for text indexing.
|
|
19
|
-
*
|
|
20
|
-
* The document is sectioned on headings, embedded, and indexed
|
|
21
|
-
* into OpenSearch for full-text and semantic search.
|
|
22
|
-
*/
|
|
23
|
-
async upload(graphId, title, content, options = {}) {
|
|
24
|
-
const response = await (0, sdk_gen_1.uploadDocument)({
|
|
25
|
-
path: { graph_id: graphId },
|
|
26
|
-
body: {
|
|
27
|
-
title,
|
|
28
|
-
content,
|
|
29
|
-
tags: options.tags ?? null,
|
|
30
|
-
folder: options.folder ?? null,
|
|
31
|
-
external_id: options.externalId ?? null,
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
if (response.error) {
|
|
35
|
-
throw new Error(`Document upload failed: ${JSON.stringify(response.error)}`);
|
|
36
|
-
}
|
|
37
|
-
return response.data;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Upload multiple markdown documents (max 50 per request).
|
|
41
|
-
*/
|
|
42
|
-
async uploadBulk(graphId, documents) {
|
|
43
|
-
const response = await (0, sdk_gen_1.uploadDocumentsBulk)({
|
|
44
|
-
path: { graph_id: graphId },
|
|
45
|
-
body: {
|
|
46
|
-
documents: documents.map((doc) => ({
|
|
47
|
-
title: doc.title,
|
|
48
|
-
content: doc.content,
|
|
49
|
-
tags: doc.tags ?? null,
|
|
50
|
-
folder: doc.folder ?? null,
|
|
51
|
-
external_id: doc.externalId ?? null,
|
|
52
|
-
})),
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
if (response.error) {
|
|
56
|
-
throw new Error(`Bulk upload failed: ${JSON.stringify(response.error)}`);
|
|
57
|
-
}
|
|
58
|
-
return response.data;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Search documents with hybrid (BM25 + kNN) search.
|
|
62
|
-
*/
|
|
63
|
-
async search(graphId, query, options = {}) {
|
|
64
|
-
const response = await (0, sdk_gen_1.searchDocuments)({
|
|
65
|
-
path: { graph_id: graphId },
|
|
66
|
-
body: {
|
|
67
|
-
query,
|
|
68
|
-
source_type: options.sourceType ?? null,
|
|
69
|
-
entity: options.entity ?? null,
|
|
70
|
-
form_type: options.formType ?? null,
|
|
71
|
-
section: options.section ?? null,
|
|
72
|
-
element: options.element ?? null,
|
|
73
|
-
fiscal_year: options.fiscalYear ?? null,
|
|
74
|
-
date_from: options.dateFrom ?? null,
|
|
75
|
-
date_to: options.dateTo ?? null,
|
|
76
|
-
size: options.size,
|
|
77
|
-
offset: options.offset,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
if (response.error) {
|
|
81
|
-
throw new Error(`Document search failed: ${JSON.stringify(response.error)}`);
|
|
82
|
-
}
|
|
83
|
-
return response.data;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Retrieve the full text of a document section by ID.
|
|
87
|
-
*
|
|
88
|
-
* @returns DocumentSection or null if not found.
|
|
89
|
-
*/
|
|
90
|
-
async getSection(graphId, documentId) {
|
|
91
|
-
const response = await (0, sdk_gen_1.getDocumentSection)({
|
|
92
|
-
path: { graph_id: graphId, document_id: documentId },
|
|
93
|
-
});
|
|
94
|
-
if (response.response.status === 404) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
if (response.error) {
|
|
98
|
-
throw new Error(`Get section failed: ${JSON.stringify(response.error)}`);
|
|
99
|
-
}
|
|
100
|
-
return response.data;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* List indexed documents for a graph.
|
|
104
|
-
*/
|
|
105
|
-
async list(graphId, sourceType) {
|
|
106
|
-
const response = await (0, sdk_gen_1.listDocuments)({
|
|
107
|
-
path: { graph_id: graphId },
|
|
108
|
-
query: sourceType ? { source_type: sourceType } : undefined,
|
|
109
|
-
});
|
|
110
|
-
if (response.error) {
|
|
111
|
-
throw new Error(`List documents failed: ${JSON.stringify(response.error)}`);
|
|
112
|
-
}
|
|
113
|
-
return response.data;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Delete a document and all its sections.
|
|
117
|
-
*
|
|
118
|
-
* @returns true if deleted, false if not found.
|
|
119
|
-
*/
|
|
120
|
-
async delete(graphId, documentId) {
|
|
121
|
-
const response = await (0, sdk_gen_1.deleteDocument)({
|
|
122
|
-
path: { graph_id: graphId, document_id: documentId },
|
|
123
|
-
});
|
|
124
|
-
if (response.response.status === 204) {
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
if (response.response.status === 404) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
if (response.error) {
|
|
131
|
-
throw new Error(`Delete document failed: ${JSON.stringify(response.error)}`);
|
|
132
|
-
}
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
exports.DocumentClient = DocumentClient;
|