yaver-feedback-react-native 0.8.3 → 0.8.6
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/dist/AuthOverlay.js +45 -18
- package/dist/FeedbackModal.js +307 -2
- package/dist/LoginScreen.js +19 -5
- package/dist/MachinePickerScreen.js +44 -6
- package/dist/P2PClient.d.ts +23 -2
- package/dist/P2PClient.js +53 -4
- package/dist/QuickActionIcon.js +27 -2
- package/dist/YaverFeedback.d.ts +13 -0
- package/dist/YaverFeedback.js +78 -34
- package/dist/__tests__/AuthDevices.test.d.ts +1 -0
- package/dist/__tests__/AuthDevices.test.js +82 -0
- package/dist/auth.d.ts +6 -0
- package/dist/auth.js +41 -0
- package/dist/types.d.ts +21 -0
- package/package.json +2 -2
- package/src/AuthOverlay.tsx +48 -19
- package/src/FeedbackModal.tsx +349 -1
- package/src/LoginScreen.tsx +19 -5
- package/src/MachinePickerScreen.tsx +45 -6
- package/src/P2PClient.ts +61 -5
- package/src/QuickActionIcon.tsx +37 -2
- package/src/YaverFeedback.ts +83 -34
- package/src/__tests__/AuthDevices.test.ts +93 -0
- package/src/auth.ts +46 -0
- package/src/types.ts +22 -0
package/src/QuickActionIcon.tsx
CHANGED
|
@@ -133,6 +133,7 @@ export const QuickActionIcon: React.FC<QuickActionIconProps> = ({
|
|
|
133
133
|
const [shakenThisSession, setShakenThisSession] = useState(false);
|
|
134
134
|
const [menuOpen, setMenuOpen] = useState(false);
|
|
135
135
|
const [hostSuppressed] = useState<boolean>(() => isRunningInsideYaverHost());
|
|
136
|
+
const [launching, setLaunching] = useState(false);
|
|
136
137
|
|
|
137
138
|
// Load the persisted disable flag once on mount. Until it resolves we
|
|
138
139
|
// render nothing — a one-frame flash of the icon before hiding would
|
|
@@ -194,6 +195,37 @@ export const QuickActionIcon: React.FC<QuickActionIconProps> = ({
|
|
|
194
195
|
};
|
|
195
196
|
}, []);
|
|
196
197
|
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
const launchSub = DeviceEventEmitter.addListener(
|
|
200
|
+
'yaverFeedback:reportLaunch',
|
|
201
|
+
(event?: { state?: string }) => {
|
|
202
|
+
if (event?.state === 'starting') {
|
|
203
|
+
setLaunching(true);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
setLaunching(false);
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
const reportSub = DeviceEventEmitter.addListener(
|
|
210
|
+
'yaverFeedback:startReport',
|
|
211
|
+
() => setLaunching(false),
|
|
212
|
+
);
|
|
213
|
+
const loginSub = DeviceEventEmitter.addListener(
|
|
214
|
+
'yaverFeedback:startLogin',
|
|
215
|
+
() => setLaunching(false),
|
|
216
|
+
);
|
|
217
|
+
const pickerSub = DeviceEventEmitter.addListener(
|
|
218
|
+
'yaverFeedback:startMachinePicker',
|
|
219
|
+
() => setLaunching(false),
|
|
220
|
+
);
|
|
221
|
+
return () => {
|
|
222
|
+
launchSub.remove();
|
|
223
|
+
reportSub.remove();
|
|
224
|
+
loginSub.remove();
|
|
225
|
+
pickerSub.remove();
|
|
226
|
+
};
|
|
227
|
+
}, []);
|
|
228
|
+
|
|
197
229
|
const panResponder = useRef(
|
|
198
230
|
PanResponder.create({
|
|
199
231
|
onStartShouldSetPanResponder: () => true,
|
|
@@ -231,9 +263,10 @@ export const QuickActionIcon: React.FC<QuickActionIconProps> = ({
|
|
|
231
263
|
).current;
|
|
232
264
|
|
|
233
265
|
const openFeedback = useCallback(() => {
|
|
266
|
+
if (launching) return;
|
|
234
267
|
setMenuOpen(false);
|
|
235
268
|
void YaverFeedback.startReport();
|
|
236
|
-
}, []);
|
|
269
|
+
}, [launching]);
|
|
237
270
|
|
|
238
271
|
const hideForever = useCallback(() => {
|
|
239
272
|
setMenuOpen(false);
|
|
@@ -275,10 +308,12 @@ export const QuickActionIcon: React.FC<QuickActionIconProps> = ({
|
|
|
275
308
|
didDrag.current = false;
|
|
276
309
|
return;
|
|
277
310
|
}
|
|
311
|
+
if (launching) return;
|
|
278
312
|
openFeedback();
|
|
279
313
|
}}
|
|
280
314
|
onLongPress={() => {
|
|
281
315
|
if (didDrag.current) return;
|
|
316
|
+
if (launching) return;
|
|
282
317
|
setMenuOpen((m) => !m);
|
|
283
318
|
}}
|
|
284
319
|
delayLongPress={LONG_PRESS_MS}
|
|
@@ -294,7 +329,7 @@ export const QuickActionIcon: React.FC<QuickActionIconProps> = ({
|
|
|
294
329
|
backgroundColor: presetColors?.backgroundColor ?? backgroundColor,
|
|
295
330
|
borderColor: presetColors?.borderColor ?? borderColor,
|
|
296
331
|
shadowColor: presetColors?.shadowColor ?? shadowColor,
|
|
297
|
-
opacity: pressed ? 0.85 : 1,
|
|
332
|
+
opacity: launching ? 0.62 : pressed ? 0.85 : 1,
|
|
298
333
|
},
|
|
299
334
|
]}
|
|
300
335
|
>
|
package/src/YaverFeedback.ts
CHANGED
|
@@ -51,6 +51,7 @@ let enabled = false;
|
|
|
51
51
|
let p2pClient: P2PClient | null = null;
|
|
52
52
|
let shakeDetector: ShakeDetector | null = null;
|
|
53
53
|
let p2pAuthToken: string | null = null;
|
|
54
|
+
let reportLaunchInFlight = false;
|
|
54
55
|
|
|
55
56
|
/** Ring buffer of captured errors. */
|
|
56
57
|
let errorBuffer: CapturedError[] = [];
|
|
@@ -420,6 +421,37 @@ export class YaverFeedback {
|
|
|
420
421
|
return all.find((device) => device.deviceId === preferredDeviceId) ?? null;
|
|
421
422
|
}
|
|
422
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Trigger remote device-auth for a CLI runner on the selected agent
|
|
426
|
+
* (codex login --device-auth / claude auth login --console). Returns
|
|
427
|
+
* the session so the host UI can render the verification URL + code.
|
|
428
|
+
*
|
|
429
|
+
* RN UI layer owns the modal (see FeedbackModal's runner sign-in
|
|
430
|
+
* buttons). This method just proxies into P2PClient — no browser
|
|
431
|
+
* launch, no API keys, works through the relay with an SDK token
|
|
432
|
+
* that carries the runner-auth scope.
|
|
433
|
+
*/
|
|
434
|
+
static async startRunnerBrowserAuth(
|
|
435
|
+
runner: string,
|
|
436
|
+
): Promise<import('./types').RunnerBrowserAuthSession> {
|
|
437
|
+
if (!p2pClient) {
|
|
438
|
+
throw new Error('Not connected to any agent. Select a machine first.');
|
|
439
|
+
}
|
|
440
|
+
return p2pClient.startRunnerBrowserAuth(runner);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
static async getRunnerBrowserAuthStatus(
|
|
444
|
+
sessionId: string,
|
|
445
|
+
): Promise<import('./types').RunnerBrowserAuthSession> {
|
|
446
|
+
if (!p2pClient) throw new Error('Not connected to any agent.');
|
|
447
|
+
return p2pClient.getRunnerBrowserAuthStatus(sessionId);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
static async cancelRunnerBrowserAuth(sessionId: string): Promise<void> {
|
|
451
|
+
if (!p2pClient) return;
|
|
452
|
+
await p2pClient.cancelRunnerBrowserAuth(sessionId);
|
|
453
|
+
}
|
|
454
|
+
|
|
423
455
|
/**
|
|
424
456
|
* Sign out: clear cached token + device, tear down the P2P client. The
|
|
425
457
|
* SDK stays enabled; the next feedback trigger will re-prompt for login.
|
|
@@ -450,47 +482,64 @@ export class YaverFeedback {
|
|
|
450
482
|
if (!enabled) {
|
|
451
483
|
return;
|
|
452
484
|
}
|
|
485
|
+
if (reportLaunchInFlight) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
453
488
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
489
|
+
reportLaunchInFlight = true;
|
|
490
|
+
const { DeviceEventEmitter } = require('react-native');
|
|
491
|
+
DeviceEventEmitter.emit('yaverFeedback:reportLaunch', {
|
|
492
|
+
state: 'starting',
|
|
493
|
+
at: Date.now(),
|
|
494
|
+
});
|
|
495
|
+
try {
|
|
496
|
+
|
|
497
|
+
// If the caller has autoLogin enabled and we have no session yet, show
|
|
498
|
+
// the in-SDK login flow instead of a failing discovery + warning spam.
|
|
460
499
|
if (!config.authToken) {
|
|
461
|
-
|
|
462
|
-
|
|
500
|
+
if (config.autoLogin !== false) {
|
|
501
|
+
await YaverFeedback.hydrateSession();
|
|
502
|
+
}
|
|
503
|
+
if (!config.authToken) {
|
|
504
|
+
YaverFeedback.showLogin();
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
463
507
|
}
|
|
464
|
-
}
|
|
465
508
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
509
|
+
// Auto-discover if no agent URL was provided
|
|
510
|
+
if (!config.agentUrl) {
|
|
511
|
+
try {
|
|
512
|
+
const result = await YaverDiscovery.discover({
|
|
513
|
+
convexUrl: config.convexUrl,
|
|
514
|
+
authToken: config.authToken,
|
|
515
|
+
preferredDeviceId: config.preferredDeviceId,
|
|
516
|
+
});
|
|
517
|
+
if (result) {
|
|
518
|
+
config.agentUrl = result.url;
|
|
519
|
+
await YaverFeedback.rebuildP2PClient(result.url);
|
|
520
|
+
} else if (config.autoLogin !== false && !config.preferredDeviceId) {
|
|
521
|
+
// No agent discovered and no device picked yet — prompt the user
|
|
522
|
+
// to pick one of their machines (handles the non-LAN case where
|
|
523
|
+
// relay discovery requires knowing which deviceId to target).
|
|
524
|
+
YaverFeedback.showMachinePicker();
|
|
525
|
+
return;
|
|
526
|
+
} else {
|
|
527
|
+
console.warn('[YaverFeedback] No agent found. Check that `yaver serve` is running on the selected machine.');
|
|
528
|
+
}
|
|
529
|
+
} catch (err) {
|
|
530
|
+
console.warn('[YaverFeedback] Auto-discovery failed:', err);
|
|
485
531
|
}
|
|
486
|
-
} catch (err) {
|
|
487
|
-
console.warn('[YaverFeedback] Auto-discovery failed:', err);
|
|
488
532
|
}
|
|
489
|
-
}
|
|
490
533
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
534
|
+
// Emit event that the FeedbackModal listens for
|
|
535
|
+
DeviceEventEmitter.emit('yaverFeedback:startReport');
|
|
536
|
+
} finally {
|
|
537
|
+
reportLaunchInFlight = false;
|
|
538
|
+
DeviceEventEmitter.emit('yaverFeedback:reportLaunch', {
|
|
539
|
+
state: 'settled',
|
|
540
|
+
at: Date.now(),
|
|
541
|
+
});
|
|
542
|
+
}
|
|
494
543
|
}
|
|
495
544
|
|
|
496
545
|
/** Returns true if the SDK has been initialized. */
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { listReachableDevices } from '../auth';
|
|
2
|
+
|
|
3
|
+
const mockFetch = jest.fn();
|
|
4
|
+
global.fetch = mockFetch as any;
|
|
5
|
+
|
|
6
|
+
describe('auth device listing', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
mockFetch.mockReset();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('keeps guest-shared devices in the shared bucket', async () => {
|
|
13
|
+
mockFetch.mockResolvedValue({
|
|
14
|
+
ok: true,
|
|
15
|
+
json: () =>
|
|
16
|
+
Promise.resolve({
|
|
17
|
+
devices: [
|
|
18
|
+
{
|
|
19
|
+
deviceId: 'own-1',
|
|
20
|
+
name: 'My Mac',
|
|
21
|
+
platform: 'macos',
|
|
22
|
+
isOnline: true,
|
|
23
|
+
isGuest: false,
|
|
24
|
+
quicHost: '10.0.0.10',
|
|
25
|
+
quicPort: 18080,
|
|
26
|
+
lastHeartbeat: 123,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
deviceId: 'guest-1',
|
|
30
|
+
name: 'yaver-test-ephemeral',
|
|
31
|
+
platform: 'linux',
|
|
32
|
+
isOnline: true,
|
|
33
|
+
isGuest: true,
|
|
34
|
+
hostName: 'Kivanc Cakmak',
|
|
35
|
+
hostEmail: 'kivanc.cakmak@icloud.com',
|
|
36
|
+
accessScope: 'shared-scoped',
|
|
37
|
+
quicHost: '157.180.114.179',
|
|
38
|
+
quicPort: 18080,
|
|
39
|
+
lastHeartbeat: 456,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const result = await listReachableDevices('sdk-user-token');
|
|
46
|
+
|
|
47
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
48
|
+
expect.stringContaining('/devices/list'),
|
|
49
|
+
expect.objectContaining({
|
|
50
|
+
headers: { Authorization: 'Bearer sdk-user-token' },
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
expect(result.owned).toHaveLength(1);
|
|
54
|
+
expect(result.shared).toHaveLength(1);
|
|
55
|
+
expect(result.owned[0].deviceId).toBe('own-1');
|
|
56
|
+
expect(result.shared[0]).toMatchObject({
|
|
57
|
+
deviceId: 'guest-1',
|
|
58
|
+
isGuest: true,
|
|
59
|
+
hostEmail: 'kivanc.cakmak@icloud.com',
|
|
60
|
+
accessScope: 'shared-scoped',
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('shows shared devices even when the guest owns no machines', async () => {
|
|
65
|
+
mockFetch.mockResolvedValue({
|
|
66
|
+
ok: true,
|
|
67
|
+
json: () =>
|
|
68
|
+
Promise.resolve({
|
|
69
|
+
devices: [
|
|
70
|
+
{
|
|
71
|
+
deviceId: 'guest-only',
|
|
72
|
+
name: 'yaver-test-ephemeral',
|
|
73
|
+
platform: 'linux',
|
|
74
|
+
isOnline: true,
|
|
75
|
+
isGuest: true,
|
|
76
|
+
hostName: 'Kivanc Cakmak',
|
|
77
|
+
hostEmail: 'kivanc.cakmak@icloud.com',
|
|
78
|
+
accessScope: 'shared-scoped',
|
|
79
|
+
quicHost: '157.180.114.179',
|
|
80
|
+
quicPort: 18080,
|
|
81
|
+
lastHeartbeat: 789,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const result = await listReachableDevices('guest-only-token');
|
|
88
|
+
|
|
89
|
+
expect(result.owned).toEqual([]);
|
|
90
|
+
expect(result.shared).toHaveLength(1);
|
|
91
|
+
expect(result.shared[0].deviceId).toBe('guest-only');
|
|
92
|
+
});
|
|
93
|
+
});
|
package/src/auth.ts
CHANGED
|
@@ -435,6 +435,11 @@ export interface DeviceList {
|
|
|
435
435
|
shared: RemoteDevice[];
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
+
export interface DeviceReachability {
|
|
439
|
+
reachable: boolean;
|
|
440
|
+
url?: string;
|
|
441
|
+
}
|
|
442
|
+
|
|
438
443
|
export interface GuestInvitation {
|
|
439
444
|
hostUserId: string;
|
|
440
445
|
hostName: string;
|
|
@@ -536,6 +541,47 @@ export async function listReachableDevices(
|
|
|
536
541
|
}
|
|
537
542
|
}
|
|
538
543
|
|
|
544
|
+
export function buildDeviceCandidateUrls(device: RemoteDevice): string[] {
|
|
545
|
+
const port = device.httpPort ?? device.quicPort ?? 18080;
|
|
546
|
+
const hosts = new Set<string>();
|
|
547
|
+
if (device.quicHost) hosts.add(device.quicHost);
|
|
548
|
+
for (const ip of device.localIps ?? []) {
|
|
549
|
+
if (ip) hosts.add(ip);
|
|
550
|
+
}
|
|
551
|
+
return Array.from(hosts).map((host) => `http://${host}:${port}`);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export async function probeDeviceReachability(
|
|
555
|
+
device: RemoteDevice,
|
|
556
|
+
timeoutMs = 2500,
|
|
557
|
+
): Promise<DeviceReachability> {
|
|
558
|
+
const candidates = buildDeviceCandidateUrls(device);
|
|
559
|
+
if (candidates.length === 0) return { reachable: false };
|
|
560
|
+
|
|
561
|
+
const probeOne = async (baseUrl: string): Promise<string> => {
|
|
562
|
+
const controller = new AbortController();
|
|
563
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
564
|
+
try {
|
|
565
|
+
const response = await fetch(`${baseUrl}/health`, {
|
|
566
|
+
method: 'GET',
|
|
567
|
+
signal: controller.signal,
|
|
568
|
+
});
|
|
569
|
+
if (!response.ok) throw new Error(`health ${response.status}`);
|
|
570
|
+
return baseUrl;
|
|
571
|
+
} finally {
|
|
572
|
+
clearTimeout(timer);
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
const settled = await Promise.allSettled(candidates.map((url) => probeOne(url)));
|
|
577
|
+
for (const result of settled) {
|
|
578
|
+
if (result.status === 'fulfilled') {
|
|
579
|
+
return { reachable: true, url: result.value };
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return { reachable: false };
|
|
583
|
+
}
|
|
584
|
+
|
|
539
585
|
export async function mintGuestSdkToken(
|
|
540
586
|
token: string,
|
|
541
587
|
hostUserId: string,
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote browser-style sign-in session for a coding-agent CLI on the
|
|
3
|
+
* connected yaver host. Mirrors runnerBrowserAuthSession on the agent
|
|
4
|
+
* Go side. Progression: starting → awaiting_browser (openUrl + code
|
|
5
|
+
* filled) → completed | failed | cancelled.
|
|
6
|
+
*/
|
|
7
|
+
export interface RunnerBrowserAuthSession {
|
|
8
|
+
id: string;
|
|
9
|
+
runner: string;
|
|
10
|
+
method: string;
|
|
11
|
+
status: 'starting' | 'awaiting_browser' | 'completed' | 'failed' | 'cancelled';
|
|
12
|
+
openUrl?: string;
|
|
13
|
+
code?: string;
|
|
14
|
+
detail?: string;
|
|
15
|
+
authConfigured?: boolean;
|
|
16
|
+
authSource?: string;
|
|
17
|
+
error?: string;
|
|
18
|
+
startedAt: number;
|
|
19
|
+
updatedAt: number;
|
|
20
|
+
completedAt?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
1
23
|
export interface FeedbackConfig {
|
|
2
24
|
/** URL of the Yaver agent (e.g. "http://192.168.1.10:18080"). If omitted, auto-discovery is used. */
|
|
3
25
|
agentUrl?: string;
|