@songsid/agend 2.3.3-beta.4 → 2.3.3-beta.6
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/agent-cli.js +13 -112
- package/dist/agent-cli.js.map +1 -1
- package/dist/agent-endpoint.d.ts +0 -1
- package/dist/agent-endpoint.js +1 -9
- package/dist/agent-endpoint.js.map +1 -1
- package/dist/agent-whats-new.d.ts +3 -6
- package/dist/agent-whats-new.js +7 -18
- package/dist/agent-whats-new.js.map +1 -1
- package/dist/auth-api.d.ts +0 -7
- package/dist/auth-api.js +1 -15
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/claude-code.js +4 -2
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/codex.d.ts +1 -0
- package/dist/backend/codex.js +106 -15
- package/dist/backend/codex.js.map +1 -1
- package/dist/backend/grok.js +57 -11
- package/dist/backend/grok.js.map +1 -1
- package/dist/backend/types.d.ts +35 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/bundled-skills.d.ts +4 -6
- package/dist/bundled-skills.js +10 -14
- package/dist/bundled-skills.js.map +1 -1
- package/dist/channel/mcp-server.js +5 -5
- package/dist/channel/mcp-server.js.map +1 -1
- package/dist/channel/mcp-tools.d.ts +1 -3
- package/dist/channel/mcp-tools.js +4 -58
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/config-validator.js +6 -3
- package/dist/config-validator.js.map +1 -1
- package/dist/daemon.d.ts +17 -3
- package/dist/daemon.js +76 -107
- package/dist/daemon.js.map +1 -1
- package/dist/dashboard-live.d.ts +1 -1
- package/dist/dashboard-live.js +3 -3
- package/dist/dashboard-live.js.map +1 -1
- package/dist/dashboard-permissions.d.ts +1 -1
- package/dist/dashboard-permissions.js +1 -3
- package/dist/dashboard-permissions.js.map +1 -1
- package/dist/fleet-manager.d.ts +31 -44
- package/dist/fleet-manager.js +94 -227
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +11 -1
- package/dist/general-knowledge/skills/session-management/SKILL.md +6 -0
- package/dist/general-knowledge/skills/web-appearance/SKILL.md +13 -204
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +26 -63
- package/dist/instance-lifecycle.d.ts +6 -0
- package/dist/instance-lifecycle.js +20 -4
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/locale.js +14 -4
- package/dist/locale.js.map +1 -1
- package/dist/outbound-handlers.js +19 -7
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/outbound-schemas.d.ts +0 -62
- package/dist/outbound-schemas.js +3 -42
- package/dist/outbound-schemas.js.map +1 -1
- package/dist/public-web-gateway.js +0 -9
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/public-web-link.d.ts +2 -0
- package/dist/public-web-link.js +5 -0
- package/dist/public-web-link.js.map +1 -1
- package/dist/search/search-docs.d.ts +1 -1
- package/dist/search/search-docs.js +2 -2
- package/dist/search/search-docs.js.map +1 -1
- package/dist/settings-api.d.ts +6 -0
- package/dist/settings-api.js +14 -2
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.js +3 -1
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-confirmation.d.ts +17 -3
- package/dist/settings-confirmation.js +8 -5
- package/dist/settings-confirmation.js.map +1 -1
- package/dist/settings-http-confirmation.js +31 -1
- package/dist/settings-http-confirmation.js.map +1 -1
- package/dist/tool-permissions.js +3 -10
- package/dist/tool-permissions.js.map +1 -1
- package/dist/topic-commands.d.ts +27 -7
- package/dist/topic-commands.js +94 -36
- package/dist/topic-commands.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/ui/chat-ambient.js +4 -4
- package/dist/ui/chat-commands.js +3 -2
- package/dist/ui/chat-store.js +4 -1
- package/dist/ui/chat-strings.js +12 -46
- package/dist/ui/chat-thread.js +51 -59
- package/dist/ui/fleet-office-skin.js +37 -14
- package/dist/ui/fleet-office.js +31 -7
- package/dist/ui/html-attachment.js +22 -8
- package/dist/ui/panel-chat.js +21 -50
- package/dist/ui/preview-panel.js +12 -21
- package/dist/ui/preview.js +10 -3
- package/dist/ui/search-dialog.js +30 -14
- package/dist/ui/settings-appearance.js +1 -3
- package/dist/ui/settings-confirm.js +18 -0
- package/dist/ui/settings-guests.js +13 -4
- package/dist/ui/settings-learn.js +1 -1
- package/dist/ui/settings-mods.js +5 -12
- package/dist/ui/settings-registry.js +0 -1
- package/dist/ui/settings-strings.js +6 -6
- package/dist/ui/shared/app-i18n.js +13 -2
- package/dist/ui/shared/app-prefs.js +17 -17
- package/dist/ui/shared/app-shell.js +47 -9
- package/dist/ui/shared/app-store.js +6 -2
- package/dist/ui/shared/app.css +19 -36
- package/dist/ui/shared/app.js +5 -4
- package/dist/ui/shared/instance-nav.js +9 -9
- package/dist/ui/shared/instance-switch.js +8 -2
- package/dist/ui/shared/panel-view.js +22 -8
- package/dist/ui/shared/view-strings.js +6 -0
- package/dist/usage/usage-api.d.ts +3 -0
- package/dist/usage/usage-api.js +5 -1
- package/dist/usage/usage-api.js.map +1 -1
- package/dist/view-api.d.ts +2 -0
- package/dist/view-api.js +64 -0
- package/dist/view-api.js.map +1 -1
- package/dist/web-api.d.ts +9 -17
- package/dist/web-api.js +255 -371
- package/dist/web-api.js.map +1 -1
- package/dist/web-appearance-tools.d.ts +0 -2
- package/dist/web-appearance-tools.js +2 -5
- package/dist/web-appearance-tools.js.map +1 -1
- package/dist/web-appearance-view.d.ts +0 -6
- package/dist/web-appearance-view.js +0 -1
- package/dist/web-appearance-view.js.map +1 -1
- package/dist/web-appearance.d.ts +14 -7
- package/dist/web-appearance.js +5 -6
- package/dist/web-appearance.js.map +1 -1
- package/dist/web-asset-parts.d.ts +1 -17
- package/dist/web-asset-parts.js +1 -15
- package/dist/web-asset-parts.js.map +1 -1
- package/dist/web-auth.js +1 -7
- package/dist/web-auth.js.map +1 -1
- package/dist/web-chat-history.d.ts +3 -7
- package/dist/web-chat-history.js +10 -17
- package/dist/web-chat-history.js.map +1 -1
- package/dist/web-commands.d.ts +9 -1
- package/dist/web-commands.js +13 -0
- package/dist/web-commands.js.map +1 -1
- package/dist/web-experimental.d.ts +2 -11
- package/dist/web-experimental.js +8 -36
- package/dist/web-experimental.js.map +1 -1
- package/dist/web-guest-access.d.ts +40 -2
- package/dist/web-guest-access.js +50 -14
- package/dist/web-guest-access.js.map +1 -1
- package/dist/web-mod-bundle.d.ts +2 -45
- package/dist/web-mod-bundle.js +15 -63
- package/dist/web-mod-bundle.js.map +1 -1
- package/dist/web-mod-store.d.ts +3 -48
- package/dist/web-mod-store.js +30 -97
- package/dist/web-mod-store.js.map +1 -1
- package/dist/web-prefs.d.ts +13 -0
- package/dist/web-prefs.js +38 -0
- package/dist/web-prefs.js.map +1 -1
- package/dist/web-preview.d.ts +6 -13
- package/dist/web-preview.js +12 -23
- package/dist/web-preview.js.map +1 -1
- package/dist/web-session.d.ts +11 -3
- package/dist/web-session.js +22 -11
- package/dist/web-session.js.map +1 -1
- package/dist/web-settings-patch.d.ts +1 -0
- package/dist/web-settings-patch.js +6 -3
- package/dist/web-settings-patch.js.map +1 -1
- package/dist/web-settings-tools.d.ts +0 -13
- package/dist/web-settings-tools.js +12 -84
- package/dist/web-settings-tools.js.map +1 -1
- package/package.json +1 -1
- package/dist/general-knowledge/skills/web-appearance/SKILL.canvas-worker-off.md +0 -376
- package/dist/general-knowledge/skills/web-dashboard/SKILL.canvas-worker-off.md +0 -672
- package/dist/ui/app-effects.js +0 -251
- package/dist/ui/chat-effect-posters.js +0 -42
- package/dist/ui/chat-effects.js +0 -167
- package/dist/ui/effect-trial-controller.js +0 -124
- package/dist/ui/effect-trial-offer.js +0 -2
- package/dist/ui/effect-trial-panel.js +0 -40
- package/dist/ui/effects-waker.js +0 -2
- package/dist/ui/settings-effects.js +0 -202
- package/dist/ui/settings-owner-effects.js +0 -82
- package/dist/ui/shared/effect-app-runtime.js +0 -299
- package/dist/ui/shared/effect-baseline.js +0 -64
- package/dist/ui/shared/effect-chat-runtime.js +0 -162
- package/dist/ui/shared/effect-cursor.js +0 -126
- package/dist/ui/shared/effect-display-metadata.js +0 -39
- package/dist/ui/shared/effect-frame.js +0 -146
- package/dist/ui/shared/effect-geometry.js +0 -137
- package/dist/ui/shared/effect-host-style.js +0 -10
- package/dist/ui/shared/effect-owner-regions.js +0 -74
- package/dist/ui/shared/effect-owner-source.js +0 -122
- package/dist/ui/shared/effect-policy.js +0 -151
- package/dist/ui/shared/effect-poster-reader.js +0 -98
- package/dist/ui/shared/effect-posters.js +0 -117
- package/dist/ui/shared/effect-profiler.js +0 -184
- package/dist/ui/shared/effect-profiles.js +0 -65
- package/dist/ui/shared/effect-registry.js +0 -545
- package/dist/ui/shared/effect-runtime-loader.js +0 -236
- package/dist/ui/shared/effect-safety.js +0 -153
- package/dist/ui/shared/effect-stock-snapshot.js +0 -43
- package/dist/ui/shared/effect-stock-trust.js +0 -217
- package/dist/ui/shared/effect-trial-shadow.js +0 -62
- package/dist/ui/shared/effect-trial-source.js +0 -103
- package/dist/ui/shared/effect-trial-stage.js +0 -170
- package/dist/ui/shared/effect-trial.css +0 -40
- package/dist/ui/shared/feature-flags.js +0 -127
- package/dist/ui/shared/owner-effect-prefs.js +0 -117
- package/dist/web-effect-bootstrap.d.ts +0 -12
- package/dist/web-effect-bootstrap.js +0 -49
- package/dist/web-effect-bootstrap.js.map +0 -1
- package/dist/web-effect-bundle.d.ts +0 -28
- package/dist/web-effect-bundle.js +0 -171
- package/dist/web-effect-bundle.js.map +0 -1
- package/dist/web-effect-canonical.d.ts +0 -8
- package/dist/web-effect-canonical.js +0 -27
- package/dist/web-effect-canonical.js.map +0 -1
- package/dist/web-effect-library.d.ts +0 -114
- package/dist/web-effect-library.js +0 -530
- package/dist/web-effect-library.js.map +0 -1
- package/dist/web-effect-playback.d.ts +0 -30
- package/dist/web-effect-playback.js +0 -71
- package/dist/web-effect-playback.js.map +0 -1
- package/dist/web-effect-poster.d.ts +0 -8
- package/dist/web-effect-poster.js +0 -52
- package/dist/web-effect-poster.js.map +0 -1
- package/dist/web-effect-profiles.d.ts +0 -118
- package/dist/web-effect-profiles.js +0 -181
- package/dist/web-effect-profiles.js.map +0 -1
- package/dist/web-effect-service.d.ts +0 -93
- package/dist/web-effect-service.js +0 -335
- package/dist/web-effect-service.js.map +0 -1
- package/dist/web-effect-tools.d.ts +0 -48
- package/dist/web-effect-tools.js +0 -129
- package/dist/web-effect-tools.js.map +0 -1
- package/dist/web-effect-trials.d.ts +0 -86
- package/dist/web-effect-trials.js +0 -204
- package/dist/web-effect-trials.js.map +0 -1
- package/dist/web-effect-upload.d.ts +0 -27
- package/dist/web-effect-upload.js +0 -185
- package/dist/web-effect-upload.js.map +0 -1
- package/dist/web-effect-worker.d.ts +0 -8
- package/dist/web-effect-worker.js +0 -170
- package/dist/web-effect-worker.js.map +0 -1
- package/dist/web-effect.d.ts +0 -103
- package/dist/web-effect.js +0 -153
- package/dist/web-effect.js.map +0 -1
- package/dist/web-experimental-http.d.ts +0 -2
- package/dist/web-experimental-http.js +0 -12
- package/dist/web-experimental-http.js.map +0 -1
- package/dist/web-mod-agent.d.ts +0 -50
- package/dist/web-mod-agent.js +0 -207
- package/dist/web-mod-agent.js.map +0 -1
package/dist/ui/app-effects.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
/** #1629: one session-only app effect owner. Importing this module starts nothing. */
|
|
2
|
-
import { appStore } from "/assets/app-store.js";
|
|
3
|
-
import { motionBlocked, onMotionChange } from "/assets/fx-motion.js";
|
|
4
|
-
import { navStore } from "/assets/app-nav.js";
|
|
5
|
-
import { onPrefsChanged } from "/assets/app-prefs.js";
|
|
6
|
-
import { resolvedMode, themesStore, themesShown } from "/assets/app-themes.js";
|
|
7
|
-
import { ownerCssLifecycle, safeMode } from "/assets/owner-css.js";
|
|
8
|
-
import { canvasWorkerEnabled } from "/assets/feature-flags.js";
|
|
9
|
-
import { constrainedDevice } from "/assets/effect-policy.js";
|
|
10
|
-
import { createAppEffectRuntime } from "/assets/effect-app-runtime.js";
|
|
11
|
-
import { effectBootstrapReady } from "/assets/effect-frame.js";
|
|
12
|
-
import { createEffectCursor } from "/assets/effect-cursor.js";
|
|
13
|
-
import { createOwnerEffectRegions } from "/assets/effect-owner-regions.js";
|
|
14
|
-
import { chatEffectIdentity, effectPlaybackIdentity } from "/assets/effect-chat-runtime.js";
|
|
15
|
-
import { createEffectTrialController } from "./effect-trial-controller.js";
|
|
16
|
-
import { effectTrialMessage } from "./effect-trial-offer.js";
|
|
17
|
-
import { claimPanel, panelVersion, panelStore, openTrialPanel, closePanel } from "./preview-panel.js";
|
|
18
|
-
const owners = new WeakMap();
|
|
19
|
-
export function getAppEffects(host = window) { const value = owners.get(host); return value && !value.dead && value.api?.ok ? value : null; }
|
|
20
|
-
|
|
21
|
-
/** Boot once with the page's Chat store, including when the first visible panel is Fleet. */
|
|
22
|
-
export function startAppEffects({ store, window: host = window, factories = {} } = {}) {
|
|
23
|
-
if (!canvasWorkerEnabled()) return null;
|
|
24
|
-
const existing = owners.get(host);
|
|
25
|
-
if (existing) { if (!existing.dead) existing.bindStore(store); return getAppEffects(host); }
|
|
26
|
-
const playbackIdentity = effectPlaybackIdentity(host), ownerIdentity = chatEffectIdentity(host);
|
|
27
|
-
if (!playbackIdentity || typeof host.AgendAuth?.onSessionEnd !== "function" || typeof host.AgendAuth?.sessionEnded !== "function") return null;
|
|
28
|
-
const doc = host.document, releases = [], ended = new Set(), updates = new Set(), trialUpdates = new Set(); let replyOff = null, replyStore = null, regions = null, cursor = null, cursorStamp = null, trialControl = null, trialIntent = null, trialHint = ownerIdentity ? null : false, trialSerial = 0, trialStamp = null, chatBinding = null;
|
|
29
|
-
const safe = fn => { try { return fn(); } catch { return null; } };
|
|
30
|
-
const hold = off => { if (entry.dead) safe(() => off?.()); else releases.push(off); };
|
|
31
|
-
const entry = { dead: false, api: null, disposed: null,
|
|
32
|
-
cursorSnapshot: () => cursor?.snapshot() ?? { status: "unavailable", id: null },
|
|
33
|
-
gates: () => context(),
|
|
34
|
-
subscribe(fn) { if (typeof fn !== "function" || entry.dead) return () => {}; updates.add(fn); return () => updates.delete(fn); },
|
|
35
|
-
subscribeTrial(fn) { if (typeof fn !== "function" || entry.dead) return () => {}; trialUpdates.add(fn); return () => trialUpdates.delete(fn); },
|
|
36
|
-
onEnd(fn) { if (typeof fn !== "function") return () => {}; if (entry.dead) { safe(fn); return () => {}; } ended.add(fn); return () => ended.delete(fn); },
|
|
37
|
-
bindStore(value) {
|
|
38
|
-
if (entry.dead || value === replyStore) return;
|
|
39
|
-
safe(() => replyOff?.()); replyOff = null; replyStore = value;
|
|
40
|
-
trialControl?.stop(); chatBinding = null; entry.api?.detachChat();
|
|
41
|
-
if (typeof value?.onAgentReply === "function") {
|
|
42
|
-
const off = value.onAgentReply(event => { if (!entry.dead && replyStore === value) entry.api?.reply(event); });
|
|
43
|
-
if (entry.dead || replyStore !== value) safe(() => off?.()); else replyOff = off;
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
trialStatus(message) {
|
|
47
|
-
const offer = safe(() => effectTrialMessage(message)), nav = navStore.get();
|
|
48
|
-
const now = safe(() => host.Date.now());
|
|
49
|
-
if (!offer || !Number.isFinite(now) || now >= offer.expiresAt) return "expired";
|
|
50
|
-
if (trialHint === null && !entry.dead) return "checking";
|
|
51
|
-
if (entry.dead || !trialHint || trialControl?.ok !== true) return "localAdmin";
|
|
52
|
-
if (!chatBinding || safe(() => chatBinding.current()) !== true || message.instance !== nav.route?.instance || nav.route?.panel !== "chat") return "chatChanged";
|
|
53
|
-
const state = trialControl.snapshot();
|
|
54
|
-
if (state.phase !== "idle" || state.busy) return "busy";
|
|
55
|
-
return trialPlaybackStatus();
|
|
56
|
-
},
|
|
57
|
-
trialFailure(message) {
|
|
58
|
-
const offer = safe(() => effectTrialMessage(message)), state = trialControl?.snapshot();
|
|
59
|
-
return offer && state?.phase === "idle" && state.offer === offer.offer && !["stopped", "replaced"].includes(state.reason) ? state.reason : null;
|
|
60
|
-
},
|
|
61
|
-
canTry(message) { return entry.trialStatus(message) === "ready"; },
|
|
62
|
-
stopTrial() { trialControl?.stop(); },
|
|
63
|
-
startTrial(message) {
|
|
64
|
-
if (!entry.canTry(message)) return Promise.resolve(false);
|
|
65
|
-
const nav = navStore.get(); trialIntent = { name: message.instance, seq: nav.seq, claim: claimPanel(), handle: null, chat: chatBinding };
|
|
66
|
-
return trialControl.start(message);
|
|
67
|
-
},
|
|
68
|
-
attachChat(options) {
|
|
69
|
-
const nav = navStore.get(), name = options?.name;
|
|
70
|
-
if (entry.dead || !entry.api?.ok || nav.route?.panel !== "chat" || nav.route.instance !== name || typeof options.current !== "function") return null;
|
|
71
|
-
const binding = { current: () => !entry.dead && host.document === doc && navStore.get().seq === nav.seq && navStore.get().route?.panel === "chat" && navStore.get().route?.instance === name && options.current() === true };
|
|
72
|
-
chatBinding = binding; trialControl?.stop();
|
|
73
|
-
if (entry.dead || chatBinding !== binding) return null;
|
|
74
|
-
const handle = entry.api.attachChat({ ...options, current: () => chatBinding === binding && binding.current() });
|
|
75
|
-
if (entry.dead || chatBinding !== binding) { safe(() => handle?.dispose()); return null; }
|
|
76
|
-
if (!handle) chatBinding = null;
|
|
77
|
-
return handle;
|
|
78
|
-
},
|
|
79
|
-
dispose(restartable = false) {
|
|
80
|
-
if (entry.dead) return entry.disposed; entry.dead = true;
|
|
81
|
-
if (restartable && owners.get(host) === entry) owners.delete(host);
|
|
82
|
-
safe(() => trialControl?.dispose()); const coreDisposed = safe(() => entry.api?.dispose(restartable === true)); safe(() => replyOff?.()); replyOff = null; replyStore = null;
|
|
83
|
-
for (const off of releases.splice(0)) safe(off);
|
|
84
|
-
updates.clear(); trialUpdates.clear(); const listeners = [...ended]; ended.clear(); for (const fn of listeners) safe(fn);
|
|
85
|
-
entry.disposed = Promise.all([coreDisposed, safe(() => cursor?.whenDisposed?.())]);
|
|
86
|
-
return entry.disposed;
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
owners.set(host, entry); // Reentrant setup never constructs another owner.
|
|
90
|
-
let media, coarse;
|
|
91
|
-
function ownerCssForPlayback() {
|
|
92
|
-
if (doc.body.dataset.tier !== "guest") return ownerCssLifecycle.get().state;
|
|
93
|
-
// Guests never install owner CSS. Prove its absence rather than borrowing the uninstalled
|
|
94
|
-
// lifecycle's initial unknown, and refuse unexpected styles instead of trusting a missing id.
|
|
95
|
-
try {
|
|
96
|
-
if (doc.body.dataset.ownerCss || doc.querySelectorAll("#owner-css").length) return "unknown";
|
|
97
|
-
// A CSP-refused or disabled STYLE has no paint. Recheck on every proof so enabling
|
|
98
|
-
// it never borrows an earlier absence verdict (WebKit capture inserts a refused no-op).
|
|
99
|
-
for (const style of doc.querySelectorAll("style")) if (style.sheet && style.sheet.disabled !== true) return "unknown";
|
|
100
|
-
const allowed = new Set(["/assets/tokens.css", "/assets/app.css"]);
|
|
101
|
-
for (const link of doc.querySelectorAll('link[rel~="stylesheet"]')) {
|
|
102
|
-
const url = new URL(link.getAttribute("href"), host.location.origin);
|
|
103
|
-
if (url.origin !== host.location.origin || !allowed.has(url.pathname) || url.search || url.hash) return "unknown";
|
|
104
|
-
}
|
|
105
|
-
return "off";
|
|
106
|
-
} catch { return "unknown"; }
|
|
107
|
-
}
|
|
108
|
-
function guestChatVersion(value) {
|
|
109
|
-
if (doc.body.dataset.tier !== "guest") return null;
|
|
110
|
-
const name = navStore.get().route?.instance, v = value.instances?.find(i => i.name === name)?.effect_chat_v;
|
|
111
|
-
return typeof v === "string" && /^[a-f0-9]{32}$/.test(v) ? v : null;
|
|
112
|
-
}
|
|
113
|
-
// #2188: whether a dialog, menu or popover is open — a whole-document query when none is (the usual case), asked
|
|
114
|
-
// several times per sync. Read once per task: the cached value is dropped at the next microtask, and whenever the
|
|
115
|
-
// document changes (the MutationObserver below drops it before it reads).
|
|
116
|
-
let modalCache = null;
|
|
117
|
-
function modalOpen() {
|
|
118
|
-
if (modalCache === null) {
|
|
119
|
-
modalCache = !!doc.querySelector("dialog[open],.menu-list,.pop,[role=alertdialog],.oc-keep,.shell.sb-open");
|
|
120
|
-
Promise.resolve().then(() => { modalCache = null; });
|
|
121
|
-
}
|
|
122
|
-
return modalCache;
|
|
123
|
-
}
|
|
124
|
-
function context() {
|
|
125
|
-
return { safe: safeMode(), publicLink: doc.body.dataset.publicLink === "1", reducedMotion: motionBlocked(host), saveData: host.navigator?.connection?.saveData === true,
|
|
126
|
-
hidden: doc.visibilityState !== "visible", enabled: entry.api?.playbackAvailable !== false && typeof host.OffscreenCanvas === "function" && typeof host.Worker === "function" && typeof host.MutationObserver === "function" && typeof host.ResizeObserver === "function",
|
|
127
|
-
show: themesShown(), transportReady: effectBootstrapReady(host, host.location?.origin, doc.body.dataset.effectBoot),
|
|
128
|
-
constrained: constrainedDevice({ memory: host.navigator?.deviceMemory, cores: host.navigator?.hardwareConcurrency, coarse: coarse?.matches === true, width: host.innerWidth }),
|
|
129
|
-
modal: modalOpen(), openInstance: null };
|
|
130
|
-
}
|
|
131
|
-
function trialCurrent(name) {
|
|
132
|
-
const intent = trialIntent, nav = navStore.get();
|
|
133
|
-
return !entry.dead && host.document === doc && !!intent && !!intent.chat && chatBinding === intent.chat && intent.chat.current() === true && intent.name === name && nav.seq === intent.seq && nav.route?.panel === "chat" && nav.route.instance === name
|
|
134
|
-
&& (panelVersion() === intent.claim || intent.handle !== null && panelStore.get().open?.handle === intent.handle);
|
|
135
|
-
}
|
|
136
|
-
// One priority order feeds both presentation and redraw identity: false→different-false must redraw.
|
|
137
|
-
function trialPlaybackStatus() {
|
|
138
|
-
const c = context();
|
|
139
|
-
if (c.safe) return "safe";
|
|
140
|
-
if (!c.show) return "effectsOff";
|
|
141
|
-
if (c.reducedMotion) return "reducedMotion";
|
|
142
|
-
if (!c.enabled) return "unsupported";
|
|
143
|
-
if (!c.transportReady) return "transport";
|
|
144
|
-
if (c.publicLink) return "localAdmin";
|
|
145
|
-
if (c.hidden || doc.hasFocus?.() !== true) return "inactive";
|
|
146
|
-
if (c.modal) return "dialog";
|
|
147
|
-
return "ready";
|
|
148
|
-
}
|
|
149
|
-
function trialAllowed() {
|
|
150
|
-
const c = context();
|
|
151
|
-
return !entry.dead && doc.visibilityState === "visible" && doc.hasFocus?.() === true
|
|
152
|
-
&& c.enabled && c.show && c.transportReady && !c.safe && !c.publicLink && !c.reducedMotion && !c.hidden && !c.modal;
|
|
153
|
-
}
|
|
154
|
-
function mountTrial(handle) {
|
|
155
|
-
const intent = trialIntent; if (!intent || !trialCurrent(handle.instance) || !handle.current() || !Number.isSafeInteger(++trialSerial)) throw Error("trial_unavailable");
|
|
156
|
-
intent.handle = handle;
|
|
157
|
-
const binding = Object.freeze({ key: `trial:${trialSerial}:${handle.reply.trial}`, id: handle.reply.offer.id, run: handle.reply.trial, instance: handle.instance, generation: trialSerial });
|
|
158
|
-
let stage = null, source = null;
|
|
159
|
-
const cleanup = () => {
|
|
160
|
-
safe(() => source?.stop()); safe(() => stage?.dispose());
|
|
161
|
-
if (panelStore.get().open?.handle === handle) closePanel();
|
|
162
|
-
};
|
|
163
|
-
try {
|
|
164
|
-
openTrialPanel({ key: binding.key, instance: handle.instance, binding, handle,
|
|
165
|
-
onStage(value) {
|
|
166
|
-
stage = value;
|
|
167
|
-
if (!handle.current()) { cleanup(); handle.stop(); return; }
|
|
168
|
-
source = entry.api.attachTrial({ reply: handle.reply, offer: handle.reply.offer.offer, startedAt: handle.startedAt, stage,
|
|
169
|
-
current: handle.current, onStop: handle.stop });
|
|
170
|
-
if (!source) { cleanup(); handle.stop(); }
|
|
171
|
-
},
|
|
172
|
-
});
|
|
173
|
-
} catch (error) { cleanup(); throw error; }
|
|
174
|
-
return cleanup;
|
|
175
|
-
}
|
|
176
|
-
function notifyTrial() {
|
|
177
|
-
if (entry.dead) return;
|
|
178
|
-
const nav = navStore.get(), next = JSON.stringify([trialHint, safe(() => chatBinding?.current()) === true, trialPlaybackStatus(), nav.route?.panel, nav.route?.instance, trialControl?.snapshot()]);
|
|
179
|
-
if (next === trialStamp) return; trialStamp = next;
|
|
180
|
-
for (const fn of [...trialUpdates]) safe(fn);
|
|
181
|
-
}
|
|
182
|
-
const notify = () => { if (!entry.dead) { trialControl?.sync(); notifyTrial(); for (const fn of [...updates]) safe(fn); } };
|
|
183
|
-
const cursorDragging = () => doc.body.classList?.contains("side-resizing") === true || !!doc.querySelector(".chat-split.resizing");
|
|
184
|
-
function syncCursor() {
|
|
185
|
-
if (entry.dead || !cursor) return;
|
|
186
|
-
const c = context();
|
|
187
|
-
cursor.update(entry.api?.cursorSelection?.() ?? null, c.enabled && c.show && c.transportReady && !c.safe && !c.publicLink && !c.reducedMotion && !c.hidden && !c.modal && !cursorDragging());
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
if (appStore.get().connection === "ended") { entry.dispose(); return null; }
|
|
191
|
-
media = host.matchMedia?.("(prefers-reduced-motion: reduce)") ?? { matches: true };
|
|
192
|
-
coarse = host.matchMedia?.("(pointer: coarse)") ?? { matches: false };
|
|
193
|
-
entry.api = (factories.runtime ?? createAppEffectRuntime)({ window: host, current: () => !entry.dead && host.document === doc,
|
|
194
|
-
observe: () => ({ context: context(), ownerCss: ownerCssForPlayback(), mode: resolvedMode() }), onDispose: () => entry.dispose(),
|
|
195
|
-
resolveOwnerTarget: (slot, manifest, proof) => !entry.dead ? regions?.resolve?.(slot, manifest.box, proof) ?? null : null,
|
|
196
|
-
onChange: () => { syncCursor(); notify(); } });
|
|
197
|
-
if (entry.dead || !entry.api.ok) { entry.dispose(); return null; }
|
|
198
|
-
if (ownerIdentity) trialControl = (factories.trialController ?? createEffectTrialController)({ window: host, current: trialCurrent, allowed: trialAllowed, onStart: mountTrial, onChange: notify });
|
|
199
|
-
hold(() => trialControl?.dispose());
|
|
200
|
-
if (ownerIdentity && typeof host.AgendAuth.trialSession === "function") Promise.resolve().then(() => host.AgendAuth.trialSession()).then(value => {
|
|
201
|
-
if (entry.dead) return; trialHint = value?.localAdmin === true && value.epoch === chatEffectIdentity(host)?.epoch; notify();
|
|
202
|
-
}).catch(() => { if (!entry.dead) { trialHint = false; notify(); } });
|
|
203
|
-
hold(panelStore.subscribe(() => { trialControl?.sync(); notifyTrial(); }));
|
|
204
|
-
const ownRegions = ownerIdentity && (factories.regions ?? createOwnerEffectRegions)({ window: host, current: () => !entry.dead && host.document === doc });
|
|
205
|
-
regions = ownRegions?.ok ? ownRegions : null; hold(() => ownRegions?.dispose?.());
|
|
206
|
-
if (entry.dead) return null;
|
|
207
|
-
const ownCursor = ownerIdentity && safe(() => (factories.cursor ?? createEffectCursor)({ window: host, current: () => !entry.dead && host.document === doc,
|
|
208
|
-
readImage: (selection, signal) => entry.api?.cursorImageSettled?.(selection, signal) ?? Promise.resolve(null),
|
|
209
|
-
onChange(value) { const next = JSON.stringify(value); if (next !== cursorStamp) { cursorStamp = next; notify(); } },
|
|
210
|
-
}));
|
|
211
|
-
cursor = ownCursor?.ok ? ownCursor : null; hold(() => ownCursor?.dispose?.());
|
|
212
|
-
if (entry.dead) return null;
|
|
213
|
-
const sync = () => { if (!entry.dead) { trialControl?.sync(); entry.api.sync(); syncCursor(); notifyTrial(); } };
|
|
214
|
-
let revision = appStore.get().themesRev, prefsRevision = appStore.get().prefsRev, guestRevision = guestChatVersion(appStore.get()), navSeq = navStore.get().seq;
|
|
215
|
-
hold(navStore.subscribe(value => { if (entry.dead || value.seq === navSeq) return; navSeq = value.seq; trialControl?.stop(); chatBinding = null; entry.api.detachChat(); syncCursor(); }));
|
|
216
|
-
hold(appStore.subscribe(value => {
|
|
217
|
-
if (entry.dead) return;
|
|
218
|
-
if (!canvasWorkerEnabled()) { entry.dispose(true); return; }
|
|
219
|
-
if (value.connection === "ended") { entry.dispose(); return; }
|
|
220
|
-
const guestNext = guestChatVersion(value), chatChanged = value.themesRev !== revision || guestNext !== guestRevision, ownerChanged = value.prefsRev !== prefsRevision;
|
|
221
|
-
revision = value.themesRev; prefsRevision = value.prefsRev; guestRevision = guestNext;
|
|
222
|
-
if (chatChanged) entry.api.changedChat();
|
|
223
|
-
if (ownerChanged) entry.api.changedOwner();
|
|
224
|
-
if (!chatChanged && !ownerChanged) sync();
|
|
225
|
-
}));
|
|
226
|
-
hold(ownerCssLifecycle.subscribe(sync)); hold(themesStore.subscribe(sync)); hold(onPrefsChanged(sync)); hold(onMotionChange(sync));
|
|
227
|
-
if (typeof host.AgendTheme?.onChange === "function") hold(host.AgendTheme.onChange(sync));
|
|
228
|
-
for (const [target, type] of [[media, "change"], [coarse, "change"], [doc, "visibilitychange"], [host, "resize"], [host.navigator?.connection, "change"]]) {
|
|
229
|
-
if (target?.addEventListener) { target.addEventListener(type, sync); hold(() => target.removeEventListener(type, sync)); }
|
|
230
|
-
}
|
|
231
|
-
if (entry.dead) return null;
|
|
232
|
-
let modal = context().modal, dragging = cursorDragging(), queuedSurface = false;
|
|
233
|
-
// Panel commits can happen after navigation and contain no Chat lease. Reproject fixed owner targets
|
|
234
|
-
// once after stock DOM changes. Body-level effect roots/frames/rules do not schedule themselves.
|
|
235
|
-
const surfaceChanged = () => {
|
|
236
|
-
if (entry.dead || queuedSurface) return; queuedSurface = true;
|
|
237
|
-
Promise.resolve().then(() => { queuedSurface = false; sync(); });
|
|
238
|
-
};
|
|
239
|
-
const barriers = typeof host.MutationObserver === "function" ? new host.MutationObserver(records => {
|
|
240
|
-
if (entry.dead) return;
|
|
241
|
-
modalCache = null; // the document changed: a dialog may have opened or closed (read it again)
|
|
242
|
-
const value = context().modal, drag = cursorDragging(); if (value !== modal || drag !== dragging) { modal = value; dragging = drag; sync(); }
|
|
243
|
-
if (Array.isArray(records) && records.some(r => r.target?.closest?.("#app") || r.target === doc.getElementById?.("app"))) surfaceChanged();
|
|
244
|
-
}) : null;
|
|
245
|
-
hold(() => barriers?.disconnect());
|
|
246
|
-
if (entry.dead) return null;
|
|
247
|
-
barriers?.observe(doc.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ["class", "open", "hidden", "role"] });
|
|
248
|
-
entry.bindStore(store); sync();
|
|
249
|
-
return getAppEffects(host);
|
|
250
|
-
} catch { entry.dispose(); return null; }
|
|
251
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/** #1629: static Chat fallback. It requires no preview origin, device consent, Worker or personal identity. */
|
|
2
|
-
import { useLayoutEffect } from "/assets/app-html.js";
|
|
3
|
-
import { appStore } from "/assets/app-store.js";
|
|
4
|
-
import { onPrefsChanged } from "/assets/app-prefs.js";
|
|
5
|
-
import { themesShown, themesStore } from "/assets/app-themes.js";
|
|
6
|
-
import { ownerCssLifecycle } from "/assets/owner-css.js";
|
|
7
|
-
import { effectPlaybackIdentity } from "/assets/effect-chat-runtime.js";
|
|
8
|
-
import { effectBootstrapReady } from "/assets/effect-frame.js";
|
|
9
|
-
import { motionBlocked, onMotionChange } from "/assets/fx-motion.js";
|
|
10
|
-
import { createChatPosters } from "/assets/effect-posters.js";
|
|
11
|
-
|
|
12
|
-
export function ChatEffectPosters({ name, lease, element }) {
|
|
13
|
-
useLayoutEffect(() => {
|
|
14
|
-
let live = true, api = null;
|
|
15
|
-
const releases = [], host = window;
|
|
16
|
-
const current = () => live && lease.current();
|
|
17
|
-
const cleanup = () => { if (!live) return; live = false; try { api?.dispose?.(); } catch { /* optional */ } for (const off of releases) { try { off?.(); } catch { /* release all */ } } };
|
|
18
|
-
lease.hold(cleanup);
|
|
19
|
-
try {
|
|
20
|
-
const motion = host.matchMedia?.("(prefers-reduced-motion: reduce)") ?? { matches: true };
|
|
21
|
-
const observe = () => {
|
|
22
|
-
// This is a surface fallback, not a replacement for an explicit Pause, queued effect or failed live read.
|
|
23
|
-
const playback = effectPlaybackIdentity(host) && typeof host.Worker === "function" && typeof host.OffscreenCanvas === "function" &&
|
|
24
|
-
effectBootstrapReady(host, host.location?.origin, host.document.body.dataset.effectBoot) && !motionBlocked(host);
|
|
25
|
-
return { shown: themesShown(), fallback: !playback, ownerCss: ownerCssLifecycle.get().state };
|
|
26
|
-
};
|
|
27
|
-
api = createChatPosters({ window: host, name, element: element.current, current, observe });
|
|
28
|
-
if (!api.ok) return cleanup;
|
|
29
|
-
const sync = () => { if (current()) api.sync(); };
|
|
30
|
-
let revision = appStore.get().themesRev;
|
|
31
|
-
releases.push(appStore.subscribe(s => {
|
|
32
|
-
if (!current()) return;
|
|
33
|
-
if (s.connection === "ended") { api.dispose(); return; }
|
|
34
|
-
if (s.themesRev !== revision) { revision = s.themesRev; api.changed(); } else sync();
|
|
35
|
-
}));
|
|
36
|
-
releases.push(ownerCssLifecycle.subscribe(sync)); releases.push(themesStore.subscribe(sync)); releases.push(onPrefsChanged(sync)); releases.push(onMotionChange(sync));
|
|
37
|
-
for (const target of [motion, host.navigator?.connection]) if (target?.addEventListener) { target.addEventListener("change", sync); releases.push(() => target.removeEventListener("change", sync)); }
|
|
38
|
-
sync(); return cleanup;
|
|
39
|
-
} catch { cleanup(); return cleanup; }
|
|
40
|
-
}, [name, lease]);
|
|
41
|
-
return null;
|
|
42
|
-
}
|
package/dist/ui/chat-effects.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
// #1629: Chat contributes a committed lease to the one app owner; no private pool or server polling.
|
|
2
|
-
import { html, useEffect, useLayoutEffect, useRef, useState } from "/assets/app-html.js";
|
|
3
|
-
import { register, t } from "/assets/app-i18n.js";
|
|
4
|
-
import { appStore, useStore } from "/assets/app-store.js";
|
|
5
|
-
import { ownerCssLifecycle } from "/assets/owner-css.js";
|
|
6
|
-
import { chatEffectState, chatEffectIdentity } from "/assets/effect-chat-runtime.js";
|
|
7
|
-
import { Dialog } from "/assets/ui-dialog.js";
|
|
8
|
-
import { navigate } from "/assets/app-nav.js";
|
|
9
|
-
import { toast } from "/assets/ui-toast.js";
|
|
10
|
-
import { setThemesShown, themesShown, themesStore } from "/assets/app-themes.js";
|
|
11
|
-
import { setFollowsReducedMotion } from "/assets/fx-motion.js";
|
|
12
|
-
import { getAppEffects, wakeEffects, effectsLoaded, onEffectsAwake } from "./effects-waker.js";
|
|
13
|
-
|
|
14
|
-
register("chatFx", {
|
|
15
|
-
en: { stock: "Off: the page layout could not be verified ({0}). Reload and report this code if it persists.", transport: "Off: the isolated effect frame could not start. Reload to try again.", enableHere: "Turn effects on here", playMotion: "Play effects anyway", leaveSafe: "Leave safe mode", viewerShow: "Show themes, effects and widgets here", clock: "Off: the page timing clock is unavailable. Reload to try again.", gatesUnknown: "Off: the playback conditions could not be verified.", resource: "Off: this effect could not be loaded or verified. Reload to try again.", frontQueue: "Waiting for a foreground slot.", consent: "This page has older playback information. Reload to use the isolated effect player.", previewMissing: "Off: the isolated effect frame is unavailable. Reload to try again.", unsupported: "Off: this browser lacks required Canvas Worker or layout support.", calibration: "Starting the effect.", baseline: "This page has older playback information. Reload to try again.", safetyUnknown: "Stopped: this device's safety history could not be verified. Reload to check it.", rawReason: "Playback blocked: {0}", missingRow: "Playback state is unavailable (runtime_unavailable).", region: "Off: this effect does not declare the chat region.", blocked: "Placed effects are blocked for this viewer:", deviceSetting: "Open device preferences", webSetting: "Open Web settings", reloadHint: "Reload page",
|
|
16
|
-
title: "Effects", loading: "Checking effects…", empty: "No effects in this chat.", failed: "Effects stopped because their resources could not be verified. Reload the page to try again.", reload: "Reload page", pause: "Pause", resume: "Resume", remove: "Remove from chat", removeFailed: "Could not remove this effect. Reload the page to check its state.", css: "Agent foreground effects are paused while your custom CSS is on or cannot be verified.", setting: "Open Settings → Look", running: "Running", starting: "Starting", off: "Stopped", resumeFailed: "This effect cannot resume: the page or its safety history is not ready. Reload the page or choose another effect.", queued: "Waiting for a slot", unknown: "Playback is off or unavailable here.", budget: "Paused to protect page responsiveness. Resume keeps the three-pauses safety limit.", pauseHelp: "Resume keeps this device’s automatic-pause history and three-pause safety limit.", paused: "Paused", low: "Reduced quality",
|
|
17
|
-
typing: "Waiting while you type — it plays when you leave the message box.", covered: "Waiting while a menu or panel covers the chat.",
|
|
18
|
-
dialogOpen: "Paused while this dialog is open.", wasRunning: "Was running; paused while this dialog is open.", modal: "Waiting while a dialog is open.",
|
|
19
|
-
off3: "Turned off on this device after three automatic pauses. Resume cannot restart it here.", interrupted: "Stopped: the page closed while it was playing. Resume to play it again.",
|
|
20
|
-
cssOff: "Off while your custom CSS is on.", reducedMotion: "Off: you chose to follow the system's reduced motion setting.", saveData: "This page has older playback information. Reload to try again.",
|
|
21
|
-
hiddenTab: "Waiting until this tab is visible.", offscreen: "Waiting until the chat is on screen.",
|
|
22
|
-
safeMode: "Off in safe mode.", publicLink: "Off on a public link.", disabled: "Effects are switched off." },
|
|
23
|
-
"zh-TW": { stock: "已關閉:無法驗證頁面版面({0})。請重新載入;若持續發生,請回報此代碼。", transport: "已關閉:無法啟動隔離效果框架。請重新載入再試。", enableHere: "在這裡開啟效果", playMotion: "仍然播放效果", leaveSafe: "離開安全模式", viewerShow: "在這裡顯示主題、效果與小工具", clock: "已關閉:頁面計時無法使用。請重新載入再試。", gatesUnknown: "已關閉:無法確認播放條件。", resource: "已關閉:無法載入或驗證此效果。請重新載入再試。", frontQueue: "等待前景空位。", consent: "這個頁面的播放資訊已過期。請重新載入以使用隔離效果播放器。", previewMissing: "已關閉:隔離效果框架無法使用。請重新載入再試。", unsupported: "已關閉:這個瀏覽器缺少 Canvas Worker 或版面驗證支援。", calibration: "正在啟動效果。", baseline: "這個頁面的播放資訊已過期,請重新載入再試。", safetyUnknown: "已停止:無法確認這台裝置的安全紀錄。請重新載入確認。", rawReason: "播放受阻:{0}", missingRow: "無法取得播放狀態(runtime_unavailable)。", region: "已關閉:此效果未宣告聊天區域。", blocked: "放置的效果目前無法在這個畫面播放:", deviceSetting: "開啟裝置偏好設定", webSetting: "開啟網頁設定", reloadHint: "重新載入頁面",
|
|
24
|
-
title: "效果", loading: "正在確認效果…", empty: "這個聊天沒有放置效果。", failed: "無法確認效果資源,已停止播放。重新載入頁面後再試。", reload: "重新載入頁面", pause: "暫停", resume: "恢復", remove: "從聊天移除", removeFailed: "無法移除效果。請重新載入頁面確認狀態。", css: "自訂 CSS 開啟或無法確認時,代理的前景效果會暫停。", setting: "開啟設定 → 外觀", running: "播放中", starting: "啟動中", off: "已停止", resumeFailed: "頁面或安全紀錄尚未就緒,無法恢復此效果。請重新載入頁面,或選擇其他效果。", queued: "等待空位", unknown: "這裡已關閉播放,或無法播放效果。", budget: "為維持頁面順暢,已暫停效果。恢復仍保留三次暫停的安全上限。", pauseHelp: "恢復仍保留這台裝置的自動暫停紀錄與三次暫停安全上限。", paused: "已暫停", low: "降低畫質",
|
|
25
|
-
typing: "輸入時暫停,離開訊息輸入框就會播放。", covered: "選單或面板蓋住聊天時暫停。",
|
|
26
|
-
dialogOpen: "開著這個對話框時暫停。", wasRunning: "原本在播放;開著這個對話框時暫停。", modal: "有對話框開著時暫停。",
|
|
27
|
-
off3: "已自動暫停三次,這台裝置已關閉此效果,無法在這裡恢復。", interrupted: "播放時頁面被關閉而停止。按「恢復」再播放一次。",
|
|
28
|
-
cssOff: "自訂 CSS 開啟時關閉。", reducedMotion: "已關閉:效果跟隨這台裝置的「減少動態效果」設定。", saveData: "這個頁面的播放資訊已過期,請重新載入再試。",
|
|
29
|
-
hiddenTab: "等這個分頁顯示時再播放。", offscreen: "等聊天顯示在畫面上時再播放。",
|
|
30
|
-
safeMode: "安全模式下關閉。", publicLink: "公開連結上關閉。", disabled: "效果已關閉。" },
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
/** Read/admin dashboard sessions keep management controls; public/guest Chat playback has no owner identity. */
|
|
34
|
-
export function chatEffectsMenuAvailable() { return chatEffectIdentity(window) !== null; }
|
|
35
|
-
|
|
36
|
-
// #2055: what a row's state means, in words — never only "Stopped" when the runtime knows why.
|
|
37
|
-
const RECENT_MS = 5000;
|
|
38
|
-
const REASON_KEY = { __proto__: null, transport_unavailable: "chatFx.transport", owner_css: "chatFx.cssOff", reduced_motion: "chatFx.reducedMotion", save_data: "chatFx.saveData", preview_unavailable: "chatFx.previewMissing", preview_not_consented: "chatFx.consent", unsupported_host: "chatFx.unsupported", registry_unsupported: "chatFx.unsupported",
|
|
39
|
-
baseline_unsupported: "chatFx.baseline", baseline_unavailable: "chatFx.baseline", baseline_timeout: "chatFx.baseline", calibrating: "chatFx.calibration", safety_unknown: "chatFx.safetyUnknown", region_unavailable: "chatFx.region",
|
|
40
|
-
hidden: "chatFx.hiddenTab", offscreen: "chatFx.offscreen", safe_mode: "chatFx.safeMode", public_link: "chatFx.publicLink", disabled: "chatFx.disabled",
|
|
41
|
-
clock_unavailable: "chatFx.clock", gates_unknown: "chatFx.gatesUnknown", runtime_unavailable: "chatFx.missingRow", resource_unavailable: "chatFx.resource", resource_timeout: "chatFx.resource", front_limit: "chatFx.frontQueue",
|
|
42
|
-
safety_off: "chatFx.off3", interrupted: "chatFx.interrupted" };
|
|
43
|
-
/** `ownOpen`: this Effects dialog is open; `wasRunning`: the effect was running when it opened (shown as past, never as current). */
|
|
44
|
-
export function effectRowText(row, { ownOpen = false, wasRunning = false, doc = typeof document === "undefined" ? null : document } = {}) {
|
|
45
|
-
if (!row) return t("chatFx.missingRow");
|
|
46
|
-
if (typeof row.reason === "string" && row.reason !== "stock_overlay" && /^(stock_|trust_|geometry_)/.test(row.reason)) return t("chatFx.stock", row.reason.replace(/[\u0000-\u001f\u007f]/g, "").slice(0, 80));
|
|
47
|
-
// The sticky history first (it is what Resume answers), then a pause, then what is playing or queued.
|
|
48
|
-
if (row.reason === "safety_off" || row.reason === "interrupted") return t(REASON_KEY[row.reason]);
|
|
49
|
-
if (row.reason === "paused" || row.reason === "host_budget") return t("chatFx.paused");
|
|
50
|
-
if (REASON_KEY[row.reason]) return t(REASON_KEY[row.reason]);
|
|
51
|
-
if (row.reason != null && !["stock_overlay", "modal", "frame_limit"].includes(row.reason))
|
|
52
|
-
return t("chatFx.rawReason", typeof row.reason === "string" ? row.reason.replace(/[\u0000-\u001f\u007f]/g, "").slice(0, 80) : "invalid_reason_type");
|
|
53
|
-
if (row.phase === "running") return t("chatFx.running");
|
|
54
|
-
if (row.phase) return t("chatFx.starting");
|
|
55
|
-
if (row.verdict === "queued") return t("chatFx.queued");
|
|
56
|
-
if (row.reason === "stock_overlay" || row.reason === "modal") {
|
|
57
|
-
if (ownOpen) return t(wasRunning ? "chatFx.wasRunning" : "chatFx.dialogOpen");
|
|
58
|
-
if (row.reason === "modal") return t("chatFx.modal");
|
|
59
|
-
return t("chatFx.covered");
|
|
60
|
-
}
|
|
61
|
-
return t("chatFx.rawReason", typeof row.reason === "string" ? row.reason.replace(/[\u0000-\u001f\u007f]/g, "").slice(0, 80) : "invalid_reason_type");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Fixed local actions: no server/Worker-provided destination or raw reason in a URL. */
|
|
65
|
-
export function effectReasonAction(reason) {
|
|
66
|
-
if (reason === "preview_not_consented" || reason === "preview_unavailable") return { reload: true, label: "chatFx.reloadHint" };
|
|
67
|
-
if (["disabled", "owner_css"].includes(reason)) return { href: "/settings/look", label: "chatFx.setting" };
|
|
68
|
-
if (["transport_unavailable", "baseline_unsupported", "baseline_unavailable", "baseline_timeout", "runtime_unavailable", "resource_unavailable", "resource_timeout", "clock_unavailable", "safety_unknown"].includes(reason)) return { reload: true, label: "chatFx.reloadHint" };
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
const localViewer = () => document.body.dataset.publicLink === "1" || document.body.dataset.tier === "guest";
|
|
72
|
-
function ReasonAction({ reason, onClose = () => {} }) {
|
|
73
|
-
if (reason === "safe_mode") return html`<button type="button" class="btn" onClick=${() => { onClose(); const url = new URL(location.href); url.searchParams.delete("safe"); location.assign(url.href); }}>${t("chatFx.leaveSafe")}</button>`;
|
|
74
|
-
if (reason === "reduced_motion") return html`<button type="button" class="btn" onClick=${() => { onClose(); setFollowsReducedMotion(false); }}>${t("chatFx.playMotion")}</button>`;
|
|
75
|
-
if (reason === "disabled" && localViewer()) return html`<button type="button" class="btn" onClick=${() => { onClose(); setThemesShown(true); }}>${t("chatFx.enableHere")}</button>`;
|
|
76
|
-
const action = document.body.dataset.tier === "guest" && reason === "owner_css" ? { reload: true, label: "chatFx.reloadHint" } : effectReasonAction(reason);
|
|
77
|
-
return action ? html`<button type="button" class="btn" onClick=${() => { onClose(); if (action.reload) location.reload(); else navigate(action.href); }}>${t(action.label)}</button>` : null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const NO_PLAYBACK = () => {};
|
|
81
|
-
export function ChatEffects({ name, lease, element, store, open, onClose, onPlayback = NO_PLAYBACK, active = true }) {
|
|
82
|
-
const cssLife = useStore(ownerCssLifecycle);
|
|
83
|
-
// #2193: `active` — this chat has placements (its status row says so). While the runtime sleeps, a chat with none
|
|
84
|
-
// attaches and reads nothing (the dialog says "No effects in this chat"); one with some wakes it and attaches once it
|
|
85
|
-
// runs. Once it runs (woken by anything — a Try card needs its chat attached), every chat attaches as before.
|
|
86
|
-
const [awake, setAwake] = useState(() => getAppEffects() !== null || effectsLoaded());
|
|
87
|
-
useEffect(() => (awake ? undefined : onEffectsAwake(() => setAwake(true))), [awake]);
|
|
88
|
-
useStore(themesStore); // Viewer-local off/on is visible immediately, independent of runtime callbacks.
|
|
89
|
-
// Which effects were running just before this dialog opened ("was running" is said in the past, never shown as
|
|
90
|
-
// current). The ⋯ menu that opens it is a barrier too, so "just before" is within RECENT_MS of the observed stop.
|
|
91
|
-
// Tracked where updates arrive (an unchanged snapshot is not republished while an effect keeps running).
|
|
92
|
-
const before = useRef(null), wasOpen = useRef(false), playing = useRef(new Map());
|
|
93
|
-
const runtime = useRef(null), [state, setState] = useState(null), [canWrite, setCanWrite] = useState(false), [busy, setBusy] = useState(false);
|
|
94
|
-
useLayoutEffect(() => {
|
|
95
|
-
let live = true, api = null;
|
|
96
|
-
const releases = [];
|
|
97
|
-
// Effects are optional: a failed setup must release its partial ownership without breaking Chat.
|
|
98
|
-
const cleanup = () => {
|
|
99
|
-
if (!live) return;
|
|
100
|
-
live = false;
|
|
101
|
-
try { api?.dispose?.(); } catch { /* continue releasing partial setup */ }
|
|
102
|
-
for (const off of releases) { try { if (typeof off === "function") off(); } catch { /* release the rest */ } }
|
|
103
|
-
if (runtime.current === api) runtime.current = null;
|
|
104
|
-
};
|
|
105
|
-
lease.hold(cleanup);
|
|
106
|
-
try {
|
|
107
|
-
setBusy(false); onClose(); setCanWrite(false); setState(null);
|
|
108
|
-
if (!active && !awake) { setState({ error: null, rows: [], effects: [], loading: false }); return cleanup; }
|
|
109
|
-
if (!awake) { void wakeEffects(); return cleanup; } // "Checking effects…" until it runs
|
|
110
|
-
const host = window, owner = getAppEffects(host);
|
|
111
|
-
const current = () => live && lease.current();
|
|
112
|
-
if (!owner) { setState({ error: null, rows: [], effects: [], unavailable: true, reason: typeof host.OffscreenCanvas !== "function" || typeof host.Worker !== "function" ? "unsupported_host" : "runtime_unavailable" }); return cleanup; }
|
|
113
|
-
releases.push(owner.onEnd(() => { if (current()) setState({ error: "resource_unavailable", rows: [], effects: [], unavailable: true }); }));
|
|
114
|
-
playing.current = new Map(); // evidence belongs to this name and lease only
|
|
115
|
-
const track = rows => {
|
|
116
|
-
const now = performance.now(), seen = new Set();
|
|
117
|
-
for (const r of Array.isArray(rows) ? rows : []) {
|
|
118
|
-
seen.add(r.id);
|
|
119
|
-
if (r.phase === "running") playing.current.set(r.id, null);
|
|
120
|
-
else if (playing.current.get(r.id) === null) playing.current.set(r.id, now);
|
|
121
|
-
}
|
|
122
|
-
for (const [id, at] of playing.current) if (!seen.has(id) && at === null) playing.current.set(id, now);
|
|
123
|
-
};
|
|
124
|
-
const changed = value => {
|
|
125
|
-
if (!current()) return;
|
|
126
|
-
track(value?.rows);
|
|
127
|
-
const g = owner.gates();
|
|
128
|
-
setState({ ...value, unavailable: !g.enabled || !g.show || !g.transportReady || g.safe || g.reducedMotion });
|
|
129
|
-
};
|
|
130
|
-
api = owner.attachChat({ name, element: element.current, current,
|
|
131
|
-
observe: () => ({ state: chatEffectState(appStore.get(), name) }), onChange: changed });
|
|
132
|
-
runtime.current = api;
|
|
133
|
-
if (!api?.ok) { setState({ error: null, rows: [], effects: [], unavailable: true, reason: "runtime_unavailable" }); return cleanup; }
|
|
134
|
-
if (chatEffectIdentity(host)) host.AgendAuth?.canWrite?.().then(value => { if (current()) setCanWrite(value === true); }).catch(() => {});
|
|
135
|
-
api.sync();
|
|
136
|
-
return cleanup;
|
|
137
|
-
} catch {
|
|
138
|
-
cleanup();
|
|
139
|
-
if (lease.current()) setState({ error: "runtime_unavailable", rows: [], effects: [] });
|
|
140
|
-
return cleanup;
|
|
141
|
-
}
|
|
142
|
-
}, [name, lease, active, awake]);
|
|
143
|
-
const rows = state?.rows ?? [], effects = state?.effects ?? [];
|
|
144
|
-
if (open && !wasOpen.current) {
|
|
145
|
-
const now = performance.now();
|
|
146
|
-
before.current = new Map([...playing.current].map(([id, stoppedAt]) => [id, stoppedAt === null || now - stoppedAt < RECENT_MS]));
|
|
147
|
-
}
|
|
148
|
-
if (!open) before.current = null;
|
|
149
|
-
wasOpen.current = open;
|
|
150
|
-
const css = cssLife.state !== "off" && effects.some(p => p.by !== "human" && p.manifest.layer === "front");
|
|
151
|
-
const remove = async id => { if (busy) return; setBusy(true); const api = runtime.current; const ok = await api?.remove?.(id); if (!lease.current() || runtime.current !== api) return; setBusy(false); if (!ok) toast(t("chatFx.removeFailed"), false); };
|
|
152
|
-
const playingNow = !state?.unavailable && !state?.error && rows.some(row => row.phase === "running" && row.reason == null);
|
|
153
|
-
useEffect(() => { onPlayback({ name, playing: playingNow }); return () => onPlayback({ name, playing: false }); }, [name, playingNow, onPlayback]);
|
|
154
|
-
const blocked = effects.flatMap(p => { const row = rows.find(r => r.id === p.id); return row?.phase === "running" && row.reason == null ? [] : [{ p, row }]; });
|
|
155
|
-
return html`${!open && localViewer() && effects.length ? html`<div class="chat-fx-notice"><label><input type="checkbox" checked=${themesShown()} onChange=${e => setThemesShown(e.currentTarget.checked)} /> ${t("chatFx.viewerShow")}</label></div>` : null}${!open && state?.error && !effects.length ? html`<div class="chat-fx-notice" role="status">${effectRowText({ reason: state.error })} <${ReasonAction} reason=${state.error} /></div>` : null}${!open && state?.reason ? html`<div class="chat-fx-notice" role="status">${effectRowText({ reason: state.reason })} <${ReasonAction} reason=${state.reason} /></div>` : null}${!open && blocked.length ? html`<div class="chat-fx-notice" role="status"><strong>${t("chatFx.blocked")}</strong>
|
|
156
|
-
${blocked.map(({ p, row }) => html`<span key=${p.id}>${p.manifest.title}: ${effectRowText(row)} ${["paused", "host_budget"].includes(row?.reason) ? html`<small>${t(row.reason === "host_budget" ? "chatFx.budget" : "chatFx.pauseHelp")}</small>` : null} <${ReasonAction} reason=${row?.reason} /></span>`)}</div>` : null}${open ? html`<${Dialog} title=${t("chatFx.title")} onClose=${onClose} busy=${busy}>
|
|
157
|
-
${state?.error ? html`<p>${t("chatFx.failed")}</p><button type="button" class="btn" onClick=${() => location.reload()}>${t("chatFx.reload")}</button>` : null}
|
|
158
|
-
${css ? html`<p>${t("chatFx.css")}</p><button type="button" class="btn" onClick=${() => { onClose(); navigate("/settings/look"); }}>${t("chatFx.setting")}</button>` : null}
|
|
159
|
-
${!effects.length && !state?.error ? html`<p>${t(state?.unavailable ? "chatFx.unknown" : state?.loading || !state ? "chatFx.loading" : "chatFx.empty")}</p>` : null}
|
|
160
|
-
${effects.map(p => { const row = rows.find(r => r.id === p.id); return html`<section key=${p.id}><h3>${p.manifest.title}</h3><p>${effectRowText(row, { ownOpen: open, wasRunning: before.current?.get(p.id) === true })}${row?.quality === "low" ? ` · ${t("chatFx.low")}` : ""}</p>
|
|
161
|
-
<${ReasonAction} reason=${row?.reason} onClose=${onClose} />
|
|
162
|
-
${["paused", "host_budget"].includes(row?.reason) ? html`<p>${t(row.reason === "host_budget" ? "chatFx.budget" : "chatFx.pauseHelp")}</p>` : null}
|
|
163
|
-
<button type="button" class="btn" disabled=${busy} onClick=${() => runtime.current?.pause?.(p.id)}>${t("chatFx.pause")}</button>
|
|
164
|
-
<button type="button" class="btn" disabled=${busy} onClick=${() => { if (!runtime.current?.resume?.(p.id)) toast(t(rows.find(r => r.id === p.id)?.reason === "safety_off" ? "chatFx.off3" : "chatFx.resumeFailed"), false); }}>${t("chatFx.resume")}</button>
|
|
165
|
-
${canWrite ? html`<button type="button" class="btn" disabled=${busy} onClick=${() => remove(p.id)}>${t("chatFx.remove")}</button>` : null}</section>`; })}
|
|
166
|
-
</${Dialog}>` : null}`;
|
|
167
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/** #1629: explicit-click control lane. Responses never grant authority; Start reauthorizes on the server. */
|
|
2
|
-
import { effectTrialMessage } from "./effect-trial-offer.js";
|
|
3
|
-
import { checkEffectTrialStart } from "/assets/effect-runtime-loader.js";
|
|
4
|
-
import { chatEffectIdentity } from "/assets/effect-chat-runtime.js";
|
|
5
|
-
const owners = new WeakSet(), safe = fn => { try { return fn(); } catch { return null; } };
|
|
6
|
-
const LIMIT = 128 * 1024;
|
|
7
|
-
export function createEffectTrialController({ window: host, current, allowed, onStart, onChange = () => {} }) {
|
|
8
|
-
let dead = false, active = null, physical = null, previous = null, broken = false, clockBusy = false, endedReason = null, endedOffer = null;
|
|
9
|
-
const cleanup = [], releases = [], identity = safe(() => chatEffectIdentity(host));
|
|
10
|
-
const tell = () => { if (!dead) safe(onChange); };
|
|
11
|
-
function clock() {
|
|
12
|
-
if (broken || clockBusy) { broken = true; return null; }
|
|
13
|
-
clockBusy = true; const t = safe(() => host.performance.now()); clockBusy = false;
|
|
14
|
-
if (broken || typeof t !== "number" || !Number.isFinite(t) || t < 0 || t > Number.MAX_SAFE_INTEGER || previous !== null && t < previous) { broken = true; return null; }
|
|
15
|
-
return previous = t;
|
|
16
|
-
}
|
|
17
|
-
function eligible(op) {
|
|
18
|
-
if (dead || broken || !op || active !== op || op.dead || op.checking || host.AgendAuth?.sessionEnded?.() !== false) return false;
|
|
19
|
-
op.checking = true;
|
|
20
|
-
try {
|
|
21
|
-
const t = clock();
|
|
22
|
-
if (t === null || t < op.began || t >= op.until || safe(() => current(op.instance) === true && allowed() === true) !== true) return false;
|
|
23
|
-
const after = clock();
|
|
24
|
-
return !dead && !op.dead && active === op && after !== null && after >= op.began && after < op.until;
|
|
25
|
-
} finally { op.checking = false; }
|
|
26
|
-
}
|
|
27
|
-
function end(op, reason = "stopped") {
|
|
28
|
-
if (!op || op.dead) return false;
|
|
29
|
-
op.dead = true; if (active === op) active = null;
|
|
30
|
-
endedReason = typeof reason === "string" && /^[a-z][a-z0-9_]{0,79}$/.test(reason) ? reason : "trial_failed";
|
|
31
|
-
endedOffer = op.offer.offer;
|
|
32
|
-
safe(() => op.resolve?.(false));
|
|
33
|
-
safe(() => host.clearTimeout(op.timer)); safe(() => op.controller.abort());
|
|
34
|
-
if (op.reply && !op.stopQueued) { op.stopQueued = true; cleanup.push(op); }
|
|
35
|
-
// Physical paint is removed before callbacks, cleanup I/O or another explicit click.
|
|
36
|
-
safe(() => op.dispose?.()); op.dispose = null;
|
|
37
|
-
if (!["stopped", "replaced"].includes(endedReason)) safe(() => host.console?.warn("[AgEnD effects] Try stopped:", endedReason));
|
|
38
|
-
tell(); drain(); return true;
|
|
39
|
-
}
|
|
40
|
-
function arm(op) {
|
|
41
|
-
safe(() => host.clearTimeout(op.timer));
|
|
42
|
-
if (!eligible(op)) { end(op, "trial_ended"); return; }
|
|
43
|
-
const t = clock(); if (t === null || t >= op.until) { end(op, "trial_expired"); return; }
|
|
44
|
-
op.timer = host.setTimeout(() => { if (!op.dead) arm(op); }, Math.max(1, Math.ceil(op.until - t)));
|
|
45
|
-
}
|
|
46
|
-
async function read(response) {
|
|
47
|
-
let reader = null;
|
|
48
|
-
try {
|
|
49
|
-
if (!response || response.redirected || response.status !== 200 || !/^application\/json(?:\s*;|$)/i.test(response.headers.get("content-type") || "")) return null;
|
|
50
|
-
const length = response.headers.get("content-length"); if (length !== null && (!/^\d+$/.test(length) || Number(length) > LIMIT)) return null;
|
|
51
|
-
reader = response.body?.getReader(); if (!reader) return null;
|
|
52
|
-
const chunks = []; let size = 0;
|
|
53
|
-
for (;;) { const r = await reader.read(); if (r.done) break; if (!(r.value instanceof Uint8Array) || (size += r.value.byteLength) > LIMIT) return null; chunks.push(r.value); }
|
|
54
|
-
const bytes = new Uint8Array(size); let offset = 0; for (const c of chunks) { bytes.set(c, offset); offset += c.byteLength; }
|
|
55
|
-
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
56
|
-
} catch { return null; }
|
|
57
|
-
finally { try { if (reader) await reader.cancel(); else await response?.body?.cancel(); } catch { /* retained until cancellation settles */ } }
|
|
58
|
-
}
|
|
59
|
-
function drain() {
|
|
60
|
-
if (physical || !cleanup.length) return;
|
|
61
|
-
const op = cleanup.shift(), token = {}; physical = token; const controller = new host.AbortController();
|
|
62
|
-
const timer = host.setTimeout(() => controller.abort(), 10000);
|
|
63
|
-
// Stop remains permitted after CSS/gate/session changes. It cannot mount or mutate appearance.
|
|
64
|
-
Promise.resolve().then(async () => {
|
|
65
|
-
const response = await host.fetch(`/ui/effect-trials/${op.reply.trial}/stop?ownerEpoch=${identity.epoch}`, {
|
|
66
|
-
method: "POST", credentials: "same-origin", cache: "no-store", redirect: "error", headers: { "Content-Type": "application/json" }, body: "{}", signal: controller.signal,
|
|
67
|
-
});
|
|
68
|
-
try { await response.body?.cancel(); } catch { /* no response fields are consumed */ }
|
|
69
|
-
}).catch(() => {}).finally(() => { safe(() => host.clearTimeout(timer)); if (physical === token) physical = null; tell(); drain(); });
|
|
70
|
-
}
|
|
71
|
-
function dispose() {
|
|
72
|
-
if (dead) return; dead = true; end(active); for (const off of releases.splice(0)) safe(off); tell();
|
|
73
|
-
}
|
|
74
|
-
const api = { ok: false, start: async () => false, stop: () => end(active), sync() { const op = active; if (op && !eligible(op)) end(op, "trial_ended"); },
|
|
75
|
-
snapshot: () => Object.freeze({ busy: !!physical || cleanup.length > 0, phase: active ? active.reply ? "running" : "starting" : "idle", reason: active ? null : endedReason, offer: active ? active.offer.offer : endedOffer }), dispose };
|
|
76
|
-
if (!identity || owners.has(host) || typeof current !== "function" || typeof allowed !== "function" || typeof onStart !== "function"
|
|
77
|
-
|| typeof host.AgendAuth?.trialSession !== "function" || typeof host.AgendAuth?.onSessionEnd !== "function") return Object.freeze(api);
|
|
78
|
-
owners.add(host);
|
|
79
|
-
try {
|
|
80
|
-
const off = host.AgendAuth.onSessionEnd(dispose);
|
|
81
|
-
if (dead) { safe(off); return Object.freeze(api); }
|
|
82
|
-
releases.push(off);
|
|
83
|
-
for (const [target, type, fn] of [[host, "blur", () => end(active, "trial_window_blur")], [host, "pagehide", dispose], [host.document, "visibilitychange", () => { if (host.document.visibilityState !== "visible") end(active, "hidden"); }]]) {
|
|
84
|
-
target.addEventListener(type, fn); releases.push(() => target.removeEventListener(type, fn));
|
|
85
|
-
}
|
|
86
|
-
} catch { dispose(); return Object.freeze(api); }
|
|
87
|
-
if (dead) return Object.freeze(api);
|
|
88
|
-
api.ok = true;
|
|
89
|
-
api.start = async message => {
|
|
90
|
-
if (dead || active || physical || cleanup.length) return false;
|
|
91
|
-
const offer = safe(() => effectTrialMessage(message)), instance = safe(() => message.instance), began = clock();
|
|
92
|
-
if (!offer || began === null || began + 10000 > Number.MAX_SAFE_INTEGER || safe(() => host.Date.now() < offer.expiresAt) !== true) return false;
|
|
93
|
-
const op = { instance, offer, began, until: began + 10000, controller: new host.AbortController(), timer: null, reply: null, dead: false, stopQueued: false, dispose: null };
|
|
94
|
-
endedReason = null; endedOffer = null; active = op; const token = {}; physical = token;
|
|
95
|
-
const cancelled = new Promise(resolve => { op.resolve = resolve; });
|
|
96
|
-
const work = Promise.resolve().then(async () => {
|
|
97
|
-
if (!eligible(op)) return false;
|
|
98
|
-
arm(op); const session = await host.AgendAuth.trialSession();
|
|
99
|
-
if (!eligible(op) || !session || session.localAdmin !== true || session.epoch !== identity.epoch) return false;
|
|
100
|
-
const response = await host.fetch(`/ui/effect-trials/start?ownerEpoch=${identity.epoch}`, {
|
|
101
|
-
method: "POST", credentials: "same-origin", cache: "no-store", redirect: "error", headers: { "Content-Type": "application/json" },
|
|
102
|
-
body: JSON.stringify({ offer: offer.offer, instance }), signal: op.controller.signal,
|
|
103
|
-
});
|
|
104
|
-
const reply = checkEffectTrialStart(await read(response), offer.offer, offer.id);
|
|
105
|
-
if (!reply) return false;
|
|
106
|
-
op.reply = reply;
|
|
107
|
-
if (op.dead && !op.stopQueued) { op.stopQueued = true; cleanup.push(op); }
|
|
108
|
-
if (reply.offer.title !== offer.title || reply.offer.expiresAt !== offer.expiresAt) return false;
|
|
109
|
-
if (!eligible(op)) { if (!op.stopQueued) { op.stopQueued = true; cleanup.push(op); } return false; }
|
|
110
|
-
op.until = began + reply.remainingMs;
|
|
111
|
-
if (op.until > Number.MAX_SAFE_INTEGER || !eligible(op)) return false;
|
|
112
|
-
arm(op);
|
|
113
|
-
const handle = Object.freeze({ reply, startedAt: began, instance, current: () => eligible(op), stop: (reason = "stopped") => end(op, reason), });
|
|
114
|
-
const disposer = onStart(handle);
|
|
115
|
-
if (typeof disposer !== "function") return false;
|
|
116
|
-
if (!eligible(op)) { safe(disposer); return false; }
|
|
117
|
-
op.dispose = disposer; tell(); return eligible(op);
|
|
118
|
-
}).catch(() => false).then(ok => { if (!ok) end(op, "trial_start_failed"); return ok; }).finally(() => { if (physical === token) physical = null; tell(); drain(); });
|
|
119
|
-
// The logical caller may stop immediately, while the physical request/cancel still owns the lane.
|
|
120
|
-
tell();
|
|
121
|
-
return Promise.race([work, cancelled]);
|
|
122
|
-
};
|
|
123
|
-
return Object.freeze(api);
|
|
124
|
-
}
|