@kelet-ai/feedback-ui 1.1.4 → 1.2.0

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
@@ -126,6 +126,43 @@ function ContentEditor() {
126
126
  }
127
127
  ```
128
128
 
129
+ ### **Pattern 4: Manual Signal Sending**
130
+
131
+ Send signals directly without tying them to component state — useful for custom events, page views, or any interaction not covered by the other patterns:
132
+
133
+ ```tsx
134
+ import { KeletProvider, useKeletSignal } from "@kelet-ai/feedback-ui"
135
+
136
+ function CopyButton({ sessionId }: { sessionId: string }) {
137
+ const sendSignal = useKeletSignal()
138
+
139
+ return (
140
+ <button
141
+ onClick={() => {
142
+ navigator.clipboard.writeText("...")
143
+ sendSignal({
144
+ session_id: sessionId,
145
+ kind: "feedback",
146
+ source: "human",
147
+ score: 1,
148
+ trigger_name: "copy_button_clicked",
149
+ })
150
+ }}
151
+ >
152
+ Copy
153
+ </button>
154
+ )
155
+ }
156
+
157
+ function App() {
158
+ return (
159
+ <KeletProvider apiKey="..." project="my-project">
160
+ <CopyButton sessionId="response-abc123" />
161
+ </KeletProvider>
162
+ )
163
+ }
164
+ ```
165
+
129
166
  ### **Pattern 3: Complex State with Reducer**
130
167
 
131
168
  For advanced state management with automatic trigger tracking, by using a drop-in replacement for useReducer:
@@ -359,6 +396,39 @@ Context-aware feedback form that appears after voting.
359
396
 
360
397
  ---
361
398
 
399
+ ## ✉️ Manual Signal Sending
400
+
401
+ ### **useKeletSignal Hook**
402
+
403
+ Returns the signal-sending function from the nearest `KeletProvider`. Use this to send signals manually for any event — custom interactions, page views, feature usage — without tying them to component state.
404
+
405
+ Safe to call outside a provider: returns a no-op and logs a warning.
406
+
407
+ ```tsx
408
+ import { useKeletSignal } from "@kelet-ai/feedback-ui"
409
+
410
+ function MyComponent() {
411
+ const sendSignal = useKeletSignal()
412
+
413
+ const handleAction = () => {
414
+ sendSignal({
415
+ session_id: "my-session",
416
+ kind: "feedback",
417
+ source: "human",
418
+ score: 1,
419
+ trigger_name: "user_action",
420
+ metadata: { context: "sidebar" },
421
+ })
422
+ }
423
+
424
+ return <button onClick={handleAction}>Do something</button>
425
+ }
426
+ ```
427
+
428
+ Requires a `KeletProvider` ancestor to send signals to the API.
429
+
430
+ ---
431
+
362
432
  ## 📊 Automatic Feedback Hooks
363
433
 
364
434
  ### **useFeedbackState Hook**
@@ -12,6 +12,26 @@ interface KeletProviderProps {
12
12
  }
13
13
  export declare const KeletContext: React.Context<KeletContextValue | null>;
14
14
  export declare const useKelet: () => KeletContextValue;
15
+ /**
16
+ * Returns the signal-sending function from the nearest KeletProvider.
17
+ *
18
+ * Use this hook to send signals manually — e.g. tracking custom events,
19
+ * page views, or any interaction not covered by useFeedbackState.
20
+ *
21
+ * Safe to call outside a provider: returns a no-op and logs a warning.
22
+ *
23
+ * @example
24
+ * const sendSignal = useKeletSignal()
25
+ *
26
+ * sendSignal({
27
+ * session_id: 'my-session',
28
+ * kind: 'feedback',
29
+ * source: 'human',
30
+ * score: 1,
31
+ * trigger_name: 'copy_button_clicked',
32
+ * })
33
+ */
34
+ export declare const useKeletSignal: () => ((data: FeedbackData) => Promise<void>);
15
35
  export declare const useDefaultFeedbackHandler: () => ((data: FeedbackData) => Promise<void>);
16
36
  export declare const KeletProvider: React.FC<React.PropsWithChildren<KeletProviderProps>>;
17
37
  export {};
@@ -443,7 +443,7 @@ const useKelet = () => {
443
443
  }
444
444
  return context;
445
445
  };
446
- const useDefaultFeedbackHandler = () => {
446
+ const useKeletSignal = () => {
447
447
  const context = useContext(KeletContext);
448
448
  if (!context) {
449
449
  console.warn(
@@ -455,6 +455,7 @@ const useDefaultFeedbackHandler = () => {
455
455
  return context.feedback;
456
456
  }
457
457
  };
458
+ const useDefaultFeedbackHandler = useKeletSignal;
458
459
  const KeletProvider = ({ apiKey, project, baseUrl, children }) => {
459
460
  useEffect(() => {
460
461
  initEventCapture();
@@ -2275,6 +2276,7 @@ export {
2275
2276
  VoteFeedback,
2276
2277
  useDefaultFeedbackHandler,
2277
2278
  useFeedbackState,
2278
- useKelet
2279
+ useKelet,
2280
+ useKeletSignal
2279
2281
  };
2280
2282
  //# sourceMappingURL=feedback-ui.es.js.map