@robosystems/client 0.2.11 → 0.2.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.
- package/extensions/AgentClient.d.ts +82 -0
- package/extensions/AgentClient.js +218 -0
- package/extensions/AgentClient.ts +321 -0
- package/extensions/QueryClient.js +85 -37
- package/extensions/QueryClient.ts +82 -34
- package/extensions/index.d.ts +7 -1
- package/extensions/index.js +18 -1
- package/extensions/index.ts +21 -1
- package/package.json +1 -1
- package/sdk/sdk.gen.d.ts +49 -32
- package/sdk/sdk.gen.js +81 -64
- package/sdk/sdk.gen.ts +81 -64
- package/sdk/types.gen.d.ts +94 -73
- package/sdk/types.gen.ts +104 -83
- package/sdk-extensions/AgentClient.d.ts +82 -0
- package/sdk-extensions/AgentClient.js +218 -0
- package/sdk-extensions/AgentClient.ts +321 -0
- package/sdk-extensions/QueryClient.js +85 -37
- package/sdk-extensions/QueryClient.ts +82 -34
- package/sdk-extensions/index.d.ts +7 -1
- package/sdk-extensions/index.js +18 -1
- package/sdk-extensions/index.ts +21 -1
- package/sdk.gen.d.ts +49 -32
- package/sdk.gen.js +81 -64
- package/sdk.gen.ts +81 -64
- package/types.gen.d.ts +94 -73
- package/types.gen.ts +104 -83
package/sdk/types.gen.ts
CHANGED
|
@@ -914,7 +914,7 @@ export type CheckoutStatusResponse = {
|
|
|
914
914
|
subscription_id: string;
|
|
915
915
|
/**
|
|
916
916
|
* Resource Id
|
|
917
|
-
* Resource ID (graph_id
|
|
917
|
+
* Resource ID (graph_id for both graphs and repositories) once provisioned. For repositories, this is the repository slug (e.g., 'sec')
|
|
918
918
|
*/
|
|
919
919
|
resource_id?: string | null;
|
|
920
920
|
/**
|
|
@@ -1154,7 +1154,7 @@ export type CreateCheckoutRequest = {
|
|
|
1154
1154
|
resource_type: string;
|
|
1155
1155
|
/**
|
|
1156
1156
|
* Resource Config
|
|
1157
|
-
* Configuration for the resource to be provisioned
|
|
1157
|
+
* Configuration for the resource to be provisioned. For repositories: {'repository_name': 'graph_id'} where graph_id is the repository slug (e.g., 'sec')
|
|
1158
1158
|
*/
|
|
1159
1159
|
resource_config: {
|
|
1160
1160
|
[key: string]: unknown;
|
|
@@ -6255,6 +6255,46 @@ export type SyncConnectionResponses = {
|
|
|
6255
6255
|
|
|
6256
6256
|
export type SyncConnectionResponse = SyncConnectionResponses[keyof SyncConnectionResponses];
|
|
6257
6257
|
|
|
6258
|
+
export type ListAgentsData = {
|
|
6259
|
+
body?: never;
|
|
6260
|
+
path: {
|
|
6261
|
+
/**
|
|
6262
|
+
* Graph Id
|
|
6263
|
+
*/
|
|
6264
|
+
graph_id: string;
|
|
6265
|
+
};
|
|
6266
|
+
query?: {
|
|
6267
|
+
/**
|
|
6268
|
+
* Capability
|
|
6269
|
+
* Filter by capability (e.g., 'financial_analysis', 'rag_search')
|
|
6270
|
+
*/
|
|
6271
|
+
capability?: string | null;
|
|
6272
|
+
};
|
|
6273
|
+
url: '/v1/graphs/{graph_id}/agent';
|
|
6274
|
+
};
|
|
6275
|
+
|
|
6276
|
+
export type ListAgentsErrors = {
|
|
6277
|
+
/**
|
|
6278
|
+
* Unauthorized - Invalid or missing authentication
|
|
6279
|
+
*/
|
|
6280
|
+
401: unknown;
|
|
6281
|
+
/**
|
|
6282
|
+
* Validation Error
|
|
6283
|
+
*/
|
|
6284
|
+
422: HttpValidationError;
|
|
6285
|
+
};
|
|
6286
|
+
|
|
6287
|
+
export type ListAgentsError = ListAgentsErrors[keyof ListAgentsErrors];
|
|
6288
|
+
|
|
6289
|
+
export type ListAgentsResponses = {
|
|
6290
|
+
/**
|
|
6291
|
+
* List of agents retrieved successfully
|
|
6292
|
+
*/
|
|
6293
|
+
200: AgentListResponse;
|
|
6294
|
+
};
|
|
6295
|
+
|
|
6296
|
+
export type ListAgentsResponse = ListAgentsResponses[keyof ListAgentsResponses];
|
|
6297
|
+
|
|
6258
6298
|
export type AutoSelectAgentData = {
|
|
6259
6299
|
body: AgentRequest;
|
|
6260
6300
|
path: {
|
|
@@ -6263,7 +6303,13 @@ export type AutoSelectAgentData = {
|
|
|
6263
6303
|
*/
|
|
6264
6304
|
graph_id: string;
|
|
6265
6305
|
};
|
|
6266
|
-
query?:
|
|
6306
|
+
query?: {
|
|
6307
|
+
/**
|
|
6308
|
+
* Mode
|
|
6309
|
+
* Override execution mode: sync, async, stream, or auto
|
|
6310
|
+
*/
|
|
6311
|
+
mode?: ResponseMode | null;
|
|
6312
|
+
};
|
|
6267
6313
|
url: '/v1/graphs/{graph_id}/agent';
|
|
6268
6314
|
};
|
|
6269
6315
|
|
|
@@ -6297,10 +6343,53 @@ export type AutoSelectAgentResponses = {
|
|
|
6297
6343
|
* Query successfully processed by selected agent
|
|
6298
6344
|
*/
|
|
6299
6345
|
200: AgentResponse;
|
|
6346
|
+
/**
|
|
6347
|
+
* Query queued for async processing with operation tracking
|
|
6348
|
+
*/
|
|
6349
|
+
202: unknown;
|
|
6300
6350
|
};
|
|
6301
6351
|
|
|
6302
6352
|
export type AutoSelectAgentResponse = AutoSelectAgentResponses[keyof AutoSelectAgentResponses];
|
|
6303
6353
|
|
|
6354
|
+
export type GetAgentMetadataData = {
|
|
6355
|
+
body?: never;
|
|
6356
|
+
path: {
|
|
6357
|
+
/**
|
|
6358
|
+
* Graph Id
|
|
6359
|
+
*/
|
|
6360
|
+
graph_id: string;
|
|
6361
|
+
/**
|
|
6362
|
+
* Agent Type
|
|
6363
|
+
* Agent type identifier (e.g., 'financial', 'research', 'rag')
|
|
6364
|
+
*/
|
|
6365
|
+
agent_type: string;
|
|
6366
|
+
};
|
|
6367
|
+
query?: never;
|
|
6368
|
+
url: '/v1/graphs/{graph_id}/agent/{agent_type}';
|
|
6369
|
+
};
|
|
6370
|
+
|
|
6371
|
+
export type GetAgentMetadataErrors = {
|
|
6372
|
+
/**
|
|
6373
|
+
* Agent type not found
|
|
6374
|
+
*/
|
|
6375
|
+
404: unknown;
|
|
6376
|
+
/**
|
|
6377
|
+
* Validation Error
|
|
6378
|
+
*/
|
|
6379
|
+
422: HttpValidationError;
|
|
6380
|
+
};
|
|
6381
|
+
|
|
6382
|
+
export type GetAgentMetadataError = GetAgentMetadataErrors[keyof GetAgentMetadataErrors];
|
|
6383
|
+
|
|
6384
|
+
export type GetAgentMetadataResponses = {
|
|
6385
|
+
/**
|
|
6386
|
+
* Agent metadata retrieved successfully
|
|
6387
|
+
*/
|
|
6388
|
+
200: AgentMetadataResponse;
|
|
6389
|
+
};
|
|
6390
|
+
|
|
6391
|
+
export type GetAgentMetadataResponse = GetAgentMetadataResponses[keyof GetAgentMetadataResponses];
|
|
6392
|
+
|
|
6304
6393
|
export type ExecuteSpecificAgentData = {
|
|
6305
6394
|
body: AgentRequest;
|
|
6306
6395
|
path: {
|
|
@@ -6313,7 +6402,13 @@ export type ExecuteSpecificAgentData = {
|
|
|
6313
6402
|
*/
|
|
6314
6403
|
graph_id: string;
|
|
6315
6404
|
};
|
|
6316
|
-
query?:
|
|
6405
|
+
query?: {
|
|
6406
|
+
/**
|
|
6407
|
+
* Mode
|
|
6408
|
+
* Override execution mode: sync, async, stream, or auto
|
|
6409
|
+
*/
|
|
6410
|
+
mode?: ResponseMode | null;
|
|
6411
|
+
};
|
|
6317
6412
|
url: '/v1/graphs/{graph_id}/agent/{agent_type}';
|
|
6318
6413
|
};
|
|
6319
6414
|
|
|
@@ -6351,6 +6446,10 @@ export type ExecuteSpecificAgentResponses = {
|
|
|
6351
6446
|
* Query successfully processed by specified agent
|
|
6352
6447
|
*/
|
|
6353
6448
|
200: AgentResponse;
|
|
6449
|
+
/**
|
|
6450
|
+
* Query queued for async processing with operation tracking
|
|
6451
|
+
*/
|
|
6452
|
+
202: unknown;
|
|
6354
6453
|
};
|
|
6355
6454
|
|
|
6356
6455
|
export type ExecuteSpecificAgentResponse = ExecuteSpecificAgentResponses[keyof ExecuteSpecificAgentResponses];
|
|
@@ -6397,85 +6496,6 @@ export type BatchProcessQueriesResponses = {
|
|
|
6397
6496
|
|
|
6398
6497
|
export type BatchProcessQueriesResponse = BatchProcessQueriesResponses[keyof BatchProcessQueriesResponses];
|
|
6399
6498
|
|
|
6400
|
-
export type ListAgentsData = {
|
|
6401
|
-
body?: never;
|
|
6402
|
-
path: {
|
|
6403
|
-
/**
|
|
6404
|
-
* Graph Id
|
|
6405
|
-
*/
|
|
6406
|
-
graph_id: string;
|
|
6407
|
-
};
|
|
6408
|
-
query?: {
|
|
6409
|
-
/**
|
|
6410
|
-
* Capability
|
|
6411
|
-
* Filter by capability (e.g., 'financial_analysis', 'rag_search')
|
|
6412
|
-
*/
|
|
6413
|
-
capability?: string | null;
|
|
6414
|
-
};
|
|
6415
|
-
url: '/v1/graphs/{graph_id}/agent/list';
|
|
6416
|
-
};
|
|
6417
|
-
|
|
6418
|
-
export type ListAgentsErrors = {
|
|
6419
|
-
/**
|
|
6420
|
-
* Unauthorized - Invalid or missing authentication
|
|
6421
|
-
*/
|
|
6422
|
-
401: unknown;
|
|
6423
|
-
/**
|
|
6424
|
-
* Validation Error
|
|
6425
|
-
*/
|
|
6426
|
-
422: HttpValidationError;
|
|
6427
|
-
};
|
|
6428
|
-
|
|
6429
|
-
export type ListAgentsError = ListAgentsErrors[keyof ListAgentsErrors];
|
|
6430
|
-
|
|
6431
|
-
export type ListAgentsResponses = {
|
|
6432
|
-
/**
|
|
6433
|
-
* List of agents retrieved successfully
|
|
6434
|
-
*/
|
|
6435
|
-
200: AgentListResponse;
|
|
6436
|
-
};
|
|
6437
|
-
|
|
6438
|
-
export type ListAgentsResponse = ListAgentsResponses[keyof ListAgentsResponses];
|
|
6439
|
-
|
|
6440
|
-
export type GetAgentMetadataData = {
|
|
6441
|
-
body?: never;
|
|
6442
|
-
path: {
|
|
6443
|
-
/**
|
|
6444
|
-
* Graph Id
|
|
6445
|
-
*/
|
|
6446
|
-
graph_id: string;
|
|
6447
|
-
/**
|
|
6448
|
-
* Agent Type
|
|
6449
|
-
* Agent type identifier (e.g., 'financial', 'research', 'rag')
|
|
6450
|
-
*/
|
|
6451
|
-
agent_type: string;
|
|
6452
|
-
};
|
|
6453
|
-
query?: never;
|
|
6454
|
-
url: '/v1/graphs/{graph_id}/agent/{agent_type}/metadata';
|
|
6455
|
-
};
|
|
6456
|
-
|
|
6457
|
-
export type GetAgentMetadataErrors = {
|
|
6458
|
-
/**
|
|
6459
|
-
* Agent type not found
|
|
6460
|
-
*/
|
|
6461
|
-
404: unknown;
|
|
6462
|
-
/**
|
|
6463
|
-
* Validation Error
|
|
6464
|
-
*/
|
|
6465
|
-
422: HttpValidationError;
|
|
6466
|
-
};
|
|
6467
|
-
|
|
6468
|
-
export type GetAgentMetadataError = GetAgentMetadataErrors[keyof GetAgentMetadataErrors];
|
|
6469
|
-
|
|
6470
|
-
export type GetAgentMetadataResponses = {
|
|
6471
|
-
/**
|
|
6472
|
-
* Agent metadata retrieved successfully
|
|
6473
|
-
*/
|
|
6474
|
-
200: AgentMetadataResponse;
|
|
6475
|
-
};
|
|
6476
|
-
|
|
6477
|
-
export type GetAgentMetadataResponse = GetAgentMetadataResponses[keyof GetAgentMetadataResponses];
|
|
6478
|
-
|
|
6479
6499
|
export type RecommendAgentData = {
|
|
6480
6500
|
body: AgentRecommendationRequest;
|
|
6481
6501
|
path: {
|
|
@@ -7214,6 +7234,7 @@ export type ListCreditTransactionsData = {
|
|
|
7214
7234
|
path: {
|
|
7215
7235
|
/**
|
|
7216
7236
|
* Graph Id
|
|
7237
|
+
* Graph database identifier
|
|
7217
7238
|
*/
|
|
7218
7239
|
graph_id: string;
|
|
7219
7240
|
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export interface AgentQueryRequest {
|
|
2
|
+
message: string;
|
|
3
|
+
history?: Array<{
|
|
4
|
+
role: string;
|
|
5
|
+
content: string;
|
|
6
|
+
}>;
|
|
7
|
+
context?: Record<string, any>;
|
|
8
|
+
mode?: 'quick' | 'standard' | 'extended' | 'streaming';
|
|
9
|
+
enableRag?: boolean;
|
|
10
|
+
forceExtendedAnalysis?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface AgentOptions {
|
|
13
|
+
mode?: 'auto' | 'sync' | 'async';
|
|
14
|
+
maxWait?: number;
|
|
15
|
+
onProgress?: (message: string, percentage?: number) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface AgentResult {
|
|
18
|
+
content: string;
|
|
19
|
+
agent_used: string;
|
|
20
|
+
mode_used: 'quick' | 'standard' | 'extended' | 'streaming';
|
|
21
|
+
metadata?: Record<string, any>;
|
|
22
|
+
tokens_used?: {
|
|
23
|
+
prompt_tokens: number;
|
|
24
|
+
completion_tokens: number;
|
|
25
|
+
total_tokens: number;
|
|
26
|
+
};
|
|
27
|
+
confidence_score?: number;
|
|
28
|
+
execution_time?: number;
|
|
29
|
+
timestamp?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface QueuedAgentResponse {
|
|
32
|
+
status: 'queued';
|
|
33
|
+
operation_id: string;
|
|
34
|
+
message: string;
|
|
35
|
+
sse_endpoint?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare class AgentClient {
|
|
38
|
+
private sseClient?;
|
|
39
|
+
private config;
|
|
40
|
+
constructor(config: {
|
|
41
|
+
baseUrl: string;
|
|
42
|
+
credentials?: 'include' | 'same-origin' | 'omit';
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
token?: string;
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Execute agent query with automatic agent selection
|
|
48
|
+
*/
|
|
49
|
+
executeQuery(graphId: string, request: AgentQueryRequest, options?: AgentOptions): Promise<AgentResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Execute specific agent type
|
|
52
|
+
*/
|
|
53
|
+
executeAgent(graphId: string, agentType: string, request: AgentQueryRequest, options?: AgentOptions): Promise<AgentResult>;
|
|
54
|
+
private waitForAgentCompletion;
|
|
55
|
+
/**
|
|
56
|
+
* Convenience method for simple agent queries with auto-selection
|
|
57
|
+
*/
|
|
58
|
+
query(graphId: string, message: string, context?: Record<string, any>): Promise<AgentResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Execute financial agent for financial analysis
|
|
61
|
+
*/
|
|
62
|
+
analyzeFinancials(graphId: string, message: string, options?: AgentOptions): Promise<AgentResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Execute research agent for deep research
|
|
65
|
+
*/
|
|
66
|
+
research(graphId: string, message: string, options?: AgentOptions): Promise<AgentResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Execute RAG agent for fast retrieval
|
|
69
|
+
*/
|
|
70
|
+
rag(graphId: string, message: string, options?: AgentOptions): Promise<AgentResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Cancel any active SSE connections
|
|
73
|
+
*/
|
|
74
|
+
close(): void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Error thrown when agent execution is queued and maxWait is 0
|
|
78
|
+
*/
|
|
79
|
+
export declare class QueuedAgentError extends Error {
|
|
80
|
+
queueInfo: QueuedAgentResponse;
|
|
81
|
+
constructor(queueInfo: QueuedAgentResponse);
|
|
82
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.QueuedAgentError = exports.AgentClient = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Enhanced Agent Client with SSE support
|
|
7
|
+
* Provides intelligent agent execution with automatic strategy selection
|
|
8
|
+
*/
|
|
9
|
+
const sdk_gen_1 = require("../sdk/sdk.gen");
|
|
10
|
+
const SSEClient_1 = require("./SSEClient");
|
|
11
|
+
class AgentClient {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Execute agent query with automatic agent selection
|
|
17
|
+
*/
|
|
18
|
+
async executeQuery(graphId, request, options = {}) {
|
|
19
|
+
const data = {
|
|
20
|
+
url: '/v1/graphs/{graph_id}/agent',
|
|
21
|
+
path: { graph_id: graphId },
|
|
22
|
+
body: {
|
|
23
|
+
message: request.message,
|
|
24
|
+
history: request.history,
|
|
25
|
+
context: request.context,
|
|
26
|
+
mode: request.mode,
|
|
27
|
+
enable_rag: request.enableRag,
|
|
28
|
+
force_extended_analysis: request.forceExtendedAnalysis,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const response = await (0, sdk_gen_1.autoSelectAgent)(data);
|
|
32
|
+
const responseData = response.data;
|
|
33
|
+
// Check if this is an immediate response (sync execution)
|
|
34
|
+
if (responseData?.content !== undefined && responseData?.agent_used) {
|
|
35
|
+
return {
|
|
36
|
+
content: responseData.content,
|
|
37
|
+
agent_used: responseData.agent_used,
|
|
38
|
+
mode_used: responseData.mode_used,
|
|
39
|
+
metadata: responseData.metadata,
|
|
40
|
+
tokens_used: responseData.tokens_used,
|
|
41
|
+
confidence_score: responseData.confidence_score,
|
|
42
|
+
execution_time: responseData.execution_time,
|
|
43
|
+
timestamp: new Date().toISOString(),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// Check if this is a queued response (async Celery execution)
|
|
47
|
+
if (responseData?.operation_id) {
|
|
48
|
+
const queuedResponse = responseData;
|
|
49
|
+
// If user doesn't want to wait, throw with queue info
|
|
50
|
+
if (options.maxWait === 0) {
|
|
51
|
+
throw new QueuedAgentError(queuedResponse);
|
|
52
|
+
}
|
|
53
|
+
// Use SSE to monitor the operation
|
|
54
|
+
return this.waitForAgentCompletion(queuedResponse.operation_id, options);
|
|
55
|
+
}
|
|
56
|
+
// Unexpected response format
|
|
57
|
+
throw new Error('Unexpected response format from agent endpoint');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Execute specific agent type
|
|
61
|
+
*/
|
|
62
|
+
async executeAgent(graphId, agentType, request, options = {}) {
|
|
63
|
+
const data = {
|
|
64
|
+
url: '/v1/graphs/{graph_id}/agent/{agent_type}',
|
|
65
|
+
path: { graph_id: graphId, agent_type: agentType },
|
|
66
|
+
body: {
|
|
67
|
+
message: request.message,
|
|
68
|
+
history: request.history,
|
|
69
|
+
context: request.context,
|
|
70
|
+
mode: request.mode,
|
|
71
|
+
enable_rag: request.enableRag,
|
|
72
|
+
force_extended_analysis: request.forceExtendedAnalysis,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const response = await (0, sdk_gen_1.executeSpecificAgent)(data);
|
|
76
|
+
const responseData = response.data;
|
|
77
|
+
// Check if this is an immediate response (sync execution)
|
|
78
|
+
if (responseData?.content !== undefined && responseData?.agent_used) {
|
|
79
|
+
return {
|
|
80
|
+
content: responseData.content,
|
|
81
|
+
agent_used: responseData.agent_used,
|
|
82
|
+
mode_used: responseData.mode_used,
|
|
83
|
+
metadata: responseData.metadata,
|
|
84
|
+
tokens_used: responseData.tokens_used,
|
|
85
|
+
confidence_score: responseData.confidence_score,
|
|
86
|
+
execution_time: responseData.execution_time,
|
|
87
|
+
timestamp: new Date().toISOString(),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// Check if this is a queued response (async Celery execution)
|
|
91
|
+
if (responseData?.operation_id) {
|
|
92
|
+
const queuedResponse = responseData;
|
|
93
|
+
// If user doesn't want to wait, throw with queue info
|
|
94
|
+
if (options.maxWait === 0) {
|
|
95
|
+
throw new QueuedAgentError(queuedResponse);
|
|
96
|
+
}
|
|
97
|
+
// Use SSE to monitor the operation
|
|
98
|
+
return this.waitForAgentCompletion(queuedResponse.operation_id, options);
|
|
99
|
+
}
|
|
100
|
+
// Unexpected response format
|
|
101
|
+
throw new Error('Unexpected response format from agent endpoint');
|
|
102
|
+
}
|
|
103
|
+
async waitForAgentCompletion(operationId, options) {
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
const sseClient = new SSEClient_1.SSEClient(this.config);
|
|
106
|
+
sseClient
|
|
107
|
+
.connect(operationId)
|
|
108
|
+
.then(() => {
|
|
109
|
+
let result = null;
|
|
110
|
+
// Listen for progress events
|
|
111
|
+
sseClient.on(SSEClient_1.EventType.OPERATION_PROGRESS, (data) => {
|
|
112
|
+
options.onProgress?.(data.message, data.progress_percentage);
|
|
113
|
+
});
|
|
114
|
+
// Listen for agent-specific events
|
|
115
|
+
sseClient.on('agent_started', (data) => {
|
|
116
|
+
options.onProgress?.(`Agent ${data.agent_type} started`, 0);
|
|
117
|
+
});
|
|
118
|
+
sseClient.on('agent_initialized', (data) => {
|
|
119
|
+
options.onProgress?.(`${data.agent_name} initialized`, 10);
|
|
120
|
+
});
|
|
121
|
+
sseClient.on('progress', (data) => {
|
|
122
|
+
options.onProgress?.(data.message, data.percentage);
|
|
123
|
+
});
|
|
124
|
+
sseClient.on('agent_completed', (data) => {
|
|
125
|
+
result = {
|
|
126
|
+
content: data.content,
|
|
127
|
+
agent_used: data.agent_used,
|
|
128
|
+
mode_used: data.mode_used,
|
|
129
|
+
metadata: data.metadata,
|
|
130
|
+
tokens_used: data.tokens_used,
|
|
131
|
+
confidence_score: data.confidence_score,
|
|
132
|
+
execution_time: data.execution_time,
|
|
133
|
+
timestamp: data.timestamp || new Date().toISOString(),
|
|
134
|
+
};
|
|
135
|
+
sseClient.close();
|
|
136
|
+
resolve(result);
|
|
137
|
+
});
|
|
138
|
+
// Fallback to generic completion event
|
|
139
|
+
sseClient.on(SSEClient_1.EventType.OPERATION_COMPLETED, (data) => {
|
|
140
|
+
if (!result) {
|
|
141
|
+
const agentResult = data.result || data;
|
|
142
|
+
result = {
|
|
143
|
+
content: agentResult.content || '',
|
|
144
|
+
agent_used: agentResult.agent_used || 'unknown',
|
|
145
|
+
mode_used: agentResult.mode_used || 'standard',
|
|
146
|
+
metadata: agentResult.metadata,
|
|
147
|
+
tokens_used: agentResult.tokens_used,
|
|
148
|
+
confidence_score: agentResult.confidence_score,
|
|
149
|
+
execution_time: agentResult.execution_time,
|
|
150
|
+
timestamp: agentResult.timestamp || new Date().toISOString(),
|
|
151
|
+
};
|
|
152
|
+
sseClient.close();
|
|
153
|
+
resolve(result);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
sseClient.on(SSEClient_1.EventType.OPERATION_ERROR, (error) => {
|
|
157
|
+
sseClient.close();
|
|
158
|
+
reject(new Error(error.message || error.error));
|
|
159
|
+
});
|
|
160
|
+
sseClient.on(SSEClient_1.EventType.OPERATION_CANCELLED, () => {
|
|
161
|
+
sseClient.close();
|
|
162
|
+
reject(new Error('Agent execution cancelled'));
|
|
163
|
+
});
|
|
164
|
+
// Handle generic error event
|
|
165
|
+
sseClient.on('error', (error) => {
|
|
166
|
+
sseClient.close();
|
|
167
|
+
reject(new Error(error.error || error.message || 'Agent execution failed'));
|
|
168
|
+
});
|
|
169
|
+
})
|
|
170
|
+
.catch(reject);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Convenience method for simple agent queries with auto-selection
|
|
175
|
+
*/
|
|
176
|
+
async query(graphId, message, context) {
|
|
177
|
+
return this.executeQuery(graphId, { message, context }, { mode: 'auto' });
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Execute financial agent for financial analysis
|
|
181
|
+
*/
|
|
182
|
+
async analyzeFinancials(graphId, message, options = {}) {
|
|
183
|
+
return this.executeAgent(graphId, 'financial', { message }, options);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Execute research agent for deep research
|
|
187
|
+
*/
|
|
188
|
+
async research(graphId, message, options = {}) {
|
|
189
|
+
return this.executeAgent(graphId, 'research', { message }, options);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Execute RAG agent for fast retrieval
|
|
193
|
+
*/
|
|
194
|
+
async rag(graphId, message, options = {}) {
|
|
195
|
+
return this.executeAgent(graphId, 'rag', { message }, options);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Cancel any active SSE connections
|
|
199
|
+
*/
|
|
200
|
+
close() {
|
|
201
|
+
if (this.sseClient) {
|
|
202
|
+
this.sseClient.close();
|
|
203
|
+
this.sseClient = undefined;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.AgentClient = AgentClient;
|
|
208
|
+
/**
|
|
209
|
+
* Error thrown when agent execution is queued and maxWait is 0
|
|
210
|
+
*/
|
|
211
|
+
class QueuedAgentError extends Error {
|
|
212
|
+
constructor(queueInfo) {
|
|
213
|
+
super('Agent execution was queued');
|
|
214
|
+
this.queueInfo = queueInfo;
|
|
215
|
+
this.name = 'QueuedAgentError';
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.QueuedAgentError = QueuedAgentError;
|