yaver-feedback-react-native 0.6.1 → 0.7.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.
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Device deduplication + online-signal merging, ported from the Yaver
3
+ * mobile app's DeviceContext.collapseAliasDevices.
4
+ *
5
+ * Convex stores one row per pair (device, re-install). After a re-pair
6
+ * or hostname change the list can contain 2-3 rows for the same
7
+ * physical machine, with different hwid/publicKey values. The picker
8
+ * then shows duplicates and the user can't tell which one is live.
9
+ *
10
+ * This file collapses rows in three passes:
11
+ * 1. Identity key (hwid → publicKey → "host:os:name" → id → name)
12
+ * 2. Alias key (os + normalized-hostname) — catches re-pairs that
13
+ * mint a new hwid
14
+ * 3. Endpoint key (host:port)
15
+ *
16
+ * When collapsing, `mergeDeviceEntries` prefers: authenticated over
17
+ * needsAuth, online over offline, freshest lastHeartbeat.
18
+ */
19
+
20
+ import type { RemoteDevice } from './auth';
21
+
22
+ function normalizedName(name: string | undefined): string {
23
+ return String(name || '').trim().toLowerCase().replace(/\.local$/i, '');
24
+ }
25
+
26
+ function normalizedHost(host: string | undefined): string {
27
+ return String(host || '').trim().toLowerCase().replace(/\.local$/i, '');
28
+ }
29
+
30
+ function identityKey(d: RemoteDevice): string {
31
+ if (d.hwid) return `hwid:${d.hwid}`;
32
+ if (d.publicKey) return `pub:${d.publicKey}`;
33
+ if (d.isGuest) {
34
+ const scope = d.hostEmail || d.hostName || 'guest';
35
+ return `guest:${scope}:${d.deviceId || d.name}`;
36
+ }
37
+ const n = normalizedName(d.name);
38
+ const os = String(d.platform || '').trim().toLowerCase();
39
+ if (n && os) return `host:${os}:${n}`;
40
+ if (d.deviceId) return `id:${d.deviceId}`;
41
+ return `name:${d.name}`;
42
+ }
43
+
44
+ function aliasKey(d: RemoteDevice): string | null {
45
+ if (d.isGuest) return null;
46
+ const n = normalizedName(d.name);
47
+ const os = String(d.platform || '').trim().toLowerCase();
48
+ if (!n || !os) return null;
49
+ return `${os}:${n}`;
50
+ }
51
+
52
+ function endpointKey(d: RemoteDevice): string | null {
53
+ if (d.isGuest) return null;
54
+ const h = normalizedHost(d.quicHost);
55
+ if (!h) return null;
56
+ return `${h}:${d.quicPort || 0}`;
57
+ }
58
+
59
+ function mergeEntries(existing: RemoteDevice, incoming: RemoteDevice): RemoteDevice {
60
+ const incomingWins =
61
+ (!!existing.needsAuth && !incoming.needsAuth) ||
62
+ (incoming.lastHeartbeat || 0) > (existing.lastHeartbeat || 0) ||
63
+ (!!incoming.isOnline && !existing.isOnline);
64
+ const base = incomingWins ? incoming : existing;
65
+ const other = incomingWins ? existing : incoming;
66
+ return {
67
+ ...other,
68
+ ...base,
69
+ quicHost: base.quicHost || other.quicHost,
70
+ quicPort: base.quicPort || other.quicPort,
71
+ isOnline: base.isOnline || other.isOnline,
72
+ runnerDown: base.runnerDown && other.runnerDown,
73
+ publicKey: base.publicKey || other.publicKey,
74
+ lastHeartbeat: Math.max(existing.lastHeartbeat || 0, incoming.lastHeartbeat || 0),
75
+ };
76
+ }
77
+
78
+ // When two rows share the same alias key (hostname + OS) but differ on
79
+ // hwid/publicKey, pick the active one over the stale needs-auth leftover.
80
+ function pickActiveOverStaleNeedsAuth(a: RemoteDevice, b: RemoteDevice): RemoteDevice | null {
81
+ const aDead = a.needsAuth && !a.isOnline;
82
+ const bDead = b.needsAuth && !b.isOnline;
83
+ const aLive = !a.needsAuth && a.isOnline;
84
+ const bLive = !b.needsAuth && b.isOnline;
85
+ if (aDead && bLive) return b;
86
+ if (bDead && aLive) return a;
87
+ return null;
88
+ }
89
+
90
+ /**
91
+ * Collapse a Convex device list so each physical machine appears once.
92
+ * Safe on an empty list; idempotent on an already-deduped list.
93
+ */
94
+ export function collapseRemoteDevices(devices: RemoteDevice[]): RemoteDevice[] {
95
+ if (!Array.isArray(devices) || devices.length === 0) return [];
96
+
97
+ const byIdentity = new Map<string, RemoteDevice>();
98
+ for (const d of devices) {
99
+ const k = identityKey(d);
100
+ const prev = byIdentity.get(k);
101
+ byIdentity.set(k, prev ? mergeEntries(prev, d) : d);
102
+ }
103
+
104
+ const byAlias = new Map<string, RemoteDevice>();
105
+ for (const d of byIdentity.values()) {
106
+ const k = aliasKey(d);
107
+ if (!k) {
108
+ byAlias.set(`id:${d.deviceId}`, d);
109
+ continue;
110
+ }
111
+ const prev = byAlias.get(k);
112
+ if (!prev) {
113
+ byAlias.set(k, d);
114
+ continue;
115
+ }
116
+ const strongIdentityConflict =
117
+ !!prev.publicKey && !!d.publicKey && prev.publicKey !== d.publicKey;
118
+ if (strongIdentityConflict) {
119
+ const winner = pickActiveOverStaleNeedsAuth(prev, d);
120
+ if (winner) {
121
+ byAlias.set(k, winner);
122
+ continue;
123
+ }
124
+ }
125
+ byAlias.set(k, mergeEntries(prev, d));
126
+ }
127
+
128
+ const byEndpoint = new Map<string, RemoteDevice>();
129
+ for (const d of byAlias.values()) {
130
+ const k = endpointKey(d);
131
+ if (!k) {
132
+ byEndpoint.set(`id:${d.deviceId}`, d);
133
+ continue;
134
+ }
135
+ const prev = byEndpoint.get(k);
136
+ byEndpoint.set(k, prev ? mergeEntries(prev, d) : d);
137
+ }
138
+
139
+ return [...byEndpoint.values()];
140
+ }
141
+
142
+ /**
143
+ * Threshold for "online" based on heartbeat age, in milliseconds.
144
+ * Matches the mobile app (HEARTBEAT_STALE_MS = 90 s). The SDK used
145
+ * 60 s, which flashed yellow on single missed beats.
146
+ */
147
+ export const HEARTBEAT_STALE_MS = 90_000;
148
+
149
+ /**
150
+ * Returns a freshness flag consistent with the mobile app. A device is
151
+ * "fresh" when it was online per Convex AND its heartbeat is within
152
+ * `HEARTBEAT_STALE_MS`.
153
+ */
154
+ export function isDeviceFresh(d: RemoteDevice): boolean {
155
+ if (!d.isOnline) return false;
156
+ if (!d.lastHeartbeat) return true;
157
+ return Date.now() - d.lastHeartbeat < HEARTBEAT_STALE_MS;
158
+ }
159
+
160
+ /**
161
+ * Pick the best candidate for an auto-connect attempt. Preference:
162
+ * 1. matches the preferred deviceId when supplied + still fresh
163
+ * 2. fresh (online + recent heartbeat) + has a quicHost
164
+ * 3. online + has a quicHost
165
+ * 4. first with a quicHost
166
+ */
167
+ export function pickTargetDevice(
168
+ devices: RemoteDevice[],
169
+ preferredDeviceId?: string,
170
+ ): RemoteDevice | null {
171
+ if (!devices.length) return null;
172
+ if (preferredDeviceId) {
173
+ const preferred = devices.find(
174
+ (d) => d.deviceId === preferredDeviceId && d.quicHost,
175
+ );
176
+ if (preferred && isDeviceFresh(preferred)) return preferred;
177
+ if (preferred) return preferred;
178
+ }
179
+ const fresh = devices.find((d) => isDeviceFresh(d) && d.quicHost);
180
+ if (fresh) return fresh;
181
+ const online = devices.find((d) => d.isOnline && d.quicHost);
182
+ if (online) return online;
183
+ return devices.find((d) => d.quicHost) || devices[0] || null;
184
+ }
package/src/expo.ts CHANGED
@@ -31,7 +31,6 @@ import type { FeedbackConfig } from './types';
31
31
  *
32
32
  * Defaults:
33
33
  * - trigger: 'shake'
34
- * - feedbackMode: 'batch'
35
34
  * - enabled: __DEV__ (only active in development)
36
35
  *
37
36
  * @param overrides - Optional partial config to override defaults
@@ -54,7 +53,6 @@ export function initExpo(overrides?: Partial<FeedbackConfig>): void {
54
53
  YaverFeedback.init({
55
54
  authToken: '', // LAN auto-discovery doesn't require a token
56
55
  trigger: 'shake',
57
- feedbackMode: 'batch',
58
56
  enabled: __DEV__,
59
57
  ...overrides,
60
58
  ...(agentUrl ? { agentUrl } : {}),
package/src/index.ts CHANGED
@@ -1,24 +1,29 @@
1
1
  /**
2
- * @yaver/feedback-react-native — Visual feedback SDK for Yaver.
2
+ * yaver-feedback-react-native — Visual feedback SDK for Yaver.
3
3
  *
4
- * Shake-to-report, screenshots, voice annotations, P2P connection,
5
- * device discovery, and live/narrated/batch feedback modes for vibe coding.
4
+ * Shake-to-report surface with five one-tap actions:
5
+ * 1. Hot Reload — instant JS reload
6
+ * 2. Screenshot & Fix — capture the screen under the modal and
7
+ * kick a fix task on the agent
8
+ * 3. Vibing — open a vibing session on the agent
9
+ * 4. Start / Stop Recording — screen recording toggle
10
+ * 5. Send Video — submit the last recording
6
11
  *
7
12
  * @example
8
13
  * ```tsx
9
- * import { YaverFeedback, FeedbackProvider } from '@yaver/feedback-react-native';
14
+ * import { YaverFeedback, FeedbackModal } from 'yaver-feedback-react-native';
10
15
  *
11
16
  * YaverFeedback.init({
12
17
  * agentUrl: 'http://192.168.1.10:18080',
13
18
  * authToken: 'your-token',
14
19
  * trigger: 'shake',
15
- * feedbackMode: 'live',
20
+ * strictNativeAuth: true,
16
21
  * });
17
22
  *
18
- * // Wrap your app root:
19
- * <FeedbackProvider>
23
+ * <>
20
24
  * <App />
21
- * </FeedbackProvider>
25
+ * <FeedbackModal />
26
+ * </>
22
27
  * ```
23
28
  */
24
29
 
@@ -67,7 +72,12 @@ export type {
67
72
  RemoteDevice,
68
73
  DeviceList,
69
74
  } from './auth';
70
- export { captureScreenshot, startAudioRecording, stopAudioRecording } from './capture';
75
+ export {
76
+ captureScreenshot,
77
+ startVideoRecording,
78
+ stopVideoRecording,
79
+ isVideoRecording,
80
+ } from './capture';
71
81
  export { uploadFeedback } from './upload';
72
82
  export type {
73
83
  FeedbackConfig,
@@ -77,7 +87,6 @@ export type {
77
87
  AppInfo,
78
88
  TimelineEvent,
79
89
  FeedbackReport,
80
- AgentCommentary,
81
90
  FeedbackStreamEvent,
82
91
  VoiceCapability,
83
92
  CapturedError,
package/src/types.ts CHANGED
@@ -65,27 +65,6 @@ export interface FeedbackConfig {
65
65
  reportingOnly?: boolean;
66
66
  /** Max screen recording duration in seconds. Default: 120 */
67
67
  maxRecordingDuration?: number;
68
- /**
69
- * Feedback mode:
70
- * - 'live': stream events to the agent as they happen
71
- * - 'narrated': record everything, send on stop
72
- * - 'batch': dump everything at end (default)
73
- */
74
- feedbackMode?: 'live' | 'narrated' | 'batch';
75
- /**
76
- * Agent commentary level (0-10).
77
- * 0 = silent, 10 = agent comments on everything it sees.
78
- * Only relevant in live mode. Default: 0.
79
- */
80
- agentCommentaryLevel?: number;
81
- /**
82
- * Enable voice input for feedback annotations. Always true by default.
83
- * Audio is recorded on the device and sent to the agent for transcription.
84
- * Works regardless of whether a speech-to-speech provider is configured —
85
- * if STT is available on the agent, audio is auto-transcribed; otherwise
86
- * raw audio is attached to the feedback report.
87
- */
88
- voiceEnabled?: boolean;
89
68
  /**
90
69
  * Maximum number of captured errors to keep in memory (ring buffer).
91
70
  * Oldest errors are evicted when the buffer is full.
@@ -180,13 +159,10 @@ export interface FeedbackConfig {
180
159
 
181
160
  export interface FeedbackBundle {
182
161
  metadata: FeedbackMetadata;
162
+ /** Screen-recording file path, when produced by the "Start Recording" action. */
183
163
  video?: string;
184
- /** Voice annotation audio file path (WAV). Always available when voiceEnabled. */
185
- audio?: string;
186
- /** Transcribed text from voice annotation (if STT/S2S provider is available on agent). */
187
- audioTranscript?: string;
188
164
  screenshots: string[];
189
- /** Captured errors with stack traces, attached automatically when captureErrors is enabled. */
165
+ /** Captured errors with stack traces, attached via attachError / wrapErrorHandler. */
190
166
  errors?: CapturedError[];
191
167
  }
192
168
 
@@ -239,13 +215,6 @@ export interface FeedbackReport {
239
215
  error?: string;
240
216
  }
241
217
 
242
- export interface AgentCommentary {
243
- id: string;
244
- timestamp: string;
245
- message: string;
246
- type: 'observation' | 'suggestion' | 'question' | 'action';
247
- }
248
-
249
218
  export interface FeedbackStreamEvent {
250
219
  type: string;
251
220
  timestamp: string;
package/src/upload.ts CHANGED
@@ -7,16 +7,17 @@ import { FeedbackBundle } from './types';
7
7
  * The agent receives the bundle at POST /feedback with:
8
8
  * - `metadata` (JSON string)
9
9
  * - `screenshot_0`, `screenshot_1`, ... (image files)
10
- * - `audio` (audio file, if present)
11
10
  * - `video` (video file, if present)
12
11
  *
13
- * @returns The feedback report ID from the agent response.
12
+ * Returns the parsed agent response typically `{ ok, id, reportId }`.
13
+ * Callers can inspect `.id` / `.reportId` to drive a follow-up
14
+ * `/feedback/{id}/fix` kick.
14
15
  */
15
16
  export async function uploadFeedback(
16
17
  agentUrl: string,
17
18
  authToken: string,
18
19
  bundle: FeedbackBundle,
19
- ): Promise<string> {
20
+ ): Promise<{ id?: string; reportId?: string; [k: string]: unknown }> {
20
21
  const formData = new FormData();
21
22
 
22
23
  // Attach metadata as JSON
@@ -32,16 +33,6 @@ export async function uploadFeedback(
32
33
  } as any);
33
34
  }
34
35
 
35
- // Attach audio
36
- if (bundle.audio) {
37
- formData.append('audio', {
38
- uri:
39
- Platform.OS === 'android' ? `file://${bundle.audio}` : bundle.audio,
40
- type: 'audio/m4a',
41
- name: 'voice_note.m4a',
42
- } as any);
43
- }
44
-
45
36
  // Attach video
46
37
  if (bundle.video) {
47
38
  formData.append('video', {
@@ -69,6 +60,6 @@ export async function uploadFeedback(
69
60
  );
70
61
  }
71
62
 
72
- const result = await response.json();
73
- return result.id ?? result.reportId ?? 'unknown';
63
+ const result = await response.json().catch(() => ({}));
64
+ return result as { id?: string; reportId?: string; [k: string]: unknown };
74
65
  }