yaver-feedback-react-native 0.9.0 → 0.9.3
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 +102 -1
- package/app.plugin.js +126 -9
- package/dist/AuthOverlay.d.ts +1 -14
- package/dist/AuthOverlay.js +9 -62
- package/dist/BlackBox.js +9 -1
- package/dist/DeployPanel.js +65 -0
- package/dist/Discovery.js +13 -8
- package/dist/DogfoodRuntime.d.ts +124 -0
- package/dist/DogfoodRuntime.js +273 -0
- package/dist/FeedbackModal.js +505 -65
- package/dist/LoginScreen.d.ts +1 -5
- package/dist/LoginScreen.js +2 -6
- package/dist/MachinePickerScreen.d.ts +1 -3
- package/dist/MachinePickerScreen.js +6 -18
- package/dist/P2PClient.d.ts +178 -2
- package/dist/P2PClient.js +493 -3
- package/dist/P2PDogfoodDriver.d.ts +12 -0
- package/dist/P2PDogfoodDriver.js +118 -0
- package/dist/PairDeviceModal.d.ts +2 -3
- package/dist/ShakeDetector.js +2 -0
- package/dist/VibeChatScreen.d.ts +11 -1
- package/dist/VibeChatScreen.js +200 -41
- package/dist/YaverFeedback.d.ts +132 -0
- package/dist/YaverFeedback.js +633 -65
- package/dist/YaverModeBadge.d.ts +22 -0
- package/dist/YaverModeBadge.js +219 -0
- package/dist/__tests__/AuthDevices.test.js +1 -48
- package/dist/__tests__/BlackBox.relayPassword.test.d.ts +1 -0
- package/dist/__tests__/BlackBox.relayPassword.test.js +105 -0
- package/dist/__tests__/BlackBoxAutoStart.test.d.ts +1 -0
- package/dist/__tests__/BlackBoxAutoStart.test.js +91 -0
- package/dist/__tests__/BlackBoxAutoStartColdStart.test.d.ts +1 -0
- package/dist/__tests__/BlackBoxAutoStartColdStart.test.js +156 -0
- package/dist/__tests__/BrowserLaneIcon.test.d.ts +3 -0
- package/dist/__tests__/BrowserLaneIcon.test.js +80 -0
- package/dist/__tests__/DogfoodRuntime.test.d.ts +1 -0
- package/dist/__tests__/DogfoodRuntime.test.js +116 -0
- package/dist/__tests__/P2PClient.test.js +2 -2
- package/dist/__tests__/P2PDogfoodDriver.test.d.ts +1 -0
- package/dist/__tests__/P2PDogfoodDriver.test.js +64 -0
- package/dist/__tests__/ReportIdentity.test.d.ts +25 -0
- package/dist/__tests__/ReportIdentity.test.js +180 -0
- package/dist/__tests__/SDKToken.test.js +1 -1
- package/dist/__tests__/ShakeToggle.test.d.ts +1 -0
- package/dist/__tests__/ShakeToggle.test.js +121 -0
- package/dist/__tests__/YaverFeedback.test.js +13 -3
- package/dist/__tests__/deviceDogfood.test.d.ts +1 -0
- package/dist/__tests__/deviceDogfood.test.js +86 -0
- package/dist/__tests__/dogfoodPolicy.test.d.ts +1 -0
- package/dist/__tests__/dogfoodPolicy.test.js +33 -0
- package/dist/__tests__/pickTargetDevice.test.d.ts +1 -0
- package/dist/__tests__/pickTargetDevice.test.js +89 -0
- package/dist/__tests__/reloadActions.test.d.ts +1 -0
- package/dist/__tests__/reloadActions.test.js +129 -0
- package/dist/__tests__/reloadActionsParity.test.d.ts +1 -0
- package/dist/__tests__/reloadActionsParity.test.js +42 -0
- package/dist/__tests__/types.test.js +5 -5
- package/dist/_core/ansi.d.ts +117 -0
- package/dist/_core/ansi.js +468 -0
- package/dist/_core/ansi.test.d.ts +1 -0
- package/dist/_core/ansi.test.js +225 -0
- package/dist/_core/buildFeedbackPrompt.d.ts +4 -9
- package/dist/_core/buildFeedbackPrompt.js +18 -72
- package/dist/_core/constants.d.ts +19 -6
- package/dist/_core/constants.js +20 -7
- package/dist/_core/device.d.ts +1 -5
- package/dist/_core/device.js +5 -14
- package/dist/_core/endpoints.d.ts +0 -7
- package/dist/_core/endpoints.js +0 -7
- package/dist/_core/index.d.ts +4 -0
- package/dist/_core/index.js +4 -0
- package/dist/_core/remoteless.d.ts +44 -0
- package/dist/_core/remoteless.js +75 -0
- package/dist/_core/trace.d.ts +47 -0
- package/dist/_core/trace.js +38 -0
- package/dist/_core/trace.test.d.ts +1 -0
- package/dist/_core/trace.test.js +60 -0
- package/dist/auth.d.ts +3 -60
- package/dist/auth.js +6 -88
- package/dist/deviceDogfood.d.ts +53 -0
- package/dist/deviceDogfood.js +137 -0
- package/dist/dogfoodPolicy.d.ts +25 -0
- package/dist/dogfoodPolicy.js +24 -0
- package/dist/index.d.ts +17 -4
- package/dist/index.js +33 -7
- package/dist/reloadActions.d.ts +88 -0
- package/dist/reloadActions.js +200 -0
- package/dist/storeShots.d.ts +67 -0
- package/dist/storeShots.js +137 -0
- package/dist/types.d.ts +208 -8
- package/package.json +13 -4
- package/src/AuthOverlay.tsx +20 -106
- package/src/BlackBox.ts +10 -1
- package/src/DeployPanel.tsx +74 -0
- package/src/Discovery.ts +13 -8
- package/src/DogfoodRuntime.ts +373 -0
- package/src/FeedbackModal.tsx +619 -79
- package/src/LoginScreen.tsx +2 -22
- package/src/MachinePickerScreen.tsx +6 -21
- package/src/P2PClient.ts +580 -4
- package/src/P2PDogfoodDriver.ts +132 -0
- package/src/PairDeviceModal.tsx +2 -3
- package/src/ShakeDetector.ts +1 -0
- package/src/VibeChatScreen.tsx +232 -42
- package/src/YaverFeedback.ts +631 -68
- package/src/YaverModeBadge.tsx +234 -0
- package/src/__tests__/AuthDevices.test.ts +1 -52
- package/src/__tests__/BlackBox.relayPassword.test.ts +129 -0
- package/src/__tests__/BlackBoxAutoStart.test.ts +111 -0
- package/src/__tests__/BlackBoxAutoStartColdStart.test.ts +191 -0
- package/src/__tests__/BrowserLaneIcon.test.ts +85 -0
- package/src/__tests__/DogfoodRuntime.test.ts +135 -0
- package/src/__tests__/P2PClient.test.ts +2 -2
- package/src/__tests__/P2PDogfoodDriver.test.ts +80 -0
- package/src/__tests__/ReportIdentity.test.ts +212 -0
- package/src/__tests__/SDKToken.test.ts +1 -1
- package/src/__tests__/ShakeToggle.test.ts +153 -0
- package/src/__tests__/YaverFeedback.test.ts +15 -3
- package/src/__tests__/deviceDogfood.test.ts +77 -0
- package/src/__tests__/dogfoodPolicy.test.ts +34 -0
- package/src/__tests__/pickTargetDevice.test.ts +101 -0
- package/src/__tests__/reloadActions.test.ts +171 -0
- package/src/__tests__/reloadActionsParity.test.ts +49 -0
- package/src/__tests__/types.test.ts +5 -5
- package/src/_core/ansi.test.ts +250 -0
- package/src/_core/ansi.ts +475 -0
- package/src/_core/buildFeedbackPrompt.ts +18 -95
- package/src/_core/constants.ts +20 -6
- package/src/_core/device.ts +5 -16
- package/src/_core/endpoints.ts +0 -7
- package/src/_core/index.ts +4 -0
- package/src/_core/remoteless.ts +110 -0
- package/src/_core/trace.test.ts +58 -0
- package/src/_core/trace.ts +75 -0
- package/src/auth.ts +7 -156
- package/src/deviceDogfood.ts +171 -0
- package/src/dogfoodPolicy.ts +40 -0
- package/src/index.ts +61 -11
- package/src/reloadActions.ts +273 -0
- package/src/storeShots.ts +189 -0
- package/src/types.ts +209 -8
- package/dist/GuestOnboardingScreen.d.ts +0 -8
- package/dist/GuestOnboardingScreen.js +0 -282
- package/src/GuestOnboardingScreen.tsx +0 -307
package/src/P2PClient.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
2
|
import {
|
|
3
|
+
AppInfo,
|
|
3
4
|
CapabilitySnapshot,
|
|
4
5
|
FeedbackBundle,
|
|
6
|
+
FeedbackProjectRef,
|
|
5
7
|
IncidentEvent,
|
|
6
8
|
OpenCodeConfigSummary,
|
|
7
9
|
OperationState,
|
|
@@ -10,6 +12,27 @@ import {
|
|
|
10
12
|
TestSession,
|
|
11
13
|
VoiceCapability,
|
|
12
14
|
} from './types';
|
|
15
|
+
import { AGENT_ENDPOINTS } from './_core/endpoints';
|
|
16
|
+
import { RELOAD_PATH, describeReloadFailure } from './reloadActions';
|
|
17
|
+
import type { DevServerSnapshot, ReloadWireMode } from './reloadActions';
|
|
18
|
+
|
|
19
|
+
function unrefTimer(timer: ReturnType<typeof setTimeout>): void {
|
|
20
|
+
const maybeNodeTimer = timer as unknown as { unref?: () => void };
|
|
21
|
+
if (typeof maybeNodeTimer.unref === 'function') {
|
|
22
|
+
maybeNodeTimer.unref();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function dogfoodFetch(url: string, init: RequestInit, timeoutMs: number): Promise<Response> {
|
|
27
|
+
const ctrl = new AbortController();
|
|
28
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
29
|
+
unrefTimer(timer);
|
|
30
|
+
try {
|
|
31
|
+
return await fetch(url, { ...init, signal: ctrl.signal });
|
|
32
|
+
} finally {
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
13
36
|
|
|
14
37
|
export interface FeedbackEvent {
|
|
15
38
|
type: string;
|
|
@@ -26,6 +49,56 @@ export interface ReloadAck {
|
|
|
26
49
|
changeClass?: string;
|
|
27
50
|
}
|
|
28
51
|
|
|
52
|
+
export interface DogfoodDevServerStatus {
|
|
53
|
+
running?: boolean;
|
|
54
|
+
serving?: boolean;
|
|
55
|
+
starting?: boolean;
|
|
56
|
+
building?: boolean;
|
|
57
|
+
framework?: string;
|
|
58
|
+
workDir?: string;
|
|
59
|
+
bundleUrl?: string;
|
|
60
|
+
previewUrl?: string;
|
|
61
|
+
error?: string;
|
|
62
|
+
capabilityGap?: unknown;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface DogfoodDevEvent {
|
|
66
|
+
type: string;
|
|
67
|
+
framework?: string;
|
|
68
|
+
logLine?: string;
|
|
69
|
+
message?: string;
|
|
70
|
+
phase?: string;
|
|
71
|
+
pct?: number;
|
|
72
|
+
currentFile?: string;
|
|
73
|
+
snapshot?: { recentLogs?: string[]; [key: string]: unknown };
|
|
74
|
+
[key: string]: unknown;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface DogfoodRemoteRuntimeTarget {
|
|
78
|
+
id: string;
|
|
79
|
+
label: string;
|
|
80
|
+
enabled: boolean;
|
|
81
|
+
reason?: string;
|
|
82
|
+
platform?: string;
|
|
83
|
+
surface?: string;
|
|
84
|
+
displaySurface?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface DogfoodRemoteRuntimeCapabilities {
|
|
88
|
+
remoteRuntimeEligible?: boolean;
|
|
89
|
+
targets: DogfoodRemoteRuntimeTarget[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface DogfoodRemoteRuntimeSession {
|
|
93
|
+
id: string;
|
|
94
|
+
status: string;
|
|
95
|
+
targetId?: string;
|
|
96
|
+
targetLabel?: string;
|
|
97
|
+
transportMode?: string;
|
|
98
|
+
note?: string;
|
|
99
|
+
[key: string]: unknown;
|
|
100
|
+
}
|
|
101
|
+
|
|
29
102
|
/**
|
|
30
103
|
* Try to resolve `{projectName, bundleId}` for the running app so the
|
|
31
104
|
* agent can map the reload request to a MobileProject in its scan
|
|
@@ -76,6 +149,148 @@ export function resolveAppIdentity(opts?: {
|
|
|
76
149
|
return out;
|
|
77
150
|
}
|
|
78
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Is this JS running inside Yaver's own container as a pushed Hermes guest?
|
|
154
|
+
*
|
|
155
|
+
* The YaverInfo native module is registered only by Yaver's app, so its
|
|
156
|
+
* presence means the ambient runtime describes Yaver rather than the app
|
|
157
|
+
* whose code is executing. Mirrors the checks in YaverFeedback.ts,
|
|
158
|
+
* ShakeDetector.ts and QuickActionIcon.tsx.
|
|
159
|
+
*/
|
|
160
|
+
function isInsideYaverContainer(): boolean {
|
|
161
|
+
try {
|
|
162
|
+
const { NativeModules } = require('react-native');
|
|
163
|
+
return !!NativeModules?.YaverInfo;
|
|
164
|
+
} catch {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Read the guest project Yaver's host shell pinned for this bundle.
|
|
171
|
+
*
|
|
172
|
+
* When an app's JS is pushed into Yaver's container as a Hermes guest, the
|
|
173
|
+
* ambient runtime describes the HOST — `expo-constants` and `SettingsManager`
|
|
174
|
+
* both answer `Yaver` / `io.yaver.mobile`. Auto-resolution would therefore
|
|
175
|
+
* file every guest report against Yaver's own repo, and the fix task would
|
|
176
|
+
* edit the SDK instead of the app under test.
|
|
177
|
+
*
|
|
178
|
+
* Yaver already knows the right answer: picking a project in the Hot Reload
|
|
179
|
+
* tab calls `YaverInfo.setInheritedGuestProject(name, path)`. Only the name
|
|
180
|
+
* is used here — the agent resolves the path itself and deliberately ignores
|
|
181
|
+
* client-supplied ones on feedback reports.
|
|
182
|
+
*/
|
|
183
|
+
function resolveInheritedGuestProjectName(): string | undefined {
|
|
184
|
+
try {
|
|
185
|
+
const { NativeModules } = require('react-native');
|
|
186
|
+
const name = String(NativeModules?.YaverInfo?.inheritedGuestProjectName || '').trim();
|
|
187
|
+
return name || undefined;
|
|
188
|
+
} catch {
|
|
189
|
+
// Not inside Yaver's container, or react-native unavailable (unit tests).
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Build the app-identity half of a feedback report's metadata.
|
|
196
|
+
*
|
|
197
|
+
* `resolveAppIdentity()` has always fed /vibing/execute and /dev/reload-app,
|
|
198
|
+
* so the agent could route a "vibe on THIS app" request to the right repo —
|
|
199
|
+
* but nothing fed /feedback. Reports arrived with no identity at all, so the
|
|
200
|
+
* agent's fix router fell through to its own working directory and edited
|
|
201
|
+
* whichever repo it happened to be sitting in. This closes that gap by
|
|
202
|
+
* reusing the same resolver for the feedback path.
|
|
203
|
+
*
|
|
204
|
+
* Precedence, most to least trustworthy:
|
|
205
|
+
* 1. What the host app declared (`FeedbackConfig.projectName`/`bundleId`).
|
|
206
|
+
* An app knows its own identity; nothing should override it.
|
|
207
|
+
* 2. The guest project Yaver's host shell pinned, when running as a Hermes
|
|
208
|
+
* guest. Ambient lookups describe Yaver there, not the guest.
|
|
209
|
+
* 3. Ambient expo-constants / native modules — correct for a standalone
|
|
210
|
+
* build, which is the common case.
|
|
211
|
+
*
|
|
212
|
+
* Every lookup is best-effort: a bare RN app with no expo-constants still
|
|
213
|
+
* produces a report, just one the agent resolves by its own means.
|
|
214
|
+
*/
|
|
215
|
+
export function resolveReportIdentity(opts?: {
|
|
216
|
+
projectName?: string;
|
|
217
|
+
bundleId?: string;
|
|
218
|
+
surface?: FeedbackProjectRef['surface'];
|
|
219
|
+
surfaces?: FeedbackProjectRef['surfaces'];
|
|
220
|
+
stack?: string;
|
|
221
|
+
stacks?: string[];
|
|
222
|
+
testSurfaces?: string[];
|
|
223
|
+
feedbackSdk?: string;
|
|
224
|
+
feedbackTransport?: string;
|
|
225
|
+
voiceCapabilities?: string[];
|
|
226
|
+
sttProvider?: string;
|
|
227
|
+
ttsProvider?: string;
|
|
228
|
+
}): {
|
|
229
|
+
appName?: string;
|
|
230
|
+
app: AppInfo;
|
|
231
|
+
project?: FeedbackProjectRef;
|
|
232
|
+
} {
|
|
233
|
+
let projectName = (opts?.projectName || '').trim() || undefined;
|
|
234
|
+
let bundleId = (opts?.bundleId || '').trim() || undefined;
|
|
235
|
+
let version: string | undefined;
|
|
236
|
+
let buildNumber: string | undefined;
|
|
237
|
+
|
|
238
|
+
if (isInsideYaverContainer()) {
|
|
239
|
+
// Every ambient lookup answers for the HOST here. Because the agent
|
|
240
|
+
// routes on bundle id first, letting Yaver's id through would resolve
|
|
241
|
+
// straight to Yaver's own repo and the guest's name would never be
|
|
242
|
+
// consulted — so nothing ambient is trusted in the container. The
|
|
243
|
+
// version is Yaver's too, and reporting it would only mislabel which
|
|
244
|
+
// build the report came from.
|
|
245
|
+
projectName = projectName || resolveInheritedGuestProjectName();
|
|
246
|
+
} else {
|
|
247
|
+
const ambient = resolveAppIdentity({ projectName, bundleId });
|
|
248
|
+
projectName = ambient.projectName;
|
|
249
|
+
bundleId = ambient.bundleId;
|
|
250
|
+
try {
|
|
251
|
+
const Constants = require('expo-constants').default ?? require('expo-constants');
|
|
252
|
+
const cfg = Constants?.expoConfig ?? Constants?.manifest ?? {};
|
|
253
|
+
version = Constants?.nativeAppVersion || cfg?.version;
|
|
254
|
+
buildNumber =
|
|
255
|
+
Constants?.nativeBuildVersion ||
|
|
256
|
+
cfg?.ios?.buildNumber ||
|
|
257
|
+
(cfg?.android?.versionCode != null ? String(cfg.android.versionCode) : undefined);
|
|
258
|
+
} catch {
|
|
259
|
+
// expo-constants not installed (bare RN). Version is cosmetic — the
|
|
260
|
+
// router keys off appName/bundleId, both of which survive without it.
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const app: AppInfo = {};
|
|
265
|
+
if (bundleId) app.bundleId = bundleId;
|
|
266
|
+
if (version) app.version = version;
|
|
267
|
+
if (buildNumber) app.buildNumber = buildNumber;
|
|
268
|
+
|
|
269
|
+
if (!projectName && !bundleId) {
|
|
270
|
+
return { app };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const project: FeedbackProjectRef = { surface: opts?.surface ?? 'mobile' };
|
|
274
|
+
if (projectName) {
|
|
275
|
+
project.projectName = projectName;
|
|
276
|
+
project.appName = projectName;
|
|
277
|
+
}
|
|
278
|
+
// Note: projectPath is intentionally omitted — the agent ignores
|
|
279
|
+
// client-supplied paths on feedback reports and resolves them itself.
|
|
280
|
+
if (bundleId) project.bundleId = bundleId;
|
|
281
|
+
if (opts?.surfaces) project.surfaces = opts.surfaces;
|
|
282
|
+
if (opts?.stack) project.stack = opts.stack;
|
|
283
|
+
if (opts?.stacks) project.stacks = opts.stacks;
|
|
284
|
+
if (opts?.testSurfaces) project.testSurfaces = opts.testSurfaces;
|
|
285
|
+
if (opts?.feedbackSdk) project.feedbackSdk = opts.feedbackSdk;
|
|
286
|
+
if (opts?.feedbackTransport) project.feedbackTransport = opts.feedbackTransport;
|
|
287
|
+
if (opts?.voiceCapabilities) project.voiceCapabilities = opts.voiceCapabilities;
|
|
288
|
+
if (opts?.sttProvider) project.sttProvider = opts.sttProvider;
|
|
289
|
+
if (opts?.ttsProvider) project.ttsProvider = opts.ttsProvider;
|
|
290
|
+
|
|
291
|
+
return { appName: projectName, app, project };
|
|
292
|
+
}
|
|
293
|
+
|
|
79
294
|
/**
|
|
80
295
|
* Translate a raw Go-agent error into something a user can act on.
|
|
81
296
|
*
|
|
@@ -255,6 +470,37 @@ export class P2PClient {
|
|
|
255
470
|
return Array.isArray(data.runners) ? (data.runners as RunnerAuthStatusRow[]) : [];
|
|
256
471
|
}
|
|
257
472
|
|
|
473
|
+
/** Canonical runner + model catalogue used by Vibing routing controls. */
|
|
474
|
+
async getAvailableRunners(): Promise<RunnerAuthStatusRow[]> {
|
|
475
|
+
const resp = await fetch(`${this.baseUrl}/agent/runners`, {
|
|
476
|
+
headers: this.authHeaders(),
|
|
477
|
+
});
|
|
478
|
+
if (!resp.ok) {
|
|
479
|
+
const text = await resp.text().catch(() => '');
|
|
480
|
+
throw new Error(`getAvailableRunners HTTP ${resp.status}: ${text}`);
|
|
481
|
+
}
|
|
482
|
+
const data = await resp.json().catch(() => ({} as Record<string, unknown>));
|
|
483
|
+
return Array.isArray(data.runners) ? (data.runners as RunnerAuthStatusRow[]) : [];
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** Discovered runnable projects on the selected owner machine. Paths stay
|
|
487
|
+
* on that machine/transport; they are never registered in Yaver's backend. */
|
|
488
|
+
async listDogfoodProjects(): Promise<Array<{
|
|
489
|
+
name: string;
|
|
490
|
+
path: string;
|
|
491
|
+
framework?: string;
|
|
492
|
+
frameworks?: string[];
|
|
493
|
+
surfaces?: string[];
|
|
494
|
+
}>> {
|
|
495
|
+
const resp = await fetch(`${this.baseUrl}/projects`, { headers: this.authHeaders() });
|
|
496
|
+
if (!resp.ok) {
|
|
497
|
+
const body = await resp.text().catch(() => '');
|
|
498
|
+
throw new Error(`listDogfoodProjects HTTP ${resp.status}: ${body}`);
|
|
499
|
+
}
|
|
500
|
+
const data = await resp.json().catch(() => ({} as Record<string, unknown>));
|
|
501
|
+
return Array.isArray(data.projects) ? data.projects : [];
|
|
502
|
+
}
|
|
503
|
+
|
|
258
504
|
async getOpenCodeConfig(): Promise<OpenCodeConfigSummary | null> {
|
|
259
505
|
const resp = await fetch(`${this.baseUrl}/runner/opencode/config`, {
|
|
260
506
|
headers: this.authHeaders(),
|
|
@@ -360,19 +606,22 @@ export class P2PClient {
|
|
|
360
606
|
|
|
361
607
|
/** Health check — returns true if the agent is reachable. */
|
|
362
608
|
async health(): Promise<boolean> {
|
|
609
|
+
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
|
363
610
|
try {
|
|
364
611
|
const controller = new AbortController();
|
|
365
|
-
|
|
612
|
+
timeoutId = setTimeout(() => controller.abort(), 3000);
|
|
613
|
+
unrefTimer(timeoutId);
|
|
366
614
|
|
|
367
615
|
const response = await fetch(`${this.baseUrl}/health`, {
|
|
368
616
|
method: 'GET',
|
|
369
617
|
signal: controller.signal,
|
|
370
618
|
});
|
|
371
619
|
|
|
372
|
-
clearTimeout(timeoutId);
|
|
373
620
|
return response.ok;
|
|
374
621
|
} catch {
|
|
375
622
|
return false;
|
|
623
|
+
} finally {
|
|
624
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
376
625
|
}
|
|
377
626
|
}
|
|
378
627
|
|
|
@@ -545,6 +794,281 @@ export class P2PClient {
|
|
|
545
794
|
* via the BlackBox command channel.
|
|
546
795
|
* @param mode - "dev" for hot reload, "bundle" for native bundle rebuild
|
|
547
796
|
*/
|
|
797
|
+
/**
|
|
798
|
+
* Read the dev server's state so the overlay can decide WHICH reload
|
|
799
|
+
* actions to offer, and disable the rest with a reason.
|
|
800
|
+
*
|
|
801
|
+
* Returns null when the machine cannot be reached at all — which the
|
|
802
|
+
* caller must render as "not connected", never as "no dev server".
|
|
803
|
+
* Those are two different problems with two different fixes.
|
|
804
|
+
*/
|
|
805
|
+
async getDevServerStatus(): Promise<DevServerSnapshot | null> {
|
|
806
|
+
try {
|
|
807
|
+
const resp = await fetch(`${this.baseUrl}${AGENT_ENDPOINTS.devStatus}`, {
|
|
808
|
+
headers: this.authHeaders(),
|
|
809
|
+
});
|
|
810
|
+
if (!resp.ok) return null;
|
|
811
|
+
const data = await resp.json().catch(() => ({} as Record<string, unknown>));
|
|
812
|
+
return {
|
|
813
|
+
running: data.running === true,
|
|
814
|
+
building: data.building === true,
|
|
815
|
+
framework: typeof data.framework === 'string' ? data.framework : undefined,
|
|
816
|
+
};
|
|
817
|
+
} catch {
|
|
818
|
+
return null;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Start the ordinary Projects runtime for an embedded Dogfood host.
|
|
824
|
+
* Requires a full signed-in-user token because /dev/start can spawn tools;
|
|
825
|
+
* a narrow feedback SDK token intentionally cannot use it.
|
|
826
|
+
*/
|
|
827
|
+
async startDogfoodDevServer(input: {
|
|
828
|
+
framework: string;
|
|
829
|
+
workDir: string;
|
|
830
|
+
lane: 'browser' | 'hermes';
|
|
831
|
+
}): Promise<DogfoodDevServerStatus> {
|
|
832
|
+
if (input.lane === 'hermes') {
|
|
833
|
+
const ack = await this.reloadApp('bundle', { projectPath: input.workDir });
|
|
834
|
+
return { running: ack.ok, framework: input.framework, workDir: input.workDir };
|
|
835
|
+
}
|
|
836
|
+
const ctrl = new AbortController();
|
|
837
|
+
const timer = setTimeout(() => ctrl.abort(), 45_000);
|
|
838
|
+
unrefTimer(timer);
|
|
839
|
+
try {
|
|
840
|
+
const response = await fetch(`${this.baseUrl}/dev/start`, {
|
|
841
|
+
method: 'POST',
|
|
842
|
+
headers: this.authHeaders({ 'Content-Type': 'application/json' }),
|
|
843
|
+
body: JSON.stringify({
|
|
844
|
+
framework: input.framework,
|
|
845
|
+
workDir: input.workDir,
|
|
846
|
+
platform: 'web',
|
|
847
|
+
caller: 'sdk',
|
|
848
|
+
}),
|
|
849
|
+
signal: ctrl.signal,
|
|
850
|
+
});
|
|
851
|
+
const data = (await response.json().catch(() => ({}))) as DogfoodDevServerStatus & {
|
|
852
|
+
code?: string; remedy?: string; retryable?: boolean;
|
|
853
|
+
};
|
|
854
|
+
if (!response.ok) {
|
|
855
|
+
const error = new Error(data.error || `Dogfood preview start failed with HTTP ${response.status}`) as Error & {
|
|
856
|
+
code?: string; remedy?: string; retryable?: boolean; capabilityGap?: unknown;
|
|
857
|
+
};
|
|
858
|
+
error.code = data.code || `DOGFOOD_DEV_START_HTTP_${response.status}`;
|
|
859
|
+
error.remedy = data.remedy || 'Fix the named dev-server failure, then retry Dogfood.';
|
|
860
|
+
error.retryable = data.retryable !== false;
|
|
861
|
+
error.capabilityGap = data.capabilityGap;
|
|
862
|
+
throw error;
|
|
863
|
+
}
|
|
864
|
+
return data;
|
|
865
|
+
} finally {
|
|
866
|
+
clearTimeout(timer);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/** Full status for Dogfood startup; unlike the compact feedback snapshot,
|
|
871
|
+
* this retains render URLs and structured startup failures. */
|
|
872
|
+
async getDogfoodDevServerStatus(): Promise<DogfoodDevServerStatus | null> {
|
|
873
|
+
const ctrl = new AbortController();
|
|
874
|
+
const timer = setTimeout(() => ctrl.abort(), 10_000);
|
|
875
|
+
unrefTimer(timer);
|
|
876
|
+
try {
|
|
877
|
+
const response = await fetch(`${this.baseUrl}${AGENT_ENDPOINTS.devStatus}`, {
|
|
878
|
+
headers: this.authHeaders(),
|
|
879
|
+
signal: ctrl.signal,
|
|
880
|
+
});
|
|
881
|
+
if (!response.ok) return null;
|
|
882
|
+
return await response.json().catch(() => null) as DogfoodDevServerStatus | null;
|
|
883
|
+
} catch {
|
|
884
|
+
return null;
|
|
885
|
+
} finally {
|
|
886
|
+
clearTimeout(timer);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
async getDogfoodRemoteRuntimeCapabilities(
|
|
891
|
+
workDir: string,
|
|
892
|
+
framework: string,
|
|
893
|
+
): Promise<DogfoodRemoteRuntimeCapabilities> {
|
|
894
|
+
const query = `?workDir=${encodeURIComponent(workDir)}&framework=${encodeURIComponent(framework)}`;
|
|
895
|
+
const response = await dogfoodFetch(`${this.baseUrl}/remote-runtime/capabilities${query}`, {
|
|
896
|
+
headers: this.authHeaders(),
|
|
897
|
+
}, 20_000);
|
|
898
|
+
const data = await response.json().catch(() => ({}));
|
|
899
|
+
if (!response.ok) throw new Error(data?.error || `Remote-runtime capabilities failed with HTTP ${response.status}`);
|
|
900
|
+
return { ...data, targets: Array.isArray(data?.targets) ? data.targets : [] };
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
async startDogfoodRemoteRuntime(
|
|
904
|
+
workDir: string,
|
|
905
|
+
framework: string,
|
|
906
|
+
targetId: string,
|
|
907
|
+
): Promise<DogfoodRemoteRuntimeSession> {
|
|
908
|
+
const response = await dogfoodFetch(`${this.baseUrl}/remote-runtime/sessions`, {
|
|
909
|
+
method: 'POST',
|
|
910
|
+
headers: this.authHeaders({ 'Content-Type': 'application/json' }),
|
|
911
|
+
body: JSON.stringify({ workDir, framework, targetId, surface: 'sdk' }),
|
|
912
|
+
}, 45_000);
|
|
913
|
+
const data = await response.json().catch(() => ({}));
|
|
914
|
+
if (!response.ok) throw new Error(data?.error || `Remote-runtime start failed with HTTP ${response.status}`);
|
|
915
|
+
return data as DogfoodRemoteRuntimeSession;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
async stopDogfoodRemoteRuntime(sessionId: string): Promise<void> {
|
|
919
|
+
const response = await dogfoodFetch(`${this.baseUrl}/remote-runtime/sessions/${encodeURIComponent(sessionId)}`, {
|
|
920
|
+
method: 'DELETE', headers: this.authHeaders(),
|
|
921
|
+
}, 15_000);
|
|
922
|
+
if (!response.ok) throw new Error(`Remote-runtime stop failed with HTTP ${response.status}`);
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/** Stop the runtime this SDK host started. Full user auth, same as start. */
|
|
926
|
+
async stopDogfoodDevServer(): Promise<void> {
|
|
927
|
+
const ctrl = new AbortController();
|
|
928
|
+
const timer = setTimeout(() => ctrl.abort(), 15_000);
|
|
929
|
+
unrefTimer(timer);
|
|
930
|
+
try {
|
|
931
|
+
const response = await fetch(`${this.baseUrl}/dev/stop`, {
|
|
932
|
+
method: 'POST', headers: this.authHeaders(), signal: ctrl.signal,
|
|
933
|
+
});
|
|
934
|
+
if (!response.ok) throw new Error(`Dogfood preview stop failed with HTTP ${response.status}`);
|
|
935
|
+
} finally {
|
|
936
|
+
clearTimeout(timer);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/** Resolve an agent-reported /dev/ or /dev-web/ route without putting auth in the URL. */
|
|
941
|
+
resolveDogfoodUrl(path: string): string {
|
|
942
|
+
return new URL(path, `${this.baseUrl.replace(/\/+$/, '')}/`).toString();
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* React-Native-safe /dev/events stream. XHR is intentional: Hermes fetch
|
|
947
|
+
* exposes no streaming response body. Reconnects are bounded and every
|
|
948
|
+
* reconnect/loss is surfaced to the host console.
|
|
949
|
+
*/
|
|
950
|
+
subscribeDogfoodDevEvents(
|
|
951
|
+
onEvent: (event: DogfoodDevEvent) => void,
|
|
952
|
+
onHealth?: (health: { kind: 'reattaching' | 'lost'; message: string } | null) => void,
|
|
953
|
+
): () => void {
|
|
954
|
+
let disposed = false;
|
|
955
|
+
let xhr: XMLHttpRequest | null = null;
|
|
956
|
+
let retryTimer: ReturnType<typeof setTimeout> | null = null;
|
|
957
|
+
let attempt = 0;
|
|
958
|
+
|
|
959
|
+
const open = () => {
|
|
960
|
+
if (disposed) return;
|
|
961
|
+
const request = new XMLHttpRequest();
|
|
962
|
+
xhr = request;
|
|
963
|
+
let parsed = 0;
|
|
964
|
+
let carry = '';
|
|
965
|
+
const consume = () => {
|
|
966
|
+
const text = request.responseText || '';
|
|
967
|
+
if (text.length <= parsed) return;
|
|
968
|
+
carry += text.slice(parsed);
|
|
969
|
+
parsed = text.length;
|
|
970
|
+
const normalized = carry.replace(/\r\n/g, '\n');
|
|
971
|
+
const frames = normalized.split('\n\n');
|
|
972
|
+
carry = frames.pop() || '';
|
|
973
|
+
for (const frame of frames) {
|
|
974
|
+
const data = frame.split('\n')
|
|
975
|
+
.filter((line) => line.startsWith('data:'))
|
|
976
|
+
.map((line) => line.slice(5).replace(/^ /, ''))
|
|
977
|
+
.join('\n');
|
|
978
|
+
if (!data) continue;
|
|
979
|
+
try {
|
|
980
|
+
attempt = 0;
|
|
981
|
+
onHealth?.(null);
|
|
982
|
+
onEvent(JSON.parse(data));
|
|
983
|
+
} catch { /* comments and non-JSON keepalives are valid SSE */ }
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
const reconnect = (reason: string) => {
|
|
987
|
+
if (disposed) return;
|
|
988
|
+
if (attempt >= 5) {
|
|
989
|
+
onHealth?.({ kind: 'lost', message: `Dev-server logs stopped: ${reason}` });
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
const wait = Math.min(8_000, 500 * (2 ** attempt));
|
|
993
|
+
attempt += 1;
|
|
994
|
+
onHealth?.({ kind: 'reattaching', message: `Dev-server logs interrupted; reconnecting (${attempt}/5): ${reason}` });
|
|
995
|
+
retryTimer = setTimeout(open, wait);
|
|
996
|
+
unrefTimer(retryTimer);
|
|
997
|
+
};
|
|
998
|
+
request.open('GET', `${this.baseUrl}/dev/events`, true);
|
|
999
|
+
for (const [key, value] of Object.entries(this.authHeaders({ Accept: 'text/event-stream' }))) {
|
|
1000
|
+
try { request.setRequestHeader(key, value); } catch { /* restricted RN header */ }
|
|
1001
|
+
}
|
|
1002
|
+
request.onprogress = consume;
|
|
1003
|
+
request.onload = () => { consume(); reconnect(`HTTP ${request.status || 0}`); };
|
|
1004
|
+
request.onerror = () => reconnect('connection failed');
|
|
1005
|
+
request.onabort = () => reconnect('connection aborted');
|
|
1006
|
+
request.ontimeout = () => reconnect('connection timed out');
|
|
1007
|
+
try {
|
|
1008
|
+
request.send();
|
|
1009
|
+
} catch (error) {
|
|
1010
|
+
reconnect(error instanceof Error ? error.message : 'connection could not start');
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
open();
|
|
1014
|
+
return () => {
|
|
1015
|
+
disposed = true;
|
|
1016
|
+
if (retryTimer) clearTimeout(retryTimer);
|
|
1017
|
+
try { xhr?.abort(); } catch { /* idempotent */ }
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Trigger a reload with an EXPLICIT fast/full mode — no bundle fallback.
|
|
1023
|
+
*
|
|
1024
|
+
* `reloadApp('dev')` silently falls through to a bundle rebuild when the
|
|
1025
|
+
* dev server is down, which is right for a one-button UX and wrong the
|
|
1026
|
+
* moment the user picks between two named actions: someone who pressed
|
|
1027
|
+
* "Full Reload" must not get a 60-second bundle rebuild without being
|
|
1028
|
+
* told. So this method reports the failure instead, with a named cause.
|
|
1029
|
+
*
|
|
1030
|
+
* Auth: the SAME bearer used for the feedback POST. `/dev/reload` is
|
|
1031
|
+
* registered under `authSDK` in desktop/agent/httpserver.go and is already
|
|
1032
|
+
* in the `reload` SDK-token scope list — nothing widens.
|
|
1033
|
+
*/
|
|
1034
|
+
async reloadWithMode(
|
|
1035
|
+
mode: ReloadWireMode,
|
|
1036
|
+
snapshot?: DevServerSnapshot | null,
|
|
1037
|
+
): Promise<ReloadAck> {
|
|
1038
|
+
if (mode === 'bundle') return this.reloadApp('bundle');
|
|
1039
|
+
|
|
1040
|
+
let resp: Response;
|
|
1041
|
+
try {
|
|
1042
|
+
resp = await fetch(`${this.baseUrl}${RELOAD_PATH}`, {
|
|
1043
|
+
method: 'POST',
|
|
1044
|
+
headers: this.authHeaders({ 'Content-Type': 'application/json' }),
|
|
1045
|
+
body: JSON.stringify({ mode }),
|
|
1046
|
+
});
|
|
1047
|
+
} catch (err) {
|
|
1048
|
+
throw new Error(
|
|
1049
|
+
describeReloadFailure(0, err instanceof Error ? err.message : '', snapshot),
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
if (!resp.ok) {
|
|
1053
|
+
const text = await resp.text().catch(() => '');
|
|
1054
|
+
throw new Error(describeReloadFailure(resp.status, text, snapshot));
|
|
1055
|
+
}
|
|
1056
|
+
const payload = await resp.json().catch(() => ({} as Record<string, unknown>));
|
|
1057
|
+
const nativeChangesDetected = payload.nativeChangesDetected === true;
|
|
1058
|
+
return {
|
|
1059
|
+
ok: true,
|
|
1060
|
+
mode: 'dev',
|
|
1061
|
+
acknowledged: true,
|
|
1062
|
+
nativeChangesDetected,
|
|
1063
|
+
changeClass: typeof payload.changeClass === 'string' ? payload.changeClass : undefined,
|
|
1064
|
+
message: nativeChangesDetected
|
|
1065
|
+
? 'Reload accepted, but native files changed — a rebuild is required.'
|
|
1066
|
+
: mode === 'full'
|
|
1067
|
+
? 'Full reload requested.'
|
|
1068
|
+
: 'Hot reload requested.',
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
|
|
548
1072
|
async reloadApp(
|
|
549
1073
|
mode: 'dev' | 'bundle' = 'bundle',
|
|
550
1074
|
opts?: { projectName?: string; bundleId?: string; projectPath?: string },
|
|
@@ -631,14 +1155,14 @@ export class P2PClient {
|
|
|
631
1155
|
* the project context plus the user's prompt. Returns the task id the
|
|
632
1156
|
* caller can poll via `/tasks/{id}` if needed.
|
|
633
1157
|
*
|
|
634
|
-
* Requires an owner/CLI
|
|
1158
|
+
* Requires an owner/CLI token — the `/vibing*` routes do not
|
|
635
1159
|
* currently accept SDK-minted tokens. Power users typically drive
|
|
636
1160
|
* vibing from Claude Code / the Yaver mobile app; this method is a
|
|
637
1161
|
* convenience for the SDK's one-tap bug-report-to-vibing path.
|
|
638
1162
|
*/
|
|
639
1163
|
async vibing(
|
|
640
1164
|
prompt: string,
|
|
641
|
-
opts?: { projectName?: string; bundleId?: string; projectPath?: string },
|
|
1165
|
+
opts?: { projectName?: string; bundleId?: string; projectPath?: string; runner?: string; model?: string },
|
|
642
1166
|
): Promise<{ taskId: string }> {
|
|
643
1167
|
// Resolve app identity exactly the same way we do for
|
|
644
1168
|
// reloadApp — bundle ID from expo-constants or native config.
|
|
@@ -656,6 +1180,8 @@ export class P2PClient {
|
|
|
656
1180
|
projectPath: identity.projectPath ?? opts?.projectPath ?? '',
|
|
657
1181
|
projectName: identity.projectName,
|
|
658
1182
|
bundleId: identity.bundleId,
|
|
1183
|
+
runner: opts?.runner,
|
|
1184
|
+
model: opts?.model,
|
|
659
1185
|
}),
|
|
660
1186
|
});
|
|
661
1187
|
if (!response.ok) {
|
|
@@ -956,6 +1482,56 @@ export class P2PClient {
|
|
|
956
1482
|
return { taskId: json.taskId, raw: json };
|
|
957
1483
|
}
|
|
958
1484
|
|
|
1485
|
+
/** Existing task history, filtered by the agent to Vibing/feedback topics. */
|
|
1486
|
+
async listVibeThreads(input?: { projectName?: string; projectPath?: string }): Promise<Array<{
|
|
1487
|
+
id: string;
|
|
1488
|
+
title: string;
|
|
1489
|
+
status: string;
|
|
1490
|
+
createdAt?: string;
|
|
1491
|
+
projectName?: string;
|
|
1492
|
+
turnCount?: number;
|
|
1493
|
+
}>> {
|
|
1494
|
+
const params = new URLSearchParams();
|
|
1495
|
+
if (input?.projectName) params.set('projectName', input.projectName);
|
|
1496
|
+
if (input?.projectPath) params.set('projectPath', input.projectPath);
|
|
1497
|
+
const query = params.toString();
|
|
1498
|
+
const resp = await fetch(`${this.baseUrl}/vibing/tasks${query ? `?${query}` : ''}`, {
|
|
1499
|
+
headers: this.authHeaders(),
|
|
1500
|
+
});
|
|
1501
|
+
if (!resp.ok) throw new Error(`listVibeThreads HTTP ${resp.status}`);
|
|
1502
|
+
const json = (await resp.json().catch(() => ({}))) as { tasks?: Array<any> };
|
|
1503
|
+
return (json.tasks || []).map((task) => ({
|
|
1504
|
+
id: String(task.id),
|
|
1505
|
+
title: String(task.title || 'New topic'),
|
|
1506
|
+
status: String(task.status || 'completed'),
|
|
1507
|
+
createdAt: task.createdAt,
|
|
1508
|
+
projectName: task.projectName,
|
|
1509
|
+
turnCount: task.turnCount,
|
|
1510
|
+
}));
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
async getVibeThread(taskId: string): Promise<{
|
|
1514
|
+
id: string;
|
|
1515
|
+
title: string;
|
|
1516
|
+
status: string;
|
|
1517
|
+
turns?: Array<{ role: 'user' | 'assistant'; content: string; timestamp?: string }>;
|
|
1518
|
+
}> {
|
|
1519
|
+
const resp = await fetch(`${this.baseUrl}/vibing/task/${encodeURIComponent(taskId)}`, {
|
|
1520
|
+
headers: this.authHeaders(),
|
|
1521
|
+
});
|
|
1522
|
+
if (!resp.ok) throw new Error(`getVibeThread HTTP ${resp.status}`);
|
|
1523
|
+
const json = (await resp.json().catch(() => ({}))) as { task?: any };
|
|
1524
|
+
return json.task || json as any;
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
async deleteVibeThread(taskId: string): Promise<void> {
|
|
1528
|
+
const resp = await fetch(`${this.baseUrl}/vibing/task/${encodeURIComponent(taskId)}`, {
|
|
1529
|
+
method: 'DELETE',
|
|
1530
|
+
headers: this.authHeaders(),
|
|
1531
|
+
});
|
|
1532
|
+
if (!resp.ok) throw new Error(`deleteVibeThread HTTP ${resp.status}`);
|
|
1533
|
+
}
|
|
1534
|
+
|
|
959
1535
|
/**
|
|
960
1536
|
* Subscribe to a task's live stdout/stderr stream. Returns an abort
|
|
961
1537
|
* function — call it to detach. The agent emits NDJSON lines on
|