@polyxd/runtime 0.4.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 +202 -0
- package/NOTICE +224 -0
- package/README.md +85 -0
- package/dist/adapters/anthropic.d.ts +22 -0
- package/dist/adapters/anthropic.js +48 -0
- package/dist/adapters/anthropic.js.map +1 -0
- package/dist/adapters/gemini.d.ts +14 -0
- package/dist/adapters/gemini.js +42 -0
- package/dist/adapters/gemini.js.map +1 -0
- package/dist/adapters/http.d.ts +25 -0
- package/dist/adapters/http.js +92 -0
- package/dist/adapters/http.js.map +1 -0
- package/dist/adapters/openai.d.ts +31 -0
- package/dist/adapters/openai.js +89 -0
- package/dist/adapters/openai.js.map +1 -0
- package/dist/audit.d.ts +17 -0
- package/dist/audit.js +48 -0
- package/dist/audit.js.map +1 -0
- package/dist/catalog.generated.d.ts +4 -0
- package/dist/catalog.generated.js +618 -0
- package/dist/catalog.generated.js.map +1 -0
- package/dist/direction.d.ts +22 -0
- package/dist/direction.js +95 -0
- package/dist/direction.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +25 -0
- package/dist/memory.js +38 -0
- package/dist/memory.js.map +1 -0
- package/dist/parse.d.ts +15 -0
- package/dist/parse.js +35 -0
- package/dist/parse.js.map +1 -0
- package/dist/prompt.d.ts +47 -0
- package/dist/prompt.js +242 -0
- package/dist/prompt.js.map +1 -0
- package/dist/runtime.d.ts +131 -0
- package/dist/runtime.js +190 -0
- package/dist/runtime.js.map +1 -0
- package/dist/types.d.ts +104 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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 [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 implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/NOTICE
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
Polyxd
|
|
2
|
+
Copyright 2026 the Polyxd authors
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Polyxd, licensed under the Apache
|
|
5
|
+
License, Version 2.0 (see LICENSE), except Polyxd Studio (apps/studio), which is
|
|
6
|
+
licensed under the Functional Source License, Version 1.1, ALv2 Future License
|
|
7
|
+
(see apps/studio/LICENSE).
|
|
8
|
+
|
|
9
|
+
It also includes material from the projects below. Each is used under its own
|
|
10
|
+
licence, and each licence is included in full beside the material it covers.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Design-system packs
|
|
14
|
+
|
|
15
|
+
A pack reads a design system's published tokens and maps them onto Polyxd's
|
|
16
|
+
semantic token contract. The upstream token files are vendored verbatim — so a
|
|
17
|
+
pack can be regenerated and audited without a network — under that pack's
|
|
18
|
+
`scripts/sources/` directory, together with the upstream licence.
|
|
19
|
+
|
|
20
|
+
The packs are Polyxd's work, not the work of the design systems they read. The
|
|
21
|
+
names below identify whose tokens a pack reads. Polyxd is not affiliated with,
|
|
22
|
+
endorsed by, or sponsored by any of these projects or their owners, and each
|
|
23
|
+
name is the trademark of its owner.
|
|
24
|
+
|
|
25
|
+
### Ant Design (`@polyxd/ds-antd`)
|
|
26
|
+
|
|
27
|
+
Upstream: https://github.com/ant-design/ant-design
|
|
28
|
+
|
|
29
|
+
- npm:antd 6.6.4 — MIT
|
|
30
|
+
- npm:@ant-design/colors 8.0.1 — MIT
|
|
31
|
+
|
|
32
|
+
Vendored under `packages/ds-antd/scripts/sources/`, with the upstream licence file beside it.
|
|
33
|
+
|
|
34
|
+
### Bootstrap 5 (`@polyxd/ds-bootstrap`)
|
|
35
|
+
|
|
36
|
+
Upstream: https://github.com/twbs/bootstrap
|
|
37
|
+
|
|
38
|
+
- npm:bootstrap dist/css/bootstrap.css 5.3.8 — MIT
|
|
39
|
+
|
|
40
|
+
Vendored under `packages/ds-bootstrap/scripts/sources/`, with the upstream licence file beside it.
|
|
41
|
+
|
|
42
|
+
### IBM Carbon (`@polyxd/ds-carbon`)
|
|
43
|
+
|
|
44
|
+
Upstream: https://github.com/carbon-design-system/carbon
|
|
45
|
+
|
|
46
|
+
- npm:@carbon/colors 11.58.0 — Apache-2.0
|
|
47
|
+
- npm:@carbon/themes 11.81.0 — Apache-2.0
|
|
48
|
+
- npm:@carbon/layout 11.59.0 — Apache-2.0
|
|
49
|
+
- npm:@carbon/type 11.67.0 — Apache-2.0
|
|
50
|
+
- npm:@carbon/motion 11.52.0 — Apache-2.0
|
|
51
|
+
- npm:@carbon/charts scss/_color-palette.scss 1.27.20 — Apache-2.0
|
|
52
|
+
- npm:@carbon/styles scss/utilities/_box-shadow.scss and _focus-outline.scss 1.115.0 — Apache-2.0
|
|
53
|
+
|
|
54
|
+
Vendored under `packages/ds-carbon/scripts/sources/`, with the upstream licence file beside it.
|
|
55
|
+
|
|
56
|
+
### Chakra UI 3 (`@polyxd/ds-chakra`)
|
|
57
|
+
|
|
58
|
+
Upstream: https://github.com/chakra-ui/chakra-ui
|
|
59
|
+
|
|
60
|
+
- npm:@chakra-ui/react defaultSystem.getTokenCss 3.37.0 — MIT
|
|
61
|
+
|
|
62
|
+
Vendored under `packages/ds-chakra/scripts/sources/`, with the upstream licence file beside it.
|
|
63
|
+
|
|
64
|
+
### Microsoft Fluent 2 (`@polyxd/ds-fluent`)
|
|
65
|
+
|
|
66
|
+
Upstream: https://github.com/microsoft/fluentui
|
|
67
|
+
|
|
68
|
+
- npm:@fluentui/tokens 1.0.0-alpha.24 — MIT
|
|
69
|
+
|
|
70
|
+
Vendored under `packages/ds-fluent/scripts/sources/`, with the upstream licence file beside it.
|
|
71
|
+
|
|
72
|
+
### GOV.UK Frontend (`@polyxd/ds-govuk`)
|
|
73
|
+
|
|
74
|
+
Upstream: https://github.com/alphagov/govuk-frontend
|
|
75
|
+
|
|
76
|
+
- npm:govuk-frontend dist/govuk/settings 6.5.1 — MIT
|
|
77
|
+
|
|
78
|
+
Vendored under `packages/ds-govuk/scripts/sources/`, with the upstream licence file beside it.
|
|
79
|
+
|
|
80
|
+
### Mantine 8 (`@polyxd/ds-mantine`)
|
|
81
|
+
|
|
82
|
+
Upstream: https://github.com/mantinedev/mantine
|
|
83
|
+
|
|
84
|
+
- npm:@mantine/core styles.css 8.4.2 — MIT
|
|
85
|
+
|
|
86
|
+
Vendored under `packages/ds-mantine/scripts/sources/`, with the upstream licence file beside it.
|
|
87
|
+
|
|
88
|
+
### Material 3 (`@polyxd/ds-material3`)
|
|
89
|
+
|
|
90
|
+
Upstream: https://github.com/material-components/material-web
|
|
91
|
+
|
|
92
|
+
- npm:@material/material-color-utilities 0.4.0 — Apache-2.0
|
|
93
|
+
- github:material-components/material-web tokens/versions/v0_192/_md-ref-typeface.scss, _md-sys-typescale.scss, _md-sys-shape.scss, _md-sys-motion.scss, _md-sys-state.scss, _md-sys-elevation.scss v2.5.0 (commit b4de401eb665ec63474f39319a4ba8f2145974cc) — Apache-2.0
|
|
94
|
+
- github:material-components/material-web tokens/versions/v0_192/_md-comp-scrim.scss, _md-comp-filled-button.scss, _md-comp-icon-button.scss, _md-comp-outlined-text-field.scss v2.5.0 (commit b4de401eb665ec63474f39319a4ba8f2145974cc) — Apache-2.0
|
|
95
|
+
- github:material-components/material-web tokens/_md-comp-focus-ring.scss and elevation/internal/_elevation.scss v2.5.0 (commit b4de401eb665ec63474f39319a4ba8f2145974cc) — Apache-2.0
|
|
96
|
+
|
|
97
|
+
Vendored under `packages/ds-material3/scripts/sources/`, with the upstream licence file beside it.
|
|
98
|
+
|
|
99
|
+
### Shopify Polaris (`@polyxd/ds-polaris`)
|
|
100
|
+
|
|
101
|
+
Upstream: https://github.com/Shopify/polaris
|
|
102
|
+
|
|
103
|
+
- npm:@shopify/polaris-tokens dist/css/styles.css 9.4.2 — MIT
|
|
104
|
+
|
|
105
|
+
Vendored under `packages/ds-polaris/scripts/sources/`, with the upstream licence file beside it.
|
|
106
|
+
|
|
107
|
+
### GitHub Primer (`@polyxd/ds-primer`)
|
|
108
|
+
|
|
109
|
+
Upstream: https://github.com/primer/primitives
|
|
110
|
+
|
|
111
|
+
- npm:@primer/primitives dist/css 11.10.0 — MIT
|
|
112
|
+
|
|
113
|
+
Vendored under `packages/ds-primer/scripts/sources/`, with the upstream licence file beside it.
|
|
114
|
+
|
|
115
|
+
### Radix Themes 3 (`@polyxd/ds-radix`)
|
|
116
|
+
|
|
117
|
+
Upstream: https://github.com/radix-ui/themes
|
|
118
|
+
|
|
119
|
+
- npm:@radix-ui/themes styles.css 3.3.0 — MIT
|
|
120
|
+
|
|
121
|
+
Vendored under `packages/ds-radix/scripts/sources/`, with the upstream licence file beside it.
|
|
122
|
+
|
|
123
|
+
### shadcn/ui on Tailwind CSS (`@polyxd/ds-shadcn`)
|
|
124
|
+
|
|
125
|
+
Upstream: https://github.com/shadcn-ui/ui
|
|
126
|
+
|
|
127
|
+
- shadcn/ui default theme main @ 2026-09-20 — MIT
|
|
128
|
+
- npm:tailwindcss theme.css 4.3.3 — MIT
|
|
129
|
+
|
|
130
|
+
Vendored under `packages/ds-shadcn/scripts/sources/`, with the upstream licence file beside it.
|
|
131
|
+
|
|
132
|
+
### Adobe Spectrum 2 (`@polyxd/ds-spectrum`)
|
|
133
|
+
|
|
134
|
+
Upstream: https://github.com/adobe/spectrum-tokens
|
|
135
|
+
|
|
136
|
+
- npm:@adobe/spectrum-tokens dist/json/variables.json 15.4.1 — Apache-2.0
|
|
137
|
+
|
|
138
|
+
Vendored under `packages/ds-spectrum/scripts/sources/`, with the upstream licence file beside it.
|
|
139
|
+
|
|
140
|
+
## Logos
|
|
141
|
+
|
|
142
|
+
Twelve packs ship their design system's official logo, unaltered, as `logo.svg`
|
|
143
|
+
(Bootstrap and Radix also ship the owner's white version as `logo-white.svg`),
|
|
144
|
+
downloaded from the owner's own site, repository or brand page. Where a design
|
|
145
|
+
system has no mark of its own (Polaris, Spectrum, Primer), the pack ships its
|
|
146
|
+
company's logo. Each is used only to identify the design system a pack is
|
|
147
|
+
modelled on, beside its name. The logos are trademarks of their owners, not
|
|
148
|
+
Polyxd's, and are not covered by Polyxd's licence:
|
|
149
|
+
|
|
150
|
+
- Material 3 (`@polyxd/ds-material3`) — Google LLC
|
|
151
|
+
- Carbon (`@polyxd/ds-carbon`) — IBM Corp.
|
|
152
|
+
- Fluent 2 (`@polyxd/ds-fluent`) — Microsoft Corporation
|
|
153
|
+
- Polaris (`@polyxd/ds-polaris`) — the Shopify logo, Shopify Inc.
|
|
154
|
+
- Spectrum 2 (`@polyxd/ds-spectrum`) — the Adobe logo, Adobe Inc.
|
|
155
|
+
- Primer (`@polyxd/ds-primer`) — the GitHub logo, GitHub, Inc.
|
|
156
|
+
- shadcn/ui (`@polyxd/ds-shadcn`) — shadcn
|
|
157
|
+
- Ant Design (`@polyxd/ds-antd`) — Ant Group
|
|
158
|
+
- Bootstrap (`@polyxd/ds-bootstrap`) — the Bootstrap team
|
|
159
|
+
- Chakra UI (`@polyxd/ds-chakra`) — Chakra Systems Inc.
|
|
160
|
+
- Mantine (`@polyxd/ds-mantine`) — Vitaly Rtishchev
|
|
161
|
+
- Radix UI (`@polyxd/ds-radix`) — WorkOS
|
|
162
|
+
|
|
163
|
+
Google, IBM, Microsoft, Shopify, Adobe and GitHub restrict the use of their
|
|
164
|
+
logos without permission; each pack's manifest (`logo`) and README record the
|
|
165
|
+
source and the owner's guidelines. GOV.UK's crown and logotype are protected and
|
|
166
|
+
may not be used by a service that is not on GOV.UK, so `@polyxd/ds-govuk` ships
|
|
167
|
+
no logo and is named in words only.
|
|
168
|
+
|
|
169
|
+
The twelve template packs' `logo.svg` files are Polyxd's own marks, drawn from
|
|
170
|
+
each template's tokens.
|
|
171
|
+
|
|
172
|
+
## Template packs
|
|
173
|
+
|
|
174
|
+
Twelve packs are original Polyxd templates, not readings of any design system:
|
|
175
|
+
`@polyxd/ds-sketch`, `@polyxd/ds-wireframe`, `@polyxd/ds-editorial`,
|
|
176
|
+
`@polyxd/ds-brutalist`, `@polyxd/ds-glass`, `@polyxd/ds-terminal`,
|
|
177
|
+
`@polyxd/ds-pastel`, `@polyxd/ds-civic`, `@polyxd/ds-finance`,
|
|
178
|
+
`@polyxd/ds-health`, `@polyxd/ds-neon` and `@polyxd/ds-mono`. Every value in
|
|
179
|
+
them was chosen for the template, they vendor nothing, and they are Apache-2.0
|
|
180
|
+
like the rest of Polyxd. The typefaces some of them name (Caveat, Patrick Hand,
|
|
181
|
+
Fraunces, Nunito, JetBrains Mono, Space Grotesk) are under the SIL Open Font
|
|
182
|
+
License and are loaded from Google Fonts by the page that uses them, never
|
|
183
|
+
distributed here.
|
|
184
|
+
|
|
185
|
+
## Specification
|
|
186
|
+
|
|
187
|
+
### A2UI
|
|
188
|
+
|
|
189
|
+
- `packages/a2ui/vendor/a2ui/v1_0-04e6f07/` — Apache-2.0
|
|
190
|
+
|
|
191
|
+
Vendored at a pinned commit so the component catalogue can be checked against
|
|
192
|
+
A2UI's schema without a network.
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
## Dependencies
|
|
196
|
+
|
|
197
|
+
Everything Polyxd depends on at runtime or to build is fetched from npm rather
|
|
198
|
+
than vendored, so the licences below are recorded rather than reproduced.
|
|
199
|
+
|
|
200
|
+
Apache-2.0: playwright
|
|
201
|
+
MIT: react, react-dom, radix-ui, ajv, ajv-formats, vite, @vitejs/plugin-react,
|
|
202
|
+
marked, lenis, @types/react, @types/react-dom
|
|
203
|
+
MIT OR Apache-2.0: wrangler, @cloudflare/workers-types
|
|
204
|
+
|
|
205
|
+
Two need a word.
|
|
206
|
+
|
|
207
|
+
**axe-core** (Mozilla Public License 2.0) runs inside the verifier's rendered
|
|
208
|
+
audit. MPL-2.0 is file-level copyleft: it attaches to modified MPL files, and
|
|
209
|
+
axe-core is used unmodified, as a library. No Polyxd file is covered by it.
|
|
210
|
+
|
|
211
|
+
**GSAP** (https://gsap.com/standard-license) drives the motion on polyxd.com
|
|
212
|
+
only, and is not an OSI-approved licence. It is not used by the spec, the
|
|
213
|
+
renderer, the packs or the verifier, none of which it can reach; and no GSAP
|
|
214
|
+
file is committed to this repository — the site's build copies them out of
|
|
215
|
+
node_modules into its own output. Anyone building the site is therefore subject
|
|
216
|
+
to GSAP's licence, and anyone using the rest of Polyxd is not.
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
## Fonts
|
|
220
|
+
|
|
221
|
+
No font files are distributed. polyxd.com loads its typefaces from Google Fonts
|
|
222
|
+
at request time, and a design-system pack names the typeface its system
|
|
223
|
+
specifies without shipping it — a pack that asks for Adobe Clean, for example,
|
|
224
|
+
names an open metric-compatible fallback for anyone who does not have it.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @polyxd/runtime
|
|
2
|
+
|
|
3
|
+
Generates a spec-valid Polyxd UI document for an ask, with the model you choose. It builds the prompt from the spec and your Design Direction, checks the answer, sends the problems back for repair, streams as it goes, and remembers the screen shown for each intent so the next one is recognisable. It uses `fetch` only and has no model SDK dependencies. It runs in Node, browsers and Cloudflare Workers as it is: the spec's schema checks come compiled ahead of time, so nothing needs `eval` or `new Function`.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createRuntime, anthropic, memoryStore } from "@polyxd/runtime";
|
|
7
|
+
|
|
8
|
+
const runtime = createRuntime({
|
|
9
|
+
generator: anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }), // model defaults to claude-sonnet-5
|
|
10
|
+
direction, // your direction.json
|
|
11
|
+
memory: memoryStore(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const { document, report, attempts, usage } = await runtime.generate({
|
|
15
|
+
ask: "Send £250 to Alex for the rent",
|
|
16
|
+
intent: "money.send",
|
|
17
|
+
capabilities: { "transfer.confirm": registry.capabilities["transfer.confirm"] },
|
|
18
|
+
data: { quote },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (report.valid) render(document, { data: { quote } });
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Generators
|
|
25
|
+
|
|
26
|
+
One interface, `generate({ system, messages, signal, onText })`, returning the text and token usage. Four adapters implement it. Keys are passed in by you; the runtime never reads them from anywhere and never logs them.
|
|
27
|
+
|
|
28
|
+
| Adapter | Calls | Model |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| `anthropic({ apiKey, model?, maxTokens?, temperature?, baseURL?, cache?, browser? })` | Anthropic Messages API, streaming. The system prompt is marked for prompt caching unless `cache: false` | Default `claude-sonnet-5` |
|
|
31
|
+
| `openai({ apiKey, model, api?, baseURL?, maxTokens?, temperature? })` | Chat Completions (`api: "chat"`, the default) or the Responses API (`api: "responses"`, sent with `store: false`) | Required |
|
|
32
|
+
| `gemini({ apiKey, model, baseURL?, maxTokens?, temperature? })` | Gemini API `streamGenerateContent`, asking for JSON output. The key goes in a header, not the URL | Required |
|
|
33
|
+
| `local({ model, baseURL?, apiKey?, maxTokens?, temperature? })` | Any OpenAI-compatible server. Default `http://localhost:11434/v1` (Ollama); llama.cpp is usually on port 8080, LM Studio on 1234 | Required |
|
|
34
|
+
|
|
35
|
+
Every adapter also takes `fetch` (your own, for a proxy or tests) and `headers`. A refusal or failure throws a `GeneratorError` with the provider and the HTTP status. Anything with a `name` and a `generate` method works as a generator, so your own code or a fake in tests can stand in.
|
|
36
|
+
|
|
37
|
+
## What goes in the prompt
|
|
38
|
+
|
|
39
|
+
`systemPrompt()` is built from the spec at build time: the document shape, the rules for a generated document (bind data by JSON Pointer, only the capabilities offered, destructive actions from a `Confirm`, no shell components), every surface component with its props, and the patterns. It is the same for every ask. Pass `components` to `createRuntime` to offer only the components your product allows.
|
|
40
|
+
|
|
41
|
+
`userPrompt()` holds everything about this ask:
|
|
42
|
+
|
|
43
|
+
- the ask, the intent, and a pattern when you name one;
|
|
44
|
+
- the capabilities on offer, with risk, inputs and undo;
|
|
45
|
+
- the data, and the JSON Pointers it offers;
|
|
46
|
+
- the Direction: profile, voice and rules as instructions, the preferred patterns that fit this ask, and disallowed patterns;
|
|
47
|
+
- up to two exemplars from the Direction, chosen by the words they share with the ask (`exemplars` sets how many; `resolveExemplar` turns a `document` path into the document);
|
|
48
|
+
- the screen shown last time for this intent, from memory.
|
|
49
|
+
|
|
50
|
+
The same input gives the same text. `runtime.prompt(ask)` returns exactly what the first call would send.
|
|
51
|
+
|
|
52
|
+
## Checks and repair
|
|
53
|
+
|
|
54
|
+
Each answer is parsed (code fences and prose around the JSON are tolerated) and checked:
|
|
55
|
+
|
|
56
|
+
- `checkDocument`: the verifier's document checks, `staticAudit` from `@polyxd/verifier/static`. That is the spec validator, with the Direction's `emphasisBudget` and bindings checked against your data; the declared pattern's checks; the capabilities on offer; the Direction's rules and its compiled voice; and the verifier's agent-readiness checks (distinct control names, labels that say what happens, no template placeholders, and the rest). They read no files and load no browser, so they run anywhere.
|
|
57
|
+
- Generated-only checks: never a shell (`generated:shell`), only allowed components (`generated:component`), no disallowed pattern (`direction:pattern-disallowed`).
|
|
58
|
+
|
|
59
|
+
Pass `audit` to use checks of your own instead of `checkDocument`. It gets the same options `staticAudit` takes.
|
|
60
|
+
|
|
61
|
+
If anything is an error, the model gets its answer back with the problems listed and is asked for the whole document again, up to `maxRepairs` times (default 2). `repairWarnings: true` sends warnings back too. The result is `{ document, report, attempts, usage }`. When it gives up, `report.valid` is false and `document` is the last one that parsed.
|
|
62
|
+
|
|
63
|
+
## Streaming
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
for await (const p of runtime.stream(ask)) {
|
|
67
|
+
if (p.type === "text") showTyping(p.text);
|
|
68
|
+
if (p.type === "done") show(p.result.document);
|
|
69
|
+
if (p.type === "error") showFallback(p.reason);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The order is `started`, then for each attempt its `text` pieces and an `attempt` report, then `repaired` if a repair worked, then `done` or `error`. Leaving the loop early aborts the model call. `generate(ask, { onProgress })` gives the same sequence as a callback, and `ask.signal` cancels either.
|
|
74
|
+
|
|
75
|
+
## Memory
|
|
76
|
+
|
|
77
|
+
`memoryStore()` keeps screens in memory; `storageStore(localStorage)` keeps them in `localStorage` or anything with `getItem`, `setItem` and `removeItem`. When a document passes, it is stored by intent without its data. The next ask with that intent sends it to the model as the screen to keep recognisable. Nothing leaves the client.
|
|
78
|
+
|
|
79
|
+
## Events
|
|
80
|
+
|
|
81
|
+
`onEvent` receives `started`, `text`, `attempt`, `repaired`, `done` and `error` with counts, timings, validity, token usage and check ids only. Never the ask, the data or the document. The package sends no telemetry anywhere; what you do with the events is up to you.
|
|
82
|
+
|
|
83
|
+
## Tests
|
|
84
|
+
|
|
85
|
+
`npm test -w @polyxd/runtime` runs with a fake generator and no network: prompt snapshots, the repair loop and giving up, fence stripping, streaming order, memory, event redaction, the default checks and a custom `audit`, that nothing loads the file system or Playwright, and each adapter's request and stream parsing against fixture streams written in each provider's documented format. `npm run build:catalog -w @polyxd/runtime` regenerates the spec catalog; a test fails when it is out of date.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Generator } from "../types.ts";
|
|
2
|
+
import { type HttpOptions } from "./http.ts";
|
|
3
|
+
export interface AnthropicOptions extends HttpOptions {
|
|
4
|
+
/** Your API key. Leave it out only when a proxy at `baseURL` adds it. */
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
/** Default `claude-sonnet-5`. */
|
|
7
|
+
model?: string;
|
|
8
|
+
/** Default 8192. */
|
|
9
|
+
maxTokens?: number;
|
|
10
|
+
temperature?: number;
|
|
11
|
+
/** Default `https://api.anthropic.com`. */
|
|
12
|
+
baseURL?: string;
|
|
13
|
+
/** Mark the system prompt for prompt caching, since it's the same for every ask. Default true. */
|
|
14
|
+
cache?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Send the header Anthropic requires for calls straight from a browser. Only for a key the person
|
|
17
|
+
* using the page owns; a key of yours in a page is a key anyone can read.
|
|
18
|
+
*/
|
|
19
|
+
browser?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Claude, through the Anthropic Messages API, streaming. */
|
|
22
|
+
export declare function anthropic(options?: AnthropicOptions): Generator;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { GeneratorError, json, post, serverEvents, trimSlash } from "./http.js";
|
|
2
|
+
/** Claude, through the Anthropic Messages API, streaming. */
|
|
3
|
+
export function anthropic(options = {}) {
|
|
4
|
+
const model = options.model ?? "claude-sonnet-5";
|
|
5
|
+
const url = `${trimSlash(options.baseURL ?? "https://api.anthropic.com")}/v1/messages`;
|
|
6
|
+
return {
|
|
7
|
+
name: "anthropic",
|
|
8
|
+
async generate({ system, messages, signal, onText }) {
|
|
9
|
+
const headers = { "anthropic-version": "2023-06-01" };
|
|
10
|
+
if (options.apiKey)
|
|
11
|
+
headers["x-api-key"] = options.apiKey;
|
|
12
|
+
if (options.browser)
|
|
13
|
+
headers["anthropic-dangerous-direct-browser-access"] = "true";
|
|
14
|
+
const body = {
|
|
15
|
+
model,
|
|
16
|
+
max_tokens: options.maxTokens ?? 8192,
|
|
17
|
+
system: options.cache === false ? system : [{ type: "text", text: system, cache_control: { type: "ephemeral" } }],
|
|
18
|
+
messages: messages.map((m) => ({ role: m.role, content: m.content })),
|
|
19
|
+
stream: true,
|
|
20
|
+
};
|
|
21
|
+
if (options.temperature !== undefined)
|
|
22
|
+
body.temperature = options.temperature;
|
|
23
|
+
const stream = await post("anthropic", options, url, headers, body, signal);
|
|
24
|
+
let text = "";
|
|
25
|
+
const usage = { inputTokens: 0, outputTokens: 0 };
|
|
26
|
+
for await (const e of serverEvents(stream)) {
|
|
27
|
+
const d = json("anthropic", e.data);
|
|
28
|
+
if (d.type === "message_start") {
|
|
29
|
+
const u = d.message?.usage ?? {};
|
|
30
|
+
usage.inputTokens = (u.input_tokens ?? 0) + (u.cache_creation_input_tokens ?? 0) + (u.cache_read_input_tokens ?? 0);
|
|
31
|
+
usage.outputTokens = u.output_tokens ?? 0;
|
|
32
|
+
}
|
|
33
|
+
else if (d.type === "content_block_delta" && d.delta?.type === "text_delta") {
|
|
34
|
+
text += d.delta.text;
|
|
35
|
+
onText?.(d.delta.text);
|
|
36
|
+
}
|
|
37
|
+
else if (d.type === "message_delta" && d.usage?.output_tokens !== undefined) {
|
|
38
|
+
usage.outputTokens = d.usage.output_tokens;
|
|
39
|
+
}
|
|
40
|
+
else if (d.type === "error") {
|
|
41
|
+
throw new GeneratorError("anthropic", `anthropic stopped: ${d.error?.type ?? "error"}${d.error?.message ? `: ${d.error.message}` : ""}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { text, usage };
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/adapters/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAoB,MAAM,WAAW,CAAC;AAqBlG,6DAA6D;AAC7D,MAAM,UAAU,SAAS,CAAC,OAAO,GAAqB,EAAE;IACtD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,iBAAiB,CAAC;IACjD,MAAM,GAAG,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,IAAI,2BAA2B,CAAC,cAAc,CAAC;IACvF,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE;YACjD,MAAM,OAAO,GAA2B,EAAE,mBAAmB,EAAE,YAAY,EAAE,CAAC;YAC9E,IAAI,OAAO,CAAC,MAAM;gB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export interface GeminiOptions extends HttpOptions {
|
|
4
|
+
/** Your API key, sent in a header, never in the URL. Leave it out only when a proxy at `baseURL` adds it. */
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
/** The model id. There is no default. */
|
|
7
|
+
model: string;
|
|
8
|
+
/** Default `https://generativelanguage.googleapis.com/v1beta`. */
|
|
9
|
+
baseURL?: string;
|
|
10
|
+
maxTokens?: number;
|
|
11
|
+
temperature?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Google Gemini, through the Gemini API's `streamGenerateContent`, asking for JSON output. */
|
|
14
|
+
export declare function gemini(options: GeminiOptions): Generator;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { GeneratorError, json, post, serverEvents, trimSlash } from "./http.js";
|
|
2
|
+
/** Google Gemini, through the Gemini API's `streamGenerateContent`, asking for JSON output. */
|
|
3
|
+
export function gemini(options) {
|
|
4
|
+
const base = trimSlash(options.baseURL ?? "https://generativelanguage.googleapis.com/v1beta");
|
|
5
|
+
const model = options.model.replace(/^models\//, "");
|
|
6
|
+
const url = `${base}/models/${encodeURIComponent(model)}:streamGenerateContent?alt=sse`;
|
|
7
|
+
return {
|
|
8
|
+
name: "gemini",
|
|
9
|
+
async generate({ system, messages, signal, onText }) {
|
|
10
|
+
const headers = options.apiKey ? { "x-goog-api-key": options.apiKey } : {};
|
|
11
|
+
const generationConfig = { responseMimeType: "application/json" };
|
|
12
|
+
if (options.maxTokens !== undefined)
|
|
13
|
+
generationConfig.maxOutputTokens = options.maxTokens;
|
|
14
|
+
if (options.temperature !== undefined)
|
|
15
|
+
generationConfig.temperature = options.temperature;
|
|
16
|
+
const body = {
|
|
17
|
+
systemInstruction: { parts: [{ text: system }] },
|
|
18
|
+
contents: messages.map((m) => ({ role: m.role === "assistant" ? "model" : "user", parts: [{ text: m.content }] })),
|
|
19
|
+
generationConfig,
|
|
20
|
+
};
|
|
21
|
+
const stream = await post("gemini", options, url, headers, body, signal);
|
|
22
|
+
let text = "";
|
|
23
|
+
let usage;
|
|
24
|
+
for await (const e of serverEvents(stream)) {
|
|
25
|
+
const d = json("gemini", e.data);
|
|
26
|
+
if (d.error)
|
|
27
|
+
throw new GeneratorError("gemini", `gemini stopped: ${d.error.message ?? "error"}`, d.error.code);
|
|
28
|
+
for (const part of d.candidates?.[0]?.content?.parts ?? []) {
|
|
29
|
+
if (part.thought || typeof part.text !== "string" || !part.text)
|
|
30
|
+
continue;
|
|
31
|
+
text += part.text;
|
|
32
|
+
onText?.(part.text);
|
|
33
|
+
}
|
|
34
|
+
const u = d.usageMetadata;
|
|
35
|
+
if (u)
|
|
36
|
+
usage = { inputTokens: u.promptTokenCount ?? 0, outputTokens: u.candidatesTokenCount ?? 0 };
|
|
37
|
+
}
|
|
38
|
+
return { text, usage };
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=gemini.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../src/adapters/gemini.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAoB,MAAM,WAAW,CAAC;AAalG,+FAA+F;AAC/F,MAAM,UAAU,MAAM,CAAC,OAAsB;IAC3C,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,IAAI,kDAAkD,CAAC,CAAC;IAC9F,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,GAAG,IAAI,WAAW,kBAAkB,CAAC,KAAK,CAAC,gCAAgC,CAAC;IACxF,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE;YACjD,MAAM,OAAO,GAA2B,OAAO,CAAC,MAAM,CAAC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