@antglobal/copilot-cards-web 0.0.0 → 0.0.20260724033338-dev.13
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/README.md +171 -2
- package/dist/index.d.ts +1353 -0
- package/dist/index.js +7092 -0
- package/package.json +39 -7
- package/LEGAL.md +0 -7
package/README.md
CHANGED
|
@@ -1,3 +1,172 @@
|
|
|
1
|
-
|
|
1
|
+
# @antglobal/copilot-cards-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Web renderer for schema-driven cards in AI conversations. It turns one JSON schema into interactive Custom Elements for desktop browsers, mobile browsers, and WebViews.
|
|
4
|
+
|
|
5
|
+
The package includes the core schema and action APIs, responsive rendering, Shadow DOM style isolation, streaming updates, and extensible component registration.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @antglobal/copilot-cards-web
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`@antglobal/copilot-cards-core` is installed automatically.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { renderCard } from "@antglobal/copilot-cards-web";
|
|
19
|
+
|
|
20
|
+
const container = document.getElementById("card");
|
|
21
|
+
if (!container) throw new Error("Missing #card container");
|
|
22
|
+
|
|
23
|
+
const schema = {
|
|
24
|
+
version: "1.0",
|
|
25
|
+
rootID: "root",
|
|
26
|
+
elements: {
|
|
27
|
+
root: {
|
|
28
|
+
id: "root",
|
|
29
|
+
type: "Text",
|
|
30
|
+
props: {
|
|
31
|
+
content: { type: "static", value: "Hello, Copilot Cards!" },
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
variables: {},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const card = renderCard(container, schema, {
|
|
39
|
+
emit: (eventName, payload) => {
|
|
40
|
+
console.log(eventName, payload);
|
|
41
|
+
},
|
|
42
|
+
showToast: (message, level) => {
|
|
43
|
+
console.log(`[${level ?? "info"}] ${message}`);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
card.updateVariables({ userName: "Alice" });
|
|
48
|
+
|
|
49
|
+
// Dispose when the host view is removed.
|
|
50
|
+
card.dispose();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Framework usage
|
|
54
|
+
|
|
55
|
+
The renderer accesses browser APIs and should be loaded on the client in frameworks that perform server-side rendering.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const { renderCard } = await import("@antglobal/copilot-cards-web");
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
In React or Next.js, run the dynamic import inside a client component effect. In Vue, run it after the component is mounted.
|
|
62
|
+
|
|
63
|
+
## Main API
|
|
64
|
+
|
|
65
|
+
### `renderCard(container, schema, options?)`
|
|
66
|
+
|
|
67
|
+
Renders a complete schema and returns a `CardInstance`:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
interface CardInstance {
|
|
71
|
+
updateVariables(variables: Record<string, unknown>): void;
|
|
72
|
+
dispose(): void;
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Common render options include:
|
|
77
|
+
|
|
78
|
+
| Option | Purpose |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| `variables` | Overrides initial schema variables |
|
|
81
|
+
| `botId` | Selects bot-scoped custom action handlers |
|
|
82
|
+
| `isMobile` | Overrides automatic viewport detection |
|
|
83
|
+
| `fetch` | Supplies a custom request implementation |
|
|
84
|
+
| `showToast` | Connects toast actions to the host UI |
|
|
85
|
+
| `navigate` | Connects URL actions to host navigation |
|
|
86
|
+
| `emit` | Receives events emitted by a card |
|
|
87
|
+
| `copyText` | Connects copy actions to the host clipboard |
|
|
88
|
+
|
|
89
|
+
### Streaming
|
|
90
|
+
|
|
91
|
+
Use `renderStreamingCard` when the card arrives incrementally from an AI model or server:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { renderStreamingCard } from "@antglobal/copilot-cards-web";
|
|
95
|
+
|
|
96
|
+
const stream = renderStreamingCard(container);
|
|
97
|
+
|
|
98
|
+
stream.feed(chunk);
|
|
99
|
+
stream.flush();
|
|
100
|
+
stream.dispose();
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The package also exports `connectStreaming` and `connectSSE` helpers, plus partial-schema and A2UI adapters.
|
|
104
|
+
|
|
105
|
+
### `BotSDK`
|
|
106
|
+
|
|
107
|
+
`BotSDK` groups card instances, bot-scoped action handlers, and declarative action providers behind one host-facing API.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { BotSDK } from "@antglobal/copilot-cards-web";
|
|
111
|
+
|
|
112
|
+
const bot = new BotSDK({
|
|
113
|
+
botId: "support-bot",
|
|
114
|
+
onAction: {
|
|
115
|
+
trackEvent: async (step) => {
|
|
116
|
+
console.log(step.params);
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
await bot.renderCard(container, schema);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Built-in components
|
|
125
|
+
|
|
126
|
+
The renderer includes:
|
|
127
|
+
|
|
128
|
+
- Text, Button, Input, Image, Divider
|
|
129
|
+
- Rate, Tag, Select, PasscodeInput
|
|
130
|
+
- Icon, Form, Loading, Progress
|
|
131
|
+
- Steps, Collapse, and sanitized HTML
|
|
132
|
+
|
|
133
|
+
Components render as isolated `ai-card-*` Custom Elements.
|
|
134
|
+
|
|
135
|
+
## Custom components
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import {
|
|
139
|
+
registerComponent,
|
|
140
|
+
type ComponentRenderer,
|
|
141
|
+
} from "@antglobal/copilot-cards-web";
|
|
142
|
+
|
|
143
|
+
const renderStatus: ComponentRenderer = (_node, props) => {
|
|
144
|
+
const element = document.createElement("div");
|
|
145
|
+
element.textContent = String(props.label ?? "");
|
|
146
|
+
return element;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
registerComponent("Status", renderStatus);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Actions
|
|
153
|
+
|
|
154
|
+
Cards can declaratively request `emit`, `request`, `setVariable`, `toast`, `url`, and `copy` actions. The host remains in control of network access, navigation, notifications, clipboard behavior, and custom business actions.
|
|
155
|
+
|
|
156
|
+
## Browser requirements
|
|
157
|
+
|
|
158
|
+
- Custom Elements
|
|
159
|
+
- Shadow DOM
|
|
160
|
+
- `AbortController`
|
|
161
|
+
- Modern JavaScript with ES2020 support
|
|
162
|
+
|
|
163
|
+
Provide appropriate polyfills when targeting older WebViews.
|
|
164
|
+
|
|
165
|
+
## Related packages
|
|
166
|
+
|
|
167
|
+
- `@antglobal/copilot-cards-core` — UI-independent schema, expression, action, lifecycle, and streaming logic.
|
|
168
|
+
- `@antglobal/copilot-cards-mini-program` — native renderer for Alipay and WeChat mini-programs.
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
MIT
|