@iyulab/chat-components 0.3.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 (208) hide show
  1. package/CHANGELOG.md +146 -0
  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 +10 -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/UFileBlock.styles.js +128 -0
  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 +52 -0
  23. package/dist/components/blocks/UTableBlock.js +198 -0
  24. package/dist/components/blocks/UTableBlock.styles.js +133 -0
  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/intents/UQuestionIntent.d.ts +22 -0
  44. package/dist/components/intents/UQuestionIntent.js +41 -0
  45. package/dist/components/intents/UQuestionIntent.styles.js +43 -0
  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 +42 -15
  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 +43 -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/views/UChartView.d.ts +39 -0
  62. package/dist/components/views/UChartView.js +167 -0
  63. package/dist/components/views/UChartView.styles.js +86 -0
  64. package/dist/components/views/UImagesView.d.ts +33 -0
  65. package/dist/components/views/UImagesView.js +144 -0
  66. package/dist/components/views/UImagesView.styles.d.ts +1 -0
  67. package/dist/components/views/UImagesView.styles.js +219 -0
  68. package/dist/components/views/UMapView.d.ts +24 -0
  69. package/dist/components/views/UMapView.js +45 -0
  70. package/dist/components/views/UMapView.styles.d.ts +1 -0
  71. package/dist/components/views/UMapView.styles.js +47 -0
  72. package/dist/components/views/UVideoView.d.ts +25 -0
  73. package/dist/components/views/UVideoView.js +81 -0
  74. package/dist/components/views/UVideoView.styles.d.ts +1 -0
  75. package/dist/components/views/UVideoView.styles.js +36 -0
  76. package/dist/components/views/UView.d.ts +46 -0
  77. package/dist/components/views/UView.js +113 -0
  78. package/dist/components/views/UView.styles.d.ts +1 -0
  79. package/dist/components/views/UView.styles.js +33 -0
  80. package/dist/events/AttachEvent.d.ts +9 -0
  81. package/dist/events/ChoiceEvent.d.ts +9 -0
  82. package/dist/events/SendEvent.d.ts +7 -0
  83. package/dist/events/StopEvent.d.ts +7 -0
  84. package/dist/index.d.ts +15 -6
  85. package/dist/index.js +28 -38
  86. package/dist/react/UAttachButton.d.ts +11 -0
  87. package/dist/react/UAttachButton.js +12 -0
  88. package/dist/react/UChartView.d.ts +9 -0
  89. package/dist/react/UChartView.js +10 -0
  90. package/dist/react/UCodeBlock.d.ts +9 -0
  91. package/dist/react/UCodeBlock.js +10 -0
  92. package/dist/react/UCopyButton.d.ts +9 -0
  93. package/dist/react/UCopyButton.js +10 -0
  94. package/dist/react/UFileBlock.d.ts +11 -0
  95. package/dist/react/UFileBlock.js +12 -0
  96. package/dist/react/UImagesView.d.ts +9 -0
  97. package/dist/react/UImagesView.js +10 -0
  98. package/dist/react/UJsonBlock.d.ts +9 -0
  99. package/dist/react/UJsonBlock.js +10 -0
  100. package/dist/react/UMapView.d.ts +9 -0
  101. package/dist/react/UMapView.js +10 -0
  102. package/dist/react/UMarkedBlock.d.ts +9 -0
  103. package/dist/react/UMarkedBlock.js +10 -0
  104. package/dist/react/UMessage.d.ts +9 -0
  105. package/dist/react/UMessage.js +10 -0
  106. package/dist/react/UPrompt.d.ts +13 -0
  107. package/dist/react/UPrompt.js +13 -0
  108. package/dist/react/UQuestionIntent.d.ts +11 -0
  109. package/dist/react/UQuestionIntent.js +12 -0
  110. package/dist/react/URefBlock.d.ts +9 -0
  111. package/dist/react/URefBlock.js +10 -0
  112. package/dist/react/URefCard.d.ts +9 -0
  113. package/dist/react/URefCard.js +10 -0
  114. package/dist/react/URefCardGroup.d.ts +9 -0
  115. package/dist/react/URefCardGroup.js +10 -0
  116. package/dist/react/URefTag.d.ts +9 -0
  117. package/dist/react/URefTag.js +10 -0
  118. package/dist/react/UTableBlock.d.ts +9 -0
  119. package/dist/react/UTableBlock.js +10 -0
  120. package/dist/react/UTextBlock.d.ts +9 -0
  121. package/dist/react/UTextBlock.js +10 -0
  122. package/dist/react/UThinkBlock.d.ts +9 -0
  123. package/dist/react/UThinkBlock.js +10 -0
  124. package/dist/react/UToolBlock.d.ts +9 -0
  125. package/dist/react/UToolBlock.js +10 -0
  126. package/dist/react/UVideoView.d.ts +9 -0
  127. package/dist/react/UVideoView.js +10 -0
  128. package/dist/react/UView.d.ts +9 -0
  129. package/dist/react/UView.js +10 -0
  130. package/dist/react/UVoteButton.d.ts +9 -0
  131. package/dist/react/UVoteButton.js +10 -0
  132. package/dist/react/index.d.ts +23 -0
  133. package/dist/react/index.js +23 -0
  134. package/dist/types/BlockItem.d.ts +21 -1
  135. package/dist/types/Intents.d.ts +26 -0
  136. package/dist/types/Intents.js +30 -0
  137. package/dist/types/JsonSchema.d.ts +59 -0
  138. package/dist/types/Views.d.ts +34 -0
  139. package/dist/types/Views.js +150 -0
  140. package/dist/utilities/IntentPromptBuilder.d.ts +40 -0
  141. package/dist/utilities/IntentPromptBuilder.js +95 -0
  142. package/dist/utilities/ViewPromptBuilder.d.ts +28 -0
  143. package/dist/utilities/ViewPromptBuilder.js +76 -0
  144. package/dist/utilities/dom-agent/DOMAgent.d.ts +74 -0
  145. package/dist/utilities/dom-agent/DOMController.d.ts +78 -0
  146. package/dist/utilities/dom-agent/DOMPromptBuilder.d.ts +54 -0
  147. package/dist/utilities/dom-agent/DOMScanner.d.ts +83 -0
  148. package/dist/utilities/dom-agent/index.d.ts +9 -0
  149. package/dist/utilities/dom-agent/types.d.ts +209 -0
  150. package/package.json +34 -18
  151. package/dist/components/blocks/UCodeBlock.component.d.ts +0 -23
  152. package/dist/components/blocks/UCodeBlock.component.js +0 -76
  153. package/dist/components/blocks/UJsonBlock.component.d.ts +0 -45
  154. package/dist/components/blocks/UJsonBlock.component.js +0 -140
  155. package/dist/components/blocks/UMarkedBlock.component.d.ts +0 -45
  156. package/dist/components/blocks/UMarkedBlock.component.js +0 -129
  157. package/dist/components/blocks/URefBlock.component.d.ts +0 -17
  158. package/dist/components/blocks/URefBlock.component.js +0 -74
  159. package/dist/components/blocks/UTextBlock.component.d.ts +0 -37
  160. package/dist/components/blocks/UTextBlock.component.js +0 -123
  161. package/dist/components/blocks/UThinkBlock.component.d.ts +0 -23
  162. package/dist/components/blocks/UThinkBlock.component.js +0 -90
  163. package/dist/components/blocks/UToolBlock.component.d.ts +0 -20
  164. package/dist/components/blocks/UToolBlock.component.js +0 -80
  165. package/dist/components/buttons/UAttachButton.component.d.ts +0 -22
  166. package/dist/components/buttons/UAttachButton.component.js +0 -89
  167. package/dist/components/buttons/UCopyButton.component.d.ts +0 -20
  168. package/dist/components/buttons/UCopyButton.component.js +0 -81
  169. package/dist/components/buttons/UReportButton.component.d.ts +0 -9
  170. package/dist/components/buttons/UReportButton.component.js +0 -36
  171. package/dist/components/buttons/UReportButton.d.ts +0 -7
  172. package/dist/components/buttons/UReportButton.js +0 -5
  173. package/dist/components/buttons/UReportButton.styles.js +0 -14
  174. package/dist/components/buttons/URetryButton.component.d.ts +0 -11
  175. package/dist/components/buttons/URetryButton.component.js +0 -53
  176. package/dist/components/buttons/URetryButton.d.ts +0 -7
  177. package/dist/components/buttons/URetryButton.js +0 -5
  178. package/dist/components/buttons/URetryButton.styles.js +0 -26
  179. package/dist/components/buttons/UShareButton.component.d.ts +0 -9
  180. package/dist/components/buttons/UShareButton.component.js +0 -36
  181. package/dist/components/buttons/UShareButton.d.ts +0 -7
  182. package/dist/components/buttons/UShareButton.js +0 -5
  183. package/dist/components/buttons/UShareButton.styles.js +0 -14
  184. package/dist/components/buttons/UVoteButton.component.d.ts +0 -15
  185. package/dist/components/buttons/UVoteButton.component.js +0 -70
  186. package/dist/components/loaders/UDotLoader.component.d.ts +0 -9
  187. package/dist/components/loaders/UDotLoader.component.js +0 -23
  188. package/dist/components/loaders/UDotLoader.d.ts +0 -7
  189. package/dist/components/loaders/UDotLoader.js +0 -5
  190. package/dist/components/loaders/UDotLoader.styles.js +0 -50
  191. package/dist/components/message/UMessage.component.d.ts +0 -19
  192. package/dist/components/message/UMessage.component.js +0 -90
  193. package/dist/components/prompt/UPrompt.component.d.ts +0 -25
  194. package/dist/components/prompt/UPrompt.component.js +0 -113
  195. package/dist/components/references/URefCard.component.d.ts +0 -24
  196. package/dist/components/references/URefCard.component.js +0 -105
  197. package/dist/components/references/URefCardGroup.component.d.ts +0 -25
  198. package/dist/components/references/URefCardGroup.component.js +0 -88
  199. package/dist/components/references/URefTag.component.d.ts +0 -13
  200. package/dist/components/references/URefTag.component.js +0 -54
  201. package/dist/events/UCancelEvent.d.ts +0 -6
  202. package/dist/events/USubmitEvent.d.ts +0 -6
  203. package/dist/utilities/converters.d.ts +0 -9
  204. package/dist/utilities/converters.js +0 -19
  205. /package/dist/components/{buttons/UReportButton.styles.d.ts → blocks/UFileBlock.styles.d.ts} +0 -0
  206. /package/dist/components/{buttons/URetryButton.styles.d.ts → blocks/UTableBlock.styles.d.ts} +0 -0
  207. /package/dist/components/{buttons/UShareButton.styles.d.ts → intents/UQuestionIntent.styles.d.ts} +0 -0
  208. /package/dist/components/{loaders/UDotLoader.styles.d.ts → views/UChartView.styles.d.ts} +0 -0
@@ -1,140 +0,0 @@
1
- import { html } from 'lit';
2
- import { state, property } from 'lit/decorators.js';
3
- import { map } from 'lit/directives/map.js';
4
- import { when } from 'lit/directives/when.js';
5
- import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
6
- import { jsonAttrConverter } from '../../utilities/converters.js';
7
- import { styles } from './UJsonBlock.styles.js';
8
-
9
- var __defProp = Object.defineProperty;
10
- var __decorateClass = (decorators, target, key, kind) => {
11
- var result = void 0 ;
12
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
13
- if (decorator = decorators[i])
14
- result = (decorator(target, key, result) ) || result;
15
- if (result) __defProp(target, key, result);
16
- return result;
17
- };
18
- class UJsonBlock extends BaseElement {
19
- constructor() {
20
- super(...arguments);
21
- this.state = {};
22
- this.expanded = true;
23
- this.value = {};
24
- this.isValueType = (value) => {
25
- return value !== Object(value);
26
- };
27
- }
28
- static {
29
- this.styles = [super.styles, styles];
30
- }
31
- static {
32
- this.dependencies = {};
33
- }
34
- connectedCallback() {
35
- super.connectedCallback();
36
- this.setAttribute("tabindex", "0");
37
- }
38
- willUpdate(changedProperties) {
39
- super.willUpdate(changedProperties);
40
- if (changedProperties.has("value") || changedProperties.has("expanded")) {
41
- this.state = this.setState(this.value);
42
- }
43
- }
44
- render() {
45
- return html`
46
- <div part="base">
47
- ${this.renderNode(this.value)}
48
- </div>
49
- `;
50
- }
51
- /**
52
- * JsonNode를 렌더링합니다.
53
- * @param value - JsonNode (JsonObject, JsonArray, 또는 JsonValue)
54
- * @param parent - 부모 노드의 경로
55
- */
56
- renderNode(value, parent = "") {
57
- return this.isValueType(value) ? this.renderValue(value) : this.renderObject(value, parent);
58
- }
59
- /**
60
- * JsonValue를 렌더링합니다.
61
- * @param node - JsonValue (string, number, boolean, null 등)
62
- */
63
- renderValue(node) {
64
- const type = node === null ? "null" : Array.isArray(node) ? "array" : typeof node === "object" ? "object" : typeof node;
65
- return html`
66
- <span part="${type}" class="${type}" role="treeitem">
67
- ${JSON.stringify(node)}
68
- </span>
69
- `;
70
- }
71
- /**
72
- * JsonObject 또는 JsonArray를 렌더링합니다.
73
- * @param node - JsonObject 또는 JsonArray
74
- * @param depth - 현재 깊이
75
- */
76
- renderObject(node, parent) {
77
- return html`
78
- <ul part="object" role="group">
79
- ${map(Object.entries(node), ([key, value]) => {
80
- const path = parent ? `${parent}.${key}` : key;
81
- const isValue = this.isValueType(value);
82
- const isExpanded = this.state[path] ?? this.expanded;
83
- return html`
84
- <li part="property" role="treeitem"
85
- data-path="${path}"
86
- aria-expanded="${isExpanded ? "true" : "false"}">
87
- <span part="key"
88
- class="key"
89
- ?collapsable="${!isValue}"
90
- ?collapsed="${!isValue && !isExpanded}"
91
- @click=${!isValue ? () => this.handlePropertyKeyClick(path) : null}>
92
- ${key}:
93
- ${when(!isValue && !isExpanded, () => this.renderPreview(value))}
94
- </span>
95
-
96
- ${when(isValue || isExpanded, () => this.renderNode(value, path))}
97
- </li>`;
98
- })}
99
- </ul>
100
- `;
101
- }
102
- /**
103
- * 노드의 미리보기를 렌더링합니다.
104
- * @param node - JsonObject 또는 JsonArray
105
- */
106
- renderPreview(node) {
107
- return html`
108
- <span part="preview" class="preview">
109
- ${Array.isArray(node) ? node.length === 0 ? "[ ]" : `[ ${node.length} items ]` : Object.keys(node).length === 0 ? "{ }" : `{ ${Object.keys(node).length} properties }`}
110
- </span>
111
- `;
112
- }
113
- /** JSON 데이터를 순회하며 각 경로의 확장 상태를 설정합니다. */
114
- setState(value, parent = "") {
115
- if (typeof value !== "object" || value === null) return {};
116
- const state2 = {};
117
- Object.entries(value).forEach(([key, item]) => {
118
- const path = parent ? `${parent}.${key}` : key;
119
- state2[path] = this.expanded;
120
- Object.assign(state2, this.setState(item, path));
121
- });
122
- return state2;
123
- }
124
- /** 노드 확장/축소 클릭 핸들러 */
125
- handlePropertyKeyClick(path) {
126
- const isExpanded = this.state[path] ?? false;
127
- this.state = { ...this.state, [path]: !isExpanded };
128
- }
129
- }
130
- __decorateClass([
131
- state()
132
- ], UJsonBlock.prototype, "state");
133
- __decorateClass([
134
- property({ type: Boolean })
135
- ], UJsonBlock.prototype, "expanded");
136
- __decorateClass([
137
- property({ type: Object, converter: jsonAttrConverter })
138
- ], UJsonBlock.prototype, "value");
139
-
140
- export { UJsonBlock };
@@ -1,45 +0,0 @@
1
- import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
2
- import { ReferenceCitation } from '../../types/References.js';
3
- /**
4
- * 마크다운 컨텐츠를 렌더링하는 컴포넌트입니다.
5
- *
6
- * 주의:
7
- * - refs로 삽입되는 커스텀 태그(u-ref-*)는 속성/내용을 모두 escape하여 XSS를 방지합니다.
8
- * - 코드블록 내부는 HTML을 전부 텍스트로 취급(escape)하며, refs 태그는 통째 제거합니다.
9
- * - 인덱스 기반 삽입(ref.endIndex)이 깨지지 않도록 "normalize(제로폭 제거)"를 insert 전에 1회 수행합니다.
10
- */
11
- export declare class UMarkedBlock extends BaseElement {
12
- static styles: import('lit').CSSResultGroup[];
13
- static dependencies: Record<string, typeof BaseElement>;
14
- private parser;
15
- /** 마크다운 컨텐츠를 렌더링할 때 사용할 값입니다. */
16
- value?: string;
17
- /** 컨텐츠의 인용 출처들입니다. */
18
- refs?: ReferenceCitation[];
19
- render(): import('lit-html/directive.js').DirectiveResult<typeof import('lit-html/directives/unsafe-html.js').UnsafeHTMLDirective>;
20
- /**
21
- * 인용/출처 참조객체가 있을때 문자열에 출처태그를 삽입합니다.
22
- * @param value 삽입할 마크다운 문자열
23
- * @return 삽입된 마크다운 문자열
24
- */
25
- private insert;
26
- /**
27
- * 참조 카드 엘리먼트를 안전하게 빌드합니다.
28
- */
29
- private buildCard;
30
- /**
31
- * Zero Width Space, LTR/RTL marks, BOM 등 특수 제어 문자를 제거합니다.
32
- * (ref.endIndex 기준을 흔들지 않게 insert 전에 1회 수행)
33
- */
34
- private normalizeText;
35
- /**
36
- * 코드블록 내부 텍스트를 안전하게 처리합니다.
37
- * - u-ref-tag는 통째로 제거(코드블록 안에서 UI 태그가 살아남는 것 방지)
38
- * - 나머지는 전부 HTML escape
39
- */
40
- private sanitizeText;
41
- /**
42
- * HTML 텍스트 노드로 안전하게 삽입하기 위해 escape 합니다.
43
- */
44
- private escapeHTML;
45
- }
@@ -1,129 +0,0 @@
1
- import { nothing } from 'lit';
2
- import { property } from 'lit/decorators.js';
3
- import { unsafeHTML } from 'lit/directives/unsafe-html.js';
4
- import { Marked } from 'marked';
5
- import markedKatex from 'marked-katex-extension';
6
- import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
7
- import { UTooltip } from '@iyulab/components/dist/components/tooltip/UTooltip.component.js';
8
- import { UCodeBlock } from './UCodeBlock.component.js';
9
- import { URefTag } from '../references/URefTag.component.js';
10
- import { URefCard } from '../references/URefCard.component.js';
11
- import { URefCardGroup } from '../references/URefCardGroup.component.js';
12
- import { styles } from './UMarkedBlock.styles.js';
13
-
14
- var __defProp = Object.defineProperty;
15
- var __decorateClass = (decorators, target, key, kind) => {
16
- var result = void 0 ;
17
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
18
- if (decorator = decorators[i])
19
- result = (decorator(target, key, result) ) || result;
20
- if (result) __defProp(target, key, result);
21
- return result;
22
- };
23
- class UMarkedBlock extends BaseElement {
24
- constructor() {
25
- super(...arguments);
26
- this.parser = new Marked({
27
- pedantic: false,
28
- gfm: true,
29
- breaks: true,
30
- silent: true,
31
- renderer: {
32
- code: ({ text, lang }) => {
33
- lang ||= "plaintext";
34
- const safeLang = this.escapeHTML(lang);
35
- const safeText = this.sanitizeText(text);
36
- return `<u-code-block lang="${safeLang}">${safeText}</u-code-block>`;
37
- }
38
- }
39
- }).use(markedKatex({ output: "mathml" }));
40
- }
41
- static {
42
- this.styles = [super.styles, styles];
43
- }
44
- static {
45
- this.dependencies = {
46
- "u-tooltip": UTooltip,
47
- "u-code-block": UCodeBlock,
48
- "u-ref-tag": URefTag,
49
- "u-ref-card": URefCard,
50
- "u-ref-card-group": URefCardGroup
51
- };
52
- }
53
- render() {
54
- if (!this.value) return nothing;
55
- let value = this.normalizeText(this.value);
56
- if (this.refs && this.refs.length > 0) {
57
- value = this.insert(value, this.refs);
58
- }
59
- const html = this.parser.parse(value, { async: false });
60
- return unsafeHTML(html);
61
- }
62
- /**
63
- * 인용/출처 참조객체가 있을때 문자열에 출처태그를 삽입합니다.
64
- * @param value 삽입할 마크다운 문자열
65
- * @return 삽입된 마크다운 문자열
66
- */
67
- insert(value, refs) {
68
- const reversed = [...refs].sort((a, b) => b.endIndex - a.endIndex);
69
- reversed.forEach((ref) => {
70
- const sources = ref.sources ?? [];
71
- const firstSource = sources.at(0);
72
- const tagName = this.escapeHTML(ref.label ?? `[${refs.indexOf(ref) + 1}]`);
73
- const tagLink = this.escapeHTML(firstSource?.url ?? "");
74
- let tooltip = "";
75
- if (firstSource && sources.length === 1) {
76
- tooltip = this.buildCard(firstSource, true);
77
- }
78
- if (sources.length > 1) {
79
- const cards = sources.map((s) => this.buildCard(s, false)).join("");
80
- tooltip = `<u-ref-card-group slot="tooltip">${cards}</u-ref-card-group>`;
81
- }
82
- const tag = `<u-ref-tag href="${tagLink}" title="${tagName}">${tagName}${tooltip}</u-ref-tag>`;
83
- value = value.slice(0, ref.endIndex) + tag + value.slice(ref.endIndex);
84
- });
85
- return value;
86
- }
87
- /**
88
- * 참조 카드 엘리먼트를 안전하게 빌드합니다.
89
- */
90
- buildCard(source, slot) {
91
- const type = this.escapeHTML(source.type || "web");
92
- const href = this.escapeHTML(source.url ?? "");
93
- const heading = this.escapeHTML(source.title ?? "");
94
- const tags = this.escapeHTML((source.tags ?? []).join(","));
95
- const snippet = this.escapeHTML(source.snippet ?? "");
96
- const slotAttr = slot ? ` slot="tooltip"` : "";
97
- return `<u-ref-card${slotAttr} type="${type}" href="${href}" heading="${heading}" tags="${tags}">${snippet}</u-ref-card>`;
98
- }
99
- /**
100
- * Zero Width Space, LTR/RTL marks, BOM 등 특수 제어 문자를 제거합니다.
101
- * (ref.endIndex 기준을 흔들지 않게 insert 전에 1회 수행)
102
- */
103
- normalizeText(value) {
104
- return value.replace(/\u200B|\u200C|\u200D|\u200E|\u200F|\uFEFF/g, "");
105
- }
106
- /**
107
- * 코드블록 내부 텍스트를 안전하게 처리합니다.
108
- * - u-ref-tag는 통째로 제거(코드블록 안에서 UI 태그가 살아남는 것 방지)
109
- * - 나머지는 전부 HTML escape
110
- */
111
- sanitizeText(value) {
112
- value = value.replace(/<u-ref-tag\b[^>]*>[\s\S]*?<\/u-ref-tag>/gi, "");
113
- return this.escapeHTML(value);
114
- }
115
- /**
116
- * HTML 텍스트 노드로 안전하게 삽입하기 위해 escape 합니다.
117
- */
118
- escapeHTML(value) {
119
- return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
120
- }
121
- }
122
- __decorateClass([
123
- property({ type: String })
124
- ], UMarkedBlock.prototype, "value");
125
- __decorateClass([
126
- property({ type: Array })
127
- ], UMarkedBlock.prototype, "refs");
128
-
129
- export { UMarkedBlock };
@@ -1,17 +0,0 @@
1
- import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
2
- import { ReferenceSource } from '../../types/References.js';
3
- /**
4
- * 레퍼런스 정보를 블록 형태로 표시하는 컴포넌트입니다.
5
- * 단일 또는 다중 레퍼런스 카드를 그리드 레이아웃으로 표시합니다.
6
- */
7
- export declare class URefBlock extends BaseElement {
8
- static styles: import('lit').CSSResultGroup[];
9
- static dependencies: Record<string, typeof BaseElement>;
10
- /** 접힘 상태 @default: true */
11
- collapsed: boolean;
12
- /** 블록 제목 */
13
- heading?: string;
14
- /** 출처 목록 */
15
- sources?: ReferenceSource[];
16
- render(): import('lit-html').TemplateResult<1>;
17
- }
@@ -1,74 +0,0 @@
1
- import { html } from 'lit';
2
- import { property } from 'lit/decorators.js';
3
- import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
4
- import { URefCard } from '../references/URefCard.component.js';
5
- import { styles } from './URefBlock.styles.js';
6
- import { repeat } from 'lit/directives/repeat.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 URefBlock extends BaseElement {
18
- constructor() {
19
- super(...arguments);
20
- this.collapsed = true;
21
- }
22
- static {
23
- this.styles = [super.styles, styles];
24
- }
25
- static {
26
- this.dependencies = {
27
- "u-ref-card": URefCard
28
- };
29
- }
30
- render() {
31
- return html`
32
- <button class="header" @click=${() => this.collapsed = !this.collapsed}>
33
- <u-icon
34
- ?collapsed=${this.collapsed}
35
- lib="internal"
36
- name="chevron-down"
37
- ></u-icon>
38
- <div class="title">
39
- ${this.heading || "References"}
40
- </div>
41
- <div style="flex: 1;"></div>
42
- <div class="count">
43
- ${this.sources ? this.sources.length : 0}
44
- </div>
45
- </button>
46
-
47
- <div class="body" ?collapsed=${this.collapsed}>
48
- ${repeat(this.sources || [], (_, idx) => idx, (source) => {
49
- return html`
50
- <u-ref-card
51
- .type=${source.type}
52
- .href=${source.url}
53
- .heading=${source.title}
54
- .tags=${source.tags}
55
- >
56
- ${source.snippet || ""}
57
- </u-ref-card>
58
- `;
59
- })}
60
- </div>
61
- `;
62
- }
63
- }
64
- __decorateClass([
65
- property({ type: Boolean, reflect: true })
66
- ], URefBlock.prototype, "collapsed");
67
- __decorateClass([
68
- property({ type: String })
69
- ], URefBlock.prototype, "heading");
70
- __decorateClass([
71
- property({ type: Array })
72
- ], URefBlock.prototype, "sources");
73
-
74
- export { URefBlock };
@@ -1,37 +0,0 @@
1
- import { PropertyValues } from 'lit';
2
- import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
3
- /**
4
- * 텍스트를 표시하거나 편집할 수 있는 블록 컴포넌트입니다.
5
- */
6
- export declare class UTextBlock extends BaseElement {
7
- static styles: import('lit').CSSResultGroup[];
8
- static dependencies: Record<string, typeof BaseElement>;
9
- textareaEl: HTMLTextAreaElement;
10
- preEl: HTMLPreElement;
11
- /** 편집 가능 여부 */
12
- editable: boolean;
13
- /** 스펠체크 여부 */
14
- spellcheck: boolean;
15
- /** 플레이스홀더 텍스트 */
16
- placeholder?: string;
17
- /** 최소 행 수, 기본값은 1 */
18
- minRows: number;
19
- /** 최대 행 수 */
20
- maxRows?: number;
21
- /** 텍스트 블록의 내용 */
22
- value?: string;
23
- protected updated(changedProperties: PropertyValues): void;
24
- render(): import('lit-html').TemplateResult<1>;
25
- /**
26
- * textarea에 포커스를 줍니다.
27
- */
28
- focus(options?: FocusOptions): void;
29
- /**
30
- * 텍스트 입력시 value를 업데이트하고 이벤트를 재전파합니다.
31
- */
32
- private updateValueFrom;
33
- /**
34
- * pre 엘리먼트에 주입될 값을 정규화합니다.
35
- */
36
- private normalizeValue;
37
- }
@@ -1,123 +0,0 @@
1
- import { html } from 'lit';
2
- import { query, property } from 'lit/decorators.js';
3
- import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
4
- import { styles } from './UTextBlock.styles.js';
5
-
6
- var __defProp = Object.defineProperty;
7
- var __decorateClass = (decorators, target, key, kind) => {
8
- var result = void 0 ;
9
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
10
- if (decorator = decorators[i])
11
- result = (decorator(target, key, result) ) || result;
12
- if (result) __defProp(target, key, result);
13
- return result;
14
- };
15
- class UTextBlock extends BaseElement {
16
- constructor() {
17
- super(...arguments);
18
- this.editable = false;
19
- this.spellcheck = false;
20
- this.minRows = 1;
21
- /**
22
- * 텍스트 입력시 value를 업데이트하고 이벤트를 재전파합니다.
23
- */
24
- this.updateValueFrom = (event) => {
25
- event.stopPropagation();
26
- this.value = this.textareaEl.value;
27
- this.dispatchEvent(new InputEvent("input", {
28
- bubbles: true,
29
- composed: true,
30
- cancelable: true,
31
- data: this.value,
32
- inputType: event.inputType,
33
- isComposing: event.isComposing,
34
- dataTransfer: event.dataTransfer,
35
- detail: event.detail,
36
- targetRanges: event.getTargetRanges(),
37
- view: event.view
38
- }));
39
- };
40
- }
41
- static {
42
- this.styles = [super.styles, styles];
43
- }
44
- static {
45
- this.dependencies = {};
46
- }
47
- updated(changedProperties) {
48
- super.updated(changedProperties);
49
- if (changedProperties.has("minRows") && this.minRows > 0) {
50
- const lineHeight = parseFloat(getComputedStyle(this.preEl).lineHeight);
51
- this.preEl.style.minHeight = `${this.minRows * lineHeight}px`;
52
- }
53
- if (changedProperties.has("maxRows") && this.maxRows && this.maxRows > 0 && this.maxRows > this.minRows) {
54
- const lineHeight = parseFloat(getComputedStyle(this.preEl).lineHeight);
55
- this.preEl.style.maxHeight = `${this.maxRows * lineHeight}px`;
56
- }
57
- if (changedProperties.has("editable") && this.editable) {
58
- requestAnimationFrame(() => {
59
- this.textareaEl.focus();
60
- this.textareaEl.setSelectionRange(this.value?.length || 0, this.value?.length || 0);
61
- });
62
- }
63
- }
64
- render() {
65
- return html`
66
- <div class="container">
67
- <textarea
68
- name="message"
69
- placeholder=${this.placeholder || ""}
70
- spellcheck=${this.spellcheck}
71
- .readOnly=${!this.editable}
72
- .value=${this.value || ""}
73
- @input=${this.updateValueFrom}
74
- ></textarea>
75
- <pre
76
- .textContent=${this.normalizeValue(this.value)}
77
- ></pre>
78
- </div>
79
- `;
80
- }
81
- /**
82
- * textarea에 포커스를 줍니다.
83
- */
84
- focus(options) {
85
- this.textareaEl.focus(options);
86
- }
87
- /**
88
- * pre 엘리먼트에 주입될 값을 정규화합니다.
89
- */
90
- normalizeValue(value) {
91
- if (!value) return "​";
92
- if (value.endsWith("\n")) {
93
- return value + "​";
94
- }
95
- return value;
96
- }
97
- }
98
- __decorateClass([
99
- query("textarea")
100
- ], UTextBlock.prototype, "textareaEl");
101
- __decorateClass([
102
- query("pre")
103
- ], UTextBlock.prototype, "preEl");
104
- __decorateClass([
105
- property({ type: Boolean, reflect: true })
106
- ], UTextBlock.prototype, "editable");
107
- __decorateClass([
108
- property({ type: Boolean })
109
- ], UTextBlock.prototype, "spellcheck");
110
- __decorateClass([
111
- property({ type: String })
112
- ], UTextBlock.prototype, "placeholder");
113
- __decorateClass([
114
- property({ type: Number })
115
- ], UTextBlock.prototype, "minRows");
116
- __decorateClass([
117
- property({ type: Number })
118
- ], UTextBlock.prototype, "maxRows");
119
- __decorateClass([
120
- property({ type: String })
121
- ], UTextBlock.prototype, "value");
122
-
123
- export { UTextBlock };
@@ -1,23 +0,0 @@
1
- import { PropertyValues } from 'lit';
2
- import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
3
- /**
4
- * 추론 내용을 표시하는 블록입니다.
5
- * 로딩 중일 때는 "Thinking..." 메시지를 표시하고, 내용 펼치기/접기 기능을 제공합니다.
6
- */
7
- export declare class UThinkBlock extends BaseElement {
8
- static styles: import('lit').CSSResultGroup[];
9
- static dependencies: Record<string, typeof BaseElement>;
10
- bodyEl: HTMLDivElement;
11
- /** 컨텐츠가 로딩 중인지 여부 */
12
- loading: boolean;
13
- /** 컨텐츠가 접혀있는지 여부 */
14
- collapsed: boolean;
15
- /** 추론 컨텐츠의 내용 */
16
- value?: string;
17
- protected updated(changedProperties: PropertyValues): void;
18
- render(): import('lit-html').TemplateResult<1>;
19
- /**
20
- * 컨텐츠가 로딩 중일 때, 스크롤을 맨 아래로 이동
21
- */
22
- private scrollToBottom;
23
- }
@@ -1,90 +0,0 @@
1
- import { html } from 'lit';
2
- import { query, property } from 'lit/decorators.js';
3
- import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
4
- import { UIcon } from '@iyulab/components/dist/components/icon/UIcon.component.js';
5
- import { UMarkedBlock } from './UMarkedBlock.component.js';
6
- import { styles } from './UThinkBlock.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 UThinkBlock extends BaseElement {
18
- constructor() {
19
- super(...arguments);
20
- this.loading = false;
21
- this.collapsed = true;
22
- /**
23
- * 컨텐츠가 로딩 중일 때, 스크롤을 맨 아래로 이동
24
- */
25
- this.scrollToBottom = () => {
26
- if (!this.bodyEl) return;
27
- requestAnimationFrame(() => {
28
- this.bodyEl.scrollTo({
29
- top: this.bodyEl.scrollHeight,
30
- behavior: "smooth"
31
- });
32
- });
33
- };
34
- }
35
- static {
36
- this.styles = [super.styles, styles];
37
- }
38
- static {
39
- this.dependencies = {
40
- "u-icon": UIcon,
41
- "u-marked-block": UMarkedBlock
42
- };
43
- }
44
- updated(changedProperties) {
45
- super.updated(changedProperties);
46
- if (changedProperties.has("value") && this.value) {
47
- this.scrollToBottom();
48
- }
49
- }
50
- render() {
51
- return html`
52
- <div class="header" part="header"
53
- @click=${() => this.collapsed = !this.collapsed}>
54
- <u-icon class="prefix-icon"
55
- ?loading=${this.loading}
56
- lib="internal"
57
- name="lightbulb-fill"
58
- ></u-icon>
59
- <span class="title">
60
- ${this.loading ? "Thinking..." : "Thought"}
61
- </span>
62
- <u-icon class="suffix-icon"
63
- lib="internal"
64
- name=${this.collapsed ? "plus-lg" : "dash-lg"}
65
- ></u-icon>
66
- </div>
67
-
68
- <div class="body" part="body" scrollable
69
- ?hidden=${this.collapsed}>
70
- <u-marked-block
71
- .value=${this.value}
72
- ></u-marked-block>
73
- </div>
74
- `;
75
- }
76
- }
77
- __decorateClass([
78
- query(".body")
79
- ], UThinkBlock.prototype, "bodyEl");
80
- __decorateClass([
81
- property({ type: Boolean, reflect: true })
82
- ], UThinkBlock.prototype, "loading");
83
- __decorateClass([
84
- property({ type: Boolean, reflect: true })
85
- ], UThinkBlock.prototype, "collapsed");
86
- __decorateClass([
87
- property({ type: String })
88
- ], UThinkBlock.prototype, "value");
89
-
90
- export { UThinkBlock };