observa-sdk 0.0.6 → 0.0.8

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 CHANGED
@@ -201,6 +201,166 @@ const response = await observa.track(
201
201
  );
202
202
  ```
203
203
 
204
+ ### `observa.trackFeedback(options)`
205
+
206
+ Track user feedback (likes, dislikes, ratings, corrections) for AI interactions.
207
+
208
+ **Parameters**:
209
+
210
+ - `options.type` (required): Feedback type - `"like"` | `"dislike"` | `"rating"` | `"correction"`
211
+ - `options.rating` (optional): Rating value (1-5 scale, automatically clamped). Required for `"rating"` type.
212
+ - `options.comment` (optional): User comment/feedback text
213
+ - `options.outcome` (optional): Outcome classification - `"success"` | `"failure"` | `"partial"`
214
+ - `options.conversationId` (optional): Conversation identifier for context
215
+ - `options.sessionId` (optional): Session identifier for context
216
+ - `options.userId` (optional): User identifier for context
217
+ - `options.messageIndex` (optional): Position in conversation (1, 2, 3...)
218
+ - `options.parentMessageId` (optional): For threaded conversations
219
+ - `options.agentName` (optional): Agent/application name
220
+ - `options.version` (optional): Application version
221
+ - `options.route` (optional): API route/endpoint
222
+ - `options.parentSpanId` (optional): Attach feedback to a specific span (e.g., LLM call span)
223
+ - `options.spanId` (optional): Custom span ID for feedback (auto-generated if not provided)
224
+
225
+ **Returns**: `string` - The span ID of the feedback event
226
+
227
+ **Examples**:
228
+
229
+ #### Basic Like/Dislike Feedback
230
+
231
+ ```typescript
232
+ // User clicks "like" button after receiving AI response
233
+ const feedbackSpanId = observa.trackFeedback({
234
+ type: "like",
235
+ outcome: "success",
236
+ conversationId: "conv-123",
237
+ userId: "user-456",
238
+ });
239
+
240
+ // User clicks "dislike" button
241
+ observa.trackFeedback({
242
+ type: "dislike",
243
+ outcome: "failure",
244
+ comment: "The answer was incorrect",
245
+ conversationId: "conv-123",
246
+ userId: "user-456",
247
+ });
248
+ ```
249
+
250
+ #### Rating Feedback (1-5 Scale)
251
+
252
+ ```typescript
253
+ // User provides a 5-star rating
254
+ observa.trackFeedback({
255
+ type: "rating",
256
+ rating: 5, // Automatically clamped to 1-5 range
257
+ comment: "Excellent response!",
258
+ outcome: "success",
259
+ conversationId: "conv-123",
260
+ userId: "user-456",
261
+ });
262
+
263
+ // Rating is automatically validated (e.g., 10 becomes 5, -1 becomes 1)
264
+ observa.trackFeedback({
265
+ type: "rating",
266
+ rating: 10, // Will be clamped to 5
267
+ conversationId: "conv-123",
268
+ });
269
+ ```
270
+
271
+ #### Correction Feedback
272
+
273
+ ```typescript
274
+ // User provides correction/feedback
275
+ observa.trackFeedback({
276
+ type: "correction",
277
+ comment: "The capital of France is Paris, not Lyon",
278
+ outcome: "partial",
279
+ conversationId: "conv-123",
280
+ userId: "user-456",
281
+ });
282
+ ```
283
+
284
+ #### Linking Feedback to Specific Spans
285
+
286
+ ```typescript
287
+ // Start a trace and track LLM call
288
+ const traceId = observa.startTrace({
289
+ conversationId: "conv-123",
290
+ userId: "user-456",
291
+ });
292
+
293
+ const llmSpanId = observa.trackLLMCall({
294
+ model: "gpt-4",
295
+ input: "What is the capital of France?",
296
+ output: "The capital of France is Paris.",
297
+ // ... other LLM call data
298
+ });
299
+
300
+ // Link feedback directly to the LLM call span
301
+ observa.trackFeedback({
302
+ type: "like",
303
+ parentSpanId: llmSpanId, // Attach feedback to the specific LLM call
304
+ conversationId: "conv-123",
305
+ userId: "user-456",
306
+ });
307
+ ```
308
+
309
+ #### Full Context Feedback
310
+
311
+ ```typescript
312
+ // Track feedback with complete context for analytics
313
+ observa.trackFeedback({
314
+ type: "rating",
315
+ rating: 4,
316
+ comment: "Good answer, but could be more detailed",
317
+ outcome: "partial",
318
+ conversationId: "conv-123",
319
+ sessionId: "session-789",
320
+ userId: "user-456",
321
+ messageIndex: 3,
322
+ agentName: "customer-support-bot",
323
+ version: "v2.1.0",
324
+ route: "/api/chat",
325
+ });
326
+ ```
327
+
328
+ #### Feedback in Conversation Flow
329
+
330
+ ```typescript
331
+ // Track feedback as part of a conversation
332
+ const traceId = observa.startTrace({
333
+ conversationId: "conv-123",
334
+ sessionId: "session-789",
335
+ userId: "user-456",
336
+ messageIndex: 1,
337
+ });
338
+
339
+ // ... perform AI operations ...
340
+
341
+ // User provides feedback after message 1
342
+ observa.trackFeedback({
343
+ type: "like",
344
+ conversationId: "conv-123",
345
+ sessionId: "session-789",
346
+ userId: "user-456",
347
+ messageIndex: 1, // Link to specific message in conversation
348
+ });
349
+
350
+ await observa.endTrace();
351
+ ```
352
+
353
+ **Best Practices**:
354
+
355
+ 1. **Always include context**: Provide `conversationId`, `userId`, and `sessionId` when available for better analytics
356
+ 2. **Link to spans**: Use `parentSpanId` to attach feedback to specific LLM calls or operations
357
+ 3. **Use appropriate types**:
358
+ - `"like"` / `"dislike"` for binary feedback
359
+ - `"rating"` for 1-5 star ratings
360
+ - `"correction"` for user corrections or detailed feedback
361
+ 4. **Include comments**: Comments provide valuable qualitative feedback for improving AI responses
362
+ 5. **Set outcome**: Use `outcome` to classify feedback (`"success"` for positive, `"failure"` for negative, `"partial"` for mixed)
363
+
204
364
  ## Data Captured
205
365
 
206
366
  The SDK automatically captures: