@cloakapi/sdk 1.5.0 → 1.6.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/CHANGELOG.md +13 -0
- package/README.md +24 -4
- package/dist/browser/index.d.mts +99 -89
- package/dist/browser/index.d.ts +99 -89
- package/dist/browser/index.js +1245 -123
- package/dist/browser/index.mjs +24 -8
- package/dist/browser/light.d.mts +3 -2
- package/dist/browser/light.d.ts +3 -2
- package/dist/browser/light.js +1 -1
- package/dist/browser/light.mjs +17 -2
- package/dist/browser/names/public.mjs +2 -2
- package/dist/browser/ner-pipeline-worker.mjs +3 -3
- package/dist/{chunk-6TMC2A6M.mjs → chunk-3MXGO6NA.mjs} +12 -8
- package/dist/{chunk-G6TZ6722.mjs → chunk-6E6T2YO5.mjs} +5 -915
- package/dist/{chunk-EY35G37A.mjs → chunk-746IWCJ4.mjs} +224 -1
- package/dist/chunk-L7RLVZMD.mjs +922 -0
- package/dist/{chunk-JV52VGVZ.mjs → chunk-TRWGRB2P.mjs} +1 -1
- package/dist/chunk-TWAQCP3Z.mjs +1258 -0
- package/dist/{chunk-36BC4GYL.mjs → chunk-VYGV643D.mjs} +262 -122
- package/dist/device/index.d.mts +1448 -0
- package/dist/device/index.d.ts +1448 -0
- package/dist/device/index.js +4539 -0
- package/dist/device/index.mjs +2462 -0
- package/dist/{disclosure-Cx6xS8Tj.d.mts → disclosure-BhM2Aqa2.d.mts} +2 -12
- package/dist/{disclosure-Cx6xS8Tj.d.ts → disclosure-BhM2Aqa2.d.ts} +2 -12
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +14 -12
- package/dist/{local-pii-supplement-SUOJZO7X.mjs → local-pii-supplement-5KFFPDDN.mjs} +4 -4
- package/dist/node.d.mts +2 -1
- package/dist/node.d.ts +2 -1
- package/dist/node.js +311 -58
- package/dist/node.mjs +18 -12
- package/dist/request-body-slots-BMShK1YO.d.mts +56 -0
- package/dist/request-body-slots-BMShK1YO.d.ts +56 -0
- package/package.json +9 -2
- package/dist/{chunk-PEDVEDAW.mjs → chunk-66SEKCCN.mjs} +8 -8
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensurePlaceData,
|
|
3
|
+
isPlaceIndexReady,
|
|
4
|
+
prewarmPlaceIndex,
|
|
5
|
+
scanGazetteerPlaces
|
|
6
|
+
} from "./chunk-DLKR3ZVZ.mjs";
|
|
1
7
|
import {
|
|
2
8
|
__wbg_init,
|
|
3
9
|
engine_hash,
|
|
@@ -11,31 +17,25 @@ import {
|
|
|
11
17
|
assertClientTokenisationProof,
|
|
12
18
|
assertEnginePin,
|
|
13
19
|
assertExactReview,
|
|
14
|
-
assertRequestBodyReviewable,
|
|
15
|
-
assertRequestBodySlotReviewable,
|
|
16
|
-
collectRequestBodyTextSlots,
|
|
17
|
-
collectValuePlacementWarnings,
|
|
18
|
-
deepClone,
|
|
19
20
|
detectPii,
|
|
20
21
|
engineIdentityHeaders,
|
|
21
22
|
inspectClientTokenisation,
|
|
22
23
|
inspectResidual,
|
|
23
24
|
lowerCoverage,
|
|
24
|
-
maskArgumentKeysForResidualCheck,
|
|
25
|
-
metadataKeyOutcomeWarnings,
|
|
26
25
|
refuseIfKnownResidual,
|
|
27
26
|
refuseIfResidual,
|
|
28
|
-
replaceObjectKeysAsync,
|
|
29
|
-
slotIsLeftAsWritten,
|
|
30
27
|
tokenizedHeaderValue,
|
|
31
28
|
validateGatewayBaseUrl,
|
|
32
29
|
warningsForResidual
|
|
33
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-6E6T2YO5.mjs";
|
|
34
31
|
import {
|
|
32
|
+
applyPrivacyModeRewrite,
|
|
35
33
|
bindFullBrowserModule,
|
|
36
34
|
canonicalise,
|
|
35
|
+
copyPrivacyLedger,
|
|
36
|
+
privacyLedgerFor,
|
|
37
37
|
privacyPosture
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-746IWCJ4.mjs";
|
|
39
39
|
import {
|
|
40
40
|
DEFAULT_SURROGATE_MODE,
|
|
41
41
|
RULESET_HASH,
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
disclosureText,
|
|
44
44
|
resolveSurrogateMode,
|
|
45
45
|
withDisclosure
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-TRWGRB2P.mjs";
|
|
47
47
|
import {
|
|
48
48
|
abortEnhancedNerLoad,
|
|
49
49
|
detectionLayerReport,
|
|
@@ -52,12 +52,23 @@ import {
|
|
|
52
52
|
resolvePinnedModelMirrorUrl,
|
|
53
53
|
resolveSameOriginMirrorUrl,
|
|
54
54
|
resolveSameOriginWorkerUrl
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-3MXGO6NA.mjs";
|
|
56
56
|
import {
|
|
57
57
|
hasWholeTokenOccurrence,
|
|
58
58
|
indexOfWholeToken,
|
|
59
59
|
replaceWholeTokenOccurrences
|
|
60
60
|
} from "./chunk-QIORVVUD.mjs";
|
|
61
|
+
import {
|
|
62
|
+
assertRequestBodyReviewable,
|
|
63
|
+
assertRequestBodySlotReviewable,
|
|
64
|
+
collectRequestBodyTextSlots,
|
|
65
|
+
collectValuePlacementWarnings,
|
|
66
|
+
deepClone,
|
|
67
|
+
maskArgumentKeysForResidualCheck,
|
|
68
|
+
metadataKeyOutcomeWarnings,
|
|
69
|
+
replaceObjectKeysAsync,
|
|
70
|
+
slotIsLeftAsWritten
|
|
71
|
+
} from "./chunk-L7RLVZMD.mjs";
|
|
61
72
|
import {
|
|
62
73
|
SURROGATE_SALT,
|
|
63
74
|
activePersonModelTier,
|
|
@@ -78,7 +89,7 @@ import {
|
|
|
78
89
|
setPlaceDataLoader,
|
|
79
90
|
setPlaceGazetteerScanner,
|
|
80
91
|
spanIsAllCommonWords
|
|
81
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-66SEKCCN.mjs";
|
|
82
93
|
import {
|
|
83
94
|
_installNerUnavailableError,
|
|
84
95
|
assertNerCoverage,
|
|
@@ -86,12 +97,6 @@ import {
|
|
|
86
97
|
enhancedNerRequirement,
|
|
87
98
|
isCoverageAcceptance
|
|
88
99
|
} from "./chunk-MOHR4UIG.mjs";
|
|
89
|
-
import {
|
|
90
|
-
ensurePlaceData,
|
|
91
|
-
isPlaceIndexReady,
|
|
92
|
-
prewarmPlaceIndex,
|
|
93
|
-
scanGazetteerPlaces
|
|
94
|
-
} from "./chunk-DLKR3ZVZ.mjs";
|
|
95
100
|
|
|
96
101
|
// src/browser/sha256.ts
|
|
97
102
|
var ROUND_CONSTANTS = new Uint32Array([
|
|
@@ -548,7 +553,7 @@ async function startInWorker() {
|
|
|
548
553
|
async function localSupplement(wire) {
|
|
549
554
|
const { ensurePlaceData: ensurePlaceData2 } = await import("./locale-name-data-QGUQD5PX.mjs");
|
|
550
555
|
await ensurePlaceData2();
|
|
551
|
-
const { applySupplement: applySupplement2 } = await import("./local-pii-supplement-
|
|
556
|
+
const { applySupplement: applySupplement2 } = await import("./local-pii-supplement-5KFFPDDN.mjs");
|
|
552
557
|
const { __acceptanceFromWire } = await import("./ner-availability-5EVZJGL2.mjs");
|
|
553
558
|
return applySupplement2(wire.text, {
|
|
554
559
|
apply: wire.apply,
|
|
@@ -1653,13 +1658,15 @@ function newConversation() {
|
|
|
1653
1658
|
};
|
|
1654
1659
|
}
|
|
1655
1660
|
function cloneConversation(c) {
|
|
1656
|
-
|
|
1661
|
+
const copy = {
|
|
1657
1662
|
seedHex: c.seedHex,
|
|
1658
1663
|
salt: c.salt,
|
|
1659
1664
|
bindings: new Map(c.bindings),
|
|
1660
1665
|
claimed: new Map(c.claimed),
|
|
1661
1666
|
counters: new Map(c.counters)
|
|
1662
1667
|
};
|
|
1668
|
+
copyPrivacyLedger(c, copy);
|
|
1669
|
+
return copy;
|
|
1663
1670
|
}
|
|
1664
1671
|
var MAX_LABELS = Object.freeze({
|
|
1665
1672
|
PERSON: "PERSON",
|
|
@@ -2210,6 +2217,7 @@ var FORMATS = /* @__PURE__ */ new Set([
|
|
|
2210
2217
|
"pdf",
|
|
2211
2218
|
"svg",
|
|
2212
2219
|
"png"
|
|
2220
|
+
// Accepted as a request. The builder may report an SVG substitution.
|
|
2213
2221
|
]);
|
|
2214
2222
|
function isObj(v) {
|
|
2215
2223
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
@@ -2641,7 +2649,7 @@ async function buildDocx(spec, bindings, map) {
|
|
|
2641
2649
|
const blocks = spec.blocks && spec.blocks.length ? spec.blocks : [{ type: "table", columns: spec.columns, rows: spec.rows }];
|
|
2642
2650
|
const titleXml = spec.title ? runP(detokeniseString(spec.title, map), { style: "Title", bold: true, size: 20 }) : "";
|
|
2643
2651
|
const body = titleXml + renderBlocks(blocks, bindings, map);
|
|
2644
|
-
const
|
|
2652
|
+
const document2 = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body>${body}<w:sectPr><w:pgSz w:w="12240" w:h="15840"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"/></w:sectPr></w:body></w:document>`;
|
|
2645
2653
|
const styles = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:style w:type="paragraph" w:styleId="Title"><w:name w:val="Title"/></w:style><w:style w:type="paragraph" w:styleId="Heading1"><w:name w:val="heading 1"/></w:style><w:style w:type="paragraph" w:styleId="Heading2"><w:name w:val="heading 2"/></w:style><w:style w:type="paragraph" w:styleId="Heading3"><w:name w:val="heading 3"/></w:style></w:styles>`;
|
|
2646
2654
|
const contentTypes = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/><Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/></Types>`;
|
|
2647
2655
|
const rootRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>`;
|
|
@@ -2649,7 +2657,7 @@ async function buildDocx(spec, bindings, map) {
|
|
|
2649
2657
|
const entries = [
|
|
2650
2658
|
{ path: "[Content_Types].xml", data: contentTypes },
|
|
2651
2659
|
{ path: "_rels/.rels", data: rootRels },
|
|
2652
|
-
{ path: "word/document.xml", data:
|
|
2660
|
+
{ path: "word/document.xml", data: document2 },
|
|
2653
2661
|
{ path: "word/styles.xml", data: styles },
|
|
2654
2662
|
{ path: "word/_rels/document.xml.rels", data: docRels }
|
|
2655
2663
|
];
|
|
@@ -2985,7 +2993,44 @@ function niceMax(v) {
|
|
|
2985
2993
|
const step = norm <= 1 ? 1 : norm <= 2 ? 2 : norm <= 5 ? 5 : 10;
|
|
2986
2994
|
return step * mag;
|
|
2987
2995
|
}
|
|
2996
|
+
var FONT_FAMILY = "system-ui,-apple-system,Segoe UI,Roboto,sans-serif";
|
|
2988
2997
|
function chartToSvg(c, theme = "light") {
|
|
2998
|
+
const { width, height } = c;
|
|
2999
|
+
const parts = [
|
|
3000
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" font-family="${FONT_FAMILY}">`
|
|
3001
|
+
];
|
|
3002
|
+
drawChart(c, theme, {
|
|
3003
|
+
rect(x, y, w, h, fill, radius) {
|
|
3004
|
+
const position = radius === void 0 ? "" : `x="${x}" y="${y}" `;
|
|
3005
|
+
const rounded = radius === void 0 ? "" : ` rx="${radius}"`;
|
|
3006
|
+
parts.push(`<rect ${position}width="${w}" height="${h}"${rounded} fill="${fill}"/>`);
|
|
3007
|
+
},
|
|
3008
|
+
line(x1, y1, x2, y2, stroke) {
|
|
3009
|
+
parts.push(`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${stroke}" stroke-width="1"/>`);
|
|
3010
|
+
},
|
|
3011
|
+
text(x, y, text, size, fill, anchor, style) {
|
|
3012
|
+
const alignment = anchor ? ` text-anchor="${anchor}"` : "";
|
|
3013
|
+
const weight = style === "title" ? ' font-weight="600"' : "";
|
|
3014
|
+
const transform = style === "vertical" ? ` transform="rotate(-90 ${x} ${y})"` : "";
|
|
3015
|
+
parts.push(`<text x="${x}" y="${y}" font-size="${size}"${alignment}${weight} fill="${fill}"${transform}>${xmlEscape(text)}</text>`);
|
|
3016
|
+
},
|
|
3017
|
+
circle(x, y, radius, fill, opacity) {
|
|
3018
|
+
const alpha = opacity === void 0 ? "" : ` fill-opacity="${opacity}"`;
|
|
3019
|
+
parts.push(`<circle cx="${x}" cy="${y}" r="${radius}" fill="${fill}"${alpha}/>`);
|
|
3020
|
+
},
|
|
3021
|
+
polyline(points, stroke) {
|
|
3022
|
+
const coordinates = points.map(([x, y]) => `${x},${y}`).join(" ");
|
|
3023
|
+
parts.push(`<polyline points="${coordinates}" fill="none" stroke="${stroke}" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>`);
|
|
3024
|
+
},
|
|
3025
|
+
slice(x, y, r, start, end, large, fill, stroke) {
|
|
3026
|
+
const point = (a) => `${(x + r * Math.cos(a)).toFixed(2)} ${(y + r * Math.sin(a)).toFixed(2)}`;
|
|
3027
|
+
parts.push(`<path d="M ${x} ${y} L ${point(start)} A ${r} ${r} 0 ${large} 1 ${point(end)} Z" fill="${fill}" stroke="${stroke}" stroke-width="2"/>`);
|
|
3028
|
+
}
|
|
3029
|
+
});
|
|
3030
|
+
parts.push("</svg>");
|
|
3031
|
+
return parts.join("");
|
|
3032
|
+
}
|
|
3033
|
+
function drawChart(c, theme, drawing) {
|
|
2989
3034
|
const W = c.width;
|
|
2990
3035
|
const H = c.height;
|
|
2991
3036
|
const ink = INK[theme];
|
|
@@ -2996,13 +3041,8 @@ function chartToSvg(c, theme = "light") {
|
|
|
2996
3041
|
const plotH = H - pad.top - pad.bottom - legendH;
|
|
2997
3042
|
const x0 = pad.left;
|
|
2998
3043
|
const y0 = pad.top;
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
`<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" font-family="system-ui,-apple-system,Segoe UI,Roboto,sans-serif">`
|
|
3002
|
-
);
|
|
3003
|
-
parts.push(`<rect width="${W}" height="${H}" fill="${surface}"/>`);
|
|
3004
|
-
if (c.title) parts.push(`<text x="${x0}" y="28" font-size="17" font-weight="600" fill="${ink.primary}">${xmlEscape(c.title)}</text>`);
|
|
3005
|
-
const gridLine = (x1, yy1, x2, yy2) => `<line x1="${x1}" y1="${yy1}" x2="${x2}" y2="${yy2}" stroke="${ink.grid}" stroke-width="1"/>`;
|
|
3044
|
+
drawing.rect(0, 0, W, H, surface);
|
|
3045
|
+
if (c.title) drawing.text(x0, 28, c.title, 17, ink.primary, void 0, "title");
|
|
3006
3046
|
if (c.type === "pie") {
|
|
3007
3047
|
const vals = c.series.length ? c.series[0].values : [];
|
|
3008
3048
|
const total = vals.reduce((a, b) => a + Math.max(0, b), 0) || 1;
|
|
@@ -3013,24 +3053,16 @@ function chartToSvg(c, theme = "light") {
|
|
|
3013
3053
|
vals.forEach((v, i) => {
|
|
3014
3054
|
const frac = Math.max(0, v) / total;
|
|
3015
3055
|
const a1 = a0 + frac * 2 * Math.PI;
|
|
3016
|
-
|
|
3017
|
-
const px0 = cx + r * Math.cos(a0);
|
|
3018
|
-
const py0 = cy + r * Math.sin(a0);
|
|
3019
|
-
const px1 = cx + r * Math.cos(a1);
|
|
3020
|
-
const py1 = cy + r * Math.sin(a1);
|
|
3021
|
-
parts.push(
|
|
3022
|
-
`<path d="M ${cx} ${cy} L ${px0.toFixed(2)} ${py0.toFixed(2)} A ${r} ${r} 0 ${large} 1 ${px1.toFixed(2)} ${py1.toFixed(2)} Z" fill="${categorical(i, theme)}" stroke="${surface}" stroke-width="2"/>`
|
|
3023
|
-
);
|
|
3056
|
+
drawing.slice(cx, cy, r, a0, a1, frac > 0.5 ? 1 : 0, categorical(i, theme), surface);
|
|
3024
3057
|
a0 = a1;
|
|
3025
3058
|
});
|
|
3026
3059
|
c.categories.forEach((cat, i) => {
|
|
3027
3060
|
const ly = y0 + plotH + 20 + Math.floor(i / 4) * 18;
|
|
3028
3061
|
const lx = x0 + i % 4 * (plotW / 4);
|
|
3029
|
-
|
|
3030
|
-
|
|
3062
|
+
drawing.rect(lx, ly - 9, 10, 10, categorical(i, theme), 2);
|
|
3063
|
+
drawing.text(lx + 15, ly, cat, 12, ink.secondary);
|
|
3031
3064
|
});
|
|
3032
|
-
|
|
3033
|
-
return parts.join("");
|
|
3065
|
+
return;
|
|
3034
3066
|
}
|
|
3035
3067
|
let maxY = 0;
|
|
3036
3068
|
let minY = 0;
|
|
@@ -3051,11 +3083,11 @@ function chartToSvg(c, theme = "light") {
|
|
|
3051
3083
|
for (let t = 0; t <= 4; t++) {
|
|
3052
3084
|
const val = bottom + span * t / 4;
|
|
3053
3085
|
const py = yToPx(val);
|
|
3054
|
-
|
|
3055
|
-
|
|
3086
|
+
drawing.line(x0, py, x0 + plotW, py, ink.grid);
|
|
3087
|
+
drawing.text(x0 - 8, py + 4, String(Number(val.toFixed(2))), 11, ink.muted, "end");
|
|
3056
3088
|
}
|
|
3057
|
-
|
|
3058
|
-
|
|
3089
|
+
drawing.line(x0, y0, x0, y0 + plotH, ink.axis);
|
|
3090
|
+
drawing.line(x0, yToPx(0), x0 + plotW, yToPx(0), ink.axis);
|
|
3059
3091
|
const cats = c.categories.length ? c.categories : c.series[0]?.values.map((_v, i) => String(i + 1)) ?? [];
|
|
3060
3092
|
if (c.type === "bar") {
|
|
3061
3093
|
const n = cats.length || 1;
|
|
@@ -3071,19 +3103,22 @@ function chartToSvg(c, theme = "light") {
|
|
|
3071
3103
|
const bx = gx + si * barW;
|
|
3072
3104
|
const bh = Math.abs(zeroY - py);
|
|
3073
3105
|
const by = Math.min(py, zeroY);
|
|
3074
|
-
|
|
3106
|
+
drawing.rect(bx.toFixed(1), by.toFixed(1), barW.toFixed(1), bh.toFixed(1), categorical(si, theme), 3);
|
|
3075
3107
|
});
|
|
3076
|
-
|
|
3108
|
+
drawing.text((x0 + ci * groupW + groupW / 2).toFixed(1), y0 + plotH + 16, cat, 11, ink.muted, "middle");
|
|
3077
3109
|
});
|
|
3078
3110
|
} else if (c.type === "line") {
|
|
3079
3111
|
const n = cats.length || 1;
|
|
3080
3112
|
const step = n > 1 ? plotW / (n - 1) : plotW;
|
|
3081
3113
|
c.series.forEach((s, si) => {
|
|
3082
|
-
const
|
|
3083
|
-
|
|
3084
|
-
|
|
3114
|
+
const points = s.values.map((v, i) => [(x0 + i * step).toFixed(1), yToPx(v).toFixed(1)]);
|
|
3115
|
+
const color = categorical(si, theme);
|
|
3116
|
+
drawing.polyline(points, color);
|
|
3117
|
+
points.forEach(([x, y]) => drawing.circle(x, y, 3, color));
|
|
3118
|
+
});
|
|
3119
|
+
cats.forEach((cat, ci) => {
|
|
3120
|
+
drawing.text((x0 + ci * step).toFixed(1), y0 + plotH + 16, cat, 11, ink.muted, "middle");
|
|
3085
3121
|
});
|
|
3086
|
-
cats.forEach((cat, ci) => parts.push(`<text x="${(x0 + ci * step).toFixed(1)}" y="${y0 + plotH + 16}" font-size="11" text-anchor="middle" fill="${ink.muted}">${xmlEscape(cat)}</text>`));
|
|
3087
3122
|
} else if (c.type === "scatter") {
|
|
3088
3123
|
let maxX = 0;
|
|
3089
3124
|
let minX = 0;
|
|
@@ -3096,50 +3131,138 @@ function chartToSvg(c, theme = "light") {
|
|
|
3096
3131
|
const spanX = topX - botX || 1;
|
|
3097
3132
|
const xToPx = (v) => x0 + (v - botX) / spanX * plotW;
|
|
3098
3133
|
c.series.forEach((s, si) => {
|
|
3099
|
-
for (const p of s.points ?? [])
|
|
3134
|
+
for (const p of s.points ?? []) {
|
|
3135
|
+
drawing.circle(xToPx(p.x).toFixed(1), yToPx(p.y).toFixed(1), 4, categorical(si, theme), 0.85);
|
|
3136
|
+
}
|
|
3100
3137
|
});
|
|
3101
3138
|
}
|
|
3102
|
-
if (c.xLabel)
|
|
3103
|
-
if (c.yLabel)
|
|
3139
|
+
if (c.xLabel) drawing.text(x0 + plotW / 2, H - legendH - 8, c.xLabel, 12, ink.secondary, "middle");
|
|
3140
|
+
if (c.yLabel) drawing.text(16, y0 + plotH / 2, c.yLabel, 12, ink.secondary, "middle", "vertical");
|
|
3104
3141
|
if (c.series.length >= 2) {
|
|
3105
3142
|
const ly = H - 10;
|
|
3106
3143
|
let lx = x0;
|
|
3107
3144
|
c.series.forEach((s, si) => {
|
|
3108
|
-
|
|
3109
|
-
|
|
3145
|
+
drawing.rect(lx, ly - 10, 11, 11, categorical(si, theme), 2);
|
|
3146
|
+
drawing.text(lx + 16, ly, s.name, 12, ink.secondary);
|
|
3110
3147
|
lx += 24 + s.name.length * 7.5;
|
|
3111
3148
|
});
|
|
3112
3149
|
}
|
|
3113
|
-
parts.push(`</svg>`);
|
|
3114
|
-
return parts.join("");
|
|
3115
3150
|
}
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3151
|
+
function drawChartOnCanvas(c, theme, ctx) {
|
|
3152
|
+
drawChart(c, theme, {
|
|
3153
|
+
rect(x, y, w, h, fill, radius) {
|
|
3154
|
+
ctx.fillStyle = fill;
|
|
3155
|
+
if (radius === void 0) {
|
|
3156
|
+
ctx.fillRect(Number(x), Number(y), Number(w), Number(h));
|
|
3157
|
+
return;
|
|
3158
|
+
}
|
|
3159
|
+
ctx.beginPath();
|
|
3160
|
+
ctx.roundRect(Number(x), Number(y), Number(w), Number(h), radius);
|
|
3161
|
+
ctx.fill();
|
|
3162
|
+
},
|
|
3163
|
+
line(x1, y1, x2, y2, stroke) {
|
|
3164
|
+
ctx.beginPath();
|
|
3165
|
+
ctx.moveTo(x1, y1);
|
|
3166
|
+
ctx.lineTo(x2, y2);
|
|
3167
|
+
ctx.strokeStyle = stroke;
|
|
3168
|
+
ctx.lineWidth = 1;
|
|
3169
|
+
ctx.stroke();
|
|
3170
|
+
},
|
|
3171
|
+
text(x, y, text, size, fill, anchor = "start", style) {
|
|
3172
|
+
ctx.font = `${style === "title" ? "600 " : ""}${size}px ${FONT_FAMILY}`;
|
|
3173
|
+
ctx.fillStyle = fill;
|
|
3174
|
+
ctx.textAlign = anchor === "middle" ? "center" : anchor === "end" ? "right" : "left";
|
|
3175
|
+
if (style === "vertical") {
|
|
3176
|
+
ctx.save();
|
|
3177
|
+
ctx.translate(Number(x), y);
|
|
3178
|
+
ctx.rotate(-Math.PI / 2);
|
|
3179
|
+
ctx.fillText(text, 0, 0);
|
|
3180
|
+
ctx.restore();
|
|
3181
|
+
} else {
|
|
3182
|
+
ctx.fillText(text, Number(x), y);
|
|
3183
|
+
}
|
|
3184
|
+
},
|
|
3185
|
+
circle(x, y, radius, fill, opacity = 1) {
|
|
3186
|
+
ctx.beginPath();
|
|
3187
|
+
ctx.arc(Number(x), Number(y), radius, 0, 2 * Math.PI);
|
|
3188
|
+
ctx.fillStyle = fill;
|
|
3189
|
+
ctx.globalAlpha = opacity;
|
|
3190
|
+
ctx.fill();
|
|
3191
|
+
ctx.globalAlpha = 1;
|
|
3192
|
+
},
|
|
3193
|
+
polyline(points, stroke) {
|
|
3194
|
+
if (points.length < 2) return;
|
|
3195
|
+
ctx.beginPath();
|
|
3196
|
+
ctx.moveTo(Number(points[0][0]), Number(points[0][1]));
|
|
3197
|
+
for (const [x, y] of points.slice(1)) ctx.lineTo(Number(x), Number(y));
|
|
3198
|
+
ctx.strokeStyle = stroke;
|
|
3199
|
+
ctx.lineWidth = 2;
|
|
3200
|
+
ctx.lineJoin = "round";
|
|
3201
|
+
ctx.lineCap = "round";
|
|
3202
|
+
ctx.stroke();
|
|
3203
|
+
},
|
|
3204
|
+
slice(x, y, radius, start, end, _large, fill, stroke) {
|
|
3205
|
+
if (radius <= 0) return;
|
|
3206
|
+
ctx.beginPath();
|
|
3207
|
+
ctx.moveTo(x, y);
|
|
3208
|
+
ctx.arc(x, y, radius, start, end);
|
|
3209
|
+
ctx.closePath();
|
|
3210
|
+
ctx.fillStyle = fill;
|
|
3211
|
+
ctx.fill();
|
|
3212
|
+
ctx.strokeStyle = stroke;
|
|
3213
|
+
ctx.lineWidth = 2;
|
|
3214
|
+
ctx.stroke();
|
|
3215
|
+
}
|
|
3216
|
+
});
|
|
3217
|
+
}
|
|
3218
|
+
async function chartToPng(c, theme) {
|
|
3219
|
+
const mime = "image/png";
|
|
3220
|
+
try {
|
|
3221
|
+
if (typeof OffscreenCanvas === "function") {
|
|
3222
|
+
const canvas = new OffscreenCanvas(c.width, c.height);
|
|
3223
|
+
const ctx = canvas.getContext("2d");
|
|
3224
|
+
if (ctx) {
|
|
3225
|
+
drawChartOnCanvas(c, theme, ctx);
|
|
3226
|
+
const blob = await canvas.convertToBlob({ type: mime });
|
|
3227
|
+
if (blob.type === mime && blob.size > 0) return new Uint8Array(await blob.arrayBuffer());
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
} catch {
|
|
3120
3231
|
}
|
|
3121
3232
|
try {
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3233
|
+
if (typeof document !== "undefined") {
|
|
3234
|
+
const canvas = document.createElement("canvas");
|
|
3235
|
+
canvas.width = c.width;
|
|
3236
|
+
canvas.height = c.height;
|
|
3237
|
+
const ctx = canvas.getContext("2d");
|
|
3238
|
+
if (ctx) {
|
|
3239
|
+
drawChartOnCanvas(c, theme, ctx);
|
|
3240
|
+
const blob = await new Promise((resolve) => canvas.toBlob(resolve, mime));
|
|
3241
|
+
if (blob?.type === mime && blob.size > 0) return new Uint8Array(await blob.arrayBuffer());
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3129
3244
|
} catch {
|
|
3130
|
-
return null;
|
|
3131
3245
|
}
|
|
3246
|
+
return null;
|
|
3132
3247
|
}
|
|
3133
3248
|
async function buildChart(spec, bindings, map, theme = "light") {
|
|
3134
3249
|
if (!spec.chart) throw new InterpreterError('chart spec missing "chart".');
|
|
3135
3250
|
const resolved = resolveChart(spec.chart, bindings, map);
|
|
3136
|
-
const svg = chartToSvg(resolved, theme);
|
|
3137
3251
|
if (spec.format === "png") {
|
|
3138
|
-
const png = await
|
|
3252
|
+
const png = await chartToPng(resolved, theme);
|
|
3139
3253
|
if (png) return { name: withExt(spec.filename, "chart", "png"), mime: "image/png", bytes: png };
|
|
3140
|
-
return {
|
|
3254
|
+
return {
|
|
3255
|
+
name: withExt(spec.filename, "chart", "svg"),
|
|
3256
|
+
mime: "image/svg+xml",
|
|
3257
|
+
bytes: utf8(chartToSvg(resolved, theme)),
|
|
3258
|
+
formatSubstitution: { requested: "png", actual: "svg", reason: "png-rendering-unavailable" }
|
|
3259
|
+
};
|
|
3141
3260
|
}
|
|
3142
|
-
return {
|
|
3261
|
+
return {
|
|
3262
|
+
name: withExt(spec.filename, "chart", "svg"),
|
|
3263
|
+
mime: "image/svg+xml",
|
|
3264
|
+
bytes: utf8(chartToSvg(resolved, theme))
|
|
3265
|
+
};
|
|
3143
3266
|
}
|
|
3144
3267
|
|
|
3145
3268
|
// src/browser/code-interpreter/make-file.ts
|
|
@@ -3209,6 +3332,8 @@ Supported \`format\`: "csv", "json", "xlsx", "docx", "pdf", "svg", "png".
|
|
|
3209
3332
|
{type:"list",ordered?,items}, {type:"table",columns?,rows} ] }.
|
|
3210
3333
|
- svg/png charts: { chart: { type:"bar"|"line"|"scatter"|"pie", title?, categories?,
|
|
3211
3334
|
series:[{name,values}] , xLabel?, yLabel? } }.
|
|
3335
|
+
PNG requires working canvas encoding. The result contains an SVG with
|
|
3336
|
+
\`formatSubstitution\` set if PNG cannot be encoded; use the returned format in the UI.
|
|
3212
3337
|
- Multiple files at once: { "files": [ <spec>, <spec>, ... ] } \u2014 the user gets each
|
|
3213
3338
|
file plus a "download all as zip".
|
|
3214
3339
|
|
|
@@ -3218,12 +3343,12 @@ product's chart palette automatically.
|
|
|
3218
3343
|
|
|
3219
3344
|
## Full-power file building (\`run_python\`)
|
|
3220
3345
|
|
|
3221
|
-
When a request genuinely needs
|
|
3222
|
-
|
|
3346
|
+
When a request genuinely needs pandas / numpy / matplotlib / openpyxl / Pillow
|
|
3347
|
+
capabilities that the declarative \`make_file\` tool can't cleanly
|
|
3223
3348
|
express (real dataframe transforms, statistical work, styled matplotlib figures,
|
|
3224
3349
|
multi-sheet workbooks with formulas), emit a \`run_python\` artifact whose body is
|
|
3225
|
-
Python source. It runs ON THE USER'S DEVICE in a Web Worker that blocks
|
|
3226
|
-
requests and permits app-origin mirror loads; write output files to the \`/out\` directory \u2014 every file there is
|
|
3350
|
+
Python source. It runs ON THE USER'S DEVICE in a Web Worker that blocks covered
|
|
3351
|
+
off-origin requests and permits app-origin mirror loads; write output files to the \`/out\` directory \u2014 every file there is
|
|
3227
3352
|
offered to the user as a local download.
|
|
3228
3353
|
|
|
3229
3354
|
<artifact identifier="tco" type="run_python" title="TCO comparison">
|
|
@@ -3238,8 +3363,8 @@ named handle \`INPUT_ROWS\` / \`INPUT_TABLE\` / \`INPUT_TEXT\` (injected as real
|
|
|
3238
3363
|
Python objects on the device) or by the tokenised surrogates you saw \u2014 NEVER by a
|
|
3239
3364
|
real value you guessed. Write results to \`/out/\u2026\`; multiple files there all
|
|
3240
3365
|
download (plus a "download all as zip"). Available packages: pandas, numpy,
|
|
3241
|
-
matplotlib, openpyxl, python-docx, Pillow, lxml (
|
|
3242
|
-
|
|
3366
|
+
matplotlib, openpyxl, python-docx, Pillow, lxml (preloaded from the app's pinned
|
|
3367
|
+
mirror when the worker starts; do NOT pip-install or fetch other packages). For PDF
|
|
3243
3368
|
output, prefer the \`make_file\` PDF builder. PREFER
|
|
3244
3369
|
\`make_file\` for ordinary tabular / document / standard-chart
|
|
3245
3370
|
outputs; reach for \`run_python\` only when the transformation truly needs Python.
|
|
@@ -3315,6 +3440,7 @@ function wheelUrl(handle, mirrorBase = DEFAULT_MIRROR_BASE) {
|
|
|
3315
3440
|
function installNoNetworkGuard(scope, options) {
|
|
3316
3441
|
const selfOrigin = options.selfOrigin;
|
|
3317
3442
|
const allowSameOrigin = options.allowSameOrigin !== false;
|
|
3443
|
+
const mirrorPathPrefixes = options.mirrorPathPrefixes ?? ["/pyodide/", "/models/", "/vendor/transformers/"];
|
|
3318
3444
|
class NetworkBlockedError extends Error {
|
|
3319
3445
|
constructor(_target) {
|
|
3320
3446
|
super("Off-origin request blocked in the on-device code sandbox by the worker guard.");
|
|
@@ -3332,13 +3458,13 @@ function installNoNetworkGuard(scope, options) {
|
|
|
3332
3458
|
return "";
|
|
3333
3459
|
}
|
|
3334
3460
|
};
|
|
3335
|
-
const
|
|
3461
|
+
const resolveMirrorRead = (raw, method, body, headers) => {
|
|
3336
3462
|
if (!allowSameOrigin || String(method ?? "GET").toUpperCase() !== "GET" || body !== void 0 && body !== null) {
|
|
3337
|
-
return
|
|
3463
|
+
return null;
|
|
3338
3464
|
}
|
|
3339
3465
|
if (headers !== void 0 && headers !== null) {
|
|
3340
3466
|
if (Array.isArray(headers)) {
|
|
3341
|
-
if (headers.length > 0) return
|
|
3467
|
+
if (headers.length > 0) return null;
|
|
3342
3468
|
} else if (typeof headers === "object") {
|
|
3343
3469
|
const headerObject = headers;
|
|
3344
3470
|
if (typeof headerObject.forEach === "function") {
|
|
@@ -3346,23 +3472,21 @@ function installNoNetworkGuard(scope, options) {
|
|
|
3346
3472
|
headerObject.forEach(() => {
|
|
3347
3473
|
count += 1;
|
|
3348
3474
|
});
|
|
3349
|
-
if (count > 0) return
|
|
3475
|
+
if (count > 0) return null;
|
|
3350
3476
|
} else if (Object.keys(headers).length > 0) {
|
|
3351
|
-
return
|
|
3477
|
+
return null;
|
|
3352
3478
|
}
|
|
3353
3479
|
} else {
|
|
3354
|
-
return
|
|
3480
|
+
return null;
|
|
3355
3481
|
}
|
|
3356
3482
|
}
|
|
3357
3483
|
try {
|
|
3358
3484
|
const resolved = new URL((raw || "").trim(), selfOrigin);
|
|
3359
3485
|
const path = resolved.pathname;
|
|
3360
|
-
if (resolved.protocol !== "http:" && resolved.protocol !== "https:" || resolved.origin !== selfOrigin || resolved.username !== "" || resolved.password !== "" || resolved.
|
|
3361
|
-
return
|
|
3362
|
-
(prefix) => path.startsWith(prefix)
|
|
3363
|
-
);
|
|
3486
|
+
if (resolved.protocol !== "http:" && resolved.protocol !== "https:" || resolved.origin !== selfOrigin || resolved.username !== "" || resolved.password !== "" || resolved.href !== resolved.origin + path || path.includes("%") || path.includes("\\") || path.split("/").some((part) => part === "." || part === "..")) return null;
|
|
3487
|
+
return mirrorPathPrefixes.some((prefix) => path.startsWith(prefix)) ? resolved.href : null;
|
|
3364
3488
|
} catch {
|
|
3365
|
-
return
|
|
3489
|
+
return null;
|
|
3366
3490
|
}
|
|
3367
3491
|
};
|
|
3368
3492
|
const originalFetch = typeof scope.fetch === "function" ? scope.fetch : void 0;
|
|
@@ -3373,9 +3497,17 @@ function installNoNetworkGuard(scope, options) {
|
|
|
3373
3497
|
const method = options2.method ?? request?.method ?? "GET";
|
|
3374
3498
|
const body = options2.body ?? request?.body;
|
|
3375
3499
|
const headers = options2.headers ?? request?.headers;
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3500
|
+
const url = resolveMirrorRead(target, method, body, headers);
|
|
3501
|
+
if (originalFetch && url) {
|
|
3502
|
+
const safeOptions = {
|
|
3503
|
+
integrity: options2.integrity ?? request?.integrity,
|
|
3504
|
+
signal: options2.signal ?? request?.signal,
|
|
3505
|
+
cache: options2.cache ?? request?.cache,
|
|
3506
|
+
credentials: "omit",
|
|
3507
|
+
redirect: "error",
|
|
3508
|
+
referrerPolicy: "no-referrer"
|
|
3509
|
+
};
|
|
3510
|
+
return Promise.resolve(originalFetch.call(scope, url, safeOptions));
|
|
3379
3511
|
}
|
|
3380
3512
|
return Promise.reject(new NetworkBlockedError(target));
|
|
3381
3513
|
};
|
|
@@ -3405,12 +3537,13 @@ function installNoNetworkGuard(scope, options) {
|
|
|
3405
3537
|
const realImport = typeof scope.importScripts === "function" ? scope.importScripts : void 0;
|
|
3406
3538
|
if (realImport) {
|
|
3407
3539
|
scope.importScripts = function guardedImportScripts(...urls) {
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3540
|
+
const safeUrls = urls.map((value) => {
|
|
3541
|
+
const raw = urlOf(value);
|
|
3542
|
+
const url = resolveMirrorRead(raw, "GET", void 0, void 0);
|
|
3543
|
+
if (!url) throw new NetworkBlockedError(raw);
|
|
3544
|
+
return url;
|
|
3545
|
+
});
|
|
3546
|
+
return realImport.apply(scope, safeUrls);
|
|
3414
3547
|
};
|
|
3415
3548
|
}
|
|
3416
3549
|
}
|
|
@@ -3423,7 +3556,10 @@ function buildPyodideWorkerSource(guardSource = NETWORK_GUARD_SOURCE) {
|
|
|
3423
3556
|
'use strict';
|
|
3424
3557
|
|
|
3425
3558
|
/* [1] WORKER GUARD FIRST \u2014 before Pyodide, before any model code. */
|
|
3426
|
-
(${guardSource})(self, {
|
|
3559
|
+
(${guardSource})(self, {
|
|
3560
|
+
selfOrigin: self.location.origin, allowSameOrigin: true,
|
|
3561
|
+
mirrorPathPrefixes: ['/pyodide/v${PYODIDE_VERSION}/']
|
|
3562
|
+
});
|
|
3427
3563
|
|
|
3428
3564
|
var validatePyodideIndexUrl = (${mirrorUrlGuard});
|
|
3429
3565
|
|
|
@@ -3478,7 +3614,7 @@ var pyodideReady = null;
|
|
|
3478
3614
|
function ensurePyodide(indexURL, packages, wheels) {
|
|
3479
3615
|
if (pyodideReady) return pyodideReady;
|
|
3480
3616
|
pyodideReady = (async function () {
|
|
3481
|
-
progress('runtime', 'Loading the on-device Python runtime
|
|
3617
|
+
progress('runtime', 'Loading the on-device Python runtime\u2026');
|
|
3482
3618
|
/* importScripts bypasses fetch wrappers: pin its exact origin and version. */
|
|
3483
3619
|
var safeIndexURL = validatePyodideIndexUrl(indexURL, self.location.origin, '${PYODIDE_VERSION}');
|
|
3484
3620
|
self.importScripts(safeIndexURL + 'pyodide.js');
|
|
@@ -3881,27 +4017,27 @@ function fileEgressOf(receipt) {
|
|
|
3881
4017
|
}
|
|
3882
4018
|
|
|
3883
4019
|
// src/browser/code-interpreter/capability.ts
|
|
3884
|
-
var CODE_INTERPRETER_CAPABILITY_LABEL = "Client-side code interpreter \u2014 execution runs on YOUR device. The AI sees tokenised placeholders; your real values are filled in locally. The Python worker blocks off-origin requests and can load packages from your app-origin mirror. This SDK does not measure whether the host app later sends output files. (Local execution, not local inference \u2014 the language model still runs upstream on the tokenised prompt.)";
|
|
4020
|
+
var CODE_INTERPRETER_CAPABILITY_LABEL = "Client-side code interpreter \u2014 execution runs on YOUR device. The AI sees tokenised placeholders; your real values are filled in locally. The Python worker blocks covered off-origin requests and can load packages from your app-origin mirror. This SDK does not measure whether the host app later sends output files. (Local execution, not local inference \u2014 the language model still runs upstream on the tokenised prompt.)";
|
|
3885
4021
|
var CODE_INTERPRETER_TOOLS = [
|
|
3886
4022
|
{
|
|
3887
4023
|
name: "make_file",
|
|
3888
4024
|
execution: "client-side",
|
|
3889
4025
|
title: "Build a file (declarative)",
|
|
3890
4026
|
bodyFormat: "json-spec",
|
|
3891
|
-
description: `Build real files (
|
|
4027
|
+
description: `Build real files (CSV, JSON, XLSX, DOCX, PDF, SVG charts, and PNG charts when canvas encoding is available). A PNG request that cannot be encoded returns SVG with formatSubstitution set. Supports multiple files and "download all as zip") from a declarative JSON spec. The file is built ON THE CALLER'S OWN DEVICE with pure-JS builders \u2014 no code execution on CloakAPI and no network request during this build helper. This SDK does not measure later uploads by the host app. Reference the real data by tokenised surrogate or the named handles INPUT_ROWS / INPUT_TABLE / INPUT_TEXT, never by a real value.`
|
|
3892
4028
|
},
|
|
3893
4029
|
{
|
|
3894
4030
|
name: "run_python",
|
|
3895
4031
|
execution: "client-side",
|
|
3896
4032
|
title: "Build a file (full Python power)",
|
|
3897
4033
|
bodyFormat: "python-source",
|
|
3898
|
-
description: "Run model-emitted Python (pandas/numpy/matplotlib/openpyxl/python-docx/Pillow) ON THE CALLER'S OWN DEVICE, in a Web Worker that blocks off-origin requests, writing output files to /out. Same-origin app-mirror requests can load packages; this SDK does not measure egress or later uploads by the host app. Reference real data only by INPUT_ROWS / INPUT_TABLE / INPUT_TEXT or tokenised surrogates. Prefer make_file for ordinary tabular/document/standard-chart output."
|
|
4034
|
+
description: "Run model-emitted Python (pandas/numpy/matplotlib/openpyxl/python-docx/Pillow) ON THE CALLER'S OWN DEVICE, in a Web Worker that blocks covered off-origin requests, writing output files to /out. Same-origin app-mirror requests can load packages; this SDK does not measure egress or later uploads by the host app. Reference real data only by INPUT_ROWS / INPUT_TABLE / INPUT_TEXT or tokenised surrogates. Prefer make_file for ordinary tabular/document/standard-chart output."
|
|
3899
4035
|
}
|
|
3900
4036
|
];
|
|
3901
4037
|
var HONEST_LIMITS = [
|
|
3902
4038
|
"Local execution is NOT local inference \u2014 the language model still runs upstream on the tokenised prompt.",
|
|
3903
4039
|
"The AI is content-blind, not blind: it sees TOKENISED placeholders, not your real values.",
|
|
3904
|
-
"Egress bytes are not measured. The Python worker blocks off-origin requests
|
|
4040
|
+
"Egress bytes are not measured. The Python worker blocks covered off-origin requests and permits same-origin app-mirror loads; the host app controls later uploads."
|
|
3905
4041
|
];
|
|
3906
4042
|
function formatOf(file) {
|
|
3907
4043
|
const name = String(file?.name ?? "");
|
|
@@ -5400,13 +5536,23 @@ async function createBrowserEngine(options) {
|
|
|
5400
5536
|
structuredMap
|
|
5401
5537
|
)
|
|
5402
5538
|
);
|
|
5403
|
-
const spans = bindConversationSurrogates(detected, conversation, mode, text);
|
|
5539
|
+
const spans = bindConversationSurrogates(detected, conversation, mode === "max" ? "balanced" : mode, text);
|
|
5404
5540
|
const applied = applyReviewDecisions(text, spans, {});
|
|
5405
5541
|
const sealed = lockResidualCardRuns(applied.body, applied.map);
|
|
5406
5542
|
assertNoRawCardLeak(sealed.body);
|
|
5543
|
+
const styled = applyPrivacyModeRewrite(
|
|
5544
|
+
{
|
|
5545
|
+
body: sealed.body,
|
|
5546
|
+
map: sealed.map,
|
|
5547
|
+
spans
|
|
5548
|
+
},
|
|
5549
|
+
mode,
|
|
5550
|
+
privacyLedgerFor(conversation)
|
|
5551
|
+
);
|
|
5552
|
+
assertNoRawCardLeak(styled.body);
|
|
5407
5553
|
return {
|
|
5408
|
-
body:
|
|
5409
|
-
map:
|
|
5554
|
+
body: styled.body,
|
|
5555
|
+
map: styled.map,
|
|
5410
5556
|
// PERSON count is TYPE-based, not source-based: the WASM's title-anchored
|
|
5411
5557
|
// name detector routes some person names through the structured channel, so a
|
|
5412
5558
|
// source-based count under-reports names (the '2 names' ledger defect). Count
|
|
@@ -5474,34 +5620,28 @@ async function createBrowserEngine(options) {
|
|
|
5474
5620
|
structuredMap
|
|
5475
5621
|
)
|
|
5476
5622
|
);
|
|
5477
|
-
const spans = bindConversationSurrogates(detected, conversation, mode, text);
|
|
5623
|
+
const spans = bindConversationSurrogates(detected, conversation, mode === "max" ? "balanced" : mode, text);
|
|
5478
5624
|
const applied = applyReviewDecisions(text, spans, {});
|
|
5479
5625
|
const sealed = lockResidualCardRuns(applied.body, applied.map);
|
|
5480
5626
|
assertNoRawCardLeak(sealed.body);
|
|
5481
|
-
|
|
5627
|
+
const drafted = {
|
|
5482
5628
|
originalText: text,
|
|
5483
5629
|
body: sealed.body,
|
|
5484
5630
|
map: sealed.map,
|
|
5485
5631
|
spans,
|
|
5486
|
-
// PERSON count is TYPE-based, not source-based: the WASM's title-anchored
|
|
5487
|
-
// name detector routes some person names through the structured channel, so a
|
|
5488
|
-
// source-based count under-reports names (the '2 names' ledger defect). Count
|
|
5489
|
-
// every PERSON span; 'structured' is then the non-person remainder (no overlap).
|
|
5490
5632
|
names: spans.filter((s) => s.type === "PERSON").length,
|
|
5491
5633
|
structured: spans.filter((s) => s.type !== "PERSON").length,
|
|
5492
5634
|
engineVersion: identity.version,
|
|
5493
5635
|
engineHash: identity.binaryHash,
|
|
5494
5636
|
coverage: coverageStatusForNer(supplement.ner),
|
|
5495
|
-
// Coverage and processing status are carried on the result so an outcome
|
|
5496
|
-
// can record what ran and whether the local time budget was met.
|
|
5497
5637
|
ner: supplement.ner,
|
|
5498
5638
|
processing: supplement.processing,
|
|
5499
|
-
// REQUIRED: which detection layers were ready when this call ran.
|
|
5500
5639
|
layers: layersAtDetection,
|
|
5501
|
-
// REQUIRED: the style these reviewed surrogates were rendered in, and the
|
|
5502
|
-
// scope over which they are stable.
|
|
5503
5640
|
surrogateMode: { mode, continuity }
|
|
5504
5641
|
};
|
|
5642
|
+
const styled = applyPrivacyModeRewrite(drafted, mode, privacyLedgerFor(conversation));
|
|
5643
|
+
assertNoRawCardLeak(styled.body);
|
|
5644
|
+
return styled;
|
|
5505
5645
|
}
|
|
5506
5646
|
function tokeniseWithReview(text, opts) {
|
|
5507
5647
|
return reviewWithGracefulCards(text, (t) => runReviewPass(t, opts?.avoid, opts));
|