kitkat-audit-sdk 0.1.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.
@@ -0,0 +1,30 @@
1
+ export type VerifyResponse = {
2
+ trust_score: number;
3
+ action: "APPROVE" | "REJECT";
4
+ tests: {
5
+ grounding: {
6
+ pass: boolean;
7
+ score: number;
8
+ reason: string;
9
+ unsupported_claims: string[];
10
+ };
11
+ citation: {
12
+ pass: boolean;
13
+ score: number;
14
+ missing_sources: string[];
15
+ };
16
+ };
17
+ retry_suggestion: string | null;
18
+ };
19
+ export type VerifyOptions = {
20
+ /** API key (header `x-api-key`). Required. */
21
+ apiKey: string;
22
+ /** Cookie string for auth (e.g. `token=eyJ...`). Optional. Use for Node when no cookie is sent. In browser, omit and use credentials. */
23
+ cookie?: string;
24
+ };
25
+ export declare class VerifyClient {
26
+ private baseUrl;
27
+ constructor(baseUrl: string, options: VerifyOptions);
28
+ private options;
29
+ verify(question: string, answer: string, context?: string[]): Promise<VerifyResponse>;
30
+ }
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ export class VerifyClient {
2
+ baseUrl;
3
+ constructor(baseUrl, options) {
4
+ this.baseUrl = baseUrl;
5
+ this.options = options;
6
+ }
7
+ options;
8
+ async verify(question, answer, context) {
9
+ const url = `${this.baseUrl.replace(/\/$/, "")}/verify`;
10
+ const headers = {
11
+ "Content-Type": "application/json",
12
+ "x-api-key": this.options.apiKey,
13
+ };
14
+ if (this.options.cookie) {
15
+ headers["Cookie"] = this.options.cookie;
16
+ }
17
+ const res = await fetch(url, {
18
+ method: "POST",
19
+ headers,
20
+ body: JSON.stringify(context ? { question, answer, context } : { question, answer }),
21
+ credentials: "include",
22
+ });
23
+ if (!res.ok) {
24
+ const err = (await res.json().catch(() => ({})));
25
+ throw new Error(err.error ?? err.message ?? `Verify failed: ${res.status}`);
26
+ }
27
+ return res.json();
28
+ }
29
+ }
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "kitkat-audit-sdk",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc"
9
+ },
10
+ "devDependencies": {
11
+ "typescript": "^5.0.0"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ]
16
+ }