@aganzefelicite/responsekit-react 0.2.0 → 0.3.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.cjs CHANGED
@@ -1,663 +1,367 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkD4WIPDH3_cjs = require('./chunk-D4WIPDH3.cjs');
4
+ var react = require('react');
4
5
  var ReactMarkdown = require('react-markdown');
5
6
  var remarkGfm = require('remark-gfm');
6
7
  var jsxRuntime = require('react/jsx-runtime');
7
- var react = require('react');
8
8
 
9
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
10
 
11
11
  var ReactMarkdown__default = /*#__PURE__*/_interopDefault(ReactMarkdown);
12
12
  var remarkGfm__default = /*#__PURE__*/_interopDefault(remarkGfm);
13
13
 
14
- // src/actions.ts
15
- var noopAction = () => {
16
- };
17
- function Markdown({ children, className }) {
18
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className ?? "rk-markdown", children: /* @__PURE__ */ jsxRuntime.jsx(
19
- ReactMarkdown__default.default,
20
- {
21
- remarkPlugins: [remarkGfm__default.default],
22
- components: {
23
- a: ({ node: _node, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("a", { ...props, target: "_blank", rel: "noopener noreferrer" })
24
- },
25
- children
14
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
15
+ var external_exports = {};
16
+ chunkD4WIPDH3_cjs.__export(external_exports, {
17
+ BRAND: () => BRAND,
18
+ DIRTY: () => DIRTY,
19
+ EMPTY_PATH: () => EMPTY_PATH,
20
+ INVALID: () => INVALID,
21
+ NEVER: () => NEVER,
22
+ OK: () => OK,
23
+ ParseStatus: () => ParseStatus,
24
+ Schema: () => ZodType,
25
+ ZodAny: () => ZodAny,
26
+ ZodArray: () => ZodArray,
27
+ ZodBigInt: () => ZodBigInt,
28
+ ZodBoolean: () => ZodBoolean,
29
+ ZodBranded: () => ZodBranded,
30
+ ZodCatch: () => ZodCatch,
31
+ ZodDate: () => ZodDate,
32
+ ZodDefault: () => ZodDefault,
33
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
34
+ ZodEffects: () => ZodEffects,
35
+ ZodEnum: () => ZodEnum,
36
+ ZodError: () => ZodError,
37
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
38
+ ZodFunction: () => ZodFunction,
39
+ ZodIntersection: () => ZodIntersection,
40
+ ZodIssueCode: () => ZodIssueCode,
41
+ ZodLazy: () => ZodLazy,
42
+ ZodLiteral: () => ZodLiteral,
43
+ ZodMap: () => ZodMap,
44
+ ZodNaN: () => ZodNaN,
45
+ ZodNativeEnum: () => ZodNativeEnum,
46
+ ZodNever: () => ZodNever,
47
+ ZodNull: () => ZodNull,
48
+ ZodNullable: () => ZodNullable,
49
+ ZodNumber: () => ZodNumber,
50
+ ZodObject: () => ZodObject,
51
+ ZodOptional: () => ZodOptional,
52
+ ZodParsedType: () => ZodParsedType,
53
+ ZodPipeline: () => ZodPipeline,
54
+ ZodPromise: () => ZodPromise,
55
+ ZodReadonly: () => ZodReadonly,
56
+ ZodRecord: () => ZodRecord,
57
+ ZodSchema: () => ZodType,
58
+ ZodSet: () => ZodSet,
59
+ ZodString: () => ZodString,
60
+ ZodSymbol: () => ZodSymbol,
61
+ ZodTransformer: () => ZodEffects,
62
+ ZodTuple: () => ZodTuple,
63
+ ZodType: () => ZodType,
64
+ ZodUndefined: () => ZodUndefined,
65
+ ZodUnion: () => ZodUnion,
66
+ ZodUnknown: () => ZodUnknown,
67
+ ZodVoid: () => ZodVoid,
68
+ addIssueToContext: () => addIssueToContext,
69
+ any: () => anyType,
70
+ array: () => arrayType,
71
+ bigint: () => bigIntType,
72
+ boolean: () => booleanType,
73
+ coerce: () => coerce,
74
+ custom: () => custom,
75
+ date: () => dateType,
76
+ datetimeRegex: () => datetimeRegex,
77
+ defaultErrorMap: () => en_default,
78
+ discriminatedUnion: () => discriminatedUnionType,
79
+ effect: () => effectsType,
80
+ enum: () => enumType,
81
+ function: () => functionType,
82
+ getErrorMap: () => getErrorMap,
83
+ getParsedType: () => getParsedType,
84
+ instanceof: () => instanceOfType,
85
+ intersection: () => intersectionType,
86
+ isAborted: () => isAborted,
87
+ isAsync: () => isAsync,
88
+ isDirty: () => isDirty,
89
+ isValid: () => isValid,
90
+ late: () => late,
91
+ lazy: () => lazyType,
92
+ literal: () => literalType,
93
+ makeIssue: () => makeIssue,
94
+ map: () => mapType,
95
+ nan: () => nanType,
96
+ nativeEnum: () => nativeEnumType,
97
+ never: () => neverType,
98
+ null: () => nullType,
99
+ nullable: () => nullableType,
100
+ number: () => numberType,
101
+ object: () => objectType,
102
+ objectUtil: () => objectUtil,
103
+ oboolean: () => oboolean,
104
+ onumber: () => onumber,
105
+ optional: () => optionalType,
106
+ ostring: () => ostring,
107
+ pipeline: () => pipelineType,
108
+ preprocess: () => preprocessType,
109
+ promise: () => promiseType,
110
+ quotelessJson: () => quotelessJson,
111
+ record: () => recordType,
112
+ set: () => setType,
113
+ setErrorMap: () => setErrorMap,
114
+ strictObject: () => strictObjectType,
115
+ string: () => stringType,
116
+ symbol: () => symbolType,
117
+ transformer: () => effectsType,
118
+ tuple: () => tupleType,
119
+ undefined: () => undefinedType,
120
+ union: () => unionType,
121
+ unknown: () => unknownType,
122
+ util: () => util,
123
+ void: () => voidType
124
+ });
125
+
126
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
127
+ var util;
128
+ (function(util2) {
129
+ util2.assertEqual = (_) => {
130
+ };
131
+ function assertIs(_arg) {
132
+ }
133
+ util2.assertIs = assertIs;
134
+ function assertNever(_x) {
135
+ throw new Error();
136
+ }
137
+ util2.assertNever = assertNever;
138
+ util2.arrayToEnum = (items) => {
139
+ const obj = {};
140
+ for (const item of items) {
141
+ obj[item] = item;
26
142
  }
27
- ) });
28
- }
29
- function TextBlock({ block }) {
30
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-block rk-block-text", children: /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: block.content }) });
31
- }
32
- var TREND_GLYPH = { UP: "\u25B2", DOWN: "\u25BC", STABLE: "\u2192" };
33
- function KpiBlock({ block }) {
34
- const items = Array.isArray(block.items) ? block.items : [];
35
- return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "rk-block rk-block-kpi", "aria-label": block.title ?? "KPIs", children: [
36
- block.title ? /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "rk-block-title", children: block.title }) : null,
37
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-kpi-grid", children: items.map((item, i) => {
38
- const display = item.formattedValue ?? chunkD4WIPDH3_cjs.formatValue(item.value);
39
- const trend = item.trend;
40
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-kpi-item", children: [
41
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-kpi-label", children: item.label }),
42
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-kpi-value", children: display }),
43
- trend || typeof item.percentageChange === "number" ? /* @__PURE__ */ jsxRuntime.jsxs(
44
- "div",
45
- {
46
- className: `rk-kpi-trend rk-kpi-trend-${(trend ?? "STABLE").toLowerCase()}`,
47
- children: [
48
- trend ? /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": true, children: TREND_GLYPH[trend] }) : null,
49
- typeof item.percentageChange === "number" ? /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
50
- item.percentageChange > 0 ? "+" : "",
51
- item.percentageChange,
52
- "%"
53
- ] }) : null
54
- ]
55
- }
56
- ) : null
57
- ] }, `${item.label}-${i}`);
58
- }) })
59
- ] });
60
- }
61
- var ChartRenderer = react.lazy(() => import('./ChartRenderer-UJNU2VNH.cjs'));
62
- function ChartBlock({ block }) {
63
- return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "rk-block rk-block-chart", children: [
64
- block.title ? /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "rk-block-title", children: block.title }) : null,
65
- /* @__PURE__ */ jsxRuntime.jsx(
66
- react.Suspense,
67
- {
68
- fallback: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-chart-placeholder", "aria-busy": "true", children: "Loading chart\u2026" }),
69
- children: /* @__PURE__ */ jsxRuntime.jsx(ChartRenderer, { block })
143
+ return obj;
144
+ };
145
+ util2.getValidEnumValues = (obj) => {
146
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
147
+ const filtered = {};
148
+ for (const k of validKeys) {
149
+ filtered[k] = obj[k];
150
+ }
151
+ return util2.objectValues(filtered);
152
+ };
153
+ util2.objectValues = (obj) => {
154
+ return util2.objectKeys(obj).map(function(e) {
155
+ return obj[e];
156
+ });
157
+ };
158
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
159
+ const keys = [];
160
+ for (const key in object) {
161
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
162
+ keys.push(key);
70
163
  }
71
- )
72
- ] });
73
- }
74
- function TableBlock({ block, onAction }) {
75
- const columns = Array.isArray(block.columns) ? block.columns : [];
76
- const rows = Array.isArray(block.rows) ? block.rows : [];
77
- const download = () => onAction({
78
- type: "DOWNLOAD",
79
- format: "CSV",
80
- filename: `${block.title ?? "table"}.csv`,
81
- data: chunkD4WIPDH3_cjs.rowsToCsv(columns, rows),
82
- blockId: block.id
83
- });
84
- return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "rk-block rk-block-table", children: [
85
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-block-header", children: [
86
- block.title ? /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "rk-block-title", children: block.title }) : null,
87
- rows.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "rk-action", onClick: download, children: "Download CSV" }) : null
88
- ] }),
89
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-table-scroll", children: [
90
- /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "rk-table", children: [
91
- /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: col.label }, col.key)) }) }),
92
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: rows.map((row, r) => /* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx("td", { children: chunkD4WIPDH3_cjs.formatValue(row[col.key]) }, col.key)) }, r)) })
93
- ] }),
94
- rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "rk-empty", children: "No data." }) : null
95
- ] })
96
- ] });
97
- }
98
- var SEVERITY_GLYPH = {
99
- INFO: "\u2139",
100
- SUCCESS: "\u2713",
101
- WARNING: "\u26A0",
102
- CRITICAL: "\u2715"
103
- };
104
- function InsightBlock({ block }) {
105
- const severity = ["INFO", "SUCCESS", "WARNING", "CRITICAL"].includes(
106
- block.severity
107
- ) ? block.severity : "INFO";
108
- return /* @__PURE__ */ jsxRuntime.jsxs(
109
- "aside",
110
- {
111
- className: `rk-block rk-block-insight rk-severity-${severity.toLowerCase()}`,
112
- role: "note",
113
- children: [
114
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-insight-icon", "aria-hidden": true, children: SEVERITY_GLYPH[severity] }),
115
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-insight-body", children: [
116
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-insight-title", children: block.title }),
117
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-insight-desc", children: block.description })
118
- ] })
119
- ]
120
164
  }
121
- );
122
- }
123
- function RecommendationBlock({
124
- block
125
- }) {
126
- const items = Array.isArray(block.items) ? block.items : [];
127
- return /* @__PURE__ */ jsxRuntime.jsx("section", { className: "rk-block rk-block-recommendation", children: /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "rk-recommendation-list", children: items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "rk-recommendation-item", children: [
128
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-recommendation-title", children: item.title }),
129
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-recommendation-desc", children: item.description })
130
- ] }, `${item.title}-${i}`)) }) });
131
- }
132
- function FilterControl({ filter }) {
133
- const options = Array.isArray(filter.options) ? filter.options : [];
134
- switch (filter.filterType) {
135
- case "SELECT":
136
- case "MULTI_SELECT":
137
- return /* @__PURE__ */ jsxRuntime.jsx("select", { disabled: true, multiple: filter.filterType === "MULTI_SELECT", "aria-label": filter.label, children: options.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o, children: o }, o)) });
138
- case "DATE_RANGE":
139
- return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "rk-filter-range", children: [
140
- /* @__PURE__ */ jsxRuntime.jsx("input", { type: "date", disabled: true, "aria-label": `${filter.label} from` }),
141
- /* @__PURE__ */ jsxRuntime.jsx("input", { type: "date", disabled: true, "aria-label": `${filter.label} to` })
142
- ] });
143
- case "NUMBER_RANGE":
144
- return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "rk-filter-range", children: [
145
- /* @__PURE__ */ jsxRuntime.jsx("input", { type: "number", disabled: true, "aria-label": `${filter.label} min`, placeholder: "min" }),
146
- /* @__PURE__ */ jsxRuntime.jsx("input", { type: "number", disabled: true, "aria-label": `${filter.label} max`, placeholder: "max" })
147
- ] });
148
- case "SEARCH":
149
- default:
150
- return /* @__PURE__ */ jsxRuntime.jsx("input", { type: "search", disabled: true, "aria-label": filter.label, placeholder: "Search\u2026" });
165
+ return keys;
166
+ };
167
+ util2.find = (arr, checker) => {
168
+ for (const item of arr) {
169
+ if (checker(item))
170
+ return item;
171
+ }
172
+ return void 0;
173
+ };
174
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
175
+ function joinValues(array, separator = " | ") {
176
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
151
177
  }
152
- }
153
- function FilterBlock({ block }) {
154
- const filters = Array.isArray(block.filters) ? block.filters : [];
155
- return /* @__PURE__ */ jsxRuntime.jsx("section", { className: "rk-block rk-block-filter", "aria-label": "Filters (read-only)", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-filter-row", children: filters.map((filter, i) => /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "rk-filter", children: [
156
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-filter-label", children: filter.label }),
157
- /* @__PURE__ */ jsxRuntime.jsx(FilterControl, { filter })
158
- ] }, `${filter.field}-${i}`)) }) });
159
- }
160
- function FallbackBlock({ block }) {
161
- const type = typeof block?.type === "string" ? block.type : "unknown";
162
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-block rk-block-fallback", role: "note", children: [
163
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-fallback-label", children: [
164
- "Unsupported block: ",
165
- type
166
- ] }),
167
- chunkD4WIPDH3_cjs.isDev() ? /* @__PURE__ */ jsxRuntime.jsxs("details", { className: "rk-fallback-raw", children: [
168
- /* @__PURE__ */ jsxRuntime.jsx("summary", { children: "Raw payload (dev only)" }),
169
- /* @__PURE__ */ jsxRuntime.jsx("pre", { children: safeStringify(block) })
170
- ] }) : null
171
- ] });
172
- }
173
- function safeStringify(value) {
174
- try {
175
- return JSON.stringify(value, null, 2);
176
- } catch {
177
- return String(value);
178
+ util2.joinValues = joinValues;
179
+ util2.jsonStringifyReplacer = (_, value) => {
180
+ if (typeof value === "bigint") {
181
+ return value.toString();
182
+ }
183
+ return value;
184
+ };
185
+ })(util || (util = {}));
186
+ var objectUtil;
187
+ (function(objectUtil2) {
188
+ objectUtil2.mergeShapes = (first, second) => {
189
+ return {
190
+ ...first,
191
+ ...second
192
+ // second overwrites first
193
+ };
194
+ };
195
+ })(objectUtil || (objectUtil = {}));
196
+ var ZodParsedType = util.arrayToEnum([
197
+ "string",
198
+ "nan",
199
+ "number",
200
+ "integer",
201
+ "float",
202
+ "boolean",
203
+ "date",
204
+ "bigint",
205
+ "symbol",
206
+ "function",
207
+ "undefined",
208
+ "null",
209
+ "array",
210
+ "object",
211
+ "unknown",
212
+ "promise",
213
+ "void",
214
+ "never",
215
+ "map",
216
+ "set"
217
+ ]);
218
+ var getParsedType = (data) => {
219
+ const t = typeof data;
220
+ switch (t) {
221
+ case "undefined":
222
+ return ZodParsedType.undefined;
223
+ case "string":
224
+ return ZodParsedType.string;
225
+ case "number":
226
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
227
+ case "boolean":
228
+ return ZodParsedType.boolean;
229
+ case "function":
230
+ return ZodParsedType.function;
231
+ case "bigint":
232
+ return ZodParsedType.bigint;
233
+ case "symbol":
234
+ return ZodParsedType.symbol;
235
+ case "object":
236
+ if (Array.isArray(data)) {
237
+ return ZodParsedType.array;
238
+ }
239
+ if (data === null) {
240
+ return ZodParsedType.null;
241
+ }
242
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
243
+ return ZodParsedType.promise;
244
+ }
245
+ if (typeof Map !== "undefined" && data instanceof Map) {
246
+ return ZodParsedType.map;
247
+ }
248
+ if (typeof Set !== "undefined" && data instanceof Set) {
249
+ return ZodParsedType.set;
250
+ }
251
+ if (typeof Date !== "undefined" && data instanceof Date) {
252
+ return ZodParsedType.date;
253
+ }
254
+ return ZodParsedType.object;
255
+ default:
256
+ return ZodParsedType.unknown;
178
257
  }
179
- }
180
-
181
- // src/blocks/index.ts
182
- var defaultBlockComponents = {
183
- TEXT: TextBlock,
184
- KPI: KpiBlock,
185
- CHART: ChartBlock,
186
- TABLE: TableBlock,
187
- INSIGHT: InsightBlock,
188
- RECOMMENDATION: RecommendationBlock,
189
- FILTER: FilterBlock
190
258
  };
191
259
 
192
- // src/registry.ts
193
- var globalRegistry = /* @__PURE__ */ new Map();
194
- function registerBlock(options) {
195
- if (!options.override && globalRegistry.has(options.type)) return;
196
- globalRegistry.set(options.type, options.component);
197
- }
198
- function unregisterBlock(type) {
199
- globalRegistry.delete(type);
200
- }
201
- function registeredBlockTypes() {
202
- return [...globalRegistry.keys()];
203
- }
204
- function resolveBlockComponent(type, overrides) {
205
- return overrides?.[type] ?? globalRegistry.get(type) ?? defaultBlockComponents[type] ?? FallbackBlock;
206
- }
207
- var ErrorBoundary = class extends react.Component {
208
- constructor() {
209
- super(...arguments);
210
- this.state = { error: null };
211
- }
212
- static getDerivedStateFromError(error) {
213
- return { error };
214
- }
215
- componentDidCatch(error, info) {
216
- this.props.onError?.(error, info);
217
- }
218
- render() {
219
- if (this.state.error) return this.props.fallback(this.state.error);
220
- return this.props.children;
221
- }
260
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
261
+ var ZodIssueCode = util.arrayToEnum([
262
+ "invalid_type",
263
+ "invalid_literal",
264
+ "custom",
265
+ "invalid_union",
266
+ "invalid_union_discriminator",
267
+ "invalid_enum_value",
268
+ "unrecognized_keys",
269
+ "invalid_arguments",
270
+ "invalid_return_type",
271
+ "invalid_date",
272
+ "invalid_string",
273
+ "too_small",
274
+ "too_big",
275
+ "invalid_intersection_types",
276
+ "not_multiple_of",
277
+ "not_finite"
278
+ ]);
279
+ var quotelessJson = (obj) => {
280
+ const json = JSON.stringify(obj, null, 2);
281
+ return json.replace(/"([^"]+)":/g, "$1:");
222
282
  };
223
- function AiRenderer({
224
- response,
225
- components,
226
- onAction = noopAction,
227
- className
228
- }) {
229
- if (!response || typeof response !== "object" || !("type" in response)) {
230
- return /* @__PURE__ */ jsxRuntime.jsx(ErrorView, { message: "No response to display." });
283
+ var ZodError = class _ZodError extends Error {
284
+ get errors() {
285
+ return this.issues;
231
286
  }
232
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: className ?? "rk-response", "data-response-type": response.type, children: [
233
- renderBody(response, components, onAction),
234
- /* @__PURE__ */ jsxRuntime.jsx(MetadataFooter, { metadata: response.metadata, onAction, responseId: response.id })
235
- ] });
236
- }
237
- function renderBody(response, components, onAction) {
238
- switch (response.type) {
239
- case "TEXT": {
240
- const { format, value } = response.content;
241
- return format === "MARKDOWN" ? /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: value }) : /* @__PURE__ */ jsxRuntime.jsx("p", { className: "rk-text-plain", children: value });
242
- }
243
- case "ANALYTICS": {
244
- const { title, blocks } = response.content;
245
- const list = Array.isArray(blocks) ? blocks : [];
246
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
247
- title ? /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "rk-response-title", children: title }) : null,
248
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-blocks", children: list.map((block, i) => /* @__PURE__ */ jsxRuntime.jsx(
249
- BlockSlot,
250
- {
251
- block,
252
- components,
253
- onAction
254
- },
255
- blockKey(block, i)
256
- )) })
257
- ] });
287
+ constructor(issues) {
288
+ super();
289
+ this.issues = [];
290
+ this.addIssue = (sub) => {
291
+ this.issues = [...this.issues, sub];
292
+ };
293
+ this.addIssues = (subs = []) => {
294
+ this.issues = [...this.issues, ...subs];
295
+ };
296
+ const actualProto = new.target.prototype;
297
+ if (Object.setPrototypeOf) {
298
+ Object.setPrototypeOf(this, actualProto);
299
+ } else {
300
+ this.__proto__ = actualProto;
258
301
  }
259
- case "ERROR":
260
- return /* @__PURE__ */ jsxRuntime.jsx(ErrorView, { message: response.content.message });
261
- default:
262
- return /* @__PURE__ */ jsxRuntime.jsx(ErrorView, { message: "Unsupported response type." });
302
+ this.name = "ZodError";
303
+ this.issues = issues;
263
304
  }
264
- }
265
- function BlockSlot({
266
- block,
267
- components,
268
- onAction
269
- }) {
270
- const type = typeof block?.type === "string" ? block.type : "UNKNOWN";
271
- const Component2 = resolveBlockComponent(type, components);
272
- return /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { fallback: () => /* @__PURE__ */ jsxRuntime.jsx(FallbackBlock, { block, onAction }), children: /* @__PURE__ */ jsxRuntime.jsx(Component2, { block, onAction }) });
273
- }
274
- function ErrorView({ message }) {
275
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-block rk-error", role: "alert", children: [
276
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-error-icon", "aria-hidden": true, children: "\u2715" }),
277
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-error-message", children: message })
278
- ] });
279
- }
280
- function MetadataFooter({
281
- metadata,
282
- onAction,
283
- responseId
284
- }) {
285
- if (!metadata) return null;
286
- const { generatedAt, dataSource, refreshable } = metadata;
287
- if (!generatedAt && !dataSource && !refreshable) return null;
288
- return /* @__PURE__ */ jsxRuntime.jsxs("footer", { className: "rk-meta", children: [
289
- generatedAt ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-meta-time", children: formatTime(generatedAt) }) : null,
290
- dataSource ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-meta-source", children: dataSource }) : null,
291
- refreshable ? /* @__PURE__ */ jsxRuntime.jsx(
292
- "button",
293
- {
294
- type: "button",
295
- className: "rk-action rk-meta-refresh",
296
- onClick: () => onAction({ type: "REFRESH", responseId }),
297
- children: "Refresh"
305
+ format(_mapper) {
306
+ const mapper = _mapper || function(issue) {
307
+ return issue.message;
308
+ };
309
+ const fieldErrors = { _errors: [] };
310
+ const processError = (error) => {
311
+ for (const issue of error.issues) {
312
+ if (issue.code === "invalid_union") {
313
+ issue.unionErrors.map(processError);
314
+ } else if (issue.code === "invalid_return_type") {
315
+ processError(issue.returnTypeError);
316
+ } else if (issue.code === "invalid_arguments") {
317
+ processError(issue.argumentsError);
318
+ } else if (issue.path.length === 0) {
319
+ fieldErrors._errors.push(mapper(issue));
320
+ } else {
321
+ let curr = fieldErrors;
322
+ let i = 0;
323
+ while (i < issue.path.length) {
324
+ const el = issue.path[i];
325
+ const terminal = i === issue.path.length - 1;
326
+ if (!terminal) {
327
+ curr[el] = curr[el] || { _errors: [] };
328
+ } else {
329
+ curr[el] = curr[el] || { _errors: [] };
330
+ curr[el]._errors.push(mapper(issue));
331
+ }
332
+ curr = curr[el];
333
+ i++;
334
+ }
335
+ }
298
336
  }
299
- ) : null
300
- ] });
301
- }
302
- function formatTime(iso) {
303
- const d = new Date(iso);
304
- return Number.isNaN(d.getTime()) ? iso : d.toLocaleString();
305
- }
306
- function blockKey(block, index) {
307
- return typeof block?.id === "string" && block.id ? block.id : `block-${index}`;
308
- }
309
-
310
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
311
- var external_exports = {};
312
- chunkD4WIPDH3_cjs.__export(external_exports, {
313
- BRAND: () => BRAND,
314
- DIRTY: () => DIRTY,
315
- EMPTY_PATH: () => EMPTY_PATH,
316
- INVALID: () => INVALID,
317
- NEVER: () => NEVER,
318
- OK: () => OK,
319
- ParseStatus: () => ParseStatus,
320
- Schema: () => ZodType,
321
- ZodAny: () => ZodAny,
322
- ZodArray: () => ZodArray,
323
- ZodBigInt: () => ZodBigInt,
324
- ZodBoolean: () => ZodBoolean,
325
- ZodBranded: () => ZodBranded,
326
- ZodCatch: () => ZodCatch,
327
- ZodDate: () => ZodDate,
328
- ZodDefault: () => ZodDefault,
329
- ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
330
- ZodEffects: () => ZodEffects,
331
- ZodEnum: () => ZodEnum,
332
- ZodError: () => ZodError,
333
- ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
334
- ZodFunction: () => ZodFunction,
335
- ZodIntersection: () => ZodIntersection,
336
- ZodIssueCode: () => ZodIssueCode,
337
- ZodLazy: () => ZodLazy,
338
- ZodLiteral: () => ZodLiteral,
339
- ZodMap: () => ZodMap,
340
- ZodNaN: () => ZodNaN,
341
- ZodNativeEnum: () => ZodNativeEnum,
342
- ZodNever: () => ZodNever,
343
- ZodNull: () => ZodNull,
344
- ZodNullable: () => ZodNullable,
345
- ZodNumber: () => ZodNumber,
346
- ZodObject: () => ZodObject,
347
- ZodOptional: () => ZodOptional,
348
- ZodParsedType: () => ZodParsedType,
349
- ZodPipeline: () => ZodPipeline,
350
- ZodPromise: () => ZodPromise,
351
- ZodReadonly: () => ZodReadonly,
352
- ZodRecord: () => ZodRecord,
353
- ZodSchema: () => ZodType,
354
- ZodSet: () => ZodSet,
355
- ZodString: () => ZodString,
356
- ZodSymbol: () => ZodSymbol,
357
- ZodTransformer: () => ZodEffects,
358
- ZodTuple: () => ZodTuple,
359
- ZodType: () => ZodType,
360
- ZodUndefined: () => ZodUndefined,
361
- ZodUnion: () => ZodUnion,
362
- ZodUnknown: () => ZodUnknown,
363
- ZodVoid: () => ZodVoid,
364
- addIssueToContext: () => addIssueToContext,
365
- any: () => anyType,
366
- array: () => arrayType,
367
- bigint: () => bigIntType,
368
- boolean: () => booleanType,
369
- coerce: () => coerce,
370
- custom: () => custom,
371
- date: () => dateType,
372
- datetimeRegex: () => datetimeRegex,
373
- defaultErrorMap: () => en_default,
374
- discriminatedUnion: () => discriminatedUnionType,
375
- effect: () => effectsType,
376
- enum: () => enumType,
377
- function: () => functionType,
378
- getErrorMap: () => getErrorMap,
379
- getParsedType: () => getParsedType,
380
- instanceof: () => instanceOfType,
381
- intersection: () => intersectionType,
382
- isAborted: () => isAborted,
383
- isAsync: () => isAsync,
384
- isDirty: () => isDirty,
385
- isValid: () => isValid,
386
- late: () => late,
387
- lazy: () => lazyType,
388
- literal: () => literalType,
389
- makeIssue: () => makeIssue,
390
- map: () => mapType,
391
- nan: () => nanType,
392
- nativeEnum: () => nativeEnumType,
393
- never: () => neverType,
394
- null: () => nullType,
395
- nullable: () => nullableType,
396
- number: () => numberType,
397
- object: () => objectType,
398
- objectUtil: () => objectUtil,
399
- oboolean: () => oboolean,
400
- onumber: () => onumber,
401
- optional: () => optionalType,
402
- ostring: () => ostring,
403
- pipeline: () => pipelineType,
404
- preprocess: () => preprocessType,
405
- promise: () => promiseType,
406
- quotelessJson: () => quotelessJson,
407
- record: () => recordType,
408
- set: () => setType,
409
- setErrorMap: () => setErrorMap,
410
- strictObject: () => strictObjectType,
411
- string: () => stringType,
412
- symbol: () => symbolType,
413
- transformer: () => effectsType,
414
- tuple: () => tupleType,
415
- undefined: () => undefinedType,
416
- union: () => unionType,
417
- unknown: () => unknownType,
418
- util: () => util,
419
- void: () => voidType
420
- });
421
-
422
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
423
- var util;
424
- (function(util2) {
425
- util2.assertEqual = (_) => {
426
- };
427
- function assertIs(_arg) {
428
- }
429
- util2.assertIs = assertIs;
430
- function assertNever(_x) {
431
- throw new Error();
337
+ };
338
+ processError(this);
339
+ return fieldErrors;
432
340
  }
433
- util2.assertNever = assertNever;
434
- util2.arrayToEnum = (items) => {
435
- const obj = {};
436
- for (const item of items) {
437
- obj[item] = item;
438
- }
439
- return obj;
440
- };
441
- util2.getValidEnumValues = (obj) => {
442
- const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
443
- const filtered = {};
444
- for (const k of validKeys) {
445
- filtered[k] = obj[k];
341
+ static assert(value) {
342
+ if (!(value instanceof _ZodError)) {
343
+ throw new Error(`Not a ZodError: ${value}`);
446
344
  }
447
- return util2.objectValues(filtered);
448
- };
449
- util2.objectValues = (obj) => {
450
- return util2.objectKeys(obj).map(function(e) {
451
- return obj[e];
452
- });
453
- };
454
- util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
455
- const keys = [];
456
- for (const key in object) {
457
- if (Object.prototype.hasOwnProperty.call(object, key)) {
458
- keys.push(key);
459
- }
460
- }
461
- return keys;
462
- };
463
- util2.find = (arr, checker) => {
464
- for (const item of arr) {
465
- if (checker(item))
466
- return item;
467
- }
468
- return void 0;
469
- };
470
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
471
- function joinValues(array, separator = " | ") {
472
- return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
473
- }
474
- util2.joinValues = joinValues;
475
- util2.jsonStringifyReplacer = (_, value) => {
476
- if (typeof value === "bigint") {
477
- return value.toString();
478
- }
479
- return value;
480
- };
481
- })(util || (util = {}));
482
- var objectUtil;
483
- (function(objectUtil2) {
484
- objectUtil2.mergeShapes = (first, second) => {
485
- return {
486
- ...first,
487
- ...second
488
- // second overwrites first
489
- };
490
- };
491
- })(objectUtil || (objectUtil = {}));
492
- var ZodParsedType = util.arrayToEnum([
493
- "string",
494
- "nan",
495
- "number",
496
- "integer",
497
- "float",
498
- "boolean",
499
- "date",
500
- "bigint",
501
- "symbol",
502
- "function",
503
- "undefined",
504
- "null",
505
- "array",
506
- "object",
507
- "unknown",
508
- "promise",
509
- "void",
510
- "never",
511
- "map",
512
- "set"
513
- ]);
514
- var getParsedType = (data) => {
515
- const t = typeof data;
516
- switch (t) {
517
- case "undefined":
518
- return ZodParsedType.undefined;
519
- case "string":
520
- return ZodParsedType.string;
521
- case "number":
522
- return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
523
- case "boolean":
524
- return ZodParsedType.boolean;
525
- case "function":
526
- return ZodParsedType.function;
527
- case "bigint":
528
- return ZodParsedType.bigint;
529
- case "symbol":
530
- return ZodParsedType.symbol;
531
- case "object":
532
- if (Array.isArray(data)) {
533
- return ZodParsedType.array;
534
- }
535
- if (data === null) {
536
- return ZodParsedType.null;
537
- }
538
- if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
539
- return ZodParsedType.promise;
540
- }
541
- if (typeof Map !== "undefined" && data instanceof Map) {
542
- return ZodParsedType.map;
543
- }
544
- if (typeof Set !== "undefined" && data instanceof Set) {
545
- return ZodParsedType.set;
546
- }
547
- if (typeof Date !== "undefined" && data instanceof Date) {
548
- return ZodParsedType.date;
549
- }
550
- return ZodParsedType.object;
551
- default:
552
- return ZodParsedType.unknown;
553
- }
554
- };
555
-
556
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
557
- var ZodIssueCode = util.arrayToEnum([
558
- "invalid_type",
559
- "invalid_literal",
560
- "custom",
561
- "invalid_union",
562
- "invalid_union_discriminator",
563
- "invalid_enum_value",
564
- "unrecognized_keys",
565
- "invalid_arguments",
566
- "invalid_return_type",
567
- "invalid_date",
568
- "invalid_string",
569
- "too_small",
570
- "too_big",
571
- "invalid_intersection_types",
572
- "not_multiple_of",
573
- "not_finite"
574
- ]);
575
- var quotelessJson = (obj) => {
576
- const json = JSON.stringify(obj, null, 2);
577
- return json.replace(/"([^"]+)":/g, "$1:");
578
- };
579
- var ZodError = class _ZodError extends Error {
580
- get errors() {
581
- return this.issues;
582
- }
583
- constructor(issues) {
584
- super();
585
- this.issues = [];
586
- this.addIssue = (sub) => {
587
- this.issues = [...this.issues, sub];
588
- };
589
- this.addIssues = (subs = []) => {
590
- this.issues = [...this.issues, ...subs];
591
- };
592
- const actualProto = new.target.prototype;
593
- if (Object.setPrototypeOf) {
594
- Object.setPrototypeOf(this, actualProto);
595
- } else {
596
- this.__proto__ = actualProto;
597
- }
598
- this.name = "ZodError";
599
- this.issues = issues;
600
- }
601
- format(_mapper) {
602
- const mapper = _mapper || function(issue) {
603
- return issue.message;
604
- };
605
- const fieldErrors = { _errors: [] };
606
- const processError = (error) => {
607
- for (const issue of error.issues) {
608
- if (issue.code === "invalid_union") {
609
- issue.unionErrors.map(processError);
610
- } else if (issue.code === "invalid_return_type") {
611
- processError(issue.returnTypeError);
612
- } else if (issue.code === "invalid_arguments") {
613
- processError(issue.argumentsError);
614
- } else if (issue.path.length === 0) {
615
- fieldErrors._errors.push(mapper(issue));
616
- } else {
617
- let curr = fieldErrors;
618
- let i = 0;
619
- while (i < issue.path.length) {
620
- const el = issue.path[i];
621
- const terminal = i === issue.path.length - 1;
622
- if (!terminal) {
623
- curr[el] = curr[el] || { _errors: [] };
624
- } else {
625
- curr[el] = curr[el] || { _errors: [] };
626
- curr[el]._errors.push(mapper(issue));
627
- }
628
- curr = curr[el];
629
- i++;
630
- }
631
- }
632
- }
633
- };
634
- processError(this);
635
- return fieldErrors;
636
- }
637
- static assert(value) {
638
- if (!(value instanceof _ZodError)) {
639
- throw new Error(`Not a ZodError: ${value}`);
640
- }
641
- }
642
- toString() {
643
- return this.message;
644
- }
645
- get message() {
646
- return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
647
- }
648
- get isEmpty() {
649
- return this.issues.length === 0;
650
- }
651
- flatten(mapper = (issue) => issue.message) {
652
- const fieldErrors = {};
653
- const formErrors = [];
654
- for (const sub of this.issues) {
655
- if (sub.path.length > 0) {
656
- const firstEl = sub.path[0];
657
- fieldErrors[firstEl] = fieldErrors[firstEl] || [];
658
- fieldErrors[firstEl].push(mapper(sub));
659
- } else {
660
- formErrors.push(mapper(sub));
345
+ }
346
+ toString() {
347
+ return this.message;
348
+ }
349
+ get message() {
350
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
351
+ }
352
+ get isEmpty() {
353
+ return this.issues.length === 0;
354
+ }
355
+ flatten(mapper = (issue) => issue.message) {
356
+ const fieldErrors = {};
357
+ const formErrors = [];
358
+ for (const sub of this.issues) {
359
+ if (sub.path.length > 0) {
360
+ const firstEl = sub.path[0];
361
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
362
+ fieldErrors[firstEl].push(mapper(sub));
363
+ } else {
364
+ formErrors.push(mapper(sub));
661
365
  }
662
366
  }
663
367
  return { formErrors, fieldErrors };
@@ -4509,149 +4213,446 @@ function safeParseAiResponse(input) {
4509
4213
  function parseBlock(input) {
4510
4214
  return blockSchema.parse(input);
4511
4215
  }
4512
- var progressEventSchema = external_exports.object({
4513
- phase: progressPhaseSchema,
4514
- message: external_exports.string().optional(),
4515
- tool: external_exports.string().optional()
4516
- });
4517
- var responseStartSchema = external_exports.object({
4518
- id: external_exports.string(),
4519
- type: responseTypeSchema,
4520
- metadata: responseMetadataSchema.optional(),
4521
- title: external_exports.string().optional()
4522
- });
4523
- var contentEventSchema = external_exports.object({
4524
- format: textFormatSchema.optional(),
4525
- value: external_exports.string().optional(),
4526
- message: external_exports.string().optional()
4527
- });
4528
- var responseEndSchema = external_exports.object({
4529
- status: external_exports.enum(["COMPLETED", "ERROR"])
4530
- });
4531
- var errorEventSchema = external_exports.object({
4532
- message: external_exports.string().optional()
4533
- });
4534
- function parseSseEvent(eventName, raw) {
4535
- let json;
4216
+ var progressEventSchema = external_exports.object({
4217
+ phase: progressPhaseSchema,
4218
+ message: external_exports.string().optional(),
4219
+ tool: external_exports.string().optional()
4220
+ });
4221
+ var responseStartSchema = external_exports.object({
4222
+ id: external_exports.string(),
4223
+ type: responseTypeSchema,
4224
+ metadata: responseMetadataSchema.optional(),
4225
+ title: external_exports.string().optional()
4226
+ });
4227
+ var contentEventSchema = external_exports.object({
4228
+ format: textFormatSchema.optional(),
4229
+ value: external_exports.string().optional(),
4230
+ message: external_exports.string().optional()
4231
+ });
4232
+ var responseEndSchema = external_exports.object({
4233
+ status: external_exports.enum(["COMPLETED", "ERROR"])
4234
+ });
4235
+ var errorEventSchema = external_exports.object({
4236
+ message: external_exports.string().optional()
4237
+ });
4238
+ function parseSseEvent(eventName, raw) {
4239
+ let json;
4240
+ try {
4241
+ json = raw.length ? JSON.parse(raw) : {};
4242
+ } catch {
4243
+ return { event: "error", data: { message: "Malformed event payload from server." } };
4244
+ }
4245
+ switch (eventName) {
4246
+ case "progress": {
4247
+ const r = progressEventSchema.safeParse(json);
4248
+ return r.success ? { event: "progress", data: r.data } : { event: "progress", data: { phase: "THINKING" } };
4249
+ }
4250
+ case "response_start": {
4251
+ const r = responseStartSchema.safeParse(json);
4252
+ return r.success ? { event: "response_start", data: r.data } : { event: "error", data: { message: "Invalid response_start event." } };
4253
+ }
4254
+ case "content": {
4255
+ const r = contentEventSchema.safeParse(json);
4256
+ return r.success ? { event: "content", data: r.data } : { event: "content", data: {} };
4257
+ }
4258
+ case "block":
4259
+ return { event: "block", data: blockSchema.parse(json) };
4260
+ case "response_end": {
4261
+ const r = responseEndSchema.safeParse(json);
4262
+ return r.success ? { event: "response_end", data: r.data } : { event: "response_end", data: { status: "COMPLETED" } };
4263
+ }
4264
+ case "error":
4265
+ default: {
4266
+ const r = errorEventSchema.safeParse(json);
4267
+ return { event: "error", data: r.success ? r.data : {} };
4268
+ }
4269
+ }
4270
+ }
4271
+ var initialStreamState = { phase: "idle" };
4272
+ function startResponse(data) {
4273
+ const type = data.type;
4274
+ const base = { id: data.id, metadata: data.metadata };
4275
+ switch (type) {
4276
+ case "ANALYTICS":
4277
+ return { ...base, type: "ANALYTICS", content: { title: data.title, blocks: [] } };
4278
+ case "ERROR":
4279
+ return { ...base, type: "ERROR", content: { message: "" } };
4280
+ case "TEXT":
4281
+ default:
4282
+ return { ...base, type: "TEXT", content: { format: "PLAIN_TEXT", value: "" } };
4283
+ }
4284
+ }
4285
+ function streamReducer(state, event) {
4286
+ switch (event.event) {
4287
+ case "progress":
4288
+ return {
4289
+ ...state,
4290
+ phase: event.data.phase,
4291
+ progressMessage: event.data.message ?? state.progressMessage,
4292
+ tool: event.data.tool
4293
+ };
4294
+ case "response_start":
4295
+ return {
4296
+ ...state,
4297
+ phase: "COMPOSING",
4298
+ tool: void 0,
4299
+ response: startResponse(event.data),
4300
+ error: void 0
4301
+ };
4302
+ case "content": {
4303
+ const response = state.response;
4304
+ if (!response) return state;
4305
+ if (response.type === "TEXT") {
4306
+ return {
4307
+ ...state,
4308
+ response: {
4309
+ ...response,
4310
+ content: {
4311
+ format: event.data.format ?? response.content.format,
4312
+ value: event.data.value ?? response.content.value
4313
+ }
4314
+ }
4315
+ };
4316
+ }
4317
+ if (response.type === "ERROR") {
4318
+ return {
4319
+ ...state,
4320
+ response: {
4321
+ ...response,
4322
+ content: { message: event.data.message ?? response.content.message }
4323
+ }
4324
+ };
4325
+ }
4326
+ return state;
4327
+ }
4328
+ case "block": {
4329
+ const response = state.response;
4330
+ if (!response || response.type !== "ANALYTICS") return state;
4331
+ return {
4332
+ ...state,
4333
+ response: {
4334
+ ...response,
4335
+ content: {
4336
+ ...response.content,
4337
+ blocks: [...response.content.blocks, event.data]
4338
+ }
4339
+ }
4340
+ };
4341
+ }
4342
+ case "response_end": {
4343
+ if (event.data.status === "ERROR") {
4344
+ const message = state.response?.type === "ERROR" && state.response.content.message || state.error || "The request failed.";
4345
+ return { ...state, phase: "error", error: message };
4346
+ }
4347
+ return { ...state, phase: "done", progressMessage: void 0, tool: void 0 };
4348
+ }
4349
+ case "error":
4350
+ return {
4351
+ ...state,
4352
+ phase: "error",
4353
+ error: event.data.message ?? "The stream encountered a fatal error."
4354
+ };
4355
+ default:
4356
+ return state;
4357
+ }
4358
+ }
4359
+
4360
+ // src/actions.ts
4361
+ var noopAction = () => {
4362
+ };
4363
+ function Markdown({ children, className }) {
4364
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className ?? "rk-markdown", children: /* @__PURE__ */ jsxRuntime.jsx(
4365
+ ReactMarkdown__default.default,
4366
+ {
4367
+ remarkPlugins: [remarkGfm__default.default],
4368
+ components: {
4369
+ a: ({ node: _node, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("a", { ...props, target: "_blank", rel: "noopener noreferrer" })
4370
+ },
4371
+ children
4372
+ }
4373
+ ) });
4374
+ }
4375
+ function TextBlock({ block }) {
4376
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-block rk-block-text", children: /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: block.content }) });
4377
+ }
4378
+ var TREND_GLYPH = { UP: "\u25B2", DOWN: "\u25BC", STABLE: "\u2192" };
4379
+ function KpiBlock({ block }) {
4380
+ const items = Array.isArray(block.items) ? block.items : [];
4381
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "rk-block rk-block-kpi", "aria-label": block.title ?? "KPIs", children: [
4382
+ block.title ? /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "rk-block-title", children: block.title }) : null,
4383
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-kpi-grid", children: items.map((item, i) => {
4384
+ const display = item.formattedValue ?? chunkD4WIPDH3_cjs.formatValue(item.value);
4385
+ const trend = item.trend;
4386
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-kpi-item", children: [
4387
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-kpi-label", children: item.label }),
4388
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-kpi-value", children: display }),
4389
+ trend || typeof item.percentageChange === "number" ? /* @__PURE__ */ jsxRuntime.jsxs(
4390
+ "div",
4391
+ {
4392
+ className: `rk-kpi-trend rk-kpi-trend-${(trend ?? "STABLE").toLowerCase()}`,
4393
+ children: [
4394
+ trend ? /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": true, children: TREND_GLYPH[trend] }) : null,
4395
+ typeof item.percentageChange === "number" ? /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
4396
+ item.percentageChange > 0 ? "+" : "",
4397
+ item.percentageChange,
4398
+ "%"
4399
+ ] }) : null
4400
+ ]
4401
+ }
4402
+ ) : null
4403
+ ] }, `${item.label}-${i}`);
4404
+ }) })
4405
+ ] });
4406
+ }
4407
+ var ChartRenderer = react.lazy(() => import('./ChartRenderer-UJNU2VNH.cjs'));
4408
+ function ChartBlock({ block }) {
4409
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "rk-block rk-block-chart", children: [
4410
+ block.title ? /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "rk-block-title", children: block.title }) : null,
4411
+ /* @__PURE__ */ jsxRuntime.jsx(
4412
+ react.Suspense,
4413
+ {
4414
+ fallback: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-chart-placeholder", "aria-busy": "true", children: "Loading chart\u2026" }),
4415
+ children: /* @__PURE__ */ jsxRuntime.jsx(ChartRenderer, { block })
4416
+ }
4417
+ )
4418
+ ] });
4419
+ }
4420
+ function TableBlock({ block, onAction }) {
4421
+ const columns = Array.isArray(block.columns) ? block.columns : [];
4422
+ const rows = Array.isArray(block.rows) ? block.rows : [];
4423
+ const download = () => onAction({
4424
+ type: "DOWNLOAD",
4425
+ format: "CSV",
4426
+ filename: `${block.title ?? "table"}.csv`,
4427
+ data: chunkD4WIPDH3_cjs.rowsToCsv(columns, rows),
4428
+ blockId: block.id
4429
+ });
4430
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "rk-block rk-block-table", children: [
4431
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-block-header", children: [
4432
+ block.title ? /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "rk-block-title", children: block.title }) : null,
4433
+ rows.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "rk-action", onClick: download, children: "Download CSV" }) : null
4434
+ ] }),
4435
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-table-scroll", children: [
4436
+ /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "rk-table", children: [
4437
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: col.label }, col.key)) }) }),
4438
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: rows.map((row, r) => /* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx("td", { children: chunkD4WIPDH3_cjs.formatValue(row[col.key]) }, col.key)) }, r)) })
4439
+ ] }),
4440
+ rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "rk-empty", children: "No data." }) : null
4441
+ ] })
4442
+ ] });
4443
+ }
4444
+ var SEVERITY_GLYPH = {
4445
+ INFO: "\u2139",
4446
+ SUCCESS: "\u2713",
4447
+ WARNING: "\u26A0",
4448
+ CRITICAL: "\u2715"
4449
+ };
4450
+ function InsightBlock({ block }) {
4451
+ const severity = ["INFO", "SUCCESS", "WARNING", "CRITICAL"].includes(
4452
+ block.severity
4453
+ ) ? block.severity : "INFO";
4454
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4455
+ "aside",
4456
+ {
4457
+ className: `rk-block rk-block-insight rk-severity-${severity.toLowerCase()}`,
4458
+ role: "note",
4459
+ children: [
4460
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-insight-icon", "aria-hidden": true, children: SEVERITY_GLYPH[severity] }),
4461
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-insight-body", children: [
4462
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-insight-title", children: block.title }),
4463
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-insight-desc", children: block.description })
4464
+ ] })
4465
+ ]
4466
+ }
4467
+ );
4468
+ }
4469
+ function RecommendationBlock({
4470
+ block
4471
+ }) {
4472
+ const items = Array.isArray(block.items) ? block.items : [];
4473
+ return /* @__PURE__ */ jsxRuntime.jsx("section", { className: "rk-block rk-block-recommendation", children: /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "rk-recommendation-list", children: items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "rk-recommendation-item", children: [
4474
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-recommendation-title", children: item.title }),
4475
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-recommendation-desc", children: item.description })
4476
+ ] }, `${item.title}-${i}`)) }) });
4477
+ }
4478
+ function FilterControl({ filter }) {
4479
+ const options = Array.isArray(filter.options) ? filter.options : [];
4480
+ switch (filter.filterType) {
4481
+ case "SELECT":
4482
+ case "MULTI_SELECT":
4483
+ return /* @__PURE__ */ jsxRuntime.jsx("select", { disabled: true, multiple: filter.filterType === "MULTI_SELECT", "aria-label": filter.label, children: options.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o, children: o }, o)) });
4484
+ case "DATE_RANGE":
4485
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "rk-filter-range", children: [
4486
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "date", disabled: true, "aria-label": `${filter.label} from` }),
4487
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "date", disabled: true, "aria-label": `${filter.label} to` })
4488
+ ] });
4489
+ case "NUMBER_RANGE":
4490
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "rk-filter-range", children: [
4491
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "number", disabled: true, "aria-label": `${filter.label} min`, placeholder: "min" }),
4492
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "number", disabled: true, "aria-label": `${filter.label} max`, placeholder: "max" })
4493
+ ] });
4494
+ case "SEARCH":
4495
+ default:
4496
+ return /* @__PURE__ */ jsxRuntime.jsx("input", { type: "search", disabled: true, "aria-label": filter.label, placeholder: "Search\u2026" });
4497
+ }
4498
+ }
4499
+ function FilterBlock({ block }) {
4500
+ const filters = Array.isArray(block.filters) ? block.filters : [];
4501
+ return /* @__PURE__ */ jsxRuntime.jsx("section", { className: "rk-block rk-block-filter", "aria-label": "Filters (read-only)", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-filter-row", children: filters.map((filter, i) => /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "rk-filter", children: [
4502
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-filter-label", children: filter.label }),
4503
+ /* @__PURE__ */ jsxRuntime.jsx(FilterControl, { filter })
4504
+ ] }, `${filter.field}-${i}`)) }) });
4505
+ }
4506
+ function FallbackBlock({ block }) {
4507
+ const type = typeof block?.type === "string" ? block.type : "unknown";
4508
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-block rk-block-fallback", role: "note", children: [
4509
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-fallback-label", children: [
4510
+ "Unsupported block: ",
4511
+ type
4512
+ ] }),
4513
+ chunkD4WIPDH3_cjs.isDev() ? /* @__PURE__ */ jsxRuntime.jsxs("details", { className: "rk-fallback-raw", children: [
4514
+ /* @__PURE__ */ jsxRuntime.jsx("summary", { children: "Raw payload (dev only)" }),
4515
+ /* @__PURE__ */ jsxRuntime.jsx("pre", { children: safeStringify(block) })
4516
+ ] }) : null
4517
+ ] });
4518
+ }
4519
+ function safeStringify(value) {
4536
4520
  try {
4537
- json = raw.length ? JSON.parse(raw) : {};
4521
+ return JSON.stringify(value, null, 2);
4538
4522
  } catch {
4539
- return { event: "error", data: { message: "Malformed event payload from server." } };
4540
- }
4541
- switch (eventName) {
4542
- case "progress": {
4543
- const r = progressEventSchema.safeParse(json);
4544
- return r.success ? { event: "progress", data: r.data } : { event: "progress", data: { phase: "THINKING" } };
4545
- }
4546
- case "response_start": {
4547
- const r = responseStartSchema.safeParse(json);
4548
- return r.success ? { event: "response_start", data: r.data } : { event: "error", data: { message: "Invalid response_start event." } };
4549
- }
4550
- case "content": {
4551
- const r = contentEventSchema.safeParse(json);
4552
- return r.success ? { event: "content", data: r.data } : { event: "content", data: {} };
4553
- }
4554
- case "block":
4555
- return { event: "block", data: blockSchema.parse(json) };
4556
- case "response_end": {
4557
- const r = responseEndSchema.safeParse(json);
4558
- return r.success ? { event: "response_end", data: r.data } : { event: "response_end", data: { status: "COMPLETED" } };
4559
- }
4560
- case "error":
4561
- default: {
4562
- const r = errorEventSchema.safeParse(json);
4563
- return { event: "error", data: r.success ? r.data : {} };
4564
- }
4523
+ return String(value);
4565
4524
  }
4566
4525
  }
4567
- var initialStreamState = { phase: "idle" };
4568
- function startResponse(data) {
4569
- const type = data.type;
4570
- const base = { id: data.id, metadata: data.metadata };
4571
- switch (type) {
4572
- case "ANALYTICS":
4573
- return { ...base, type: "ANALYTICS", content: { title: data.title, blocks: [] } };
4574
- case "ERROR":
4575
- return { ...base, type: "ERROR", content: { message: "" } };
4576
- case "TEXT":
4577
- default:
4578
- return { ...base, type: "TEXT", content: { format: "PLAIN_TEXT", value: "" } };
4526
+
4527
+ // src/blocks/index.ts
4528
+ var defaultBlockComponents = {
4529
+ TEXT: TextBlock,
4530
+ KPI: KpiBlock,
4531
+ CHART: ChartBlock,
4532
+ TABLE: TableBlock,
4533
+ INSIGHT: InsightBlock,
4534
+ RECOMMENDATION: RecommendationBlock,
4535
+ FILTER: FilterBlock
4536
+ };
4537
+
4538
+ // src/registry.ts
4539
+ var globalRegistry = /* @__PURE__ */ new Map();
4540
+ function registerBlock(options) {
4541
+ if (!options.override && globalRegistry.has(options.type)) return;
4542
+ globalRegistry.set(options.type, options.component);
4543
+ }
4544
+ function unregisterBlock(type) {
4545
+ globalRegistry.delete(type);
4546
+ }
4547
+ function registeredBlockTypes() {
4548
+ return [...globalRegistry.keys()];
4549
+ }
4550
+ function resolveBlockComponent(type, overrides) {
4551
+ return overrides?.[type] ?? globalRegistry.get(type) ?? defaultBlockComponents[type] ?? FallbackBlock;
4552
+ }
4553
+ var ErrorBoundary = class extends react.Component {
4554
+ constructor() {
4555
+ super(...arguments);
4556
+ this.state = { error: null };
4557
+ }
4558
+ static getDerivedStateFromError(error) {
4559
+ return { error };
4560
+ }
4561
+ componentDidCatch(error, info) {
4562
+ this.props.onError?.(error, info);
4563
+ }
4564
+ render() {
4565
+ if (this.state.error) return this.props.fallback(this.state.error);
4566
+ return this.props.children;
4567
+ }
4568
+ };
4569
+ function AiRenderer({
4570
+ response,
4571
+ components,
4572
+ onAction = noopAction,
4573
+ className
4574
+ }) {
4575
+ const parsed = react.useMemo(() => parseAiResponse(response), [response]);
4576
+ if (response == null) {
4577
+ return /* @__PURE__ */ jsxRuntime.jsx(ErrorView, { message: "No response to display." });
4579
4578
  }
4579
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: className ?? "rk-response", "data-response-type": parsed.type, children: [
4580
+ renderBody(parsed, components, onAction),
4581
+ /* @__PURE__ */ jsxRuntime.jsx(MetadataFooter, { metadata: parsed.metadata, onAction, responseId: parsed.id })
4582
+ ] });
4580
4583
  }
4581
- function streamReducer(state, event) {
4582
- switch (event.event) {
4583
- case "progress":
4584
- return {
4585
- ...state,
4586
- phase: event.data.phase,
4587
- progressMessage: event.data.message ?? state.progressMessage,
4588
- tool: event.data.tool
4589
- };
4590
- case "response_start":
4591
- return {
4592
- ...state,
4593
- phase: "COMPOSING",
4594
- tool: void 0,
4595
- response: startResponse(event.data),
4596
- error: void 0
4597
- };
4598
- case "content": {
4599
- const response = state.response;
4600
- if (!response) return state;
4601
- if (response.type === "TEXT") {
4602
- return {
4603
- ...state,
4604
- response: {
4605
- ...response,
4606
- content: {
4607
- format: event.data.format ?? response.content.format,
4608
- value: event.data.value ?? response.content.value
4609
- }
4610
- }
4611
- };
4612
- }
4613
- if (response.type === "ERROR") {
4614
- return {
4615
- ...state,
4616
- response: {
4617
- ...response,
4618
- content: { message: event.data.message ?? response.content.message }
4619
- }
4620
- };
4621
- }
4622
- return state;
4623
- }
4624
- case "block": {
4625
- const response = state.response;
4626
- if (!response || response.type !== "ANALYTICS") return state;
4627
- return {
4628
- ...state,
4629
- response: {
4630
- ...response,
4631
- content: {
4632
- ...response.content,
4633
- blocks: [...response.content.blocks, event.data]
4634
- }
4635
- }
4636
- };
4584
+ function renderBody(response, components, onAction) {
4585
+ switch (response.type) {
4586
+ case "TEXT": {
4587
+ const { format, value } = response.content;
4588
+ return format === "MARKDOWN" ? /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: value }) : /* @__PURE__ */ jsxRuntime.jsx("p", { className: "rk-text-plain", children: value });
4637
4589
  }
4638
- case "response_end": {
4639
- if (event.data.status === "ERROR") {
4640
- const message = state.response?.type === "ERROR" && state.response.content.message || state.error || "The request failed.";
4641
- return { ...state, phase: "error", error: message };
4642
- }
4643
- return { ...state, phase: "done", progressMessage: void 0, tool: void 0 };
4590
+ case "ANALYTICS": {
4591
+ const { title, blocks } = response.content;
4592
+ const list = Array.isArray(blocks) ? blocks : [];
4593
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4594
+ title ? /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "rk-response-title", children: title }) : null,
4595
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rk-blocks", children: list.map((block, i) => /* @__PURE__ */ jsxRuntime.jsx(
4596
+ BlockSlot,
4597
+ {
4598
+ block,
4599
+ components,
4600
+ onAction
4601
+ },
4602
+ blockKey(block, i)
4603
+ )) })
4604
+ ] });
4644
4605
  }
4645
- case "error":
4646
- return {
4647
- ...state,
4648
- phase: "error",
4649
- error: event.data.message ?? "The stream encountered a fatal error."
4650
- };
4606
+ case "ERROR":
4607
+ return /* @__PURE__ */ jsxRuntime.jsx(ErrorView, { message: response.content.message });
4651
4608
  default:
4652
- return state;
4609
+ return /* @__PURE__ */ jsxRuntime.jsx(ErrorView, { message: "Unsupported response type." });
4653
4610
  }
4654
4611
  }
4612
+ function BlockSlot({
4613
+ block,
4614
+ components,
4615
+ onAction
4616
+ }) {
4617
+ const type = typeof block?.type === "string" ? block.type : "UNKNOWN";
4618
+ const Component2 = resolveBlockComponent(type, components);
4619
+ return /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { fallback: () => /* @__PURE__ */ jsxRuntime.jsx(FallbackBlock, { block, onAction }), children: /* @__PURE__ */ jsxRuntime.jsx(Component2, { block, onAction }) });
4620
+ }
4621
+ function ErrorView({ message }) {
4622
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rk-block rk-error", role: "alert", children: [
4623
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-error-icon", "aria-hidden": true, children: "\u2715" }),
4624
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-error-message", children: message })
4625
+ ] });
4626
+ }
4627
+ function MetadataFooter({
4628
+ metadata,
4629
+ onAction,
4630
+ responseId
4631
+ }) {
4632
+ if (!metadata) return null;
4633
+ const { generatedAt, dataSource, refreshable } = metadata;
4634
+ if (!generatedAt && !dataSource && !refreshable) return null;
4635
+ return /* @__PURE__ */ jsxRuntime.jsxs("footer", { className: "rk-meta", children: [
4636
+ generatedAt ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-meta-time", children: formatTime(generatedAt) }) : null,
4637
+ dataSource ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rk-meta-source", children: dataSource }) : null,
4638
+ refreshable ? /* @__PURE__ */ jsxRuntime.jsx(
4639
+ "button",
4640
+ {
4641
+ type: "button",
4642
+ className: "rk-action rk-meta-refresh",
4643
+ onClick: () => onAction({ type: "REFRESH", responseId }),
4644
+ children: "Refresh"
4645
+ }
4646
+ ) : null
4647
+ ] });
4648
+ }
4649
+ function formatTime(iso) {
4650
+ const d = new Date(iso);
4651
+ return Number.isNaN(d.getTime()) ? iso : d.toLocaleString();
4652
+ }
4653
+ function blockKey(block, index) {
4654
+ return typeof block?.id === "string" && block.id ? block.id : `block-${index}`;
4655
+ }
4655
4656
 
4656
4657
  // src/sse.ts
4657
4658
  var trimTrailingSlash = (s) => s.replace(/\/+$/, "");