@dmsfe/data-agent-sdk 0.1.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.
- package/CHANGES.md +33 -0
- package/LICENSE +201 -0
- package/README.md +212 -0
- package/lib/index.cjs +30 -0
- package/lib/index.d.cts +60 -0
- package/lib/index.d.ts +60 -0
- package/lib/index.js +30 -0
- package/lib/render/index.cjs +24 -0
- package/lib/render/index.d.cts +31 -0
- package/lib/render/index.d.ts +31 -0
- package/lib/render/index.js +24 -0
- package/lib/task-finish-CMXO70b5.d.cts +52 -0
- package/lib/task-finish-CMXO70b5.d.ts +52 -0
- package/package.json +65 -0
package/CHANGES.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-05-21
|
|
4
|
+
|
|
5
|
+
Initial stable 0.x release.
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **Layer 1 types** — `ChartType`, `ChartData`, `ContentType`, `TaskFinishChart`, `TaskFinishCharts`, `TaskFinishToolArgs`, `TaskFinishChartData`, `DataAgentEvent`, `ParsedTaskFinishContent`.
|
|
10
|
+
- **Layer 2 parsers** — `parseDataAgentSSE` (bytes → events, with signal + consumer-break cancellation), `parseDataAgentChunks` (sync array / async iterable overloads), `parseTaskFinishContent`, `parseChartData`.
|
|
11
|
+
- **Layer 3 render** (subpath `./render`) — `renderTaskFinishChart` / `renderTaskFinishCharts` (wire wrappers), `renderTaskFinishChartData` / `renderTaskFinishChartsData` (structured core). Supports `chart_type: bar | line | pie | table | number`; unknown types are silent no-op.
|
|
12
|
+
- `RendererInstance<TData>` generic + `ChartInstance` / `ChartsInstance` aliases.
|
|
13
|
+
- `TaskFinishRenderOptions.chartHeight` for multi-chart renderers. Defaults to `300px` per child chart host; numbers are treated as px and strings as CSS height values.
|
|
14
|
+
- CSS-variable theming (`--dmsfe-chart-category-1..12`, `--dmsfe-chart-sequential-1..8`).
|
|
15
|
+
- Bundled internal deps: `zod ^4`, `@ai-sdk/provider-utils ^3`. `echarts ^5` as optional peer.
|
|
16
|
+
- Built with tsup → ESM + CJS + DTS. `sideEffects: false`.
|
|
17
|
+
- npm package metadata supports Node 18 ESM consumers via `type: module` while preserving CJS `require` entry points.
|
|
18
|
+
- 发布包不包含 source map,并开启 minify 以降低 npm tarball 体积。
|
|
19
|
+
|
|
20
|
+
### Bundle size baseline (measured at first build)
|
|
21
|
+
|
|
22
|
+
- `lib/index.js`: ~73KB gz (Layer 1 + 2 + bundled `zod` + `@ai-sdk/provider-utils`).
|
|
23
|
+
- `lib/render/index.js`: ~72KB gz (Layer 3 + bundled `zod` + shared DOM scaffold; `echarts` external).
|
|
24
|
+
|
|
25
|
+
Re-measure with `gzip -c lib/index.js | wc -c` and `gzip -c lib/render/index.js | wc -c`.
|
|
26
|
+
|
|
27
|
+
These are higher than initially estimated in the spec because `@ai-sdk/provider-utils` and `zod 4` together compress to more than the back-of-envelope guess. The trade-off is intentional: bundling them keeps the customer's `node_modules` minimal and removes version-conflict surface, at the cost of a larger one-time SDK download.
|
|
28
|
+
|
|
29
|
+
Subsequent releases that increase any entry by >20% must include a note explaining why.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
Versioning policy: 0.x minors may include breaking API changes (documented here). 1.0 will be cut after (a) ≥3 customers integrated, (b) ≥3 months without breaking changes, (c) Phase 2 dependency inversion completed.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# @dmsfe/data-agent-sdk
|
|
2
|
+
|
|
3
|
+
面向 [DMS Data Agent](https://agent.dms.aliyun.com) 的前端无框架 UI SDK:用于解析 Data Agent SSE 响应,并在任意前端技术栈(React、Vue、Svelte、Vanilla JS 等)中渲染 `task_finish` 图表。
|
|
4
|
+
|
|
5
|
+
> **状态:0.x 实验版本。** Minor 版本中 API 仍可能调整。变更记录见 [CHANGES.md](./CHANGES.md)。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @dmsfe/data-agent-sdk
|
|
11
|
+
# 或 npm install / yarn add
|
|
12
|
+
|
|
13
|
+
# 如果使用 /render 子路径,需要同时安装:
|
|
14
|
+
pnpm add echarts
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 快速开始
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import {
|
|
21
|
+
parseDataAgentSSE,
|
|
22
|
+
parseTaskFinishContent,
|
|
23
|
+
} from '@dmsfe/data-agent-sdk';
|
|
24
|
+
import { renderTaskFinishCharts } from '@dmsfe/data-agent-sdk/render';
|
|
25
|
+
|
|
26
|
+
const response = await fetch('/openapi/SendChatMessage', { /* ... */ });
|
|
27
|
+
const container = document.getElementById('charts')!;
|
|
28
|
+
|
|
29
|
+
for await (const event of parseDataAgentSSE(response.body!)) {
|
|
30
|
+
if (event.type !== 'task_finish') continue;
|
|
31
|
+
const parsed = parseTaskFinishContent(event.payload.content, event.payload.content_type);
|
|
32
|
+
if (parsed.type === 'charts') {
|
|
33
|
+
renderTaskFinishCharts(container, parsed.charts, { chartHeight: 320 });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 框架集成
|
|
39
|
+
|
|
40
|
+
### React
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
44
|
+
import { parseTaskFinishContent, type TaskFinishToolArgs } from '@dmsfe/data-agent-sdk';
|
|
45
|
+
import { renderTaskFinishCharts, type ChartsInstance } from '@dmsfe/data-agent-sdk/render';
|
|
46
|
+
|
|
47
|
+
export function TaskFinishView({ payload }: { payload: TaskFinishToolArgs }) {
|
|
48
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
49
|
+
const parsed = useMemo(
|
|
50
|
+
() => parseTaskFinishContent(payload.content, payload.content_type),
|
|
51
|
+
[payload.content, payload.content_type],
|
|
52
|
+
);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (parsed.type !== 'charts' || !ref.current) return;
|
|
55
|
+
const inst: ChartsInstance = renderTaskFinishCharts(ref.current, parsed.charts, {
|
|
56
|
+
chartHeight: 320,
|
|
57
|
+
});
|
|
58
|
+
return () => inst.destroy();
|
|
59
|
+
}, [parsed]);
|
|
60
|
+
if (parsed.type === 'markdown') return <pre>{parsed.content}</pre>;
|
|
61
|
+
return <div ref={ref} />;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Vue 3
|
|
66
|
+
|
|
67
|
+
```vue
|
|
68
|
+
<script setup lang="ts">
|
|
69
|
+
import { ref, computed, watchEffect, onBeforeUnmount } from 'vue';
|
|
70
|
+
import { parseTaskFinishContent, type TaskFinishToolArgs } from '@dmsfe/data-agent-sdk';
|
|
71
|
+
import { renderTaskFinishCharts, type ChartsInstance } from '@dmsfe/data-agent-sdk/render';
|
|
72
|
+
|
|
73
|
+
const props = defineProps<{ payload: TaskFinishToolArgs }>();
|
|
74
|
+
const parsed = computed(() => parseTaskFinishContent(props.payload.content, props.payload.content_type));
|
|
75
|
+
const el = ref<HTMLElement>();
|
|
76
|
+
let inst: ChartsInstance | undefined;
|
|
77
|
+
|
|
78
|
+
watchEffect(() => {
|
|
79
|
+
inst?.destroy(); inst = undefined;
|
|
80
|
+
if (parsed.value.type === 'charts' && el.value) {
|
|
81
|
+
inst = renderTaskFinishCharts(el.value, parsed.value.charts, {
|
|
82
|
+
chartHeight: 320,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
onBeforeUnmount(() => inst?.destroy());
|
|
87
|
+
</script>
|
|
88
|
+
<template>
|
|
89
|
+
<pre v-if="parsed.type === 'markdown'">{{ parsed.content }}</pre>
|
|
90
|
+
<div v-else ref="el" />
|
|
91
|
+
</template>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Vanilla JS
|
|
95
|
+
|
|
96
|
+
参考上面的“快速开始”示例。
|
|
97
|
+
|
|
98
|
+
## 其他输入方式:`parseDataAgentChunks`
|
|
99
|
+
|
|
100
|
+
如果你的 HTTP 层已经把 SSE 响应解码成 JSON 对象,或者你手里有一组已捕获的日志对象,可以直接使用 `parseDataAgentChunks`,不需要再使用 `parseDataAgentSSE`:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { parseDataAgentChunks } from '@dmsfe/data-agent-sdk';
|
|
104
|
+
|
|
105
|
+
const events = parseDataAgentChunks(myDecodedChunkArray); // 同步数组输入,返回数组
|
|
106
|
+
// 或
|
|
107
|
+
for await (const e of parseDataAgentChunks(myAsyncIterable, { signal })) { /* ... */ }
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 独立渲染:`renderTaskFinishChartData`
|
|
111
|
+
|
|
112
|
+
用于测试、Storybook fixture,或回放已经解码好的结构化 payload:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { renderTaskFinishChartData } from '@dmsfe/data-agent-sdk/render';
|
|
116
|
+
|
|
117
|
+
renderTaskFinishChartData(document.getElementById('chart')!, {
|
|
118
|
+
title: 'Monthly Sales',
|
|
119
|
+
chart_type: 'bar',
|
|
120
|
+
data: { columns: ['m', 'v'], data: [['Jan', 10], ['Feb', 20]] },
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
使用单图渲染器(`renderTaskFinishChart` 或 `renderTaskFinishChartData`)时,需要在渲染前给目标容器设置非零高度:
|
|
125
|
+
|
|
126
|
+
```html
|
|
127
|
+
<div id="chart" style="height: 320px"></div>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
多图渲染器(`renderTaskFinishCharts` 和 `renderTaskFinishChartsData`)会为每张图创建一个子容器,默认每个子容器高度为 `300px`。可以通过 `options.chartHeight` 覆盖。
|
|
131
|
+
|
|
132
|
+
**适用范围说明**:该渲染入口面向 Data Agent 已解码的 payload。SDK 不是通用图表库;`chart_type` 枚举和字段推断规则都跟随 Data Agent 的 `task_finish` 协议。如果要渲染任意业务图表,建议直接使用 echarts。
|
|
133
|
+
|
|
134
|
+
## API 参考
|
|
135
|
+
|
|
136
|
+
### Layer 1:类型
|
|
137
|
+
|
|
138
|
+
- `ChartType` = `string | null`
|
|
139
|
+
- `ChartData`:`{ columns: string[], data: (string|number|null)[][] }`
|
|
140
|
+
- `ContentType` = `'str' | 'json' | undefined`
|
|
141
|
+
- `TaskFinishChart`:wire 格式,`data` 字段是 JSON 字符串
|
|
142
|
+
- `TaskFinishCharts` = `TaskFinishChart[]`
|
|
143
|
+
- `TaskFinishChartData`:结构化格式,`data` 字段是 `ChartData`
|
|
144
|
+
- `TaskFinishToolArgs`:`{ content: string, content_type? }`
|
|
145
|
+
- `DataAgentEvent` = `{ type: 'task_finish'; payload } | { type: 'unknown'; raw }`
|
|
146
|
+
- `ParsedTaskFinishContent` = `{ type: 'markdown'; content } | { type: 'charts'; charts }`
|
|
147
|
+
|
|
148
|
+
### Layer 2:解析器
|
|
149
|
+
|
|
150
|
+
- `parseDataAgentSSE(stream, { signal? })` → `AsyncIterable<DataAgentEvent>`
|
|
151
|
+
- `parseDataAgentChunks(chunks)` → `DataAgentEvent[]`(数组重载)
|
|
152
|
+
- `parseDataAgentChunks(iterable, { signal? })` → `AsyncIterable<DataAgentEvent>`
|
|
153
|
+
- `parseTaskFinishContent(content, contentType?)` → `ParsedTaskFinishContent`
|
|
154
|
+
- `parseChartData(jsonString)` → `ChartData | null`
|
|
155
|
+
|
|
156
|
+
### Layer 3:渲染器(从 `/render` 子路径导入)
|
|
157
|
+
|
|
158
|
+
- `renderTaskFinishChart(container, chart, options?)` → `ChartInstance`
|
|
159
|
+
- `renderTaskFinishCharts(container, charts, options?)` → `ChartsInstance`
|
|
160
|
+
- `renderTaskFinishChartData(container, input, options?)` → `RendererInstance<TaskFinishChartData>`
|
|
161
|
+
- `renderTaskFinishChartsData(container, inputs, options?)` → `RendererInstance<TaskFinishChartData[]>`
|
|
162
|
+
|
|
163
|
+
### 渲染选项
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
interface TaskFinishRenderOptions {
|
|
167
|
+
theme?: 'light' | 'dark';
|
|
168
|
+
locale?: 'zh-CN' | 'en-US';
|
|
169
|
+
chartHeight?: number | string;
|
|
170
|
+
onUnknownChartType?: (chartType: string | null) => void;
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
| 选项 | 适用范围 | 默认值 | 说明 |
|
|
175
|
+
|---|---|---|---|
|
|
176
|
+
| `theme` | 所有渲染器 | 浏览器 / echarts 默认主题 | 预留给渲染器主题选择。 |
|
|
177
|
+
| `locale` | 所有渲染器 | 根据浏览器语言自动判断 | 控制内置兜底文案,例如空数据提示。 |
|
|
178
|
+
| `chartHeight` | 多图渲染器 | `300` | `renderTaskFinishCharts` / `renderTaskFinishChartsData` 创建的每个子图表容器高度。数字会按 px 处理;字符串会作为 CSS 高度值使用,例如 `'24rem'`。 |
|
|
179
|
+
| `onUnknownChartType` | 所有渲染器 | `undefined` | 当 `chart_type` 为 `null` 或不支持的类型时触发。 |
|
|
180
|
+
|
|
181
|
+
### 图表类型
|
|
182
|
+
|
|
183
|
+
| `chart_type` | 渲染结果 |
|
|
184
|
+
|---|---|
|
|
185
|
+
| `'bar'` | echarts 柱状图 |
|
|
186
|
+
| `'line'` | echarts 折线图 |
|
|
187
|
+
| `'pie'` | echarts 饼图 |
|
|
188
|
+
| `'table'` | 原生 HTML `<table>`,不创建 echarts 实例 |
|
|
189
|
+
| `'number'` | 原生 DOM 指标卡,不创建 echarts 实例 |
|
|
190
|
+
| `null` 或其他值 | 不渲染图表,可通过 `onUnknownChartType` 回调感知 |
|
|
191
|
+
|
|
192
|
+
### CSS 变量(主题)
|
|
193
|
+
|
|
194
|
+
可以在图表容器的任意祖先节点上覆盖以下 CSS 变量:
|
|
195
|
+
|
|
196
|
+
- `--dmsfe-chart-category-1` 到 `--dmsfe-chart-category-12`:分类色板,默认是阿里云蓝色系与辅助色
|
|
197
|
+
- `--dmsfe-chart-sequential-1` 到 `--dmsfe-chart-sequential-8`:连续色板,默认是品牌蓝色系
|
|
198
|
+
|
|
199
|
+
## 限制(Phase 1)
|
|
200
|
+
|
|
201
|
+
- 目前只有 `task_finish` SSE 事件会被解析成强类型;其他 category 会作为 `{ type: 'unknown', raw }` 返回。
|
|
202
|
+
- 暂不提供 React/Vue 组件层,当前使用命令式 API。
|
|
203
|
+
- 暂不支持 notebook cell output、plan progress、mission report 等渲染器,这些会放到后续阶段。
|
|
204
|
+
- `ParsedTaskFinishContent.type === 'markdown'` 分支暂不提供内置 Markdown 渲染器。
|
|
205
|
+
|
|
206
|
+
## 路线图
|
|
207
|
+
|
|
208
|
+
- Phase 2:框架适配包、更多事件类型和渲染器(例如 `output_conclusion` Markdown 卡片、`plan_update` 进度可视化等),并完成与 `apps/data-agent` 的依赖反转。
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
Apache-2.0
|