@babav/knowledge-core-client 0.9.0 → 0.11.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/dist/index.d.ts CHANGED
@@ -75,18 +75,33 @@ export interface QueryResponse {
75
75
  standalone_query: string | null;
76
76
  }
77
77
  export interface Citation {
78
- quote: string;
78
+ /** Char span IN THE ANSWER this citation supports (for highlighting). */
79
79
  text_span: [number, number] | null;
80
+ /** The exact SOURCE passage the model used (native Anthropic citation). */
81
+ cited_text: string | null;
80
82
  context_index: number;
81
83
  document_id: string;
84
+ filename: string | null;
85
+ visibility: Visibility | string;
86
+ custom_metadata: Record<string, unknown>;
82
87
  source_url: string | null;
83
- supported: boolean;
84
88
  }
85
- export interface Groundedness {
89
+ export interface GroundednessSentence {
90
+ /** Char span IN THE ANSWER of this sentence. */
91
+ text_span: [number, number];
86
92
  score: number;
93
+ passed: boolean | null;
94
+ }
95
+ export interface Groundedness {
96
+ /** Headline faithfulness of the whole answer vs. the full context. */
97
+ overall: {
98
+ score: number | null;
99
+ passed: boolean | null;
100
+ };
101
+ /** Per-sentence faithfulness — flag low-`score` sentences as weakly grounded. */
102
+ sentences: GroundednessSentence[];
87
103
  model: string;
88
104
  threshold: number | null;
89
- passed: boolean | null;
90
105
  }
91
106
  export interface Corpus {
92
107
  id: UUID;
@@ -246,6 +261,12 @@ export interface StreamHandlers {
246
261
  retrieval_contents: RetrievalContent[];
247
262
  }) => void;
248
263
  onToken?: (text: string) => void;
264
+ /** A citation, emitted inline as the answer streams (Claude/native path). Also
265
+ * present aggregated in the `final` event. */
266
+ onCitation?: (c: Citation) => void;
267
+ /** Per-sentence + overall groundedness, emitted once after the answer streams
268
+ * (native path). Also present in `final`. May be `{}` if scoring was unavailable. */
269
+ onGroundedness?: (g: Groundedness | Record<string, never>) => void;
249
270
  onFinal?: (d: QueryResponse) => void;
250
271
  onError?: (d: unknown) => void;
251
272
  onDone?: () => void;
package/dist/index.js CHANGED
@@ -374,6 +374,12 @@ function dispatchSse(frame, h) {
374
374
  case "token":
375
375
  h.onToken?.(data.text);
376
376
  break;
377
+ case "citation":
378
+ h.onCitation?.(data);
379
+ break;
380
+ case "groundedness":
381
+ h.onGroundedness?.(data);
382
+ break;
377
383
  case "final":
378
384
  h.onFinal?.(data);
379
385
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "TypeScript client for the Babav Knowledge Core API (Deno + Node 18+, zero deps).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -88,18 +88,32 @@ export interface QueryResponse {
88
88
  }
89
89
 
90
90
  export interface Citation {
91
- quote: string;
91
+ /** Char span IN THE ANSWER this citation supports (for highlighting). */
92
92
  text_span: [number, number] | null;
93
+ /** The exact SOURCE passage the model used (native Anthropic citation). */
94
+ cited_text: string | null;
93
95
  context_index: number;
94
96
  document_id: string;
97
+ // Source identity carried inline — no per-citation API round-trip to render it.
98
+ filename: string | null;
99
+ visibility: Visibility | string;
100
+ custom_metadata: Record<string, unknown>;
95
101
  source_url: string | null;
96
- supported: boolean;
97
102
  }
98
- export interface Groundedness {
103
+
104
+ export interface GroundednessSentence {
105
+ /** Char span IN THE ANSWER of this sentence. */
106
+ text_span: [number, number];
99
107
  score: number;
108
+ passed: boolean | null;
109
+ }
110
+ export interface Groundedness {
111
+ /** Headline faithfulness of the whole answer vs. the full context. */
112
+ overall: { score: number | null; passed: boolean | null };
113
+ /** Per-sentence faithfulness — flag low-`score` sentences as weakly grounded. */
114
+ sentences: GroundednessSentence[];
100
115
  model: string;
101
116
  threshold: number | null;
102
- passed: boolean | null;
103
117
  }
104
118
 
105
119
  export interface Corpus {
@@ -381,6 +395,12 @@ const MULTIPART_MAX_BYTES = 30 * 1024 * 1024;
381
395
  export interface StreamHandlers {
382
396
  onSources?: (d: { retrieval_contents: RetrievalContent[] }) => void;
383
397
  onToken?: (text: string) => void;
398
+ /** A citation, emitted inline as the answer streams (Claude/native path). Also
399
+ * present aggregated in the `final` event. */
400
+ onCitation?: (c: Citation) => void;
401
+ /** Per-sentence + overall groundedness, emitted once after the answer streams
402
+ * (native path). Also present in `final`. May be `{}` if scoring was unavailable. */
403
+ onGroundedness?: (g: Groundedness | Record<string, never>) => void;
384
404
  onFinal?: (d: QueryResponse) => void;
385
405
  onError?: (d: unknown) => void;
386
406
  onDone?: () => void;
@@ -627,6 +647,8 @@ function dispatchSse(frame: string, h: StreamHandlers): void {
627
647
  switch (event) {
628
648
  case "retrieval_contents": h.onSources?.(data as never); break;
629
649
  case "token": h.onToken?.((data as { text: string }).text); break;
650
+ case "citation": h.onCitation?.(data as Citation); break;
651
+ case "groundedness": h.onGroundedness?.(data as never); break;
630
652
  case "final": h.onFinal?.(data as QueryResponse); break;
631
653
  case "error": h.onError?.(data); break;
632
654
  case "done": h.onDone?.(); break;