@withone/cli 1.44.2 → 1.45.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/README.md +5 -3
- package/dist/chunk-77564KWS.js +211 -0
- package/dist/{chunk-YGOS6KEC.js → chunk-DZK56R5R.js} +257 -85
- package/dist/{chunk-MNNKOQ6V.js → chunk-KH4ERRJ5.js} +4 -2
- package/dist/{chunk-YBEVCY4D.js → chunk-TGWQUBKA.js} +4 -2
- package/dist/{chunk-7ZILTQQO.js → chunk-TLRJMJGU.js} +2 -2
- package/dist/{chunk-ZD5S4IWT.js → chunk-TVIZC7AC.js} +2 -203
- package/dist/{chunk-VQPV5XET.js → chunk-Z4HKASJT.js} +2 -2
- package/dist/{embedding-GZGDGIUA.js → embedding-C3E4EAQ7.js} +2 -1
- package/dist/{flow-runner-EXZ77YLF.js → flow-runner-6KN2ZVXB.js} +2 -1
- package/dist/index.js +311 -380
- package/dist/{migrate-J2ZRDEFB.js → migrate-VV3VOXWJ.js} +5 -4
- package/dist/{runtime-RVXAPQAZ.js → runtime-3NDWRLXL.js} +3 -2
- package/dist/sql-ZABEXIXW.js +12 -0
- package/package.json +2 -2
- package/skills/one/SKILL.md +6 -5
- package/dist/sql-V44IVBHX.js +0 -11
|
@@ -242,199 +242,6 @@ function getEnvFromApiKey(apiKey) {
|
|
|
242
242
|
return apiKey.startsWith("sk_test_") ? "test" : "live";
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
// src/lib/memory/config.ts
|
|
246
|
-
var DEFAULT_MEMORY_CONFIG = {
|
|
247
|
-
backend: "embedded-postgres",
|
|
248
|
-
plugins: [],
|
|
249
|
-
embedding: {
|
|
250
|
-
provider: "none",
|
|
251
|
-
model: "text-embedding-3-small",
|
|
252
|
-
dimensions: 1536
|
|
253
|
-
},
|
|
254
|
-
defaults: {
|
|
255
|
-
trackAccessOnSearch: true,
|
|
256
|
-
embedOnAdd: true,
|
|
257
|
-
embedOnSync: false
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
function getMemoryConfig() {
|
|
261
|
-
const config = readConfig();
|
|
262
|
-
return config?.memory ?? null;
|
|
263
|
-
}
|
|
264
|
-
function getMemoryConfigOrDefault() {
|
|
265
|
-
return getMemoryConfig() ?? DEFAULT_MEMORY_CONFIG;
|
|
266
|
-
}
|
|
267
|
-
function memoryConfigExists() {
|
|
268
|
-
return getMemoryConfig() !== null;
|
|
269
|
-
}
|
|
270
|
-
function updateMemoryConfig(patch, opts = {}) {
|
|
271
|
-
const config = readConfig();
|
|
272
|
-
if (!config) {
|
|
273
|
-
throw new Error("No One config found. Run `one init` first.");
|
|
274
|
-
}
|
|
275
|
-
const current = config.memory ?? DEFAULT_MEMORY_CONFIG;
|
|
276
|
-
const next = opts.replace ? patch : { ...current, ...patch };
|
|
277
|
-
config.memory = next;
|
|
278
|
-
writeConfig(config);
|
|
279
|
-
return next;
|
|
280
|
-
}
|
|
281
|
-
function getEmbeddingApiKey() {
|
|
282
|
-
const fromCore = getOpenAiApiKey();
|
|
283
|
-
if (fromCore) return fromCore;
|
|
284
|
-
const mem = getMemoryConfig();
|
|
285
|
-
return mem?.embedding.apiKey ?? null;
|
|
286
|
-
}
|
|
287
|
-
function setOpenAiApiKey2(key) {
|
|
288
|
-
setOpenAiApiKey(key);
|
|
289
|
-
if (key === "") return;
|
|
290
|
-
const mem = getMemoryConfig();
|
|
291
|
-
if (!mem) return;
|
|
292
|
-
if (mem.embedding.provider === "openai") return;
|
|
293
|
-
updateMemoryConfig({
|
|
294
|
-
...mem,
|
|
295
|
-
embedding: { ...mem.embedding, provider: "openai" }
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// src/lib/memory/embedding.ts
|
|
300
|
-
var FETCH_TIMEOUT_MS = 3e4;
|
|
301
|
-
function fetchWithTimeout(url, init, timeoutMs) {
|
|
302
|
-
const ctrl = new AbortController();
|
|
303
|
-
const t = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
304
|
-
return fetch(url, { ...init, signal: ctrl.signal }).finally(() => clearTimeout(t));
|
|
305
|
-
}
|
|
306
|
-
async function embed(text, opts = {}) {
|
|
307
|
-
const clean = text?.trim();
|
|
308
|
-
if (!clean) return null;
|
|
309
|
-
const cfg = getMemoryConfigOrDefault();
|
|
310
|
-
if (cfg.embedding.provider !== "openai") return null;
|
|
311
|
-
const apiKey = getEmbeddingApiKey();
|
|
312
|
-
if (!apiKey) return null;
|
|
313
|
-
const model = opts.model ?? cfg.embedding.model;
|
|
314
|
-
const dimensions = cfg.embedding.dimensions;
|
|
315
|
-
for (let attempt = 0; attempt < 3; attempt++) {
|
|
316
|
-
try {
|
|
317
|
-
const res = await fetchWithTimeout("https://api.openai.com/v1/embeddings", {
|
|
318
|
-
method: "POST",
|
|
319
|
-
headers: {
|
|
320
|
-
"Content-Type": "application/json",
|
|
321
|
-
Authorization: `Bearer ${apiKey}`
|
|
322
|
-
},
|
|
323
|
-
body: JSON.stringify({
|
|
324
|
-
model,
|
|
325
|
-
input: clean.slice(0, 8e3),
|
|
326
|
-
dimensions
|
|
327
|
-
})
|
|
328
|
-
}, FETCH_TIMEOUT_MS);
|
|
329
|
-
if (!res.ok) {
|
|
330
|
-
if (res.status === 429 || res.status >= 500) {
|
|
331
|
-
await sleep(500 * (attempt + 1));
|
|
332
|
-
continue;
|
|
333
|
-
}
|
|
334
|
-
const body2 = await res.text();
|
|
335
|
-
throw new Error(`OpenAI embeddings ${res.status}: ${body2}`);
|
|
336
|
-
}
|
|
337
|
-
const body = await res.json();
|
|
338
|
-
const vector = body.data[0]?.embedding;
|
|
339
|
-
if (!vector || vector.length !== dimensions) {
|
|
340
|
-
throw new Error(`Unexpected embedding shape (got length ${vector?.length})`);
|
|
341
|
-
}
|
|
342
|
-
return { vector, model: `openai:${model}` };
|
|
343
|
-
} catch (err) {
|
|
344
|
-
if (attempt === 2) {
|
|
345
|
-
process.stderr.write(`[mem] embedding failed: ${err instanceof Error ? err.message : String(err)}
|
|
346
|
-
`);
|
|
347
|
-
return null;
|
|
348
|
-
}
|
|
349
|
-
await sleep(500 * (attempt + 1));
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return null;
|
|
353
|
-
}
|
|
354
|
-
async function embedBatch(texts, opts = {}) {
|
|
355
|
-
if (texts.length === 0) return [];
|
|
356
|
-
const cfg = getMemoryConfigOrDefault();
|
|
357
|
-
if (cfg.embedding.provider !== "openai") return texts.map(() => null);
|
|
358
|
-
const apiKey = getEmbeddingApiKey();
|
|
359
|
-
if (!apiKey) return texts.map(() => null);
|
|
360
|
-
const model = opts.model ?? cfg.embedding.model;
|
|
361
|
-
const dimensions = cfg.embedding.dimensions;
|
|
362
|
-
const active = [];
|
|
363
|
-
texts.forEach((t, i) => {
|
|
364
|
-
const clean = t?.trim();
|
|
365
|
-
if (clean) active.push({ index: i, input: clean.slice(0, 8e3) });
|
|
366
|
-
});
|
|
367
|
-
if (active.length === 0) return texts.map(() => null);
|
|
368
|
-
const result = texts.map(() => null);
|
|
369
|
-
for (let attempt = 0; attempt < 3; attempt++) {
|
|
370
|
-
try {
|
|
371
|
-
const res = await fetchWithTimeout("https://api.openai.com/v1/embeddings", {
|
|
372
|
-
method: "POST",
|
|
373
|
-
headers: {
|
|
374
|
-
"Content-Type": "application/json",
|
|
375
|
-
Authorization: `Bearer ${apiKey}`
|
|
376
|
-
},
|
|
377
|
-
body: JSON.stringify({
|
|
378
|
-
model,
|
|
379
|
-
input: active.map((a) => a.input),
|
|
380
|
-
dimensions
|
|
381
|
-
})
|
|
382
|
-
}, FETCH_TIMEOUT_MS);
|
|
383
|
-
if (!res.ok) {
|
|
384
|
-
if (res.status === 429 || res.status >= 500) {
|
|
385
|
-
await sleep(500 * (attempt + 1));
|
|
386
|
-
continue;
|
|
387
|
-
}
|
|
388
|
-
const body2 = await res.text();
|
|
389
|
-
throw new Error(`OpenAI embeddings ${res.status}: ${body2}`);
|
|
390
|
-
}
|
|
391
|
-
const body = await res.json();
|
|
392
|
-
for (const item of body.data) {
|
|
393
|
-
const slot = active[item.index];
|
|
394
|
-
if (!slot) continue;
|
|
395
|
-
result[slot.index] = { vector: item.embedding, model: `openai:${model}` };
|
|
396
|
-
}
|
|
397
|
-
return result;
|
|
398
|
-
} catch (err) {
|
|
399
|
-
if (attempt === 2) {
|
|
400
|
-
process.stderr.write(`[mem] batch embedding failed: ${err instanceof Error ? err.message : String(err)}
|
|
401
|
-
`);
|
|
402
|
-
return result;
|
|
403
|
-
}
|
|
404
|
-
await sleep(500 * (attempt + 1));
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
return result;
|
|
408
|
-
}
|
|
409
|
-
function sleep(ms) {
|
|
410
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
411
|
-
}
|
|
412
|
-
function defaultSearchableText(data, maxLen = 4e3) {
|
|
413
|
-
const parts = [];
|
|
414
|
-
const walk = (value, depth = 0) => {
|
|
415
|
-
if (value === null || value === void 0) return;
|
|
416
|
-
if (typeof value === "string" && value.trim()) {
|
|
417
|
-
parts.push(value.trim());
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
421
|
-
parts.push(String(value));
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
if (depth > 4) return;
|
|
425
|
-
if (Array.isArray(value)) {
|
|
426
|
-
for (const v of value) walk(v, depth + 1);
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
if (typeof value === "object") {
|
|
430
|
-
for (const v of Object.values(value)) walk(v, depth + 1);
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
walk(data);
|
|
434
|
-
const joined = parts.join(" ").replace(/\s+/g, " ").trim();
|
|
435
|
-
return joined.length > maxLen ? joined.slice(0, maxLen) : joined;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
245
|
export {
|
|
439
246
|
getProjectRoot,
|
|
440
247
|
getProjectConfigPath,
|
|
@@ -449,6 +256,7 @@ export {
|
|
|
449
256
|
writeConfig,
|
|
450
257
|
getApiKey,
|
|
451
258
|
getOpenAiApiKey,
|
|
259
|
+
setOpenAiApiKey,
|
|
452
260
|
getAccessControlFromAllSources,
|
|
453
261
|
getAccessControl,
|
|
454
262
|
getApiBase,
|
|
@@ -458,14 +266,5 @@ export {
|
|
|
458
266
|
getWhoAmI,
|
|
459
267
|
updateWhoAmI,
|
|
460
268
|
ensureWhoAmI,
|
|
461
|
-
getEnvFromApiKey
|
|
462
|
-
DEFAULT_MEMORY_CONFIG,
|
|
463
|
-
getMemoryConfig,
|
|
464
|
-
getMemoryConfigOrDefault,
|
|
465
|
-
memoryConfigExists,
|
|
466
|
-
updateMemoryConfig,
|
|
467
|
-
setOpenAiApiKey2 as setOpenAiApiKey,
|
|
468
|
-
embed,
|
|
469
|
-
embedBatch,
|
|
470
|
-
defaultSearchableText
|
|
269
|
+
getEnvFromApiKey
|
|
471
270
|
};
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
note,
|
|
7
7
|
okJson,
|
|
8
8
|
requireMemoryInit
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-KH4ERRJ5.js";
|
|
10
10
|
import {
|
|
11
11
|
getBackend,
|
|
12
12
|
upsertRecord
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-TGWQUBKA.js";
|
|
14
14
|
|
|
15
15
|
// src/commands/mem/migrate.ts
|
|
16
16
|
import fs4 from "fs";
|