wauldo 0.2.0 → 0.4.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/README.md CHANGED
@@ -11,7 +11,9 @@ Official TypeScript SDK for the [Wauldo API](https://wauldo.com) — the AI infe
11
11
 
12
12
  ## Why Wauldo?
13
13
 
14
- - **Fact-Check API** verify any claim against source context, get verdict (verified/weak/rejected), action (allow/review/block), and structured reason
14
+ - **Native PDF & DOCX Upload** upload files directly, server-side text extraction with document quality scoring
15
+ - **Citation Verify API** — detect uncited sentences, phantom citations, and measure coverage ratio. No LLM needed
16
+ - **Fact-Check API** — verify any claim against source with 3 modes (lexical, hybrid, semantic). Get verdict, action, and structured reason
15
17
  - **Zero hallucinations** — every answer is verified against source documents
16
18
  - **Smart model routing** — auto-selects the cheapest model that meets quality (save 40-80% on AI costs)
17
19
  - **One API, 7+ providers** — OpenAI, Anthropic, Google, Qwen, Meta, Mistral, DeepSeek with automatic fallback
package/dist/index.d.mts CHANGED
@@ -277,6 +277,22 @@ interface RagUploadResponse {
277
277
  document_id: string;
278
278
  chunks_count: number;
279
279
  }
280
+ interface DocumentQuality {
281
+ score: number;
282
+ label: string;
283
+ word_count: number;
284
+ line_density: number;
285
+ avg_line_length: number;
286
+ paragraph_count: number;
287
+ }
288
+ interface UploadFileResponse {
289
+ document_id: string;
290
+ chunks_count: number;
291
+ indexed_at: string;
292
+ content_type: string;
293
+ trace_id: string;
294
+ quality?: DocumentQuality;
295
+ }
280
296
  interface RagSource {
281
297
  document_id: string;
282
298
  content: string;
@@ -340,6 +356,30 @@ interface FactCheckResponse {
340
356
  mode_warning?: string | null;
341
357
  processing_time_ms: number;
342
358
  }
359
+ interface SourceChunk {
360
+ name: string;
361
+ content: string;
362
+ }
363
+ interface CitationDetail {
364
+ citation: string;
365
+ source_name: string;
366
+ is_valid: boolean;
367
+ }
368
+ interface VerifyCitationRequest {
369
+ text: string;
370
+ sources?: SourceChunk[];
371
+ threshold?: number;
372
+ }
373
+ interface VerifyCitationResponse {
374
+ citation_ratio: number;
375
+ has_sufficient_citations: boolean;
376
+ sentence_count: number;
377
+ citation_count: number;
378
+ uncited_sentences: string[];
379
+ citations?: CitationDetail[];
380
+ phantom_count?: number;
381
+ processing_time_ms: number;
382
+ }
343
383
  /** Minimal interface required by Conversation — implemented by both HttpClient and MockHttpClient */
344
384
  interface ChatClientLike {
345
385
  chat(request: ChatRequest, options?: RequestOptions): Promise<ChatResponse>;
@@ -463,6 +503,19 @@ declare class HttpClient {
463
503
  * @returns Upload confirmation with document_id and chunks_count
464
504
  */
465
505
  ragUpload(content: string, filename?: string, options?: RequestOptions): Promise<RagUploadResponse>;
506
+ /**
507
+ * POST /v1/upload-file — Upload a file (PDF, DOCX, text, image) for RAG indexing.
508
+ *
509
+ * @param file - File content as Buffer/Uint8Array
510
+ * @param filename - The filename (determines content type detection)
511
+ * @param options - Optional title, tags, timeoutMs
512
+ * @returns Upload confirmation with quality scoring
513
+ */
514
+ uploadFile(file: Uint8Array | Buffer, filename: string, options?: {
515
+ title?: string;
516
+ tags?: string;
517
+ timeoutMs?: number;
518
+ }): Promise<UploadFileResponse>;
466
519
  /** POST /v1/query — Query RAG knowledge base */
467
520
  ragQuery(query: string, topK?: number, options?: {
468
521
  debug?: boolean;
@@ -514,6 +567,19 @@ declare class HttpClient {
514
567
  * ```
515
568
  */
516
569
  factCheck(request: FactCheckRequest): Promise<FactCheckResponse>;
570
+ /**
571
+ * POST /v1/verify — Verify citations in AI-generated text.
572
+ *
573
+ * @example
574
+ * ```ts
575
+ * const result = await client.verifyCitation({
576
+ * text: 'Rust was released in 2010 [Source: rust_book].',
577
+ * sources: [{ name: 'rust_book', content: 'Rust was first released in 2010.' }],
578
+ * });
579
+ * console.log(result.phantom_count); // 0
580
+ * ```
581
+ */
582
+ verifyCitation(request: VerifyCitationRequest): Promise<VerifyCitationResponse>;
517
583
  }
518
584
 
519
585
  /**
@@ -634,4 +700,4 @@ declare class ToolNotFoundError extends WauldoError {
634
700
  constructor(toolName: string);
635
701
  }
636
702
 
637
- export { AgentClient, type CallToolResponse, type ChatChoice, type ChatClientLike, type ChatMessage, type ChatRequest, type ChatResponse, type ChatUsage, type Chunk, type ChunkResult, type ClaimResult, type ClientOptions, type Concept, type ConceptResult, ConnectionError, Conversation, type DetailLevel, type EmbeddingData, type EmbeddingResponse, type EmbeddingUsage, type FactCheckRequest, type FactCheckResponse, type GraphNode, HttpClient, type HttpClientConfig, type KnowledgeGraphResult, type LogLevel, MockHttpClient, type ModelInfo, type ModelList, type OrchestratorResponse, type PlanOptions, type PlanResult, type PlanStep, type RagAuditInfo, type RagQueryResponse, type RagSource, type RagUploadResponse, type ReasoningOptions, type ReasoningResult, type RequestOptions, type RetrievalResult, ServerError, type SourceType, TimeoutError, type ToolContent, type ToolDefinition, ToolNotFoundError, ValidationError, WauldoError, chatContent };
703
+ export { AgentClient, type CallToolResponse, type ChatChoice, type ChatClientLike, type ChatMessage, type ChatRequest, type ChatResponse, type ChatUsage, type Chunk, type ChunkResult, type CitationDetail, type ClaimResult, type ClientOptions, type Concept, type ConceptResult, ConnectionError, Conversation, type DetailLevel, type DocumentQuality, type EmbeddingData, type EmbeddingResponse, type EmbeddingUsage, type FactCheckRequest, type FactCheckResponse, type GraphNode, HttpClient, type HttpClientConfig, type KnowledgeGraphResult, type LogLevel, MockHttpClient, type ModelInfo, type ModelList, type OrchestratorResponse, type PlanOptions, type PlanResult, type PlanStep, type RagAuditInfo, type RagQueryResponse, type RagSource, type RagUploadResponse, type ReasoningOptions, type ReasoningResult, type RequestOptions, type RetrievalResult, ServerError, type SourceChunk, type SourceType, TimeoutError, type ToolContent, type ToolDefinition, ToolNotFoundError, type UploadFileResponse, ValidationError, type VerifyCitationRequest, type VerifyCitationResponse, WauldoError, chatContent };
package/dist/index.d.ts CHANGED
@@ -277,6 +277,22 @@ interface RagUploadResponse {
277
277
  document_id: string;
278
278
  chunks_count: number;
279
279
  }
280
+ interface DocumentQuality {
281
+ score: number;
282
+ label: string;
283
+ word_count: number;
284
+ line_density: number;
285
+ avg_line_length: number;
286
+ paragraph_count: number;
287
+ }
288
+ interface UploadFileResponse {
289
+ document_id: string;
290
+ chunks_count: number;
291
+ indexed_at: string;
292
+ content_type: string;
293
+ trace_id: string;
294
+ quality?: DocumentQuality;
295
+ }
280
296
  interface RagSource {
281
297
  document_id: string;
282
298
  content: string;
@@ -340,6 +356,30 @@ interface FactCheckResponse {
340
356
  mode_warning?: string | null;
341
357
  processing_time_ms: number;
342
358
  }
359
+ interface SourceChunk {
360
+ name: string;
361
+ content: string;
362
+ }
363
+ interface CitationDetail {
364
+ citation: string;
365
+ source_name: string;
366
+ is_valid: boolean;
367
+ }
368
+ interface VerifyCitationRequest {
369
+ text: string;
370
+ sources?: SourceChunk[];
371
+ threshold?: number;
372
+ }
373
+ interface VerifyCitationResponse {
374
+ citation_ratio: number;
375
+ has_sufficient_citations: boolean;
376
+ sentence_count: number;
377
+ citation_count: number;
378
+ uncited_sentences: string[];
379
+ citations?: CitationDetail[];
380
+ phantom_count?: number;
381
+ processing_time_ms: number;
382
+ }
343
383
  /** Minimal interface required by Conversation — implemented by both HttpClient and MockHttpClient */
344
384
  interface ChatClientLike {
345
385
  chat(request: ChatRequest, options?: RequestOptions): Promise<ChatResponse>;
@@ -463,6 +503,19 @@ declare class HttpClient {
463
503
  * @returns Upload confirmation with document_id and chunks_count
464
504
  */
465
505
  ragUpload(content: string, filename?: string, options?: RequestOptions): Promise<RagUploadResponse>;
506
+ /**
507
+ * POST /v1/upload-file — Upload a file (PDF, DOCX, text, image) for RAG indexing.
508
+ *
509
+ * @param file - File content as Buffer/Uint8Array
510
+ * @param filename - The filename (determines content type detection)
511
+ * @param options - Optional title, tags, timeoutMs
512
+ * @returns Upload confirmation with quality scoring
513
+ */
514
+ uploadFile(file: Uint8Array | Buffer, filename: string, options?: {
515
+ title?: string;
516
+ tags?: string;
517
+ timeoutMs?: number;
518
+ }): Promise<UploadFileResponse>;
466
519
  /** POST /v1/query — Query RAG knowledge base */
467
520
  ragQuery(query: string, topK?: number, options?: {
468
521
  debug?: boolean;
@@ -514,6 +567,19 @@ declare class HttpClient {
514
567
  * ```
515
568
  */
516
569
  factCheck(request: FactCheckRequest): Promise<FactCheckResponse>;
570
+ /**
571
+ * POST /v1/verify — Verify citations in AI-generated text.
572
+ *
573
+ * @example
574
+ * ```ts
575
+ * const result = await client.verifyCitation({
576
+ * text: 'Rust was released in 2010 [Source: rust_book].',
577
+ * sources: [{ name: 'rust_book', content: 'Rust was first released in 2010.' }],
578
+ * });
579
+ * console.log(result.phantom_count); // 0
580
+ * ```
581
+ */
582
+ verifyCitation(request: VerifyCitationRequest): Promise<VerifyCitationResponse>;
517
583
  }
518
584
 
519
585
  /**
@@ -634,4 +700,4 @@ declare class ToolNotFoundError extends WauldoError {
634
700
  constructor(toolName: string);
635
701
  }
636
702
 
637
- export { AgentClient, type CallToolResponse, type ChatChoice, type ChatClientLike, type ChatMessage, type ChatRequest, type ChatResponse, type ChatUsage, type Chunk, type ChunkResult, type ClaimResult, type ClientOptions, type Concept, type ConceptResult, ConnectionError, Conversation, type DetailLevel, type EmbeddingData, type EmbeddingResponse, type EmbeddingUsage, type FactCheckRequest, type FactCheckResponse, type GraphNode, HttpClient, type HttpClientConfig, type KnowledgeGraphResult, type LogLevel, MockHttpClient, type ModelInfo, type ModelList, type OrchestratorResponse, type PlanOptions, type PlanResult, type PlanStep, type RagAuditInfo, type RagQueryResponse, type RagSource, type RagUploadResponse, type ReasoningOptions, type ReasoningResult, type RequestOptions, type RetrievalResult, ServerError, type SourceType, TimeoutError, type ToolContent, type ToolDefinition, ToolNotFoundError, ValidationError, WauldoError, chatContent };
703
+ export { AgentClient, type CallToolResponse, type ChatChoice, type ChatClientLike, type ChatMessage, type ChatRequest, type ChatResponse, type ChatUsage, type Chunk, type ChunkResult, type CitationDetail, type ClaimResult, type ClientOptions, type Concept, type ConceptResult, ConnectionError, Conversation, type DetailLevel, type DocumentQuality, type EmbeddingData, type EmbeddingResponse, type EmbeddingUsage, type FactCheckRequest, type FactCheckResponse, type GraphNode, HttpClient, type HttpClientConfig, type KnowledgeGraphResult, type LogLevel, MockHttpClient, type ModelInfo, type ModelList, type OrchestratorResponse, type PlanOptions, type PlanResult, type PlanStep, type RagAuditInfo, type RagQueryResponse, type RagSource, type RagUploadResponse, type ReasoningOptions, type ReasoningResult, type RequestOptions, type RetrievalResult, ServerError, type SourceChunk, type SourceType, TimeoutError, type ToolContent, type ToolDefinition, ToolNotFoundError, type UploadFileResponse, ValidationError, type VerifyCitationRequest, type VerifyCitationResponse, WauldoError, chatContent };
package/dist/index.js CHANGED
@@ -900,6 +900,16 @@ async function* parseSSEStream(body) {
900
900
  }
901
901
 
902
902
  // src/http_client.ts
903
+ function concatUint8Arrays(arrays) {
904
+ const total = arrays.reduce((n, a) => n + a.length, 0);
905
+ const result = new Uint8Array(total);
906
+ let offset = 0;
907
+ for (const a of arrays) {
908
+ result.set(a, offset);
909
+ offset += a.length;
910
+ }
911
+ return result;
912
+ }
903
913
  function validateResponse(data, typeName) {
904
914
  if (data === null || data === void 0) {
905
915
  throw new ServerError(`Invalid ${typeName}: response is null`, 0);
@@ -1034,6 +1044,51 @@ var HttpClient = class {
1034
1044
  );
1035
1045
  return validateResponse(data, "RagUploadResponse");
1036
1046
  }
1047
+ /**
1048
+ * POST /v1/upload-file — Upload a file (PDF, DOCX, text, image) for RAG indexing.
1049
+ *
1050
+ * @param file - File content as Buffer/Uint8Array
1051
+ * @param filename - The filename (determines content type detection)
1052
+ * @param options - Optional title, tags, timeoutMs
1053
+ * @returns Upload confirmation with quality scoring
1054
+ */
1055
+ async uploadFile(file, filename, options) {
1056
+ const boundary = "----WauldoSDKBoundary";
1057
+ const parts = [];
1058
+ const enc = new TextEncoder();
1059
+ parts.push(enc.encode(`--${boundary}\r
1060
+ Content-Disposition: form-data; name="file"; filename="${filename}"\r
1061
+ Content-Type: application/octet-stream\r
1062
+ \r
1063
+ `));
1064
+ parts.push(file instanceof Uint8Array ? file : new Uint8Array(file));
1065
+ parts.push(enc.encode("\r\n"));
1066
+ if (options?.title) {
1067
+ parts.push(enc.encode(`--${boundary}\r
1068
+ Content-Disposition: form-data; name="title"\r
1069
+ \r
1070
+ ${options.title}\r
1071
+ `));
1072
+ }
1073
+ if (options?.tags) {
1074
+ parts.push(enc.encode(`--${boundary}\r
1075
+ Content-Disposition: form-data; name="tags"\r
1076
+ \r
1077
+ ${options.tags}\r
1078
+ `));
1079
+ }
1080
+ parts.push(enc.encode(`--${boundary}--\r
1081
+ `));
1082
+ const body = concatUint8Arrays(parts);
1083
+ const data = await fetchWithRetry(
1084
+ { ...this.retryConfig, headers: { ...this.retryConfig.headers, "Content-Type": `multipart/form-data; boundary=${boundary}` } },
1085
+ "POST",
1086
+ "/v1/upload-file",
1087
+ body,
1088
+ options?.timeoutMs
1089
+ );
1090
+ return validateResponse(data, "UploadFileResponse");
1091
+ }
1037
1092
  /** POST /v1/query — Query RAG knowledge base */
1038
1093
  async ragQuery(query, topK = 5, options) {
1039
1094
  const body = { query, top_k: topK };
@@ -1123,6 +1178,27 @@ var HttpClient = class {
1123
1178
  );
1124
1179
  return validateResponse(data, "FactCheckResponse");
1125
1180
  }
1181
+ /**
1182
+ * POST /v1/verify — Verify citations in AI-generated text.
1183
+ *
1184
+ * @example
1185
+ * ```ts
1186
+ * const result = await client.verifyCitation({
1187
+ * text: 'Rust was released in 2010 [Source: rust_book].',
1188
+ * sources: [{ name: 'rust_book', content: 'Rust was first released in 2010.' }],
1189
+ * });
1190
+ * console.log(result.phantom_count); // 0
1191
+ * ```
1192
+ */
1193
+ async verifyCitation(request) {
1194
+ const data = await fetchWithRetry(
1195
+ this.retryConfig,
1196
+ "POST",
1197
+ "/v1/verify",
1198
+ request
1199
+ );
1200
+ return validateResponse(data, "VerifyCitationResponse");
1201
+ }
1126
1202
  };
1127
1203
 
1128
1204
  // src/mock_client.ts
package/dist/index.mjs CHANGED
@@ -864,6 +864,16 @@ async function* parseSSEStream(body) {
864
864
  }
865
865
 
866
866
  // src/http_client.ts
867
+ function concatUint8Arrays(arrays) {
868
+ const total = arrays.reduce((n, a) => n + a.length, 0);
869
+ const result = new Uint8Array(total);
870
+ let offset = 0;
871
+ for (const a of arrays) {
872
+ result.set(a, offset);
873
+ offset += a.length;
874
+ }
875
+ return result;
876
+ }
867
877
  function validateResponse(data, typeName) {
868
878
  if (data === null || data === void 0) {
869
879
  throw new ServerError(`Invalid ${typeName}: response is null`, 0);
@@ -998,6 +1008,51 @@ var HttpClient = class {
998
1008
  );
999
1009
  return validateResponse(data, "RagUploadResponse");
1000
1010
  }
1011
+ /**
1012
+ * POST /v1/upload-file — Upload a file (PDF, DOCX, text, image) for RAG indexing.
1013
+ *
1014
+ * @param file - File content as Buffer/Uint8Array
1015
+ * @param filename - The filename (determines content type detection)
1016
+ * @param options - Optional title, tags, timeoutMs
1017
+ * @returns Upload confirmation with quality scoring
1018
+ */
1019
+ async uploadFile(file, filename, options) {
1020
+ const boundary = "----WauldoSDKBoundary";
1021
+ const parts = [];
1022
+ const enc = new TextEncoder();
1023
+ parts.push(enc.encode(`--${boundary}\r
1024
+ Content-Disposition: form-data; name="file"; filename="${filename}"\r
1025
+ Content-Type: application/octet-stream\r
1026
+ \r
1027
+ `));
1028
+ parts.push(file instanceof Uint8Array ? file : new Uint8Array(file));
1029
+ parts.push(enc.encode("\r\n"));
1030
+ if (options?.title) {
1031
+ parts.push(enc.encode(`--${boundary}\r
1032
+ Content-Disposition: form-data; name="title"\r
1033
+ \r
1034
+ ${options.title}\r
1035
+ `));
1036
+ }
1037
+ if (options?.tags) {
1038
+ parts.push(enc.encode(`--${boundary}\r
1039
+ Content-Disposition: form-data; name="tags"\r
1040
+ \r
1041
+ ${options.tags}\r
1042
+ `));
1043
+ }
1044
+ parts.push(enc.encode(`--${boundary}--\r
1045
+ `));
1046
+ const body = concatUint8Arrays(parts);
1047
+ const data = await fetchWithRetry(
1048
+ { ...this.retryConfig, headers: { ...this.retryConfig.headers, "Content-Type": `multipart/form-data; boundary=${boundary}` } },
1049
+ "POST",
1050
+ "/v1/upload-file",
1051
+ body,
1052
+ options?.timeoutMs
1053
+ );
1054
+ return validateResponse(data, "UploadFileResponse");
1055
+ }
1001
1056
  /** POST /v1/query — Query RAG knowledge base */
1002
1057
  async ragQuery(query, topK = 5, options) {
1003
1058
  const body = { query, top_k: topK };
@@ -1087,6 +1142,27 @@ var HttpClient = class {
1087
1142
  );
1088
1143
  return validateResponse(data, "FactCheckResponse");
1089
1144
  }
1145
+ /**
1146
+ * POST /v1/verify — Verify citations in AI-generated text.
1147
+ *
1148
+ * @example
1149
+ * ```ts
1150
+ * const result = await client.verifyCitation({
1151
+ * text: 'Rust was released in 2010 [Source: rust_book].',
1152
+ * sources: [{ name: 'rust_book', content: 'Rust was first released in 2010.' }],
1153
+ * });
1154
+ * console.log(result.phantom_count); // 0
1155
+ * ```
1156
+ */
1157
+ async verifyCitation(request) {
1158
+ const data = await fetchWithRetry(
1159
+ this.retryConfig,
1160
+ "POST",
1161
+ "/v1/verify",
1162
+ request
1163
+ );
1164
+ return validateResponse(data, "VerifyCitationResponse");
1165
+ }
1090
1166
  };
1091
1167
 
1092
1168
  // src/mock_client.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wauldo",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Official TypeScript SDK for Wauldo — Verified AI answers from your documents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",