playcanvas-agent-bridge-cli 0.6.2 → 0.7.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.
@@ -0,0 +1,475 @@
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
4
+ import { homedir } from "node:os";
5
+ import { join, resolve } from "node:path";
6
+ import { randomUUID } from "node:crypto";
7
+ import { compareSemver, CONFIG_DIR, EXTENSION_INSTALL_DIR, findPackageRoot, INSTALLED_SKILLS_FILE, PACKAGE_NAME, UPDATE_STATE_FILE, VERSION, } from "./config.js";
8
+ import { PluginStore, } from "./plugins/store.js";
9
+ export const UPDATE_CACHE_TTL_MS = 60 * 60 * 1000;
10
+ export async function detectInstallKind(packageRoot) {
11
+ const mocked = process.env.PCBRIDGE_UPDATE_MOCK_INSTALL_KIND;
12
+ if (mocked === "source" ||
13
+ mocked === "bun-global" ||
14
+ mocked === "npm-global" ||
15
+ mocked === "pnpm-global") {
16
+ return mocked;
17
+ }
18
+ try {
19
+ const root = packageRoot || (await findPackageRoot());
20
+ if (existsSync(join(root, ".git"))) {
21
+ return "source";
22
+ }
23
+ const normalized = root.replaceAll("\\", "/");
24
+ if (normalized.includes("/.bun/") || normalized.includes("/bun/install/global")) {
25
+ return "bun-global";
26
+ }
27
+ if (normalized.includes("/pnpm")) {
28
+ return "pnpm-global";
29
+ }
30
+ if (normalized.includes("/node_modules/")) {
31
+ return process.versions.bun ? "bun-global" : "npm-global";
32
+ }
33
+ }
34
+ catch {
35
+ // Fall through to default below.
36
+ }
37
+ return "bun-global";
38
+ }
39
+ export function globalInstallCommand(installKind, targetVersion = "latest") {
40
+ const spec = `${PACKAGE_NAME}@${targetVersion}`;
41
+ if (installKind === "pnpm-global") {
42
+ return {
43
+ command: "pnpm",
44
+ args: ["add", "--global", spec],
45
+ display: `pnpm add --global ${spec}`,
46
+ };
47
+ }
48
+ if (installKind === "npm-global") {
49
+ return {
50
+ command: "npm",
51
+ args: ["install", "--global", spec],
52
+ display: `npm install --global ${spec}`,
53
+ };
54
+ }
55
+ return {
56
+ command: process.execPath,
57
+ args: ["add", "--global", spec],
58
+ display: `bun add --global ${spec}`,
59
+ };
60
+ }
61
+ export async function readGeneratedExtensionVersion(extensionDir = EXTENSION_INSTALL_DIR) {
62
+ try {
63
+ const manifest = JSON.parse(await readFile(join(extensionDir, "manifest.json"), "utf8"));
64
+ return typeof manifest.version === "string" ? manifest.version : null;
65
+ }
66
+ catch {
67
+ return null;
68
+ }
69
+ }
70
+ export async function readCachedUpdateState(stateFile = UPDATE_STATE_FILE) {
71
+ try {
72
+ const parsed = JSON.parse(await readFile(stateFile, "utf8"));
73
+ if (parsed && parsed.schemaVersion === 1 && typeof parsed.checkedAt === "string") {
74
+ return {
75
+ schemaVersion: 1,
76
+ checkedAt: parsed.checkedAt,
77
+ latestCoreVersion: typeof parsed.latestCoreVersion === "string" ? parsed.latestCoreVersion : null,
78
+ officialCatalog: Array.isArray(parsed.officialCatalog) ? parsed.officialCatalog : [],
79
+ };
80
+ }
81
+ }
82
+ catch {
83
+ // Ignore missing or invalid cache.
84
+ }
85
+ return null;
86
+ }
87
+ export async function writeCachedUpdateState(state, stateFile = UPDATE_STATE_FILE) {
88
+ const dir = resolve(stateFile, "..");
89
+ await mkdir(dir, { recursive: true });
90
+ const tempFile = `${stateFile}.${process.pid}.${randomUUID()}.tmp`;
91
+ await writeFile(tempFile, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600 });
92
+ await rename(tempFile, stateFile);
93
+ }
94
+ export async function fetchLatestNpmVersion(fetchImpl = fetch) {
95
+ const url = process.env.PCBRIDGE_NPM_LATEST_URL !== undefined
96
+ ? process.env.PCBRIDGE_NPM_LATEST_URL
97
+ : `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
98
+ if (!url)
99
+ return null;
100
+ try {
101
+ const response = await fetchImpl(url, {
102
+ headers: {
103
+ Accept: "application/vnd.npm.install-v1+json, application/json",
104
+ "User-Agent": `${PACKAGE_NAME}/${VERSION}`,
105
+ },
106
+ signal: AbortSignal.timeout(5000),
107
+ });
108
+ if (!response.ok)
109
+ return null;
110
+ const parsed = (await response.json());
111
+ if (typeof parsed.version === "string" && /^\d+\.\d+\.\d+/.test(parsed.version)) {
112
+ return parsed.version;
113
+ }
114
+ }
115
+ catch {
116
+ // Offline or unreachable registry degrades gracefully.
117
+ }
118
+ return null;
119
+ }
120
+ export async function getUpdateReport(options = {}) {
121
+ const configDir = options.configDir || CONFIG_DIR;
122
+ const stateFile = join(configDir, "update-state.json");
123
+ const extensionDir = join(configDir, "extension");
124
+ const fetchImpl = options.fetch || fetch;
125
+ const store = options.store ||
126
+ new PluginStore(join(configDir, "plugins"), { fetch: fetchImpl });
127
+ let cached = await readCachedUpdateState(stateFile);
128
+ const cacheAge = cached?.checkedAt ? Date.now() - Date.parse(cached.checkedAt) : Infinity;
129
+ const shouldFetch = options.allowNetwork !== false &&
130
+ (options.refresh === true || !cached || Number.isNaN(cacheAge) || cacheAge > UPDATE_CACHE_TTL_MS);
131
+ if (shouldFetch) {
132
+ const [latestCoreVersion, catalogMap] = await Promise.all([
133
+ fetchLatestNpmVersion(fetchImpl),
134
+ store.catalog({ refresh: true }),
135
+ ]);
136
+ cached = {
137
+ schemaVersion: 1,
138
+ checkedAt: new Date().toISOString(),
139
+ latestCoreVersion: latestCoreVersion || cached?.latestCoreVersion || null,
140
+ officialCatalog: [...catalogMap.values()],
141
+ };
142
+ await writeCachedUpdateState(cached, stateFile).catch(() => undefined);
143
+ }
144
+ const [installKind, generatedExtensionVersion, summaries, availableOfficialPlugins] = await Promise.all([
145
+ detectInstallKind(),
146
+ readGeneratedExtensionVersion(extensionDir),
147
+ store.summaries({ refresh: false }),
148
+ store.available({ refresh: false }),
149
+ ]);
150
+ const currentVersion = VERSION;
151
+ const latestVersion = cached?.latestCoreVersion || null;
152
+ const updateAvailable = Boolean(latestVersion && compareSemver(latestVersion, currentVersion) > 0);
153
+ const targetCoreVersion = updateAvailable && latestVersion ? latestVersion : currentVersion;
154
+ const daemonVersion = options.daemonVersion ?? null;
155
+ const daemonRestartRequired = Boolean(daemonVersion && daemonVersion !== targetCoreVersion);
156
+ const extensionRegenerateRequired = Boolean(generatedExtensionVersion && generatedExtensionVersion !== targetCoreVersion);
157
+ const connectedExtensionVersions = (options.connectedExtensionVersions || []).filter(Boolean);
158
+ const mismatchedConnected = connectedExtensionVersions.filter((ver) => ver !== targetCoreVersion);
159
+ const extensionReloadRequired = extensionRegenerateRequired || mismatchedConnected.length > 0;
160
+ const tabRefreshRequired = mismatchedConnected.length > 0;
161
+ const coreNeedsAttention = updateAvailable ||
162
+ daemonRestartRequired ||
163
+ extensionRegenerateRequired ||
164
+ extensionReloadRequired;
165
+ const plugins = summaries.map((item) => ({
166
+ id: item.id,
167
+ name: item.name,
168
+ enabled: item.enabled,
169
+ currentVersion: item.version,
170
+ latestVersion: item.latestVersion,
171
+ updateAvailable: item.updateAvailable,
172
+ compatible: item.compatible,
173
+ minPcbridgeVersion: item.minPcbridgeVersion,
174
+ sourceType: item.source.type,
175
+ command: `pcbridge plugin update ${item.id}`,
176
+ }));
177
+ const outdatedPlugins = plugins.filter((item) => item.updateAvailable);
178
+ const nextActions = [];
179
+ if (updateAvailable) {
180
+ if (installKind === "source") {
181
+ nextActions.push(`pcbridge v${latestVersion} is available on npm (running from source checkout v${currentVersion}). Pull latest git changes and run bun run build.`);
182
+ }
183
+ else {
184
+ nextActions.push(`Run pcbridge update to upgrade CLI, daemon, skills, and Chrome extension from v${currentVersion} to v${latestVersion}.`);
185
+ }
186
+ }
187
+ else if (daemonRestartRequired || extensionReloadRequired) {
188
+ nextActions.push("Run pcbridge update to synchronize the local daemon, unpacked Chrome extension, and open PlayCanvas tabs.");
189
+ }
190
+ if (outdatedPlugins.length === 1) {
191
+ const item = outdatedPlugins[0];
192
+ if (item.compatible) {
193
+ nextActions.push(`Run pcbridge plugin update ${item.id} to upgrade ${item.name} from v${item.currentVersion} to v${item.latestVersion}.`);
194
+ }
195
+ else {
196
+ nextActions.push(`Plugin ${item.id} v${item.latestVersion} requires pcbridge v${item.minPcbridgeVersion}+; run pcbridge update first.`);
197
+ }
198
+ }
199
+ else if (outdatedPlugins.length > 1) {
200
+ nextActions.push(`Run pcbridge plugin update --all to upgrade ${outdatedPlugins.length} outdated plugins (${outdatedPlugins.map((p) => p.id).join(", ")}).`);
201
+ }
202
+ return {
203
+ checkedAt: cached?.checkedAt || null,
204
+ hasUpdates: coreNeedsAttention || outdatedPlugins.length > 0,
205
+ core: {
206
+ currentVersion,
207
+ latestVersion,
208
+ updateAvailable,
209
+ installKind,
210
+ canSelfUpdate: installKind !== "source",
211
+ daemonVersion,
212
+ daemonRestartRequired,
213
+ generatedExtensionVersion,
214
+ extensionRegenerateRequired,
215
+ connectedExtensionVersions,
216
+ extensionReloadRequired,
217
+ tabRefreshRequired,
218
+ command: "pcbridge update",
219
+ },
220
+ plugins,
221
+ availableOfficialPlugins,
222
+ nextActions,
223
+ };
224
+ }
225
+ export function compactUpdatesMeta(report) {
226
+ if (!report.hasUpdates)
227
+ return null;
228
+ const outdatedPlugins = report.plugins.filter((item) => item.updateAvailable);
229
+ const coreNeedsAction = report.core.updateAvailable ||
230
+ report.core.daemonRestartRequired ||
231
+ report.core.extensionReloadRequired;
232
+ const result = {};
233
+ if (coreNeedsAction) {
234
+ result.pcbridge = {
235
+ currentVersion: report.core.currentVersion,
236
+ latestVersion: report.core.latestVersion,
237
+ updateAvailable: report.core.updateAvailable,
238
+ daemonVersion: report.core.daemonVersion,
239
+ daemonRestartRequired: report.core.daemonRestartRequired,
240
+ extensionReloadRequired: report.core.extensionReloadRequired,
241
+ tabRefreshRequired: report.core.tabRefreshRequired,
242
+ command: report.core.command,
243
+ };
244
+ }
245
+ if (outdatedPlugins.length > 0) {
246
+ result.plugins = outdatedPlugins.map((item) => ({
247
+ id: item.id,
248
+ name: item.name,
249
+ currentVersion: item.currentVersion,
250
+ latestVersion: item.latestVersion,
251
+ compatible: item.compatible,
252
+ minPcbridgeVersion: item.minPcbridgeVersion,
253
+ command: item.command,
254
+ }));
255
+ }
256
+ if (report.nextActions.length > 0) {
257
+ result.nextActions = report.nextActions;
258
+ }
259
+ return Object.keys(result).length > 0 ? result : null;
260
+ }
261
+ export function formatHumanUpdateHint(report) {
262
+ if (!report.hasUpdates)
263
+ return null;
264
+ const parts = [];
265
+ if (report.core.updateAvailable && report.core.latestVersion) {
266
+ parts.push(`pcbridge v${report.core.currentVersion} -> v${report.core.latestVersion}`);
267
+ }
268
+ else if (report.core.daemonRestartRequired || report.core.extensionReloadRequired) {
269
+ parts.push(`pcbridge local components out of sync (v${report.core.currentVersion})`);
270
+ }
271
+ for (const plugin of report.plugins) {
272
+ if (plugin.updateAvailable && plugin.latestVersion) {
273
+ parts.push(`plugin ${plugin.id} v${plugin.currentVersion} -> v${plugin.latestVersion}`);
274
+ }
275
+ }
276
+ if (parts.length === 0)
277
+ return null;
278
+ const cmd = report.core.updateAvailable ||
279
+ report.core.daemonRestartRequired ||
280
+ report.core.extensionReloadRequired
281
+ ? report.plugins.some((p) => p.updateAvailable)
282
+ ? "pcbridge update --plugins"
283
+ : "pcbridge update"
284
+ : report.plugins.filter((p) => p.updateAvailable).length > 1
285
+ ? "pcbridge plugin update --all"
286
+ : `pcbridge plugin update ${report.plugins.find((p) => p.updateAvailable).id}`;
287
+ return `[pcbridge] Update available: ${parts.join(", ")}. Run: ${cmd}`;
288
+ }
289
+ export async function recordInstalledSkills(targets, skillsFile = INSTALLED_SKILLS_FILE) {
290
+ const existing = await readRecordedSkills(skillsFile);
291
+ const map = new Map();
292
+ for (const item of [...existing, ...targets]) {
293
+ const key = `${item.agent}:${item.customParent || ""}`;
294
+ map.set(key, item);
295
+ }
296
+ await mkdir(resolve(skillsFile, ".."), { recursive: true });
297
+ await writeFile(skillsFile, `${JSON.stringify({ version: 1, targets: [...map.values()] }, null, 2)}\n`, { mode: 0o600 });
298
+ }
299
+ export async function readRecordedSkills(skillsFile = INSTALLED_SKILLS_FILE) {
300
+ try {
301
+ const parsed = JSON.parse(await readFile(skillsFile, "utf8"));
302
+ if (Array.isArray(parsed.targets)) {
303
+ return parsed.targets.filter((item) => Boolean(item &&
304
+ ["codex", "claude", "cursor", "windsurf"].includes(item.agent) &&
305
+ (item.customParent === null || typeof item.customParent === "string")));
306
+ }
307
+ }
308
+ catch {
309
+ // Ignore missing file.
310
+ }
311
+ return [];
312
+ }
313
+ export async function detectInstalledSkills(skillsFile = INSTALLED_SKILLS_FILE) {
314
+ const recorded = await readRecordedSkills(skillsFile);
315
+ const map = new Map();
316
+ for (const item of recorded) {
317
+ if (!item.customParent || existsSync(item.customParent)) {
318
+ map.set(`${item.agent}:${item.customParent || ""}`, item);
319
+ }
320
+ }
321
+ if (process.env.PCBRIDGE_SKIP_HOME_SKILL_PROBE !== "1") {
322
+ const defaults = [
323
+ {
324
+ agent: "codex",
325
+ checkPath: join(process.env.CODEX_HOME || join(homedir(), ".codex"), "skills", "playcanvas-agent-bridge-cli"),
326
+ },
327
+ {
328
+ agent: "claude",
329
+ checkPath: join(homedir(), ".claude", "skills", "playcanvas-agent-bridge-cli"),
330
+ },
331
+ {
332
+ agent: "cursor",
333
+ checkPath: join(homedir(), ".cursor", "rules", "playcanvas-agent-bridge-cli.mdc"),
334
+ },
335
+ {
336
+ agent: "windsurf",
337
+ checkPath: join(homedir(), ".windsurf", "rules", "playcanvas-agent-bridge-cli.md"),
338
+ },
339
+ ];
340
+ for (const candidate of defaults) {
341
+ if (existsSync(candidate.checkPath)) {
342
+ map.set(`${candidate.agent}:`, { agent: candidate.agent, customParent: null });
343
+ }
344
+ }
345
+ }
346
+ return [...map.values()];
347
+ }
348
+ function runCommand(command, args, env = process.env) {
349
+ return new Promise((resolveRun, rejectRun) => {
350
+ const child = spawn(command, args, {
351
+ env,
352
+ stdio: ["ignore", "pipe", "pipe"],
353
+ });
354
+ let stdout = "";
355
+ let stderr = "";
356
+ child.stdout.setEncoding("utf8");
357
+ child.stderr.setEncoding("utf8");
358
+ child.stdout.on("data", (chunk) => {
359
+ stdout = `${stdout}${chunk}`.slice(-4000);
360
+ });
361
+ child.stderr.on("data", (chunk) => {
362
+ stderr = `${stderr}${chunk}`.slice(-4000);
363
+ });
364
+ child.once("error", rejectRun);
365
+ child.once("close", (code) => {
366
+ resolveRun({ code: code ?? 1, stdout: stdout.trim(), stderr: stderr.trim() });
367
+ });
368
+ });
369
+ }
370
+ export async function executeOneClickUpdate(options = {}) {
371
+ const configDir = options.configDir || CONFIG_DIR;
372
+ const store = options.store ||
373
+ new PluginStore(join(configDir, "plugins"), { fetch: options.fetch });
374
+ const reloadTabs = options.reloadTabs !== false;
375
+ const before = await getUpdateReport({
376
+ refresh: true,
377
+ configDir,
378
+ store,
379
+ daemonVersion: options.daemonVersion,
380
+ connectedExtensionVersions: options.connectedExtensionVersions,
381
+ fetch: options.fetch,
382
+ });
383
+ let packageUpdated = false;
384
+ if (before.core.updateAvailable && before.core.canSelfUpdate) {
385
+ const targetVersion = before.core.latestVersion || "latest";
386
+ const customCmd = process.env.PCBRIDGE_UPDATE_INSTALL_CMD;
387
+ const installResult = customCmd
388
+ ? await runCommand(process.platform === "win32" ? "cmd" : "sh", process.platform === "win32" ? ["/c", customCmd] : ["-c", customCmd], { ...process.env, PCBRIDGE_TARGET_VERSION: targetVersion, PCBRIDGE_CONFIG_DIR: configDir })
389
+ : await (() => {
390
+ const spec = globalInstallCommand(before.core.installKind, targetVersion);
391
+ return runCommand(spec.command, spec.args, {
392
+ ...process.env,
393
+ PCBRIDGE_CONFIG_DIR: configDir,
394
+ });
395
+ })();
396
+ if (installResult.code !== 0) {
397
+ throw Object.assign(new Error(`Global package update failed (exit ${installResult.code}): ${installResult.stderr || installResult.stdout || "unknown error"}`), { code: "UPDATE_INSTALL_FAILED" });
398
+ }
399
+ packageUpdated = true;
400
+ }
401
+ const cliEntry = process.env.PCBRIDGE_UPDATE_CLI_PATH ||
402
+ (process.argv[1] && existsSync(process.argv[1])
403
+ ? process.argv[1]
404
+ : join(await findPackageRoot(), "dist", "cli.js"));
405
+ const childEnv = { ...process.env, PCBRIDGE_CONFIG_DIR: configDir };
406
+ const extRun = await runCommand(process.execPath, [cliEntry, "install-extension", "--no-open"], childEnv);
407
+ if (extRun.code !== 0) {
408
+ throw Object.assign(new Error(`Extension directory update failed: ${extRun.stderr || extRun.stdout}`), { code: "EXTENSION_UPDATE_FAILED" });
409
+ }
410
+ let skillsRefreshed = 0;
411
+ const skillRun = await runCommand(process.execPath, [cliEntry, "install-skill", "--refresh-installed"], childEnv);
412
+ if (skillRun.code === 0 && skillRun.stdout) {
413
+ try {
414
+ const parsed = JSON.parse(skillRun.stdout);
415
+ if (parsed.ok && Array.isArray(parsed.data)) {
416
+ skillsRefreshed = parsed.data.length;
417
+ }
418
+ }
419
+ catch {
420
+ // Ignore non-JSON output.
421
+ }
422
+ }
423
+ let pluginsUpdated = null;
424
+ if (options.includePlugins) {
425
+ pluginsUpdated = options.updatePlugins
426
+ ? await options.updatePlugins()
427
+ : await store.updateAll();
428
+ }
429
+ const extensionPath = join(configDir, "extension");
430
+ const extensionVersion = await readGeneratedExtensionVersion(extensionPath);
431
+ const effectiveVersion = extensionVersion ||
432
+ (packageUpdated && before.core.latestVersion
433
+ ? before.core.latestVersion
434
+ : before.core.currentVersion);
435
+ let extensionReloadTriggered = false;
436
+ if (options.reloadConnectedExtension &&
437
+ (packageUpdated ||
438
+ before.core.extensionReloadRequired ||
439
+ before.core.connectedExtensionVersions.some((v) => v !== effectiveVersion))) {
440
+ extensionReloadTriggered = await options
441
+ .reloadConnectedExtension(reloadTabs)
442
+ .catch(() => false);
443
+ }
444
+ let daemonRestartTriggered = false;
445
+ if (options.restartDaemon &&
446
+ options.daemonVersion &&
447
+ (packageUpdated || options.daemonVersion !== effectiveVersion)) {
448
+ daemonRestartTriggered = await options.restartDaemon().catch(() => false);
449
+ }
450
+ const nextActions = [];
451
+ if (before.core.updateAvailable && !before.core.canSelfUpdate) {
452
+ nextActions.push(`pcbridge is running from a git checkout (v${before.core.currentVersion}); pull latest git commits and run bun run build to update source to v${before.core.latestVersion}.`);
453
+ }
454
+ if (!extensionReloadTriggered && before.core.connectedExtensionVersions.length === 0) {
455
+ nextActions.push("Open or refresh a PlayCanvas Editor/Launch tab in Chrome; if the extension was not loaded yet, load ~/.pcbridge/extension in chrome://extensions.");
456
+ }
457
+ else if (extensionReloadTriggered && !reloadTabs) {
458
+ nextActions.push("Refresh open PlayCanvas Editor and Launch tabs to attach the reloaded extension.");
459
+ }
460
+ return {
461
+ previousVersion: before.core.currentVersion,
462
+ version: effectiveVersion,
463
+ latestVersion: before.core.latestVersion,
464
+ installKind: before.core.installKind,
465
+ packageUpdated,
466
+ extensionPath,
467
+ extensionVersion,
468
+ extensionReloadTriggered,
469
+ tabsReloadRequested: reloadTabs,
470
+ skillsRefreshed,
471
+ daemonRestartTriggered,
472
+ pluginsUpdated,
473
+ nextActions,
474
+ };
475
+ }
@@ -145,11 +145,10 @@
145
145
 
146
146
  async function callDaemon(path, method, body) {
147
147
  const allowed =
148
- (path === "/builder/jobs" && method === "POST") ||
148
+ (/^\/plugins\/[a-z0-9-]+\/actions\/[\w.-]+$/.test(path) && method === "POST") ||
149
149
  (path === "/workspace/sync" && method === "POST") ||
150
150
  (path === "/workspace/settings" && (method === "GET" || method === "POST")) ||
151
- (/^\/processing\/(capabilities|begin|chunk|run|status|read|cancel|finish)$/.test(path) && method === "POST") ||
152
- (/^\/builder\/jobs\/[^/]+$/.test(path) && method === "GET");
151
+ (/^\/processing\/(capabilities|begin|chunk|run|status|read|cancel|finish)$/.test(path) && method === "POST");
153
152
  if (!allowed) throw new Error("Unsupported pcbridge browser request.");
154
153
  const payload = body && typeof body === "object" ? { ...body } : {};
155
154
  if (method === "POST" && !payload.target && Number.isInteger(tabInfo.tabId)) {
@@ -422,6 +421,16 @@
422
421
  throw new Error((data && data.error) || "Could not focus the PlayCanvas tab.");
423
422
  }
424
423
  response = { data, meta: {} };
424
+ } else if (message.method === "bridge:reloadExtension") {
425
+ const reloadTabs = !message.params || message.params.reloadTabs !== false;
426
+ const data = await requestRuntime({
427
+ type: "pcbridge:reloadExtension",
428
+ reloadTabs
429
+ });
430
+ if (!data || !data.ok) {
431
+ throw new Error((data && data.error) || "Could not reload the Chrome extension.");
432
+ }
433
+ response = { data, meta: {} };
425
434
  } else {
426
435
  response = await callMain(message.method, message.params || {}, message.timeoutMs);
427
436
  }