@mgamadeus/ddd-agents 0.5.15 → 0.5.17

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 CHANGED
@@ -12,7 +12,7 @@ npm install @mgamadeus/ddd-agents@~0.1.1 @types/google.maps@^3.55.0 apexcharts@^
12
12
  remark-directive@^4.0.0 remark-gfm@^4.0.1 remark-parse@^11.0.0 unified@^11.0.5 unist-util-visit@^5.0.0
13
13
  ```
14
14
 
15
- The second part is the peer set (React 19 assumed present; `axios` ^0.28.0 only for the optional axios client).
15
+ The second part is the peer set (React 19 assumed present).
16
16
  `react-apexcharts` stays below 1.6.0: from 1.6.0 it needs apexcharts 4, the package draws with apexcharts 3.
17
17
  The agent skills come with the Composer package (`vendor/mgamadeus/ddd-agents/.claude/skills`), not with this one.
18
18
 
@@ -21,6 +21,12 @@ Entries: `@mgamadeus/ddd-agents` (provider and setup), `/provider` (the provider
21
21
  (import it once). Non-code files (widget documentation, preview fixtures, contracts, the node schema, the
22
22
  sandbox frame, SCSS tokens) are exported one subpath per file at their path below `src`. React 19 and the libraries listed under `peerDependencies` come from the application.
23
23
 
24
+ The request stand-ins of `/preview` (`installWidgetPreviewRequests`) and `/image-render` (`installFrozenWidgetRequests`,
25
+ `installLiveWidgetRequests`) replace `XMLHttpRequest` (the transport of axios's browser adapter) until the returned
26
+ function is called; the preview and the live capture answer `fetch` as well. The frozen capture leaves `fetch` alone
27
+ unless asked: `installFrozenWidgetRequests(responses, fail, { interceptFetch: true })` for an application that reads
28
+ through `fetch`. No request needs to route through axios.
29
+
24
30
  ## The conversation client over HTTP
25
31
 
26
32
  `createAgentsHttpConversationClient` (`/client`) binds the client port to the module's own conversation routes
@@ -0,0 +1,335 @@
1
+ "use client";
2
+ import { V as getSandboxLegacyAliases } from "./link-navigation-CNX8Am2L.js";
3
+ const WIDGET_IMAGE_READINESS_GLOBAL_NAME = "__AGENTS_WIDGET_IMAGE_V1__";
4
+ const readWidgetImageReadinessGlobalNames = () => [
5
+ WIDGET_IMAGE_READINESS_GLOBAL_NAME,
6
+ ...(getSandboxLegacyAliases().imageReadinessGlobalNames ?? []).filter(
7
+ (aliasName) => aliasName !== WIDGET_IMAGE_READINESS_GLOBAL_NAME
8
+ )
9
+ ];
10
+ const publishWidgetImageReadiness = (readiness) => {
11
+ const windowSignals = window;
12
+ for (const globalName of readWidgetImageReadinessGlobalNames()) windowSignals[globalName] = readiness;
13
+ };
14
+ const readWidgetImageReadiness = () => {
15
+ const windowSignals = window;
16
+ const publishedSignals = readWidgetImageReadinessGlobalNames().map((globalName) => windowSignals[globalName]).filter((signal) => signal !== void 0 && signal !== null);
17
+ return publishedSignals.find((signal) => signal.state === "failed") ?? publishedSignals[0];
18
+ };
19
+ const createProgressEvent = (type, loaded, total) => typeof ProgressEvent === "function" ? new ProgressEvent(type, { lengthComputable: total > 0, loaded, total }) : new Event(type);
20
+ class InterceptedXMLHttpRequestUpload extends EventTarget {
21
+ constructor() {
22
+ super(...arguments);
23
+ this.onloadstart = null;
24
+ this.onprogress = null;
25
+ this.onload = null;
26
+ this.onerror = null;
27
+ this.onabort = null;
28
+ this.ontimeout = null;
29
+ this.onloadend = null;
30
+ }
31
+ emit(type, loaded = 0, total = 0) {
32
+ const event = createProgressEvent(type, loaded, total);
33
+ this.dispatchEvent(event);
34
+ this[`on${type}`]?.call(this, event);
35
+ }
36
+ }
37
+ const createHeaderlessResponse = (body, status, statusText = "") => new Response(body === null ? null : new TextEncoder().encode(body), { status, statusText });
38
+ const isFetchRequest = (input) => Object.prototype.toString.call(input) === "[object Request]";
39
+ const pageOrigin = () => typeof window !== "undefined" && window.location ? window.location.origin : "http://localhost";
40
+ const copyHeaders = (target, source) => {
41
+ if (source === void 0) return;
42
+ new Headers(source).forEach((value, name) => target.set(name, value));
43
+ };
44
+ const readFetchRequest = async (input, init, originalFetch) => {
45
+ const fromRequest = isFetchRequest(input) ? input : void 0;
46
+ const headers = new Headers();
47
+ if (fromRequest) fromRequest.headers.forEach((value, name) => headers.set(name, value));
48
+ copyHeaders(headers, init?.headers);
49
+ const initBody = init?.body ?? null;
50
+ const body = initBody !== null ? initBody : fromRequest && fromRequest.body !== null ? await fromRequest.clone().arrayBuffer() : null;
51
+ return {
52
+ method: (init?.method ?? fromRequest?.method ?? "GET").toUpperCase(),
53
+ url: new URL(fromRequest ? fromRequest.url : String(input), pageOrigin()),
54
+ headers,
55
+ body,
56
+ signal: init?.signal ?? fromRequest?.signal ?? void 0,
57
+ transport: "fetch",
58
+ forward: () => originalFetch(input, init)
59
+ };
60
+ };
61
+ const bodySize = (body) => {
62
+ if (body === null) return 0;
63
+ if (typeof body === "string") return new TextEncoder().encode(body).byteLength;
64
+ if (typeof Blob !== "undefined" && body instanceof Blob) return body.size;
65
+ if (body instanceof ArrayBuffer) return body.byteLength;
66
+ if (ArrayBuffer.isView(body)) return body.byteLength;
67
+ return 0;
68
+ };
69
+ const invalidState = (message) => new DOMException(message, "InvalidStateError");
70
+ const createInterceptedXMLHttpRequest = (handle, originalFetch) => class InterceptedXMLHttpRequest extends EventTarget {
71
+ constructor() {
72
+ super(...arguments);
73
+ this.UNSENT = 0;
74
+ this.OPENED = 1;
75
+ this.HEADERS_RECEIVED = 2;
76
+ this.LOADING = 3;
77
+ this.DONE = 4;
78
+ this.readyState = 0;
79
+ this.status = 0;
80
+ this.statusText = "";
81
+ this.responseURL = "";
82
+ this.responseType = "";
83
+ this.timeout = 0;
84
+ this.withCredentials = false;
85
+ this.upload = new InterceptedXMLHttpRequestUpload();
86
+ this.responseXML = null;
87
+ this.onreadystatechange = null;
88
+ this.onloadstart = null;
89
+ this.onprogress = null;
90
+ this.onload = null;
91
+ this.onerror = null;
92
+ this.onabort = null;
93
+ this.ontimeout = null;
94
+ this.onloadend = null;
95
+ this.method = "GET";
96
+ this.requestUrl = "";
97
+ this.requestHeaders = new Headers();
98
+ this.responseHeaders = new Headers();
99
+ this.responseValue = "";
100
+ this.responseTextValue = "";
101
+ this.sent = false;
102
+ this.settled = false;
103
+ }
104
+ static {
105
+ this.UNSENT = 0;
106
+ }
107
+ static {
108
+ this.OPENED = 1;
109
+ }
110
+ static {
111
+ this.HEADERS_RECEIVED = 2;
112
+ }
113
+ static {
114
+ this.LOADING = 3;
115
+ }
116
+ static {
117
+ this.DONE = 4;
118
+ }
119
+ get response() {
120
+ if (this.responseType === "" || this.responseType === "text") return this.responseText;
121
+ return this.readyState === 4 ? this.responseValue : null;
122
+ }
123
+ get responseText() {
124
+ if (this.responseType !== "" && this.responseType !== "text") {
125
+ throw invalidState(`responseText is not available for responseType "${this.responseType}"`);
126
+ }
127
+ return this.readyState >= 3 ? this.responseTextValue : "";
128
+ }
129
+ open(method, url) {
130
+ if (this.sent && !this.settled) this.settle();
131
+ this.controller?.abort();
132
+ this.controller = void 0;
133
+ this.method = method.toUpperCase();
134
+ this.requestUrl = String(url);
135
+ this.requestHeaders = new Headers();
136
+ this.responseHeaders = new Headers();
137
+ this.responseValue = "";
138
+ this.responseTextValue = "";
139
+ this.status = 0;
140
+ this.statusText = "";
141
+ this.responseURL = "";
142
+ this.sent = false;
143
+ this.settled = false;
144
+ this.setReadyState(1);
145
+ }
146
+ setRequestHeader(name, value) {
147
+ if (this.readyState !== 1 || this.sent) throw invalidState("setRequestHeader needs an opened, unsent request");
148
+ this.requestHeaders.append(name, value);
149
+ }
150
+ overrideMimeType() {
151
+ }
152
+ getAllResponseHeaders() {
153
+ if (this.readyState < 2) return "";
154
+ let lines = "";
155
+ this.responseHeaders.forEach((value, name) => {
156
+ lines += `${name}: ${value}\r
157
+ `;
158
+ });
159
+ return lines;
160
+ }
161
+ getResponseHeader(name) {
162
+ return this.readyState < 2 ? null : this.responseHeaders.get(name);
163
+ }
164
+ send(body) {
165
+ if (this.readyState !== 1 || this.sent) throw invalidState("send needs an opened, unsent request");
166
+ this.sent = true;
167
+ const controller = new AbortController();
168
+ this.controller = controller;
169
+ const passedBody = body === void 0 || body === null ? null : body;
170
+ const requestBody = this.method === "GET" || this.method === "HEAD" ? null : passedBody;
171
+ const headers = new Headers(this.requestHeaders);
172
+ const url = new URL(this.requestUrl, pageOrigin());
173
+ const credentials = this.withCredentials ? "include" : "same-origin";
174
+ const method = this.method;
175
+ const request = {
176
+ method,
177
+ url,
178
+ headers,
179
+ body: passedBody,
180
+ signal: controller.signal,
181
+ transport: "xhr",
182
+ forward: () => originalFetch(url.href, {
183
+ method,
184
+ headers: new Headers(headers),
185
+ body: requestBody,
186
+ credentials,
187
+ signal: controller.signal
188
+ })
189
+ };
190
+ const responseUrl = url.href;
191
+ if (this.timeout > 0) this.timer = setTimeout(() => this.finishWithoutResponse("timeout"), this.timeout);
192
+ this.emit("loadstart");
193
+ const size = bodySize(requestBody);
194
+ if (requestBody !== null) {
195
+ this.upload.emit("loadstart", 0, size);
196
+ this.upload.emit("progress", size, size);
197
+ this.upload.emit("load", size, size);
198
+ this.upload.emit("loadend", size, size);
199
+ }
200
+ Promise.resolve().then(() => handle(request)).then(
201
+ (response) => this.receive(controller, response, responseUrl),
202
+ () => {
203
+ if (this.controller === controller) this.finishWithoutResponse("error");
204
+ }
205
+ );
206
+ }
207
+ abort() {
208
+ if (!this.sent || this.settled) return;
209
+ this.finishWithoutResponse("abort");
210
+ this.readyState = 0;
211
+ }
212
+ async receive(controller, response, responseUrl) {
213
+ if (this.controller !== controller || this.settled) return;
214
+ try {
215
+ this.status = response.status;
216
+ this.statusText = response.statusText;
217
+ this.responseURL = responseUrl;
218
+ this.responseHeaders = new Headers(response.headers);
219
+ this.setReadyState(2);
220
+ const value = await this.readBody(response);
221
+ if (this.controller !== controller || this.settled) return;
222
+ this.responseValue = value;
223
+ this.setReadyState(3);
224
+ const size = typeof this.responseTextValue === "string" ? this.responseTextValue.length : 0;
225
+ this.emit("progress", size, size);
226
+ this.settle();
227
+ this.setReadyState(4);
228
+ this.emit("load", size, size);
229
+ this.emit("loadend", size, size);
230
+ } catch {
231
+ if (this.controller === controller && !this.settled) this.finishWithoutResponse("error");
232
+ }
233
+ }
234
+ async readBody(response) {
235
+ switch (this.responseType) {
236
+ case "json": {
237
+ const text = await response.text();
238
+ this.responseTextValue = text;
239
+ try {
240
+ return text === "" ? null : JSON.parse(text);
241
+ } catch {
242
+ return null;
243
+ }
244
+ }
245
+ case "blob":
246
+ return response.blob();
247
+ case "arraybuffer":
248
+ return response.arrayBuffer();
249
+ case "document":
250
+ return null;
251
+ default: {
252
+ const text = await response.text();
253
+ this.responseTextValue = text;
254
+ return text;
255
+ }
256
+ }
257
+ }
258
+ /** A request that ends without a response — an error, an abort or a timeout: status 0, nothing of a body. */
259
+ finishWithoutResponse(type) {
260
+ if (this.settled) return;
261
+ this.settle();
262
+ this.controller?.abort();
263
+ this.status = 0;
264
+ this.statusText = "";
265
+ this.responseHeaders = new Headers();
266
+ this.responseValue = null;
267
+ this.responseTextValue = "";
268
+ this.setReadyState(4);
269
+ this.emit(type);
270
+ this.emit("loadend");
271
+ }
272
+ settle() {
273
+ this.settled = true;
274
+ if (this.timer !== void 0) clearTimeout(this.timer);
275
+ this.timer = void 0;
276
+ }
277
+ setReadyState(state) {
278
+ this.readyState = state;
279
+ this.emit("readystatechange");
280
+ }
281
+ emit(type, loaded = 0, total = 0) {
282
+ const event = type === "readystatechange" ? new Event(type) : createProgressEvent(type, loaded, total);
283
+ this.dispatchEvent(event);
284
+ this[`on${type}`]?.call(this, event);
285
+ }
286
+ };
287
+ const globalScopes = () => {
288
+ const scopes = [globalThis];
289
+ if (typeof window !== "undefined" && window !== globalThis) scopes.push(window);
290
+ return scopes;
291
+ };
292
+ const capturePageFetch = () => {
293
+ const pageFetch = typeof window !== "undefined" ? window.fetch : globalThis.fetch;
294
+ return (input, init) => pageFetch.call(globalThis, input, init);
295
+ };
296
+ const replaceGlobal = (name, value) => {
297
+ const saved = globalScopes().map((scope) => ({ scope, value: scope[name] }));
298
+ for (const { scope } of saved) scope[name] = value;
299
+ return () => {
300
+ for (const entry of saved) entry.scope[name] = entry.value;
301
+ };
302
+ };
303
+ const interceptXMLHttpRequests = (handle) => replaceGlobal(
304
+ "XMLHttpRequest",
305
+ createInterceptedXMLHttpRequest(handle, capturePageFetch())
306
+ );
307
+ const interceptFetchRequests = (handle) => {
308
+ const originalFetch = capturePageFetch();
309
+ const interceptedFetch = async (input, init) => handle(await readFetchRequest(input, init, originalFetch));
310
+ return replaceGlobal("fetch", interceptedFetch);
311
+ };
312
+ const toSameRealmFetchInput = async (input) => {
313
+ if (!isFetchRequest(input) || input instanceof Request) return input;
314
+ const foreign = input;
315
+ const body = foreign.body !== null ? await foreign.clone().arrayBuffer() : null;
316
+ return new Request(foreign.url, {
317
+ method: foreign.method,
318
+ headers: new Headers(foreign.headers),
319
+ body,
320
+ // A signal of another realm is not accepted by this realm's constructor.
321
+ signal: foreign.signal instanceof AbortSignal ? foreign.signal : void 0
322
+ });
323
+ };
324
+ export {
325
+ WIDGET_IMAGE_READINESS_GLOBAL_NAME as W,
326
+ interceptFetchRequests as a,
327
+ readWidgetImageReadinessGlobalNames as b,
328
+ createHeaderlessResponse as c,
329
+ isFetchRequest as d,
330
+ interceptXMLHttpRequests as i,
331
+ publishWidgetImageReadiness as p,
332
+ readWidgetImageReadiness as r,
333
+ toSameRealmFetchInput as t
334
+ };
335
+ //# sourceMappingURL=browser-request-interception-BdKjYz31.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-request-interception-BdKjYz31.js","sources":["../../src/image-render/widget-image-readiness-signal.ts","../../src/request-interception/intercepted-xml-http-request-upload.ts","../../src/request-interception/browser-request-interception.ts"],"sourcesContent":["import { getSandboxLegacyAliases } from \"../provider/environment\";\nimport type { WidgetImageReadiness } from \"./widget-image-render.types\";\n\n/** The `window` property the image capture waits on. */\nexport const WIDGET_IMAGE_READINESS_GLOBAL_NAME = \"__AGENTS_WIDGET_IMAGE_V1__\";\n\ntype WindowSignals = Record<string, WidgetImageReadiness | undefined>;\n\n/**\n * Every name the image readiness signal is published under: the package's own, then each name the app declares\n * (`AgentsEnvironment.sandboxLegacyAliases.imageReadinessGlobalNames`) — read at each publish, so an app may declare\n * them after a readiness was created.\n */\nexport const readWidgetImageReadinessGlobalNames = (): string[] => [\n WIDGET_IMAGE_READINESS_GLOBAL_NAME,\n ...(getSandboxLegacyAliases().imageReadinessGlobalNames ?? []).filter(\n (aliasName) => aliasName !== WIDGET_IMAGE_READINESS_GLOBAL_NAME,\n ),\n];\n\n/** Publishes (or with `undefined` clears) the image readiness signal under every name. */\nexport const publishWidgetImageReadiness = (readiness: WidgetImageReadiness | undefined): void => {\n const windowSignals = window as unknown as WindowSignals;\n for (const globalName of readWidgetImageReadinessGlobalNames()) windowSignals[globalName] = readiness;\n};\n\n/**\n * The published image readiness signal. A `failed` value under ANY name wins — the app's own capture code may have\n * written it under a name it declared — otherwise the value under the package's name, otherwise the first value found.\n */\nexport const readWidgetImageReadiness = (): WidgetImageReadiness | undefined => {\n const windowSignals = window as unknown as WindowSignals;\n const publishedSignals = readWidgetImageReadinessGlobalNames()\n .map((globalName) => windowSignals[globalName])\n .filter((signal): signal is WidgetImageReadiness => signal !== undefined && signal !== null);\n return publishedSignals.find((signal) => signal.state === \"failed\") ?? publishedSignals[0];\n};\n","/** The upload side of the `XMLHttpRequest` stand-in (`xhr.upload`) and the events both sides dispatch. */\n\nexport type XhrEventName = \"loadstart\" | \"progress\" | \"load\" | \"error\" | \"abort\" | \"timeout\" | \"loadend\" | \"readystatechange\";\nexport type XhrEventHandler = ((this: unknown, event: Event) => unknown) | null;\n\nexport const createProgressEvent = (type: string, loaded: number, total: number): Event =>\n typeof ProgressEvent === \"function\"\n ? new ProgressEvent(type, { lengthComputable: total > 0, loaded, total })\n : new Event(type);\n\n/** The event target of `xhr.upload`: listeners and `on…` handlers for the upload's progress. */\nexport class InterceptedXMLHttpRequestUpload extends EventTarget {\n onloadstart: XhrEventHandler = null;\n onprogress: XhrEventHandler = null;\n onload: XhrEventHandler = null;\n onerror: XhrEventHandler = null;\n onabort: XhrEventHandler = null;\n ontimeout: XhrEventHandler = null;\n onloadend: XhrEventHandler = null;\n\n emit(type: XhrEventName, loaded = 0, total = 0) {\n const event = createProgressEvent(type, loaded, total);\n this.dispatchEvent(event);\n (this[`on${type}` as keyof this] as XhrEventHandler)?.call(this, event);\n }\n}\n","import {\n createProgressEvent,\n InterceptedXMLHttpRequestUpload,\n type XhrEventHandler,\n type XhrEventName,\n} from \"./intercepted-xml-http-request-upload\";\n\n/**\n * The browser-level request stand-in of the capture and preview pages: `XMLHttpRequest` (the transport of axios's\n * browser adapter and of uploads with progress) and, where an install asks for it, `window.fetch` are replaced for the\n * duration of an install and send every request into one handler, whatever HTTP client the application uses.\n *\n * The handler answers with a `Response` or throws: `fetch` then rejects with the thrown error, an `XMLHttpRequest`\n * fails like a network error (status 0, `error` and `loadend`, no body, no header). A handler that never settles\n * leaves the request pending. Nothing of the request reaches the network unless the handler sends it itself\n * (`forward()`, or its own copy of the original `fetch`).\n */\n\n/** A request as the handler sees it, the same for `fetch` and `XMLHttpRequest`. */\nexport interface InterceptedRequest {\n /** Upper case (`GET`, `POST`, …). */\n method: string;\n /** Absolute, resolved against the page's origin. A fresh object per request; the handler may change it. */\n url: URL;\n headers: Headers;\n /** The body the client passed (`fetch`'s, or the argument of `XMLHttpRequest.send`, also for a GET), or null. */\n body: BodyInit | null;\n signal: AbortSignal | undefined;\n transport: \"fetch\" | \"xhr\";\n /** Sends the request unchanged through the original `fetch` (an `XMLHttpRequest` with its own credentials mode). */\n forward: () => Promise<Response>;\n}\n\nexport type InterceptedRequestHandler = (request: InterceptedRequest) => Promise<Response>;\n\ntype FetchInput = RequestInfo | URL;\n\n/**\n * An answer without any header, as the former axios adapters answered (`headers: {}`): a string body would add a\n * `Content-Type`, the bytes of it do not.\n */\nexport const createHeaderlessResponse = (body: string | null, status: number, statusText = \"\"): Response =>\n new Response(body === null ? null : new TextEncoder().encode(body), { status, statusText });\n\n/** A `Request` of any realm (an iframe's, jsdom's, Node's) — never `instanceof`, which holds only for this realm. */\nexport const isFetchRequest = (input: unknown): input is Request =>\n Object.prototype.toString.call(input) === \"[object Request]\";\n\nconst pageOrigin = (): string =>\n typeof window !== \"undefined\" && window.location ? window.location.origin : \"http://localhost\";\n\nconst copyHeaders = (target: Headers, source: HeadersInit | undefined) => {\n if (source === undefined) return;\n new Headers(source).forEach((value, name) => target.set(name, value));\n};\n\n/** The `fetch` arguments as one request: a `Request` of any realm, a `URL` or a string, with `init` taking precedence. */\nexport const readFetchRequest = async (\n input: FetchInput,\n init: RequestInit | undefined,\n originalFetch: typeof fetch,\n): Promise<InterceptedRequest> => {\n const fromRequest = isFetchRequest(input) ? input : undefined;\n const headers = new Headers();\n if (fromRequest) fromRequest.headers.forEach((value, name) => headers.set(name, value));\n copyHeaders(headers, init?.headers);\n const initBody = init?.body ?? null;\n const body =\n initBody !== null\n ? initBody\n : fromRequest && fromRequest.body !== null\n ? await fromRequest.clone().arrayBuffer()\n : null;\n return {\n method: (init?.method ?? fromRequest?.method ?? \"GET\").toUpperCase(),\n url: new URL(fromRequest ? fromRequest.url : String(input), pageOrigin()),\n headers,\n body,\n signal: init?.signal ?? fromRequest?.signal ?? undefined,\n transport: \"fetch\",\n forward: () => originalFetch(input, init),\n };\n};\n\nconst bodySize = (body: BodyInit | null): number => {\n if (body === null) return 0;\n if (typeof body === \"string\") return new TextEncoder().encode(body).byteLength;\n if (typeof Blob !== \"undefined\" && body instanceof Blob) return body.size;\n if (body instanceof ArrayBuffer) return body.byteLength;\n if (ArrayBuffer.isView(body)) return body.byteLength;\n return 0;\n};\n\nconst invalidState = (message: string) => new DOMException(message, \"InvalidStateError\");\n\n/** Builds the `XMLHttpRequest` class an install puts on the page: every request goes to `handle`. */\nconst createInterceptedXMLHttpRequest = (handle: InterceptedRequestHandler, originalFetch: typeof fetch) =>\n class InterceptedXMLHttpRequest extends EventTarget {\n static readonly UNSENT = 0;\n static readonly OPENED = 1;\n static readonly HEADERS_RECEIVED = 2;\n static readonly LOADING = 3;\n static readonly DONE = 4;\n readonly UNSENT = 0;\n readonly OPENED = 1;\n readonly HEADERS_RECEIVED = 2;\n readonly LOADING = 3;\n readonly DONE = 4;\n\n readyState = 0;\n status = 0;\n statusText = \"\";\n responseURL = \"\";\n responseType: XMLHttpRequestResponseType = \"\";\n timeout = 0;\n withCredentials = false;\n readonly upload = new InterceptedXMLHttpRequestUpload();\n readonly responseXML = null;\n\n onreadystatechange: XhrEventHandler = null;\n onloadstart: XhrEventHandler = null;\n onprogress: XhrEventHandler = null;\n onload: XhrEventHandler = null;\n onerror: XhrEventHandler = null;\n onabort: XhrEventHandler = null;\n ontimeout: XhrEventHandler = null;\n onloadend: XhrEventHandler = null;\n\n protected method = \"GET\";\n protected requestUrl = \"\";\n protected requestHeaders = new Headers();\n protected responseHeaders = new Headers();\n protected responseValue: unknown = \"\";\n protected responseTextValue = \"\";\n protected sent = false;\n protected settled = false;\n protected controller: AbortController | undefined;\n protected timer: ReturnType<typeof setTimeout> | undefined;\n\n get response(): unknown {\n if (this.responseType === \"\" || this.responseType === \"text\") return this.responseText;\n return this.readyState === 4 ? this.responseValue : null;\n }\n\n get responseText(): string {\n if (this.responseType !== \"\" && this.responseType !== \"text\") {\n throw invalidState(`responseText is not available for responseType \"${this.responseType}\"`);\n }\n return this.readyState >= 3 ? this.responseTextValue : \"\";\n }\n\n open(method: string, url: string | URL) {\n // A running request is dropped without events, as a browser does.\n if (this.sent && !this.settled) this.settle();\n this.controller?.abort();\n this.controller = undefined;\n this.method = method.toUpperCase();\n this.requestUrl = String(url);\n this.requestHeaders = new Headers();\n this.responseHeaders = new Headers();\n this.responseValue = \"\";\n this.responseTextValue = \"\";\n this.status = 0;\n this.statusText = \"\";\n this.responseURL = \"\";\n this.sent = false;\n this.settled = false;\n this.setReadyState(1);\n }\n\n setRequestHeader(name: string, value: string) {\n if (this.readyState !== 1 || this.sent) throw invalidState(\"setRequestHeader needs an opened, unsent request\");\n this.requestHeaders.append(name, value);\n }\n\n overrideMimeType() {}\n\n getAllResponseHeaders(): string {\n if (this.readyState < 2) return \"\";\n let lines = \"\";\n this.responseHeaders.forEach((value, name) => {\n lines += `${name}: ${value}\\r\\n`;\n });\n return lines;\n }\n\n getResponseHeader(name: string): string | null {\n return this.readyState < 2 ? null : this.responseHeaders.get(name);\n }\n\n send(body?: Document | XMLHttpRequestBodyInit | null) {\n if (this.readyState !== 1 || this.sent) throw invalidState(\"send needs an opened, unsent request\");\n this.sent = true;\n const controller = new AbortController();\n this.controller = controller;\n const passedBody = body === undefined || body === null ? null : (body as BodyInit);\n // A browser sends no body with a GET or HEAD; the handler still sees what the client passed.\n const requestBody = this.method === \"GET\" || this.method === \"HEAD\" ? null : passedBody;\n const headers = new Headers(this.requestHeaders);\n const url = new URL(this.requestUrl, pageOrigin());\n const credentials: RequestCredentials = this.withCredentials ? \"include\" : \"same-origin\";\n const method = this.method;\n const request: InterceptedRequest = {\n method,\n url,\n headers,\n body: passedBody,\n signal: controller.signal,\n transport: \"xhr\",\n forward: () =>\n originalFetch(url.href, {\n method,\n headers: new Headers(headers),\n body: requestBody,\n credentials,\n signal: controller.signal,\n }),\n };\n const responseUrl = url.href;\n if (this.timeout > 0) this.timer = setTimeout(() => this.finishWithoutResponse(\"timeout\"), this.timeout);\n this.emit(\"loadstart\");\n const size = bodySize(requestBody);\n if (requestBody !== null) {\n this.upload.emit(\"loadstart\", 0, size);\n this.upload.emit(\"progress\", size, size);\n this.upload.emit(\"load\", size, size);\n this.upload.emit(\"loadend\", size, size);\n }\n Promise.resolve()\n .then(() => handle(request))\n .then(\n (response) => this.receive(controller, response, responseUrl),\n () => {\n if (this.controller === controller) this.finishWithoutResponse(\"error\");\n },\n );\n }\n\n abort() {\n if (!this.sent || this.settled) return;\n this.finishWithoutResponse(\"abort\");\n this.readyState = 0;\n }\n\n protected async receive(controller: AbortController, response: Response, responseUrl: string) {\n if (this.controller !== controller || this.settled) return;\n try {\n this.status = response.status;\n this.statusText = response.statusText;\n this.responseURL = responseUrl;\n this.responseHeaders = new Headers(response.headers);\n this.setReadyState(2);\n const value = await this.readBody(response);\n if (this.controller !== controller || this.settled) return;\n this.responseValue = value;\n this.setReadyState(3);\n const size = typeof this.responseTextValue === \"string\" ? this.responseTextValue.length : 0;\n this.emit(\"progress\", size, size);\n this.settle();\n this.setReadyState(4);\n this.emit(\"load\", size, size);\n this.emit(\"loadend\", size, size);\n } catch {\n if (this.controller === controller && !this.settled) this.finishWithoutResponse(\"error\");\n }\n }\n\n protected async readBody(response: Response): Promise<unknown> {\n switch (this.responseType) {\n case \"json\": {\n const text = await response.text();\n this.responseTextValue = text;\n try {\n return text === \"\" ? null : JSON.parse(text);\n } catch {\n return null;\n }\n }\n case \"blob\":\n return response.blob();\n case \"arraybuffer\":\n return response.arrayBuffer();\n case \"document\":\n return null;\n default: {\n const text = await response.text();\n this.responseTextValue = text;\n return text;\n }\n }\n }\n\n /** A request that ends without a response — an error, an abort or a timeout: status 0, nothing of a body. */\n protected finishWithoutResponse(type: \"error\" | \"abort\" | \"timeout\") {\n if (this.settled) return;\n this.settle();\n this.controller?.abort();\n this.status = 0;\n this.statusText = \"\";\n this.responseHeaders = new Headers();\n this.responseValue = null;\n this.responseTextValue = \"\";\n this.setReadyState(4);\n this.emit(type);\n this.emit(\"loadend\");\n }\n\n protected settle() {\n this.settled = true;\n if (this.timer !== undefined) clearTimeout(this.timer);\n this.timer = undefined;\n }\n\n protected setReadyState(state: number) {\n this.readyState = state;\n this.emit(\"readystatechange\");\n }\n\n protected emit(type: XhrEventName, loaded = 0, total = 0) {\n const event = type === \"readystatechange\" ? new Event(type) : createProgressEvent(type, loaded, total);\n this.dispatchEvent(event);\n (this[`on${type}` as keyof this] as XhrEventHandler)?.call(this, event);\n }\n };\n\ntype GlobalScope = { fetch?: typeof fetch; XMLHttpRequest?: typeof XMLHttpRequest };\n\n/** The scopes that carry the page's `fetch` and `XMLHttpRequest` (the window and the global object, once each). */\nconst globalScopes = (): GlobalScope[] => {\n const scopes: GlobalScope[] = [globalThis as GlobalScope];\n if (typeof window !== \"undefined\" && (window as unknown) !== globalThis) scopes.push(window as GlobalScope);\n return scopes;\n};\n\n/** The page's `fetch` as it is now (the window's), callable after an install replaced it. */\nconst capturePageFetch = (): typeof fetch => {\n const pageFetch = (typeof window !== \"undefined\" ? window.fetch : globalThis.fetch) as typeof fetch;\n return (input, init) => pageFetch.call(globalThis, input, init);\n};\n\n/** Puts `value` on every global scope under `name` until the returned function restores what was there. */\nconst replaceGlobal = <Name extends keyof GlobalScope>(name: Name, value: GlobalScope[Name]): (() => void) => {\n const saved = globalScopes().map((scope) => ({ scope, value: scope[name] }));\n for (const { scope } of saved) scope[name] = value;\n return () => {\n for (const entry of saved) entry.scope[name] = entry.value;\n };\n};\n\n/**\n * Replaces `XMLHttpRequest` on the page until the returned function is called; `fetch` stays as it is. A handler's\n * `forward()` goes through the page's `fetch` as it was at the install.\n */\nexport const interceptXMLHttpRequests = (handle: InterceptedRequestHandler): (() => void) =>\n replaceGlobal(\n \"XMLHttpRequest\",\n createInterceptedXMLHttpRequest(handle, capturePageFetch()) as unknown as typeof XMLHttpRequest,\n );\n\n/** Replaces `fetch` on the page until the returned function is called; `XMLHttpRequest` stays as it is. */\nexport const interceptFetchRequests = (handle: InterceptedRequestHandler): (() => void) => {\n const originalFetch = capturePageFetch();\n const interceptedFetch = async (input: FetchInput, init?: RequestInit): Promise<Response> =>\n handle(await readFetchRequest(input, init, originalFetch));\n return replaceGlobal(\"fetch\", interceptedFetch as typeof fetch);\n};\n\n/**\n * A `fetch` input this realm's `Request` constructor reads correctly: a `Request` of another realm becomes one of this\n * realm with the same URL, method, headers, body and signal; anything else is returned as it is.\n */\nexport const toSameRealmFetchInput = async (input: FetchInput): Promise<FetchInput> => {\n if (!isFetchRequest(input) || (input as unknown) instanceof Request) return input;\n const foreign: Request = input;\n const body = foreign.body !== null ? await foreign.clone().arrayBuffer() : null;\n return new Request(foreign.url, {\n method: foreign.method,\n headers: new Headers(foreign.headers),\n body,\n // A signal of another realm is not accepted by this realm's constructor.\n signal: fore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M;AACX,eAAW,SAAS,MAAO,OAAM,MAAM,IAAI,IAAI,MAAM;AAAA,EACvD;AACF;AAMO,MAAM,2BAA2B,CAAC,WACvC;AAAA,EACE;AAAA,EACA,gCAAgC,QAAQ,iBAAA,CAAkB;AAC5D;AAGK,MAAM,yBAAyB,CAAC,WAAoD;AACzF,QAAM,gBAAgB,iBAAA;AACtB,QAAM,mBAAmB,OAAO,OAAmB,SACjD,OAAO,MAAM,iBAAiB,OAAO,MAAM,aAAa,CAAC;AAC3D,SAAO,cAAc,SAAS,gBAAgC;AAChE;AAMO,MAAM,wBAAwB,OAAO,UAA2C;AACrF,MAAI,CAAC,eAAe,KAAK,KAAM,iBAA6B,QAAS,QAAO;AAC5E,QAAM,UAAmB;AACzB,QAAM,OAAO,QAAQ,SAAS,OAAO,MAAM,QAAQ,MAAA,EAAQ,YAAA,IAAgB;AAC3E,SAAO,IAAI,QAAQ,QAAQ,KAAK;AAAA,IAC9B,QAAQ,QAAQ;AAAA,IAChB,SAAS,IAAI,QAAQ,QAAQ,OAAO;AAAA,IACpC;AAAA;AAAA,IAEA,QAAQ,QAAQ,kBAAkB,cAAc,QAAQ,SAAS;AAAA,EAAA,CAClE;AACH;"}
@@ -5,9 +5,8 @@ import { G as resolveWidgetName, j as conversationWidgetRegistry } from "./chunk
5
5
  import { H } from "./chunks/widget-name-resolver-BVEuAsW5.js";
6
6
  import { y as ConversationWidgetRenderContext, a6 as WidgetImageReadinessContext, R as ReadOnlyConversationWidgetProvider, a7 as WidgetImageRenderContext, a8 as WidgetImageLiveHydrationContext, z as buildWidgetAgentSpaceKeyProps } from "./chunks/WebSearchResultsConversationWidget-887v8Wen.js";
7
7
  import { a9, aa, ab } from "./chunks/WebSearchResultsConversationWidget-887v8Wen.js";
8
- import { r as readWidgetImageReadiness, p as publishWidgetImageReadiness } from "./chunks/widget-image-readiness-signal-C58JkCQA.js";
9
- import { W, a } from "./chunks/widget-image-readiness-signal-C58JkCQA.js";
10
- import axios from "axios";
8
+ import { r as readWidgetImageReadiness, p as publishWidgetImageReadiness, i as interceptXMLHttpRequests, a as interceptFetchRequests, c as createHeaderlessResponse, t as toSameRealmFetchInput } from "./chunks/browser-request-interception-BdKjYz31.js";
9
+ import { W, b } from "./chunks/browser-request-interception-BdKjYz31.js";
11
10
  import { U as getGoogleMapWidgetNames, X as getWidgetImageCaptureReadPathPrefix } from "./chunks/link-navigation-CNX8Am2L.js";
12
11
  const root = "agents_root_prMo3u";
13
12
  const styles = {
@@ -186,22 +185,6 @@ const createWidgetImageReadiness = (bootstrap) => {
186
185
  };
187
186
  return { ready, observe, fail, isFailed, beginRequest, setHydrationPending };
188
187
  };
189
- const installFrozenWidgetRequests = (responses, fail) => {
190
- const originalAdapter = axios.defaults.adapter;
191
- axios.defaults.adapter = async (config) => {
192
- const url = new URL(axios.getUri(config), window.location.origin);
193
- url.searchParams.sort();
194
- const key = `${(config.method ?? "get").toUpperCase()} ${url.pathname}${url.search}`;
195
- if ((config.method ?? "get").toLowerCase() !== "get" || !Object.prototype.hasOwnProperty.call(responses, key)) {
196
- fail("MISSING_FROZEN_RESPONSE");
197
- throw new Error("MISSING_FROZEN_RESPONSE");
198
- }
199
- return { data: structuredClone(responses[key]), status: 200, statusText: "OK", config, headers: {} };
200
- };
201
- return () => {
202
- axios.defaults.adapter = originalAdapter;
203
- };
204
- };
205
188
  const MAX_TREE_DEPTH = 32;
206
189
  const isMapNodeInValue = (value, depth, googleMapWidgetNames) => {
207
190
  if (depth > MAX_TREE_DEPTH || typeof value !== "object" || value === null) return false;
@@ -224,9 +207,47 @@ const isGoogleMapCapture = (widgetName, props) => {
224
207
  return false;
225
208
  }
226
209
  };
210
+ const isGoogleMapsSdkRequestUrl = (url) => url.protocol === "https:" && (url.hostname === "maps.googleapis.com" && (url.pathname.startsWith("/maps/") || url.pathname.startsWith("/$rpc/")) || url.hostname === "maps.gstatic.com" && url.pathname.startsWith("/mapfiles/"));
227
211
  const STATIC_ASSET_PATH = /^\/react\/(?:app-build|widget-image-build)\/assets\/(?:[\w-]+\/)*[\w.-]+\.(?:svg|png|jpe?g|webp|gif)$/;
212
+ const isStaticBundleImageRequest = (url, method) => url.origin === window.location.origin && STATIC_ASSET_PATH.test(url.pathname) && url.search === "" && method === "GET";
213
+ const frozenRequestKey = (request) => {
214
+ const url = new URL(request.url.href);
215
+ url.searchParams.sort();
216
+ return `${request.method} ${url.pathname}${url.search}`;
217
+ };
218
+ const findFrozenResponse = (responses, request) => {
219
+ const key = frozenRequestKey(request);
220
+ return request.method === "GET" && Object.prototype.hasOwnProperty.call(responses, key) ? { value: responses[key] } : void 0;
221
+ };
222
+ const installFrozenWidgetRequests = (responses, fail, options = {}) => {
223
+ const refuse = () => {
224
+ fail("MISSING_FROZEN_RESPONSE");
225
+ throw new Error("MISSING_FROZEN_RESPONSE");
226
+ };
227
+ const restoreXMLHttpRequest = interceptXMLHttpRequests(async (request) => {
228
+ const frozen = findFrozenResponse(responses, request);
229
+ if (!frozen) return refuse();
230
+ return createHeaderlessResponse(JSON.stringify(frozen.value), 200, "OK");
231
+ });
232
+ const restoreFetch = options.interceptFetch ? interceptFetchRequests(async (request) => {
233
+ const frozen = findFrozenResponse(responses, request);
234
+ if (frozen) {
235
+ return new Response(JSON.stringify(frozen.value), {
236
+ status: 200,
237
+ statusText: "OK",
238
+ headers: { "Content-Type": "application/json" }
239
+ });
240
+ }
241
+ const passesUnanswered = isGoogleMapsSdkRequestUrl(request.url) || isStaticBundleImageRequest(request.url, request.method);
242
+ return passesUnanswered ? request.forward() : refuse();
243
+ }) : () => {
244
+ };
245
+ return () => {
246
+ restoreXMLHttpRequest();
247
+ restoreFetch();
248
+ };
249
+ };
228
250
  const installLiveWidgetRequests = (bootstrap, readiness) => {
229
- const originalAdapter = axios.defaults.adapter;
230
251
  const originalFetch = window.fetch;
231
252
  const fetchRead = originalFetch.bind(window);
232
253
  const isScopedRead = (url, method, hasBody) => Boolean(bootstrap.authToken) && url.origin === window.location.origin && url.pathname.startsWith(getWidgetImageCaptureReadPathPrefix()) && method.toLowerCase() === "get" && !hasBody && !readiness.isFailed() && Date.now() < bootstrap.expiresAt * 1e3;
@@ -250,10 +271,14 @@ const installLiveWidgetRequests = (bootstrap, readiness) => {
250
271
  return response;
251
272
  };
252
273
  window.fetch = async (input, init) => {
253
- const request = new Request(typeof input === "string" ? new URL(input, window.location.origin).href : input, init);
274
+ const sameRealmInput = await toSameRealmFetchInput(input);
275
+ const request = new Request(
276
+ typeof sameRealmInput === "string" ? new URL(sameRealmInput, window.location.origin).href : sameRealmInput,
277
+ init
278
+ );
254
279
  const url = new URL(request.url, window.location.origin);
255
280
  const unavailable = readiness.isFailed() || Date.now() >= bootstrap.expiresAt * 1e3;
256
- const isStaticAsset = url.origin === window.location.origin && STATIC_ASSET_PATH.test(url.pathname) && url.search === "" && request.method === "GET";
281
+ const isStaticAsset = isStaticBundleImageRequest(url, request.method);
257
282
  if (url.origin === window.location.origin && url.pathname.startsWith(getWidgetImageCaptureReadPathPrefix())) {
258
283
  const finish2 = readiness.beginRequest();
259
284
  try {
@@ -279,7 +304,7 @@ const installLiveWidgetRequests = (bootstrap, readiness) => {
279
304
  }
280
305
  }
281
306
  const isMap = isGoogleMapCapture(bootstrap.input.widgetName, bootstrap.input.props);
282
- const isGoogleMapRequest = url.protocol === "https:" && (url.hostname === "maps.googleapis.com" && (url.pathname.startsWith("/maps/") || url.pathname.startsWith("/$rpc/")) || url.hostname === "maps.gstatic.com" && url.pathname.startsWith("/mapfiles/"));
307
+ const isGoogleMapRequest = isGoogleMapsSdkRequestUrl(url);
283
308
  if (!isMap || !isGoogleMapRequest || !["GET", "POST"].includes(request.method) || unavailable) {
284
309
  readiness.fail("UNSCOPED_REQUEST");
285
310
  throw new Error("Unscoped render request");
@@ -306,23 +331,25 @@ const installLiveWidgetRequests = (bootstrap, readiness) => {
306
331
  finish();
307
332
  }
308
333
  };
309
- axios.defaults.adapter = async (config) => {
334
+ const isMapCapture = isGoogleMapCapture(bootstrap.input.widgetName, bootstrap.input.props);
335
+ const restoreXMLHttpRequest = interceptXMLHttpRequests(async (request) => {
336
+ if (isMapCapture && isGoogleMapsSdkRequestUrl(request.url)) return request.forward();
310
337
  const finish = readiness.beginRequest();
311
338
  try {
312
- const url = new URL(axios.getUri(config), window.location.origin);
313
- if (!isScopedRead(url, config.method ?? "get", config.data !== void 0)) throw new Error("RENDER_READ_DENIED");
314
- const response = await readScoped(url, config.signal);
315
- const data = await response.json();
316
- return { data, status: response.status, statusText: "OK", config: {}, headers: {} };
339
+ if (!isScopedRead(request.url, request.method, request.body !== null)) throw new Error("RENDER_READ_DENIED");
340
+ const response = await readScoped(request.url, request.signal);
341
+ const text = await response.text();
342
+ JSON.parse(text);
343
+ return createHeaderlessResponse(text, response.status, "OK");
317
344
  } catch {
318
345
  readiness.fail("WIDGET_HYDRATION_FAILED");
319
- throw { message: "Widget hydration failed", response: { status: 0, data: { error: "Widget hydration failed" } } };
346
+ throw new TypeError("Widget hydration failed");
320
347
  } finally {
321
348
  finish();
322
349
  }
323
- };
350
+ });
324
351
  return () => {
325
- axios.defaults.adapter = originalAdapter;
352
+ restoreXMLHttpRequest();
326
353
  window.fetch = originalFetch;
327
354
  };
328
355
  };
@@ -342,7 +369,7 @@ export {
342
369
  H as readComposedViewDataTimes,
343
370
  a9 as readFrozenHydration,
344
371
  readWidgetImageReadiness,
345
- a as readWidgetImageReadinessGlobalNames,
372
+ b as readWidgetImageReadinessGlobalNames,
346
373
  registerStaticWidgetImageComponents,
347
374
  staticWidgetImageComponents,
348
375
  aa as useWidgetImageLiveHydration,