@babav/knowledge-core-client 0.18.0 → 0.21.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,51 @@ 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
+ }
76
+ /** Per-request visual control. Absent => mode resolves from the agent default. All visual
77
+ * PROCESSING is server-side; the client only displays the result. */
78
+ export interface VisualRequest {
79
+ mode?: "off" | "on";
80
+ delivery?: "svg" | "json" | "both";
81
+ overrides?: VisualOverrides;
82
+ }
67
83
  export interface QueryRequest {
68
84
  corpus_ids: UUID[];
69
85
  query: string;
70
86
  conversation_id?: UUID | null;
71
87
  overrides?: QueryOverrides;
72
88
  filter?: MetadataFilter;
89
+ visual?: VisualRequest;
90
+ }
91
+ /** A visual attached to a response, anchored by char offsets into `answer` (SAME coordinate
92
+ * system as citations). For delivery="svg", `rendered_svg` is set; scenic sets `image`. */
93
+ export interface Visual {
94
+ id: string;
95
+ anchor: {
96
+ start: number;
97
+ end: number;
98
+ };
99
+ register: "chart" | "structural" | "conceptual" | "scenic";
100
+ priority: number;
101
+ payload: Record<string, unknown>;
102
+ rendered_svg?: string;
103
+ image?: {
104
+ url: string;
105
+ expires_at: number;
106
+ width: number;
107
+ height: number;
108
+ };
109
+ }
110
+ export interface VisualsMeta {
111
+ count: number;
112
+ dropped: number;
73
113
  }
74
114
  export interface QueryResponse {
75
115
  conversation_id: UUID | null;
@@ -80,6 +120,8 @@ export interface QueryResponse {
80
120
  groundedness: Groundedness | null;
81
121
  usage: Record<string, number | null>;
82
122
  standalone_query: string | null;
123
+ visuals?: Visual[];
124
+ visuals_meta?: VisualsMeta | null;
83
125
  }
84
126
  export interface Citation {
85
127
  /** Char span IN THE ANSWER this citation supports (for highlighting). */
@@ -182,6 +224,10 @@ export interface Message {
182
224
  groundedness: Record<string, unknown> | null;
183
225
  retrieval_contents: unknown[] | null;
184
226
  usage: Record<string, unknown> | null;
227
+ visuals?: {
228
+ items: Visual[];
229
+ meta: VisualsMeta;
230
+ } | null;
185
231
  }
186
232
  export interface Attachment {
187
233
  id: UUID;
@@ -290,6 +336,11 @@ export interface StreamHandlers {
290
336
  * (native path). Also present in `final`. May be `{}` if scoring was unavailable. */
291
337
  onGroundedness?: (g: Groundedness | Record<string, never>) => void;
292
338
  onFinal?: (d: QueryResponse) => void;
339
+ /** A visual, emitted (out of anchor order) during the trailing visual phase when
340
+ * visual.mode="on". Place by `anchor`, not arrival order. */
341
+ onVisual?: (v: Visual) => void;
342
+ /** Always emitted exactly once to close the visual phase (incl. count=0), before `done`. */
343
+ onVisualsComplete?: (m: VisualsMeta) => void;
293
344
  onError?: (d: unknown) => void;
294
345
  onDone?: () => void;
295
346
  /** Catch-all for any event (incl. unknown ones). */
@@ -528,4 +579,3 @@ export declare class AdminClient extends HttpBase {
528
579
  delete: (id: UUID) => Promise<void>;
529
580
  };
530
581
  }
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.21.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,47 @@ 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
+ }
98
+
99
+ /** Per-request visual control. Absent => mode resolves from the agent default. All visual
100
+ * PROCESSING is server-side; the client only displays the result. */
101
+ export interface VisualRequest {
102
+ mode?: "off" | "on";
103
+ delivery?: "svg" | "json" | "both";
104
+ overrides?: VisualOverrides;
105
+ }
106
+
78
107
  export interface QueryRequest {
79
108
  corpus_ids: UUID[];
80
109
  query: string;
81
110
  conversation_id?: UUID | null; // present => conversational; absent => one-shot
82
111
  overrides?: QueryOverrides;
83
112
  filter?: MetadataFilter;
113
+ visual?: VisualRequest;
114
+ }
115
+
116
+ /** A visual attached to a response, anchored by char offsets into `answer` (SAME coordinate
117
+ * system as citations). For delivery="svg", `rendered_svg` is set; scenic sets `image`. */
118
+ export interface Visual {
119
+ id: string;
120
+ anchor: { start: number; end: number };
121
+ register: "chart" | "structural" | "conceptual" | "scenic";
122
+ priority: number;
123
+ payload: Record<string, unknown>; // {kind: "grammar"|"vega_lite"|"svg"|"image", ...}
124
+ rendered_svg?: string;
125
+ image?: { url: string; expires_at: number; width: number; height: number };
126
+ }
127
+
128
+ export interface VisualsMeta {
129
+ count: number;
130
+ dropped: number;
84
131
  }
85
132
 
86
133
  export interface QueryResponse {
@@ -92,6 +139,8 @@ export interface QueryResponse {
92
139
  groundedness: Groundedness | null;
93
140
  usage: Record<string, number | null>;
94
141
  standalone_query: string | null;
142
+ visuals?: Visual[]; // [] when off/none
143
+ visuals_meta?: VisualsMeta | null;
95
144
  }
96
145
 
97
146
  export interface Citation {
@@ -195,6 +244,7 @@ export interface Message {
195
244
  groundedness: Record<string, unknown> | null;
196
245
  retrieval_contents: unknown[] | null;
197
246
  usage: Record<string, unknown> | null;
247
+ visuals?: { items: Visual[]; meta: VisualsMeta } | null; // post-generation visuals (re-signed URLs on read)
198
248
  }
199
249
  export interface Attachment {
200
250
  id: UUID;
@@ -405,6 +455,11 @@ export interface StreamHandlers {
405
455
  * (native path). Also present in `final`. May be `{}` if scoring was unavailable. */
406
456
  onGroundedness?: (g: Groundedness | Record<string, never>) => void;
407
457
  onFinal?: (d: QueryResponse) => void;
458
+ /** A visual, emitted (out of anchor order) during the trailing visual phase when
459
+ * visual.mode="on". Place by `anchor`, not arrival order. */
460
+ onVisual?: (v: Visual) => void;
461
+ /** Always emitted exactly once to close the visual phase (incl. count=0), before `done`. */
462
+ onVisualsComplete?: (m: VisualsMeta) => void;
408
463
  onError?: (d: unknown) => void;
409
464
  onDone?: () => void;
410
465
  /** Catch-all for any event (incl. unknown ones). */
@@ -653,6 +708,8 @@ function dispatchSse(frame: string, h: StreamHandlers): void {
653
708
  case "citation": h.onCitation?.(data as Citation); break;
654
709
  case "groundedness": h.onGroundedness?.(data as never); break;
655
710
  case "final": h.onFinal?.(data as QueryResponse); break;
711
+ case "visual": h.onVisual?.(data as Visual); break;
712
+ case "visuals_complete": h.onVisualsComplete?.(data as VisualsMeta); break;
656
713
  case "error": h.onError?.(data); break;
657
714
  case "done": h.onDone?.(); break;
658
715
  }
@@ -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
+ }