guideai-app 0.3.4 → 0.4.1

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.
@@ -0,0 +1,398 @@
1
+ # Workflow Trigger Feature - Usage Guide
2
+
3
+ ## Overview
4
+
5
+ The GuideAI package now supports workflow triggers based on trigger words detected in user messages. This feature allows you to create dynamic workflows that are activated when specific keywords or phrases are mentioned by users. Workflows are configured entirely through the `initialize-session` API endpoint.
6
+
7
+ ## Features
8
+
9
+ ✅ **Trigger Word Detection**: Automatically detect trigger words in user messages
10
+ ✅ **Workflow Integration**: Seamlessly integrate with your backend workflow system
11
+ ✅ **Dynamic Prompts**: Workflow-specific prompts from the initialize-session API
12
+ ✅ **Tool-based Triggers**: AI can call workflow triggers through function calls
13
+ ✅ **Configurable**: Support for multiple workflows with different trigger patterns
14
+ ✅ **No Additional API**: All workflow configuration handled through initialize-session
15
+
16
+ ## Setup
17
+
18
+ ### 1. Backend API Endpoint
19
+
20
+ You only need to implement the `initialize-session` endpoint:
21
+
22
+ #### POST `/initialize-session`
23
+ Returns workflow-specific prompts, session data, and available workflows:
24
+
25
+ ```json
26
+ {
27
+ "organizationKey": "your-org-key",
28
+ "workflowKey": "customer-support",
29
+ "userId": "anonymous",
30
+ "date": "2024-01-15",
31
+ "time": "14:30:00",
32
+ "messages": []
33
+ }
34
+ ```
35
+
36
+ Response:
37
+ ```json
38
+ {
39
+ "id": "conversation-uuid",
40
+ "ephemeralToken": "openai-realtime-token",
41
+ "prompt": "You are Guide AI. Your role is to help users...",
42
+ "workflows": [
43
+ {
44
+ "id": "workflow-uuid",
45
+ "name": "Customer Support Workflow",
46
+ "triggers": ["help", "support", "customer service"],
47
+ "organizationKey": "org-key-123",
48
+ "prompt": "You are a helpful customer support agent...",
49
+ "archived": false,
50
+ "createdAt": "2024-01-01T00:00:00.000Z",
51
+ "updatedAt": "2024-01-01T00:00:00.000Z"
52
+ }
53
+ ]
54
+ }
55
+ ```
56
+
57
+ ### 2. Frontend Configuration
58
+
59
+ #### Basic Usage
60
+
61
+ ```typescript
62
+ import GuideAI from 'guideai-app';
63
+
64
+ function App() {
65
+ return (
66
+ <GuideAI
67
+ organizationKey="your-organization-key"
68
+ workflowKey="customer-support"
69
+ position={{ bottom: '2rem', right: '2rem' }}
70
+ onError={(error) => console.error(error)}
71
+ />
72
+ );
73
+ }
74
+ ```
75
+
76
+ #### Advanced Configuration
77
+
78
+ ```typescript
79
+ <GuideAI
80
+ organizationKey="your-org-key"
81
+ workflowKey="customer-support"
82
+ position={{ bottom: '2rem', right: '2rem' }}
83
+ onError={(error) => console.error(error)}
84
+ transcript={{
85
+ enabled: true,
86
+ showToggleButton: true,
87
+ position: 'right'
88
+ }}
89
+ input={{
90
+ enableTextInput: true,
91
+ showInputToggle: true,
92
+ defaultMode: 'voice',
93
+ placeholder: "How can I help you today?"
94
+ }}
95
+ />
96
+ ```
97
+
98
+ ## How It Works
99
+
100
+ ### 1. Session Initialization
101
+ When a conversation starts, the system:
102
+ - Calls `/initialize-session` with the `workflowKey`
103
+ - Receives a workflow-specific prompt and available workflows
104
+ - Configures the AI with trigger word detection capabilities for each workflow
105
+
106
+ ### 2. Workflow Configuration
107
+ The system automatically:
108
+ - Creates individual tools for each active workflow
109
+ - Configures trigger words for each workflow
110
+ - Sets up function call handlers for workflow activation
111
+
112
+ ### 3. Trigger Word Detection
113
+ The AI automatically:
114
+ - Analyzes user messages for trigger words from all workflows
115
+ - Detects patterns like "help", "support", "issue", "problem", etc.
116
+ - Calls the appropriate `trigger_workflow_[id]` function when triggers are found
117
+
118
+ ### 4. Workflow Execution
119
+ When triggers are detected:
120
+ - The AI calls the specific workflow trigger function
121
+ - The workflow's prompt is sent as a system message to guide the AI
122
+ - The AI continues the conversation using the workflow-specific instructions
123
+
124
+ ## Workflow Data Schema
125
+
126
+ ```typescript
127
+ interface Workflow {
128
+ id: string; // Unique workflow identifier
129
+ name: string; // Human-readable workflow name
130
+ triggers: string[]; // Array of trigger words/phrases
131
+ organizationKey: string; // Organization this workflow belongs to
132
+ prompt: string; // Workflow-specific prompt for the AI
133
+ archived: boolean; // Whether the workflow is archived
134
+ createdAt: string; // ISO timestamp of creation
135
+ updatedAt: string; // ISO timestamp of last update
136
+ }
137
+ ```
138
+
139
+ ## Example Workflows
140
+
141
+ ### Customer Support Workflow
142
+
143
+ ```json
144
+ {
145
+ "id": "support-workflow-123",
146
+ "name": "Customer Support Workflow",
147
+ "triggers": ["help", "support", "issue", "problem", "broken"],
148
+ "organizationKey": "acme-corp",
149
+ "prompt": "You are a helpful customer support agent. When users have issues, be empathetic and provide clear solutions. Always ask for specific details about their problem and offer to escalate if needed.",
150
+ "archived": false,
151
+ "createdAt": "2024-01-01T00:00:00.000Z",
152
+ "updatedAt": "2024-01-01T00:00:00.000Z"
153
+ }
154
+ ```
155
+
156
+ ### Sales Workflow
157
+
158
+ ```json
159
+ {
160
+ "id": "sales-workflow-456",
161
+ "name": "Sales Inquiry Workflow",
162
+ "triggers": ["pricing", "cost", "buy", "purchase", "quote"],
163
+ "organizationKey": "acme-corp",
164
+ "prompt": "You are a sales representative. When users ask about pricing or purchasing, provide detailed information about our products and services. Always ask about their specific needs and budget to provide the best recommendations.",
165
+ "archived": false,
166
+ "createdAt": "2024-01-01T00:00:00.000Z",
167
+ "updatedAt": "2024-01-01T00:00:00.000Z"
168
+ }
169
+ ```
170
+
171
+ ### Technical Support Workflow
172
+
173
+ ```json
174
+ {
175
+ "id": "tech-support-789",
176
+ "name": "Technical Support Workflow",
177
+ "triggers": ["error", "bug", "crash", "not working", "technical"],
178
+ "organizationKey": "acme-corp",
179
+ "prompt": "You are a technical support specialist. When users report technical issues, ask for specific error messages, steps to reproduce, and their system information. Provide troubleshooting steps and escalate complex issues.",
180
+ "archived": false,
181
+ "createdAt": "2024-01-01T00:00:00.000Z",
182
+ "updatedAt": "2024-01-01T00:00:00.000Z"
183
+ }
184
+ ```
185
+
186
+ ## Configuration Options
187
+
188
+ ### Workflow Keys
189
+ Different workflow keys can be used for different scenarios:
190
+
191
+ - `customer-support`: General customer service
192
+ - `sales-inquiry`: Sales and pricing questions
193
+ - `technical-support`: Technical issues and bugs
194
+ - `onboarding`: New user guidance
195
+ - `billing`: Payment and billing issues
196
+
197
+ ### Trigger Word Patterns
198
+ The system supports various trigger patterns:
199
+
200
+ - **Exact matches**: "help", "support"
201
+ - **Phrases**: "how to", "what is", "can you"
202
+ - **Contextual**: "broken", "not working", "issue"
203
+
204
+ ## Best Practices
205
+
206
+ ### 1. Define Clear Trigger Words
207
+ - Use specific, actionable trigger words
208
+ - Avoid overly broad terms that might cause false positives
209
+ - Consider synonyms and variations
210
+
211
+ ### 2. Write Effective Workflow Prompts
212
+ - Be specific about the AI's role and behavior
213
+ - Include guidelines for handling different scenarios
214
+ - Provide examples of good responses
215
+
216
+ ### 3. Monitor and Optimize
217
+ - Track which triggers are most effective
218
+ - Adjust trigger words based on user behavior
219
+ - Optimize workflow prompts based on feedback
220
+
221
+ ### 4. Handle Edge Cases
222
+ - Provide fallback responses for unclear triggers
223
+ - Handle multiple trigger words in the same message
224
+ - Consider user context and conversation history
225
+
226
+ ## Error Handling
227
+
228
+ The system includes robust error handling:
229
+
230
+ - **Network errors**: Graceful fallback to default behavior
231
+ - **Invalid workflows**: Logging and user-friendly error messages
232
+ - **Missing workflow data**: Fallback to default prompt
233
+ - **Archived workflows**: Automatically excluded from triggers
234
+
235
+ ## Integration Examples
236
+
237
+ ### React Application
238
+ ```typescript
239
+ import GuideAI from 'guideai-app';
240
+
241
+ function CustomerSupportPage() {
242
+ return (
243
+ <div>
244
+ <h1>Customer Support</h1>
245
+ <GuideAI
246
+ organizationKey="acme-corp"
247
+ workflowKey="customer-support"
248
+ position={{ bottom: '2rem', right: '2rem' }}
249
+ onError={(error) => {
250
+ console.error('GuideAI Error:', error);
251
+ // Handle error appropriately
252
+ }}
253
+ />
254
+ </div>
255
+ );
256
+ }
257
+ ```
258
+
259
+ ### Next.js Application
260
+ ```typescript
261
+ // app/support/page.tsx
262
+ 'use client';
263
+
264
+ import GuideAI from 'guideai-app';
265
+
266
+ export default function SupportPage() {
267
+ return (
268
+ <div>
269
+ <GuideAI
270
+ organizationKey={process.env.NEXT_PUBLIC_ORG_KEY}
271
+ workflowKey="customer-support"
272
+ position={{ bottom: '2rem', right: '2rem' }}
273
+ transcript={{ enabled: true, position: 'right' }}
274
+ input={{ enableTextInput: true, defaultMode: 'text' }}
275
+ />
276
+ </div>
277
+ );
278
+ }
279
+ ```
280
+
281
+ ## Logging and Monitoring
282
+
283
+ The system provides comprehensive logging for workflow events:
284
+
285
+ ### Console Logs
286
+ All workflow events are logged to the browser console with clear formatting:
287
+
288
+ ```
289
+ 🔧 [2:30:15 PM] Workflows initialized: 3 active workflow(s)
290
+ 🎯 [2:30:45 PM] Trigger words detected: Customer Support Workflow
291
+ 🚀 [2:30:46 PM] Workflow activated: Customer Support Workflow
292
+ ```
293
+
294
+ ### Transcript Logs
295
+ Workflow events are also logged in the conversation transcript:
296
+
297
+ - **Workflow Initialization**: Shows all available workflows and their trigger words
298
+ - **Trigger Detection**: Indicates when trigger words are detected in user messages
299
+ - **Workflow Activation**: Confirms when a workflow is activated and provides context
300
+
301
+ ### Log Event Types
302
+
303
+ 1. **Workflow Initialization** (`workflow_init`)
304
+ - Logged when workflows are loaded from the API
305
+ - Shows total workflows and active workflows
306
+ - Lists all trigger words for each workflow
307
+
308
+ 2. **Trigger Detection** (`trigger_detected`)
309
+ - Logged when trigger words are found in user messages
310
+ - Shows which workflows were triggered
311
+ - Includes the user message that triggered them
312
+
313
+ 3. **Workflow Activation** (`workflow_activated`)
314
+ - Logged when a workflow is actually activated
315
+ - Shows the workflow name and trigger words used
316
+ - Includes the user message that caused activation
317
+
318
+ ### Debug Mode
319
+ Enable detailed logging by checking the browser console:
320
+
321
+ ```typescript
322
+ <GuideAI
323
+ organizationKey="your-org-key"
324
+ workflowKey="customer-support"
325
+ onError={(error, context) => {
326
+ console.log('GuideAI Error:', { error, context });
327
+ }}
328
+ />
329
+ ```
330
+
331
+ ## Troubleshooting
332
+
333
+ ### Common Issues
334
+
335
+ 1. **Workflows not triggering**
336
+ - Check that workflows are returned in the `/initialize-session` response
337
+ - Verify trigger words are correctly defined
338
+ - Ensure workflows are not archived
339
+ - Check console logs for workflow initialization messages
340
+
341
+ 2. **No workflow prompt received**
342
+ - Verify `/initialize-session` endpoint returns a `workflows` array
343
+ - Check that `workflowKey` is being sent in the request
344
+ - Ensure backend is properly configured for the workflow
345
+ - Look for workflow initialization logs in console
346
+
347
+ 3. **Function calls not working**
348
+ - Check browser console for errors
349
+ - Verify WebRTC connection is established
350
+ - Ensure session configuration includes the workflow trigger tools
351
+ - Check for trigger detection logs in console
352
+
353
+ ### Debug Mode
354
+ Enable debug logging to troubleshoot issues:
355
+
356
+ ```typescript
357
+ <GuideAI
358
+ organizationKey="your-org-key"
359
+ workflowKey="customer-support"
360
+ onError={(error, context) => {
361
+ console.log('GuideAI Error:', { error, context });
362
+ }}
363
+ />
364
+ ```
365
+
366
+ ## API Reference
367
+
368
+ ### GuideAI Props
369
+ ```typescript
370
+ interface GuideAIProps {
371
+ organizationKey: string; // Required: Your organization key
372
+ workflowKey?: string; // Optional: Workflow key for filtering
373
+ position?: PositionConfig; // Optional: Component positioning
374
+ onError?: ErrorHandler; // Optional: Error handling
375
+ // ... other props
376
+ }
377
+ ```
378
+
379
+ ### Workflow API Endpoints
380
+ - `POST /initialize-session`: Initialize conversation with workflows
381
+ - `POST /conversations/{id}/messages`: Log conversation messages
382
+
383
+ ### Workflow Utilities
384
+ ```typescript
385
+ // Detect which workflows should be triggered
386
+ detectWorkflowTriggers(message: string, workflows: Workflow[]): Workflow[]
387
+
388
+ // Get trigger words for a specific workflow
389
+ getWorkflowTriggerWords(message: string, workflow: Workflow): string[]
390
+
391
+ // Check if any workflows should be triggered
392
+ hasWorkflowTriggers(message: string, workflows: Workflow[]): boolean
393
+
394
+ // Get the most relevant workflow
395
+ getMostRelevantWorkflow(message: string, workflows: Workflow[]): Workflow | null
396
+ ```
397
+
398
+ This workflow trigger system provides a powerful way to create dynamic, context-aware AI interactions that can seamlessly integrate with your existing business processes and workflows, all configured through a single API endpoint.
@@ -1,2 +0,0 @@
1
- export declare const clickElement: (element: Element, rect: DOMRect) => Promise<void>;
2
- export declare const highlightElement: (selector: string | string[], isHighlighting: boolean, setIsHighlighting: (highlighting: boolean) => void, logMessage: (content: string, sender: "GUIDEAI" | "HUMAN") => void) => Promise<boolean>;