@optique/prompt 1.3.0-dev.2375 → 1.3.0-dev.2380
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/dist/index.cjs +41 -1
- package/dist/index.js +41 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -88,6 +88,29 @@ function unwrapCompleteResult(result) {
|
|
|
88
88
|
function createPromptAdapter(adapter) {
|
|
89
89
|
return function prompt(parser, config) {
|
|
90
90
|
const promptBindStateKey = Symbol("@optique/prompt/promptState");
|
|
91
|
+
const completionCacheKeys = /* @__PURE__ */ new Map();
|
|
92
|
+
const completionCacheSymbolIds = /* @__PURE__ */ new Map();
|
|
93
|
+
const completionCacheKeyFor = (path) => {
|
|
94
|
+
const serialized = (path ?? []).map((segment) => {
|
|
95
|
+
if (typeof segment === "symbol") {
|
|
96
|
+
let id = completionCacheSymbolIds.get(segment);
|
|
97
|
+
if (id == null) {
|
|
98
|
+
id = completionCacheSymbolIds.size;
|
|
99
|
+
completionCacheSymbolIds.set(segment, id);
|
|
100
|
+
}
|
|
101
|
+
return `y${id}:`;
|
|
102
|
+
}
|
|
103
|
+
const tag = typeof segment === "number" ? "n" : "s";
|
|
104
|
+
const text = String(segment);
|
|
105
|
+
return `${tag}${text.length}:${text}`;
|
|
106
|
+
}).join("");
|
|
107
|
+
let key = completionCacheKeys.get(serialized);
|
|
108
|
+
if (key == null) {
|
|
109
|
+
key = Symbol("@optique/prompt/completionCache");
|
|
110
|
+
completionCacheKeys.set(serialized, key);
|
|
111
|
+
}
|
|
112
|
+
return key;
|
|
113
|
+
};
|
|
91
114
|
function isPromptBindState(value) {
|
|
92
115
|
return value != null && typeof value === "object" && promptBindStateKey in value;
|
|
93
116
|
}
|
|
@@ -214,6 +237,22 @@ function createPromptAdapter(adapter) {
|
|
|
214
237
|
success: true,
|
|
215
238
|
value: readPlaceholder()
|
|
216
239
|
});
|
|
240
|
+
const session = exec?.effectfulCompletionSession;
|
|
241
|
+
const sourceId = promptedParser.dependencyMetadata?.source?.sourceId;
|
|
242
|
+
if (session != null && sourceId != null) {
|
|
243
|
+
const cacheKey = completionCacheKeyFor(exec?.path);
|
|
244
|
+
const cached = session.results.get(cacheKey);
|
|
245
|
+
if (cached != null) {
|
|
246
|
+
session.effectfulSources.add(sourceId);
|
|
247
|
+
return Promise.resolve(cached);
|
|
248
|
+
}
|
|
249
|
+
if (session.policy === "demand-only" && !session.demanded.has(sourceId)) return Promise.resolve(deferredPromptResult(readPlaceholder()));
|
|
250
|
+
return executePrompt().then((result) => {
|
|
251
|
+
session.results.set(cacheKey, result);
|
|
252
|
+
session.effectfulSources.add(sourceId);
|
|
253
|
+
return result;
|
|
254
|
+
});
|
|
255
|
+
}
|
|
217
256
|
return executePrompt();
|
|
218
257
|
};
|
|
219
258
|
const hasDeferHook = typeof parser.shouldDeferCompletion === "function";
|
|
@@ -295,7 +334,8 @@ function createPromptAdapter(adapter) {
|
|
|
295
334
|
extractSourceValue: (state) => {
|
|
296
335
|
if (!isPromptBindState(state)) return source.extractSourceValue(state);
|
|
297
336
|
return source.extractSourceValue(state.cliState ?? state);
|
|
298
|
-
}
|
|
337
|
+
},
|
|
338
|
+
completeSource: source.preservesSourceValue === false ? void 0 : (state, exec) => promptedParser.complete(state, exec)
|
|
299
339
|
}));
|
|
300
340
|
if (dependencyMetadata != null) Object.defineProperty(promptedParser, "dependencyMetadata", {
|
|
301
341
|
value: dependencyMetadata,
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,29 @@ function unwrapCompleteResult(result) {
|
|
|
65
65
|
function createPromptAdapter(adapter) {
|
|
66
66
|
return function prompt(parser, config) {
|
|
67
67
|
const promptBindStateKey = Symbol("@optique/prompt/promptState");
|
|
68
|
+
const completionCacheKeys = /* @__PURE__ */ new Map();
|
|
69
|
+
const completionCacheSymbolIds = /* @__PURE__ */ new Map();
|
|
70
|
+
const completionCacheKeyFor = (path) => {
|
|
71
|
+
const serialized = (path ?? []).map((segment) => {
|
|
72
|
+
if (typeof segment === "symbol") {
|
|
73
|
+
let id = completionCacheSymbolIds.get(segment);
|
|
74
|
+
if (id == null) {
|
|
75
|
+
id = completionCacheSymbolIds.size;
|
|
76
|
+
completionCacheSymbolIds.set(segment, id);
|
|
77
|
+
}
|
|
78
|
+
return `y${id}:`;
|
|
79
|
+
}
|
|
80
|
+
const tag = typeof segment === "number" ? "n" : "s";
|
|
81
|
+
const text = String(segment);
|
|
82
|
+
return `${tag}${text.length}:${text}`;
|
|
83
|
+
}).join("");
|
|
84
|
+
let key = completionCacheKeys.get(serialized);
|
|
85
|
+
if (key == null) {
|
|
86
|
+
key = Symbol("@optique/prompt/completionCache");
|
|
87
|
+
completionCacheKeys.set(serialized, key);
|
|
88
|
+
}
|
|
89
|
+
return key;
|
|
90
|
+
};
|
|
68
91
|
function isPromptBindState(value) {
|
|
69
92
|
return value != null && typeof value === "object" && promptBindStateKey in value;
|
|
70
93
|
}
|
|
@@ -191,6 +214,22 @@ function createPromptAdapter(adapter) {
|
|
|
191
214
|
success: true,
|
|
192
215
|
value: readPlaceholder()
|
|
193
216
|
});
|
|
217
|
+
const session = exec?.effectfulCompletionSession;
|
|
218
|
+
const sourceId = promptedParser.dependencyMetadata?.source?.sourceId;
|
|
219
|
+
if (session != null && sourceId != null) {
|
|
220
|
+
const cacheKey = completionCacheKeyFor(exec?.path);
|
|
221
|
+
const cached = session.results.get(cacheKey);
|
|
222
|
+
if (cached != null) {
|
|
223
|
+
session.effectfulSources.add(sourceId);
|
|
224
|
+
return Promise.resolve(cached);
|
|
225
|
+
}
|
|
226
|
+
if (session.policy === "demand-only" && !session.demanded.has(sourceId)) return Promise.resolve(deferredPromptResult(readPlaceholder()));
|
|
227
|
+
return executePrompt().then((result) => {
|
|
228
|
+
session.results.set(cacheKey, result);
|
|
229
|
+
session.effectfulSources.add(sourceId);
|
|
230
|
+
return result;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
194
233
|
return executePrompt();
|
|
195
234
|
};
|
|
196
235
|
const hasDeferHook = typeof parser.shouldDeferCompletion === "function";
|
|
@@ -272,7 +311,8 @@ function createPromptAdapter(adapter) {
|
|
|
272
311
|
extractSourceValue: (state) => {
|
|
273
312
|
if (!isPromptBindState(state)) return source.extractSourceValue(state);
|
|
274
313
|
return source.extractSourceValue(state.cliState ?? state);
|
|
275
|
-
}
|
|
314
|
+
},
|
|
315
|
+
completeSource: source.preservesSourceValue === false ? void 0 : (state, exec) => promptedParser.complete(state, exec)
|
|
276
316
|
}));
|
|
277
317
|
if (dependencyMetadata != null) Object.defineProperty(promptedParser, "dependencyMetadata", {
|
|
278
318
|
value: dependencyMetadata,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/prompt",
|
|
3
|
-
"version": "1.3.0-dev.
|
|
3
|
+
"version": "1.3.0-dev.2380",
|
|
4
4
|
"description": "Generic prompt adapter support for Optique",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
},
|
|
61
61
|
"sideEffects": false,
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@optique/core": "1.3.0-dev.
|
|
63
|
+
"@optique/core": "1.3.0-dev.2380+4bce39a7"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@optique/config": "1.3.0-dev.
|
|
67
|
-
"@optique/env": "1.3.0-dev.
|
|
68
|
-
"@optique/run": "1.3.0-dev.
|
|
66
|
+
"@optique/config": "1.3.0-dev.2380+4bce39a7",
|
|
67
|
+
"@optique/env": "1.3.0-dev.2380+4bce39a7",
|
|
68
|
+
"@optique/run": "1.3.0-dev.2380+4bce39a7",
|
|
69
69
|
"@types/node": "^24.0.0",
|
|
70
70
|
"fast-check": "^4.7.0",
|
|
71
71
|
"tsdown": "^0.13.0",
|