gheim 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +208 -0
  3. package/dist/cjs/index.cjs +707 -0
  4. package/dist/cjs/openai/index.cjs +1291 -0
  5. package/dist/esm/index.js +668 -0
  6. package/dist/esm/openai/index.js +1252 -0
  7. package/dist/types/core/sentinels.d.ts +24 -0
  8. package/dist/types/core/sentinels.d.ts.map +1 -0
  9. package/dist/types/core/session.d.ts +31 -0
  10. package/dist/types/core/session.d.ts.map +1 -0
  11. package/dist/types/core/stream.d.ts +9 -0
  12. package/dist/types/core/stream.d.ts.map +1 -0
  13. package/dist/types/detectors/base.d.ts +28 -0
  14. package/dist/types/detectors/base.d.ts.map +1 -0
  15. package/dist/types/detectors/index.d.ts +9 -0
  16. package/dist/types/detectors/index.d.ts.map +1 -0
  17. package/dist/types/detectors/local.d.ts +68 -0
  18. package/dist/types/detectors/local.d.ts.map +1 -0
  19. package/dist/types/detectors/remote.d.ts +24 -0
  20. package/dist/types/detectors/remote.d.ts.map +1 -0
  21. package/dist/types/index.d.ts +20 -0
  22. package/dist/types/index.d.ts.map +1 -0
  23. package/dist/types/normalizers.d.ts +89 -0
  24. package/dist/types/normalizers.d.ts.map +1 -0
  25. package/dist/types/openai/_anonymize_only.d.ts +25 -0
  26. package/dist/types/openai/_anonymize_only.d.ts.map +1 -0
  27. package/dist/types/openai/_audio.d.ts +41 -0
  28. package/dist/types/openai/_audio.d.ts.map +1 -0
  29. package/dist/types/openai/_base.d.ts +31 -0
  30. package/dist/types/openai/_base.d.ts.map +1 -0
  31. package/dist/types/openai/_chat.d.ts +16 -0
  32. package/dist/types/openai/_chat.d.ts.map +1 -0
  33. package/dist/types/openai/_client.d.ts +36 -0
  34. package/dist/types/openai/_client.d.ts.map +1 -0
  35. package/dist/types/openai/_completions.d.ts +11 -0
  36. package/dist/types/openai/_completions.d.ts.map +1 -0
  37. package/dist/types/openai/_responses.d.ts +13 -0
  38. package/dist/types/openai/_responses.d.ts.map +1 -0
  39. package/dist/types/openai/_strict.d.ts +15 -0
  40. package/dist/types/openai/_strict.d.ts.map +1 -0
  41. package/dist/types/openai/index.d.ts +25 -0
  42. package/dist/types/openai/index.d.ts.map +1 -0
  43. package/dist/types/plain.d.ts +34 -0
  44. package/dist/types/plain.d.ts.map +1 -0
  45. package/package.json +69 -0
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Sentinel format, allocation, and regex matching. Mirrors gheim-py.
3
+ *
4
+ * A sentinel is a stable, uniquely-numbered placeholder like `<PERSON_1>` or
5
+ * `<EMAIL_2>`. ASCII-only angle brackets so downstream LLM tokenizers preserve them.
6
+ */
7
+ export declare const LABEL_TO_TAG: Record<string, string>;
8
+ /** Matches any complete sentinel anywhere in a string. */
9
+ export declare const SENTINEL_RE: RegExp;
10
+ /** Same pattern, anchored — for testing a single token. */
11
+ export declare const SENTINEL_FULL_RE: RegExp;
12
+ export declare function labelTag(label: string): string;
13
+ export interface Sentinel {
14
+ tag: string;
15
+ index: number;
16
+ }
17
+ export declare function renderSentinel(s: Sentinel): string;
18
+ export declare function parseSentinel(s: string): Sentinel | null;
19
+ /**
20
+ * Could `buffer` still become a sentinel if more characters arrive?
21
+ * True iff buffer is a non-empty *strict* prefix of a valid sentinel.
22
+ */
23
+ export declare function isPossibleSentinelPrefix(buffer: string): boolean;
24
+ //# sourceMappingURL=sentinels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentinels.d.ts","sourceRoot":"","sources":["../../../src/core/sentinels.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAS/C,CAAC;AAKF,0DAA0D;AAC1D,eAAO,MAAM,WAAW,QAGvB,CAAC;AAEF,2DAA2D;AAC3D,eAAO,MAAM,gBAAgB,QAE5B,CAAC;AAOF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAElD;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAIxD;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAIhE"}
@@ -0,0 +1,31 @@
1
+ /** Session state — mirrors gheim-py's Session. */
2
+ import type { Span } from "../detectors/base.ts";
3
+ import type { Normalizer } from "../normalizers.ts";
4
+ /** Constructor options for Session. */
5
+ export interface SessionOptions {
6
+ /**
7
+ * Optional per-label canonical-form normalizers. Maps a label name
8
+ * (e.g. "private_phone") to either a built-in name ("e164" /
9
+ * "iso_date") or a callable Normalizer. Surfaces that fail to parse
10
+ * fall back to the default NFKC+lowercase key. See ./normalizers.ts.
11
+ */
12
+ normalizers?: Record<string, string | Normalizer>;
13
+ }
14
+ export declare class Session {
15
+ /** Sentinel string ("<PERSON_1>") → original surface form. */
16
+ mapping: Record<string, string>;
17
+ private coalesce;
18
+ private counters;
19
+ private resolvedNormalizers;
20
+ constructor(opts?: SessionOptions);
21
+ allocate(label: string, surface: string): string;
22
+ applySpans(text: string, spans: Span[]): string;
23
+ restore(text: string): string;
24
+ toJSON(): {
25
+ mapping: Record<string, string>;
26
+ };
27
+ static fromJSON(raw: {
28
+ mapping: Record<string, string>;
29
+ }, opts?: SessionOptions): Session;
30
+ }
31
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/core/session.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAmBpD,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC;CACnD;AAED,qBAAa,OAAO;IAClB,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACrC,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,mBAAmB,CAAkC;gBAEjD,IAAI,GAAE,cAAmB;IAQrC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;IAiBhD,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM;IAoB/C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAK7B,MAAM,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE;IAI7C,MAAM,CAAC,QAAQ,CACb,GAAG,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,EACxC,IAAI,GAAE,cAAmB,GACxB,OAAO;CAqBX"}
@@ -0,0 +1,9 @@
1
+ export declare class StreamDeanonymizer {
2
+ private readonly mapping;
3
+ private hold;
4
+ constructor(mapping: Record<string, string>);
5
+ feed(chunk: string): string;
6
+ flush(): string;
7
+ transform(chunks: AsyncIterable<string> | Iterable<string>): AsyncGenerator<string>;
8
+ }
9
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/core/stream.ts"],"names":[],"mappings":"AAMA,qBAAa,kBAAkB;IAGjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,IAAI,CAAM;gBAEW,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAE5D,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IA4C3B,KAAK,IAAI,MAAM;IAMR,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC;CAQ3F"}
@@ -0,0 +1,28 @@
1
+ /** Detector protocol — anything that maps text to PII spans. */
2
+ /**
3
+ * Strip leading/trailing whitespace from a span range. The upstream
4
+ * privacy-filter model tends to include leading whitespace in spans as a BPE
5
+ * tokenization artifact; trimming fixes cosmetically-broken restored text.
6
+ * Returns null if the trimmed range is empty.
7
+ */
8
+ export declare function trimSpan(text: string, start: number, end: number): {
9
+ start: number;
10
+ end: number;
11
+ } | null;
12
+ export interface Span {
13
+ /** e.g. "private_person", "private_email" */
14
+ label: string;
15
+ /** Inclusive character offset in the original string. */
16
+ start: number;
17
+ /** Exclusive. */
18
+ end: number;
19
+ /** Original surface form (text.slice(start, end)). */
20
+ text: string;
21
+ score?: number;
22
+ }
23
+ export interface Detector {
24
+ detect(text: string, opts?: {
25
+ model?: string;
26
+ }): Promise<Span[]>;
27
+ }
28
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/detectors/base.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACV;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAKvC;AAED,MAAM,WAAW,IAAI;IACnB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;CAClE"}
@@ -0,0 +1,9 @@
1
+ export type { Detector, Span } from "./base.ts";
2
+ export { DEFAULT_BASE_URL, DEFAULT_MODEL as REMOTE_DEFAULT_MODEL, RemoteDetector, } from "./remote.ts";
3
+ export type { RemoteDetectorOptions } from "./remote.ts";
4
+ export { LocalDetector } from "./local.ts";
5
+ export type { LocalDetectorOptions } from "./local.ts";
6
+ import type { Detector } from "./base.ts";
7
+ /** Pick a reasonable default: remote if `GHEIM_API_KEY` is set in env, else local. */
8
+ export declare function defaultDetector(): Detector;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/detectors/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EACL,gBAAgB,EAChB,aAAa,IAAI,oBAAoB,EACrC,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAI1C,sFAAsF;AACtF,wBAAgB,eAAe,IAAI,QAAQ,CAI1C"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Local detector — runs the privacy-filter model in-process via @huggingface/transformers.
3
+ *
4
+ * Works in Node and the browser (with `device: 'webgpu'` for the latter).
5
+ * `@huggingface/transformers` is an *optional peer dependency* — only needed
6
+ * when this detector is actually instantiated.
7
+ *
8
+ * Long inputs (more tokens than the model's positional limit, typically
9
+ * 512 for BERT/XLM-R/roberta encoders) are split into overlapping sliding
10
+ * windows; spans from each window are reprojected to the original character
11
+ * offsets and deduplicated. Without this, anything past ~512 tokens would
12
+ * be silently truncated by the underlying pipeline. Multiple inputs and
13
+ * within-input chunks are batched together for one forward pass.
14
+ */
15
+ import type { Detector, Span } from "./base.ts";
16
+ export declare const DEFAULT_MODEL = "joelbarmettler/gheim-ch-560m";
17
+ /** transformers.js token-classification options used by this detector. */
18
+ export interface LocalDetectorOptions {
19
+ /** HuggingFace model id (must be a token-classification model). */
20
+ model?: string;
21
+ /** transformers.js device: "auto" | "cpu" | "wasm" | "webgpu" | "gpu" | ... */
22
+ device?: string;
23
+ /** Quantization dtype: "fp32" | "fp16" | "q8" | "q4" | "auto" */
24
+ dtype?: string;
25
+ /** Aggregation strategy passed to the pipeline call. */
26
+ aggregationStrategy?: string;
27
+ /** Sliding-window size in model tokens (default 510 for a 512-token model). */
28
+ chunkTokens?: number;
29
+ /**
30
+ * Token overlap between consecutive windows. Must exceed the longest PII
31
+ * span you expect to detect; default 32 covers all realistic cases.
32
+ */
33
+ chunkOverlapTokens?: number;
34
+ /**
35
+ * Forward-pass batch size used both for within-input chunk batching and
36
+ * for `detectBatch` cross-input batching.
37
+ */
38
+ batchSize?: number;
39
+ /** Optional pre-built pipeline instance (e.g. for tests). */
40
+ pipelineInstance?: unknown;
41
+ }
42
+ export declare class LocalDetector implements Detector {
43
+ readonly model: string;
44
+ readonly device: string;
45
+ readonly dtype: string;
46
+ readonly aggregationStrategy: string;
47
+ readonly chunkTokens: number;
48
+ readonly chunkOverlapTokens: number;
49
+ readonly batchSize: number;
50
+ private _pipeline;
51
+ private _loadPromise;
52
+ constructor(opts?: LocalDetectorOptions);
53
+ private load;
54
+ detect(text: string, opts?: {
55
+ model?: string;
56
+ }): Promise<Span[]>;
57
+ /**
58
+ * Detect PII in many inputs in a single batched forward pass. Inputs that
59
+ * exceed the model's token limit are split into overlapping windows; all
60
+ * chunks across all inputs are batched into one pipeline call (subject to
61
+ * `batchSize`). Empty texts produce empty `[]` at the matching position.
62
+ */
63
+ detectBatch(texts: string[], opts?: {
64
+ model?: string;
65
+ }): Promise<Span[][]>;
66
+ private chunkText;
67
+ }
68
+ //# sourceMappingURL=local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../src/detectors/local.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEhD,eAAO,MAAM,aAAa,iCAAiC,CAAC;AAQ5D,0EAA0E;AAC1E,MAAM,WAAW,oBAAoB;IACnC,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,+EAA+E;IAC/E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAsCD,qBAAa,aAAc,YAAW,QAAQ;IAC5C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,YAAY,CAA0C;gBAElD,IAAI,GAAE,oBAAyB;YAkB7B,IAAI;IAuBZ,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAYtE;;;;;OAKG;IACG,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YAyFlE,SAAS;CAkBxB"}
@@ -0,0 +1,24 @@
1
+ /** Remote detector — calls a gheim-server (or compatible) over HTTP. */
2
+ import { type Detector, type Span } from "./base.ts";
3
+ export declare const DEFAULT_BASE_URL = "https://api.gheim.ch";
4
+ export declare const DEFAULT_MODEL = "openai/privacy-filter";
5
+ export interface RemoteDetectorOptions {
6
+ baseUrl?: string;
7
+ apiKey?: string;
8
+ model?: string;
9
+ /** Strip leading/trailing whitespace from each span (default: true). */
10
+ trimWhitespace?: boolean;
11
+ fetch?: typeof fetch;
12
+ }
13
+ export declare class RemoteDetector implements Detector {
14
+ private readonly baseUrl;
15
+ private readonly apiKey?;
16
+ private readonly model;
17
+ private readonly trimWhitespace;
18
+ private readonly fetchImpl;
19
+ constructor(opts?: RemoteDetectorOptions);
20
+ detect(text: string, opts?: {
21
+ model?: string;
22
+ }): Promise<Span[]>;
23
+ }
24
+ //# sourceMappingURL=remote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../../src/detectors/remote.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,IAAI,EAAY,MAAM,WAAW,CAAC;AAE/D,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AACvD,eAAO,MAAM,aAAa,0BAA0B,CAAC;AAErD,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,qBAAa,cAAe,YAAW,QAAQ;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;gBAE7B,IAAI,GAAE,qBAA0B;IAUtC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;CA+BvE"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * gheim — PII round-trip for LLM APIs.
3
+ *
4
+ * Public API:
5
+ * - Session, Span, Detector
6
+ * - LocalDetector (planned v0.2), RemoteDetector
7
+ * - anonymizeText / deanonymizeText / anonymizeMessages / deanonymizeStream
8
+ * - StreamDeanonymizer (low-level)
9
+ */
10
+ export { Session } from "./core/session.ts";
11
+ export { LABEL_TO_TAG, SENTINEL_RE, isPossibleSentinelPrefix, labelTag, parseSentinel, renderSentinel, } from "./core/sentinels.ts";
12
+ export type { Sentinel } from "./core/sentinels.ts";
13
+ export { StreamDeanonymizer } from "./core/stream.ts";
14
+ export type { Detector, Span } from "./detectors/base.ts";
15
+ export { DEFAULT_BASE_URL, REMOTE_DEFAULT_MODEL, RemoteDetector, LocalDetector, defaultDetector, } from "./detectors/index.ts";
16
+ export type { RemoteDetectorOptions, LocalDetectorOptions } from "./detectors/index.ts";
17
+ export { anonymizeMessages, anonymizeText, deanonymizeStream, deanonymizeText, } from "./plain.ts";
18
+ export type { ChatMessage } from "./plain.ts";
19
+ export declare const VERSION = "0.1.0";
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EACL,YAAY,EACZ,WAAW,EACX,wBAAwB,EACxB,QAAQ,EACR,aAAa,EACb,cAAc,GACf,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,eAAO,MAAM,OAAO,UAAU,CAAC"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Optional surface-form normalizers for Session.
3
+ *
4
+ * A normalizer canonicalises one specific category of PII so that
5
+ * trivially-different formats of the same identity collapse to a single
6
+ * sentinel — beyond what NFKC + lowercase + whitespace-collapse alone
7
+ * catches.
8
+ *
9
+ * Examples that the default key does NOT collapse and that an opt-in
10
+ * normalizer here does:
11
+ * - Phone formats: "+41 44 268 12 34" / "0041 44 268 1234" / "044 268 12 34"
12
+ * (with region "CH") → all "+41442681234" under {@link e164}.
13
+ * - Date formats: "1990-01-02" / "Jan 2 1990" → both "1990-01-02"
14
+ * under {@link isoDate}.
15
+ *
16
+ * Wire it up by passing a `{label: normalizer}` map to Session:
17
+ *
18
+ * ```ts
19
+ * import { Session } from "gheim";
20
+ * import { e164, isoDate } from "gheim/normalizers";
21
+ *
22
+ * const session = new Session({
23
+ * normalizers: {
24
+ * private_phone: e164({ region: "CH" }),
25
+ * private_date: isoDate(),
26
+ * },
27
+ * });
28
+ * ```
29
+ *
30
+ * A normalizer returns `null` for un-parseable input; when that happens,
31
+ * the session falls back to the default NFKC+lowercase key so the
32
+ * surface still gets a sentinel — it just won't collapse with format
33
+ * variants.
34
+ *
35
+ * Both `libphonenumber-js` and `chrono-node` are optional peer
36
+ * dependencies. They are loaded synchronously on first use and fail
37
+ * with an actionable error if missing:
38
+ *
39
+ * ```bash
40
+ * bun add libphonenumber-js chrono-node
41
+ * ```
42
+ */
43
+ /**
44
+ * A normalizer takes a raw surface and returns a canonical form, or
45
+ * `null` if the surface is unparseable (caller falls back to the
46
+ * default NFKC+lowercase key).
47
+ */
48
+ export type Normalizer = (s: string) => string | null;
49
+ /** Options for {@link e164}. */
50
+ export interface E164Options {
51
+ /**
52
+ * Default region (ISO 3166-1 alpha-2, e.g. "CH") for phone numbers
53
+ * without an explicit country code. Undefined disables parsing of
54
+ * non-fully-qualified numbers.
55
+ */
56
+ region?: string;
57
+ }
58
+ /**
59
+ * Phone-number canonicaliser via Google's libphonenumber-js port.
60
+ * Returns the E.164 form (+<country><subscriber>) of valid phone
61
+ * numbers; returns `null` for invalid or unparseable input.
62
+ */
63
+ export declare function e164(opts?: E164Options): Normalizer;
64
+ /** Options for {@link isoDate}. */
65
+ export interface IsoDateOptions {
66
+ /**
67
+ * Locale name to look up on chrono-node's exported parser objects
68
+ * (e.g. "en", "de", "fr"). Defaults to chrono's universal parser.
69
+ */
70
+ locale?: "en" | "de" | "fr" | "ja" | "nl" | "pt" | "ru" | "uk" | "zh";
71
+ }
72
+ /**
73
+ * Date canonicaliser to ISO-8601 (YYYY-MM-DD) via chrono-node. Returns
74
+ * `null` for input that doesn't parse as a date.
75
+ */
76
+ export declare function isoDate(opts?: IsoDateOptions): Normalizer;
77
+ /**
78
+ * German DIN-5007-2 transliteration on top of NFKC + lowercase. Collapses
79
+ * `ä`→`ae`, `ö`→`oe`, `ü`→`ue`, `ß`→`ss` so that German bureaucracy
80
+ * surface variants — `Müller` / `Mueller` / `MÜLLER` / `MUELLER` — collapse
81
+ * to one sentinel. The codepoint `ü` doesn't decompose to `ue` under NFKC,
82
+ * which is why the default key alone misses this case.
83
+ *
84
+ * Pure-JS — no extra dependencies.
85
+ */
86
+ export declare function germanTransliteration(): Normalizer;
87
+ /** Resolve a built-in name or pass through a custom callable. */
88
+ export declare function resolveNormalizer(spec: string | Normalizer): Normalizer;
89
+ //# sourceMappingURL=normalizers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizers.d.ts","sourceRoot":"","sources":["../../src/normalizers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;AAEtD,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAgDD;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,IAAI,GAAE,WAAgB,GAAG,UAAU,CAavD;AAED,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;CACvE;AAmBD;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,GAAE,cAAmB,GAAG,UAAU,CAQ7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,IAAI,UAAU,CAclD;AAQD,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAUvE"}
@@ -0,0 +1,25 @@
1
+ /** Anonymize-input-only endpoints: embeddings, moderations, images. */
2
+ import type OpenAIClass from "openai";
3
+ import type { Detector } from "../detectors/base.ts";
4
+ import { type CallExtras } from "./_base.ts";
5
+ export declare class GheimEmbeddings {
6
+ private readonly clientPromise;
7
+ private readonly defaultDet;
8
+ constructor(clientPromise: Promise<OpenAIClass>, defaultDet: Detector);
9
+ create(body: Record<string, unknown> & CallExtras): Promise<unknown>;
10
+ }
11
+ export declare class GheimModerations {
12
+ private readonly clientPromise;
13
+ private readonly defaultDet;
14
+ constructor(clientPromise: Promise<OpenAIClass>, defaultDet: Detector);
15
+ create(body: Record<string, unknown> & CallExtras): Promise<unknown>;
16
+ }
17
+ export declare class GheimImages {
18
+ private readonly clientPromise;
19
+ private readonly defaultDet;
20
+ constructor(clientPromise: Promise<OpenAIClass>, defaultDet: Detector);
21
+ generate(body: Record<string, unknown> & CallExtras): Promise<unknown>;
22
+ edit(body: Record<string, unknown> & CallExtras): Promise<unknown>;
23
+ createVariation(body: Record<string, unknown> & CallExtras): Promise<unknown>;
24
+ }
25
+ //# sourceMappingURL=_anonymize_only.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_anonymize_only.d.ts","sourceRoot":"","sources":["../../../src/openai/_anonymize_only.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,KAAK,WAAW,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAkB,KAAK,UAAU,EAAsB,MAAM,YAAY,CAAC;AA0BjF,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,EACnC,UAAU,EAAE,QAAQ;IAGjC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAK3E;AAED,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,EACnC,UAAU,EAAE,QAAQ;IAGjC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAK3E;AAED,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,EACnC,UAAU,EAAE,QAAQ;IAGjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAMtE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAMlE,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAQpF"}
@@ -0,0 +1,41 @@
1
+ /** Audio endpoints — speech (anonymize-only); transcriptions/translations (round-trip). */
2
+ import type OpenAIClass from "openai";
3
+ import type { Detector } from "../detectors/base.ts";
4
+ import { type CallExtras } from "./_base.ts";
5
+ interface AudioInner {
6
+ speech: {
7
+ create(body: unknown): Promise<unknown>;
8
+ };
9
+ transcriptions: {
10
+ create(body: unknown): Promise<unknown>;
11
+ };
12
+ translations: {
13
+ create(body: unknown): Promise<unknown>;
14
+ };
15
+ }
16
+ export declare class GheimSpeech {
17
+ private readonly innerP;
18
+ private readonly defaultDet;
19
+ constructor(innerP: Promise<AudioInner>, defaultDet: Detector);
20
+ create(body: Record<string, unknown> & CallExtras): Promise<unknown>;
21
+ }
22
+ export declare class GheimTranscriptions {
23
+ private readonly innerP;
24
+ private readonly defaultDet;
25
+ constructor(innerP: Promise<AudioInner>, defaultDet: Detector);
26
+ create(body: Record<string, unknown> & CallExtras): Promise<unknown>;
27
+ }
28
+ export declare class GheimTranslations {
29
+ private readonly innerP;
30
+ private readonly defaultDet;
31
+ constructor(innerP: Promise<AudioInner>, defaultDet: Detector);
32
+ create(body: Record<string, unknown> & CallExtras): Promise<unknown>;
33
+ }
34
+ export declare class GheimAudio {
35
+ readonly speech: GheimSpeech;
36
+ readonly transcriptions: GheimTranscriptions;
37
+ readonly translations: GheimTranslations;
38
+ constructor(clientPromise: Promise<OpenAIClass>, detector: Detector);
39
+ }
40
+ export {};
41
+ //# sourceMappingURL=_audio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_audio.d.ts","sourceRoot":"","sources":["../../../src/openai/_audio.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,OAAO,KAAK,WAAW,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAqC,KAAK,UAAU,EAAsB,MAAM,YAAY,CAAC;AAEpG,UAAU,UAAU;IAClB,MAAM,EAAE;QAAE,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;IACpD,cAAc,EAAE;QAAE,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;IAC5D,YAAY,EAAE;QAAE,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;CAC3D;AAqBD,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,EAC3B,UAAU,EAAE,QAAQ;IAGjC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAU3E;AAED,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,EAC3B,UAAU,EAAE,QAAQ;IAGjC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAkB3E;AAED,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,EAC3B,UAAU,EAAE,QAAQ;IAGjC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAW3E;AAED,qBAAa,UAAU;IACrB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,mBAAmB,CAAC;IAC7C,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC;gBAE7B,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ;CAMpE"}
@@ -0,0 +1,31 @@
1
+ /** Shared helpers for all endpoint proxies (JS). */
2
+ import { Session } from "../core/session.ts";
3
+ import { StreamDeanonymizer } from "../core/stream.ts";
4
+ import type { Detector } from "../detectors/base.ts";
5
+ export interface CallExtras {
6
+ gheimSession?: Session;
7
+ gheimDetector?: Detector;
8
+ }
9
+ export declare function resolveCallSession(body: Record<string, unknown> & CallExtras, defaultDet: Detector): {
10
+ session: Session;
11
+ detector: Detector;
12
+ rest: Record<string, unknown>;
13
+ };
14
+ /**
15
+ * Anonymize a single value: strings get redacted, arrays of strings recurse,
16
+ * arrays of pure ints (pre-tokenized inputs) pass through, anything else
17
+ * passes through.
18
+ */
19
+ export declare function anonymizeValue(value: unknown, session: Session, detector: Detector): Promise<unknown>;
20
+ export declare function restoreString(value: unknown, session: Session): unknown;
21
+ /** Streaming wrapper — wraps an AsyncIterable, calls mutate per chunk, emits tail. */
22
+ export declare class StreamingResponse<C> implements AsyncIterable<C> {
23
+ private readonly inner;
24
+ private readonly session;
25
+ private readonly mutate;
26
+ private readonly makeTail?;
27
+ readonly buf: StreamDeanonymizer;
28
+ constructor(inner: AsyncIterable<C>, session: Session, mutate: (chunk: C, buf: StreamDeanonymizer) => void, makeTail?: ((template: C, tail: string) => C) | undefined);
29
+ [Symbol.asyncIterator](): AsyncIterator<C>;
30
+ }
31
+ //# sourceMappingURL=_base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_base.d.ts","sourceRoot":"","sources":["../../../src/openai/_base.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,QAAQ,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,EAC1C,UAAU,EAAE,QAAQ,GACnB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAQzE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,OAAO,CAAC,CAalB;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAGvE;AAED,sFAAsF;AACtF,qBAAa,iBAAiB,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAIzD,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAN5B,QAAQ,CAAC,GAAG,EAAE,kBAAkB,CAAC;gBAGd,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EACvB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,kBAAkB,KAAK,IAAI,EACnD,QAAQ,CAAC,GAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,aAAA;IAKvD,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;CAYlD"}
@@ -0,0 +1,16 @@
1
+ /** Chat completions wrapper — adds tools/name redaction on top of the existing surface. */
2
+ import type OpenAIClass from "openai";
3
+ import type { Detector } from "../detectors/base.ts";
4
+ import { type CallExtras } from "./_base.ts";
5
+ export declare class GheimChatCompletions {
6
+ private readonly clientPromise;
7
+ private readonly defaultDet;
8
+ constructor(clientPromise: Promise<OpenAIClass>, defaultDet: Detector);
9
+ create(body: OpenAIClass.Chat.Completions.ChatCompletionCreateParamsNonStreaming & CallExtras): Promise<OpenAIClass.Chat.Completions.ChatCompletion>;
10
+ create(body: OpenAIClass.Chat.Completions.ChatCompletionCreateParamsStreaming & CallExtras): Promise<AsyncIterable<OpenAIClass.Chat.Completions.ChatCompletionChunk>>;
11
+ }
12
+ export declare class GheimChat {
13
+ readonly completions: GheimChatCompletions;
14
+ constructor(clientPromise: Promise<OpenAIClass>, detector: Detector);
15
+ }
16
+ //# sourceMappingURL=_chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_chat.d.ts","sourceRoot":"","sources":["../../../src/openai/_chat.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,OAAO,KAAK,WAAW,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAqC,KAAK,UAAU,EAAsB,MAAM,YAAY,CAAC;AAmGpG,qBAAa,oBAAoB;IAE7B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,EACnC,UAAU,EAAE,QAAQ;IAGjC,MAAM,CACV,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,sCAAsC,GAAG,UAAU,GACrF,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;IACjD,MAAM,CACV,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,mCAAmC,GAAG,UAAU,GAClF,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;CAoB5E;AAED,qBAAa,SAAS;IACpB,QAAQ,CAAC,WAAW,EAAE,oBAAoB,CAAC;gBAC/B,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ;CAGpE"}
@@ -0,0 +1,36 @@
1
+ /** Client class — wraps the upstream openai client and exposes wrapped endpoints. */
2
+ import type OpenAIClass from "openai";
3
+ import type { Detector } from "../detectors/base.ts";
4
+ import { GheimAudio } from "./_audio.ts";
5
+ import { GheimChat } from "./_chat.ts";
6
+ import { GheimCompletions } from "./_completions.ts";
7
+ import { GheimResponses } from "./_responses.ts";
8
+ import { GheimEmbeddings, GheimImages, GheimModerations } from "./_anonymize_only.ts";
9
+ export interface GheimOpenAIOptions {
10
+ gheimDetector?: Detector;
11
+ /** Strict mode: raise on access to unwrapped endpoints. Default true. */
12
+ gheimStrict?: boolean;
13
+ /** Pre-built openai client to wrap (useful for tests). */
14
+ openaiClient?: OpenAIClass;
15
+ /** Forwarded to ``new OpenAI(...)`` when constructing the underlying client. */
16
+ clientOptions?: ConstructorParameters<typeof OpenAIClass>[0];
17
+ }
18
+ export declare class OpenAI {
19
+ readonly chat: GheimChat;
20
+ readonly completions: GheimCompletions;
21
+ readonly responses: GheimResponses;
22
+ readonly embeddings: GheimEmbeddings;
23
+ readonly moderations: GheimModerations;
24
+ readonly audio: GheimAudio;
25
+ readonly images: GheimImages;
26
+ /** Underlying openai client; available after ``ready()`` resolves. */
27
+ raw: OpenAIClass | undefined;
28
+ /** Whether strict mode is on. */
29
+ readonly gheimStrict: boolean;
30
+ private readonly _clientPromise;
31
+ constructor(opts?: GheimOpenAIOptions);
32
+ ready(): Promise<OpenAIClass>;
33
+ }
34
+ export declare const AsyncOpenAI: typeof OpenAI;
35
+ export type AsyncOpenAI = OpenAI;
36
+ //# sourceMappingURL=_client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_client.d.ts","sourceRoot":"","sources":["../../../src/openai/_client.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,OAAO,KAAK,WAAW,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,eAAe,EACf,WAAW,EACX,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAG9B,MAAM,WAAW,kBAAkB;IACjC,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,yEAAyE;IACzE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,gFAAgF;IAChF,aAAa,CAAC,EAAE,qBAAqB,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9D;AAqBD,qBAAa,MAAM;IACjB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;IACrC,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,sEAAsE;IACtE,GAAG,EAAE,WAAW,GAAG,SAAS,CAAC;IAC7B,iCAAiC;IACjC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAuB;gBAE1C,IAAI,GAAE,kBAAuB;IAiCnC,KAAK,IAAI,OAAO,CAAC,WAAW,CAAC;CAGpC;AAED,eAAO,MAAM,WAAW,eAAS,CAAC;AAClC,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC"}
@@ -0,0 +1,11 @@
1
+ /** Legacy completions API — text-in / text-out. */
2
+ import type OpenAIClass from "openai";
3
+ import type { Detector } from "../detectors/base.ts";
4
+ import { type CallExtras } from "./_base.ts";
5
+ export declare class GheimCompletions {
6
+ private readonly clientPromise;
7
+ private readonly defaultDet;
8
+ constructor(clientPromise: Promise<OpenAIClass>, defaultDet: Detector);
9
+ create(body: Record<string, unknown> & CallExtras): Promise<unknown>;
10
+ }
11
+ //# sourceMappingURL=_completions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_completions.d.ts","sourceRoot":"","sources":["../../../src/openai/_completions.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,OAAO,KAAK,WAAW,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAqC,KAAK,UAAU,EAAsB,MAAM,YAAY,CAAC;AAgCpG,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,EACnC,UAAU,EAAE,QAAQ;IAGjC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAuB3E"}
@@ -0,0 +1,13 @@
1
+ /** Responses API — text-in / text-out with event-based streaming.
2
+ * Mirrors gheim/openai/_responses.py.
3
+ */
4
+ import type OpenAIClass from "openai";
5
+ import type { Detector } from "../detectors/base.ts";
6
+ import { type CallExtras } from "./_base.ts";
7
+ export declare class GheimResponses {
8
+ private readonly clientPromise;
9
+ private readonly defaultDet;
10
+ constructor(clientPromise: Promise<OpenAIClass>, defaultDet: Detector);
11
+ create(body: Record<string, unknown> & CallExtras): Promise<unknown>;
12
+ }
13
+ //# sourceMappingURL=_responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_responses.d.ts","sourceRoot":"","sources":["../../../src/openai/_responses.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,WAAW,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAkB,KAAK,UAAU,EAAsB,MAAM,YAAY,CAAC;AA8DjF,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,EACnC,UAAU,EAAE,QAAQ;IAGjC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAqC3E"}
@@ -0,0 +1,15 @@
1
+ /** Strict-mode proxy: raises on access to unwrapped endpoints. */
2
+ export declare const STRICT_REASONS: Record<string, string>;
3
+ export declare class GheimStrictError extends Error {
4
+ constructor(message: string);
5
+ }
6
+ /**
7
+ * Build a Proxy that throws on any property access or call. Each level of
8
+ * sub-property nesting (client.beta.assistants.create) gets its own raise so
9
+ * the error message names the leaf operation.
10
+ */
11
+ export declare function makeStrictProxy(attrName: string, reason: string, path?: string[]): unknown;
12
+ /** Build a forwarder that warns once per attribute then forwards to the inner object. */
13
+ export declare function makeWarningProxy<T extends object>(attrName: string, inner: T, reason: string): T;
14
+ export declare function _resetWarnings(): void;
15
+ //# sourceMappingURL=_strict.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_strict.d.ts","sourceRoot":"","sources":["../../../src/openai/_strict.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAElE,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAyBjD,CAAC;AAEF,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAI5B;AAWD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,EAAO,GAAG,OAAO,CAc9F;AAID,yFAAyF;AACzF,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC/C,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,MAAM,GACb,CAAC,CAcH;AAED,wBAAgB,cAAc,IAAI,IAAI,CAErC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * OpenAI SDK drop-in wrapper (gheim/openai).
3
+ *
4
+ * Public surface:
5
+ * - `OpenAI` / `AsyncOpenAI` — drop-in clients with PII round-trip on every
6
+ * text-carrying endpoint
7
+ * - Stateless helpers (kept for backward-compat with v0.1):
8
+ * anonymizeOpenAIMessages, deanonymizeOpenAIResponse, deanonymizeOpenAIStream
9
+ *
10
+ * The `openai` package is an *optional* peer dependency — only required when
11
+ * the drop-in client is actually instantiated.
12
+ */
13
+ import type OpenAIClass from "openai";
14
+ import { Session } from "../core/session.ts";
15
+ import type { Detector } from "../detectors/base.ts";
16
+ export { OpenAI, AsyncOpenAI } from "./_client.ts";
17
+ export type { GheimOpenAIOptions } from "./_client.ts";
18
+ export { GheimStrictError, STRICT_REASONS } from "./_strict.ts";
19
+ export declare function anonymizeOpenAIMessages(messages: OpenAIClass.Chat.Completions.ChatCompletionMessageParam[], session: Session, opts?: {
20
+ detector?: Detector;
21
+ model?: string;
22
+ }): Promise<OpenAIClass.Chat.Completions.ChatCompletionMessageParam[]>;
23
+ export declare function deanonymizeOpenAIResponse<R extends OpenAIClass.Chat.Completions.ChatCompletion>(response: R, session: Session): R;
24
+ export declare function deanonymizeOpenAIStream(stream: AsyncIterable<OpenAIClass.Chat.Completions.ChatCompletionChunk>, session: Session): AsyncGenerator<OpenAIClass.Chat.Completions.ChatCompletionChunk>;
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/openai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,WAAW,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAIhE,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,0BAA0B,EAAE,EACnE,OAAO,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7C,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,0BAA0B,EAAE,CAAC,CAEpE;AAED,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,EAC7F,QAAQ,EAAE,CAAC,EACX,OAAO,EAAE,OAAO,GACf,CAAC,CAcH;AAED,wBAAuB,uBAAuB,CAC5C,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,EACvE,OAAO,EAAE,OAAO,GACf,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,CA6BlE"}