@absolutejs/ai 0.0.30 → 0.0.32
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/ai/index.js +483 -6
- package/dist/ai/index.js.map +6 -3
- package/dist/src/ai/index.d.ts +1 -0
- package/dist/src/ai/ui/catalog.d.ts +55 -0
- package/dist/src/ai/ui/index.d.ts +13 -0
- package/dist/src/ai/ui/svg.d.ts +33 -0
- package/dist/src/ai/ui/uiCards.d.ts +46 -0
- package/package.json +8 -1
package/dist/src/ai/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { streamAI } from "./streamAI";
|
|
|
3
3
|
export { streamAIToSSE } from "./streamAIToSSE";
|
|
4
4
|
export { streamAIWithTools } from "./streamAIWithTools";
|
|
5
5
|
export type { StreamAIWithToolsEvent, StreamAIWithToolsOptions, StreamAIWithToolsSummary, } from "./streamAIWithTools";
|
|
6
|
+
export * from "./ui";
|
|
6
7
|
export { generateAI, generateAIWithTools, generateObjectAI, } from "./generateAI";
|
|
7
8
|
export type { GenerateAIOptions, GenerateAIResult, GenerateAIToolCall, GenerateAIWithToolsOptions, GenerateAIWithToolsResult, GenerateObjectAIOptions, GenerateObjectAIResult, } from "./generateAI";
|
|
8
9
|
export { createConversationManager } from "./conversationManager";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { UiCardDefinition } from "./uiCards";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in UI card catalog: chart, table, stat tiles. Declarative specs the
|
|
4
|
+
* model authors and the host renders — see svg.ts for the dependency-free
|
|
5
|
+
* default renderer. Caps are hard product guards (a model can't render a
|
|
6
|
+
* 400-row table into a chat bubble).
|
|
7
|
+
*/
|
|
8
|
+
export declare const CHART_TYPES: readonly ["bar", "line", "donut"];
|
|
9
|
+
export type ChartType = (typeof CHART_TYPES)[number];
|
|
10
|
+
export type ChartSeries = {
|
|
11
|
+
name: string;
|
|
12
|
+
values: number[];
|
|
13
|
+
};
|
|
14
|
+
export type ChartSpec = {
|
|
15
|
+
type: ChartType;
|
|
16
|
+
title: string;
|
|
17
|
+
/** Category labels: x-axis (bar/line) or slice names (donut). */
|
|
18
|
+
labels: string[];
|
|
19
|
+
/** ≤ 8 series (fixed hue order). Donut charts use exactly one series. */
|
|
20
|
+
series: ChartSeries[];
|
|
21
|
+
/** Value formatting, e.g. "$" / "%". */
|
|
22
|
+
unitPrefix?: string;
|
|
23
|
+
unitSuffix?: string;
|
|
24
|
+
};
|
|
25
|
+
export type TableSpec = {
|
|
26
|
+
title?: string;
|
|
27
|
+
columns: string[];
|
|
28
|
+
rows: string[][];
|
|
29
|
+
};
|
|
30
|
+
export type StatTile = {
|
|
31
|
+
label: string;
|
|
32
|
+
value: string;
|
|
33
|
+
/** Optional change annotation, e.g. "+12% vs last month". */
|
|
34
|
+
delta?: string;
|
|
35
|
+
deltaDirection?: "up" | "down" | "flat";
|
|
36
|
+
};
|
|
37
|
+
export type StatTilesSpec = {
|
|
38
|
+
tiles: StatTile[];
|
|
39
|
+
};
|
|
40
|
+
export declare const CHART_MAX_SERIES = 8;
|
|
41
|
+
export declare const CHART_MAX_POINTS = 24;
|
|
42
|
+
export declare const TABLE_MAX_COLUMNS = 8;
|
|
43
|
+
export declare const TABLE_MAX_ROWS = 30;
|
|
44
|
+
export declare const STAT_TILES_MAX = 6;
|
|
45
|
+
export declare const parseChartSpec: (input: unknown) => ChartSpec | null;
|
|
46
|
+
export declare const parseTableSpec: (input: unknown) => TableSpec | null;
|
|
47
|
+
export declare const parseStatTilesSpec: (input: unknown) => StatTilesSpec | null;
|
|
48
|
+
/** render_chart — bar / line / donut from data you already have. */
|
|
49
|
+
export declare const chartCard: UiCardDefinition<ChartSpec>;
|
|
50
|
+
/** render_table — a compact data table. */
|
|
51
|
+
export declare const tableCard: UiCardDefinition<TableSpec>;
|
|
52
|
+
/** render_stat_tiles — a row of headline numbers. */
|
|
53
|
+
export declare const statTilesCard: UiCardDefinition<StatTilesSpec>;
|
|
54
|
+
/** The built-in catalog, ready for createUiCards. */
|
|
55
|
+
export declare const BUILTIN_UI_CARDS: readonly [UiCardDefinition<ChartSpec>, UiCardDefinition<TableSpec>, UiCardDefinition<StatTilesSpec>];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@absolutejs/ai` UI cards — generative UI for agent chats.
|
|
3
|
+
*
|
|
4
|
+
* A UI card is a schema-only tool: the model calls it with a structured spec,
|
|
5
|
+
* the loop feeds back a steering ack, and the HOST renders the validated spec
|
|
6
|
+
* with real components. {@link createUiCards} builds the tool map + collector
|
|
7
|
+
* for any card set; {@link BUILTIN_UI_CARDS} ships chart / table / stat-tile
|
|
8
|
+
* cards with hard caps, and {@link renderChartSvg} is a dependency-free
|
|
9
|
+
* default chart renderer (pure string — server or client, light/dark).
|
|
10
|
+
*/
|
|
11
|
+
export { createUiCards, type UiCardDefinition, type UiCardEvent, type UiCards, } from "./uiCards";
|
|
12
|
+
export { BUILTIN_UI_CARDS, chartCard, CHART_MAX_POINTS, CHART_MAX_SERIES, CHART_TYPES, parseChartSpec, parseStatTilesSpec, parseTableSpec, STAT_TILES_MAX, statTilesCard, TABLE_MAX_COLUMNS, TABLE_MAX_ROWS, tableCard, type ChartSeries, type ChartSpec, type ChartType, type StatTile, type StatTilesSpec, type TableSpec, } from "./catalog";
|
|
13
|
+
export { DARK_UI_THEME, LIGHT_UI_THEME, renderChartSvg, type RenderChartSvgOptions, type UiSvgTheme, } from "./svg";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ChartSpec } from "./catalog";
|
|
2
|
+
/**
|
|
3
|
+
* Dependency-free default chart renderer: a validated ChartSpec in, a
|
|
4
|
+
* self-contained SVG string out. Pure — no DOM — so it runs server-side or in
|
|
5
|
+
* any framework component (call it client-side with the viewer's mode so dark
|
|
6
|
+
* themes get the dark-stepped palette, not an automatic flip).
|
|
7
|
+
*
|
|
8
|
+
* Design method: thin marks with rounded data-ends, 2px surface gaps between
|
|
9
|
+
* adjacent fills, recessive horizontal grid, a legend for ≥2 series plus
|
|
10
|
+
* direct labels, all text in text tokens (never series colors), native <title>
|
|
11
|
+
* hover tooltips per mark. The default palette is the validated reference set
|
|
12
|
+
* (worst adjacent CVD ΔE 24.2 light / 10.3 dark) — override `palette` with
|
|
13
|
+
* your brand's VALIDATED hues, in their fixed slot order.
|
|
14
|
+
*/
|
|
15
|
+
export type UiSvgTheme = {
|
|
16
|
+
/** Categorical hues in fixed slot order (series 1..n). */
|
|
17
|
+
palette: string[];
|
|
18
|
+
surface: string;
|
|
19
|
+
textPrimary: string;
|
|
20
|
+
textSecondary: string;
|
|
21
|
+
grid: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const LIGHT_UI_THEME: UiSvgTheme;
|
|
24
|
+
export declare const DARK_UI_THEME: UiSvgTheme;
|
|
25
|
+
export type RenderChartSvgOptions = {
|
|
26
|
+
mode?: "light" | "dark";
|
|
27
|
+
/** Override any theme slot (e.g. your brand palette / chat-bubble surface). */
|
|
28
|
+
theme?: Partial<UiSvgTheme>;
|
|
29
|
+
width?: number;
|
|
30
|
+
height?: number;
|
|
31
|
+
};
|
|
32
|
+
/** Render a validated ChartSpec to a self-contained SVG string. */
|
|
33
|
+
export declare const renderChartSvg: (spec: ChartSpec, options?: RenderChartSvgOptions) => string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AIToolMap } from "../../../types/ai";
|
|
2
|
+
/**
|
|
3
|
+
* UI cards — the generative-UI primitive extracted from onSpark's chat.
|
|
4
|
+
*
|
|
5
|
+
* A "card" is a schema-only tool: the model calls it with a structured payload,
|
|
6
|
+
* the handler only ACKNOWLEDGES (steering the model's continuation), and the
|
|
7
|
+
* host watches the executed tool calls to render the payload as a real,
|
|
8
|
+
* host-styled component (a chart, a table, an approval card, a deep link…).
|
|
9
|
+
* No model-written code ever executes: the payload is validated by the card's
|
|
10
|
+
* `parse` before anything renders, so a malformed call simply drops.
|
|
11
|
+
*/
|
|
12
|
+
export type UiCardDefinition<T = unknown> = {
|
|
13
|
+
/** Tool name the model calls, e.g. "render_chart". */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Tool description — steer WHEN the model should render this card. */
|
|
16
|
+
description: string;
|
|
17
|
+
/** JSON schema for the tool input. */
|
|
18
|
+
inputSchema: Record<string, unknown>;
|
|
19
|
+
/** Tool-result text fed back to the model (e.g. "(chart rendered — don't
|
|
20
|
+
* repeat its numbers in text)"). */
|
|
21
|
+
ack: string;
|
|
22
|
+
/** Validate + narrow the raw model input to the card payload. Return null
|
|
23
|
+
* to reject the call (the card is dropped, the ack still steered). */
|
|
24
|
+
parse: (input: unknown) => T | null;
|
|
25
|
+
};
|
|
26
|
+
export type UiCardEvent = {
|
|
27
|
+
/** The card's tool name. */
|
|
28
|
+
card: string;
|
|
29
|
+
/** The parsed, validated payload. */
|
|
30
|
+
data: unknown;
|
|
31
|
+
};
|
|
32
|
+
export type UiCards = {
|
|
33
|
+
/** AIToolMap entries (ack handlers) — spread into the tools you hand to
|
|
34
|
+
* streamAIWithTools / generateAIWithTools. */
|
|
35
|
+
tools: AIToolMap;
|
|
36
|
+
/** Pull validated card events out of a turn's tool calls, in call order.
|
|
37
|
+
* Invalid payloads and non-card tools are skipped. */
|
|
38
|
+
collect: (calls: readonly {
|
|
39
|
+
name: string;
|
|
40
|
+
input: unknown;
|
|
41
|
+
}[]) => UiCardEvent[];
|
|
42
|
+
/** Is this tool name one of the registered cards? */
|
|
43
|
+
has: (name: string) => boolean;
|
|
44
|
+
};
|
|
45
|
+
/** Build the tool map + collector for a set of UI cards. */
|
|
46
|
+
export declare const createUiCards: (definitions: readonly UiCardDefinition[]) => UiCards;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absolutejs/ai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"homepage": "https://github.com/absolutejs/ai",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/absolutejs/ai/issues"
|
|
@@ -70,6 +70,10 @@
|
|
|
70
70
|
"./tools": {
|
|
71
71
|
"import": "./dist/ai/tools/index.js",
|
|
72
72
|
"types": "./dist/src/ai/tools/index.d.ts"
|
|
73
|
+
},
|
|
74
|
+
"./ui": {
|
|
75
|
+
"import": "./dist/ai/ui/index.js",
|
|
76
|
+
"types": "./dist/src/ai/ui/index.d.ts"
|
|
73
77
|
}
|
|
74
78
|
},
|
|
75
79
|
"dependencies": {
|
|
@@ -136,6 +140,9 @@
|
|
|
136
140
|
"client": [
|
|
137
141
|
"dist/src/ai/client/index.d.ts"
|
|
138
142
|
],
|
|
143
|
+
"ui": [
|
|
144
|
+
"dist/src/ai/ui/index.d.ts"
|
|
145
|
+
],
|
|
139
146
|
"react": [
|
|
140
147
|
"dist/src/react/ai/index.d.ts"
|
|
141
148
|
],
|