@babav/knowledge-core-client 0.18.0 → 0.20.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
@@ -20,6 +20,7 @@
20
20
  * A missing baseUrl or apiKey throws at construction with a clear message.
21
21
  */
22
22
  export type UUID = string;
23
+ export type { VisualEnvelope, VisualPayload, VisualElement, VisualComposition, VisualRegister, ChartBlockElement, } from "./visual/types.js";
23
24
  export interface Page<T> {
24
25
  items: T[];
25
26
  next_cursor: string | null;
@@ -64,12 +65,52 @@ export interface QueryOverrides {
64
65
  grounding_enabled?: boolean;
65
66
  citations_enabled?: boolean;
66
67
  }
68
+ /** Per-request visual overrides (see VisualRequest). */
69
+ export interface VisualOverrides {
70
+ concept_rounds_max?: number;
71
+ proposals_n?: number;
72
+ max_revisions?: number;
73
+ claims_check_model?: string;
74
+ vision_judge_model?: string;
75
+ scenic_enabled?: boolean;
76
+ }
77
+ /** Per-request visual control. Absent => mode resolves from the agent default. All visual
78
+ * PROCESSING is server-side; the client only displays the result. */
79
+ export interface VisualRequest {
80
+ mode?: "off" | "on";
81
+ delivery?: "svg" | "json" | "both";
82
+ overrides?: VisualOverrides;
83
+ }
67
84
  export interface QueryRequest {
68
85
  corpus_ids: UUID[];
69
86
  query: string;
70
87
  conversation_id?: UUID | null;
71
88
  overrides?: QueryOverrides;
72
89
  filter?: MetadataFilter;
90
+ visual?: VisualRequest;
91
+ }
92
+ /** A visual attached to a response, anchored by char offsets into `answer` (SAME coordinate
93
+ * system as citations). For delivery="svg", `rendered_svg` is set; scenic sets `image`. */
94
+ export interface Visual {
95
+ id: string;
96
+ anchor: {
97
+ start: number;
98
+ end: number;
99
+ };
100
+ register: "chart" | "structural" | "conceptual" | "scenic";
101
+ priority: number;
102
+ payload: Record<string, unknown>;
103
+ rendered_svg?: string;
104
+ image?: {
105
+ url: string;
106
+ expires_at: number;
107
+ width: number;
108
+ height: number;
109
+ };
110
+ }
111
+ export interface VisualsMeta {
112
+ count: number;
113
+ dropped: number;
73
114
  }
74
115
  export interface QueryResponse {
75
116
  conversation_id: UUID | null;
@@ -80,6 +121,8 @@ export interface QueryResponse {
80
121
  groundedness: Groundedness | null;
81
122
  usage: Record<string, number | null>;
82
123
  standalone_query: string | null;
124
+ visuals?: Visual[];
125
+ visuals_meta?: VisualsMeta | null;
83
126
  }
84
127
  export interface Citation {
85
128
  /** Char span IN THE ANSWER this citation supports (for highlighting). */
@@ -182,6 +225,10 @@ export interface Message {
182
225
  groundedness: Record<string, unknown> | null;
183
226
  retrieval_contents: unknown[] | null;
184
227
  usage: Record<string, unknown> | null;
228
+ visuals?: {
229
+ items: Visual[];
230
+ meta: VisualsMeta;
231
+ } | null;
185
232
  }
186
233
  export interface Attachment {
187
234
  id: UUID;
@@ -290,6 +337,11 @@ export interface StreamHandlers {
290
337
  * (native path). Also present in `final`. May be `{}` if scoring was unavailable. */
291
338
  onGroundedness?: (g: Groundedness | Record<string, never>) => void;
292
339
  onFinal?: (d: QueryResponse) => void;
340
+ /** A visual, emitted (out of anchor order) during the trailing visual phase when
341
+ * visual.mode="on". Place by `anchor`, not arrival order. */
342
+ onVisual?: (v: Visual) => void;
343
+ /** Always emitted exactly once to close the visual phase (incl. count=0), before `done`. */
344
+ onVisualsComplete?: (m: VisualsMeta) => void;
293
345
  onError?: (d: unknown) => void;
294
346
  onDone?: () => void;
295
347
  /** Catch-all for any event (incl. unknown ones). */
@@ -528,4 +580,3 @@ export declare class AdminClient extends HttpBase {
528
580
  delete: (id: UUID) => Promise<void>;
529
581
  };
530
582
  }
531
- export {};
package/dist/index.js CHANGED
@@ -364,6 +364,12 @@ function dispatchSse(frame, h) {
364
364
  case "final":
365
365
  h.onFinal?.(data);
366
366
  break;
367
+ case "visual":
368
+ h.onVisual?.(data);
369
+ break;
370
+ case "visuals_complete":
371
+ h.onVisualsComplete?.(data);
372
+ break;
367
373
  case "error":
368
374
  h.onError?.(data);
369
375
  break;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@babav/knowledge-core-client/visual` — the babav.visual grammar TYPES.
3
+ *
4
+ * Types only (zero runtime, zero deps): they let a client type the visual payloads it may
5
+ * receive. All visual PROCESSING — grammar validation, layout, and SVG/PNG rendering — runs
6
+ * SERVER-SIDE in render-service; the client only displays the server-produced SVG/image.
7
+ * The schema + validators + renderers therefore live in render-service, not here.
8
+ */
9
+ export * from "./types.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@babav/knowledge-core-client/visual` — the babav.visual grammar TYPES.
3
+ *
4
+ * Types only (zero runtime, zero deps): they let a client type the visual payloads it may
5
+ * receive. All visual PROCESSING — grammar validation, layout, and SVG/PNG rendering — runs
6
+ * SERVER-SIDE in render-service; the client only displays the server-produced SVG/image.
7
+ * The schema + validators + renderers therefore live in render-service, not here.
8
+ */
9
+ export * from "./types.js";
@@ -0,0 +1,105 @@
1
+ /**
2
+ * `babav.visual` grammar — TypeScript types (WP1a).
3
+ *
4
+ * The typed structural-composition language the visual pipeline emits for the
5
+ * `structural` register (and the envelope that wraps every register's payload). Uses
6
+ * vocabulary models already know — nodes, connectors (edges), containers/panels
7
+ * (clusters), composition operators. LLMs compose in this grammar; a deterministic
8
+ * engine (ELK) does layout — models never emit coordinates.
9
+ *
10
+ * NB: the grammar uses its own camelCase convention (`chartBlock`, `vegaLiteSpec`,
11
+ * `focalElement`) per the visual spec — distinct from the KC API's snake_case wire
12
+ * shapes. Versioned from the first commit (`version: "1"`).
13
+ */
14
+ export type VisualRegister = "chart" | "structural" | "conceptual" | "scenic";
15
+ export type EmphasisLevel = "normal" | "strong" | "muted";
16
+ export type ConnectorKind = "flow" | "dependency" | "association" | "containment" | "bidirectional";
17
+ export interface NodeElement {
18
+ type: "node";
19
+ id: string;
20
+ label: string;
21
+ role?: string;
22
+ emphasis?: EmphasisLevel;
23
+ }
24
+ export interface ConnectorElement {
25
+ type: "connector";
26
+ id?: string;
27
+ from: string;
28
+ to: string;
29
+ label?: string;
30
+ kind: ConnectorKind;
31
+ }
32
+ export interface ContainerElement {
33
+ type: "container";
34
+ id: string;
35
+ label?: string;
36
+ children: string[];
37
+ }
38
+ export interface PanelElement {
39
+ type: "panel";
40
+ id: string;
41
+ title?: string;
42
+ children: string[];
43
+ }
44
+ export interface AnnotationElement {
45
+ type: "annotation";
46
+ id?: string;
47
+ target: string;
48
+ text: string;
49
+ }
50
+ export interface ChartBlockElement {
51
+ type: "chartBlock";
52
+ id: string;
53
+ vegaLiteSpec: Record<string, unknown>;
54
+ }
55
+ export type VisualElement = NodeElement | ConnectorElement | ContainerElement | PanelElement | AnnotationElement | ChartBlockElement;
56
+ export interface NestComposition {
57
+ op: "nest";
58
+ parent: string;
59
+ children: string[];
60
+ }
61
+ export interface SequenceComposition {
62
+ op: "sequence";
63
+ items: string[];
64
+ }
65
+ export interface JuxtaposeComposition {
66
+ op: "juxtapose";
67
+ items: string[];
68
+ }
69
+ export interface LayerComposition {
70
+ op: "layer";
71
+ items: string[];
72
+ }
73
+ export interface LinkComposition {
74
+ op: "link";
75
+ from: string;
76
+ to: string;
77
+ label?: string;
78
+ kind?: ConnectorKind;
79
+ }
80
+ export type VisualComposition = NestComposition | SequenceComposition | JuxtaposeComposition | LayerComposition | LinkComposition;
81
+ export type Orientation = "horizontal" | "vertical" | "radial";
82
+ export type Density = "compact" | "comfortable" | "spacious";
83
+ export interface LayoutIntent {
84
+ orientation?: Orientation;
85
+ density?: Density;
86
+ focalElement?: string;
87
+ }
88
+ export interface VisualPayload {
89
+ elements: VisualElement[];
90
+ composition?: VisualComposition[];
91
+ layout?: LayoutIntent;
92
+ }
93
+ /** Per-element source provenance. Present from v1; populated in Phase 2. */
94
+ export interface VisualProvenance {
95
+ [k: string]: unknown;
96
+ }
97
+ /** The envelope wrapping every register's payload. */
98
+ export interface VisualEnvelope {
99
+ schema: "babav.visual";
100
+ version: "1";
101
+ register: VisualRegister;
102
+ gist?: string;
103
+ provenance?: VisualProvenance[];
104
+ payload: VisualPayload;
105
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `babav.visual` grammar — TypeScript types (WP1a).
3
+ *
4
+ * The typed structural-composition language the visual pipeline emits for the
5
+ * `structural` register (and the envelope that wraps every register's payload). Uses
6
+ * vocabulary models already know — nodes, connectors (edges), containers/panels
7
+ * (clusters), composition operators. LLMs compose in this grammar; a deterministic
8
+ * engine (ELK) does layout — models never emit coordinates.
9
+ *
10
+ * NB: the grammar uses its own camelCase convention (`chartBlock`, `vegaLiteSpec`,
11
+ * `focalElement`) per the visual spec — distinct from the KC API's snake_case wire
12
+ * shapes. Versioned from the first commit (`version: "1"`).
13
+ */
14
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.18.0",
4
- "description": "TypeScript client for the Babav Knowledge Core API (Deno + Node 18+, zero deps).",
3
+ "version": "0.20.0",
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",
7
7
  "types": "./dist/index.d.ts",
@@ -9,6 +9,10 @@
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.js"
12
+ },
13
+ "./visual": {
14
+ "types": "./dist/visual/index.d.ts",
15
+ "import": "./dist/visual/index.js"
12
16
  }
13
17
  },
14
18
  "files": [
package/src/index.ts CHANGED
@@ -25,6 +25,18 @@
25
25
  // ---------------------------------------------------------------------------
26
26
  export type UUID = string;
27
27
 
28
+ // The babav.visual grammar (WP1a). Types are re-exported here for convenience; the full
29
+ // grammar (schema + validators + fixtures) lives at the `./visual` subpath so it can pull
30
+ // its optional `ajv` peer without adding any dependency to this main entry.
31
+ export type {
32
+ VisualEnvelope,
33
+ VisualPayload,
34
+ VisualElement,
35
+ VisualComposition,
36
+ VisualRegister,
37
+ ChartBlockElement,
38
+ } from "./visual/types.js";
39
+
28
40
  export interface Page<T> {
29
41
  items: T[];
30
42
  next_cursor: string | null;
@@ -75,12 +87,48 @@ export interface QueryOverrides {
75
87
  citations_enabled?: boolean; // source attribution (default on)
76
88
  }
77
89
 
90
+ /** Per-request visual overrides (see VisualRequest). */
91
+ export interface VisualOverrides {
92
+ concept_rounds_max?: number;
93
+ proposals_n?: number;
94
+ max_revisions?: number;
95
+ claims_check_model?: string;
96
+ vision_judge_model?: string;
97
+ scenic_enabled?: boolean;
98
+ }
99
+
100
+ /** Per-request visual control. Absent => mode resolves from the agent default. All visual
101
+ * PROCESSING is server-side; the client only displays the result. */
102
+ export interface VisualRequest {
103
+ mode?: "off" | "on";
104
+ delivery?: "svg" | "json" | "both";
105
+ overrides?: VisualOverrides;
106
+ }
107
+
78
108
  export interface QueryRequest {
79
109
  corpus_ids: UUID[];
80
110
  query: string;
81
111
  conversation_id?: UUID | null; // present => conversational; absent => one-shot
82
112
  overrides?: QueryOverrides;
83
113
  filter?: MetadataFilter;
114
+ visual?: VisualRequest;
115
+ }
116
+
117
+ /** A visual attached to a response, anchored by char offsets into `answer` (SAME coordinate
118
+ * system as citations). For delivery="svg", `rendered_svg` is set; scenic sets `image`. */
119
+ export interface Visual {
120
+ id: string;
121
+ anchor: { start: number; end: number };
122
+ register: "chart" | "structural" | "conceptual" | "scenic";
123
+ priority: number;
124
+ payload: Record<string, unknown>; // {kind: "grammar"|"vega_lite"|"svg"|"image", ...}
125
+ rendered_svg?: string;
126
+ image?: { url: string; expires_at: number; width: number; height: number };
127
+ }
128
+
129
+ export interface VisualsMeta {
130
+ count: number;
131
+ dropped: number;
84
132
  }
85
133
 
86
134
  export interface QueryResponse {
@@ -92,6 +140,8 @@ export interface QueryResponse {
92
140
  groundedness: Groundedness | null;
93
141
  usage: Record<string, number | null>;
94
142
  standalone_query: string | null;
143
+ visuals?: Visual[]; // [] when off/none
144
+ visuals_meta?: VisualsMeta | null;
95
145
  }
96
146
 
97
147
  export interface Citation {
@@ -195,6 +245,7 @@ export interface Message {
195
245
  groundedness: Record<string, unknown> | null;
196
246
  retrieval_contents: unknown[] | null;
197
247
  usage: Record<string, unknown> | null;
248
+ visuals?: { items: Visual[]; meta: VisualsMeta } | null; // post-generation visuals (re-signed URLs on read)
198
249
  }
199
250
  export interface Attachment {
200
251
  id: UUID;
@@ -405,6 +456,11 @@ export interface StreamHandlers {
405
456
  * (native path). Also present in `final`. May be `{}` if scoring was unavailable. */
406
457
  onGroundedness?: (g: Groundedness | Record<string, never>) => void;
407
458
  onFinal?: (d: QueryResponse) => void;
459
+ /** A visual, emitted (out of anchor order) during the trailing visual phase when
460
+ * visual.mode="on". Place by `anchor`, not arrival order. */
461
+ onVisual?: (v: Visual) => void;
462
+ /** Always emitted exactly once to close the visual phase (incl. count=0), before `done`. */
463
+ onVisualsComplete?: (m: VisualsMeta) => void;
408
464
  onError?: (d: unknown) => void;
409
465
  onDone?: () => void;
410
466
  /** Catch-all for any event (incl. unknown ones). */
@@ -653,6 +709,8 @@ function dispatchSse(frame: string, h: StreamHandlers): void {
653
709
  case "citation": h.onCitation?.(data as Citation); break;
654
710
  case "groundedness": h.onGroundedness?.(data as never); break;
655
711
  case "final": h.onFinal?.(data as QueryResponse); break;
712
+ case "visual": h.onVisual?.(data as Visual); break;
713
+ case "visuals_complete": h.onVisualsComplete?.(data as VisualsMeta); break;
656
714
  case "error": h.onError?.(data); break;
657
715
  case "done": h.onDone?.(); break;
658
716
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `@babav/knowledge-core-client/visual` — the babav.visual grammar TYPES.
3
+ *
4
+ * Types only (zero runtime, zero deps): they let a client type the visual payloads it may
5
+ * receive. All visual PROCESSING — grammar validation, layout, and SVG/PNG rendering — runs
6
+ * SERVER-SIDE in render-service; the client only displays the server-produced SVG/image.
7
+ * The schema + validators + renderers therefore live in render-service, not here.
8
+ */
9
+
10
+ export * from "./types.js";
@@ -0,0 +1,132 @@
1
+ /**
2
+ * `babav.visual` grammar — TypeScript types (WP1a).
3
+ *
4
+ * The typed structural-composition language the visual pipeline emits for the
5
+ * `structural` register (and the envelope that wraps every register's payload). Uses
6
+ * vocabulary models already know — nodes, connectors (edges), containers/panels
7
+ * (clusters), composition operators. LLMs compose in this grammar; a deterministic
8
+ * engine (ELK) does layout — models never emit coordinates.
9
+ *
10
+ * NB: the grammar uses its own camelCase convention (`chartBlock`, `vegaLiteSpec`,
11
+ * `focalElement`) per the visual spec — distinct from the KC API's snake_case wire
12
+ * shapes. Versioned from the first commit (`version: "1"`).
13
+ */
14
+
15
+ export type VisualRegister = "chart" | "structural" | "conceptual" | "scenic";
16
+
17
+ export type EmphasisLevel = "normal" | "strong" | "muted";
18
+ export type ConnectorKind =
19
+ | "flow"
20
+ | "dependency"
21
+ | "association"
22
+ | "containment"
23
+ | "bidirectional";
24
+
25
+ // --- Layer A: primitives (each drawable element; `type`-discriminated) --------
26
+ export interface NodeElement {
27
+ type: "node";
28
+ id: string;
29
+ label: string;
30
+ role?: string;
31
+ emphasis?: EmphasisLevel;
32
+ }
33
+ export interface ConnectorElement {
34
+ type: "connector";
35
+ id?: string;
36
+ from: string; // node id
37
+ to: string; // node id
38
+ label?: string;
39
+ kind: ConnectorKind;
40
+ }
41
+ export interface ContainerElement {
42
+ type: "container";
43
+ id: string;
44
+ label?: string;
45
+ children: string[]; // element ids
46
+ }
47
+ export interface PanelElement {
48
+ type: "panel";
49
+ id: string;
50
+ title?: string;
51
+ children: string[]; // element ids
52
+ }
53
+ export interface AnnotationElement {
54
+ type: "annotation";
55
+ id?: string;
56
+ target: string; // element id
57
+ text: string;
58
+ }
59
+ export interface ChartBlockElement {
60
+ type: "chartBlock";
61
+ id: string;
62
+ vegaLiteSpec: Record<string, unknown>; // whitelisted subset enforced at render time
63
+ }
64
+ export type VisualElement =
65
+ | NodeElement
66
+ | ConnectorElement
67
+ | ContainerElement
68
+ | PanelElement
69
+ | AnnotationElement
70
+ | ChartBlockElement;
71
+
72
+ // --- Layer B: composition (arrangement over element ids; `op`-discriminated) --
73
+ export interface NestComposition {
74
+ op: "nest";
75
+ parent: string;
76
+ children: string[];
77
+ }
78
+ export interface SequenceComposition {
79
+ op: "sequence";
80
+ items: string[];
81
+ }
82
+ export interface JuxtaposeComposition {
83
+ op: "juxtapose";
84
+ items: string[];
85
+ }
86
+ export interface LayerComposition {
87
+ op: "layer";
88
+ items: string[];
89
+ }
90
+ export interface LinkComposition {
91
+ op: "link";
92
+ from: string;
93
+ to: string;
94
+ label?: string;
95
+ kind?: ConnectorKind;
96
+ }
97
+ export type VisualComposition =
98
+ | NestComposition
99
+ | SequenceComposition
100
+ | JuxtaposeComposition
101
+ | LayerComposition
102
+ | LinkComposition;
103
+
104
+ // --- Layout intent: hints only; the engine decides -------------------------
105
+ export type Orientation = "horizontal" | "vertical" | "radial";
106
+ export type Density = "compact" | "comfortable" | "spacious";
107
+ export interface LayoutIntent {
108
+ orientation?: Orientation;
109
+ density?: Density;
110
+ focalElement?: string; // element id
111
+ }
112
+
113
+ export interface VisualPayload {
114
+ elements: VisualElement[];
115
+ composition?: VisualComposition[];
116
+ layout?: LayoutIntent;
117
+ }
118
+
119
+ /** Per-element source provenance. Present from v1; populated in Phase 2. */
120
+ export interface VisualProvenance {
121
+ [k: string]: unknown;
122
+ }
123
+
124
+ /** The envelope wrapping every register's payload. */
125
+ export interface VisualEnvelope {
126
+ schema: "babav.visual";
127
+ version: "1";
128
+ register: VisualRegister;
129
+ gist?: string;
130
+ provenance?: VisualProvenance[];
131
+ payload: VisualPayload;
132
+ }