@fleetx_io/ai-ui-dsl 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.0.0] - 2026-03-27
10
+
11
+ ### Added
12
+
13
+ - TypeScript types for block-based assistant UI: `Message`, `Conversation`, block variants (`text`, `chart`, `table`, `form`, `action`, `widget`, `tool_use`, `tool_result`, `step`, `loading`, `error`, `map`), and related helpers.
14
+ - Streaming protocol types: `StreamEvent` variants and `StreamEventCallbacks`.
15
+ - Delta types: `text_delta`, `input_json_delta`, `json_patch`, `html_delta`, `status_delta`, `loading_message`.
16
+ - Pure reducers: `messageReducer`, `applyDelta`, `createEmptyMessage`, `setByPath`.
17
+ - Type guard: `isBlockType`.
18
+ - **ESM-only** package (`"type": "module"`), Node 20+.
19
+ - `exports` map for the package entry point.
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2025 Satish Kumar
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10
+ SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
13
+ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # @fleetx_io/ai-ui-dsl
2
+
3
+ **FleetX AI UI DSL** — a domain-specific language for **block-based, streaming AI chat UIs**. Assistant replies are a `Message` made of an ordered list of **Blocks** (text, charts, tables, maps, forms, actions, tools, etc.), updated through a small streaming protocol.
4
+
5
+ This npm package ships **TypeScript types** and **pure reducers** (`messageReducer`, `applyDelta`, …). It is **framework-agnostic** (no React/Vue).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @fleetx_io/ai-ui-dsl
11
+ ```
12
+
13
+ ## Core ideas
14
+
15
+ 1. **Block composition** — One message = a flat list of blocks; blocks are not nested.
16
+ 2. **Incremental streaming** — Each block follows `block_start → block_delta (0..N) → block_end` (or `block_error`).
17
+ 3. **Immutable reducers** — Feed `StreamEvent`s into `messageReducer`; render the resulting `Message`.
18
+
19
+ ### Server → client flow
20
+
21
+ ```
22
+ message_start → create / bind Message
23
+ block_start → append Block (status streaming)
24
+ block_delta → applyDelta → re-render
25
+ block_end → mark Block completed
26
+
27
+ message_end → mark Message completed
28
+ ```
29
+
30
+ ## Block types (summary)
31
+
32
+ | Block | `type` | Typical streaming |
33
+ | --------------- | ------------- | ------------------------------------------ |
34
+ | Text | `text` | `text_delta` (append to `content`) |
35
+ | Chart | `chart` | `json_patch` on Highcharts `config` |
36
+ | Table | `table` | `json_patch` (e.g. rows) |
37
+ | Form | `form` | Often static at start; optional `json_patch` |
38
+ | Action | `action` | Static |
39
+ | Widget | `widget` | `html_delta` (sandboxed HTML) |
40
+ | Tool use/result | `tool_use` / `tool_result` | `input_json_delta` / `json_patch` |
41
+ | Step | `step` | `json_patch` on steps |
42
+ | Loading | `loading` | `loading_message` |
43
+ | Error | `error` | Static |
44
+ | Map | `map` | `json_patch` markers, polylines, polygons |
45
+
46
+ ## Streaming protocol (summary)
47
+
48
+ **Events:** `message_start`, `block_start`, `block_delta`, `block_end`, `block_error`, `message_end` (includes `messageId`).
49
+
50
+ **Deltas:** `text_delta`, `input_json_delta`, `json_patch`, `html_delta`, `status_delta`, `loading_message`. Which block uses which delta is summarized in the table above.
51
+
52
+ ## Usage
53
+
54
+ ```ts
55
+ import {
56
+ createEmptyMessage,
57
+ messageReducer,
58
+ type StreamEvent,
59
+ } from '@fleetx_io/ai-ui-dsl';
60
+
61
+ let message = createEmptyMessage();
62
+
63
+ for await (const event of streamEvents) {
64
+ message = messageReducer(message, event);
65
+ // renderMessage(message);
66
+ }
67
+ ```
68
+
69
+ Synchronous replay:
70
+
71
+ ```ts
72
+ const events: StreamEvent[] = [
73
+ { type: 'message_start', message: { id: 'm1', role: 'assistant' } },
74
+ { type: 'block_start', block: { id: 'b1', type: 'text', content: '' } },
75
+ { type: 'block_delta', blockId: 'b1', delta: { type: 'text_delta', text: 'Hi' } },
76
+ { type: 'block_end', blockId: 'b1' },
77
+ { type: 'message_end', messageId: 'm1' },
78
+ ];
79
+
80
+ for (const event of events) {
81
+ message = messageReducer(message, event);
82
+ }
83
+ ```
84
+
85
+ ### Package exports
86
+
87
+ The package is **ESM-only** (`"type": "module"`): use `import` in Node 20+ or bundlers (e.g. Vite). Plain CommonJS `require()` is not supported.
88
+
89
+ Types: `Block`, block variants, `Message`, `Conversation`, `Delta`, `StreamEvent`, streaming callbacks, etc.
90
+
91
+ Functions: `messageReducer`, `applyDelta`, `createEmptyMessage`, `setByPath`, and `isBlockType`.
92
+
93
+ ## UI Composer Agent (concept)
94
+
95
+ A **UI Composer Agent** is an LLM layer that does **not** call tools: it takes tool results plus context and returns **`{ blocks: Block[] }`** in this DSL. An **orchestrator** then turns those blocks into an SSE stream (`block_start`, deltas, `block_end`) for the client. Composition heuristics (e.g. open with a short text block, use charts or maps instead of raw JSON in prose, end with suggested actions) are up to your server-side prompt and validation schema.
96
+
97
+ ## Playground
98
+
99
+ Requires **Node 20+**. From the repository root:
100
+
101
+ ```bash
102
+ npm install
103
+ npm run build
104
+ npm run playground
105
+ ```
106
+
107
+ Starts a **Vite** dev server that steps through a canned `StreamEvent` script and shows the reduced `Message` state.
108
+
109
+ ## License
110
+
111
+ ISC.
@@ -0,0 +1,134 @@
1
+ export type BlockStatus = 'streaming' | 'completed' | 'error';
2
+ export type BaseBlock = {
3
+ id: string;
4
+ type: string;
5
+ status?: BlockStatus;
6
+ priority?: number;
7
+ createdAt?: number;
8
+ metadata?: Record<string, unknown>;
9
+ };
10
+ export type TextBlock = BaseBlock & {
11
+ type: 'text';
12
+ content: string;
13
+ format?: 'markdown' | 'plain';
14
+ };
15
+ export type ChartLibrary = 'highcharts';
16
+ export type ChartBlock = BaseBlock & {
17
+ type: 'chart';
18
+ library: ChartLibrary;
19
+ config: Record<string, unknown>;
20
+ title?: string;
21
+ };
22
+ export type TableColumn = {
23
+ key: string;
24
+ label: string;
25
+ };
26
+ export type TableBlock = BaseBlock & {
27
+ type: 'table';
28
+ columns: TableColumn[];
29
+ rows: Record<string, unknown>[];
30
+ };
31
+ /**
32
+ * Form block whose `schema` is a standard JSON Schema (draft-07) object.
33
+ * The renderer interprets `properties`, `required`, `type`, `format`, `enum`,
34
+ * and the `x-widget` / `x-options` extensions for domain-specific controls.
35
+ *
36
+ * An optional `uiSchema` (JSON Forms UI Schema) controls layout
37
+ * (VerticalLayout, HorizontalLayout, Group). When omitted the renderer
38
+ * auto-generates a single-column vertical layout from `schema.properties`.
39
+ */
40
+ export type FormBlock = BaseBlock & {
41
+ type: 'form';
42
+ schema: Record<string, unknown>;
43
+ uiSchema?: Record<string, unknown>;
44
+ submitAction: string;
45
+ submitLabel?: string;
46
+ };
47
+ export type ActionItem = {
48
+ id: string;
49
+ label: string;
50
+ payload: string;
51
+ };
52
+ export type ActionBlock = BaseBlock & {
53
+ type: 'action';
54
+ actions: ActionItem[];
55
+ };
56
+ export type WidgetBlock = BaseBlock & {
57
+ type: 'widget';
58
+ html: string;
59
+ sandbox?: boolean;
60
+ };
61
+ export type ToolUseStatus = 'pending' | 'running' | 'completed';
62
+ export type ToolUseBlock = BaseBlock & {
63
+ type: 'tool_use';
64
+ name: string;
65
+ input: unknown;
66
+ toolStatus?: ToolUseStatus;
67
+ };
68
+ export type ToolResultBlock = BaseBlock & {
69
+ type: 'tool_result';
70
+ toolUseId: string;
71
+ result: unknown;
72
+ };
73
+ export type StepItemStatus = 'pending' | 'running' | 'completed';
74
+ export type StepItem = {
75
+ id: string;
76
+ title: string;
77
+ description?: string;
78
+ status: StepItemStatus;
79
+ };
80
+ export type StepBlock = BaseBlock & {
81
+ type: 'step';
82
+ items: StepItem[];
83
+ };
84
+ export type LoadingBlock = BaseBlock & {
85
+ type: 'loading';
86
+ message?: string;
87
+ };
88
+ export type ErrorBlock = BaseBlock & {
89
+ type: 'error';
90
+ message: string;
91
+ retryable?: boolean;
92
+ };
93
+ /** [latitude, longitude] */
94
+ export type LatLng = [number, number];
95
+ export type MapProvider = 'leaflet' | 'google';
96
+ export type MapMarker = {
97
+ id: string;
98
+ position: LatLng;
99
+ label?: string;
100
+ icon?: string;
101
+ metadata?: Record<string, unknown>;
102
+ };
103
+ export type MapPolyline = {
104
+ id: string;
105
+ path: LatLng[];
106
+ color?: string;
107
+ width?: number;
108
+ };
109
+ export type MapPolygon = {
110
+ id: string;
111
+ path: LatLng[];
112
+ color?: string;
113
+ fillOpacity?: number;
114
+ };
115
+ export type MapBlockOptions = {
116
+ clustering?: boolean;
117
+ fitBounds?: boolean;
118
+ };
119
+ export type MapBlock = BaseBlock & {
120
+ type: 'map';
121
+ provider: MapProvider;
122
+ center: LatLng;
123
+ zoom: number;
124
+ markers?: MapMarker[];
125
+ polylines?: MapPolyline[];
126
+ polygons?: MapPolygon[];
127
+ options?: MapBlockOptions;
128
+ };
129
+ export type Block = TextBlock | ChartBlock | TableBlock | FormBlock | ActionBlock | WidgetBlock | ToolUseBlock | ToolResultBlock | StepBlock | LoadingBlock | ErrorBlock | MapBlock;
130
+ export type BlockType = Block['type'];
131
+ export declare function isBlockType<T extends BlockType>(block: Block, type: T): block is Extract<Block, {
132
+ type: T;
133
+ }>;
134
+ //# sourceMappingURL=blocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,OAAO,CAAC;AAI9D,MAAM,MAAM,SAAS,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC,CAAC;AAIF,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;CACjC,CAAC;AAIF,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC;AAExC,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAIF,MAAM,MAAM,WAAW,GAAG;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CA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B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG;IAC/B,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,EAAE,WAAW,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE,eAAe,CAAC;CAC7B,CAAC;AAIF,MAAM,MAAM,KAAK,GACX,SAAS,GACT,UAAU,GACV,UAAU,GACV,SAAS,GACT,WAAW,GACX,WAAW,GACX,YAAY,GACZ,eAAe,GACf,SAAS,GACT,YAAY,GACZ,UAAU,GACV,QAAQ,CAAC;AAIf,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAItC,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAE5G"}
package/dist/blocks.js ADDED
@@ -0,0 +1,6 @@
1
+ // ─── Block Status ────────────────────────────────────────────────────────────
2
+ // ─── Type Guards ─────────────────────────────────────────────────────────────
3
+ export function isBlockType(block, type) {
4
+ return block.type === type;
5
+ }
6
+ //# sourceMappingURL=blocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks.js","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAAA,gFAAgF;AA0MhF,gFAAgF;AAEhF,MAAM,UAAU,WAAW,CAAsB,KAAY,EAAE,IAAO;IAClE,OAAO,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,28 @@
1
+ export type TextDelta = {
2
+ type: 'text_delta';
3
+ text: string;
4
+ };
5
+ export type InputJsonDelta = {
6
+ type: 'input_json_delta';
7
+ partial_json: string;
8
+ };
9
+ export type JsonPatchDelta = {
10
+ type: 'json_patch';
11
+ path: string;
12
+ value: unknown;
13
+ };
14
+ export type HtmlDelta = {
15
+ type: 'html_delta';
16
+ html: string;
17
+ };
18
+ export type StatusDelta = {
19
+ type: 'status_delta';
20
+ status: string;
21
+ };
22
+ export type LoadingMessageDelta = {
23
+ type: 'loading_message';
24
+ message: string;
25
+ };
26
+ export type Delta = TextDelta | InputJsonDelta | JsonPatchDelta | HtmlDelta | StatusDelta | LoadingMessageDelta;
27
+ export type DeltaType = Delta['type'];
28
+ //# sourceMappingURL=deltas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deltas.d.ts","sourceRoot":"","sources":["../src/deltas.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IACzB,IAAI,EAAE,kBAAkB,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACtB,IAAI,EAAE,cAAc,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAC9B,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,SAAS,GAAG,cAAc,GAAG,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,mBAAmB,CAAC;AAEhH,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC"}
package/dist/deltas.js ADDED
@@ -0,0 +1,3 @@
1
+ // ─── Deltas ──────────────────────────────────────────────────────────────────
2
+ export {};
3
+ //# sourceMappingURL=deltas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deltas.js","sourceRoot":"","sources":["../src/deltas.ts"],"names":[],"mappings":"AAAA,gFAAgF"}
@@ -0,0 +1,7 @@
1
+ export type { BaseBlock, BlockStatus, TextBlock, ChartBlock, ChartLibrary, TableBlock, TableColumn, FormBlock, ActionBlock, ActionItem, WidgetBlock, ToolUseBlock, ToolUseStatus, ToolResultBlock, StepBlock, StepItem, StepItemStatus, LoadingBlock, ErrorBlock, MapBlock, LatLng, MapProvider, MapMarker, MapPolyline, MapPolygon, MapBlockOptions, Block, BlockType, } from './blocks.js';
2
+ export { isBlockType } from './blocks.js';
3
+ export type { Message, MessageStatus, MessageRole, Conversation, UserMessageMetadata } from './message.js';
4
+ export type { TextDelta, InputJsonDelta, JsonPatchDelta, HtmlDelta, StatusDelta, LoadingMessageDelta, Delta, DeltaType, } from './deltas.js';
5
+ export type { MessageStartEvent, BlockStartEvent, BlockDeltaEvent, BlockEndEvent, BlockErrorEvent, MessageEndEvent, StreamEvent, StreamEventType, StreamEventCallbacks, } from './streaming.js';
6
+ export { applyDelta, messageReducer, createEmptyMessage, setByPath } from './reducers.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,YAAY,EACR,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,eAAe,EACf,SAAS,EACT,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,MAAM,EACN,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,EACV,eAAe,EACf,KAAK,EACL,SAAS,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAG3G,YAAY,EACR,SAAS,EACT,cAAc,EACd,cAAc,EACd,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,KAAK,EACL,SAAS,GACZ,MAAM,aAAa,CAAC;AAGrB,YAAY,EACR,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,aAAa,EACb,eAAe,EACf,eAAe,EACf,WAAW,EACX,eAAe,EACf,oBAAoB,GACvB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // ─── @fleetx_io/ai-ui-dsl ────────────────────────────────────────────────────
2
+ // FleetX AI UI DSL — Block-based streaming UI protocol
3
+ // ─────────────────────────────────────────────────────────────────────────────
4
+ export { isBlockType } from './blocks.js';
5
+ // Reducers & Helpers
6
+ export { applyDelta, messageReducer, createEmptyMessage, setByPath } from './reducers.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,uDAAuD;AACvD,gFAAgF;AAkChF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA8B1C,qBAAqB;AACrB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { Block } from './blocks.js';
2
+ export type MessageStatus = 'streaming' | 'completed' | 'error';
3
+ export type MessageRole = 'user' | 'assistant' | 'system';
4
+ /**
5
+ * Convention for `Message.metadata` on **user** turns sent to the agent (`POST` body `messages`).
6
+ * Other keys may be added; `type` discriminates the shape.
7
+ */
8
+ export type UserMessageMetadata = {
9
+ type: 'text';
10
+ } | {
11
+ type: 'form_submission';
12
+ /** Same intent as FormBlock.submitAction (e.g. `report-generator`). */
13
+ formId: string;
14
+ data: Record<string, unknown>;
15
+ /** Assistant message id that contained the submitted form. */
16
+ sourceMessageId?: string;
17
+ };
18
+ export type Message = {
19
+ id: string;
20
+ role: MessageRole;
21
+ blocks: Block[];
22
+ status: MessageStatus;
23
+ createdAt: number;
24
+ metadata?: Record<string, unknown>;
25
+ };
26
+ export type Conversation = {
27
+ id: string;
28
+ title?: string;
29
+ messages: Message[];
30
+ createdAt: number;
31
+ updatedAt: number;
32
+ /** Sidebar section label, e.g. "Today" */
33
+ group?: string;
34
+ metadata?: Record<string, unknown>;
35
+ };
36
+ //# sourceMappingURL=message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAIzC,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,WAAW,GAAG,OAAO,CAAC;AAEhE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GACzB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,8DAA8D;IAC9D,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAIN,MAAM,MAAM,OAAO,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC,CAAC;AAIF,MAAM,MAAM,YAAY,GAAG;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ import type { Block } from './blocks.js';
2
+ import type { Delta } from './deltas.js';
3
+ import type { Message } from './message.js';
4
+ import type { StreamEvent } from './streaming.js';
5
+ /**
6
+ * Set a value at a dot-notation path on an object, supporting bracket syntax
7
+ * for array indices (e.g. "items[0].status", "config.series[0].data").
8
+ *
9
+ * Mutates `target` in place and returns it for convenience.
10
+ */
11
+ export declare function setByPath(target: Record<string, unknown>, path: string, value: unknown): Record<string, unknown>;
12
+ /**
13
+ * Apply a single Delta to a Block, returning a **new** block (immutable).
14
+ */
15
+ export declare function applyDelta(block: Block, delta: Delta): Block;
16
+ /**
17
+ * Pure reducer: given the current Message state and a StreamEvent,
18
+ * returns the next Message state.
19
+ *
20
+ * This is the core state machine for processing a streaming response.
21
+ */
22
+ export declare function messageReducer(state: Message, event: StreamEvent): Message;
23
+ /**
24
+ * Create an empty Message suitable as the initial state for `messageReducer`.
25
+ */
26
+ export declare function createEmptyMessage(id?: string): Message;
27
+ //# sourceMappingURL=reducers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducers.d.ts","sourceRoot":"","sources":["../src/reducers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAsD,MAAM,aAAa,CAAC;AAC7F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAmB,MAAM,gBAAgB,CAAC;AAInE;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAehH;AAqBD;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAwC5D;AAID;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAqC1E;AAWD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAQvD"}
@@ -0,0 +1,136 @@
1
+ // ─── JSON Path Helpers ───────────────────────────────────────────────────────
2
+ /**
3
+ * Set a value at a dot-notation path on an object, supporting bracket syntax
4
+ * for array indices (e.g. "items[0].status", "config.series[0].data").
5
+ *
6
+ * Mutates `target` in place and returns it for convenience.
7
+ */
8
+ export function setByPath(target, path, value) {
9
+ const segments = parsePath(path);
10
+ let current = target;
11
+ for (let i = 0; i < segments.length - 1; i++) {
12
+ const seg = segments[i];
13
+ if (current[seg] === undefined || current[seg] === null) {
14
+ const nextSeg = segments[i + 1];
15
+ current[seg] = typeof nextSeg === 'number' ? [] : {};
16
+ }
17
+ current = current[seg];
18
+ }
19
+ current[segments[segments.length - 1]] = value;
20
+ return target;
21
+ }
22
+ function parsePath(path) {
23
+ const segments = [];
24
+ const parts = path.split('.');
25
+ for (const part of parts) {
26
+ const bracketMatch = part.match(/^([^\[]*)\[(\d+)\]$/);
27
+ if (bracketMatch) {
28
+ if (bracketMatch[1])
29
+ segments.push(bracketMatch[1]);
30
+ segments.push(Number(bracketMatch[2]));
31
+ }
32
+ else {
33
+ segments.push(part);
34
+ }
35
+ }
36
+ return segments;
37
+ }
38
+ // ─── Delta Reducers ──────────────────────────────────────────────────────────
39
+ /**
40
+ * Apply a single Delta to a Block, returning a **new** block (immutable).
41
+ */
42
+ export function applyDelta(block, delta) {
43
+ switch (delta.type) {
44
+ case 'text_delta': {
45
+ const b = block;
46
+ return { ...b, content: (b.content ?? '') + delta.text };
47
+ }
48
+ case 'input_json_delta': {
49
+ const b = block;
50
+ const buffer = (b._inputBuffer ?? '') + delta.partial_json;
51
+ try {
52
+ return { ...b, input: JSON.parse(buffer), _inputBuffer: buffer };
53
+ }
54
+ catch {
55
+ return { ...b, _inputBuffer: buffer };
56
+ }
57
+ }
58
+ case 'json_patch': {
59
+ const clone = structuredClone(block);
60
+ setByPath(clone, delta.path, delta.value);
61
+ return clone;
62
+ }
63
+ case 'html_delta': {
64
+ const b = block;
65
+ return { ...b, html: (b.html ?? '') + delta.html };
66
+ }
67
+ case 'status_delta': {
68
+ return { ...block, status: delta.status };
69
+ }
70
+ case 'loading_message': {
71
+ const b = block;
72
+ return { ...b, message: delta.message };
73
+ }
74
+ default:
75
+ return block;
76
+ }
77
+ }
78
+ // ─── Message Reducer ─────────────────────────────────────────────────────────
79
+ /**
80
+ * Pure reducer: given the current Message state and a StreamEvent,
81
+ * returns the next Message state.
82
+ *
83
+ * This is the core state machine for processing a streaming response.
84
+ */
85
+ export function messageReducer(state, event) {
86
+ switch (event.type) {
87
+ case 'message_start':
88
+ return {
89
+ ...state,
90
+ id: event.message.id,
91
+ role: event.message.role,
92
+ status: 'streaming',
93
+ };
94
+ case 'block_start':
95
+ return {
96
+ ...state,
97
+ blocks: [...state.blocks, { ...event.block, status: 'streaming' }],
98
+ };
99
+ case 'block_delta':
100
+ return applyBlockDelta(state, event);
101
+ case 'block_end':
102
+ return {
103
+ ...state,
104
+ blocks: state.blocks.map((b) => (b.id === event.blockId ? { ...b, status: 'completed' } : b)),
105
+ };
106
+ case 'block_error':
107
+ return {
108
+ ...state,
109
+ blocks: state.blocks.map((b) => (b.id === event.blockId ? { ...b, status: 'error' } : b)),
110
+ };
111
+ case 'message_end':
112
+ return { ...state, status: 'completed' };
113
+ default:
114
+ return state;
115
+ }
116
+ }
117
+ function applyBlockDelta(state, event) {
118
+ return {
119
+ ...state,
120
+ blocks: state.blocks.map((b) => (b.id === event.blockId ? applyDelta(b, event.delta) : b)),
121
+ };
122
+ }
123
+ // ─── Factory ─────────────────────────────────────────────────────────────────
124
+ /**
125
+ * Create an empty Message suitable as the initial state for `messageReducer`.
126
+ */
127
+ export function createEmptyMessage(id) {
128
+ return {
129
+ id: id ?? '',
130
+ role: 'assistant',
131
+ blocks: [],
132
+ status: 'streaming',
133
+ createdAt: Date.now(),
134
+ };
135
+ }
136
+ //# sourceMappingURL=reducers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducers.js","sourceRoot":"","sources":["../src/reducers.ts"],"names":[],"mappings":"AAKA,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,MAA+B,EAAE,IAAY,EAAE,KAAc;IACnF,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,OAAO,GAAQ,MA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;gBACH,GAAG,KAAK;gBACR,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,OAAgB,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACrG,CAAC;QAEN,KAAK,aAAa;YACd,OAAO,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;QAE7C;YACI,OAAO,KAAK,CAAC;IACrB,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CAAC,KAAc,EAAE,KAAsB;IAC3D,OAAO;QACH,GAAG,KAAK;QACR,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7F,CAAC;AACN,CAAC;AAED,gFAAgF;AAEhF;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,EAAW;IAC1C,OAAO;QACH,EAAE,EAAE,EAAE,IAAI,EAAE;QACZ,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACxB,CAAC;AACN,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { BaseBlock } from './blocks.js';
2
+ import type { Delta } from './deltas.js';
3
+ export type MessageStartEvent = {
4
+ type: 'message_start';
5
+ message: {
6
+ id: string;
7
+ role: string;
8
+ };
9
+ };
10
+ export type BlockStartEvent = {
11
+ type: 'block_start';
12
+ block: BaseBlock & Record<string, unknown>;
13
+ };
14
+ export type BlockDeltaEvent = {
15
+ type: 'block_delta';
16
+ blockId: string;
17
+ delta: Delta;
18
+ };
19
+ export type BlockEndEvent = {
20
+ type: 'block_end';
21
+ blockId: string;
22
+ };
23
+ export type BlockErrorEvent = {
24
+ type: 'block_error';
25
+ blockId: string;
26
+ error: string;
27
+ };
28
+ export type MessageEndEvent = {
29
+ type: 'message_end';
30
+ messageId: string;
31
+ };
32
+ export type StreamEvent = MessageStartEvent | BlockStartEvent | BlockDeltaEvent | BlockEndEvent | BlockErrorEvent | MessageEndEvent;
33
+ export type StreamEventType = StreamEvent['type'];
34
+ export interface StreamEventCallbacks {
35
+ onMessageStart?: (event: MessageStartEvent) => void;
36
+ onBlockStart?: (event: BlockStartEvent) => void;
37
+ onBlockDelta?: (event: BlockDeltaEvent) => void;
38
+ onBlockEnd?: (event: BlockEndEvent) => void;
39
+ onBlockError?: (event: BlockErrorEvent) => void;
40
+ onMessageEnd?: (event: MessageEndEvent) => void;
41
+ }
42
+ //# sourceMappingURL=streaming.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAIzC,MAAM,MAAM,iBAAiB,GAAG;IAC5B,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,WAAW,GACjB,iBAAiB,GACjB,eAAe,GACf,eAAe,GACf,aAAa,GACb,eAAe,GACf,eAAe,CAAC;AAEtB,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AAIlD,MAAM,WAAW,oBAAoB;IACjC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACpD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAChD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAChD,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC5C,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAChD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;CACnD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=streaming.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@fleetx_io/ai-ui-dsl",
3
+ "version": "1.0.0",
4
+ "description": "A Domain Specific Language for describing rich, streaming AI chat interfaces via composable Blocks.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "sideEffects": false,
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "playground": "npm run dev -w playground",
19
+ "playground:build": "npm run build -w playground",
20
+ "publish": "npm run build && npm publish --access public",
21
+ "test": "echo \"Error: no test specified\" && exit 1"
22
+ },
23
+ "workspaces": [
24
+ "playground"
25
+ ],
26
+ "engines": {
27
+ "node": ">=20.0.0"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "package.json",
32
+ "README.md",
33
+ "LICENSE",
34
+ "CHANGELOG.md"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "keywords": [
40
+ "UI",
41
+ "AI",
42
+ "Chat",
43
+ "Interfaces",
44
+ "DSL",
45
+ "streaming",
46
+ "AI chat interfaces",
47
+ "composable blocks",
48
+ "fleetx"
49
+ ],
50
+ "author": "Satish Kumar <satish@fleetx.io>",
51
+ "license": "ISC",
52
+ "devDependencies": {
53
+ "@types/node": "^25.3.3",
54
+ "typescript": "^5.9.3",
55
+ "prettier": "2.0.5"
56
+ }
57
+ }