@babav/knowledge-core-client 0.24.0 → 0.25.1

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
@@ -242,6 +242,76 @@ export interface FinalizeResult {
242
242
  status: "ingesting" | "failed";
243
243
  error?: string;
244
244
  }
245
+ export type AnalyticsBand = "frequent" | "occasional" | "rare" | "never" | "insufficient_data";
246
+ export interface UsageSeries {
247
+ corpus_id: UUID;
248
+ granularity: string;
249
+ points: Array<{
250
+ bucket: string;
251
+ queries: number;
252
+ }>;
253
+ }
254
+ export interface DocumentAnalytics {
255
+ document_id: UUID;
256
+ filename: string | null;
257
+ chunks_retrieved: number;
258
+ chunks_reranked: number;
259
+ citation_count: number;
260
+ best_rerank_rank: number | null;
261
+ best_rerank_score: number | null;
262
+ exposure_queries: number;
263
+ retrieved_reach: number;
264
+ citation_reach: number;
265
+ conversion: number;
266
+ band: AnalyticsBand;
267
+ }
268
+ export interface SectionAnalytics {
269
+ parent_id: UUID;
270
+ ordinal: number;
271
+ chunks_retrieved: number;
272
+ chunks_reranked: number;
273
+ citation_count: number;
274
+ best_rerank_score: number | null;
275
+ band: AnalyticsBand;
276
+ }
277
+ export interface SectionsResponse {
278
+ document_id: UUID;
279
+ sections: SectionAnalytics[];
280
+ }
281
+ export interface MonthlyCorpus {
282
+ corpus_id: UUID;
283
+ yyyy_mm: string;
284
+ queries: number;
285
+ documents_retrieved: number;
286
+ chunks_retrieved: number;
287
+ citations: number;
288
+ revenue_share: number;
289
+ }
290
+ export interface CorpusMonthSlice {
291
+ corpus_id: UUID;
292
+ queries: number;
293
+ documents_retrieved: number;
294
+ chunks_retrieved: number;
295
+ citations: number;
296
+ revenue_share: number;
297
+ }
298
+ export interface MonthTotals {
299
+ yyyy_mm: string;
300
+ queries: number;
301
+ documents_retrieved: number;
302
+ chunks_retrieved: number;
303
+ citations: number;
304
+ unattributed_share: number;
305
+ corpora: CorpusMonthSlice[];
306
+ }
307
+ export interface RetrievalEventRow {
308
+ id: UUID;
309
+ created_at: string;
310
+ corpus_ids: UUID[];
311
+ pool_size: number;
312
+ message_id: UUID | null;
313
+ documents: Array<Record<string, unknown>>;
314
+ }
245
315
  export interface Conversation {
246
316
  id: UUID;
247
317
  title: string | null;
@@ -685,6 +755,43 @@ export declare class KnowledgeCoreClient extends HttpBase {
685
755
  listAll: () => Promise<Agent[]>;
686
756
  get: (id: UUID) => Promise<Agent>;
687
757
  };
758
+ analytics: {
759
+ /** Query-volume time series for a corpus (the denominator for everything). */
760
+ corpusUsage: (corpusId: UUID, q?: {
761
+ from?: string;
762
+ to?: string;
763
+ granularity?: "day" | "week" | "month";
764
+ }) => Promise<UsageSeries>;
765
+ /** Per-document analytics for a corpus (feeds the document list + the quadrant scatter). */
766
+ corpusDocuments: (corpusId: UUID, q?: {
767
+ sort?: "citations" | "reranked" | "retrieved" | "best_score";
768
+ limit?: number;
769
+ cursor?: string;
770
+ from?: string;
771
+ to?: string;
772
+ }) => Promise<{
773
+ items: DocumentAnalytics[];
774
+ next_cursor: string | null;
775
+ }>;
776
+ /** One document's lifetime rollup (headline reach is CITATION reach). */
777
+ document: (documentId: UUID) => Promise<DocumentAnalytics>;
778
+ /** Parent-section grain for a document (never exposes chunk ids). */
779
+ documentSections: (documentId: UUID) => Promise<SectionsResponse>;
780
+ /** A corpus's monthly metrics + revenue_share (YYYY-MM). */
781
+ corpusMonthly: (corpusId: UUID, yyyyMm: string) => Promise<MonthlyCorpus>;
782
+ /** Cross-corpus monthly totals + per-corpus breakdown + unattributed share (YYYY-MM). */
783
+ month: (yyyyMm: string) => Promise<MonthTotals>;
784
+ /** Raw immutable events + document rollups (escape hatch for custom formulas). */
785
+ events: (q?: {
786
+ from?: string;
787
+ to?: string;
788
+ limit?: number;
789
+ cursor?: string;
790
+ }) => Promise<{
791
+ items: RetrievalEventRow[];
792
+ next_cursor: string | null;
793
+ }>;
794
+ };
688
795
  }
689
796
  export declare class AdminClient extends HttpBase {
690
797
  /** @param opts.apiKey the ADMIN key, supplied by the caller. */
package/dist/index.js CHANGED
@@ -410,6 +410,23 @@ export class KnowledgeCoreClient extends HttpBase {
410
410
  listAll: () => this.pageAll("/v1/agents"),
411
411
  get: (id) => this.request("GET", `/v1/agents/${id}`),
412
412
  };
413
+ // --- retrieval analytics (read-only, tenant-scoped, aggregate-on-read) ---
414
+ analytics = {
415
+ /** Query-volume time series for a corpus (the denominator for everything). */
416
+ corpusUsage: (corpusId, q) => this.request("GET", `/v1/analytics/corpora/${corpusId}/usage`, { query: q }),
417
+ /** Per-document analytics for a corpus (feeds the document list + the quadrant scatter). */
418
+ corpusDocuments: (corpusId, q) => this.request("GET", `/v1/analytics/corpora/${corpusId}/documents`, { query: q }),
419
+ /** One document's lifetime rollup (headline reach is CITATION reach). */
420
+ document: (documentId) => this.request("GET", `/v1/analytics/documents/${documentId}`),
421
+ /** Parent-section grain for a document (never exposes chunk ids). */
422
+ documentSections: (documentId) => this.request("GET", `/v1/analytics/documents/${documentId}/sections`),
423
+ /** A corpus's monthly metrics + revenue_share (YYYY-MM). */
424
+ corpusMonthly: (corpusId, yyyyMm) => this.request("GET", `/v1/analytics/corpora/${corpusId}/monthly/${yyyyMm}`),
425
+ /** Cross-corpus monthly totals + per-corpus breakdown + unattributed share (YYYY-MM). */
426
+ month: (yyyyMm) => this.request("GET", `/v1/analytics/months/${yyyyMm}`),
427
+ /** Raw immutable events + document rollups (escape hatch for custom formulas). */
428
+ events: (q) => this.request("GET", "/v1/analytics/events", { query: q }),
429
+ };
413
430
  }
414
431
  // ---------------------------------------------------------------------------
415
432
  // Admin client (tenant + key + agent management) — use the ADMIN key
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.24.0",
3
+ "version": "0.25.1",
4
4
  "description": "TypeScript client for the Babav Knowledge Core API (Deno + Node 18+, zero deps). Includes the babav.visual grammar TYPES at the ./visual subpath (types only; all visual rendering is server-side).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -258,6 +258,41 @@ export interface FinalizeResult {
258
258
  status: "ingesting" | "failed";
259
259
  error?: string;
260
260
  }
261
+ // --- retrieval analytics ---
262
+ export type AnalyticsBand = "frequent" | "occasional" | "rare" | "never" | "insufficient_data";
263
+ export interface UsageSeries {
264
+ corpus_id: UUID;
265
+ granularity: string;
266
+ points: Array<{ bucket: string; queries: number }>;
267
+ }
268
+ export interface DocumentAnalytics {
269
+ document_id: UUID; filename: string | null;
270
+ chunks_retrieved: number; chunks_reranked: number; citation_count: number;
271
+ best_rerank_rank: number | null; best_rerank_score: number | null;
272
+ exposure_queries: number; retrieved_reach: number; citation_reach: number;
273
+ conversion: number; band: AnalyticsBand;
274
+ }
275
+ export interface SectionAnalytics {
276
+ parent_id: UUID; ordinal: number; chunks_retrieved: number; chunks_reranked: number;
277
+ citation_count: number; best_rerank_score: number | null; band: AnalyticsBand;
278
+ }
279
+ export interface SectionsResponse { document_id: UUID; sections: SectionAnalytics[] }
280
+ export interface MonthlyCorpus {
281
+ corpus_id: UUID; yyyy_mm: string; queries: number; documents_retrieved: number;
282
+ chunks_retrieved: number; citations: number; revenue_share: number;
283
+ }
284
+ export interface CorpusMonthSlice {
285
+ corpus_id: UUID; queries: number; documents_retrieved: number;
286
+ chunks_retrieved: number; citations: number; revenue_share: number;
287
+ }
288
+ export interface MonthTotals {
289
+ yyyy_mm: string; queries: number; documents_retrieved: number; chunks_retrieved: number;
290
+ citations: number; unattributed_share: number; corpora: CorpusMonthSlice[];
291
+ }
292
+ export interface RetrievalEventRow {
293
+ id: UUID; created_at: string; corpus_ids: UUID[]; pool_size: number;
294
+ message_id: UUID | null; documents: Array<Record<string, unknown>>;
295
+ }
261
296
  export interface Conversation {
262
297
  id: UUID;
263
298
  title: string | null;
@@ -863,6 +898,27 @@ export class KnowledgeCoreClient extends HttpBase {
863
898
  listAll: () => this.pageAll<Agent>("/v1/agents"),
864
899
  get: (id: UUID) => this.request<Agent>("GET", `/v1/agents/${id}`),
865
900
  };
901
+
902
+ // --- retrieval analytics (read-only, tenant-scoped, aggregate-on-read) ---
903
+ analytics = {
904
+ /** Query-volume time series for a corpus (the denominator for everything). */
905
+ corpusUsage: (corpusId: UUID, q?: { from?: string; to?: string; granularity?: "day" | "week" | "month" }) =>
906
+ this.request<UsageSeries>("GET", `/v1/analytics/corpora/${corpusId}/usage`, { query: q }),
907
+ /** Per-document analytics for a corpus (feeds the document list + the quadrant scatter). */
908
+ corpusDocuments: (corpusId: UUID, q?: { sort?: "citations" | "reranked" | "retrieved" | "best_score"; limit?: number; cursor?: string; from?: string; to?: string }) =>
909
+ this.request<{ items: DocumentAnalytics[]; next_cursor: string | null }>("GET", `/v1/analytics/corpora/${corpusId}/documents`, { query: q }),
910
+ /** One document's lifetime rollup (headline reach is CITATION reach). */
911
+ document: (documentId: UUID) => this.request<DocumentAnalytics>("GET", `/v1/analytics/documents/${documentId}`),
912
+ /** Parent-section grain for a document (never exposes chunk ids). */
913
+ documentSections: (documentId: UUID) => this.request<SectionsResponse>("GET", `/v1/analytics/documents/${documentId}/sections`),
914
+ /** A corpus's monthly metrics + revenue_share (YYYY-MM). */
915
+ corpusMonthly: (corpusId: UUID, yyyyMm: string) => this.request<MonthlyCorpus>("GET", `/v1/analytics/corpora/${corpusId}/monthly/${yyyyMm}`),
916
+ /** Cross-corpus monthly totals + per-corpus breakdown + unattributed share (YYYY-MM). */
917
+ month: (yyyyMm: string) => this.request<MonthTotals>("GET", `/v1/analytics/months/${yyyyMm}`),
918
+ /** Raw immutable events + document rollups (escape hatch for custom formulas). */
919
+ events: (q?: { from?: string; to?: string; limit?: number; cursor?: string }) =>
920
+ this.request<{ items: RetrievalEventRow[]; next_cursor: string | null }>("GET", "/v1/analytics/events", { query: q }),
921
+ };
866
922
  }
867
923
 
868
924
  // ---------------------------------------------------------------------------