@pasko70/pibo 1.11.4 → 1.12.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.
Files changed (37) hide show
  1. package/dist/apps/{context-files-ui/assets/dist-DT9QkgTN.js → chat-ui/assets/dist-B2Pozq2c.js} +1 -1
  2. package/dist/apps/chat-ui/assets/{dist-yjwDcRbw.js → dist-Bgv5Fm3v.js} +1 -1
  3. package/dist/apps/chat-ui/assets/{dist-TS4EA6YQ.js → dist-Ci4lft6y.js} +1 -1
  4. package/dist/apps/{context-files-ui/assets/dist-B07Whoa6.js → chat-ui/assets/dist-CkLit_da.js} +1 -1
  5. package/dist/apps/{context-files-ui/assets/dist-Dtv5S2qd.js → chat-ui/assets/dist-D1U9ck8z.js} +1 -1
  6. package/dist/apps/chat-ui/assets/{dist-CjXSEbsr.js → dist-D4qbF8wy.js} +1 -1
  7. package/dist/apps/chat-ui/assets/{dist-D9B41N2f.js → dist-DYdgxFZX.js} +1 -1
  8. package/dist/apps/chat-ui/assets/{dist-BXjLdcn6.js → dist-DiPvo4rq.js} +1 -1
  9. package/dist/apps/{context-files-ui/assets/dist-BQK_wUMR.js → chat-ui/assets/dist-DxJWicji.js} +1 -1
  10. package/dist/apps/chat-ui/assets/{dist-CSBDio7C.js → dist-la7ZfDGk.js} +1 -1
  11. package/dist/apps/chat-ui/assets/index-BJoo_GJP.css +1 -0
  12. package/dist/apps/chat-ui/assets/index-CYxPvrxL.js +237 -0
  13. package/dist/apps/chat-ui/index.html +2 -2
  14. package/dist/apps/chat-vscode-web/assets/index-CFSHKXsQ.js +41 -0
  15. package/dist/apps/chat-vscode-web/index.html +1 -1
  16. package/dist/apps/{chat-ui/assets/dist-BeKdUsyg.js → context-files-ui/assets/dist-BYcsFgKp.js} +1 -1
  17. package/dist/apps/context-files-ui/assets/{dist-TG9QLHKj.js → dist-Bdudyq9I.js} +1 -1
  18. package/dist/apps/context-files-ui/assets/{dist-BFlEjppv.js → dist-BvIW3V94.js} +1 -1
  19. package/dist/apps/context-files-ui/assets/{dist-De6eI3Cr.js → dist-CSLUWBzz.js} +1 -1
  20. package/dist/apps/{chat-ui/assets/dist-CNv02m3N.js → context-files-ui/assets/dist-CT-91DFe.js} +1 -1
  21. package/dist/apps/{chat-ui/assets/dist-BtQ20SMU.js → context-files-ui/assets/dist-DcsDivye.js} +1 -1
  22. package/dist/apps/context-files-ui/assets/{dist-BACxmdQ2.js → dist-DeozI4lc.js} +1 -1
  23. package/dist/apps/context-files-ui/assets/{dist-D68eIqmX.js → dist-f2E1-leP.js} +1 -1
  24. package/dist/apps/context-files-ui/assets/{dist-CigbyRK5.js → dist-sus90AFR.js} +1 -1
  25. package/dist/apps/{chat-ui/assets/dist-TAhl1jC0.js → context-files-ui/assets/dist-uFphVGi8.js} +1 -1
  26. package/dist/apps/context-files-ui/assets/index-CQ25ablG.js +202 -0
  27. package/dist/apps/context-files-ui/index.html +1 -1
  28. package/dist/apps/vscode-artifacts/latest.vsix +0 -0
  29. package/dist/apps/vscode-artifacts/pibo-vscode-ext-1.12.0.vsix +0 -0
  30. package/dist/debug/web.js +1 -1
  31. package/dist/tools/cdp-client.js +87 -3
  32. package/package.json +1 -1
  33. package/dist/apps/chat-ui/assets/index-BoRl0OB_.js +0 -473
  34. package/dist/apps/chat-ui/assets/index-aTOOomMF.css +0 -1
  35. package/dist/apps/chat-vscode-web/assets/index-DGcSd2ZH.js +0 -275
  36. package/dist/apps/context-files-ui/assets/index-B5j33Q2B.js +0 -438
  37. package/dist/apps/vscode-artifacts/pibo-vscode-ext-1.11.4.vsix +0 -0
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Pibo Context Files</title>
7
- <script type="module" crossorigin src="/apps/context-files/assets/index-B5j33Q2B.js"></script>
7
+ <script type="module" crossorigin src="/apps/context-files/assets/index-CQ25ablG.js"></script>
8
8
  <link rel="modulepreload" crossorigin href="/apps/context-files/assets/dist-D1KyNDg5.js">
9
9
  <link rel="stylesheet" crossorigin href="/apps/context-files/assets/index-CukPnd6A.css">
10
10
  </head>
package/dist/debug/web.js CHANGED
@@ -486,7 +486,7 @@ async function runStreamingBenchmarkSeries(client, runs, durationMs, options) {
486
486
  async function runStreamingBenchmark(client, durationMs, options = {}) {
487
487
  await client.send("Page.bringToFront").catch(() => undefined);
488
488
  const benchmarkTimeoutMs = durationMs + (options.startBackendFixture ? 20_000 : 10_000);
489
- const benchmark = await client.evaluate(buildStreamingBenchmarkExpression(durationMs, options), benchmarkTimeoutMs);
489
+ const benchmark = await client.evaluateJson(buildStreamingBenchmarkExpression(durationMs, options), benchmarkTimeoutMs);
490
490
  const withRenderOrder = { ...benchmark, renderOrder: analyzeStreamingRenderOrderCapture(benchmark.renderOrder) };
491
491
  const withProvider = { ...withRenderOrder, provider: options.providerTelemetry };
492
492
  const scored = { ...withProvider, score: scoreStreamingBenchmark(withProvider), providerPreservation: summarizeStreamingProviderPreservation(withProvider) };
@@ -1,5 +1,7 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  export const DEFAULT_CDP_URL = "http://127.0.0.1:56663";
2
3
  export const DEFAULT_CDP_TIMEOUT_MS = 2_500;
4
+ const CDP_JSON_CHUNK_SIZE = 256 * 1024;
3
5
  export class CdpClient {
4
6
  webSocketUrl;
5
7
  nextId = 0;
@@ -32,10 +34,11 @@ export class CdpClient {
32
34
  socket.addEventListener("open", succeed);
33
35
  socket.addEventListener("message", (event) => this.handleMessage(String(event.data)));
34
36
  socket.addEventListener("error", () => fail(new Error(`CDP WebSocket error connecting to ${this.webSocketUrl}`)));
35
- socket.addEventListener("close", () => {
37
+ socket.addEventListener("close", (event) => {
38
+ const detail = `code ${event.code}${event.reason ? `: ${event.reason}` : ""}`;
36
39
  for (const [id, pending] of this.pending) {
37
40
  clearTimeout(pending.timer);
38
- pending.reject(new Error("CDP target closed"));
41
+ pending.reject(new Error(`CDP target closed during ${pending.method} (${detail})`));
39
42
  this.pending.delete(id);
40
43
  }
41
44
  });
@@ -51,11 +54,17 @@ export class CdpClient {
51
54
  this.pending.delete(id);
52
55
  reject(new Error(`Timed out waiting for CDP method ${method}`));
53
56
  }, timeoutMs);
54
- this.pending.set(id, { resolve, reject, timer });
57
+ this.pending.set(id, { method, resolve, reject, timer });
55
58
  });
56
59
  this.socket.send(JSON.stringify(payload));
57
60
  return promise;
58
61
  }
62
+ sendDetached(method, params) {
63
+ if (!this.socket || this.socket.readyState !== WebSocket.OPEN)
64
+ return;
65
+ const id = ++this.nextId;
66
+ this.socket.send(JSON.stringify(params ? { id, method, params } : { id, method }));
67
+ }
59
68
  async evaluate(expression, timeoutMs = 10_000) {
60
69
  const response = await this.send("Runtime.evaluate", {
61
70
  expression,
@@ -67,6 +76,72 @@ export class CdpClient {
67
76
  throw new Error(`Browser evaluation failed: ${JSON.stringify(response.exceptionDetails)}`);
68
77
  return response.result?.value;
69
78
  }
79
+ async evaluateJson(expression, timeoutMs = 10_000) {
80
+ const deadlineMs = Date.now() + timeoutMs;
81
+ const cleanupReserveMs = Math.min(100, Math.max(1, Math.floor(timeoutMs / 10)));
82
+ const transferDeadlineMs = deadlineMs - cleanupReserveMs;
83
+ const storageKey = `__piboCdpJsonResult_${randomUUID()}`;
84
+ const keyLiteral = JSON.stringify(storageKey);
85
+ try {
86
+ const descriptor = await this.evaluate(`(async () => {
87
+ const deadlineMs = ${deadlineMs};
88
+ if (Date.now() >= deadlineMs) throw new Error("CDP JSON evaluation exceeded its deadline");
89
+ const state = { cancelled: false, json: undefined, cleanupTimer: undefined };
90
+ Object.defineProperty(globalThis, ${keyLiteral}, { value: state, configurable: true });
91
+ state.cleanupTimer = setTimeout(() => {
92
+ state.cancelled = true;
93
+ if (globalThis[${keyLiteral}] === state) delete globalThis[${keyLiteral}];
94
+ }, Math.max(0, deadlineMs - Date.now()));
95
+ try {
96
+ const value = await (${expression});
97
+ const json = JSON.stringify(value);
98
+ if (typeof json !== "string") throw new Error("CDP evaluation result is not JSON serializable");
99
+ if (Date.now() >= deadlineMs || state.cancelled || globalThis[${keyLiteral}] !== state) throw new Error("CDP JSON evaluation exceeded its deadline");
100
+ state.json = json;
101
+ return { length: json.length };
102
+ } catch (error) {
103
+ state.cancelled = true;
104
+ clearTimeout(state.cleanupTimer);
105
+ if (globalThis[${keyLiteral}] === state) delete globalThis[${keyLiteral}];
106
+ throw error;
107
+ }
108
+ })()`, remainingTime(transferDeadlineMs, "evaluating JSON through CDP"));
109
+ if (!Number.isInteger(descriptor?.length) || descriptor.length < 0)
110
+ throw new Error("CDP evaluation returned an invalid JSON result length");
111
+ const chunks = [];
112
+ for (let offset = 0; offset < descriptor.length; offset += CDP_JSON_CHUNK_SIZE) {
113
+ const end = Math.min(descriptor.length, offset + CDP_JSON_CHUNK_SIZE);
114
+ chunks.push(await this.evaluate(`(() => {
115
+ const state = globalThis[${keyLiteral}];
116
+ if (!state || typeof state.json !== "string") throw new Error("CDP JSON result storage is unavailable");
117
+ return state.json.slice(${offset}, ${end});
118
+ })()`, remainingTime(transferDeadlineMs, "retrieving JSON chunks through CDP")));
119
+ }
120
+ return JSON.parse(chunks.join(""));
121
+ }
122
+ finally {
123
+ const cleanupExpression = `(() => {
124
+ const state = globalThis[${keyLiteral}];
125
+ if (state && typeof state === "object") {
126
+ state.cancelled = true;
127
+ clearTimeout(state.cleanupTimer);
128
+ }
129
+ return delete globalThis[${keyLiteral}];
130
+ })()`;
131
+ const cleanupTimeoutMs = remainingTimeOrZero(deadlineMs);
132
+ if (cleanupTimeoutMs > 0) {
133
+ await this.evaluate(cleanupExpression, cleanupTimeoutMs).catch(() => undefined);
134
+ }
135
+ else {
136
+ this.sendDetached("Runtime.evaluate", {
137
+ expression: cleanupExpression,
138
+ awaitPromise: true,
139
+ returnByValue: true,
140
+ userGesture: true,
141
+ });
142
+ }
143
+ }
144
+ }
70
145
  close() {
71
146
  try {
72
147
  this.socket?.close();
@@ -187,3 +262,12 @@ function optionalStringValue(value) {
187
262
  const text = stringValue(value);
188
263
  return text || undefined;
189
264
  }
265
+ function remainingTime(deadlineMs, operation) {
266
+ const remainingMs = remainingTimeOrZero(deadlineMs);
267
+ if (remainingMs <= 0)
268
+ throw new Error(`Timed out ${operation}`);
269
+ return remainingMs;
270
+ }
271
+ function remainingTimeOrZero(deadlineMs) {
272
+ return Math.max(0, Math.floor(deadlineMs - Date.now()));
273
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pasko70/pibo",
3
- "version": "1.11.4",
3
+ "version": "1.12.0",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "vscode": "./src/apps/chat-vscode/extension/src/vscode-shim.js"