@vite-hub/choices 0.0.0 → 0.4.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.
- package/LICENSE +201 -0
- package/README.md +136 -1
- package/dist/cli.d.ts +148 -0
- package/dist/cli.js +282 -0
- package/dist/diagnostics-DTMZy54f.js +48 -0
- package/dist/index.d.ts +157 -0
- package/dist/index.js +321 -0
- package/dist/vue.d.ts +54 -0
- package/dist/vue.js +79 -0
- package/package.json +74 -9
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
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
1
|
# @vite-hub/choices
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Turn text into choices over options that you declare. A person types "nord parts except vak supply". Your app gets back which options the text includes and excludes. Use it for filters, search facets, command palettes, and builders.
|
|
4
|
+
|
|
5
|
+
`defineChoices()` is a plain function on the server. It does not know your routes, your UI, or your store. You write the two bridges: from your data to options, and from the selection to your state. ViteHub applications import it as `vite-hub/choices`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @vite-hub/choices @vite-hub/gateways advocaat
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The model call goes through an AI gateway that has `ask()`, such as `typesafe()` or `vercel()` from `@vite-hub/gateways`, to TypeSafe Jev. The gateway reads its key from the environment. The key stays on your server. To use another model, pass any AI SDK model as `model` instead of `gateway`, and install `ai`.
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```ts fragment
|
|
18
|
+
import { defineChoices, toOptions } from '@vite-hub/choices'
|
|
19
|
+
import { typesafe } from '@vite-hub/gateways'
|
|
20
|
+
|
|
21
|
+
export const forecast = defineChoices({
|
|
22
|
+
name: 'forecast', // a label for logs only
|
|
23
|
+
gateway: typesafe(), // reads TYPESAFE_API_KEY
|
|
24
|
+
groups: {
|
|
25
|
+
supplier: {
|
|
26
|
+
label: 'Supplier',
|
|
27
|
+
options: toOptions(suppliers, { value: s => s.code, label: s => s.name, aliases: s => [s.code] }),
|
|
28
|
+
},
|
|
29
|
+
chart: {
|
|
30
|
+
label: 'Chart',
|
|
31
|
+
multiple: false, // choose one
|
|
32
|
+
options: [{ value: 'line', label: 'Line' }, { value: 'bar', label: 'Bar' }],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// In any server code: a route, a queue worker, a test.
|
|
38
|
+
const [error, selection] = await forecast.resolve('nord parts except vak supply')
|
|
39
|
+
if (error) return handle(error)
|
|
40
|
+
|
|
41
|
+
selection.supplier // { include: ['S2'], exclude: ['S1'] }
|
|
42
|
+
selection.chart // { value: null, confidence: 0.9, ranked: [{ value: 'line', probability: 0.5 }, ...] }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`resolve()` returns `[error, data]` and never throws. Definition errors throw when you define the choices.
|
|
46
|
+
|
|
47
|
+
## The bridges
|
|
48
|
+
|
|
49
|
+
| You write | We do |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `options`: your data as `{ value, label, aliases? }`, or a function that loads them for one request | Build one question per option and ask the gateway |
|
|
52
|
+
| The route that calls `resolve()`, with your auth and rate limit | Check the limits and the answers |
|
|
53
|
+
| The code that applies `selection` to your state | Type `selection` from your options |
|
|
54
|
+
|
|
55
|
+
An `options` function receives `context`. Annotate its parameter, and `resolve()` asks for the same type:
|
|
56
|
+
|
|
57
|
+
```ts fragment
|
|
58
|
+
options: async ({ tenantId }: { tenantId: string }) => toOptions(await loadSites(tenantId), { value: s => s.id, label: s => s.name })
|
|
59
|
+
// await sites.resolve(text, { context: { tenantId: session.tenantId } })
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Groups
|
|
63
|
+
|
|
64
|
+
| Option | Meaning |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| `multiple: true` (default) | Any number of options. The selection is `{ include, exclude }`. |
|
|
67
|
+
| `multiple: false` | At most one option. The selection is `{ value, confidence, ranked }`. `value` is `null` below `thresholds.option`. |
|
|
68
|
+
| `hints` | A short note for the model about this group. |
|
|
69
|
+
|
|
70
|
+
The top-level `hints` apply to every question. Put your domain words there, such as "mtop means Make to order".
|
|
71
|
+
|
|
72
|
+
## Use it in the browser
|
|
73
|
+
|
|
74
|
+
`useChoices()` from `@vite-hub/choices/vue` (auto-imported in Nuxt) turns the text of an input into a selection. You give it a `resolve` function that calls your route. It does not know your server, your store, or your UI.
|
|
75
|
+
|
|
76
|
+
```vue
|
|
77
|
+
<script setup lang="ts">
|
|
78
|
+
import type { forecast } from '~~/server/utils/forecast-choices' // a type, so no server code reaches the browser
|
|
79
|
+
|
|
80
|
+
const store = useForecastStore()
|
|
81
|
+
const ai = useChoices<typeof forecast>({
|
|
82
|
+
resolve: (text, { signal }) => $fetch('/api/forecast/choices', { method: 'POST', body: { text }, signal }),
|
|
83
|
+
onSelect: selection => store.setSuppliers(selection.supplier), // your bridge out
|
|
84
|
+
debounce: 800, // leave it out to resolve only on ai.submit()
|
|
85
|
+
})
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<template>
|
|
89
|
+
<input v-model="ai.text.value" @keydown.enter="ai.submit()">
|
|
90
|
+
<p v-if="ai.status.value === 'thinking'">Thinking</p>
|
|
91
|
+
<p v-else-if="ai.error.value">{{ ai.error.value.message }}</p>
|
|
92
|
+
</template>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
| Returned | Meaning |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `text` | A ref for your input. |
|
|
98
|
+
| `status` | `idle`, `thinking`, `ready`, or `error`. |
|
|
99
|
+
| `selection`, `error` | The latest result and the latest failure. |
|
|
100
|
+
| `submit()`, `abort()`, `clear()` | Resolve now, cancel the request, reset the text, selection, and error. `clear()` also calls `onClear`, so you can reset your own state. |
|
|
101
|
+
|
|
102
|
+
A newer request cancels the older one through `signal`, and the older result never reaches `onSelect`. With debounce enabled, changing the text cancels the current request immediately, including while waiting for the next request to start. Throw from `resolve` to set `error`. The text must be at least `minLength` (3) characters before a debounced resolve runs.
|
|
103
|
+
|
|
104
|
+
## Limits and errors
|
|
105
|
+
|
|
106
|
+
| Limit | Default |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| Groups | 40 |
|
|
109
|
+
| Options per group | 100 |
|
|
110
|
+
| Options in all groups | 100 |
|
|
111
|
+
| Text length | 300 |
|
|
112
|
+
|
|
113
|
+
| Code | Meaning |
|
|
114
|
+
| --- | --- |
|
|
115
|
+
| `DECISIONS_R0001` | The definition is wrong. It throws when you define it. |
|
|
116
|
+
| `DECISIONS_R0002` | The options are over a limit or invalid. Nothing was asked. |
|
|
117
|
+
| `DECISIONS_R0003` | The text is empty or too long. Nothing was asked. |
|
|
118
|
+
| `DECISIONS_R0004` | The model says the options cannot express the text. |
|
|
119
|
+
| `DECISIONS_R0005` | The gateway request failed. `message` and `fix` show known, client-safe gateway diagnostics. Other failures use a generic message. `cause` has the original error for server-side inspection. |
|
|
120
|
+
| `DECISIONS_R0006` | The model answer misses a question. |
|
|
121
|
+
|
|
122
|
+
`thresholds.option` (0.5) decides one option. `thresholds.supported` (0.6) decides whether the text can be expressed at all. A decision model answers from the options you gave it. It cannot compare numbers or invent a value.
|
|
123
|
+
|
|
124
|
+
## Inspect
|
|
125
|
+
|
|
126
|
+
`choices.inspect(text)` returns the state and the questions that `resolve()` would send. Nothing leaves your server.
|
|
127
|
+
|
|
128
|
+
The `vitehub` CLI of `vite-hub` runs a definition by its file path. There is no registry.
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
pnpm vitehub choices list # the exports of defineChoices() results, by file
|
|
132
|
+
pnpm vitehub choices run server/utils/forecast-choices.ts "nord parts except vak supply"
|
|
133
|
+
pnpm vitehub choices run server/utils/forecast-choices.ts "nord parts" --inspect # no model call
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`run` prints the selection as JSON. `--export <name>` picks one export of a file with several, and `--context <json>` passes the `context` of `options` functions. A Choices error prints `{ "error": { "code", "message" } }` and exits with status 1. The command reads gateway keys from the shell and the project `.env` files. It loads the file with Vite but not with the project config, so Nuxt aliases and auto-imports do not resolve.
|
|
137
|
+
|
|
138
|
+
`createChoicesCliNamespace()` from `@vite-hub/choices/cli` returns the same commands for another CLI. It needs `vite`.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Diagnostic } from "nostics";
|
|
2
|
+
//#region ../internal/src/host-credentials.d.ts
|
|
3
|
+
interface HostCliRunResult {
|
|
4
|
+
exitCode: number | null;
|
|
5
|
+
stdout: string;
|
|
6
|
+
}
|
|
7
|
+
/** Runs a host CLI with an argument array and no shell, and returns its stdout. */
|
|
8
|
+
type HostCliRun = (command: string, args: readonly string[], options: {
|
|
9
|
+
cwd?: string;
|
|
10
|
+
env: NodeJS.ProcessEnv;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}) => Promise<HostCliRunResult>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region ../internal/src/provision.d.ts
|
|
15
|
+
type ProvisionProvider = "cloudflare" | "vercel";
|
|
16
|
+
interface ProvisionLogger {
|
|
17
|
+
log: (message: string) => void;
|
|
18
|
+
warn: (message: string) => void;
|
|
19
|
+
}
|
|
20
|
+
interface ProvisionContext {
|
|
21
|
+
env: Record<string, string | undefined>;
|
|
22
|
+
fetch: typeof globalThis.fetch;
|
|
23
|
+
logger: ProvisionLogger;
|
|
24
|
+
markPlanUnchecked?: () => void;
|
|
25
|
+
}
|
|
26
|
+
interface ProvisionState {
|
|
27
|
+
cloudflare?: Record<string, Record<string, string>>;
|
|
28
|
+
vercel?: Record<string, Record<string, string>>;
|
|
29
|
+
}
|
|
30
|
+
interface ProvisionResult {
|
|
31
|
+
ids?: ProvisionState;
|
|
32
|
+
}
|
|
33
|
+
interface ProvisionAction {
|
|
34
|
+
kind: string;
|
|
35
|
+
name: string;
|
|
36
|
+
exists: boolean;
|
|
37
|
+
pending?: boolean;
|
|
38
|
+
/** Describes the change that `apply()` makes to an existing resource, for example `read replication: disabled -> auto`. */
|
|
39
|
+
update?: string;
|
|
40
|
+
apply: () => Promise<ProvisionResult>;
|
|
41
|
+
}
|
|
42
|
+
/** One Provision State category that a step records, with the keys that current Definitions use. */
|
|
43
|
+
interface ProvisionStateCategory {
|
|
44
|
+
category: string;
|
|
45
|
+
declared: readonly string[];
|
|
46
|
+
/** Provider resource identity for shared-resource checks. Return undefined when the recorded id lacks enough information. Defaults to the recorded id. */
|
|
47
|
+
resourceIdentity?: (entry: {
|
|
48
|
+
id: string;
|
|
49
|
+
key: string;
|
|
50
|
+
}) => string | undefined;
|
|
51
|
+
/** Identity expected by current config for a declared key. Omit when it cannot be established without provider access. */
|
|
52
|
+
declaredResourceIdentity?: (key: string) => string | undefined;
|
|
53
|
+
/** Tells a developer how to delete the resource of a recorded entry that no Definition declares. ViteHub never runs it. */
|
|
54
|
+
deleteHint: (entry: {
|
|
55
|
+
id: string;
|
|
56
|
+
key: string;
|
|
57
|
+
}) => string;
|
|
58
|
+
}
|
|
59
|
+
interface ProvisionStep {
|
|
60
|
+
id: string;
|
|
61
|
+
provider: ProvisionProvider;
|
|
62
|
+
plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
|
|
63
|
+
/** Describes the Provision State this step records. Runs without network access, also without credentials. */
|
|
64
|
+
recordedState?: (context: Pick<ProvisionContext, "env">) => ProvisionStateCategory[];
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region ../internal/src/cli.d.ts
|
|
68
|
+
interface ViteHubCliStreams {
|
|
69
|
+
stderr: {
|
|
70
|
+
write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
|
|
71
|
+
};
|
|
72
|
+
stdout: {
|
|
73
|
+
write: (chunk: string | Uint8Array) => unknown;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
interface ViteHubCliSpawnResult {
|
|
77
|
+
exitCode: number | null;
|
|
78
|
+
signal?: NodeJS.Signals | null;
|
|
79
|
+
/** The output of the child when `stdout` is `pipe`. */
|
|
80
|
+
stdout?: string;
|
|
81
|
+
}
|
|
82
|
+
interface ViteHubCliSpawnOptions {
|
|
83
|
+
cwd?: string;
|
|
84
|
+
env?: NodeJS.ProcessEnv;
|
|
85
|
+
stderr?: "inherit" | "pipe";
|
|
86
|
+
/** `ignore` gives the child no terminal input, so a tool that asks questions on a terminal does not ask. */
|
|
87
|
+
stdin?: "ignore" | "inherit";
|
|
88
|
+
/** `stderr` sends the child's stdout to the parent's stderr, so the parent's stdout keeps only its own output. */
|
|
89
|
+
stdout?: "inherit" | "pipe" | "stderr";
|
|
90
|
+
}
|
|
91
|
+
type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
|
|
92
|
+
interface ViteHubCliContext extends ViteHubCliStreams {
|
|
93
|
+
cwd: string;
|
|
94
|
+
env: NodeJS.ProcessEnv;
|
|
95
|
+
/** Replaces `fetch` for commands that call a running app, so tests need no server. */
|
|
96
|
+
fetch?: typeof fetch;
|
|
97
|
+
/**
|
|
98
|
+
* Loads the project config for a build on `host` and returns the Provision Steps of its plugins, with the config root
|
|
99
|
+
* that holds `.vitehub/provision.json`. Setup commands, such as `vitehub deploy`, call it only when they need the
|
|
100
|
+
* steps, so they still run on a config that throws.
|
|
101
|
+
*/
|
|
102
|
+
loadProvision?: (host: ProvisionProvider) => Promise<ViteHubCliProvision>;
|
|
103
|
+
/** The deployed app's public origin from `vitehub({ publicUrl })`, when it is one string. */
|
|
104
|
+
publicUrl?: string;
|
|
105
|
+
rootDir: string;
|
|
106
|
+
/** Replaces the host CLI runner, such as for `wrangler auth token`, so tests need no real host CLI. */
|
|
107
|
+
runHostCli?: HostCliRun;
|
|
108
|
+
spawn: ViteHubCliSpawn;
|
|
109
|
+
}
|
|
110
|
+
interface ViteHubCliProvision {
|
|
111
|
+
rootDir: string;
|
|
112
|
+
steps: readonly ProvisionStep[];
|
|
113
|
+
}
|
|
114
|
+
interface ViteHubCliFeature {
|
|
115
|
+
description?: string;
|
|
116
|
+
name: string;
|
|
117
|
+
run: (args: string[], context: ViteHubCliContext) => Promise<number | void> | number | void;
|
|
118
|
+
usage?: string;
|
|
119
|
+
}
|
|
120
|
+
interface ViteHubCliCommandNamespace {
|
|
121
|
+
/** The feature that `vitehub <name>` runs when the next argument names no other feature. It gets every argument after `<name>`. */
|
|
122
|
+
defaultFeature?: string;
|
|
123
|
+
description?: string;
|
|
124
|
+
features: ViteHubCliFeature[];
|
|
125
|
+
name: string;
|
|
126
|
+
}
|
|
127
|
+
type StdoutWriteCallback = (error?: Error | null) => void;
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/cli.d.ts
|
|
130
|
+
interface FoundChoices {
|
|
131
|
+
export: string;
|
|
132
|
+
name: string | undefined;
|
|
133
|
+
}
|
|
134
|
+
interface ListedFile {
|
|
135
|
+
/** The exports of the file that `defineChoices()` returned. Empty when the file failed to load. */
|
|
136
|
+
choices: FoundChoices[];
|
|
137
|
+
/** Why the file did not load. */
|
|
138
|
+
error?: string;
|
|
139
|
+
file: string;
|
|
140
|
+
}
|
|
141
|
+
/** Finds the files that name `defineChoices()`, then loads each one to read its exports. There is no registry. */
|
|
142
|
+
export declare function listChoices(rootDir: string): Promise<ListedFile[]>;
|
|
143
|
+
/**
|
|
144
|
+
* The `vitehub choices` commands. They load a Choices file by path and do not load the project config.
|
|
145
|
+
* `run` calls the gateway of the definition, so it reads the same keys as the app, from the shell or the `.env` files.
|
|
146
|
+
*/
|
|
147
|
+
export declare function createChoicesCliNamespace(): ViteHubCliCommandNamespace;
|
|
148
|
+
//#endregion
|