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.
- package/LICENSE +190 -0
- package/README.md +208 -0
- package/dist/cjs/index.cjs +707 -0
- package/dist/cjs/openai/index.cjs +1291 -0
- package/dist/esm/index.js +668 -0
- package/dist/esm/openai/index.js +1252 -0
- package/dist/types/core/sentinels.d.ts +24 -0
- package/dist/types/core/sentinels.d.ts.map +1 -0
- package/dist/types/core/session.d.ts +31 -0
- package/dist/types/core/session.d.ts.map +1 -0
- package/dist/types/core/stream.d.ts +9 -0
- package/dist/types/core/stream.d.ts.map +1 -0
- package/dist/types/detectors/base.d.ts +28 -0
- package/dist/types/detectors/base.d.ts.map +1 -0
- package/dist/types/detectors/index.d.ts +9 -0
- package/dist/types/detectors/index.d.ts.map +1 -0
- package/dist/types/detectors/local.d.ts +68 -0
- package/dist/types/detectors/local.d.ts.map +1 -0
- package/dist/types/detectors/remote.d.ts +24 -0
- package/dist/types/detectors/remote.d.ts.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/normalizers.d.ts +89 -0
- package/dist/types/normalizers.d.ts.map +1 -0
- package/dist/types/openai/_anonymize_only.d.ts +25 -0
- package/dist/types/openai/_anonymize_only.d.ts.map +1 -0
- package/dist/types/openai/_audio.d.ts +41 -0
- package/dist/types/openai/_audio.d.ts.map +1 -0
- package/dist/types/openai/_base.d.ts +31 -0
- package/dist/types/openai/_base.d.ts.map +1 -0
- package/dist/types/openai/_chat.d.ts +16 -0
- package/dist/types/openai/_chat.d.ts.map +1 -0
- package/dist/types/openai/_client.d.ts +36 -0
- package/dist/types/openai/_client.d.ts.map +1 -0
- package/dist/types/openai/_completions.d.ts +11 -0
- package/dist/types/openai/_completions.d.ts.map +1 -0
- package/dist/types/openai/_responses.d.ts +13 -0
- package/dist/types/openai/_responses.d.ts.map +1 -0
- package/dist/types/openai/_strict.d.ts +15 -0
- package/dist/types/openai/_strict.d.ts.map +1 -0
- package/dist/types/openai/index.d.ts +25 -0
- package/dist/types/openai/index.d.ts.map +1 -0
- package/dist/types/plain.d.ts +34 -0
- package/dist/types/plain.d.ts.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Session } from "./core/session.ts";
|
|
2
|
+
import type { Detector } from "./detectors/base.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Loose chat-message shape — compatible with OpenAI / Anthropic / Google / etc.
|
|
5
|
+
*
|
|
6
|
+
* For an OpenAI-typed surface, use `gheim/openai` which constrains messages to
|
|
7
|
+
* `OpenAI.Chat.Completions.ChatCompletionMessageParam`.
|
|
8
|
+
*/
|
|
9
|
+
export interface ChatMessage {
|
|
10
|
+
role: string;
|
|
11
|
+
content: string | Array<{
|
|
12
|
+
type: string;
|
|
13
|
+
[k: string]: unknown;
|
|
14
|
+
}> | null;
|
|
15
|
+
[k: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
export declare function anonymizeText(text: string, session: Session, opts?: {
|
|
18
|
+
detector?: Detector;
|
|
19
|
+
model?: string;
|
|
20
|
+
}): Promise<string>;
|
|
21
|
+
export declare function deanonymizeText(text: string, session: Session): string;
|
|
22
|
+
/**
|
|
23
|
+
* Anonymize the ``content`` field of each message. The caller's exact message
|
|
24
|
+
* type is preserved in the return type — works equally well with the loose
|
|
25
|
+
* ``ChatMessage`` shape and with strict OpenAI / Anthropic / Google types.
|
|
26
|
+
*/
|
|
27
|
+
export declare function anonymizeMessages<M extends {
|
|
28
|
+
content?: unknown;
|
|
29
|
+
}>(messages: M[], session: Session, opts?: {
|
|
30
|
+
detector?: Detector;
|
|
31
|
+
model?: string;
|
|
32
|
+
}): Promise<M[]>;
|
|
33
|
+
export declare function deanonymizeStream(chunks: AsyncIterable<string> | Iterable<string>, session: Session): AsyncGenerator<string>;
|
|
34
|
+
//# sourceMappingURL=plain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gheim",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "PII round-trip for LLM APIs: anonymize before the request, de-anonymize the stream on the way back.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Joel Barmettler <joel.barmettler@gmail.com>",
|
|
7
|
+
"homepage": "https://github.com/joelbarmettlerUZH/gheim",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/joelbarmettlerUZH/gheim/issues"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/joelbarmettlerUZH/gheim.git",
|
|
14
|
+
"directory": "packages/gheim-js"
|
|
15
|
+
},
|
|
16
|
+
"keywords": ["pii", "privacy", "redaction", "openai", "llm", "anonymization", "ner", "swiss", "transformers"],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./dist/cjs/index.cjs",
|
|
19
|
+
"module": "./dist/esm/index.js",
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/types/index.d.ts",
|
|
24
|
+
"import": "./dist/esm/index.js",
|
|
25
|
+
"require": "./dist/cjs/index.cjs",
|
|
26
|
+
"default": "./dist/esm/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./openai": {
|
|
29
|
+
"types": "./dist/types/openai/index.d.ts",
|
|
30
|
+
"import": "./dist/esm/openai/index.js",
|
|
31
|
+
"require": "./dist/cjs/openai/index.cjs",
|
|
32
|
+
"default": "./dist/esm/openai/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "rm -rf dist && bun run build:esm && bun run build:cjs && bun run build:types",
|
|
39
|
+
"build:esm": "bun build ./src/index.ts ./src/openai/index.ts --outdir ./dist/esm --target node --format esm --external openai --external @huggingface/transformers",
|
|
40
|
+
"build:cjs": "bun build ./src/index.ts ./src/openai/index.ts --outdir ./dist/cjs --target node --format cjs --entry-naming '[dir]/[name].cjs' --external openai --external @huggingface/transformers",
|
|
41
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist/types",
|
|
42
|
+
"test": "bun test",
|
|
43
|
+
"test:live": "GHEIM_RUN_LIVE=1 bun test tests/live.test.ts tests/live-swiss.test.ts",
|
|
44
|
+
"lint": "tsc --noEmit"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@huggingface/transformers": "^4.2.0",
|
|
48
|
+
"@types/bun": "latest",
|
|
49
|
+
"chrono-node": "^2.9.1",
|
|
50
|
+
"libphonenumber-js": "^1.13.0",
|
|
51
|
+
"openai": "^4.50.0",
|
|
52
|
+
"typescript": "^5.5.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@huggingface/transformers": ">=3.0.0 <5.0.0",
|
|
56
|
+
"chrono-node": "^2.7.0",
|
|
57
|
+
"libphonenumber-js": "^1.10.0",
|
|
58
|
+
"openai": ">=4.0.0 <6.0.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"openai": { "optional": true },
|
|
62
|
+
"@huggingface/transformers": { "optional": true },
|
|
63
|
+
"libphonenumber-js": { "optional": true },
|
|
64
|
+
"chrono-node": { "optional": true }
|
|
65
|
+
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=18"
|
|
68
|
+
}
|
|
69
|
+
}
|