@veroq/sdk 2.0.0 → 2.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.
@@ -0,0 +1,108 @@
1
+ /**
2
+ * VeroQ Prompt Shield — One-line verification for any LLM output.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * import { shield } from "@veroq/sdk";
7
+ *
8
+ * const result = await shield("NVIDIA reported $22B in Q4 revenue");
9
+ * console.log(result.trustScore); // 0.73
10
+ * console.log(result.isTrusted); // false
11
+ * console.log(result.corrections); // [{claim, correction, confidence}]
12
+ * console.log(result.verifiedText); // text with corrections inline
13
+ *
14
+ * // Wrap any LLM call
15
+ * const response = await openai.chat.completions.create({...});
16
+ * const verified = await shield(response.choices[0].message.content);
17
+ * ```
18
+ */
19
+ export interface ShieldOptions {
20
+ /** Source identifier (e.g., "gpt-4o", "claude-3") */
21
+ source?: string;
22
+ /** Agent ID for memory integration */
23
+ agentId?: string;
24
+ /** Max claims to extract (1-10, default 5) */
25
+ maxClaims?: number;
26
+ /** API key override */
27
+ apiKey?: string;
28
+ /** If true, throws VeroqError when claims are contradicted */
29
+ blockIfUntrusted?: boolean;
30
+ }
31
+ export interface ShieldClaim {
32
+ text: string;
33
+ category: string;
34
+ verdict: string;
35
+ confidence: number;
36
+ correction: string | null;
37
+ receiptId: string | null;
38
+ evidenceChain: Array<{
39
+ source: string;
40
+ position: string;
41
+ snippet: string;
42
+ }>;
43
+ }
44
+ export declare class ShieldResult {
45
+ /** Original text (truncated) */
46
+ readonly text: string;
47
+ /** Source identifier */
48
+ readonly source: string;
49
+ /** All extracted claims with verdicts */
50
+ readonly claims: ShieldClaim[];
51
+ /** Number of claims extracted */
52
+ readonly claimsExtracted: number;
53
+ /** Number of claims verified */
54
+ readonly claimsVerified: number;
55
+ /** Number of claims supported */
56
+ readonly claimsSupported: number;
57
+ /** Number of claims contradicted */
58
+ readonly claimsContradicted: number;
59
+ /** Overall trust score (0-1) */
60
+ readonly trustScore: number;
61
+ /** Overall verdict */
62
+ readonly overallVerdict: string;
63
+ /** Summary */
64
+ readonly summary: string;
65
+ /** Credits used */
66
+ readonly creditsUsed: number;
67
+ /** Processing time in ms */
68
+ readonly processingTimeMs: number;
69
+ /** Full original text (before server truncation) */
70
+ private readonly _fullText;
71
+ constructor(raw: Record<string, any>, fullText?: string);
72
+ /** True if no claims were contradicted */
73
+ get isTrusted(): boolean;
74
+ /** Corrections for contradicted claims */
75
+ get corrections(): Array<{
76
+ claim: string;
77
+ correction: string;
78
+ confidence: number;
79
+ }>;
80
+ /** Text with contradicted claims annotated */
81
+ get verifiedText(): string;
82
+ /** Verification receipt IDs */
83
+ get receiptIds(): string[];
84
+ }
85
+ /**
86
+ * Shield any LLM output with VeroQ verification.
87
+ *
88
+ * Extracts claims, verifies each against evidence, returns trust score
89
+ * with corrections for any contradicted claims.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * import { shield } from "@veroq/sdk";
94
+ *
95
+ * // Basic
96
+ * const result = await shield("NVIDIA's Q4 revenue exceeded $22B");
97
+ * console.log(result.trustScore, result.corrections);
98
+ *
99
+ * // With options
100
+ * const result = await shield(llmOutput, {
101
+ * source: "gpt-4o",
102
+ * agentId: "my-bot",
103
+ * blockIfUntrusted: true,
104
+ * });
105
+ * ```
106
+ */
107
+ export declare function shield(text: string, options?: ShieldOptions): Promise<ShieldResult>;
108
+ //# sourceMappingURL=shield.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield.d.ts","sourceRoot":"","sources":["../../src/shield.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,C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GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM;IAwBvD,0CAA0C;IAC1C,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,0CAA0C;IAC1C,IAAI,WAAW,IAAI,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAIlF;IAED,8CAA8C;IAC9C,IAAI,YAAY,IAAI,MAAM,CAQzB;IAED,+BAA+B;IAC/B,IAAI,UAAU,IAAI,MAAM,EAAE,CAEzB;CACF;AAYD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAuC7F"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * VeroQ Prompt Shield — One-line verification for any LLM output.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * import { shield } from "@veroq/sdk";
7
+ *
8
+ * const result = await shield("NVIDIA reported $22B in Q4 revenue");
9
+ * console.log(result.trustScore); // 0.73
10
+ * console.log(result.isTrusted); // false
11
+ * console.log(result.corrections); // [{claim, correction, confidence}]
12
+ * console.log(result.verifiedText); // text with corrections inline
13
+ *
14
+ * // Wrap any LLM call
15
+ * const response = await openai.chat.completions.create({...});
16
+ * const verified = await shield(response.choices[0].message.content);
17
+ * ```
18
+ */
19
+ import { VeroqClient } from "./client.js";
20
+ import { VeroqError } from "./errors.js";
21
+ export class ShieldResult {
22
+ constructor(raw, fullText) {
23
+ this._fullText = fullText || raw.text || "";
24
+ this.text = raw.text || "";
25
+ this.source = raw.source || "unknown";
26
+ this.claims = (raw.claims || []).map((c) => ({
27
+ text: c.text,
28
+ category: c.category,
29
+ verdict: c.verdict,
30
+ confidence: c.confidence || 0,
31
+ correction: c.correction || null,
32
+ receiptId: c.receipt_id || null,
33
+ evidenceChain: c.evidence_chain || [],
34
+ }));
35
+ this.claimsExtracted = raw.claims_extracted || 0;
36
+ this.claimsVerified = raw.claims_verified || 0;
37
+ this.claimsSupported = raw.claims_supported || 0;
38
+ this.claimsContradicted = raw.claims_contradicted || 0;
39
+ this.trustScore = raw.overall_confidence || 0;
40
+ this.overallVerdict = raw.overall_verdict || "unknown";
41
+ this.summary = raw.summary || "";
42
+ this.creditsUsed = raw.credits_used || 0;
43
+ this.processingTimeMs = raw.processing_time_ms || 0;
44
+ }
45
+ /** True if no claims were contradicted */
46
+ get isTrusted() {
47
+ return this.claimsContradicted === 0;
48
+ }
49
+ /** Corrections for contradicted claims */
50
+ get corrections() {
51
+ return this.claims
52
+ .filter(c => c.verdict === "contradicted" && c.correction)
53
+ .map(c => ({ claim: c.text, correction: c.correction, confidence: c.confidence }));
54
+ }
55
+ /** Text with contradicted claims annotated */
56
+ get verifiedText() {
57
+ let result = this._fullText;
58
+ for (const c of this.claims) {
59
+ if (c.verdict === "contradicted" && c.correction && result.includes(c.text)) {
60
+ result = result.replace(c.text, `[CORRECTED: ${c.correction.slice(0, 200)}]`);
61
+ }
62
+ }
63
+ return result;
64
+ }
65
+ /** Verification receipt IDs */
66
+ get receiptIds() {
67
+ return this.claims.map(c => c.receiptId).filter((id) => !!id);
68
+ }
69
+ }
70
+ // Module-level client
71
+ let _client = null;
72
+ function getClient(apiKey) {
73
+ if (!_client || apiKey) {
74
+ _client = new VeroqClient({ apiKey });
75
+ }
76
+ return _client;
77
+ }
78
+ /**
79
+ * Shield any LLM output with VeroQ verification.
80
+ *
81
+ * Extracts claims, verifies each against evidence, returns trust score
82
+ * with corrections for any contradicted claims.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import { shield } from "@veroq/sdk";
87
+ *
88
+ * // Basic
89
+ * const result = await shield("NVIDIA's Q4 revenue exceeded $22B");
90
+ * console.log(result.trustScore, result.corrections);
91
+ *
92
+ * // With options
93
+ * const result = await shield(llmOutput, {
94
+ * source: "gpt-4o",
95
+ * agentId: "my-bot",
96
+ * blockIfUntrusted: true,
97
+ * });
98
+ * ```
99
+ */
100
+ export async function shield(text, options = {}) {
101
+ if (!text || text.trim().length < 20) {
102
+ return new ShieldResult({
103
+ text: text || "",
104
+ claims: [],
105
+ claims_extracted: 0,
106
+ overall_confidence: 1.0,
107
+ overall_verdict: "no_claims",
108
+ summary: "Text too short to extract verifiable claims.",
109
+ });
110
+ }
111
+ const client = getClient(options.apiKey);
112
+ const raw = await client.verifyOutput(text, {
113
+ source: options.source,
114
+ maxClaims: options.maxClaims,
115
+ });
116
+ // Store to memory if agentId provided
117
+ if (options.agentId && raw.claims?.length) {
118
+ client.memoryStore(options.agentId, `shield:${text.slice(0, 50).replace(/\s+/g, "_")}`, {
119
+ trust_score: raw.overall_confidence,
120
+ verdict: raw.overall_verdict,
121
+ claims_extracted: raw.claims_extracted,
122
+ claims_contradicted: raw.claims_contradicted,
123
+ }, { category: "verification", queryText: text.slice(0, 200) }).catch(() => { });
124
+ }
125
+ const result = new ShieldResult(raw, text);
126
+ if (options.blockIfUntrusted && !result.isTrusted) {
127
+ throw new VeroqError(`Shield blocked: ${result.claimsContradicted} of ${result.claimsExtracted} claims contradicted. ` +
128
+ `Corrections: ${result.corrections.map(c => c.claim.slice(0, 80)).join("; ")}`);
129
+ }
130
+ return result;
131
+ }
132
+ //# sourceMappingURL=shield.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield.js","sourceRoot":"","sources":["../../src/shield.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAyBzC,MAAM,OAAO,YAAY;IA6BvB,YAAY,GAAwB,EAAE,QAAiB;QACrD,IAAI,CAAC,SAAS,GAAG,QAAQ,IAAI,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QAC5C,I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AE,cAAc,EAAE,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAClF,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAE3C,IAAI,OAAO,CAAC,gBAAgB,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QAClD,MAAM,IAAI,UAAU,CAClB,mBAAmB,MAAM,CAAC,kBAAkB,OAAO,MAAM,CAAC,eAAe,wBAAwB;YACjG,gBAAgB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC/E,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veroq/sdk",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "VeroQ TypeScript SDK — the verified intelligence layer for AI agents",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",