@intentic/sandbox-contract 1.416.0 → 1.417.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/contracts/runner.contract.d.ts +246 -246
- package/dist/contracts/system.contract.d.ts +18 -18
- package/dist/models/plan-pools.d.ts +2 -13
- package/dist/models/plan-pools.d.ts.map +1 -1
- package/dist/models/plan-pools.js +7 -41
- package/dist/models/plan-pools.js.map +1 -1
- package/dist/models/verdict/refusal-verdict.d.ts +2 -0
- package/dist/models/verdict/refusal-verdict.d.ts.map +1 -1
- package/dist/models/verdict/refusal-verdict.js +24 -2
- package/dist/models/verdict/refusal-verdict.js.map +1 -1
- package/dist/models/verdict/window-period.d.ts +13 -0
- package/dist/models/verdict/window-period.d.ts.map +1 -0
- package/dist/models/verdict/window-period.js +37 -0
- package/dist/models/verdict/window-period.js.map +1 -0
- package/dist/text/pages.d.ts +5 -0
- package/dist/text/pages.d.ts.map +1 -1
- package/dist/text/pages.js +15 -1
- package/dist/text/pages.js.map +1 -1
- package/package.json +5 -5
- package/src/models/plan-pools.test.ts +46 -3
- package/src/models/plan-pools.ts +11 -64
- package/src/models/verdict/refusal-verdict.ts +48 -3
- package/src/models/verdict/window-period.ts +57 -0
- package/src/text/pages.ts +27 -3
package/src/models/plan-pools.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { AccountState, AccountUsage, ProviderRefusal, UsageWindow } from "../schemas/providers/plan-limits.js";
|
|
2
2
|
import { humanizeModelId } from "./model-label.js";
|
|
3
3
|
import { bindingWindow, gatesModel, gatingWindows, type ModelRef, pinnedFull, provenFull, SPENT_UTILIZATION } from "./verdict/pool-gates.js";
|
|
4
|
-
import { type RefusalsOnFile, type ServiceFacts, standingOver } from "./verdict/refusal-verdict.js";
|
|
4
|
+
import { type RefusalsOnFile, refusedInstant, type ServiceFacts, standingOver } from "./verdict/refusal-verdict.js";
|
|
5
|
+
import { windowPeriod } from "./verdict/window-period.js";
|
|
5
6
|
|
|
6
7
|
// Which pool gates a model (verdict/pool-gates.ts) and how each refusal on file stands over each account
|
|
7
8
|
// (verdict/refusal-verdict.ts), kept beside this module and served from it, so every caller reads the one rule through
|
|
@@ -20,65 +21,8 @@ export {
|
|
|
20
21
|
uncoveredModels,
|
|
21
22
|
wordsOf,
|
|
22
23
|
} from "./verdict/pool-gates.js";
|
|
23
|
-
export { refusalVerdict, refusedPoolReset, type RefusalsOnFile, type ServiceFacts, standingOver } from "./verdict/refusal-verdict.js";
|
|
24
|
-
|
|
25
|
-
// How long a pool's window runs, read off the provider's own key and whatever name it published. One implementation,
|
|
26
|
-
// because two things need it and must agree: a narrow column names the window by `short`, and a reading with no
|
|
27
|
-
// published reset instant may only be trusted for `seconds` past the moment it was taken.
|
|
28
|
-
|
|
29
|
-
export interface WindowPeriod {
|
|
30
|
-
readonly seconds: number;
|
|
31
|
-
// The token a narrow column names this window by, e.g. "5h", "wk".
|
|
32
|
-
readonly short: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const HOUR_SECONDS = 3_600;
|
|
36
|
-
const DAY_SECONDS = 86_400;
|
|
37
|
-
|
|
38
|
-
/** Kind and label as space-padded lowercase words, underscores split, so `\b` matches across both spellings. */
|
|
39
|
-
export const periodWords = (pool: { readonly kind: string; readonly label?: string | undefined }): string =>
|
|
40
|
-
` ${`${pool.kind} ${pool.label ?? ""}`
|
|
41
|
-
.toLowerCase()
|
|
42
|
-
.replaceAll(/[^a-z0-9]+/gu, " ")
|
|
43
|
-
.trim()} `;
|
|
44
|
-
|
|
45
|
-
// A count the words spell out, e.g. the 3 in "3 days".
|
|
46
|
-
const counted = (words: string, pattern: RegExp): number | undefined => {
|
|
47
|
-
const found = pattern.exec(words)?.[1];
|
|
48
|
-
return found === undefined ? undefined : Number(found);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// Day-scale and longer, where the named periods outrank a bare count: "7 days" is the week every plan sells, not a
|
|
52
|
-
// seven-day span of its own.
|
|
53
|
-
const dayPeriod = (words: string, days: number | undefined): WindowPeriod | undefined => {
|
|
54
|
-
if (days === 7 || /\bseven days?\b|\bweek(ly|s)?\b/u.test(words)) {
|
|
55
|
-
return { seconds: 7 * DAY_SECONDS, short: "wk" };
|
|
56
|
-
}
|
|
57
|
-
if (/\bmonth(ly|s)?\b/u.test(words)) {
|
|
58
|
-
return { seconds: 30 * DAY_SECONDS, short: "mo" };
|
|
59
|
-
}
|
|
60
|
-
if (days === 1 || /\bdaily\b/u.test(words)) {
|
|
61
|
-
return { seconds: DAY_SECONDS, short: "24h" };
|
|
62
|
-
}
|
|
63
|
-
return days === undefined ? undefined : { seconds: days * DAY_SECONDS, short: `${days}d` };
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/** Window length behind a pool; undefined when neither the key nor the name says how long it runs. */
|
|
67
|
-
export const windowPeriod = (pool: { readonly kind: string; readonly label?: string | undefined }): WindowPeriod | undefined => {
|
|
68
|
-
const words = periodWords(pool);
|
|
69
|
-
const hours = counted(words, /\b(\d+) hours?\b/u);
|
|
70
|
-
// Hours first: a pool named both ("5 hours, weekly cap") runs on the shorter clock.
|
|
71
|
-
if (hours !== undefined || /\bfive hours?\b/u.test(words)) {
|
|
72
|
-
const span = hours ?? 5;
|
|
73
|
-
return { seconds: span * HOUR_SECONDS, short: `${span}h` };
|
|
74
|
-
}
|
|
75
|
-
const day = dayPeriod(words, counted(words, /\b(\d+) days?\b/u));
|
|
76
|
-
if (day !== undefined) {
|
|
77
|
-
return day;
|
|
78
|
-
}
|
|
79
|
-
const minutes = counted(words, /\b(\d+) minutes?\b/u);
|
|
80
|
-
return minutes === undefined ? undefined : { seconds: minutes * 60, short: `${minutes}m` };
|
|
81
|
-
};
|
|
24
|
+
export { type RefusedInstant, refusedInstant, refusalVerdict, refusedPoolReset, type RefusalsOnFile, type ServiceFacts, standingOver } from "./verdict/refusal-verdict.js";
|
|
25
|
+
export { periodWords, type WindowPeriod, windowPeriod } from "./verdict/window-period.js";
|
|
82
26
|
|
|
83
27
|
// Whether a reading of this window can still be true. A published reset instant is the authority; with none, the
|
|
84
28
|
// window's own length is, since a pool read as empty says nothing about the window that opened after it. A window whose
|
|
@@ -218,10 +162,13 @@ const refusedPool = (refusal: ProviderRefusal): UsageWindow => {
|
|
|
218
162
|
|
|
219
163
|
// One limit refusal laid on a reading: the pool the refused turn's model spends (else the one asked about, else the
|
|
220
164
|
// tightest) read full, since a polled reading freezes the moment a pool actually empties, and reopening when the provider
|
|
221
|
-
// said to try again, where it said, over whatever the polled pool last said. Never another model's allowance.
|
|
222
|
-
|
|
165
|
+
// said to try again, where it said, over whatever the polled pool last said. Never another model's allowance. A refusal
|
|
166
|
+
// whose instant no pool of the reading `polled` since resets at is a pool of its own (refusedInstant `unpublished`): a
|
|
167
|
+
// Codex refusal on GPT 6.1 Sol naming a reset neither window had pinned the weekly window, which gates every model, so
|
|
168
|
+
// every Codex model read spent for four days while both windows showed most of the allowance free (2026-11-14).
|
|
169
|
+
const pinRefusal = (usage: AccountUsage | undefined, refusal: ProviderRefusal, model: ModelRef | undefined, polled: AccountUsage | undefined): AccountUsage => {
|
|
223
170
|
const binding = bindingWindow(usage, refusal.model === undefined ? model : { id: refusal.model });
|
|
224
|
-
if (usage === undefined || binding === undefined) {
|
|
171
|
+
if (usage === undefined || binding === undefined || refusedInstant(refusal, polled) === "unpublished") {
|
|
225
172
|
return { ...(usage ?? { measuredAt: refusal.at }), windows: [...(usage?.windows ?? []), refusedPool(refusal)] };
|
|
226
173
|
}
|
|
227
174
|
const pinned = pinnedFull(binding);
|
|
@@ -242,7 +189,7 @@ export const judgedReading = (usage: AccountUsage | undefined, standing: Refusal
|
|
|
242
189
|
standing
|
|
243
190
|
.filter((refusal) => refusal.kind === "limit")
|
|
244
191
|
.toSorted((left, right) => left.at - right.at)
|
|
245
|
-
.reduce<AccountUsage | undefined>((reading, refusal) => pinRefusal(reading, refusal, model), usage);
|
|
192
|
+
.reduce<AccountUsage | undefined>((reading, refusal) => pinRefusal(reading, refusal, model, usage), usage);
|
|
246
193
|
|
|
247
194
|
/** The newest of some refusals: the latest word, where a surface says one line about a provider or an account. */
|
|
248
195
|
export const newestRefusal = (refusals: RefusalsOnFile): ProviderRefusal | undefined =>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AccountUsage, ModelCooldown, ProviderRefusal } from "../../schemas/providers/plan-limits.js";
|
|
2
|
-
import { bindingWindow, SPENT_UTILIZATION } from "./pool-gates.js";
|
|
2
|
+
import { bindingWindow, gatingWindows, SPENT_UTILIZATION } from "./pool-gates.js";
|
|
3
|
+
import { windowPeriod } from "./window-period.js";
|
|
3
4
|
|
|
4
5
|
// Which refusals on file still speak, and over which account: the half of the serviceability rule plan-pools.ts runs
|
|
5
6
|
// before it lays them on the readings (judgedReading). Every account is judged on its own facts, never another's.
|
|
@@ -66,6 +67,49 @@ export const refusedPoolReset = (refusal: ProviderRefusal, accounts: readonly Se
|
|
|
66
67
|
return resets.length === 0 ? undefined : Math.min(...resets);
|
|
67
68
|
};
|
|
68
69
|
|
|
70
|
+
// How far apart two instants may be and still name one reset: a reading's reset and a refusal's are each worked out
|
|
71
|
+
// from a countdown at the moment it was said.
|
|
72
|
+
const SAME_RESET_SECONDS = 30 * 60;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* What a reading of the refused account taken since says about the instant a spent allowance named, judged on the pools
|
|
76
|
+
* the refused model spends:
|
|
77
|
+
* - `published`: one of them resets at that instant, so the refusal is that pool's, and the instant outranks the room
|
|
78
|
+
* the reading shows (verdictOn).
|
|
79
|
+
* - `renewed`: none resets there, and every pool long enough to have held the refusal opened after it was filed, with
|
|
80
|
+
* room: the provider renewed the allowance early. 2026-11-13, OpenAI reset ChatGPT allowances days ahead; a Codex
|
|
81
|
+
* refusal kept naming the old weekly reset, and every model stayed held for four more days while each window read
|
|
82
|
+
* open, since nothing but a turn could answer it and every turn was held at the door.
|
|
83
|
+
* - `unpublished`: none resets there and none is a pool renewed since: the refusal is a pool the reading does not name
|
|
84
|
+
* (a model's own cap), so it holds that model alone (plan-pools.ts judgedReading).
|
|
85
|
+
* - `unjudged`: no such reading, or a pool that publishes no reset or no length to judge by.
|
|
86
|
+
*/
|
|
87
|
+
export type RefusedInstant = "published" | "renewed" | "unpublished" | "unjudged";
|
|
88
|
+
|
|
89
|
+
export const refusedInstant = (refusal: ProviderRefusal, usage: AccountUsage | undefined): RefusedInstant => {
|
|
90
|
+
const { resetsAt } = refusal;
|
|
91
|
+
if (refusal.kind !== "limit" || resetsAt === undefined || usage === undefined || usage.measuredAt <= refusal.at) {
|
|
92
|
+
return "unjudged";
|
|
93
|
+
}
|
|
94
|
+
const pools = gatingWindows(usage, refusal.model === undefined ? undefined : { id: refusal.model }).flatMap((window) => {
|
|
95
|
+
const period = windowPeriod(window)?.seconds;
|
|
96
|
+
return window.lapsedAt === undefined ? [{ window, reset: window.resetsAt, period }] : [];
|
|
97
|
+
});
|
|
98
|
+
if (pools.length === 0 || pools.some(({ reset, period }) => reset === undefined || period === undefined)) {
|
|
99
|
+
return "unjudged";
|
|
100
|
+
}
|
|
101
|
+
if (pools.some(({ reset }) => Math.abs((reset ?? 0) - resetsAt) <= SAME_RESET_SECONDS)) {
|
|
102
|
+
return "published";
|
|
103
|
+
}
|
|
104
|
+
// A pool held the refusal only if its window is at least as long as the wait the provider named.
|
|
105
|
+
const filedAt = refusal.at / 1000;
|
|
106
|
+
const holders = pools.filter(({ period }) => (period ?? 0) + SAME_RESET_SECONDS >= resetsAt - filedAt);
|
|
107
|
+
const renewed = holders.every(
|
|
108
|
+
({ window, reset, period }) => (reset ?? 0) - (period ?? 0) > filedAt + SAME_RESET_SECONDS && window.utilization < SPENT_UTILIZATION,
|
|
109
|
+
);
|
|
110
|
+
return holders.length > 0 && renewed ? "renewed" : "unpublished";
|
|
111
|
+
};
|
|
112
|
+
|
|
69
113
|
/*
|
|
70
114
|
* How one refusal stands over ONE account, judged from that account's facts alone: nothing read of another account
|
|
71
115
|
* answers it there (2026-11-08: one Google account reading room answered every nameless refusal for all 31, within
|
|
@@ -73,7 +117,8 @@ export const refusedPoolReset = (refusal: ProviderRefusal, accounts: readonly Se
|
|
|
73
117
|
* instant it named has passed (or, where it named none, the reset of the pool it was refused in, stamped as it was filed:
|
|
74
118
|
* refusedPoolReset, unless this account was read since and a reading outranks a stamp: 2026-10-21). Where it is known to
|
|
75
119
|
* be this account's (it named it, or the provider has no other), the provider's own instant outranks a usage endpoint
|
|
76
|
-
* that kept showing room while it refused, so it stands until then
|
|
120
|
+
* that kept showing room while it refused, so it stands until then, unless a reading since shows that pool renewed
|
|
121
|
+
* early (refusedInstant); else this account's reading of the refused pool
|
|
77
122
|
* since it answers it. A nameless one is one account saying no and nothing saying which, so on each account it is only
|
|
78
123
|
* that account's own reading that answers it, whatever kind of allowance or instant it named: held to its instant, one
|
|
79
124
|
* team account's refusal held every Codex account spent for a day, the free ones reading 0% used (2026-10-19).
|
|
@@ -86,7 +131,7 @@ const verdictOn = (refusal: ProviderRefusal, facts: ServiceFacts, accounts: numb
|
|
|
86
131
|
}
|
|
87
132
|
const known = refusal.account !== undefined || accounts <= 1;
|
|
88
133
|
if (refusal.kind === "limit" && refusal.resetsAt !== undefined && known) {
|
|
89
|
-
return "standing";
|
|
134
|
+
return refusedInstant(refusal, facts.usage) === "renewed" ? "answered" : "standing";
|
|
90
135
|
}
|
|
91
136
|
return answers(refusal, facts, known ? undefined : true) ? "answered" : "standing";
|
|
92
137
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// How long a pool's window runs, read off the provider's own key and whatever name it published. One implementation,
|
|
2
|
+
// because two things need it and must agree: a narrow column names the window by `short`, and a reading with no
|
|
3
|
+
// published reset instant may only be trusted for `seconds` past the moment it was taken.
|
|
4
|
+
|
|
5
|
+
export interface WindowPeriod {
|
|
6
|
+
readonly seconds: number;
|
|
7
|
+
// The token a narrow column names this window by, e.g. "5h", "wk".
|
|
8
|
+
readonly short: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const HOUR_SECONDS = 3_600;
|
|
12
|
+
const DAY_SECONDS = 86_400;
|
|
13
|
+
|
|
14
|
+
/** Kind and label as space-padded lowercase words, underscores split, so `\b` matches across both spellings. */
|
|
15
|
+
export const periodWords = (pool: { readonly kind: string; readonly label?: string | undefined }): string =>
|
|
16
|
+
` ${`${pool.kind} ${pool.label ?? ""}`
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.replaceAll(/[^a-z0-9]+/gu, " ")
|
|
19
|
+
.trim()} `;
|
|
20
|
+
|
|
21
|
+
// A count the words spell out, e.g. the 3 in "3 days".
|
|
22
|
+
const counted = (words: string, pattern: RegExp): number | undefined => {
|
|
23
|
+
const found = pattern.exec(words)?.[1];
|
|
24
|
+
return found === undefined ? undefined : Number(found);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Day-scale and longer, where the named periods outrank a bare count: "7 days" is the week every plan sells, not a
|
|
28
|
+
// seven-day span of its own.
|
|
29
|
+
const dayPeriod = (words: string, days: number | undefined): WindowPeriod | undefined => {
|
|
30
|
+
if (days === 7 || /\bseven days?\b|\bweek(ly|s)?\b/u.test(words)) {
|
|
31
|
+
return { seconds: 7 * DAY_SECONDS, short: "wk" };
|
|
32
|
+
}
|
|
33
|
+
if (/\bmonth(ly|s)?\b/u.test(words)) {
|
|
34
|
+
return { seconds: 30 * DAY_SECONDS, short: "mo" };
|
|
35
|
+
}
|
|
36
|
+
if (days === 1 || /\bdaily\b/u.test(words)) {
|
|
37
|
+
return { seconds: DAY_SECONDS, short: "24h" };
|
|
38
|
+
}
|
|
39
|
+
return days === undefined ? undefined : { seconds: days * DAY_SECONDS, short: `${days}d` };
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Window length behind a pool; undefined when neither the key nor the name says how long it runs. */
|
|
43
|
+
export const windowPeriod = (pool: { readonly kind: string; readonly label?: string | undefined }): WindowPeriod | undefined => {
|
|
44
|
+
const words = periodWords(pool);
|
|
45
|
+
const hours = counted(words, /\b(\d+) hours?\b/u);
|
|
46
|
+
// Hours first: a pool named both ("5 hours, weekly cap") runs on the shorter clock.
|
|
47
|
+
if (hours !== undefined || /\bfive hours?\b/u.test(words)) {
|
|
48
|
+
const span = hours ?? 5;
|
|
49
|
+
return { seconds: span * HOUR_SECONDS, short: `${span}h` };
|
|
50
|
+
}
|
|
51
|
+
const day = dayPeriod(words, counted(words, /\b(\d+) days?\b/u));
|
|
52
|
+
if (day !== undefined) {
|
|
53
|
+
return day;
|
|
54
|
+
}
|
|
55
|
+
const minutes = counted(words, /\b(\d+) minutes?\b/u);
|
|
56
|
+
return minutes === undefined ? undefined : { seconds: minutes * 60, short: `${minutes}m` };
|
|
57
|
+
};
|
package/src/text/pages.ts
CHANGED
|
@@ -57,8 +57,20 @@ export const PAGE_BRIDGE = {
|
|
|
57
57
|
// A video or audio element of the page's own failed to load: the chat checks whether the page's media ticket is
|
|
58
58
|
// still good, since the sealed frame cannot see why a load failed and the chat can.
|
|
59
59
|
mediaError: `intentic/media-error`,
|
|
60
|
+
// The pointer rests on one of the page's pictures that is drawn smaller than it is: the chat floats it bigger beside
|
|
61
|
+
// the page, the way it does a turn's own screenshots. Said again with no picture once the pointer leaves it.
|
|
62
|
+
pictureLook: `intentic/picture-look`,
|
|
63
|
+
// A press on such a picture: the chat opens its picture viewer at it, walking every such picture on the page.
|
|
64
|
+
pictureOpen: `intentic/picture-open`,
|
|
60
65
|
} as const;
|
|
61
66
|
|
|
67
|
+
// Which of a page's pictures the chat offers bigger (pictureLook, pictureOpen): one carried in as data whose own pixels
|
|
68
|
+
// outnumber what it is drawn at by this much on a side, and that is at least this many pixels on its longer side, so an
|
|
69
|
+
// icon drawn from a sharper file is left alone. How many one press hands the viewer, at most.
|
|
70
|
+
export const PAGE_PICTURE_LARGER = 1.2;
|
|
71
|
+
export const PAGE_PICTURE_MIN_SIDE = 160;
|
|
72
|
+
export const PAGE_PICTURES_MAX = 100;
|
|
73
|
+
|
|
62
74
|
// How many distinct errors a page tells, and how long each may be: enough to fix it by, never a flood.
|
|
63
75
|
export const PAGE_ERRORS_MAX = 10;
|
|
64
76
|
export const PAGE_ERROR_CHARS = 600;
|
|
@@ -201,15 +213,19 @@ export const PAGE_LAYOUT_GUIDE =
|
|
|
201
213
|
const baseCss = (canvas: boolean): string =>
|
|
202
214
|
`html{${canvas ? `background:var(--background);` : `background:transparent;`}color:var(--foreground);font-family:var(--font-sans);` +
|
|
203
215
|
`font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;scrollbar-width:none;accent-color:var(--primary)}` +
|
|
204
|
-
`html::-webkit-scrollbar{display:none}body{margin:0}code,kbd,pre,samp{font-family:var(--font-mono)}
|
|
216
|
+
`html::-webkit-scrollbar{display:none}body{margin:0}code,kbd,pre,samp{font-family:var(--font-mono)}` +
|
|
217
|
+
// A picture the chat opens bigger on a press says so, at no specificity, so any cursor the page gives it wins.
|
|
218
|
+
`:where(img[data-intentic-zoom]){cursor:zoom-in}`;
|
|
205
219
|
|
|
206
220
|
// The theme as one `:root` rule; a value can hold nothing that ends the rule.
|
|
207
221
|
export const pageThemeCss = (theme: PageTheme, canvas = false): string =>
|
|
208
222
|
`:root{color-scheme:${theme.appearance};${PAGE_THEME_VARIABLES.map((name) => `${name}:${theme.variables[name].replace(/[;{}<>]/g, ``)};`).join(``)}}${baseCss(canvas)}`;
|
|
209
223
|
|
|
210
224
|
// The page's half of the bridge, run first in its head: the theme it starts in and every change the chat posts, the
|
|
211
|
-
// height it needs whenever that changes,
|
|
212
|
-
//
|
|
225
|
+
// height it needs whenever that changes, which of its pictures the pointer rests on or presses (one already drawn at its
|
|
226
|
+
// own size, or inside something the page made pressable, is never offered), and `window.intentic` for the page's own
|
|
227
|
+
// scripts (submit an answer, send the chat a message, open a link). Every request is answered by the chat, which alone
|
|
228
|
+
// decides whether to act on it.
|
|
213
229
|
const bootstrapScript = (canvas: boolean): string => `(function(){
|
|
214
230
|
var style=document.getElementById("intentic-theme"),n=0,pending={},theme=null,canvas=${canvas ? `true` : `false`};
|
|
215
231
|
var names=${JSON.stringify(PAGE_THEME_VARIABLES)};
|
|
@@ -225,6 +241,14 @@ window.addEventListener("unhandledrejection",function(e){fault("Unhandled reject
|
|
|
225
241
|
var mediaTold=false;window.addEventListener("error",function(e){var t=e.target;if(mediaTold||!t||!t.tagName||!/^(VIDEO|AUDIO|SOURCE)$/.test(t.tagName))return;var s=String(t.currentSrc||t.src||"");if(/^(data|blob):/i.test(s)||s==="")return;mediaTold=true;post({jsonrpc:"2.0",method:${JSON.stringify(PAGE_BRIDGE.mediaError)},params:{}});},true);
|
|
226
242
|
function request(method,params){return new Promise(function(resolve,reject){if(!framed){reject(new Error("This page is not inside a chat."));return;}var id="intentic-"+(++n);pending[id]={resolve:resolve,reject:reject};post({jsonrpc:"2.0",id:id,method:method,params:params});});}
|
|
227
243
|
window.addEventListener("message",function(e){if(e.source!==window.parent)return;var d=e.data;if(!d||d.jsonrpc!=="2.0")return;if(d.method===${JSON.stringify(PAGE_BRIDGE.hostContextChanged)}&&d.params){apply({appearance:d.params.theme,variables:d.params.styles&&d.params.styles.variables});return;}if(d.id!==undefined&&pending[d.id]){var p=pending[d.id];delete pending[d.id];if(d.error)p.reject(new Error(String(d.error.message||"Refused")));else p.resolve(d.result);}});
|
|
244
|
+
var looking=false;
|
|
245
|
+
function larger(t){if(!t||t.tagName!=="IMG")return null;var s=String(t.currentSrc||t.src||"");if(s.slice(0,11).toLowerCase()!=="data:image/")return null;var w=t.naturalWidth,v=t.naturalHeight,r=t.getBoundingClientRect();if(!w||!v||r.width<1||r.height<1||Math.max(w,v)<${PAGE_PICTURE_MIN_SIDE}||(w<r.width*${PAGE_PICTURE_LARGER}&&v<r.height*${PAGE_PICTURE_LARGER}))return null;return{src:s,alt:String(t.alt||"").slice(0,200),left:r.left,top:r.top,width:r.width,height:r.height,aspect:w/v};}
|
|
246
|
+
function opens(t){if(t.closest("a,button,label,summary,select,textarea,[role=button],[role=link],[role=option],[onclick]"))return false;var up=t.parentElement;return getComputedStyle(t).cursor!=="pointer"&&!(up&&getComputedStyle(up).cursor==="pointer");}
|
|
247
|
+
function look(p){if(!p&&!looking)return;looking=!!p;post({jsonrpc:"2.0",method:${JSON.stringify(PAGE_BRIDGE.pictureLook)},params:p||{}});}
|
|
248
|
+
document.addEventListener("pointerover",function(e){if(e.pointerType==="touch")return;var t=e.target,p=larger(t);if(p){if(opens(t))t.setAttribute("data-intentic-zoom","");else t.removeAttribute("data-intentic-zoom");}look(p);},true);
|
|
249
|
+
document.addEventListener("pointerout",function(e){if(e.target&&e.target.tagName==="IMG")look(null);},true);
|
|
250
|
+
window.addEventListener("scroll",function(){look(null);},true);
|
|
251
|
+
document.addEventListener("click",function(e){var t=e.target;if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;var p=larger(t);if(!p||!opens(t))return;var all=[],seen={},at=-1,list=document.images,has=Object.prototype.hasOwnProperty;for(var i=0;i<list.length;i++){var mine=list[i]===t,q=mine?p:larger(list[i]);if(!q)continue;var k=has.call(seen,q.src)?seen[q.src]:-1;if(k<0){if(all.length>=${PAGE_PICTURES_MAX}){if(at>=0)break;if(!mine)continue;all.pop();}k=seen[q.src]=all.length;all.push({src:q.src,alt:q.alt});}if(mine)at=k;}look(null);post({jsonrpc:"2.0",method:${JSON.stringify(PAGE_BRIDGE.pictureOpen)},params:{pictures:all,index:at}});});
|
|
228
252
|
if(framed){var h=-1,z=function(){var r=document.documentElement,b=document.body,v=Math.ceil(Math.max(r.scrollHeight>r.clientHeight?r.scrollHeight:r.getBoundingClientRect().height,b?b.getBoundingClientRect().bottom:0));if(v===h||v<=0)return;h=v;post({jsonrpc:"2.0",method:${JSON.stringify(PAGE_BRIDGE.sizeChanged)},params:{height:v}});};if(window.ResizeObserver){var o=new ResizeObserver(z);o.observe(document.documentElement);document.addEventListener("DOMContentLoaded",function(){if(document.body)o.observe(document.body);z();});}window.addEventListener("load",z);setTimeout(z,50);}
|
|
229
253
|
window.intentic={
|
|
230
254
|
submit:function(value){return request(${JSON.stringify(PAGE_BRIDGE.submit)},{value:value===undefined?null:JSON.parse(JSON.stringify(value))});},
|