@neuraltrust/trustguard-sdk 0.1.4 → 0.1.6
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/README.md +51 -1
- package/dist/ai-sdk/index.cjs +373 -0
- package/dist/ai-sdk/index.cjs.map +1 -0
- package/dist/ai-sdk/index.d.cts +81 -0
- package/dist/ai-sdk/index.d.ts +81 -0
- package/dist/ai-sdk/index.js +345 -0
- package/dist/ai-sdk/index.js.map +1 -0
- package/dist/client-ZoD3M6yg.d.cts +99 -0
- package/dist/client-ZoD3M6yg.d.ts +99 -0
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -98
- package/dist/index.d.ts +2 -98
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/package.json +25 -3
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["export { TrustGuard } from \"./client.js\";\nexport { TrustGuardAPIError } from \"./errors.js\";\nexport type {\n Attachment,\n Direction,\n Finding,\n FindingOutcome,\n FindingSignal,\n FindingSource,\n GuardRequest,\n GuardResponse,\n Protocol,\n TrustGuardOptions,\n} from \"./types.js\";\n","/**\n * A non-2xx response from the TrustGuard API, carrying the status code and the\n * correlation ids needed to chase the request in telemetry. Transport-level\n * failures (network errors, timeouts) are thrown as-is instead.\n */\nexport class TrustGuardAPIError extends Error {\n readonly status: number;\n readonly traceId: string;\n readonly requestId: string;\n\n constructor(status: number, message: string, traceId: string, requestId: string) {\n super(`TrustGuard API error ${status}: ${message} (trace_id=${traceId}, request_id=${requestId})`);\n this.name = \"TrustGuardAPIError\";\n this.status = status;\n this.traceId = traceId;\n this.requestId = requestId;\n }\n}\n","import { TrustGuardAPIError } from \"./errors.js\";\nimport type {\n Attachment,\n Finding,\n FindingOutcome,\n FindingSignal,\n FindingSource,\n GuardRequest,\n GuardResponse,\n TrustGuardOptions,\n} from \"./types.js\";\n\nconst EVALUATE_PATH = \"/v1/evaluate\";\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\ninterface WireFindingSource {\n kind?: string;\n plugin?: string;\n detector_id?: string;\n detector_name?: string;\n policy_id?: string;\n gate_name?: string;\n}\n\ninterface WireFindingSignal {\n type?: string;\n confidence?: number;\n}\n\ninterface WireFindingOutcome {\n action?: string;\n}\n\ninterface WireFinding {\n source?: WireFindingSource;\n signal?: WireFindingSignal;\n outcome?: WireFindingOutcome;\n evidence?: Record<string, unknown>;\n}\n\ninterface WireResponse {\n status?: string;\n transformed_payload?: Record<string, unknown> | null;\n findings?: WireFinding[];\n trace_id?: string;\n request_id?: string;\n}\n\n/** Client for the TrustGuard runtime evaluate API. */\nexport class TrustGuard {\n readonly #baseUrl: string;\n readonly #apiKey: string;\n readonly #timeoutMs: number;\n readonly #fetch: typeof fetch;\n\n constructor(options: TrustGuardOptions) {\n const baseUrl = options.baseUrl?.trim().replace(/\\/+$/, \"\");\n if (!baseUrl) {\n throw new Error(\"TrustGuard: baseUrl is required\");\n }\n if (!options.apiKey?.trim()) {\n throw new Error(\"TrustGuard: apiKey is required\");\n }\n this.#baseUrl = baseUrl;\n this.#apiKey = options.apiKey;\n this.#timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n this.#fetch = options.fetch ?? globalThis.fetch;\n }\n\n /**\n * Evaluates the request against the policy attached to the API key and\n * returns the verdict. Throws TrustGuardAPIError on non-2xx responses.\n */\n async guard(request: GuardRequest): Promise<GuardResponse> {\n if (!request.payload) {\n throw new Error(\"TrustGuard: request payload is required\");\n }\n\n const response = await this.#fetch(this.#baseUrl + EVALUATE_PATH, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${this.#apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(serializeRequest(request)),\n signal: AbortSignal.timeout(this.#timeoutMs),\n });\n\n const text = await response.text();\n if (!response.ok) {\n throw apiError(response.status, text);\n }\n\n return deserializeResponse(parseJson(text) ?? {});\n }\n}\n\n/** Maps the camelCase request onto the snake_case wire format, omitting empty optionals (the server rejects unknown top-level fields). */\nfunction serializeRequest(request: GuardRequest): Record<string, unknown> {\n let payload = request.payload;\n if (request.attachments?.length) {\n payload = { ...payload, attachments: request.attachments.map(serializeAttachment) };\n }\n const body: Record<string, unknown> = { payload };\n if (request.direction) body.direction = request.direction;\n if (request.protocol) body.protocol = request.protocol;\n if (request.sessionId) body.session_id = request.sessionId;\n if (request.consumerId) body.consumer_id = request.consumerId;\n if (request.attributes && Object.keys(request.attributes).length > 0) body.attributes = request.attributes;\n return body;\n}\n\nfunction serializeAttachment(attachment: Attachment): Record<string, string> {\n const entry: Record<string, string> = {\n filename: attachment.filename,\n content_type: attachment.contentType,\n };\n if (attachment.data !== undefined) {\n const bytes =\n typeof attachment.data === \"string\" ? Buffer.from(attachment.data, \"utf-8\") : Buffer.from(attachment.data);\n entry.data = bytes.toString(\"base64\");\n }\n if (attachment.url !== undefined) entry.url = attachment.url;\n return entry;\n}\n\nfunction deserializeResponse(wire: WireResponse): GuardResponse {\n const status = wire.status ?? \"\";\n return {\n status,\n isBlocked: status === \"block\",\n transformedPayload: wire.transformed_payload ?? null,\n findings: (wire.findings ?? []).map(deserializeFinding),\n traceId: wire.trace_id ?? \"\",\n requestId: wire.request_id ?? \"\",\n };\n}\n\nfunction deserializeFinding(f: WireFinding): Finding {\n const sourceWire = f.source ?? {};\n const source: FindingSource = {\n kind: sourceWire.kind ?? \"\",\n };\n if (sourceWire.plugin !== undefined) source.plugin = sourceWire.plugin;\n if (sourceWire.detector_id !== undefined) source.detectorId = sourceWire.detector_id;\n if (sourceWire.detector_name !== undefined) source.detectorName = sourceWire.detector_name;\n if (sourceWire.policy_id !== undefined) source.policyId = sourceWire.policy_id;\n if (sourceWire.gate_name !== undefined) source.gateName = sourceWire.gate_name;\n\n const finding: Finding = { source };\n if (f.signal?.type) {\n const signal: FindingSignal = { type: f.signal.type };\n if (f.signal.confidence !== undefined) signal.confidence = f.signal.confidence;\n finding.signal = signal;\n }\n if (f.outcome?.action) {\n const outcome: FindingOutcome = { action: f.outcome.action };\n finding.outcome = outcome;\n }\n if (f.evidence && Object.keys(f.evidence).length > 0) {\n finding.evidence = f.evidence;\n }\n return finding;\n}\n\nfunction apiError(status: number, text: string): TrustGuardAPIError {\n const payload = parseJson(text) as { error?: string; message?: string; trace_id?: string; request_id?: string } | undefined;\n const message = payload?.error || payload?.message || text.trim() || `HTTP ${status}`;\n return new TrustGuardAPIError(status, message, payload?.trace_id ?? \"\", payload?.request_id ?? \"\");\n}\n\nfunction parseJson(text: string): WireResponse | undefined {\n try {\n return JSON.parse(text) as WireResponse;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,SAAiB,SAAiB,WAAmB;AAC/E,UAAM,wBAAwB,MAAM,KAAK,OAAO,cAAc,OAAO,gBAAgB,SAAS,GAAG;AACjG,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,UAAU;AACf,SAAK,YAAY;AAAA,EACnB;AACF;;;ACLA,IAAM,gBAAgB;AACtB,IAAM,qBAAqB;AAoCpB,IAAM,aAAN,MAAiB;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,SAA4B;AACtC,UAAM,UAAU,QAAQ,SAAS,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAC1D,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AACA,QAAI,CAAC,QAAQ,QAAQ,KAAK,GAAG;AAC3B,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AACA,SAAK,WAAW;AAChB,SAAK,UAAU,QAAQ;AACvB,SAAK,aA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,MAAI,EAAE,YAAY,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,GAAG;AACpD,YAAQ,WAAW,EAAE;AAAA,EACvB;AACA,SAAO;AACT;AAEA,SAAS,SAAS,QAAgB,MAAkC;AAClE,QAAM,UAAU,UAAU,IAAI;AAC9B,QAAM,UAAU,SAAS,SAAS,SAAS,WAAW,KAAK,KAAK,KAAK,QAAQ,MAAM;AACnF,SAAO,IAAI,mBAAmB,QAAQ,SAAS,SAAS,YAAY,IAAI,SAAS,cAAc,EAAE;AACnG;AAEA,SAAS,UAAU,MAAwC;AACzD,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["export { TrustGuard } from \"./client.js\";\nexport { TrustGuardAPIError } from \"./errors.js\";\nexport type {\n Attachment,\n Direction,\n Finding,\n FindingOutcome,\n FindingSignal,\n FindingSource,\n GuardRequest,\n GuardResponse,\n Protocol,\n TrustGuardOptions,\n} from \"./types.js\";\n","/**\n * A non-2xx response from the TrustGuard API, carrying the status code and the\n * correlation ids needed to chase the request in telemetry. Transport-level\n * failures (network errors, timeouts) are thrown as-is instead.\n */\nexport class TrustGuardAPIError extends Error {\n readonly status: number;\n readonly traceId: string;\n readonly requestId: string;\n\n constructor(status: number, message: string, traceId: string, requestId: string) {\n super(`TrustGuard API error ${status}: ${message} (trace_id=${traceId}, request_id=${requestId})`);\n this.name = \"TrustGuardAPIError\";\n this.status = status;\n this.traceId = traceId;\n this.requestId = requestId;\n }\n}\n","import { TrustGuardAPIError } from \"./errors.js\";\nimport type {\n Attachment,\n Finding,\n FindingOutcome,\n FindingSignal,\n FindingSource,\n GuardRequest,\n GuardResponse,\n TrustGuardOptions,\n} from \"./types.js\";\n\nconst EVALUATE_PATH = \"/v1/evaluate\";\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\ninterface WireFindingSource {\n kind?: string;\n plugin?: string;\n detector_id?: string;\n detector_name?: string;\n policy_id?: string;\n gate_name?: string;\n}\n\ninterface WireFindingSignal {\n type?: string;\n confidence?: number;\n}\n\ninterface WireFindingOutcome {\n action?: string;\n}\n\ninterface WireFinding {\n source?: WireFindingSource;\n signal?: WireFindingSignal;\n outcome?: WireFindingOutcome;\n evidence?: Record<string, unknown>;\n}\n\ninterface WireResponse {\n status?: string;\n transformed_payload?: Record<string, unknown> | null;\n findings?: WireFinding[];\n trace_id?: string;\n request_id?: string;\n}\n\n/** Client for the TrustGuard runtime evaluate API. */\nexport class TrustGuard {\n readonly #baseUrl: string;\n readonly #apiKey: string;\n readonly #timeoutMs: number;\n readonly #fetch: typeof fetch;\n\n constructor(options: TrustGuardOptions) {\n const baseUrl = options.baseUrl?.trim().replace(/\\/+$/, \"\");\n if (!baseUrl) {\n throw new Error(\"TrustGuard: baseUrl is required\");\n }\n if (!options.apiKey?.trim()) {\n throw new Error(\"TrustGuard: apiKey is required\");\n }\n this.#baseUrl = baseUrl;\n this.#apiKey = options.apiKey;\n this.#timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n this.#fetch = options.fetch ?? globalThis.fetch;\n }\n\n /**\n * Evaluates the request against the policy attached to the API key and\n * returns the verdict. Throws TrustGuardAPIError on non-2xx responses.\n */\n async guard(request: GuardRequest): Promise<GuardResponse> {\n if (!request.payload) {\n throw new Error(\"TrustGuard: request payload is required\");\n }\n\n const response = await this.#fetch(this.#baseUrl + EVALUATE_PATH, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${this.#apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(serializeRequest(request)),\n signal: AbortSignal.timeout(this.#timeoutMs),\n });\n\n const text = await response.text();\n if (!response.ok) {\n throw apiError(response.status, text);\n }\n\n return deserializeResponse(parseJson(text) ?? {});\n }\n}\n\n/** Maps the camelCase request onto the snake_case wire format, omitting empty optionals (the server rejects unknown top-level fields). */\nfunction serializeRequest(request: GuardRequest): Record<string, unknown> {\n let payload = request.payload;\n if (request.attachments?.length) {\n payload = { ...payload, attachments: request.attachments.map(serializeAttachment) };\n }\n const body: Record<string, unknown> = { payload };\n if (request.direction) body.direction = request.direction;\n if (request.protocol) body.protocol = request.protocol;\n if (request.sessionId) body.session_id = request.sessionId;\n if (request.consumerId) body.consumer_id = request.consumerId;\n if (request.attributes && Object.keys(request.attributes).length > 0) body.attributes = request.attributes;\n return body;\n}\n\nfunction serializeAttachment(attachment: Attachment): Record<string, string> {\n const entry: Record<string, string> = {\n filename: attachment.filename,\n content_type: attachment.contentType,\n };\n if (attachment.data !== undefined) {\n const bytes = typeof attachment.data === \"string\" ? new TextEncoder().encode(attachment.data) : attachment.data;\n entry.data = toBase64(bytes);\n }\n if (attachment.url !== undefined) entry.url = attachment.url;\n return entry;\n}\n\n/** Base64 without Buffer, so the client also runs on edge runtimes. Chunked to stay under the argument limit of fromCharCode. */\nfunction toBase64(bytes: Uint8Array): string {\n let binary = \"\";\n for (let i = 0; i < bytes.length; i += 0x8000) {\n binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));\n }\n return btoa(binary);\n}\n\nfunction deserializeResponse(wire: WireResponse): GuardResponse {\n const status = wire.status ?? \"\";\n return {\n status,\n isBlocked: status === \"block\",\n transformedPayload: wire.transformed_payload ?? null,\n findings: (wire.findings ?? []).map(deserializeFinding),\n traceId: wire.trace_id ?? \"\",\n requestId: wire.request_id ?? \"\",\n };\n}\n\nfunction deserializeFinding(f: WireFinding): Finding {\n const sourceWire = f.source ?? {};\n const source: FindingSource = {\n kind: sourceWire.kind ?? \"\",\n };\n if (sourceWire.plugin !== undefined) source.plugin = sourceWire.plugin;\n if (sourceWire.detector_id !== undefined) source.detectorId = sourceWire.detector_id;\n if (sourceWire.detector_name !== undefined) source.detectorName = sourceWire.detector_name;\n if (sourceWire.policy_id !== undefined) source.policyId = sourceWire.policy_id;\n if (sourceWire.gate_name !== undefined) source.gateName = sourceWire.gate_name;\n\n const finding: Finding = { source };\n if (f.signal?.type) {\n const signal: FindingSignal = { type: f.signal.type };\n if (f.signal.confidence !== undefined) signal.confidence = f.signal.confidence;\n finding.signal = signal;\n }\n if (f.outcome?.action) {\n const outcome: FindingOutcome = { action: f.outcome.action };\n finding.outcome = outcome;\n }\n if (f.evidence && Object.keys(f.evidence).length > 0) {\n finding.evidence = f.evidence;\n }\n return finding;\n}\n\nfunction apiError(status: number, text: string): TrustGuardAPIError {\n const payload = parseJson(text) as { error?: string; message?: string; trace_id?: string; request_id?: string } | undefined;\n const message = payload?.error || payload?.message || text.trim() || `HTTP ${status}`;\n return new TrustGuardAPIError(status, message, payload?.trace_id ?? \"\", payload?.request_id ?? \"\");\n}\n\nfunction parseJson(text: string): WireResponse | undefined {\n try {\n return JSON.parse(text) as WireResponse;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,SAAiB,SAAiB,WAAmB;AAC/E,UAAM,wBAAwB,MAAM,KAAK,OAAO,cAAc,OAAO,gBAAgB,SAAS,GAAG;AACjG,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,UAAU;AACf,SAAK,YAAY;AAAA,EACnB;AACF;;;ACLA,IAAM,gBAAgB;AACtB,IAAM,qBAAqB;AAoCpB,IAAM,aAAN,MAAiB;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,SAA4B;AACtC,UAAM,UAAU,QAAQ,SAAS,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAC1D,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AACA,QAAI,CAAC,QAAQ,QAAQ,KAAK,GAAG;AAC3B,YAAM,IAAI,MAAM,gCAAgC;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;AAClB,UAAM,SAAwB,EAAE,MAAM,EAAE,OAAO,KAAK;AACpD,QAAI,EAAE,OAAO,eAAe,OAAW,QAAO,aAAa,EAAE,OAAO;AACpE,YAAQ,SAAS;AAAA,EACnB;AACA,MAAI,EAAE,SAAS,QAAQ;AACrB,UAAM,UAA0B,EAAE,QAAQ,EAAE,QAAQ,OAAO;AAC3D,YAAQ,UAAU;AAAA,EACpB;AACA,MAAI,EAAE,YAAY,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,GAAG;AACpD,YAAQ,WAAW,EAAE;AAAA,EACvB;AACA,SAAO;AACT;AAEA,SAAS,SAAS,QAAgB,MAAkC;AAClE,QAAM,UAAU,UAAU,IAAI;AAC9B,QAAM,UAAU,SAAS,SAAS,SAAS,WAAW,KAAK,KAAK,KAAK,QAAQ,MAAM;AACnF,SAAO,IAAI,mBAAmB,QAAQ,SAAS,SAAS,YAAY,IAAI,SAAS,cAAc,EAAE;AACnG;AAEA,SAAS,UAAU,MAAwC;AACzD,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,100 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
type Direction = "input" | "output";
|
|
3
|
-
/** Traffic protocol the policy rules are scoped to. Defaults to "all" server-side. */
|
|
4
|
-
type Protocol = "all" | "llm" | "mcp" | "a2a";
|
|
5
|
-
/** A document evaluated alongside the payload by file-aware plugins. */
|
|
6
|
-
interface Attachment {
|
|
7
|
-
filename: string;
|
|
8
|
-
contentType: string;
|
|
9
|
-
/** Raw file content; strings are encoded as UTF-8, then base64 on the wire. Provide `data` or `url`. */
|
|
10
|
-
data?: Uint8Array | string;
|
|
11
|
-
/** URL for the server to fetch instead of inlining `data`. */
|
|
12
|
-
url?: string;
|
|
13
|
-
}
|
|
14
|
-
/** Payload for a guard evaluation (`POST /v1/evaluate`). */
|
|
15
|
-
interface GuardRequest {
|
|
16
|
-
/** The content to evaluate, e.g. `{ input: "..." }` or provider-shaped fields. Required. */
|
|
17
|
-
payload: Record<string, unknown>;
|
|
18
|
-
/** Traffic side; the server defaults to "input" when omitted. */
|
|
19
|
-
direction?: Direction;
|
|
20
|
-
/** Traffic protocol; the server defaults to "all" when omitted. */
|
|
21
|
-
protocol?: Protocol;
|
|
22
|
-
/** Groups multi-turn traffic; the server synthesises one when omitted. */
|
|
23
|
-
sessionId?: string;
|
|
24
|
-
/** Identifies the end user on whose behalf the request runs. */
|
|
25
|
-
consumerId?: string;
|
|
26
|
-
/** Optional routing hints. Server-side key: `content_type` (overrides the payload content type). */
|
|
27
|
-
attributes?: Record<string, unknown>;
|
|
28
|
-
/** Documents to evaluate; folded into `payload.attachments` on the wire. */
|
|
29
|
-
attachments?: Attachment[];
|
|
30
|
-
}
|
|
31
|
-
/** Who produced the finding — a detector or a gate. */
|
|
32
|
-
interface FindingSource {
|
|
33
|
-
kind: string;
|
|
34
|
-
plugin?: string;
|
|
35
|
-
detectorId?: string;
|
|
36
|
-
detectorName?: string;
|
|
37
|
-
policyId?: string;
|
|
38
|
-
gateName?: string;
|
|
39
|
-
}
|
|
40
|
-
/** Detection signal when the finding fired (omitted for observational-only runs). */
|
|
41
|
-
interface FindingSignal {
|
|
42
|
-
type: string;
|
|
43
|
-
confidence?: number;
|
|
44
|
-
}
|
|
45
|
-
/** Applied execution-rule action when the finding enforced an outcome. */
|
|
46
|
-
interface FindingOutcome {
|
|
47
|
-
action: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* A single finding from the evaluate response.
|
|
51
|
-
* Observational (below-threshold) runs keep `source` + `evidence` only.
|
|
52
|
-
*/
|
|
53
|
-
interface Finding {
|
|
54
|
-
source: FindingSource;
|
|
55
|
-
signal?: FindingSignal;
|
|
56
|
-
outcome?: FindingOutcome;
|
|
57
|
-
evidence?: Record<string, unknown>;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Verdict returned by POST /v1/evaluate. TrustGuard detects; the caller enforces:
|
|
61
|
-
* block when `status` is "block" (`isBlocked` is the convenience signal).
|
|
62
|
-
*/
|
|
63
|
-
interface GuardResponse {
|
|
64
|
-
/** Most restrictive verdict: "allow", "block", "transform", "report", or "" when omitted. */
|
|
65
|
-
status: string;
|
|
66
|
-
/** Convenience flag: true when `status === "block"`. */
|
|
67
|
-
isBlocked: boolean;
|
|
68
|
-
/** The payload as rewritten by in-flight masking, null when untouched. */
|
|
69
|
-
transformedPayload: Record<string, unknown> | null;
|
|
70
|
-
/** What every plugin / gate in the policy chain reported. */
|
|
71
|
-
findings: Finding[];
|
|
72
|
-
/** Correlation ids for TrustGuard telemetry. */
|
|
73
|
-
traceId: string;
|
|
74
|
-
requestId: string;
|
|
75
|
-
}
|
|
76
|
-
/** Configuration for the TrustGuard client. */
|
|
77
|
-
interface TrustGuardOptions {
|
|
78
|
-
/** Base URL of the TrustGuard deployment, e.g. https://trustguard.neuraltrust.ai */
|
|
79
|
-
baseUrl: string;
|
|
80
|
-
/** Collector API key, sent as a Bearer token. */
|
|
81
|
-
apiKey: string;
|
|
82
|
-
/** Per-request timeout in milliseconds. Default 10000. */
|
|
83
|
-
timeoutMs?: number;
|
|
84
|
-
/** Custom fetch implementation (proxies, test doubles). Default globalThis.fetch. */
|
|
85
|
-
fetch?: typeof fetch;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** Client for the TrustGuard runtime evaluate API. */
|
|
89
|
-
declare class TrustGuard {
|
|
90
|
-
#private;
|
|
91
|
-
constructor(options: TrustGuardOptions);
|
|
92
|
-
/**
|
|
93
|
-
* Evaluates the request against the policy attached to the API key and
|
|
94
|
-
* returns the verdict. Throws TrustGuardAPIError on non-2xx responses.
|
|
95
|
-
*/
|
|
96
|
-
guard(request: GuardRequest): Promise<GuardResponse>;
|
|
97
|
-
}
|
|
1
|
+
export { A as Attachment, D as Direction, F as Finding, a as FindingOutcome, b as FindingSignal, c as FindingSource, d as GuardRequest, G as GuardResponse, P as Protocol, T as TrustGuard, e as TrustGuardOptions } from './client-ZoD3M6yg.cjs';
|
|
98
2
|
|
|
99
3
|
/**
|
|
100
4
|
* A non-2xx response from the TrustGuard API, carrying the status code and the
|
|
@@ -108,4 +12,4 @@ declare class TrustGuardAPIError extends Error {
|
|
|
108
12
|
constructor(status: number, message: string, traceId: string, requestId: string);
|
|
109
13
|
}
|
|
110
14
|
|
|
111
|
-
export {
|
|
15
|
+
export { TrustGuardAPIError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,100 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
type Direction = "input" | "output";
|
|
3
|
-
/** Traffic protocol the policy rules are scoped to. Defaults to "all" server-side. */
|
|
4
|
-
type Protocol = "all" | "llm" | "mcp" | "a2a";
|
|
5
|
-
/** A document evaluated alongside the payload by file-aware plugins. */
|
|
6
|
-
interface Attachment {
|
|
7
|
-
filename: string;
|
|
8
|
-
contentType: string;
|
|
9
|
-
/** Raw file content; strings are encoded as UTF-8, then base64 on the wire. Provide `data` or `url`. */
|
|
10
|
-
data?: Uint8Array | string;
|
|
11
|
-
/** URL for the server to fetch instead of inlining `data`. */
|
|
12
|
-
url?: string;
|
|
13
|
-
}
|
|
14
|
-
/** Payload for a guard evaluation (`POST /v1/evaluate`). */
|
|
15
|
-
interface GuardRequest {
|
|
16
|
-
/** The content to evaluate, e.g. `{ input: "..." }` or provider-shaped fields. Required. */
|
|
17
|
-
payload: Record<string, unknown>;
|
|
18
|
-
/** Traffic side; the server defaults to "input" when omitted. */
|
|
19
|
-
direction?: Direction;
|
|
20
|
-
/** Traffic protocol; the server defaults to "all" when omitted. */
|
|
21
|
-
protocol?: Protocol;
|
|
22
|
-
/** Groups multi-turn traffic; the server synthesises one when omitted. */
|
|
23
|
-
sessionId?: string;
|
|
24
|
-
/** Identifies the end user on whose behalf the request runs. */
|
|
25
|
-
consumerId?: string;
|
|
26
|
-
/** Optional routing hints. Server-side key: `content_type` (overrides the payload content type). */
|
|
27
|
-
attributes?: Record<string, unknown>;
|
|
28
|
-
/** Documents to evaluate; folded into `payload.attachments` on the wire. */
|
|
29
|
-
attachments?: Attachment[];
|
|
30
|
-
}
|
|
31
|
-
/** Who produced the finding — a detector or a gate. */
|
|
32
|
-
interface FindingSource {
|
|
33
|
-
kind: string;
|
|
34
|
-
plugin?: string;
|
|
35
|
-
detectorId?: string;
|
|
36
|
-
detectorName?: string;
|
|
37
|
-
policyId?: string;
|
|
38
|
-
gateName?: string;
|
|
39
|
-
}
|
|
40
|
-
/** Detection signal when the finding fired (omitted for observational-only runs). */
|
|
41
|
-
interface FindingSignal {
|
|
42
|
-
type: string;
|
|
43
|
-
confidence?: number;
|
|
44
|
-
}
|
|
45
|
-
/** Applied execution-rule action when the finding enforced an outcome. */
|
|
46
|
-
interface FindingOutcome {
|
|
47
|
-
action: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* A single finding from the evaluate response.
|
|
51
|
-
* Observational (below-threshold) runs keep `source` + `evidence` only.
|
|
52
|
-
*/
|
|
53
|
-
interface Finding {
|
|
54
|
-
source: FindingSource;
|
|
55
|
-
signal?: FindingSignal;
|
|
56
|
-
outcome?: FindingOutcome;
|
|
57
|
-
evidence?: Record<string, unknown>;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Verdict returned by POST /v1/evaluate. TrustGuard detects; the caller enforces:
|
|
61
|
-
* block when `status` is "block" (`isBlocked` is the convenience signal).
|
|
62
|
-
*/
|
|
63
|
-
interface GuardResponse {
|
|
64
|
-
/** Most restrictive verdict: "allow", "block", "transform", "report", or "" when omitted. */
|
|
65
|
-
status: string;
|
|
66
|
-
/** Convenience flag: true when `status === "block"`. */
|
|
67
|
-
isBlocked: boolean;
|
|
68
|
-
/** The payload as rewritten by in-flight masking, null when untouched. */
|
|
69
|
-
transformedPayload: Record<string, unknown> | null;
|
|
70
|
-
/** What every plugin / gate in the policy chain reported. */
|
|
71
|
-
findings: Finding[];
|
|
72
|
-
/** Correlation ids for TrustGuard telemetry. */
|
|
73
|
-
traceId: string;
|
|
74
|
-
requestId: string;
|
|
75
|
-
}
|
|
76
|
-
/** Configuration for the TrustGuard client. */
|
|
77
|
-
interface TrustGuardOptions {
|
|
78
|
-
/** Base URL of the TrustGuard deployment, e.g. https://trustguard.neuraltrust.ai */
|
|
79
|
-
baseUrl: string;
|
|
80
|
-
/** Collector API key, sent as a Bearer token. */
|
|
81
|
-
apiKey: string;
|
|
82
|
-
/** Per-request timeout in milliseconds. Default 10000. */
|
|
83
|
-
timeoutMs?: number;
|
|
84
|
-
/** Custom fetch implementation (proxies, test doubles). Default globalThis.fetch. */
|
|
85
|
-
fetch?: typeof fetch;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** Client for the TrustGuard runtime evaluate API. */
|
|
89
|
-
declare class TrustGuard {
|
|
90
|
-
#private;
|
|
91
|
-
constructor(options: TrustGuardOptions);
|
|
92
|
-
/**
|
|
93
|
-
* Evaluates the request against the policy attached to the API key and
|
|
94
|
-
* returns the verdict. Throws TrustGuardAPIError on non-2xx responses.
|
|
95
|
-
*/
|
|
96
|
-
guard(request: GuardRequest): Promise<GuardResponse>;
|
|
97
|
-
}
|
|
1
|
+
export { A as Attachment, D as Direction, F as Finding, a as FindingOutcome, b as FindingSignal, c as FindingSource, d as GuardRequest, G as GuardResponse, P as Protocol, T as TrustGuard, e as TrustGuardOptions } from './client-ZoD3M6yg.js';
|
|
98
2
|
|
|
99
3
|
/**
|
|
100
4
|
* A non-2xx response from the TrustGuard API, carrying the status code and the
|
|
@@ -108,4 +12,4 @@ declare class TrustGuardAPIError extends Error {
|
|
|
108
12
|
constructor(status: number, message: string, traceId: string, requestId: string);
|
|
109
13
|
}
|
|
110
14
|
|
|
111
|
-
export {
|
|
15
|
+
export { TrustGuardAPIError };
|
package/dist/index.js
CHANGED
|
@@ -76,12 +76,19 @@ function serializeAttachment(attachment) {
|
|
|
76
76
|
content_type: attachment.contentType
|
|
77
77
|
};
|
|
78
78
|
if (attachment.data !== void 0) {
|
|
79
|
-
const bytes = typeof attachment.data === "string" ?
|
|
80
|
-
entry.data = bytes
|
|
79
|
+
const bytes = typeof attachment.data === "string" ? new TextEncoder().encode(attachment.data) : attachment.data;
|
|
80
|
+
entry.data = toBase64(bytes);
|
|
81
81
|
}
|
|
82
82
|
if (attachment.url !== void 0) entry.url = attachment.url;
|
|
83
83
|
return entry;
|
|
84
84
|
}
|
|
85
|
+
function toBase64(bytes) {
|
|
86
|
+
let binary = "";
|
|
87
|
+
for (let i = 0; i < bytes.length; i += 32768) {
|
|
88
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
89
|
+
}
|
|
90
|
+
return btoa(binary);
|
|
91
|
+
}
|
|
85
92
|
function deserializeResponse(wire) {
|
|
86
93
|
const status = wire.status ?? "";
|
|
87
94
|
return {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["/**\n * A non-2xx response from the TrustGuard API, carrying the status code and the\n * correlation ids needed to chase the request in telemetry. Transport-level\n * failures (network errors, timeouts) are thrown as-is instead.\n */\nexport class TrustGuardAPIError extends Error {\n readonly status: number;\n readonly traceId: string;\n readonly requestId: string;\n\n constructor(status: number, message: string, traceId: string, requestId: string) {\n super(`TrustGuard API error ${status}: ${message} (trace_id=${traceId}, request_id=${requestId})`);\n this.name = \"TrustGuardAPIError\";\n this.status = status;\n this.traceId = traceId;\n this.requestId = requestId;\n }\n}\n","import { TrustGuardAPIError } from \"./errors.js\";\nimport type {\n Attachment,\n Finding,\n FindingOutcome,\n FindingSignal,\n FindingSource,\n GuardRequest,\n GuardResponse,\n TrustGuardOptions,\n} from \"./types.js\";\n\nconst EVALUATE_PATH = \"/v1/evaluate\";\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\ninterface WireFindingSource {\n kind?: string;\n plugin?: string;\n detector_id?: string;\n detector_name?: string;\n policy_id?: string;\n gate_name?: string;\n}\n\ninterface WireFindingSignal {\n type?: string;\n confidence?: number;\n}\n\ninterface WireFindingOutcome {\n action?: string;\n}\n\ninterface WireFinding {\n source?: WireFindingSource;\n signal?: WireFindingSignal;\n outcome?: WireFindingOutcome;\n evidence?: Record<string, unknown>;\n}\n\ninterface WireResponse {\n status?: string;\n transformed_payload?: Record<string, unknown> | null;\n findings?: WireFinding[];\n trace_id?: string;\n request_id?: string;\n}\n\n/** Client for the TrustGuard runtime evaluate API. */\nexport class TrustGuard {\n readonly #baseUrl: string;\n readonly #apiKey: string;\n readonly #timeoutMs: number;\n readonly #fetch: typeof fetch;\n\n constructor(options: TrustGuardOptions) {\n const baseUrl = options.baseUrl?.trim().replace(/\\/+$/, \"\");\n if (!baseUrl) {\n throw new Error(\"TrustGuard: baseUrl is required\");\n }\n if (!options.apiKey?.trim()) {\n throw new Error(\"TrustGuard: apiKey is required\");\n }\n this.#baseUrl = baseUrl;\n this.#apiKey = options.apiKey;\n this.#timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n this.#fetch = options.fetch ?? globalThis.fetch;\n }\n\n /**\n * Evaluates the request against the policy attached to the API key and\n * returns the verdict. Throws TrustGuardAPIError on non-2xx responses.\n */\n async guard(request: GuardRequest): Promise<GuardResponse> {\n if (!request.payload) {\n throw new Error(\"TrustGuard: request payload is required\");\n }\n\n const response = await this.#fetch(this.#baseUrl + EVALUATE_PATH, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${this.#apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(serializeRequest(request)),\n signal: AbortSignal.timeout(this.#timeoutMs),\n });\n\n const text = await response.text();\n if (!response.ok) {\n throw apiError(response.status, text);\n }\n\n return deserializeResponse(parseJson(text) ?? {});\n }\n}\n\n/** Maps the camelCase request onto the snake_case wire format, omitting empty optionals (the server rejects unknown top-level fields). */\nfunction serializeRequest(request: GuardRequest): Record<string, unknown> {\n let payload = request.payload;\n if (request.attachments?.length) {\n payload = { ...payload, attachments: request.attachments.map(serializeAttachment) };\n }\n const body: Record<string, unknown> = { payload };\n if (request.direction) body.direction = request.direction;\n if (request.protocol) body.protocol = request.protocol;\n if (request.sessionId) body.session_id = request.sessionId;\n if (request.consumerId) body.consumer_id = request.consumerId;\n if (request.attributes && Object.keys(request.attributes).length > 0) body.attributes = request.attributes;\n return body;\n}\n\nfunction serializeAttachment(attachment: Attachment): Record<string, string> {\n const entry: Record<string, string> = {\n filename: attachment.filename,\n content_type: attachment.contentType,\n };\n if (attachment.data !== undefined) {\n const bytes =\n typeof attachment.data === \"string\" ? Buffer.from(attachment.data, \"utf-8\") : Buffer.from(attachment.data);\n entry.data = bytes.toString(\"base64\");\n }\n if (attachment.url !== undefined) entry.url = attachment.url;\n return entry;\n}\n\nfunction deserializeResponse(wire: WireResponse): GuardResponse {\n const status = wire.status ?? \"\";\n return {\n status,\n isBlocked: status === \"block\",\n transformedPayload: wire.transformed_payload ?? null,\n findings: (wire.findings ?? []).map(deserializeFinding),\n traceId: wire.trace_id ?? \"\",\n requestId: wire.request_id ?? \"\",\n };\n}\n\nfunction deserializeFinding(f: WireFinding): Finding {\n const sourceWire = f.source ?? {};\n const source: FindingSource = {\n kind: sourceWire.kind ?? \"\",\n };\n if (sourceWire.plugin !== undefined) source.plugin = sourceWire.plugin;\n if (sourceWire.detector_id !== undefined) source.detectorId = sourceWire.detector_id;\n if (sourceWire.detector_name !== undefined) source.detectorName = sourceWire.detector_name;\n if (sourceWire.policy_id !== undefined) source.policyId = sourceWire.policy_id;\n if (sourceWire.gate_name !== undefined) source.gateName = sourceWire.gate_name;\n\n const finding: Finding = { source };\n if (f.signal?.type) {\n const signal: FindingSignal = { type: f.signal.type };\n if (f.signal.confidence !== undefined) signal.confidence = f.signal.confidence;\n finding.signal = signal;\n }\n if (f.outcome?.action) {\n const outcome: FindingOutcome = { action: f.outcome.action };\n finding.outcome = outcome;\n }\n if (f.evidence && Object.keys(f.evidence).length > 0) {\n finding.evidence = f.evidence;\n }\n return finding;\n}\n\nfunction apiError(status: number, text: string): TrustGuardAPIError {\n const payload = parseJson(text) as { error?: string; message?: string; trace_id?: string; request_id?: string } | undefined;\n const message = payload?.error || payload?.message || text.trim() || `HTTP ${status}`;\n return new TrustGuardAPIError(status, message, payload?.trace_id ?? \"\", payload?.request_id ?? \"\");\n}\n\nfunction parseJson(text: string): WireResponse | undefined {\n try {\n return JSON.parse(text) as WireResponse;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";AAKO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,SAAiB,SAAiB,WAAmB;AAC/E,UAAM,wBAAwB,MAAM,KAAK,OAAO,cAAc,OAAO,gBAAgB,SAAS,GAAG;AACjG,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,UAAU;AACf,SAAK,YAAY;AAAA,EACnB;AACF;;;ACLA,IAAM,gBAAgB;AACtB,IAAM,qBAAqB;AAoCpB,IAAM,aAAN,MAAiB;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,SAA4B;AACtC,UAAM,UAAU,QAAQ,SAAS,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAC1D,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AACA,QAAI,CAAC,QAAQ,QAAQ,KAAK,GAAG;AAC3B,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AACA,SAAK,WAAW;AAChB,SAAK,UAAU,QAAQ;AACvB,SAAK,aAAa,QAAQ,aAAa;AACvC,SAAK,SAAS,QAAQ,SAAS,WAAW;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,MAAM,SAA+C;AACzD,QAAI,CAAC,QAAQ,SAAS;AACpB,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AAEA,UAAM,WAAW,MAAM,KAAK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AAK,KAAK,QAAQ,MAAM;AACnF,SAAO,IAAI,mBAAmB,QAAQ,SAAS,SAAS,YAAY,IAAI,SAAS,cAAc,EAAE;AACnG;AAEA,SAAS,UAAU,MAAwC;AACzD,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["/**\n * A non-2xx response from the TrustGuard API, carrying the status code and the\n * correlation ids needed to chase the request in telemetry. Transport-level\n * failures (network errors, timeouts) are thrown as-is instead.\n */\nexport class TrustGuardAPIError extends Error {\n readonly status: number;\n readonly traceId: string;\n readonly requestId: string;\n\n constructor(status: number, message: string, traceId: string, requestId: string) {\n super(`TrustGuard API error ${status}: ${message} (trace_id=${traceId}, request_id=${requestId})`);\n this.name = \"TrustGuardAPIError\";\n this.status = status;\n this.traceId = traceId;\n this.requestId = requestId;\n }\n}\n","import { TrustGuardAPIError } from \"./errors.js\";\nimport type {\n Attachment,\n Finding,\n FindingOutcome,\n FindingSignal,\n FindingSource,\n GuardRequest,\n GuardResponse,\n TrustGuardOptions,\n} from \"./types.js\";\n\nconst EVALUATE_PATH = \"/v1/evaluate\";\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\ninterface WireFindingSource {\n kind?: string;\n plugin?: string;\n detector_id?: string;\n detector_name?: string;\n policy_id?: string;\n gate_name?: string;\n}\n\ninterface WireFindingSignal {\n type?: string;\n confidence?: number;\n}\n\ninterface WireFindingOutcome {\n action?: string;\n}\n\ninterface WireFinding {\n source?: WireFindingSource;\n signal?: WireFindingSignal;\n outcome?: WireFindingOutcome;\n evidence?: Record<string, unknown>;\n}\n\ninterface WireResponse {\n status?: string;\n transformed_payload?: Record<string, unknown> | null;\n findings?: WireFinding[];\n trace_id?: string;\n request_id?: string;\n}\n\n/** Client for the TrustGuard runtime evaluate API. */\nexport class TrustGuard {\n readonly #baseUrl: string;\n readonly #apiKey: string;\n readonly #timeoutMs: number;\n readonly #fetch: typeof fetch;\n\n constructor(options: TrustGuardOptions) {\n const baseUrl = options.baseUrl?.trim().replace(/\\/+$/, \"\");\n if (!baseUrl) {\n throw new Error(\"TrustGuard: baseUrl is required\");\n }\n if (!options.apiKey?.trim()) {\n throw new Error(\"TrustGuard: apiKey is required\");\n }\n this.#baseUrl = baseUrl;\n this.#apiKey = options.apiKey;\n this.#timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n this.#fetch = options.fetch ?? globalThis.fetch;\n }\n\n /**\n * Evaluates the request against the policy attached to the API key and\n * returns the verdict. Throws TrustGuardAPIError on non-2xx responses.\n */\n async guard(request: GuardRequest): Promise<GuardResponse> {\n if (!request.payload) {\n throw new Error(\"TrustGuard: request payload is required\");\n }\n\n const response = await this.#fetch(this.#baseUrl + EVALUATE_PATH, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${this.#apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(serializeRequest(request)),\n signal: AbortSignal.timeout(this.#timeoutMs),\n });\n\n const text = await response.text();\n if (!response.ok) {\n throw apiError(response.status, text);\n }\n\n return deserializeResponse(parseJson(text) ?? {});\n }\n}\n\n/** Maps the camelCase request onto the snake_case wire format, omitting empty optionals (the server rejects unknown top-level fields). */\nfunction serializeRequest(request: GuardRequest): Record<string, unknown> {\n let payload = request.payload;\n if (request.attachments?.length) {\n payload = { ...payload, attachments: request.attachments.map(serializeAttachment) };\n }\n const body: Record<string, unknown> = { payload };\n if (request.direction) body.direction = request.direction;\n if (request.protocol) body.protocol = request.protocol;\n if (request.sessionId) body.session_id = request.sessionId;\n if (request.consumerId) body.consumer_id = request.consumerId;\n if (request.attributes && Object.keys(request.attributes).length > 0) body.attributes = request.attributes;\n return body;\n}\n\nfunction serializeAttachment(attachment: Attachment): Record<string, string> {\n const entry: Record<string, string> = {\n filename: attachment.filename,\n content_type: attachment.contentType,\n };\n if (attachment.data !== undefined) {\n const bytes = typeof attachment.data === \"string\" ? new TextEncoder().encode(attachment.data) : attachment.data;\n entry.data = toBase64(bytes);\n }\n if (attachment.url !== undefined) entry.url = attachment.url;\n return entry;\n}\n\n/** Base64 without Buffer, so the client also runs on edge runtimes. Chunked to stay under the argument limit of fromCharCode. */\nfunction toBase64(bytes: Uint8Array): string {\n let binary = \"\";\n for (let i = 0; i < bytes.length; i += 0x8000) {\n binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));\n }\n return btoa(binary);\n}\n\nfunction deserializeResponse(wire: WireResponse): GuardResponse {\n const status = wire.status ?? \"\";\n return {\n status,\n isBlocked: status === \"block\",\n transformedPayload: wire.transformed_payload ?? null,\n findings: (wire.findings ?? []).map(deserializeFinding),\n traceId: wire.trace_id ?? \"\",\n requestId: wire.request_id ?? \"\",\n };\n}\n\nfunction deserializeFinding(f: WireFinding): Finding {\n const sourceWire = f.source ?? {};\n const source: FindingSource = {\n kind: sourceWire.kind ?? \"\",\n };\n if (sourceWire.plugin !== undefined) source.plugin = sourceWire.plugin;\n if (sourceWire.detector_id !== undefined) source.detectorId = sourceWire.detector_id;\n if (sourceWire.detector_name !== undefined) source.detectorName = sourceWire.detector_name;\n if (sourceWire.policy_id !== undefined) source.policyId = sourceWire.policy_id;\n if (sourceWire.gate_name !== undefined) source.gateName = sourceWire.gate_name;\n\n const finding: Finding = { source };\n if (f.signal?.type) {\n const signal: FindingSignal = { type: f.signal.type };\n if (f.signal.confidence !== undefined) signal.confidence = f.signal.confidence;\n finding.signal = signal;\n }\n if (f.outcome?.action) {\n const outcome: FindingOutcome = { action: f.outcome.action };\n finding.outcome = outcome;\n }\n if (f.evidence && Object.keys(f.evidence).length > 0) {\n finding.evidence = f.evidence;\n }\n return finding;\n}\n\nfunction apiError(status: number, text: string): TrustGuardAPIError {\n const payload = parseJson(text) as { error?: string; message?: string; trace_id?: string; request_id?: string } | undefined;\n const message = payload?.error || payload?.message || text.trim() || `HTTP ${status}`;\n return new TrustGuardAPIError(status, message, payload?.trace_id ?? \"\", payload?.request_id ?? \"\");\n}\n\nfunction parseJson(text: string): WireResponse | undefined {\n try {\n return JSON.parse(text) as WireResponse;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";AAKO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,SAAiB,SAAiB,WAAmB;AAC/E,UAAM,wBAAwB,MAAM,KAAK,OAAO,cAAc,OAAO,gBAAgB,SAAS,GAAG;AACjG,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,UAAU;AACf,SAAK,YAAY;AAAA,EACnB;AACF;;;ACLA,IAAM,gBAAgB;AACtB,IAAM,qBAAqB;AAoCpB,IAAM,aAAN,MAAiB;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,SAA4B;AACtC,UAAM,UAAU,QAAQ,SAAS,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAC1D,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AACA,QAAI,CAAC,QAAQ,QAAQ,KAAK,GAAG;AAC3B,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AACA,SAAK,WAAW;AAChB,SAAK,UAAU,QAAQ;AACvB,SAAK,aAAa,QAAQ,aAAa;AACvC,SAAK,SAAS,QAAQ,SAAS,WAAW;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,MAAM,SAA+C;AACzD,QAAI,CAAC,QAAQ,SAAS;AACpB,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AAEA,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,WAAW,eAAe;AAAA,MAChE,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,eAAe,UAAU,KAAK,OAAO;AAAA,QACrC,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM,KAAK,UAAU,iBAAiB,OAAO,CAAC;AA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AW,KAAK,KAAK,KAAK,QAAQ,MAAM;AACnF,SAAO,IAAI,mBAAmB,QAAQ,SAAS,SAAS,YAAY,IAAI,SAAS,cAAc,EAAE;AACnG;AAEA,SAAS,UAAU,MAAwC;AACzD,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neuraltrust/trustguard-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Official Node.js SDK for the TrustGuard runtime evaluate API (POST /v1/evaluate)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "NeuralTrust",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"trustguard",
|
|
19
19
|
"guardrails",
|
|
20
20
|
"llm-security",
|
|
21
|
-
"ai-firewall"
|
|
21
|
+
"ai-firewall",
|
|
22
|
+
"vercel",
|
|
23
|
+
"ai-sdk"
|
|
22
24
|
],
|
|
23
25
|
"type": "module",
|
|
24
26
|
"main": "./dist/index.cjs",
|
|
@@ -29,6 +31,11 @@
|
|
|
29
31
|
"types": "./dist/index.d.ts",
|
|
30
32
|
"import": "./dist/index.js",
|
|
31
33
|
"require": "./dist/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./ai-sdk": {
|
|
36
|
+
"types": "./dist/ai-sdk/index.d.ts",
|
|
37
|
+
"import": "./dist/ai-sdk/index.js",
|
|
38
|
+
"require": "./dist/ai-sdk/index.cjs"
|
|
32
39
|
}
|
|
33
40
|
},
|
|
34
41
|
"files": [
|
|
@@ -44,10 +51,25 @@
|
|
|
44
51
|
"test": "vitest run",
|
|
45
52
|
"prepublishOnly": "npm run lint && npm run test && npm run build"
|
|
46
53
|
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@ai-sdk/provider": "^4.0.0",
|
|
56
|
+
"ai": "^7.0.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"@ai-sdk/provider": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"ai": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
47
66
|
"devDependencies": {
|
|
67
|
+
"@ai-sdk/provider": "^4.0.18",
|
|
48
68
|
"@types/node": "^22.10.2",
|
|
69
|
+
"ai": "^7.0.112",
|
|
49
70
|
"tsup": "^8.3.5",
|
|
50
71
|
"typescript": "^5.7.2",
|
|
51
|
-
"vitest": "^4.1.9"
|
|
72
|
+
"vitest": "^4.1.9",
|
|
73
|
+
"zod": "^4.6.5"
|
|
52
74
|
}
|
|
53
75
|
}
|