guideai-app 0.1.9 → 0.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.
@@ -2,7 +2,9 @@ import { RecordingStatus } from '../types';
2
2
  export declare const useRecording: (organizationKey: string, onError: (error: string | Error, context?: string) => void, logMessageFn: (message: string, sender: "GUIDEAI" | "HUMAN") => Promise<void>, addConversationHistoryFn: (sendMessageFn: (message: any) => void) => void, storeConversationItemFn: (item: any) => void, updateConversationItem: (itemId: string, updateData: Partial<any>) => void, isAddingHistoryContextRef: React.MutableRefObject<boolean>) => {
3
3
  status: RecordingStatus;
4
4
  isSessionReady: boolean;
5
+ isConversationActive: boolean;
5
6
  toggleRecording: () => Promise<void>;
7
+ toggleConversation: () => Promise<void>;
6
8
  cleanupWebRTC: () => void;
7
9
  audioElementRef: import("react").MutableRefObject<HTMLAudioElement | null>;
8
10
  ephemeralToken: string | null;
package/obfuscate.js ADDED
@@ -0,0 +1,40 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const JavaScriptObfuscator = require('javascript-obfuscator');
4
+
5
+ // Files to obfuscate
6
+ const files = [
7
+ 'dist/index.js',
8
+ 'dist/index.esm.js'
9
+ ];
10
+
11
+ // Load obfuscator config
12
+ const config = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'obfuscator.json'), 'utf8'));
13
+
14
+ // Process each file
15
+
16
+ files.forEach(file => {
17
+ const filePath = path.resolve(__dirname, file);
18
+
19
+ try {
20
+ // Check if file exists
21
+ if (!fs.existsSync(filePath)) {
22
+ console.warn(`Warning: ${file} does not exist, skipping obfuscation.`);
23
+ return;
24
+ }
25
+
26
+
27
+ // Read the file
28
+ const code = fs.readFileSync(filePath, 'utf8');
29
+
30
+ // Obfuscate the code
31
+ const obfuscationResult = JavaScriptObfuscator.obfuscate(code, config);
32
+
33
+ // Write the obfuscated code back to the file
34
+ fs.writeFileSync(filePath, obfuscationResult.getObfuscatedCode());
35
+
36
+ } catch (error) {
37
+ console.error(`Error obfuscating ${file}:`, error);
38
+ process.exit(1);
39
+ }
40
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guideai-app",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
4
4
  "description": "AI-powered guide component for React applications",
5
5
  "main": "dist/GuideAI.js",
6
6
  "types": "dist/GuideAI.d.ts",
@@ -0,0 +1,34 @@
1
+ import commonjs from '@rollup/plugin-commonjs';
2
+ import resolve from '@rollup/plugin-node-resolve';
3
+ import typescript from '@rollup/plugin-typescript';
4
+ import { terser } from 'rollup-plugin-terser';
5
+ import peerDepsExternal from 'rollup-plugin-peer-deps-external';
6
+
7
+ export default {
8
+ input: 'src/index.ts',
9
+ output: [
10
+ {
11
+ file: 'dist/index.js',
12
+ format: 'cjs',
13
+ sourcemap: true,
14
+ exports: 'named'
15
+ },
16
+ {
17
+ file: 'dist/index.esm.js',
18
+ format: 'esm',
19
+ sourcemap: true,
20
+ exports: 'named'
21
+ },
22
+ ],
23
+ plugins: [
24
+ peerDepsExternal(),
25
+ resolve(),
26
+ commonjs(),
27
+ typescript({
28
+ tsconfig: './tsconfig.json',
29
+ exclude: ['**/__tests__/**'],
30
+ }),
31
+ terser(),
32
+ ],
33
+ external: ['react', 'react-dom', 'openai'],
34
+ };
package/structure.md ADDED
@@ -0,0 +1,128 @@
1
+ # GuideAI Package Structure
2
+
3
+ ## Directory Structure
4
+
5
+ ```
6
+ guide-ai-package/src/
7
+ ├── GuideAI.tsx # Main component
8
+ ├── index.ts # Package entry point
9
+ ├── components/ # React components
10
+ │ └── Styles.tsx # Styling for the component
11
+ ├── hooks/ # React hooks
12
+ │ ├── useConversation.ts # Conversation management
13
+ │ └── useRecording.ts # Audio recording and WebRTC
14
+ ├── types/ # TypeScript type definitions
15
+ │ └── index.ts # Type definitions
16
+ └── utils/ # Utility functions
17
+ ├── api-services.ts # API related functions
18
+ ├── dom-interaction.ts # DOM manipulation utilities
19
+ ├── react-hooks.ts # React hooks utilities
20
+ ├── storage.ts # Local storage utilities
21
+ └── webrtc.ts # WebRTC related utilities
22
+ ```
23
+
24
+ ## File Descriptions
25
+
26
+ ### Main Files
27
+
28
+ #### `GuideAI.tsx`
29
+ The main component exported by the package that provides the user interface for audio interactions.
30
+
31
+ **Functions & Components:**
32
+ - `GuideAI(props: GuideAIProps)`: Main component that renders the UI
33
+ - Sets up conversation management
34
+ - Initializes audio recording
35
+ - Handles user interactions
36
+
37
+ #### `index.ts`
38
+ Entry point for the package, exports the GuideAI component and types.
39
+
40
+ **Exports:**
41
+ - `GuideAI`
42
+ - `GuideAIProps` (type)
43
+
44
+ ### Components
45
+
46
+ #### `components/Styles.tsx`
47
+ Contains the CSS styling for the GuideAI component.
48
+
49
+ **Functions & Components:**
50
+ - `Styles()`: Component that injects CSS styles into the page
51
+
52
+ ### Hooks
53
+
54
+ #### `hooks/useConversation.ts`
55
+ Custom hook for managing conversation state and interaction with the API.
56
+
57
+ **Functions:**
58
+ - `useConversation(organizationKey, onError)`: Main hook function
59
+ - `storeConversationItem(item)`: Stores a conversation item
60
+ - `initializeConversation()`: Creates or restores a conversation
61
+ - `logMessageToConversation(content, sender)`: Logs a message to the conversation
62
+ - `addConversationHistory(sendMessageFn)`: Adds conversation history to a new session
63
+ - `isConversationStale()`: Checks if conversation is more than 15 minutes old
64
+
65
+ #### `hooks/useRecording.ts`
66
+ Custom hook for managing audio recording, WebRTC connections, and handling responses.
67
+
68
+ **Functions:**
69
+ - `useRecording(organizationKey, onError, logMessageFn, addConversationHistoryFn, storeConversationItemFn, isAddingHistoryContextRef)`: Main hook function
70
+ - `sendWebRTCMessage(message)`: Sends a message through WebRTC
71
+ - `cleanupWebRTC()`: Cleans up WebRTC connections and media streams
72
+ - `handleWebRTCMessage(message)`: Handles incoming WebRTC messages
73
+ - `startRecording()`: Starts audio recording
74
+ - `stopRecording()`: Stops audio recording
75
+ - `toggleRecording()`: Toggles recording state
76
+
77
+ ### Types
78
+
79
+ #### `types/index.ts`
80
+ Contains TypeScript type definitions used throughout the package.
81
+
82
+ **Types:**
83
+ - `ConversationItem`: Represents an item in the conversation
84
+ - `RecordingStatus`: Status of the recording ('idle' | 'recording' | 'processing' | 'playing' | 'initializing')
85
+ - `GuideAIProps`: Props for the GuideAI component
86
+
87
+ ### Utils
88
+
89
+ #### `utils/api-services.ts`
90
+ Functions for interacting with external APIs.
91
+
92
+ **Functions:**
93
+ - `createNewConversation(organizationKey)`: Creates a new conversation
94
+ - `logMessage(conversationId, content, sender)`: Logs a message to the conversation
95
+ - `fetchEphemeralToken(organizationKey)`: Fetches an ephemeral token for WebRTC
96
+ - `geminiFlash(prompt)`: Makes a call to the Gemini API
97
+
98
+ #### `utils/dom-interaction.ts`
99
+ Utilities for interacting with the DOM.
100
+
101
+ **Functions:**
102
+ - `highlightElement(selector, logMessageFn)`: Highlights an element on the page
103
+ - DOM traversal and interaction functions
104
+
105
+ #### `utils/react-hooks.ts`
106
+ Utilities for React hooks to avoid duplicate React instances.
107
+
108
+ **Functions:**
109
+ - `getReactHooks()`: Returns React hooks from the host application or fall back to local ones
110
+
111
+ #### `utils/storage.ts`
112
+ Local storage utility functions.
113
+
114
+ **Constants:**
115
+ - `STORAGE_PREFIX`: Prefix for storage keys
116
+ - `STORAGE_KEYS`: Object containing all storage keys
117
+
118
+ **Functions:**
119
+ - `saveToStorage(key, value)`: Saves a value to localStorage
120
+ - `getFromStorage(key, defaultValue)`: Gets a value from localStorage
121
+
122
+ #### `utils/webrtc.ts`
123
+ WebRTC related utilities for audio streaming.
124
+
125
+ **Functions:**
126
+ - `initializeWebRTC(audioStream, token, audioElementRef, peerConnectionRef, dataChannelRef, handleMessageCallback)`: Sets up WebRTC connection
127
+ - `sendMessage(dataChannel, message)`: Sends a message through the data channel
128
+ - `orderConversationItems(items)`: Orders conversation items for replay