@iyulab/chat-components 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -144
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.128.0}/helpers/decorate.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.128.0}/helpers/decorateMetadata.js +1 -1
- package/dist/components/blocks/UCodeBlock.js +4 -3
- package/dist/components/blocks/UFileBlock.js +2 -2
- package/dist/components/blocks/UJsonBlock.js +2 -2
- package/dist/components/blocks/UMarkedBlock.js +3 -27
- package/dist/components/blocks/URefBlock.js +2 -2
- package/dist/components/blocks/UTableBlock.js +4 -3
- package/dist/components/blocks/UTextBlock.js +2 -2
- package/dist/components/blocks/UThinkBlock.js +2 -2
- package/dist/components/blocks/UToolBlock.js +2 -2
- package/dist/components/buttons/UAttachButton.js +2 -2
- package/dist/components/buttons/UCopyButton.js +2 -2
- package/dist/components/buttons/UVoteButton.js +2 -2
- package/dist/components/intents/UQuestionIntent.js +2 -2
- package/dist/components/message/UMessage.js +2 -2
- package/dist/components/prompt/UPrompt.d.ts +5 -0
- package/dist/components/prompt/UPrompt.js +27 -5
- package/dist/components/references/URefCard.js +2 -2
- package/dist/components/references/URefCardGroup.js +4 -3
- package/dist/components/references/URefTag.js +2 -2
- package/dist/components/views/UChartView.js +2 -2
- package/dist/components/views/UImagesView.js +2 -2
- package/dist/components/views/UMapView.js +2 -2
- package/dist/components/views/UVideoView.js +2 -2
- package/dist/components/views/UView.js +2 -2
- package/dist/events/SendEvent.d.ts +15 -1
- package/dist/events/StopEvent.d.ts +11 -1
- package/dist/types/Intents.js +1 -1
- package/dist/types/Views.js +1 -1
- package/dist/utilities/HtmlPlaceholder.d.ts +11 -0
- package/dist/utilities/HtmlPlaceholder.js +26 -0
- package/package.json +11 -10
- package/skills/iyulab-chat-components/SKILL.md +107 -0
- package/skills/iyulab-chat-components/references/components/attach-button.md +69 -0
- package/skills/iyulab-chat-components/references/components/chart-view.md +65 -0
- package/skills/iyulab-chat-components/references/components/code-block.md +42 -0
- package/skills/iyulab-chat-components/references/components/copy-button.md +46 -0
- package/skills/iyulab-chat-components/references/components/file-block.md +64 -0
- package/skills/iyulab-chat-components/references/components/images-view.md +63 -0
- package/skills/iyulab-chat-components/references/components/json-block.md +41 -0
- package/skills/iyulab-chat-components/references/components/map-view.md +54 -0
- package/skills/iyulab-chat-components/references/components/marked-block.md +53 -0
- package/skills/iyulab-chat-components/references/components/message.md +60 -0
- package/skills/iyulab-chat-components/references/components/prompt.md +102 -0
- package/skills/iyulab-chat-components/references/components/question-intent.md +75 -0
- package/skills/iyulab-chat-components/references/components/ref-block.md +45 -0
- package/skills/iyulab-chat-components/references/components/ref-card-group.md +41 -0
- package/skills/iyulab-chat-components/references/components/ref-card.md +48 -0
- package/skills/iyulab-chat-components/references/components/ref-tag.md +40 -0
- package/skills/iyulab-chat-components/references/components/table-block.md +63 -0
- package/skills/iyulab-chat-components/references/components/text-block.md +59 -0
- package/skills/iyulab-chat-components/references/components/think-block.md +48 -0
- package/skills/iyulab-chat-components/references/components/tool-block.md +57 -0
- package/skills/iyulab-chat-components/references/components/video-view.md +55 -0
- package/skills/iyulab-chat-components/references/components/view.md +51 -0
- package/skills/iyulab-chat-components/references/components/vote-button.md +60 -0
- package/skills/iyulab-chat-components/references/types.md +115 -0
- package/skills/iyulab-chat-components/references/usage.md +254 -0
- package/skills/iyulab-chat-components/references/utilities/intent-prompt-builder.md +123 -0
- package/skills/iyulab-chat-components/references/utilities/view-prompt-builder.md +112 -0
|
@@ -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?` |
|