@copilotkit/vue 2.0.0-rc.0 → 2.0.0-rc.2

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 (239) hide show
  1. package/PARITY.md +13 -12
  2. package/README.md +1 -2
  3. package/dist/components/copilot-provider/CopilotKit.vue.d.ts +3 -1
  4. package/dist/components/copilot-provider/CopilotKit.vue.d.ts.map +1 -1
  5. package/dist/index.cjs +43 -46
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.mjs +10170 -7506
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/v2/components/A2UIMessageRenderer.d.ts +7 -0
  10. package/dist/v2/components/A2UIMessageRenderer.d.ts.map +1 -1
  11. package/dist/v2/components/A2UISurfaceActivityRenderer.vue.d.ts.map +1 -1
  12. package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts +11 -2
  13. package/dist/v2/components/a2ui/A2UIBuiltInToolCallRenderer.d.ts.map +1 -1
  14. package/dist/v2/components/a2ui/A2UIRecoveryStates.d.ts +136 -0
  15. package/dist/v2/components/a2ui/A2UIRecoveryStates.d.ts.map +1 -0
  16. package/dist/v2/components/chat/BasicMarkdown.vue.d.ts.map +1 -1
  17. package/dist/v2/components/chat/CopilotChat.vue.d.ts +1 -0
  18. package/dist/v2/components/chat/CopilotChat.vue.d.ts.map +1 -1
  19. package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts +3 -1
  20. package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts.map +1 -1
  21. package/dist/v2/components/chat/CopilotChatAssistantToolbarButton.vue.d.ts +16 -0
  22. package/dist/v2/components/chat/CopilotChatAssistantToolbarButton.vue.d.ts.map +1 -0
  23. package/dist/v2/components/chat/CopilotChatAttachmentQueue.vue.d.ts.map +1 -1
  24. package/dist/v2/components/chat/CopilotChatAttachmentRenderer.vue.d.ts.map +1 -1
  25. package/dist/v2/components/chat/CopilotChatAudioRecorder.vue.d.ts.map +1 -1
  26. package/dist/v2/components/chat/CopilotChatFeedbackCommentPopover.vue.d.ts +22 -0
  27. package/dist/v2/components/chat/CopilotChatFeedbackCommentPopover.vue.d.ts.map +1 -0
  28. package/dist/v2/components/chat/CopilotChatInput.vue.d.ts +69 -16
  29. package/dist/v2/components/chat/CopilotChatInput.vue.d.ts.map +1 -1
  30. package/dist/v2/components/chat/CopilotChatInspectorButton.vue.d.ts +12 -0
  31. package/dist/v2/components/chat/CopilotChatInspectorButton.vue.d.ts.map +1 -0
  32. package/dist/v2/components/chat/CopilotChatLightbox.vue.d.ts +22 -0
  33. package/dist/v2/components/chat/CopilotChatLightbox.vue.d.ts.map +1 -0
  34. package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts +20 -0
  35. package/dist/v2/components/chat/CopilotChatMessageView.vue.d.ts.map +1 -1
  36. package/dist/v2/components/chat/CopilotChatReasoningMessage.vue.d.ts.map +1 -1
  37. package/dist/v2/components/chat/CopilotChatSuggestionPill.vue.d.ts.map +1 -1
  38. package/dist/v2/components/chat/CopilotChatSuggestionView.vue.d.ts.map +1 -1
  39. package/dist/v2/components/chat/CopilotChatToggleButton.vue.d.ts.map +1 -1
  40. package/dist/v2/components/chat/CopilotChatToolCallGroup.vue.d.ts +32 -0
  41. package/dist/v2/components/chat/CopilotChatToolCallGroup.vue.d.ts.map +1 -0
  42. package/dist/v2/components/chat/CopilotChatToolCallItem.vue.d.ts.map +1 -1
  43. package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts +11 -1
  44. package/dist/v2/components/chat/CopilotChatToolCallsView.vue.d.ts.map +1 -1
  45. package/dist/v2/components/chat/CopilotChatUserMessage.vue.d.ts.map +1 -1
  46. package/dist/v2/components/chat/CopilotChatView.vue.d.ts +1 -0
  47. package/dist/v2/components/chat/CopilotChatView.vue.d.ts.map +1 -1
  48. package/dist/v2/components/chat/CopilotChatWorkSummary.vue.d.ts +5 -0
  49. package/dist/v2/components/chat/CopilotChatWorkSummary.vue.d.ts.map +1 -0
  50. package/dist/v2/components/chat/CopilotModalHeader.vue.d.ts.map +1 -1
  51. package/dist/v2/components/chat/CopilotModalHeaderCloseButton.d.ts.map +1 -1
  52. package/dist/v2/components/chat/CopilotModalHeaderTitle.d.ts.map +1 -1
  53. package/dist/v2/components/chat/CopilotPopup.vue.d.ts +1 -0
  54. package/dist/v2/components/chat/CopilotPopup.vue.d.ts.map +1 -1
  55. package/dist/v2/components/chat/CopilotPopupView.vue.d.ts +1 -0
  56. package/dist/v2/components/chat/CopilotPopupView.vue.d.ts.map +1 -1
  57. package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts +1 -0
  58. package/dist/v2/components/chat/CopilotPopupViewInternal.vue.d.ts.map +1 -1
  59. package/dist/v2/components/chat/CopilotPopupWelcomeScreen.vue.d.ts.map +1 -1
  60. package/dist/v2/components/chat/CopilotSidebar.vue.d.ts +2 -0
  61. package/dist/v2/components/chat/CopilotSidebar.vue.d.ts.map +1 -1
  62. package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts +2 -0
  63. package/dist/v2/components/chat/CopilotSidebarView.vue.d.ts.map +1 -1
  64. package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts +2 -0
  65. package/dist/v2/components/chat/CopilotSidebarViewInternal.vue.d.ts.map +1 -1
  66. package/dist/v2/components/chat/CopilotSidebarWelcomeScreen.vue.d.ts.map +1 -1
  67. package/dist/v2/components/chat/StreamingMarkdownDefault.vue.d.ts.map +1 -1
  68. package/dist/v2/components/chat/index.d.ts +17 -0
  69. package/dist/v2/components/chat/index.d.ts.map +1 -1
  70. package/dist/v2/components/chat/inspector-shortcuts.d.ts +12 -0
  71. package/dist/v2/components/chat/inspector-shortcuts.d.ts.map +1 -0
  72. package/dist/v2/components/chat/message-feedback.d.ts +89 -0
  73. package/dist/v2/components/chat/message-feedback.d.ts.map +1 -0
  74. package/dist/v2/components/chat/tool-call-capture.d.ts +39 -0
  75. package/dist/v2/components/chat/tool-call-capture.d.ts.map +1 -0
  76. package/dist/v2/components/chat/tool-call-display-context.d.ts +39 -0
  77. package/dist/v2/components/chat/tool-call-display-context.d.ts.map +1 -0
  78. package/dist/v2/components/chat/tool-call-group-parts.d.ts +144 -0
  79. package/dist/v2/components/chat/tool-call-group-parts.d.ts.map +1 -0
  80. package/dist/v2/components/chat/tool-call-layout.d.ts +115 -0
  81. package/dist/v2/components/chat/tool-call-layout.d.ts.map +1 -0
  82. package/dist/v2/components/chat/turn-work.d.ts +35 -0
  83. package/dist/v2/components/chat/turn-work.d.ts.map +1 -0
  84. package/dist/v2/components/chat/types.d.ts +104 -4
  85. package/dist/v2/components/chat/types.d.ts.map +1 -1
  86. package/dist/v2/components/chat/use-lightbox.d.ts +18 -0
  87. package/dist/v2/components/chat/use-lightbox.d.ts.map +1 -0
  88. package/dist/v2/components/icons/index.d.ts +1 -1
  89. package/dist/v2/components/icons/index.d.ts.map +1 -1
  90. package/dist/v2/components/ui/CopilotDropdownMenuContent.vue.d.ts +55 -0
  91. package/dist/v2/components/ui/CopilotDropdownMenuContent.vue.d.ts.map +1 -0
  92. package/dist/v2/components/ui/CopilotPopover.vue.d.ts +40 -0
  93. package/dist/v2/components/ui/CopilotPopover.vue.d.ts.map +1 -0
  94. package/dist/v2/components/ui/CopilotTooltip.vue.d.ts +37 -0
  95. package/dist/v2/components/ui/CopilotTooltip.vue.d.ts.map +1 -0
  96. package/dist/v2/components/ui/dropdown-menu.d.ts +14 -0
  97. package/dist/v2/components/ui/dropdown-menu.d.ts.map +1 -0
  98. package/dist/v2/components/ui/floating.d.ts +84 -0
  99. package/dist/v2/components/ui/floating.d.ts.map +1 -0
  100. package/dist/v2/components/ui/presence.d.ts +9 -0
  101. package/dist/v2/components/ui/presence.d.ts.map +1 -0
  102. package/dist/v2/components/ui/use-id.d.ts +9 -0
  103. package/dist/v2/components/ui/use-id.d.ts.map +1 -0
  104. package/dist/v2/hooks/use-default-render-tool.d.ts +6 -0
  105. package/dist/v2/hooks/use-default-render-tool.d.ts.map +1 -1
  106. package/dist/v2/hooks/use-render-tool.d.ts +4 -0
  107. package/dist/v2/hooks/use-render-tool.d.ts.map +1 -1
  108. package/dist/v2/index.cjs +1 -1
  109. package/dist/v2/index.d.cts +3 -0
  110. package/dist/v2/index.d.mts +3 -0
  111. package/dist/v2/index.d.ts +3 -0
  112. package/dist/v2/index.d.ts.map +1 -1
  113. package/dist/v2/index.mjs +165 -162
  114. package/dist/v2/lib/message-feedback.d.ts +33 -0
  115. package/dist/v2/lib/message-feedback.d.ts.map +1 -0
  116. package/dist/v2/providers/CopilotChatConfigurationProvider.vue.d.ts.map +1 -1
  117. package/dist/v2/providers/CopilotKitProvider.types.d.ts +56 -1
  118. package/dist/v2/providers/CopilotKitProvider.types.d.ts.map +1 -1
  119. package/dist/v2/providers/CopilotKitProvider.vue.d.ts +5 -1
  120. package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -1
  121. package/dist/v2/providers/index.d.ts +1 -1
  122. package/dist/v2/providers/index.d.ts.map +1 -1
  123. package/dist/v2/providers/keys.d.ts +8 -0
  124. package/dist/v2/providers/keys.d.ts.map +1 -1
  125. package/dist/v2/providers/types.d.ts +9 -0
  126. package/dist/v2/providers/types.d.ts.map +1 -1
  127. package/dist/v2/styles/CopilotKitStyles.d.ts +18 -0
  128. package/dist/v2/styles/CopilotKitStyles.d.ts.map +1 -0
  129. package/dist/v2/types/defineToolCallRenderer.d.ts +2 -0
  130. package/dist/v2/types/defineToolCallRenderer.d.ts.map +1 -1
  131. package/dist/v2/types/vue-tool-call-renderer.d.ts +7 -0
  132. package/dist/v2/types/vue-tool-call-renderer.d.ts.map +1 -1
  133. package/package.json +11 -23
  134. package/src/components/copilot-provider/CopilotKit.vue +4 -1
  135. package/src/v2/__tests__/exports.test.ts +4 -2
  136. package/src/v2/components/A2UIMessageRenderer.ts +55 -67
  137. package/src/v2/components/A2UISurfaceActivityRenderer.vue +11 -23
  138. package/src/v2/components/__tests__/A2UIBasicCatalogColors.test.ts +8 -9
  139. package/src/v2/components/__tests__/A2UIMessageRenderer.test.ts +63 -36
  140. package/src/v2/components/a2ui/A2UIBuiltInToolCallRenderer.ts +14 -257
  141. package/src/v2/components/a2ui/A2UIRecoveryStates.ts +444 -0
  142. package/src/v2/components/a2ui/__tests__/A2UIRecoveryStates.test.ts +175 -0
  143. package/src/v2/components/chat/BasicMarkdown.vue +8 -6
  144. package/src/v2/components/chat/CopilotChat.vue +7 -0
  145. package/src/v2/components/chat/CopilotChatAssistantMessage.vue +267 -67
  146. package/src/v2/components/chat/CopilotChatAssistantToolbarButton.vue +46 -0
  147. package/src/v2/components/chat/CopilotChatAttachmentQueue.vue +141 -168
  148. package/src/v2/components/chat/CopilotChatAttachmentRenderer.vue +67 -18
  149. package/src/v2/components/chat/CopilotChatAudioRecorder.vue +2 -2
  150. package/src/v2/components/chat/CopilotChatFeedbackCommentPopover.vue +240 -0
  151. package/src/v2/components/chat/CopilotChatInput.vue +210 -161
  152. package/src/v2/components/chat/CopilotChatInspectorButton.vue +331 -0
  153. package/src/v2/components/chat/CopilotChatLightbox.vue +105 -0
  154. package/src/v2/components/chat/CopilotChatMessageView.vue +261 -18
  155. package/src/v2/components/chat/CopilotChatReasoningMessage.vue +21 -22
  156. package/src/v2/components/chat/CopilotChatSuggestionPill.vue +5 -14
  157. package/src/v2/components/chat/CopilotChatSuggestionView.vue +1 -4
  158. package/src/v2/components/chat/CopilotChatToggleButton.vue +3 -9
  159. package/src/v2/components/chat/CopilotChatToggleButtonCloseIcon.ts +1 -1
  160. package/src/v2/components/chat/CopilotChatToggleButtonOpenIcon.ts +1 -1
  161. package/src/v2/components/chat/CopilotChatToolCallGroup.vue +330 -0
  162. package/src/v2/components/chat/CopilotChatToolCallItem.vue +21 -11
  163. package/src/v2/components/chat/CopilotChatToolCallsView.vue +192 -21
  164. package/src/v2/components/chat/CopilotChatUserMessage.vue +105 -42
  165. package/src/v2/components/chat/CopilotChatView.vue +33 -38
  166. package/src/v2/components/chat/CopilotChatWorkSummary.vue +85 -0
  167. package/src/v2/components/chat/CopilotModalHeader.vue +10 -8
  168. package/src/v2/components/chat/CopilotModalHeaderCloseButton.ts +7 -6
  169. package/src/v2/components/chat/CopilotModalHeaderTitle.ts +1 -4
  170. package/src/v2/components/chat/CopilotPopup.vue +3 -0
  171. package/src/v2/components/chat/CopilotPopupView.vue +1 -0
  172. package/src/v2/components/chat/CopilotPopupViewInternal.vue +9 -19
  173. package/src/v2/components/chat/CopilotPopupWelcomeScreen.vue +5 -8
  174. package/src/v2/components/chat/CopilotSidebar.vue +5 -0
  175. package/src/v2/components/chat/CopilotSidebarView.vue +2 -0
  176. package/src/v2/components/chat/CopilotSidebarViewInternal.vue +24 -17
  177. package/src/v2/components/chat/CopilotSidebarWelcomeScreen.vue +7 -10
  178. package/src/v2/components/chat/StreamingMarkdownDefault.vue +3 -5
  179. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.inspector.test.ts +269 -0
  180. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.learningFeedback.test.ts +760 -0
  181. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.ts +3 -5
  182. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.ts +2 -2
  183. package/src/v2/components/chat/__tests__/CopilotChatInput.addMenu.test.ts +328 -0
  184. package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.ts +6 -3
  185. package/src/v2/components/chat/__tests__/CopilotChatInput.test.ts +22 -13
  186. package/src/v2/components/chat/__tests__/CopilotChatLightbox.test.ts +160 -0
  187. package/src/v2/components/chat/__tests__/CopilotChatMessageView.toolCallDisplay.test.ts +735 -0
  188. package/src/v2/components/chat/__tests__/CopilotChatSuggestionPill.test.ts +1 -1
  189. package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.ts +3 -1
  190. package/src/v2/components/chat/__tests__/CopilotChatToolCallsView.learning.test.ts +75 -0
  191. package/src/v2/components/chat/__tests__/CopilotChatUserMessage.attachments.test.ts +143 -0
  192. package/src/v2/components/chat/__tests__/CopilotChatView.inputOverlay.test.ts +5 -4
  193. package/src/v2/components/chat/__tests__/CopilotChatView.rootWidth.test.ts +7 -33
  194. package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.ts +1 -1
  195. package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.ts +3 -3
  196. package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.ts +126 -0
  197. package/src/v2/components/chat/__tests__/messageFeedbackDefaults.test.ts +33 -0
  198. package/src/v2/components/chat/__tests__/modalChatDisplayProps.test.ts +44 -0
  199. package/src/v2/components/chat/index.ts +2 -0
  200. package/src/v2/components/chat/inspector-shortcuts.ts +34 -0
  201. package/src/v2/components/chat/message-feedback.ts +291 -0
  202. package/src/v2/components/chat/tool-call-capture.ts +55 -0
  203. package/src/v2/components/chat/tool-call-display-context.ts +49 -0
  204. package/src/v2/components/chat/tool-call-group-parts.ts +292 -0
  205. package/src/v2/components/chat/tool-call-layout.ts +304 -0
  206. package/src/v2/components/chat/turn-work.ts +61 -0
  207. package/src/v2/components/chat/types.ts +113 -3
  208. package/src/v2/components/chat/use-lightbox.ts +64 -0
  209. package/src/v2/components/icons/index.ts +4 -0
  210. package/src/v2/components/ui/CopilotDropdownMenuContent.vue +465 -0
  211. package/src/v2/components/ui/CopilotPopover.vue +138 -0
  212. package/src/v2/components/ui/CopilotTooltip.vue +237 -0
  213. package/src/v2/components/ui/__tests__/CopilotTooltip.test.ts +168 -0
  214. package/src/v2/components/ui/dropdown-menu.ts +15 -0
  215. package/src/v2/components/ui/floating.ts +321 -0
  216. package/src/v2/components/ui/presence.ts +54 -0
  217. package/src/v2/components/ui/use-id.ts +16 -0
  218. package/src/v2/hooks/use-default-render-tool.ts +123 -62
  219. package/src/v2/hooks/use-render-tool.ts +8 -0
  220. package/src/v2/index.ts +3 -0
  221. package/src/v2/lib/__tests__/message-feedback.test.ts +152 -0
  222. package/src/v2/lib/message-feedback.ts +120 -0
  223. package/src/v2/providers/CopilotChatConfigurationProvider.vue +29 -2
  224. package/src/v2/providers/CopilotKitProvider.types.ts +57 -0
  225. package/src/v2/providers/CopilotKitProvider.vue +125 -3
  226. package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.openThread.test.ts +69 -0
  227. package/src/v2/providers/__tests__/CopilotKitProvider.learning.test.ts +534 -0
  228. package/src/v2/providers/index.ts +4 -1
  229. package/src/v2/providers/keys.ts +12 -0
  230. package/src/v2/providers/types.ts +11 -0
  231. package/src/v2/styles/CopilotKitStyles.ts +95 -0
  232. package/src/v2/styles/__tests__/CopilotKitStyles.client.test.ts +149 -0
  233. package/src/v2/styles/__tests__/CopilotKitStyles.ssr.test.ts +71 -0
  234. package/src/v2/types/defineToolCallRenderer.ts +4 -0
  235. package/src/v2/types/vue-tool-call-renderer.ts +7 -0
  236. package/vite.config.ts +2 -1
  237. package/dist/styles.css +0 -2
  238. package/scripts/scope-preflight.mjs +0 -100
  239. package/src/styles/globals.css +0 -233
@@ -1,7 +1,6 @@
1
- import { h, watch, type VNodeChild } from "vue";
1
+ import { watch } from "vue";
2
2
  import type { ShallowRef } from "vue";
3
3
  import { z } from "zod";
4
- import type { ToolCallStatus } from "@copilotkit/core";
5
4
  import type { CopilotKitCoreVue } from "../../lib/vue-core";
6
5
  import { defineToolCallRenderer } from "../../types/defineToolCallRenderer";
7
6
 
@@ -12,8 +11,17 @@ import { defineToolCallRenderer } from "../../types/defineToolCallRenderer";
12
11
  export const RENDER_A2UI_TOOL_NAME = "render_a2ui";
13
12
 
14
13
  /**
15
- * Registers the built-in `render_a2ui` tool call renderer via the props-based
16
- * `setRenderToolCalls` mechanism (not `useRenderTool`).
14
+ * Registers a no-op renderer for the `render_a2ui` tool call so its raw
15
+ * streamed args are never surfaced in the transcript, as React does.
16
+ *
17
+ * The generation skeleton / retry / failure UX is not owned here: the A2UI
18
+ * middleware drives the whole lifecycle on the `a2ui-surface` activity (one
19
+ * stable messageId, building → retrying → failed → painted), rendered in place
20
+ * by `createA2UIMessageRenderer`. A skeleton per tool call would duplicate on
21
+ * retries and multi-call generations and linger after the surface painted.
22
+ *
23
+ * The renderer is registered via the props-based `setRenderToolCalls`
24
+ * mechanism (not `useRenderTool`).
17
25
  *
18
26
  * This ensures user-registered `useRenderTool({ name: "render_a2ui", ... })`
19
27
  * hooks automatically override the built-in, since the merge logic in
@@ -33,23 +41,8 @@ export function registerA2UIBuiltInToolCallRenderer(
33
41
  const renderer = defineToolCallRenderer({
34
42
  name: RENDER_A2UI_TOOL_NAME,
35
43
  args: z.any(),
36
- render: ({
37
- status,
38
- args: parameters,
39
- }: {
40
- status: ToolCallStatus;
41
- args: unknown;
42
- [key: string]: unknown;
43
- }): VNodeChild => {
44
- if (status === "complete") return null;
45
- const params = parameters as Record<string, unknown>;
46
- // Hide skeleton once the A2UI surface has enough data to render.
47
- const items = params?.items;
48
- if (Array.isArray(items) && items.length > 0) return null;
49
- const components = params?.components;
50
- if (Array.isArray(components) && components.length > 2) return null;
51
- return renderA2UIProgressIndicator(parameters);
52
- },
44
+ // Render nothing: the a2ui-surface activity owns all generation UX.
45
+ render: () => null,
53
46
  });
54
47
 
55
48
  // Register via props-based mechanism so useRenderTool hooks take priority
@@ -64,244 +57,8 @@ export function registerA2UIBuiltInToolCallRenderer(
64
57
  core.setRenderToolCalls(
65
58
  current.filter((rc) => rc.name !== RENDER_A2UI_TOOL_NAME),
66
59
  );
67
- progressState.clear();
68
60
  });
69
61
  },
70
62
  { immediate: true },
71
63
  );
72
64
  }
73
-
74
- /**
75
- * Vue render-function equivalent of the React A2UIProgressIndicator.
76
- * Shows a skeleton wireframe that progressively reveals as tokens stream in.
77
- */
78
- const progressState = new Map<
79
- string,
80
- { lastTime: number; lastTokens: number }
81
- >();
82
-
83
- function renderA2UIProgressIndicator(parameters: unknown): VNodeChild {
84
- const params = parameters as Record<string, unknown> | null | undefined;
85
- const key = typeof params?.name === "string" ? params.name : "__default__";
86
- let state = progressState.get(key);
87
- if (!state) {
88
- state = { lastTime: 0, lastTokens: 0 };
89
- progressState.set(key, state);
90
- }
91
-
92
- const now = Date.now();
93
- let tokens = state.lastTokens;
94
- if (now - state.lastTime > 200) {
95
- const chars = JSON.stringify(parameters ?? {}).length;
96
- tokens = Math.round(chars / 4);
97
- state.lastTime = now;
98
- state.lastTokens = tokens;
99
- }
100
-
101
- const phase = tokens < 50 ? 0 : tokens < 200 ? 1 : tokens < 400 ? 2 : 3;
102
-
103
- const dot = () =>
104
- h("div", {
105
- style: {
106
- width: "7px",
107
- height: "7px",
108
- borderRadius: "50%",
109
- backgroundColor: "#d4d4d8",
110
- flexShrink: 0,
111
- },
112
- });
113
-
114
- const spacer = () => h("div", { style: { width: "12px" } });
115
-
116
- const bar = (
117
- w: number,
118
- ht: number,
119
- bg: string,
120
- anim?: number,
121
- opacity?: number,
122
- transition?: string,
123
- ) =>
124
- h("div", {
125
- style: {
126
- width: `${w}px`,
127
- height: `${ht}px`,
128
- borderRadius: "9999px",
129
- backgroundColor: bg,
130
- ...(anim !== undefined
131
- ? {
132
- animation: `cpk-a2ui-fade 2.4s ease-in-out ${anim}s infinite`,
133
- }
134
- : {}),
135
- ...(opacity !== undefined ? { opacity } : {}),
136
- ...(transition ? { transition } : {}),
137
- },
138
- });
139
-
140
- const row = (show: boolean, delay: number, children: VNodeChild[]) =>
141
- h(
142
- "div",
143
- {
144
- style: {
145
- display: "flex",
146
- alignItems: "center",
147
- gap: "6px",
148
- opacity: show ? 1 : 0,
149
- transition: `opacity 0.4s ${delay}s`,
150
- },
151
- },
152
- children,
153
- );
154
-
155
- return h("div", { style: { margin: "12px 0", maxWidth: "320px" } }, [
156
- h(
157
- "div",
158
- {
159
- style: {
160
- position: "relative",
161
- overflow: "hidden",
162
- borderRadius: "12px",
163
- border: "1px solid rgba(228,228,231,0.8)",
164
- backgroundColor: "#fff",
165
- boxShadow: "0 1px 2px rgba(0,0,0,0.04)",
166
- padding: "16px 18px 14px",
167
- },
168
- },
169
- [
170
- // Top bar
171
- h(
172
- "div",
173
- {
174
- style: {
175
- display: "flex",
176
- alignItems: "center",
177
- gap: "8px",
178
- marginBottom: "12px",
179
- },
180
- },
181
- [
182
- h("div", { style: { display: "flex", gap: "4px" } }, [
183
- dot(),
184
- dot(),
185
- dot(),
186
- ]),
187
- bar(
188
- 64,
189
- 6,
190
- "#e4e4e7",
191
- undefined,
192
- phase >= 1 ? 1 : 0.4,
193
- "opacity 0.5s",
194
- ),
195
- ],
196
- ),
197
- // Skeleton lines
198
- h("div", { style: { display: "grid", gap: "7px" } }, [
199
- row(phase >= 0, 0, [
200
- bar(36, 7, "rgba(147,197,253,0.7)", 0),
201
- bar(80, 7, "rgba(219,234,254,0.8)", 0.2),
202
- ]),
203
- row(phase >= 0, 0.1, [
204
- spacer(),
205
- dot(),
206
- bar(100, 7, "rgba(24,24,27,0.2)", 0.3),
207
- ]),
208
- row(phase >= 1, 0.15, [
209
- spacer(),
210
- bar(48, 7, "rgba(24,24,27,0.15)", 0.1),
211
- bar(40, 7, "rgba(153,246,228,0.6)", 0.5),
212
- bar(56, 7, "rgba(147,197,253,0.6)", 0.3),
213
- ]),
214
- row(phase >= 1, 0.2, [
215
- spacer(),
216
- dot(),
217
- bar(60, 7, "rgba(24,24,27,0.15)", 0.4),
218
- ]),
219
- row(phase >= 2, 0.25, [
220
- bar(40, 7, "rgba(153,246,228,0.5)", 0.2),
221
- dot(),
222
- bar(48, 7, "rgba(24,24,27,0.15)", 0.6),
223
- bar(64, 7, "rgba(147,197,253,0.5)", 0.1),
224
- ]),
225
- row(phase >= 2, 0.3, [
226
- bar(36, 7, "rgba(147,197,253,0.6)", 0.5),
227
- bar(36, 7, "rgba(24,24,27,0.12)", 0.7),
228
- ]),
229
- row(phase >= 3, 0.35, [
230
- dot(),
231
- bar(44, 7, "rgba(24,24,27,0.18)", 0.3),
232
- dot(),
233
- bar(56, 7, "rgba(153,246,228,0.5)", 0.8),
234
- bar(48, 7, "rgba(147,197,253,0.5)", 0.4),
235
- ]),
236
- ]),
237
- // Shimmer
238
- h("div", {
239
- style: {
240
- pointerEvents: "none",
241
- position: "absolute",
242
- inset: "0",
243
- background:
244
- "linear-gradient(105deg, transparent 0%, transparent 40%, rgba(255,255,255,0.6) 50%, transparent 60%, transparent 100%)",
245
- backgroundSize: "250% 100%",
246
- animation: "cpk-a2ui-sweep 3s ease-in-out infinite",
247
- },
248
- }),
249
- ],
250
- ),
251
- // Label
252
- h(
253
- "div",
254
- {
255
- style: {
256
- display: "flex",
257
- alignItems: "center",
258
- justifyContent: "center",
259
- gap: "8px",
260
- marginTop: "8px",
261
- },
262
- },
263
- [
264
- h(
265
- "span",
266
- {
267
- style: {
268
- fontSize: "12px",
269
- color: "#a1a1aa",
270
- letterSpacing: "0.025em",
271
- },
272
- },
273
- "Building interface",
274
- ),
275
- ...(tokens > 0
276
- ? [
277
- h(
278
- "span",
279
- {
280
- style: {
281
- fontSize: "11px",
282
- color: "#d4d4d8",
283
- fontVariantNumeric: "tabular-nums",
284
- },
285
- },
286
- `~${tokens.toLocaleString()} tokens`,
287
- ),
288
- ]
289
- : []),
290
- ],
291
- ),
292
- // Keyframe styles
293
- h(
294
- "style",
295
- `
296
- @keyframes cpk-a2ui-fade {
297
- 0%, 100% { opacity: 1; }
298
- 50% { opacity: 0.5; }
299
- }
300
- @keyframes cpk-a2ui-sweep {
301
- 0% { background-position: 250% 0; }
302
- 100% { background-position: -250% 0; }
303
- }
304
- `,
305
- ),
306
- ]);
307
- }