@mgamadeus/ddd-agents 0.5.16 → 0.6.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.
- package/README.md +170 -6
- package/boundary.json +13 -0
- package/dist/chat.js +148 -773
- package/dist/chat.js.map +1 -1
- package/dist/chunks/{canvas-title-slot-context-DK4sfhkl.js → ConversationMarkdown-BsCjyhj4.js} +14 -43
- package/dist/chunks/ConversationMarkdown-BsCjyhj4.js.map +1 -0
- package/dist/chunks/{ConversationMessageInputComposerWidgets-B3Zf69rD.js → ConversationMessageInputComposerWidgets-CE8LpyXY.js} +10 -37
- package/dist/chunks/ConversationMessageInputComposerWidgets-CE8LpyXY.js.map +1 -0
- package/dist/chunks/VoiceBarsIcon-BIcURsBF.js +643 -0
- package/dist/chunks/VoiceBarsIcon-BIcURsBF.js.map +1 -0
- package/dist/chunks/{WebSearchResultsConversationWidget-887v8Wen.js → WebSearchResultsConversationWidget-DXhfSikV.js} +2 -2
- package/dist/chunks/{WebSearchResultsConversationWidget-887v8Wen.js.map → WebSearchResultsConversationWidget-DXhfSikV.js.map} +1 -1
- package/dist/chunks/browser-request-interception-BnzFbH0m.js +335 -0
- package/dist/chunks/browser-request-interception-BnzFbH0m.js.map +1 -0
- package/dist/chunks/{canvas-reducers-CwFA3rQ6.js → canvas-reducers-D-YxAR4B.js} +2 -2
- package/dist/chunks/{canvas-reducers-CwFA3rQ6.js.map → canvas-reducers-D-YxAR4B.js.map} +1 -1
- package/dist/chunks/canvas-title-slot-context-D6UXrkdJ.js +36 -0
- package/dist/chunks/canvas-title-slot-context-D6UXrkdJ.js.map +1 -0
- package/dist/chunks/{canvasBodies-C7qqThc9.js → canvasBodies-CQEBkIVw.js} +4 -4
- package/dist/chunks/{canvasBodies-C7qqThc9.js.map → canvasBodies-CQEBkIVw.js.map} +1 -1
- package/dist/chunks/{canvasStorage-i2wKVSBf.js → canvasStorage-BbEI3h-8.js} +2 -2
- package/dist/chunks/{canvasStorage-i2wKVSBf.js.map → canvasStorage-BbEI3h-8.js.map} +1 -1
- package/dist/chunks/format-agent-voice-call-duration-C-3hRc9p.js +10 -0
- package/dist/chunks/format-agent-voice-call-duration-C-3hRc9p.js.map +1 -0
- package/dist/chunks/{link-navigation-CNX8Am2L.js → link-navigation-BUcy5qWW.js} +2 -2
- package/dist/chunks/{link-navigation-CNX8Am2L.js.map → link-navigation-BUcy5qWW.js.map} +1 -1
- package/dist/chunks/{realtime-arrival-BTLE3jjt.js → realtime-arrival-BfsAPwqQ.js} +8 -3
- package/dist/chunks/realtime-arrival-BfsAPwqQ.js.map +1 -0
- package/dist/chunks/use-agents-chat-store-CuIkCz9v.js +34 -0
- package/dist/chunks/use-agents-chat-store-CuIkCz9v.js.map +1 -0
- package/dist/chunks/{widget-name-resolver-BVEuAsW5.js → widget-name-resolver-B9k-s_cF.js} +3 -3
- package/dist/chunks/{widget-name-resolver-BVEuAsW5.js.map → widget-name-resolver-B9k-s_cF.js.map} +1 -1
- package/dist/chunks/withPollingChangeSubscription-CnQnubfK.js.map +1 -1
- package/dist/client-testing.js +4 -4
- package/dist/client.js +14 -3
- package/dist/client.js.map +1 -1
- package/dist/files/i18n-keys.json +1128 -100
- package/dist/image-render.js +65 -38
- package/dist/image-render.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/kit.js +2 -2
- package/dist/preview.js +23 -26
- package/dist/preview.js.map +1 -1
- package/dist/provider.js +1 -1
- package/dist/renderer.js +25 -24
- package/dist/renderer.js.map +1 -1
- package/dist/styles.css +531 -93
- package/dist/types/client/AgentsConversationClient.d.ts +4 -1
- package/dist/types/client/http/createAgentsHttpConversationClient.d.ts +2 -1
- package/dist/types/entries/voice-admin.d.ts +7 -0
- package/dist/types/entries/voice.d.ts +24 -0
- package/dist/types/image-render/frozen-widget-requests.d.ts +11 -2
- package/dist/types/image-render/widget-image-google-map.d.ts +5 -0
- package/dist/types/image-render/widget-image-static-assets.d.ts +2 -0
- package/dist/types/preview/widget-preview-requests.d.ts +6 -5
- package/dist/types/request-interception/browser-request-interception.d.ts +48 -0
- package/dist/types/request-interception/intercepted-xml-http-request-upload.d.ts +15 -0
- package/dist/types/ui/account-realtime.d.ts +50 -11
- package/dist/types/voice/AgentVoiceCallBand/AgentVoiceCallBand.d.ts +49 -0
- package/dist/types/voice/AgentVoiceCallBand/agent-voice-call-outcome-title-text-key.d.ts +8 -0
- package/dist/types/voice/AgentVoiceCallCaptions/AgentVoiceCallCaptions.d.ts +15 -0
- package/dist/types/voice/AgentVoiceCallCaptions/saved-messages-of-agent-voice-chat.d.ts +12 -0
- package/dist/types/voice/AgentVoiceCallProvider/AgentVoiceCallProvider.d.ts +21 -0
- package/dist/types/voice/AgentVoiceCallProvider/agent-voice-call-context.d.ts +17 -0
- package/dist/types/voice/AgentVoiceChatStartButton/AgentVoiceChatStartButton.d.ts +15 -0
- package/dist/types/voice/AgentVoiceIcons/AgentVoiceIcons.d.ts +10 -0
- package/dist/types/voice/AgentVoiceIncomingCall/AgentVoiceIncomingCall.d.ts +28 -0
- package/dist/types/voice/AgentVoiceInputGlow/AgentVoiceInputGlow.d.ts +11 -0
- package/dist/types/voice/AgentVoiceInputGlow/agent-voice-input-glow-voice.d.ts +8 -0
- package/dist/types/voice/admin/AgentVoiceCallConversationLink/AgentVoiceCallConversationLink.d.ts +10 -0
- package/dist/types/voice/admin/AgentVoiceCallDetailScreen/AgentVoiceCallDetailScreen.d.ts +27 -0
- package/dist/types/voice/admin/AgentVoiceCallStateBadges/AgentVoiceCallStateBadges.d.ts +12 -0
- package/dist/types/voice/admin/AgentVoiceCallsScreen/AgentVoiceCallsScreen.d.ts +33 -0
- package/dist/types/voice/admin/agent-voice-admin-api.d.ts +59 -0
- package/dist/types/voice/admin/agent-voice-admin-format.d.ts +38 -0
- package/dist/types/voice/admin/agent-voice-admin-types.d.ts +110 -0
- package/dist/types/voice/agent-voice-api.d.ts +114 -0
- package/dist/types/voice/call/agent-voice-call-elapsed-seconds.d.ts +6 -0
- package/dist/types/voice/call/agent-voice-call-end-reasons.d.ts +3 -0
- package/dist/types/voice/call/agent-voice-call-store.d.ts +111 -0
- package/dist/types/voice/call/agent-voice-call-turn.d.ts +4 -0
- package/dist/types/voice/call/build-unsaved-agent-voice-call-lines.d.ts +14 -0
- package/dist/types/voice/call/format-agent-voice-call-duration.d.ts +2 -0
- package/dist/types/voice/call/use-agent-voice-call-elapsed-seconds.d.ts +3 -0
- package/dist/types/voice/call/use-agent-voice-call-server-end.d.ts +15 -0
- package/dist/types/voice/call/use-agent-voice-call.d.ts +12 -0
- package/dist/types/voice/call/use-follow-agent-voice-call-conversation.d.ts +9 -0
- package/dist/types/voice/ring/agent-voice-caller-label.d.ts +21 -0
- package/dist/types/voice/ring/agent-voice-incoming-ring-list.d.ts +10 -0
- package/dist/types/voice/ring/agent-voice-incoming-ring-store.d.ts +47 -0
- package/dist/types/voice/ring/agent-voice-ring-source.d.ts +75 -0
- package/dist/types/voice/ring/agent-voice-ring.d.ts +35 -0
- package/dist/types/voice/ring/answer-incoming-agent-voice-call.d.ts +13 -0
- package/dist/types/voice/ring/use-agent-voice-incoming-rings.d.ts +14 -0
- package/dist/types/voice/ring/use-agent-voice-ring-tone.d.ts +6 -0
- package/dist/ui.js +82 -19
- package/dist/ui.js.map +1 -1
- package/dist/voice-admin.js +738 -0
- package/dist/voice-admin.js.map +1 -0
- package/dist/voice.js +1586 -0
- package/dist/voice.js.map +1 -0
- package/dist/widgets.js +4 -4
- package/package.json +23 -4
- package/public-api.json +156 -0
- package/dist/chunks/ConversationMessageInputComposerWidgets-B3Zf69rD.js.map +0 -1
- package/dist/chunks/canvas-title-slot-context-DK4sfhkl.js.map +0 -1
- package/dist/chunks/realtime-arrival-BTLE3jjt.js.map +0 -1
- package/dist/chunks/widget-image-readiness-signal-C58JkCQA.js +0 -25
- package/dist/chunks/widget-image-readiness-signal-C58JkCQA.js.map +0 -1
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { V as getSandboxLegacyAliases } from "./link-navigation-BUcy5qWW.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-BnzFbH0m.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-request-interception-BnzFbH0m.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: foreign.signal instanceof AbortSignal ? foreign.signal : undefined,\n });\n};\n"],"names":[],"mappings":";;AAIO,MAAM,qCAAqC;AAS3C,MAAM,sCAAsC,MAAgB;AAAA,EACjE;AAAA,EACA,IAAI,wBAAA,EAA0B,6BAA6B,CAAA,GAAI;AAAA,IAC7D,CAAC,cAAc,cAAc;AAAA,EAAA;AAEjC;AAGO,MAAM,8BAA8B,CAAC,cAAsD;AAChG,QAAM,gBAAgB;AACtB,aAAW,cAAc,oCAAA,EAAuC,eAAc,UAAU,IAAI;AAC9F;AAMO,MAAM,2BAA2B,MAAwC;AAC9E,QAAM,gBAAgB;AACtB,QAAM,mBAAmB,oCAAA,EACtB,IAAI,CAAC,eAAe,cAAc,UAAU,CAAC,EAC7C,OAAO,CAAC,WAA2C,WAAW,UAAa,WAAW,IAAI;AAC7F,SAAO,iBAAiB,KAAK,CAAC,WAAW,OAAO,UAAU,QAAQ,KAAK,iBAAiB,CAAC;AAC3F;AC/BO,MAAM,sBAAsB,CAAC,MAAc,QAAgB,UAChE,OAAO,kBAAkB,aACrB,IAAI,cAAc,MAAM,EAAE,kBAAkB,QAAQ,GAAG,QAAQ,OAAO,IACtE,IAAI,MAAM,IAAI;AAGb,MAAM,wCAAwC,YAAY;AAAA,EAA1D,cAAA;AAAA,UAAA,GAAA,SAAA;AACL,SAAA,cAA+B;AAC/B,SAAA,aAA8B;AAC9B,SAAA,SAA0B;AAC1B,SAAA,UAA2B;AAC3B,SAAA,UAA2B;AAC3B,SAAA,YAA6B;AAC7B,SAAA,YAA6B;AAAA,EAAA;AAAA,EAE7B,KAAK,MAAoB,SAAS,GAAG,QAAQ,GAAG;AAC9C,UAAM,QAAQ,oBAAoB,MAAM,QAAQ,KAAK;AACrD,SAAK,cAAc,KAAK;AACvB,SAAK,KAAK,IAAI,EAAgB,GAAuB,KAAK,MAAM,KAAK;AAAA,EAC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,EAAI;AAC3E,aAAW,EAAE,MAAA,KAAW,MAAO,OAAM,IAAI,IAAI;AAC7C,SAAO,MAAM;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;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { s as sameCanvasIdentity, h as canvasBehaviourOf } from "./WebSearchResultsConversationWidget-
|
|
2
|
+
import { s as sameCanvasIdentity, h as canvasBehaviourOf } from "./WebSearchResultsConversationWidget-DXhfSikV.js";
|
|
3
3
|
const ACCEPT = { kind: "accept" };
|
|
4
4
|
const ignore = (reason) => ({ kind: "ignore", reason });
|
|
5
5
|
const decideCanvasOpen = (behaviour, openCanvas, lastClosedCanvas, request) => {
|
|
@@ -84,4 +84,4 @@ export {
|
|
|
84
84
|
applySetCanvasCreatedEntityId as e,
|
|
85
85
|
decideCanvasOpen as f
|
|
86
86
|
};
|
|
87
|
-
//# sourceMappingURL=canvas-reducers-
|
|
87
|
+
//# sourceMappingURL=canvas-reducers-D-YxAR4B.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-reducers-CwFA3rQ6.js","sources":["../../src/renderer/canvas/decide-canvas-open.ts","../../src/renderer/canvas/canvas-reducers.ts"],"sourcesContent":["import type { CanvasBehaviour } from \"./canvas-behaviours\";\nimport { CanvasOpenRequest, CanvasState, LastClosedCanvas, sameCanvasIdentity } from \"./canvas-state\";\n\n/**\n * Why an open request is ignored. Every reason is a sentence the shell could log:\n * - `unknownCanvas` no behaviour is declared for the id (a stale stored pointer, a typo)\n * - `noSurface` the host renders no split (`disableSplitView`), so there is nowhere to open\n * - `replay` a delivery-origin request for a message that was NOT just delivered — history\n * replay, a reload, scroll-back; rejected BEFORE anything is read or written\n * - `alreadyOpen` a delivery-origin request for the identity that is already open (the agent re-emits\n * an editor widget after a rebuild) — the open canvas is kept, never remounted\n * - `customerClosedIt` the customer closed exactly this identity and nothing has cleared the veto yet\n * - `noTakeoverOnNarrowViewport` a live delivery on a narrow viewport of a canvas that declares no overlay — the\n * card stays, the customer taps it\n */\nexport type CanvasOpenIgnoreReason =\n | \"unknownCanvas\"\n | \"noSurface\"\n | \"replay\"\n | \"alreadyOpen\"\n | \"customerClosedIt\"\n | \"noTakeoverOnNarrowViewport\";\n\nexport type CanvasOpenDecision =\n | { readonly kind: \"accept\" }\n | { readonly kind: \"ignore\"; readonly reason: CanvasOpenIgnoreReason };\n\nconst ACCEPT: CanvasOpenDecision = { kind: \"accept\" };\n\nconst ignore = (reason: CanvasOpenIgnoreReason): CanvasOpenDecision => ({ kind: \"ignore\", reason });\n\n/**\n * THE opening rule — the one place that answers \"may this canvas open now?\". Pure: it reads the behaviour, the open\n * canvas, the last closed one and the request, and returns Accept or Ignore. It never mutates; the reducer\n * (`canvas-reducers.ts`) applies an Accept. There is no merge rung: the same identity opened again from a card click\n * is a fresh Accept (remount), and the refresh contract of a pinned work surface is a value the body derives from the\n * message list, not a reducer merge.\n *\n * A `widgetClick`, an `openedByPage` and a `restoredAfterReload` request always open (the customer, the page or the\n * stored pointer decided); only `deliveredInMessage` is judged.\n */\nexport const decideCanvasOpen = (\n behaviour: CanvasBehaviour | undefined,\n openCanvas: CanvasState | null,\n lastClosedCanvas: LastClosedCanvas | null,\n request: CanvasOpenRequest,\n): CanvasOpenDecision => {\n if (behaviour === undefined) return ignore(\"unknownCanvas\");\n if (!request.hostHasCanvasSurface) return ignore(\"noSurface\");\n if (request.origin !== \"deliveredInMessage\") return ACCEPT;\n\n // Replay is rejected first: a replayed message must not touch the open canvas in any way.\n if (!request.justDelivered) return ignore(\"replay\");\n if (openCanvas !== null && sameCanvasIdentity(openCanvas, request)) return ignore(\"alreadyOpen\");\n if (lastClosedCanvas !== null && lastClosedCanvas.closedByCustomer && sameCanvasIdentity(lastClosedCanvas, request)) {\n return ignore(\"customerClosedIt\");\n }\n if (!request.viewportViable && behaviour.narrowViewport === \"none\") return ignore(\"noTakeoverOnNarrowViewport\");\n return ACCEPT;\n};\n","import { canvasBehaviourOf } from \"./canvas-behaviours\";\nimport { CanvasOpenRequest, CanvasState, LastClosedCanvas, sameCanvasIdentity } from \"./canvas-state\";\nimport { CanvasOpenDecision, decideCanvasOpen } from \"./decide-canvas-open\";\n\n/**\n * The canvas part of a chat slice partition — the two fields every transition reads and writes. Both chat doors carry\n * them (`ConversationState`); the shell is shared, so the state must have the same shape in both partitions.\n */\nexport interface CanvasSliceState {\n canvas: CanvasState | null;\n lastClosedCanvas: LastClosedCanvas | null;\n /**\n * How many canvases this partition has mounted so far — the source of `mountGeneration`. Never reset by a close,\n * a send or a clear (and exempt from `resetState`), so a late asynchronous write from a body that was replaced,\n * cleared or belonged to the previous conversation can never match a new canvas's generation.\n */\n canvasMountCount: number;\n}\n\n/**\n * The lifetime state machine as REDUCERS. Hand-written, not generated setters:\n * a generated setter is a blind overwrite of a snapshot the caller read a render earlier, and two opens in one commit\n * would both see the same stale state. Each function mutates the Immer draft it receives and returns the decision it\n * applied, so the slice can expose them as case reducers and a spec can assert every transition on a plain object.\n */\n\nconst toLastClosed = (canvas: CanvasState, closedByCustomer: boolean): LastClosedCanvas => ({\n canvasId: canvas.canvasId,\n instanceId: canvas.instanceId,\n anchor: canvas.anchor,\n mountGeneration: canvas.mountGeneration,\n closedByCustomer,\n ...(canvas.createdEntityId !== undefined ? { createdEntityId: canvas.createdEntityId } : {}),\n});\n\n/** Next render key: strictly increasing for the partition's lifetime, so no two mounts ever share a generation. */\nconst nextMountGeneration = (state: CanvasSliceState): number => {\n state.canvasMountCount += 1;\n return state.canvasMountCount;\n};\n\n/**\n * Open a canvas — the ONE way to open, for all four origins. On Accept: the replaced canvas (a different identity)\n * becomes `lastClosedCanvas`; a `lastClosedCanvas` of the accepted identity is consumed (its veto is cleared — the\n * customer, the page or the restore decided to have it back); the created entity survives a re-open of the same\n * identity so a restored editor keeps its draft.\n */\nexport const applyOpenCanvas = (state: CanvasSliceState, request: CanvasOpenRequest): CanvasOpenDecision => {\n const decision = decideCanvasOpen(canvasBehaviourOf(request.canvasId), state.canvas, state.lastClosedCanvas, request);\n if (decision.kind === \"ignore\") return decision;\n\n const previous = state.canvas;\n const mountGeneration = nextMountGeneration(state);\n const carriedCreatedEntityId =\n request.createdEntityId ??\n (previous !== null && sameCanvasIdentity(previous, request) ? previous.createdEntityId : undefined) ??\n (state.lastClosedCanvas !== null && sameCanvasIdentity(state.lastClosedCanvas, request)\n ? state.lastClosedCanvas.createdEntityId\n : undefined);\n\n if (previous !== null && !sameCanvasIdentity(previous, request)) {\n state.lastClosedCanvas = toLastClosed(previous, false);\n } else if (state.lastClosedCanvas !== null && sameCanvasIdentity(state.lastClosedCanvas, request)) {\n state.lastClosedCanvas = null;\n }\n state.canvas = {\n canvasId: request.canvasId,\n instanceId: request.instanceId,\n anchor: request.anchor,\n origin: request.origin,\n mountGeneration,\n ...(carriedCreatedEntityId !== undefined ? { createdEntityId: carriedCreatedEntityId } : {}),\n };\n return decision;\n};\n\n/**\n * Close the open canvas but keep it re-openable: it becomes `lastClosedCanvas`. `byCustomer` marks the customer's own\n * close (the canvas close control) — a live delivery of the same identity is then ignored until a send, a card click\n * or a page hand-over. A shell-driven close (compact mode, the side panel opening, a narrow crossing) passes false.\n */\nexport const applyCloseCanvas = (state: CanvasSliceState, byCustomer: boolean): void => {\n if (state.canvas === null) return;\n state.lastClosedCanvas = toLastClosed(state.canvas, byCustomer);\n state.canvas = null;\n};\n\n/**\n * The SEND boundary: a new user message starts a new turn. A `turn` canvas is over for good — it leaves the open slot\n * AND `lastClosedCanvas` (the card in the transcript is the way back). A `pinned` canvas stays open,\n * and a closed pinned one stays re-openable with its customer veto cleared (the send is a clearing edge).\n */\nexport const applyResetCanvasForNewTurn = (state: CanvasSliceState): void => {\n if (state.canvas !== null && canvasBehaviourOf(state.canvas.canvasId)?.lifetime === \"turn\") {\n state.canvas = null;\n }\n if (state.lastClosedCanvas !== null) {\n if (canvasBehaviourOf(state.lastClosedCanvas.canvasId)?.lifetime === \"turn\") {\n state.lastClosedCanvas = null;\n } else if (state.lastClosedCanvas.closedByCustomer) {\n state.lastClosedCanvas = { ...state.lastClosedCanvas, closedByCustomer: false };\n }\n }\n};\n\n/** Forget the canvas entirely — a conversation switch, `closeAgent`, the modal unmount. Nothing is re-openable. */\nexport const applyClearCanvas = (state: CanvasSliceState): void => {\n state.canvas = null;\n state.lastClosedCanvas = null;\n};\n\nexport interface CanvasCreatedEntity {\n readonly canvasId: CanvasState[\"canvasId\"];\n readonly instanceId: string;\n /** The generation the body was mounted with — a late write from a body that was replaced meanwhile is dropped. */\n readonly mountGeneration: number;\n readonly createdEntityId: number;\n}\n\n/** A body created its entity (the post editor's draft): remember the id on the canvas it was created for. */\nexport const applySetCanvasCreatedEntityId = (state: CanvasSliceState, created: CanvasCreatedEntity): boolean => {\n const canvas = state.canvas;\n if (canvas === null || !sameCanvasIdentity(canvas, created) || canvas.mountGeneration !== created.mountGeneration) {\n return false;\n }\n state.canvas = { ...canvas, createdEntityId: created.createdEntityId };\n return true;\n};\n"],"names":[],"mappings":";;AA2BA,MAAM,SAA6B,EAAE,MAAM,SAAA;AAE3C,MAAM,SAAS,CAAC,YAAwD,EAAE,MAAM,UAAU,OAAA;AAYnF,MAAM,mBAAmB,CAC9B,WACA,YACA,kBACA,YACuB;AACvB,MAAI,cAAc,OAAW,QAAO,OAAO,eAAe;AAC1D,MAAI,CAAC,QAAQ,qBAAsB,QAAO,OAAO,WAAW;AAC5D,MAAI,QAAQ,WAAW,qBAAsB,QAAO;AAGpD,MAAI,CAAC,QAAQ,cAAe,QAAO,OAAO,QAAQ;AAClD,MAAI,eAAe,QAAQ,mBAAmB,YAAY,OAAO,EAAG,QAAO,OAAO,aAAa;AAC/F,MAAI,qBAAqB,QAAQ,iBAAiB,oBAAoB,mBAAmB,kBAAkB,OAAO,GAAG;AACnH,WAAO,OAAO,kBAAkB;AAAA,EAClC;AACA,MAAI,CAAC,QAAQ,kBAAkB,UAAU,mBAAmB,OAAQ,QAAO,OAAO,4BAA4B;AAC9G,SAAO;AACT;ACjCA,MAAM,eAAe,CAAC,QAAqB,sBAAiD;AAAA,EAC1F,UAAU,OAAO;AAAA,EACjB,YAAY,OAAO;AAAA,EACnB,QAAQ,OAAO;AAAA,EACf,iBAAiB,OAAO;AAAA,EACxB;AAAA,EACA,GAAI,OAAO,oBAAoB,SAAY,EAAE,iBAAiB,OAAO,oBAAoB,CAAA;AAC3F;AAGA,MAAM,sBAAsB,CAAC,UAAoC;AAC/D,QAAM,oBAAoB;AAC1B,SAAO,MAAM;AACf;AAQO,MAAM,kBAAkB,CAAC,OAAyB,YAAmD;AAC1G,QAAM,WAAW,iBAAiB,kBAAkB,QAAQ,QAAQ,GAAG,MAAM,QAAQ,MAAM,kBAAkB,OAAO;AACpH,MAAI,SAAS,SAAS,SAAU,QAAO;AAEvC,QAAM,WAAW,MAAM;AACv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mBAAmB;AAC3B;AAWO,MAAM,gCAAgC,CAAC,OAAyB,YAA0C;AAC/G,QAAM,SAAS,MAAM;AACrB,MAAI,WAAW,QAAQ,CAAC,mBAAmB,QAAQ,OAAO,KAAK,OAAO,oBAAoB,QAAQ,iBAAiB;AACjH,WAAO;AAAA,EACT;AACA,QAAM,SAAS,EAAE,GAAG,QAAQ,iBAAiB,QAAQ,gBAAA;AACrD,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"canvas-reducers-D-YxAR4B.js","sources":["../../src/renderer/canvas/decide-canvas-open.ts","../../src/renderer/canvas/canvas-reducers.ts"],"sourcesContent":["import type { CanvasBehaviour } from \"./canvas-behaviours\";\nimport { CanvasOpenRequest, CanvasState, LastClosedCanvas, sameCanvasIdentity } from \"./canvas-state\";\n\n/**\n * Why an open request is ignored. Every reason is a sentence the shell could log:\n * - `unknownCanvas` no behaviour is declared for the id (a stale stored pointer, a typo)\n * - `noSurface` the host renders no split (`disableSplitView`), so there is nowhere to open\n * - `replay` a delivery-origin request for a message that was NOT just delivered — history\n * replay, a reload, scroll-back; rejected BEFORE anything is read or written\n * - `alreadyOpen` a delivery-origin request for the identity that is already open (the agent re-emits\n * an editor widget after a rebuild) — the open canvas is kept, never remounted\n * - `customerClosedIt` the customer closed exactly this identity and nothing has cleared the veto yet\n * - `noTakeoverOnNarrowViewport` a live delivery on a narrow viewport of a canvas that declares no overlay — the\n * card stays, the customer taps it\n */\nexport type CanvasOpenIgnoreReason =\n | \"unknownCanvas\"\n | \"noSurface\"\n | \"replay\"\n | \"alreadyOpen\"\n | \"customerClosedIt\"\n | \"noTakeoverOnNarrowViewport\";\n\nexport type CanvasOpenDecision =\n | { readonly kind: \"accept\" }\n | { readonly kind: \"ignore\"; readonly reason: CanvasOpenIgnoreReason };\n\nconst ACCEPT: CanvasOpenDecision = { kind: \"accept\" };\n\nconst ignore = (reason: CanvasOpenIgnoreReason): CanvasOpenDecision => ({ kind: \"ignore\", reason });\n\n/**\n * THE opening rule — the one place that answers \"may this canvas open now?\". Pure: it reads the behaviour, the open\n * canvas, the last closed one and the request, and returns Accept or Ignore. It never mutates; the reducer\n * (`canvas-reducers.ts`) applies an Accept. There is no merge rung: the same identity opened again from a card click\n * is a fresh Accept (remount), and the refresh contract of a pinned work surface is a value the body derives from the\n * message list, not a reducer merge.\n *\n * A `widgetClick`, an `openedByPage` and a `restoredAfterReload` request always open (the customer, the page or the\n * stored pointer decided); only `deliveredInMessage` is judged.\n */\nexport const decideCanvasOpen = (\n behaviour: CanvasBehaviour | undefined,\n openCanvas: CanvasState | null,\n lastClosedCanvas: LastClosedCanvas | null,\n request: CanvasOpenRequest,\n): CanvasOpenDecision => {\n if (behaviour === undefined) return ignore(\"unknownCanvas\");\n if (!request.hostHasCanvasSurface) return ignore(\"noSurface\");\n if (request.origin !== \"deliveredInMessage\") return ACCEPT;\n\n // Replay is rejected first: a replayed message must not touch the open canvas in any way.\n if (!request.justDelivered) return ignore(\"replay\");\n if (openCanvas !== null && sameCanvasIdentity(openCanvas, request)) return ignore(\"alreadyOpen\");\n if (lastClosedCanvas !== null && lastClosedCanvas.closedByCustomer && sameCanvasIdentity(lastClosedCanvas, request)) {\n return ignore(\"customerClosedIt\");\n }\n if (!request.viewportViable && behaviour.narrowViewport === \"none\") return ignore(\"noTakeoverOnNarrowViewport\");\n return ACCEPT;\n};\n","import { canvasBehaviourOf } from \"./canvas-behaviours\";\nimport { CanvasOpenRequest, CanvasState, LastClosedCanvas, sameCanvasIdentity } from \"./canvas-state\";\nimport { CanvasOpenDecision, decideCanvasOpen } from \"./decide-canvas-open\";\n\n/**\n * The canvas part of a chat slice partition — the two fields every transition reads and writes. Both chat doors carry\n * them (`ConversationState`); the shell is shared, so the state must have the same shape in both partitions.\n */\nexport interface CanvasSliceState {\n canvas: CanvasState | null;\n lastClosedCanvas: LastClosedCanvas | null;\n /**\n * How many canvases this partition has mounted so far — the source of `mountGeneration`. Never reset by a close,\n * a send or a clear (and exempt from `resetState`), so a late asynchronous write from a body that was replaced,\n * cleared or belonged to the previous conversation can never match a new canvas's generation.\n */\n canvasMountCount: number;\n}\n\n/**\n * The lifetime state machine as REDUCERS. Hand-written, not generated setters:\n * a generated setter is a blind overwrite of a snapshot the caller read a render earlier, and two opens in one commit\n * would both see the same stale state. Each function mutates the Immer draft it receives and returns the decision it\n * applied, so the slice can expose them as case reducers and a spec can assert every transition on a plain object.\n */\n\nconst toLastClosed = (canvas: CanvasState, closedByCustomer: boolean): LastClosedCanvas => ({\n canvasId: canvas.canvasId,\n instanceId: canvas.instanceId,\n anchor: canvas.anchor,\n mountGeneration: canvas.mountGeneration,\n closedByCustomer,\n ...(canvas.createdEntityId !== undefined ? { createdEntityId: canvas.createdEntityId } : {}),\n});\n\n/** Next render key: strictly increasing for the partition's lifetime, so no two mounts ever share a generation. */\nconst nextMountGeneration = (state: CanvasSliceState): number => {\n state.canvasMountCount += 1;\n return state.canvasMountCount;\n};\n\n/**\n * Open a canvas — the ONE way to open, for all four origins. On Accept: the replaced canvas (a different identity)\n * becomes `lastClosedCanvas`; a `lastClosedCanvas` of the accepted identity is consumed (its veto is cleared — the\n * customer, the page or the restore decided to have it back); the created entity survives a re-open of the same\n * identity so a restored editor keeps its draft.\n */\nexport const applyOpenCanvas = (state: CanvasSliceState, request: CanvasOpenRequest): CanvasOpenDecision => {\n const decision = decideCanvasOpen(canvasBehaviourOf(request.canvasId), state.canvas, state.lastClosedCanvas, request);\n if (decision.kind === \"ignore\") return decision;\n\n const previous = state.canvas;\n const mountGeneration = nextMountGeneration(state);\n const carriedCreatedEntityId =\n request.createdEntityId ??\n (previous !== null && sameCanvasIdentity(previous, request) ? previous.createdEntityId : undefined) ??\n (state.lastClosedCanvas !== null && sameCanvasIdentity(state.lastClosedCanvas, request)\n ? state.lastClosedCanvas.createdEntityId\n : undefined);\n\n if (previous !== null && !sameCanvasIdentity(previous, request)) {\n state.lastClosedCanvas = toLastClosed(previous, false);\n } else if (state.lastClosedCanvas !== null && sameCanvasIdentity(state.lastClosedCanvas, request)) {\n state.lastClosedCanvas = null;\n }\n state.canvas = {\n canvasId: request.canvasId,\n instanceId: request.instanceId,\n anchor: request.anchor,\n origin: request.origin,\n mountGeneration,\n ...(carriedCreatedEntityId !== undefined ? { createdEntityId: carriedCreatedEntityId } : {}),\n };\n return decision;\n};\n\n/**\n * Close the open canvas but keep it re-openable: it becomes `lastClosedCanvas`. `byCustomer` marks the customer's own\n * close (the canvas close control) — a live delivery of the same identity is then ignored until a send, a card click\n * or a page hand-over. A shell-driven close (compact mode, the side panel opening, a narrow crossing) passes false.\n */\nexport const applyCloseCanvas = (state: CanvasSliceState, byCustomer: boolean): void => {\n if (state.canvas === null) return;\n state.lastClosedCanvas = toLastClosed(state.canvas, byCustomer);\n state.canvas = null;\n};\n\n/**\n * The SEND boundary: a new user message starts a new turn. A `turn` canvas is over for good — it leaves the open slot\n * AND `lastClosedCanvas` (the card in the transcript is the way back). A `pinned` canvas stays open,\n * and a closed pinned one stays re-openable with its customer veto cleared (the send is a clearing edge).\n */\nexport const applyResetCanvasForNewTurn = (state: CanvasSliceState): void => {\n if (state.canvas !== null && canvasBehaviourOf(state.canvas.canvasId)?.lifetime === \"turn\") {\n state.canvas = null;\n }\n if (state.lastClosedCanvas !== null) {\n if (canvasBehaviourOf(state.lastClosedCanvas.canvasId)?.lifetime === \"turn\") {\n state.lastClosedCanvas = null;\n } else if (state.lastClosedCanvas.closedByCustomer) {\n state.lastClosedCanvas = { ...state.lastClosedCanvas, closedByCustomer: false };\n }\n }\n};\n\n/** Forget the canvas entirely — a conversation switch, `closeAgent`, the modal unmount. Nothing is re-openable. */\nexport const applyClearCanvas = (state: CanvasSliceState): void => {\n state.canvas = null;\n state.lastClosedCanvas = null;\n};\n\nexport interface CanvasCreatedEntity {\n readonly canvasId: CanvasState[\"canvasId\"];\n readonly instanceId: string;\n /** The generation the body was mounted with — a late write from a body that was replaced meanwhile is dropped. */\n readonly mountGeneration: number;\n readonly createdEntityId: number;\n}\n\n/** A body created its entity (the post editor's draft): remember the id on the canvas it was created for. */\nexport const applySetCanvasCreatedEntityId = (state: CanvasSliceState, created: CanvasCreatedEntity): boolean => {\n const canvas = state.canvas;\n if (canvas === null || !sameCanvasIdentity(canvas, created) || canvas.mountGeneration !== created.mountGeneration) {\n return false;\n }\n state.canvas = { ...canvas, createdEntityId: created.createdEntityId };\n return true;\n};\n"],"names":[],"mappings":";;AA2BA,MAAM,SAA6B,EAAE,MAAM,SAAA;AAE3C,MAAM,SAAS,CAAC,YAAwD,EAAE,MAAM,UAAU,OAAA;AAYnF,MAAM,mBAAmB,CAC9B,WACA,YACA,kBACA,YACuB;AACvB,MAAI,cAAc,OAAW,QAAO,OAAO,eAAe;AAC1D,MAAI,CAAC,QAAQ,qBAAsB,QAAO,OAAO,WAAW;AAC5D,MAAI,QAAQ,WAAW,qBAAsB,QAAO;AAGpD,MAAI,CAAC,QAAQ,cAAe,QAAO,OAAO,QAAQ;AAClD,MAAI,eAAe,QAAQ,mBAAmB,YAAY,OAAO,EAAG,QAAO,OAAO,aAAa;AAC/F,MAAI,qBAAqB,QAAQ,iBAAiB,oBAAoB,mBAAmB,kBAAkB,OAAO,GAAG;AACnH,WAAO,OAAO,kBAAkB;AAAA,EAClC;AACA,MAAI,CAAC,QAAQ,kBAAkB,UAAU,mBAAmB,OAAQ,QAAO,OAAO,4BAA4B;AAC9G,SAAO;AACT;ACjCA,MAAM,eAAe,CAAC,QAAqB,sBAAiD;AAAA,EAC1F,UAAU,OAAO;AAAA,EACjB,YAAY,OAAO;AAAA,EACnB,QAAQ,OAAO;AAAA,EACf,iBAAiB,OAAO;AAAA,EACxB;AAAA,EACA,GAAI,OAAO,oBAAoB,SAAY,EAAE,iBAAiB,OAAO,oBAAoB,CAAA;AAC3F;AAGA,MAAM,sBAAsB,CAAC,UAAoC;AAC/D,QAAM,oBAAoB;AAC1B,SAAO,MAAM;AACf;AAQO,MAAM,kBAAkB,CAAC,OAAyB,YAAmD;AAC1G,QAAM,WAAW,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mB,EAAE,GAAG,MAAM,kBAAkB,kBAAkB,MAAA;AAAA,IAC1E;AAAA,EACF;AACF;AAGO,MAAM,mBAAmB,CAAC,UAAkC;AACjE,QAAM,SAAS;AACf,QAAM,mBAAmB;AAC3B;AAWO,MAAM,gCAAgC,CAAC,OAAyB,YAA0C;AAC/G,QAAM,SAAS,MAAM;AACrB,MAAI,WAAW,QAAQ,CAAC,mBAAmB,QAAQ,OAAO,KAAK,OAAO,oBAAoB,QAAQ,iBAAiB;AACjH,WAAO;AAAA,EACT;AACA,QAAM,SAAS,EAAE,GAAG,QAAQ,iBAAiB,QAAQ,gBAAA;AACrD,SAAO;AACT;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { j as conversationWidgetRegistry } from "./widget-name-resolver-B9k-s_cF.js";
|
|
3
|
+
import { Q as getFurtherWidgetClickSignalSources } from "./link-navigation-BUcy5qWW.js";
|
|
4
|
+
import { createContext, useContext } from "react";
|
|
5
|
+
const resolveDeepLinkableWidget = (widgetName) => {
|
|
6
|
+
if (!widgetName) return null;
|
|
7
|
+
return conversationWidgetRegistry.widgets.find((entry) => entry.name === widgetName && entry.deepLinkable === true) ?? null;
|
|
8
|
+
};
|
|
9
|
+
const deepLinkableWidgetNameForCanvas = (canvasId) => {
|
|
10
|
+
if (!canvasId) return null;
|
|
11
|
+
return conversationWidgetRegistry.widgets.find(
|
|
12
|
+
(entry) => entry.deepLinkable === true && entry.opensCanvases?.includes(canvasId)
|
|
13
|
+
)?.name ?? null;
|
|
14
|
+
};
|
|
15
|
+
const FRONTEND_WIDGET_CLICK_SIGNAL_SOURCE = "FRONTEND_WIDGET_CLICK";
|
|
16
|
+
const OWNER_ACTION_CONFIRM_SIGNAL_SOURCE = "OWNER_ACTION_CONFIRM";
|
|
17
|
+
const PACKAGE_WIDGET_CLICK_SIGNAL_SOURCES = [
|
|
18
|
+
FRONTEND_WIDGET_CLICK_SIGNAL_SOURCE,
|
|
19
|
+
OWNER_ACTION_CONFIRM_SIGNAL_SOURCE
|
|
20
|
+
];
|
|
21
|
+
const getWidgetClickSignalSources = () => [
|
|
22
|
+
...PACKAGE_WIDGET_CLICK_SIGNAL_SOURCES,
|
|
23
|
+
...getFurtherWidgetClickSignalSources()
|
|
24
|
+
];
|
|
25
|
+
const isWidgetClickSignalSource = (signalSource) => signalSource != null && getWidgetClickSignalSources().includes(signalSource);
|
|
26
|
+
const CanvasTitleSlotContext = createContext(null);
|
|
27
|
+
const useCanvasTitleSlot = () => useContext(CanvasTitleSlotContext);
|
|
28
|
+
export {
|
|
29
|
+
CanvasTitleSlotContext as C,
|
|
30
|
+
deepLinkableWidgetNameForCanvas as d,
|
|
31
|
+
getWidgetClickSignalSources as g,
|
|
32
|
+
isWidgetClickSignalSource as i,
|
|
33
|
+
resolveDeepLinkableWidget as r,
|
|
34
|
+
useCanvasTitleSlot as u
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=canvas-title-slot-context-D6UXrkdJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-title-slot-context-D6UXrkdJ.js","sources":["../../src/renderer/resolve-deep-linkable-widget.ts","../../src/renderer/widget-click-signal-sources.ts","../../src/renderer/canvas/canvas-title-slot-context.ts"],"sourcesContent":["import type { CanvasId } from \"./canvas/canvas-behaviours\";\nimport { ConversationWidgetEntry, conversationWidgetRegistry } from \"./conversationWidgetRegistry\";\n\n/**\n * Resolves the widget a `?agentWidget=<name>` deep-link (or a restored pinned canvas) may mount, by its CANONICAL\n * registry wire name.\n *\n * A URL is untrusted input, so this is an allow-list rather than a registry lookup: only an entry that declares\n * `deepLinkable: true` can be opened this way. Every other widget is emitted by the agent inside a message, where the\n * conversation itself is the authorisation — a link must not be able to mount an arbitrary widget (some carry\n * mount-time side effects) just because its name was typed into the address bar.\n *\n * Returns the entry (the caller renders its `component`, applying the feature gate the entry declares) or null when the\n * name is empty, unknown, or not deep-linkable.\n */\nexport const resolveDeepLinkableWidget = (widgetName?: string | null): ConversationWidgetEntry | null => {\n if (!widgetName) return null;\n return (\n conversationWidgetRegistry.widgets.find((entry) => entry.name === widgetName && entry.deepLinkable === true) ?? null\n );\n};\n\n/**\n * The reverse direction: which deep-linkable widget re-opens THIS canvas. The open canvas of the agent chat is\n * mirrored into `?agentWidget=` (AgentTrigger) so a reload brings the customer back to the surface they were working\n * on — an editor a cold chat opened has no conversation id yet, so the canvas model's own pointer storage\n * has nothing to restore from.\n *\n * Null for every canvas no deep-linkable widget declares: it is the agent's to open inside a message, and a URL must\n * not be able to mount it (the allow-list above).\n */\nexport const deepLinkableWidgetNameForCanvas = (canvasId: CanvasId | null | undefined): string | null => {\n if (!canvasId) return null;\n return (\n conversationWidgetRegistry.widgets.find(\n (entry) => entry.deepLinkable === true && entry.opensCanvases?.includes(canvasId),\n )?.name ?? null\n );\n};\n","import { getFurtherWidgetClickSignalSources } from \"../provider/environment\";\n\n/**\n * The `signalSource`s a widget CLICK posts into the conversation (`injectSignal`): the generic widget click and the\n * dedicated source the former owner-action consent widget sent (no component posts it any more; stored rows keep it),\n * plus the further sources an app's own widgets post (`AgentsEnvironment.furtherWidgetClickSignalSources`, e.g. a form\n * submit that starts its own owner turn). The message list reads them to tell an answered widget from an open one after\n * a reload — a widget the owner already clicked must never come back interactive (a consent widget re-armed is a second\n * confirmation for a destructive tool). Add a source here when a widget of the package starts posting a new one.\n */\nexport const FRONTEND_WIDGET_CLICK_SIGNAL_SOURCE = \"FRONTEND_WIDGET_CLICK\";\nexport const OWNER_ACTION_CONFIRM_SIGNAL_SOURCE = \"OWNER_ACTION_CONFIRM\";\n\n/** The package's own widget click sources (the backend's sources of the package that carry an owner statement). */\nexport const PACKAGE_WIDGET_CLICK_SIGNAL_SOURCES: readonly string[] = [\n FRONTEND_WIDGET_CLICK_SIGNAL_SOURCE,\n OWNER_ACTION_CONFIRM_SIGNAL_SOURCE,\n];\n\n/** Every widget click source: the package's own and the app's further ones. */\nexport const getWidgetClickSignalSources = (): readonly string[] => [\n ...PACKAGE_WIDGET_CLICK_SIGNAL_SOURCES,\n ...getFurtherWidgetClickSignalSources(),\n];\n\nexport const isWidgetClickSignalSource = (signalSource: string | undefined | null): boolean =>\n signalSource != null && getWidgetClickSignalSources().includes(signalSource);\n","import { createContext, useContext } from \"react\";\n\n/**\n * The place beside the canvas pane's close button, for a canvas whose behaviour declares `titleBesideCloseButton`:\n * its body portals its title there. Null outside a canvas pane and for every other canvas.\n */\nexport const CanvasTitleSlotContext = createContext<HTMLElement | null>(null);\n\nexport const useCanvasTitleSlot = (): HTMLElement | null => useContext(CanvasTitleSlotContext);\n"],"names":[],"mappings":";;;;AAeO,MAAM,4BAA4B,CAAC,eAA+D;AACvG,MAAI,CAAC,WAAY,QAAO;AACxB,SACE,2BAA2B,QAAQ,KAAK,CAAC,UAAU,MAAM,SAAS,cAAc,MAAM,iBAAiB,IAAI,KAAK;AAEpH;AAWO,MAAM,kCAAkC,CAAC,aAAyD;AACvG,MAAI,CAAC,SAAU,QAAO;AACtB,SACE,2BAA2B,QAAQ;AAAA,IACjC,CAAC,UAAU,MAAM,iBAAiB,QAAQ,MAAM,eAAe,SAAS,QAAQ;AAAA,EAAA,GAC/E,QAAQ;AAEf;AC5BO,MAAM,sCAAsC;AAC5C,MAAM,qCAAqC;AAG3C,MAAM,sCAAyD;AAAA,EACpE;AAAA,EACA;AACF;AAGO,MAAM,8BAA8B,MAAyB;AAAA,EAClE,GAAG;AAAA,EACH,GAAG,mCAAA;AACL;AAEO,MAAM,4BAA4B,CAAC,iBACxC,gBAAgB,QAAQ,4BAAA,EAA8B,SAAS,YAAY;ACpBtE,MAAM,yBAAyB,cAAkC,IAAI;AAErE,MAAM,qBAAqB,MAA0B,WAAW,sBAAsB;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useMemo, useCallback, useContext, createContext, useState } from "react";
|
|
4
|
-
import { p as payloadHashOfInstanceId, a0 as useConversationWidgetContext, b6 as parseConversationSearchResultsPayload, b7 as WebSearchAnswer, b8 as WebSearchSourcesList, b9 as parseWebSearchResultsPayload, ba as ENTITY_MENTION_WIDGET_NAME, bb as buildEntityMentionFields, bc as normalizeEntityMentionFields, bd as entityMentionKey, be as MAX_ENTITY_MENTIONS_PER_MESSAGE, bf as toEntityMentionWireFields, a1 as useIsEmailWidgetRender, bg as ConversationWidgetButton } from "./WebSearchResultsConversationWidget-
|
|
5
|
-
import { m as findWidgetFenceByPayloadHash, n as findWidgetFencesInMarkdown, I as readEntityDetailInstanceId, J as readMapNodeKeyOfInstanceId, K as findMapNodeInMarkdown, D as readOpenEntityActionTarget, L as canvasInstanceIdForEntityDetail, M as mapStyles, N as MapPresentationContext, e as ComposedViewRenderer } from "./widget-name-resolver-
|
|
6
|
-
import { s as Text, b as ConversationSearchResultsList, a5 as useAgentsEnvironment } from "./link-navigation-
|
|
4
|
+
import { p as payloadHashOfInstanceId, a0 as useConversationWidgetContext, b6 as parseConversationSearchResultsPayload, b7 as WebSearchAnswer, b8 as WebSearchSourcesList, b9 as parseWebSearchResultsPayload, ba as ENTITY_MENTION_WIDGET_NAME, bb as buildEntityMentionFields, bc as normalizeEntityMentionFields, bd as entityMentionKey, be as MAX_ENTITY_MENTIONS_PER_MESSAGE, bf as toEntityMentionWireFields, a1 as useIsEmailWidgetRender, bg as ConversationWidgetButton } from "./WebSearchResultsConversationWidget-DXhfSikV.js";
|
|
5
|
+
import { m as findWidgetFenceByPayloadHash, n as findWidgetFencesInMarkdown, I as readEntityDetailInstanceId, J as readMapNodeKeyOfInstanceId, K as findMapNodeInMarkdown, D as readOpenEntityActionTarget, L as canvasInstanceIdForEntityDetail, M as mapStyles, N as MapPresentationContext, e as ComposedViewRenderer } from "./widget-name-resolver-B9k-s_cF.js";
|
|
6
|
+
import { s as Text, b as ConversationSearchResultsList, a5 as useAgentsEnvironment } from "./link-navigation-BUcy5qWW.js";
|
|
7
7
|
import { E as EntityDetailNameReportContext } from "./entity-detail-name-3A82gDAp.js";
|
|
8
8
|
const useAnchorWidgetPayload = (canvas, anchorMessageMarkdown, widgetName) => useMemo(() => {
|
|
9
9
|
if (canvas.anchor.kind !== "message" || anchorMessageMarkdown === null) return void 0;
|
|
@@ -295,4 +295,4 @@ export {
|
|
|
295
295
|
registerCanvasBodies as r,
|
|
296
296
|
useAnchorWidgetPayload as u
|
|
297
297
|
};
|
|
298
|
-
//# sourceMappingURL=canvasBodies-
|
|
298
|
+
//# sourceMappingURL=canvasBodies-CQEBkIVw.js.map
|