@babav/knowledge-core-client 0.10.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,21 +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;
82
84
  filename: string | null;
83
85
  visibility: Visibility | string;
84
86
  custom_metadata: Record<string, unknown>;
85
87
  source_url: string | null;
86
- supported: boolean;
87
88
  }
88
- export interface Groundedness {
89
+ export interface GroundednessSentence {
90
+ /** Char span IN THE ANSWER of this sentence. */
91
+ text_span: [number, number];
89
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[];
90
103
  model: string;
91
104
  threshold: number | null;
92
- passed: boolean | null;
93
105
  }
94
106
  export interface Corpus {
95
107
  id: UUID;
@@ -249,6 +261,12 @@ export interface StreamHandlers {
249
261
  retrieval_contents: RetrievalContent[];
250
262
  }) => void;
251
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;
252
270
  onFinal?: (d: QueryResponse) => void;
253
271
  onError?: (d: unknown) => void;
254
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.10.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,8 +88,10 @@ 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;
95
97
  // Source identity carried inline — no per-citation API round-trip to render it.
@@ -97,13 +99,21 @@ export interface Citation {
97
99
  visibility: Visibility | string;
98
100
  custom_metadata: Record<string, unknown>;
99
101
  source_url: string | null;
100
- supported: boolean;
101
102
  }
102
- export interface Groundedness {
103
+
104
+ export interface GroundednessSentence {
105
+ /** Char span IN THE ANSWER of this sentence. */
106
+ text_span: [number, number];
103
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[];
104
115
  model: string;
105
116
  threshold: number | null;
106
- passed: boolean | null;
107
117
  }
108
118
 
109
119
  export interface Corpus {
@@ -385,6 +395,12 @@ const MULTIPART_MAX_BYTES = 30 * 1024 * 1024;
385
395
  export interface StreamHandlers {
386
396
  onSources?: (d: { retrieval_contents: RetrievalContent[] }) => void;
387
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;
388
404
  onFinal?: (d: QueryResponse) => void;
389
405
  onError?: (d: unknown) => void;
390
406
  onDone?: () => void;
@@ -631,6 +647,8 @@ function dispatchSse(frame: string, h: StreamHandlers): void {
631
647
  switch (event) {
632
648
  case "retrieval_contents": h.onSources?.(data as never); break;
633
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;
634
652
  case "final": h.onFinal?.(data as QueryResponse); break;
635
653
  case "error": h.onError?.(data); break;
636
654
  case "done": h.onDone?.(); break;