@jivaai/agent-chat-typescript 0.1.0
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/LICENSE +22 -0
- package/README.md +793 -0
- package/dist/api.d.ts +121 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +1032 -0
- package/dist/api.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +18 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +97 -0
- package/dist/logger.js.map +1 -0
- package/dist/types.d.ts +340 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -0
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jiva.ai Agent Chat API Client
|
|
3
|
+
*
|
|
4
|
+
* A simple REST API client for interacting with Jiva.ai workflows.
|
|
5
|
+
*/
|
|
6
|
+
import { ApiConfig, ApiResponse, SuccessCallback, ErrorCallback, InitiateConversationRequest, InitiateConversationWithContext, ConversationResponse, PollRequest, PollResponse, PollingOptions, UploadResponse, SocketOptions, SocketCallbacks } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Clears the cached EventSource class (useful for testing)
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function clearEventSourceCache(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Jiva.ai API Client
|
|
14
|
+
*/
|
|
15
|
+
export declare class JivaApiClient {
|
|
16
|
+
private config;
|
|
17
|
+
private reconnectAttemptsMap;
|
|
18
|
+
private reconnectScheduledMap;
|
|
19
|
+
private logger;
|
|
20
|
+
constructor(config: ApiConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Makes a GET request to the API
|
|
23
|
+
*
|
|
24
|
+
* @param endpoint - Optional endpoint path (appended to base URL)
|
|
25
|
+
* @param onSuccess - Optional success callback
|
|
26
|
+
* @param onError - Optional error callback
|
|
27
|
+
* @returns Promise with the API response
|
|
28
|
+
*/
|
|
29
|
+
get<T = unknown>(endpoint?: string, onSuccess?: SuccessCallback<T>, onError?: ErrorCallback): Promise<ApiResponse<T>>;
|
|
30
|
+
/**
|
|
31
|
+
* Makes a POST request to the API
|
|
32
|
+
*
|
|
33
|
+
* @param payload - JSON payload to send
|
|
34
|
+
* @param endpoint - Optional endpoint path (appended to base URL)
|
|
35
|
+
* @param onSuccess - Optional success callback
|
|
36
|
+
* @param onError - Optional error callback
|
|
37
|
+
* @returns Promise with the API response
|
|
38
|
+
*/
|
|
39
|
+
post<T = unknown>(payload?: Record<string, unknown>, endpoint?: string, onSuccess?: SuccessCallback<T>, onError?: ErrorCallback): Promise<ApiResponse<T>>;
|
|
40
|
+
/**
|
|
41
|
+
* Polls for the status of a running conversation
|
|
42
|
+
*
|
|
43
|
+
* @param sessionId - The session ID from the original request
|
|
44
|
+
* @param executionId - The ID from the RUNNING response
|
|
45
|
+
* @param options - Polling options
|
|
46
|
+
* @returns Promise with the poll response
|
|
47
|
+
*/
|
|
48
|
+
private pollConversationStatus;
|
|
49
|
+
/**
|
|
50
|
+
* Polls for the status of a running conversation (public method)
|
|
51
|
+
*
|
|
52
|
+
* @param request - Poll request with sessionId, id, and mode
|
|
53
|
+
* @param onSuccess - Optional success callback
|
|
54
|
+
* @param onError - Optional error callback
|
|
55
|
+
* @returns Promise with the poll response
|
|
56
|
+
*/
|
|
57
|
+
poll(request: PollRequest, onSuccess?: SuccessCallback<PollResponse>, onError?: ErrorCallback): Promise<ApiResponse<PollResponse>>;
|
|
58
|
+
/**
|
|
59
|
+
* Validates and normalizes conversation messages
|
|
60
|
+
*/
|
|
61
|
+
private validateAndNormalizeMessages;
|
|
62
|
+
/**
|
|
63
|
+
* Initiates a conversation with the Jiva.ai agent
|
|
64
|
+
*
|
|
65
|
+
* @param request - Conversation request (single message or array of messages for context)
|
|
66
|
+
* @param options - Optional polling options for RUNNING state
|
|
67
|
+
* @param onSuccess - Optional success callback
|
|
68
|
+
* @param onError - Optional error callback
|
|
69
|
+
* @returns Promise with the conversation response
|
|
70
|
+
*/
|
|
71
|
+
initiateConversation(request: InitiateConversationRequest | InitiateConversationWithContext, options?: PollingOptions, onSuccess?: SuccessCallback<ConversationResponse>, onError?: ErrorCallback): Promise<ApiResponse<ConversationResponse>>;
|
|
72
|
+
/**
|
|
73
|
+
* Uploads a file to the File Upload Cache
|
|
74
|
+
*
|
|
75
|
+
* @param file - The file to upload (File, Blob, or base64 string)
|
|
76
|
+
* @param onSuccess - Optional success callback
|
|
77
|
+
* @param onError - Optional error callback
|
|
78
|
+
* @returns Promise with the upload response containing the assetId
|
|
79
|
+
*/
|
|
80
|
+
uploadFile(file: File | Blob | string, onSuccess?: SuccessCallback<UploadResponse>, onError?: ErrorCallback): Promise<ApiResponse<UploadResponse>>;
|
|
81
|
+
/**
|
|
82
|
+
* Uploads text to the Text Upload Cache
|
|
83
|
+
*
|
|
84
|
+
* @param text - The text content to upload
|
|
85
|
+
* @param onSuccess - Optional success callback
|
|
86
|
+
* @param onError - Optional error callback
|
|
87
|
+
* @returns Promise with the upload response containing the assetId
|
|
88
|
+
*/
|
|
89
|
+
uploadText(text: string, onSuccess?: SuccessCallback<UploadResponse>, onError?: ErrorCallback): Promise<ApiResponse<UploadResponse>>;
|
|
90
|
+
/**
|
|
91
|
+
* Uploads table data to the Table Upload Cache
|
|
92
|
+
*
|
|
93
|
+
* @param tableData - The table data to upload (array of objects with consistent structure)
|
|
94
|
+
* @param onSuccess - Optional success callback
|
|
95
|
+
* @param onError - Optional error callback
|
|
96
|
+
* @returns Promise with the upload response containing the assetId
|
|
97
|
+
*/
|
|
98
|
+
uploadTable(tableData: Record<string, unknown>[], onSuccess?: SuccessCallback<UploadResponse>, onError?: ErrorCallback): Promise<ApiResponse<UploadResponse>>;
|
|
99
|
+
/**
|
|
100
|
+
* Helper method to convert File/Blob to base64 string
|
|
101
|
+
*/
|
|
102
|
+
private fileToBase64;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a Server-Sent Events (SSE) connection to subscribe to real-time agent updates
|
|
105
|
+
* Uses POST request to initiate the connection, then streams SSE events.
|
|
106
|
+
*
|
|
107
|
+
* The backend Spring implementation sends an initial "connected" event when the connection is established,
|
|
108
|
+
* followed by streaming agent update messages.
|
|
109
|
+
*
|
|
110
|
+
* @param sessionId - The session ID to subscribe to
|
|
111
|
+
* @param callbacks - Event callbacks for socket events
|
|
112
|
+
* @param options - Socket connection options
|
|
113
|
+
* @returns An object that mimics EventSource interface for compatibility
|
|
114
|
+
*/
|
|
115
|
+
subscribeToSocket(sessionId: string, callbacks?: SocketCallbacks, options?: SocketOptions): {
|
|
116
|
+
url: string;
|
|
117
|
+
close: () => void;
|
|
118
|
+
readyState: number;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,SAAS,EACT,WAAW,EACX,eAAe,EACf,aAAa,EACb,2BAA2B,EAC3B,+BAA+B,EAE/B,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,cAAc,EAEd,aAAa,EACb,eAAe,EAEhB,MAAM,SAAS,CAAC;AAUjB;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AA0LD;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAY;IAE1B,OAAO,CAAC,oBAAoB,CAA6B;IAEzD,OAAO,CAAC,qBAAqB,CAA8B;IAC3D,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,SAAS;IAwB7B;;;;;;;OAOG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EACnB,QAAQ,CAAC,EAAE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