@olbrain/js-sdk 1.0.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/README.md +488 -0
- package/dist/chunk-QEZYOGUI.mjs +29 -0
- package/dist/chunk-QEZYOGUI.mjs.map +1 -0
- package/dist/eventsource-TFSNWQMS.mjs +382 -0
- package/dist/eventsource-TFSNWQMS.mjs.map +1 -0
- package/dist/index.d.mts +250 -0
- package/dist/index.d.ts +250 -0
- package/dist/index.global.js +979 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +1001 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +573 -0
- package/dist/index.mjs.map +1 -0
- package/dist/widget.d.ts +345 -0
- package/dist/widget.widget.global.js +1747 -0
- package/dist/widget.widget.global.js.map +1 -0
- package/package.json +67 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Types for Olbrain JavaScript SDK
|
|
3
|
+
* Matches Python SDK data models for consistency
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for AgentClient
|
|
7
|
+
*/
|
|
8
|
+
interface AgentConfig {
|
|
9
|
+
agentId: string;
|
|
10
|
+
apiKey: string;
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Options for creating a new session
|
|
15
|
+
*/
|
|
16
|
+
interface CreateSessionOptions {
|
|
17
|
+
title?: string;
|
|
18
|
+
userId?: string;
|
|
19
|
+
metadata?: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for updating a session
|
|
23
|
+
*/
|
|
24
|
+
interface SessionUpdates {
|
|
25
|
+
title?: string;
|
|
26
|
+
metadata?: Record<string, any>;
|
|
27
|
+
status?: 'active' | 'archived';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for sending messages
|
|
31
|
+
*/
|
|
32
|
+
interface SendOptions {
|
|
33
|
+
metadata?: Record<string, any>;
|
|
34
|
+
timeout?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Token usage statistics
|
|
38
|
+
*/
|
|
39
|
+
interface TokenUsage {
|
|
40
|
+
promptTokens: number;
|
|
41
|
+
completionTokens: number;
|
|
42
|
+
totalTokens: number;
|
|
43
|
+
cost?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Session information
|
|
47
|
+
*/
|
|
48
|
+
interface SessionInfo {
|
|
49
|
+
sessionId: string;
|
|
50
|
+
title: string;
|
|
51
|
+
status: 'active' | 'archived';
|
|
52
|
+
createdAt: string;
|
|
53
|
+
messageCount: number;
|
|
54
|
+
userId?: string;
|
|
55
|
+
metadata: Record<string, any>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Session statistics
|
|
59
|
+
*/
|
|
60
|
+
interface SessionStats {
|
|
61
|
+
sessionId: string;
|
|
62
|
+
messageCount: number;
|
|
63
|
+
totalTokens: number;
|
|
64
|
+
createdAt: string;
|
|
65
|
+
lastMessageAt?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Chat response from the agent
|
|
69
|
+
*/
|
|
70
|
+
interface ChatResponse {
|
|
71
|
+
text: string;
|
|
72
|
+
sessionId: string;
|
|
73
|
+
success: boolean;
|
|
74
|
+
tokenUsage?: TokenUsage;
|
|
75
|
+
modelUsed?: string;
|
|
76
|
+
responseTimeMs?: number;
|
|
77
|
+
error?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Message in a conversation
|
|
81
|
+
*/
|
|
82
|
+
interface Message {
|
|
83
|
+
role: 'user' | 'assistant';
|
|
84
|
+
content: string;
|
|
85
|
+
timestamp: string;
|
|
86
|
+
metadata?: Record<string, any>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Callback for message events
|
|
90
|
+
*/
|
|
91
|
+
type MessageCallback = (message: Message) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Callback for error events
|
|
94
|
+
*/
|
|
95
|
+
type ErrorCallback = (error: Error) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Configuration for streaming
|
|
98
|
+
*/
|
|
99
|
+
interface StreamConfig {
|
|
100
|
+
sessionId: string;
|
|
101
|
+
apiKey: string;
|
|
102
|
+
agentId: string;
|
|
103
|
+
baseUrl: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Widget configuration
|
|
107
|
+
*/
|
|
108
|
+
interface WidgetConfig {
|
|
109
|
+
agentId: string;
|
|
110
|
+
apiKey: string;
|
|
111
|
+
position?: 'bottom-right' | 'bottom-left' | 'custom';
|
|
112
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
113
|
+
primaryColor?: string;
|
|
114
|
+
title?: string;
|
|
115
|
+
greeting?: string;
|
|
116
|
+
placeholder?: string;
|
|
117
|
+
autoOpen?: boolean;
|
|
118
|
+
persistSession?: boolean;
|
|
119
|
+
target?: string | HTMLElement;
|
|
120
|
+
onMessage?: MessageCallback;
|
|
121
|
+
baseUrl?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Main AgentClient class for communicating with Olbrain agents
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Main API client for interacting with Olbrain agents
|
|
130
|
+
*/
|
|
131
|
+
declare class AgentClient {
|
|
132
|
+
private config;
|
|
133
|
+
private streamManager;
|
|
134
|
+
constructor(config: AgentConfig);
|
|
135
|
+
/**
|
|
136
|
+
* Create a new session
|
|
137
|
+
*/
|
|
138
|
+
createSession(options?: CreateSessionOptions): Promise<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Get session information
|
|
141
|
+
* @note May not be implemented on all backends
|
|
142
|
+
*/
|
|
143
|
+
getSession(sessionId: string): Promise<SessionInfo>;
|
|
144
|
+
/**
|
|
145
|
+
* Update session information
|
|
146
|
+
* @note May not be implemented on all backends
|
|
147
|
+
*/
|
|
148
|
+
updateSession(sessionId: string, updates: SessionUpdates): Promise<SessionInfo>;
|
|
149
|
+
/**
|
|
150
|
+
* Delete a session
|
|
151
|
+
* @note May not be implemented on all backends
|
|
152
|
+
*/
|
|
153
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Get messages from a session
|
|
156
|
+
* @note May not be implemented on all backends
|
|
157
|
+
*/
|
|
158
|
+
getMessages(sessionId: string, limit?: number): Promise<Message[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Get session statistics
|
|
161
|
+
* @note May not be implemented on all backends
|
|
162
|
+
*/
|
|
163
|
+
getSessionStats(sessionId: string): Promise<SessionStats>;
|
|
164
|
+
/**
|
|
165
|
+
* Send a message and wait for response
|
|
166
|
+
*/
|
|
167
|
+
sendAndWait(sessionId: string, message: string, options?: SendOptions): Promise<ChatResponse>;
|
|
168
|
+
/**
|
|
169
|
+
* Send a message (fire and forget)
|
|
170
|
+
*/
|
|
171
|
+
send(sessionId: string, message: string): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Start listening for messages via SSE streaming
|
|
174
|
+
*/
|
|
175
|
+
listen(sessionId: string, onMessage: MessageCallback, onError?: ErrorCallback): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Stop listening for messages
|
|
178
|
+
*/
|
|
179
|
+
stopListening(sessionId: string): void;
|
|
180
|
+
/**
|
|
181
|
+
* Close client and clean up resources
|
|
182
|
+
*/
|
|
183
|
+
close(): void;
|
|
184
|
+
/**
|
|
185
|
+
* Helper method to make HTTP requests
|
|
186
|
+
*/
|
|
187
|
+
private _request;
|
|
188
|
+
/**
|
|
189
|
+
* Helper to parse session info from response
|
|
190
|
+
*/
|
|
191
|
+
private _parseSessionInfo;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Error classes for Olbrain SDK
|
|
196
|
+
*/
|
|
197
|
+
/**
|
|
198
|
+
* Base error class for all Olbrain errors
|
|
199
|
+
*/
|
|
200
|
+
declare class OlbrainError extends Error {
|
|
201
|
+
constructor(message: string);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Raised when authentication fails (invalid API key, missing auth header, etc.)
|
|
205
|
+
*/
|
|
206
|
+
declare class AuthenticationError extends OlbrainError {
|
|
207
|
+
constructor(message?: string);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Raised when a session is not found
|
|
211
|
+
*/
|
|
212
|
+
declare class SessionNotFoundError extends OlbrainError {
|
|
213
|
+
sessionId: string;
|
|
214
|
+
constructor(sessionId: string);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Raised when rate limit is exceeded
|
|
218
|
+
*/
|
|
219
|
+
declare class RateLimitError extends OlbrainError {
|
|
220
|
+
retryAfter?: number;
|
|
221
|
+
constructor(message?: string, retryAfter?: number);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Raised when a network error occurs
|
|
225
|
+
*/
|
|
226
|
+
declare class NetworkError extends OlbrainError {
|
|
227
|
+
statusCode?: number;
|
|
228
|
+
constructor(message?: string, statusCode?: number);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Raised when input validation fails
|
|
232
|
+
*/
|
|
233
|
+
declare class ValidationError extends OlbrainError {
|
|
234
|
+
constructor(message?: string);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Raised when streaming connection fails
|
|
238
|
+
*/
|
|
239
|
+
declare class StreamingError extends OlbrainError {
|
|
240
|
+
constructor(message?: string);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Olbrain JavaScript SDK
|
|
245
|
+
* Main entry point for core API exports
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
declare const VERSION = "1.0.0";
|
|
249
|
+
|
|
250
|
+
export { AgentClient, type AgentConfig, AuthenticationError, type ChatResponse, type CreateSessionOptions, type ErrorCallback, type Message, type MessageCallback, NetworkError, OlbrainError, RateLimitError, type SendOptions, type SessionInfo, SessionNotFoundError, type SessionStats, type SessionUpdates, type StreamConfig, StreamingError, type TokenUsage, VERSION, ValidationError, type WidgetConfig };
|