@snackbit/opendil 0.0.0 → 0.2.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/LICENSE +201 -0
- package/README.md +137 -2
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/bin/opendil.mjs +75 -0
- package/bin/publish-directory.d.mts +18 -0
- package/bin/publish-directory.mjs +188 -0
- package/dist/agent-spec.js +9 -0
- package/dist/chunk-RPZW4WVX.js +2 -0
- package/dist/chunk-ZSTXLIS6.js +2 -0
- package/dist/index.js +2 -0
- package/dist/mermaid-diagram-GFWD4Y2X.js +2 -0
- package/dist/runtime/frame.html +2435 -0
- package/dist/runtime/frame.js +4621 -0
- package/dist/spec/genui.agent.full.md +1927 -0
- package/dist/spec/genui.agent.md +479 -0
- package/dist/spec/genui.examples.md +836 -0
- package/dist/styled-renderer-PHI4MNPF.js +2441 -0
- package/dist/styles.css +2434 -0
- package/dist/types/agent-spec.d.ts +12 -0
- package/dist/types/components/ui/controls/button.d.ts +10 -0
- package/dist/types/components/ui/controls/checkbox.d.ts +4 -0
- package/dist/types/components/ui/controls/input.d.ts +3 -0
- package/dist/types/components/ui/controls/radio-group.d.ts +5 -0
- package/dist/types/components/ui/controls/select.d.ts +14 -0
- package/dist/types/components/ui/controls/slider.d.ts +4 -0
- package/dist/types/components/ui/controls/tabs.d.ts +7 -0
- package/dist/types/components/ui/controls/textarea.d.ts +3 -0
- package/dist/types/components/ui/controls/toggle-group.d.ts +10 -0
- package/dist/types/components/ui/controls/toggle.d.ts +9 -0
- package/dist/types/components/ui/display/badge.d.ts +9 -0
- package/dist/types/components/ui/display/card.d.ts +9 -0
- package/dist/types/components/ui/display/chart.d.ts +39 -0
- package/dist/types/components/ui/display/separator.d.ts +4 -0
- package/dist/types/components/ui/display/skeleton.d.ts +2 -0
- package/dist/types/components/ui/display/table.d.ts +10 -0
- package/dist/types/components/ui/media/carousel.d.ts +19 -0
- package/dist/types/components/ui/overlays/collapsible.d.ts +6 -0
- package/dist/types/components/ui/overlays/popover.d.ts +11 -0
- package/dist/types/components/ui/overlays/tooltip.d.ts +8 -0
- package/dist/types/components/ui/overlays/ui-scope.d.ts +27 -0
- package/dist/types/dil/custom-component.d.ts +14 -0
- package/dist/types/dil/customization.d.ts +21 -0
- package/dist/types/dil/dil-renderer.d.ts +90 -0
- package/dist/types/dil/isolation/frame-startup.d.ts +18 -0
- package/dist/types/dil/isolation/frame-theme.d.ts +14 -0
- package/dist/types/dil/isolation/frame-viewport.d.ts +30 -0
- package/dist/types/dil/isolation/frame.d.ts +1 -0
- package/dist/types/dil/isolation/isolated-renderer.d.ts +28 -0
- package/dist/types/dil/isolation/overlay-room.d.ts +29 -0
- package/dist/types/dil/isolation/shadow-renderer.d.ts +7 -0
- package/dist/types/dil/isolation/shadow-styles.d.ts +2 -0
- package/dist/types/dil/isolation/viewport-scroll.d.ts +7 -0
- package/dist/types/dil/isolation/vm-worker.d.ts +1 -0
- package/dist/types/dil/message-renderer.d.ts +17 -0
- package/dist/types/dil/parser/dil-parser.d.ts +74 -0
- package/dist/types/dil/parser/lexical.d.ts +27 -0
- package/dist/types/dil/parser/literal-tag.d.ts +16 -0
- package/dist/types/dil/parser/markdown-lexing.d.ts +41 -0
- package/dist/types/dil/parser/stream-worker.d.ts +1 -0
- package/dist/types/dil/parser/types.d.ts +53 -0
- package/dist/types/dil/parser/unfinished.d.ts +22 -0
- package/dist/types/dil/parser/vocabulary.d.ts +12 -0
- package/dist/types/dil/render-error.d.ts +47 -0
- package/dist/types/dil/renderer-environment.d.ts +33 -0
- package/dist/types/dil/renderer-handle.d.ts +4 -0
- package/dist/types/dil/runtime/action-receipt.d.ts +5 -0
- package/dist/types/dil/runtime/child-list.d.ts +8 -0
- package/dist/types/dil/runtime/document.d.ts +54 -0
- package/dist/types/dil/runtime/evaluation-cache.d.ts +24 -0
- package/dist/types/dil/runtime/execution-queue.d.ts +56 -0
- package/dist/types/dil/runtime/expressions.d.ts +62 -0
- package/dist/types/dil/runtime/inline-worker.d.ts +33 -0
- package/dist/types/dil/runtime/markdown-stream.d.ts +17 -0
- package/dist/types/dil/runtime/presentation-history.d.ts +14 -0
- package/dist/types/dil/runtime/presentation-scheduler.d.ts +16 -0
- package/dist/types/dil/runtime/render-budget.d.ts +10 -0
- package/dist/types/dil/runtime/view-cost.d.ts +10 -0
- package/dist/types/dil/styled-renderer.d.ts +39 -0
- package/dist/types/dil/view/conditional-view.d.ts +12 -0
- package/dist/types/dil/view/loading-block.d.ts +7 -0
- package/dist/types/dil/view/markdown-node.d.ts +12 -0
- package/dist/types/dil/view/node-children.d.ts +13 -0
- package/dist/types/dil/view/node-view.d.ts +11 -0
- package/dist/types/dil/view/progressive-reveal.d.ts +7 -0
- package/dist/types/dil/view/render-boundary.d.ts +35 -0
- package/dist/types/dil/view/render-limit.d.ts +14 -0
- package/dist/types/dil/view/repeated-nodes.d.ts +15 -0
- package/dist/types/dil/view/reveal/controller.d.ts +32 -0
- package/dist/types/dil/view/reveal/presentation.d.ts +13 -0
- package/dist/types/dil/view/reveal-options.d.ts +11 -0
- package/dist/types/dil/view/scroll/controller.d.ts +42 -0
- package/dist/types/dil/view/scroll/host-viewport.d.ts +24 -0
- package/dist/types/dil/view/scroll/root-tracker.d.ts +17 -0
- package/dist/types/dil/view/scroll/scroll-root.d.ts +36 -0
- package/dist/types/dil/view/scroll-options.d.ts +25 -0
- package/dist/types/dil/view/stream-follow.d.ts +15 -0
- package/dist/types/dil/view/table-context.d.ts +15 -0
- package/dist/types/dil/view/virtual-flow.d.ts +15 -0
- package/dist/types/dil/widgets/action-feedback.d.ts +11 -0
- package/dist/types/dil/widgets/async-image.d.ts +6 -0
- package/dist/types/dil/widgets/charts/chart-hover.d.ts +17 -0
- package/dist/types/dil/widgets/charts/chart-legend.d.ts +10 -0
- package/dist/types/dil/widgets/charts/chart-pie.d.ts +16 -0
- package/dist/types/dil/widgets/charts/chart-selection.d.ts +8 -0
- package/dist/types/dil/widgets/charts/chart-series.d.ts +19 -0
- package/dist/types/dil/widgets/charts/chart-snapping.d.ts +13 -0
- package/dist/types/dil/widgets/charts/dil-chart.d.ts +5 -0
- package/dist/types/dil/widgets/charts/snap-cursor.d.ts +12 -0
- package/dist/types/dil/widgets/charts/snap-tooltip.d.ts +12 -0
- package/dist/types/dil/widgets/code/code-editor.d.ts +9 -0
- package/dist/types/dil/widgets/code/highlighted-code.d.ts +25 -0
- package/dist/types/dil/widgets/code-block.d.ts +11 -0
- package/dist/types/dil/widgets/control-revision.d.ts +1 -0
- package/dist/types/dil/widgets/control-state.d.ts +8 -0
- package/dist/types/dil/widgets/controls.d.ts +25 -0
- package/dist/types/dil/widgets/graphs/graph-model.d.ts +13 -0
- package/dist/types/dil/widgets/graphs/node-graph.d.ts +6 -0
- package/dist/types/dil/widgets/graphs/service-node.d.ts +3 -0
- package/dist/types/dil/widgets/mermaid-diagram.d.ts +5 -0
- package/dist/types/dil/widgets/primitives/attribute-values.d.ts +12 -0
- package/dist/types/dil/widgets/primitives/primitive.d.ts +17 -0
- package/dist/types/dil/widgets/primitives/vocabulary.d.ts +5 -0
- package/dist/types/dil/widgets/use-control-value.d.ts +2 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/lib/cn.d.ts +2 -0
- package/dist/types/ui.d.ts +11 -0
- package/dist/ui.js +2 -0
- package/package.json +85 -4
- package/styles/tailwind.css +443 -0
- package/styles/tokens.css +32 -0
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 reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and 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 choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your 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 2026 OpenDIL contributors
|
|
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 implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# OpenDIL
|
|
4
|
+
|
|
5
|
+
**Interactive interfaces that stream in with your model's answer.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@snackbit/opendil)
|
|
8
|
+
[](https://github.com/snackbit/opendil/actions/workflows/ci.yml)
|
|
9
|
+
[](https://github.com/snackbit/opendil/blob/main/LICENSE)
|
|
10
|
+
|
|
11
|
+
[Docs](https://opendil.com/docs/) · [Quickstart](https://opendil.com/docs/getting-started/) · [Playground](https://opendil.com/demo/) · [Agent spec](https://opendil.com/docs/agent-spec/)
|
|
12
|
+
|
|
13
|
+
<img src="https://raw.githubusercontent.com/snackbit/opendil/main/docs/dil-assets/streaming-demo.gif" width="880" alt="DIL source streams in on the left while a budget planner builds up on the right. After the stream ends, the team slider moves from 8 to 18, annual billing is switched on, and the total and chart update." />
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
OpenDIL is a React renderer for DIL (Dynamic Interface Language): Markdown mixed with component tags, a little state, and expressions. A model writes DIL as plain text, your app passes along what has arrived so far, and readers can use the sliders, charts, and buttons before the answer finishes.
|
|
18
|
+
|
|
19
|
+
OpenDIL never calls your model provider. It works with any client that streams text, including the Vercel AI SDK, the OpenAI and Anthropic SDKs, and plain `fetch`.
|
|
20
|
+
|
|
21
|
+
## Quickstart
|
|
22
|
+
|
|
23
|
+
Install the package and copy the iframe runtime into your public folder:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm install @snackbit/opendil
|
|
27
|
+
npx opendil copy-assets --out public/opendil
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The default rendering mode draws each answer in a sandboxed iframe that loads `frame.html` and `frame.js` from `/opendil/`. Copy them again on every install (a `postinstall` script works), and serve `frame.html` with the header described in the [Quickstart](https://opendil.com/docs/getting-started/#send-the-frames-security-header) before you ship.
|
|
31
|
+
|
|
32
|
+
Put the agent spec first in your system prompt:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { agentSpec } from "@snackbit/opendil/agent-spec";
|
|
36
|
+
|
|
37
|
+
export const systemPrompt = [
|
|
38
|
+
agentSpec,
|
|
39
|
+
"You are the assistant in a pricing app. Keep answers short.",
|
|
40
|
+
].join("\n\n");
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Render each assistant message with `DilRenderer`:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
"use client";
|
|
47
|
+
import { DilRenderer } from "@snackbit/opendil";
|
|
48
|
+
import "@snackbit/opendil/styles.css";
|
|
49
|
+
|
|
50
|
+
type Message = { id: string; role: "user" | "assistant"; text: string };
|
|
51
|
+
|
|
52
|
+
export function Messages(props: { messages: Message[]; streaming: boolean }) {
|
|
53
|
+
const { messages, streaming } = props;
|
|
54
|
+
return messages.map((message, index) =>
|
|
55
|
+
message.role === "user" ? (
|
|
56
|
+
<p key={message.id}>{message.text}</p>
|
|
57
|
+
) : (
|
|
58
|
+
<DilRenderer
|
|
59
|
+
key={message.id}
|
|
60
|
+
text={message.text}
|
|
61
|
+
isStreaming={streaming && index === messages.length - 1}
|
|
62
|
+
showStatus={false}
|
|
63
|
+
/>
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Three rules apply to every streamed answer:
|
|
70
|
+
|
|
71
|
+
1. Pass all the text received so far. `text` only grows.
|
|
72
|
+
2. Set `isStreaming={false}` when the answer is complete.
|
|
73
|
+
3. Give each answer its own `key`. A new key starts a new answer.
|
|
74
|
+
|
|
75
|
+
## Integrating OpenDIL
|
|
76
|
+
|
|
77
|
+
An integration has two halves, one on each side of your existing chat.
|
|
78
|
+
|
|
79
|
+
**Teach the model DIL.** The agent spec is a Markdown document that teaches a model the syntax, the stock components, and the output rules. It ships in the package, so the prompt always matches your renderer version. `@snackbit/opendil/agent-spec` exports three strings: `agentSpec` (the primary spec, about 23 KB), `agentSpecFull` (about 83 KB, with a block per component and task), and `agentSpecExamples` (a runnable example per component). The same files are exported as Markdown under `@snackbit/opendil/spec/`, and the source lives in [`spec/`](https://github.com/snackbit/opendil/tree/main/spec).
|
|
80
|
+
|
|
81
|
+
- [Agent spec](https://opendil.com/docs/agent-spec/): load the spec, choose primary or full, and add your own rules.
|
|
82
|
+
- [Prompting and evaluation](https://opendil.com/docs/prompting/): decide when the model should use UI, supply data, and test generated answers.
|
|
83
|
+
|
|
84
|
+
**Render the stream in React.** `DilRenderer` takes the text received so far and whether more may arrive. Your app keeps its transport, message storage, and chat interface.
|
|
85
|
+
|
|
86
|
+
- [Add OpenDIL to your chat app](https://opendil.com/docs/chat-integration/): server routes and client code for the AI SDK, OpenAI, Anthropic, and `fetch` with server-sent events, including stop, retry, and "Jump to latest".
|
|
87
|
+
- [Streaming](https://opendil.com/docs/streaming/): fade in new content, follow the stream, and control update frequency.
|
|
88
|
+
- [`DilRenderer` reference](https://opendil.com/docs/renderer/): every prop, the ref handle, and the types.
|
|
89
|
+
|
|
90
|
+
Two example apps show a complete integration:
|
|
91
|
+
|
|
92
|
+
- [`examples/next-ai-sdk`](https://github.com/snackbit/opendil/tree/main/examples/next-ai-sdk): Next.js with the Vercel AI SDK.
|
|
93
|
+
- [`examples/vite-sse`](https://github.com/snackbit/opendil/tree/main/examples/vite-sse): Vite with a server that streams server-sent events.
|
|
94
|
+
|
|
95
|
+
## What DIL looks like
|
|
96
|
+
|
|
97
|
+
```jsx
|
|
98
|
+
{@body const [count,setCount] = DIL.useState(0)}
|
|
99
|
+
<box border padding={4} gap={3}>
|
|
100
|
+
<title>Hello from DIL</title>
|
|
101
|
+
<button onClick={() => setCount(count + 1)}>Clicked {count} times</button>
|
|
102
|
+
</box>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Markdown carries the prose. Tags such as `<box>`, `<slider>`, and `<Chart>` become components, `{@body …}` declares state and derived values, and `{#if}` and `{#each}` show content conditionally or repeat it. The [DIL tour](https://opendil.com/docs/language/) covers the language, and the [component pages](https://opendil.com/docs/components/text/) list every stock component.
|
|
106
|
+
|
|
107
|
+
## Rendering modes
|
|
108
|
+
|
|
109
|
+
| Mode | Where it renders | Custom components | Setup |
|
|
110
|
+
| -------------------- | --------------------------------------- | ----------------- | ------------------------------------- |
|
|
111
|
+
| `isolated` (default) | A sandboxed iframe with no origin | No | Runtime files and one response header |
|
|
112
|
+
| `shadow` | A shadow root in your page | Yes | Two CSP directives, if you send a CSP |
|
|
113
|
+
| `host` | Your page's DOM, in a `.dil-scope` root | Yes | Two CSP directives, if you send a CSP |
|
|
114
|
+
|
|
115
|
+
Start with the default. Switch to Shadow DOM or host mode when you need [custom components](https://opendil.com/docs/custom-components/) or your own classes on built-in ones. [Rendering modes](https://opendil.com/docs/rendering-modes/) covers headers, base paths, and Content Security Policy for each mode, and [Theming](https://opendil.com/docs/theming/) covers light and dark appearance and design tokens.
|
|
116
|
+
|
|
117
|
+
## Security
|
|
118
|
+
|
|
119
|
+
OpenDIL treats every answer as untrusted input. In every mode, expressions run in QuickJS, a JavaScript engine compiled to WebAssembly, inside a Web Worker with memory and work limits; your page never evaluates them. The default iframe mode also keeps the answer away from your page, its storage, and the network, while Shadow DOM and host modes render in your page's origin and are a styling boundary, not a security boundary. [Security](https://opendil.com/docs/security/) describes the threat model and what you must configure. Report vulnerabilities as described in [SECURITY.md](https://github.com/snackbit/opendil/blob/main/SECURITY.md).
|
|
120
|
+
|
|
121
|
+
## Requirements
|
|
122
|
+
|
|
123
|
+
- React 19. `react` and `react-dom` `^19.0.0` are peer dependencies.
|
|
124
|
+
- A bundler that reads package `exports` and CSS imports, such as Next.js or Vite. The package is ESM only.
|
|
125
|
+
- A browser with Web Workers, WebAssembly, and sandboxed iframes. Shadow DOM mode also needs constructable stylesheets.
|
|
126
|
+
- Node.js 22 or newer for the `opendil` command.
|
|
127
|
+
|
|
128
|
+
[Package and CLI](https://opendil.com/docs/package/) lists the entry points, stylesheets, and bundle sizes. [Limits](https://opendil.com/docs/limits/) lists what DIL and the stock renderer do not do.
|
|
129
|
+
|
|
130
|
+
## Contributing
|
|
131
|
+
|
|
132
|
+
See [CONTRIBUTING.md](https://github.com/snackbit/opendil/blob/main/CONTRIBUTING.md) for the repository layout, checks, and release process.
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
Apache 2.0. See [LICENSE](https://github.com/snackbit/opendil/blob/main/LICENSE) and the [third-party notices](https://github.com/snackbit/opendil/blob/main/THIRD_PARTY_NOTICES.md).
|
|
137
|
+
|
|
138
|
+
Made by [Felix Faust](https://turtledev.net).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
OpenDIL uses React, Radix UI, shadcn/ui-derived primitives, Tailwind CSS, QuickJS/WASM, Acorn, Recharts, React Flow, Mermaid, DOMPurify, Lowlight/highlight.js, and other packages listed in its package manifest. The demo uses gpt-tokenizer. Their licenses remain in their distributed packages; Apache 2.0 does not replace those terms.
|
|
4
|
+
|
|
5
|
+
The maintained UI primitives were adapted from shadcn/ui, copyright shadcn, under the MIT license. Permission is granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: the above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
|
9
|
+
The website uses Astro, Starlight, CodeMirror, and self-hosted Space Grotesk, Inter, and IBM Plex Mono fonts. Their licenses remain in the corresponding distributed packages. The demo showcase document is adapted from a generative UI response that a maintainer created with ChatGPT. The raw captures of that session are not part of the repository or the npm package. The image carousel uses original geometric SVG illustrations. OpenDIL is an independent project and is not affiliated with or endorsed by OpenAI.
|
package/bin/opendil.mjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { MANIFEST, publishDirectory } from "./publish-directory.mjs";
|
|
6
|
+
|
|
7
|
+
const usage = `Usage: opendil copy-assets --out <public-directory>
|
|
8
|
+
|
|
9
|
+
Copies the iframe runtime (frame.html, frame.js) into a directory your app
|
|
10
|
+
serves, such as public/opendil. Serve it at the renderer's runtimeBaseUrl
|
|
11
|
+
(default /opendil/). Only the default iframe mode needs these files.
|
|
12
|
+
|
|
13
|
+
Options:
|
|
14
|
+
--out <dir>, --out=<dir> Destination directory (created if missing)
|
|
15
|
+
-h, --help Show this help
|
|
16
|
+
|
|
17
|
+
Each copy writes ${MANIFEST} into the destination. The next copy uses it to
|
|
18
|
+
remove runtime files that an earlier version wrote and this version no longer
|
|
19
|
+
ships. Files the manifest does not list, or that changed since, are kept.`;
|
|
20
|
+
|
|
21
|
+
function parse(args) {
|
|
22
|
+
if (args.some((arg) => arg === "-h" || arg === "--help"))
|
|
23
|
+
return { help: true };
|
|
24
|
+
const [command, ...rest] = args;
|
|
25
|
+
if (command !== "copy-assets") return {};
|
|
26
|
+
let out;
|
|
27
|
+
for (let index = 0; index < rest.length; index++) {
|
|
28
|
+
const arg = rest[index];
|
|
29
|
+
if (out !== undefined) return {};
|
|
30
|
+
if (arg === "--out") out = rest[++index];
|
|
31
|
+
else if (arg.startsWith("--out=")) out = arg.slice("--out=".length);
|
|
32
|
+
else return {};
|
|
33
|
+
}
|
|
34
|
+
return out ? { out } : {};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function size(bytes) {
|
|
38
|
+
return bytes >= 1024 * 1024
|
|
39
|
+
? (bytes / 1024 / 1024).toFixed(1) + " MB"
|
|
40
|
+
: (bytes / 1024).toFixed(1) + " kB";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const options = parse(process.argv.slice(2));
|
|
44
|
+
if (options.help) console.log(usage);
|
|
45
|
+
else if (!options.out) {
|
|
46
|
+
console.error(usage);
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
} else {
|
|
49
|
+
const output = resolve(options.out);
|
|
50
|
+
const { name, version } = JSON.parse(
|
|
51
|
+
await readFile(new URL("../package.json", import.meta.url), "utf8"),
|
|
52
|
+
);
|
|
53
|
+
const result = await publishDirectory(
|
|
54
|
+
fileURLToPath(new URL("../dist/runtime/", import.meta.url)),
|
|
55
|
+
output,
|
|
56
|
+
{
|
|
57
|
+
// Development builds can leave older files in dist/runtime; copy only the runtime.
|
|
58
|
+
files: ["frame.html", "frame.js"],
|
|
59
|
+
removeStale: true,
|
|
60
|
+
metadata: { package: name, version },
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
const plural = (count) => count + (count === 1 ? " file" : " files");
|
|
64
|
+
console.log(
|
|
65
|
+
`Copied ${plural(result.files.length)} (${size(result.bytes)}) from ${name}@${version} to ${output}`,
|
|
66
|
+
);
|
|
67
|
+
if (result.removed.length)
|
|
68
|
+
console.log(
|
|
69
|
+
`Removed ${plural(result.removed.length)} left by an earlier copy: ${result.removed.join(", ")}`,
|
|
70
|
+
);
|
|
71
|
+
if (result.kept.length)
|
|
72
|
+
console.log(
|
|
73
|
+
`Kept ${plural(result.kept.length)} from an earlier copy that changed since: ${result.kept.join(", ")}`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const MANIFEST: string;
|
|
2
|
+
export function listFiles(directory: string): Promise<string[]>;
|
|
3
|
+
export function readManifest(directory: string): Promise<Map<string, string>>;
|
|
4
|
+
export function publishDirectory(
|
|
5
|
+
source: string,
|
|
6
|
+
destination: string,
|
|
7
|
+
options?: {
|
|
8
|
+
files?: string[];
|
|
9
|
+
removeStale?: boolean;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
},
|
|
12
|
+
): Promise<{
|
|
13
|
+
files: string[];
|
|
14
|
+
bytes: number;
|
|
15
|
+
removed: string[];
|
|
16
|
+
kept: string[];
|
|
17
|
+
}>;
|
|
18
|
+
export function pruneUnlisted(directory: string): Promise<string[]>;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mkdir,
|
|
3
|
+
readdir,
|
|
4
|
+
readFile,
|
|
5
|
+
copyFile,
|
|
6
|
+
rename,
|
|
7
|
+
rm,
|
|
8
|
+
lstat,
|
|
9
|
+
realpath,
|
|
10
|
+
writeFile,
|
|
11
|
+
} from "node:fs/promises";
|
|
12
|
+
import { join, dirname, isAbsolute, normalize, sep } from "node:path";
|
|
13
|
+
import { randomUUID, createHash } from "node:crypto";
|
|
14
|
+
|
|
15
|
+
/** Lists every published file in a directory written by publishDirectory. */
|
|
16
|
+
export const MANIFEST = ".opendil-manifest.json";
|
|
17
|
+
|
|
18
|
+
/** Returns the relative paths of all files below a directory, using "/" separators. */
|
|
19
|
+
export async function listFiles(directory) {
|
|
20
|
+
const files = [];
|
|
21
|
+
async function collect(relative) {
|
|
22
|
+
for (const entry of await readdir(join(directory, relative), {
|
|
23
|
+
withFileTypes: true,
|
|
24
|
+
})) {
|
|
25
|
+
const file = relative ? relative + "/" + entry.name : entry.name;
|
|
26
|
+
if (entry.isDirectory()) await collect(file);
|
|
27
|
+
else files.push(file);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
await collect("");
|
|
31
|
+
return files.sort();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function hash(content) {
|
|
35
|
+
return createHash("sha256").update(content).digest("hex");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function replaceFile(target, write) {
|
|
39
|
+
await mkdir(dirname(target), { recursive: true });
|
|
40
|
+
const temporary = target + "." + randomUUID() + ".tmp";
|
|
41
|
+
try {
|
|
42
|
+
await write(temporary);
|
|
43
|
+
await rename(temporary, target);
|
|
44
|
+
} finally {
|
|
45
|
+
await rm(temporary, { force: true });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Accepts only plain relative paths with "/" separators. Backslashes and colons
|
|
51
|
+
* are rejected so Windows cannot read an entry as a traversal or drive path.
|
|
52
|
+
*/
|
|
53
|
+
function isContainedPath(file) {
|
|
54
|
+
return (
|
|
55
|
+
typeof file === "string" &&
|
|
56
|
+
file !== "" &&
|
|
57
|
+
!/[\\:]/.test(file) &&
|
|
58
|
+
!isAbsolute(file) &&
|
|
59
|
+
normalize(file) === file.split("/").join(sep) &&
|
|
60
|
+
!file.split("/").some((part) => part === ".." || part === ".")
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Resolves symlinked parent directories so a link cannot lead a removal outside root. */
|
|
65
|
+
async function isInsideDirectory(root, target) {
|
|
66
|
+
try {
|
|
67
|
+
const [base, parent] = await Promise.all([
|
|
68
|
+
realpath(root),
|
|
69
|
+
realpath(dirname(target)),
|
|
70
|
+
]);
|
|
71
|
+
return parent === base || parent.startsWith(base + sep);
|
|
72
|
+
} catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Reads the files and hashes recorded by an earlier publish. A missing or
|
|
79
|
+
* unreadable manifest yields no entries, so nothing becomes eligible for removal.
|
|
80
|
+
*/
|
|
81
|
+
export async function readManifest(directory) {
|
|
82
|
+
let parsed;
|
|
83
|
+
try {
|
|
84
|
+
parsed = JSON.parse(await readFile(join(directory, MANIFEST), "utf8"));
|
|
85
|
+
} catch {
|
|
86
|
+
return new Map();
|
|
87
|
+
}
|
|
88
|
+
const files =
|
|
89
|
+
parsed && typeof parsed.files === "object" && parsed.files
|
|
90
|
+
? parsed.files
|
|
91
|
+
: {};
|
|
92
|
+
return new Map(
|
|
93
|
+
Object.entries(files).filter(
|
|
94
|
+
([file, hash]) =>
|
|
95
|
+
isContainedPath(file) && file !== MANIFEST && typeof hash === "string",
|
|
96
|
+
),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Publishes complete files without removing paths used by an active dev server.
|
|
102
|
+
* Copies every file below source unless files names a subset. Writes a manifest
|
|
103
|
+
* of the published files and their SHA-256 hashes. With removeStale, files
|
|
104
|
+
* listed in the previous manifest but absent from this publish are deleted when
|
|
105
|
+
* their content is still what was published. Files the manifest does not list,
|
|
106
|
+
* that changed since, or whose real path leaves destination are never touched.
|
|
107
|
+
*/
|
|
108
|
+
export async function publishDirectory(
|
|
109
|
+
source,
|
|
110
|
+
destination,
|
|
111
|
+
{ files: selected, removeStale = false, metadata = {} } = {},
|
|
112
|
+
) {
|
|
113
|
+
const files = (selected ?? (await listFiles(source))).filter(
|
|
114
|
+
(file) => file !== MANIFEST,
|
|
115
|
+
);
|
|
116
|
+
const previous = removeStale ? await readManifest(destination) : new Map();
|
|
117
|
+
// Entry points go last so they never reference a chunk that is not yet written.
|
|
118
|
+
const priority = (file) =>
|
|
119
|
+
/(?:^|\/)(?:index\.js|ui\.js|frame\.html)$/.test(file) ? 1 : 0;
|
|
120
|
+
const ordered = [...files].sort((a, b) => priority(a) - priority(b));
|
|
121
|
+
const hashes = {};
|
|
122
|
+
let bytes = 0;
|
|
123
|
+
for (const file of ordered) {
|
|
124
|
+
const from = join(source, file);
|
|
125
|
+
const content = await readFile(from);
|
|
126
|
+
hashes[file] = hash(content);
|
|
127
|
+
bytes += content.length;
|
|
128
|
+
await replaceFile(join(destination, file), (temporary) =>
|
|
129
|
+
copyFile(from, temporary),
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const removed = [];
|
|
133
|
+
const kept = [];
|
|
134
|
+
for (const [file, recorded] of previous) {
|
|
135
|
+
if (file in hashes) continue;
|
|
136
|
+
const target = join(destination, file);
|
|
137
|
+
if (!(await isInsideDirectory(destination, target))) continue;
|
|
138
|
+
let stats;
|
|
139
|
+
try {
|
|
140
|
+
stats = await lstat(target);
|
|
141
|
+
} catch {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (stats.isFile() && hash(await readFile(target)) === recorded) {
|
|
145
|
+
await rm(target, { force: true });
|
|
146
|
+
removed.push(file);
|
|
147
|
+
} else kept.push(file);
|
|
148
|
+
}
|
|
149
|
+
const sorted = Object.fromEntries(
|
|
150
|
+
Object.keys(hashes)
|
|
151
|
+
.sort()
|
|
152
|
+
.map((file) => [file, hashes[file]]),
|
|
153
|
+
);
|
|
154
|
+
await replaceFile(join(destination, MANIFEST), (temporary) =>
|
|
155
|
+
writeFile(
|
|
156
|
+
temporary,
|
|
157
|
+
JSON.stringify({ ...metadata, files: sorted }, null, 2) + "\n",
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
return { files, bytes, removed, kept };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Deletes every file below a directory that its manifest does not list. Use it
|
|
165
|
+
* only for directories the publisher owns completely, such as a build output.
|
|
166
|
+
*/
|
|
167
|
+
export async function pruneUnlisted(directory) {
|
|
168
|
+
const listed = await readManifest(directory);
|
|
169
|
+
if (!listed.size)
|
|
170
|
+
throw new Error("No publish manifest in " + directory + "; build it first");
|
|
171
|
+
const removed = [];
|
|
172
|
+
for (const file of await listFiles(directory)) {
|
|
173
|
+
if (file === MANIFEST || listed.has(file)) continue;
|
|
174
|
+
await rm(join(directory, file), { force: true });
|
|
175
|
+
removed.push(file);
|
|
176
|
+
}
|
|
177
|
+
await removeEmptyDirectories(directory);
|
|
178
|
+
return removed;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function removeEmptyDirectories(directory) {
|
|
182
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
183
|
+
if (!entry.isDirectory()) continue;
|
|
184
|
+
const path = join(directory, entry.name);
|
|
185
|
+
await removeEmptyDirectories(path);
|
|
186
|
+
if (!(await readdir(path)).length) await rm(path, { recursive: true });
|
|
187
|
+
}
|
|
188
|
+
}
|