playcanvas-agent-bridge-cli 0.6.1 → 0.6.2

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.
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,6 +1,9 @@
1
1
  (() => {
2
2
  "use strict";
3
3
 
4
+ if (window.__pcbridgeIsolatedWorld) return;
5
+ window.__pcbridgeIsolatedWorld = true;
6
+
4
7
  const CHANNEL = "playcanvas-agent-bridge";
5
8
  const DEFAULT_CONFIG = {
6
9
  host: "127.0.0.1",
@@ -144,6 +147,8 @@
144
147
  const allowed =
145
148
  (path === "/builder/jobs" && method === "POST") ||
146
149
  (path === "/workspace/sync" && method === "POST") ||
150
+ (path === "/workspace/settings" && (method === "GET" || method === "POST")) ||
151
+ (/^\/processing\/(capabilities|begin|chunk|run|status|read|cancel|finish)$/.test(path) && method === "POST") ||
147
152
  (/^\/builder\/jobs\/[^/]+$/.test(path) && method === "GET");
148
153
  if (!allowed) throw new Error("Unsupported pcbridge browser request.");
149
154
  const payload = body && typeof body === "object" ? { ...body } : {};
@@ -203,6 +208,22 @@
203
208
  return;
204
209
  }
205
210
 
211
+ if (message.type === "workspace-delta" && message.delta) {
212
+ if (!stopped && ws && ws.readyState === WebSocket.OPEN) {
213
+ try {
214
+ ws.send(JSON.stringify({
215
+ type: "workspace:delta",
216
+ clientId,
217
+ tabId: tabInfo.tabId,
218
+ delta: message.delta
219
+ }));
220
+ } catch {
221
+ // Reconnect loop handles broken sockets.
222
+ }
223
+ }
224
+ return;
225
+ }
226
+
206
227
  if (message.type === "ready") {
207
228
  sendTargetUpdate().catch((error) => {
208
229
  if (isExtensionContextInvalidated(error)) stopBridge();
@@ -267,7 +288,10 @@
267
288
  async function sendTargetUpdate(force = false) {
268
289
  if (stopped || !ws || ws.readyState !== WebSocket.OPEN) return;
269
290
  try {
291
+ const site = await requestRuntime({ type: "pcbridge:siteStatus" });
292
+ if (!site || !site.enabled) { stopBridge(); return; }
270
293
  const target = await describeTarget();
294
+ if (!["editor", "launch"].includes(target.kind)) { stopBridge(); return; }
271
295
  const signature = JSON.stringify(target);
272
296
  if (!force && signature === lastTargetSignature) return;
273
297
  if (target.projectId) {
@@ -320,6 +344,14 @@
320
344
 
321
345
  async function connect() {
322
346
  if (stopped) return;
347
+ const site = await requestRuntime({ type: "pcbridge:siteStatus" });
348
+ if (!site || !site.enabled) { stopBridge(); return; }
349
+ const target = await describeTarget();
350
+ if (!["editor", "launch"].includes(target.kind) ||
351
+ (target.kind === "editor" ? !target.hasEditor : !target.hasRuntimeApp)) {
352
+ scheduleReconnect();
353
+ return;
354
+ }
323
355
  if (connecting) return;
324
356
  if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) {
325
357
  return;
@@ -355,6 +387,18 @@
355
387
  socket.addEventListener("open", () => {
356
388
  reconnectAttempt = 0;
357
389
  setConnectionState("connected");
390
+ requestRuntime({ type: "pcbridge:getWorkspaceSettings" })
391
+ .then(async (settings) => {
392
+ if (settings && settings.pendingDaemonSync && Number.isFinite(Number(settings.eagerMaxMb))) {
393
+ await callDaemon("/workspace/settings", "POST", { eagerMaxMb: Number(settings.eagerMaxMb) });
394
+ await requestRuntime({
395
+ type: "pcbridge:setWorkspaceSettings",
396
+ eagerMaxMb: Number(settings.eagerMaxMb),
397
+ pendingDaemonSync: false
398
+ });
399
+ }
400
+ })
401
+ .catch(() => undefined);
358
402
  sendTargetUpdate(true).catch((error) => {
359
403
  if (isExtensionContextInvalidated(error)) stopBridge();
360
404
  });
@@ -449,6 +493,10 @@
449
493
  }, 2000);
450
494
  }
451
495
 
496
+ chrome.runtime.onMessage?.addListener((message) => {
497
+ if (message?.type === "pcbridge:siteDisabled") stopBridge();
498
+ });
499
+
452
500
  start().catch((error) => {
453
501
  if (isExtensionContextInvalidated(error)) stopBridge();
454
502
  });