@babav/knowledge-core-client 0.10.0 → 0.12.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
@@ -56,6 +56,7 @@ export interface QueryOverrides {
56
56
  max_hops?: number;
57
57
  groundedness_threshold?: number;
58
58
  grounding_enabled?: boolean;
59
+ citations_enabled?: boolean;
59
60
  }
60
61
  export interface QueryRequest {
61
62
  corpus_ids: UUID[];
@@ -75,21 +76,33 @@ export interface QueryResponse {
75
76
  standalone_query: string | null;
76
77
  }
77
78
  export interface Citation {
78
- quote: string;
79
+ /** Char span IN THE ANSWER this citation supports (for highlighting). */
79
80
  text_span: [number, number] | null;
81
+ /** The exact SOURCE passage the model used (native Anthropic citation). */
82
+ cited_text: string | null;
80
83
  context_index: number;
81
84
  document_id: string;
82
85
  filename: string | null;
83
86
  visibility: Visibility | string;
84
87
  custom_metadata: Record<string, unknown>;
85
88
  source_url: string | null;
86
- supported: boolean;
87
89
  }
88
- export interface Groundedness {
90
+ export interface GroundednessSentence {
91
+ /** Char span IN THE ANSWER of this sentence. */
92
+ text_span: [number, number];
89
93
  score: number;
94
+ passed: boolean | null;
95
+ }
96
+ export interface Groundedness {
97
+ /** Headline faithfulness of the whole answer vs. the full context. */
98
+ overall: {
99
+ score: number | null;
100
+ passed: boolean | null;
101
+ };
102
+ /** Per-sentence faithfulness — flag low-`score` sentences as weakly grounded. */
103
+ sentences: GroundednessSentence[];
90
104
  model: string;
91
105
  threshold: number | null;
92
- passed: boolean | null;
93
106
  }
94
107
  export interface Corpus {
95
108
  id: UUID;
@@ -180,6 +193,7 @@ export interface Agent {
180
193
  max_hops: number | null;
181
194
  groundedness_threshold: number | null;
182
195
  grounding_enabled: boolean | null;
196
+ citations_enabled: boolean | null;
183
197
  }
184
198
  export interface Tenant {
185
199
  id: UUID;
@@ -249,6 +263,12 @@ export interface StreamHandlers {
249
263
  retrieval_contents: RetrievalContent[];
250
264
  }) => void;
251
265
  onToken?: (text: string) => void;
266
+ /** A citation, emitted inline as the answer streams (Claude/native path). Also
267
+ * present aggregated in the `final` event. */
268
+ onCitation?: (c: Citation) => void;
269
+ /** Per-sentence + overall groundedness, emitted once after the answer streams
270
+ * (native path). Also present in `final`. May be `{}` if scoring was unavailable. */
271
+ onGroundedness?: (g: Groundedness | Record<string, never>) => void;
252
272
  onFinal?: (d: QueryResponse) => void;
253
273
  onError?: (d: unknown) => void;
254
274
  onDone?: () => void;
@@ -474,6 +494,7 @@ export declare class AdminClient extends HttpBase {
474
494
  max_hops?: number;
475
495
  groundedness_threshold?: number;
476
496
  grounding_enabled?: boolean;
497
+ citations_enabled?: boolean;
477
498
  }) => Promise<Agent>;
478
499
  update: (id: UUID, b: Partial<Omit<Agent, "id">>) => Promise<Agent>;
479
500
  delete: (id: UUID) => Promise<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.12.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
@@ -65,7 +65,8 @@ export interface QueryOverrides {
65
65
  rerank_instruction?: string;
66
66
  max_hops?: number;
67
67
  groundedness_threshold?: number;
68
- grounding_enabled?: boolean;
68
+ grounding_enabled?: boolean; // HHEM groundedness score (default off)
69
+ citations_enabled?: boolean; // source attribution (default on)
69
70
  }
70
71
 
71
72
  export interface QueryRequest {
@@ -88,8 +89,10 @@ export interface QueryResponse {
88
89
  }
89
90
 
90
91
  export interface Citation {
91
- quote: string;
92
+ /** Char span IN THE ANSWER this citation supports (for highlighting). */
92
93
  text_span: [number, number] | null;
94
+ /** The exact SOURCE passage the model used (native Anthropic citation). */
95
+ cited_text: string | null;
93
96
  context_index: number;
94
97
  document_id: string;
95
98
  // Source identity carried inline — no per-citation API round-trip to render it.
@@ -97,13 +100,21 @@ export interface Citation {
97
100
  visibility: Visibility | string;
98
101
  custom_metadata: Record<string, unknown>;
99
102
  source_url: string | null;
100
- supported: boolean;
101
103
  }
102
- export interface Groundedness {
104
+
105
+ export interface GroundednessSentence {
106
+ /** Char span IN THE ANSWER of this sentence. */
107
+ text_span: [number, number];
103
108
  score: number;
109
+ passed: boolean | null;
110
+ }
111
+ export interface Groundedness {
112
+ /** Headline faithfulness of the whole answer vs. the full context. */
113
+ overall: { score: number | null; passed: boolean | null };
114
+ /** Per-sentence faithfulness — flag low-`score` sentences as weakly grounded. */
115
+ sentences: GroundednessSentence[];
104
116
  model: string;
105
117
  threshold: number | null;
106
- passed: boolean | null;
107
118
  }
108
119
 
109
120
  export interface Corpus {
@@ -195,6 +206,7 @@ export interface Agent {
195
206
  max_hops: number | null;
196
207
  groundedness_threshold: number | null;
197
208
  grounding_enabled: boolean | null;
209
+ citations_enabled: boolean | null;
198
210
  }
199
211
  export interface Tenant {
200
212
  id: UUID;
@@ -385,6 +397,12 @@ const MULTIPART_MAX_BYTES = 30 * 1024 * 1024;
385
397
  export interface StreamHandlers {
386
398
  onSources?: (d: { retrieval_contents: RetrievalContent[] }) => void;
387
399
  onToken?: (text: string) => void;
400
+ /** A citation, emitted inline as the answer streams (Claude/native path). Also
401
+ * present aggregated in the `final` event. */
402
+ onCitation?: (c: Citation) => void;
403
+ /** Per-sentence + overall groundedness, emitted once after the answer streams
404
+ * (native path). Also present in `final`. May be `{}` if scoring was unavailable. */
405
+ onGroundedness?: (g: Groundedness | Record<string, never>) => void;
388
406
  onFinal?: (d: QueryResponse) => void;
389
407
  onError?: (d: unknown) => void;
390
408
  onDone?: () => void;
@@ -607,7 +625,7 @@ export class AdminClient extends HttpBase {
607
625
 
608
626
  // Agents are query agents, global for now.
609
627
  agents = {
610
- create: (b: { name: string; identity_prompt?: string; response_prompt?: string; generation_model?: string; top_k?: number; rerank_instruction?: string; max_hops?: number; groundedness_threshold?: number; grounding_enabled?: boolean }) =>
628
+ create: (b: { name: string; identity_prompt?: string; response_prompt?: string; generation_model?: string; top_k?: number; rerank_instruction?: string; max_hops?: number; groundedness_threshold?: number; grounding_enabled?: boolean; citations_enabled?: boolean }) =>
611
629
  this.request<Agent>("POST", "/v1/agents", { json: b }),
612
630
  update: (id: UUID, b: Partial<Omit<Agent, "id">>) =>
613
631
  this.request<Agent>("PATCH", `/v1/agents/${id}`, { json: b }),
@@ -631,6 +649,8 @@ function dispatchSse(frame: string, h: StreamHandlers): void {
631
649
  switch (event) {
632
650
  case "retrieval_contents": h.onSources?.(data as never); break;
633
651
  case "token": h.onToken?.((data as { text: string }).text); break;
652
+ case "citation": h.onCitation?.(data as Citation); break;
653
+ case "groundedness": h.onGroundedness?.(data as never); break;
634
654
  case "final": h.onFinal?.(data as QueryResponse); break;
635
655
  case "error": h.onError?.(data); break;
636
656
  case "done": h.onDone?.(); break;