@elqnt/agent-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 ADDED
@@ -0,0 +1,401 @@
1
+ # @eloquent/agent-sdk
2
+
3
+ Build custom AI agent UIs with ease. The Eloquent Agent SDK provides a developer-friendly framework for creating agent interfaces, from simple chat widgets to complex custom implementations.
4
+
5
+ ## Features
6
+
7
+ ✅ **Phase 1: Foundation** (Available Now)
8
+ - 🎯 Core hooks for agent interaction
9
+ - 💬 WebSocket-based real-time chat
10
+ - 🔧 Client-side tool execution
11
+ - 📊 Metadata management
12
+ - 🎭 TypeScript-first with full type safety
13
+ - 📝 Comprehensive JSDoc documentation
14
+
15
+ 🚧 **Coming Soon**
16
+ - Phase 2: React component library
17
+ - Phase 3: Pre-built widgets
18
+ - Phase 4: CLI tools and templates
19
+ - Phase 5: Visual builder and developer portal
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @eloquent/agent-sdk
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### Option 1: All-in-One Hook (Recommended)
30
+
31
+ The `useAgent` hook provides everything you need in one place:
32
+
33
+ ```tsx
34
+ import { useAgent } from '@eloquent/agent-sdk';
35
+
36
+ function MyAgentUI() {
37
+ const {
38
+ messages,
39
+ sendMessage,
40
+ isConnected,
41
+ isWaiting,
42
+ executeClientTool,
43
+ metadata,
44
+ updateMetadata
45
+ } = useAgent({
46
+ agentId: 'your-agent-id',
47
+ orgId: 'your-org-id',
48
+ serverBaseUrl: 'wss://chat.example.com',
49
+ userEmail: 'user@example.com',
50
+ tools: {
51
+ 'search_products': async (params) => {
52
+ const results = await api.search(params.query);
53
+ return { products: results };
54
+ }
55
+ }
56
+ });
57
+
58
+ return (
59
+ <div>
60
+ <div className="messages">
61
+ {messages.map(msg => (
62
+ <div key={msg.id}>{msg.content}</div>
63
+ ))}
64
+ </div>
65
+
66
+ <input
67
+ onKeyPress={(e) => {
68
+ if (e.key === 'Enter') {
69
+ sendMessage(e.currentTarget.value);
70
+ e.currentTarget.value = '';
71
+ }
72
+ }}
73
+ disabled={!isConnected}
74
+ />
75
+
76
+ {isWaiting && <div>Agent is typing...</div>}
77
+ </div>
78
+ );
79
+ }
80
+ ```
81
+
82
+ ### Option 2: Individual Hooks
83
+
84
+ For more control, use hooks separately:
85
+
86
+ #### Chat Functionality
87
+
88
+ ```tsx
89
+ import { useAgentChat } from '@eloquent/agent-sdk';
90
+
91
+ function ChatComponent() {
92
+ const {
93
+ messages,
94
+ sendMessage,
95
+ isConnected,
96
+ startNewChat
97
+ } = useAgentChat({
98
+ agentId: 'your-agent-id',
99
+ orgId: 'your-org-id',
100
+ serverBaseUrl: 'wss://chat.example.com',
101
+ userEmail: 'user@example.com'
102
+ });
103
+
104
+ useEffect(() => {
105
+ startNewChat();
106
+ }, []);
107
+
108
+ return (
109
+ // Your UI
110
+ );
111
+ }
112
+ ```
113
+
114
+ #### Tool Execution
115
+
116
+ ```tsx
117
+ import { useAgentTools } from '@eloquent/agent-sdk';
118
+
119
+ function ToolsComponent() {
120
+ const { executeClientTool, registerTool } = useAgentTools({
121
+ tools: {
122
+ 'track_order': async ({ orderId }) => {
123
+ const order = await api.getOrder(orderId);
124
+ return { status: order.status };
125
+ }
126
+ },
127
+ onToolExecuted: (toolName, result) => {
128
+ console.log(`Tool ${toolName} executed:`, result);
129
+ }
130
+ });
131
+
132
+ return (
133
+ // Your UI
134
+ );
135
+ }
136
+ ```
137
+
138
+ ## API Reference
139
+
140
+ ### useAgent(config)
141
+
142
+ All-in-one hook for complete agent interaction.
143
+
144
+ #### Configuration
145
+
146
+ ```typescript
147
+ interface UseAgentConfig {
148
+ agentId: string; // Required: Agent ID
149
+ orgId: string; // Required: Organization ID
150
+ serverBaseUrl: string; // Required: WebSocket server URL
151
+ userEmail: string; // Required: User identifier
152
+ tools?: ToolHandlers; // Optional: Client-side tool handlers
153
+ initialMetadata?: Record<string, any>; // Optional: Initial metadata
154
+ features?: AgentFeatures; // Optional: Feature flags
155
+ onMessage?: (event: ChatEvent) => void;
156
+ onConnect?: () => void;
157
+ onDisconnect?: () => void;
158
+ onToolCall?: (toolName: string, params: any) => void;
159
+ onCSATSubmit?: (response: any) => void;
160
+ autoReconnect?: boolean; // Default: true
161
+ debug?: boolean; // Default: false
162
+ }
163
+ ```
164
+
165
+ #### Returns
166
+
167
+ ```typescript
168
+ {
169
+ // Agent info
170
+ agent: Agent | undefined;
171
+
172
+ // Chat state
173
+ messages: ChatMessage[];
174
+ currentChat: Chat | undefined;
175
+ users: ChatUser[];
176
+ isConnected: boolean;
177
+ isWaiting: boolean;
178
+ chatKey: string | undefined;
179
+ error: AgentError | undefined;
180
+
181
+ // Chat actions
182
+ sendMessage: (content: string) => Promise<void>;
183
+ startNewChat: () => Promise<void>;
184
+ endChat: () => void;
185
+ resetChat: () => void;
186
+ disconnect: (intentional?: boolean) => void;
187
+
188
+ // Tools
189
+ tools: Record<string, Tool>;
190
+ executeClientTool: (toolName: string, params: any) => Promise<any>;
191
+ registerTool: (toolName: string, handler: ToolHandler) => void;
192
+ unregisterTool: (toolName: string) => void;
193
+
194
+ // Metadata
195
+ metadata: Record<string, any>;
196
+ updateMetadata: (updates: Record<string, any>) => void;
197
+ clearMetadata: () => void;
198
+
199
+ // CSAT
200
+ csatSurvey: CSATSurvey | undefined;
201
+ submitCSATResponse: (response: any) => void;
202
+ dismissCSAT: () => void;
203
+
204
+ // Analytics
205
+ logEvent: (eventData: any) => Promise<void>;
206
+ }
207
+ ```
208
+
209
+ ### useAgentChat(config)
210
+
211
+ Hook for WebSocket chat functionality only.
212
+
213
+ See detailed API documentation in TypeScript definitions.
214
+
215
+ ### useAgentTools(config)
216
+
217
+ Hook for client-side tool execution only.
218
+
219
+ See detailed API documentation in TypeScript definitions.
220
+
221
+ ## Examples
222
+
223
+ ### E-commerce Shopping Assistant
224
+
225
+ ```tsx
226
+ import { useAgent } from '@eloquent/agent-sdk';
227
+
228
+ function ShoppingAssistant() {
229
+ const {
230
+ messages,
231
+ sendMessage,
232
+ metadata,
233
+ updateMetadata,
234
+ executeClientTool
235
+ } = useAgent({
236
+ agentId: 'shopping-agent',
237
+ orgId: 'my-store',
238
+ serverBaseUrl: 'wss://chat.mystore.com',
239
+ userEmail: 'customer@example.com',
240
+ tools: {
241
+ 'add_to_cart': async ({ productId }) => {
242
+ const product = await api.getProduct(productId);
243
+ updateMetadata({
244
+ cart: [...(metadata.cart || []), product]
245
+ });
246
+ return { success: true };
247
+ },
248
+ 'search_products': async ({ query }) => {
249
+ const results = await api.search(query);
250
+ return { products: results };
251
+ }
252
+ }
253
+ });
254
+
255
+ return (
256
+ <div className="shopping-assistant">
257
+ {/* Your shopping assistant UI */}
258
+ </div>
259
+ );
260
+ }
261
+ ```
262
+
263
+ ### Customer Support
264
+
265
+ ```tsx
266
+ import { useAgent } from '@eloquent/agent-sdk';
267
+
268
+ function SupportChat() {
269
+ const {
270
+ messages,
271
+ sendMessage,
272
+ csatSurvey,
273
+ submitCSATResponse
274
+ } = useAgent({
275
+ agentId: 'support-agent',
276
+ orgId: 'my-company',
277
+ serverBaseUrl: 'wss://support.mycompany.com',
278
+ userEmail: 'user@example.com',
279
+ features: {
280
+ csat: true,
281
+ handoff: true
282
+ }
283
+ });
284
+
285
+ return (
286
+ <div className="support-chat">
287
+ {/* Chat UI */}
288
+
289
+ {csatSurvey && (
290
+ <CSATForm
291
+ survey={csatSurvey}
292
+ onSubmit={submitCSATResponse}
293
+ />
294
+ )}
295
+ </div>
296
+ );
297
+ }
298
+ ```
299
+
300
+ ## TypeScript Support
301
+
302
+ The SDK is written in TypeScript and provides full type safety:
303
+
304
+ ```typescript
305
+ import { useAgent, ToolHandler } from '@eloquent/agent-sdk';
306
+
307
+ // Type-safe tool handlers
308
+ const tools: Record<string, ToolHandler> = {
309
+ 'search': async (params: { query: string }) => {
310
+ return { results: [] };
311
+ }
312
+ };
313
+
314
+ const agent = useAgent({
315
+ agentId: 'my-agent',
316
+ orgId: 'my-org',
317
+ serverBaseUrl: 'wss://...',
318
+ userEmail: 'user@example.com',
319
+ tools
320
+ });
321
+
322
+ // All properties are fully typed
323
+ agent.messages.forEach(msg => {
324
+ console.log(msg.content); // ✅ TypeScript knows the structure
325
+ });
326
+ ```
327
+
328
+ ## Advanced Usage
329
+
330
+ ### Custom Tool Handlers
331
+
332
+ ```tsx
333
+ const { registerTool, unregisterTool } = useAgentTools();
334
+
335
+ // Register a tool dynamically
336
+ registerTool('custom_analysis', async (params) => {
337
+ const result = await performAnalysis(params);
338
+ return result;
339
+ });
340
+
341
+ // Unregister when no longer needed
342
+ unregisterTool('custom_analysis');
343
+ ```
344
+
345
+ ### Metadata Management
346
+
347
+ ```tsx
348
+ const { metadata, updateMetadata, clearMetadata } = useAgent({
349
+ // ... config
350
+ });
351
+
352
+ // Update metadata
353
+ updateMetadata({
354
+ selectedProduct: product,
355
+ cartItems: [...metadata.cartItems, newItem]
356
+ });
357
+
358
+ // Clear all metadata
359
+ clearMetadata();
360
+ ```
361
+
362
+ ### Analytics Tracking
363
+
364
+ ```tsx
365
+ const { logEvent } = useAgent({
366
+ // ... config
367
+ features: {
368
+ analytics: true
369
+ }
370
+ });
371
+
372
+ // Track custom events
373
+ await logEvent({
374
+ eventType: 'product_viewed',
375
+ productId: '123',
376
+ source: 'agent_recommendation'
377
+ });
378
+ ```
379
+
380
+ ## Roadmap
381
+
382
+ - ✅ **Phase 1: Foundation** - Core hooks and type system
383
+ - 🚧 **Phase 2: Component Library** - Pre-built React components
384
+ - 🚧 **Phase 3: Widget SDK** - Production-ready widgets
385
+ - 🚧 **Phase 4: CLI & Templates** - Developer tools
386
+ - 🚧 **Phase 5: Developer Portal** - Visual builders and docs
387
+
388
+ ## Contributing
389
+
390
+ This is an internal package for the Eloquent platform. For questions or issues, contact the Eloquent team.
391
+
392
+ ## License
393
+
394
+ Proprietary - Eloquent Platform
395
+
396
+ ## Documentation
397
+
398
+ For complete documentation, see:
399
+ - Design Document: `/docs/agents-sdk.md`
400
+ - API Reference: TypeScript definitions
401
+ - Examples: `/examples` (coming soon)