@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.
Files changed (38) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +24 -4
  3. package/dist/browser/index.d.mts +99 -89
  4. package/dist/browser/index.d.ts +99 -89
  5. package/dist/browser/index.js +1245 -123
  6. package/dist/browser/index.mjs +24 -8
  7. package/dist/browser/light.d.mts +3 -2
  8. package/dist/browser/light.d.ts +3 -2
  9. package/dist/browser/light.js +1 -1
  10. package/dist/browser/light.mjs +17 -2
  11. package/dist/browser/names/public.mjs +2 -2
  12. package/dist/browser/ner-pipeline-worker.mjs +3 -3
  13. package/dist/{chunk-6TMC2A6M.mjs → chunk-3MXGO6NA.mjs} +12 -8
  14. package/dist/{chunk-G6TZ6722.mjs → chunk-6E6T2YO5.mjs} +5 -915
  15. package/dist/{chunk-EY35G37A.mjs → chunk-746IWCJ4.mjs} +224 -1
  16. package/dist/chunk-L7RLVZMD.mjs +922 -0
  17. package/dist/{chunk-JV52VGVZ.mjs → chunk-TRWGRB2P.mjs} +1 -1
  18. package/dist/chunk-TWAQCP3Z.mjs +1258 -0
  19. package/dist/{chunk-36BC4GYL.mjs → chunk-VYGV643D.mjs} +262 -122
  20. package/dist/device/index.d.mts +1448 -0
  21. package/dist/device/index.d.ts +1448 -0
  22. package/dist/device/index.js +4539 -0
  23. package/dist/device/index.mjs +2462 -0
  24. package/dist/{disclosure-Cx6xS8Tj.d.mts → disclosure-BhM2Aqa2.d.mts} +2 -12
  25. package/dist/{disclosure-Cx6xS8Tj.d.ts → disclosure-BhM2Aqa2.d.ts} +2 -12
  26. package/dist/index.d.mts +3 -2
  27. package/dist/index.d.ts +3 -2
  28. package/dist/index.js +1 -1
  29. package/dist/index.mjs +14 -12
  30. package/dist/{local-pii-supplement-SUOJZO7X.mjs → local-pii-supplement-5KFFPDDN.mjs} +4 -4
  31. package/dist/node.d.mts +2 -1
  32. package/dist/node.d.ts +2 -1
  33. package/dist/node.js +311 -58
  34. package/dist/node.mjs +18 -12
  35. package/dist/request-body-slots-BMShK1YO.d.mts +56 -0
  36. package/dist/request-body-slots-BMShK1YO.d.ts +56 -0
  37. package/package.json +9 -2
  38. package/dist/{chunk-PEDVEDAW.mjs → chunk-66SEKCCN.mjs} +8 -8
package/dist/node.mjs CHANGED
@@ -1,17 +1,22 @@
1
1
  import {
2
2
  createBrowserEngine,
3
3
  newConversation
4
- } from "./chunk-36BC4GYL.mjs";
4
+ } from "./chunk-VYGV643D.mjs";
5
+ import {
6
+ scanGazetteerPlaces
7
+ } from "./chunk-DLKR3ZVZ.mjs";
5
8
  import "./chunk-DMJIRWAT.mjs";
6
- import "./chunk-G6TZ6722.mjs";
7
- import "./chunk-EY35G37A.mjs";
8
- import "./chunk-JV52VGVZ.mjs";
9
+ import "./chunk-6E6T2YO5.mjs";
10
+ import "./chunk-746IWCJ4.mjs";
11
+ import "./chunk-TRWGRB2P.mjs";
9
12
  import {
10
13
  PORTAL_ENHANCED_NER_MODEL_ID,
11
14
  loadNodePinnedEnhancedNerModel,
12
15
  loadNodePinnedNonLatinNerModel
13
- } from "./chunk-6TMC2A6M.mjs";
16
+ } from "./chunk-3MXGO6NA.mjs";
14
17
  import "./chunk-QIORVVUD.mjs";
18
+ import "./chunk-L7RLVZMD.mjs";
19
+ import "./chunk-TWAQCP3Z.mjs";
15
20
  import {
16
21
  CARD_SECRETS_MESSAGE,
17
22
  SURROGATE_SALT,
@@ -33,14 +38,11 @@ import {
33
38
  spanIsAllCommonWords,
34
39
  titleCaseAllCapsRuns,
35
40
  titleCaseLowercaseRuns
36
- } from "./chunk-PEDVEDAW.mjs";
41
+ } from "./chunk-66SEKCCN.mjs";
42
+ import "./chunk-KBDFJIEW.mjs";
37
43
  import "./chunk-44DSUIC2.mjs";
38
44
  import "./chunk-SUUFGE34.mjs";
39
45
  import "./chunk-MOHR4UIG.mjs";
40
- import {
41
- scanGazetteerPlaces
42
- } from "./chunk-DLKR3ZVZ.mjs";
43
- import "./chunk-KBDFJIEW.mjs";
44
46
  import "./chunk-I6KKUHEY.mjs";
45
47
 
46
48
  // src/node.ts
@@ -52,7 +54,7 @@ import { pathToFileURL } from "url";
52
54
  import { createHash } from "crypto";
53
55
  import { closeSync, existsSync, fstatSync, openSync, readFileSync, realpathSync } from "fs";
54
56
  import { constants as fsConstants } from "fs";
55
- import { dirname, resolve } from "path";
57
+ import path, { dirname, resolve } from "path";
56
58
  import { fileURLToPath } from "url";
57
59
 
58
60
  // src/vendor-shared/ner-model-pins.json
@@ -194,6 +196,10 @@ function fileMetadata(stat) {
194
196
  const value = stat;
195
197
  return `${value.dev}:${value.ino}:${value.size}:${value.mtimeNs}:${value.ctimeNs}`;
196
198
  }
199
+ function isWithinPinnedBase(root, file, pathOps = path) {
200
+ const relative = pathOps.relative(root, file);
201
+ return relative !== ".." && !relative.startsWith(`..${pathOps.sep}`) && !pathOps.isAbsolute(relative);
202
+ }
197
203
  function verifyNodeNerModelPins(base, id) {
198
204
  captureNodeNerModelFiles(base, id ? [id] : [SLOT2, SLOT3]);
199
205
  }
@@ -213,7 +219,7 @@ function captureNodeNerModelFiles(base, ids = [SLOT2, SLOT3]) {
213
219
  const localName = expected.lokalt ? resolve(root, id, dirname(relative), expected.lokalt) : requested;
214
220
  const file = existsSync(localName) ? localName : requested;
215
221
  const realFile = realpathSync(file);
216
- if (realFile !== root && !realFile.startsWith(`${root}/`)) {
222
+ if (!isWithinPinnedBase(root, realFile)) {
217
223
  throw new Error(`NER model file escapes pinned base: ${id}/${relative}`);
218
224
  }
219
225
  let fd;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The request-body CHANNEL LIST — which string fields of an OpenAI/Anthropic-style
3
+ * request body carry customer text — as ONE pure module with NO imports.
4
+ *
5
+ * ⛔ WHY THIS LIVES IN ITS OWN FILE (B1, 2026-09-29). It used to sit inside
6
+ * `browser/request-body.ts`, whose `tokeniseRequestBody` needs the browser WASM
7
+ * engine (`./index`). The Node client (`src/client.ts`) could not import the
8
+ * channel list from there without dragging that whole engine into the Node entry
9
+ * point, so it did not — it kept its own two-line walk (`messages[].content` when
10
+ * a string) and relayed `system`, content blocks, `tool_use.input`,
11
+ * `tool_calls[].function.arguments`, tool descriptions and `metadata` RAW.
12
+ *
13
+ * The browser drivers (`tokeniseRequestBody`, `spliceReviewedBody`) and the Node
14
+ * client now all read THIS list. A channel added here reaches every surface; a
15
+ * surface can no longer be one traversal behind.
16
+ *
17
+ * `browser/request-body.ts` re-exports everything below, so every existing import
18
+ * of `collectRequestBodyTextSlots` / `RequestBodyTextSlot` keeps working.
19
+ */
20
+ /** Plain deep clone for JSON-shaped request bodies (preserves arrays + objects). */
21
+ declare function deepClone<T>(v: T, seen?: WeakSet<object>): T;
22
+ /** One mutable text field of a request body, addressed by its owner + key. */
23
+ interface RequestBodyTextSlot {
24
+ /** Dotted path — diagnostics and tests only. Never egressed. */
25
+ readonly path: string;
26
+ /** The current string. */
27
+ get(): string;
28
+ /** Write the transformed string back into the body. */
29
+ set(v: string): void;
30
+ /** Schema contract literals may pass only when tokenisation leaves them unchanged. */
31
+ readonly policy: 'tokenise' | 'reject-if-changed' | 'json-argument' | 'json-number';
32
+ }
33
+ /** Only ordinary prose slots use the standalone encoded-payload shape guard. */
34
+ /** Schema literals, attachment URLs and data: URLs stay as written. They are not probed into the stand-in map. */
35
+ declare function slotIsLeftAsWritten(slot: {
36
+ policy: string;
37
+ }, value: string): boolean;
38
+ declare function collectRequestBodyTextSlots(root: unknown): RequestBodyTextSlot[];
39
+ declare const PLACEMENT_SCHEMA = "A tool schema holds a fixed value or property name that looks like personal data. Replacing it would change the tool's contract, so it was not replaced. It is sent as written.";
40
+ /**
41
+ * One reason list for an `unchecked_content` notice.
42
+ * The Node client and the browser relay both use this union.
43
+ */
44
+ type UncheckedContentReason = 'unverified_script' | 'value_not_replaced' | 'media_not_checked' | 'unrecognised_block';
45
+ interface ValuePlacementWarning {
46
+ reason: Extract<UncheckedContentReason, 'value_not_replaced' | 'media_not_checked' | 'unrecognised_block'>;
47
+ message: string;
48
+ }
49
+ declare function collectValuePlacementWarnings(root: unknown, personal: (value: string) => boolean, options?: {
50
+ metadataKeys?: boolean;
51
+ }): ValuePlacementWarning[];
52
+ /** Contract literals cannot be replaced without changing their caller-visible meaning. */
53
+ /** Schema literals stay as written. Replacing one would change the tool contract. */
54
+ declare function assertContractLiteralSafe(_original: string, _tokenised: string, _path: string): void;
55
+
56
+ export { PLACEMENT_SCHEMA as P, type UncheckedContentReason as U, type ValuePlacementWarning as V, assertContractLiteralSafe as a, collectValuePlacementWarnings as b, collectRequestBodyTextSlots as c, deepClone as d, slotIsLeftAsWritten as s };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The request-body CHANNEL LIST — which string fields of an OpenAI/Anthropic-style
3
+ * request body carry customer text — as ONE pure module with NO imports.
4
+ *
5
+ * ⛔ WHY THIS LIVES IN ITS OWN FILE (B1, 2026-09-29). It used to sit inside
6
+ * `browser/request-body.ts`, whose `tokeniseRequestBody` needs the browser WASM
7
+ * engine (`./index`). The Node client (`src/client.ts`) could not import the
8
+ * channel list from there without dragging that whole engine into the Node entry
9
+ * point, so it did not — it kept its own two-line walk (`messages[].content` when
10
+ * a string) and relayed `system`, content blocks, `tool_use.input`,
11
+ * `tool_calls[].function.arguments`, tool descriptions and `metadata` RAW.
12
+ *
13
+ * The browser drivers (`tokeniseRequestBody`, `spliceReviewedBody`) and the Node
14
+ * client now all read THIS list. A channel added here reaches every surface; a
15
+ * surface can no longer be one traversal behind.
16
+ *
17
+ * `browser/request-body.ts` re-exports everything below, so every existing import
18
+ * of `collectRequestBodyTextSlots` / `RequestBodyTextSlot` keeps working.
19
+ */
20
+ /** Plain deep clone for JSON-shaped request bodies (preserves arrays + objects). */
21
+ declare function deepClone<T>(v: T, seen?: WeakSet<object>): T;
22
+ /** One mutable text field of a request body, addressed by its owner + key. */
23
+ interface RequestBodyTextSlot {
24
+ /** Dotted path — diagnostics and tests only. Never egressed. */
25
+ readonly path: string;
26
+ /** The current string. */
27
+ get(): string;
28
+ /** Write the transformed string back into the body. */
29
+ set(v: string): void;
30
+ /** Schema contract literals may pass only when tokenisation leaves them unchanged. */
31
+ readonly policy: 'tokenise' | 'reject-if-changed' | 'json-argument' | 'json-number';
32
+ }
33
+ /** Only ordinary prose slots use the standalone encoded-payload shape guard. */
34
+ /** Schema literals, attachment URLs and data: URLs stay as written. They are not probed into the stand-in map. */
35
+ declare function slotIsLeftAsWritten(slot: {
36
+ policy: string;
37
+ }, value: string): boolean;
38
+ declare function collectRequestBodyTextSlots(root: unknown): RequestBodyTextSlot[];
39
+ declare const PLACEMENT_SCHEMA = "A tool schema holds a fixed value or property name that looks like personal data. Replacing it would change the tool's contract, so it was not replaced. It is sent as written.";
40
+ /**
41
+ * One reason list for an `unchecked_content` notice.
42
+ * The Node client and the browser relay both use this union.
43
+ */
44
+ type UncheckedContentReason = 'unverified_script' | 'value_not_replaced' | 'media_not_checked' | 'unrecognised_block';
45
+ interface ValuePlacementWarning {
46
+ reason: Extract<UncheckedContentReason, 'value_not_replaced' | 'media_not_checked' | 'unrecognised_block'>;
47
+ message: string;
48
+ }
49
+ declare function collectValuePlacementWarnings(root: unknown, personal: (value: string) => boolean, options?: {
50
+ metadataKeys?: boolean;
51
+ }): ValuePlacementWarning[];
52
+ /** Contract literals cannot be replaced without changing their caller-visible meaning. */
53
+ /** Schema literals stay as written. Replacing one would change the tool contract. */
54
+ declare function assertContractLiteralSafe(_original: string, _tokenised: string, _path: string): void;
55
+
56
+ export { PLACEMENT_SCHEMA as P, type UncheckedContentReason as U, type ValuePlacementWarning as V, assertContractLiteralSafe as a, collectValuePlacementWarnings as b, collectRequestBodyTextSlots as c, deepClone as d, slotIsLeftAsWritten as s };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloakapi/sdk",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "CloakAPI TypeScript SDK: detects personal data with structured rules on your device, replaces it with stand-ins before the request leaves, sends it through the CloakAPI gateway and restores the reply. Without the native engine it runs its built-in rules and says so. OpenAI- and Anthropic-shaped clients for Node and the browser.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -52,6 +52,11 @@
52
52
  "types": "./dist/node.d.ts",
53
53
  "import": "./dist/node.mjs",
54
54
  "require": "./dist/node.js"
55
+ },
56
+ "./device": {
57
+ "types": "./dist/device/index.d.ts",
58
+ "import": "./dist/device/index.mjs",
59
+ "require": "./dist/device/index.js"
55
60
  }
56
61
  },
57
62
  "sideEffects": [
@@ -66,6 +71,8 @@
66
71
  "./dist/browser/names/public.mjs",
67
72
  "./dist/browser/ner-pipeline-worker.js",
68
73
  "./dist/browser/ner-pipeline-worker.mjs",
74
+ "./dist/device/index.js",
75
+ "./dist/device/index.mjs",
69
76
  "./dist/chunk-*.mjs",
70
77
  "./dist/*-*.mjs",
71
78
  "./dist/browser/engine-heavy-worker.js",
@@ -75,7 +82,7 @@
75
82
  "scripts": {
76
83
  "gen:wasm": "node scripts/gen-wasm-inline.mjs",
77
84
  "gen:wasm-worker": "node scripts/gen-wasm-worker.mjs",
78
- "build": "npm run check:shared && npm run gen:version && npm run check:release-set && node scripts/copy-wasm.mjs --port && npm run gen:wasm && npm run gen:wasm-worker && tsup src/index.ts src/browser/index.ts src/browser/light.ts src/browser/names/public.ts src/browser/ner-pipeline-worker.ts src/node.ts --format esm --splitting --clean --dts && tsup src/index.ts src/browser/index.ts src/browser/light.ts src/browser/names/public.ts src/browser/ner-pipeline-worker.ts src/node.ts --format cjs --dts && node scripts/copy-wasm.mjs --kopi && node -e \"require('node:fs').copyFileSync('src/browser/engine/engine-heavy-worker.js','dist/engine-heavy-worker.js');require('node:fs').copyFileSync('src/browser/engine/engine-heavy-worker.js','dist/browser/engine-heavy-worker.js')\" && node scripts/gen-light-cjs.mjs && node scripts/dist-motor-vakt.mjs && node scripts/light-entry-vakt.mjs && node scripts/dist-types-vakt.mjs",
85
+ "build": "npm run check:shared && npm run gen:version && npm run check:release-set && node scripts/copy-wasm.mjs --port && npm run gen:wasm && npm run gen:wasm-worker && tsup src/index.ts src/browser/index.ts src/browser/light.ts src/browser/names/public.ts src/browser/ner-pipeline-worker.ts src/node.ts src/device/index.ts --format esm --splitting --clean --dts && tsup src/index.ts src/browser/index.ts src/browser/light.ts src/browser/names/public.ts src/browser/ner-pipeline-worker.ts src/node.ts src/device/index.ts --format cjs --dts && node scripts/copy-wasm.mjs --kopi && node -e \"require('node:fs').copyFileSync('src/browser/engine/engine-heavy-worker.js','dist/engine-heavy-worker.js');require('node:fs').copyFileSync('src/browser/engine/engine-heavy-worker.js','dist/browser/engine-heavy-worker.js')\" && node scripts/gen-light-cjs.mjs && node scripts/dist-motor-vakt.mjs && node scripts/light-entry-vakt.mjs && node scripts/dist-types-vakt.mjs",
79
86
  "prepack": "npm run test:gate && npm run build",
80
87
  "prepublishOnly": "bash ../../../bin/publiseringstre-vakt.sh --sti \"$PWD\" && npm run build && bash ../../../bin/sdk-lisens-vakt.sh --pakke \"$PWD\"",
81
88
  "test": "vitest run",
@@ -1,3 +1,11 @@
1
+ import {
2
+ LATIN_POOLS,
3
+ LOCALE_POOLS,
4
+ detectDocCyrillicLocale,
5
+ makeLatinLocaleSurrogate,
6
+ makeLocaleSurrogate,
7
+ makePlaceSurrogate
8
+ } from "./chunk-KBDFJIEW.mjs";
1
9
  import {
2
10
  findCardSpans
3
11
  } from "./chunk-44DSUIC2.mjs";
@@ -9,14 +17,6 @@ import {
9
17
  import {
10
18
  buildNerCoverage
11
19
  } from "./chunk-MOHR4UIG.mjs";
12
- import {
13
- LATIN_POOLS,
14
- LOCALE_POOLS,
15
- detectDocCyrillicLocale,
16
- makeLatinLocaleSurrogate,
17
- makeLocaleSurrogate,
18
- makePlaceSurrogate
19
- } from "./chunk-KBDFJIEW.mjs";
20
20
 
21
21
  // src/browser/names/local-names-data.ts
22
22
  var GIVEN_NAMES = /* @__PURE__ */ new Set([