promptlike 0.6.0 → 0.6.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/CHANGELOG.md +25 -1
- package/dist/commands/import.js +3 -1
- package/dist/lib/api-client.js +66 -4
- 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,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.6.
|
|
3
|
+
## 0.6.1 — 2026-10-12
|
|
4
|
+
|
|
5
|
+
- **Fix:** `ple <name>` commands (show, copy, get, log, ...) now find a prompt by its
|
|
6
|
+
8-character short id even when your library has more than 100 prompts. The
|
|
7
|
+
lookup used to read only the newest 100 and answered "No prompt matched" for
|
|
8
|
+
anything older; it now walks the pages (newest first, up to 2000 prompts) and
|
|
9
|
+
stops at the first page with a match.
|
|
10
|
+
- **Fix:** `ple loop` / `ple improve` no longer sit on a stuck server for about
|
|
11
|
+
five minutes (Node's built-in limit, which ended in a bare "fetch failed"):
|
|
12
|
+
variant generation gives up after 120 s and saving the winner after 30 s,
|
|
13
|
+
with a plain "No response from <url>" message.
|
|
14
|
+
- **Fix:** every other command that talks to the server no longer sits on a
|
|
15
|
+
stuck connection for about five minutes either: reads (list, show, search,
|
|
16
|
+
log, stats, ...) give up after 15 s, login and rollback after 30 s,
|
|
17
|
+
`ple import` / `ple sync` uploads after 120 s. After a write times out the
|
|
18
|
+
message says the server may still have finished, so check before running it
|
|
19
|
+
again.
|
|
20
|
+
- **Fix:** when `ple import --scan` stops at your plan's prompt limit, the hint
|
|
21
|
+
now reads "Upgrade to Pro to bring the rest" instead of promising a 14-day
|
|
22
|
+
trial that may not be on offer.
|
|
23
|
+
- **Security (dev only):** `source-map-js` is patched in the lock file
|
|
24
|
+
(GHSA-68fv-2mgg-jv7q). It is only used by the test tooling and was never part
|
|
25
|
+
of the published package; `npm audit` now reports 0 vulnerabilities.
|
|
26
|
+
|
|
27
|
+
## 0.6.0 — 2026-09-27
|
|
4
28
|
|
|
5
29
|
Your library, where you already work.
|
|
6
30
|
|
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,11 @@
|
|
|
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
|
|
15
17
|
*/
|
|
16
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.USE_SURFACES = void 0;
|
|
19
|
+
exports.USE_SURFACES = exports.RequestTimeoutError = exports.USE_EVENT_TIMEOUT_MS = exports.IMPORT_TIMEOUT_MS = exports.WRITE_TIMEOUT_MS = exports.READ_TIMEOUT_MS = void 0;
|
|
18
20
|
exports.login = login;
|
|
19
21
|
exports.ensureAuthed = ensureAuthed;
|
|
20
22
|
exports.listPrompts = listPrompts;
|
|
@@ -32,6 +34,44 @@ const constants_1 = require("./constants");
|
|
|
32
34
|
const config_1 = require("./config");
|
|
33
35
|
const NOT_LOGGED_IN = 'Not logged in. Run `ple login` first.';
|
|
34
36
|
const SESSION_EXPIRED = 'Session expired. Log in again: `ple login`';
|
|
37
|
+
/**
|
|
38
|
+
* İstek zaman aşımları (O5 / PLE-03). Süre yalnız başlıkları değil gövde
|
|
39
|
+
* okumasını da kapsar (aynı sinyal). Otomatik tekrar deneme YOK: zaman aşımına
|
|
40
|
+
* uğrayan bir yazma sunucuda tamamlanmış olabilir, körü körüne tekrar çift kayıt
|
|
41
|
+
* yapabilir; bu yüzden yazma iletisi "önce kontrol et" der.
|
|
42
|
+
*/
|
|
43
|
+
/** GET istekleri (liste, detay, içgörü): hafif okumalar. */
|
|
44
|
+
exports.READ_TIMEOUT_MS = 15000;
|
|
45
|
+
/** GET dışı istekler (giriş, yenileme, geri alma). */
|
|
46
|
+
exports.WRITE_TIMEOUT_MS = 30000;
|
|
47
|
+
/** Toplu içe aktarma: istek başına 50 kayda kadar, kayıt başına birkaç sorgu. */
|
|
48
|
+
exports.IMPORT_TIMEOUT_MS = 120000;
|
|
49
|
+
/** Kullanım kaydı (fire-and-forget): asılı sunucu komutun çıkışını bekletmesin. */
|
|
50
|
+
exports.USE_EVENT_TIMEOUT_MS = 5000;
|
|
51
|
+
/** Zaman aşımı hatası — `refreshSession` bunu "oturum bitti"ye çevirmesin diye ayrı sınıf. */
|
|
52
|
+
class RequestTimeoutError extends Error {
|
|
53
|
+
constructor(timeoutMs, method) {
|
|
54
|
+
const advice = method === 'GET'
|
|
55
|
+
? 'Check your connection and try again.'
|
|
56
|
+
: 'The server may still have completed the request; check before retrying.';
|
|
57
|
+
super(`No response from ${constants_1.API_BASE_URL} within ${Math.round(timeoutMs / 1000)}s. ${advice}`);
|
|
58
|
+
this.name = 'RequestTimeoutError';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.RequestTimeoutError = RequestTimeoutError;
|
|
62
|
+
/**
|
|
63
|
+
* Hata süre aşımından mı geldi? Önce sinyalin kendisine bakılır: eski Node /
|
|
64
|
+
* undici sürümlerinde gövde okuması yarıda kesilince hata `TimeoutError` yerine
|
|
65
|
+
* `TypeError: terminated` gibi başka biçimde gelebilir; sinyal `aborted` ise
|
|
66
|
+
* sebep süre dolmasıdır, hatanın biçimi önemsizdir. Ad kontrolü yedektir
|
|
67
|
+
* (AbortSignal.timeout → `TimeoutError`, iptal → `AbortError`).
|
|
68
|
+
*/
|
|
69
|
+
function isTimeout(err, signal) {
|
|
70
|
+
if (signal.aborted)
|
|
71
|
+
return true;
|
|
72
|
+
const name = err?.name;
|
|
73
|
+
return name === 'TimeoutError' || name === 'AbortError';
|
|
74
|
+
}
|
|
35
75
|
/**
|
|
36
76
|
* Fallback messages for server error codes. The API almost always sends a
|
|
37
77
|
* human-readable `error` string; this map is only used when a response carries
|
|
@@ -112,7 +152,10 @@ async function refreshSession() {
|
|
|
112
152
|
auth: false,
|
|
113
153
|
});
|
|
114
154
|
}
|
|
115
|
-
catch {
|
|
155
|
+
catch (err) {
|
|
156
|
+
// Asılı sunucu "oturumun bitti, yeniden giriş yap" demek değildir.
|
|
157
|
+
if (err instanceof RequestTimeoutError)
|
|
158
|
+
throw err;
|
|
116
159
|
throw new Error(SESSION_EXPIRED);
|
|
117
160
|
}
|
|
118
161
|
persist(data);
|
|
@@ -120,6 +163,8 @@ async function refreshSession() {
|
|
|
120
163
|
/** Core request helper. See module doc for behavior. */
|
|
121
164
|
async function apiFetch(path, opts = {}) {
|
|
122
165
|
const { method = 'GET', body, query, auth = true } = opts;
|
|
166
|
+
const timeoutMs = opts.timeoutMs ?? (method === 'GET' ? exports.READ_TIMEOUT_MS : exports.WRITE_TIMEOUT_MS);
|
|
167
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
123
168
|
const headers = {
|
|
124
169
|
'Content-Type': 'application/json',
|
|
125
170
|
// REV-6: sunucu CLI surumunu bilsin — eski CLI + degismis API semasi
|
|
@@ -135,9 +180,13 @@ async function apiFetch(path, opts = {}) {
|
|
|
135
180
|
method,
|
|
136
181
|
headers,
|
|
137
182
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
183
|
+
// Süre başlıkla sınırlı değil: gövde okuması da aynı sinyalle kesilir.
|
|
184
|
+
signal,
|
|
138
185
|
});
|
|
139
186
|
}
|
|
140
187
|
catch (err) {
|
|
188
|
+
if (isTimeout(err, signal))
|
|
189
|
+
throw new RequestTimeoutError(timeoutMs, method);
|
|
141
190
|
throw new Error(`Cannot reach ${constants_1.API_BASE_URL}. Check your connection. (${err instanceof Error ? err.message : String(err)})`);
|
|
142
191
|
}
|
|
143
192
|
// Reactive refresh: expired/invalid access token → refresh once, retry once.
|
|
@@ -154,7 +203,15 @@ async function apiFetch(path, opts = {}) {
|
|
|
154
203
|
if (!res.ok) {
|
|
155
204
|
throw await toError(res);
|
|
156
205
|
}
|
|
157
|
-
|
|
206
|
+
try {
|
|
207
|
+
return (await res.json());
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
// Başlıklar geldi, gövde yarıda kaldı ve süre doldu.
|
|
211
|
+
if (isTimeout(err, signal))
|
|
212
|
+
throw new RequestTimeoutError(timeoutMs, method);
|
|
213
|
+
throw err;
|
|
214
|
+
}
|
|
158
215
|
}
|
|
159
216
|
// ---------------------------------------------------------------------------
|
|
160
217
|
// Public surface used by commands / the resolver
|
|
@@ -206,6 +263,7 @@ async function importPrompts(prompts, options = {}) {
|
|
|
206
263
|
const res = await apiFetch('/api/prompts/import', {
|
|
207
264
|
method: 'POST',
|
|
208
265
|
body: { prompts, ...options },
|
|
266
|
+
timeoutMs: exports.IMPORT_TIMEOUT_MS,
|
|
209
267
|
});
|
|
210
268
|
return {
|
|
211
269
|
imported: res.imported ?? 0,
|
|
@@ -312,7 +370,11 @@ function buildUseEventBody(opts = {}, env = process.env) {
|
|
|
312
370
|
* komutu asla kırmaz.
|
|
313
371
|
*/
|
|
314
372
|
function recordPromptUse(promptId, opts = {}) {
|
|
315
|
-
apiFetch(`/api/prompts/${promptId}/use`, {
|
|
373
|
+
apiFetch(`/api/prompts/${promptId}/use`, {
|
|
374
|
+
method: 'POST',
|
|
375
|
+
body: buildUseEventBody(opts),
|
|
376
|
+
timeoutMs: exports.USE_EVENT_TIMEOUT_MS,
|
|
377
|
+
}).catch(() => {
|
|
316
378
|
/* sessiz — telemetri */
|
|
317
379
|
});
|
|
318
380
|
}
|
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