@iyulab/chat-components 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/CHANGELOG.md +124 -21
  2. package/README.md +133 -16
  3. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js +9 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.122.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 +32 -2
  50. package/dist/components/prompt/UPrompt.js +118 -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 +7 -0
  79. package/dist/events/StopEvent.d.ts +7 -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 +32 -16
  146. package/dist/assets/action-prompt.md.js +0 -3
  147. package/dist/assets/widget-prompt.md.js +0 -3
  148. package/dist/components/actions/UQuestionAction.component.js +0 -58
  149. package/dist/components/actions/UQuestionAction.d.ts +0 -7
  150. package/dist/components/actions/UQuestionAction.js +0 -5
  151. package/dist/components/blocks/UCodeBlock.component.d.ts +0 -25
  152. package/dist/components/blocks/UCodeBlock.component.js +0 -88
  153. package/dist/components/blocks/UFilesBlock.component.d.ts +0 -22
  154. package/dist/components/blocks/UFilesBlock.component.js +0 -192
  155. package/dist/components/blocks/UFilesBlock.d.ts +0 -7
  156. package/dist/components/blocks/UFilesBlock.js +0 -5
  157. package/dist/components/blocks/UJsonBlock.component.d.ts +0 -45
  158. package/dist/components/blocks/UJsonBlock.component.js +0 -140
  159. package/dist/components/blocks/UMarkedBlock.component.d.ts +0 -40
  160. package/dist/components/blocks/UMarkedBlock.component.js +0 -159
  161. package/dist/components/blocks/URefBlock.component.d.ts +0 -17
  162. package/dist/components/blocks/URefBlock.component.js +0 -73
  163. package/dist/components/blocks/UTableBlock.component.d.ts +0 -49
  164. package/dist/components/blocks/UTableBlock.component.js +0 -228
  165. package/dist/components/blocks/UTextBlock.component.d.ts +0 -37
  166. package/dist/components/blocks/UTextBlock.component.js +0 -123
  167. package/dist/components/blocks/UThinkBlock.component.d.ts +0 -23
  168. package/dist/components/blocks/UThinkBlock.component.js +0 -90
  169. package/dist/components/blocks/UToolBlock.component.d.ts +0 -20
  170. package/dist/components/blocks/UToolBlock.component.js +0 -80
  171. package/dist/components/buttons/UAttachButton.component.d.ts +0 -22
  172. package/dist/components/buttons/UAttachButton.component.js +0 -89
  173. package/dist/components/buttons/UCopyButton.component.d.ts +0 -20
  174. package/dist/components/buttons/UCopyButton.component.js +0 -81
  175. package/dist/components/buttons/UReportButton.component.d.ts +0 -9
  176. package/dist/components/buttons/UReportButton.component.js +0 -36
  177. package/dist/components/buttons/UReportButton.d.ts +0 -7
  178. package/dist/components/buttons/UReportButton.js +0 -5
  179. package/dist/components/buttons/UReportButton.styles.js +0 -14
  180. package/dist/components/buttons/URetryButton.component.d.ts +0 -11
  181. package/dist/components/buttons/URetryButton.component.js +0 -53
  182. package/dist/components/buttons/URetryButton.d.ts +0 -7
  183. package/dist/components/buttons/URetryButton.js +0 -5
  184. package/dist/components/buttons/URetryButton.styles.js +0 -26
  185. package/dist/components/buttons/UShareButton.component.d.ts +0 -9
  186. package/dist/components/buttons/UShareButton.component.js +0 -36
  187. package/dist/components/buttons/UShareButton.d.ts +0 -7
  188. package/dist/components/buttons/UShareButton.js +0 -5
  189. package/dist/components/buttons/UShareButton.styles.js +0 -14
  190. package/dist/components/buttons/UVoteButton.component.d.ts +0 -15
  191. package/dist/components/buttons/UVoteButton.component.js +0 -73
  192. package/dist/components/message/UMessage.component.d.ts +0 -19
  193. package/dist/components/message/UMessage.component.js +0 -56
  194. package/dist/components/prompt/UPrompt.component.d.ts +0 -25
  195. package/dist/components/prompt/UPrompt.component.js +0 -113
  196. package/dist/components/references/URefCard.component.d.ts +0 -27
  197. package/dist/components/references/URefCard.component.js +0 -109
  198. package/dist/components/references/URefCardGroup.component.d.ts +0 -26
  199. package/dist/components/references/URefCardGroup.component.js +0 -88
  200. package/dist/components/references/URefTag.component.d.ts +0 -13
  201. package/dist/components/references/URefTag.component.js +0 -54
  202. package/dist/components/widgets/UChartWidget.component.js +0 -180
  203. package/dist/components/widgets/UChartWidget.d.ts +0 -7
  204. package/dist/components/widgets/UChartWidget.js +0 -5
  205. package/dist/components/widgets/UImagesWidget.component.js +0 -164
  206. package/dist/components/widgets/UImagesWidget.d.ts +0 -7
  207. package/dist/components/widgets/UImagesWidget.js +0 -5
  208. package/dist/components/widgets/UMapWidget.component.js +0 -65
  209. package/dist/components/widgets/UMapWidget.d.ts +0 -7
  210. package/dist/components/widgets/UMapWidget.js +0 -5
  211. package/dist/components/widgets/UMapWidget.styles.d.ts +0 -1
  212. package/dist/components/widgets/UVideoWidget.component.js +0 -106
  213. package/dist/components/widgets/UVideoWidget.d.ts +0 -7
  214. package/dist/components/widgets/UVideoWidget.js +0 -5
  215. package/dist/components/widgets/UVideoWidget.styles.d.ts +0 -1
  216. package/dist/components/widgets/UWidget.component.js +0 -140
  217. package/dist/components/widgets/UWidget.d.ts +0 -7
  218. package/dist/components/widgets/UWidget.js +0 -5
  219. package/dist/components/widgets/UWidget.styles.d.ts +0 -1
  220. package/dist/events/UCancelEvent.d.ts +0 -6
  221. package/dist/events/USubmitEvent.d.ts +0 -6
  222. package/dist/types/Actions.d.ts +0 -24
  223. package/dist/types/Actions.js +0 -34
  224. package/dist/types/Widgets.js +0 -115
  225. package/dist/utilities/ActionPromptBuilder.d.ts +0 -40
  226. package/dist/utilities/ActionPromptBuilder.js +0 -93
  227. package/dist/utilities/WidgetPromptBuilder.d.ts +0 -28
  228. package/dist/utilities/WidgetPromptBuilder.js +0 -87
  229. package/dist/utilities/converters.d.ts +0 -9
  230. package/dist/utilities/converters.js +0 -19
  231. /package/dist/components/{actions/UQuestionAction.styles.d.ts → blocks/UFileBlock.styles.d.ts} +0 -0
  232. /package/dist/components/{blocks/UFilesBlock.styles.d.ts → intents/UQuestionIntent.styles.d.ts} +0 -0
  233. /package/dist/components/{buttons/UReportButton.styles.d.ts → views/UChartView.styles.d.ts} +0 -0
  234. /package/dist/components/{buttons/URetryButton.styles.d.ts → views/UImagesView.styles.d.ts} +0 -0
  235. /package/dist/components/{buttons/UShareButton.styles.d.ts → views/UMapView.styles.d.ts} +0 -0
  236. /package/dist/components/{widgets/UChartWidget.styles.d.ts → views/UVideoView.styles.d.ts} +0 -0
  237. /package/dist/components/{widgets/UImagesWidget.styles.d.ts → views/UView.styles.d.ts} +0 -0
@@ -1,115 +0,0 @@
1
- import { UImagesWidget } from '../components/widgets/UImagesWidget.component.js';
2
- import { UVideoWidget } from '../components/widgets/UVideoWidget.component.js';
3
- import { UMapWidget } from '../components/widgets/UMapWidget.component.js';
4
- import { UChartWidget } from '../components/widgets/UChartWidget.component.js';
5
-
6
- var PresetWidget = /* @__PURE__ */ ((PresetWidget2) => {
7
- PresetWidget2[PresetWidget2["Images"] = 1] = "Images";
8
- PresetWidget2[PresetWidget2["Video"] = 2] = "Video";
9
- PresetWidget2[PresetWidget2["Map"] = 8] = "Map";
10
- PresetWidget2[PresetWidget2["Chart"] = 16] = "Chart";
11
- PresetWidget2[PresetWidget2["All"] = 27] = "All";
12
- return PresetWidget2;
13
- })(PresetWidget || {});
14
- const PRESET_WIDGET_LIST = [
15
- 1 /* Images */,
16
- 2 /* Video */,
17
- 8 /* Map */,
18
- 16 /* Chart */
19
- ];
20
- const PRESET_WIDGET_DEFINITIONS = /* @__PURE__ */ new Map([
21
- [
22
- 1 /* Images */,
23
- {
24
- element: UImagesWidget,
25
- tag: "u-images-widget",
26
- description: "Display multiple images in a scrollable gallery",
27
- properties: {
28
- items: {
29
- type: "array",
30
- items: {
31
- type: "object",
32
- properties: {
33
- src: { type: "string", description: "Image URL" },
34
- alt: { type: "string", description: "Alt text for accessibility" },
35
- caption: { type: "string", description: "Image caption" }
36
- },
37
- required: ["src"]
38
- },
39
- minItems: 1,
40
- description: "Array of image objects"
41
- }
42
- },
43
- required: ["items"]
44
- }
45
- ],
46
- [
47
- 2 /* Video */,
48
- {
49
- element: UVideoWidget,
50
- tag: "u-video-widget",
51
- description: "Embed video from YouTube, Vimeo, or Others. Provide a direct video file URL or a platform URL.",
52
- properties: {
53
- src: { type: "string", description: "Video URL (YouTube, Vimeo, or direct video file URL)" },
54
- poster: { type: "string", description: "Poster image URL" },
55
- ratio: {
56
- type: "string",
57
- enum: ["16:9", "4:3", "1:1"],
58
- default: "16:9",
59
- description: "Video aspect ratio"
60
- }
61
- },
62
- required: ["src"]
63
- }
64
- ],
65
- [
66
- 8 /* Map */,
67
- {
68
- element: UMapWidget,
69
- tag: "u-map-widget",
70
- description: "Display a map showing a single location",
71
- properties: {
72
- lat: { type: "number", description: "Latitude coordinate" },
73
- lng: { type: "number", description: "Longitude coordinate" },
74
- zoom: {
75
- type: "integer",
76
- minimum: 1,
77
- maximum: 20,
78
- default: 15,
79
- description: "Map zoom level"
80
- },
81
- label: { type: "string", description: "Location title" },
82
- description: { type: "string", description: "Location description" }
83
- },
84
- required: ["lat", "lng"]
85
- }
86
- ],
87
- [
88
- 16 /* Chart */,
89
- {
90
- element: UChartWidget,
91
- tag: "u-chart-widget",
92
- description: "Display charts using Chart.js v4 format. Use standard Chart.js configuration (type, data, options). The widget accepts the exact same structure as Chart.js - no conversion needed.",
93
- properties: {
94
- type: {
95
- type: "string",
96
- enum: ["bar", "line", "pie", "doughnut", "radar", "polarArea", "bubble", "scatter"],
97
- description: "Chart.js chart type"
98
- },
99
- data: {
100
- type: "object",
101
- description: "Chart.js data configuration",
102
- additionalProperties: true
103
- },
104
- options: {
105
- type: "object",
106
- description: "Chart.js options configuration (optional)",
107
- additionalProperties: true
108
- }
109
- },
110
- required: ["type", "data"]
111
- }
112
- ]
113
- ]);
114
-
115
- export { PRESET_WIDGET_DEFINITIONS, PRESET_WIDGET_LIST, PresetWidget };
@@ -1,40 +0,0 @@
1
- import { PresetAction, ActionDefinition, ActionSchema } from '../types/Actions.js';
2
- /**
3
- * Action 등록, LLM 인스트럭션 빌드, 텍스트 추출을 통합 제공하는 유틸리티
4
- *
5
- * @example
6
- * ActionPromptBuilder.use(PresetAction.All);
7
- * const prompt = ActionPromptBuilder.buildPrompt();
8
- * const [clean, templates] = ActionPromptBuilder.extractPrompt(llmText);
9
- */
10
- export declare class ActionPromptBuilder {
11
- private static _instance;
12
- private actions;
13
- /**
14
- * 싱글톤 인스턴스를 반환합니다. 최초 호출 시 인스턴스가 생성됩니다.
15
- */
16
- static get instance(): ActionPromptBuilder;
17
- /**
18
- * Action 정의를 등록합니다. 같은 type이 이미 등록되어 있으면 에러를 던집니다.
19
- * @throws {Error} 같은 type의 action이 이미 등록된 경우
20
- */
21
- add(definition: ActionDefinition): ActionPromptBuilder;
22
- /**
23
- * 미리 정의된 프리셋 Action을 등록합니다.
24
- * @example
25
- * ActionPromptBuilder.use(PresetAction.Questions);
26
- * ActionPromptBuilder.use(PresetAction.All);
27
- */
28
- use(flags: PresetAction): ActionPromptBuilder;
29
- /**
30
- * 등록된 action들에 대한 LLM 시스템 프롬프트 인스트럭션을 생성합니다.
31
- */
32
- build(): string;
33
- /**
34
- * LLM 응답 텍스트에서 `action-json` 코드블록을 추출합니다.
35
- *
36
- * @param value - LLM 응답 텍스트
37
- * @returns `[actions, rest]` — actions는 파싱된 JSON 객체 배열, rest는 블록이 제거된 나머지 텍스트
38
- */
39
- parse(value: string): [ActionSchema[], string];
40
- }
@@ -1,93 +0,0 @@
1
- import template from '../assets/action-prompt.md.js';
2
- import { PRESET_ACTION_LIST, PRESET_ACTION_DEFINITIONS } from '../types/Actions.js';
3
-
4
- class ActionPromptBuilder {
5
- constructor() {
6
- this.actions = /* @__PURE__ */ new Map();
7
- }
8
- /**
9
- * 싱글톤 인스턴스를 반환합니다. 최초 호출 시 인스턴스가 생성됩니다.
10
- */
11
- static get instance() {
12
- if (!this._instance) {
13
- this._instance = new ActionPromptBuilder();
14
- }
15
- return this._instance;
16
- }
17
- /**
18
- * Action 정의를 등록합니다. 같은 type이 이미 등록되어 있으면 에러를 던집니다.
19
- * @throws {Error} 같은 type의 action이 이미 등록된 경우
20
- */
21
- add(definition) {
22
- if (this.actions.has(definition.type)) {
23
- throw new Error(`Action with type "${definition.type}" is already registered.`);
24
- }
25
- this.actions.set(definition.type, definition);
26
- return this;
27
- }
28
- /**
29
- * 미리 정의된 프리셋 Action을 등록합니다.
30
- * @example
31
- * ActionPromptBuilder.use(PresetAction.Questions);
32
- * ActionPromptBuilder.use(PresetAction.All);
33
- */
34
- use(flags) {
35
- for (const flag of PRESET_ACTION_LIST) {
36
- if (flags & flag) {
37
- const definition = PRESET_ACTION_DEFINITIONS.get(flag);
38
- if (definition && !this.actions.has(definition.type)) {
39
- this.actions.set(definition.type, definition);
40
- }
41
- }
42
- }
43
- return this;
44
- }
45
- /**
46
- * 등록된 action들에 대한 LLM 시스템 프롬프트 인스트럭션을 생성합니다.
47
- */
48
- build() {
49
- if (this.actions.size === 0) return "";
50
- const defs = Array.from(this.actions.values());
51
- const actionList = defs.map((d) => `- \`${d.type}\`: ${d.description}`).join("\n");
52
- const actionDocs = defs.map((def) => {
53
- const lines = [
54
- `### ${def.type}`,
55
- "",
56
- def.description,
57
- "",
58
- `**Type:** \`${def.type}\``
59
- ];
60
- if (def.properties) {
61
- lines.push(
62
- "",
63
- "**Properties (JSON Schema):**",
64
- "```json",
65
- JSON.stringify({ type: "object", properties: def.properties }, null, 2),
66
- "```"
67
- );
68
- }
69
- return lines.join("\n");
70
- }).join("\n\n---\n\n");
71
- return template.replace("{{ACTION_LIST}}", actionList).replace("{{ACTION_DOCS}}", actionDocs);
72
- }
73
- /**
74
- * LLM 응답 텍스트에서 `action-json` 코드블록을 추출합니다.
75
- *
76
- * @param value - LLM 응답 텍스트
77
- * @returns `[actions, rest]` — actions는 파싱된 JSON 객체 배열, rest는 블록이 제거된 나머지 텍스트
78
- */
79
- parse(value) {
80
- const pattern = /```action-json\s*([\s\S]*?)```/g;
81
- const actions = [];
82
- const rest = value.replace(pattern, (_, json) => {
83
- try {
84
- actions.push(JSON.parse(json.trim()));
85
- } catch {
86
- }
87
- return "";
88
- }).trim();
89
- return [actions, rest];
90
- }
91
- }
92
-
93
- export { ActionPromptBuilder };
@@ -1,28 +0,0 @@
1
- import { PresetWidget, WidgetDefinition } from '../types/Widgets.js';
2
- /**
3
- * 위젯 등록, LLM 인스트럭션 빌드, HTML 렌더링을 통합 제공하는 유틸리티
4
- */
5
- export declare class WidgetPromptBuilder {
6
- private static _instance;
7
- private widgets;
8
- /**
9
- * 싱글톤 인스턴스를 반환합니다. 최초 호출 시 인스턴스가 생성됩니다.
10
- */
11
- static get instance(): WidgetPromptBuilder;
12
- /**
13
- * 위젯 정의를 등록합니다. 같은 이름의 위젯이 이미 등록되어 있으면 에러를 던집니다.
14
- * @throws {Error} 같은 이름의 위젯이 이미 등록된 경우 또는 같은 태그의 커스텀 요소가 다른 클래스에 의해 정의된 경우
15
- */
16
- add(definition: WidgetDefinition): WidgetPromptBuilder;
17
- /**
18
- * 미리 정의된 프리셋 위젯을 사용합니다.
19
- * @example
20
- * WidgetRegistry.use(Widget.Images | Widget.Chart);
21
- * WidgetRegistry.use(Widget.All);
22
- */
23
- use(flags: PresetWidget): WidgetPromptBuilder;
24
- /**
25
- * 등록된 위젯들에 대한 LLM 인스트럭션 문자열을 생성합니다.
26
- */
27
- build(): string;
28
- }
@@ -1,87 +0,0 @@
1
- import template from '../assets/widget-prompt.md.js';
2
- import { UElement } from '@iyulab/components/dist/components/UElement.js';
3
- import { PRESET_WIDGET_LIST, PRESET_WIDGET_DEFINITIONS } from '../types/Widgets.js';
4
-
5
- class WidgetPromptBuilder {
6
- constructor() {
7
- this.widgets = /* @__PURE__ */ new Map();
8
- }
9
- /**
10
- * 싱글톤 인스턴스를 반환합니다. 최초 호출 시 인스턴스가 생성됩니다.
11
- */
12
- static get instance() {
13
- if (!this._instance) {
14
- this._instance = new WidgetPromptBuilder();
15
- }
16
- return this._instance;
17
- }
18
- /**
19
- * 위젯 정의를 등록합니다. 같은 이름의 위젯이 이미 등록되어 있으면 에러를 던집니다.
20
- * @throws {Error} 같은 이름의 위젯이 이미 등록된 경우 또는 같은 태그의 커스텀 요소가 다른 클래스에 의해 정의된 경우
21
- */
22
- add(definition) {
23
- if (this.widgets.has(definition.tag)) {
24
- throw new Error(`Widget with tag "${definition.tag}" is already registered.`);
25
- }
26
- const constructor = customElements.get(definition.tag);
27
- if (constructor && constructor !== definition.element) {
28
- throw new Error(`Custom element with tag "${definition.tag}" is already defined to a different class.`);
29
- }
30
- if (definition.element.prototype instanceof UElement) {
31
- definition.element.define(definition.tag);
32
- } else {
33
- customElements.define(definition.tag, definition.element);
34
- }
35
- this.widgets.set(definition.tag, definition);
36
- return this;
37
- }
38
- /**
39
- * 미리 정의된 프리셋 위젯을 사용합니다.
40
- * @example
41
- * WidgetRegistry.use(Widget.Images | Widget.Chart);
42
- * WidgetRegistry.use(Widget.All);
43
- */
44
- use(flags) {
45
- for (const flag of PRESET_WIDGET_LIST) {
46
- if (flags & flag) {
47
- const definition = PRESET_WIDGET_DEFINITIONS.get(flag);
48
- if (definition) {
49
- this.add(definition);
50
- }
51
- }
52
- }
53
- return this;
54
- }
55
- /**
56
- * 등록된 위젯들에 대한 LLM 인스트럭션 문자열을 생성합니다.
57
- */
58
- build() {
59
- if (this.widgets.size === 0) return "";
60
- const widgets = Array.from(this.widgets.values());
61
- const widgetList = widgets.map((w) => `- \`${w.tag}\`: ${w.description}`).join("\n");
62
- const widgetDocs = widgets.map((w) => {
63
- const lines = [
64
- `### ${w.tag}`,
65
- "",
66
- `**Tag:** \`${w.tag}\``
67
- ];
68
- if (w.properties) {
69
- lines.push(
70
- "",
71
- "**Properties (JSON Schema):**",
72
- "```json",
73
- JSON.stringify({
74
- type: "object",
75
- properties: w.properties,
76
- ...w.required ? { required: w.required } : {}
77
- }, null, 2),
78
- "```"
79
- );
80
- }
81
- return lines.join("\n");
82
- }).join("\n\n---\n\n");
83
- return template.replace("{{WIDGET_LIST}}", widgetList).replace("{{WIDGET_DOCS}}", widgetDocs);
84
- }
85
- }
86
-
87
- export { WidgetPromptBuilder };
@@ -1,9 +0,0 @@
1
- import { JsonNode } from '../types/JsonNode';
2
- /**
3
- * 이 컨버터는 JsonNode 타입을 사용하여 JSON 데이터를 처리합니다.
4
- * 문자열 어트리뷰트로 전달된 JSON 문자열을 객체로 변환/직렬화합니다.
5
- */
6
- export declare const jsonAttrConverter: {
7
- fromAttribute: (value: string | null) => JsonNode;
8
- toAttribute: (value: JsonNode) => string;
9
- };
@@ -1,19 +0,0 @@
1
- const jsonAttrConverter = {
2
- fromAttribute: (value) => {
3
- if (!value || !value.trim()) return {};
4
- try {
5
- return JSON.parse(value);
6
- } catch {
7
- return {};
8
- }
9
- },
10
- toAttribute: (value) => {
11
- try {
12
- return JSON.stringify(value);
13
- } catch {
14
- return "{}";
15
- }
16
- }
17
- };
18
-
19
- export { jsonAttrConverter };