primeorbit 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,260 @@
1
+ # PrimeOrbit JavaScript SDK
2
+
3
+ Track conversations, model responses, user feedback, and custom analytics
4
+ through a simple event-based API.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ npm install primeorbit
10
+ ```
11
+
12
+ ## Quick Start
13
+
14
+ ```javascript
15
+ import { PrimeOrbitClient } from 'primeorbit';
16
+
17
+ const po = new PrimeOrbitClient(
18
+ 'np_live_abc123', // Your API Key
19
+ 'https://sdk.primeorbit.ai', // Endpoint
20
+ );
21
+
22
+ // Set base properties once
23
+ po.add_properties({
24
+ agentId: 'agent_456',
25
+ conversationId: 'conv_789',
26
+ userId: 'user_123',
27
+ });
28
+
29
+ // Record events
30
+ po.record_raw_event('user_message', {
31
+ content: 'Hello, I need help!',
32
+ });
33
+ ```
34
+
35
+ ## Configuration
36
+
37
+ ### API Key and Endpoint
38
+
39
+ You can provide credentials in two ways:
40
+
41
+ 1. **Direct parameters:**
42
+
43
+ ```javascript
44
+ const po = new PrimeOrbitClient('your-api-key', 'https://sdk.primeorbit.ai');
45
+ ```
46
+
47
+ 2. **Environment variables:**
48
+
49
+ ```bash
50
+ PRIMEORBIT_API_KEY=your-api-key
51
+ PRIMEORBIT_ENDPOINT=https://sdk.primeorbit.ai
52
+ ```
53
+
54
+ ```javascript
55
+ const po = new PrimeOrbitClient(); // Uses env variables
56
+ ```
57
+
58
+ ### Logging
59
+
60
+ Control SDK logging verbosity:
61
+
62
+ ```javascript
63
+ import { setLogLevel } from 'primeorbit';
64
+
65
+ // Available levels: 'debug', 'info', 'warn', 'error', 'silent'
66
+ setLogLevel('debug'); // Show all logs including debug
67
+ setLogLevel('error'); // Only show errors
68
+ setLogLevel('silent'); // Disable all logging
69
+ ```
70
+
71
+ ### Base Properties
72
+
73
+ Set properties once to include in all events:
74
+
75
+ ```javascript
76
+ po.add_properties({
77
+ agentId: 'agent_456',
78
+ conversationId: 'conv_789',
79
+ userId: 'user_123',
80
+ sessionId: 'sess_001',
81
+ platform: 'web',
82
+ });
83
+ ```
84
+
85
+ ## Event Types
86
+
87
+ ### Message Events
88
+
89
+ - `user_message` - User sends a message
90
+ - `agent_response` - Agent/bot responds
91
+
92
+ ### Feedback Events
93
+
94
+ - `user_feedback` - Free text feedback
95
+
96
+ ## Required Fields
97
+
98
+ | Field | Type | Description |
99
+ | ---------------- | ------ | --------------------------------------- |
100
+ | `conversationId` | string | Unique ID representing the conversation |
101
+ | `userId` | string | ID of the end user |
102
+ | `content` | string | Message text or feedback content |
103
+
104
+ ## Optional Fields
105
+
106
+ | Field | Type | Description |
107
+ | -------------- | ------ | ------------------------------------------------ |
108
+ | `eventId` | string | Unique event identifier |
109
+ | `agentId` | string | ID of the agent/app/model that handled the event |
110
+ | `sessionId` | string | Session identifier |
111
+ | `messageId` | string | Message ID for tracking within conversation |
112
+ | `inputMode` | string | e.g., `"text"`, `"voice"`, `"button"` |
113
+ | `experimentId` | string | A/B test or experiment tracking |
114
+ | `appId` | string | Application identifier |
115
+ | `device` | string | Device type (`mobile`, `desktop`) |
116
+ | `country` | string | User's country (ISO code) |
117
+ | `platform` | string | Platform (`web`, `ios`, `android`) |
118
+ | `model` | string | Model name for `agent_response` events |
119
+
120
+ Any additional fields are captured in `additional_properties`.
121
+
122
+ ## Event Examples
123
+
124
+ ### User Message
125
+
126
+ ```javascript
127
+ po.record_raw_event('user_message', {
128
+ content: 'Hello, I need help!',
129
+ });
130
+ ```
131
+
132
+ ### Agent Response
133
+
134
+ ```javascript
135
+ po.record_raw_event('agent_response', {
136
+ content: 'Sure! What can I help you with?',
137
+ model: 'gpt-4',
138
+ });
139
+ ```
140
+
141
+ ### User Feedback
142
+
143
+ ```javascript
144
+ po.record_raw_event('user_feedback', {
145
+ content: "The answer wasn't very helpful.",
146
+ });
147
+ ```
148
+
149
+ ## Latency Tracking
150
+
151
+ Wrap functions to automatically track execution time:
152
+
153
+ ```javascript
154
+ import { wrapToRecordLatency } from 'primeorbit';
155
+
156
+ // Wrap any function
157
+ const wrappedFn = wrapToRecordLatency(myFunction, 'agent-id', 'action-name');
158
+
159
+ // For type-safe async/sync wrappers
160
+ import { wrapAsyncToRecordLatency, wrapSyncToRecordLatency } from 'primeorbit';
161
+
162
+ const wrappedAsync = wrapAsyncToRecordLatency(myAsyncFn, 'agent-id');
163
+ const wrappedSync = wrapSyncToRecordLatency(mySyncFn, 'agent-id');
164
+ ```
165
+
166
+ ## Standalone Feedback Functions
167
+
168
+ ```javascript
169
+ import { record_star_rating, record_thumbs_feedback } from 'primeorbit';
170
+
171
+ // Star rating (1-5)
172
+ record_star_rating('agent-id', 5, 'task-name', 'user-id');
173
+
174
+ // Thumbs feedback
175
+ record_thumbs_feedback('agent-id', true, 'task-name', 'user-id'); // thumbs up
176
+ record_thumbs_feedback('agent-id', false, 'task-name', 'user-id'); // thumbs down
177
+ ```
178
+
179
+ ## Complete Example
180
+
181
+ ```javascript
182
+ import { PrimeOrbitClient, setLogLevel } from 'primeorbit';
183
+
184
+ // Configure logging (optional)
185
+ setLogLevel('info');
186
+
187
+ // Initialize the client
188
+ const po = new PrimeOrbitClient('YOUR_API_KEY', 'https://sdk.primeorbit.ai');
189
+
190
+ // Set conversation metadata
191
+ po.add_properties({
192
+ userId: 'user_123',
193
+ agentId: 'agent_001',
194
+ conversationId: 'conv_456',
195
+ sessionId: 'session_789',
196
+ });
197
+
198
+ async function handleConversation() {
199
+ const userMessage = 'Hello, I need help!';
200
+
201
+ // Record user message
202
+ await po.record_raw_event('user_message', {
203
+ content: userMessage,
204
+ });
205
+
206
+ // Get bot response (your logic here)
207
+ const botResponse = await getBotResponse(userMessage);
208
+
209
+ // Record agent response
210
+ await po.record_raw_event('agent_response', {
211
+ content: botResponse,
212
+ model: 'gpt-4',
213
+ });
214
+ }
215
+
216
+ handleConversation();
217
+ ```
218
+
219
+ ## TypeScript Support
220
+
221
+ The SDK is written in TypeScript and includes full type definitions.
222
+
223
+ ```typescript
224
+ import { PrimeOrbitClient, LogLevel, setLogLevel } from 'primeorbit';
225
+
226
+ const level: LogLevel = 'debug';
227
+ setLogLevel(level);
228
+
229
+ const client = new PrimeOrbitClient('api-key');
230
+ ```
231
+
232
+ ## API Reference
233
+
234
+ ### PrimeOrbitClient
235
+
236
+ - `constructor(apiKey?: string, endpoint?: string)` - Create a new client
237
+ - `add_properties(props: Record<string, unknown>)` - Set base properties
238
+ - `record_raw_event(eventType, params)` - Record an event
239
+
240
+ ### Logging
241
+
242
+ - `setLogLevel(level: LogLevel)` - Set log level
243
+ - `getLogLevel(): LogLevel` - Get current log level
244
+ - `logger` - Direct access to logger instance
245
+
246
+ ### Latency Tracking
247
+
248
+ - `wrapToRecordLatency(fn, agentId, actionId?)` - Wrap any function
249
+ - `wrapSyncToRecordLatency(fn, agentId, actionId?)` - Wrap sync function
250
+ - `wrapAsyncToRecordLatency(fn, agentId, actionId?)` - Wrap async function
251
+
252
+ ### Feedback
253
+
254
+ - `record_star_rating(agentId, rating, taskName, userId?)` - Record star rating
255
+ - `record_thumbs_feedback(agentId, isThumbsUp, taskName, userId?)` - Record
256
+ thumbs
257
+
258
+ ## License
259
+
260
+ MIT