@iyulab/chat-components 0.4.0 → 0.5.1

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 (265) hide show
  1. package/CHANGELOG.md +83 -52
  2. package/README.md +133 -16
  3. package/dist/_virtual/_@oxc-project_runtime@0.124.0/helpers/decorate.js +9 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.124.0/helpers/decorateMetadata.js +6 -0
  5. package/dist/_virtual/_glob-assets_raw/intent-prompt.md.1907474e.js +4 -0
  6. package/dist/_virtual/_glob-assets_raw/view-prompt.md.e0dbcffe.js +4 -0
  7. package/dist/components/blocks/UCodeBlock.d.ts +24 -2
  8. package/dist/components/blocks/UCodeBlock.js +65 -2
  9. package/dist/components/blocks/UCodeBlock.styles.js +4 -4
  10. package/dist/components/blocks/UFileBlock.d.ts +33 -0
  11. package/dist/components/blocks/UFileBlock.js +154 -0
  12. package/dist/components/blocks/{UFilesBlock.styles.js → UFileBlock.styles.js} +12 -90
  13. package/dist/components/blocks/UJsonBlock.d.ts +44 -2
  14. package/dist/components/blocks/UJsonBlock.js +128 -3
  15. package/dist/components/blocks/UJsonBlock.styles.js +4 -4
  16. package/dist/components/blocks/UMarkedBlock.d.ts +44 -2
  17. package/dist/components/blocks/UMarkedBlock.js +154 -4
  18. package/dist/components/blocks/UMarkedBlock.styles.js +4 -4
  19. package/dist/components/blocks/URefBlock.d.ts +16 -2
  20. package/dist/components/blocks/URefBlock.js +58 -3
  21. package/dist/components/blocks/URefBlock.styles.js +4 -4
  22. package/dist/components/blocks/UTableBlock.d.ts +47 -2
  23. package/dist/components/blocks/UTableBlock.js +197 -4
  24. package/dist/components/blocks/UTableBlock.styles.js +4 -5
  25. package/dist/components/blocks/UTextBlock.d.ts +36 -2
  26. package/dist/components/blocks/UTextBlock.js +94 -4
  27. package/dist/components/blocks/UTextBlock.styles.js +4 -4
  28. package/dist/components/blocks/UThinkBlock.d.ts +30 -2
  29. package/dist/components/blocks/UThinkBlock.js +86 -4
  30. package/dist/components/blocks/UThinkBlock.styles.js +4 -4
  31. package/dist/components/blocks/UToolBlock.d.ts +19 -2
  32. package/dist/components/blocks/UToolBlock.js +68 -3
  33. package/dist/components/blocks/UToolBlock.styles.js +4 -4
  34. package/dist/components/buttons/UAttachButton.d.ts +21 -2
  35. package/dist/components/buttons/UAttachButton.js +61 -3
  36. package/dist/components/buttons/UAttachButton.styles.js +4 -4
  37. package/dist/components/buttons/UCopyButton.d.ts +19 -2
  38. package/dist/components/buttons/UCopyButton.js +57 -3
  39. package/dist/components/buttons/UCopyButton.styles.js +4 -4
  40. package/dist/components/buttons/UVoteButton.d.ts +14 -3
  41. package/dist/components/buttons/UVoteButton.js +62 -3
  42. package/dist/components/buttons/UVoteButton.styles.js +4 -4
  43. package/dist/components/{actions/UQuestionAction.component.d.ts → intents/UQuestionIntent.d.ts} +6 -2
  44. package/dist/components/intents/UQuestionIntent.js +41 -0
  45. package/dist/components/{actions/UQuestionAction.styles.js → intents/UQuestionIntent.styles.js} +4 -6
  46. package/dist/components/message/UMessage.d.ts +18 -2
  47. package/dist/components/message/UMessage.js +47 -2
  48. package/dist/components/message/UMessage.styles.js +4 -4
  49. package/dist/components/prompt/UPrompt.d.ts +37 -2
  50. package/dist/components/prompt/UPrompt.js +139 -2
  51. package/dist/components/prompt/UPrompt.styles.js +15 -5
  52. package/dist/components/references/URefCard.d.ts +30 -2
  53. package/dist/components/references/URefCard.js +97 -2
  54. package/dist/components/references/URefCard.styles.js +4 -4
  55. package/dist/components/references/URefCardGroup.d.ts +25 -2
  56. package/dist/components/references/URefCardGroup.js +69 -4
  57. package/dist/components/references/URefCardGroup.styles.js +4 -4
  58. package/dist/components/references/URefTag.d.ts +12 -2
  59. package/dist/components/references/URefTag.js +37 -2
  60. package/dist/components/references/URefTag.styles.js +4 -4
  61. package/dist/components/{widgets/UChartWidget.component.d.ts → views/UChartView.d.ts} +7 -4
  62. package/dist/components/views/UChartView.js +167 -0
  63. package/dist/components/{widgets/UChartWidget.styles.js → views/UChartView.styles.js} +4 -4
  64. package/dist/components/{widgets/UImagesWidget.component.d.ts → views/UImagesView.d.ts} +7 -4
  65. package/dist/components/views/UImagesView.js +144 -0
  66. package/dist/components/{widgets/UImagesWidget.styles.js → views/UImagesView.styles.js} +6 -5
  67. package/dist/components/{widgets/UMapWidget.component.d.ts → views/UMapView.d.ts} +7 -3
  68. package/dist/components/views/UMapView.js +45 -0
  69. package/dist/components/{widgets/UMapWidget.styles.js → views/UMapView.styles.js} +4 -4
  70. package/dist/components/{widgets/UVideoWidget.component.d.ts → views/UVideoView.d.ts} +7 -3
  71. package/dist/components/views/UVideoView.js +81 -0
  72. package/dist/components/{widgets/UVideoWidget.styles.js → views/UVideoView.styles.js} +4 -4
  73. package/dist/components/{widgets/UWidget.component.d.ts → views/UView.d.ts} +8 -5
  74. package/dist/components/views/UView.js +113 -0
  75. package/dist/components/{widgets/UWidget.styles.js → views/UView.styles.js} +4 -4
  76. package/dist/events/AttachEvent.d.ts +9 -0
  77. package/dist/events/ChoiceEvent.d.ts +9 -0
  78. package/dist/events/SendEvent.d.ts +21 -0
  79. package/dist/events/StopEvent.d.ts +17 -0
  80. package/dist/index.d.ts +13 -16
  81. package/dist/index.js +28 -56
  82. package/dist/react/UAttachButton.d.ts +11 -0
  83. package/dist/react/UAttachButton.js +12 -0
  84. package/dist/react/UChartView.d.ts +9 -0
  85. package/dist/react/UChartView.js +10 -0
  86. package/dist/react/UCodeBlock.d.ts +9 -0
  87. package/dist/react/UCodeBlock.js +10 -0
  88. package/dist/react/UCopyButton.d.ts +9 -0
  89. package/dist/react/UCopyButton.js +10 -0
  90. package/dist/react/UFileBlock.d.ts +11 -0
  91. package/dist/react/UFileBlock.js +12 -0
  92. package/dist/react/UImagesView.d.ts +9 -0
  93. package/dist/react/UImagesView.js +10 -0
  94. package/dist/react/UJsonBlock.d.ts +9 -0
  95. package/dist/react/UJsonBlock.js +10 -0
  96. package/dist/react/UMapView.d.ts +9 -0
  97. package/dist/react/UMapView.js +10 -0
  98. package/dist/react/UMarkedBlock.d.ts +9 -0
  99. package/dist/react/UMarkedBlock.js +10 -0
  100. package/dist/react/UMessage.d.ts +9 -0
  101. package/dist/react/UMessage.js +10 -0
  102. package/dist/react/UPrompt.d.ts +13 -0
  103. package/dist/react/UPrompt.js +13 -0
  104. package/dist/react/UQuestionIntent.d.ts +11 -0
  105. package/dist/react/UQuestionIntent.js +12 -0
  106. package/dist/react/URefBlock.d.ts +9 -0
  107. package/dist/react/URefBlock.js +10 -0
  108. package/dist/react/URefCard.d.ts +9 -0
  109. package/dist/react/URefCard.js +10 -0
  110. package/dist/react/URefCardGroup.d.ts +9 -0
  111. package/dist/react/URefCardGroup.js +10 -0
  112. package/dist/react/URefTag.d.ts +9 -0
  113. package/dist/react/URefTag.js +10 -0
  114. package/dist/react/UTableBlock.d.ts +9 -0
  115. package/dist/react/UTableBlock.js +10 -0
  116. package/dist/react/UTextBlock.d.ts +9 -0
  117. package/dist/react/UTextBlock.js +10 -0
  118. package/dist/react/UThinkBlock.d.ts +9 -0
  119. package/dist/react/UThinkBlock.js +10 -0
  120. package/dist/react/UToolBlock.d.ts +9 -0
  121. package/dist/react/UToolBlock.js +10 -0
  122. package/dist/react/UVideoView.d.ts +9 -0
  123. package/dist/react/UVideoView.js +10 -0
  124. package/dist/react/UView.d.ts +9 -0
  125. package/dist/react/UView.js +10 -0
  126. package/dist/react/UVoteButton.d.ts +9 -0
  127. package/dist/react/UVoteButton.js +10 -0
  128. package/dist/react/index.d.ts +23 -0
  129. package/dist/react/index.js +23 -0
  130. package/dist/types/BlockItem.d.ts +21 -32
  131. package/dist/types/Intents.d.ts +26 -0
  132. package/dist/types/Intents.js +30 -0
  133. package/dist/types/{Widgets.d.ts → Views.d.ts} +8 -8
  134. package/dist/types/Views.js +150 -0
  135. package/dist/utilities/IntentPromptBuilder.d.ts +40 -0
  136. package/dist/utilities/IntentPromptBuilder.js +95 -0
  137. package/dist/utilities/ViewPromptBuilder.d.ts +28 -0
  138. package/dist/utilities/ViewPromptBuilder.js +76 -0
  139. package/dist/utilities/dom-agent/DOMAgent.d.ts +74 -0
  140. package/dist/utilities/dom-agent/DOMController.d.ts +78 -0
  141. package/dist/utilities/dom-agent/DOMPromptBuilder.d.ts +54 -0
  142. package/dist/utilities/dom-agent/DOMScanner.d.ts +83 -0
  143. package/dist/utilities/dom-agent/index.d.ts +9 -0
  144. package/dist/utilities/dom-agent/types.d.ts +209 -0
  145. package/package.json +33 -16
  146. package/skills/iyulab-chat-components/SKILL.md +107 -0
  147. package/skills/iyulab-chat-components/references/components/attach-button.md +69 -0
  148. package/skills/iyulab-chat-components/references/components/chart-view.md +65 -0
  149. package/skills/iyulab-chat-components/references/components/code-block.md +42 -0
  150. package/skills/iyulab-chat-components/references/components/copy-button.md +46 -0
  151. package/skills/iyulab-chat-components/references/components/file-block.md +64 -0
  152. package/skills/iyulab-chat-components/references/components/images-view.md +63 -0
  153. package/skills/iyulab-chat-components/references/components/json-block.md +41 -0
  154. package/skills/iyulab-chat-components/references/components/map-view.md +54 -0
  155. package/skills/iyulab-chat-components/references/components/marked-block.md +53 -0
  156. package/skills/iyulab-chat-components/references/components/message.md +60 -0
  157. package/skills/iyulab-chat-components/references/components/prompt.md +102 -0
  158. package/skills/iyulab-chat-components/references/components/question-intent.md +75 -0
  159. package/skills/iyulab-chat-components/references/components/ref-block.md +45 -0
  160. package/skills/iyulab-chat-components/references/components/ref-card-group.md +41 -0
  161. package/skills/iyulab-chat-components/references/components/ref-card.md +48 -0
  162. package/skills/iyulab-chat-components/references/components/ref-tag.md +40 -0
  163. package/skills/iyulab-chat-components/references/components/table-block.md +63 -0
  164. package/skills/iyulab-chat-components/references/components/text-block.md +59 -0
  165. package/skills/iyulab-chat-components/references/components/think-block.md +48 -0
  166. package/skills/iyulab-chat-components/references/components/tool-block.md +57 -0
  167. package/skills/iyulab-chat-components/references/components/video-view.md +55 -0
  168. package/skills/iyulab-chat-components/references/components/view.md +51 -0
  169. package/skills/iyulab-chat-components/references/components/vote-button.md +60 -0
  170. package/skills/iyulab-chat-components/references/types.md +115 -0
  171. package/skills/iyulab-chat-components/references/usage.md +254 -0
  172. package/skills/iyulab-chat-components/references/utilities/intent-prompt-builder.md +123 -0
  173. package/skills/iyulab-chat-components/references/utilities/view-prompt-builder.md +112 -0
  174. package/dist/assets/action-prompt.md.js +0 -3
  175. package/dist/assets/widget-prompt.md.js +0 -3
  176. package/dist/components/actions/UQuestionAction.component.js +0 -58
  177. package/dist/components/actions/UQuestionAction.d.ts +0 -7
  178. package/dist/components/actions/UQuestionAction.js +0 -5
  179. package/dist/components/blocks/UCodeBlock.component.d.ts +0 -25
  180. package/dist/components/blocks/UCodeBlock.component.js +0 -88
  181. package/dist/components/blocks/UFilesBlock.component.d.ts +0 -22
  182. package/dist/components/blocks/UFilesBlock.component.js +0 -192
  183. package/dist/components/blocks/UFilesBlock.d.ts +0 -7
  184. package/dist/components/blocks/UFilesBlock.js +0 -5
  185. package/dist/components/blocks/UJsonBlock.component.d.ts +0 -45
  186. package/dist/components/blocks/UJsonBlock.component.js +0 -140
  187. package/dist/components/blocks/UMarkedBlock.component.d.ts +0 -40
  188. package/dist/components/blocks/UMarkedBlock.component.js +0 -159
  189. package/dist/components/blocks/URefBlock.component.d.ts +0 -17
  190. package/dist/components/blocks/URefBlock.component.js +0 -73
  191. package/dist/components/blocks/UTableBlock.component.d.ts +0 -49
  192. package/dist/components/blocks/UTableBlock.component.js +0 -228
  193. package/dist/components/blocks/UTextBlock.component.d.ts +0 -37
  194. package/dist/components/blocks/UTextBlock.component.js +0 -123
  195. package/dist/components/blocks/UThinkBlock.component.d.ts +0 -23
  196. package/dist/components/blocks/UThinkBlock.component.js +0 -90
  197. package/dist/components/blocks/UToolBlock.component.d.ts +0 -20
  198. package/dist/components/blocks/UToolBlock.component.js +0 -80
  199. package/dist/components/buttons/UAttachButton.component.d.ts +0 -22
  200. package/dist/components/buttons/UAttachButton.component.js +0 -89
  201. package/dist/components/buttons/UCopyButton.component.d.ts +0 -20
  202. package/dist/components/buttons/UCopyButton.component.js +0 -81
  203. package/dist/components/buttons/UReportButton.component.d.ts +0 -9
  204. package/dist/components/buttons/UReportButton.component.js +0 -36
  205. package/dist/components/buttons/UReportButton.d.ts +0 -7
  206. package/dist/components/buttons/UReportButton.js +0 -5
  207. package/dist/components/buttons/UReportButton.styles.js +0 -14
  208. package/dist/components/buttons/URetryButton.component.d.ts +0 -11
  209. package/dist/components/buttons/URetryButton.component.js +0 -53
  210. package/dist/components/buttons/URetryButton.d.ts +0 -7
  211. package/dist/components/buttons/URetryButton.js +0 -5
  212. package/dist/components/buttons/URetryButton.styles.js +0 -26
  213. package/dist/components/buttons/UShareButton.component.d.ts +0 -9
  214. package/dist/components/buttons/UShareButton.component.js +0 -36
  215. package/dist/components/buttons/UShareButton.d.ts +0 -7
  216. package/dist/components/buttons/UShareButton.js +0 -5
  217. package/dist/components/buttons/UShareButton.styles.js +0 -14
  218. package/dist/components/buttons/UVoteButton.component.d.ts +0 -15
  219. package/dist/components/buttons/UVoteButton.component.js +0 -73
  220. package/dist/components/message/UMessage.component.d.ts +0 -19
  221. package/dist/components/message/UMessage.component.js +0 -56
  222. package/dist/components/prompt/UPrompt.component.d.ts +0 -25
  223. package/dist/components/prompt/UPrompt.component.js +0 -113
  224. package/dist/components/references/URefCard.component.d.ts +0 -27
  225. package/dist/components/references/URefCard.component.js +0 -109
  226. package/dist/components/references/URefCardGroup.component.d.ts +0 -26
  227. package/dist/components/references/URefCardGroup.component.js +0 -88
  228. package/dist/components/references/URefTag.component.d.ts +0 -13
  229. package/dist/components/references/URefTag.component.js +0 -54
  230. package/dist/components/widgets/UChartWidget.component.js +0 -180
  231. package/dist/components/widgets/UChartWidget.d.ts +0 -7
  232. package/dist/components/widgets/UChartWidget.js +0 -5
  233. package/dist/components/widgets/UImagesWidget.component.js +0 -164
  234. package/dist/components/widgets/UImagesWidget.d.ts +0 -7
  235. package/dist/components/widgets/UImagesWidget.js +0 -5
  236. package/dist/components/widgets/UMapWidget.component.js +0 -65
  237. package/dist/components/widgets/UMapWidget.d.ts +0 -7
  238. package/dist/components/widgets/UMapWidget.js +0 -5
  239. package/dist/components/widgets/UMapWidget.styles.d.ts +0 -1
  240. package/dist/components/widgets/UVideoWidget.component.js +0 -106
  241. package/dist/components/widgets/UVideoWidget.d.ts +0 -7
  242. package/dist/components/widgets/UVideoWidget.js +0 -5
  243. package/dist/components/widgets/UVideoWidget.styles.d.ts +0 -1
  244. package/dist/components/widgets/UWidget.component.js +0 -140
  245. package/dist/components/widgets/UWidget.d.ts +0 -7
  246. package/dist/components/widgets/UWidget.js +0 -5
  247. package/dist/components/widgets/UWidget.styles.d.ts +0 -1
  248. package/dist/events/UCancelEvent.d.ts +0 -6
  249. package/dist/events/USubmitEvent.d.ts +0 -6
  250. package/dist/types/Actions.d.ts +0 -24
  251. package/dist/types/Actions.js +0 -34
  252. package/dist/types/Widgets.js +0 -115
  253. package/dist/utilities/ActionPromptBuilder.d.ts +0 -40
  254. package/dist/utilities/ActionPromptBuilder.js +0 -93
  255. package/dist/utilities/WidgetPromptBuilder.d.ts +0 -28
  256. package/dist/utilities/WidgetPromptBuilder.js +0 -87
  257. package/dist/utilities/converters.d.ts +0 -9
  258. package/dist/utilities/converters.js +0 -19
  259. /package/dist/components/{actions/UQuestionAction.styles.d.ts → blocks/UFileBlock.styles.d.ts} +0 -0
  260. /package/dist/components/{blocks/UFilesBlock.styles.d.ts → intents/UQuestionIntent.styles.d.ts} +0 -0
  261. /package/dist/components/{buttons/UReportButton.styles.d.ts → views/UChartView.styles.d.ts} +0 -0
  262. /package/dist/components/{buttons/URetryButton.styles.d.ts → views/UImagesView.styles.d.ts} +0 -0
  263. /package/dist/components/{buttons/UShareButton.styles.d.ts → views/UMapView.styles.d.ts} +0 -0
  264. /package/dist/components/{widgets/UChartWidget.styles.d.ts → views/UVideoView.styles.d.ts} +0 -0
  265. /package/dist/components/{widgets/UImagesWidget.styles.d.ts → views/UView.styles.d.ts} +0 -0
@@ -0,0 +1,254 @@
1
+ # Usage Guide
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ npm install @iyulab/chat-components
7
+ ```
8
+
9
+ ---
10
+
11
+ ## Importing Components
12
+
13
+ ### All at once
14
+
15
+ ```ts
16
+ import '@iyulab/chat-components';
17
+ ```
18
+
19
+ ### Individual (tree-shakable)
20
+
21
+ ```ts
22
+ import '@iyulab/chat-components/dist/components/message/UMessage.js';
23
+ import '@iyulab/chat-components/dist/components/prompt/UPrompt.js';
24
+ import '@iyulab/chat-components/dist/components/blocks/UMarkedBlock.js';
25
+ ```
26
+
27
+ ### Types only
28
+
29
+ ```ts
30
+ import type { BlockItem, ReferenceSource } from '@iyulab/chat-components';
31
+ import { PresetIntent, PresetView } from '@iyulab/chat-components';
32
+ ```
33
+
34
+ ---
35
+
36
+ ## Basic Chat UI
37
+
38
+ Minimal setup connecting a message list and input prompt:
39
+
40
+ ```html
41
+ <div id="chat-container">
42
+ <div id="messages"></div>
43
+ <u-prompt id="prompt" placeholder="Type a message..."></u-prompt>
44
+ </div>
45
+ ```
46
+
47
+ ```ts
48
+ import '@iyulab/chat-components';
49
+
50
+ const prompt = document.getElementById('prompt');
51
+ const messages = document.getElementById('messages');
52
+
53
+ // Handle send event
54
+ prompt.addEventListener('send', () => {
55
+ const value = prompt.value;
56
+ if (!value) return;
57
+
58
+ // Add user message
59
+ const userMsg = document.createElement('u-message');
60
+ userMsg.position = 'right';
61
+ userMsg.innerHTML = `<u-text-block .value="${value}"></u-text-block>`;
62
+ messages.appendChild(userMsg);
63
+ prompt.value = '';
64
+
65
+ // Add AI response (loading)
66
+ const aiMsg = document.createElement('u-message');
67
+ aiMsg.loading = true;
68
+ messages.appendChild(aiMsg);
69
+
70
+ // Handle LLM streaming...
71
+ });
72
+
73
+ // Handle file attachments
74
+ prompt.addEventListener('attach', (e) => {
75
+ const { files } = e.detail;
76
+ prompt.files = files.map(f => ({
77
+ type: 'file',
78
+ name: f.name,
79
+ size: f.size,
80
+ mimeType: f.type,
81
+ status: 'idle',
82
+ }));
83
+ });
84
+ ```
85
+
86
+ ---
87
+
88
+ ## Rendering Markdown Responses
89
+
90
+ Stream LLM responses as markdown:
91
+
92
+ ```html
93
+ <u-message>
94
+ <u-marked-block
95
+ .value=${"# Hello\n\nThis is **markdown** with `code`."}
96
+ ></u-marked-block>
97
+ </u-message>
98
+ ```
99
+
100
+ With citation references:
101
+
102
+ ```ts
103
+ import type { ReferenceCitation } from '@iyulab/chat-components';
104
+
105
+ const refs: ReferenceCitation[] = [
106
+ {
107
+ startIndex: 10,
108
+ endIndex: 20,
109
+ label: '[1]',
110
+ sources: [{ type: 'web', url: 'https://example.com', title: 'Example' }]
111
+ }
112
+ ];
113
+
114
+ markedBlock.value = '...markdown text...';
115
+ markedBlock.refs = refs;
116
+ ```
117
+
118
+ ---
119
+
120
+ ## Intent System
121
+
122
+ Make the LLM output structured intent-json blocks by adding instructions to the system prompt:
123
+
124
+ ```ts
125
+ import { IntentPromptBuilder, PresetIntent } from '@iyulab/chat-components';
126
+
127
+ // Use preset intents
128
+ IntentPromptBuilder.instance.use(PresetIntent.Questions);
129
+
130
+ // Add custom intent
131
+ IntentPromptBuilder.instance.add({
132
+ type: 'rating',
133
+ description: 'Ask user to rate something on a scale',
134
+ properties: {
135
+ label: { type: 'string', description: 'What to rate' },
136
+ max: { type: 'number', description: 'Max score (default: 5)' }
137
+ },
138
+ required: ['label']
139
+ });
140
+
141
+ // Inject into system prompt
142
+ const systemPrompt = IntentPromptBuilder.instance.build();
143
+ ```
144
+
145
+ Parse intent-json from the LLM response and render components:
146
+
147
+ ```ts
148
+ const [cleanText, intents] = IntentPromptBuilder.instance.parse(llmResponse);
149
+
150
+ for (const intent of intents) {
151
+ if (intent.type === 'question') {
152
+ const el = document.createElement('u-question-intent');
153
+ el.question = intent.properties?.question;
154
+ el.choices = intent.properties?.choices ?? [];
155
+ messageEl.appendChild(el);
156
+ }
157
+ }
158
+
159
+ markedBlock.value = cleanText;
160
+ ```
161
+
162
+ ---
163
+
164
+ ## View System
165
+
166
+ Let the LLM render rich content (charts, maps, videos, etc.) via view-json code blocks:
167
+
168
+ ```ts
169
+ import { ViewPromptBuilder, PresetView } from '@iyulab/chat-components';
170
+
171
+ // Use all preset views
172
+ ViewPromptBuilder.instance.use(PresetView.All);
173
+ // Or selectively
174
+ ViewPromptBuilder.instance.use(PresetView.Images | PresetView.Chart);
175
+
176
+ // Inject into system prompt
177
+ const systemPrompt = ViewPromptBuilder.instance.build();
178
+ ```
179
+
180
+ When `u-marked-block` encounters a view-json code block from the LLM, it automatically renders it via `u-view`:
181
+
182
+ ````
183
+ ```view-json
184
+ {
185
+ "tag": "u-chart-view",
186
+ "properties": {
187
+ "type": "bar",
188
+ "data": { "labels": ["A", "B"], "datasets": [{ "data": [10, 20] }] }
189
+ }
190
+ }
191
+ ```
192
+ ````
193
+
194
+ ---
195
+
196
+ ## Rendering BlockItem Arrays
197
+
198
+ Pattern for rendering structured message data received from a server:
199
+
200
+ ```ts
201
+ import type { BlockItem } from '@iyulab/chat-components';
202
+
203
+ function renderBlocks(blocks: BlockItem[], container: HTMLElement) {
204
+ for (const block of blocks) {
205
+ switch (block.type) {
206
+ case 'text': {
207
+ const el = document.createElement('u-text-block');
208
+ el.value = block.value;
209
+ container.appendChild(el);
210
+ break;
211
+ }
212
+ case 'markdown': {
213
+ const el = document.createElement('u-marked-block');
214
+ el.value = block.value;
215
+ el.refs = block.refs;
216
+ container.appendChild(el);
217
+ break;
218
+ }
219
+ case 'thinking': {
220
+ const el = document.createElement('u-think-block');
221
+ el.loading = block.loading ?? false;
222
+ el.value = block.value;
223
+ container.appendChild(el);
224
+ break;
225
+ }
226
+ case 'tool': {
227
+ const el = document.createElement('u-tool-block');
228
+ el.loading = block.loading ?? false;
229
+ el.title = block.title ?? '';
230
+ el.input = block.input;
231
+ el.output = block.output;
232
+ container.appendChild(el);
233
+ break;
234
+ }
235
+ case 'file': {
236
+ const el = document.createElement('u-file-block');
237
+ el.name = block.name;
238
+ el.size = block.size;
239
+ el.type = block.mimeType;
240
+ el.url = block.url;
241
+ el.status = block.status ?? 'idle';
242
+ container.appendChild(el);
243
+ break;
244
+ }
245
+ case 'reference': {
246
+ const el = document.createElement('u-ref-block');
247
+ el.sources = block.sources;
248
+ container.appendChild(el);
249
+ break;
250
+ }
251
+ }
252
+ }
253
+ }
254
+ ```
@@ -0,0 +1,123 @@
1
+ # IntentPromptBuilder
2
+
3
+ ```ts
4
+ import { IntentPromptBuilder, PresetIntent } from '@iyulab/chat-components';
5
+ ```
6
+
7
+ Singleton utility that registers intents, generates LLM system prompt instructions, and parses `intent-json` blocks from LLM responses.
8
+
9
+ ---
10
+
11
+ ## Overview
12
+
13
+ ```ts
14
+ import { IntentPromptBuilder, PresetIntent } from '@iyulab/chat-components';
15
+
16
+ const builder = IntentPromptBuilder.instance;
17
+
18
+ // 1. Register preset intents
19
+ builder.use(PresetIntent.Questions);
20
+
21
+ // 2. Register custom intents
22
+ builder.add({
23
+ type: 'rating',
24
+ description: 'Prompt the user to rate something on a scale',
25
+ properties: {
26
+ label: { type: 'string', description: 'What to rate' },
27
+ max: { type: 'number', description: 'Maximum score (default: 5)' }
28
+ },
29
+ required: ['label']
30
+ });
31
+
32
+ // 3. Inject into LLM system prompt
33
+ const instruction = builder.build();
34
+
35
+ // 4. Parse LLM response
36
+ const [cleanText, intents] = builder.parse(llmResponse);
37
+ // cleanText → markdown with intent-json blocks removed
38
+ // intents → parsed IntentSchema[]
39
+
40
+ // 5. Render components
41
+ for (const intent of intents) {
42
+ if (intent.type === 'question') {
43
+ const el = document.createElement('u-question-intent');
44
+ el.question = intent.properties?.question as string;
45
+ el.choices = intent.properties?.choices as string[] ?? [];
46
+ container.appendChild(el);
47
+ }
48
+ }
49
+
50
+ markedBlock.value = cleanText;
51
+ ```
52
+
53
+ ---
54
+
55
+ ## API
56
+
57
+ ### `IntentPromptBuilder.instance`
58
+
59
+ Returns the singleton. Created on first access.
60
+
61
+ ### `.use(flags: PresetIntent): this`
62
+
63
+ Registers preset intents by bit flag.
64
+
65
+ ```ts
66
+ builder.use(PresetIntent.Questions);
67
+ builder.use(PresetIntent.All);
68
+ ```
69
+
70
+ ### `.add(definition: IntentDefinition): this`
71
+
72
+ Registers a custom intent. Throws if the same `type` is already registered.
73
+
74
+ ```ts
75
+ interface IntentDefinition {
76
+ type: string;
77
+ description: string;
78
+ properties?: Record<string, JsonSchema>;
79
+ required?: string[];
80
+ }
81
+ ```
82
+
83
+ ### `.build(): string`
84
+
85
+ Returns LLM system prompt instructions for all registered intents. Returns an empty string if no intents are registered.
86
+
87
+ ### `.parse(value: string): [string, IntentSchema[]]`
88
+
89
+ Extracts `intent-json` blocks from an LLM response string.
90
+
91
+ - Index `[0]` — clean markdown text with intent-json blocks removed
92
+ - Index `[1]` — array of parsed `IntentSchema` objects
93
+
94
+ ```ts
95
+ interface IntentSchema {
96
+ type: string;
97
+ properties?: Record<string, unknown>;
98
+ }
99
+ ```
100
+
101
+ ---
102
+
103
+ ## PresetIntent Flags
104
+
105
+ ```ts
106
+ enum PresetIntent {
107
+ Questions = 1 << 0,
108
+ All = Questions
109
+ }
110
+ ```
111
+
112
+ ### Questions Intent Schema
113
+
114
+ ```json
115
+ {
116
+ "type": "question",
117
+ "properties": {
118
+ "question": { "type": "string" },
119
+ "choices": { "type": "array", "items": { "type": "string" }, "minItems": 1, "maxItems": 5 }
120
+ },
121
+ "required": ["choices"]
122
+ }
123
+ ```
@@ -0,0 +1,112 @@
1
+ # ViewPromptBuilder
2
+
3
+ ```ts
4
+ import { ViewPromptBuilder, PresetView } from '@iyulab/chat-components';
5
+ ```
6
+
7
+ Singleton utility that registers views and generates LLM system prompt instructions. No manual parsing is needed — `u-marked-block` automatically renders `view-json` code blocks via `u-view`.
8
+
9
+ ---
10
+
11
+ ## Overview
12
+
13
+ ```ts
14
+ import { ViewPromptBuilder, PresetView } from '@iyulab/chat-components';
15
+
16
+ const builder = ViewPromptBuilder.instance;
17
+
18
+ // 1. Register preset views
19
+ builder.use(PresetView.All);
20
+ // Or selectively
21
+ builder.use(PresetView.Images | PresetView.Chart);
22
+
23
+ // 2. Register a custom view
24
+ builder.add({
25
+ element: MyCustomView, // CustomElementConstructor
26
+ tag: 'my-custom-view',
27
+ description: 'Display a custom visualization',
28
+ properties: {
29
+ data: { type: 'array', description: 'Data array' }
30
+ },
31
+ required: ['data']
32
+ });
33
+
34
+ // 3. Inject into LLM system prompt
35
+ const instruction = builder.build();
36
+ ```
37
+
38
+ When the LLM outputs a `view-json` block, `u-marked-block` renders it automatically:
39
+
40
+ ````
41
+ ```view-json
42
+ {
43
+ "tag": "u-chart-view",
44
+ "properties": {
45
+ "type": "pie",
46
+ "data": {
47
+ "labels": ["A", "B", "C"],
48
+ "datasets": [{ "data": [30, 50, 20] }]
49
+ }
50
+ }
51
+ }
52
+ ```
53
+ ````
54
+
55
+ ---
56
+
57
+ ## API
58
+
59
+ ### `ViewPromptBuilder.instance`
60
+
61
+ Returns the singleton. Created on first access.
62
+
63
+ ### `.use(flags: PresetView): this`
64
+
65
+ Registers preset views by bit flag.
66
+
67
+ ```ts
68
+ builder.use(PresetView.Images);
69
+ builder.use(PresetView.All);
70
+ builder.use(PresetView.Images | PresetView.Chart);
71
+ ```
72
+
73
+ ### `.add(definition: ViewDefinition): this`
74
+
75
+ Registers a custom view and its custom element. Throws if the same `tag` is already registered or if the tag is already defined with a different class.
76
+
77
+ ```ts
78
+ interface ViewDefinition {
79
+ element: CustomElementConstructor;
80
+ tag: string;
81
+ description: string;
82
+ properties?: Record<string, JsonSchema>;
83
+ required?: string[];
84
+ }
85
+ ```
86
+
87
+ ### `.build(): string`
88
+
89
+ Returns LLM system prompt instructions for all registered views. Returns an empty string if no views are registered.
90
+
91
+ ---
92
+
93
+ ## PresetView Flags
94
+
95
+ ```ts
96
+ enum PresetView {
97
+ Images = 1 << 0, // u-images-view
98
+ Video = 1 << 1, // u-video-view
99
+ Map = 1 << 3, // u-map-view
100
+ Chart = 1 << 4, // u-chart-view
101
+ All = Images | Video | Map | Chart
102
+ }
103
+ ```
104
+
105
+ ### Preset View Schema Summary
106
+
107
+ | Tag | Key Properties |
108
+ |-----|----------------|
109
+ | `u-images-view` | `items: [{ src, alt?, caption? }]` |
110
+ | `u-video-view` | `src`, `poster?`, `ratio?` |
111
+ | `u-map-view` | `lat`, `lng`, `zoom?`, `label?`, `description?` |
112
+ | `u-chart-view` | `type`, `data`, `options?` |
@@ -1,3 +0,0 @@
1
- const template = "## Interactive Actions\n\nYou can guide the user with interactive actions by appending `action-json` fenced code blocks at the end of your response.\nThe user will see these as interactive UI elements and can click them to continue the conversation.\n\n**Output format (the fence language must be `action-json`):**\n```action-json\n{\n \"type\": \"action-type-here\",\n \"properties\" : {\n \"key\": \"value\"\n }\n}\n```\n\n**Rules — follow these STRICTLY. Violation means the feature will not work:**\n1. ALWAYS wrap the block in triple backticks with the language identifier `action-json` exactly — never use `json`, plain text, or any other identifier.\n2. `type` must be one of the exact strings listed below. Do not invent new types.\n3. Place ALL action blocks at the very end of your response, after all prose content.\n4. Output valid JSON only — no comments, no trailing commas, no markdown inside the block.\n5. Only include actions when they genuinely help the user continue the conversation.\n6. Do NOT describe or explain the action block in surrounding text (e.g. do not write \"Here are some suggested questions:\"). Just output the block.\n\n**Available actions:**\n{{ACTION_LIST}}\n\n---\n\n{{ACTION_DOCS}}\n";
2
-
3
- export { template as default };
@@ -1,3 +0,0 @@
1
- const template = "## Renderable Widgets\n\nYou can render interactive visual widgets inside your response.\nWhen a widget would make your answer clearer or more useful, output a `widget-json` fenced code block.\n\n**Output format (the fence language must be `widget-json`):**\n```widget-json\n{\n \"tag\": \"exact-widget-tag-here\",\n \"properties\": {\n \"key\": \"value\"\n }\n}\n```\n\n**Rules — follow these strictly:**\n1. The fenced block language identifier must be `widget-json`, not `json` or anything else.\n2. `tag` must be one of the exact strings listed below. Never invent a tag.\n3. Include every property listed under `required`. Omit optional properties only if not needed.\n4. For schema-less `object` fields (e.g., Chart.js `data` / `options`), output a complete, realistic configuration using your knowledge.\n5. Output valid JSON — no comments, no trailing commas.\n\n**Available widgets:**\n{{WIDGET_LIST}}\n\n---\n\n{{WIDGET_DOCS}}\n";
2
-
3
- export { template as default };
@@ -1,58 +0,0 @@
1
- import { nothing, html } from 'lit';
2
- import { property } from 'lit/decorators.js';
3
- import { repeat } from 'lit/directives/repeat.js';
4
- import { UElement } from '@iyulab/components/dist/components/UElement.js';
5
- import { UButton } from '@iyulab/components/dist/components/button/UButton.component.js';
6
- import { styles } from './UQuestionAction.styles.js';
7
-
8
- var __defProp = Object.defineProperty;
9
- var __decorateClass = (decorators, target, key, kind) => {
10
- var result = void 0 ;
11
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
12
- if (decorator = decorators[i])
13
- result = (decorator(target, key, result) ) || result;
14
- if (result) __defProp(target, key, result);
15
- return result;
16
- };
17
- class UQuestionAction extends UElement {
18
- constructor() {
19
- super(...arguments);
20
- this.choices = [];
21
- }
22
- static {
23
- this.styles = [super.styles, styles];
24
- }
25
- static {
26
- this.dependencies = {
27
- "u-button": UButton
28
- };
29
- }
30
- render() {
31
- if (!this.choices || this.choices.length === 0) {
32
- return nothing;
33
- }
34
- return html`
35
- <p class="question" ?hidden=${!this.question}>${this.question}</p>
36
- <div class="choices">
37
- ${repeat(this.choices, (value, index) => html`
38
- <u-button @click=${() => this.handleChoiceClick(index)}>
39
- ${value}
40
- </u-button>
41
- `)}
42
- </div>
43
- `;
44
- }
45
- handleChoiceClick(index) {
46
- const value = this.choices[index];
47
- if (!value) return;
48
- this.emit("u-submit", { value });
49
- }
50
- }
51
- __decorateClass([
52
- property({ type: String })
53
- ], UQuestionAction.prototype, "question");
54
- __decorateClass([
55
- property({ type: Array })
56
- ], UQuestionAction.prototype, "choices");
57
-
58
- export { UQuestionAction };
@@ -1,7 +0,0 @@
1
- import { UQuestionAction } from './UQuestionAction.component.js';
2
- declare global {
3
- interface HTMLElementTagNameMap {
4
- "u-question-action": UQuestionAction;
5
- }
6
- }
7
- export { UQuestionAction };
@@ -1,5 +0,0 @@
1
- import { UQuestionAction } from './UQuestionAction.component.js';
2
-
3
- UQuestionAction.define("u-question-action");
4
-
5
- export { UQuestionAction };
@@ -1,25 +0,0 @@
1
- import { UElement } from '@iyulab/components/dist/components/UElement.js';
2
- /**
3
- * 코드 블록을 렌더링하는 컴포넌트입니다.
4
- * 언어와 코드를 받아 syntax highlighting을 적용합니다.
5
- */
6
- export declare class UCodeBlock extends UElement {
7
- static styles: import('lit').CSSResultGroup[];
8
- static dependencies: Record<string, typeof UElement>;
9
- /** 클립보드 복사 상태를 나타내는 플래그입니다. */
10
- isCopied: boolean;
11
- /** 코드 블록이 로딩 중인지 여부를 나타냅니다. */
12
- loading: boolean;
13
- /** 코드 블록의 헤더를 숨길지 여부를 지정합니다. */
14
- headless: boolean;
15
- /** 코드 언어를 지정합니다. */
16
- lang: string;
17
- /** 표시할 코드 내용입니다. */
18
- value?: string;
19
- render(): import('lit-html').TemplateResult<1>;
20
- /**
21
- * slot에 할당된 코드를 value로 설정합니다.
22
- * 이 기능을 통해 HTML 내에 직접 코드를 작성할 수 있습니다.
23
- */
24
- private handleSlotChange;
25
- }
@@ -1,88 +0,0 @@
1
- import { html } from 'lit';
2
- import { state, property } from 'lit/decorators.js';
3
- import { unsafeHTML } from 'lit/directives/unsafe-html.js';
4
- import hljs from 'highlight.js';
5
- import { UElement } from '@iyulab/components/dist/components/UElement.js';
6
- import { UIcon } from '@iyulab/components/dist/components/icon/UIcon.component.js';
7
- import { USpinner } from '@iyulab/components/dist/components/spinner/USpinner.component.js';
8
- import { UCopyButton } from '../buttons/UCopyButton.component.js';
9
- import { styles } from './UCodeBlock.styles.js';
10
-
11
- var __defProp = Object.defineProperty;
12
- var __decorateClass = (decorators, target, key, kind) => {
13
- var result = void 0 ;
14
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
15
- if (decorator = decorators[i])
16
- result = (decorator(target, key, result) ) || result;
17
- if (result) __defProp(target, key, result);
18
- return result;
19
- };
20
- class UCodeBlock extends UElement {
21
- constructor() {
22
- super(...arguments);
23
- this.isCopied = false;
24
- this.loading = false;
25
- this.headless = false;
26
- this.lang = "plaintext";
27
- /**
28
- * slot에 할당된 코드를 value로 설정합니다.
29
- * 이 기능을 통해 HTML 내에 직접 코드를 작성할 수 있습니다.
30
- */
31
- this.handleSlotChange = (e) => {
32
- const slot = e.target;
33
- const nodes = slot.assignedNodes({ flatten: true });
34
- this.value = nodes.map((node) => node.textContent).join("\n\n");
35
- };
36
- }
37
- static {
38
- this.styles = [super.styles, styles];
39
- }
40
- static {
41
- this.dependencies = {
42
- "u-icon": UIcon,
43
- "u-spinner": USpinner,
44
- "u-copy-button": UCopyButton
45
- };
46
- }
47
- render() {
48
- const lang = hljs.getLanguage(this.lang) ? this.lang : "plaintext";
49
- const value = this.value || "";
50
- return html`
51
- <div class="header" ?hidden=${this.headless}>
52
- <span class="status">
53
- ${this.loading ? html`<u-spinner></u-spinner>` : html`<u-icon lib="internal" name="code-slash"></u-icon>`}
54
- </span>
55
- <span class="lang">
56
- ${lang}
57
- </span>
58
- <div style="flex: 1"></div>
59
- <u-copy-button
60
- .value=${value}
61
- ></u-copy-button>
62
- </div>
63
-
64
- <pre class="hljs">${unsafeHTML(hljs.highlight(value, {
65
- language: lang
66
- }).value)}</pre>
67
-
68
- <slot hidden @slotchange=${this.handleSlotChange}></slot>
69
- `;
70
- }
71
- }
72
- __decorateClass([
73
- state()
74
- ], UCodeBlock.prototype, "isCopied");
75
- __decorateClass([
76
- property({ type: Boolean, reflect: true })
77
- ], UCodeBlock.prototype, "loading");
78
- __decorateClass([
79
- property({ type: Boolean, reflect: true })
80
- ], UCodeBlock.prototype, "headless");
81
- __decorateClass([
82
- property({ type: String, reflect: true })
83
- ], UCodeBlock.prototype, "lang");
84
- __decorateClass([
85
- property({ type: String })
86
- ], UCodeBlock.prototype, "value");
87
-
88
- export { UCodeBlock };