@babav/knowledge-core-client 0.25.1 → 0.27.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
@@ -90,6 +90,10 @@ export interface QueryRequest {
90
90
  filter?: MetadataFilter;
91
91
  visual?: VisualRequest;
92
92
  }
93
+ /** The spatial arrangement a conceptual visual encodes (the geometry that carries the meaning).
94
+ * "free" = renderer's judgment / not a declared arrangement (also the value for non-conceptual
95
+ * registers). */
96
+ export type VisualLayout = "linear-flow" | "ring-cycle" | "nesting" | "radial-hub" | "side-by-side" | "stacked-layers" | "two-state" | "free";
93
97
  /** A visual attached to a response, anchored by char offsets into `answer` (SAME coordinate
94
98
  * system as citations). For delivery="svg", `rendered_svg` is set; scenic sets `image`. */
95
99
  export interface Visual {
@@ -101,6 +105,8 @@ export interface Visual {
101
105
  register: "chart" | "structural" | "conceptual" | "scenic";
102
106
  priority: number;
103
107
  payload: Record<string, unknown>;
108
+ /** Declared spatial arrangement (meaningful for `conceptual`; "free" otherwise). */
109
+ layout: VisualLayout;
104
110
  rendered_svg?: string;
105
111
  image?: {
106
112
  url: string;
@@ -181,6 +187,16 @@ export interface Folder {
181
187
  corpus_id: UUID;
182
188
  name: string;
183
189
  }
190
+ export interface Reach {
191
+ exposure_queries: number;
192
+ citation_reach: number | null;
193
+ retrieved_reach: number | null;
194
+ conversion: number | null;
195
+ citation_count: number;
196
+ chunks_reranked: number;
197
+ best_rerank_score: number | null;
198
+ band: AnalyticsBand;
199
+ }
184
200
  export interface Document {
185
201
  id: UUID;
186
202
  corpus_id: UUID;
@@ -192,6 +208,7 @@ export interface Document {
192
208
  chunk_count: number;
193
209
  custom_metadata: Record<string, unknown>;
194
210
  error: string | null;
211
+ reach?: Reach;
195
212
  }
196
213
  export interface ContentUrl {
197
214
  content_url: string;
@@ -312,6 +329,25 @@ export interface RetrievalEventRow {
312
329
  message_id: UUID | null;
313
330
  documents: Array<Record<string, unknown>>;
314
331
  }
332
+ export type Quadrant = "workhorse" | "hidden_gem" | "padding" | "cold" | "insufficient_data";
333
+ export interface ScatterDoc {
334
+ document_id: UUID;
335
+ filename: string | null;
336
+ x_retrieved_reach: number;
337
+ y_conversion: number;
338
+ chunk_count: number;
339
+ citation_count: number;
340
+ exposure_queries: number;
341
+ band: AnalyticsBand;
342
+ quadrant: Quadrant;
343
+ }
344
+ export interface ScatterResponse {
345
+ corpus_id: UUID;
346
+ corpus_total_queries: number;
347
+ generated_at: string;
348
+ truncated: boolean;
349
+ documents: ScatterDoc[];
350
+ }
315
351
  export interface Conversation {
316
352
  id: UUID;
317
353
  title: string | null;
@@ -638,6 +674,7 @@ export declare class KnowledgeCoreClient extends HttpBase {
638
674
  listDocuments: (folderId: UUID, q?: {
639
675
  limit?: number;
640
676
  cursor?: string;
677
+ include?: "reach";
641
678
  }) => Promise<Page<Document>>;
642
679
  /** Count documents in the folder: { total, indexed, in_flight, failed }. */
643
680
  countDocuments: (folderId: UUID) => Promise<DocumentCount>;
@@ -651,7 +688,9 @@ export declare class KnowledgeCoreClient extends HttpBase {
651
688
  events: (folderId: UUID, handlers: DocumentEventHandlers, signal?: AbortSignal) => Promise<void>;
652
689
  };
653
690
  documents: {
654
- get: (id: UUID) => Promise<Document>;
691
+ get: (id: UUID, opts?: {
692
+ include?: "reach";
693
+ }) => Promise<Document>;
655
694
  getCustomMetadata: (id: UUID) => Promise<Record<string, unknown>>;
656
695
  /** Merge custom_metadata (a null value deletes a key). Returns the merged object. */
657
696
  patchCustomMetadata: (id: UUID, custom_metadata: Record<string, unknown>) => Promise<Record<string, unknown>>;
@@ -777,6 +816,9 @@ export declare class KnowledgeCoreClient extends HttpBase {
777
816
  document: (documentId: UUID) => Promise<DocumentAnalytics>;
778
817
  /** Parent-section grain for a document (never exposes chunk ids). */
779
818
  documentSections: (documentId: UUID) => Promise<SectionsResponse>;
819
+ /** Whole-corpus scatter payload: every document with x=retrieved_reach, y=conversion,
820
+ * bubble=chunk_count, and a server-computed quadrant. No pagination (`truncated` if capped). */
821
+ corpusScatter: (corpusId: UUID) => Promise<ScatterResponse>;
780
822
  /** A corpus's monthly metrics + revenue_share (YYYY-MM). */
781
823
  corpusMonthly: (corpusId: UUID, yyyyMm: string) => Promise<MonthlyCorpus>;
782
824
  /** Cross-corpus monthly totals + per-corpus breakdown + unattributed share (YYYY-MM). */
package/dist/index.js CHANGED
@@ -336,7 +336,7 @@ export class KnowledgeCoreClient extends HttpBase {
336
336
  };
337
337
  // --- documents ---
338
338
  documents = {
339
- get: (id) => this.request("GET", `/v1/documents/${id}`),
339
+ get: (id, opts) => this.request("GET", `/v1/documents/${id}`, { query: opts }),
340
340
  getCustomMetadata: (id) => this.request("GET", `/v1/documents/${id}/custom_metadata`),
341
341
  /** Merge custom_metadata (a null value deletes a key). Returns the merged object. */
342
342
  patchCustomMetadata: (id, custom_metadata) => this.request("PATCH", `/v1/documents/${id}/custom_metadata`, { json: custom_metadata }),
@@ -420,6 +420,9 @@ export class KnowledgeCoreClient extends HttpBase {
420
420
  document: (documentId) => this.request("GET", `/v1/analytics/documents/${documentId}`),
421
421
  /** Parent-section grain for a document (never exposes chunk ids). */
422
422
  documentSections: (documentId) => this.request("GET", `/v1/analytics/documents/${documentId}/sections`),
423
+ /** Whole-corpus scatter payload: every document with x=retrieved_reach, y=conversion,
424
+ * bubble=chunk_count, and a server-computed quadrant. No pagination (`truncated` if capped). */
425
+ corpusScatter: (corpusId) => this.request("GET", `/v1/analytics/corpora/${corpusId}/scatter`),
423
426
  /** A corpus's monthly metrics + revenue_share (YYYY-MM). */
424
427
  corpusMonthly: (corpusId, yyyyMm) => this.request("GET", `/v1/analytics/corpora/${corpusId}/monthly/${yyyyMm}`),
425
428
  /** Cross-corpus monthly totals + per-corpus breakdown + unattributed share (YYYY-MM). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.25.1",
3
+ "version": "0.27.0",
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
@@ -115,6 +115,19 @@ export interface QueryRequest {
115
115
  visual?: VisualRequest;
116
116
  }
117
117
 
118
+ /** The spatial arrangement a conceptual visual encodes (the geometry that carries the meaning).
119
+ * "free" = renderer's judgment / not a declared arrangement (also the value for non-conceptual
120
+ * registers). */
121
+ export type VisualLayout =
122
+ | "linear-flow"
123
+ | "ring-cycle"
124
+ | "nesting"
125
+ | "radial-hub"
126
+ | "side-by-side"
127
+ | "stacked-layers"
128
+ | "two-state"
129
+ | "free";
130
+
118
131
  /** A visual attached to a response, anchored by char offsets into `answer` (SAME coordinate
119
132
  * system as citations). For delivery="svg", `rendered_svg` is set; scenic sets `image`. */
120
133
  export interface Visual {
@@ -123,6 +136,8 @@ export interface Visual {
123
136
  register: "chart" | "structural" | "conceptual" | "scenic";
124
137
  priority: number;
125
138
  payload: Record<string, unknown>; // {kind: "grammar"|"vega_lite"|"svg"|"image", ...}
139
+ /** Declared spatial arrangement (meaningful for `conceptual`; "free" otherwise). */
140
+ layout: VisualLayout;
126
141
  rendered_svg?: string;
127
142
  image?: { url: string; expires_at: number; width: number; height: number };
128
143
  }
@@ -202,6 +217,16 @@ export interface Folder {
202
217
  corpus_id: UUID;
203
218
  name: string;
204
219
  }
220
+ export interface Reach {
221
+ exposure_queries: number;
222
+ citation_reach: number | null; // DOCUMENT headline metric
223
+ retrieved_reach: number | null;
224
+ conversion: number | null;
225
+ citation_count: number;
226
+ chunks_reranked: number;
227
+ best_rerank_score: number | null;
228
+ band: AnalyticsBand;
229
+ }
205
230
  export interface Document {
206
231
  id: UUID;
207
232
  corpus_id: UUID;
@@ -213,6 +238,7 @@ export interface Document {
213
238
  chunk_count: number;
214
239
  custom_metadata: Record<string, unknown>;
215
240
  error: string | null;
241
+ reach?: Reach; // present only when requested with include=reach
216
242
  }
217
243
  export interface ContentUrl {
218
244
  content_url: string;
@@ -293,6 +319,17 @@ export interface RetrievalEventRow {
293
319
  id: UUID; created_at: string; corpus_ids: UUID[]; pool_size: number;
294
320
  message_id: UUID | null; documents: Array<Record<string, unknown>>;
295
321
  }
322
+ export type Quadrant = "workhorse" | "hidden_gem" | "padding" | "cold" | "insufficient_data";
323
+ export interface ScatterDoc {
324
+ document_id: UUID; filename: string | null;
325
+ x_retrieved_reach: number; y_conversion: number;
326
+ chunk_count: number; citation_count: number; exposure_queries: number;
327
+ band: AnalyticsBand; quadrant: Quadrant;
328
+ }
329
+ export interface ScatterResponse {
330
+ corpus_id: UUID; corpus_total_queries: number; generated_at: string;
331
+ truncated: boolean; documents: ScatterDoc[];
332
+ }
296
333
  export interface Conversation {
297
334
  id: UUID;
298
335
  title: string | null;
@@ -792,7 +829,7 @@ export class KnowledgeCoreClient extends HttpBase {
792
829
  // folder cannot be deleted either way.
793
830
  delete: (folderId: UUID, confirmName?: string) =>
794
831
  this.request<void>("DELETE", `/v1/folders/${folderId}`, confirmName ? { query: { confirm: confirmName } } : undefined),
795
- listDocuments: (folderId: UUID, q?: { limit?: number; cursor?: string }) =>
832
+ listDocuments: (folderId: UUID, q?: { limit?: number; cursor?: string; include?: "reach" }) =>
796
833
  this.request<Page<Document>>("GET", `/v1/folders/${folderId}/documents`, { query: q }),
797
834
  /** Count documents in the folder: { total, indexed, in_flight, failed }. */
798
835
  countDocuments: (folderId: UUID) =>
@@ -808,7 +845,8 @@ export class KnowledgeCoreClient extends HttpBase {
808
845
 
809
846
  // --- documents ---
810
847
  documents = {
811
- get: (id: UUID) => this.request<Document>("GET", `/v1/documents/${id}`),
848
+ get: (id: UUID, opts?: { include?: "reach" }) =>
849
+ this.request<Document>("GET", `/v1/documents/${id}`, { query: opts }),
812
850
  getCustomMetadata: (id: UUID) => this.request<Record<string, unknown>>("GET", `/v1/documents/${id}/custom_metadata`),
813
851
  /** Merge custom_metadata (a null value deletes a key). Returns the merged object. */
814
852
  patchCustomMetadata: (id: UUID, custom_metadata: Record<string, unknown>) =>
@@ -911,6 +949,9 @@ export class KnowledgeCoreClient extends HttpBase {
911
949
  document: (documentId: UUID) => this.request<DocumentAnalytics>("GET", `/v1/analytics/documents/${documentId}`),
912
950
  /** Parent-section grain for a document (never exposes chunk ids). */
913
951
  documentSections: (documentId: UUID) => this.request<SectionsResponse>("GET", `/v1/analytics/documents/${documentId}/sections`),
952
+ /** Whole-corpus scatter payload: every document with x=retrieved_reach, y=conversion,
953
+ * bubble=chunk_count, and a server-computed quadrant. No pagination (`truncated` if capped). */
954
+ corpusScatter: (corpusId: UUID) => this.request<ScatterResponse>("GET", `/v1/analytics/corpora/${corpusId}/scatter`),
914
955
  /** A corpus's monthly metrics + revenue_share (YYYY-MM). */
915
956
  corpusMonthly: (corpusId: UUID, yyyyMm: string) => this.request<MonthlyCorpus>("GET", `/v1/analytics/corpora/${corpusId}/monthly/${yyyyMm}`),
916
957
  /** Cross-corpus monthly totals + per-corpus breakdown + unattributed share (YYYY-MM). */