guideai-app 0.3.5 → 0.4.2-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.
Files changed (49) hide show
  1. package/API_DATA_CONTRACTS.md +516 -0
  2. package/API_SESSIONID_TESTING.md +215 -0
  3. package/GuideAI.js +1 -1
  4. package/GuideAI.js.map +1 -1
  5. package/PII_HASHING_EPIC.md +886 -0
  6. package/PII_HASHING_STORIES_SUMMARY.md +275 -0
  7. package/README.md +129 -0
  8. package/SESSION_ID_VERIFICATION.md +122 -0
  9. package/VISIT_COUNT_TESTING.md +453 -0
  10. package/dist/GuideAI.d.ts +1 -2
  11. package/dist/GuideAI.js +1 -1
  12. package/dist/GuideAI.js.LICENSE.txt +20 -0
  13. package/dist/GuideAI.js.map +1 -1
  14. package/dist/components/Onboarding.d.ts +2 -2
  15. package/dist/components/TranscriptBox.d.ts +10 -3
  16. package/dist/components/WelcomeBubble.d.ts +2 -2
  17. package/dist/index.d.ts +3 -0
  18. package/dist/metric/index.d.ts +0 -2
  19. package/dist/metric/metadata-tracker.d.ts +8 -2
  20. package/dist/styles/GuideAI.styles.d.ts +1 -1
  21. package/dist/types/GuideAI.types.d.ts +12 -6
  22. package/dist/types/metadata.types.d.ts +2 -0
  23. package/dist/utils/api.d.ts +18 -2
  24. package/dist/utils/constants.d.ts +1 -0
  25. package/dist/utils/elementInteractions.d.ts +92 -0
  26. package/dist/utils/gemini.d.ts +3 -0
  27. package/dist/utils/goToAElmLink.d.ts +1 -0
  28. package/dist/utils/highlightThenClick.d.ts +1 -0
  29. package/dist/utils/hoverThenClick.d.ts +1 -0
  30. package/dist/utils/logger.d.ts +37 -0
  31. package/dist/utils/session.d.ts +23 -0
  32. package/dist/utils/ui.d.ts +1 -1
  33. package/dist/utils/workflow.d.ts +62 -0
  34. package/dist/visualContext/VisualContextScheduler.d.ts +43 -0
  35. package/dist/visualContext/VisualContextStore.d.ts +11 -0
  36. package/dist/visualContext/debug-overlay.d.ts +10 -0
  37. package/dist/visualContext/defaultProvider.d.ts +15 -0
  38. package/dist/visualContext/index.d.ts +5 -0
  39. package/dist/visualContext/types.d.ts +45 -0
  40. package/index.d.ts +5 -1
  41. package/jest.config.js +26 -0
  42. package/jest.setup.js +21 -0
  43. package/metadata-tracking-example.md +11 -11
  44. package/package.json +15 -3
  45. package/structure.md +1 -1
  46. package/webpack.config.js +4 -15
  47. package/workflow-trigger-usage.md +398 -0
  48. package/dist/metric/event-listner.d.ts +0 -132
  49. package/dist/utils/highlight.d.ts +0 -2
@@ -0,0 +1,45 @@
1
+ export type ScreenshotResponse = {
2
+ ok?: boolean;
3
+ dataUrl?: string;
4
+ width?: number;
5
+ height?: number;
6
+ hash?: string;
7
+ isDuplicate?: boolean;
8
+ timestamp?: number;
9
+ error?: any;
10
+ metadata?: {
11
+ width?: number;
12
+ height?: number;
13
+ quality?: number;
14
+ [key: string]: any;
15
+ };
16
+ };
17
+ export type ScreenshotFrame = {
18
+ dataUrl: string;
19
+ width?: number;
20
+ height?: number;
21
+ hash?: string;
22
+ reason: 'preview' | 'final' | 'change';
23
+ timestamp?: number;
24
+ sentToLLM?: boolean;
25
+ llmReceivedAt?: number;
26
+ };
27
+ export type ScreenshotOptions = {
28
+ targetElement?: HTMLElement;
29
+ targetWidth?: number;
30
+ quality?: number;
31
+ minQuality?: number;
32
+ maxBytes?: number;
33
+ };
34
+ export type ScreenshotProvider = (options: ScreenshotOptions) => Promise<ScreenshotResponse>;
35
+ export type VisualContextConfig = {
36
+ enabled: boolean;
37
+ screenshotProvider?: ScreenshotProvider;
38
+ shadowRoot?: ShadowRoot;
39
+ debug?: boolean;
40
+ maxFrames?: number;
41
+ targetWidth?: number;
42
+ quality?: number;
43
+ minQuality?: number;
44
+ maxBytes?: number;
45
+ };
package/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  import GuideAI from './GuideAI';
2
+ import TranscriptBox from './components/TranscriptBox';
2
3
  export default GuideAI;
3
- export type { GuideAIProps } from './GuideAI';
4
+ export { TranscriptBox };
5
+ export type { GuideAIProps } from './types/GuideAI.types';
6
+ export * from './visualContext';
7
+ export * from './visualContext/types';
package/jest.config.js ADDED
@@ -0,0 +1,26 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'jsdom',
4
+ roots: ['<rootDir>/src'],
5
+ testMatch: ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'],
6
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7
+ collectCoverageFrom: [
8
+ 'src/**/*.{ts,tsx}',
9
+ '!src/**/*.d.ts',
10
+ '!src/**/*.types.ts'
11
+ ],
12
+ setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
13
+ transform: {
14
+ '^.+\\.tsx?$': ['ts-jest', {
15
+ tsconfig: {
16
+ jsx: 'react',
17
+ esModuleInterop: true,
18
+ allowSyntheticDefaultImports: true
19
+ }
20
+ }]
21
+ },
22
+ moduleNameMapper: {
23
+ '^@/(.*)$': '<rootDir>/src/$1'
24
+ }
25
+ };
26
+
package/jest.setup.js ADDED
@@ -0,0 +1,21 @@
1
+ // Jest setup file
2
+ require('jest-localstorage-mock');
3
+ require('@testing-library/jest-dom');
4
+
5
+ // Mock console methods to reduce noise in tests
6
+ global.console = {
7
+ ...console,
8
+ log: jest.fn(),
9
+ warn: jest.fn(),
10
+ error: jest.fn(),
11
+ };
12
+
13
+ // Setup localStorage and sessionStorage mocks
14
+ Object.defineProperty(window, 'localStorage', {
15
+ value: global.localStorage,
16
+ });
17
+
18
+ Object.defineProperty(window, 'sessionStorage', {
19
+ value: global.sessionStorage,
20
+ });
21
+
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- The GuideAI package now includes comprehensive user metadata tracking capabilities designed for integration with Overproof. This system tracks the following metadata:
5
+ The GuideAI package now includes comprehensive user metadata tracking capabilities designed for integration with client. This system tracks the following metadata:
6
6
 
7
7
  - **User's First Visit** - Timestamp of the first time the user interacted with GuideAI
8
8
  - **User's Last Visit** - Timestamp of the most recent user interaction
@@ -181,7 +181,7 @@ interface UserMetadata {
181
181
  platform?: string;
182
182
  };
183
183
 
184
- // Custom fields for Overproof-specific needs
184
+ // Custom fields for client-specific needs
185
185
  customFields?: Record<string, string | number | boolean>;
186
186
  }
187
187
  ```
@@ -255,14 +255,14 @@ guideAIRef.current?.trackCustomEvent('document_viewed', {
255
255
  });
256
256
  ```
257
257
 
258
- ## Overproof Integration Example
258
+ ## client Integration Example
259
259
 
260
260
  ```typescript
261
- function OverproofApp() {
261
+ function clientApp() {
262
262
  const guideAIRef = useRef();
263
263
 
264
- // Track when user logs into Overproof
265
- const handleOverproofLogin = (user) => {
264
+ // Track when user logs into client
265
+ const handleclientLogin = (user) => {
266
266
  guideAIRef.current?.trackLogin({
267
267
  userId: user.id,
268
268
  userType: user.role, // 'agent', 'admin', etc.
@@ -291,18 +291,18 @@ function OverproofApp() {
291
291
  return (
292
292
  <GuideAI
293
293
  ref={guideAIRef}
294
- organizationKey="overproof-org-key"
294
+ organizationKey="demo-org-key"
295
295
  metadata={{
296
296
  config: {
297
297
  trackVisits: true,
298
298
  trackLogins: true,
299
- syncInterval: 15000, // More frequent syncing for Overproof
299
+ syncInterval: 15000, // More frequent syncing for client
300
300
  customFields: ['agencyId', 'territory', 'permissions'],
301
301
  collectBrowserInfo: true
302
302
  },
303
303
  onMetadataUpdate: (metadata) => {
304
- // Send to Overproof analytics
305
- window.OverproofAnalytics?.track('guideai_metadata_update', metadata);
304
+ // Send to client analytics
305
+ window.clientAnalytics?.track('guideai_metadata_update', metadata);
306
306
  }
307
307
  }}
308
308
  />
@@ -321,4 +321,4 @@ Metadata is automatically:
321
321
  - Synced to backend at configured intervals
322
322
  - Restored when user returns (if using persistent storage)
323
323
 
324
- This implementation provides a robust foundation for tracking user metadata in the Overproof environment while maintaining flexibility for other use cases.
324
+ This implementation provides a robust foundation for tracking user metadata in the client environment while maintaining flexibility for other use cases.
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "guideai-app",
3
- "version": "0.3.5",
3
+ "version": "0.4.2-1",
4
4
  "description": "AI-powered guide component for React applications",
5
5
  "main": "dist/GuideAI.js",
6
- "types": "dist/GuideAI.d.ts",
6
+ "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "webpack && tsc --emitDeclarationOnly && javascript-obfuscator dist/GuideAI.js --config obfuscator.json --output dist/GuideAI.js",
9
9
  "prepare": "npm run build",
10
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "test": "jest",
11
+ "test:watch": "jest --watch",
12
+ "test:coverage": "jest --coverage"
11
13
  },
12
14
  "keywords": [
13
15
  "react",
@@ -19,6 +21,8 @@
19
21
  "license": "ISC",
20
22
  "dependencies": {
21
23
  "@google/generative-ai": "^0.2.1",
24
+ "guideai-app": "^0.3.4",
25
+ "html2canvas": "^1.4.1",
22
26
  "openai": "^4.28.0"
23
27
  },
24
28
  "peerDependencies": {
@@ -26,10 +30,18 @@
26
30
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
27
31
  },
28
32
  "devDependencies": {
33
+ "@testing-library/jest-dom": "^6.9.1",
34
+ "@testing-library/react": "^16.3.0",
35
+ "@types/jest": "^30.0.0",
29
36
  "@types/react": "^18.2.0",
30
37
  "javascript-obfuscator": "^4.1.0",
38
+ "jest": "^30.2.0",
39
+ "jest-circus": "^30.2.0",
40
+ "jest-environment-jsdom": "^30.2.0",
41
+ "jest-localstorage-mock": "^2.4.26",
31
42
  "process": "^0.11.10",
32
43
  "stream-browserify": "^3.0.0",
44
+ "ts-jest": "^29.4.5",
33
45
  "ts-loader": "^9.5.2",
34
46
  "typescript": "^5.0.0",
35
47
  "util": "^0.12.5",
package/structure.md CHANGED
@@ -99,7 +99,7 @@ Functions for interacting with external APIs.
99
99
  Utilities for interacting with the DOM.
100
100
 
101
101
  **Functions:**
102
- - `highlightElement(selector, logMessageFn)`: Highlights an element on the page
102
+ - `selectElementAndClick(selector, logMessageFn)`: Highlights an element on the page with animated cursor and clicks it
103
103
  - DOM traversal and interaction functions
104
104
 
105
105
  #### `utils/react-hooks.ts`
package/webpack.config.js CHANGED
@@ -31,21 +31,10 @@ module.exports = {
31
31
  ]
32
32
  },
33
33
  externals: {
34
- // Mark React and ReactDOM as external dependencies
35
- // This means they won't be bundled with the package
36
- // The consuming application is expected to provide them
37
- 'react': {
38
- commonjs: 'react',
39
- commonjs2: 'react',
40
- amd: 'React',
41
- root: 'React'
42
- },
43
- 'react-dom': {
44
- commonjs: 'react-dom',
45
- commonjs2: 'react-dom',
46
- amd: 'ReactDOM',
47
- root: 'ReactDOM'
48
- }
34
+ // Externalize React and ReactDOM to expect them from the host environment
35
+ 'react': 'React',
36
+ 'react-dom': 'ReactDOM',
37
+ 'react-dom/client': 'ReactDOM'
49
38
  },
50
39
  performance: {
51
40
  hints: false
@@ -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.