@affectively/aeon-pages-runtime 0.1.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/dist/cache.d.ts +94 -0
- package/dist/durable-object.d.ts +79 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +9497 -0
- package/dist/navigation.d.ts +124 -0
- package/dist/predictor.d.ts +121 -0
- package/dist/registry.d.ts +79 -0
- package/dist/router/context-extractor.d.ts +31 -0
- package/dist/router/esi-control-react.d.ts +248 -0
- package/dist/router/esi-control.d.ts +161 -0
- package/dist/router/esi-react.d.ts +198 -0
- package/dist/router/esi.d.ts +44 -0
- package/dist/router/heuristic-adapter.d.ts +57 -0
- package/dist/router/index.d.ts +24 -0
- package/dist/router/index.js +3515 -0
- package/dist/router/speculation.d.ts +91 -0
- package/dist/router/types.d.ts +305 -0
- package/dist/router.d.ts +56 -0
- package/dist/server.d.ts +25 -0
- package/dist/server.js +8065 -0
- package/dist/service-worker.d.ts +12 -0
- package/dist/storage.d.ts +354 -0
- package/dist/types.d.ts +161 -0
- package/package.json +63 -0
|
@@ -0,0 +1,3515 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
29
|
+
var __require = import.meta.require;
|
|
30
|
+
|
|
31
|
+
// ../../../../node_modules/react/cjs/react.development.js
|
|
32
|
+
var require_react_development = __commonJS((exports, module) => {
|
|
33
|
+
(function() {
|
|
34
|
+
function defineDeprecationWarning(methodName, info) {
|
|
35
|
+
Object.defineProperty(Component.prototype, methodName, {
|
|
36
|
+
get: function() {
|
|
37
|
+
console.warn("%s(...) is deprecated in plain JavaScript React classes. %s", info[0], info[1]);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function getIteratorFn(maybeIterable) {
|
|
42
|
+
if (maybeIterable === null || typeof maybeIterable !== "object")
|
|
43
|
+
return null;
|
|
44
|
+
maybeIterable = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable["@@iterator"];
|
|
45
|
+
return typeof maybeIterable === "function" ? maybeIterable : null;
|
|
46
|
+
}
|
|
47
|
+
function warnNoop(publicInstance, callerName) {
|
|
48
|
+
publicInstance = (publicInstance = publicInstance.constructor) && (publicInstance.displayName || publicInstance.name) || "ReactClass";
|
|
49
|
+
var warningKey = publicInstance + "." + callerName;
|
|
50
|
+
didWarnStateUpdateForUnmountedComponent[warningKey] || (console.error("Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.", callerName, publicInstance), didWarnStateUpdateForUnmountedComponent[warningKey] = true);
|
|
51
|
+
}
|
|
52
|
+
function Component(props, context, updater) {
|
|
53
|
+
this.props = props;
|
|
54
|
+
this.context = context;
|
|
55
|
+
this.refs = emptyObject;
|
|
56
|
+
this.updater = updater || ReactNoopUpdateQueue;
|
|
57
|
+
}
|
|
58
|
+
function ComponentDummy() {}
|
|
59
|
+
function PureComponent(props, context, updater) {
|
|
60
|
+
this.props = props;
|
|
61
|
+
this.context = context;
|
|
62
|
+
this.refs = emptyObject;
|
|
63
|
+
this.updater = updater || ReactNoopUpdateQueue;
|
|
64
|
+
}
|
|
65
|
+
function noop() {}
|
|
66
|
+
function testStringCoercion(value) {
|
|
67
|
+
return "" + value;
|
|
68
|
+
}
|
|
69
|
+
function checkKeyStringCoercion(value) {
|
|
70
|
+
try {
|
|
71
|
+
testStringCoercion(value);
|
|
72
|
+
var JSCompiler_inline_result = false;
|
|
73
|
+
} catch (e) {
|
|
74
|
+
JSCompiler_inline_result = true;
|
|
75
|
+
}
|
|
76
|
+
if (JSCompiler_inline_result) {
|
|
77
|
+
JSCompiler_inline_result = console;
|
|
78
|
+
var JSCompiler_temp_const = JSCompiler_inline_result.error;
|
|
79
|
+
var JSCompiler_inline_result$jscomp$0 = typeof Symbol === "function" && Symbol.toStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object";
|
|
80
|
+
JSCompiler_temp_const.call(JSCompiler_inline_result, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", JSCompiler_inline_result$jscomp$0);
|
|
81
|
+
return testStringCoercion(value);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function getComponentNameFromType(type) {
|
|
85
|
+
if (type == null)
|
|
86
|
+
return null;
|
|
87
|
+
if (typeof type === "function")
|
|
88
|
+
return type.$$typeof === REACT_CLIENT_REFERENCE ? null : type.displayName || type.name || null;
|
|
89
|
+
if (typeof type === "string")
|
|
90
|
+
return type;
|
|
91
|
+
switch (type) {
|
|
92
|
+
case REACT_FRAGMENT_TYPE:
|
|
93
|
+
return "Fragment";
|
|
94
|
+
case REACT_PROFILER_TYPE:
|
|
95
|
+
return "Profiler";
|
|
96
|
+
case REACT_STRICT_MODE_TYPE:
|
|
97
|
+
return "StrictMode";
|
|
98
|
+
case REACT_SUSPENSE_TYPE:
|
|
99
|
+
return "Suspense";
|
|
100
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
101
|
+
return "SuspenseList";
|
|
102
|
+
case REACT_ACTIVITY_TYPE:
|
|
103
|
+
return "Activity";
|
|
104
|
+
}
|
|
105
|
+
if (typeof type === "object")
|
|
106
|
+
switch (typeof type.tag === "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), type.$$typeof) {
|
|
107
|
+
case REACT_PORTAL_TYPE:
|
|
108
|
+
return "Portal";
|
|
109
|
+
case REACT_CONTEXT_TYPE:
|
|
110
|
+
return type.displayName || "Context";
|
|
111
|
+
case REACT_CONSUMER_TYPE:
|
|
112
|
+
return (type._context.displayName || "Context") + ".Consumer";
|
|
113
|
+
case REACT_FORWARD_REF_TYPE:
|
|
114
|
+
var innerType = type.render;
|
|
115
|
+
type = type.displayName;
|
|
116
|
+
type || (type = innerType.displayName || innerType.name || "", type = type !== "" ? "ForwardRef(" + type + ")" : "ForwardRef");
|
|
117
|
+
return type;
|
|
118
|
+
case REACT_MEMO_TYPE:
|
|
119
|
+
return innerType = type.displayName || null, innerType !== null ? innerType : getComponentNameFromType(type.type) || "Memo";
|
|
120
|
+
case REACT_LAZY_TYPE:
|
|
121
|
+
innerType = type._payload;
|
|
122
|
+
type = type._init;
|
|
123
|
+
try {
|
|
124
|
+
return getComponentNameFromType(type(innerType));
|
|
125
|
+
} catch (x) {}
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
function getTaskName(type) {
|
|
130
|
+
if (type === REACT_FRAGMENT_TYPE)
|
|
131
|
+
return "<>";
|
|
132
|
+
if (typeof type === "object" && type !== null && type.$$typeof === REACT_LAZY_TYPE)
|
|
133
|
+
return "<...>";
|
|
134
|
+
try {
|
|
135
|
+
var name = getComponentNameFromType(type);
|
|
136
|
+
return name ? "<" + name + ">" : "<...>";
|
|
137
|
+
} catch (x) {
|
|
138
|
+
return "<...>";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function getOwner() {
|
|
142
|
+
var dispatcher = ReactSharedInternals.A;
|
|
143
|
+
return dispatcher === null ? null : dispatcher.getOwner();
|
|
144
|
+
}
|
|
145
|
+
function UnknownOwner() {
|
|
146
|
+
return Error("react-stack-top-frame");
|
|
147
|
+
}
|
|
148
|
+
function hasValidKey(config) {
|
|
149
|
+
if (hasOwnProperty.call(config, "key")) {
|
|
150
|
+
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
|
|
151
|
+
if (getter && getter.isReactWarning)
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
return config.key !== undefined;
|
|
155
|
+
}
|
|
156
|
+
function defineKeyPropWarningGetter(props, displayName) {
|
|
157
|
+
function warnAboutAccessingKey() {
|
|
158
|
+
specialPropKeyWarningShown || (specialPropKeyWarningShown = true, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", displayName));
|
|
159
|
+
}
|
|
160
|
+
warnAboutAccessingKey.isReactWarning = true;
|
|
161
|
+
Object.defineProperty(props, "key", {
|
|
162
|
+
get: warnAboutAccessingKey,
|
|
163
|
+
configurable: true
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function elementRefGetterWithDeprecationWarning() {
|
|
167
|
+
var componentName = getComponentNameFromType(this.type);
|
|
168
|
+
didWarnAboutElementRef[componentName] || (didWarnAboutElementRef[componentName] = true, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."));
|
|
169
|
+
componentName = this.props.ref;
|
|
170
|
+
return componentName !== undefined ? componentName : null;
|
|
171
|
+
}
|
|
172
|
+
function ReactElement(type, key, props, owner, debugStack, debugTask) {
|
|
173
|
+
var refProp = props.ref;
|
|
174
|
+
type = {
|
|
175
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
176
|
+
type,
|
|
177
|
+
key,
|
|
178
|
+
props,
|
|
179
|
+
_owner: owner
|
|
180
|
+
};
|
|
181
|
+
(refProp !== undefined ? refProp : null) !== null ? Object.defineProperty(type, "ref", {
|
|
182
|
+
enumerable: false,
|
|
183
|
+
get: elementRefGetterWithDeprecationWarning
|
|
184
|
+
}) : Object.defineProperty(type, "ref", { enumerable: false, value: null });
|
|
185
|
+
type._store = {};
|
|
186
|
+
Object.defineProperty(type._store, "validated", {
|
|
187
|
+
configurable: false,
|
|
188
|
+
enumerable: false,
|
|
189
|
+
writable: true,
|
|
190
|
+
value: 0
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(type, "_debugInfo", {
|
|
193
|
+
configurable: false,
|
|
194
|
+
enumerable: false,
|
|
195
|
+
writable: true,
|
|
196
|
+
value: null
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(type, "_debugStack", {
|
|
199
|
+
configurable: false,
|
|
200
|
+
enumerable: false,
|
|
201
|
+
writable: true,
|
|
202
|
+
value: debugStack
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(type, "_debugTask", {
|
|
205
|
+
configurable: false,
|
|
206
|
+
enumerable: false,
|
|
207
|
+
writable: true,
|
|
208
|
+
value: debugTask
|
|
209
|
+
});
|
|
210
|
+
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
|
|
211
|
+
return type;
|
|
212
|
+
}
|
|
213
|
+
function cloneAndReplaceKey(oldElement, newKey) {
|
|
214
|
+
newKey = ReactElement(oldElement.type, newKey, oldElement.props, oldElement._owner, oldElement._debugStack, oldElement._debugTask);
|
|
215
|
+
oldElement._store && (newKey._store.validated = oldElement._store.validated);
|
|
216
|
+
return newKey;
|
|
217
|
+
}
|
|
218
|
+
function validateChildKeys(node) {
|
|
219
|
+
isValidElement(node) ? node._store && (node._store.validated = 1) : typeof node === "object" && node !== null && node.$$typeof === REACT_LAZY_TYPE && (node._payload.status === "fulfilled" ? isValidElement(node._payload.value) && node._payload.value._store && (node._payload.value._store.validated = 1) : node._store && (node._store.validated = 1));
|
|
220
|
+
}
|
|
221
|
+
function isValidElement(object) {
|
|
222
|
+
return typeof object === "object" && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
223
|
+
}
|
|
224
|
+
function escape(key) {
|
|
225
|
+
var escaperLookup = { "=": "=0", ":": "=2" };
|
|
226
|
+
return "$" + key.replace(/[=:]/g, function(match) {
|
|
227
|
+
return escaperLookup[match];
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function getElementKey(element, index) {
|
|
231
|
+
return typeof element === "object" && element !== null && element.key != null ? (checkKeyStringCoercion(element.key), escape("" + element.key)) : index.toString(36);
|
|
232
|
+
}
|
|
233
|
+
function resolveThenable(thenable) {
|
|
234
|
+
switch (thenable.status) {
|
|
235
|
+
case "fulfilled":
|
|
236
|
+
return thenable.value;
|
|
237
|
+
case "rejected":
|
|
238
|
+
throw thenable.reason;
|
|
239
|
+
default:
|
|
240
|
+
switch (typeof thenable.status === "string" ? thenable.then(noop, noop) : (thenable.status = "pending", thenable.then(function(fulfilledValue) {
|
|
241
|
+
thenable.status === "pending" && (thenable.status = "fulfilled", thenable.value = fulfilledValue);
|
|
242
|
+
}, function(error) {
|
|
243
|
+
thenable.status === "pending" && (thenable.status = "rejected", thenable.reason = error);
|
|
244
|
+
})), thenable.status) {
|
|
245
|
+
case "fulfilled":
|
|
246
|
+
return thenable.value;
|
|
247
|
+
case "rejected":
|
|
248
|
+
throw thenable.reason;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
throw thenable;
|
|
252
|
+
}
|
|
253
|
+
function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
|
|
254
|
+
var type = typeof children;
|
|
255
|
+
if (type === "undefined" || type === "boolean")
|
|
256
|
+
children = null;
|
|
257
|
+
var invokeCallback = false;
|
|
258
|
+
if (children === null)
|
|
259
|
+
invokeCallback = true;
|
|
260
|
+
else
|
|
261
|
+
switch (type) {
|
|
262
|
+
case "bigint":
|
|
263
|
+
case "string":
|
|
264
|
+
case "number":
|
|
265
|
+
invokeCallback = true;
|
|
266
|
+
break;
|
|
267
|
+
case "object":
|
|
268
|
+
switch (children.$$typeof) {
|
|
269
|
+
case REACT_ELEMENT_TYPE:
|
|
270
|
+
case REACT_PORTAL_TYPE:
|
|
271
|
+
invokeCallback = true;
|
|
272
|
+
break;
|
|
273
|
+
case REACT_LAZY_TYPE:
|
|
274
|
+
return invokeCallback = children._init, mapIntoArray(invokeCallback(children._payload), array, escapedPrefix, nameSoFar, callback);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (invokeCallback) {
|
|
278
|
+
invokeCallback = children;
|
|
279
|
+
callback = callback(invokeCallback);
|
|
280
|
+
var childKey = nameSoFar === "" ? "." + getElementKey(invokeCallback, 0) : nameSoFar;
|
|
281
|
+
isArrayImpl(callback) ? (escapedPrefix = "", childKey != null && (escapedPrefix = childKey.replace(userProvidedKeyEscapeRegex, "$&/") + "/"), mapIntoArray(callback, array, escapedPrefix, "", function(c) {
|
|
282
|
+
return c;
|
|
283
|
+
})) : callback != null && (isValidElement(callback) && (callback.key != null && (invokeCallback && invokeCallback.key === callback.key || checkKeyStringCoercion(callback.key)), escapedPrefix = cloneAndReplaceKey(callback, escapedPrefix + (callback.key == null || invokeCallback && invokeCallback.key === callback.key ? "" : ("" + callback.key).replace(userProvidedKeyEscapeRegex, "$&/") + "/") + childKey), nameSoFar !== "" && invokeCallback != null && isValidElement(invokeCallback) && invokeCallback.key == null && invokeCallback._store && !invokeCallback._store.validated && (escapedPrefix._store.validated = 2), callback = escapedPrefix), array.push(callback));
|
|
284
|
+
return 1;
|
|
285
|
+
}
|
|
286
|
+
invokeCallback = 0;
|
|
287
|
+
childKey = nameSoFar === "" ? "." : nameSoFar + ":";
|
|
288
|
+
if (isArrayImpl(children))
|
|
289
|
+
for (var i = 0;i < children.length; i++)
|
|
290
|
+
nameSoFar = children[i], type = childKey + getElementKey(nameSoFar, i), invokeCallback += mapIntoArray(nameSoFar, array, escapedPrefix, type, callback);
|
|
291
|
+
else if (i = getIteratorFn(children), typeof i === "function")
|
|
292
|
+
for (i === children.entries && (didWarnAboutMaps || console.warn("Using Maps as children is not supported. Use an array of keyed ReactElements instead."), didWarnAboutMaps = true), children = i.call(children), i = 0;!(nameSoFar = children.next()).done; )
|
|
293
|
+
nameSoFar = nameSoFar.value, type = childKey + getElementKey(nameSoFar, i++), invokeCallback += mapIntoArray(nameSoFar, array, escapedPrefix, type, callback);
|
|
294
|
+
else if (type === "object") {
|
|
295
|
+
if (typeof children.then === "function")
|
|
296
|
+
return mapIntoArray(resolveThenable(children), array, escapedPrefix, nameSoFar, callback);
|
|
297
|
+
array = String(children);
|
|
298
|
+
throw Error("Objects are not valid as a React child (found: " + (array === "[object Object]" ? "object with keys {" + Object.keys(children).join(", ") + "}" : array) + "). If you meant to render a collection of children, use an array instead.");
|
|
299
|
+
}
|
|
300
|
+
return invokeCallback;
|
|
301
|
+
}
|
|
302
|
+
function mapChildren(children, func, context) {
|
|
303
|
+
if (children == null)
|
|
304
|
+
return children;
|
|
305
|
+
var result = [], count = 0;
|
|
306
|
+
mapIntoArray(children, result, "", "", function(child) {
|
|
307
|
+
return func.call(context, child, count++);
|
|
308
|
+
});
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
function lazyInitializer(payload) {
|
|
312
|
+
if (payload._status === -1) {
|
|
313
|
+
var ioInfo = payload._ioInfo;
|
|
314
|
+
ioInfo != null && (ioInfo.start = ioInfo.end = performance.now());
|
|
315
|
+
ioInfo = payload._result;
|
|
316
|
+
var thenable = ioInfo();
|
|
317
|
+
thenable.then(function(moduleObject) {
|
|
318
|
+
if (payload._status === 0 || payload._status === -1) {
|
|
319
|
+
payload._status = 1;
|
|
320
|
+
payload._result = moduleObject;
|
|
321
|
+
var _ioInfo = payload._ioInfo;
|
|
322
|
+
_ioInfo != null && (_ioInfo.end = performance.now());
|
|
323
|
+
thenable.status === undefined && (thenable.status = "fulfilled", thenable.value = moduleObject);
|
|
324
|
+
}
|
|
325
|
+
}, function(error) {
|
|
326
|
+
if (payload._status === 0 || payload._status === -1) {
|
|
327
|
+
payload._status = 2;
|
|
328
|
+
payload._result = error;
|
|
329
|
+
var _ioInfo2 = payload._ioInfo;
|
|
330
|
+
_ioInfo2 != null && (_ioInfo2.end = performance.now());
|
|
331
|
+
thenable.status === undefined && (thenable.status = "rejected", thenable.reason = error);
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
ioInfo = payload._ioInfo;
|
|
335
|
+
if (ioInfo != null) {
|
|
336
|
+
ioInfo.value = thenable;
|
|
337
|
+
var displayName = thenable.displayName;
|
|
338
|
+
typeof displayName === "string" && (ioInfo.name = displayName);
|
|
339
|
+
}
|
|
340
|
+
payload._status === -1 && (payload._status = 0, payload._result = thenable);
|
|
341
|
+
}
|
|
342
|
+
if (payload._status === 1)
|
|
343
|
+
return ioInfo = payload._result, ioInfo === undefined && console.error(`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
344
|
+
|
|
345
|
+
Your code should look like:
|
|
346
|
+
const MyComponent = lazy(() => import('./MyComponent'))
|
|
347
|
+
|
|
348
|
+
Did you accidentally put curly braces around the import?`, ioInfo), "default" in ioInfo || console.error(`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
349
|
+
|
|
350
|
+
Your code should look like:
|
|
351
|
+
const MyComponent = lazy(() => import('./MyComponent'))`, ioInfo), ioInfo.default;
|
|
352
|
+
throw payload._result;
|
|
353
|
+
}
|
|
354
|
+
function resolveDispatcher() {
|
|
355
|
+
var dispatcher = ReactSharedInternals.H;
|
|
356
|
+
dispatcher === null && console.error(`Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
|
|
357
|
+
1. You might have mismatching versions of React and the renderer (such as React DOM)
|
|
358
|
+
2. You might be breaking the Rules of Hooks
|
|
359
|
+
3. You might have more than one copy of React in the same app
|
|
360
|
+
See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.`);
|
|
361
|
+
return dispatcher;
|
|
362
|
+
}
|
|
363
|
+
function releaseAsyncTransition() {
|
|
364
|
+
ReactSharedInternals.asyncTransitions--;
|
|
365
|
+
}
|
|
366
|
+
function enqueueTask(task) {
|
|
367
|
+
if (enqueueTaskImpl === null)
|
|
368
|
+
try {
|
|
369
|
+
var requireString = ("require" + Math.random()).slice(0, 7);
|
|
370
|
+
enqueueTaskImpl = (module && module[requireString]).call(module, "timers").setImmediate;
|
|
371
|
+
} catch (_err) {
|
|
372
|
+
enqueueTaskImpl = function(callback) {
|
|
373
|
+
didWarnAboutMessageChannel === false && (didWarnAboutMessageChannel = true, typeof MessageChannel === "undefined" && console.error("This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning."));
|
|
374
|
+
var channel = new MessageChannel;
|
|
375
|
+
channel.port1.onmessage = callback;
|
|
376
|
+
channel.port2.postMessage(undefined);
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
return enqueueTaskImpl(task);
|
|
380
|
+
}
|
|
381
|
+
function aggregateErrors(errors) {
|
|
382
|
+
return 1 < errors.length && typeof AggregateError === "function" ? new AggregateError(errors) : errors[0];
|
|
383
|
+
}
|
|
384
|
+
function popActScope(prevActQueue, prevActScopeDepth) {
|
|
385
|
+
prevActScopeDepth !== actScopeDepth - 1 && console.error("You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one. ");
|
|
386
|
+
actScopeDepth = prevActScopeDepth;
|
|
387
|
+
}
|
|
388
|
+
function recursivelyFlushAsyncActWork(returnValue, resolve, reject) {
|
|
389
|
+
var queue = ReactSharedInternals.actQueue;
|
|
390
|
+
if (queue !== null)
|
|
391
|
+
if (queue.length !== 0)
|
|
392
|
+
try {
|
|
393
|
+
flushActQueue(queue);
|
|
394
|
+
enqueueTask(function() {
|
|
395
|
+
return recursivelyFlushAsyncActWork(returnValue, resolve, reject);
|
|
396
|
+
});
|
|
397
|
+
return;
|
|
398
|
+
} catch (error) {
|
|
399
|
+
ReactSharedInternals.thrownErrors.push(error);
|
|
400
|
+
}
|
|
401
|
+
else
|
|
402
|
+
ReactSharedInternals.actQueue = null;
|
|
403
|
+
0 < ReactSharedInternals.thrownErrors.length ? (queue = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, reject(queue)) : resolve(returnValue);
|
|
404
|
+
}
|
|
405
|
+
function flushActQueue(queue) {
|
|
406
|
+
if (!isFlushing) {
|
|
407
|
+
isFlushing = true;
|
|
408
|
+
var i = 0;
|
|
409
|
+
try {
|
|
410
|
+
for (;i < queue.length; i++) {
|
|
411
|
+
var callback = queue[i];
|
|
412
|
+
do {
|
|
413
|
+
ReactSharedInternals.didUsePromise = false;
|
|
414
|
+
var continuation = callback(false);
|
|
415
|
+
if (continuation !== null) {
|
|
416
|
+
if (ReactSharedInternals.didUsePromise) {
|
|
417
|
+
queue[i] = callback;
|
|
418
|
+
queue.splice(0, i);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
callback = continuation;
|
|
422
|
+
} else
|
|
423
|
+
break;
|
|
424
|
+
} while (1);
|
|
425
|
+
}
|
|
426
|
+
queue.length = 0;
|
|
427
|
+
} catch (error) {
|
|
428
|
+
queue.splice(0, i + 1), ReactSharedInternals.thrownErrors.push(error);
|
|
429
|
+
} finally {
|
|
430
|
+
isFlushing = false;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
435
|
+
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = Symbol.for("react.memo"), REACT_LAZY_TYPE = Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = Symbol.for("react.activity"), MAYBE_ITERATOR_SYMBOL = Symbol.iterator, didWarnStateUpdateForUnmountedComponent = {}, ReactNoopUpdateQueue = {
|
|
436
|
+
isMounted: function() {
|
|
437
|
+
return false;
|
|
438
|
+
},
|
|
439
|
+
enqueueForceUpdate: function(publicInstance) {
|
|
440
|
+
warnNoop(publicInstance, "forceUpdate");
|
|
441
|
+
},
|
|
442
|
+
enqueueReplaceState: function(publicInstance) {
|
|
443
|
+
warnNoop(publicInstance, "replaceState");
|
|
444
|
+
},
|
|
445
|
+
enqueueSetState: function(publicInstance) {
|
|
446
|
+
warnNoop(publicInstance, "setState");
|
|
447
|
+
}
|
|
448
|
+
}, assign = Object.assign, emptyObject = {};
|
|
449
|
+
Object.freeze(emptyObject);
|
|
450
|
+
Component.prototype.isReactComponent = {};
|
|
451
|
+
Component.prototype.setState = function(partialState, callback) {
|
|
452
|
+
if (typeof partialState !== "object" && typeof partialState !== "function" && partialState != null)
|
|
453
|
+
throw Error("takes an object of state variables to update or a function which returns an object of state variables.");
|
|
454
|
+
this.updater.enqueueSetState(this, partialState, callback, "setState");
|
|
455
|
+
};
|
|
456
|
+
Component.prototype.forceUpdate = function(callback) {
|
|
457
|
+
this.updater.enqueueForceUpdate(this, callback, "forceUpdate");
|
|
458
|
+
};
|
|
459
|
+
var deprecatedAPIs = {
|
|
460
|
+
isMounted: [
|
|
461
|
+
"isMounted",
|
|
462
|
+
"Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."
|
|
463
|
+
],
|
|
464
|
+
replaceState: [
|
|
465
|
+
"replaceState",
|
|
466
|
+
"Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."
|
|
467
|
+
]
|
|
468
|
+
};
|
|
469
|
+
for (fnName in deprecatedAPIs)
|
|
470
|
+
deprecatedAPIs.hasOwnProperty(fnName) && defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
|
|
471
|
+
ComponentDummy.prototype = Component.prototype;
|
|
472
|
+
deprecatedAPIs = PureComponent.prototype = new ComponentDummy;
|
|
473
|
+
deprecatedAPIs.constructor = PureComponent;
|
|
474
|
+
assign(deprecatedAPIs, Component.prototype);
|
|
475
|
+
deprecatedAPIs.isPureReactComponent = true;
|
|
476
|
+
var isArrayImpl = Array.isArray, REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"), ReactSharedInternals = {
|
|
477
|
+
H: null,
|
|
478
|
+
A: null,
|
|
479
|
+
T: null,
|
|
480
|
+
S: null,
|
|
481
|
+
actQueue: null,
|
|
482
|
+
asyncTransitions: 0,
|
|
483
|
+
isBatchingLegacy: false,
|
|
484
|
+
didScheduleLegacyUpdate: false,
|
|
485
|
+
didUsePromise: false,
|
|
486
|
+
thrownErrors: [],
|
|
487
|
+
getCurrentStack: null,
|
|
488
|
+
recentlyCreatedOwnerStacks: 0
|
|
489
|
+
}, hasOwnProperty = Object.prototype.hasOwnProperty, createTask = console.createTask ? console.createTask : function() {
|
|
490
|
+
return null;
|
|
491
|
+
};
|
|
492
|
+
deprecatedAPIs = {
|
|
493
|
+
react_stack_bottom_frame: function(callStackForError) {
|
|
494
|
+
return callStackForError();
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
var specialPropKeyWarningShown, didWarnAboutOldJSXRuntime;
|
|
498
|
+
var didWarnAboutElementRef = {};
|
|
499
|
+
var unknownOwnerDebugStack = deprecatedAPIs.react_stack_bottom_frame.bind(deprecatedAPIs, UnknownOwner)();
|
|
500
|
+
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
|
|
501
|
+
var didWarnAboutMaps = false, userProvidedKeyEscapeRegex = /\/+/g, reportGlobalError = typeof reportError === "function" ? reportError : function(error) {
|
|
502
|
+
if (typeof window === "object" && typeof window.ErrorEvent === "function") {
|
|
503
|
+
var event = new window.ErrorEvent("error", {
|
|
504
|
+
bubbles: true,
|
|
505
|
+
cancelable: true,
|
|
506
|
+
message: typeof error === "object" && error !== null && typeof error.message === "string" ? String(error.message) : String(error),
|
|
507
|
+
error
|
|
508
|
+
});
|
|
509
|
+
if (!window.dispatchEvent(event))
|
|
510
|
+
return;
|
|
511
|
+
} else if (typeof process === "object" && typeof process.emit === "function") {
|
|
512
|
+
process.emit("uncaughtException", error);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
console.error(error);
|
|
516
|
+
}, didWarnAboutMessageChannel = false, enqueueTaskImpl = null, actScopeDepth = 0, didWarnNoAwaitAct = false, isFlushing = false, queueSeveralMicrotasks = typeof queueMicrotask === "function" ? function(callback) {
|
|
517
|
+
queueMicrotask(function() {
|
|
518
|
+
return queueMicrotask(callback);
|
|
519
|
+
});
|
|
520
|
+
} : enqueueTask;
|
|
521
|
+
deprecatedAPIs = Object.freeze({
|
|
522
|
+
__proto__: null,
|
|
523
|
+
c: function(size) {
|
|
524
|
+
return resolveDispatcher().useMemoCache(size);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
var fnName = {
|
|
528
|
+
map: mapChildren,
|
|
529
|
+
forEach: function(children, forEachFunc, forEachContext) {
|
|
530
|
+
mapChildren(children, function() {
|
|
531
|
+
forEachFunc.apply(this, arguments);
|
|
532
|
+
}, forEachContext);
|
|
533
|
+
},
|
|
534
|
+
count: function(children) {
|
|
535
|
+
var n = 0;
|
|
536
|
+
mapChildren(children, function() {
|
|
537
|
+
n++;
|
|
538
|
+
});
|
|
539
|
+
return n;
|
|
540
|
+
},
|
|
541
|
+
toArray: function(children) {
|
|
542
|
+
return mapChildren(children, function(child) {
|
|
543
|
+
return child;
|
|
544
|
+
}) || [];
|
|
545
|
+
},
|
|
546
|
+
only: function(children) {
|
|
547
|
+
if (!isValidElement(children))
|
|
548
|
+
throw Error("React.Children.only expected to receive a single React element child.");
|
|
549
|
+
return children;
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
exports.Activity = REACT_ACTIVITY_TYPE;
|
|
553
|
+
exports.Children = fnName;
|
|
554
|
+
exports.Component = Component;
|
|
555
|
+
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
556
|
+
exports.Profiler = REACT_PROFILER_TYPE;
|
|
557
|
+
exports.PureComponent = PureComponent;
|
|
558
|
+
exports.StrictMode = REACT_STRICT_MODE_TYPE;
|
|
559
|
+
exports.Suspense = REACT_SUSPENSE_TYPE;
|
|
560
|
+
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = ReactSharedInternals;
|
|
561
|
+
exports.__COMPILER_RUNTIME = deprecatedAPIs;
|
|
562
|
+
exports.act = function(callback) {
|
|
563
|
+
var prevActQueue = ReactSharedInternals.actQueue, prevActScopeDepth = actScopeDepth;
|
|
564
|
+
actScopeDepth++;
|
|
565
|
+
var queue = ReactSharedInternals.actQueue = prevActQueue !== null ? prevActQueue : [], didAwaitActCall = false;
|
|
566
|
+
try {
|
|
567
|
+
var result = callback();
|
|
568
|
+
} catch (error) {
|
|
569
|
+
ReactSharedInternals.thrownErrors.push(error);
|
|
570
|
+
}
|
|
571
|
+
if (0 < ReactSharedInternals.thrownErrors.length)
|
|
572
|
+
throw popActScope(prevActQueue, prevActScopeDepth), callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback;
|
|
573
|
+
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
574
|
+
var thenable = result;
|
|
575
|
+
queueSeveralMicrotasks(function() {
|
|
576
|
+
didAwaitActCall || didWarnNoAwaitAct || (didWarnNoAwaitAct = true, console.error("You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);"));
|
|
577
|
+
});
|
|
578
|
+
return {
|
|
579
|
+
then: function(resolve, reject) {
|
|
580
|
+
didAwaitActCall = true;
|
|
581
|
+
thenable.then(function(returnValue) {
|
|
582
|
+
popActScope(prevActQueue, prevActScopeDepth);
|
|
583
|
+
if (prevActScopeDepth === 0) {
|
|
584
|
+
try {
|
|
585
|
+
flushActQueue(queue), enqueueTask(function() {
|
|
586
|
+
return recursivelyFlushAsyncActWork(returnValue, resolve, reject);
|
|
587
|
+
});
|
|
588
|
+
} catch (error$0) {
|
|
589
|
+
ReactSharedInternals.thrownErrors.push(error$0);
|
|
590
|
+
}
|
|
591
|
+
if (0 < ReactSharedInternals.thrownErrors.length) {
|
|
592
|
+
var _thrownError = aggregateErrors(ReactSharedInternals.thrownErrors);
|
|
593
|
+
ReactSharedInternals.thrownErrors.length = 0;
|
|
594
|
+
reject(_thrownError);
|
|
595
|
+
}
|
|
596
|
+
} else
|
|
597
|
+
resolve(returnValue);
|
|
598
|
+
}, function(error) {
|
|
599
|
+
popActScope(prevActQueue, prevActScopeDepth);
|
|
600
|
+
0 < ReactSharedInternals.thrownErrors.length ? (error = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, reject(error)) : reject(error);
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
var returnValue$jscomp$0 = result;
|
|
606
|
+
popActScope(prevActQueue, prevActScopeDepth);
|
|
607
|
+
prevActScopeDepth === 0 && (flushActQueue(queue), queue.length !== 0 && queueSeveralMicrotasks(function() {
|
|
608
|
+
didAwaitActCall || didWarnNoAwaitAct || (didWarnNoAwaitAct = true, console.error("A component suspended inside an `act` scope, but the `act` call was not awaited. When testing React components that depend on asynchronous data, you must await the result:\n\nawait act(() => ...)"));
|
|
609
|
+
}), ReactSharedInternals.actQueue = null);
|
|
610
|
+
if (0 < ReactSharedInternals.thrownErrors.length)
|
|
611
|
+
throw callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback;
|
|
612
|
+
return {
|
|
613
|
+
then: function(resolve, reject) {
|
|
614
|
+
didAwaitActCall = true;
|
|
615
|
+
prevActScopeDepth === 0 ? (ReactSharedInternals.actQueue = queue, enqueueTask(function() {
|
|
616
|
+
return recursivelyFlushAsyncActWork(returnValue$jscomp$0, resolve, reject);
|
|
617
|
+
})) : resolve(returnValue$jscomp$0);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
};
|
|
621
|
+
exports.cache = function(fn) {
|
|
622
|
+
return function() {
|
|
623
|
+
return fn.apply(null, arguments);
|
|
624
|
+
};
|
|
625
|
+
};
|
|
626
|
+
exports.cacheSignal = function() {
|
|
627
|
+
return null;
|
|
628
|
+
};
|
|
629
|
+
exports.captureOwnerStack = function() {
|
|
630
|
+
var getCurrentStack = ReactSharedInternals.getCurrentStack;
|
|
631
|
+
return getCurrentStack === null ? null : getCurrentStack();
|
|
632
|
+
};
|
|
633
|
+
exports.cloneElement = function(element, config, children) {
|
|
634
|
+
if (element === null || element === undefined)
|
|
635
|
+
throw Error("The argument must be a React element, but you passed " + element + ".");
|
|
636
|
+
var props = assign({}, element.props), key = element.key, owner = element._owner;
|
|
637
|
+
if (config != null) {
|
|
638
|
+
var JSCompiler_inline_result;
|
|
639
|
+
a: {
|
|
640
|
+
if (hasOwnProperty.call(config, "ref") && (JSCompiler_inline_result = Object.getOwnPropertyDescriptor(config, "ref").get) && JSCompiler_inline_result.isReactWarning) {
|
|
641
|
+
JSCompiler_inline_result = false;
|
|
642
|
+
break a;
|
|
643
|
+
}
|
|
644
|
+
JSCompiler_inline_result = config.ref !== undefined;
|
|
645
|
+
}
|
|
646
|
+
JSCompiler_inline_result && (owner = getOwner());
|
|
647
|
+
hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key);
|
|
648
|
+
for (propName in config)
|
|
649
|
+
!hasOwnProperty.call(config, propName) || propName === "key" || propName === "__self" || propName === "__source" || propName === "ref" && config.ref === undefined || (props[propName] = config[propName]);
|
|
650
|
+
}
|
|
651
|
+
var propName = arguments.length - 2;
|
|
652
|
+
if (propName === 1)
|
|
653
|
+
props.children = children;
|
|
654
|
+
else if (1 < propName) {
|
|
655
|
+
JSCompiler_inline_result = Array(propName);
|
|
656
|
+
for (var i = 0;i < propName; i++)
|
|
657
|
+
JSCompiler_inline_result[i] = arguments[i + 2];
|
|
658
|
+
props.children = JSCompiler_inline_result;
|
|
659
|
+
}
|
|
660
|
+
props = ReactElement(element.type, key, props, owner, element._debugStack, element._debugTask);
|
|
661
|
+
for (key = 2;key < arguments.length; key++)
|
|
662
|
+
validateChildKeys(arguments[key]);
|
|
663
|
+
return props;
|
|
664
|
+
};
|
|
665
|
+
exports.createContext = function(defaultValue) {
|
|
666
|
+
defaultValue = {
|
|
667
|
+
$$typeof: REACT_CONTEXT_TYPE,
|
|
668
|
+
_currentValue: defaultValue,
|
|
669
|
+
_currentValue2: defaultValue,
|
|
670
|
+
_threadCount: 0,
|
|
671
|
+
Provider: null,
|
|
672
|
+
Consumer: null
|
|
673
|
+
};
|
|
674
|
+
defaultValue.Provider = defaultValue;
|
|
675
|
+
defaultValue.Consumer = {
|
|
676
|
+
$$typeof: REACT_CONSUMER_TYPE,
|
|
677
|
+
_context: defaultValue
|
|
678
|
+
};
|
|
679
|
+
defaultValue._currentRenderer = null;
|
|
680
|
+
defaultValue._currentRenderer2 = null;
|
|
681
|
+
return defaultValue;
|
|
682
|
+
};
|
|
683
|
+
exports.createElement = function(type, config, children) {
|
|
684
|
+
for (var i = 2;i < arguments.length; i++)
|
|
685
|
+
validateChildKeys(arguments[i]);
|
|
686
|
+
i = {};
|
|
687
|
+
var key = null;
|
|
688
|
+
if (config != null)
|
|
689
|
+
for (propName in didWarnAboutOldJSXRuntime || !("__self" in config) || "key" in config || (didWarnAboutOldJSXRuntime = true, console.warn("Your app (or one of its dependencies) is using an outdated JSX transform. Update to the modern JSX transform for faster performance: https://react.dev/link/new-jsx-transform")), hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key), config)
|
|
690
|
+
hasOwnProperty.call(config, propName) && propName !== "key" && propName !== "__self" && propName !== "__source" && (i[propName] = config[propName]);
|
|
691
|
+
var childrenLength = arguments.length - 2;
|
|
692
|
+
if (childrenLength === 1)
|
|
693
|
+
i.children = children;
|
|
694
|
+
else if (1 < childrenLength) {
|
|
695
|
+
for (var childArray = Array(childrenLength), _i = 0;_i < childrenLength; _i++)
|
|
696
|
+
childArray[_i] = arguments[_i + 2];
|
|
697
|
+
Object.freeze && Object.freeze(childArray);
|
|
698
|
+
i.children = childArray;
|
|
699
|
+
}
|
|
700
|
+
if (type && type.defaultProps)
|
|
701
|
+
for (propName in childrenLength = type.defaultProps, childrenLength)
|
|
702
|
+
i[propName] === undefined && (i[propName] = childrenLength[propName]);
|
|
703
|
+
key && defineKeyPropWarningGetter(i, typeof type === "function" ? type.displayName || type.name || "Unknown" : type);
|
|
704
|
+
var propName = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
|
705
|
+
return ReactElement(type, key, i, getOwner(), propName ? Error("react-stack-top-frame") : unknownOwnerDebugStack, propName ? createTask(getTaskName(type)) : unknownOwnerDebugTask);
|
|
706
|
+
};
|
|
707
|
+
exports.createRef = function() {
|
|
708
|
+
var refObject = { current: null };
|
|
709
|
+
Object.seal(refObject);
|
|
710
|
+
return refObject;
|
|
711
|
+
};
|
|
712
|
+
exports.forwardRef = function(render) {
|
|
713
|
+
render != null && render.$$typeof === REACT_MEMO_TYPE ? console.error("forwardRef requires a render function but received a `memo` component. Instead of forwardRef(memo(...)), use memo(forwardRef(...)).") : typeof render !== "function" ? console.error("forwardRef requires a render function but was given %s.", render === null ? "null" : typeof render) : render.length !== 0 && render.length !== 2 && console.error("forwardRef render functions accept exactly two parameters: props and ref. %s", render.length === 1 ? "Did you forget to use the ref parameter?" : "Any additional parameter will be undefined.");
|
|
714
|
+
render != null && render.defaultProps != null && console.error("forwardRef render functions do not support defaultProps. Did you accidentally pass a React component?");
|
|
715
|
+
var elementType = { $$typeof: REACT_FORWARD_REF_TYPE, render }, ownName;
|
|
716
|
+
Object.defineProperty(elementType, "displayName", {
|
|
717
|
+
enumerable: false,
|
|
718
|
+
configurable: true,
|
|
719
|
+
get: function() {
|
|
720
|
+
return ownName;
|
|
721
|
+
},
|
|
722
|
+
set: function(name) {
|
|
723
|
+
ownName = name;
|
|
724
|
+
render.name || render.displayName || (Object.defineProperty(render, "name", { value: name }), render.displayName = name);
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
return elementType;
|
|
728
|
+
};
|
|
729
|
+
exports.isValidElement = isValidElement;
|
|
730
|
+
exports.lazy = function(ctor) {
|
|
731
|
+
ctor = { _status: -1, _result: ctor };
|
|
732
|
+
var lazyType = {
|
|
733
|
+
$$typeof: REACT_LAZY_TYPE,
|
|
734
|
+
_payload: ctor,
|
|
735
|
+
_init: lazyInitializer
|
|
736
|
+
}, ioInfo = {
|
|
737
|
+
name: "lazy",
|
|
738
|
+
start: -1,
|
|
739
|
+
end: -1,
|
|
740
|
+
value: null,
|
|
741
|
+
owner: null,
|
|
742
|
+
debugStack: Error("react-stack-top-frame"),
|
|
743
|
+
debugTask: console.createTask ? console.createTask("lazy()") : null
|
|
744
|
+
};
|
|
745
|
+
ctor._ioInfo = ioInfo;
|
|
746
|
+
lazyType._debugInfo = [{ awaited: ioInfo }];
|
|
747
|
+
return lazyType;
|
|
748
|
+
};
|
|
749
|
+
exports.memo = function(type, compare) {
|
|
750
|
+
type == null && console.error("memo: The first argument must be a component. Instead received: %s", type === null ? "null" : typeof type);
|
|
751
|
+
compare = {
|
|
752
|
+
$$typeof: REACT_MEMO_TYPE,
|
|
753
|
+
type,
|
|
754
|
+
compare: compare === undefined ? null : compare
|
|
755
|
+
};
|
|
756
|
+
var ownName;
|
|
757
|
+
Object.defineProperty(compare, "displayName", {
|
|
758
|
+
enumerable: false,
|
|
759
|
+
configurable: true,
|
|
760
|
+
get: function() {
|
|
761
|
+
return ownName;
|
|
762
|
+
},
|
|
763
|
+
set: function(name) {
|
|
764
|
+
ownName = name;
|
|
765
|
+
type.name || type.displayName || (Object.defineProperty(type, "name", { value: name }), type.displayName = name);
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
return compare;
|
|
769
|
+
};
|
|
770
|
+
exports.startTransition = function(scope) {
|
|
771
|
+
var prevTransition = ReactSharedInternals.T, currentTransition = {};
|
|
772
|
+
currentTransition._updatedFibers = new Set;
|
|
773
|
+
ReactSharedInternals.T = currentTransition;
|
|
774
|
+
try {
|
|
775
|
+
var returnValue = scope(), onStartTransitionFinish = ReactSharedInternals.S;
|
|
776
|
+
onStartTransitionFinish !== null && onStartTransitionFinish(currentTransition, returnValue);
|
|
777
|
+
typeof returnValue === "object" && returnValue !== null && typeof returnValue.then === "function" && (ReactSharedInternals.asyncTransitions++, returnValue.then(releaseAsyncTransition, releaseAsyncTransition), returnValue.then(noop, reportGlobalError));
|
|
778
|
+
} catch (error) {
|
|
779
|
+
reportGlobalError(error);
|
|
780
|
+
} finally {
|
|
781
|
+
prevTransition === null && currentTransition._updatedFibers && (scope = currentTransition._updatedFibers.size, currentTransition._updatedFibers.clear(), 10 < scope && console.warn("Detected a large number of updates inside startTransition. If this is due to a subscription please re-write it to use React provided hooks. Otherwise concurrent mode guarantees are off the table.")), prevTransition !== null && currentTransition.types !== null && (prevTransition.types !== null && prevTransition.types !== currentTransition.types && console.error("We expected inner Transitions to have transferred the outer types set and that you cannot add to the outer Transition while inside the inner.This is a bug in React."), prevTransition.types = currentTransition.types), ReactSharedInternals.T = prevTransition;
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
exports.unstable_useCacheRefresh = function() {
|
|
785
|
+
return resolveDispatcher().useCacheRefresh();
|
|
786
|
+
};
|
|
787
|
+
exports.use = function(usable) {
|
|
788
|
+
return resolveDispatcher().use(usable);
|
|
789
|
+
};
|
|
790
|
+
exports.useActionState = function(action, initialState, permalink) {
|
|
791
|
+
return resolveDispatcher().useActionState(action, initialState, permalink);
|
|
792
|
+
};
|
|
793
|
+
exports.useCallback = function(callback, deps) {
|
|
794
|
+
return resolveDispatcher().useCallback(callback, deps);
|
|
795
|
+
};
|
|
796
|
+
exports.useContext = function(Context) {
|
|
797
|
+
var dispatcher = resolveDispatcher();
|
|
798
|
+
Context.$$typeof === REACT_CONSUMER_TYPE && console.error("Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?");
|
|
799
|
+
return dispatcher.useContext(Context);
|
|
800
|
+
};
|
|
801
|
+
exports.useDebugValue = function(value, formatterFn) {
|
|
802
|
+
return resolveDispatcher().useDebugValue(value, formatterFn);
|
|
803
|
+
};
|
|
804
|
+
exports.useDeferredValue = function(value, initialValue) {
|
|
805
|
+
return resolveDispatcher().useDeferredValue(value, initialValue);
|
|
806
|
+
};
|
|
807
|
+
exports.useEffect = function(create, deps) {
|
|
808
|
+
create == null && console.warn("React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?");
|
|
809
|
+
return resolveDispatcher().useEffect(create, deps);
|
|
810
|
+
};
|
|
811
|
+
exports.useEffectEvent = function(callback) {
|
|
812
|
+
return resolveDispatcher().useEffectEvent(callback);
|
|
813
|
+
};
|
|
814
|
+
exports.useId = function() {
|
|
815
|
+
return resolveDispatcher().useId();
|
|
816
|
+
};
|
|
817
|
+
exports.useImperativeHandle = function(ref, create, deps) {
|
|
818
|
+
return resolveDispatcher().useImperativeHandle(ref, create, deps);
|
|
819
|
+
};
|
|
820
|
+
exports.useInsertionEffect = function(create, deps) {
|
|
821
|
+
create == null && console.warn("React Hook useInsertionEffect requires an effect callback. Did you forget to pass a callback to the hook?");
|
|
822
|
+
return resolveDispatcher().useInsertionEffect(create, deps);
|
|
823
|
+
};
|
|
824
|
+
exports.useLayoutEffect = function(create, deps) {
|
|
825
|
+
create == null && console.warn("React Hook useLayoutEffect requires an effect callback. Did you forget to pass a callback to the hook?");
|
|
826
|
+
return resolveDispatcher().useLayoutEffect(create, deps);
|
|
827
|
+
};
|
|
828
|
+
exports.useMemo = function(create, deps) {
|
|
829
|
+
return resolveDispatcher().useMemo(create, deps);
|
|
830
|
+
};
|
|
831
|
+
exports.useOptimistic = function(passthrough, reducer) {
|
|
832
|
+
return resolveDispatcher().useOptimistic(passthrough, reducer);
|
|
833
|
+
};
|
|
834
|
+
exports.useReducer = function(reducer, initialArg, init) {
|
|
835
|
+
return resolveDispatcher().useReducer(reducer, initialArg, init);
|
|
836
|
+
};
|
|
837
|
+
exports.useRef = function(initialValue) {
|
|
838
|
+
return resolveDispatcher().useRef(initialValue);
|
|
839
|
+
};
|
|
840
|
+
exports.useState = function(initialState) {
|
|
841
|
+
return resolveDispatcher().useState(initialState);
|
|
842
|
+
};
|
|
843
|
+
exports.useSyncExternalStore = function(subscribe, getSnapshot, getServerSnapshot) {
|
|
844
|
+
return resolveDispatcher().useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
845
|
+
};
|
|
846
|
+
exports.useTransition = function() {
|
|
847
|
+
return resolveDispatcher().useTransition();
|
|
848
|
+
};
|
|
849
|
+
exports.version = "19.2.3";
|
|
850
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
851
|
+
})();
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
// ../../../../node_modules/react/index.js
|
|
855
|
+
var require_react = __commonJS((exports, module) => {
|
|
856
|
+
var react_development = __toESM(require_react_development());
|
|
857
|
+
if (false) {} else {
|
|
858
|
+
module.exports = react_development;
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
// ../../../../node_modules/react/cjs/react-jsx-dev-runtime.development.js
|
|
863
|
+
var require_react_jsx_dev_runtime_development = __commonJS((exports) => {
|
|
864
|
+
var React = __toESM(require_react());
|
|
865
|
+
(function() {
|
|
866
|
+
function getComponentNameFromType(type) {
|
|
867
|
+
if (type == null)
|
|
868
|
+
return null;
|
|
869
|
+
if (typeof type === "function")
|
|
870
|
+
return type.$$typeof === REACT_CLIENT_REFERENCE ? null : type.displayName || type.name || null;
|
|
871
|
+
if (typeof type === "string")
|
|
872
|
+
return type;
|
|
873
|
+
switch (type) {
|
|
874
|
+
case REACT_FRAGMENT_TYPE:
|
|
875
|
+
return "Fragment";
|
|
876
|
+
case REACT_PROFILER_TYPE:
|
|
877
|
+
return "Profiler";
|
|
878
|
+
case REACT_STRICT_MODE_TYPE:
|
|
879
|
+
return "StrictMode";
|
|
880
|
+
case REACT_SUSPENSE_TYPE:
|
|
881
|
+
return "Suspense";
|
|
882
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
883
|
+
return "SuspenseList";
|
|
884
|
+
case REACT_ACTIVITY_TYPE:
|
|
885
|
+
return "Activity";
|
|
886
|
+
}
|
|
887
|
+
if (typeof type === "object")
|
|
888
|
+
switch (typeof type.tag === "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), type.$$typeof) {
|
|
889
|
+
case REACT_PORTAL_TYPE:
|
|
890
|
+
return "Portal";
|
|
891
|
+
case REACT_CONTEXT_TYPE:
|
|
892
|
+
return type.displayName || "Context";
|
|
893
|
+
case REACT_CONSUMER_TYPE:
|
|
894
|
+
return (type._context.displayName || "Context") + ".Consumer";
|
|
895
|
+
case REACT_FORWARD_REF_TYPE:
|
|
896
|
+
var innerType = type.render;
|
|
897
|
+
type = type.displayName;
|
|
898
|
+
type || (type = innerType.displayName || innerType.name || "", type = type !== "" ? "ForwardRef(" + type + ")" : "ForwardRef");
|
|
899
|
+
return type;
|
|
900
|
+
case REACT_MEMO_TYPE:
|
|
901
|
+
return innerType = type.displayName || null, innerType !== null ? innerType : getComponentNameFromType(type.type) || "Memo";
|
|
902
|
+
case REACT_LAZY_TYPE:
|
|
903
|
+
innerType = type._payload;
|
|
904
|
+
type = type._init;
|
|
905
|
+
try {
|
|
906
|
+
return getComponentNameFromType(type(innerType));
|
|
907
|
+
} catch (x) {}
|
|
908
|
+
}
|
|
909
|
+
return null;
|
|
910
|
+
}
|
|
911
|
+
function testStringCoercion(value) {
|
|
912
|
+
return "" + value;
|
|
913
|
+
}
|
|
914
|
+
function checkKeyStringCoercion(value) {
|
|
915
|
+
try {
|
|
916
|
+
testStringCoercion(value);
|
|
917
|
+
var JSCompiler_inline_result = false;
|
|
918
|
+
} catch (e) {
|
|
919
|
+
JSCompiler_inline_result = true;
|
|
920
|
+
}
|
|
921
|
+
if (JSCompiler_inline_result) {
|
|
922
|
+
JSCompiler_inline_result = console;
|
|
923
|
+
var JSCompiler_temp_const = JSCompiler_inline_result.error;
|
|
924
|
+
var JSCompiler_inline_result$jscomp$0 = typeof Symbol === "function" && Symbol.toStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object";
|
|
925
|
+
JSCompiler_temp_const.call(JSCompiler_inline_result, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", JSCompiler_inline_result$jscomp$0);
|
|
926
|
+
return testStringCoercion(value);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
function getTaskName(type) {
|
|
930
|
+
if (type === REACT_FRAGMENT_TYPE)
|
|
931
|
+
return "<>";
|
|
932
|
+
if (typeof type === "object" && type !== null && type.$$typeof === REACT_LAZY_TYPE)
|
|
933
|
+
return "<...>";
|
|
934
|
+
try {
|
|
935
|
+
var name = getComponentNameFromType(type);
|
|
936
|
+
return name ? "<" + name + ">" : "<...>";
|
|
937
|
+
} catch (x) {
|
|
938
|
+
return "<...>";
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
function getOwner() {
|
|
942
|
+
var dispatcher = ReactSharedInternals.A;
|
|
943
|
+
return dispatcher === null ? null : dispatcher.getOwner();
|
|
944
|
+
}
|
|
945
|
+
function UnknownOwner() {
|
|
946
|
+
return Error("react-stack-top-frame");
|
|
947
|
+
}
|
|
948
|
+
function hasValidKey(config) {
|
|
949
|
+
if (hasOwnProperty.call(config, "key")) {
|
|
950
|
+
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
|
|
951
|
+
if (getter && getter.isReactWarning)
|
|
952
|
+
return false;
|
|
953
|
+
}
|
|
954
|
+
return config.key !== undefined;
|
|
955
|
+
}
|
|
956
|
+
function defineKeyPropWarningGetter(props, displayName) {
|
|
957
|
+
function warnAboutAccessingKey() {
|
|
958
|
+
specialPropKeyWarningShown || (specialPropKeyWarningShown = true, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", displayName));
|
|
959
|
+
}
|
|
960
|
+
warnAboutAccessingKey.isReactWarning = true;
|
|
961
|
+
Object.defineProperty(props, "key", {
|
|
962
|
+
get: warnAboutAccessingKey,
|
|
963
|
+
configurable: true
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
function elementRefGetterWithDeprecationWarning() {
|
|
967
|
+
var componentName = getComponentNameFromType(this.type);
|
|
968
|
+
didWarnAboutElementRef[componentName] || (didWarnAboutElementRef[componentName] = true, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."));
|
|
969
|
+
componentName = this.props.ref;
|
|
970
|
+
return componentName !== undefined ? componentName : null;
|
|
971
|
+
}
|
|
972
|
+
function ReactElement(type, key, props, owner, debugStack, debugTask) {
|
|
973
|
+
var refProp = props.ref;
|
|
974
|
+
type = {
|
|
975
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
976
|
+
type,
|
|
977
|
+
key,
|
|
978
|
+
props,
|
|
979
|
+
_owner: owner
|
|
980
|
+
};
|
|
981
|
+
(refProp !== undefined ? refProp : null) !== null ? Object.defineProperty(type, "ref", {
|
|
982
|
+
enumerable: false,
|
|
983
|
+
get: elementRefGetterWithDeprecationWarning
|
|
984
|
+
}) : Object.defineProperty(type, "ref", { enumerable: false, value: null });
|
|
985
|
+
type._store = {};
|
|
986
|
+
Object.defineProperty(type._store, "validated", {
|
|
987
|
+
configurable: false,
|
|
988
|
+
enumerable: false,
|
|
989
|
+
writable: true,
|
|
990
|
+
value: 0
|
|
991
|
+
});
|
|
992
|
+
Object.defineProperty(type, "_debugInfo", {
|
|
993
|
+
configurable: false,
|
|
994
|
+
enumerable: false,
|
|
995
|
+
writable: true,
|
|
996
|
+
value: null
|
|
997
|
+
});
|
|
998
|
+
Object.defineProperty(type, "_debugStack", {
|
|
999
|
+
configurable: false,
|
|
1000
|
+
enumerable: false,
|
|
1001
|
+
writable: true,
|
|
1002
|
+
value: debugStack
|
|
1003
|
+
});
|
|
1004
|
+
Object.defineProperty(type, "_debugTask", {
|
|
1005
|
+
configurable: false,
|
|
1006
|
+
enumerable: false,
|
|
1007
|
+
writable: true,
|
|
1008
|
+
value: debugTask
|
|
1009
|
+
});
|
|
1010
|
+
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
|
|
1011
|
+
return type;
|
|
1012
|
+
}
|
|
1013
|
+
function jsxDEVImpl(type, config, maybeKey, isStaticChildren, debugStack, debugTask) {
|
|
1014
|
+
var children = config.children;
|
|
1015
|
+
if (children !== undefined)
|
|
1016
|
+
if (isStaticChildren)
|
|
1017
|
+
if (isArrayImpl(children)) {
|
|
1018
|
+
for (isStaticChildren = 0;isStaticChildren < children.length; isStaticChildren++)
|
|
1019
|
+
validateChildKeys(children[isStaticChildren]);
|
|
1020
|
+
Object.freeze && Object.freeze(children);
|
|
1021
|
+
} else
|
|
1022
|
+
console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
1023
|
+
else
|
|
1024
|
+
validateChildKeys(children);
|
|
1025
|
+
if (hasOwnProperty.call(config, "key")) {
|
|
1026
|
+
children = getComponentNameFromType(type);
|
|
1027
|
+
var keys = Object.keys(config).filter(function(k) {
|
|
1028
|
+
return k !== "key";
|
|
1029
|
+
});
|
|
1030
|
+
isStaticChildren = 0 < keys.length ? "{key: someKey, " + keys.join(": ..., ") + ": ...}" : "{key: someKey}";
|
|
1031
|
+
didWarnAboutKeySpread[children + isStaticChildren] || (keys = 0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}", console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
1032
|
+
let props = %s;
|
|
1033
|
+
<%s {...props} />
|
|
1034
|
+
React keys must be passed directly to JSX without using spread:
|
|
1035
|
+
let props = %s;
|
|
1036
|
+
<%s key={someKey} {...props} />`, isStaticChildren, children, keys, children), didWarnAboutKeySpread[children + isStaticChildren] = true);
|
|
1037
|
+
}
|
|
1038
|
+
children = null;
|
|
1039
|
+
maybeKey !== undefined && (checkKeyStringCoercion(maybeKey), children = "" + maybeKey);
|
|
1040
|
+
hasValidKey(config) && (checkKeyStringCoercion(config.key), children = "" + config.key);
|
|
1041
|
+
if ("key" in config) {
|
|
1042
|
+
maybeKey = {};
|
|
1043
|
+
for (var propName in config)
|
|
1044
|
+
propName !== "key" && (maybeKey[propName] = config[propName]);
|
|
1045
|
+
} else
|
|
1046
|
+
maybeKey = config;
|
|
1047
|
+
children && defineKeyPropWarningGetter(maybeKey, typeof type === "function" ? type.displayName || type.name || "Unknown" : type);
|
|
1048
|
+
return ReactElement(type, children, maybeKey, getOwner(), debugStack, debugTask);
|
|
1049
|
+
}
|
|
1050
|
+
function validateChildKeys(node) {
|
|
1051
|
+
isValidElement(node) ? node._store && (node._store.validated = 1) : typeof node === "object" && node !== null && node.$$typeof === REACT_LAZY_TYPE && (node._payload.status === "fulfilled" ? isValidElement(node._payload.value) && node._payload.value._store && (node._payload.value._store.validated = 1) : node._store && (node._store.validated = 1));
|
|
1052
|
+
}
|
|
1053
|
+
function isValidElement(object) {
|
|
1054
|
+
return typeof object === "object" && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
1055
|
+
}
|
|
1056
|
+
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = Symbol.for("react.memo"), REACT_LAZY_TYPE = Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = Symbol.for("react.activity"), REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"), ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, hasOwnProperty = Object.prototype.hasOwnProperty, isArrayImpl = Array.isArray, createTask = console.createTask ? console.createTask : function() {
|
|
1057
|
+
return null;
|
|
1058
|
+
};
|
|
1059
|
+
React = {
|
|
1060
|
+
react_stack_bottom_frame: function(callStackForError) {
|
|
1061
|
+
return callStackForError();
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
var specialPropKeyWarningShown;
|
|
1065
|
+
var didWarnAboutElementRef = {};
|
|
1066
|
+
var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(React, UnknownOwner)();
|
|
1067
|
+
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
|
|
1068
|
+
var didWarnAboutKeySpread = {};
|
|
1069
|
+
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
1070
|
+
exports.jsxDEV = function(type, config, maybeKey, isStaticChildren) {
|
|
1071
|
+
var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
|
1072
|
+
return jsxDEVImpl(type, config, maybeKey, isStaticChildren, trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack, trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask);
|
|
1073
|
+
};
|
|
1074
|
+
})();
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
// ../../../../node_modules/react/jsx-dev-runtime.js
|
|
1078
|
+
var require_jsx_dev_runtime = __commonJS((exports, module) => {
|
|
1079
|
+
var react_jsx_dev_runtime_development = __toESM(require_react_jsx_dev_runtime_development());
|
|
1080
|
+
if (false) {} else {
|
|
1081
|
+
module.exports = react_jsx_dev_runtime_development;
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
// src/router/types.ts
|
|
1086
|
+
var DEFAULT_ROUTER_CONFIG = {
|
|
1087
|
+
adapter: "heuristic",
|
|
1088
|
+
speculation: {
|
|
1089
|
+
enabled: true,
|
|
1090
|
+
depth: 2,
|
|
1091
|
+
prerenderTop: 1,
|
|
1092
|
+
maxPrefetch: 5
|
|
1093
|
+
},
|
|
1094
|
+
personalization: {
|
|
1095
|
+
featureGating: true,
|
|
1096
|
+
emotionTheming: true,
|
|
1097
|
+
componentOrdering: true,
|
|
1098
|
+
densityAdaptation: true
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
var DEFAULT_ESI_CONFIG = {
|
|
1102
|
+
enabled: false,
|
|
1103
|
+
endpoint: process.env.ESI_ENDPOINT || "",
|
|
1104
|
+
timeout: 5000,
|
|
1105
|
+
defaultCacheTtl: 300,
|
|
1106
|
+
maxConcurrent: 5,
|
|
1107
|
+
warmupModels: ["llm"],
|
|
1108
|
+
tierLimits: {
|
|
1109
|
+
free: {
|
|
1110
|
+
maxInferencesPerRequest: 2,
|
|
1111
|
+
allowedModels: ["llm", "embed"],
|
|
1112
|
+
maxTokens: 500
|
|
1113
|
+
},
|
|
1114
|
+
starter: {
|
|
1115
|
+
maxInferencesPerRequest: 5,
|
|
1116
|
+
allowedModels: ["llm", "embed", "classify"],
|
|
1117
|
+
maxTokens: 1000
|
|
1118
|
+
},
|
|
1119
|
+
pro: {
|
|
1120
|
+
maxInferencesPerRequest: 20,
|
|
1121
|
+
allowedModels: ["llm", "embed", "classify", "vision", "tts"],
|
|
1122
|
+
maxTokens: 4000
|
|
1123
|
+
},
|
|
1124
|
+
enterprise: {
|
|
1125
|
+
maxInferencesPerRequest: 100,
|
|
1126
|
+
allowedModels: ["llm", "embed", "classify", "vision", "tts", "stt", "custom"],
|
|
1127
|
+
maxTokens: 32000
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
// src/router/esi.ts
|
|
1132
|
+
var esiCache = new Map;
|
|
1133
|
+
function getCacheKey(directive, context) {
|
|
1134
|
+
const contextParts = directive.contextAware ? [
|
|
1135
|
+
context.tier,
|
|
1136
|
+
context.emotionState?.primary,
|
|
1137
|
+
context.localHour
|
|
1138
|
+
].join(":") : "";
|
|
1139
|
+
return directive.cacheKey || `esi:${directive.params.model}:${directive.content.value}:${contextParts}`;
|
|
1140
|
+
}
|
|
1141
|
+
function getCached(key) {
|
|
1142
|
+
const entry = esiCache.get(key);
|
|
1143
|
+
if (!entry)
|
|
1144
|
+
return null;
|
|
1145
|
+
if (Date.now() > entry.expiresAt) {
|
|
1146
|
+
esiCache.delete(key);
|
|
1147
|
+
return null;
|
|
1148
|
+
}
|
|
1149
|
+
return { ...entry.result, cached: true };
|
|
1150
|
+
}
|
|
1151
|
+
function setCache(key, result, ttl) {
|
|
1152
|
+
if (ttl <= 0)
|
|
1153
|
+
return;
|
|
1154
|
+
esiCache.set(key, {
|
|
1155
|
+
result,
|
|
1156
|
+
expiresAt: Date.now() + ttl * 1000
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
function interpolatePrompt(content, context, signals = []) {
|
|
1160
|
+
let prompt = content.value;
|
|
1161
|
+
if (content.type === "template" && content.variables) {
|
|
1162
|
+
for (const [key, value] of Object.entries(content.variables)) {
|
|
1163
|
+
prompt = prompt.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), String(value));
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
if (signals.length > 0) {
|
|
1167
|
+
const contextParts = [];
|
|
1168
|
+
if (signals.includes("emotion") && context.emotionState) {
|
|
1169
|
+
contextParts.push(`User emotion: ${context.emotionState.primary} ` + `(valence: ${context.emotionState.valence.toFixed(2)}, ` + `arousal: ${context.emotionState.arousal.toFixed(2)})`);
|
|
1170
|
+
}
|
|
1171
|
+
if (signals.includes("preferences") && Object.keys(context.preferences).length > 0) {
|
|
1172
|
+
contextParts.push(`User preferences: ${JSON.stringify(context.preferences)}`);
|
|
1173
|
+
}
|
|
1174
|
+
if (signals.includes("history") && context.recentPages.length > 0) {
|
|
1175
|
+
contextParts.push(`Recent pages: ${context.recentPages.slice(-5).join(", ")}`);
|
|
1176
|
+
}
|
|
1177
|
+
if (signals.includes("time")) {
|
|
1178
|
+
contextParts.push(`Local time: ${context.localHour}:00, Timezone: ${context.timezone}`);
|
|
1179
|
+
}
|
|
1180
|
+
if (signals.includes("device")) {
|
|
1181
|
+
contextParts.push(`Device: ${context.viewport.width}x${context.viewport.height}, ` + `Connection: ${context.connection}`);
|
|
1182
|
+
}
|
|
1183
|
+
if (contextParts.length > 0) {
|
|
1184
|
+
prompt = `[Context]
|
|
1185
|
+
${contextParts.join(`
|
|
1186
|
+
`)}
|
|
1187
|
+
|
|
1188
|
+
[Task]
|
|
1189
|
+
${prompt}`;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
return prompt;
|
|
1193
|
+
}
|
|
1194
|
+
function checkTierAccess(directive, context, config) {
|
|
1195
|
+
const tierLimits = config.tierLimits?.[context.tier];
|
|
1196
|
+
if (!tierLimits) {
|
|
1197
|
+
return { allowed: true };
|
|
1198
|
+
}
|
|
1199
|
+
if (!tierLimits.allowedModels.includes(directive.params.model)) {
|
|
1200
|
+
return {
|
|
1201
|
+
allowed: false,
|
|
1202
|
+
reason: `Model '${directive.params.model}' not available for ${context.tier} tier`
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
if (directive.params.maxTokens && directive.params.maxTokens > tierLimits.maxTokens) {
|
|
1206
|
+
return {
|
|
1207
|
+
allowed: false,
|
|
1208
|
+
reason: `Token limit ${directive.params.maxTokens} exceeds ${context.tier} tier max of ${tierLimits.maxTokens}`
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
return { allowed: true };
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
class EdgeWorkersESIProcessor {
|
|
1215
|
+
name = "edge-workers";
|
|
1216
|
+
config;
|
|
1217
|
+
warmupPromise;
|
|
1218
|
+
constructor(config = {}) {
|
|
1219
|
+
this.config = {
|
|
1220
|
+
enabled: config.enabled ?? false,
|
|
1221
|
+
endpoint: config.endpoint || process.env.ESI_ENDPOINT || "",
|
|
1222
|
+
timeout: config.timeout ?? 5000,
|
|
1223
|
+
defaultCacheTtl: config.defaultCacheTtl ?? 300,
|
|
1224
|
+
maxConcurrent: config.maxConcurrent ?? 5,
|
|
1225
|
+
warmupModels: config.warmupModels,
|
|
1226
|
+
tierLimits: config.tierLimits
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
async warmup() {
|
|
1230
|
+
if (this.warmupPromise)
|
|
1231
|
+
return this.warmupPromise;
|
|
1232
|
+
this.warmupPromise = (async () => {
|
|
1233
|
+
if (!this.config.warmupModels?.length)
|
|
1234
|
+
return;
|
|
1235
|
+
await Promise.all(this.config.warmupModels.map((model) => fetch(`${this.config.endpoint}/api/warmup`, {
|
|
1236
|
+
method: "POST",
|
|
1237
|
+
headers: { "Content-Type": "application/json" },
|
|
1238
|
+
body: JSON.stringify({ model })
|
|
1239
|
+
}).catch(() => {})));
|
|
1240
|
+
})();
|
|
1241
|
+
return this.warmupPromise;
|
|
1242
|
+
}
|
|
1243
|
+
isModelAvailable(model) {
|
|
1244
|
+
return ["llm", "embed", "vision", "tts", "stt", "emotion", "classify", "custom"].includes(model);
|
|
1245
|
+
}
|
|
1246
|
+
async process(directive, context) {
|
|
1247
|
+
const startTime = Date.now();
|
|
1248
|
+
const cacheKey = getCacheKey(directive, context);
|
|
1249
|
+
const cached = getCached(cacheKey);
|
|
1250
|
+
if (cached) {
|
|
1251
|
+
return cached;
|
|
1252
|
+
}
|
|
1253
|
+
const access = checkTierAccess(directive, context, this.config);
|
|
1254
|
+
if (!access.allowed) {
|
|
1255
|
+
return {
|
|
1256
|
+
id: directive.id,
|
|
1257
|
+
success: false,
|
|
1258
|
+
error: access.reason,
|
|
1259
|
+
latencyMs: Date.now() - startTime,
|
|
1260
|
+
cached: false,
|
|
1261
|
+
model: directive.params.model
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
const prompt = directive.contextAware ? interpolatePrompt(directive.content, context, directive.signals) : directive.content.value;
|
|
1265
|
+
try {
|
|
1266
|
+
const result = await this.callEdgeWorkers(directive, prompt);
|
|
1267
|
+
const cacheTtl = directive.params.cacheTtl ?? this.config.defaultCacheTtl;
|
|
1268
|
+
setCache(cacheKey, result, cacheTtl);
|
|
1269
|
+
return {
|
|
1270
|
+
...result,
|
|
1271
|
+
latencyMs: Date.now() - startTime
|
|
1272
|
+
};
|
|
1273
|
+
} catch (error) {
|
|
1274
|
+
if (directive.params.fallback) {
|
|
1275
|
+
return {
|
|
1276
|
+
id: directive.id,
|
|
1277
|
+
success: true,
|
|
1278
|
+
output: directive.params.fallback,
|
|
1279
|
+
latencyMs: Date.now() - startTime,
|
|
1280
|
+
cached: false,
|
|
1281
|
+
model: directive.params.model
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
return {
|
|
1285
|
+
id: directive.id,
|
|
1286
|
+
success: false,
|
|
1287
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
1288
|
+
latencyMs: Date.now() - startTime,
|
|
1289
|
+
cached: false,
|
|
1290
|
+
model: directive.params.model
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
async processBatch(directives, context) {
|
|
1295
|
+
const semaphore = new Semaphore(this.config.maxConcurrent);
|
|
1296
|
+
return Promise.all(directives.map(async (directive) => {
|
|
1297
|
+
await semaphore.acquire();
|
|
1298
|
+
try {
|
|
1299
|
+
return await this.process(directive, context);
|
|
1300
|
+
} finally {
|
|
1301
|
+
semaphore.release();
|
|
1302
|
+
}
|
|
1303
|
+
}));
|
|
1304
|
+
}
|
|
1305
|
+
async stream(directive, context, onChunk) {
|
|
1306
|
+
const startTime = Date.now();
|
|
1307
|
+
const access = checkTierAccess(directive, context, this.config);
|
|
1308
|
+
if (!access.allowed) {
|
|
1309
|
+
return {
|
|
1310
|
+
id: directive.id,
|
|
1311
|
+
success: false,
|
|
1312
|
+
error: access.reason,
|
|
1313
|
+
latencyMs: Date.now() - startTime,
|
|
1314
|
+
cached: false,
|
|
1315
|
+
model: directive.params.model
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
const prompt = directive.contextAware ? interpolatePrompt(directive.content, context, directive.signals) : directive.content.value;
|
|
1319
|
+
try {
|
|
1320
|
+
const response = await fetch(`${this.config.endpoint}/api/llm/stream`, {
|
|
1321
|
+
method: "POST",
|
|
1322
|
+
headers: { "Content-Type": "application/json" },
|
|
1323
|
+
body: JSON.stringify({
|
|
1324
|
+
input: prompt,
|
|
1325
|
+
model: directive.params.variant,
|
|
1326
|
+
options: {
|
|
1327
|
+
temperature: directive.params.temperature,
|
|
1328
|
+
max_tokens: directive.params.maxTokens,
|
|
1329
|
+
stop: directive.params.stop,
|
|
1330
|
+
top_p: directive.params.topP,
|
|
1331
|
+
system: directive.params.system
|
|
1332
|
+
}
|
|
1333
|
+
}),
|
|
1334
|
+
signal: AbortSignal.timeout(directive.params.timeout ?? this.config.timeout)
|
|
1335
|
+
});
|
|
1336
|
+
if (!response.ok) {
|
|
1337
|
+
throw new Error(`Stream failed: ${response.status}`);
|
|
1338
|
+
}
|
|
1339
|
+
const reader = response.body?.getReader();
|
|
1340
|
+
if (!reader) {
|
|
1341
|
+
throw new Error("No response body");
|
|
1342
|
+
}
|
|
1343
|
+
const decoder = new TextDecoder;
|
|
1344
|
+
let fullOutput = "";
|
|
1345
|
+
while (true) {
|
|
1346
|
+
const { done, value } = await reader.read();
|
|
1347
|
+
if (done)
|
|
1348
|
+
break;
|
|
1349
|
+
const chunk = decoder.decode(value);
|
|
1350
|
+
fullOutput += chunk;
|
|
1351
|
+
onChunk(chunk);
|
|
1352
|
+
}
|
|
1353
|
+
return {
|
|
1354
|
+
id: directive.id,
|
|
1355
|
+
success: true,
|
|
1356
|
+
output: fullOutput,
|
|
1357
|
+
latencyMs: Date.now() - startTime,
|
|
1358
|
+
cached: false,
|
|
1359
|
+
model: directive.params.variant || directive.params.model
|
|
1360
|
+
};
|
|
1361
|
+
} catch (error) {
|
|
1362
|
+
if (directive.params.fallback) {
|
|
1363
|
+
onChunk(directive.params.fallback);
|
|
1364
|
+
return {
|
|
1365
|
+
id: directive.id,
|
|
1366
|
+
success: true,
|
|
1367
|
+
output: directive.params.fallback,
|
|
1368
|
+
latencyMs: Date.now() - startTime,
|
|
1369
|
+
cached: false,
|
|
1370
|
+
model: directive.params.model
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
return {
|
|
1374
|
+
id: directive.id,
|
|
1375
|
+
success: false,
|
|
1376
|
+
error: error instanceof Error ? error.message : "Stream failed",
|
|
1377
|
+
latencyMs: Date.now() - startTime,
|
|
1378
|
+
cached: false,
|
|
1379
|
+
model: directive.params.model
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
async callEdgeWorkers(directive, prompt) {
|
|
1384
|
+
const endpoint = this.getEndpointForModel(directive.params.model);
|
|
1385
|
+
const response = await fetch(`${this.config.endpoint}${endpoint}`, {
|
|
1386
|
+
method: "POST",
|
|
1387
|
+
headers: { "Content-Type": "application/json" },
|
|
1388
|
+
body: JSON.stringify(this.buildRequestBody(directive, prompt)),
|
|
1389
|
+
signal: AbortSignal.timeout(directive.params.timeout ?? this.config.timeout)
|
|
1390
|
+
});
|
|
1391
|
+
if (!response.ok) {
|
|
1392
|
+
const error = await response.text();
|
|
1393
|
+
throw new Error(`ESI inference failed: ${response.status} - ${error}`);
|
|
1394
|
+
}
|
|
1395
|
+
const data = await response.json();
|
|
1396
|
+
return this.parseResponse(directive, data);
|
|
1397
|
+
}
|
|
1398
|
+
getEndpointForModel(model) {
|
|
1399
|
+
switch (model) {
|
|
1400
|
+
case "llm":
|
|
1401
|
+
return "/api/llm/infer";
|
|
1402
|
+
case "embed":
|
|
1403
|
+
return "/api/embed";
|
|
1404
|
+
case "vision":
|
|
1405
|
+
return "/api/vision";
|
|
1406
|
+
case "tts":
|
|
1407
|
+
return "/api/tts";
|
|
1408
|
+
case "stt":
|
|
1409
|
+
return "/api/stt";
|
|
1410
|
+
case "emotion":
|
|
1411
|
+
return "/api/emotion";
|
|
1412
|
+
case "classify":
|
|
1413
|
+
return "/api/classify";
|
|
1414
|
+
case "custom":
|
|
1415
|
+
return "/api/custom";
|
|
1416
|
+
default:
|
|
1417
|
+
return "/api/llm/infer";
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
buildRequestBody(directive, prompt) {
|
|
1421
|
+
const { params, content } = directive;
|
|
1422
|
+
const body = {
|
|
1423
|
+
input: content.type === "base64" ? content.value : prompt,
|
|
1424
|
+
model: params.variant
|
|
1425
|
+
};
|
|
1426
|
+
if (params.model === "llm") {
|
|
1427
|
+
body.options = {
|
|
1428
|
+
temperature: params.temperature,
|
|
1429
|
+
max_tokens: params.maxTokens,
|
|
1430
|
+
stop: params.stop,
|
|
1431
|
+
top_p: params.topP,
|
|
1432
|
+
frequency_penalty: params.frequencyPenalty,
|
|
1433
|
+
presence_penalty: params.presencePenalty,
|
|
1434
|
+
system: params.system
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
if (params.custom) {
|
|
1438
|
+
body.custom = params.custom;
|
|
1439
|
+
}
|
|
1440
|
+
return body;
|
|
1441
|
+
}
|
|
1442
|
+
parseResponse(directive, data) {
|
|
1443
|
+
const base = {
|
|
1444
|
+
id: directive.id,
|
|
1445
|
+
success: true,
|
|
1446
|
+
latencyMs: 0,
|
|
1447
|
+
cached: false,
|
|
1448
|
+
model: String(data.model || directive.params.model)
|
|
1449
|
+
};
|
|
1450
|
+
switch (directive.params.model) {
|
|
1451
|
+
case "embed":
|
|
1452
|
+
return { ...base, embedding: data.embedding };
|
|
1453
|
+
case "tts":
|
|
1454
|
+
return { ...base, audio: data.audio };
|
|
1455
|
+
default:
|
|
1456
|
+
return {
|
|
1457
|
+
...base,
|
|
1458
|
+
output: String(data.output || data.text || data.result || ""),
|
|
1459
|
+
tokens: data.tokens
|
|
1460
|
+
};
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
class Semaphore {
|
|
1466
|
+
permits;
|
|
1467
|
+
queue = [];
|
|
1468
|
+
constructor(permits) {
|
|
1469
|
+
this.permits = permits;
|
|
1470
|
+
}
|
|
1471
|
+
async acquire() {
|
|
1472
|
+
if (this.permits > 0) {
|
|
1473
|
+
this.permits--;
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
return new Promise((resolve) => {
|
|
1477
|
+
this.queue.push(resolve);
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
release() {
|
|
1481
|
+
const next = this.queue.shift();
|
|
1482
|
+
if (next) {
|
|
1483
|
+
next();
|
|
1484
|
+
} else {
|
|
1485
|
+
this.permits++;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
function esiInfer(prompt, options = {}) {
|
|
1490
|
+
return {
|
|
1491
|
+
id: `esi-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
1492
|
+
params: {
|
|
1493
|
+
model: "llm",
|
|
1494
|
+
...options
|
|
1495
|
+
},
|
|
1496
|
+
content: {
|
|
1497
|
+
type: "text",
|
|
1498
|
+
value: prompt
|
|
1499
|
+
},
|
|
1500
|
+
contextAware: options.system?.includes("{context}")
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
function esiEmbed(text) {
|
|
1504
|
+
return {
|
|
1505
|
+
id: `esi-embed-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
1506
|
+
params: { model: "embed" },
|
|
1507
|
+
content: { type: "text", value: text }
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
function esiEmotion(text, contextAware = true) {
|
|
1511
|
+
return {
|
|
1512
|
+
id: `esi-emotion-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
1513
|
+
params: { model: "emotion" },
|
|
1514
|
+
content: { type: "text", value: text },
|
|
1515
|
+
contextAware,
|
|
1516
|
+
signals: contextAware ? ["emotion", "history"] : undefined
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
function esiVision(base64Image, prompt, options = {}) {
|
|
1520
|
+
return {
|
|
1521
|
+
id: `esi-vision-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
1522
|
+
params: {
|
|
1523
|
+
model: "vision",
|
|
1524
|
+
system: prompt,
|
|
1525
|
+
...options
|
|
1526
|
+
},
|
|
1527
|
+
content: { type: "base64", value: base64Image }
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
function esiWithContext(prompt, signals = ["emotion", "preferences", "time"], options = {}) {
|
|
1531
|
+
return {
|
|
1532
|
+
id: `esi-ctx-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
1533
|
+
params: {
|
|
1534
|
+
model: "llm",
|
|
1535
|
+
...options
|
|
1536
|
+
},
|
|
1537
|
+
content: { type: "text", value: prompt },
|
|
1538
|
+
contextAware: true,
|
|
1539
|
+
signals
|
|
1540
|
+
};
|
|
1541
|
+
}
|
|
1542
|
+
// src/router/esi-react.tsx
|
|
1543
|
+
var import_react = __toESM(require_react(), 1);
|
|
1544
|
+
var jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
|
|
1545
|
+
var ESIContext = import_react.createContext(null);
|
|
1546
|
+
var ESIProvider = ({
|
|
1547
|
+
children,
|
|
1548
|
+
config,
|
|
1549
|
+
userContext,
|
|
1550
|
+
processor: customProcessor
|
|
1551
|
+
}) => {
|
|
1552
|
+
const [processor] = import_react.useState(() => customProcessor || new EdgeWorkersESIProcessor(config));
|
|
1553
|
+
import_react.useEffect(() => {
|
|
1554
|
+
processor.warmup?.();
|
|
1555
|
+
}, [processor]);
|
|
1556
|
+
const process2 = import_react.useCallback(async (directive) => {
|
|
1557
|
+
if (!userContext) {
|
|
1558
|
+
return {
|
|
1559
|
+
id: directive.id,
|
|
1560
|
+
success: false,
|
|
1561
|
+
error: "No user context available",
|
|
1562
|
+
latencyMs: 0,
|
|
1563
|
+
cached: false,
|
|
1564
|
+
model: directive.params.model
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
return processor.process(directive, userContext);
|
|
1568
|
+
}, [processor, userContext]);
|
|
1569
|
+
const processWithStream = import_react.useCallback(async (directive, onChunk) => {
|
|
1570
|
+
if (!userContext) {
|
|
1571
|
+
return {
|
|
1572
|
+
id: directive.id,
|
|
1573
|
+
success: false,
|
|
1574
|
+
error: "No user context available",
|
|
1575
|
+
latencyMs: 0,
|
|
1576
|
+
cached: false,
|
|
1577
|
+
model: directive.params.model
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
if (!processor.stream) {
|
|
1581
|
+
return processor.process(directive, userContext);
|
|
1582
|
+
}
|
|
1583
|
+
return processor.stream(directive, userContext, onChunk);
|
|
1584
|
+
}, [processor, userContext]);
|
|
1585
|
+
return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ESIContext.Provider, {
|
|
1586
|
+
value: {
|
|
1587
|
+
processor,
|
|
1588
|
+
userContext: userContext || null,
|
|
1589
|
+
enabled: config?.enabled ?? true,
|
|
1590
|
+
process: process2,
|
|
1591
|
+
processWithStream
|
|
1592
|
+
},
|
|
1593
|
+
children
|
|
1594
|
+
}, undefined, false, undefined, this);
|
|
1595
|
+
};
|
|
1596
|
+
function useESI() {
|
|
1597
|
+
const ctx = import_react.useContext(ESIContext);
|
|
1598
|
+
if (!ctx) {
|
|
1599
|
+
throw new Error("useESI must be used within an ESIProvider");
|
|
1600
|
+
}
|
|
1601
|
+
return ctx;
|
|
1602
|
+
}
|
|
1603
|
+
var ESIInfer = ({
|
|
1604
|
+
children,
|
|
1605
|
+
prompt,
|
|
1606
|
+
model = "llm",
|
|
1607
|
+
variant,
|
|
1608
|
+
temperature,
|
|
1609
|
+
maxTokens,
|
|
1610
|
+
system,
|
|
1611
|
+
stream = false,
|
|
1612
|
+
fallback,
|
|
1613
|
+
loading = "...",
|
|
1614
|
+
contextAware = false,
|
|
1615
|
+
signals,
|
|
1616
|
+
cacheTtl,
|
|
1617
|
+
render,
|
|
1618
|
+
className,
|
|
1619
|
+
onComplete,
|
|
1620
|
+
onError
|
|
1621
|
+
}) => {
|
|
1622
|
+
const { process: process2, processWithStream, enabled } = useESI();
|
|
1623
|
+
const [output, setOutput] = import_react.useState("");
|
|
1624
|
+
const [isLoading, setIsLoading] = import_react.useState(true);
|
|
1625
|
+
const [error, setError] = import_react.useState(null);
|
|
1626
|
+
const promptText = prompt || (typeof children === "string" ? children : String(children || ""));
|
|
1627
|
+
import_react.useEffect(() => {
|
|
1628
|
+
if (!enabled) {
|
|
1629
|
+
setOutput(typeof fallback === "string" ? fallback : "");
|
|
1630
|
+
setIsLoading(false);
|
|
1631
|
+
return;
|
|
1632
|
+
}
|
|
1633
|
+
const directive = contextAware ? esiWithContext(promptText, signals, {
|
|
1634
|
+
model,
|
|
1635
|
+
variant,
|
|
1636
|
+
temperature,
|
|
1637
|
+
maxTokens,
|
|
1638
|
+
system,
|
|
1639
|
+
cacheTtl,
|
|
1640
|
+
fallback: typeof fallback === "string" ? fallback : undefined
|
|
1641
|
+
}) : esiInfer(promptText, {
|
|
1642
|
+
model,
|
|
1643
|
+
variant,
|
|
1644
|
+
temperature,
|
|
1645
|
+
maxTokens,
|
|
1646
|
+
system,
|
|
1647
|
+
cacheTtl,
|
|
1648
|
+
fallback: typeof fallback === "string" ? fallback : undefined
|
|
1649
|
+
});
|
|
1650
|
+
if (stream) {
|
|
1651
|
+
setOutput("");
|
|
1652
|
+
processWithStream(directive, (chunk) => {
|
|
1653
|
+
setOutput((prev) => prev + chunk);
|
|
1654
|
+
}).then((result) => {
|
|
1655
|
+
setIsLoading(false);
|
|
1656
|
+
if (!result.success) {
|
|
1657
|
+
setError(result.error || "Inference failed");
|
|
1658
|
+
onError?.(result.error || "Inference failed");
|
|
1659
|
+
}
|
|
1660
|
+
onComplete?.(result);
|
|
1661
|
+
});
|
|
1662
|
+
} else {
|
|
1663
|
+
process2(directive).then((result) => {
|
|
1664
|
+
setIsLoading(false);
|
|
1665
|
+
if (result.success && result.output) {
|
|
1666
|
+
setOutput(result.output);
|
|
1667
|
+
} else {
|
|
1668
|
+
setError(result.error || "Inference failed");
|
|
1669
|
+
onError?.(result.error || "Inference failed");
|
|
1670
|
+
}
|
|
1671
|
+
onComplete?.(result);
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
}, [promptText, model, variant, temperature, maxTokens, system, contextAware, stream, enabled]);
|
|
1675
|
+
if (isLoading && !stream) {
|
|
1676
|
+
return /* @__PURE__ */ jsx_dev_runtime.jsxDEV("span", {
|
|
1677
|
+
className,
|
|
1678
|
+
children: loading
|
|
1679
|
+
}, undefined, false, undefined, this);
|
|
1680
|
+
}
|
|
1681
|
+
if (error && fallback) {
|
|
1682
|
+
return /* @__PURE__ */ jsx_dev_runtime.jsxDEV("span", {
|
|
1683
|
+
className,
|
|
1684
|
+
children: fallback
|
|
1685
|
+
}, undefined, false, undefined, this);
|
|
1686
|
+
}
|
|
1687
|
+
if (render) {
|
|
1688
|
+
return /* @__PURE__ */ jsx_dev_runtime.jsxDEV("span", {
|
|
1689
|
+
className,
|
|
1690
|
+
children: render({
|
|
1691
|
+
id: "",
|
|
1692
|
+
success: !error,
|
|
1693
|
+
output,
|
|
1694
|
+
error: error || undefined,
|
|
1695
|
+
latencyMs: 0,
|
|
1696
|
+
cached: false,
|
|
1697
|
+
model
|
|
1698
|
+
})
|
|
1699
|
+
}, undefined, false, undefined, this);
|
|
1700
|
+
}
|
|
1701
|
+
return /* @__PURE__ */ jsx_dev_runtime.jsxDEV("span", {
|
|
1702
|
+
className,
|
|
1703
|
+
children: output || (isLoading ? loading : "")
|
|
1704
|
+
}, undefined, false, undefined, this);
|
|
1705
|
+
};
|
|
1706
|
+
var ESIEmbed = ({ children, onComplete, onError }) => {
|
|
1707
|
+
const { process: process2, enabled } = useESI();
|
|
1708
|
+
const text = typeof children === "string" ? children : String(children || "");
|
|
1709
|
+
import_react.useEffect(() => {
|
|
1710
|
+
if (!enabled)
|
|
1711
|
+
return;
|
|
1712
|
+
const directive = esiEmbed(text);
|
|
1713
|
+
process2(directive).then((result) => {
|
|
1714
|
+
if (result.success && result.embedding) {
|
|
1715
|
+
onComplete?.(result.embedding);
|
|
1716
|
+
} else {
|
|
1717
|
+
onError?.(result.error || "Embedding failed");
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1720
|
+
}, [text, enabled]);
|
|
1721
|
+
return null;
|
|
1722
|
+
};
|
|
1723
|
+
var ESIEmotion = ({
|
|
1724
|
+
children,
|
|
1725
|
+
contextAware = true,
|
|
1726
|
+
onComplete,
|
|
1727
|
+
onError
|
|
1728
|
+
}) => {
|
|
1729
|
+
const { process: process2, enabled } = useESI();
|
|
1730
|
+
const text = typeof children === "string" ? children : String(children || "");
|
|
1731
|
+
import_react.useEffect(() => {
|
|
1732
|
+
if (!enabled)
|
|
1733
|
+
return;
|
|
1734
|
+
const directive = esiEmotion(text, contextAware);
|
|
1735
|
+
process2(directive).then((result) => {
|
|
1736
|
+
if (result.success && result.output) {
|
|
1737
|
+
try {
|
|
1738
|
+
const parsed = JSON.parse(result.output);
|
|
1739
|
+
onComplete?.(parsed);
|
|
1740
|
+
} catch {
|
|
1741
|
+
onComplete?.({ emotion: result.output, confidence: 1 });
|
|
1742
|
+
}
|
|
1743
|
+
} else {
|
|
1744
|
+
onError?.(result.error || "Emotion detection failed");
|
|
1745
|
+
}
|
|
1746
|
+
});
|
|
1747
|
+
}, [text, contextAware, enabled]);
|
|
1748
|
+
return null;
|
|
1749
|
+
};
|
|
1750
|
+
var ESIVision = ({
|
|
1751
|
+
src,
|
|
1752
|
+
prompt,
|
|
1753
|
+
fallback,
|
|
1754
|
+
loading = "...",
|
|
1755
|
+
className,
|
|
1756
|
+
onComplete,
|
|
1757
|
+
onError
|
|
1758
|
+
}) => {
|
|
1759
|
+
const { process: process2, enabled } = useESI();
|
|
1760
|
+
const [output, setOutput] = import_react.useState("");
|
|
1761
|
+
const [isLoading, setIsLoading] = import_react.useState(true);
|
|
1762
|
+
const [error, setError] = import_react.useState(null);
|
|
1763
|
+
import_react.useEffect(() => {
|
|
1764
|
+
if (!enabled) {
|
|
1765
|
+
setOutput(typeof fallback === "string" ? fallback : "");
|
|
1766
|
+
setIsLoading(false);
|
|
1767
|
+
return;
|
|
1768
|
+
}
|
|
1769
|
+
const directive = esiVision(src, prompt);
|
|
1770
|
+
process2(directive).then((result) => {
|
|
1771
|
+
setIsLoading(false);
|
|
1772
|
+
if (result.success && result.output) {
|
|
1773
|
+
setOutput(result.output);
|
|
1774
|
+
} else {
|
|
1775
|
+
setError(result.error || "Vision analysis failed");
|
|
1776
|
+
onError?.(result.error || "Vision analysis failed");
|
|
1777
|
+
}
|
|
1778
|
+
onComplete?.(result);
|
|
1779
|
+
});
|
|
1780
|
+
}, [src, prompt, enabled]);
|
|
1781
|
+
if (isLoading) {
|
|
1782
|
+
return /* @__PURE__ */ jsx_dev_runtime.jsxDEV("span", {
|
|
1783
|
+
className,
|
|
1784
|
+
children: loading
|
|
1785
|
+
}, undefined, false, undefined, this);
|
|
1786
|
+
}
|
|
1787
|
+
if (error && fallback) {
|
|
1788
|
+
return /* @__PURE__ */ jsx_dev_runtime.jsxDEV("span", {
|
|
1789
|
+
className,
|
|
1790
|
+
children: fallback
|
|
1791
|
+
}, undefined, false, undefined, this);
|
|
1792
|
+
}
|
|
1793
|
+
return /* @__PURE__ */ jsx_dev_runtime.jsxDEV("span", {
|
|
1794
|
+
className,
|
|
1795
|
+
children: output
|
|
1796
|
+
}, undefined, false, undefined, this);
|
|
1797
|
+
};
|
|
1798
|
+
function useESIInfer(options = {}) {
|
|
1799
|
+
const { process: process2, processWithStream, enabled } = useESI();
|
|
1800
|
+
const [result, setResult] = import_react.useState(null);
|
|
1801
|
+
const [isLoading, setIsLoading] = import_react.useState(false);
|
|
1802
|
+
const [error, setError] = import_react.useState(null);
|
|
1803
|
+
const run = import_react.useCallback(async (prompt) => {
|
|
1804
|
+
if (!enabled) {
|
|
1805
|
+
setError("ESI is disabled");
|
|
1806
|
+
return null;
|
|
1807
|
+
}
|
|
1808
|
+
setIsLoading(true);
|
|
1809
|
+
setError(null);
|
|
1810
|
+
const directive = options.contextAware ? esiWithContext(prompt, options.signals, {
|
|
1811
|
+
model: options.model,
|
|
1812
|
+
variant: options.variant,
|
|
1813
|
+
temperature: options.temperature,
|
|
1814
|
+
maxTokens: options.maxTokens,
|
|
1815
|
+
system: options.system,
|
|
1816
|
+
cacheTtl: options.cacheTtl
|
|
1817
|
+
}) : esiInfer(prompt, {
|
|
1818
|
+
model: options.model,
|
|
1819
|
+
variant: options.variant,
|
|
1820
|
+
temperature: options.temperature,
|
|
1821
|
+
maxTokens: options.maxTokens,
|
|
1822
|
+
system: options.system,
|
|
1823
|
+
cacheTtl: options.cacheTtl
|
|
1824
|
+
});
|
|
1825
|
+
try {
|
|
1826
|
+
let inferenceResult;
|
|
1827
|
+
if (options.stream) {
|
|
1828
|
+
let output = "";
|
|
1829
|
+
inferenceResult = await processWithStream(directive, (chunk) => {
|
|
1830
|
+
output += chunk;
|
|
1831
|
+
setResult((prev) => ({
|
|
1832
|
+
...prev,
|
|
1833
|
+
output
|
|
1834
|
+
}));
|
|
1835
|
+
});
|
|
1836
|
+
} else {
|
|
1837
|
+
inferenceResult = await process2(directive);
|
|
1838
|
+
}
|
|
1839
|
+
setResult(inferenceResult);
|
|
1840
|
+
setIsLoading(false);
|
|
1841
|
+
if (!inferenceResult.success) {
|
|
1842
|
+
setError(inferenceResult.error || "Inference failed");
|
|
1843
|
+
}
|
|
1844
|
+
options.onComplete?.(inferenceResult);
|
|
1845
|
+
return inferenceResult;
|
|
1846
|
+
} catch (err) {
|
|
1847
|
+
const errorMsg = err instanceof Error ? err.message : "Unknown error";
|
|
1848
|
+
setError(errorMsg);
|
|
1849
|
+
setIsLoading(false);
|
|
1850
|
+
options.onError?.(errorMsg);
|
|
1851
|
+
return null;
|
|
1852
|
+
}
|
|
1853
|
+
}, [process2, processWithStream, enabled, options]);
|
|
1854
|
+
const reset = import_react.useCallback(() => {
|
|
1855
|
+
setResult(null);
|
|
1856
|
+
setError(null);
|
|
1857
|
+
setIsLoading(false);
|
|
1858
|
+
}, []);
|
|
1859
|
+
return { run, result, isLoading, error, reset };
|
|
1860
|
+
}
|
|
1861
|
+
var ESI = {
|
|
1862
|
+
Provider: ESIProvider,
|
|
1863
|
+
Infer: ESIInfer,
|
|
1864
|
+
Embed: ESIEmbed,
|
|
1865
|
+
Emotion: ESIEmotion,
|
|
1866
|
+
Vision: ESIVision
|
|
1867
|
+
};
|
|
1868
|
+
// src/router/heuristic-adapter.ts
|
|
1869
|
+
var DEFAULT_CONFIG = {
|
|
1870
|
+
tierFeatures: {
|
|
1871
|
+
free: {},
|
|
1872
|
+
starter: {},
|
|
1873
|
+
pro: {},
|
|
1874
|
+
enterprise: {}
|
|
1875
|
+
},
|
|
1876
|
+
defaultAccent: "#6366f1",
|
|
1877
|
+
signals: {},
|
|
1878
|
+
defaultPaths: ["/"],
|
|
1879
|
+
maxSpeculationPaths: 5
|
|
1880
|
+
};
|
|
1881
|
+
function defaultDeriveTheme(context) {
|
|
1882
|
+
if (context.preferences.theme) {
|
|
1883
|
+
return context.preferences.theme;
|
|
1884
|
+
}
|
|
1885
|
+
const hour = context.localHour;
|
|
1886
|
+
const isNight = hour >= 20 || hour < 6;
|
|
1887
|
+
const isEvening = hour >= 18 && hour < 20;
|
|
1888
|
+
if (isNight) {
|
|
1889
|
+
return "dark";
|
|
1890
|
+
}
|
|
1891
|
+
if (isEvening) {
|
|
1892
|
+
return "auto";
|
|
1893
|
+
}
|
|
1894
|
+
return "light";
|
|
1895
|
+
}
|
|
1896
|
+
function determineDensity(context) {
|
|
1897
|
+
if (context.preferences.density) {
|
|
1898
|
+
return context.preferences.density;
|
|
1899
|
+
}
|
|
1900
|
+
const { width, height } = context.viewport;
|
|
1901
|
+
if (width < 768) {
|
|
1902
|
+
return "compact";
|
|
1903
|
+
}
|
|
1904
|
+
if (width >= 1440 && height >= 900) {
|
|
1905
|
+
return "comfortable";
|
|
1906
|
+
}
|
|
1907
|
+
return "normal";
|
|
1908
|
+
}
|
|
1909
|
+
function buildTransitionMatrix(history) {
|
|
1910
|
+
const matrix = {};
|
|
1911
|
+
for (let i = 0;i < history.length - 1; i++) {
|
|
1912
|
+
const from = history[i];
|
|
1913
|
+
const to = history[i + 1];
|
|
1914
|
+
if (!matrix[from]) {
|
|
1915
|
+
matrix[from] = {};
|
|
1916
|
+
}
|
|
1917
|
+
matrix[from][to] = (matrix[from][to] || 0) + 1;
|
|
1918
|
+
}
|
|
1919
|
+
for (const from of Object.keys(matrix)) {
|
|
1920
|
+
const total = Object.values(matrix[from]).reduce((a, b) => a + b, 0);
|
|
1921
|
+
for (const to of Object.keys(matrix[from])) {
|
|
1922
|
+
matrix[from][to] /= total;
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
return matrix;
|
|
1926
|
+
}
|
|
1927
|
+
function defaultPredictNavigation(currentPath, context, defaultPaths, topN) {
|
|
1928
|
+
const history = context.recentPages;
|
|
1929
|
+
if (history.length >= 3) {
|
|
1930
|
+
const matrix = buildTransitionMatrix(history);
|
|
1931
|
+
const transitions = matrix[currentPath];
|
|
1932
|
+
if (transitions) {
|
|
1933
|
+
const sorted = Object.entries(transitions).sort(([, a], [, b]) => b - a).slice(0, topN).map(([path]) => path);
|
|
1934
|
+
if (sorted.length > 0) {
|
|
1935
|
+
return sorted;
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
return defaultPaths.filter((p) => p !== currentPath).slice(0, topN);
|
|
1940
|
+
}
|
|
1941
|
+
function defaultScoreRelevance(node, context) {
|
|
1942
|
+
let score = 50;
|
|
1943
|
+
if (node.requiredTier) {
|
|
1944
|
+
const tierOrder = ["free", "starter", "pro", "enterprise"];
|
|
1945
|
+
const requiredIndex = tierOrder.indexOf(node.requiredTier);
|
|
1946
|
+
const userIndex = tierOrder.indexOf(context.tier);
|
|
1947
|
+
if (userIndex < requiredIndex) {
|
|
1948
|
+
return 0;
|
|
1949
|
+
}
|
|
1950
|
+
score += 10;
|
|
1951
|
+
}
|
|
1952
|
+
if (node.relevanceSignals) {
|
|
1953
|
+
for (const signal of node.relevanceSignals) {
|
|
1954
|
+
if (signal.startsWith("recentPage:")) {
|
|
1955
|
+
const page = signal.slice("recentPage:".length);
|
|
1956
|
+
if (context.recentPages.includes(page)) {
|
|
1957
|
+
score += 20;
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
if (signal.startsWith("timeOfDay:")) {
|
|
1961
|
+
const timeRange = signal.slice("timeOfDay:".length);
|
|
1962
|
+
const hour = context.localHour;
|
|
1963
|
+
if (timeRange === "morning" && hour >= 5 && hour < 12)
|
|
1964
|
+
score += 15;
|
|
1965
|
+
if (timeRange === "afternoon" && hour >= 12 && hour < 17)
|
|
1966
|
+
score += 15;
|
|
1967
|
+
if (timeRange === "evening" && hour >= 17 && hour < 21)
|
|
1968
|
+
score += 15;
|
|
1969
|
+
if (timeRange === "night" && (hour >= 21 || hour < 5))
|
|
1970
|
+
score += 15;
|
|
1971
|
+
}
|
|
1972
|
+
if (signal.startsWith("preference:")) {
|
|
1973
|
+
const pref = signal.slice("preference:".length);
|
|
1974
|
+
if (context.preferences[pref]) {
|
|
1975
|
+
score += 20;
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
if (signal.startsWith("tier:")) {
|
|
1979
|
+
const requiredTier = signal.slice("tier:".length);
|
|
1980
|
+
const tierOrder = ["free", "starter", "pro", "enterprise"];
|
|
1981
|
+
if (tierOrder.indexOf(context.tier) >= tierOrder.indexOf(requiredTier)) {
|
|
1982
|
+
score += 15;
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
if (node.defaultHidden) {
|
|
1988
|
+
score -= 30;
|
|
1989
|
+
}
|
|
1990
|
+
return Math.max(0, Math.min(100, score));
|
|
1991
|
+
}
|
|
1992
|
+
function orderComponentsByRelevance(tree, context, scoreRelevance) {
|
|
1993
|
+
const scored = [];
|
|
1994
|
+
tree.nodes.forEach((node, id) => {
|
|
1995
|
+
scored.push({
|
|
1996
|
+
id,
|
|
1997
|
+
score: scoreRelevance(node, context)
|
|
1998
|
+
});
|
|
1999
|
+
});
|
|
2000
|
+
return scored.sort((a, b) => b.score - a.score).map((s) => s.id);
|
|
2001
|
+
}
|
|
2002
|
+
function findHiddenComponents(tree, context, scoreRelevance) {
|
|
2003
|
+
const hidden = [];
|
|
2004
|
+
tree.nodes.forEach((node, id) => {
|
|
2005
|
+
const score = scoreRelevance(node, context);
|
|
2006
|
+
if (score === 0) {
|
|
2007
|
+
hidden.push(id);
|
|
2008
|
+
}
|
|
2009
|
+
});
|
|
2010
|
+
return hidden;
|
|
2011
|
+
}
|
|
2012
|
+
function computeSkeletonHints(route, context, tree) {
|
|
2013
|
+
let layout = "custom";
|
|
2014
|
+
if (route === "/" || route.includes("dashboard")) {
|
|
2015
|
+
layout = "dashboard";
|
|
2016
|
+
} else if (route.includes("chat") || route.includes("message")) {
|
|
2017
|
+
layout = "chat";
|
|
2018
|
+
} else if (route.includes("setting") || route.includes("config")) {
|
|
2019
|
+
layout = "settings";
|
|
2020
|
+
} else if (route.includes("tool")) {
|
|
2021
|
+
layout = "tools";
|
|
2022
|
+
}
|
|
2023
|
+
const baseHeight = context.viewport.height;
|
|
2024
|
+
const contentMultiplier = tree.nodes.size > 10 ? 1.5 : 1;
|
|
2025
|
+
const estimatedHeight = Math.round(baseHeight * contentMultiplier);
|
|
2026
|
+
const sections = tree.getChildren(tree.rootId).map((child, i) => ({
|
|
2027
|
+
id: child.id,
|
|
2028
|
+
height: Math.round(estimatedHeight / (tree.nodes.size || 1)),
|
|
2029
|
+
priority: i + 1
|
|
2030
|
+
}));
|
|
2031
|
+
return {
|
|
2032
|
+
layout,
|
|
2033
|
+
estimatedHeight,
|
|
2034
|
+
sections
|
|
2035
|
+
};
|
|
2036
|
+
}
|
|
2037
|
+
function getPrefetchDepth(context) {
|
|
2038
|
+
switch (context.connection) {
|
|
2039
|
+
case "fast":
|
|
2040
|
+
case "4g":
|
|
2041
|
+
return { prefetch: 5, prerender: 1 };
|
|
2042
|
+
case "3g":
|
|
2043
|
+
return { prefetch: 3, prerender: 0 };
|
|
2044
|
+
case "2g":
|
|
2045
|
+
return { prefetch: 1, prerender: 0 };
|
|
2046
|
+
case "slow-2g":
|
|
2047
|
+
return { prefetch: 0, prerender: 0 };
|
|
2048
|
+
default:
|
|
2049
|
+
return { prefetch: 3, prerender: 0 };
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
class HeuristicAdapter {
|
|
2054
|
+
name = "heuristic";
|
|
2055
|
+
config;
|
|
2056
|
+
constructor(config = {}) {
|
|
2057
|
+
this.config = {
|
|
2058
|
+
...DEFAULT_CONFIG,
|
|
2059
|
+
...config,
|
|
2060
|
+
tierFeatures: config.tierFeatures ?? DEFAULT_CONFIG.tierFeatures,
|
|
2061
|
+
signals: config.signals ?? DEFAULT_CONFIG.signals
|
|
2062
|
+
};
|
|
2063
|
+
}
|
|
2064
|
+
async route(path, context, tree) {
|
|
2065
|
+
const startTime = Date.now();
|
|
2066
|
+
const sessionId = this.generateSessionId(path, context);
|
|
2067
|
+
const featureFlags = { ...this.config.tierFeatures[context.tier] };
|
|
2068
|
+
const theme = this.config.signals.deriveTheme ? this.config.signals.deriveTheme(context) : defaultDeriveTheme(context);
|
|
2069
|
+
const accent = this.config.signals.deriveAccent ? this.config.signals.deriveAccent(context) : this.config.defaultAccent;
|
|
2070
|
+
const density = determineDensity(context);
|
|
2071
|
+
const scoreRelevance = this.config.signals.scoreRelevance ?? defaultScoreRelevance;
|
|
2072
|
+
const componentOrder = orderComponentsByRelevance(tree, context, scoreRelevance);
|
|
2073
|
+
const hiddenComponents = findHiddenComponents(tree, context, scoreRelevance);
|
|
2074
|
+
const predictions = this.config.signals.predictNavigation ? this.config.signals.predictNavigation(path, context) : defaultPredictNavigation(path, context, this.config.defaultPaths, this.config.maxSpeculationPaths);
|
|
2075
|
+
const { prefetch: prefetchDepth, prerender: prerenderCount } = getPrefetchDepth(context);
|
|
2076
|
+
const prefetch = predictions.slice(0, prefetchDepth);
|
|
2077
|
+
const prerender = predictions.slice(0, prerenderCount);
|
|
2078
|
+
const skeleton = computeSkeletonHints(path, context, tree);
|
|
2079
|
+
return {
|
|
2080
|
+
route: path,
|
|
2081
|
+
sessionId,
|
|
2082
|
+
componentOrder,
|
|
2083
|
+
hiddenComponents,
|
|
2084
|
+
featureFlags,
|
|
2085
|
+
theme,
|
|
2086
|
+
accent,
|
|
2087
|
+
density,
|
|
2088
|
+
prefetch,
|
|
2089
|
+
prerender,
|
|
2090
|
+
skeleton,
|
|
2091
|
+
routedAt: startTime,
|
|
2092
|
+
routerName: this.name,
|
|
2093
|
+
confidence: 0.85
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
async speculate(currentPath, context) {
|
|
2097
|
+
return this.config.signals.predictNavigation ? this.config.signals.predictNavigation(currentPath, context) : defaultPredictNavigation(currentPath, context, this.config.defaultPaths, this.config.maxSpeculationPaths);
|
|
2098
|
+
}
|
|
2099
|
+
personalizeTree(tree, decision) {
|
|
2100
|
+
const cloned = tree.clone();
|
|
2101
|
+
if (decision.hiddenComponents) {
|
|
2102
|
+
for (const id of decision.hiddenComponents) {
|
|
2103
|
+
const node = cloned.getNode(id);
|
|
2104
|
+
if (node) {
|
|
2105
|
+
node.defaultHidden = true;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
return cloned;
|
|
2110
|
+
}
|
|
2111
|
+
emotionToAccent(emotionState) {
|
|
2112
|
+
if (this.config.signals.deriveAccent) {
|
|
2113
|
+
return this.config.signals.deriveAccent({
|
|
2114
|
+
emotionState,
|
|
2115
|
+
tier: "free",
|
|
2116
|
+
recentPages: [],
|
|
2117
|
+
dwellTimes: new Map,
|
|
2118
|
+
clickPatterns: [],
|
|
2119
|
+
preferences: {},
|
|
2120
|
+
viewport: { width: 0, height: 0 },
|
|
2121
|
+
connection: "fast",
|
|
2122
|
+
reducedMotion: false,
|
|
2123
|
+
localHour: 12,
|
|
2124
|
+
timezone: "UTC",
|
|
2125
|
+
isNewSession: true
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
return this.config.defaultAccent;
|
|
2129
|
+
}
|
|
2130
|
+
generateSessionId(path, context) {
|
|
2131
|
+
const base = path.replace(/^\/|\/$/g, "").replace(/\//g, "-") || "index";
|
|
2132
|
+
const userId = context.userId || "anon";
|
|
2133
|
+
const sessionPrefix = context.sessionId || Date.now().toString(36);
|
|
2134
|
+
return `${base}-${userId.slice(0, 8)}-${sessionPrefix.slice(0, 8)}`;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
// src/router/context-extractor.ts
|
|
2138
|
+
function parseCookies(cookieHeader) {
|
|
2139
|
+
if (!cookieHeader)
|
|
2140
|
+
return {};
|
|
2141
|
+
return cookieHeader.split(";").reduce((acc, cookie) => {
|
|
2142
|
+
const [key, value] = cookie.trim().split("=");
|
|
2143
|
+
if (key && value) {
|
|
2144
|
+
acc[key] = decodeURIComponent(value);
|
|
2145
|
+
}
|
|
2146
|
+
return acc;
|
|
2147
|
+
}, {});
|
|
2148
|
+
}
|
|
2149
|
+
function parseJSON(value, fallback) {
|
|
2150
|
+
if (!value)
|
|
2151
|
+
return fallback;
|
|
2152
|
+
try {
|
|
2153
|
+
return JSON.parse(value);
|
|
2154
|
+
} catch {
|
|
2155
|
+
return fallback;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
function extractViewport(request) {
|
|
2159
|
+
const headers = request.headers;
|
|
2160
|
+
const viewportWidth = headers.get("sec-ch-viewport-width");
|
|
2161
|
+
const viewportHeight = headers.get("sec-ch-viewport-height");
|
|
2162
|
+
const dpr = headers.get("sec-ch-dpr");
|
|
2163
|
+
if (viewportWidth && viewportHeight) {
|
|
2164
|
+
return {
|
|
2165
|
+
width: parseInt(viewportWidth, 10),
|
|
2166
|
+
height: parseInt(viewportHeight, 10),
|
|
2167
|
+
devicePixelRatio: dpr ? parseFloat(dpr) : undefined
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
const xViewport = headers.get("x-viewport");
|
|
2171
|
+
if (xViewport) {
|
|
2172
|
+
const [width, height, devicePixelRatio] = xViewport.split(",").map(Number);
|
|
2173
|
+
return { width: width || 1920, height: height || 1080, devicePixelRatio };
|
|
2174
|
+
}
|
|
2175
|
+
return { width: 1920, height: 1080 };
|
|
2176
|
+
}
|
|
2177
|
+
function extractConnection(request) {
|
|
2178
|
+
const headers = request.headers;
|
|
2179
|
+
const downlink = headers.get("downlink");
|
|
2180
|
+
const rtt = headers.get("rtt");
|
|
2181
|
+
const ect = headers.get("ect");
|
|
2182
|
+
if (ect) {
|
|
2183
|
+
switch (ect) {
|
|
2184
|
+
case "4g":
|
|
2185
|
+
return "fast";
|
|
2186
|
+
case "3g":
|
|
2187
|
+
return "3g";
|
|
2188
|
+
case "2g":
|
|
2189
|
+
return "2g";
|
|
2190
|
+
case "slow-2g":
|
|
2191
|
+
return "slow-2g";
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
if (downlink) {
|
|
2195
|
+
const mbps = parseFloat(downlink);
|
|
2196
|
+
if (mbps >= 10)
|
|
2197
|
+
return "fast";
|
|
2198
|
+
if (mbps >= 2)
|
|
2199
|
+
return "4g";
|
|
2200
|
+
if (mbps >= 0.5)
|
|
2201
|
+
return "3g";
|
|
2202
|
+
if (mbps >= 0.1)
|
|
2203
|
+
return "2g";
|
|
2204
|
+
return "slow-2g";
|
|
2205
|
+
}
|
|
2206
|
+
if (rtt) {
|
|
2207
|
+
const ms = parseInt(rtt, 10);
|
|
2208
|
+
if (ms < 50)
|
|
2209
|
+
return "fast";
|
|
2210
|
+
if (ms < 100)
|
|
2211
|
+
return "4g";
|
|
2212
|
+
if (ms < 300)
|
|
2213
|
+
return "3g";
|
|
2214
|
+
if (ms < 700)
|
|
2215
|
+
return "2g";
|
|
2216
|
+
return "slow-2g";
|
|
2217
|
+
}
|
|
2218
|
+
return "4g";
|
|
2219
|
+
}
|
|
2220
|
+
function extractReducedMotion(request) {
|
|
2221
|
+
const prefersReducedMotion = request.headers.get("sec-ch-prefers-reduced-motion");
|
|
2222
|
+
return prefersReducedMotion === "reduce";
|
|
2223
|
+
}
|
|
2224
|
+
function extractTimeContext(request) {
|
|
2225
|
+
const headers = request.headers;
|
|
2226
|
+
const xTimezone = headers.get("x-timezone");
|
|
2227
|
+
const xLocalHour = headers.get("x-local-hour");
|
|
2228
|
+
const cfTimezone = request.cf?.timezone;
|
|
2229
|
+
const timezone = xTimezone || cfTimezone || "UTC";
|
|
2230
|
+
const localHour = xLocalHour ? parseInt(xLocalHour, 10) : new Date().getUTCHours();
|
|
2231
|
+
return { timezone, localHour };
|
|
2232
|
+
}
|
|
2233
|
+
function extractIdentity(cookies, request) {
|
|
2234
|
+
const userId = cookies["user_id"] || request.headers.get("x-user-id") || undefined;
|
|
2235
|
+
const tierCookie = cookies["user_tier"];
|
|
2236
|
+
const tierHeader = request.headers.get("x-user-tier");
|
|
2237
|
+
const tier = tierCookie || tierHeader || "free";
|
|
2238
|
+
return { userId, tier };
|
|
2239
|
+
}
|
|
2240
|
+
function extractNavigationHistory(cookies) {
|
|
2241
|
+
const recentPages = parseJSON(cookies["recent_pages"], []);
|
|
2242
|
+
const dwellTimesObj = parseJSON(cookies["dwell_times"], {});
|
|
2243
|
+
const clickPatterns = parseJSON(cookies["click_patterns"], []);
|
|
2244
|
+
return {
|
|
2245
|
+
recentPages,
|
|
2246
|
+
dwellTimes: new Map(Object.entries(dwellTimesObj)),
|
|
2247
|
+
clickPatterns
|
|
2248
|
+
};
|
|
2249
|
+
}
|
|
2250
|
+
function extractEmotionState(cookies, request) {
|
|
2251
|
+
const xEmotion = request.headers.get("x-emotion-state");
|
|
2252
|
+
if (xEmotion) {
|
|
2253
|
+
return parseJSON(xEmotion, undefined);
|
|
2254
|
+
}
|
|
2255
|
+
const emotionCookie = cookies["emotion_state"];
|
|
2256
|
+
if (emotionCookie) {
|
|
2257
|
+
return parseJSON(emotionCookie, undefined);
|
|
2258
|
+
}
|
|
2259
|
+
return;
|
|
2260
|
+
}
|
|
2261
|
+
function extractPreferences(cookies) {
|
|
2262
|
+
return parseJSON(cookies["user_preferences"], {});
|
|
2263
|
+
}
|
|
2264
|
+
function extractSessionInfo(cookies) {
|
|
2265
|
+
const sessionId = cookies["session_id"];
|
|
2266
|
+
const sessionStarted = cookies["session_started"];
|
|
2267
|
+
return {
|
|
2268
|
+
sessionId,
|
|
2269
|
+
isNewSession: !sessionId,
|
|
2270
|
+
sessionStartedAt: sessionStarted ? new Date(sessionStarted) : undefined
|
|
2271
|
+
};
|
|
2272
|
+
}
|
|
2273
|
+
async function extractUserContext(request, options = {}) {
|
|
2274
|
+
const cookies = parseCookies(request.headers.get("cookie"));
|
|
2275
|
+
const viewport = extractViewport(request);
|
|
2276
|
+
const connection = extractConnection(request);
|
|
2277
|
+
const reducedMotion = extractReducedMotion(request);
|
|
2278
|
+
const { timezone, localHour } = extractTimeContext(request);
|
|
2279
|
+
const { userId, tier: initialTier } = extractIdentity(cookies, request);
|
|
2280
|
+
const { recentPages, dwellTimes, clickPatterns } = extractNavigationHistory(cookies);
|
|
2281
|
+
const preferences = extractPreferences(cookies);
|
|
2282
|
+
const { sessionId, isNewSession, sessionStartedAt } = extractSessionInfo(cookies);
|
|
2283
|
+
let tier = initialTier;
|
|
2284
|
+
if (options.resolveUserTier && userId) {
|
|
2285
|
+
try {
|
|
2286
|
+
tier = await options.resolveUserTier(userId);
|
|
2287
|
+
} catch {}
|
|
2288
|
+
}
|
|
2289
|
+
let emotionState = extractEmotionState(cookies, request);
|
|
2290
|
+
if (!emotionState && options.detectEmotion) {
|
|
2291
|
+
try {
|
|
2292
|
+
emotionState = await options.detectEmotion(request);
|
|
2293
|
+
} catch {}
|
|
2294
|
+
}
|
|
2295
|
+
let context = {
|
|
2296
|
+
userId,
|
|
2297
|
+
tier,
|
|
2298
|
+
recentPages,
|
|
2299
|
+
dwellTimes,
|
|
2300
|
+
clickPatterns,
|
|
2301
|
+
emotionState,
|
|
2302
|
+
preferences,
|
|
2303
|
+
viewport,
|
|
2304
|
+
connection,
|
|
2305
|
+
reducedMotion,
|
|
2306
|
+
localHour,
|
|
2307
|
+
timezone,
|
|
2308
|
+
sessionId,
|
|
2309
|
+
isNewSession,
|
|
2310
|
+
sessionStartedAt
|
|
2311
|
+
};
|
|
2312
|
+
if (options.enrich) {
|
|
2313
|
+
context = await options.enrich(context, request);
|
|
2314
|
+
}
|
|
2315
|
+
return context;
|
|
2316
|
+
}
|
|
2317
|
+
function createContextMiddleware(options = {}) {
|
|
2318
|
+
return async (request) => {
|
|
2319
|
+
return extractUserContext(request, options);
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
function setContextCookies(response, context, currentPath) {
|
|
2323
|
+
const headers = new Headers(response.headers);
|
|
2324
|
+
const recentPages = [...context.recentPages.slice(-9), currentPath];
|
|
2325
|
+
headers.append("Set-Cookie", `recent_pages=${encodeURIComponent(JSON.stringify(recentPages))}; Path=/; Max-Age=604800; SameSite=Lax`);
|
|
2326
|
+
if (context.isNewSession) {
|
|
2327
|
+
const sessionId = `sess_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
2328
|
+
headers.append("Set-Cookie", `session_id=${sessionId}; Path=/; Max-Age=86400; SameSite=Lax`);
|
|
2329
|
+
headers.append("Set-Cookie", `session_started=${new Date().toISOString()}; Path=/; Max-Age=86400; SameSite=Lax`);
|
|
2330
|
+
}
|
|
2331
|
+
return new Response(response.body, {
|
|
2332
|
+
status: response.status,
|
|
2333
|
+
statusText: response.statusText,
|
|
2334
|
+
headers
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2337
|
+
function addSpeculationHeaders(response, prefetch, prerender) {
|
|
2338
|
+
const headers = new Headers(response.headers);
|
|
2339
|
+
if (prefetch.length > 0) {
|
|
2340
|
+
const linkHeader = prefetch.map((path) => `<${path}>; rel=prefetch`).join(", ");
|
|
2341
|
+
headers.append("Link", linkHeader);
|
|
2342
|
+
}
|
|
2343
|
+
if (prerender.length > 0) {
|
|
2344
|
+
headers.set("X-Prerender-Hints", prerender.join(","));
|
|
2345
|
+
}
|
|
2346
|
+
return new Response(response.body, {
|
|
2347
|
+
status: response.status,
|
|
2348
|
+
statusText: response.statusText,
|
|
2349
|
+
headers
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2352
|
+
// src/router/speculation.ts
|
|
2353
|
+
function supportsSpeculationRules() {
|
|
2354
|
+
if (typeof document === "undefined")
|
|
2355
|
+
return false;
|
|
2356
|
+
return "supports" in HTMLScriptElement && HTMLScriptElement.supports?.("speculationrules");
|
|
2357
|
+
}
|
|
2358
|
+
function supportsLinkPrefetch() {
|
|
2359
|
+
if (typeof document === "undefined")
|
|
2360
|
+
return false;
|
|
2361
|
+
const link = document.createElement("link");
|
|
2362
|
+
return link.relList?.supports?.("prefetch") ?? false;
|
|
2363
|
+
}
|
|
2364
|
+
function addSpeculationRules(prefetch, prerender) {
|
|
2365
|
+
if (!supportsSpeculationRules())
|
|
2366
|
+
return null;
|
|
2367
|
+
const rules = {};
|
|
2368
|
+
if (prefetch.length > 0) {
|
|
2369
|
+
rules.prefetch = [{ urls: prefetch }];
|
|
2370
|
+
}
|
|
2371
|
+
if (prerender.length > 0) {
|
|
2372
|
+
rules.prerender = [{ urls: prerender }];
|
|
2373
|
+
}
|
|
2374
|
+
if (Object.keys(rules).length === 0)
|
|
2375
|
+
return null;
|
|
2376
|
+
const script = document.createElement("script");
|
|
2377
|
+
script.type = "speculationrules";
|
|
2378
|
+
script.textContent = JSON.stringify(rules);
|
|
2379
|
+
document.head.appendChild(script);
|
|
2380
|
+
return script;
|
|
2381
|
+
}
|
|
2382
|
+
function removeSpeculationRules(script) {
|
|
2383
|
+
script.remove();
|
|
2384
|
+
}
|
|
2385
|
+
function linkPrefetch(path) {
|
|
2386
|
+
if (!supportsLinkPrefetch())
|
|
2387
|
+
return null;
|
|
2388
|
+
const existing = document.querySelector(`link[rel="prefetch"][href="${path}"]`);
|
|
2389
|
+
if (existing)
|
|
2390
|
+
return existing;
|
|
2391
|
+
const link = document.createElement("link");
|
|
2392
|
+
link.rel = "prefetch";
|
|
2393
|
+
link.href = path;
|
|
2394
|
+
document.head.appendChild(link);
|
|
2395
|
+
return link;
|
|
2396
|
+
}
|
|
2397
|
+
function removePrefetch(link) {
|
|
2398
|
+
link.remove();
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
class SpeculationManager {
|
|
2402
|
+
options;
|
|
2403
|
+
state;
|
|
2404
|
+
observers = new Map;
|
|
2405
|
+
hoverTimers = new Map;
|
|
2406
|
+
speculationScript = null;
|
|
2407
|
+
prefetchLinks = new Map;
|
|
2408
|
+
constructor(options = {}) {
|
|
2409
|
+
this.options = {
|
|
2410
|
+
maxPrefetch: options.maxPrefetch ?? 5,
|
|
2411
|
+
maxPrerender: options.maxPrerender ?? 1,
|
|
2412
|
+
hoverDelay: options.hoverDelay ?? 100,
|
|
2413
|
+
prefetchOnVisible: options.prefetchOnVisible ?? true,
|
|
2414
|
+
visibilityThreshold: options.visibilityThreshold ?? 0.1,
|
|
2415
|
+
cacheDuration: options.cacheDuration ?? 5 * 60 * 1000,
|
|
2416
|
+
onSpeculate: options.onSpeculate ?? (() => {})
|
|
2417
|
+
};
|
|
2418
|
+
this.state = {
|
|
2419
|
+
prefetched: new Set,
|
|
2420
|
+
prerendered: new Set,
|
|
2421
|
+
pending: new Set
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
initFromHints(prefetch = [], prerender = []) {
|
|
2425
|
+
const newPrefetch = prefetch.filter((p) => !this.state.prefetched.has(p) && !this.state.prerendered.has(p)).slice(0, this.options.maxPrefetch);
|
|
2426
|
+
const newPrerender = prerender.filter((p) => !this.state.prerendered.has(p)).slice(0, this.options.maxPrerender);
|
|
2427
|
+
if (supportsSpeculationRules()) {
|
|
2428
|
+
this.speculationScript = addSpeculationRules(newPrefetch, newPrerender);
|
|
2429
|
+
newPrefetch.forEach((p) => {
|
|
2430
|
+
this.state.prefetched.add(p);
|
|
2431
|
+
this.options.onSpeculate(p, "prefetch");
|
|
2432
|
+
});
|
|
2433
|
+
newPrerender.forEach((p) => {
|
|
2434
|
+
this.state.prerendered.add(p);
|
|
2435
|
+
this.options.onSpeculate(p, "prerender");
|
|
2436
|
+
});
|
|
2437
|
+
} else {
|
|
2438
|
+
newPrefetch.forEach((path) => {
|
|
2439
|
+
const link = linkPrefetch(path);
|
|
2440
|
+
if (link) {
|
|
2441
|
+
this.prefetchLinks.set(path, link);
|
|
2442
|
+
this.state.prefetched.add(path);
|
|
2443
|
+
this.options.onSpeculate(path, "prefetch");
|
|
2444
|
+
}
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
prefetch(path) {
|
|
2449
|
+
if (this.state.prefetched.has(path) || this.state.prerendered.has(path)) {
|
|
2450
|
+
return false;
|
|
2451
|
+
}
|
|
2452
|
+
if (this.state.prefetched.size >= this.options.maxPrefetch) {
|
|
2453
|
+
return false;
|
|
2454
|
+
}
|
|
2455
|
+
if (supportsSpeculationRules()) {
|
|
2456
|
+
const allPrefetch = [...this.state.prefetched, path];
|
|
2457
|
+
const allPrerender = [...this.state.prerendered];
|
|
2458
|
+
if (this.speculationScript) {
|
|
2459
|
+
removeSpeculationRules(this.speculationScript);
|
|
2460
|
+
}
|
|
2461
|
+
this.speculationScript = addSpeculationRules(allPrefetch, allPrerender);
|
|
2462
|
+
} else {
|
|
2463
|
+
const link = linkPrefetch(path);
|
|
2464
|
+
if (link) {
|
|
2465
|
+
this.prefetchLinks.set(path, link);
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
this.state.prefetched.add(path);
|
|
2469
|
+
this.options.onSpeculate(path, "prefetch");
|
|
2470
|
+
return true;
|
|
2471
|
+
}
|
|
2472
|
+
watchHover(element) {
|
|
2473
|
+
const path = new URL(element.href, window.location.href).pathname;
|
|
2474
|
+
const handleMouseEnter = () => {
|
|
2475
|
+
if (this.state.prefetched.has(path) || this.state.pending.has(path)) {
|
|
2476
|
+
return;
|
|
2477
|
+
}
|
|
2478
|
+
this.state.pending.add(path);
|
|
2479
|
+
const timer = setTimeout(() => {
|
|
2480
|
+
this.prefetch(path);
|
|
2481
|
+
this.state.pending.delete(path);
|
|
2482
|
+
}, this.options.hoverDelay);
|
|
2483
|
+
this.hoverTimers.set(element, timer);
|
|
2484
|
+
};
|
|
2485
|
+
const handleMouseLeave = () => {
|
|
2486
|
+
const timer = this.hoverTimers.get(element);
|
|
2487
|
+
if (timer) {
|
|
2488
|
+
clearTimeout(timer);
|
|
2489
|
+
this.hoverTimers.delete(element);
|
|
2490
|
+
}
|
|
2491
|
+
this.state.pending.delete(path);
|
|
2492
|
+
};
|
|
2493
|
+
element.addEventListener("mouseenter", handleMouseEnter);
|
|
2494
|
+
element.addEventListener("mouseleave", handleMouseLeave);
|
|
2495
|
+
return () => {
|
|
2496
|
+
element.removeEventListener("mouseenter", handleMouseEnter);
|
|
2497
|
+
element.removeEventListener("mouseleave", handleMouseLeave);
|
|
2498
|
+
handleMouseLeave();
|
|
2499
|
+
};
|
|
2500
|
+
}
|
|
2501
|
+
watchVisible(element) {
|
|
2502
|
+
if (!this.options.prefetchOnVisible) {
|
|
2503
|
+
return () => {};
|
|
2504
|
+
}
|
|
2505
|
+
const path = new URL(element.href, window.location.href).pathname;
|
|
2506
|
+
const observer = new IntersectionObserver((entries) => {
|
|
2507
|
+
entries.forEach((entry) => {
|
|
2508
|
+
if (entry.isIntersecting) {
|
|
2509
|
+
this.prefetch(path);
|
|
2510
|
+
observer.disconnect();
|
|
2511
|
+
this.observers.delete(element);
|
|
2512
|
+
}
|
|
2513
|
+
});
|
|
2514
|
+
}, { threshold: this.options.visibilityThreshold });
|
|
2515
|
+
observer.observe(element);
|
|
2516
|
+
this.observers.set(element, observer);
|
|
2517
|
+
return () => {
|
|
2518
|
+
observer.disconnect();
|
|
2519
|
+
this.observers.delete(element);
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
watchAllLinks() {
|
|
2523
|
+
const links = document.querySelectorAll('a[href^="/"]');
|
|
2524
|
+
const cleanups = [];
|
|
2525
|
+
links.forEach((link) => {
|
|
2526
|
+
if (link instanceof HTMLAnchorElement) {
|
|
2527
|
+
cleanups.push(this.watchHover(link));
|
|
2528
|
+
cleanups.push(this.watchVisible(link));
|
|
2529
|
+
}
|
|
2530
|
+
});
|
|
2531
|
+
return () => {
|
|
2532
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
2533
|
+
};
|
|
2534
|
+
}
|
|
2535
|
+
clear() {
|
|
2536
|
+
if (this.speculationScript) {
|
|
2537
|
+
removeSpeculationRules(this.speculationScript);
|
|
2538
|
+
this.speculationScript = null;
|
|
2539
|
+
}
|
|
2540
|
+
this.prefetchLinks.forEach((link) => removePrefetch(link));
|
|
2541
|
+
this.prefetchLinks.clear();
|
|
2542
|
+
this.observers.forEach((observer) => observer.disconnect());
|
|
2543
|
+
this.observers.clear();
|
|
2544
|
+
this.hoverTimers.forEach((timer) => clearTimeout(timer));
|
|
2545
|
+
this.hoverTimers.clear();
|
|
2546
|
+
this.state.prefetched.clear();
|
|
2547
|
+
this.state.prerendered.clear();
|
|
2548
|
+
this.state.pending.clear();
|
|
2549
|
+
}
|
|
2550
|
+
getState() {
|
|
2551
|
+
return {
|
|
2552
|
+
prefetched: new Set(this.state.prefetched),
|
|
2553
|
+
prerendered: new Set(this.state.prerendered),
|
|
2554
|
+
pending: new Set(this.state.pending)
|
|
2555
|
+
};
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
function createSpeculationHook(useState2, useEffect2, useRef) {
|
|
2559
|
+
return function useSpeculation(options = {}) {
|
|
2560
|
+
const managerRef = useRef(null);
|
|
2561
|
+
const [state, setState] = useState2({
|
|
2562
|
+
prefetched: new Set,
|
|
2563
|
+
prerendered: new Set,
|
|
2564
|
+
pending: new Set
|
|
2565
|
+
});
|
|
2566
|
+
useEffect2(() => {
|
|
2567
|
+
managerRef.current = new SpeculationManager({
|
|
2568
|
+
...options,
|
|
2569
|
+
onSpeculate: (path, type) => {
|
|
2570
|
+
options.onSpeculate?.(path, type);
|
|
2571
|
+
setState(managerRef.current.getState());
|
|
2572
|
+
}
|
|
2573
|
+
});
|
|
2574
|
+
const cleanup = managerRef.current.watchAllLinks();
|
|
2575
|
+
return () => {
|
|
2576
|
+
cleanup();
|
|
2577
|
+
managerRef.current?.clear();
|
|
2578
|
+
};
|
|
2579
|
+
}, []);
|
|
2580
|
+
return {
|
|
2581
|
+
state,
|
|
2582
|
+
prefetch: (path) => managerRef.current?.prefetch(path),
|
|
2583
|
+
initFromHints: (prefetch, prerender) => managerRef.current?.initFromHints(prefetch, prerender),
|
|
2584
|
+
clear: () => managerRef.current?.clear()
|
|
2585
|
+
};
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2588
|
+
function autoInitSpeculation() {
|
|
2589
|
+
if (typeof window === "undefined")
|
|
2590
|
+
return null;
|
|
2591
|
+
const hints = window.__AEON_SPECULATION__;
|
|
2592
|
+
const manager = new SpeculationManager;
|
|
2593
|
+
if (hints) {
|
|
2594
|
+
manager.initFromHints(hints.prefetch || [], hints.prerender || []);
|
|
2595
|
+
}
|
|
2596
|
+
manager.watchAllLinks();
|
|
2597
|
+
return manager;
|
|
2598
|
+
}
|
|
2599
|
+
// src/router/esi-control.ts
|
|
2600
|
+
function generateSchemaPrompt(schema) {
|
|
2601
|
+
const schemaDescription = describeZodSchema(schema);
|
|
2602
|
+
return `
|
|
2603
|
+
|
|
2604
|
+
Respond with valid JSON matching this schema:
|
|
2605
|
+
${schemaDescription}
|
|
2606
|
+
|
|
2607
|
+
Output ONLY the JSON, no markdown, no explanation.`;
|
|
2608
|
+
}
|
|
2609
|
+
function describeZodSchema(schema) {
|
|
2610
|
+
const def = schema._def;
|
|
2611
|
+
if (def.typeName === "ZodObject") {
|
|
2612
|
+
const shape = def.shape;
|
|
2613
|
+
const fields = Object.entries(shape).map(([key, fieldSchema]) => {
|
|
2614
|
+
const fieldDef = fieldSchema._def;
|
|
2615
|
+
return ` "${key}": ${describeZodType(fieldDef)}`;
|
|
2616
|
+
});
|
|
2617
|
+
return `{
|
|
2618
|
+
${fields.join(`,
|
|
2619
|
+
`)}
|
|
2620
|
+
}`;
|
|
2621
|
+
}
|
|
2622
|
+
return describeZodType(def);
|
|
2623
|
+
}
|
|
2624
|
+
function describeZodType(def) {
|
|
2625
|
+
const typeName = def.typeName;
|
|
2626
|
+
switch (typeName) {
|
|
2627
|
+
case "ZodString":
|
|
2628
|
+
return "string";
|
|
2629
|
+
case "ZodNumber":
|
|
2630
|
+
return "number";
|
|
2631
|
+
case "ZodBoolean":
|
|
2632
|
+
return "boolean";
|
|
2633
|
+
case "ZodArray":
|
|
2634
|
+
const innerType = def.type;
|
|
2635
|
+
return `array of ${describeZodType(innerType._def)}`;
|
|
2636
|
+
case "ZodEnum":
|
|
2637
|
+
const values = def.values;
|
|
2638
|
+
return `one of: ${values.map((v) => `"${v}"`).join(" | ")}`;
|
|
2639
|
+
case "ZodLiteral":
|
|
2640
|
+
return JSON.stringify(def.value);
|
|
2641
|
+
case "ZodOptional":
|
|
2642
|
+
const optionalType = def.innerType;
|
|
2643
|
+
return `${describeZodType(optionalType._def)} (optional)`;
|
|
2644
|
+
case "ZodNullable":
|
|
2645
|
+
const nullableType = def.innerType;
|
|
2646
|
+
return `${describeZodType(nullableType._def)} or null`;
|
|
2647
|
+
case "ZodObject":
|
|
2648
|
+
return "object";
|
|
2649
|
+
default:
|
|
2650
|
+
return "any";
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
function parseWithSchema(output, schema) {
|
|
2654
|
+
let jsonStr = output.trim();
|
|
2655
|
+
if (jsonStr.startsWith("```")) {
|
|
2656
|
+
const match = jsonStr.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
2657
|
+
if (match) {
|
|
2658
|
+
jsonStr = match[1].trim();
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
let parsed;
|
|
2662
|
+
try {
|
|
2663
|
+
parsed = JSON.parse(jsonStr);
|
|
2664
|
+
} catch (e) {
|
|
2665
|
+
const jsonMatch = jsonStr.match(/\{[\s\S]*\}/);
|
|
2666
|
+
if (jsonMatch) {
|
|
2667
|
+
try {
|
|
2668
|
+
parsed = JSON.parse(jsonMatch[0]);
|
|
2669
|
+
} catch {
|
|
2670
|
+
return {
|
|
2671
|
+
success: false,
|
|
2672
|
+
errors: [`Failed to parse JSON: ${e instanceof Error ? e.message : "Unknown error"}`]
|
|
2673
|
+
};
|
|
2674
|
+
}
|
|
2675
|
+
} else {
|
|
2676
|
+
return {
|
|
2677
|
+
success: false,
|
|
2678
|
+
errors: [`No valid JSON found in output`]
|
|
2679
|
+
};
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
const result = schema.safeParse(parsed);
|
|
2683
|
+
if (result.success) {
|
|
2684
|
+
return { success: true, data: result.data };
|
|
2685
|
+
}
|
|
2686
|
+
return {
|
|
2687
|
+
success: false,
|
|
2688
|
+
errors: result.error.errors.map((e) => `${e.path.join(".")}: ${e.message}`)
|
|
2689
|
+
};
|
|
2690
|
+
}
|
|
2691
|
+
function createControlProcessor(processESI) {
|
|
2692
|
+
return {
|
|
2693
|
+
async processWithSchema(prompt, schema, params, context) {
|
|
2694
|
+
const fullPrompt = prompt + generateSchemaPrompt(schema);
|
|
2695
|
+
const directive = {
|
|
2696
|
+
id: `esi-schema-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
2697
|
+
params: {
|
|
2698
|
+
model: "llm",
|
|
2699
|
+
...params
|
|
2700
|
+
},
|
|
2701
|
+
content: {
|
|
2702
|
+
type: "text",
|
|
2703
|
+
value: fullPrompt
|
|
2704
|
+
}
|
|
2705
|
+
};
|
|
2706
|
+
const result = await processESI(directive, context);
|
|
2707
|
+
if (!result.success || !result.output) {
|
|
2708
|
+
return {
|
|
2709
|
+
...result,
|
|
2710
|
+
validationErrors: result.error ? [result.error] : ["No output"]
|
|
2711
|
+
};
|
|
2712
|
+
}
|
|
2713
|
+
const parseResult = parseWithSchema(result.output, schema);
|
|
2714
|
+
if (parseResult.success) {
|
|
2715
|
+
return {
|
|
2716
|
+
...result,
|
|
2717
|
+
data: parseResult.data,
|
|
2718
|
+
rawOutput: result.output
|
|
2719
|
+
};
|
|
2720
|
+
}
|
|
2721
|
+
return {
|
|
2722
|
+
...result,
|
|
2723
|
+
rawOutput: result.output,
|
|
2724
|
+
validationErrors: parseResult.errors
|
|
2725
|
+
};
|
|
2726
|
+
},
|
|
2727
|
+
async processIf(directive, context) {
|
|
2728
|
+
const schemaResult = await this.processWithSchema(directive.prompt, directive.schema, directive.params || {}, context);
|
|
2729
|
+
let conditionMet = false;
|
|
2730
|
+
if (schemaResult.data !== undefined) {
|
|
2731
|
+
try {
|
|
2732
|
+
conditionMet = directive.when(schemaResult.data, context);
|
|
2733
|
+
} catch (e) {
|
|
2734
|
+
conditionMet = false;
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
return {
|
|
2738
|
+
id: directive.id,
|
|
2739
|
+
conditionMet,
|
|
2740
|
+
data: schemaResult.data,
|
|
2741
|
+
inferenceResult: schemaResult
|
|
2742
|
+
};
|
|
2743
|
+
},
|
|
2744
|
+
async processMatch(directive, context) {
|
|
2745
|
+
const schemaResult = await this.processWithSchema(directive.prompt, directive.schema, directive.params || {}, context);
|
|
2746
|
+
let matchedCase;
|
|
2747
|
+
if (schemaResult.data !== undefined) {
|
|
2748
|
+
for (const caseItem of directive.cases) {
|
|
2749
|
+
try {
|
|
2750
|
+
if (caseItem.match(schemaResult.data, context)) {
|
|
2751
|
+
matchedCase = caseItem.id;
|
|
2752
|
+
break;
|
|
2753
|
+
}
|
|
2754
|
+
} catch {}
|
|
2755
|
+
}
|
|
2756
|
+
if (!matchedCase && directive.defaultCase) {
|
|
2757
|
+
matchedCase = directive.defaultCase;
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
return {
|
|
2761
|
+
id: directive.id,
|
|
2762
|
+
matchedCase,
|
|
2763
|
+
data: schemaResult.data,
|
|
2764
|
+
inferenceResult: schemaResult
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
};
|
|
2768
|
+
}
|
|
2769
|
+
function esiIf(prompt, schema, when, options = {}) {
|
|
2770
|
+
return {
|
|
2771
|
+
id: `esi-if-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
2772
|
+
prompt,
|
|
2773
|
+
schema,
|
|
2774
|
+
when,
|
|
2775
|
+
params: options
|
|
2776
|
+
};
|
|
2777
|
+
}
|
|
2778
|
+
function esiMatch(prompt, schema, cases, defaultCase, options = {}) {
|
|
2779
|
+
return {
|
|
2780
|
+
id: `esi-match-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
2781
|
+
prompt,
|
|
2782
|
+
schema,
|
|
2783
|
+
cases,
|
|
2784
|
+
defaultCase,
|
|
2785
|
+
params: options
|
|
2786
|
+
};
|
|
2787
|
+
}
|
|
2788
|
+
// src/router/esi-control-react.tsx
|
|
2789
|
+
var import_react2 = __toESM(require_react(), 1);
|
|
2790
|
+
var jsx_dev_runtime2 = __toESM(require_jsx_dev_runtime(), 1);
|
|
2791
|
+
var PresenceContext = import_react2.createContext(null);
|
|
2792
|
+
function usePresenceForESI() {
|
|
2793
|
+
const ctx = import_react2.useContext(PresenceContext);
|
|
2794
|
+
return ctx || { users: [], localUser: null };
|
|
2795
|
+
}
|
|
2796
|
+
function ESIStructured({
|
|
2797
|
+
children,
|
|
2798
|
+
prompt,
|
|
2799
|
+
schema,
|
|
2800
|
+
render,
|
|
2801
|
+
fallback,
|
|
2802
|
+
loading = "...",
|
|
2803
|
+
retryOnFail = false,
|
|
2804
|
+
maxRetries = 2,
|
|
2805
|
+
temperature,
|
|
2806
|
+
maxTokens,
|
|
2807
|
+
cacheTtl,
|
|
2808
|
+
onSuccess,
|
|
2809
|
+
onValidationError,
|
|
2810
|
+
onError,
|
|
2811
|
+
className
|
|
2812
|
+
}) {
|
|
2813
|
+
const { process: process2, enabled } = useESI();
|
|
2814
|
+
const [result, setResult] = import_react2.useState(null);
|
|
2815
|
+
const [isLoading, setIsLoading] = import_react2.useState(true);
|
|
2816
|
+
const [retryCount, setRetryCount] = import_react2.useState(0);
|
|
2817
|
+
const promptText = prompt || (typeof children === "string" ? children : String(children || ""));
|
|
2818
|
+
const fullPrompt = promptText + generateSchemaPrompt(schema);
|
|
2819
|
+
import_react2.useEffect(() => {
|
|
2820
|
+
if (!enabled) {
|
|
2821
|
+
setIsLoading(false);
|
|
2822
|
+
return;
|
|
2823
|
+
}
|
|
2824
|
+
async function runInference() {
|
|
2825
|
+
setIsLoading(true);
|
|
2826
|
+
const directive = {
|
|
2827
|
+
id: `esi-structured-${Date.now()}`,
|
|
2828
|
+
params: {
|
|
2829
|
+
model: "llm",
|
|
2830
|
+
temperature,
|
|
2831
|
+
maxTokens,
|
|
2832
|
+
cacheTtl
|
|
2833
|
+
},
|
|
2834
|
+
content: {
|
|
2835
|
+
type: "text",
|
|
2836
|
+
value: fullPrompt
|
|
2837
|
+
}
|
|
2838
|
+
};
|
|
2839
|
+
const inferenceResult = await process2(directive);
|
|
2840
|
+
if (!inferenceResult.success || !inferenceResult.output) {
|
|
2841
|
+
setResult({
|
|
2842
|
+
...inferenceResult,
|
|
2843
|
+
validationErrors: [inferenceResult.error || "No output"]
|
|
2844
|
+
});
|
|
2845
|
+
onError?.(inferenceResult.error || "Inference failed");
|
|
2846
|
+
setIsLoading(false);
|
|
2847
|
+
return;
|
|
2848
|
+
}
|
|
2849
|
+
const parseResult = parseWithSchema(inferenceResult.output, schema);
|
|
2850
|
+
if (parseResult.success) {
|
|
2851
|
+
const schemaResult = {
|
|
2852
|
+
...inferenceResult,
|
|
2853
|
+
data: parseResult.data,
|
|
2854
|
+
rawOutput: inferenceResult.output
|
|
2855
|
+
};
|
|
2856
|
+
setResult(schemaResult);
|
|
2857
|
+
onSuccess?.(parseResult.data);
|
|
2858
|
+
} else {
|
|
2859
|
+
if (retryOnFail && retryCount < maxRetries) {
|
|
2860
|
+
setRetryCount((c) => c + 1);
|
|
2861
|
+
} else {
|
|
2862
|
+
const schemaResult = {
|
|
2863
|
+
...inferenceResult,
|
|
2864
|
+
rawOutput: inferenceResult.output,
|
|
2865
|
+
validationErrors: parseResult.errors
|
|
2866
|
+
};
|
|
2867
|
+
setResult(schemaResult);
|
|
2868
|
+
onValidationError?.(parseResult.errors, inferenceResult.output);
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
setIsLoading(false);
|
|
2872
|
+
}
|
|
2873
|
+
runInference();
|
|
2874
|
+
}, [fullPrompt, enabled, retryCount]);
|
|
2875
|
+
if (isLoading) {
|
|
2876
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
2877
|
+
className,
|
|
2878
|
+
children: loading
|
|
2879
|
+
}, undefined, false, undefined, this);
|
|
2880
|
+
}
|
|
2881
|
+
if (!result?.data) {
|
|
2882
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
2883
|
+
className,
|
|
2884
|
+
children: fallback
|
|
2885
|
+
}, undefined, false, undefined, this);
|
|
2886
|
+
}
|
|
2887
|
+
if (render) {
|
|
2888
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
2889
|
+
className,
|
|
2890
|
+
children: render(result.data, {
|
|
2891
|
+
cached: result.cached,
|
|
2892
|
+
latencyMs: result.latencyMs
|
|
2893
|
+
})
|
|
2894
|
+
}, undefined, false, undefined, this);
|
|
2895
|
+
}
|
|
2896
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
2897
|
+
className,
|
|
2898
|
+
children: JSON.stringify(result.data)
|
|
2899
|
+
}, undefined, false, undefined, this);
|
|
2900
|
+
}
|
|
2901
|
+
function ESIIf({
|
|
2902
|
+
children,
|
|
2903
|
+
prompt,
|
|
2904
|
+
schema,
|
|
2905
|
+
when,
|
|
2906
|
+
then: thenContent,
|
|
2907
|
+
else: elseContent,
|
|
2908
|
+
loading = null,
|
|
2909
|
+
temperature,
|
|
2910
|
+
cacheTtl,
|
|
2911
|
+
onEvaluate,
|
|
2912
|
+
className
|
|
2913
|
+
}) {
|
|
2914
|
+
const [conditionMet, setConditionMet] = import_react2.useState(null);
|
|
2915
|
+
const [data, setData] = import_react2.useState(null);
|
|
2916
|
+
const handleSuccess = import_react2.useCallback((result) => {
|
|
2917
|
+
setData(result);
|
|
2918
|
+
try {
|
|
2919
|
+
const met = when(result, {});
|
|
2920
|
+
setConditionMet(met);
|
|
2921
|
+
onEvaluate?.(result, met);
|
|
2922
|
+
} catch {
|
|
2923
|
+
setConditionMet(false);
|
|
2924
|
+
}
|
|
2925
|
+
}, [when, onEvaluate]);
|
|
2926
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
2927
|
+
className,
|
|
2928
|
+
children: [
|
|
2929
|
+
/* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ESIStructured, {
|
|
2930
|
+
prompt,
|
|
2931
|
+
schema,
|
|
2932
|
+
temperature,
|
|
2933
|
+
cacheTtl,
|
|
2934
|
+
loading,
|
|
2935
|
+
onSuccess: handleSuccess,
|
|
2936
|
+
render: () => null,
|
|
2937
|
+
children
|
|
2938
|
+
}, undefined, false, undefined, this),
|
|
2939
|
+
conditionMet === true && thenContent,
|
|
2940
|
+
conditionMet === false && elseContent
|
|
2941
|
+
]
|
|
2942
|
+
}, undefined, true, undefined, this);
|
|
2943
|
+
}
|
|
2944
|
+
function ESICase({ children }) {
|
|
2945
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(jsx_dev_runtime2.Fragment, {
|
|
2946
|
+
children
|
|
2947
|
+
}, undefined, false, undefined, this);
|
|
2948
|
+
}
|
|
2949
|
+
function ESIDefault({ children }) {
|
|
2950
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(jsx_dev_runtime2.Fragment, {
|
|
2951
|
+
children
|
|
2952
|
+
}, undefined, false, undefined, this);
|
|
2953
|
+
}
|
|
2954
|
+
function ESIMatch({
|
|
2955
|
+
children,
|
|
2956
|
+
prompt,
|
|
2957
|
+
schema,
|
|
2958
|
+
loading = null,
|
|
2959
|
+
temperature,
|
|
2960
|
+
cacheTtl,
|
|
2961
|
+
onMatch,
|
|
2962
|
+
className
|
|
2963
|
+
}) {
|
|
2964
|
+
const [matchedIndex, setMatchedIndex] = import_react2.useState(null);
|
|
2965
|
+
const [data, setData] = import_react2.useState(null);
|
|
2966
|
+
const { cases, defaultCase, promptFromChildren } = import_react2.useMemo(() => {
|
|
2967
|
+
const cases2 = [];
|
|
2968
|
+
let defaultCase2 = null;
|
|
2969
|
+
let promptFromChildren2 = "";
|
|
2970
|
+
import_react2.Children.forEach(children, (child) => {
|
|
2971
|
+
if (!import_react2.isValidElement(child)) {
|
|
2972
|
+
if (typeof child === "string") {
|
|
2973
|
+
promptFromChildren2 += child;
|
|
2974
|
+
}
|
|
2975
|
+
return;
|
|
2976
|
+
}
|
|
2977
|
+
if (child.type === ESICase) {
|
|
2978
|
+
const props = child.props;
|
|
2979
|
+
cases2.push({
|
|
2980
|
+
match: props.match,
|
|
2981
|
+
content: props.children
|
|
2982
|
+
});
|
|
2983
|
+
} else if (child.type === ESIDefault) {
|
|
2984
|
+
defaultCase2 = child.props.children;
|
|
2985
|
+
}
|
|
2986
|
+
});
|
|
2987
|
+
return { cases: cases2, defaultCase: defaultCase2, promptFromChildren: promptFromChildren2 };
|
|
2988
|
+
}, [children]);
|
|
2989
|
+
const handleSuccess = import_react2.useCallback((result) => {
|
|
2990
|
+
setData(result);
|
|
2991
|
+
for (let i = 0;i < cases.length; i++) {
|
|
2992
|
+
try {
|
|
2993
|
+
if (cases[i].match(result, {})) {
|
|
2994
|
+
setMatchedIndex(i);
|
|
2995
|
+
onMatch?.(result, i);
|
|
2996
|
+
return;
|
|
2997
|
+
}
|
|
2998
|
+
} catch {}
|
|
2999
|
+
}
|
|
3000
|
+
setMatchedIndex(-1);
|
|
3001
|
+
onMatch?.(result, -1);
|
|
3002
|
+
}, [cases, onMatch]);
|
|
3003
|
+
const finalPrompt = prompt || promptFromChildren;
|
|
3004
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3005
|
+
className,
|
|
3006
|
+
children: [
|
|
3007
|
+
/* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ESIStructured, {
|
|
3008
|
+
prompt: finalPrompt,
|
|
3009
|
+
schema,
|
|
3010
|
+
temperature,
|
|
3011
|
+
cacheTtl,
|
|
3012
|
+
loading,
|
|
3013
|
+
onSuccess: handleSuccess,
|
|
3014
|
+
render: () => null
|
|
3015
|
+
}, undefined, false, undefined, this),
|
|
3016
|
+
matchedIndex !== null && matchedIndex >= 0 && cases[matchedIndex]?.content,
|
|
3017
|
+
matchedIndex === -1 && defaultCase
|
|
3018
|
+
]
|
|
3019
|
+
}, undefined, true, undefined, this);
|
|
3020
|
+
}
|
|
3021
|
+
function defaultDescribeUsers(users) {
|
|
3022
|
+
if (users.length === 0)
|
|
3023
|
+
return "No other users are viewing this content.";
|
|
3024
|
+
if (users.length === 1)
|
|
3025
|
+
return `1 user is viewing: ${describeUser(users[0])}`;
|
|
3026
|
+
const roles = [...new Set(users.map((u) => u.role).filter(Boolean))];
|
|
3027
|
+
const roleStr = roles.length > 0 ? ` with roles: ${roles.join(", ")}` : "";
|
|
3028
|
+
return `${users.length} users are viewing${roleStr}:
|
|
3029
|
+
${users.map(describeUser).join(`
|
|
3030
|
+
`)}`;
|
|
3031
|
+
}
|
|
3032
|
+
function describeUser(user) {
|
|
3033
|
+
const parts = [user.name || user.userId];
|
|
3034
|
+
if (user.role)
|
|
3035
|
+
parts.push(`(${user.role})`);
|
|
3036
|
+
if (user.status)
|
|
3037
|
+
parts.push(`[${user.status}]`);
|
|
3038
|
+
return `- ${parts.join(" ")}`;
|
|
3039
|
+
}
|
|
3040
|
+
function ESICollaborative({
|
|
3041
|
+
children,
|
|
3042
|
+
prompt,
|
|
3043
|
+
schema,
|
|
3044
|
+
render,
|
|
3045
|
+
fallback,
|
|
3046
|
+
loading = "...",
|
|
3047
|
+
describeUsers = defaultDescribeUsers,
|
|
3048
|
+
reactToPresenceChange = true,
|
|
3049
|
+
presenceDebounce = 2000,
|
|
3050
|
+
temperature,
|
|
3051
|
+
maxTokens,
|
|
3052
|
+
cacheTtl,
|
|
3053
|
+
onSuccess,
|
|
3054
|
+
className
|
|
3055
|
+
}) {
|
|
3056
|
+
const presence = usePresenceForESI();
|
|
3057
|
+
const [debouncedUsers, setDebouncedUsers] = import_react2.useState(presence.users);
|
|
3058
|
+
const [result, setResult] = import_react2.useState(null);
|
|
3059
|
+
import_react2.useEffect(() => {
|
|
3060
|
+
if (!reactToPresenceChange)
|
|
3061
|
+
return;
|
|
3062
|
+
const timer = setTimeout(() => {
|
|
3063
|
+
setDebouncedUsers(presence.users);
|
|
3064
|
+
}, presenceDebounce);
|
|
3065
|
+
return () => clearTimeout(timer);
|
|
3066
|
+
}, [presence.users, reactToPresenceChange, presenceDebounce]);
|
|
3067
|
+
const basePrompt = prompt || (typeof children === "string" ? children : String(children || ""));
|
|
3068
|
+
const presenceDescription = describeUsers(debouncedUsers);
|
|
3069
|
+
const collaborativePrompt = `[Audience Context]
|
|
3070
|
+
${presenceDescription}
|
|
3071
|
+
|
|
3072
|
+
[Task]
|
|
3073
|
+
${basePrompt}
|
|
3074
|
+
|
|
3075
|
+
Consider ALL viewers when generating your response. The content should be relevant and appropriate for everyone currently viewing.`;
|
|
3076
|
+
const handleSuccess = import_react2.useCallback((data) => {
|
|
3077
|
+
setResult(data);
|
|
3078
|
+
onSuccess?.(data, debouncedUsers);
|
|
3079
|
+
}, [debouncedUsers, onSuccess]);
|
|
3080
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ESIStructured, {
|
|
3081
|
+
prompt: collaborativePrompt,
|
|
3082
|
+
schema,
|
|
3083
|
+
temperature,
|
|
3084
|
+
maxTokens,
|
|
3085
|
+
cacheTtl,
|
|
3086
|
+
loading,
|
|
3087
|
+
fallback,
|
|
3088
|
+
onSuccess: handleSuccess,
|
|
3089
|
+
className,
|
|
3090
|
+
render: (data, meta) => {
|
|
3091
|
+
if (render) {
|
|
3092
|
+
return render(data, debouncedUsers);
|
|
3093
|
+
}
|
|
3094
|
+
return JSON.stringify(data);
|
|
3095
|
+
}
|
|
3096
|
+
}, undefined, false, undefined, this);
|
|
3097
|
+
}
|
|
3098
|
+
function ESIReflect({
|
|
3099
|
+
children,
|
|
3100
|
+
prompt,
|
|
3101
|
+
schema,
|
|
3102
|
+
until,
|
|
3103
|
+
maxIterations = 3,
|
|
3104
|
+
render,
|
|
3105
|
+
showProgress = false,
|
|
3106
|
+
fallback,
|
|
3107
|
+
loading = "...",
|
|
3108
|
+
onIteration,
|
|
3109
|
+
onComplete,
|
|
3110
|
+
className
|
|
3111
|
+
}) {
|
|
3112
|
+
const { process: process2, enabled } = useESI();
|
|
3113
|
+
const [currentResult, setCurrentResult] = import_react2.useState(null);
|
|
3114
|
+
const [iteration, setIteration] = import_react2.useState(0);
|
|
3115
|
+
const [isComplete, setIsComplete] = import_react2.useState(false);
|
|
3116
|
+
const [isLoading, setIsLoading] = import_react2.useState(true);
|
|
3117
|
+
const basePrompt = prompt || (typeof children === "string" ? children : String(children || ""));
|
|
3118
|
+
import_react2.useEffect(() => {
|
|
3119
|
+
if (!enabled) {
|
|
3120
|
+
setIsLoading(false);
|
|
3121
|
+
return;
|
|
3122
|
+
}
|
|
3123
|
+
async function runReflection() {
|
|
3124
|
+
setIsLoading(true);
|
|
3125
|
+
let currentIteration = 0;
|
|
3126
|
+
let lastResult = null;
|
|
3127
|
+
let previousAttempts = [];
|
|
3128
|
+
while (currentIteration < maxIterations) {
|
|
3129
|
+
let reflectionPrompt = basePrompt;
|
|
3130
|
+
if (currentIteration > 0 && lastResult) {
|
|
3131
|
+
reflectionPrompt = `[Previous Attempt ${currentIteration}]
|
|
3132
|
+
${JSON.stringify(lastResult)}
|
|
3133
|
+
|
|
3134
|
+
[Reflection]
|
|
3135
|
+
The previous attempt did not meet the quality threshold. Please improve upon it.
|
|
3136
|
+
|
|
3137
|
+
[Original Task]
|
|
3138
|
+
${basePrompt}`;
|
|
3139
|
+
}
|
|
3140
|
+
const fullPrompt = reflectionPrompt + generateSchemaPrompt(schema);
|
|
3141
|
+
const directive = {
|
|
3142
|
+
id: `esi-reflect-${Date.now()}-${currentIteration}`,
|
|
3143
|
+
params: { model: "llm" },
|
|
3144
|
+
content: { type: "text", value: fullPrompt }
|
|
3145
|
+
};
|
|
3146
|
+
const result = await process2(directive);
|
|
3147
|
+
if (!result.success || !result.output) {
|
|
3148
|
+
break;
|
|
3149
|
+
}
|
|
3150
|
+
const parseResult = parseWithSchema(result.output, schema);
|
|
3151
|
+
if (!parseResult.success) {
|
|
3152
|
+
currentIteration++;
|
|
3153
|
+
continue;
|
|
3154
|
+
}
|
|
3155
|
+
lastResult = parseResult.data;
|
|
3156
|
+
setCurrentResult(parseResult.data);
|
|
3157
|
+
setIteration(currentIteration + 1);
|
|
3158
|
+
onIteration?.(parseResult.data, currentIteration + 1);
|
|
3159
|
+
if (until(parseResult.data, currentIteration + 1)) {
|
|
3160
|
+
setIsComplete(true);
|
|
3161
|
+
onComplete?.(parseResult.data, currentIteration + 1);
|
|
3162
|
+
break;
|
|
3163
|
+
}
|
|
3164
|
+
previousAttempts.push(result.output);
|
|
3165
|
+
currentIteration++;
|
|
3166
|
+
}
|
|
3167
|
+
if (!isComplete && lastResult) {
|
|
3168
|
+
setIsComplete(true);
|
|
3169
|
+
onComplete?.(lastResult, currentIteration);
|
|
3170
|
+
}
|
|
3171
|
+
setIsLoading(false);
|
|
3172
|
+
}
|
|
3173
|
+
runReflection();
|
|
3174
|
+
}, [basePrompt, enabled, maxIterations]);
|
|
3175
|
+
if (isLoading) {
|
|
3176
|
+
if (showProgress && currentResult) {
|
|
3177
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3178
|
+
className,
|
|
3179
|
+
children: [
|
|
3180
|
+
render ? render(currentResult, iteration) : JSON.stringify(currentResult),
|
|
3181
|
+
/* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3182
|
+
children: [
|
|
3183
|
+
" (refining... iteration ",
|
|
3184
|
+
iteration,
|
|
3185
|
+
")"
|
|
3186
|
+
]
|
|
3187
|
+
}, undefined, true, undefined, this)
|
|
3188
|
+
]
|
|
3189
|
+
}, undefined, true, undefined, this);
|
|
3190
|
+
}
|
|
3191
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3192
|
+
className,
|
|
3193
|
+
children: loading
|
|
3194
|
+
}, undefined, false, undefined, this);
|
|
3195
|
+
}
|
|
3196
|
+
if (!currentResult) {
|
|
3197
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3198
|
+
className,
|
|
3199
|
+
children: fallback
|
|
3200
|
+
}, undefined, false, undefined, this);
|
|
3201
|
+
}
|
|
3202
|
+
if (render) {
|
|
3203
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3204
|
+
className,
|
|
3205
|
+
children: render(currentResult, iteration)
|
|
3206
|
+
}, undefined, false, undefined, this);
|
|
3207
|
+
}
|
|
3208
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3209
|
+
className,
|
|
3210
|
+
children: JSON.stringify(currentResult)
|
|
3211
|
+
}, undefined, false, undefined, this);
|
|
3212
|
+
}
|
|
3213
|
+
function ESIOptimize({
|
|
3214
|
+
children,
|
|
3215
|
+
prompt,
|
|
3216
|
+
schema,
|
|
3217
|
+
criteria = ["clarity", "relevance", "completeness", "conciseness"],
|
|
3218
|
+
targetQuality = 0.85,
|
|
3219
|
+
maxRounds = 3,
|
|
3220
|
+
onlyWhenAlone = true,
|
|
3221
|
+
render,
|
|
3222
|
+
fallback,
|
|
3223
|
+
loading = "...",
|
|
3224
|
+
onImprove,
|
|
3225
|
+
onOptimized,
|
|
3226
|
+
className
|
|
3227
|
+
}) {
|
|
3228
|
+
const { process: process2, enabled } = useESI();
|
|
3229
|
+
const presence = usePresenceForESI();
|
|
3230
|
+
const [result, setResult] = import_react2.useState(null);
|
|
3231
|
+
const [meta, setMeta] = import_react2.useState({
|
|
3232
|
+
rounds: 0,
|
|
3233
|
+
quality: 0,
|
|
3234
|
+
improvements: [],
|
|
3235
|
+
wasOptimized: false
|
|
3236
|
+
});
|
|
3237
|
+
const [isLoading, setIsLoading] = import_react2.useState(true);
|
|
3238
|
+
const basePrompt = prompt || (typeof children === "string" ? children : String(children || ""));
|
|
3239
|
+
const shouldOptimize = !onlyWhenAlone || presence.users.length <= 1;
|
|
3240
|
+
import_react2.useEffect(() => {
|
|
3241
|
+
if (!enabled) {
|
|
3242
|
+
setIsLoading(false);
|
|
3243
|
+
return;
|
|
3244
|
+
}
|
|
3245
|
+
async function runOptimization() {
|
|
3246
|
+
setIsLoading(true);
|
|
3247
|
+
const criteriaList = criteria.join(", ");
|
|
3248
|
+
const firstPassPrompt = `${basePrompt}
|
|
3249
|
+
|
|
3250
|
+
After generating your response, assess its quality on these criteria: ${criteriaList}
|
|
3251
|
+
|
|
3252
|
+
${generateSchemaPrompt(schema)}
|
|
3253
|
+
|
|
3254
|
+
Additionally, include a self-assessment in this format:
|
|
3255
|
+
{
|
|
3256
|
+
"result": <your response matching the schema above>,
|
|
3257
|
+
"selfAssessment": {
|
|
3258
|
+
"quality": <0-1 score>,
|
|
3259
|
+
"strengths": [<list of strengths>],
|
|
3260
|
+
"weaknesses": [<list of weaknesses>],
|
|
3261
|
+
"improvementSuggestions": [<specific improvements>]
|
|
3262
|
+
}
|
|
3263
|
+
}`;
|
|
3264
|
+
let currentResult = null;
|
|
3265
|
+
let currentQuality = 0;
|
|
3266
|
+
let round = 0;
|
|
3267
|
+
let improvements = [];
|
|
3268
|
+
let lastWeaknesses = [];
|
|
3269
|
+
const firstResult = await process2({
|
|
3270
|
+
id: `esi-optimize-${Date.now()}-0`,
|
|
3271
|
+
params: { model: "llm" },
|
|
3272
|
+
content: { type: "text", value: firstPassPrompt }
|
|
3273
|
+
});
|
|
3274
|
+
if (!firstResult.success || !firstResult.output) {
|
|
3275
|
+
setIsLoading(false);
|
|
3276
|
+
return;
|
|
3277
|
+
}
|
|
3278
|
+
try {
|
|
3279
|
+
const parsed = JSON.parse(extractJson(firstResult.output));
|
|
3280
|
+
const validated = schema.safeParse(parsed.result);
|
|
3281
|
+
if (validated.success) {
|
|
3282
|
+
currentResult = validated.data;
|
|
3283
|
+
currentQuality = parsed.selfAssessment?.quality || 0.5;
|
|
3284
|
+
lastWeaknesses = parsed.selfAssessment?.weaknesses || [];
|
|
3285
|
+
round = 1;
|
|
3286
|
+
setResult(currentResult);
|
|
3287
|
+
setMeta({
|
|
3288
|
+
rounds: 1,
|
|
3289
|
+
quality: currentQuality,
|
|
3290
|
+
improvements: [],
|
|
3291
|
+
wasOptimized: false
|
|
3292
|
+
});
|
|
3293
|
+
onImprove?.(currentResult, 1, currentQuality);
|
|
3294
|
+
}
|
|
3295
|
+
} catch {
|
|
3296
|
+
const parseResult = parseWithSchema(firstResult.output, schema);
|
|
3297
|
+
if (parseResult.success) {
|
|
3298
|
+
currentResult = parseResult.data;
|
|
3299
|
+
currentQuality = 0.6;
|
|
3300
|
+
round = 1;
|
|
3301
|
+
setResult(currentResult);
|
|
3302
|
+
} else {
|
|
3303
|
+
setIsLoading(false);
|
|
3304
|
+
return;
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
if (shouldOptimize && currentQuality < targetQuality) {
|
|
3308
|
+
while (round < maxRounds && currentQuality < targetQuality) {
|
|
3309
|
+
const optimizePrompt = `You previously generated this response:
|
|
3310
|
+
${JSON.stringify(currentResult)}
|
|
3311
|
+
|
|
3312
|
+
Quality score: ${currentQuality.toFixed(2)}
|
|
3313
|
+
Weaknesses identified: ${lastWeaknesses.join(", ") || "none specified"}
|
|
3314
|
+
|
|
3315
|
+
Please improve the response, focusing on: ${criteriaList}
|
|
3316
|
+
Address the weaknesses and aim for a quality score above ${targetQuality}.
|
|
3317
|
+
|
|
3318
|
+
${generateSchemaPrompt(schema)}
|
|
3319
|
+
|
|
3320
|
+
Include your improved self-assessment:
|
|
3321
|
+
{
|
|
3322
|
+
"result": <improved response>,
|
|
3323
|
+
"selfAssessment": {
|
|
3324
|
+
"quality": <0-1 score>,
|
|
3325
|
+
"strengths": [...],
|
|
3326
|
+
"weaknesses": [...],
|
|
3327
|
+
"improvementSuggestions": [...]
|
|
3328
|
+
},
|
|
3329
|
+
"improvementsMade": [<what you improved>]
|
|
3330
|
+
}`;
|
|
3331
|
+
const improvedResult = await process2({
|
|
3332
|
+
id: `esi-optimize-${Date.now()}-${round}`,
|
|
3333
|
+
params: { model: "llm" },
|
|
3334
|
+
content: { type: "text", value: optimizePrompt }
|
|
3335
|
+
});
|
|
3336
|
+
if (!improvedResult.success || !improvedResult.output) {
|
|
3337
|
+
break;
|
|
3338
|
+
}
|
|
3339
|
+
try {
|
|
3340
|
+
const parsed = JSON.parse(extractJson(improvedResult.output));
|
|
3341
|
+
const validated = schema.safeParse(parsed.result);
|
|
3342
|
+
if (validated.success) {
|
|
3343
|
+
const newQuality = parsed.selfAssessment?.quality || currentQuality;
|
|
3344
|
+
if (newQuality > currentQuality) {
|
|
3345
|
+
currentResult = validated.data;
|
|
3346
|
+
currentQuality = newQuality;
|
|
3347
|
+
lastWeaknesses = parsed.selfAssessment?.weaknesses || [];
|
|
3348
|
+
if (parsed.improvementsMade) {
|
|
3349
|
+
improvements.push(...parsed.improvementsMade);
|
|
3350
|
+
}
|
|
3351
|
+
setResult(currentResult);
|
|
3352
|
+
setMeta({
|
|
3353
|
+
rounds: round + 1,
|
|
3354
|
+
quality: currentQuality,
|
|
3355
|
+
improvements,
|
|
3356
|
+
wasOptimized: true
|
|
3357
|
+
});
|
|
3358
|
+
onImprove?.(currentResult, round + 1, currentQuality);
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
} catch {}
|
|
3362
|
+
round++;
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
if (currentResult) {
|
|
3366
|
+
setMeta((prev) => ({
|
|
3367
|
+
...prev,
|
|
3368
|
+
rounds: round,
|
|
3369
|
+
quality: currentQuality,
|
|
3370
|
+
wasOptimized: round > 1
|
|
3371
|
+
}));
|
|
3372
|
+
onOptimized?.(currentResult, round, currentQuality);
|
|
3373
|
+
}
|
|
3374
|
+
setIsLoading(false);
|
|
3375
|
+
}
|
|
3376
|
+
runOptimization();
|
|
3377
|
+
}, [basePrompt, enabled, shouldOptimize, targetQuality, maxRounds]);
|
|
3378
|
+
if (isLoading) {
|
|
3379
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3380
|
+
className,
|
|
3381
|
+
children: loading
|
|
3382
|
+
}, undefined, false, undefined, this);
|
|
3383
|
+
}
|
|
3384
|
+
if (!result) {
|
|
3385
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3386
|
+
className,
|
|
3387
|
+
children: fallback
|
|
3388
|
+
}, undefined, false, undefined, this);
|
|
3389
|
+
}
|
|
3390
|
+
if (render) {
|
|
3391
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3392
|
+
className,
|
|
3393
|
+
children: render(result, meta)
|
|
3394
|
+
}, undefined, false, undefined, this);
|
|
3395
|
+
}
|
|
3396
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV("span", {
|
|
3397
|
+
className,
|
|
3398
|
+
children: JSON.stringify(result)
|
|
3399
|
+
}, undefined, false, undefined, this);
|
|
3400
|
+
}
|
|
3401
|
+
function extractJson(str) {
|
|
3402
|
+
let cleaned = str.trim();
|
|
3403
|
+
if (cleaned.startsWith("```")) {
|
|
3404
|
+
const match = cleaned.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
3405
|
+
if (match)
|
|
3406
|
+
cleaned = match[1].trim();
|
|
3407
|
+
}
|
|
3408
|
+
const jsonMatch = cleaned.match(/\{[\s\S]*\}/);
|
|
3409
|
+
if (jsonMatch)
|
|
3410
|
+
return jsonMatch[0];
|
|
3411
|
+
return cleaned;
|
|
3412
|
+
}
|
|
3413
|
+
function ESIAuto({
|
|
3414
|
+
children,
|
|
3415
|
+
prompt,
|
|
3416
|
+
schema,
|
|
3417
|
+
render,
|
|
3418
|
+
collaborativeThreshold = 2,
|
|
3419
|
+
optimizeSettings,
|
|
3420
|
+
fallback,
|
|
3421
|
+
loading,
|
|
3422
|
+
className
|
|
3423
|
+
}) {
|
|
3424
|
+
const presence = usePresenceForESI();
|
|
3425
|
+
const userCount = presence.users.length;
|
|
3426
|
+
const mode = userCount >= collaborativeThreshold ? "collaborative" : userCount === 1 ? "optimized" : "basic";
|
|
3427
|
+
if (mode === "collaborative") {
|
|
3428
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ESICollaborative, {
|
|
3429
|
+
prompt,
|
|
3430
|
+
schema,
|
|
3431
|
+
fallback,
|
|
3432
|
+
loading,
|
|
3433
|
+
className,
|
|
3434
|
+
render: render ? (data) => render(data, "collaborative") : undefined,
|
|
3435
|
+
children
|
|
3436
|
+
}, undefined, false, undefined, this);
|
|
3437
|
+
}
|
|
3438
|
+
if (mode === "optimized") {
|
|
3439
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ESIOptimize, {
|
|
3440
|
+
prompt,
|
|
3441
|
+
schema,
|
|
3442
|
+
criteria: optimizeSettings?.criteria,
|
|
3443
|
+
targetQuality: optimizeSettings?.targetQuality,
|
|
3444
|
+
maxRounds: optimizeSettings?.maxRounds,
|
|
3445
|
+
fallback,
|
|
3446
|
+
loading,
|
|
3447
|
+
className,
|
|
3448
|
+
render: render ? (data) => render(data, "optimized") : undefined,
|
|
3449
|
+
children
|
|
3450
|
+
}, undefined, false, undefined, this);
|
|
3451
|
+
}
|
|
3452
|
+
return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ESIStructured, {
|
|
3453
|
+
prompt,
|
|
3454
|
+
schema,
|
|
3455
|
+
fallback,
|
|
3456
|
+
loading,
|
|
3457
|
+
className,
|
|
3458
|
+
render: render ? (data) => render(data, "basic") : undefined,
|
|
3459
|
+
children
|
|
3460
|
+
}, undefined, false, undefined, this);
|
|
3461
|
+
}
|
|
3462
|
+
var ESIControl = {
|
|
3463
|
+
Structured: ESIStructured,
|
|
3464
|
+
If: ESIIf,
|
|
3465
|
+
Match: ESIMatch,
|
|
3466
|
+
Case: ESICase,
|
|
3467
|
+
Default: ESIDefault,
|
|
3468
|
+
Collaborative: ESICollaborative,
|
|
3469
|
+
Reflect: ESIReflect,
|
|
3470
|
+
Optimize: ESIOptimize,
|
|
3471
|
+
Auto: ESIAuto
|
|
3472
|
+
};
|
|
3473
|
+
export {
|
|
3474
|
+
useESIInfer,
|
|
3475
|
+
useESI,
|
|
3476
|
+
supportsSpeculationRules,
|
|
3477
|
+
supportsLinkPrefetch,
|
|
3478
|
+
setContextCookies,
|
|
3479
|
+
parseWithSchema,
|
|
3480
|
+
generateSchemaPrompt,
|
|
3481
|
+
extractUserContext,
|
|
3482
|
+
esiWithContext,
|
|
3483
|
+
esiVision,
|
|
3484
|
+
esiMatch,
|
|
3485
|
+
esiInfer,
|
|
3486
|
+
esiIf,
|
|
3487
|
+
esiEmotion,
|
|
3488
|
+
esiEmbed,
|
|
3489
|
+
createSpeculationHook,
|
|
3490
|
+
createControlProcessor,
|
|
3491
|
+
createContextMiddleware,
|
|
3492
|
+
autoInitSpeculation,
|
|
3493
|
+
addSpeculationHeaders,
|
|
3494
|
+
SpeculationManager,
|
|
3495
|
+
HeuristicAdapter,
|
|
3496
|
+
EdgeWorkersESIProcessor,
|
|
3497
|
+
ESIVision,
|
|
3498
|
+
ESIStructured,
|
|
3499
|
+
ESIReflect,
|
|
3500
|
+
ESIProvider,
|
|
3501
|
+
ESIOptimize,
|
|
3502
|
+
ESIMatch,
|
|
3503
|
+
ESIInfer,
|
|
3504
|
+
ESIIf,
|
|
3505
|
+
ESIEmotion,
|
|
3506
|
+
ESIEmbed,
|
|
3507
|
+
ESIDefault,
|
|
3508
|
+
ESIControl,
|
|
3509
|
+
ESICollaborative,
|
|
3510
|
+
ESICase,
|
|
3511
|
+
ESIAuto,
|
|
3512
|
+
ESI,
|
|
3513
|
+
DEFAULT_ROUTER_CONFIG,
|
|
3514
|
+
DEFAULT_ESI_CONFIG
|
|
3515
|
+
};
|