promptlike 0.6.0 → 0.6.2
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/CHANGELOG.md +42 -1
- package/README.md +3 -1
- package/dist/commands/import.js +3 -1
- package/dist/lib/api-client.js +160 -10
- package/dist/lib/loopApi.js +35 -4
- package/dist/lib/promptResolver.js +36 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.6.
|
|
3
|
+
## 0.6.2 — 2026-10-12
|
|
4
|
+
|
|
5
|
+
- **Fix:** a network problem while your session is being refreshed (no DNS,
|
|
6
|
+
connection refused, a dropped Wi-Fi) no longer says "Session expired. Log in
|
|
7
|
+
again". It now says the server could not be reached: check your connection
|
|
8
|
+
and run the command again. Your saved login is kept. A temporary server
|
|
9
|
+
problem during the refresh (busy, rate limited, 5xx) asks you to run the
|
|
10
|
+
command again in a moment and keeps your login; only if it keeps happening
|
|
11
|
+
does it suggest `ple login`. Only a definite rejection from the server (the
|
|
12
|
+
refresh token expired, was revoked or was already used) still asks you to log
|
|
13
|
+
in again right away. Nothing is retried automatically.
|
|
14
|
+
- **Fix:** when the session refresh itself gets no answer within 30 s, the
|
|
15
|
+
message no longer says "the server may still have completed the request;
|
|
16
|
+
check before retrying" (that warning is for your own writes and was
|
|
17
|
+
misleading on read commands). It now says the refresh did not finish and to
|
|
18
|
+
run the command again; if it then reports an expired session, run `ple login`.
|
|
19
|
+
|
|
20
|
+
## 0.6.1 — 2026-10-12
|
|
21
|
+
|
|
22
|
+
- **Fix:** `ple <name>` commands (show, copy, get, log, ...) now find a prompt by its
|
|
23
|
+
8-character short id even when your library has more than 100 prompts. The
|
|
24
|
+
lookup used to read only the newest 100 and answered "No prompt matched" for
|
|
25
|
+
anything older; it now walks the pages (newest first, up to 2000 prompts) and
|
|
26
|
+
stops at the first page with a match.
|
|
27
|
+
- **Fix:** `ple loop` / `ple improve` no longer sit on a stuck server for about
|
|
28
|
+
five minutes (Node's built-in limit, which ended in a bare "fetch failed"):
|
|
29
|
+
variant generation gives up after 120 s and saving the winner after 30 s,
|
|
30
|
+
with a plain "No response from <url>" message.
|
|
31
|
+
- **Fix:** every other command that talks to the server no longer sits on a
|
|
32
|
+
stuck connection for about five minutes either: reads (list, show, search,
|
|
33
|
+
log, stats, ...) give up after 15 s, login and rollback after 30 s,
|
|
34
|
+
`ple import` / `ple sync` uploads after 120 s. After a write times out the
|
|
35
|
+
message says the server may still have finished, so check before running it
|
|
36
|
+
again.
|
|
37
|
+
- **Fix:** when `ple import --scan` stops at your plan's prompt limit, the hint
|
|
38
|
+
now reads "Upgrade to Pro to bring the rest" instead of promising a 14-day
|
|
39
|
+
trial that may not be on offer.
|
|
40
|
+
- **Security (dev only):** `source-map-js` is patched in the lock file
|
|
41
|
+
(GHSA-68fv-2mgg-jv7q). It is only used by the test tooling and was never part
|
|
42
|
+
of the published package; `npm audit` now reports 0 vulnerabilities.
|
|
43
|
+
|
|
44
|
+
## 0.6.0 — 2026-09-27
|
|
4
45
|
|
|
5
46
|
Your library, where you already work.
|
|
6
47
|
|
package/README.md
CHANGED
|
@@ -581,7 +581,9 @@ out of the published tarball — only `dist/`, `LICENSE`, and `README.md` ship.
|
|
|
581
581
|
| Symptom | Cause | Fix |
|
|
582
582
|
|---|---|---|
|
|
583
583
|
| `Not logged in. Run ple login first.` | No session on disk | `ple login` |
|
|
584
|
-
| `Session expired. Log in again: ple login` |
|
|
584
|
+
| `Session expired. Log in again: ple login` | The server rejected the refresh token (expired, revoked or already used) | `ple login` again |
|
|
585
|
+
| `Cannot reach <url>. Could not refresh your session…` | Network problem while refreshing the session | Check your connection and run the command again; your saved login is kept |
|
|
586
|
+
| `Could not refresh your session right now (…)` | The server could not refresh the session for a moment (busy, rate limited) | Run the command again in a moment; your saved login is kept. If it keeps happening, run `ple login` |
|
|
585
587
|
| `Invalid email or password. If you signed up with Google…` | OAuth-only account has no password | Set a password in Account settings on the web, then `ple login` |
|
|
586
588
|
| `Clipboard command (xclip) not found` | Linux without xclip / wl-copy | `apt install xclip` (X11) or `apt install wl-clipboard` (Wayland) |
|
|
587
589
|
| `No prompt matched 'X'.` | Name doesn't match anything | Run `ple list` to see real titles |
|
package/dist/commands/import.js
CHANGED
|
@@ -240,7 +240,9 @@ async function importCommand(options = {}, deps = {}) {
|
|
|
240
240
|
console.log(format_1.c.warn(`⚠ Stopped early: ${abortMessage}`));
|
|
241
241
|
if (truncatedByQuota > 0) {
|
|
242
242
|
console.log(format_1.c.warn(`⚠ ${truncatedByQuota} not imported — plan prompt limit reached.`));
|
|
243
|
-
|
|
243
|
+
// Deneme vaadi YOK: deneme web'de bayrakla (NEXT_PUBLIC_PRO_TRIAL_DAYS) açılır
|
|
244
|
+
// kapanır; CLI bayrağı bilemez, kapalıyken "14-day trial" yanlış söz olurdu.
|
|
245
|
+
console.log(format_1.c.muted(` Upgrade to Pro to bring the rest: ${constants_1.WEB_APP_URL}/pricing`));
|
|
244
246
|
console.log(format_1.c.muted(' Then run `ple import --scan` again — what already came in is skipped.'));
|
|
245
247
|
}
|
|
246
248
|
if (failed > 0)
|
package/dist/lib/api-client.js
CHANGED
|
@@ -12,9 +12,14 @@
|
|
|
12
12
|
* - attach the bearer token, resolve URLs against API_BASE_URL
|
|
13
13
|
* - proactive refresh (expiring token) + reactive refresh on 401, retry once
|
|
14
14
|
* - map 429 / error bodies to clean, user-facing Error messages
|
|
15
|
+
* - bound every request with a timeout (O5 / PLE-03): a server that keeps the
|
|
16
|
+
* connection open without answering must not hang a command forever
|
|
17
|
+
* - only a definitive refresh rejection means "session expired" (O11): a
|
|
18
|
+
* network error or a temporary server failure keeps the saved login
|
|
15
19
|
*/
|
|
16
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.USE_SURFACES = void 0;
|
|
21
|
+
exports.USE_SURFACES = exports.NetworkError = exports.ApiError = exports.DEFINITIVE_REFRESH_CODES = exports.REFRESH_UNAVAILABLE_LAST_RESORT = exports.REFRESH_NETWORK_ADVICE = exports.REFRESH_TIMEOUT_ADVICE = exports.RequestTimeoutError = exports.USE_EVENT_TIMEOUT_MS = exports.IMPORT_TIMEOUT_MS = exports.WRITE_TIMEOUT_MS = exports.READ_TIMEOUT_MS = void 0;
|
|
22
|
+
exports.refreshUnavailableMessage = refreshUnavailableMessage;
|
|
18
23
|
exports.login = login;
|
|
19
24
|
exports.ensureAuthed = ensureAuthed;
|
|
20
25
|
exports.listPrompts = listPrompts;
|
|
@@ -32,6 +37,120 @@ const constants_1 = require("./constants");
|
|
|
32
37
|
const config_1 = require("./config");
|
|
33
38
|
const NOT_LOGGED_IN = 'Not logged in. Run `ple login` first.';
|
|
34
39
|
const SESSION_EXPIRED = 'Session expired. Log in again: `ple login`';
|
|
40
|
+
/**
|
|
41
|
+
* İstek zaman aşımları (O5 / PLE-03). Süre yalnız başlıkları değil gövde
|
|
42
|
+
* okumasını da kapsar (aynı sinyal). Otomatik tekrar deneme YOK: zaman aşımına
|
|
43
|
+
* uğrayan bir yazma sunucuda tamamlanmış olabilir, körü körüne tekrar çift kayıt
|
|
44
|
+
* yapabilir; bu yüzden yazma iletisi "önce kontrol et" der.
|
|
45
|
+
*/
|
|
46
|
+
/** GET istekleri (liste, detay, içgörü): hafif okumalar. */
|
|
47
|
+
exports.READ_TIMEOUT_MS = 15000;
|
|
48
|
+
/** GET dışı istekler (giriş, yenileme, geri alma). */
|
|
49
|
+
exports.WRITE_TIMEOUT_MS = 30000;
|
|
50
|
+
/** Toplu içe aktarma: istek başına 50 kayda kadar, kayıt başına birkaç sorgu. */
|
|
51
|
+
exports.IMPORT_TIMEOUT_MS = 120000;
|
|
52
|
+
/** Kullanım kaydı (fire-and-forget): asılı sunucu komutun çıkışını bekletmesin. */
|
|
53
|
+
exports.USE_EVENT_TIMEOUT_MS = 5000;
|
|
54
|
+
/** Zaman aşımı hatası — `refreshSession` bunu "oturum bitti"ye çevirmesin diye ayrı sınıf. */
|
|
55
|
+
class RequestTimeoutError extends Error {
|
|
56
|
+
constructor(timeoutMs, method, advice) {
|
|
57
|
+
const defaultAdvice = method === 'GET'
|
|
58
|
+
? 'Check your connection and try again.'
|
|
59
|
+
: 'The server may still have completed the request; check before retrying.';
|
|
60
|
+
super(`No response from ${constants_1.API_BASE_URL} within ${Math.round(timeoutMs / 1000)}s. ${advice ?? defaultAdvice}`);
|
|
61
|
+
this.timeoutMs = timeoutMs;
|
|
62
|
+
this.name = 'RequestTimeoutError';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.RequestTimeoutError = RequestTimeoutError;
|
|
66
|
+
/**
|
|
67
|
+
* Oturum yenileme zaman aşımına uğradığında kullanıcıya söylenecek şey. Yenileme
|
|
68
|
+
* kullanıcının komutu değil, arka plandaki bir POST'tur; "yazma sunucuda
|
|
69
|
+
* tamamlanmış olabilir, önce kontrol et" uyarısı okuma komutunda bile çıkıp
|
|
70
|
+
* yanıltırdı. Sunucu yenilemeyi tamamlamış ama yeni token yerelde saklanmamış
|
|
71
|
+
* olabilir; bu durumda bir sonraki çalıştırma "Session expired" der.
|
|
72
|
+
*/
|
|
73
|
+
exports.REFRESH_TIMEOUT_ADVICE = 'Session refresh did not finish. Run the command again; if it then says the session expired, run `ple login`.';
|
|
74
|
+
/**
|
|
75
|
+
* Yenileme isteği sunucuya hiç ulaşamadığında (DNS, bağlantı reddi, kopma; O11).
|
|
76
|
+
* Ağ hatası oturumun bittiğini göstermez: yerel oturum silinmez (yalnız `ple
|
|
77
|
+
* logout` siler), kullanıcı gereksiz yere `ple login`'e yönlendirilmez.
|
|
78
|
+
*/
|
|
79
|
+
exports.REFRESH_NETWORK_ADVICE = 'Could not refresh your session: check your connection and run the command again. Your saved login is kept.';
|
|
80
|
+
/**
|
|
81
|
+
* Sunucu yenilemeyi kesin reddetmedi ama tamamlayamadı (503 + Retry-After, 429,
|
|
82
|
+
* 5xx, tanınmayan yanıt; O11). Web `/api/auth/cli/refresh` sözleşmesi: bunlar
|
|
83
|
+
* geçicidir, oturum korunur, sonra yeniden denenir. Otomatik tekrar YOK.
|
|
84
|
+
* Son çare cümlesi: web tanınmayan üst servis hatasını (kodsuz 401/403, yeni bir
|
|
85
|
+
* GoTrue kodu) da 503 geçici sayar; refresh token gerçekten iptal edilmişse
|
|
86
|
+
* kullanıcı "az sonra tekrar dene"de takılı kalmasın.
|
|
87
|
+
*/
|
|
88
|
+
exports.REFRESH_UNAVAILABLE_LAST_RESORT = 'If this keeps happening, run `ple login`.';
|
|
89
|
+
function refreshUnavailableMessage(detail) {
|
|
90
|
+
return `Could not refresh your session right now (${detail}). Run the command again in a moment; your saved login is kept. ${exports.REFRESH_UNAVAILABLE_LAST_RESORT}`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Sunucunun yenilemeyi KESİN reddettiğini gösteren yanıt kodları (O11). Web
|
|
94
|
+
* `src/app/api/auth/cli/refresh/_handlers/classify.ts` DEFINITIVE_CODES (GoTrue
|
|
95
|
+
* `error_code`) ile aynı liste + rotanın kendi `SESSION_EXPIRED` kodu; tutarlılık
|
|
96
|
+
* `api-client.refresh.test.ts` ile kilitli. Yalnız bunlar (ya da 401 / 400)
|
|
97
|
+
* "Session expired" sayılır; tanınmayan her şey geçicidir (emin değilsen oturumu bitirme).
|
|
98
|
+
*/
|
|
99
|
+
exports.DEFINITIVE_REFRESH_CODES = new Set([
|
|
100
|
+
'SESSION_EXPIRED',
|
|
101
|
+
'refresh_token_not_found',
|
|
102
|
+
'refresh_token_already_used',
|
|
103
|
+
'session_expired',
|
|
104
|
+
'session_not_found',
|
|
105
|
+
'invalid_grant',
|
|
106
|
+
'user_not_found',
|
|
107
|
+
'user_banned',
|
|
108
|
+
'validation_failed',
|
|
109
|
+
]);
|
|
110
|
+
/** HTTP hatası; durum kodu ve sunucu kodu korunur (yenileme sınıflaması için). İleti değişmedi. */
|
|
111
|
+
class ApiError extends Error {
|
|
112
|
+
constructor(message, status, code) {
|
|
113
|
+
super(message);
|
|
114
|
+
this.status = status;
|
|
115
|
+
this.code = code;
|
|
116
|
+
this.name = 'ApiError';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.ApiError = ApiError;
|
|
120
|
+
/** İstek sunucuya ulaşamadı (DNS, bağlantı reddi, kopma). Varsayılan ileti eskisiyle aynı. */
|
|
121
|
+
class NetworkError extends Error {
|
|
122
|
+
constructor(detail, advice = 'Check your connection.') {
|
|
123
|
+
super(`Cannot reach ${constants_1.API_BASE_URL}. ${advice} (${detail})`);
|
|
124
|
+
this.detail = detail;
|
|
125
|
+
this.name = 'NetworkError';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.NetworkError = NetworkError;
|
|
129
|
+
/**
|
|
130
|
+
* Yenileme yanıtı oturumun gerçekten bittiğini mi söylüyor? Web sözleşmesi:
|
|
131
|
+
* 401 SESSION_EXPIRED (kesin ret) ve 400 (refresh_token eksik: yerel oturum
|
|
132
|
+
* kaydı bozuk) kesindir; 503 / 429 / 5xx / ağ / zaman aşımı geçicidir.
|
|
133
|
+
*/
|
|
134
|
+
function isDefinitiveRefreshRejection(err) {
|
|
135
|
+
if (!(err instanceof ApiError))
|
|
136
|
+
return false;
|
|
137
|
+
if (err.status === 401 || err.status === 400)
|
|
138
|
+
return true;
|
|
139
|
+
return err.code !== undefined && exports.DEFINITIVE_REFRESH_CODES.has(err.code);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Hata süre aşımından mı geldi? Önce sinyalin kendisine bakılır: eski Node /
|
|
143
|
+
* undici sürümlerinde gövde okuması yarıda kesilince hata `TimeoutError` yerine
|
|
144
|
+
* `TypeError: terminated` gibi başka biçimde gelebilir; sinyal `aborted` ise
|
|
145
|
+
* sebep süre dolmasıdır, hatanın biçimi önemsizdir. Ad kontrolü yedektir
|
|
146
|
+
* (AbortSignal.timeout → `TimeoutError`, iptal → `AbortError`).
|
|
147
|
+
*/
|
|
148
|
+
function isTimeout(err, signal) {
|
|
149
|
+
if (signal.aborted)
|
|
150
|
+
return true;
|
|
151
|
+
const name = err?.name;
|
|
152
|
+
return name === 'TimeoutError' || name === 'AbortError';
|
|
153
|
+
}
|
|
35
154
|
/**
|
|
36
155
|
* Fallback messages for server error codes. The API almost always sends a
|
|
37
156
|
* human-readable `error` string; this map is only used when a response carries
|
|
@@ -73,12 +192,13 @@ async function toError(res) {
|
|
|
73
192
|
catch {
|
|
74
193
|
// Non-JSON error body — fall back to a generic message below.
|
|
75
194
|
}
|
|
195
|
+
const code = typeof body.code === 'string' ? body.code : undefined;
|
|
76
196
|
if (body.error)
|
|
77
|
-
return new
|
|
78
|
-
if (
|
|
79
|
-
return new
|
|
197
|
+
return new ApiError(body.error, res.status, code);
|
|
198
|
+
if (code && ERROR_FALLBACKS[code]) {
|
|
199
|
+
return new ApiError(ERROR_FALLBACKS[code], res.status, code);
|
|
80
200
|
}
|
|
81
|
-
return new
|
|
201
|
+
return new ApiError(`Request failed (${res.status}).`, res.status, code);
|
|
82
202
|
}
|
|
83
203
|
function getAccessTokenOrThrow() {
|
|
84
204
|
const config = (0, config_1.readConfig)();
|
|
@@ -112,14 +232,27 @@ async function refreshSession() {
|
|
|
112
232
|
auth: false,
|
|
113
233
|
});
|
|
114
234
|
}
|
|
115
|
-
catch {
|
|
116
|
-
|
|
235
|
+
catch (err) {
|
|
236
|
+
// Asılı sunucu "oturumun bitti, yeniden giriş yap" demek değildir.
|
|
237
|
+
if (err instanceof RequestTimeoutError) {
|
|
238
|
+
throw new RequestTimeoutError(err.timeoutMs, 'POST', exports.REFRESH_TIMEOUT_ADVICE);
|
|
239
|
+
}
|
|
240
|
+
// Yalnız sunucunun kesin reddi oturumu bitirir (O11).
|
|
241
|
+
if (isDefinitiveRefreshRejection(err))
|
|
242
|
+
throw new Error(SESSION_EXPIRED);
|
|
243
|
+
// Ağ hatası (DNS, bağlantı reddi): sunucuya ulaşılamadı, oturum hakkında bilgi yok.
|
|
244
|
+
if (err instanceof NetworkError)
|
|
245
|
+
throw new NetworkError(err.detail, exports.REFRESH_NETWORK_ADVICE);
|
|
246
|
+
// 503 / 429 / 5xx / tanınmayan yanıt: geçici; yerel oturum korunur.
|
|
247
|
+
throw new Error(refreshUnavailableMessage(err instanceof Error ? err.message : String(err)));
|
|
117
248
|
}
|
|
118
249
|
persist(data);
|
|
119
250
|
}
|
|
120
251
|
/** Core request helper. See module doc for behavior. */
|
|
121
252
|
async function apiFetch(path, opts = {}) {
|
|
122
253
|
const { method = 'GET', body, query, auth = true } = opts;
|
|
254
|
+
const timeoutMs = opts.timeoutMs ?? (method === 'GET' ? exports.READ_TIMEOUT_MS : exports.WRITE_TIMEOUT_MS);
|
|
255
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
123
256
|
const headers = {
|
|
124
257
|
'Content-Type': 'application/json',
|
|
125
258
|
// REV-6: sunucu CLI surumunu bilsin — eski CLI + degismis API semasi
|
|
@@ -135,10 +268,14 @@ async function apiFetch(path, opts = {}) {
|
|
|
135
268
|
method,
|
|
136
269
|
headers,
|
|
137
270
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
271
|
+
// Süre başlıkla sınırlı değil: gövde okuması da aynı sinyalle kesilir.
|
|
272
|
+
signal,
|
|
138
273
|
});
|
|
139
274
|
}
|
|
140
275
|
catch (err) {
|
|
141
|
-
|
|
276
|
+
if (isTimeout(err, signal))
|
|
277
|
+
throw new RequestTimeoutError(timeoutMs, method);
|
|
278
|
+
throw new NetworkError(err instanceof Error ? err.message : String(err));
|
|
142
279
|
}
|
|
143
280
|
// Reactive refresh: expired/invalid access token → refresh once, retry once.
|
|
144
281
|
if (res.status === 401 && auth) {
|
|
@@ -154,7 +291,15 @@ async function apiFetch(path, opts = {}) {
|
|
|
154
291
|
if (!res.ok) {
|
|
155
292
|
throw await toError(res);
|
|
156
293
|
}
|
|
157
|
-
|
|
294
|
+
try {
|
|
295
|
+
return (await res.json());
|
|
296
|
+
}
|
|
297
|
+
catch (err) {
|
|
298
|
+
// Başlıklar geldi, gövde yarıda kaldı ve süre doldu.
|
|
299
|
+
if (isTimeout(err, signal))
|
|
300
|
+
throw new RequestTimeoutError(timeoutMs, method);
|
|
301
|
+
throw err;
|
|
302
|
+
}
|
|
158
303
|
}
|
|
159
304
|
// ---------------------------------------------------------------------------
|
|
160
305
|
// Public surface used by commands / the resolver
|
|
@@ -206,6 +351,7 @@ async function importPrompts(prompts, options = {}) {
|
|
|
206
351
|
const res = await apiFetch('/api/prompts/import', {
|
|
207
352
|
method: 'POST',
|
|
208
353
|
body: { prompts, ...options },
|
|
354
|
+
timeoutMs: exports.IMPORT_TIMEOUT_MS,
|
|
209
355
|
});
|
|
210
356
|
return {
|
|
211
357
|
imported: res.imported ?? 0,
|
|
@@ -312,7 +458,11 @@ function buildUseEventBody(opts = {}, env = process.env) {
|
|
|
312
458
|
* komutu asla kırmaz.
|
|
313
459
|
*/
|
|
314
460
|
function recordPromptUse(promptId, opts = {}) {
|
|
315
|
-
apiFetch(`/api/prompts/${promptId}/use`, {
|
|
461
|
+
apiFetch(`/api/prompts/${promptId}/use`, {
|
|
462
|
+
method: 'POST',
|
|
463
|
+
body: buildUseEventBody(opts),
|
|
464
|
+
timeoutMs: exports.USE_EVENT_TIMEOUT_MS,
|
|
465
|
+
}).catch(() => {
|
|
316
466
|
/* sessiz — telemetri */
|
|
317
467
|
});
|
|
318
468
|
}
|
package/dist/lib/loopApi.js
CHANGED
|
@@ -9,10 +9,17 @@
|
|
|
9
9
|
* first, so the token is fresh).
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SAVE_TIMEOUT_MS = exports.VARIANTS_TIMEOUT_MS = void 0;
|
|
12
13
|
exports.requestVariants = requestVariants;
|
|
13
14
|
exports.saveWinner = saveWinner;
|
|
14
15
|
const constants_1 = require("./constants");
|
|
15
16
|
const config_1 = require("./config");
|
|
17
|
+
/**
|
|
18
|
+
* İstek zaman aşımları: sunucu takılırsa `ple loop` / `ple improve` sonsuza dek beklemesin.
|
|
19
|
+
* Varyant üretimi bir LLM çağrısı (genelde 10-40 sn), kayıt hafif bir yazma.
|
|
20
|
+
*/
|
|
21
|
+
exports.VARIANTS_TIMEOUT_MS = 120000;
|
|
22
|
+
exports.SAVE_TIMEOUT_MS = 30000;
|
|
16
23
|
const NOT_LOGGED_IN = 'Not logged in. Run `ple login` first.';
|
|
17
24
|
const SESSION_EXPIRED = 'Session expired. Log in again: `ple login`';
|
|
18
25
|
/** The Pro upsell suffix — appended to every 403 from the loop endpoints. */
|
|
@@ -20,15 +27,32 @@ function proMessage(serverError) {
|
|
|
20
27
|
const base = serverError?.trim() || 'Loop requires Pro';
|
|
21
28
|
return `${base} — upgrade at ${constants_1.API_BASE_URL}/pricing`;
|
|
22
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Hata süre aşımından mı geldi? Önce sinyalin kendisine bakılır: eski Node /
|
|
32
|
+
* undici sürümlerinde gövde okuması yarıda kesilince hata `TimeoutError` yerine
|
|
33
|
+
* `TypeError: terminated` gibi başka biçimde gelebilir; sinyal `aborted` ise
|
|
34
|
+
* sebep süre dolmasıdır. Ad kontrolü yedektir (api-client.ts ile aynı kural).
|
|
35
|
+
*/
|
|
36
|
+
function isTimeout(err, signal) {
|
|
37
|
+
if (signal.aborted)
|
|
38
|
+
return true;
|
|
39
|
+
const name = err?.name;
|
|
40
|
+
return name === 'TimeoutError' || name === 'AbortError';
|
|
41
|
+
}
|
|
42
|
+
function timeoutError(timeoutMs) {
|
|
43
|
+
return new Error(`No response from ${constants_1.API_BASE_URL} within ${Math.round(timeoutMs / 1000)}s. ` +
|
|
44
|
+
'The server may still be working on it; wait a moment, then try again.');
|
|
45
|
+
}
|
|
23
46
|
/**
|
|
24
47
|
* Minimal bearer POST used by the two loop calls. Mirrors the error mapping
|
|
25
48
|
* of `api-client.ts` (network / 401 / 403 / 429 / error body) without the
|
|
26
49
|
* refresh-retry machinery — `ensureAuthed()` has already refreshed the token.
|
|
27
50
|
*/
|
|
28
|
-
async function bearerPost(path, body) {
|
|
51
|
+
async function bearerPost(path, body, timeoutMs) {
|
|
29
52
|
const config = (0, config_1.readConfig)();
|
|
30
53
|
if (!config)
|
|
31
54
|
throw new Error(NOT_LOGGED_IN);
|
|
55
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
32
56
|
let res;
|
|
33
57
|
try {
|
|
34
58
|
res = await fetch(constants_1.API_BASE_URL + path, {
|
|
@@ -38,9 +62,13 @@ async function bearerPost(path, body) {
|
|
|
38
62
|
Authorization: `Bearer ${config.access_token}`,
|
|
39
63
|
},
|
|
40
64
|
body: JSON.stringify(body),
|
|
65
|
+
// Süre başlıkla sınırlı değil: gövde okuması da aynı sinyalle kesilir.
|
|
66
|
+
signal,
|
|
41
67
|
});
|
|
42
68
|
}
|
|
43
69
|
catch (err) {
|
|
70
|
+
if (isTimeout(err, signal))
|
|
71
|
+
throw timeoutError(timeoutMs);
|
|
44
72
|
throw new Error(`Cannot reach ${constants_1.API_BASE_URL}. Check your connection. (${err instanceof Error ? err.message : String(err)})`);
|
|
45
73
|
}
|
|
46
74
|
if (res.status === 401)
|
|
@@ -49,7 +77,10 @@ async function bearerPost(path, body) {
|
|
|
49
77
|
try {
|
|
50
78
|
parsed = (await res.json());
|
|
51
79
|
}
|
|
52
|
-
catch {
|
|
80
|
+
catch (err) {
|
|
81
|
+
// Gövde yarıda kaldı ve süre doldu: "Request failed" değil, zaman aşımı de.
|
|
82
|
+
if (isTimeout(err, signal))
|
|
83
|
+
throw timeoutError(timeoutMs);
|
|
53
84
|
// Non-JSON body — fall through to the generic messages below.
|
|
54
85
|
}
|
|
55
86
|
// Pro gate → 403; tükenen AI token bütçesi → 402 (ApiErrors.insufficientTokens).
|
|
@@ -83,7 +114,7 @@ async function requestVariants(promptId, opts = {}) {
|
|
|
83
114
|
body.count = opts.count;
|
|
84
115
|
if (opts.focus !== undefined && opts.focus.trim() !== '')
|
|
85
116
|
body.focus = opts.focus.trim();
|
|
86
|
-
const res = await bearerPost(`/api/prompts/${promptId}/variants`, body);
|
|
117
|
+
const res = await bearerPost(`/api/prompts/${promptId}/variants`, body, exports.VARIANTS_TIMEOUT_MS);
|
|
87
118
|
return { variants: res.variants ?? [], tokensUsed: res.tokensUsed ?? 0 };
|
|
88
119
|
}
|
|
89
120
|
/**
|
|
@@ -100,5 +131,5 @@ async function saveWinner(promptId, variant, changelog) {
|
|
|
100
131
|
contextText: variant.context || '',
|
|
101
132
|
changelog,
|
|
102
133
|
source: 'cli',
|
|
103
|
-
});
|
|
134
|
+
}, exports.SAVE_TIMEOUT_MS);
|
|
104
135
|
}
|
|
@@ -7,6 +7,13 @@ const format_1 = require("./format");
|
|
|
7
7
|
const api_client_1 = require("./api-client");
|
|
8
8
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
9
9
|
const SHORT_ID_RE = /^[0-9a-f]{8,}$/i;
|
|
10
|
+
/** Server cap per page (GET /api/prompts maxLimit). */
|
|
11
|
+
const PAGE_LIMIT = 100;
|
|
12
|
+
/**
|
|
13
|
+
* Upper bound for the short-id walk: 20 pages x 100 = 2000 prompts (newest first). Keeps a
|
|
14
|
+
* worst-case lookup at 20 requests, well inside the per-minute read budget.
|
|
15
|
+
*/
|
|
16
|
+
const MAX_ID_PAGES = 20;
|
|
10
17
|
/**
|
|
11
18
|
* Resolve a `--project <value>` argument (UUID, exact name, or slug) to a
|
|
12
19
|
* project id. Throws a friendly error when it matches zero or multiple repos.
|
|
@@ -30,7 +37,8 @@ async function resolveProjectId(value) {
|
|
|
30
37
|
/**
|
|
31
38
|
* Resolve a user-supplied `<name>` argument to a single prompt.
|
|
32
39
|
* - Full UUID → direct detail lookup.
|
|
33
|
-
* - 8+ hex-char short-id prefix →
|
|
40
|
+
* - 8+ hex-char short-id prefix → walk the user's prompts page by page (newest
|
|
41
|
+
* first) and match the prefix client-side; stops at the first page with a hit.
|
|
34
42
|
* - Otherwise → title/description search (server-side, escaped), preferring
|
|
35
43
|
* title matches.
|
|
36
44
|
* - One match → return it. Multiple → print the candidates and return null.
|
|
@@ -55,11 +63,9 @@ async function resolvePromptByName(name, scope = {}) {
|
|
|
55
63
|
}
|
|
56
64
|
// Not found by id — fall through to a title search.
|
|
57
65
|
}
|
|
58
|
-
// 2) Short-id prefix (hex, 8+ chars, not a full UUID) →
|
|
66
|
+
// 2) Short-id prefix (hex, 8+ chars, not a full UUID) → walk the pages.
|
|
59
67
|
if (!UUID_RE.test(trimmed) && SHORT_ID_RE.test(trimmed)) {
|
|
60
|
-
const
|
|
61
|
-
const lower = trimmed.toLowerCase();
|
|
62
|
-
const matches = page.filter((p) => p.id.toLowerCase().startsWith(lower));
|
|
68
|
+
const matches = await findByShortId(trimmed, projectId);
|
|
63
69
|
if (matches.length === 1)
|
|
64
70
|
return matches[0];
|
|
65
71
|
if (matches.length > 1) {
|
|
@@ -87,6 +93,31 @@ async function resolvePromptByName(name, scope = {}) {
|
|
|
87
93
|
printAmbiguous(trimmed, pool);
|
|
88
94
|
return null;
|
|
89
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Walks GET /api/prompts page by page (updated_at desc, stable id tie-break) and returns the
|
|
98
|
+
* prompts whose id starts with `prefix`. Stops at the first page that has a hit (that page's
|
|
99
|
+
* hits are all returned, so same-page ambiguity is still reported), on the last (short) page,
|
|
100
|
+
* after MAX_ID_PAGES, or if the server ignores `page` and repeats the first page.
|
|
101
|
+
* Before this, only the first 100 prompts were looked at, so a user with 100+ prompts got
|
|
102
|
+
* "not found" (or a wrong title-search fallback) for any older prompt's short id.
|
|
103
|
+
*/
|
|
104
|
+
async function findByShortId(prefix, projectId) {
|
|
105
|
+
const lower = prefix.toLowerCase();
|
|
106
|
+
let firstId;
|
|
107
|
+
for (let page = 1; page <= MAX_ID_PAGES; page++) {
|
|
108
|
+
const rows = await (0, api_client_1.listPrompts)({ limit: PAGE_LIMIT, page, projectId });
|
|
109
|
+
const matches = rows.filter((p) => p.id.toLowerCase().startsWith(lower));
|
|
110
|
+
if (matches.length > 0)
|
|
111
|
+
return matches;
|
|
112
|
+
if (rows.length < PAGE_LIMIT)
|
|
113
|
+
break; // last page
|
|
114
|
+
if (page === 1)
|
|
115
|
+
firstId = rows[0]?.id;
|
|
116
|
+
else if (rows[0]?.id === firstId)
|
|
117
|
+
break; // server ignored `page` → same rows again
|
|
118
|
+
}
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
90
121
|
function printAmbiguous(query, rows) {
|
|
91
122
|
console.error(format_1.c.warn(`'${query}' matched multiple prompts. Narrow with --project <repo>, or use a short id:`));
|
|
92
123
|
for (const r of rows.slice(0, 10)) {
|
package/package.json
CHANGED