dreamboard 0.1.21 → 0.1.23

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.
Files changed (186) hide show
  1. package/dist/{chunk-EYYWGWTO.js → chunk-2RCUHMGL.js} +343 -1911
  2. package/dist/chunk-2RCUHMGL.js.map +1 -0
  3. package/dist/{chunk-MOVHYB6E.js → chunk-GN7232BY.js} +1025 -695
  4. package/dist/chunk-GN7232BY.js.map +1 -0
  5. package/dist/{chunk-BMYC6772.js → chunk-H3O43F5P.js} +9765 -3068
  6. package/dist/chunk-H3O43F5P.js.map +1 -0
  7. package/dist/dev-host/dev-api-proxy-plugin.ts +330 -0
  8. package/dist/dev-host/dev-diagnostics.ts +62 -0
  9. package/dist/dev-host/dev-fallback-stylesheet.ts +50 -0
  10. package/dist/dev-host/dev-host-controller.ts +686 -0
  11. package/dist/dev-host/dev-host-player-query.ts +17 -0
  12. package/dist/dev-host/dev-host-session-transport.ts +52 -0
  13. package/dist/dev-host/dev-host-storage.ts +56 -0
  14. package/dist/dev-host/dev-log-relay-plugin.ts +469 -0
  15. package/dist/dev-host/dev-runtime-config.ts +14 -0
  16. package/dist/dev-host/dev-runtime-platform.ts +419 -0
  17. package/dist/dev-host/dev-virtual-modules-plugin.ts +63 -0
  18. package/dist/dev-host/host-main.css +182 -0
  19. package/dist/dev-host/host-main.tsx +754 -0
  20. package/dist/dev-host/index.html +56 -0
  21. package/dist/dev-host/plugin-main.ts +55 -0
  22. package/dist/dev-host/plugin.html +24 -0
  23. package/dist/dev-host/start-dev-server.ts +138 -0
  24. package/dist/dev-host/virtual-modules.d.ts +27 -0
  25. package/dist/dist-FEPN3BDN.js +16543 -0
  26. package/dist/dist-FEPN3BDN.js.map +1 -0
  27. package/dist/{dist-WJRJNFLI.js → dist-FRURQI7Q.js} +4 -2
  28. package/dist/index.js +3 -3
  29. package/dist/internal.js +159 -124
  30. package/dist/internal.js.map +1 -1
  31. package/dist/runtime-packages/tailwind-config/shared-styles.css +146 -0
  32. package/dist/runtime-packages/ui/src/components/.gitkeep +0 -0
  33. package/dist/runtime-packages/ui/src/components/accordion.tsx +66 -0
  34. package/dist/runtime-packages/ui/src/components/ai-elements/actions.tsx +65 -0
  35. package/dist/runtime-packages/ui/src/components/ai-elements/artifact.tsx +147 -0
  36. package/dist/runtime-packages/ui/src/components/ai-elements/branch.tsx +215 -0
  37. package/dist/runtime-packages/ui/src/components/ai-elements/canvas.tsx +22 -0
  38. package/dist/runtime-packages/ui/src/components/ai-elements/chain-of-thought.tsx +228 -0
  39. package/dist/runtime-packages/ui/src/components/ai-elements/code-block.tsx +179 -0
  40. package/dist/runtime-packages/ui/src/components/ai-elements/confirmation.tsx +158 -0
  41. package/dist/runtime-packages/ui/src/components/ai-elements/connection.tsx +28 -0
  42. package/dist/runtime-packages/ui/src/components/ai-elements/context.tsx +408 -0
  43. package/dist/runtime-packages/ui/src/components/ai-elements/controls.tsx +18 -0
  44. package/dist/runtime-packages/ui/src/components/ai-elements/conversation.tsx +97 -0
  45. package/dist/runtime-packages/ui/src/components/ai-elements/edge.tsx +140 -0
  46. package/dist/runtime-packages/ui/src/components/ai-elements/image.tsx +24 -0
  47. package/dist/runtime-packages/ui/src/components/ai-elements/inline-citation.tsx +287 -0
  48. package/dist/runtime-packages/ui/src/components/ai-elements/loader.tsx +96 -0
  49. package/dist/runtime-packages/ui/src/components/ai-elements/message.tsx +463 -0
  50. package/dist/runtime-packages/ui/src/components/ai-elements/node.tsx +71 -0
  51. package/dist/runtime-packages/ui/src/components/ai-elements/open-in-chat.tsx +365 -0
  52. package/dist/runtime-packages/ui/src/components/ai-elements/panel.tsx +15 -0
  53. package/dist/runtime-packages/ui/src/components/ai-elements/plan.tsx +142 -0
  54. package/dist/runtime-packages/ui/src/components/ai-elements/prompt-input.tsx +1380 -0
  55. package/dist/runtime-packages/ui/src/components/ai-elements/queue.tsx +274 -0
  56. package/dist/runtime-packages/ui/src/components/ai-elements/reasoning.tsx +182 -0
  57. package/dist/runtime-packages/ui/src/components/ai-elements/response.tsx +22 -0
  58. package/dist/runtime-packages/ui/src/components/ai-elements/shimmer.tsx +64 -0
  59. package/dist/runtime-packages/ui/src/components/ai-elements/sources.tsx +77 -0
  60. package/dist/runtime-packages/ui/src/components/ai-elements/suggestion.tsx +53 -0
  61. package/dist/runtime-packages/ui/src/components/ai-elements/task.tsx +87 -0
  62. package/dist/runtime-packages/ui/src/components/ai-elements/tool.tsx +165 -0
  63. package/dist/runtime-packages/ui/src/components/ai-elements/toolbar.tsx +16 -0
  64. package/dist/runtime-packages/ui/src/components/ai-elements/web-preview.tsx +263 -0
  65. package/dist/runtime-packages/ui/src/components/alert-dialog.tsx +157 -0
  66. package/dist/runtime-packages/ui/src/components/alert.tsx +66 -0
  67. package/dist/runtime-packages/ui/src/components/avatar.tsx +53 -0
  68. package/dist/runtime-packages/ui/src/components/badge.tsx +46 -0
  69. package/dist/runtime-packages/ui/src/components/button-group.tsx +83 -0
  70. package/dist/runtime-packages/ui/src/components/button.tsx +65 -0
  71. package/dist/runtime-packages/ui/src/components/card.tsx +92 -0
  72. package/dist/runtime-packages/ui/src/components/carousel.tsx +241 -0
  73. package/dist/runtime-packages/ui/src/components/collapsible.tsx +33 -0
  74. package/dist/runtime-packages/ui/src/components/command.tsx +184 -0
  75. package/dist/runtime-packages/ui/src/components/context-menu.tsx +252 -0
  76. package/dist/runtime-packages/ui/src/components/counter.tsx +11 -0
  77. package/dist/runtime-packages/ui/src/components/dialog.tsx +146 -0
  78. package/dist/runtime-packages/ui/src/components/drawer.tsx +132 -0
  79. package/dist/runtime-packages/ui/src/components/dropdown-menu.tsx +257 -0
  80. package/dist/runtime-packages/ui/src/components/form.tsx +168 -0
  81. package/dist/runtime-packages/ui/src/components/header.tsx +13 -0
  82. package/dist/runtime-packages/ui/src/components/hover-card.tsx +44 -0
  83. package/dist/runtime-packages/ui/src/components/input-group.tsx +178 -0
  84. package/dist/runtime-packages/ui/src/components/input.tsx +21 -0
  85. package/dist/runtime-packages/ui/src/components/item.tsx +193 -0
  86. package/dist/runtime-packages/ui/src/components/label.tsx +24 -0
  87. package/dist/runtime-packages/ui/src/components/navigation-menu.tsx +168 -0
  88. package/dist/runtime-packages/ui/src/components/popover.tsx +55 -0
  89. package/dist/runtime-packages/ui/src/components/progress.tsx +31 -0
  90. package/dist/runtime-packages/ui/src/components/radio-group.tsx +45 -0
  91. package/dist/runtime-packages/ui/src/components/resizable.tsx +56 -0
  92. package/dist/runtime-packages/ui/src/components/scroll-area.tsx +58 -0
  93. package/dist/runtime-packages/ui/src/components/select.tsx +187 -0
  94. package/dist/runtime-packages/ui/src/components/separator.tsx +28 -0
  95. package/dist/runtime-packages/ui/src/components/skeleton.tsx +13 -0
  96. package/dist/runtime-packages/ui/src/components/sonner.tsx +25 -0
  97. package/dist/runtime-packages/ui/src/components/spinner.tsx +16 -0
  98. package/dist/runtime-packages/ui/src/components/switch.tsx +31 -0
  99. package/dist/runtime-packages/ui/src/components/table.tsx +137 -0
  100. package/dist/runtime-packages/ui/src/components/tabs.tsx +74 -0
  101. package/dist/runtime-packages/ui/src/components/textarea.tsx +23 -0
  102. package/dist/runtime-packages/ui/src/components/theme-provider.tsx +73 -0
  103. package/dist/runtime-packages/ui/src/components/tooltip.tsx +61 -0
  104. package/dist/runtime-packages/ui/src/components/ui/file-upload.tsx +195 -0
  105. package/dist/runtime-packages/ui/src/hooks/.gitkeep +0 -0
  106. package/dist/runtime-packages/ui/src/index.ts +68 -0
  107. package/dist/runtime-packages/ui/src/lib/utils.ts +6 -0
  108. package/dist/runtime-packages/ui-host-runtime/src/actor-principal.ts +68 -0
  109. package/dist/runtime-packages/ui-host-runtime/src/components/host-controls.tsx +359 -0
  110. package/dist/runtime-packages/ui-host-runtime/src/components/host-feedback-toaster.tsx +274 -0
  111. package/dist/runtime-packages/ui-host-runtime/src/components/host-feedback.tsx +214 -0
  112. package/dist/runtime-packages/ui-host-runtime/src/components/host-session-metadata.tsx +135 -0
  113. package/dist/runtime-packages/ui-host-runtime/src/components/index.ts +5 -0
  114. package/dist/runtime-packages/ui-host-runtime/src/components/perf-overlay.tsx +194 -0
  115. package/dist/runtime-packages/ui-host-runtime/src/host-controls.tsx +1 -0
  116. package/dist/runtime-packages/ui-host-runtime/src/host-feedback.tsx +1 -0
  117. package/dist/runtime-packages/ui-host-runtime/src/host-session-transport.ts +162 -0
  118. package/dist/runtime-packages/ui-host-runtime/src/index.ts +2 -0
  119. package/dist/runtime-packages/ui-host-runtime/src/logger.ts +11 -0
  120. package/dist/runtime-packages/ui-host-runtime/src/perf.ts +253 -0
  121. package/dist/runtime-packages/ui-host-runtime/src/plugin-bridge.ts +195 -0
  122. package/dist/runtime-packages/ui-host-runtime/src/plugin-health-check.ts +138 -0
  123. package/dist/runtime-packages/ui-host-runtime/src/plugin-messages.ts +159 -0
  124. package/dist/runtime-packages/ui-host-runtime/src/plugin-session-gateway.ts +524 -0
  125. package/dist/runtime-packages/ui-host-runtime/src/runtime/index.ts +12 -0
  126. package/dist/runtime-packages/ui-host-runtime/src/screenshot/projection-to-snapshot.ts +122 -0
  127. package/dist/runtime-packages/ui-host-runtime/src/screenshot/static-store-api.ts +26 -0
  128. package/dist/runtime-packages/ui-host-runtime/src/session-ingress-controller.ts +477 -0
  129. package/dist/runtime-packages/ui-host-runtime/src/session-ingress.ts +209 -0
  130. package/dist/runtime-packages/ui-host-runtime/src/session-live-runtime.ts +112 -0
  131. package/dist/runtime-packages/ui-host-runtime/src/session-model.ts +318 -0
  132. package/dist/runtime-packages/ui-host-runtime/src/session-projection.ts +211 -0
  133. package/dist/runtime-packages/ui-host-runtime/src/session-state-reducer.ts +814 -0
  134. package/dist/runtime-packages/ui-host-runtime/src/sse-manager.ts +334 -0
  135. package/dist/runtime-packages/ui-host-runtime/src/unified-session-store.ts +180 -0
  136. package/dist/scaffold/assets/static/app/tsconfig.framework.json +3 -1
  137. package/dist/scaffold/assets/static/ui/tsconfig.framework.json +7 -19
  138. package/package.json +52 -17
  139. package/skills/dreamboard/SKILL.md +41 -75
  140. package/LICENSE +0 -89
  141. package/NOTICE +0 -1
  142. package/dist/chunk-BMYC6772.js.map +0 -1
  143. package/dist/chunk-EYYWGWTO.js.map +0 -1
  144. package/dist/chunk-MOVHYB6E.js.map +0 -1
  145. package/dist/scaffold/assets/static/ui/App.tsx +0 -22
  146. package/dist/src-CUL7EGGG.js +0 -634
  147. package/dist/src-CUL7EGGG.js.map +0 -1
  148. package/skills/dreamboard/references/authoring-lifecycle.md +0 -102
  149. package/skills/dreamboard/references/board-surfaces.md +0 -36
  150. package/skills/dreamboard/references/board-topology.md +0 -443
  151. package/skills/dreamboard/references/boards-and-topology.md +0 -100
  152. package/skills/dreamboard/references/card-actions.md +0 -107
  153. package/skills/dreamboard/references/cli.md +0 -120
  154. package/skills/dreamboard/references/core-concepts.md +0 -514
  155. package/skills/dreamboard/references/custom-renderers.md +0 -26
  156. package/skills/dreamboard/references/derived-values.md +0 -55
  157. package/skills/dreamboard/references/effects.md +0 -111
  158. package/skills/dreamboard/references/game-contract.md +0 -89
  159. package/skills/dreamboard/references/game-definition.md +0 -89
  160. package/skills/dreamboard/references/game-shell.md +0 -80
  161. package/skills/dreamboard/references/hand-surfaces.md +0 -33
  162. package/skills/dreamboard/references/index.md +0 -112
  163. package/skills/dreamboard/references/inputs-and-targets.md +0 -160
  164. package/skills/dreamboard/references/interactions.md +0 -158
  165. package/skills/dreamboard/references/manifest-fields.md +0 -137
  166. package/skills/dreamboard/references/manifest.md +0 -81
  167. package/skills/dreamboard/references/package-surfaces.md +0 -69
  168. package/skills/dreamboard/references/phases.md +0 -145
  169. package/skills/dreamboard/references/prompts-and-choices.md +0 -55
  170. package/skills/dreamboard/references/quickstart.md +0 -71
  171. package/skills/dreamboard/references/rule-authoring.md +0 -144
  172. package/skills/dreamboard/references/setup-bootstrap.md +0 -78
  173. package/skills/dreamboard/references/stages-and-zones.md +0 -59
  174. package/skills/dreamboard/references/static-views.md +0 -67
  175. package/skills/dreamboard/references/table-queries-and-ops.md +0 -103
  176. package/skills/dreamboard/references/testing-bases.md +0 -147
  177. package/skills/dreamboard/references/testing-generated-contracts.md +0 -142
  178. package/skills/dreamboard/references/testing-runtime-assertions.md +0 -124
  179. package/skills/dreamboard/references/testing-scenarios.md +0 -148
  180. package/skills/dreamboard/references/testing-ui-tests.md +0 -174
  181. package/skills/dreamboard/references/testing.md +0 -161
  182. package/skills/dreamboard/references/ui-architecture.md +0 -137
  183. package/skills/dreamboard/references/ui-components.md +0 -34
  184. package/skills/dreamboard/references/views.md +0 -72
  185. package/skills/dreamboard/references/workspace-layout.md +0 -136
  186. /package/dist/{dist-WJRJNFLI.js.map → dist-FRURQI7Q.js.map} +0 -0
@@ -0,0 +1,408 @@
1
+ "use client";
2
+
3
+ import { Button } from "@dreamboard/ui/components/button";
4
+ import {
5
+ HoverCard,
6
+ HoverCardContent,
7
+ HoverCardTrigger,
8
+ } from "@dreamboard/ui/components/hover-card";
9
+ import { Progress } from "@dreamboard/ui/components/progress";
10
+ import { cn } from "@dreamboard/ui/lib/utils";
11
+ import type { LanguageModelUsage } from "ai";
12
+ import { type ComponentProps, createContext, useContext } from "react";
13
+ import { getUsage } from "tokenlens";
14
+
15
+ const PERCENT_MAX = 100;
16
+ const ICON_RADIUS = 10;
17
+ const ICON_VIEWBOX = 24;
18
+ const ICON_CENTER = 12;
19
+ const ICON_STROKE_WIDTH = 2;
20
+
21
+ type ModelId = string;
22
+
23
+ interface ContextSchema {
24
+ usedTokens: number;
25
+ maxTokens: number;
26
+ usage?: LanguageModelUsage;
27
+ modelId?: ModelId;
28
+ }
29
+
30
+ const ContextContext = createContext<ContextSchema | null>(null);
31
+
32
+ const useContextValue = () => {
33
+ const context = useContext(ContextContext);
34
+
35
+ if (!context) {
36
+ throw new Error("Context components must be used within Context");
37
+ }
38
+
39
+ return context;
40
+ };
41
+
42
+ export type ContextProps = ComponentProps<typeof HoverCard> & ContextSchema;
43
+
44
+ export const Context = ({
45
+ usedTokens,
46
+ maxTokens,
47
+ usage,
48
+ modelId,
49
+ ...props
50
+ }: ContextProps) => (
51
+ <ContextContext.Provider
52
+ value={{
53
+ usedTokens,
54
+ maxTokens,
55
+ usage,
56
+ modelId,
57
+ }}
58
+ >
59
+ <HoverCard closeDelay={0} openDelay={0} {...props} />
60
+ </ContextContext.Provider>
61
+ );
62
+
63
+ const ContextIcon = () => {
64
+ const { usedTokens, maxTokens } = useContextValue();
65
+ const circumference = 2 * Math.PI * ICON_RADIUS;
66
+ const usedPercent = usedTokens / maxTokens;
67
+ const dashOffset = circumference * (1 - usedPercent);
68
+
69
+ return (
70
+ <svg
71
+ aria-label="Model context usage"
72
+ height="20"
73
+ role="img"
74
+ style={{ color: "currentcolor" }}
75
+ viewBox={`0 0 ${ICON_VIEWBOX} ${ICON_VIEWBOX}`}
76
+ width="20"
77
+ >
78
+ <circle
79
+ cx={ICON_CENTER}
80
+ cy={ICON_CENTER}
81
+ fill="none"
82
+ opacity="0.25"
83
+ r={ICON_RADIUS}
84
+ stroke="currentColor"
85
+ strokeWidth={ICON_STROKE_WIDTH}
86
+ />
87
+ <circle
88
+ cx={ICON_CENTER}
89
+ cy={ICON_CENTER}
90
+ fill="none"
91
+ opacity="0.7"
92
+ r={ICON_RADIUS}
93
+ stroke="currentColor"
94
+ strokeDasharray={`${circumference} ${circumference}`}
95
+ strokeDashoffset={dashOffset}
96
+ strokeLinecap="round"
97
+ strokeWidth={ICON_STROKE_WIDTH}
98
+ style={{ transformOrigin: "center", transform: "rotate(-90deg)" }}
99
+ />
100
+ </svg>
101
+ );
102
+ };
103
+
104
+ export type ContextTriggerProps = ComponentProps<typeof Button>;
105
+
106
+ export const ContextTrigger = ({ children, ...props }: ContextTriggerProps) => {
107
+ const { usedTokens, maxTokens } = useContextValue();
108
+ const usedPercent = usedTokens / maxTokens;
109
+ const renderedPercent = new Intl.NumberFormat("en-US", {
110
+ style: "percent",
111
+ maximumFractionDigits: 1,
112
+ }).format(usedPercent);
113
+
114
+ return (
115
+ <HoverCardTrigger asChild>
116
+ {children ?? (
117
+ <Button type="button" variant="ghost" {...props}>
118
+ <span className="font-medium text-muted-foreground">
119
+ {renderedPercent}
120
+ </span>
121
+ <ContextIcon />
122
+ </Button>
123
+ )}
124
+ </HoverCardTrigger>
125
+ );
126
+ };
127
+
128
+ export type ContextContentProps = ComponentProps<typeof HoverCardContent>;
129
+
130
+ export const ContextContent = ({
131
+ className,
132
+ ...props
133
+ }: ContextContentProps) => (
134
+ <HoverCardContent
135
+ className={cn("min-w-60 divide-y overflow-hidden p-0", className)}
136
+ {...props}
137
+ />
138
+ );
139
+
140
+ export type ContextContentHeaderProps = ComponentProps<"div">;
141
+
142
+ export const ContextContentHeader = ({
143
+ children,
144
+ className,
145
+ ...props
146
+ }: ContextContentHeaderProps) => {
147
+ const { usedTokens, maxTokens } = useContextValue();
148
+ const usedPercent = usedTokens / maxTokens;
149
+ const displayPct = new Intl.NumberFormat("en-US", {
150
+ style: "percent",
151
+ maximumFractionDigits: 1,
152
+ }).format(usedPercent);
153
+ const used = new Intl.NumberFormat("en-US", {
154
+ notation: "compact",
155
+ }).format(usedTokens);
156
+ const total = new Intl.NumberFormat("en-US", {
157
+ notation: "compact",
158
+ }).format(maxTokens);
159
+
160
+ return (
161
+ <div className={cn("w-full space-y-2 p-3", className)} {...props}>
162
+ {children ?? (
163
+ <>
164
+ <div className="flex items-center justify-between gap-3 text-xs">
165
+ <p>{displayPct}</p>
166
+ <p className="font-mono text-muted-foreground">
167
+ {used} / {total}
168
+ </p>
169
+ </div>
170
+ <div className="space-y-2">
171
+ <Progress className="bg-muted" value={usedPercent * PERCENT_MAX} />
172
+ </div>
173
+ </>
174
+ )}
175
+ </div>
176
+ );
177
+ };
178
+
179
+ export type ContextContentBodyProps = ComponentProps<"div">;
180
+
181
+ export const ContextContentBody = ({
182
+ children,
183
+ className,
184
+ ...props
185
+ }: ContextContentBodyProps) => (
186
+ <div className={cn("w-full p-3", className)} {...props}>
187
+ {children}
188
+ </div>
189
+ );
190
+
191
+ export type ContextContentFooterProps = ComponentProps<"div">;
192
+
193
+ export const ContextContentFooter = ({
194
+ children,
195
+ className,
196
+ ...props
197
+ }: ContextContentFooterProps) => {
198
+ const { modelId, usage } = useContextValue();
199
+ const costUSD = modelId
200
+ ? getUsage({
201
+ modelId,
202
+ usage: {
203
+ input: usage?.inputTokens ?? 0,
204
+ output: usage?.outputTokens ?? 0,
205
+ },
206
+ }).costUSD?.totalUSD
207
+ : undefined;
208
+ const totalCost = new Intl.NumberFormat("en-US", {
209
+ style: "currency",
210
+ currency: "USD",
211
+ }).format(costUSD ?? 0);
212
+
213
+ return (
214
+ <div
215
+ className={cn(
216
+ "flex w-full items-center justify-between gap-3 bg-secondary p-3 text-xs",
217
+ className,
218
+ )}
219
+ {...props}
220
+ >
221
+ {children ?? (
222
+ <>
223
+ <span className="text-muted-foreground">Total cost</span>
224
+ <span>{totalCost}</span>
225
+ </>
226
+ )}
227
+ </div>
228
+ );
229
+ };
230
+
231
+ export type ContextInputUsageProps = ComponentProps<"div">;
232
+
233
+ export const ContextInputUsage = ({
234
+ className,
235
+ children,
236
+ ...props
237
+ }: ContextInputUsageProps) => {
238
+ const { usage, modelId } = useContextValue();
239
+ const inputTokens = usage?.inputTokens ?? 0;
240
+
241
+ if (children) {
242
+ return children;
243
+ }
244
+
245
+ if (!inputTokens) {
246
+ return null;
247
+ }
248
+
249
+ const inputCost = modelId
250
+ ? getUsage({
251
+ modelId,
252
+ usage: { input: inputTokens, output: 0 },
253
+ }).costUSD?.totalUSD
254
+ : undefined;
255
+ const inputCostText = new Intl.NumberFormat("en-US", {
256
+ style: "currency",
257
+ currency: "USD",
258
+ }).format(inputCost ?? 0);
259
+
260
+ return (
261
+ <div
262
+ className={cn("flex items-center justify-between text-xs", className)}
263
+ {...props}
264
+ >
265
+ <span className="text-muted-foreground">Input</span>
266
+ <TokensWithCost costText={inputCostText} tokens={inputTokens} />
267
+ </div>
268
+ );
269
+ };
270
+
271
+ export type ContextOutputUsageProps = ComponentProps<"div">;
272
+
273
+ export const ContextOutputUsage = ({
274
+ className,
275
+ children,
276
+ ...props
277
+ }: ContextOutputUsageProps) => {
278
+ const { usage, modelId } = useContextValue();
279
+ const outputTokens = usage?.outputTokens ?? 0;
280
+
281
+ if (children) {
282
+ return children;
283
+ }
284
+
285
+ if (!outputTokens) {
286
+ return null;
287
+ }
288
+
289
+ const outputCost = modelId
290
+ ? getUsage({
291
+ modelId,
292
+ usage: { input: 0, output: outputTokens },
293
+ }).costUSD?.totalUSD
294
+ : undefined;
295
+ const outputCostText = new Intl.NumberFormat("en-US", {
296
+ style: "currency",
297
+ currency: "USD",
298
+ }).format(outputCost ?? 0);
299
+
300
+ return (
301
+ <div
302
+ className={cn("flex items-center justify-between text-xs", className)}
303
+ {...props}
304
+ >
305
+ <span className="text-muted-foreground">Output</span>
306
+ <TokensWithCost costText={outputCostText} tokens={outputTokens} />
307
+ </div>
308
+ );
309
+ };
310
+
311
+ export type ContextReasoningUsageProps = ComponentProps<"div">;
312
+
313
+ export const ContextReasoningUsage = ({
314
+ className,
315
+ children,
316
+ ...props
317
+ }: ContextReasoningUsageProps) => {
318
+ const { usage, modelId } = useContextValue();
319
+ const reasoningTokens = usage?.reasoningTokens ?? 0;
320
+
321
+ if (children) {
322
+ return children;
323
+ }
324
+
325
+ if (!reasoningTokens) {
326
+ return null;
327
+ }
328
+
329
+ const reasoningCost = modelId
330
+ ? getUsage({
331
+ modelId,
332
+ usage: { reasoningTokens },
333
+ }).costUSD?.totalUSD
334
+ : undefined;
335
+ const reasoningCostText = new Intl.NumberFormat("en-US", {
336
+ style: "currency",
337
+ currency: "USD",
338
+ }).format(reasoningCost ?? 0);
339
+
340
+ return (
341
+ <div
342
+ className={cn("flex items-center justify-between text-xs", className)}
343
+ {...props}
344
+ >
345
+ <span className="text-muted-foreground">Reasoning</span>
346
+ <TokensWithCost costText={reasoningCostText} tokens={reasoningTokens} />
347
+ </div>
348
+ );
349
+ };
350
+
351
+ export type ContextCacheUsageProps = ComponentProps<"div">;
352
+
353
+ export const ContextCacheUsage = ({
354
+ className,
355
+ children,
356
+ ...props
357
+ }: ContextCacheUsageProps) => {
358
+ const { usage, modelId } = useContextValue();
359
+ const cacheTokens = usage?.cachedInputTokens ?? 0;
360
+
361
+ if (children) {
362
+ return children;
363
+ }
364
+
365
+ if (!cacheTokens) {
366
+ return null;
367
+ }
368
+
369
+ const cacheCost = modelId
370
+ ? getUsage({
371
+ modelId,
372
+ usage: { cacheReads: cacheTokens, input: 0, output: 0 },
373
+ }).costUSD?.totalUSD
374
+ : undefined;
375
+ const cacheCostText = new Intl.NumberFormat("en-US", {
376
+ style: "currency",
377
+ currency: "USD",
378
+ }).format(cacheCost ?? 0);
379
+
380
+ return (
381
+ <div
382
+ className={cn("flex items-center justify-between text-xs", className)}
383
+ {...props}
384
+ >
385
+ <span className="text-muted-foreground">Cache</span>
386
+ <TokensWithCost costText={cacheCostText} tokens={cacheTokens} />
387
+ </div>
388
+ );
389
+ };
390
+
391
+ const TokensWithCost = ({
392
+ tokens,
393
+ costText,
394
+ }: {
395
+ tokens?: number;
396
+ costText?: string;
397
+ }) => (
398
+ <span>
399
+ {tokens === undefined
400
+ ? "—"
401
+ : new Intl.NumberFormat("en-US", {
402
+ notation: "compact",
403
+ }).format(tokens)}
404
+ {costText ? (
405
+ <span className="ml-2 text-muted-foreground">• {costText}</span>
406
+ ) : null}
407
+ </span>
408
+ );
@@ -0,0 +1,18 @@
1
+ "use client";
2
+
3
+ import { cn } from "@dreamboard/ui/lib/utils";
4
+ import { Controls as ControlsPrimitive } from "@xyflow/react";
5
+ import type { ComponentProps } from "react";
6
+
7
+ export type ControlsProps = ComponentProps<typeof ControlsPrimitive>;
8
+
9
+ export const Controls = ({ className, ...props }: ControlsProps) => (
10
+ <ControlsPrimitive
11
+ className={cn(
12
+ "gap-px overflow-hidden rounded-md border bg-card p-1 shadow-none!",
13
+ "[&>button]:rounded-md [&>button]:border-none! [&>button]:bg-transparent! [&>button]:hover:bg-secondary!",
14
+ className,
15
+ )}
16
+ {...props}
17
+ />
18
+ );
@@ -0,0 +1,97 @@
1
+ "use client";
2
+
3
+ import { Button } from "@dreamboard/ui/components/button";
4
+ import { cn } from "@dreamboard/ui/lib/utils";
5
+ import { ArrowDownIcon } from "lucide-react";
6
+ import type { ComponentProps, ComponentPropsWithoutRef } from "react";
7
+ import { useCallback } from "react";
8
+ import { StickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
9
+
10
+ export type ConversationProps = ComponentProps<typeof StickToBottom>;
11
+
12
+ export const Conversation = ({ className, ...props }: ConversationProps) => (
13
+ <StickToBottom
14
+ className={cn("relative flex-1 overflow-y-auto", className)}
15
+ initial="smooth"
16
+ resize="smooth"
17
+ role="log"
18
+ {...props}
19
+ />
20
+ );
21
+
22
+ export type ConversationContentProps = ComponentProps<
23
+ typeof StickToBottom.Content
24
+ >;
25
+
26
+ export const ConversationContent = ({
27
+ className,
28
+ ...props
29
+ }: ConversationContentProps) => (
30
+ <StickToBottom.Content className={cn("p-4", className)} {...props} />
31
+ );
32
+
33
+ export type ConversationEmptyStateProps = ComponentPropsWithoutRef<"div"> & {
34
+ title?: string;
35
+ description?: string;
36
+ icon?: React.ReactNode;
37
+ };
38
+
39
+ export const ConversationEmptyState = ({
40
+ className,
41
+ title = "No messages yet",
42
+ description = "Start a conversation to see messages here",
43
+ icon,
44
+ children,
45
+ ...props
46
+ }: ConversationEmptyStateProps) => (
47
+ <div
48
+ className={cn(
49
+ "flex size-full flex-col items-center justify-center gap-3 p-8 text-center",
50
+ className,
51
+ )}
52
+ {...props}
53
+ >
54
+ {children ?? (
55
+ <>
56
+ {icon && <div className="text-muted-foreground">{icon}</div>}
57
+ <div className="space-y-1">
58
+ <h3 className="font-medium text-sm">{title}</h3>
59
+ {description && (
60
+ <p className="text-muted-foreground text-sm">{description}</p>
61
+ )}
62
+ </div>
63
+ </>
64
+ )}
65
+ </div>
66
+ );
67
+
68
+ export type ConversationScrollButtonProps = ComponentProps<typeof Button>;
69
+
70
+ export const ConversationScrollButton = ({
71
+ className,
72
+ ...props
73
+ }: ConversationScrollButtonProps) => {
74
+ const { isAtBottom, scrollToBottom } = useStickToBottomContext();
75
+
76
+ const handleScrollToBottom = useCallback(() => {
77
+ scrollToBottom();
78
+ }, [scrollToBottom]);
79
+
80
+ return (
81
+ !isAtBottom && (
82
+ <Button
83
+ className={cn(
84
+ "absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",
85
+ className,
86
+ )}
87
+ onClick={handleScrollToBottom}
88
+ size="icon"
89
+ type="button"
90
+ variant="outline"
91
+ {...props}
92
+ >
93
+ <ArrowDownIcon className="size-4" />
94
+ </Button>
95
+ )
96
+ );
97
+ };
@@ -0,0 +1,140 @@
1
+ import {
2
+ BaseEdge,
3
+ type EdgeProps,
4
+ getBezierPath,
5
+ getSimpleBezierPath,
6
+ type InternalNode,
7
+ type Node,
8
+ Position,
9
+ useInternalNode,
10
+ } from "@xyflow/react";
11
+
12
+ const Temporary = ({
13
+ id,
14
+ sourceX,
15
+ sourceY,
16
+ targetX,
17
+ targetY,
18
+ sourcePosition,
19
+ targetPosition,
20
+ }: EdgeProps) => {
21
+ const [edgePath] = getSimpleBezierPath({
22
+ sourceX,
23
+ sourceY,
24
+ sourcePosition,
25
+ targetX,
26
+ targetY,
27
+ targetPosition,
28
+ });
29
+
30
+ return (
31
+ <BaseEdge
32
+ className="stroke-1 stroke-ring"
33
+ id={id}
34
+ path={edgePath}
35
+ style={{
36
+ strokeDasharray: "5, 5",
37
+ }}
38
+ />
39
+ );
40
+ };
41
+
42
+ const getHandleCoordsByPosition = (
43
+ node: InternalNode<Node>,
44
+ handlePosition: Position,
45
+ ) => {
46
+ // Choose the handle type based on position - Left is for target, Right is for source
47
+ const handleType = handlePosition === Position.Left ? "target" : "source";
48
+
49
+ const handle = node.internals.handleBounds?.[handleType]?.find(
50
+ (h) => h.position === handlePosition,
51
+ );
52
+
53
+ if (!handle) {
54
+ return [0, 0] as const;
55
+ }
56
+
57
+ let offsetX = handle.width / 2;
58
+ let offsetY = handle.height / 2;
59
+
60
+ // this is a tiny detail to make the markerEnd of an edge visible.
61
+ // The handle position that gets calculated has the origin top-left, so depending which side we are using, we add a little offset
62
+ // when the handlePosition is Position.Right for example, we need to add an offset as big as the handle itself in order to get the correct position
63
+ switch (handlePosition) {
64
+ case Position.Left:
65
+ offsetX = 0;
66
+ break;
67
+ case Position.Right:
68
+ offsetX = handle.width;
69
+ break;
70
+ case Position.Top:
71
+ offsetY = 0;
72
+ break;
73
+ case Position.Bottom:
74
+ offsetY = handle.height;
75
+ break;
76
+ default:
77
+ throw new Error(`Invalid handle position: ${handlePosition}`);
78
+ }
79
+
80
+ const x = node.internals.positionAbsolute.x + handle.x + offsetX;
81
+ const y = node.internals.positionAbsolute.y + handle.y + offsetY;
82
+
83
+ return [x, y] as const;
84
+ };
85
+
86
+ const getEdgeParams = (
87
+ source: InternalNode<Node>,
88
+ target: InternalNode<Node>,
89
+ ) => {
90
+ const sourcePos = Position.Right;
91
+ const [sx, sy] = getHandleCoordsByPosition(source, sourcePos);
92
+ const targetPos = Position.Left;
93
+ const [tx, ty] = getHandleCoordsByPosition(target, targetPos);
94
+
95
+ return {
96
+ sx,
97
+ sy,
98
+ tx,
99
+ ty,
100
+ sourcePos,
101
+ targetPos,
102
+ };
103
+ };
104
+
105
+ const Animated = ({ id, source, target, markerEnd, style }: EdgeProps) => {
106
+ const sourceNode = useInternalNode(source);
107
+ const targetNode = useInternalNode(target);
108
+
109
+ if (!(sourceNode && targetNode)) {
110
+ return null;
111
+ }
112
+
113
+ const { sx, sy, tx, ty, sourcePos, targetPos } = getEdgeParams(
114
+ sourceNode,
115
+ targetNode,
116
+ );
117
+
118
+ const [edgePath] = getBezierPath({
119
+ sourceX: sx,
120
+ sourceY: sy,
121
+ sourcePosition: sourcePos,
122
+ targetX: tx,
123
+ targetY: ty,
124
+ targetPosition: targetPos,
125
+ });
126
+
127
+ return (
128
+ <>
129
+ <BaseEdge id={id} markerEnd={markerEnd} path={edgePath} style={style} />
130
+ <circle fill="var(--primary)" r="4">
131
+ <animateMotion dur="2s" path={edgePath} repeatCount="indefinite" />
132
+ </circle>
133
+ </>
134
+ );
135
+ };
136
+
137
+ export const Edge = {
138
+ Temporary,
139
+ Animated,
140
+ };
@@ -0,0 +1,24 @@
1
+ import { cn } from "@dreamboard/ui/lib/utils";
2
+ import type { Experimental_GeneratedImage } from "ai";
3
+
4
+ export type ImageProps = Experimental_GeneratedImage & {
5
+ className?: string;
6
+ alt?: string;
7
+ };
8
+
9
+ export const Image = ({
10
+ base64,
11
+ uint8Array: _uint8Array,
12
+ mediaType,
13
+ ...props
14
+ }: ImageProps) => (
15
+ <img
16
+ {...props}
17
+ alt={props.alt}
18
+ className={cn(
19
+ "h-auto max-w-full overflow-hidden rounded-md",
20
+ props.className,
21
+ )}
22
+ src={`data:${mediaType};base64,${base64}`}
23
+ />
24
+ );