@optique/prompt 1.2.0-dev.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 +20 -0
- package/README.md +55 -0
- package/dist/index.cjs +292 -0
- package/dist/index.d.cts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +269 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025–2026 Hong Minhee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
@optique/prompt
|
|
2
|
+
===============
|
|
3
|
+
|
|
4
|
+
Generic prompt adapter support for [Optique].
|
|
5
|
+
|
|
6
|
+
This package contains the shared machinery used by interactive prompt
|
|
7
|
+
integrations. Most applications should use a concrete integration such as
|
|
8
|
+
*@optique/inquirer* or *@optique/clack* instead.
|
|
9
|
+
|
|
10
|
+
[Optique]: https://optique.dev/
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
Installation
|
|
14
|
+
------------
|
|
15
|
+
|
|
16
|
+
~~~~ bash
|
|
17
|
+
deno add jsr:@optique/prompt
|
|
18
|
+
npm add @optique/prompt
|
|
19
|
+
pnpm add @optique/prompt
|
|
20
|
+
yarn add @optique/prompt
|
|
21
|
+
bun add @optique/prompt
|
|
22
|
+
~~~~
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Documentation
|
|
26
|
+
-------------
|
|
27
|
+
|
|
28
|
+
For full documentation, visit <https://optique.dev/integrations/prompt>.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Quick start
|
|
32
|
+
-----------
|
|
33
|
+
|
|
34
|
+
~~~~ typescript
|
|
35
|
+
import { option } from "@optique/core/primitives";
|
|
36
|
+
import { string } from "@optique/core/valueparser";
|
|
37
|
+
import { createPromptAdapter } from "@optique/prompt";
|
|
38
|
+
|
|
39
|
+
const prompt = createPromptAdapter<{ readonly message: string }>({
|
|
40
|
+
async execute<TValue>(config) {
|
|
41
|
+
const value = globalThis.prompt?.(config.message) ?? "";
|
|
42
|
+
return { success: true, value: value as TValue };
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const name = prompt(option("--name", string()), {
|
|
47
|
+
message: "Name:",
|
|
48
|
+
});
|
|
49
|
+
~~~~
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
License
|
|
53
|
+
-------
|
|
54
|
+
|
|
55
|
+
MIT License. See [LICENSE](../../LICENSE) for details.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
const __optique_core_annotations = __toESM(require("@optique/core/annotations"));
|
|
25
|
+
const __optique_core_extension = __toESM(require("@optique/core/extension"));
|
|
26
|
+
const __optique_core_fluent = __toESM(require("@optique/core/fluent"));
|
|
27
|
+
|
|
28
|
+
//#region src/index.ts
|
|
29
|
+
function shouldDeferPrompt(parser, state, exec) {
|
|
30
|
+
return typeof parser.shouldDeferCompletion === "function" && parser.shouldDeferCompletion(state, exec) === true;
|
|
31
|
+
}
|
|
32
|
+
function deferredPromptResult(placeholderValue) {
|
|
33
|
+
if (placeholderValue == null || typeof placeholderValue !== "object") return {
|
|
34
|
+
success: true,
|
|
35
|
+
value: placeholderValue,
|
|
36
|
+
deferred: true
|
|
37
|
+
};
|
|
38
|
+
const isArray = Array.isArray(placeholderValue);
|
|
39
|
+
const keys = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const key of Reflect.ownKeys(placeholderValue)) {
|
|
41
|
+
if (isArray && key === "length") continue;
|
|
42
|
+
keys.set(key, null);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
success: true,
|
|
46
|
+
value: placeholderValue,
|
|
47
|
+
deferred: true,
|
|
48
|
+
deferredKeys: keys
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function withAnnotatedInnerState(sourceState, innerState, run) {
|
|
52
|
+
const annotations = (0, __optique_core_annotations.getAnnotations)(sourceState);
|
|
53
|
+
if (annotations == null || innerState == null || typeof innerState !== "object" || (0, __optique_core_annotations.getAnnotations)(innerState) != null) return run(innerState);
|
|
54
|
+
const inheritedState = (0, __optique_core_extension.inheritAnnotations)(sourceState, innerState);
|
|
55
|
+
if (inheritedState !== innerState) return run(inheritedState);
|
|
56
|
+
return run((0, __optique_core_extension.withAnnotationView)(innerState, annotations));
|
|
57
|
+
}
|
|
58
|
+
function hasSourceBindingMarker(state) {
|
|
59
|
+
return state != null && typeof state === "object" && "hasCliValue" in state && Object.getOwnPropertySymbols(state).length > 0;
|
|
60
|
+
}
|
|
61
|
+
function readDefaultValue(adapter, config) {
|
|
62
|
+
if (adapter.getDefaultValue != null) return adapter.getDefaultValue(config);
|
|
63
|
+
if (config != null && typeof config === "object" && "default" in config) return config.default;
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates a `prompt()` parser wrapper for a prompt library adapter.
|
|
68
|
+
*
|
|
69
|
+
* The generated wrapper tries the inner parser first. If CLI tokens, source
|
|
70
|
+
* bindings, or defaults satisfy the parser, the prompt is skipped. Otherwise
|
|
71
|
+
* the adapter runs during the real completion phase and provides a fallback
|
|
72
|
+
* value.
|
|
73
|
+
*
|
|
74
|
+
* @typeParam TConfig Prompt configuration accepted by the adapter.
|
|
75
|
+
* @param adapter Library-specific prompt executor.
|
|
76
|
+
* @returns A `prompt(parser, config)` wrapper that always produces an async
|
|
77
|
+
* parser.
|
|
78
|
+
* @since 1.2.0
|
|
79
|
+
*/
|
|
80
|
+
function createPromptAdapter(adapter) {
|
|
81
|
+
return function prompt(parser, config) {
|
|
82
|
+
const promptBindStateKey = Symbol("@optique/prompt/promptState");
|
|
83
|
+
function isPromptBindState(value) {
|
|
84
|
+
return value != null && typeof value === "object" && promptBindStateKey in value;
|
|
85
|
+
}
|
|
86
|
+
function shouldAttemptInnerCompletion(cliState, state) {
|
|
87
|
+
if (cliState == null) return false;
|
|
88
|
+
const cliStateHasAnnotations = (0, __optique_core_annotations.getAnnotations)(cliState) != null;
|
|
89
|
+
if (cliStateHasAnnotations) return true;
|
|
90
|
+
if ((0, __optique_core_annotations.getAnnotations)(state) == null || typeof cliState !== "object") return false;
|
|
91
|
+
if ("hasCliValue" in cliState) return true;
|
|
92
|
+
if (Array.isArray(cliState)) return typeof parser.shouldDeferCompletion === "function";
|
|
93
|
+
const prototype = Object.getPrototypeOf(cliState);
|
|
94
|
+
return prototype !== Object.prototype && prototype !== null;
|
|
95
|
+
}
|
|
96
|
+
function shouldCompleteFromSourceBinding(cliState, state) {
|
|
97
|
+
const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && (0, __optique_core_extension.unwrapInjectedAnnotationState)(cliState) !== cliState;
|
|
98
|
+
const requiresSourceBindingForAnnotationWrapper = (0, __optique_core_extension.getTraits)(parser).requiresSourceBinding === true;
|
|
99
|
+
const hasNestedSourceBinding = hasSourceBindingMarker(cliState) || Array.isArray(cliState) && cliState.length === 1 && (hasSourceBindingMarker(cliState[0]) || cliState[0] != null && typeof cliState[0] === "object" && (0, __optique_core_annotations.getAnnotations)(cliState[0]) != null);
|
|
100
|
+
if (cliStateIsInjectedAnnotationWrapper && requiresSourceBindingForAnnotationWrapper) return hasNestedSourceBinding;
|
|
101
|
+
return shouldAttemptInnerCompletion(cliState, state) || hasNestedSourceBinding;
|
|
102
|
+
}
|
|
103
|
+
function executePrompt() {
|
|
104
|
+
return adapter.execute(config);
|
|
105
|
+
}
|
|
106
|
+
const promptedParser = {
|
|
107
|
+
mode: "async",
|
|
108
|
+
$valueType: parser.$valueType,
|
|
109
|
+
$stateType: parser.$stateType,
|
|
110
|
+
priority: parser.priority,
|
|
111
|
+
usage: parser.usage.length === 1 && parser.usage[0].type === "optional" ? parser.usage : [{
|
|
112
|
+
type: "optional",
|
|
113
|
+
terms: parser.usage
|
|
114
|
+
}],
|
|
115
|
+
leadingNames: parser.leadingNames,
|
|
116
|
+
acceptingAnyToken: parser.acceptingAnyToken,
|
|
117
|
+
shouldDeferCompletion(state) {
|
|
118
|
+
return !isPromptBindState(state) || !state.hasCliValue;
|
|
119
|
+
},
|
|
120
|
+
getSuggestRuntimeNodes(state, path) {
|
|
121
|
+
const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
|
|
122
|
+
return (0, __optique_core_extension.delegateSuggestNodes)(parser, promptedParser, state, path, innerState, "prepend");
|
|
123
|
+
},
|
|
124
|
+
initialState: {
|
|
125
|
+
[promptBindStateKey]: true,
|
|
126
|
+
hasCliValue: false
|
|
127
|
+
},
|
|
128
|
+
parse: (context) => {
|
|
129
|
+
const annotations = (0, __optique_core_annotations.getAnnotations)(context.state);
|
|
130
|
+
const innerState = isPromptBindState(context.state) ? context.state.hasCliValue ? context.state.cliState : parser.initialState : context.state;
|
|
131
|
+
const baseInnerContext = innerState !== context.state ? {
|
|
132
|
+
...context,
|
|
133
|
+
state: innerState
|
|
134
|
+
} : context;
|
|
135
|
+
const effectiveInnerState = annotations != null && innerState == null && (0, __optique_core_extension.getTraits)(parser).inheritsAnnotations === true ? (0, __optique_core_extension.injectAnnotations)(innerState, annotations) : innerState;
|
|
136
|
+
const processResult = (result$1) => {
|
|
137
|
+
if (result$1.success) {
|
|
138
|
+
const cliState = annotations != null && result$1.next.state != null && typeof result$1.next.state === "object" && (0, __optique_core_annotations.getAnnotations)(result$1.next.state) !== annotations ? (0, __optique_core_extension.injectAnnotations)(result$1.next.state, annotations) : result$1.next.state;
|
|
139
|
+
const cliConsumed = result$1.consumed.length > 0;
|
|
140
|
+
const nextState$1 = (0, __optique_core_extension.injectAnnotations)({
|
|
141
|
+
[promptBindStateKey]: true,
|
|
142
|
+
hasCliValue: cliConsumed,
|
|
143
|
+
cliState
|
|
144
|
+
}, annotations);
|
|
145
|
+
return {
|
|
146
|
+
success: true,
|
|
147
|
+
...result$1.provisional ? { provisional: true } : {},
|
|
148
|
+
next: {
|
|
149
|
+
...result$1.next,
|
|
150
|
+
state: nextState$1
|
|
151
|
+
},
|
|
152
|
+
consumed: result$1.consumed
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (result$1.consumed > 0) return result$1;
|
|
156
|
+
const nextState = (0, __optique_core_extension.injectAnnotations)({
|
|
157
|
+
[promptBindStateKey]: true,
|
|
158
|
+
hasCliValue: false
|
|
159
|
+
}, annotations);
|
|
160
|
+
return {
|
|
161
|
+
success: true,
|
|
162
|
+
next: {
|
|
163
|
+
...baseInnerContext,
|
|
164
|
+
state: nextState
|
|
165
|
+
},
|
|
166
|
+
consumed: []
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
const result = withAnnotatedInnerState(context.state, effectiveInnerState, (annotatedInnerState) => {
|
|
170
|
+
const innerContext = annotatedInnerState !== context.state ? {
|
|
171
|
+
...context,
|
|
172
|
+
state: annotatedInnerState
|
|
173
|
+
} : context;
|
|
174
|
+
return parser.parse(innerContext);
|
|
175
|
+
});
|
|
176
|
+
if (result instanceof Promise) return result.then(processResult);
|
|
177
|
+
return Promise.resolve(processResult(result));
|
|
178
|
+
},
|
|
179
|
+
complete: (state, exec) => {
|
|
180
|
+
if (isPromptBindState(state) && state.hasCliValue) {
|
|
181
|
+
const r = withAnnotatedInnerState(state, state.cliState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
|
|
182
|
+
if (r instanceof Promise) return r;
|
|
183
|
+
return Promise.resolve(r);
|
|
184
|
+
}
|
|
185
|
+
const isProbe = exec != null && exec.phase !== "complete";
|
|
186
|
+
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
187
|
+
const innerInitialState = parser.initialState;
|
|
188
|
+
const shouldInheritInitialStateAnnotations = annotations != null && (innerInitialState == null || typeof innerInitialState === "object");
|
|
189
|
+
const effectiveInitialState = shouldInheritInitialStateAnnotations ? (0, __optique_core_extension.inheritAnnotations)(state, innerInitialState) : innerInitialState;
|
|
190
|
+
const readPlaceholder = () => {
|
|
191
|
+
try {
|
|
192
|
+
return "placeholder" in parser ? parser.placeholder : void 0;
|
|
193
|
+
} catch {
|
|
194
|
+
return void 0;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const finalizePrompt = () => {
|
|
198
|
+
const shouldDefer = withAnnotatedInnerState(state, effectiveInitialState, (annotatedInnerState) => shouldDeferPrompt(parser, annotatedInnerState, exec));
|
|
199
|
+
if (shouldDefer) return Promise.resolve(deferredPromptResult(readPlaceholder()));
|
|
200
|
+
if (isProbe) return Promise.resolve({
|
|
201
|
+
success: true,
|
|
202
|
+
value: readPlaceholder()
|
|
203
|
+
});
|
|
204
|
+
return executePrompt();
|
|
205
|
+
};
|
|
206
|
+
const hasDeferHook = typeof parser.shouldDeferCompletion === "function";
|
|
207
|
+
const decideFromParse = (parseResult) => {
|
|
208
|
+
const consumed = parseResult.success ? parseResult.consumed.length : 0;
|
|
209
|
+
const cliState = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
|
|
210
|
+
const cliStateIsInjected = cliState != null && typeof cliState === "object" && (0, __optique_core_extension.unwrapInjectedAnnotationState)(cliState) !== cliState;
|
|
211
|
+
const isSourceBinding = shouldCompleteFromSourceBinding(cliState, state);
|
|
212
|
+
if (!isSourceBinding) return finalizePrompt();
|
|
213
|
+
const completeState = parseResult.success ? parseResult.next.state : effectiveInitialState;
|
|
214
|
+
const innerR = parser.complete(completeState, exec);
|
|
215
|
+
const handleCompleteResult = (res) => {
|
|
216
|
+
if (res.success && res.value === void 0 && cliStateIsInjected) return finalizePrompt();
|
|
217
|
+
if (!res.success) return finalizePrompt();
|
|
218
|
+
return Promise.resolve(res);
|
|
219
|
+
};
|
|
220
|
+
if (innerR instanceof Promise) return innerR.then(handleCompleteResult);
|
|
221
|
+
return handleCompleteResult(innerR);
|
|
222
|
+
};
|
|
223
|
+
if (hasDeferHook) {
|
|
224
|
+
const innerR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
|
|
225
|
+
const handleDeferHookResult = (res) => {
|
|
226
|
+
if (res.success && res.value === void 0) return finalizePrompt();
|
|
227
|
+
if (!res.success) return finalizePrompt();
|
|
228
|
+
return Promise.resolve(res);
|
|
229
|
+
};
|
|
230
|
+
if (innerR instanceof Promise) return innerR.then(handleDeferHookResult);
|
|
231
|
+
return handleDeferHookResult(innerR);
|
|
232
|
+
}
|
|
233
|
+
const simParseR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedState) => parser.parse({
|
|
234
|
+
buffer: [],
|
|
235
|
+
state: annotatedState,
|
|
236
|
+
optionsTerminated: false,
|
|
237
|
+
usage: parser.usage
|
|
238
|
+
}));
|
|
239
|
+
if (simParseR instanceof Promise) return simParseR.then(decideFromParse);
|
|
240
|
+
return decideFromParse(simParseR);
|
|
241
|
+
},
|
|
242
|
+
suggest: (context, prefix) => {
|
|
243
|
+
const innerState = isPromptBindState(context.state) ? context.state.cliState === void 0 ? parser.initialState : context.state.cliState : context.state;
|
|
244
|
+
const innerContext = innerState !== context.state ? {
|
|
245
|
+
...context,
|
|
246
|
+
state: innerState
|
|
247
|
+
} : context;
|
|
248
|
+
const innerResult = parser.suggest(innerContext, prefix);
|
|
249
|
+
return async function* () {
|
|
250
|
+
yield* innerResult;
|
|
251
|
+
}();
|
|
252
|
+
},
|
|
253
|
+
getDocFragments(state, upperDefaultValue) {
|
|
254
|
+
const defaultValue = upperDefaultValue ?? readDefaultValue(adapter, config);
|
|
255
|
+
return parser.getDocFragments(state, defaultValue);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
(0, __optique_core_extension.defineTraits)(promptedParser, { inheritsAnnotations: true });
|
|
259
|
+
if ("placeholder" in parser) Object.defineProperty(promptedParser, "placeholder", {
|
|
260
|
+
get() {
|
|
261
|
+
try {
|
|
262
|
+
return parser.placeholder;
|
|
263
|
+
} catch {
|
|
264
|
+
return void 0;
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
configurable: true,
|
|
268
|
+
enumerable: false
|
|
269
|
+
});
|
|
270
|
+
if (typeof parser.normalizeValue === "function") Object.defineProperty(promptedParser, "normalizeValue", {
|
|
271
|
+
value: parser.normalizeValue.bind(parser),
|
|
272
|
+
configurable: true,
|
|
273
|
+
enumerable: false
|
|
274
|
+
});
|
|
275
|
+
const dependencyMetadata = (0, __optique_core_extension.mapSourceMetadata)(parser, (source) => ({
|
|
276
|
+
...source,
|
|
277
|
+
extractSourceValue: (state) => {
|
|
278
|
+
if (!isPromptBindState(state)) return source.extractSourceValue(state);
|
|
279
|
+
return source.extractSourceValue(state.cliState ?? state);
|
|
280
|
+
}
|
|
281
|
+
}));
|
|
282
|
+
if (dependencyMetadata != null) Object.defineProperty(promptedParser, "dependencyMetadata", {
|
|
283
|
+
value: dependencyMetadata,
|
|
284
|
+
configurable: true,
|
|
285
|
+
enumerable: false
|
|
286
|
+
});
|
|
287
|
+
return (0, __optique_core_fluent.fluent)(promptedParser);
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
//#endregion
|
|
292
|
+
exports.createPromptAdapter = createPromptAdapter;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { FluentParser } from "@optique/core/fluent";
|
|
2
|
+
import { Mode, Parser } from "@optique/core/parser";
|
|
3
|
+
import { ValueParserResult } from "@optique/core/valueparser";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Prompt adapter used by {@link createPromptAdapter}.
|
|
9
|
+
*
|
|
10
|
+
* The adapter owns library-specific prompt execution and maps the result into
|
|
11
|
+
* Optique's value-parser result shape. The shared parser wrapping behavior,
|
|
12
|
+
* including CLI priority, source bindings, deferred completion, suggestions,
|
|
13
|
+
* and usage metadata, is handled by *@optique/prompt*.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam TConfig Prompt configuration accepted by the adapter.
|
|
16
|
+
* @since 1.2.0
|
|
17
|
+
*/
|
|
18
|
+
interface PromptAdapter<TConfig> {
|
|
19
|
+
/**
|
|
20
|
+
* Executes the library-specific prompt.
|
|
21
|
+
*
|
|
22
|
+
* @typeParam TValue Value type produced by the wrapped parser.
|
|
23
|
+
* @param config Prompt configuration supplied to the generated `prompt()`
|
|
24
|
+
* wrapper.
|
|
25
|
+
* @returns The prompted value or a prompt failure.
|
|
26
|
+
* @throws Any unexpected prompt execution failure.
|
|
27
|
+
*/
|
|
28
|
+
readonly execute: <TValue>(config: TConfig) => Promise<ValueParserResult<TValue>>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a default value from the prompt config for documentation purposes.
|
|
31
|
+
*
|
|
32
|
+
* If omitted, *@optique/prompt* reads a `default` property from object-shaped
|
|
33
|
+
* configs when present.
|
|
34
|
+
*
|
|
35
|
+
* @param config Prompt configuration supplied to the generated `prompt()`
|
|
36
|
+
* wrapper.
|
|
37
|
+
* @returns A default value to pass to the wrapped parser's documentation
|
|
38
|
+
* fragments.
|
|
39
|
+
*/
|
|
40
|
+
readonly getDefaultValue?: (config: TConfig) => unknown;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a `prompt()` parser wrapper for a prompt library adapter.
|
|
44
|
+
*
|
|
45
|
+
* The generated wrapper tries the inner parser first. If CLI tokens, source
|
|
46
|
+
* bindings, or defaults satisfy the parser, the prompt is skipped. Otherwise
|
|
47
|
+
* the adapter runs during the real completion phase and provides a fallback
|
|
48
|
+
* value.
|
|
49
|
+
*
|
|
50
|
+
* @typeParam TConfig Prompt configuration accepted by the adapter.
|
|
51
|
+
* @param adapter Library-specific prompt executor.
|
|
52
|
+
* @returns A `prompt(parser, config)` wrapper that always produces an async
|
|
53
|
+
* parser.
|
|
54
|
+
* @since 1.2.0
|
|
55
|
+
*/
|
|
56
|
+
declare function createPromptAdapter<TConfig>(adapter: PromptAdapter<TConfig>): <M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: TConfig) => FluentParser<"async", TValue, TState>;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { PromptAdapter, createPromptAdapter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { FluentParser } from "@optique/core/fluent";
|
|
2
|
+
import { Mode, Parser } from "@optique/core/parser";
|
|
3
|
+
import { ValueParserResult } from "@optique/core/valueparser";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Prompt adapter used by {@link createPromptAdapter}.
|
|
9
|
+
*
|
|
10
|
+
* The adapter owns library-specific prompt execution and maps the result into
|
|
11
|
+
* Optique's value-parser result shape. The shared parser wrapping behavior,
|
|
12
|
+
* including CLI priority, source bindings, deferred completion, suggestions,
|
|
13
|
+
* and usage metadata, is handled by *@optique/prompt*.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam TConfig Prompt configuration accepted by the adapter.
|
|
16
|
+
* @since 1.2.0
|
|
17
|
+
*/
|
|
18
|
+
interface PromptAdapter<TConfig> {
|
|
19
|
+
/**
|
|
20
|
+
* Executes the library-specific prompt.
|
|
21
|
+
*
|
|
22
|
+
* @typeParam TValue Value type produced by the wrapped parser.
|
|
23
|
+
* @param config Prompt configuration supplied to the generated `prompt()`
|
|
24
|
+
* wrapper.
|
|
25
|
+
* @returns The prompted value or a prompt failure.
|
|
26
|
+
* @throws Any unexpected prompt execution failure.
|
|
27
|
+
*/
|
|
28
|
+
readonly execute: <TValue>(config: TConfig) => Promise<ValueParserResult<TValue>>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a default value from the prompt config for documentation purposes.
|
|
31
|
+
*
|
|
32
|
+
* If omitted, *@optique/prompt* reads a `default` property from object-shaped
|
|
33
|
+
* configs when present.
|
|
34
|
+
*
|
|
35
|
+
* @param config Prompt configuration supplied to the generated `prompt()`
|
|
36
|
+
* wrapper.
|
|
37
|
+
* @returns A default value to pass to the wrapped parser's documentation
|
|
38
|
+
* fragments.
|
|
39
|
+
*/
|
|
40
|
+
readonly getDefaultValue?: (config: TConfig) => unknown;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a `prompt()` parser wrapper for a prompt library adapter.
|
|
44
|
+
*
|
|
45
|
+
* The generated wrapper tries the inner parser first. If CLI tokens, source
|
|
46
|
+
* bindings, or defaults satisfy the parser, the prompt is skipped. Otherwise
|
|
47
|
+
* the adapter runs during the real completion phase and provides a fallback
|
|
48
|
+
* value.
|
|
49
|
+
*
|
|
50
|
+
* @typeParam TConfig Prompt configuration accepted by the adapter.
|
|
51
|
+
* @param adapter Library-specific prompt executor.
|
|
52
|
+
* @returns A `prompt(parser, config)` wrapper that always produces an async
|
|
53
|
+
* parser.
|
|
54
|
+
* @since 1.2.0
|
|
55
|
+
*/
|
|
56
|
+
declare function createPromptAdapter<TConfig>(adapter: PromptAdapter<TConfig>): <M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: TConfig) => FluentParser<"async", TValue, TState>;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { PromptAdapter, createPromptAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { getAnnotations } from "@optique/core/annotations";
|
|
2
|
+
import { defineTraits, delegateSuggestNodes, getTraits, inheritAnnotations, injectAnnotations, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView } from "@optique/core/extension";
|
|
3
|
+
import { fluent } from "@optique/core/fluent";
|
|
4
|
+
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
function shouldDeferPrompt(parser, state, exec) {
|
|
7
|
+
return typeof parser.shouldDeferCompletion === "function" && parser.shouldDeferCompletion(state, exec) === true;
|
|
8
|
+
}
|
|
9
|
+
function deferredPromptResult(placeholderValue) {
|
|
10
|
+
if (placeholderValue == null || typeof placeholderValue !== "object") return {
|
|
11
|
+
success: true,
|
|
12
|
+
value: placeholderValue,
|
|
13
|
+
deferred: true
|
|
14
|
+
};
|
|
15
|
+
const isArray = Array.isArray(placeholderValue);
|
|
16
|
+
const keys = /* @__PURE__ */ new Map();
|
|
17
|
+
for (const key of Reflect.ownKeys(placeholderValue)) {
|
|
18
|
+
if (isArray && key === "length") continue;
|
|
19
|
+
keys.set(key, null);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
success: true,
|
|
23
|
+
value: placeholderValue,
|
|
24
|
+
deferred: true,
|
|
25
|
+
deferredKeys: keys
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function withAnnotatedInnerState(sourceState, innerState, run) {
|
|
29
|
+
const annotations = getAnnotations(sourceState);
|
|
30
|
+
if (annotations == null || innerState == null || typeof innerState !== "object" || getAnnotations(innerState) != null) return run(innerState);
|
|
31
|
+
const inheritedState = inheritAnnotations(sourceState, innerState);
|
|
32
|
+
if (inheritedState !== innerState) return run(inheritedState);
|
|
33
|
+
return run(withAnnotationView(innerState, annotations));
|
|
34
|
+
}
|
|
35
|
+
function hasSourceBindingMarker(state) {
|
|
36
|
+
return state != null && typeof state === "object" && "hasCliValue" in state && Object.getOwnPropertySymbols(state).length > 0;
|
|
37
|
+
}
|
|
38
|
+
function readDefaultValue(adapter, config) {
|
|
39
|
+
if (adapter.getDefaultValue != null) return adapter.getDefaultValue(config);
|
|
40
|
+
if (config != null && typeof config === "object" && "default" in config) return config.default;
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a `prompt()` parser wrapper for a prompt library adapter.
|
|
45
|
+
*
|
|
46
|
+
* The generated wrapper tries the inner parser first. If CLI tokens, source
|
|
47
|
+
* bindings, or defaults satisfy the parser, the prompt is skipped. Otherwise
|
|
48
|
+
* the adapter runs during the real completion phase and provides a fallback
|
|
49
|
+
* value.
|
|
50
|
+
*
|
|
51
|
+
* @typeParam TConfig Prompt configuration accepted by the adapter.
|
|
52
|
+
* @param adapter Library-specific prompt executor.
|
|
53
|
+
* @returns A `prompt(parser, config)` wrapper that always produces an async
|
|
54
|
+
* parser.
|
|
55
|
+
* @since 1.2.0
|
|
56
|
+
*/
|
|
57
|
+
function createPromptAdapter(adapter) {
|
|
58
|
+
return function prompt(parser, config) {
|
|
59
|
+
const promptBindStateKey = Symbol("@optique/prompt/promptState");
|
|
60
|
+
function isPromptBindState(value) {
|
|
61
|
+
return value != null && typeof value === "object" && promptBindStateKey in value;
|
|
62
|
+
}
|
|
63
|
+
function shouldAttemptInnerCompletion(cliState, state) {
|
|
64
|
+
if (cliState == null) return false;
|
|
65
|
+
const cliStateHasAnnotations = getAnnotations(cliState) != null;
|
|
66
|
+
if (cliStateHasAnnotations) return true;
|
|
67
|
+
if (getAnnotations(state) == null || typeof cliState !== "object") return false;
|
|
68
|
+
if ("hasCliValue" in cliState) return true;
|
|
69
|
+
if (Array.isArray(cliState)) return typeof parser.shouldDeferCompletion === "function";
|
|
70
|
+
const prototype = Object.getPrototypeOf(cliState);
|
|
71
|
+
return prototype !== Object.prototype && prototype !== null;
|
|
72
|
+
}
|
|
73
|
+
function shouldCompleteFromSourceBinding(cliState, state) {
|
|
74
|
+
const cliStateIsInjectedAnnotationWrapper = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationState(cliState) !== cliState;
|
|
75
|
+
const requiresSourceBindingForAnnotationWrapper = getTraits(parser).requiresSourceBinding === true;
|
|
76
|
+
const hasNestedSourceBinding = hasSourceBindingMarker(cliState) || Array.isArray(cliState) && cliState.length === 1 && (hasSourceBindingMarker(cliState[0]) || cliState[0] != null && typeof cliState[0] === "object" && getAnnotations(cliState[0]) != null);
|
|
77
|
+
if (cliStateIsInjectedAnnotationWrapper && requiresSourceBindingForAnnotationWrapper) return hasNestedSourceBinding;
|
|
78
|
+
return shouldAttemptInnerCompletion(cliState, state) || hasNestedSourceBinding;
|
|
79
|
+
}
|
|
80
|
+
function executePrompt() {
|
|
81
|
+
return adapter.execute(config);
|
|
82
|
+
}
|
|
83
|
+
const promptedParser = {
|
|
84
|
+
mode: "async",
|
|
85
|
+
$valueType: parser.$valueType,
|
|
86
|
+
$stateType: parser.$stateType,
|
|
87
|
+
priority: parser.priority,
|
|
88
|
+
usage: parser.usage.length === 1 && parser.usage[0].type === "optional" ? parser.usage : [{
|
|
89
|
+
type: "optional",
|
|
90
|
+
terms: parser.usage
|
|
91
|
+
}],
|
|
92
|
+
leadingNames: parser.leadingNames,
|
|
93
|
+
acceptingAnyToken: parser.acceptingAnyToken,
|
|
94
|
+
shouldDeferCompletion(state) {
|
|
95
|
+
return !isPromptBindState(state) || !state.hasCliValue;
|
|
96
|
+
},
|
|
97
|
+
getSuggestRuntimeNodes(state, path) {
|
|
98
|
+
const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
|
|
99
|
+
return delegateSuggestNodes(parser, promptedParser, state, path, innerState, "prepend");
|
|
100
|
+
},
|
|
101
|
+
initialState: {
|
|
102
|
+
[promptBindStateKey]: true,
|
|
103
|
+
hasCliValue: false
|
|
104
|
+
},
|
|
105
|
+
parse: (context) => {
|
|
106
|
+
const annotations = getAnnotations(context.state);
|
|
107
|
+
const innerState = isPromptBindState(context.state) ? context.state.hasCliValue ? context.state.cliState : parser.initialState : context.state;
|
|
108
|
+
const baseInnerContext = innerState !== context.state ? {
|
|
109
|
+
...context,
|
|
110
|
+
state: innerState
|
|
111
|
+
} : context;
|
|
112
|
+
const effectiveInnerState = annotations != null && innerState == null && getTraits(parser).inheritsAnnotations === true ? injectAnnotations(innerState, annotations) : innerState;
|
|
113
|
+
const processResult = (result$1) => {
|
|
114
|
+
if (result$1.success) {
|
|
115
|
+
const cliState = annotations != null && result$1.next.state != null && typeof result$1.next.state === "object" && getAnnotations(result$1.next.state) !== annotations ? injectAnnotations(result$1.next.state, annotations) : result$1.next.state;
|
|
116
|
+
const cliConsumed = result$1.consumed.length > 0;
|
|
117
|
+
const nextState$1 = injectAnnotations({
|
|
118
|
+
[promptBindStateKey]: true,
|
|
119
|
+
hasCliValue: cliConsumed,
|
|
120
|
+
cliState
|
|
121
|
+
}, annotations);
|
|
122
|
+
return {
|
|
123
|
+
success: true,
|
|
124
|
+
...result$1.provisional ? { provisional: true } : {},
|
|
125
|
+
next: {
|
|
126
|
+
...result$1.next,
|
|
127
|
+
state: nextState$1
|
|
128
|
+
},
|
|
129
|
+
consumed: result$1.consumed
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (result$1.consumed > 0) return result$1;
|
|
133
|
+
const nextState = injectAnnotations({
|
|
134
|
+
[promptBindStateKey]: true,
|
|
135
|
+
hasCliValue: false
|
|
136
|
+
}, annotations);
|
|
137
|
+
return {
|
|
138
|
+
success: true,
|
|
139
|
+
next: {
|
|
140
|
+
...baseInnerContext,
|
|
141
|
+
state: nextState
|
|
142
|
+
},
|
|
143
|
+
consumed: []
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
const result = withAnnotatedInnerState(context.state, effectiveInnerState, (annotatedInnerState) => {
|
|
147
|
+
const innerContext = annotatedInnerState !== context.state ? {
|
|
148
|
+
...context,
|
|
149
|
+
state: annotatedInnerState
|
|
150
|
+
} : context;
|
|
151
|
+
return parser.parse(innerContext);
|
|
152
|
+
});
|
|
153
|
+
if (result instanceof Promise) return result.then(processResult);
|
|
154
|
+
return Promise.resolve(processResult(result));
|
|
155
|
+
},
|
|
156
|
+
complete: (state, exec) => {
|
|
157
|
+
if (isPromptBindState(state) && state.hasCliValue) {
|
|
158
|
+
const r = withAnnotatedInnerState(state, state.cliState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
|
|
159
|
+
if (r instanceof Promise) return r;
|
|
160
|
+
return Promise.resolve(r);
|
|
161
|
+
}
|
|
162
|
+
const isProbe = exec != null && exec.phase !== "complete";
|
|
163
|
+
const annotations = getAnnotations(state);
|
|
164
|
+
const innerInitialState = parser.initialState;
|
|
165
|
+
const shouldInheritInitialStateAnnotations = annotations != null && (innerInitialState == null || typeof innerInitialState === "object");
|
|
166
|
+
const effectiveInitialState = shouldInheritInitialStateAnnotations ? inheritAnnotations(state, innerInitialState) : innerInitialState;
|
|
167
|
+
const readPlaceholder = () => {
|
|
168
|
+
try {
|
|
169
|
+
return "placeholder" in parser ? parser.placeholder : void 0;
|
|
170
|
+
} catch {
|
|
171
|
+
return void 0;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const finalizePrompt = () => {
|
|
175
|
+
const shouldDefer = withAnnotatedInnerState(state, effectiveInitialState, (annotatedInnerState) => shouldDeferPrompt(parser, annotatedInnerState, exec));
|
|
176
|
+
if (shouldDefer) return Promise.resolve(deferredPromptResult(readPlaceholder()));
|
|
177
|
+
if (isProbe) return Promise.resolve({
|
|
178
|
+
success: true,
|
|
179
|
+
value: readPlaceholder()
|
|
180
|
+
});
|
|
181
|
+
return executePrompt();
|
|
182
|
+
};
|
|
183
|
+
const hasDeferHook = typeof parser.shouldDeferCompletion === "function";
|
|
184
|
+
const decideFromParse = (parseResult) => {
|
|
185
|
+
const consumed = parseResult.success ? parseResult.consumed.length : 0;
|
|
186
|
+
const cliState = parseResult.success && consumed === 0 ? parseResult.next.state : void 0;
|
|
187
|
+
const cliStateIsInjected = cliState != null && typeof cliState === "object" && unwrapInjectedAnnotationState(cliState) !== cliState;
|
|
188
|
+
const isSourceBinding = shouldCompleteFromSourceBinding(cliState, state);
|
|
189
|
+
if (!isSourceBinding) return finalizePrompt();
|
|
190
|
+
const completeState = parseResult.success ? parseResult.next.state : effectiveInitialState;
|
|
191
|
+
const innerR = parser.complete(completeState, exec);
|
|
192
|
+
const handleCompleteResult = (res) => {
|
|
193
|
+
if (res.success && res.value === void 0 && cliStateIsInjected) return finalizePrompt();
|
|
194
|
+
if (!res.success) return finalizePrompt();
|
|
195
|
+
return Promise.resolve(res);
|
|
196
|
+
};
|
|
197
|
+
if (innerR instanceof Promise) return innerR.then(handleCompleteResult);
|
|
198
|
+
return handleCompleteResult(innerR);
|
|
199
|
+
};
|
|
200
|
+
if (hasDeferHook) {
|
|
201
|
+
const innerR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
|
|
202
|
+
const handleDeferHookResult = (res) => {
|
|
203
|
+
if (res.success && res.value === void 0) return finalizePrompt();
|
|
204
|
+
if (!res.success) return finalizePrompt();
|
|
205
|
+
return Promise.resolve(res);
|
|
206
|
+
};
|
|
207
|
+
if (innerR instanceof Promise) return innerR.then(handleDeferHookResult);
|
|
208
|
+
return handleDeferHookResult(innerR);
|
|
209
|
+
}
|
|
210
|
+
const simParseR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedState) => parser.parse({
|
|
211
|
+
buffer: [],
|
|
212
|
+
state: annotatedState,
|
|
213
|
+
optionsTerminated: false,
|
|
214
|
+
usage: parser.usage
|
|
215
|
+
}));
|
|
216
|
+
if (simParseR instanceof Promise) return simParseR.then(decideFromParse);
|
|
217
|
+
return decideFromParse(simParseR);
|
|
218
|
+
},
|
|
219
|
+
suggest: (context, prefix) => {
|
|
220
|
+
const innerState = isPromptBindState(context.state) ? context.state.cliState === void 0 ? parser.initialState : context.state.cliState : context.state;
|
|
221
|
+
const innerContext = innerState !== context.state ? {
|
|
222
|
+
...context,
|
|
223
|
+
state: innerState
|
|
224
|
+
} : context;
|
|
225
|
+
const innerResult = parser.suggest(innerContext, prefix);
|
|
226
|
+
return async function* () {
|
|
227
|
+
yield* innerResult;
|
|
228
|
+
}();
|
|
229
|
+
},
|
|
230
|
+
getDocFragments(state, upperDefaultValue) {
|
|
231
|
+
const defaultValue = upperDefaultValue ?? readDefaultValue(adapter, config);
|
|
232
|
+
return parser.getDocFragments(state, defaultValue);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
defineTraits(promptedParser, { inheritsAnnotations: true });
|
|
236
|
+
if ("placeholder" in parser) Object.defineProperty(promptedParser, "placeholder", {
|
|
237
|
+
get() {
|
|
238
|
+
try {
|
|
239
|
+
return parser.placeholder;
|
|
240
|
+
} catch {
|
|
241
|
+
return void 0;
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
configurable: true,
|
|
245
|
+
enumerable: false
|
|
246
|
+
});
|
|
247
|
+
if (typeof parser.normalizeValue === "function") Object.defineProperty(promptedParser, "normalizeValue", {
|
|
248
|
+
value: parser.normalizeValue.bind(parser),
|
|
249
|
+
configurable: true,
|
|
250
|
+
enumerable: false
|
|
251
|
+
});
|
|
252
|
+
const dependencyMetadata = mapSourceMetadata(parser, (source) => ({
|
|
253
|
+
...source,
|
|
254
|
+
extractSourceValue: (state) => {
|
|
255
|
+
if (!isPromptBindState(state)) return source.extractSourceValue(state);
|
|
256
|
+
return source.extractSourceValue(state.cliState ?? state);
|
|
257
|
+
}
|
|
258
|
+
}));
|
|
259
|
+
if (dependencyMetadata != null) Object.defineProperty(promptedParser, "dependencyMetadata", {
|
|
260
|
+
value: dependencyMetadata,
|
|
261
|
+
configurable: true,
|
|
262
|
+
enumerable: false
|
|
263
|
+
});
|
|
264
|
+
return fluent(promptedParser);
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
//#endregion
|
|
269
|
+
export { createPromptAdapter };
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@optique/prompt",
|
|
3
|
+
"version": "1.2.0-dev.0",
|
|
4
|
+
"description": "Generic prompt adapter support for Optique",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"CLI",
|
|
7
|
+
"command-line",
|
|
8
|
+
"commandline",
|
|
9
|
+
"parser",
|
|
10
|
+
"prompt",
|
|
11
|
+
"interactive"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": {
|
|
15
|
+
"name": "Hong Minhee",
|
|
16
|
+
"email": "hong@minhee.org",
|
|
17
|
+
"url": "https://hongminhee.org/"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://optique.dev/",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/dahlia/optique.git",
|
|
23
|
+
"directory": "packages/prompt/"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/dahlia/optique/issues"
|
|
27
|
+
},
|
|
28
|
+
"funding": [
|
|
29
|
+
"https://github.com/sponsors/dahlia"
|
|
30
|
+
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=20.0.0",
|
|
33
|
+
"bun": ">=1.2.0",
|
|
34
|
+
"deno": ">=2.3.0"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist/",
|
|
38
|
+
"package.json",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"type": "module",
|
|
42
|
+
"module": "./dist/index.js",
|
|
43
|
+
"main": "./dist/index.cjs",
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"types": {
|
|
48
|
+
"import": "./dist/index.d.ts",
|
|
49
|
+
"require": "./dist/index.d.cts"
|
|
50
|
+
},
|
|
51
|
+
"import": "./dist/index.js",
|
|
52
|
+
"require": "./dist/index.cjs"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"imports": {
|
|
56
|
+
"#src/*.ts": {
|
|
57
|
+
"node": "./dist/*.js",
|
|
58
|
+
"default": "./src/*.ts"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"sideEffects": false,
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@optique/core": "1.2.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/node": "^24.0.0",
|
|
67
|
+
"fast-check": "^4.7.0",
|
|
68
|
+
"tsdown": "^0.13.0",
|
|
69
|
+
"typescript": "^5.8.3",
|
|
70
|
+
"@optique/config": "1.2.0",
|
|
71
|
+
"@optique/run": "1.2.0",
|
|
72
|
+
"@optique/env": "1.2.0"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build": "tsdown",
|
|
76
|
+
"prepublish": "tsdown",
|
|
77
|
+
"test": "node --test",
|
|
78
|
+
"test:bun": "bun test",
|
|
79
|
+
"test:deno": "deno test",
|
|
80
|
+
"test-all": "tsdown && node --test && bun test && deno test"
|
|
81
|
+
}
|
|
82
|
+
}
|