@yourgpt/copilot-sdk 2.1.5-alpha.4 → 2.1.5-alpha.6
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/{MessageTree-CSIHErPK.d.ts → MessageTree-Clhiv_k2.d.ts} +4 -3
- package/dist/{MessageTree-B0JGQOCi.d.cts → MessageTree-Dt9qfJ55.d.cts} +4 -3
- package/dist/{chunk-XUR3IOPX.cjs → chunk-2QLF7XM7.cjs} +1557 -3120
- package/dist/chunk-2QLF7XM7.cjs.map +1 -0
- package/dist/{chunk-NUXLAZOE.cjs → chunk-3ZDRX7J2.cjs} +2 -2
- package/dist/{chunk-NUXLAZOE.cjs.map → chunk-3ZDRX7J2.cjs.map} +1 -1
- package/dist/{chunk-RKGRQRZU.js → chunk-533K2Z7C.js} +4 -4
- package/dist/{chunk-RKGRQRZU.js.map → chunk-533K2Z7C.js.map} +1 -1
- package/dist/chunk-5EGBIQYS.cjs +292 -0
- package/dist/chunk-5EGBIQYS.cjs.map +1 -0
- package/dist/{chunk-3AONOZLY.js → chunk-AIVXGTWS.js} +2 -2
- package/dist/chunk-AIVXGTWS.js.map +1 -0
- package/dist/{chunk-LLM7AHMO.js → chunk-DDZLRCVX.js} +2 -2
- package/dist/{chunk-LLM7AHMO.js.map → chunk-DDZLRCVX.js.map} +1 -1
- package/dist/{chunk-FLZO2FO3.js → chunk-I2XOCFHG.js} +1558 -3071
- package/dist/chunk-I2XOCFHG.js.map +1 -0
- package/dist/{chunk-EEH3L64W.js → chunk-PSNLKMZH.js} +73 -11
- package/dist/chunk-PSNLKMZH.js.map +1 -0
- package/dist/chunk-PURFAD2P.js +2020 -0
- package/dist/chunk-PURFAD2P.js.map +1 -0
- package/dist/chunk-QTGEEBRW.cjs +2077 -0
- package/dist/chunk-QTGEEBRW.cjs.map +1 -0
- package/dist/{chunk-TPB7XED6.cjs → chunk-TPDMBDQX.cjs} +2 -2
- package/dist/chunk-TPDMBDQX.cjs.map +1 -0
- package/dist/chunk-TXQ37MAO.js +287 -0
- package/dist/chunk-TXQ37MAO.js.map +1 -0
- package/dist/{chunk-B4YDIMP3.cjs → chunk-VION33GW.cjs} +92 -30
- package/dist/chunk-VION33GW.cjs.map +1 -0
- package/dist/{chunk-MDS23G2S.cjs → chunk-Y2A6AMGO.cjs} +10 -10
- package/dist/{chunk-MDS23G2S.cjs.map → chunk-Y2A6AMGO.cjs.map} +1 -1
- package/dist/core/index.cjs +93 -93
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +5 -5
- package/dist/experimental/index.cjs +644 -0
- package/dist/experimental/index.cjs.map +1 -0
- package/dist/experimental/index.d.cts +924 -0
- package/dist/experimental/index.d.ts +924 -0
- package/dist/experimental/index.js +611 -0
- package/dist/experimental/index.js.map +1 -0
- package/dist/{index-D7169xuR.d.ts → index-D8zza1Q8.d.ts} +1 -1
- package/dist/{index-CzJB8Ddo.d.cts → index-DCVjTdIZ.d.cts} +1 -1
- package/dist/mcp/index.d.cts +3 -3
- package/dist/mcp/index.d.ts +3 -3
- package/dist/react/index.cjs +140 -123
- package/dist/react/index.d.cts +378 -10
- package/dist/react/index.d.ts +378 -10
- package/dist/react/index.js +7 -6
- package/dist/styles.css +45 -0
- package/dist/tools/anthropic/index.cjs +3 -3
- package/dist/tools/anthropic/index.d.cts +1 -1
- package/dist/tools/anthropic/index.d.ts +1 -1
- package/dist/tools/anthropic/index.js +2 -2
- package/dist/tools/brave/index.cjs +6 -6
- package/dist/tools/brave/index.d.cts +1 -1
- package/dist/tools/brave/index.d.ts +1 -1
- package/dist/tools/brave/index.js +3 -3
- package/dist/tools/exa/index.cjs +6 -6
- package/dist/tools/exa/index.d.cts +1 -1
- package/dist/tools/exa/index.d.ts +1 -1
- package/dist/tools/exa/index.js +3 -3
- package/dist/tools/google/index.cjs +6 -6
- package/dist/tools/google/index.d.cts +1 -1
- package/dist/tools/google/index.d.ts +1 -1
- package/dist/tools/google/index.js +4 -4
- package/dist/tools/openai/index.cjs +6 -6
- package/dist/tools/openai/index.d.cts +1 -1
- package/dist/tools/openai/index.d.ts +1 -1
- package/dist/tools/openai/index.js +3 -3
- package/dist/tools/searxng/index.cjs +6 -6
- package/dist/tools/searxng/index.d.cts +1 -1
- package/dist/tools/searxng/index.d.ts +1 -1
- package/dist/tools/searxng/index.js +3 -3
- package/dist/tools/serper/index.cjs +6 -6
- package/dist/tools/serper/index.d.cts +1 -1
- package/dist/tools/serper/index.d.ts +1 -1
- package/dist/tools/serper/index.js +3 -3
- package/dist/tools/tavily/index.cjs +6 -6
- package/dist/tools/tavily/index.d.cts +1 -1
- package/dist/tools/tavily/index.d.ts +1 -1
- package/dist/tools/tavily/index.js +3 -3
- package/dist/tools/web-search/index.cjs +7 -7
- package/dist/tools/web-search/index.d.cts +2 -2
- package/dist/tools/web-search/index.d.ts +2 -2
- package/dist/tools/web-search/index.js +4 -4
- package/dist/{tools-tmksfhUo.d.cts → tools-DcS6Aeao.d.cts} +7 -3
- package/dist/{tools-tmksfhUo.d.ts → tools-DcS6Aeao.d.ts} +7 -3
- package/dist/{types-BqwW3Baj.d.ts → types-BUYni9B8.d.ts} +1 -1
- package/dist/{types-BLw7mxtW.d.cts → types-Cvg4DUoc.d.cts} +1 -1
- package/dist/ui/index.cjs +1297 -596
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +136 -9
- package/dist/ui/index.d.ts +136 -9
- package/dist/ui/index.js +1128 -436
- package/dist/ui/index.js.map +1 -1
- package/package.json +6 -1
- package/dist/chunk-3AONOZLY.js.map +0 -1
- package/dist/chunk-B4YDIMP3.cjs.map +0 -1
- package/dist/chunk-EEH3L64W.js.map +0 -1
- package/dist/chunk-FLZO2FO3.js.map +0 -1
- package/dist/chunk-TPB7XED6.cjs.map +0 -1
- package/dist/chunk-XUR3IOPX.cjs.map +0 -1
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5EGBIQYS_cjs = require('../chunk-5EGBIQYS.cjs');
|
|
4
|
+
var chunk2QLF7XM7_cjs = require('../chunk-2QLF7XM7.cjs');
|
|
5
|
+
require('../chunk-VION33GW.cjs');
|
|
6
|
+
require('../chunk-JGPDQDY4.cjs');
|
|
7
|
+
require('../chunk-BJYA5NDL.cjs');
|
|
8
|
+
require('../chunk-Y2A6AMGO.cjs');
|
|
9
|
+
require('../chunk-TPDMBDQX.cjs');
|
|
10
|
+
require('../chunk-3ZDRX7J2.cjs');
|
|
11
|
+
require('../chunk-XWOHNY3F.cjs');
|
|
12
|
+
require('../chunk-TXLIY7GF.cjs');
|
|
13
|
+
require('../chunk-CBAHCI4R.cjs');
|
|
14
|
+
require('../chunk-MEBXW75C.cjs');
|
|
15
|
+
require('../chunk-W73FBYIH.cjs');
|
|
16
|
+
require('../chunk-2FAWEBZS.cjs');
|
|
17
|
+
require('../chunk-6T5XXJEP.cjs');
|
|
18
|
+
require('../chunk-GANCV72Z.cjs');
|
|
19
|
+
require('../chunk-JEQ2X3Z6.cjs');
|
|
20
|
+
var React = require('react');
|
|
21
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
22
|
+
var zod = require('zod');
|
|
23
|
+
|
|
24
|
+
function _interopNamespace(e) {
|
|
25
|
+
if (e && e.__esModule) return e;
|
|
26
|
+
var n = Object.create(null);
|
|
27
|
+
if (e) {
|
|
28
|
+
Object.keys(e).forEach(function (k) {
|
|
29
|
+
if (k !== 'default') {
|
|
30
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
31
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return e[k]; }
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
n.default = e;
|
|
39
|
+
return Object.freeze(n);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
43
|
+
|
|
44
|
+
// src/experimental/generativeUITool.ts
|
|
45
|
+
var RENDER_UI_PARAMETERS = {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: {
|
|
48
|
+
type: {
|
|
49
|
+
type: "string",
|
|
50
|
+
enum: ["html", "chart", "table", "stat", "card"],
|
|
51
|
+
description: "UI component type to render"
|
|
52
|
+
},
|
|
53
|
+
html: {
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "Raw HTML with Tailwind classes (type=html)"
|
|
56
|
+
},
|
|
57
|
+
height: { type: "string" },
|
|
58
|
+
chartType: {
|
|
59
|
+
type: "string",
|
|
60
|
+
enum: ["bar", "line", "pie", "area", "scatter"],
|
|
61
|
+
description: "Chart variant (type=chart)"
|
|
62
|
+
},
|
|
63
|
+
labels: {
|
|
64
|
+
type: "array",
|
|
65
|
+
items: { type: "string" },
|
|
66
|
+
description: "X-axis category labels (type=chart)"
|
|
67
|
+
},
|
|
68
|
+
datasets: {
|
|
69
|
+
type: "array",
|
|
70
|
+
items: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
label: { type: "string" },
|
|
74
|
+
data: { type: "array", items: { type: "number" } }
|
|
75
|
+
},
|
|
76
|
+
required: ["label", "data"]
|
|
77
|
+
},
|
|
78
|
+
description: "Data series (type=chart)"
|
|
79
|
+
},
|
|
80
|
+
xLabel: { type: "string" },
|
|
81
|
+
yLabel: { type: "string" },
|
|
82
|
+
columns: {
|
|
83
|
+
type: "array",
|
|
84
|
+
items: {
|
|
85
|
+
type: "object",
|
|
86
|
+
properties: {
|
|
87
|
+
key: { type: "string" },
|
|
88
|
+
label: { type: "string" },
|
|
89
|
+
align: { type: "string" }
|
|
90
|
+
},
|
|
91
|
+
required: ["key", "label"]
|
|
92
|
+
},
|
|
93
|
+
description: "Column definitions \u2014 key matches row property names (type=table)"
|
|
94
|
+
},
|
|
95
|
+
rows: {
|
|
96
|
+
type: "array",
|
|
97
|
+
items: { type: "object" },
|
|
98
|
+
description: "Array of row objects keyed by column.key (type=table)"
|
|
99
|
+
},
|
|
100
|
+
caption: { type: "string" },
|
|
101
|
+
stats: {
|
|
102
|
+
type: "array",
|
|
103
|
+
items: {
|
|
104
|
+
type: "object",
|
|
105
|
+
properties: {
|
|
106
|
+
label: { type: "string" },
|
|
107
|
+
value: { type: "string" },
|
|
108
|
+
change: { type: "string" },
|
|
109
|
+
changeDirection: {
|
|
110
|
+
type: "string",
|
|
111
|
+
enum: ["positive", "negative", "neutral"]
|
|
112
|
+
},
|
|
113
|
+
description: { type: "string" }
|
|
114
|
+
},
|
|
115
|
+
required: ["label", "value"]
|
|
116
|
+
},
|
|
117
|
+
description: "KPI stats array (type=stat)"
|
|
118
|
+
},
|
|
119
|
+
title: {
|
|
120
|
+
type: "string",
|
|
121
|
+
description: "Title shown above the component"
|
|
122
|
+
},
|
|
123
|
+
subtitle: { type: "string" },
|
|
124
|
+
body: { type: "string" },
|
|
125
|
+
fields: {
|
|
126
|
+
type: "array",
|
|
127
|
+
items: {
|
|
128
|
+
type: "object",
|
|
129
|
+
properties: {
|
|
130
|
+
label: { type: "string" },
|
|
131
|
+
value: { type: "string" },
|
|
132
|
+
badge: { type: "boolean" }
|
|
133
|
+
},
|
|
134
|
+
required: ["label", "value"]
|
|
135
|
+
},
|
|
136
|
+
description: "Key-value fields (type=card)"
|
|
137
|
+
},
|
|
138
|
+
cta: {
|
|
139
|
+
type: "object",
|
|
140
|
+
properties: {
|
|
141
|
+
label: { type: "string" },
|
|
142
|
+
url: { type: "string" }
|
|
143
|
+
},
|
|
144
|
+
required: ["label", "url"],
|
|
145
|
+
description: "Call-to-action link (type=card)"
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
required: ["type"]
|
|
149
|
+
};
|
|
150
|
+
function generativeUITool(config = {}) {
|
|
151
|
+
return {
|
|
152
|
+
description: config.description ?? `Render a rich visual UI component directly in the chat. Use this tool whenever the user's request is best answered with a visual instead of text.
|
|
153
|
+
|
|
154
|
+
Choose the type based on what fits best:
|
|
155
|
+
- "table": structured rows of data (comparisons, lists, records)
|
|
156
|
+
- "stat": KPI metrics, numbers with labels, dashboards with change deltas
|
|
157
|
+
- "card": entity summaries \u2014 profiles, products, results, structured key-value info
|
|
158
|
+
- "chart": graphs and visualizations \u2014 bar, line, pie, area, scatter \u2014 pass raw data only, not markup
|
|
159
|
+
- "html": anything that requires custom layout, rich formatting, or doesn't fit the above types \u2014 use Tailwind CSS classes freely
|
|
160
|
+
|
|
161
|
+
Always prefer a structured type (table, stat, card) over html when the data fits.
|
|
162
|
+
Only use html as a last resort for truly freeform content.`,
|
|
163
|
+
parameters: RENDER_UI_PARAMETERS
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function sanitizeHtml(html) {
|
|
167
|
+
return html.replace(/<script\b[^>]*\bsrc=["'][^"']*["'][^>]*><\/script>/gi, "").replace(/\s*on\w+="[^"]*"/gi, "").replace(/\s*on\w+='[^']*'/gi, "");
|
|
168
|
+
}
|
|
169
|
+
function HtmlRenderer({ payload, className }) {
|
|
170
|
+
const clean = sanitizeHtml(payload.html);
|
|
171
|
+
const srcdoc = `<!DOCTYPE html>
|
|
172
|
+
<html>
|
|
173
|
+
<head>
|
|
174
|
+
<meta charset="utf-8" />
|
|
175
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
176
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
177
|
+
<style>
|
|
178
|
+
body { margin: 0; padding: 4px; font-family: ui-sans-serif, system-ui, sans-serif; }
|
|
179
|
+
* { box-sizing: border-box; }
|
|
180
|
+
</style>
|
|
181
|
+
</head>
|
|
182
|
+
<body>${clean}</body>
|
|
183
|
+
</html>`;
|
|
184
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
185
|
+
"div",
|
|
186
|
+
{
|
|
187
|
+
className: chunk5EGBIQYS_cjs.cn("csdk-genui-html", className),
|
|
188
|
+
style: { width: "min(700px, calc(100vw - 320px))", minWidth: "320px" },
|
|
189
|
+
children: [
|
|
190
|
+
payload.title && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1.5 text-xs font-medium text-muted-foreground", children: payload.title }),
|
|
191
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
192
|
+
"iframe",
|
|
193
|
+
{
|
|
194
|
+
srcDoc: srcdoc,
|
|
195
|
+
sandbox: "allow-scripts",
|
|
196
|
+
style: {
|
|
197
|
+
height: payload.height ?? "520px",
|
|
198
|
+
minHeight: "120px",
|
|
199
|
+
width: "100%"
|
|
200
|
+
},
|
|
201
|
+
className: "rounded-md border border-border bg-white",
|
|
202
|
+
title: payload.title ?? "Rendered HTML"
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
]
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
function TableRenderer({ payload, className }) {
|
|
210
|
+
const { columns, rows, caption } = payload;
|
|
211
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
212
|
+
"div",
|
|
213
|
+
{
|
|
214
|
+
className: chunk5EGBIQYS_cjs.cn(
|
|
215
|
+
"csdk-genui-table w-full overflow-x-auto rounded-md border border-border",
|
|
216
|
+
className
|
|
217
|
+
),
|
|
218
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full min-w-full text-sm", children: [
|
|
219
|
+
caption && /* @__PURE__ */ jsxRuntime.jsx("caption", { className: "px-3 pt-2 pb-1 text-left text-xs text-muted-foreground", children: caption }),
|
|
220
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "border-b border-border bg-muted/40", children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
221
|
+
"th",
|
|
222
|
+
{
|
|
223
|
+
className: chunk5EGBIQYS_cjs.cn(
|
|
224
|
+
"whitespace-nowrap px-3 py-2 font-medium text-foreground",
|
|
225
|
+
col.align === "right" && "text-right",
|
|
226
|
+
col.align === "center" && "text-center",
|
|
227
|
+
(!col.align || col.align === "left") && "text-left"
|
|
228
|
+
),
|
|
229
|
+
children: col.label
|
|
230
|
+
},
|
|
231
|
+
col.key
|
|
232
|
+
)) }) }),
|
|
233
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
234
|
+
"td",
|
|
235
|
+
{
|
|
236
|
+
colSpan: columns.length,
|
|
237
|
+
className: "px-3 py-4 text-center text-sm text-muted-foreground",
|
|
238
|
+
children: "No data"
|
|
239
|
+
}
|
|
240
|
+
) }) : rows.map((row, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
241
|
+
"tr",
|
|
242
|
+
{
|
|
243
|
+
className: chunk5EGBIQYS_cjs.cn(
|
|
244
|
+
"border-b border-border last:border-0",
|
|
245
|
+
i % 2 === 1 && "bg-muted/20"
|
|
246
|
+
),
|
|
247
|
+
children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
248
|
+
"td",
|
|
249
|
+
{
|
|
250
|
+
className: chunk5EGBIQYS_cjs.cn(
|
|
251
|
+
"px-3 py-2 text-foreground/90",
|
|
252
|
+
col.align === "right" && "text-right tabular-nums",
|
|
253
|
+
col.align === "center" && "text-center",
|
|
254
|
+
(!col.align || col.align === "left") && "text-left"
|
|
255
|
+
),
|
|
256
|
+
children: row[col.key] === null || row[col.key] === void 0 ? "\u2014" : String(row[col.key])
|
|
257
|
+
},
|
|
258
|
+
col.key
|
|
259
|
+
))
|
|
260
|
+
},
|
|
261
|
+
i
|
|
262
|
+
)) })
|
|
263
|
+
] })
|
|
264
|
+
}
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
function StatRenderer({ payload, className }) {
|
|
268
|
+
const { stats, title } = payload;
|
|
269
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chunk5EGBIQYS_cjs.cn("csdk-genui-stat", className), children: [
|
|
270
|
+
title && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-2 text-sm font-semibold text-foreground", children: title }),
|
|
271
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
272
|
+
"div",
|
|
273
|
+
{
|
|
274
|
+
className: chunk5EGBIQYS_cjs.cn(
|
|
275
|
+
"grid gap-2",
|
|
276
|
+
stats.length === 1 && "grid-cols-1",
|
|
277
|
+
stats.length === 2 && "grid-cols-2",
|
|
278
|
+
stats.length >= 3 && "grid-cols-2 sm:grid-cols-3"
|
|
279
|
+
),
|
|
280
|
+
children: stats.map((stat, i) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
281
|
+
"div",
|
|
282
|
+
{
|
|
283
|
+
className: "flex flex-col gap-0.5 rounded-lg border border-border bg-card p-3",
|
|
284
|
+
children: [
|
|
285
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-xs text-muted-foreground", children: stat.label }),
|
|
286
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xl font-bold tabular-nums leading-tight text-foreground", children: stat.value }),
|
|
287
|
+
stat.change && /* @__PURE__ */ jsxRuntime.jsx(
|
|
288
|
+
"span",
|
|
289
|
+
{
|
|
290
|
+
className: chunk5EGBIQYS_cjs.cn(
|
|
291
|
+
"text-xs font-medium",
|
|
292
|
+
stat.changeDirection === "positive" && "text-green-600 dark:text-green-400",
|
|
293
|
+
stat.changeDirection === "negative" && "text-red-500 dark:text-red-400",
|
|
294
|
+
(!stat.changeDirection || stat.changeDirection === "neutral") && "text-muted-foreground"
|
|
295
|
+
),
|
|
296
|
+
children: stat.change
|
|
297
|
+
}
|
|
298
|
+
),
|
|
299
|
+
stat.description && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs leading-snug text-muted-foreground", children: stat.description })
|
|
300
|
+
]
|
|
301
|
+
},
|
|
302
|
+
i
|
|
303
|
+
))
|
|
304
|
+
}
|
|
305
|
+
)
|
|
306
|
+
] });
|
|
307
|
+
}
|
|
308
|
+
function CardRenderer({ payload, className }) {
|
|
309
|
+
const { title, subtitle, fields, body, cta } = payload;
|
|
310
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
311
|
+
"div",
|
|
312
|
+
{
|
|
313
|
+
className: chunk5EGBIQYS_cjs.cn(
|
|
314
|
+
"csdk-genui-card flex flex-col gap-3 rounded-lg border border-border bg-card p-4",
|
|
315
|
+
className
|
|
316
|
+
),
|
|
317
|
+
children: [
|
|
318
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
319
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-semibold leading-snug text-foreground", children: title }),
|
|
320
|
+
subtitle && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-0.5 text-xs text-muted-foreground", children: subtitle })
|
|
321
|
+
] }),
|
|
322
|
+
fields && fields.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("dl", { className: "grid grid-cols-[auto_1fr] gap-x-3 gap-y-1.5", children: fields.map((field, i) => /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
|
|
323
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "self-center whitespace-nowrap text-xs text-muted-foreground", children: field.label }),
|
|
324
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { className: "text-xs text-foreground", children: field.badge ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-flex items-center rounded-full border border-border bg-muted px-2 py-0.5 font-medium text-foreground", children: String(field.value) }) : String(field.value) })
|
|
325
|
+
] }, i)) }),
|
|
326
|
+
body && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs leading-relaxed text-muted-foreground", children: body }),
|
|
327
|
+
cta && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
328
|
+
"a",
|
|
329
|
+
{
|
|
330
|
+
href: cta.url,
|
|
331
|
+
target: "_blank",
|
|
332
|
+
rel: "noopener noreferrer",
|
|
333
|
+
className: "mt-1 inline-flex items-center gap-1 text-xs font-medium text-primary underline-offset-2 hover:underline",
|
|
334
|
+
children: [
|
|
335
|
+
cta.label,
|
|
336
|
+
" \u2197"
|
|
337
|
+
]
|
|
338
|
+
}
|
|
339
|
+
)
|
|
340
|
+
]
|
|
341
|
+
}
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
var HtmlPayloadSchema = zod.z.object({
|
|
345
|
+
type: zod.z.literal("html"),
|
|
346
|
+
html: zod.z.string().describe(
|
|
347
|
+
"Raw HTML string rendered in an isolated Shadow DOM with Tailwind CSS"
|
|
348
|
+
),
|
|
349
|
+
title: zod.z.string().optional().describe("Optional label shown above the component"),
|
|
350
|
+
height: zod.z.string().optional().describe("CSS height value e.g. '300px'. Defaults to auto.")
|
|
351
|
+
}).passthrough();
|
|
352
|
+
var ChartPayloadSchema = zod.z.object({
|
|
353
|
+
type: zod.z.literal("chart"),
|
|
354
|
+
chartType: zod.z.enum(["bar", "line", "pie", "area", "scatter"]).describe("Chart visualization type"),
|
|
355
|
+
title: zod.z.string().optional(),
|
|
356
|
+
labels: zod.z.array(zod.z.string()).describe("X-axis labels or category names"),
|
|
357
|
+
datasets: zod.z.array(
|
|
358
|
+
zod.z.object({
|
|
359
|
+
label: zod.z.string(),
|
|
360
|
+
data: zod.z.array(zod.z.number()),
|
|
361
|
+
color: zod.z.string().optional().describe("Hex or CSS color for this series")
|
|
362
|
+
})
|
|
363
|
+
).describe("One or more data series"),
|
|
364
|
+
xLabel: zod.z.string().optional().describe("X-axis label"),
|
|
365
|
+
yLabel: zod.z.string().optional().describe("Y-axis label")
|
|
366
|
+
}).passthrough();
|
|
367
|
+
var TablePayloadSchema = zod.z.object({
|
|
368
|
+
type: zod.z.literal("table"),
|
|
369
|
+
title: zod.z.string().optional(),
|
|
370
|
+
columns: zod.z.array(
|
|
371
|
+
zod.z.object({
|
|
372
|
+
key: zod.z.string(),
|
|
373
|
+
label: zod.z.string(),
|
|
374
|
+
align: zod.z.enum(["left", "right", "center"]).optional()
|
|
375
|
+
}).passthrough()
|
|
376
|
+
).describe("Column definitions \u2014 order controls render order"),
|
|
377
|
+
rows: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).describe("Row data keyed by column.key"),
|
|
378
|
+
caption: zod.z.string().optional()
|
|
379
|
+
}).passthrough();
|
|
380
|
+
var StatPayloadSchema = zod.z.object({
|
|
381
|
+
type: zod.z.literal("stat"),
|
|
382
|
+
title: zod.z.string().optional(),
|
|
383
|
+
stats: zod.z.array(
|
|
384
|
+
zod.z.object({
|
|
385
|
+
label: zod.z.string(),
|
|
386
|
+
value: zod.z.union([zod.z.string(), zod.z.number()]),
|
|
387
|
+
change: zod.z.string().optional().describe("e.g. '+12%' or '-3.4%'"),
|
|
388
|
+
changeDirection: zod.z.enum(["positive", "negative", "neutral"]).optional(),
|
|
389
|
+
description: zod.z.string().optional().describe("Sub-text below value")
|
|
390
|
+
}).passthrough()
|
|
391
|
+
)
|
|
392
|
+
}).passthrough();
|
|
393
|
+
var CardPayloadSchema = zod.z.object({
|
|
394
|
+
type: zod.z.literal("card"),
|
|
395
|
+
title: zod.z.string(),
|
|
396
|
+
subtitle: zod.z.string().optional(),
|
|
397
|
+
body: zod.z.string().optional(),
|
|
398
|
+
fields: zod.z.array(
|
|
399
|
+
zod.z.object({
|
|
400
|
+
label: zod.z.string(),
|
|
401
|
+
value: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]),
|
|
402
|
+
badge: zod.z.boolean().optional().describe("Render value as a badge pill")
|
|
403
|
+
})
|
|
404
|
+
).optional(),
|
|
405
|
+
cta: zod.z.object({
|
|
406
|
+
label: zod.z.string().optional(),
|
|
407
|
+
text: zod.z.string().optional(),
|
|
408
|
+
// LLMs sometimes use "text" instead of "label"
|
|
409
|
+
url: zod.z.string().describe("URL for the call-to-action link")
|
|
410
|
+
}).transform((c) => ({ ...c, label: c.label ?? c.text ?? "" })).optional()
|
|
411
|
+
}).passthrough();
|
|
412
|
+
var GenerativeUIPayloadSchema = zod.z.discriminatedUnion("type", [
|
|
413
|
+
HtmlPayloadSchema,
|
|
414
|
+
ChartPayloadSchema,
|
|
415
|
+
TablePayloadSchema,
|
|
416
|
+
StatPayloadSchema,
|
|
417
|
+
CardPayloadSchema
|
|
418
|
+
]);
|
|
419
|
+
var RENDER_UI_SCHEMA = {
|
|
420
|
+
type: "object",
|
|
421
|
+
properties: {
|
|
422
|
+
type: {
|
|
423
|
+
type: "string",
|
|
424
|
+
enum: ["html", "chart", "table", "stat", "card"],
|
|
425
|
+
description: "The UI component type to render"
|
|
426
|
+
},
|
|
427
|
+
// html
|
|
428
|
+
html: {
|
|
429
|
+
type: "string",
|
|
430
|
+
description: "Raw HTML with Tailwind classes (type=html only)"
|
|
431
|
+
},
|
|
432
|
+
height: {
|
|
433
|
+
type: "string",
|
|
434
|
+
description: "Optional CSS height (type=html only)"
|
|
435
|
+
},
|
|
436
|
+
// chart
|
|
437
|
+
chartType: {
|
|
438
|
+
type: "string",
|
|
439
|
+
enum: ["bar", "line", "pie", "area", "scatter"],
|
|
440
|
+
description: "Chart variant (type=chart only)"
|
|
441
|
+
},
|
|
442
|
+
labels: {
|
|
443
|
+
type: "array",
|
|
444
|
+
items: { type: "string" },
|
|
445
|
+
description: "X-axis labels (type=chart only)"
|
|
446
|
+
},
|
|
447
|
+
datasets: {
|
|
448
|
+
type: "array",
|
|
449
|
+
items: {
|
|
450
|
+
type: "object",
|
|
451
|
+
properties: {
|
|
452
|
+
label: { type: "string" },
|
|
453
|
+
data: { type: "array", items: { type: "number" } }
|
|
454
|
+
},
|
|
455
|
+
required: ["label", "data"]
|
|
456
|
+
},
|
|
457
|
+
description: "Data series array (type=chart only)"
|
|
458
|
+
},
|
|
459
|
+
xLabel: { type: "string" },
|
|
460
|
+
yLabel: { type: "string" },
|
|
461
|
+
// table
|
|
462
|
+
columns: {
|
|
463
|
+
type: "array",
|
|
464
|
+
items: {
|
|
465
|
+
type: "object",
|
|
466
|
+
properties: {
|
|
467
|
+
key: { type: "string" },
|
|
468
|
+
label: { type: "string" },
|
|
469
|
+
align: { type: "string", enum: ["left", "right", "center"] }
|
|
470
|
+
},
|
|
471
|
+
required: ["key", "label"]
|
|
472
|
+
},
|
|
473
|
+
description: "Column definitions \u2014 key matches row property names (type=table only)"
|
|
474
|
+
},
|
|
475
|
+
rows: {
|
|
476
|
+
type: "array",
|
|
477
|
+
items: { type: "object" },
|
|
478
|
+
description: "Row objects keyed by column.key values (type=table only)"
|
|
479
|
+
},
|
|
480
|
+
caption: { type: "string" },
|
|
481
|
+
// stat
|
|
482
|
+
stats: {
|
|
483
|
+
type: "array",
|
|
484
|
+
items: {
|
|
485
|
+
type: "object",
|
|
486
|
+
properties: {
|
|
487
|
+
label: { type: "string" },
|
|
488
|
+
value: { type: "string" },
|
|
489
|
+
change: { type: "string" },
|
|
490
|
+
changeDirection: {
|
|
491
|
+
type: "string",
|
|
492
|
+
enum: ["positive", "negative", "neutral"]
|
|
493
|
+
},
|
|
494
|
+
description: { type: "string" }
|
|
495
|
+
},
|
|
496
|
+
required: ["label", "value"]
|
|
497
|
+
},
|
|
498
|
+
description: "KPI stats array (type=stat only)"
|
|
499
|
+
},
|
|
500
|
+
// card
|
|
501
|
+
title: { type: "string", description: "Card or table title" },
|
|
502
|
+
subtitle: { type: "string" },
|
|
503
|
+
body: { type: "string" },
|
|
504
|
+
fields: {
|
|
505
|
+
type: "array",
|
|
506
|
+
items: {
|
|
507
|
+
type: "object",
|
|
508
|
+
properties: {
|
|
509
|
+
label: { type: "string" },
|
|
510
|
+
value: { type: "string" },
|
|
511
|
+
badge: { type: "boolean" }
|
|
512
|
+
},
|
|
513
|
+
required: ["label", "value"]
|
|
514
|
+
},
|
|
515
|
+
description: "Key-value fields (type=card only)"
|
|
516
|
+
},
|
|
517
|
+
cta: {
|
|
518
|
+
type: "object",
|
|
519
|
+
properties: {
|
|
520
|
+
label: { type: "string" },
|
|
521
|
+
url: { type: "string" }
|
|
522
|
+
},
|
|
523
|
+
required: ["label", "url"],
|
|
524
|
+
description: "Call-to-action link (type=card only)"
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
required: ["type"]
|
|
528
|
+
};
|
|
529
|
+
function useGenerativeUI(config = {}) {
|
|
530
|
+
const toolName = config.name ?? "render_ui";
|
|
531
|
+
const configRef = React__namespace.useRef(config);
|
|
532
|
+
configRef.current = config;
|
|
533
|
+
chunk2QLF7XM7_cjs.useTool({
|
|
534
|
+
name: toolName,
|
|
535
|
+
description: "Renders a rich UI component inline in the chat. Handled automatically by the SDK.",
|
|
536
|
+
inputSchema: RENDER_UI_SCHEMA,
|
|
537
|
+
hidden: false,
|
|
538
|
+
aiResponseMode: "none",
|
|
539
|
+
aiContext: (_, args) => {
|
|
540
|
+
const type = args?.type ?? "ui";
|
|
541
|
+
return `[Rendered ${type} component to user]`;
|
|
542
|
+
},
|
|
543
|
+
handler: async (params) => {
|
|
544
|
+
const raw = params && typeof params === "object" && "data" in params ? params.data : params;
|
|
545
|
+
const parsed = GenerativeUIPayloadSchema.safeParse(raw);
|
|
546
|
+
if (!parsed.success) {
|
|
547
|
+
return {
|
|
548
|
+
success: false,
|
|
549
|
+
error: `Invalid generative UI payload: ${parsed.error.message}`
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
return {
|
|
553
|
+
success: true,
|
|
554
|
+
data: parsed.data,
|
|
555
|
+
_aiContext: `[Rendered ${parsed.data.type} component to user]`,
|
|
556
|
+
_aiResponseMode: "none"
|
|
557
|
+
};
|
|
558
|
+
},
|
|
559
|
+
render: (props) => /* @__PURE__ */ jsxRuntime.jsx(GenerativeUIRenderer, { props, configRef })
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
function GenerativeUIRenderer({
|
|
563
|
+
props: renderProps,
|
|
564
|
+
configRef
|
|
565
|
+
}) {
|
|
566
|
+
const { status, result, error } = renderProps;
|
|
567
|
+
const config = configRef.current;
|
|
568
|
+
if (status === "pending" || status === "executing") {
|
|
569
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 py-1.5 text-sm text-muted-foreground", children: [
|
|
570
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunk5EGBIQYS_cjs.DotsLoader, { size: "sm" }),
|
|
571
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "Preparing response\u2026" })
|
|
572
|
+
] });
|
|
573
|
+
}
|
|
574
|
+
if (status === "error") {
|
|
575
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive", children: error ?? "Failed to render UI component." });
|
|
576
|
+
}
|
|
577
|
+
if (status !== "completed") return null;
|
|
578
|
+
const rawPayload = result?.data;
|
|
579
|
+
const parsed = GenerativeUIPayloadSchema.safeParse(rawPayload);
|
|
580
|
+
if (!parsed.success) {
|
|
581
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-auto rounded-md border border-border bg-muted/30 px-3 py-2", children: /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap text-xs text-muted-foreground", children: JSON.stringify(rawPayload, null, 2) }) });
|
|
582
|
+
}
|
|
583
|
+
const payload = parsed.data;
|
|
584
|
+
switch (payload.type) {
|
|
585
|
+
case "html": {
|
|
586
|
+
const Override = config.overrideRenderers?.html;
|
|
587
|
+
return Override ? /* @__PURE__ */ jsxRuntime.jsx(Override, { payload }) : /* @__PURE__ */ jsxRuntime.jsx(HtmlRenderer, { payload });
|
|
588
|
+
}
|
|
589
|
+
case "chart": {
|
|
590
|
+
const ChartComp = config.overrideRenderers?.chart ?? config.chartRenderer;
|
|
591
|
+
return ChartComp ? /* @__PURE__ */ jsxRuntime.jsx(ChartComp, { payload }) : /* @__PURE__ */ jsxRuntime.jsx(ChartFallback, { payload });
|
|
592
|
+
}
|
|
593
|
+
case "table": {
|
|
594
|
+
const Override = config.overrideRenderers?.table;
|
|
595
|
+
return Override ? /* @__PURE__ */ jsxRuntime.jsx(Override, { payload }) : /* @__PURE__ */ jsxRuntime.jsx(TableRenderer, { payload });
|
|
596
|
+
}
|
|
597
|
+
case "stat": {
|
|
598
|
+
const Override = config.overrideRenderers?.stat;
|
|
599
|
+
return Override ? /* @__PURE__ */ jsxRuntime.jsx(Override, { payload }) : /* @__PURE__ */ jsxRuntime.jsx(StatRenderer, { payload });
|
|
600
|
+
}
|
|
601
|
+
case "card": {
|
|
602
|
+
const Override = config.overrideRenderers?.card;
|
|
603
|
+
return Override ? /* @__PURE__ */ jsxRuntime.jsx(Override, { payload }) : /* @__PURE__ */ jsxRuntime.jsx(CardRenderer, { payload });
|
|
604
|
+
}
|
|
605
|
+
default:
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function ChartFallback({ payload }) {
|
|
610
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md border border-border bg-muted/20 p-3", children: [
|
|
611
|
+
payload.title && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1.5 text-sm font-medium text-foreground", children: payload.title }),
|
|
612
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mb-2 text-xs text-muted-foreground", children: [
|
|
613
|
+
"Chart type:",
|
|
614
|
+
" ",
|
|
615
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "rounded bg-muted px-1 py-0.5 font-mono text-xs", children: payload.chartType }),
|
|
616
|
+
". Pass a ",
|
|
617
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "font-mono", children: "chartRenderer" }),
|
|
618
|
+
" prop to",
|
|
619
|
+
" ",
|
|
620
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "font-mono", children: "useGenerativeUI()" }),
|
|
621
|
+
" to render this."
|
|
622
|
+
] }),
|
|
623
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { className: "max-h-40 overflow-auto whitespace-pre-wrap text-xs text-muted-foreground font-mono", children: JSON.stringify(
|
|
624
|
+
{ labels: payload.labels, datasets: payload.datasets },
|
|
625
|
+
null,
|
|
626
|
+
2
|
|
627
|
+
) })
|
|
628
|
+
] });
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
exports.CardPayloadSchema = CardPayloadSchema;
|
|
632
|
+
exports.CardRenderer = CardRenderer;
|
|
633
|
+
exports.ChartPayloadSchema = ChartPayloadSchema;
|
|
634
|
+
exports.GenerativeUIPayloadSchema = GenerativeUIPayloadSchema;
|
|
635
|
+
exports.HtmlPayloadSchema = HtmlPayloadSchema;
|
|
636
|
+
exports.HtmlRenderer = HtmlRenderer;
|
|
637
|
+
exports.StatPayloadSchema = StatPayloadSchema;
|
|
638
|
+
exports.StatRenderer = StatRenderer;
|
|
639
|
+
exports.TablePayloadSchema = TablePayloadSchema;
|
|
640
|
+
exports.TableRenderer = TableRenderer;
|
|
641
|
+
exports.generativeUITool = generativeUITool;
|
|
642
|
+
exports.useGenerativeUI = useGenerativeUI;
|
|
643
|
+
//# sourceMappingURL=index.cjs.map
|
|
644
|
+
//# sourceMappingURL=index.cjs.map
|