@mano8/astro-prompt-m8 0.1.0-alpha.1

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.
Files changed (163) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +116 -0
  3. package/dist/src/integration.d.ts +42 -0
  4. package/dist/src/integration.d.ts.map +1 -0
  5. package/dist/src/integration.js +86 -0
  6. package/dist/src/integration.js.map +1 -0
  7. package/dist/src/lib/csp.d.ts +25 -0
  8. package/dist/src/lib/csp.d.ts.map +1 -0
  9. package/dist/src/lib/csp.js +53 -0
  10. package/dist/src/lib/csp.js.map +1 -0
  11. package/dist/src/middleware.d.ts +4 -0
  12. package/dist/src/middleware.d.ts.map +1 -0
  13. package/dist/src/middleware.js +24 -0
  14. package/dist/src/middleware.js.map +1 -0
  15. package/dist/src/runtime/api/admin.d.ts +15 -0
  16. package/dist/src/runtime/api/admin.d.ts.map +1 -0
  17. package/dist/src/runtime/api/admin.js +39 -0
  18. package/dist/src/runtime/api/admin.js.map +1 -0
  19. package/dist/src/runtime/api/blocks.d.ts +24 -0
  20. package/dist/src/runtime/api/blocks.d.ts.map +1 -0
  21. package/dist/src/runtime/api/blocks.js +74 -0
  22. package/dist/src/runtime/api/blocks.js.map +1 -0
  23. package/dist/src/runtime/api/categories.d.ts +7 -0
  24. package/dist/src/runtime/api/categories.d.ts.map +1 -0
  25. package/dist/src/runtime/api/categories.js +49 -0
  26. package/dist/src/runtime/api/categories.js.map +1 -0
  27. package/dist/src/runtime/api/dashboard.d.ts +6 -0
  28. package/dist/src/runtime/api/dashboard.d.ts.map +1 -0
  29. package/dist/src/runtime/api/dashboard.js +21 -0
  30. package/dist/src/runtime/api/dashboard.js.map +1 -0
  31. package/dist/src/runtime/api/index.d.ts +46 -0
  32. package/dist/src/runtime/api/index.d.ts.map +1 -0
  33. package/dist/src/runtime/api/index.js +48 -0
  34. package/dist/src/runtime/api/index.js.map +1 -0
  35. package/dist/src/runtime/api/internal.server.d.ts +18 -0
  36. package/dist/src/runtime/api/internal.server.d.ts.map +1 -0
  37. package/dist/src/runtime/api/internal.server.js +43 -0
  38. package/dist/src/runtime/api/internal.server.js.map +1 -0
  39. package/dist/src/runtime/api/templates.d.ts +14 -0
  40. package/dist/src/runtime/api/templates.d.ts.map +1 -0
  41. package/dist/src/runtime/api/templates.js +108 -0
  42. package/dist/src/runtime/api/templates.js.map +1 -0
  43. package/dist/src/runtime/authAdapter.d.ts +48 -0
  44. package/dist/src/runtime/authAdapter.d.ts.map +1 -0
  45. package/dist/src/runtime/authAdapter.js +62 -0
  46. package/dist/src/runtime/authAdapter.js.map +1 -0
  47. package/dist/src/runtime/client.d.ts +24 -0
  48. package/dist/src/runtime/client.d.ts.map +1 -0
  49. package/dist/src/runtime/client.js +85 -0
  50. package/dist/src/runtime/client.js.map +1 -0
  51. package/dist/src/runtime/compatibility.d.ts +32 -0
  52. package/dist/src/runtime/compatibility.d.ts.map +1 -0
  53. package/dist/src/runtime/compatibility.js +97 -0
  54. package/dist/src/runtime/compatibility.js.map +1 -0
  55. package/dist/src/runtime/config.d.ts +16 -0
  56. package/dist/src/runtime/config.d.ts.map +1 -0
  57. package/dist/src/runtime/config.js +22 -0
  58. package/dist/src/runtime/config.js.map +1 -0
  59. package/dist/src/runtime/errors.d.ts +23 -0
  60. package/dist/src/runtime/errors.d.ts.map +1 -0
  61. package/dist/src/runtime/errors.js +50 -0
  62. package/dist/src/runtime/errors.js.map +1 -0
  63. package/dist/src/runtime/hooks/index.d.ts +9 -0
  64. package/dist/src/runtime/hooks/index.d.ts.map +1 -0
  65. package/dist/src/runtime/hooks/index.js +9 -0
  66. package/dist/src/runtime/hooks/index.js.map +1 -0
  67. package/dist/src/runtime/hooks/useComposePrompt.d.ts +13 -0
  68. package/dist/src/runtime/hooks/useComposePrompt.d.ts.map +1 -0
  69. package/dist/src/runtime/hooks/useComposePrompt.js +17 -0
  70. package/dist/src/runtime/hooks/useComposePrompt.js.map +1 -0
  71. package/dist/src/runtime/hooks/usePromptAdmin.d.ts +10 -0
  72. package/dist/src/runtime/hooks/usePromptAdmin.d.ts.map +1 -0
  73. package/dist/src/runtime/hooks/usePromptAdmin.js +33 -0
  74. package/dist/src/runtime/hooks/usePromptAdmin.js.map +1 -0
  75. package/dist/src/runtime/hooks/usePromptBlock.d.ts +18 -0
  76. package/dist/src/runtime/hooks/usePromptBlock.d.ts.map +1 -0
  77. package/dist/src/runtime/hooks/usePromptBlock.js +25 -0
  78. package/dist/src/runtime/hooks/usePromptBlock.js.map +1 -0
  79. package/dist/src/runtime/hooks/usePromptBlocks.d.ts +22 -0
  80. package/dist/src/runtime/hooks/usePromptBlocks.d.ts.map +1 -0
  81. package/dist/src/runtime/hooks/usePromptBlocks.js +53 -0
  82. package/dist/src/runtime/hooks/usePromptBlocks.js.map +1 -0
  83. package/dist/src/runtime/hooks/usePromptCategories.d.ts +20 -0
  84. package/dist/src/runtime/hooks/usePromptCategories.d.ts.map +1 -0
  85. package/dist/src/runtime/hooks/usePromptCategories.js +53 -0
  86. package/dist/src/runtime/hooks/usePromptCategories.js.map +1 -0
  87. package/dist/src/runtime/hooks/usePromptDashboard.d.ts +13 -0
  88. package/dist/src/runtime/hooks/usePromptDashboard.d.ts.map +1 -0
  89. package/dist/src/runtime/hooks/usePromptDashboard.js +11 -0
  90. package/dist/src/runtime/hooks/usePromptDashboard.js.map +1 -0
  91. package/dist/src/runtime/hooks/usePromptTemplate.d.ts +33 -0
  92. package/dist/src/runtime/hooks/usePromptTemplate.d.ts.map +1 -0
  93. package/dist/src/runtime/hooks/usePromptTemplate.js +43 -0
  94. package/dist/src/runtime/hooks/usePromptTemplate.js.map +1 -0
  95. package/dist/src/runtime/hooks/usePromptTemplates.d.ts +37 -0
  96. package/dist/src/runtime/hooks/usePromptTemplates.d.ts.map +1 -0
  97. package/dist/src/runtime/hooks/usePromptTemplates.js +106 -0
  98. package/dist/src/runtime/hooks/usePromptTemplates.js.map +1 -0
  99. package/dist/src/runtime/listParams.d.ts +27 -0
  100. package/dist/src/runtime/listParams.d.ts.map +1 -0
  101. package/dist/src/runtime/listParams.js +67 -0
  102. package/dist/src/runtime/listParams.js.map +1 -0
  103. package/dist/src/runtime/queryKeys.d.ts +25 -0
  104. package/dist/src/runtime/queryKeys.d.ts.map +1 -0
  105. package/dist/src/runtime/queryKeys.js +29 -0
  106. package/dist/src/runtime/queryKeys.js.map +1 -0
  107. package/dist/src/runtime/react/AdminPromptPanel.d.ts +21 -0
  108. package/dist/src/runtime/react/AdminPromptPanel.d.ts.map +1 -0
  109. package/dist/src/runtime/react/AdminPromptPanel.js +53 -0
  110. package/dist/src/runtime/react/AdminPromptPanel.js.map +1 -0
  111. package/dist/src/runtime/react/PromptBlockLibrary.d.ts +36 -0
  112. package/dist/src/runtime/react/PromptBlockLibrary.d.ts.map +1 -0
  113. package/dist/src/runtime/react/PromptBlockLibrary.js +122 -0
  114. package/dist/src/runtime/react/PromptBlockLibrary.js.map +1 -0
  115. package/dist/src/runtime/react/PromptComposer.d.ts +24 -0
  116. package/dist/src/runtime/react/PromptComposer.d.ts.map +1 -0
  117. package/dist/src/runtime/react/PromptComposer.js +48 -0
  118. package/dist/src/runtime/react/PromptComposer.js.map +1 -0
  119. package/dist/src/runtime/react/PromptProvider.d.ts +16 -0
  120. package/dist/src/runtime/react/PromptProvider.d.ts.map +1 -0
  121. package/dist/src/runtime/react/PromptProvider.js +79 -0
  122. package/dist/src/runtime/react/PromptProvider.js.map +1 -0
  123. package/dist/src/runtime/react/PromptQueryProvider.d.ts +8 -0
  124. package/dist/src/runtime/react/PromptQueryProvider.d.ts.map +1 -0
  125. package/dist/src/runtime/react/PromptQueryProvider.js +11 -0
  126. package/dist/src/runtime/react/PromptQueryProvider.js.map +1 -0
  127. package/dist/src/runtime/react/PromptTemplateEditor.d.ts +36 -0
  128. package/dist/src/runtime/react/PromptTemplateEditor.d.ts.map +1 -0
  129. package/dist/src/runtime/react/PromptTemplateEditor.js +141 -0
  130. package/dist/src/runtime/react/PromptTemplateEditor.js.map +1 -0
  131. package/dist/src/runtime/react/RequireSuperuser.d.ts +7 -0
  132. package/dist/src/runtime/react/RequireSuperuser.d.ts.map +1 -0
  133. package/dist/src/runtime/react/RequireSuperuser.js +10 -0
  134. package/dist/src/runtime/react/RequireSuperuser.js.map +1 -0
  135. package/dist/src/runtime/react/default-ui/index.d.ts +17 -0
  136. package/dist/src/runtime/react/default-ui/index.d.ts.map +1 -0
  137. package/dist/src/runtime/react/default-ui/index.js +23 -0
  138. package/dist/src/runtime/react/default-ui/index.js.map +1 -0
  139. package/dist/src/runtime/react/index.d.ts +8 -0
  140. package/dist/src/runtime/react/index.d.ts.map +1 -0
  141. package/dist/src/runtime/react/index.js +8 -0
  142. package/dist/src/runtime/react/index.js.map +1 -0
  143. package/dist/src/runtime/routes.d.ts +17 -0
  144. package/dist/src/runtime/routes.d.ts.map +1 -0
  145. package/dist/src/runtime/routes.js +33 -0
  146. package/dist/src/runtime/routes.js.map +1 -0
  147. package/dist/src/runtime/schemas.d.ts +286 -0
  148. package/dist/src/runtime/schemas.d.ts.map +1 -0
  149. package/dist/src/runtime/schemas.js +172 -0
  150. package/dist/src/runtime/schemas.js.map +1 -0
  151. package/package.json +99 -0
  152. package/registry/r/admin-prompt-dashboard.json +23 -0
  153. package/registry/r/prompt-block-editor.json +20 -0
  154. package/registry/r/prompt-dashboard-overview.json +22 -0
  155. package/registry/r/prompt-maintenance-panel.json +23 -0
  156. package/registry/r/prompt-template-editor.json +20 -0
  157. package/registry/r/registry.json +37 -0
  158. package/registry.json +86 -0
  159. package/src/routes/admin/prompts.astro +11 -0
  160. package/src/routes/blocks.astro +11 -0
  161. package/src/routes/composer.astro +12 -0
  162. package/src/routes/templates.astro +11 -0
  163. package/src/scaffold/styles/prompt.css +9 -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 [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.
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # @mano8/astro-prompt-m8
2
+
3
+ Astro integration and headless client for [`prompt-engine-m8`]. The prompt-side
4
+ analog of `@mano8/astro-media-m8`: typed Zod schemas, API wrappers for the full
5
+ prompt contract, a compose helper, optional React provider/hooks, and injectable
6
+ starter routes — so any Astro stack can drive prompt blocks/templates/composition
7
+ without re-implementing the contract.
8
+
9
+ Pinned to `prompt-engine-m8@0.0` (supported service-version range
10
+ `>=0.0.1 <0.1.0`; see `promptEngineM8` in `package.json`).
11
+
12
+ ## Backend contract
13
+
14
+ This package targets the `prompt-engine-m8@0.0` API contract and was tested
15
+ against `prompt-engine-m8` service version `0.0.1`. Supported backend service
16
+ versions are `>=0.0.1 <0.1.0`.
17
+
18
+ Compatibility helpers are exported from `@mano8/astro-prompt-m8/compatibility`.
19
+ Pass the backend `/meta` payload (or flat version fields) straight to the assert:
20
+
21
+ ```ts
22
+ import { assertPromptEngineM8Compatibility } from "@mano8/astro-prompt-m8/compatibility";
23
+
24
+ const meta = await fetch(`${base}/prompt/meta`).then((r) => r.json());
25
+ assertPromptEngineM8Compatibility(meta);
26
+ ```
27
+
28
+ The helper also accepts flat fields (`prompt_contract_version` /
29
+ `contract_version` / `service_version`) for backends that surface metadata
30
+ elsewhere.
31
+
32
+ ## Install
33
+
34
+ ```sh
35
+ npm i @mano8/astro-prompt-m8 @mano8/astro-auth-m8 zod
36
+ ```
37
+
38
+ `@mano8/astro-auth-m8` is a required peer: `prompt-engine-m8` only accepts
39
+ `fa-auth-m8`-issued tokens, so the plugin's auth adapter must be backed by
40
+ `fa-auth-m8` (the official plugin, or a custom adapter that obtains those
41
+ tokens). `react`/`react-dom` are optional — only `./react`, `./hooks` and the
42
+ starter views need them.
43
+
44
+ ## Modes
45
+
46
+ - **headless** — schemas, API wrappers, compose helper, stores; no pages.
47
+ - **starter** — injects blocks / templates / composer / admin routes.
48
+ - **scaffolded** — `views.strategy: "scaffolded"` to own the view files.
49
+
50
+ ## Quick start
51
+
52
+ ```ts
53
+ // astro.config.mjs
54
+ import { defineConfig } from "astro/config";
55
+ import react from "@astrojs/react";
56
+ import faAuth from "@mano8/astro-auth-m8";
57
+ import faPrompt from "@mano8/astro-prompt-m8";
58
+
59
+ export default defineConfig({
60
+ integrations: [
61
+ react(),
62
+ faAuth({ apiBase: "/user" }), // list auth BEFORE prompt
63
+ faPrompt({ apiBase: "/prompt", apiPrefix: "/fastapi", mode: "starter" })
64
+ ]
65
+ });
66
+ ```
67
+
68
+ Wire the auth adapter once (browser entry / provider):
69
+
70
+ ```ts
71
+ import { getToken } from "@mano8/astro-auth-m8/client";
72
+ import { refreshToken } from "@mano8/astro-auth-m8/api";
73
+ import {
74
+ createFaAuthAdapter,
75
+ setPromptAuthAdapter
76
+ } from "@mano8/astro-prompt-m8/auth-adapter";
77
+
78
+ setPromptAuthAdapter(createFaAuthAdapter({ getToken, refreshToken }));
79
+ ```
80
+
81
+ ## Headless usage
82
+
83
+ ```ts
84
+ import { blocks, templates } from "@mano8/astro-prompt-m8/api";
85
+
86
+ const list = await blocks.list({ skip: 0, limit: 50 });
87
+ const composed = await templates.compose(1, [{ id: 2, content: "Be terse." }]);
88
+ ```
89
+
90
+ ## Security model
91
+
92
+ - Access tokens are delegated to the auth adapter and **never persisted** here.
93
+ - Service tokens are server-only: `@mano8/astro-prompt-m8/internal-server` throws
94
+ if imported in the browser and is excluded from the client `api` barrel.
95
+ - Admin calls are gated client-side (`ForbiddenError`) before the request when
96
+ the adapter already knows the user is not a superuser.
97
+ - Every response body is parsed through Zod; `204` responses skip parsing.
98
+ - Request URLs are protocol-pinned to http(s).
99
+
100
+ ## Content Security Policy
101
+
102
+ When `guards.middleware` is enabled, the integration injects a
103
+ `Content-Security-Policy` header on every response. The `connect-src` directive
104
+ covers `'self'` and the prompt API origin (when `apiBase` is an absolute URL).
105
+ Pass additional service origins in `csp.serviceOrigin` / `csp.connectExtraOrigins`.
106
+
107
+ ## Contract surface
108
+
109
+ The plugin exports explicit subpaths (`./api`, `./client`, `./schemas`,
110
+ `./auth-adapter`, `./hooks`, `./react`, `./default-ui`, `./routes`,
111
+ `./list-params`, `./compatibility`, `./middleware`, `./internal-server`). See
112
+ `package.json` for the exact list.
113
+
114
+ ## License
115
+
116
+ MIT
@@ -0,0 +1,42 @@
1
+ import type { AstroIntegration } from "astro";
2
+ import { type PromptRouteFragments } from "./runtime/routes.js";
3
+ import { type PromptCspOptions } from "./lib/csp.js";
4
+ export type FaPromptAstroOptions = {
5
+ /** Browser-facing base of the prompt-engine-m8 service. Defaults to `/prompt`. */
6
+ apiBase?: string;
7
+ /** FastAPI prefix on the service contract. Defaults to `/fastapi`. */
8
+ apiPrefix?: string;
9
+ mode?: "headless" | "starter";
10
+ output?: "static" | "server" | "hybrid";
11
+ locales?: string[];
12
+ defaultLocale?: string;
13
+ auth?: {
14
+ provider?: "fa-auth-astro" | "custom" | "none";
15
+ adapterImport?: string;
16
+ requireAuth?: boolean;
17
+ adminRole?: "superadmin" | "admin" | "is_superuser";
18
+ };
19
+ routes?: PromptRouteFragments;
20
+ views?: {
21
+ strategy?: "none" | "package" | "scaffolded";
22
+ layout?: "plain" | "starlight" | "custom";
23
+ customLayoutImport?: string;
24
+ componentsImport?: string;
25
+ i18nImport?: string;
26
+ };
27
+ admin?: {
28
+ enabled?: boolean;
29
+ };
30
+ guards?: {
31
+ middleware?: boolean;
32
+ };
33
+ /** CSP header support for server/hybrid output modes. Enabled by default when the middleware is active. */
34
+ csp?: {
35
+ /** Set to false to disable CSP header injection even when the middleware is active. Default: true. */
36
+ enabled?: boolean;
37
+ } & PromptCspOptions;
38
+ };
39
+ export default function faPrompt(options?: FaPromptAstroOptions): AstroIntegration;
40
+ export { buildPromptRoutes } from "./runtime/routes.js";
41
+ export type { PromptRouteFragments, BuiltPromptRoutes } from "./runtime/routes.js";
42
+ //# sourceMappingURL=integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../src/integration.ts"],"names":[],"mappings":"AAAA,OAA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tG,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,GAAG,gBAAgB,CAAC;CACtB,CAAC;AA+BF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,OAAO,GAAE,oBAAyB,GAAG,gBAAgB,CAqErF;AAED,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,86 @@
1
+ import { buildPromptRoutes } from "./runtime/routes.js";
2
+ import { buildPromptCspPolicy } from "./lib/csp.js";
3
+ const ROUTE_ENTRYPOINTS = {
4
+ blocks: "@mano8/astro-prompt-m8/routes/blocks.astro",
5
+ templates: "@mano8/astro-prompt-m8/routes/templates.astro",
6
+ composer: "@mano8/astro-prompt-m8/routes/composer.astro",
7
+ admin: "@mano8/astro-prompt-m8/routes/admin/prompts.astro"
8
+ };
9
+ const AUTH_INTEGRATION_NAME = "@mano8/astro-auth-m8";
10
+ /**
11
+ * Warn when the official auth plugin is not registered before this one — order
12
+ * matters because the prompt adapter resolves the auth runtime at module load.
13
+ */
14
+ function checkAuthOrder(integrations, logger) {
15
+ const names = (integrations ?? []).map((entry) => entry?.name);
16
+ const authIndex = names.indexOf(AUTH_INTEGRATION_NAME);
17
+ const promptIndex = names.indexOf("@mano8/astro-prompt-m8");
18
+ if (authIndex === -1) {
19
+ logger?.warn(`auth.provider is "fa-auth-astro" but ${AUTH_INTEGRATION_NAME} is not in the integrations list`);
20
+ }
21
+ else if (promptIndex !== -1 && authIndex > promptIndex) {
22
+ logger?.warn(`${AUTH_INTEGRATION_NAME} should be listed before @mano8/astro-prompt-m8`);
23
+ }
24
+ }
25
+ export default function faPrompt(options = {}) {
26
+ const mode = options.mode ?? "headless";
27
+ const provider = options.auth?.provider ?? "fa-auth-astro";
28
+ const routes = buildPromptRoutes(options.routes);
29
+ const apiBase = options.apiBase ?? "/prompt";
30
+ const apiPrefix = options.apiPrefix ?? "/fastapi";
31
+ const cspEnabled = options.csp?.enabled !== false;
32
+ const middlewareActive = options.guards?.middleware === true;
33
+ const cspPolicy = cspEnabled && middlewareActive
34
+ ? buildPromptCspPolicy(apiBase, {
35
+ serviceOrigin: options.csp?.serviceOrigin,
36
+ connectExtraOrigins: options.csp?.connectExtraOrigins
37
+ })
38
+ : "";
39
+ return {
40
+ name: "@mano8/astro-prompt-m8",
41
+ hooks: {
42
+ "astro:config:setup": ({ injectRoute, addMiddleware, updateConfig, config, logger }) => {
43
+ updateConfig({
44
+ vite: {
45
+ define: {
46
+ "import.meta.env.PUBLIC_FA_PROMPT_API_BASE": JSON.stringify(apiBase),
47
+ "import.meta.env.PUBLIC_FA_PROMPT_API_PREFIX": JSON.stringify(apiPrefix),
48
+ "import.meta.env.PUBLIC_FA_PROMPT_ADMIN_ROLE": JSON.stringify(options.auth?.adminRole ?? "is_superuser"),
49
+ "import.meta.env.PUBLIC_FA_PROMPT_CSP_POLICY": JSON.stringify(cspPolicy)
50
+ }
51
+ }
52
+ });
53
+ // prompt-engine-m8 only accepts fa-auth-m8-issued tokens, so the auth
54
+ // adapter must be backed by fa-auth-m8 (official astro-auth-m8 plugin,
55
+ // or a custom adapter that obtains fa-auth-m8 tokens).
56
+ if (provider === "fa-auth-astro") {
57
+ checkAuthOrder(config?.integrations, logger);
58
+ }
59
+ else if (provider === "custom" && !options.auth?.adapterImport) {
60
+ logger?.warn("auth.provider is \"custom\" but no auth.adapterImport was given; configure a fa-auth-m8-compatible PromptAuthAdapter via setPromptAuthAdapter()");
61
+ }
62
+ const starter = mode === "starter" && (options.views?.strategy ?? "package") !== "none";
63
+ if (starter && provider === "none") {
64
+ logger?.warn("prompt starter routes are enabled but auth.provider is \"none\"; prompt-engine-m8 requires fa-auth-m8 authentication");
65
+ }
66
+ if (starter) {
67
+ for (const [name, pattern] of Object.entries(routes)) {
68
+ if (!pattern)
69
+ continue;
70
+ if (name === "admin" && options.admin?.enabled === false)
71
+ continue;
72
+ injectRoute({
73
+ pattern,
74
+ entrypoint: ROUTE_ENTRYPOINTS[name]
75
+ });
76
+ }
77
+ }
78
+ if (options.guards?.middleware) {
79
+ addMiddleware({ order: "pre", entrypoint: "@mano8/astro-prompt-m8/middleware" });
80
+ }
81
+ }
82
+ }
83
+ };
84
+ }
85
+ export { buildPromptRoutes } from "./runtime/routes.js";
86
+ //# sourceMappingURL=integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.js","sourceRoot":"","sources":["../../src/integration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAA6B,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAyB,MAAM,cAAc,CAAC;AAsC3E,MAAM,iBAAiB,GAAG;IACxB,MAAM,EAAE,4CAA4C;IACpD,SAAS,EAAE,+CAA+C;IAC1D,QAAQ,EAAE,8CAA8C;IACxD,KAAK,EAAE,mDAAmD;CAClD,CAAC;AAEX,MAAM,qBAAqB,GAAG,sBAAsB,CAAC;AAErD;;;GAGG;AACH,SAAS,cAAc,CACrB,YAA6C,EAC7C,MAAsC;IAEtC,MAAM,KAAK,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACvD,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC5D,IAAI,SAAS,KAAK,CAAC,CAAC,EAAE,CAAC;QACrB,MAAM,EAAE,IAAI,CACV,wCAAwC,qBAAqB,kCAAkC,CAChG,CAAC;IACJ,CAAC;SAAM,IAAI,WAAW,KAAK,CAAC,CAAC,IAAI,SAAS,GAAG,WAAW,EAAE,CAAC;QACzD,MAAM,EAAE,IAAI,CAAC,GAAG,qBAAqB,iDAAiD,CAAC,CAAC;IAC1F,CAAC;AAC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,qBAAqB,CAAC"}
@@ -0,0 +1,25 @@
1
+ export type PromptCspOptions = {
2
+ /**
3
+ * Public origin of the prompt-engine-m8 service when configured behind an
4
+ * absolute URL (e.g. `"https://prompt.example.com"`).
5
+ * Ignored when empty or not a valid absolute URL.
6
+ */
7
+ serviceOrigin?: string;
8
+ connectExtraOrigins?: string[];
9
+ };
10
+ /** Extracts the origin (scheme + host + port) from an absolute URL; returns null for relative paths. */
11
+ export declare function originOf(url: string): string | null;
12
+ /**
13
+ * Builds the `connect-src` directive value for the prompt service and any extra origins.
14
+ * Relative `apiBase` values (e.g. `/prompt`) add nothing beyond `'self'`.
15
+ */
16
+ export declare function buildPromptConnectSrc(apiBase: string, extraOrigins?: string[]): string;
17
+ /**
18
+ * Builds a Content-Security-Policy header value for prompt integration routes.
19
+ *
20
+ * Scripts are strict (`'self'` only, no `'unsafe-inline'`).
21
+ * Styles allow `'unsafe-inline'` because React/Radix set inline styles that cannot be hashed.
22
+ * The `connect-src` directive includes the prompt API origin when `apiBase` is an absolute URL.
23
+ */
24
+ export declare function buildPromptCspPolicy(apiBase: string, options?: PromptCspOptions): string;
25
+ //# sourceMappingURL=csp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csp.d.ts","sourceRoot":"","sources":["../../../src/lib/csp.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC,CAAC;AAEF,wGAAwG;AACxG,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMnD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,GAAE,MAAM,EAAO,GAAG,MAAM,CAS1F;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAmB5F"}
@@ -0,0 +1,53 @@
1
+ /** Extracts the origin (scheme + host + port) from an absolute URL; returns null for relative paths. */
2
+ export function originOf(url) {
3
+ try {
4
+ return new URL(url).origin;
5
+ }
6
+ catch {
7
+ return null;
8
+ }
9
+ }
10
+ /**
11
+ * Builds the `connect-src` directive value for the prompt service and any extra origins.
12
+ * Relative `apiBase` values (e.g. `/prompt`) add nothing beyond `'self'`.
13
+ */
14
+ export function buildPromptConnectSrc(apiBase, extraOrigins = []) {
15
+ const origins = new Set(["'self'"]);
16
+ const promptOrigin = originOf(apiBase);
17
+ if (promptOrigin)
18
+ origins.add(promptOrigin);
19
+ for (const o of extraOrigins) {
20
+ const origin = originOf(o);
21
+ if (origin)
22
+ origins.add(origin);
23
+ }
24
+ return [...origins].join(" ");
25
+ }
26
+ /**
27
+ * Builds a Content-Security-Policy header value for prompt integration routes.
28
+ *
29
+ * Scripts are strict (`'self'` only, no `'unsafe-inline'`).
30
+ * Styles allow `'unsafe-inline'` because React/Radix set inline styles that cannot be hashed.
31
+ * The `connect-src` directive includes the prompt API origin when `apiBase` is an absolute URL.
32
+ */
33
+ export function buildPromptCspPolicy(apiBase, options = {}) {
34
+ const extraOrigins = [
35
+ ...(options.serviceOrigin ? [options.serviceOrigin] : []),
36
+ ...(options.connectExtraOrigins ?? [])
37
+ ];
38
+ const connectSrc = buildPromptConnectSrc(apiBase, extraOrigins);
39
+ const directives = [
40
+ ["default-src", "'self'"],
41
+ ["script-src", "'self'"],
42
+ ["style-src", "'self' 'unsafe-inline'"],
43
+ ["img-src", "'self' data: blob: https:"],
44
+ ["font-src", "'self' data:"],
45
+ ["connect-src", connectSrc],
46
+ ["form-action", "'self'"],
47
+ ["frame-ancestors", "'none'"],
48
+ ["base-uri", "'self'"],
49
+ ["object-src", "'none'"]
50
+ ];
51
+ return directives.map(([k, v]) => `${k} ${v}`).join("; ");
52
+ }
53
+ //# sourceMappingURL=csp.js.map
@@ -0,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,CAAC,YAAY,EAAE,QAAQ,CAAC;QACxB,CAAC,WAAW,EAAE,wBAAwB,CAAC;QACvC,CAAC,SAAS,EAAE,2BAA2B,CAAC;QACxC,CAAC,UAAU,EAAE,cAAc,CAAC;QAC5B,CAAC,aAAa,EAAE,UAAU,CAAC;QAC3B,CAAC,aAAa,EAAE,QAAQ,CAAC;QACzB,CAAC,iBAAiB,EAAE,QAAQ,CAAC;QAC7B,CAAC,UAAU,EAAE,QAAQ,CAAC;QACtB,CAAC,YAAY,EAAE,QAAQ,CAAC;KACzB,CAAC;IACF,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,4 @@
1
+ type MiddlewareNext = () => Promise<Response> | Response;
2
+ export declare function onRequest(_context: unknown, next: MiddlewareNext): Promise<Response> | Response;
3
+ export {};
4
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AAczD,wBAAgB,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAW/F"}
@@ -0,0 +1,24 @@
1
+ function withCsp(response, policy) {
2
+ const headers = new Headers(response.headers);
3
+ if (!headers.has("Content-Security-Policy")) {
4
+ headers.set("Content-Security-Policy", policy);
5
+ }
6
+ return new Response(response.body, {
7
+ status: response.status,
8
+ statusText: response.statusText,
9
+ headers
10
+ });
11
+ }
12
+ export function onRequest(_context, next) {
13
+ // Policy is injected by vite.define in the integration setup; read as a runtime env var in tests.
14
+ const policy = import.meta.env.PUBLIC_FA_PROMPT_CSP_POLICY;
15
+ if (!policy) {
16
+ return next();
17
+ }
18
+ const result = next();
19
+ if (result instanceof Promise) {
20
+ return result.then((r) => withCsp(r, policy));
21
+ }
22
+ return withCsp(result, policy);
23
+ }
24
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAEA,SAAS,OAAO,CAAC,QAAkB,EAAE,MAAc;IACjD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;QACjC,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,QAAiB,EAAE,IAAoB;IAC/D,kGAAkG;IAClG,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC;IAC3D,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC;IACtB,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { type CategoriesPublic, type PromptBlocksPublic, type PromptTemplatesPublic, type UsersActivity } from "../schemas.js";
2
+ /**
3
+ * Aggregate admin overview: block/template/category counters + activity. The
4
+ * prompt-engine-m8 service has no purge/repair surface (unlike media-service-m8),
5
+ * so the admin side is read-only here; destructive creates/edits stay on the
6
+ * per-resource views behind confirmation panels.
7
+ */
8
+ export type PromptAdminOverview = {
9
+ blocks: PromptBlocksPublic;
10
+ templates: PromptTemplatesPublic;
11
+ categories: CategoriesPublic | null;
12
+ activity: UsersActivity;
13
+ };
14
+ export declare function getAdminOverview(): Promise<PromptAdminOverview>;
15
+ //# sourceMappingURL=admin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../../../src/runtime/api/admin.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAEvB;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,SAAS,EAAE,qBAAqB,CAAC;IACjC,UAAU,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACpC,QAAQ,EAAE,aAAa,CAAC;CACzB,CAAC;AAEF,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAmCrE"}
@@ -0,0 +1,39 @@
1
+ import { request } from "../client.js";
2
+ import { CategoriesPublicSchema, PromptBlocksPublicSchema, PromptTemplatesPublicSchema, UsersActivitySchema } from "../schemas.js";
3
+ export async function getAdminOverview() {
4
+ const [blocks, templates, categories, activity] = await Promise.all([
5
+ request({
6
+ method: "GET",
7
+ path: "/prompt-block/",
8
+ query: { skip: 0, limit: 100 },
9
+ schema: PromptBlocksPublicSchema,
10
+ auth: true,
11
+ admin: true
12
+ }),
13
+ request({
14
+ method: "GET",
15
+ path: "/prompt-template/",
16
+ query: { skip: 0, limit: 100 },
17
+ schema: PromptTemplatesPublicSchema,
18
+ auth: true,
19
+ admin: true
20
+ }),
21
+ request({
22
+ method: "GET",
23
+ path: "/category/",
24
+ query: { skip: 0, limit: 100 },
25
+ schema: CategoriesPublicSchema.nullable(),
26
+ auth: true,
27
+ admin: true
28
+ }),
29
+ request({
30
+ method: "GET",
31
+ path: "/dashboard/users/activity/",
32
+ schema: UsersActivitySchema,
33
+ auth: true,
34
+ admin: true
35
+ })
36
+ ]);
37
+ return { blocks, templates, categories, activity };
38
+ }
39
+ //# sourceMappingURL=admin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.js","sourceRoot":"","sources":["../../../../src/runtime/api/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,2BAA2B,EAC3B,mBAAmB,EAKpB,MAAM,eAAe,CAAC;AAevB,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAClE,OAAO,CAAC;YACN,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,gBAAgB;YACtB,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE;YAC9B,MAAM,EAAE,wBAAwB;YAChC,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,IAAI;SACZ,CAAC;QACF,OAAO,CAAC;YACN,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,mBAAmB;YACzB,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE;YAC9B,MAAM,EAAE,2BAA2B;YACnC,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,IAAI;SACZ,CAAC;QACF,OAAO,CAAC;YACN,MAAM,EAAE,KAAK;YACb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