calmlens 0.37.1 → 0.38.1
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/bin/calmlens.js +87 -17
- package/cjs/{BrowserUpload-84KQWr1Q.js → BrowserUpload-DS0lxg5C.js} +1 -1
- package/{esm/BrowserUpload-CuG3tWSo.d.ts → cjs/BrowserUpload-_iMX_nq0.d.ts} +2 -2
- package/{esm/CalmLensAppClient-QqtovWE-.d.ts → cjs/CalmLensAppClient-CQpnc4JZ.d.ts} +1 -1
- package/cjs/{CalmLensAppClient-D4tRb_P2.js → CalmLensAppClient-Diu1QtBz.js} +3 -3
- package/cjs/{CalmLensCdn-CdYY_XtK.js → CalmLensCdn-DCj0AfoS.js} +2 -2
- package/cjs/{CalmLensConnection-GkR2cKn5.js → CalmLensConnection-BpBq0nQR.js} +14 -4
- package/cjs/{CalmLensError-ifj5rLmk.js → CalmLensError-C9g7GXfU.js} +7 -2
- package/{esm/CalmLensServerClient-csSQqHBt.d.ts → cjs/CalmLensServerClient-CeTsE5Jx.d.ts} +5 -5
- package/cjs/{CalmLensServerClient-cgPOG4Sv.js → CalmLensServerClient-vdHfH0Nf.js} +15 -6
- package/cjs/{CalmLensTypes-_f7QVRtO.d.ts → CalmLensTypes-jond9q6a.d.ts} +28 -9
- package/cjs/{Core-BlnBBJKb.js → Core-BHQSo7rY.js} +3 -3
- package/{esm/Core-4iFxKJnY.d.ts → cjs/Core-C6_Q5ZME.d.ts} +2 -2
- package/cjs/{ReactUpload-D3AYIZBh.js → ReactUpload-bbHMmEUQ.js} +1 -1
- package/cjs/{ReactUpload-4qd2xACg.d.ts → ReactUpload-fy6zhY8M.d.ts} +1 -1
- package/cjs/{UploadController-BYuHuZ7K.js → UploadController-C1tiTTRR.js} +2 -2
- package/{esm/WebhookPayload-BJtggTLd.d.ts → cjs/WebhookPayload-DdpKjQGw.d.ts} +5 -3
- package/cjs/app.d.ts +4 -4
- package/cjs/app.js +3 -3
- package/cjs/elements.d.ts +4 -4
- package/cjs/elements.js +4 -4
- package/cjs/{index-IEA75nev.d.ts → index-CgAztQdX.d.ts} +2 -2
- package/cjs/index.d.ts +3 -3
- package/cjs/index.js +2 -2
- package/cjs/react-native.d.ts +2 -2
- package/cjs/react-native.js +4 -4
- package/cjs/react.d.ts +4 -4
- package/cjs/react.js +5 -5
- package/cjs/server.d.ts +4 -4
- package/cjs/server.js +3 -3
- package/cjs/{CalmLensTestInputArguments-C6S09FVQ.js → test-inputs-DJnupsBH.js} +231 -22
- package/{esm/TestTriggers-CjDhhz78.d.ts → cjs/test-inputs-fugEK0py.d.ts} +36 -142
- package/cjs/test-inputs.d.ts +2 -18
- package/cjs/test-inputs.js +17 -126
- package/cjs/testing.d.ts +11 -14
- package/cjs/testing.js +38 -68
- package/cjs/{ui-Cy8MWXOw.js → ui-2jJvTcCP.js} +2 -2
- package/cjs/{ui-BMQW3Hse.d.ts → ui-Cp18fGXG.d.ts} +2 -2
- package/cjs/ui.d.ts +2 -2
- package/cjs/ui.js +3 -3
- package/cjs/vue.d.ts +5 -5
- package/cjs/vue.js +4 -4
- package/esm/{BrowserUpload-C429CcUi.js → BrowserUpload-C4YF17a3.js} +1 -1
- package/{cjs/BrowserUpload-CuG3tWSo.d.ts → esm/BrowserUpload-_iMX_nq0.d.ts} +2 -2
- package/esm/{CalmLensAppClient-Brvc-GXt.js → CalmLensAppClient-B2H7x_SJ.js} +3 -3
- package/{cjs/CalmLensAppClient-QqtovWE-.d.ts → esm/CalmLensAppClient-CQpnc4JZ.d.ts} +1 -1
- package/esm/{CalmLensCdn-cmxtF_dw.js → CalmLensCdn-Dh546rXe.js} +2 -2
- package/esm/{CalmLensConnection-DEfpIugc.js → CalmLensConnection-BbFlVAdl.js} +14 -4
- package/esm/{CalmLensError-C15tWu8W.js → CalmLensError-DjkibkdI.js} +7 -2
- package/{cjs/CalmLensServerClient-csSQqHBt.d.ts → esm/CalmLensServerClient-CeTsE5Jx.d.ts} +5 -5
- package/esm/{CalmLensServerClient-BpsCXVeO.js → CalmLensServerClient-CqH-tqcC.js} +15 -6
- package/esm/{CalmLensTypes-_f7QVRtO.d.ts → CalmLensTypes-jond9q6a.d.ts} +28 -9
- package/{cjs/Core-4iFxKJnY.d.ts → esm/Core-C6_Q5ZME.d.ts} +2 -2
- package/esm/{Core-C_f1o9RQ.js → Core-VNBTpvrG.js} +3 -3
- package/esm/{ReactUpload-Ch5qY7PS.js → ReactUpload-CRH6rSaX.js} +1 -1
- package/esm/{ReactUpload-4qd2xACg.d.ts → ReactUpload-fy6zhY8M.d.ts} +1 -1
- package/esm/{UploadController-9fkYFVZM.js → UploadController-BYxiONcw.js} +2 -2
- package/{cjs/WebhookPayload-BJtggTLd.d.ts → esm/WebhookPayload-DdpKjQGw.d.ts} +5 -3
- package/esm/app.d.ts +4 -4
- package/esm/app.js +3 -3
- package/esm/elements.d.ts +4 -4
- package/esm/elements.js +4 -4
- package/esm/{index-IEA75nev.d.ts → index-CgAztQdX.d.ts} +2 -2
- package/esm/index.d.ts +3 -3
- package/esm/index.js +2 -2
- package/esm/react-native.d.ts +2 -2
- package/esm/react-native.js +4 -4
- package/esm/react.d.ts +4 -4
- package/esm/react.js +5 -5
- package/esm/server.d.ts +4 -4
- package/esm/server.js +3 -3
- package/esm/{CalmLensTestInputArguments-DS_3mt1C.js → test-inputs-BLlkOmNC.js} +212 -15
- package/{cjs/TestTriggers-CjDhhz78.d.ts → esm/test-inputs-fugEK0py.d.ts} +36 -142
- package/esm/test-inputs.d.ts +2 -18
- package/esm/test-inputs.js +1 -115
- package/esm/testing.d.ts +11 -14
- package/esm/testing.js +27 -57
- package/esm/{ui-BMQW3Hse.d.ts → ui-Cp18fGXG.d.ts} +2 -2
- package/esm/{ui-HK74e42L.js → ui-siBYiNJZ.js} +2 -2
- package/esm/ui.d.ts +2 -2
- package/esm/ui.js +3 -3
- package/esm/vue.d.ts +5 -5
- package/esm/vue.js +4 -4
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as invalidArgument } from "./CalmLensError-
|
|
1
|
+
import { S as invalidArgument } from "./CalmLensError-DjkibkdI.js";
|
|
2
2
|
import { r as timingSafeEqual, t as hmacSha256Hex } from "./CryptoUtils-BLCa-oZe-DKr3LmN6.js";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
import { globalRegistry } from "zod";
|
|
@@ -135,7 +135,7 @@ Object.keys(JURISDICTIONS).filter((code) => !JURISDICTIONS[code].optional);
|
|
|
135
135
|
Object.keys(JURISDICTIONS).filter((code) => JURISDICTIONS[code].optional);
|
|
136
136
|
new Set("AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW".split(" "));
|
|
137
137
|
const EU_COUNTRIES = new Set("AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE".split(" "));
|
|
138
|
-
// src/contract/TestRegionalActions-
|
|
138
|
+
// src/contract/TestRegionalActions-BAzqFJfV.js
|
|
139
139
|
/**
|
|
140
140
|
* Marks English text in shared, backend and data modules that the portal shows, so the app's
|
|
141
141
|
* message catalog (packages/app/vite/messageCatalog.ts) extracts it and the portal can translate it
|
|
@@ -1150,13 +1150,15 @@ const MODERATION_QUALIFIER_INFO = {
|
|
|
1150
1150
|
}
|
|
1151
1151
|
};
|
|
1152
1152
|
const MODERATION_QUALIFIERS = Object.keys(MODERATION_QUALIFIER_INFO);
|
|
1153
|
-
MODERATION_QUALIFIERS.reduce((groups, qualifier) => {
|
|
1153
|
+
const MODERATION_QUALIFIERS_BY_CATEGORY = MODERATION_QUALIFIERS.reduce((groups, qualifier) => {
|
|
1154
1154
|
(groups[MODERATION_QUALIFIER_INFO[qualifier].category] ??= []).push(qualifier);
|
|
1155
1155
|
return groups;
|
|
1156
1156
|
}, {});
|
|
1157
|
-
|
|
1158
|
-
|
|
1157
|
+
/** A qualifier the input type sets (`fromInput`), which no model is asked about. */
|
|
1158
|
+
function isInputQualifier(qualifier) {
|
|
1159
|
+
return MODERATION_QUALIFIER_INFO[qualifier].fromInput === true;
|
|
1159
1160
|
}
|
|
1161
|
+
const getModerationQualifiers = (category) => MODERATION_QUALIFIERS_BY_CATEGORY[category] ?? [];
|
|
1160
1162
|
/** Authenticated test inputs can add regional delivery restrictions without inventing evidence. */
|
|
1161
1163
|
const TEST_REGIONAL_ACTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => z.array(z.object({
|
|
1162
1164
|
region: JURISDICTION_SCHEMA.exclude(["global"]),
|
|
@@ -1166,7 +1168,7 @@ const TEST_REGIONAL_ACTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => z.array(z.
|
|
|
1166
1168
|
"block"
|
|
1167
1169
|
])
|
|
1168
1170
|
}).strict()).max(7).refine((entries) => new Set(entries.map((entry) => entry.region)).size === entries.length, "Choose each region once"));
|
|
1169
|
-
// src/contract/TestTriggers-
|
|
1171
|
+
// src/contract/TestTriggers-ByQZ27Zp.js
|
|
1170
1172
|
/**
|
|
1171
1173
|
* The visual encoding of test images (shared by images and video frames), independent of what the
|
|
1172
1174
|
* bytes mean. An odd N×N grid of square cells fills the image. Its outer ring alternates black and
|
|
@@ -1652,6 +1654,22 @@ const TEST_DETECTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => z.object({
|
|
|
1652
1654
|
people: z.union([z.array(TEST_DETECTED_PERSON_SCHEMA).max(32), z.literal("unavailable")]).optional(),
|
|
1653
1655
|
faces: z.union([z.array(TEST_DETECTED_FACE_SCHEMA).max(32), z.literal("unavailable")]).optional()
|
|
1654
1656
|
}).strict());
|
|
1657
|
+
/**
|
|
1658
|
+
* Why a test input's qualifier is refused: each zod issue's `params` carry the `category`,
|
|
1659
|
+
* `qualifier` and `reason`, and `allowed` (the category's qualifiers) for an unknown one.
|
|
1660
|
+
*/
|
|
1661
|
+
const TEST_INPUT_QUALIFIER_ERRORS = {
|
|
1662
|
+
/** Not a qualifier of the instance's category. */
|
|
1663
|
+
unknown: "unknown-qualifier",
|
|
1664
|
+
/** A qualifier the input type sets, such as `sexual-text`. */
|
|
1665
|
+
automatic: "input-type-qualifier",
|
|
1666
|
+
/** Given more than once in one instance. */
|
|
1667
|
+
repeated: "repeated-qualifier"
|
|
1668
|
+
};
|
|
1669
|
+
const isKnownQualifier = (qualifier) => MODERATION_QUALIFIERS.includes(qualifier);
|
|
1670
|
+
const isCategoryQualifier = (category, qualifier) => getModerationQualifiers(category).includes(qualifier);
|
|
1671
|
+
/** The qualifiers a test input may give for `category`: its own, less those the input type sets. */
|
|
1672
|
+
const getTestInputQualifiers = (category) => getModerationQualifiers(category).filter((qualifier) => !isInputQualifier(qualifier));
|
|
1655
1673
|
/** Each row is one qualifying instance. Unselected qualifiers are explicitly absent. */
|
|
1656
1674
|
const TEST_INPUT_SCHEMA = /* @__PURE__ */ lazySchema(() => z.object({
|
|
1657
1675
|
regionalActions: TEST_REGIONAL_ACTIONS_SCHEMA.optional(),
|
|
@@ -1664,11 +1682,46 @@ const TEST_INPUT_SCHEMA = /* @__PURE__ */ lazySchema(() => z.object({
|
|
|
1664
1682
|
"age-restrict",
|
|
1665
1683
|
"block"
|
|
1666
1684
|
]).optional(),
|
|
1667
|
-
qualifiers: z.array(z.
|
|
1685
|
+
qualifiers: z.array(z.custom((value) => typeof value === "string", { message: "A qualifier is a string, such as harassment-abuse." })).max(64)
|
|
1668
1686
|
}).strict().superRefine((instance, context) => {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1687
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1688
|
+
instance.qualifiers.forEach((qualifier, index) => {
|
|
1689
|
+
const path = ["qualifiers", index];
|
|
1690
|
+
const details = {
|
|
1691
|
+
category: instance.category,
|
|
1692
|
+
qualifier
|
|
1693
|
+
};
|
|
1694
|
+
if (isKnownQualifier(qualifier) && isInputQualifier(qualifier)) context.addIssue({
|
|
1695
|
+
code: "custom",
|
|
1696
|
+
path,
|
|
1697
|
+
params: {
|
|
1698
|
+
...details,
|
|
1699
|
+
reason: TEST_INPUT_QUALIFIER_ERRORS.automatic
|
|
1700
|
+
},
|
|
1701
|
+
message: `"${qualifier}" is set by the input type: leave it out.`
|
|
1702
|
+
});
|
|
1703
|
+
else if (!isCategoryQualifier(instance.category, qualifier)) {
|
|
1704
|
+
const allowed = getTestInputQualifiers(instance.category);
|
|
1705
|
+
context.addIssue({
|
|
1706
|
+
code: "custom",
|
|
1707
|
+
path,
|
|
1708
|
+
params: {
|
|
1709
|
+
...details,
|
|
1710
|
+
reason: TEST_INPUT_QUALIFIER_ERRORS.unknown,
|
|
1711
|
+
allowed
|
|
1712
|
+
},
|
|
1713
|
+
message: `Unknown ${instance.category} qualifier "${qualifier}": choose from ${allowed.join(", ")}.`
|
|
1714
|
+
});
|
|
1715
|
+
} else if (seen.has(qualifier)) context.addIssue({
|
|
1716
|
+
code: "custom",
|
|
1717
|
+
path,
|
|
1718
|
+
params: {
|
|
1719
|
+
...details,
|
|
1720
|
+
reason: TEST_INPUT_QUALIFIER_ERRORS.repeated
|
|
1721
|
+
},
|
|
1722
|
+
message: `"${qualifier}" is repeated: give each qualifier once.`
|
|
1723
|
+
});
|
|
1724
|
+
seen.add(qualifier);
|
|
1672
1725
|
});
|
|
1673
1726
|
})).max(128),
|
|
1674
1727
|
detections: TEST_DETECTIONS_SCHEMA.optional()
|
|
@@ -1850,7 +1903,7 @@ const toBase64Url = (bytes) => btoa(String.fromCharCode(...bytes)).replaceAll("+
|
|
|
1850
1903
|
const fromBase64Url = (text) => Uint8Array.from(atob(text.replaceAll("-", "+").replaceAll("_", "/")), (char) => char.charCodeAt(0));
|
|
1851
1904
|
/** The signed bytes: the scenario's canonical JSON (ASCII). */
|
|
1852
1905
|
const envelope = (scenario) => new TextEncoder().encode(JSON.stringify(TEST_INPUT_SCHEMA.parse(scenario)));
|
|
1853
|
-
async function generateTestTextCode(scenario, key) {
|
|
1906
|
+
async function generateTestTextCode$1(scenario, key) {
|
|
1854
1907
|
if (!/^[a-f0-9]{32}$/.test(key)) throw new TypeError("Invalid test input key");
|
|
1855
1908
|
const payload = toBase64Url(envelope(typeof scenario === "string" ? testInputForSignal(scenario) : scenario));
|
|
1856
1909
|
if (payload.length > 8e3) throw new RangeError("Test scenario is too large");
|
|
@@ -1926,9 +1979,9 @@ const TEST_INPUT_CATEGORY_COLORS = {
|
|
|
1926
1979
|
* bytes, big-endian), the 16-byte tag, then the payload (the scenario JSON). The reader rebuilds
|
|
1927
1980
|
* the text code, so images and text share one verification.
|
|
1928
1981
|
*/
|
|
1929
|
-
async function paintTestImage(scenario, key) {
|
|
1982
|
+
async function paintTestImage$1(scenario, key) {
|
|
1930
1983
|
const input = TEST_INPUT_SCHEMA.parse(typeof scenario === "string" ? testInputForSignal(scenario, "image") : scenario);
|
|
1931
|
-
const [, signature, payload] = (await generateTestTextCode(input, key)).slice(0, -1).split(" ");
|
|
1984
|
+
const [, signature, payload] = (await generateTestTextCode$1(input, key)).slice(0, -1).split(" ");
|
|
1932
1985
|
const signed = fromBase64Url(payload);
|
|
1933
1986
|
const data = new Uint8Array(18 + signed.length);
|
|
1934
1987
|
data.set([signed.length >> 8, signed.length & 255]);
|
|
@@ -1972,10 +2025,154 @@ async function withValidTestInputArguments(key, generate) {
|
|
|
1972
2025
|
if (error instanceof z.ZodError) {
|
|
1973
2026
|
const [issue] = error.issues;
|
|
1974
2027
|
const path = (issue?.path ?? []).map((segment) => typeof segment === "number" ? segment : String(segment));
|
|
1975
|
-
|
|
2028
|
+
const qualifier = issue?.code === "custom" && typeof issue.params?.reason === "string" ? issue.params : {};
|
|
2029
|
+
throw invalidArgument(`Invalid test scenario at ${path.length ? path.join(".") : "scenario"}: ${issue?.message ?? error.message}`, {
|
|
2030
|
+
path,
|
|
2031
|
+
...qualifier
|
|
2032
|
+
});
|
|
1976
2033
|
}
|
|
1977
2034
|
if (error instanceof RangeError) throw invalidArgument(error.message);
|
|
1978
2035
|
throw error;
|
|
1979
2036
|
}
|
|
1980
2037
|
}
|
|
1981
|
-
|
|
2038
|
+
// src/client/TestImagePng.ts
|
|
2039
|
+
/**
|
|
2040
|
+
* Encodes a painted test image as a PNG: 8-bit RGBA rows without filtering in stored deflate
|
|
2041
|
+
* blocks, as every SDK writes it, so the bytes match across SDKs. Runs anywhere, with no
|
|
2042
|
+
* compression library.
|
|
2043
|
+
*/
|
|
2044
|
+
function encodeTestImagePng(width, height, rgba) {
|
|
2045
|
+
const stride = width * 4;
|
|
2046
|
+
const raw = new Uint8Array((stride + 1) * height);
|
|
2047
|
+
for (let row = 0; row < height; row++) raw.set(rgba.subarray(row * stride, (row + 1) * stride), row * (stride + 1) + 1);
|
|
2048
|
+
const blocks = Math.max(1, Math.ceil(raw.length / 65535));
|
|
2049
|
+
const stream = new Uint8Array(2 + raw.length + blocks * 5 + 4);
|
|
2050
|
+
stream.set([120, 1]);
|
|
2051
|
+
let position = 2;
|
|
2052
|
+
for (let offset = 0; offset < raw.length || position === 2; offset += 65535) {
|
|
2053
|
+
const block = raw.subarray(offset, offset + 65535);
|
|
2054
|
+
const length = block.length;
|
|
2055
|
+
stream.set([
|
|
2056
|
+
offset + length >= raw.length ? 1 : 0,
|
|
2057
|
+
length & 255,
|
|
2058
|
+
length >> 8,
|
|
2059
|
+
~length & 255,
|
|
2060
|
+
~length >> 8 & 255
|
|
2061
|
+
], position);
|
|
2062
|
+
stream.set(block, position + 5);
|
|
2063
|
+
position += 5 + length;
|
|
2064
|
+
}
|
|
2065
|
+
writeUint32(stream, position, adler32(raw));
|
|
2066
|
+
const header = /* @__PURE__ */ new Uint8Array(13);
|
|
2067
|
+
writeUint32(header, 0, width);
|
|
2068
|
+
writeUint32(header, 4, height);
|
|
2069
|
+
header.set([
|
|
2070
|
+
8,
|
|
2071
|
+
6,
|
|
2072
|
+
0,
|
|
2073
|
+
0,
|
|
2074
|
+
0
|
|
2075
|
+
], 8);
|
|
2076
|
+
return concat([
|
|
2077
|
+
Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10),
|
|
2078
|
+
chunk("IHDR", header),
|
|
2079
|
+
chunk("IDAT", stream),
|
|
2080
|
+
chunk("IEND", /* @__PURE__ */ new Uint8Array(0))
|
|
2081
|
+
]);
|
|
2082
|
+
}
|
|
2083
|
+
function chunk(kind, body) {
|
|
2084
|
+
const typed = new Uint8Array(4 + body.length);
|
|
2085
|
+
for (let i = 0; i < 4; i++) typed[i] = kind.charCodeAt(i);
|
|
2086
|
+
typed.set(body, 4);
|
|
2087
|
+
const out = new Uint8Array(12 + body.length);
|
|
2088
|
+
writeUint32(out, 0, body.length);
|
|
2089
|
+
out.set(typed, 4);
|
|
2090
|
+
writeUint32(out, 8 + body.length, crc32(typed));
|
|
2091
|
+
return out;
|
|
2092
|
+
}
|
|
2093
|
+
function writeUint32(target, offset, value) {
|
|
2094
|
+
target[offset] = value >>> 24;
|
|
2095
|
+
target[offset + 1] = value >>> 16 & 255;
|
|
2096
|
+
target[offset + 2] = value >>> 8 & 255;
|
|
2097
|
+
target[offset + 3] = value & 255;
|
|
2098
|
+
}
|
|
2099
|
+
function concat(parts) {
|
|
2100
|
+
const out = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
2101
|
+
let offset = 0;
|
|
2102
|
+
for (const part of parts) {
|
|
2103
|
+
out.set(part, offset);
|
|
2104
|
+
offset += part.length;
|
|
2105
|
+
}
|
|
2106
|
+
return out;
|
|
2107
|
+
}
|
|
2108
|
+
let crcTable;
|
|
2109
|
+
function crc32(bytes) {
|
|
2110
|
+
if (!crcTable) {
|
|
2111
|
+
crcTable = /* @__PURE__ */ new Uint32Array(256);
|
|
2112
|
+
for (let n = 0; n < 256; n++) {
|
|
2113
|
+
let c = n;
|
|
2114
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
2115
|
+
crcTable[n] = c >>> 0;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
let crc = 4294967295;
|
|
2119
|
+
for (const byte of bytes) crc = crcTable[(crc ^ byte) & 255] ^ crc >>> 8;
|
|
2120
|
+
return (crc ^ 4294967295) >>> 0;
|
|
2121
|
+
}
|
|
2122
|
+
function adler32(bytes) {
|
|
2123
|
+
let a = 1;
|
|
2124
|
+
let b = 0;
|
|
2125
|
+
for (const byte of bytes) {
|
|
2126
|
+
a = (a + byte) % 65521;
|
|
2127
|
+
b = (b + a) % 65521;
|
|
2128
|
+
}
|
|
2129
|
+
return (b << 16 | a) >>> 0;
|
|
2130
|
+
}
|
|
2131
|
+
// src/contract/MediaTestTriggers.js
|
|
2132
|
+
const MEDIA_TEST_SIGNALS = [...CLASSIFICATION_CATEGORIES, "violence.graphic"];
|
|
2133
|
+
const HEX_WORDS = [
|
|
2134
|
+
"zero",
|
|
2135
|
+
"one",
|
|
2136
|
+
"two",
|
|
2137
|
+
"three",
|
|
2138
|
+
"four",
|
|
2139
|
+
"five",
|
|
2140
|
+
"six",
|
|
2141
|
+
"seven",
|
|
2142
|
+
"eight",
|
|
2143
|
+
"nine",
|
|
2144
|
+
"alpha",
|
|
2145
|
+
"bravo",
|
|
2146
|
+
"charlie",
|
|
2147
|
+
"delta",
|
|
2148
|
+
"echo",
|
|
2149
|
+
"foxtrot"
|
|
2150
|
+
];
|
|
2151
|
+
/** Read this aloud, or render it as large, high-contrast text in a video frame. */
|
|
2152
|
+
async function generateMediaTestCode$1(signal, testInputKey) {
|
|
2153
|
+
if (!MEDIA_TEST_SIGNALS.includes(signal)) throw new RangeError("Unsupported media test signal");
|
|
2154
|
+
return `Calm Lens test ${[...await getTestInputTag("media", signal, testInputKey)].map((character) => HEX_WORDS[Number.parseInt(character, 16)]).join(" ")} ${signal.replace(/[.-]/g, " ")} end test`;
|
|
2155
|
+
}
|
|
2156
|
+
// src/test-inputs.ts
|
|
2157
|
+
/**
|
|
2158
|
+
* Portable test inputs: presets and custom instances share one authenticated format. CalmLens
|
|
2159
|
+
* recognises a code only as the whole text and a test image only as the whole
|
|
2160
|
+
* upload, signed with the project's own key.
|
|
2161
|
+
*/
|
|
2162
|
+
/** A spoken media test phrase for `signal`, signed with the project's test input key. */
|
|
2163
|
+
const generateMediaTestCode = (signal, key) => withValidTestInputArguments(key, () => generateMediaTestCode$1(signal, key));
|
|
2164
|
+
/** A text code for `scenario`, signed with the project's test input key. */
|
|
2165
|
+
const generateTestTextCode = (scenario, key) => withValidTestInputArguments(key, () => generateTestTextCode$1(scenario, key));
|
|
2166
|
+
/**
|
|
2167
|
+
* The test image for `scenario`, signed with the project's test input key. Upload its `png` bytes
|
|
2168
|
+
* (or encode `rgba` in another format: the image survives lossy formats and resizing) as the whole
|
|
2169
|
+
* image, optionally on a plain single-colour border.
|
|
2170
|
+
*/
|
|
2171
|
+
const paintTestImage = async (scenario, key) => {
|
|
2172
|
+
const image = await withValidTestInputArguments(key, () => paintTestImage$1(scenario, key));
|
|
2173
|
+
return {
|
|
2174
|
+
...image,
|
|
2175
|
+
png: encodeTestImagePng(image.width, image.height, image.rgba)
|
|
2176
|
+
};
|
|
2177
|
+
};
|
|
2178
|
+
export { EU_COUNTRIES as _, TEST_DETECTIONS_MAX as a, TEST_FACE_AGE_PRESETS as c, TEST_INPUT_QUALIFIER_ERRORS as d, detectTestImage as f, testInputForSignal as g, getTestInputQualifiers as h, MEDIA_TEST_SIGNALS as i, TEST_INPUT_KEY_PATTERN as l, getImageTestCategories as m, generateTestTextCode as n, TEST_DETECTION_BOX_MAX as o, detectTestTrigger as p, paintTestImage as r, TEST_FACE_AGE_MAX as s, generateMediaTestCode as t, TEST_INPUT_PRESETS as u, lazySchema as v, CLASSIFICATION_CATEGORIES as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ClassificationCategory } from "./Classification-C3pkrGYS-B7EygpJn.js";
|
|
1
|
+
import { n as ClassificationCategory, s as ModerationQualifier } from "./Classification-C3pkrGYS-B7EygpJn.js";
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
interface RgbaImage {
|
|
4
4
|
width: number;
|
|
@@ -46,6 +46,20 @@ declare const TEST_DETECTIONS_SCHEMA: z.ZodObject<{
|
|
|
46
46
|
}, z.core.$strict>>, z.ZodLiteral<"unavailable">]>>;
|
|
47
47
|
}, z.core.$strict>;
|
|
48
48
|
type TestDetections = z.infer<typeof TEST_DETECTIONS_SCHEMA>;
|
|
49
|
+
/**
|
|
50
|
+
* Why a test input's qualifier is refused: each zod issue's `params` carry the `category`,
|
|
51
|
+
* `qualifier` and `reason`, and `allowed` (the category's qualifiers) for an unknown one.
|
|
52
|
+
*/
|
|
53
|
+
declare const TEST_INPUT_QUALIFIER_ERRORS: {
|
|
54
|
+
/** Not a qualifier of the instance's category. */
|
|
55
|
+
readonly unknown: "unknown-qualifier";
|
|
56
|
+
/** A qualifier the input type sets, such as `sexual-text`. */
|
|
57
|
+
readonly automatic: "input-type-qualifier";
|
|
58
|
+
/** Given more than once in one instance. */
|
|
59
|
+
readonly repeated: "repeated-qualifier";
|
|
60
|
+
};
|
|
61
|
+
/** The qualifiers a test input may give for `category`: its own, less those the input type sets. */
|
|
62
|
+
declare const getTestInputQualifiers: (category: string) => ModerationQualifier[];
|
|
49
63
|
/** Each row is one qualifying instance. Unselected qualifiers are explicitly absent. */
|
|
50
64
|
declare const TEST_INPUT_SCHEMA: z.ZodObject<{
|
|
51
65
|
regionalActions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
@@ -91,146 +105,7 @@ declare const TEST_INPUT_SCHEMA: z.ZodObject<{
|
|
|
91
105
|
block: "block";
|
|
92
106
|
limit: "limit";
|
|
93
107
|
}>>;
|
|
94
|
-
qualifiers: z.ZodArray<z.
|
|
95
|
-
"criminal-activity-alcohol": "criminal-activity-alcohol";
|
|
96
|
-
"criminal-activity-coded-incitement": "criminal-activity-coded-incitement";
|
|
97
|
-
"criminal-activity-csam": "criminal-activity-csam";
|
|
98
|
-
"criminal-activity-demonstration": "criminal-activity-demonstration";
|
|
99
|
-
"criminal-activity-discussion": "criminal-activity-discussion";
|
|
100
|
-
"criminal-activity-documentary": "criminal-activity-documentary";
|
|
101
|
-
"criminal-activity-educational": "criminal-activity-educational";
|
|
102
|
-
"criminal-activity-fictional": "criminal-activity-fictional";
|
|
103
|
-
"criminal-activity-fraud": "criminal-activity-fraud";
|
|
104
|
-
"criminal-activity-gambling": "criminal-activity-gambling";
|
|
105
|
-
"criminal-activity-graffiti": "criminal-activity-graffiti";
|
|
106
|
-
"criminal-activity-grooming": "criminal-activity-grooming";
|
|
107
|
-
"criminal-activity-historical": "criminal-activity-historical";
|
|
108
|
-
"criminal-activity-instructions": "criminal-activity-instructions";
|
|
109
|
-
"criminal-activity-preparation": "criminal-activity-preparation";
|
|
110
|
-
"criminal-activity-promotion": "criminal-activity-promotion";
|
|
111
|
-
"criminal-activity-request": "criminal-activity-request";
|
|
112
|
-
"criminal-activity-sexual-solicitation": "criminal-activity-sexual-solicitation";
|
|
113
|
-
"criminal-activity-substances": "criminal-activity-substances";
|
|
114
|
-
"criminal-activity-support-prevention": "criminal-activity-support-prevention";
|
|
115
|
-
"criminal-activity-tobacco": "criminal-activity-tobacco";
|
|
116
|
-
"harassment-abuse": "harassment-abuse";
|
|
117
|
-
"harassment-bullying": "harassment-bullying";
|
|
118
|
-
"harassment-documentary": "harassment-documentary";
|
|
119
|
-
"harassment-educational": "harassment-educational";
|
|
120
|
-
"harassment-encouragement": "harassment-encouragement";
|
|
121
|
-
"harassment-fictional": "harassment-fictional";
|
|
122
|
-
"harassment-historical": "harassment-historical";
|
|
123
|
-
"harassment-mild": "harassment-mild";
|
|
124
|
-
"harassment-public-target": "harassment-public-target";
|
|
125
|
-
"harassment-sexual": "harassment-sexual";
|
|
126
|
-
"harassment-support-prevention": "harassment-support-prevention";
|
|
127
|
-
"harassment-threat": "harassment-threat";
|
|
128
|
-
"hate-abuse": "hate-abuse";
|
|
129
|
-
"hate-adjudicated-nazi-crimes-denial": "hate-adjudicated-nazi-crimes-denial";
|
|
130
|
-
"hate-counterspeech": "hate-counterspeech";
|
|
131
|
-
"hate-dehumanization": "hate-dehumanization";
|
|
132
|
-
"hate-documentary": "hate-documentary";
|
|
133
|
-
"hate-educational": "hate-educational";
|
|
134
|
-
"hate-exclusion": "hate-exclusion";
|
|
135
|
-
"hate-fictional": "hate-fictional";
|
|
136
|
-
"hate-historical": "hate-historical";
|
|
137
|
-
"hate-hostility": "hate-hostility";
|
|
138
|
-
"hate-inferiority": "hate-inferiority";
|
|
139
|
-
"hate-nazi-genocide-denial-or-approval": "hate-nazi-genocide-denial-or-approval";
|
|
140
|
-
"hate-nazi-genocide-public-peace": "hate-nazi-genocide-public-peace";
|
|
141
|
-
"hate-nazi-insignia-public-display": "hate-nazi-insignia-public-display";
|
|
142
|
-
"hate-nazi-symbols-public-display": "hate-nazi-symbols-public-display";
|
|
143
|
-
"hate-personal": "hate-personal";
|
|
144
|
-
"hate-slurs": "hate-slurs";
|
|
145
|
-
"hate-support-prevention": "hate-support-prevention";
|
|
146
|
-
"hate-symbol": "hate-symbol";
|
|
147
|
-
"hate-threat": "hate-threat";
|
|
148
|
-
"personal-information-contact": "personal-information-contact";
|
|
149
|
-
"personal-information-credentials": "personal-information-credentials";
|
|
150
|
-
"personal-information-documentary": "personal-information-documentary";
|
|
151
|
-
"personal-information-educational": "personal-information-educational";
|
|
152
|
-
"personal-information-email": "personal-information-email";
|
|
153
|
-
"personal-information-fictional": "personal-information-fictional";
|
|
154
|
-
"personal-information-financial": "personal-information-financial";
|
|
155
|
-
"personal-information-government-id": "personal-information-government-id";
|
|
156
|
-
"personal-information-historical": "personal-information-historical";
|
|
157
|
-
"personal-information-identifiers": "personal-information-identifiers";
|
|
158
|
-
"personal-information-location": "personal-information-location";
|
|
159
|
-
"personal-information-phone": "personal-information-phone";
|
|
160
|
-
"personal-information-request": "personal-information-request";
|
|
161
|
-
"personal-information-self-disclosure": "personal-information-self-disclosure";
|
|
162
|
-
"personal-information-support-prevention": "personal-information-support-prevention";
|
|
163
|
-
"personal-information-third-party": "personal-information-third-party";
|
|
164
|
-
"profanity-documentary": "profanity-documentary";
|
|
165
|
-
"profanity-educational": "profanity-educational";
|
|
166
|
-
"profanity-fictional": "profanity-fictional";
|
|
167
|
-
"profanity-historical": "profanity-historical";
|
|
168
|
-
"profanity-mild": "profanity-mild";
|
|
169
|
-
"profanity-obfuscated": "profanity-obfuscated";
|
|
170
|
-
"profanity-slurs": "profanity-slurs";
|
|
171
|
-
"profanity-strong": "profanity-strong";
|
|
172
|
-
"profanity-support-prevention": "profanity-support-prevention";
|
|
173
|
-
"self-harm-act": "self-harm-act";
|
|
174
|
-
"self-harm-age-restricted": "self-harm-age-restricted";
|
|
175
|
-
"self-harm-documentary": "self-harm-documentary";
|
|
176
|
-
"self-harm-educational": "self-harm-educational";
|
|
177
|
-
"self-harm-encouragement": "self-harm-encouragement";
|
|
178
|
-
"self-harm-fictional": "self-harm-fictional";
|
|
179
|
-
"self-harm-historical": "self-harm-historical";
|
|
180
|
-
"self-harm-methods": "self-harm-methods";
|
|
181
|
-
"self-harm-preparation": "self-harm-preparation";
|
|
182
|
-
"self-harm-support-prevention": "self-harm-support-prevention";
|
|
183
|
-
"self-harm-thoughts": "self-harm-thoughts";
|
|
184
|
-
"sexual-activity": "sexual-activity";
|
|
185
|
-
"sexual-adult-promotion": "sexual-adult-promotion";
|
|
186
|
-
"sexual-artistic": "sexual-artistic";
|
|
187
|
-
"sexual-assault-media": "sexual-assault-media";
|
|
188
|
-
"sexual-discussion": "sexual-discussion";
|
|
189
|
-
"sexual-documentary": "sexual-documentary";
|
|
190
|
-
"sexual-educational": "sexual-educational";
|
|
191
|
-
"sexual-explicit-language": "sexual-explicit-language";
|
|
192
|
-
"sexual-extreme": "sexual-extreme";
|
|
193
|
-
"sexual-fictional": "sexual-fictional";
|
|
194
|
-
"sexual-historical": "sexual-historical";
|
|
195
|
-
"sexual-incest": "sexual-incest";
|
|
196
|
-
"sexual-intimate-image-abuse": "sexual-intimate-image-abuse";
|
|
197
|
-
"sexual-minors": "sexual-minors";
|
|
198
|
-
"sexual-non-consensual": "sexual-non-consensual";
|
|
199
|
-
"sexual-non-erotic-nudity": "sexual-non-erotic-nudity";
|
|
200
|
-
"sexual-nudity": "sexual-nudity";
|
|
201
|
-
"sexual-paid": "sexual-paid";
|
|
202
|
-
"sexual-pornographic-media": "sexual-pornographic-media";
|
|
203
|
-
"sexual-revealing-clothing": "sexual-revealing-clothing";
|
|
204
|
-
"sexual-solicitation": "sexual-solicitation";
|
|
205
|
-
"sexual-strangulation": "sexual-strangulation";
|
|
206
|
-
"sexual-suggestive": "sexual-suggestive";
|
|
207
|
-
"sexual-support-prevention": "sexual-support-prevention";
|
|
208
|
-
"sexual-text": "sexual-text";
|
|
209
|
-
"violence-attack": "violence-attack";
|
|
210
|
-
"violence-coded-incitement": "violence-coded-incitement";
|
|
211
|
-
"violence-decapitation-act": "violence-decapitation-act";
|
|
212
|
-
"violence-discussion": "violence-discussion";
|
|
213
|
-
"violence-documentary": "violence-documentary";
|
|
214
|
-
"violence-educational": "violence-educational";
|
|
215
|
-
"violence-encouragement": "violence-encouragement";
|
|
216
|
-
"violence-extremism": "violence-extremism";
|
|
217
|
-
"violence-fantasy": "violence-fantasy";
|
|
218
|
-
"violence-fictional": "violence-fictional";
|
|
219
|
-
"violence-gore": "violence-gore";
|
|
220
|
-
"violence-graphic": "violence-graphic";
|
|
221
|
-
"violence-high-impact": "violence-high-impact";
|
|
222
|
-
"violence-historical": "violence-historical";
|
|
223
|
-
"violence-injury": "violence-injury";
|
|
224
|
-
"violence-natural-death": "violence-natural-death";
|
|
225
|
-
"violence-preparation": "violence-preparation";
|
|
226
|
-
"violence-sport": "violence-sport";
|
|
227
|
-
"violence-support-prevention": "violence-support-prevention";
|
|
228
|
-
"violence-text": "violence-text";
|
|
229
|
-
"violence-threat": "violence-threat";
|
|
230
|
-
"violence-violent-death": "violence-violent-death";
|
|
231
|
-
"violence-weapon": "violence-weapon";
|
|
232
|
-
"violence-wish": "violence-wish";
|
|
233
|
-
}>>;
|
|
108
|
+
qualifiers: z.ZodArray<z.ZodCustom<"criminal-activity-alcohol" | "criminal-activity-coded-incitement" | "criminal-activity-csam" | "criminal-activity-demonstration" | "criminal-activity-discussion" | "criminal-activity-documentary" | "criminal-activity-educational" | "criminal-activity-fictional" | "criminal-activity-fraud" | "criminal-activity-gambling" | "criminal-activity-graffiti" | "criminal-activity-grooming" | "criminal-activity-historical" | "criminal-activity-instructions" | "criminal-activity-preparation" | "criminal-activity-promotion" | "criminal-activity-request" | "criminal-activity-sexual-solicitation" | "criminal-activity-substances" | "criminal-activity-support-prevention" | "criminal-activity-tobacco" | "harassment-abuse" | "harassment-bullying" | "harassment-documentary" | "harassment-educational" | "harassment-encouragement" | "harassment-fictional" | "harassment-historical" | "harassment-mild" | "harassment-public-target" | "harassment-sexual" | "harassment-support-prevention" | "harassment-threat" | "hate-abuse" | "hate-adjudicated-nazi-crimes-denial" | "hate-counterspeech" | "hate-dehumanization" | "hate-documentary" | "hate-educational" | "hate-exclusion" | "hate-fictional" | "hate-historical" | "hate-hostility" | "hate-inferiority" | "hate-nazi-genocide-denial-or-approval" | "hate-nazi-genocide-public-peace" | "hate-nazi-insignia-public-display" | "hate-nazi-symbols-public-display" | "hate-personal" | "hate-slurs" | "hate-support-prevention" | "hate-symbol" | "hate-threat" | "personal-information-contact" | "personal-information-credentials" | "personal-information-documentary" | "personal-information-educational" | "personal-information-email" | "personal-information-fictional" | "personal-information-financial" | "personal-information-government-id" | "personal-information-historical" | "personal-information-identifiers" | "personal-information-location" | "personal-information-phone" | "personal-information-request" | "personal-information-self-disclosure" | "personal-information-support-prevention" | "personal-information-third-party" | "profanity-documentary" | "profanity-educational" | "profanity-fictional" | "profanity-historical" | "profanity-mild" | "profanity-obfuscated" | "profanity-slurs" | "profanity-strong" | "profanity-support-prevention" | "self-harm-act" | "self-harm-age-restricted" | "self-harm-documentary" | "self-harm-educational" | "self-harm-encouragement" | "self-harm-fictional" | "self-harm-historical" | "self-harm-methods" | "self-harm-preparation" | "self-harm-support-prevention" | "self-harm-thoughts" | "sexual-activity" | "sexual-adult-promotion" | "sexual-artistic" | "sexual-assault-media" | "sexual-discussion" | "sexual-documentary" | "sexual-educational" | "sexual-explicit-language" | "sexual-extreme" | "sexual-fictional" | "sexual-historical" | "sexual-incest" | "sexual-intimate-image-abuse" | "sexual-minors" | "sexual-non-consensual" | "sexual-non-erotic-nudity" | "sexual-nudity" | "sexual-paid" | "sexual-pornographic-media" | "sexual-revealing-clothing" | "sexual-solicitation" | "sexual-strangulation" | "sexual-suggestive" | "sexual-support-prevention" | "sexual-text" | "violence-attack" | "violence-coded-incitement" | "violence-decapitation-act" | "violence-discussion" | "violence-documentary" | "violence-educational" | "violence-encouragement" | "violence-extremism" | "violence-fantasy" | "violence-fictional" | "violence-gore" | "violence-graphic" | "violence-high-impact" | "violence-historical" | "violence-injury" | "violence-natural-death" | "violence-preparation" | "violence-sport" | "violence-support-prevention" | "violence-text" | "violence-threat" | "violence-violent-death" | "violence-weapon" | "violence-wish", "criminal-activity-alcohol" | "criminal-activity-coded-incitement" | "criminal-activity-csam" | "criminal-activity-demonstration" | "criminal-activity-discussion" | "criminal-activity-documentary" | "criminal-activity-educational" | "criminal-activity-fictional" | "criminal-activity-fraud" | "criminal-activity-gambling" | "criminal-activity-graffiti" | "criminal-activity-grooming" | "criminal-activity-historical" | "criminal-activity-instructions" | "criminal-activity-preparation" | "criminal-activity-promotion" | "criminal-activity-request" | "criminal-activity-sexual-solicitation" | "criminal-activity-substances" | "criminal-activity-support-prevention" | "criminal-activity-tobacco" | "harassment-abuse" | "harassment-bullying" | "harassment-documentary" | "harassment-educational" | "harassment-encouragement" | "harassment-fictional" | "harassment-historical" | "harassment-mild" | "harassment-public-target" | "harassment-sexual" | "harassment-support-prevention" | "harassment-threat" | "hate-abuse" | "hate-adjudicated-nazi-crimes-denial" | "hate-counterspeech" | "hate-dehumanization" | "hate-documentary" | "hate-educational" | "hate-exclusion" | "hate-fictional" | "hate-historical" | "hate-hostility" | "hate-inferiority" | "hate-nazi-genocide-denial-or-approval" | "hate-nazi-genocide-public-peace" | "hate-nazi-insignia-public-display" | "hate-nazi-symbols-public-display" | "hate-personal" | "hate-slurs" | "hate-support-prevention" | "hate-symbol" | "hate-threat" | "personal-information-contact" | "personal-information-credentials" | "personal-information-documentary" | "personal-information-educational" | "personal-information-email" | "personal-information-fictional" | "personal-information-financial" | "personal-information-government-id" | "personal-information-historical" | "personal-information-identifiers" | "personal-information-location" | "personal-information-phone" | "personal-information-request" | "personal-information-self-disclosure" | "personal-information-support-prevention" | "personal-information-third-party" | "profanity-documentary" | "profanity-educational" | "profanity-fictional" | "profanity-historical" | "profanity-mild" | "profanity-obfuscated" | "profanity-slurs" | "profanity-strong" | "profanity-support-prevention" | "self-harm-act" | "self-harm-age-restricted" | "self-harm-documentary" | "self-harm-educational" | "self-harm-encouragement" | "self-harm-fictional" | "self-harm-historical" | "self-harm-methods" | "self-harm-preparation" | "self-harm-support-prevention" | "self-harm-thoughts" | "sexual-activity" | "sexual-adult-promotion" | "sexual-artistic" | "sexual-assault-media" | "sexual-discussion" | "sexual-documentary" | "sexual-educational" | "sexual-explicit-language" | "sexual-extreme" | "sexual-fictional" | "sexual-historical" | "sexual-incest" | "sexual-intimate-image-abuse" | "sexual-minors" | "sexual-non-consensual" | "sexual-non-erotic-nudity" | "sexual-nudity" | "sexual-paid" | "sexual-pornographic-media" | "sexual-revealing-clothing" | "sexual-solicitation" | "sexual-strangulation" | "sexual-suggestive" | "sexual-support-prevention" | "sexual-text" | "violence-attack" | "violence-coded-incitement" | "violence-decapitation-act" | "violence-discussion" | "violence-documentary" | "violence-educational" | "violence-encouragement" | "violence-extremism" | "violence-fantasy" | "violence-fictional" | "violence-gore" | "violence-graphic" | "violence-high-impact" | "violence-historical" | "violence-injury" | "violence-natural-death" | "violence-preparation" | "violence-sport" | "violence-support-prevention" | "violence-text" | "violence-threat" | "violence-violent-death" | "violence-weapon" | "violence-wish">>;
|
|
234
109
|
}, z.core.$strict>>;
|
|
235
110
|
detections: z.ZodOptional<z.ZodObject<{
|
|
236
111
|
people: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodObject<{
|
|
@@ -402,4 +277,23 @@ declare function detectTestImage(image: RgbaImage, key: string,
|
|
|
402
277
|
}[] | undefined;
|
|
403
278
|
} | undefined;
|
|
404
279
|
} | undefined>;
|
|
405
|
-
|
|
280
|
+
declare const MEDIA_TEST_SIGNALS: readonly ["sexual", "violence", "self-harm", "harassment", "hate", "criminal-activity", "personal-information", "profanity", "violence.graphic"];
|
|
281
|
+
/** A spoken media test phrase for `signal`, signed with the project's test input key. */
|
|
282
|
+
declare const generateMediaTestCode: (signal: ClassificationTestSignal, key: string) => Promise<string>;
|
|
283
|
+
/** A text code for `scenario`, signed with the project's test input key. */
|
|
284
|
+
declare const generateTestTextCode: (scenario: TestInput | ClassificationTestSignal, key: string) => Promise<string>;
|
|
285
|
+
/** A painted test image: its RGBA pixels, row by row, and the same image as PNG bytes. */
|
|
286
|
+
interface TestImage {
|
|
287
|
+
width: number;
|
|
288
|
+
height: number;
|
|
289
|
+
rgba: Uint8Array;
|
|
290
|
+
/** The image as a PNG, to upload as it is. */
|
|
291
|
+
png: Uint8Array;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* The test image for `scenario`, signed with the project's test input key. Upload its `png` bytes
|
|
295
|
+
* (or encode `rgba` in another format: the image survives lossy formats and resizing) as the whole
|
|
296
|
+
* image, optionally on a plain single-colour border.
|
|
297
|
+
*/
|
|
298
|
+
declare const paintTestImage: (scenario: TestInput | ClassificationTestSignal, key: string) => Promise<TestImage>;
|
|
299
|
+
export { detectTestTrigger as _, MEDIA_TEST_SIGNALS as a, testInputForSignal as b, TEST_DETECTION_BOX_MAX as c, TEST_INPUT_KEY_PATTERN as d, TEST_INPUT_PRESETS as f, detectTestImage as g, TestInput as h, paintTestImage as i, TEST_FACE_AGE_MAX as l, TestDetections as m, generateMediaTestCode as n, ClassificationTestSignal as o, TEST_INPUT_QUALIFIER_ERRORS as p, generateTestTextCode as r, TEST_DETECTIONS_MAX as s, TestImage as t, TEST_FACE_AGE_PRESETS as u, getImageTestCategories as v, getTestInputQualifiers as y };
|
package/esm/test-inputs.d.ts
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
3
|
-
export declare const generateTestTextCode: (scenario: TestInput | ClassificationTestSignal, key: string) => Promise<string>;
|
|
4
|
-
/** A painted test image: its RGBA pixels, row by row, and the same image as PNG bytes. */
|
|
5
|
-
export interface TestImage {
|
|
6
|
-
width: number;
|
|
7
|
-
height: number;
|
|
8
|
-
rgba: Uint8Array;
|
|
9
|
-
/** The image as a PNG, to upload as it is. */
|
|
10
|
-
png: Uint8Array;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* The test image for `scenario`, signed with the project's test input key. Upload its `png` bytes
|
|
14
|
-
* (or encode `rgba` in another format: the image survives lossy formats and resizing) as the whole
|
|
15
|
-
* image, optionally on a plain single-colour border.
|
|
16
|
-
*/
|
|
17
|
-
export declare const paintTestImage: (scenario: TestInput | ClassificationTestSignal, key: string) => Promise<TestImage>;
|
|
18
|
-
export { type ClassificationTestSignal, TEST_DETECTIONS_MAX, TEST_DETECTION_BOX_MAX, TEST_FACE_AGE_MAX, TEST_FACE_AGE_PRESETS, TEST_INPUT_KEY_PATTERN, TEST_INPUT_PRESETS, type TestDetections, type TestInput, detectTestImage, detectTestTrigger, getImageTestCategories, testInputForSignal };
|
|
1
|
+
import { _ as detectTestTrigger, a as MEDIA_TEST_SIGNALS, b as testInputForSignal, c as TEST_DETECTION_BOX_MAX, d as TEST_INPUT_KEY_PATTERN, f as TEST_INPUT_PRESETS, g as detectTestImage, h as TestInput, i as paintTestImage, l as TEST_FACE_AGE_MAX, m as TestDetections, n as generateMediaTestCode, o as ClassificationTestSignal, p as TEST_INPUT_QUALIFIER_ERRORS, r as generateTestTextCode, s as TEST_DETECTIONS_MAX, t as TestImage, u as TEST_FACE_AGE_PRESETS, v as getImageTestCategories, y as getTestInputQualifiers } from "./test-inputs-fugEK0py.js";
|
|
2
|
+
export { type ClassificationTestSignal, MEDIA_TEST_SIGNALS, TEST_DETECTIONS_MAX, TEST_DETECTION_BOX_MAX, TEST_FACE_AGE_MAX, TEST_FACE_AGE_PRESETS, TEST_INPUT_KEY_PATTERN, TEST_INPUT_PRESETS, TEST_INPUT_QUALIFIER_ERRORS, type TestDetections, TestImage, type TestInput, detectTestImage, detectTestTrigger, generateMediaTestCode, generateTestTextCode, getImageTestCategories, getTestInputQualifiers, paintTestImage, testInputForSignal };
|
package/esm/test-inputs.js
CHANGED
|
@@ -1,115 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// src/client/TestImagePng.ts
|
|
3
|
-
/**
|
|
4
|
-
* Encodes a painted test image as a PNG: 8-bit RGBA rows without filtering in stored deflate
|
|
5
|
-
* blocks, as every SDK writes it, so the bytes match across SDKs. Runs anywhere, with no
|
|
6
|
-
* compression library.
|
|
7
|
-
*/
|
|
8
|
-
function encodeTestImagePng(width, height, rgba) {
|
|
9
|
-
const stride = width * 4;
|
|
10
|
-
const raw = new Uint8Array((stride + 1) * height);
|
|
11
|
-
for (let row = 0; row < height; row++) raw.set(rgba.subarray(row * stride, (row + 1) * stride), row * (stride + 1) + 1);
|
|
12
|
-
const blocks = Math.max(1, Math.ceil(raw.length / 65535));
|
|
13
|
-
const stream = new Uint8Array(2 + raw.length + blocks * 5 + 4);
|
|
14
|
-
stream.set([120, 1]);
|
|
15
|
-
let position = 2;
|
|
16
|
-
for (let offset = 0; offset < raw.length || position === 2; offset += 65535) {
|
|
17
|
-
const block = raw.subarray(offset, offset + 65535);
|
|
18
|
-
const length = block.length;
|
|
19
|
-
stream.set([
|
|
20
|
-
offset + length >= raw.length ? 1 : 0,
|
|
21
|
-
length & 255,
|
|
22
|
-
length >> 8,
|
|
23
|
-
~length & 255,
|
|
24
|
-
~length >> 8 & 255
|
|
25
|
-
], position);
|
|
26
|
-
stream.set(block, position + 5);
|
|
27
|
-
position += 5 + length;
|
|
28
|
-
}
|
|
29
|
-
writeUint32(stream, position, adler32(raw));
|
|
30
|
-
const header = /* @__PURE__ */ new Uint8Array(13);
|
|
31
|
-
writeUint32(header, 0, width);
|
|
32
|
-
writeUint32(header, 4, height);
|
|
33
|
-
header.set([
|
|
34
|
-
8,
|
|
35
|
-
6,
|
|
36
|
-
0,
|
|
37
|
-
0,
|
|
38
|
-
0
|
|
39
|
-
], 8);
|
|
40
|
-
return concat([
|
|
41
|
-
Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10),
|
|
42
|
-
chunk("IHDR", header),
|
|
43
|
-
chunk("IDAT", stream),
|
|
44
|
-
chunk("IEND", /* @__PURE__ */ new Uint8Array(0))
|
|
45
|
-
]);
|
|
46
|
-
}
|
|
47
|
-
function chunk(kind, body) {
|
|
48
|
-
const typed = new Uint8Array(4 + body.length);
|
|
49
|
-
for (let i = 0; i < 4; i++) typed[i] = kind.charCodeAt(i);
|
|
50
|
-
typed.set(body, 4);
|
|
51
|
-
const out = new Uint8Array(12 + body.length);
|
|
52
|
-
writeUint32(out, 0, body.length);
|
|
53
|
-
out.set(typed, 4);
|
|
54
|
-
writeUint32(out, 8 + body.length, crc32(typed));
|
|
55
|
-
return out;
|
|
56
|
-
}
|
|
57
|
-
function writeUint32(target, offset, value) {
|
|
58
|
-
target[offset] = value >>> 24;
|
|
59
|
-
target[offset + 1] = value >>> 16 & 255;
|
|
60
|
-
target[offset + 2] = value >>> 8 & 255;
|
|
61
|
-
target[offset + 3] = value & 255;
|
|
62
|
-
}
|
|
63
|
-
function concat(parts) {
|
|
64
|
-
const out = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
65
|
-
let offset = 0;
|
|
66
|
-
for (const part of parts) {
|
|
67
|
-
out.set(part, offset);
|
|
68
|
-
offset += part.length;
|
|
69
|
-
}
|
|
70
|
-
return out;
|
|
71
|
-
}
|
|
72
|
-
let crcTable;
|
|
73
|
-
function crc32(bytes) {
|
|
74
|
-
if (!crcTable) {
|
|
75
|
-
crcTable = /* @__PURE__ */ new Uint32Array(256);
|
|
76
|
-
for (let n = 0; n < 256; n++) {
|
|
77
|
-
let c = n;
|
|
78
|
-
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
79
|
-
crcTable[n] = c >>> 0;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
let crc = 4294967295;
|
|
83
|
-
for (const byte of bytes) crc = crcTable[(crc ^ byte) & 255] ^ crc >>> 8;
|
|
84
|
-
return (crc ^ 4294967295) >>> 0;
|
|
85
|
-
}
|
|
86
|
-
function adler32(bytes) {
|
|
87
|
-
let a = 1;
|
|
88
|
-
let b = 0;
|
|
89
|
-
for (const byte of bytes) {
|
|
90
|
-
a = (a + byte) % 65521;
|
|
91
|
-
b = (b + a) % 65521;
|
|
92
|
-
}
|
|
93
|
-
return (b << 16 | a) >>> 0;
|
|
94
|
-
}
|
|
95
|
-
// src/test-inputs.ts
|
|
96
|
-
/**
|
|
97
|
-
* Portable test inputs: presets and custom instances share one authenticated format. CalmLens
|
|
98
|
-
* recognises a code only as the whole text and a test image only as the whole
|
|
99
|
-
* upload, signed with the project's own key.
|
|
100
|
-
*/
|
|
101
|
-
/** A text code for `scenario`, signed with the project's test input key. */
|
|
102
|
-
const generateTestTextCode = (scenario, key) => withValidTestInputArguments(key, () => generateTestTextCode$1(scenario, key));
|
|
103
|
-
/**
|
|
104
|
-
* The test image for `scenario`, signed with the project's test input key. Upload its `png` bytes
|
|
105
|
-
* (or encode `rgba` in another format: the image survives lossy formats and resizing) as the whole
|
|
106
|
-
* image, optionally on a plain single-colour border.
|
|
107
|
-
*/
|
|
108
|
-
const paintTestImage = async (scenario, key) => {
|
|
109
|
-
const image = await withValidTestInputArguments(key, () => paintTestImage$1(scenario, key));
|
|
110
|
-
return {
|
|
111
|
-
...image,
|
|
112
|
-
png: encodeTestImagePng(image.width, image.height, image.rgba)
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
export { TEST_DETECTIONS_MAX, TEST_DETECTION_BOX_MAX, TEST_FACE_AGE_MAX, TEST_FACE_AGE_PRESETS, TEST_INPUT_KEY_PATTERN, TEST_INPUT_PRESETS, detectTestImage, detectTestTrigger, generateTestTextCode, getImageTestCategories, paintTestImage, testInputForSignal };
|
|
1
|
+
export { i as MEDIA_TEST_SIGNALS, a as TEST_DETECTIONS_MAX, o as TEST_DETECTION_BOX_MAX, s as TEST_FACE_AGE_MAX, c as TEST_FACE_AGE_PRESETS, l as TEST_INPUT_KEY_PATTERN, u as TEST_INPUT_PRESETS, d as TEST_INPUT_QUALIFIER_ERRORS, f as detectTestImage, p as detectTestTrigger, t as generateMediaTestCode, n as generateTestTextCode, m as getImageTestCategories, h as getTestInputQualifiers, r as paintTestImage, g as testInputForSignal } from "./test-inputs-BLlkOmNC.js";
|