latticesql 4.2.0 → 4.2.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/dist/cli.js +291 -180
- package/dist/index.cjs +581 -469
- package/dist/index.js +305 -194
- package/docs/configuration.md +27 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -224,10 +224,10 @@ function manifestPath(outputDir) {
|
|
|
224
224
|
return join2(outputDir, ".lattice", "manifest.json");
|
|
225
225
|
}
|
|
226
226
|
function readManifest(outputDir) {
|
|
227
|
-
const
|
|
228
|
-
if (!existsSync2(
|
|
227
|
+
const path3 = manifestPath(outputDir);
|
|
228
|
+
if (!existsSync2(path3)) return null;
|
|
229
229
|
try {
|
|
230
|
-
return JSON.parse(readFileSync2(
|
|
230
|
+
return JSON.parse(readFileSync2(path3, "utf8"));
|
|
231
231
|
} catch {
|
|
232
232
|
return null;
|
|
233
233
|
}
|
|
@@ -415,20 +415,130 @@ var init_render_cursor = __esm({
|
|
|
415
415
|
}
|
|
416
416
|
});
|
|
417
417
|
|
|
418
|
+
// src/db/load-sqlite.ts
|
|
419
|
+
import path from "path";
|
|
420
|
+
import { createRequire } from "module";
|
|
421
|
+
import { spawnSync } from "child_process";
|
|
422
|
+
function runtimeRequire() {
|
|
423
|
+
const importMetaUrl = import.meta.url;
|
|
424
|
+
return importMetaUrl ? createRequire(importMetaUrl) : (
|
|
425
|
+
// CJS fallback — Node provides `require` on every CJS module scope. Under
|
|
426
|
+
// tsup's CJS output `import.meta.url` is rewritten to undefined, so this
|
|
427
|
+
// branch keeps the loader working in the published .cjs bundle.
|
|
428
|
+
__require
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
function asCtor(mod) {
|
|
432
|
+
return mod.default ?? mod;
|
|
433
|
+
}
|
|
434
|
+
function isAbiMismatch(err) {
|
|
435
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
436
|
+
const code = err.code;
|
|
437
|
+
return message.includes("NODE_MODULE_VERSION") || code === "ERR_DLOPEN_FAILED" || message.includes("was compiled against a different Node.js version");
|
|
438
|
+
}
|
|
439
|
+
function autoRebuildDisabled() {
|
|
440
|
+
const v2 = process.env.LATTICE_SQLITE_NO_AUTOREBUILD;
|
|
441
|
+
if (!v2) return false;
|
|
442
|
+
const normalized = v2.trim().toLowerCase();
|
|
443
|
+
return normalized !== "" && normalized !== "0" && normalized !== "false" && normalized !== "no";
|
|
444
|
+
}
|
|
445
|
+
function installRootFor(req) {
|
|
446
|
+
const pkgJsonPath = req.resolve("better-sqlite3/package.json");
|
|
447
|
+
return path.resolve(path.dirname(pkgJsonPath), "..", "..");
|
|
448
|
+
}
|
|
449
|
+
function defaultRebuild(installRoot) {
|
|
450
|
+
const npmBin = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
451
|
+
const res = spawnSync(npmBin, ["rebuild", "better-sqlite3"], {
|
|
452
|
+
cwd: installRoot,
|
|
453
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
454
|
+
encoding: "utf8",
|
|
455
|
+
timeout: 5 * 60 * 1e3
|
|
456
|
+
});
|
|
457
|
+
if (res.error) {
|
|
458
|
+
return { ok: false, reason: res.error.message };
|
|
459
|
+
}
|
|
460
|
+
if (res.status !== 0) {
|
|
461
|
+
const stderr = res.stderr.trim();
|
|
462
|
+
const tail = stderr ? stderr.slice(-300) : `npm rebuild exited with code ${String(res.status)}`;
|
|
463
|
+
return { ok: false, reason: tail };
|
|
464
|
+
}
|
|
465
|
+
return { ok: true };
|
|
466
|
+
}
|
|
467
|
+
function resolveSqliteCtor(options = {}) {
|
|
468
|
+
const req = options.require ?? runtimeRequire();
|
|
469
|
+
const rebuild = options.rebuild ?? defaultRebuild;
|
|
470
|
+
const resolveInstallRoot = options.installRoot ?? installRootFor;
|
|
471
|
+
const log = options.log ?? ((msg) => process.stderr.write(msg + "\n"));
|
|
472
|
+
let firstError;
|
|
473
|
+
try {
|
|
474
|
+
return asCtor(req("better-sqlite3"));
|
|
475
|
+
} catch (err) {
|
|
476
|
+
firstError = err;
|
|
477
|
+
}
|
|
478
|
+
if (!isAbiMismatch(firstError)) {
|
|
479
|
+
throw new Error(PEER_DEP_MISSING_MESSAGE);
|
|
480
|
+
}
|
|
481
|
+
if (autoRebuildDisabled()) {
|
|
482
|
+
throw new Error(
|
|
483
|
+
rebuildFailedMessage("automatic rebuild is disabled (LATTICE_SQLITE_NO_AUTOREBUILD)")
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
log("[latticesql] SQLite engine built for a different Node runtime \u2014 rebuilding better-sqlite3\u2026");
|
|
487
|
+
let installRoot;
|
|
488
|
+
try {
|
|
489
|
+
installRoot = resolveInstallRoot(req);
|
|
490
|
+
} catch (err) {
|
|
491
|
+
throw new Error(
|
|
492
|
+
rebuildFailedMessage(
|
|
493
|
+
"could not locate the better-sqlite3 install root (" + (err instanceof Error ? err.message : String(err)) + ")"
|
|
494
|
+
)
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
const outcome = rebuild(installRoot);
|
|
498
|
+
if (!outcome.ok) {
|
|
499
|
+
throw new Error(rebuildFailedMessage(outcome.reason));
|
|
500
|
+
}
|
|
501
|
+
try {
|
|
502
|
+
return asCtor(req("better-sqlite3"));
|
|
503
|
+
} catch (err) {
|
|
504
|
+
throw new Error(
|
|
505
|
+
rebuildFailedMessage(
|
|
506
|
+
"the rebuilt module still failed to load (" + (err instanceof Error ? err.message : String(err)) + ")"
|
|
507
|
+
)
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function rebuildFailedMessage(reason) {
|
|
512
|
+
return "latticesql: the better-sqlite3 native module doesn\u2019t match this Node runtime and an automatic rebuild did not complete (" + reason + "). Run `npm rebuild better-sqlite3` (or reinstall) and retry.";
|
|
513
|
+
}
|
|
514
|
+
function loadSqlite() {
|
|
515
|
+
if (_ctor) return _ctor;
|
|
516
|
+
_ctor = resolveSqliteCtor();
|
|
517
|
+
return _ctor;
|
|
518
|
+
}
|
|
519
|
+
var PEER_DEP_MISSING_MESSAGE, _ctor;
|
|
520
|
+
var init_load_sqlite = __esm({
|
|
521
|
+
"src/db/load-sqlite.ts"() {
|
|
522
|
+
"use strict";
|
|
523
|
+
PEER_DEP_MISSING_MESSAGE = "better-sqlite3 is a required peer dependency of latticesql \u2014 install it (npm install better-sqlite3).";
|
|
524
|
+
_ctor = null;
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
|
|
418
528
|
// src/db/sqlite.ts
|
|
419
|
-
import Database from "better-sqlite3";
|
|
420
529
|
var SQLiteAdapter;
|
|
421
530
|
var init_sqlite = __esm({
|
|
422
531
|
"src/db/sqlite.ts"() {
|
|
423
532
|
"use strict";
|
|
533
|
+
init_load_sqlite();
|
|
424
534
|
SQLiteAdapter = class {
|
|
425
535
|
dialect = "sqlite";
|
|
426
536
|
_db = null;
|
|
427
537
|
_path;
|
|
428
538
|
_wal;
|
|
429
539
|
_busyTimeout;
|
|
430
|
-
constructor(
|
|
431
|
-
this._path =
|
|
540
|
+
constructor(path3, options) {
|
|
541
|
+
this._path = path3;
|
|
432
542
|
this._wal = options?.wal ?? true;
|
|
433
543
|
this._busyTimeout = options?.busyTimeout ?? 5e3;
|
|
434
544
|
}
|
|
@@ -437,7 +547,8 @@ var init_sqlite = __esm({
|
|
|
437
547
|
return this._db;
|
|
438
548
|
}
|
|
439
549
|
open() {
|
|
440
|
-
|
|
550
|
+
const Ctor = loadSqlite();
|
|
551
|
+
this._db = new Ctor(this._path);
|
|
441
552
|
this._db.pragma(`busy_timeout = ${this._busyTimeout.toString()}`);
|
|
442
553
|
if (this._wal) {
|
|
443
554
|
this._db.pragma("journal_mode = WAL");
|
|
@@ -609,16 +720,16 @@ var init_sqlite = __esm({
|
|
|
609
720
|
});
|
|
610
721
|
|
|
611
722
|
// src/db/postgres.ts
|
|
612
|
-
import
|
|
723
|
+
import path2 from "path";
|
|
613
724
|
import { fileURLToPath } from "url";
|
|
614
|
-
import { createRequire } from "module";
|
|
725
|
+
import { createRequire as createRequire2 } from "module";
|
|
615
726
|
function moduleContext() {
|
|
616
727
|
if (_moduleContext) return _moduleContext;
|
|
617
728
|
const importMetaUrl = import.meta.url;
|
|
618
729
|
if (importMetaUrl) {
|
|
619
730
|
_moduleContext = {
|
|
620
|
-
dir:
|
|
621
|
-
require:
|
|
731
|
+
dir: path2.dirname(fileURLToPath(importMetaUrl)),
|
|
732
|
+
require: createRequire2(importMetaUrl)
|
|
622
733
|
};
|
|
623
734
|
} else {
|
|
624
735
|
_moduleContext = { dir: __dirname, require: __require };
|
|
@@ -2547,14 +2658,14 @@ var init_core = __esm({
|
|
|
2547
2658
|
columnRef(f6) {
|
|
2548
2659
|
const col = `"${ident(f6.col)}"`;
|
|
2549
2660
|
if (f6.jsonPath === void 0) return { sql: col, params: [] };
|
|
2550
|
-
const
|
|
2661
|
+
const path3 = Array.isArray(f6.jsonPath) ? f6.jsonPath : [f6.jsonPath];
|
|
2551
2662
|
const numeric = isNumericComparison(f6);
|
|
2552
2663
|
if (this.adapter.dialect === "postgres") {
|
|
2553
2664
|
const extract2 = `((${col})::jsonb #>> ?::text[])`;
|
|
2554
2665
|
const sql2 = numeric ? `(${extract2})::numeric` : extract2;
|
|
2555
|
-
return { sql: sql2, params: [
|
|
2666
|
+
return { sql: sql2, params: [path3] };
|
|
2556
2667
|
}
|
|
2557
|
-
const jsonpath = `$.${
|
|
2668
|
+
const jsonpath = `$.${path3.join(".")}`;
|
|
2558
2669
|
const extract = `json_extract(${col}, ?)`;
|
|
2559
2670
|
const sql = numeric ? `CAST(${extract} AS REAL)` : extract;
|
|
2560
2671
|
return { sql, params: [jsonpath] };
|
|
@@ -5189,8 +5300,8 @@ var init_pipeline = __esm({
|
|
|
5189
5300
|
|
|
5190
5301
|
// src/render/interpolate.ts
|
|
5191
5302
|
function interpolate(template, row) {
|
|
5192
|
-
return template.replace(/\{\{([^}]+)\}\}/g, (_,
|
|
5193
|
-
const parts =
|
|
5303
|
+
return template.replace(/\{\{([^}]+)\}\}/g, (_, path3) => {
|
|
5304
|
+
const parts = path3.trim().split(".");
|
|
5194
5305
|
let val = row;
|
|
5195
5306
|
for (const part of parts) {
|
|
5196
5307
|
if (val == null || typeof val !== "object") return "";
|
|
@@ -5456,10 +5567,10 @@ function getOrCreateMasterKey() {
|
|
|
5456
5567
|
}
|
|
5457
5568
|
function readIdentity() {
|
|
5458
5569
|
const dir = ensureConfigDir();
|
|
5459
|
-
const
|
|
5460
|
-
if (!existsSync9(
|
|
5570
|
+
const path3 = join9(dir, IDENTITY_FILENAME);
|
|
5571
|
+
if (!existsSync9(path3)) return { ...EMPTY_IDENTITY };
|
|
5461
5572
|
try {
|
|
5462
|
-
const parsed = JSON.parse(readFileSync6(
|
|
5573
|
+
const parsed = JSON.parse(readFileSync6(path3, "utf8"));
|
|
5463
5574
|
return {
|
|
5464
5575
|
display_name: typeof parsed.display_name === "string" ? parsed.display_name : "",
|
|
5465
5576
|
email: typeof parsed.email === "string" ? parsed.email : ""
|
|
@@ -5470,26 +5581,26 @@ function readIdentity() {
|
|
|
5470
5581
|
}
|
|
5471
5582
|
function writeIdentity(identity) {
|
|
5472
5583
|
const dir = ensureConfigDir();
|
|
5473
|
-
const
|
|
5584
|
+
const path3 = join9(dir, IDENTITY_FILENAME);
|
|
5474
5585
|
const body = JSON.stringify(
|
|
5475
5586
|
{ display_name: identity.display_name, email: identity.email },
|
|
5476
5587
|
null,
|
|
5477
5588
|
2
|
|
5478
5589
|
);
|
|
5479
|
-
writeFileSync2(
|
|
5590
|
+
writeFileSync2(path3, body + "\n", "utf8");
|
|
5480
5591
|
if (platform2() !== "win32") {
|
|
5481
5592
|
try {
|
|
5482
|
-
chmodSync2(
|
|
5593
|
+
chmodSync2(path3, 384);
|
|
5483
5594
|
} catch {
|
|
5484
5595
|
}
|
|
5485
5596
|
}
|
|
5486
5597
|
}
|
|
5487
5598
|
function readPreferences() {
|
|
5488
5599
|
const dir = ensureConfigDir();
|
|
5489
|
-
const
|
|
5490
|
-
if (!existsSync9(
|
|
5600
|
+
const path3 = join9(dir, PREFERENCES_FILENAME);
|
|
5601
|
+
if (!existsSync9(path3)) return { ...DEFAULT_PREFERENCES };
|
|
5491
5602
|
try {
|
|
5492
|
-
const parsed = JSON.parse(readFileSync6(
|
|
5603
|
+
const parsed = JSON.parse(readFileSync6(path3, "utf8"));
|
|
5493
5604
|
const agg = typeof parsed.aggressiveness === "number" ? parsed.aggressiveness : NaN;
|
|
5494
5605
|
return {
|
|
5495
5606
|
show_system_tables: typeof parsed.show_system_tables === "boolean" ? parsed.show_system_tables : DEFAULT_PREFERENCES.show_system_tables,
|
|
@@ -5503,7 +5614,7 @@ function readPreferences() {
|
|
|
5503
5614
|
}
|
|
5504
5615
|
function writePreferences(prefs) {
|
|
5505
5616
|
const dir = ensureConfigDir();
|
|
5506
|
-
const
|
|
5617
|
+
const path3 = join9(dir, PREFERENCES_FILENAME);
|
|
5507
5618
|
const body = JSON.stringify(
|
|
5508
5619
|
{
|
|
5509
5620
|
show_system_tables: prefs.show_system_tables,
|
|
@@ -5514,10 +5625,10 @@ function writePreferences(prefs) {
|
|
|
5514
5625
|
null,
|
|
5515
5626
|
2
|
|
5516
5627
|
);
|
|
5517
|
-
writeFileSync2(
|
|
5628
|
+
writeFileSync2(path3, body + "\n", "utf8");
|
|
5518
5629
|
if (platform2() !== "win32") {
|
|
5519
5630
|
try {
|
|
5520
|
-
chmodSync2(
|
|
5631
|
+
chmodSync2(path3, 384);
|
|
5521
5632
|
} catch {
|
|
5522
5633
|
}
|
|
5523
5634
|
}
|
|
@@ -5581,8 +5692,8 @@ function withCredentialLock(fn) {
|
|
|
5581
5692
|
}
|
|
5582
5693
|
}
|
|
5583
5694
|
}
|
|
5584
|
-
function writeFileAtomic(
|
|
5585
|
-
const tmp = `${
|
|
5695
|
+
function writeFileAtomic(path3, data) {
|
|
5696
|
+
const tmp = `${path3}.${String(process.pid)}.${randomBytes4(4).toString("hex")}.tmp`;
|
|
5586
5697
|
writeFileSync2(tmp, data, "utf8");
|
|
5587
5698
|
if (platform2() !== "win32") {
|
|
5588
5699
|
try {
|
|
@@ -5590,7 +5701,7 @@ function writeFileAtomic(path2, data) {
|
|
|
5590
5701
|
} catch {
|
|
5591
5702
|
}
|
|
5592
5703
|
}
|
|
5593
|
-
renameSync2(tmp,
|
|
5704
|
+
renameSync2(tmp, path3);
|
|
5594
5705
|
}
|
|
5595
5706
|
function mutateCredentials(mutate) {
|
|
5596
5707
|
withCredentialLock(() => {
|
|
@@ -5601,11 +5712,11 @@ function mutateCredentials(mutate) {
|
|
|
5601
5712
|
}
|
|
5602
5713
|
function loadCredentials() {
|
|
5603
5714
|
const dir = ensureConfigDir();
|
|
5604
|
-
const
|
|
5605
|
-
if (!existsSync9(
|
|
5715
|
+
const path3 = join9(dir, DB_CREDENTIALS_FILENAME);
|
|
5716
|
+
if (!existsSync9(path3)) return {};
|
|
5606
5717
|
const key = deriveKey(getOrCreateMasterKey());
|
|
5607
5718
|
try {
|
|
5608
|
-
const ciphertext = readFileSync6(
|
|
5719
|
+
const ciphertext = readFileSync6(path3, "utf8").trim();
|
|
5609
5720
|
const plaintext = decrypt(ciphertext, key);
|
|
5610
5721
|
const parsed = JSON.parse(plaintext);
|
|
5611
5722
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
@@ -5620,10 +5731,10 @@ function loadCredentials() {
|
|
|
5620
5731
|
}
|
|
5621
5732
|
function saveCredentials(creds) {
|
|
5622
5733
|
const dir = ensureConfigDir();
|
|
5623
|
-
const
|
|
5734
|
+
const path3 = join9(dir, DB_CREDENTIALS_FILENAME);
|
|
5624
5735
|
const key = deriveKey(getOrCreateMasterKey());
|
|
5625
5736
|
const ciphertext = encrypt(JSON.stringify(creds), key);
|
|
5626
|
-
writeFileAtomic(
|
|
5737
|
+
writeFileAtomic(path3, ciphertext + "\n");
|
|
5627
5738
|
}
|
|
5628
5739
|
function listDbCredentials() {
|
|
5629
5740
|
return Object.keys(loadCredentials()).sort();
|
|
@@ -5671,11 +5782,11 @@ function healRawDbUrl(configPath) {
|
|
|
5671
5782
|
}
|
|
5672
5783
|
function loadS3Configs() {
|
|
5673
5784
|
const dir = ensureConfigDir();
|
|
5674
|
-
const
|
|
5675
|
-
if (!existsSync9(
|
|
5785
|
+
const path3 = join9(dir, S3_CONFIG_FILENAME);
|
|
5786
|
+
if (!existsSync9(path3)) return {};
|
|
5676
5787
|
const key = deriveKey(getOrCreateMasterKey());
|
|
5677
5788
|
try {
|
|
5678
|
-
const parsed = JSON.parse(decrypt(readFileSync6(
|
|
5789
|
+
const parsed = JSON.parse(decrypt(readFileSync6(path3, "utf8").trim(), key));
|
|
5679
5790
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
5680
5791
|
return parsed;
|
|
5681
5792
|
}
|
|
@@ -5689,12 +5800,12 @@ function loadS3Configs() {
|
|
|
5689
5800
|
}
|
|
5690
5801
|
function saveS3Configs(cfgs) {
|
|
5691
5802
|
const dir = ensureConfigDir();
|
|
5692
|
-
const
|
|
5803
|
+
const path3 = join9(dir, S3_CONFIG_FILENAME);
|
|
5693
5804
|
const key = deriveKey(getOrCreateMasterKey());
|
|
5694
|
-
writeFileSync2(
|
|
5805
|
+
writeFileSync2(path3, encrypt(JSON.stringify(cfgs), key) + "\n", "utf8");
|
|
5695
5806
|
if (platform2() !== "win32") {
|
|
5696
5807
|
try {
|
|
5697
|
-
chmodSync2(
|
|
5808
|
+
chmodSync2(path3, 384);
|
|
5698
5809
|
} catch {
|
|
5699
5810
|
}
|
|
5700
5811
|
}
|
|
@@ -5731,11 +5842,11 @@ function deleteDbCredential(label) {
|
|
|
5731
5842
|
}
|
|
5732
5843
|
function loadAssistantCredentials() {
|
|
5733
5844
|
const dir = ensureConfigDir();
|
|
5734
|
-
const
|
|
5735
|
-
if (!existsSync9(
|
|
5845
|
+
const path3 = join9(dir, ASSISTANT_CREDENTIALS_FILENAME);
|
|
5846
|
+
if (!existsSync9(path3)) return {};
|
|
5736
5847
|
const key = deriveKey(getOrCreateMasterKey());
|
|
5737
5848
|
try {
|
|
5738
|
-
const ciphertext = readFileSync6(
|
|
5849
|
+
const ciphertext = readFileSync6(path3, "utf8").trim();
|
|
5739
5850
|
const plaintext = decrypt(ciphertext, key);
|
|
5740
5851
|
const parsed = JSON.parse(plaintext);
|
|
5741
5852
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
@@ -5750,13 +5861,13 @@ function loadAssistantCredentials() {
|
|
|
5750
5861
|
}
|
|
5751
5862
|
function saveAssistantCredentials(creds) {
|
|
5752
5863
|
const dir = ensureConfigDir();
|
|
5753
|
-
const
|
|
5864
|
+
const path3 = join9(dir, ASSISTANT_CREDENTIALS_FILENAME);
|
|
5754
5865
|
const key = deriveKey(getOrCreateMasterKey());
|
|
5755
5866
|
const ciphertext = encrypt(JSON.stringify(creds), key);
|
|
5756
|
-
writeFileSync2(
|
|
5867
|
+
writeFileSync2(path3, ciphertext + "\n", "utf8");
|
|
5757
5868
|
if (platform2() !== "win32") {
|
|
5758
5869
|
try {
|
|
5759
|
-
chmodSync2(
|
|
5870
|
+
chmodSync2(path3, 384);
|
|
5760
5871
|
} catch {
|
|
5761
5872
|
}
|
|
5762
5873
|
}
|
|
@@ -5817,25 +5928,25 @@ function listTokens() {
|
|
|
5817
5928
|
}
|
|
5818
5929
|
function readToken(label) {
|
|
5819
5930
|
assertSafeLabel(label);
|
|
5820
|
-
const
|
|
5821
|
-
if (!existsSync9(
|
|
5822
|
-
return readFileSync6(
|
|
5931
|
+
const path3 = join9(ensureKeysDir(), label + TOKEN_EXT);
|
|
5932
|
+
if (!existsSync9(path3)) return null;
|
|
5933
|
+
return readFileSync6(path3, "utf8").trim();
|
|
5823
5934
|
}
|
|
5824
5935
|
function writeToken(label, token) {
|
|
5825
5936
|
assertSafeLabel(label);
|
|
5826
|
-
const
|
|
5827
|
-
writeFileSync2(
|
|
5937
|
+
const path3 = join9(ensureKeysDir(), label + TOKEN_EXT);
|
|
5938
|
+
writeFileSync2(path3, token + "\n", "utf8");
|
|
5828
5939
|
if (platform2() !== "win32") {
|
|
5829
5940
|
try {
|
|
5830
|
-
chmodSync2(
|
|
5941
|
+
chmodSync2(path3, 384);
|
|
5831
5942
|
} catch {
|
|
5832
5943
|
}
|
|
5833
5944
|
}
|
|
5834
5945
|
}
|
|
5835
5946
|
function deleteToken(label) {
|
|
5836
5947
|
assertSafeLabel(label);
|
|
5837
|
-
const
|
|
5838
|
-
if (existsSync9(
|
|
5948
|
+
const path3 = join9(ensureKeysDir(), label + TOKEN_EXT);
|
|
5949
|
+
if (existsSync9(path3)) unlinkSync3(path3);
|
|
5839
5950
|
}
|
|
5840
5951
|
var MASTER_KEY_FILENAME, IDENTITY_FILENAME, EMPTY_IDENTITY, PREFERENCES_FILENAME, DEFAULT_PREFERENCES, DB_CREDENTIALS_FILENAME, CRED_LOCK_FILENAME, LOCK_STALE_MS, LOCK_TIMEOUT_MS, lockDepthInProcess, S3_CONFIG_FILENAME, ASSISTANT_CREDENTIALS_FILENAME, CLEARED_SENTINEL_PREFIX, KEYS_SUBDIR, TOKEN_EXT;
|
|
5841
5952
|
var init_user_config = __esm({
|
|
@@ -6210,13 +6321,13 @@ function uniqueDirName(displayName, existing) {
|
|
|
6210
6321
|
}
|
|
6211
6322
|
}
|
|
6212
6323
|
function readRegistry(root6) {
|
|
6213
|
-
const
|
|
6214
|
-
if (!existsSync10(
|
|
6324
|
+
const path3 = registryPath(root6);
|
|
6325
|
+
if (!existsSync10(path3)) return { ...EMPTY_REGISTRY, workspaces: [] };
|
|
6215
6326
|
let parsed;
|
|
6216
6327
|
try {
|
|
6217
|
-
parsed = JSON.parse(readFileSync8(
|
|
6328
|
+
parsed = JSON.parse(readFileSync8(path3, "utf-8"));
|
|
6218
6329
|
} catch (e6) {
|
|
6219
|
-
throw new Error(`Lattice: corrupt workspace registry at "${
|
|
6330
|
+
throw new Error(`Lattice: corrupt workspace registry at "${path3}": ${e6.message}`);
|
|
6220
6331
|
}
|
|
6221
6332
|
const reg = parsed;
|
|
6222
6333
|
return {
|
|
@@ -6226,11 +6337,11 @@ function readRegistry(root6) {
|
|
|
6226
6337
|
};
|
|
6227
6338
|
}
|
|
6228
6339
|
function writeRegistry(root6, registry) {
|
|
6229
|
-
const
|
|
6230
|
-
const tmp = `${
|
|
6340
|
+
const path3 = registryPath(root6);
|
|
6341
|
+
const tmp = `${path3}.tmp-${String(process.pid)}`;
|
|
6231
6342
|
writeFileSync3(tmp, `${JSON.stringify(registry, null, 2)}
|
|
6232
6343
|
`, "utf-8");
|
|
6233
|
-
renameSync3(tmp,
|
|
6344
|
+
renameSync3(tmp, path3);
|
|
6234
6345
|
}
|
|
6235
6346
|
function listWorkspaces(root6) {
|
|
6236
6347
|
return readRegistry(root6).workspaces;
|
|
@@ -8011,18 +8122,18 @@ function computedColumnOrder(table, computed) {
|
|
|
8011
8122
|
const names = new Set(Object.keys(computed));
|
|
8012
8123
|
const order = [];
|
|
8013
8124
|
const state2 = /* @__PURE__ */ new Map();
|
|
8014
|
-
const visit = (name,
|
|
8125
|
+
const visit = (name, path3) => {
|
|
8015
8126
|
const st = state2.get(name);
|
|
8016
8127
|
if (st === "done") return;
|
|
8017
8128
|
if (st === "visiting") {
|
|
8018
|
-
const start =
|
|
8019
|
-
throw new ComputedColumnCycleError(table, [...
|
|
8129
|
+
const start = path3.indexOf(name);
|
|
8130
|
+
throw new ComputedColumnCycleError(table, [...path3.slice(start), name]);
|
|
8020
8131
|
}
|
|
8021
8132
|
state2.set(name, "visiting");
|
|
8022
8133
|
const spec = computed[name];
|
|
8023
8134
|
if (spec) {
|
|
8024
8135
|
for (const dep of spec.deps) {
|
|
8025
|
-
if (names.has(dep)) visit(dep, [...
|
|
8136
|
+
if (names.has(dep)) visit(dep, [...path3, name]);
|
|
8026
8137
|
}
|
|
8027
8138
|
}
|
|
8028
8139
|
state2.set(name, "done");
|
|
@@ -16112,14 +16223,14 @@ var init_readFile = __esm({
|
|
|
16112
16223
|
"use strict";
|
|
16113
16224
|
filePromises = {};
|
|
16114
16225
|
fileIntercept = {};
|
|
16115
|
-
readFile2 = (
|
|
16116
|
-
if (fileIntercept[
|
|
16117
|
-
return fileIntercept[
|
|
16226
|
+
readFile2 = (path3, options) => {
|
|
16227
|
+
if (fileIntercept[path3] !== void 0) {
|
|
16228
|
+
return fileIntercept[path3];
|
|
16118
16229
|
}
|
|
16119
|
-
if (!filePromises[
|
|
16120
|
-
filePromises[
|
|
16230
|
+
if (!filePromises[path3] || options?.ignoreCache) {
|
|
16231
|
+
filePromises[path3] = fsReadFile(path3, "utf8");
|
|
16121
16232
|
}
|
|
16122
|
-
return filePromises[
|
|
16233
|
+
return filePromises[path3];
|
|
16123
16234
|
};
|
|
16124
16235
|
}
|
|
16125
16236
|
});
|
|
@@ -16237,8 +16348,8 @@ var init_externalDataInterceptor = __esm({
|
|
|
16237
16348
|
getFileRecord() {
|
|
16238
16349
|
return fileIntercept;
|
|
16239
16350
|
},
|
|
16240
|
-
interceptFile(
|
|
16241
|
-
fileIntercept[
|
|
16351
|
+
interceptFile(path3, contents) {
|
|
16352
|
+
fileIntercept[path3] = Promise.resolve(contents);
|
|
16242
16353
|
},
|
|
16243
16354
|
getTokenRecord() {
|
|
16244
16355
|
return tokenIntercept;
|
|
@@ -16572,13 +16683,13 @@ var init_resolveDefaultsModeConfig = __esm({
|
|
|
16572
16683
|
}
|
|
16573
16684
|
return { hostname: "169.254.169.254", path: "/" };
|
|
16574
16685
|
};
|
|
16575
|
-
imdsHttpGet = async ({ hostname, path:
|
|
16686
|
+
imdsHttpGet = async ({ hostname, path: path3 }) => {
|
|
16576
16687
|
const { request } = await import("http");
|
|
16577
16688
|
return new Promise((resolve17, reject) => {
|
|
16578
16689
|
const req = request({
|
|
16579
16690
|
method: "GET",
|
|
16580
16691
|
hostname: hostname.replace(/^\[(.+)]$/, "$1"),
|
|
16581
|
-
path:
|
|
16692
|
+
path: path3,
|
|
16582
16693
|
timeout: 1e3,
|
|
16583
16694
|
signal: AbortSignal.timeout(1e3)
|
|
16584
16695
|
});
|
|
@@ -16779,8 +16890,8 @@ var init_createConfigValueProvider = __esm({
|
|
|
16779
16890
|
return endpoint.url.href;
|
|
16780
16891
|
}
|
|
16781
16892
|
if ("hostname" in endpoint) {
|
|
16782
|
-
const { protocol, hostname, port, path:
|
|
16783
|
-
return `${protocol}//${hostname}${port ? ":" + port : ""}${
|
|
16893
|
+
const { protocol, hostname, port, path: path3 } = endpoint;
|
|
16894
|
+
return `${protocol}//${hostname}${port ? ":" + port : ""}${path3}`;
|
|
16784
16895
|
}
|
|
16785
16896
|
}
|
|
16786
16897
|
return endpoint;
|
|
@@ -17217,18 +17328,18 @@ var init_getAttrPathList = __esm({
|
|
|
17217
17328
|
"node_modules/@smithy/core/dist-es/submodules/endpoints/util-endpoints/lib/getAttrPathList.js"() {
|
|
17218
17329
|
"use strict";
|
|
17219
17330
|
init_types2();
|
|
17220
|
-
getAttrPathList = (
|
|
17221
|
-
const parts =
|
|
17331
|
+
getAttrPathList = (path3) => {
|
|
17332
|
+
const parts = path3.split(".");
|
|
17222
17333
|
const pathList = [];
|
|
17223
17334
|
for (const part of parts) {
|
|
17224
17335
|
const squareBracketIndex = part.indexOf("[");
|
|
17225
17336
|
if (squareBracketIndex !== -1) {
|
|
17226
17337
|
if (part.indexOf("]") !== part.length - 1) {
|
|
17227
|
-
throw new EndpointError(`Path: '${
|
|
17338
|
+
throw new EndpointError(`Path: '${path3}' does not end with ']'`);
|
|
17228
17339
|
}
|
|
17229
17340
|
const arrayIndex = part.slice(squareBracketIndex + 1, -1);
|
|
17230
17341
|
if (Number.isNaN(parseInt(arrayIndex))) {
|
|
17231
|
-
throw new EndpointError(`Invalid array index: '${arrayIndex}' in path: '${
|
|
17342
|
+
throw new EndpointError(`Invalid array index: '${arrayIndex}' in path: '${path3}'`);
|
|
17232
17343
|
}
|
|
17233
17344
|
if (squareBracketIndex !== 0) {
|
|
17234
17345
|
pathList.push(part.slice(0, squareBracketIndex));
|
|
@@ -17250,9 +17361,9 @@ var init_getAttr = __esm({
|
|
|
17250
17361
|
"use strict";
|
|
17251
17362
|
init_types2();
|
|
17252
17363
|
init_getAttrPathList();
|
|
17253
|
-
getAttr = (value,
|
|
17364
|
+
getAttr = (value, path3) => getAttrPathList(path3).reduce((acc, index) => {
|
|
17254
17365
|
if (typeof acc !== "object") {
|
|
17255
|
-
throw new EndpointError(`Index '${index}' in '${
|
|
17366
|
+
throw new EndpointError(`Index '${index}' in '${path3}' not found in '${JSON.stringify(value)}'`);
|
|
17256
17367
|
} else if (Array.isArray(acc)) {
|
|
17257
17368
|
const i6 = parseInt(index);
|
|
17258
17369
|
return acc[i6 < 0 ? acc.length + i6 : i6];
|
|
@@ -17318,8 +17429,8 @@ var init_parseURL = __esm({
|
|
|
17318
17429
|
return value;
|
|
17319
17430
|
}
|
|
17320
17431
|
if (typeof value === "object" && "hostname" in value) {
|
|
17321
|
-
const { hostname: hostname2, port, protocol: protocol2 = "", path:
|
|
17322
|
-
const url = new URL(`${protocol2}//${hostname2}${port ? `:${port}` : ""}${
|
|
17432
|
+
const { hostname: hostname2, port, protocol: protocol2 = "", path: path3 = "", query = {} } = value;
|
|
17433
|
+
const url = new URL(`${protocol2}//${hostname2}${port ? `:${port}` : ""}${path3}`);
|
|
17323
17434
|
url.search = Object.entries(query).map(([k6, v2]) => `${k6}=${v2}`).join("&");
|
|
17324
17435
|
return url;
|
|
17325
17436
|
}
|
|
@@ -20430,11 +20541,11 @@ var init_HttpBindingProtocol = __esm({
|
|
|
20430
20541
|
const opTraits = translateTraits(operationSchema.traits);
|
|
20431
20542
|
if (opTraits.http) {
|
|
20432
20543
|
request.method = opTraits.http[0];
|
|
20433
|
-
const [
|
|
20544
|
+
const [path3, search] = opTraits.http[1].split("?");
|
|
20434
20545
|
if (request.path == "/") {
|
|
20435
|
-
request.path =
|
|
20546
|
+
request.path = path3;
|
|
20436
20547
|
} else {
|
|
20437
|
-
request.path +=
|
|
20548
|
+
request.path += path3;
|
|
20438
20549
|
}
|
|
20439
20550
|
const traitSearchParams = new URLSearchParams(search ?? "");
|
|
20440
20551
|
for (const [key, value] of traitSearchParams) {
|
|
@@ -22413,9 +22524,9 @@ var init_createPaginator = __esm({
|
|
|
22413
22524
|
command = withCommand(command) ?? command;
|
|
22414
22525
|
return await client.send(command, ...args);
|
|
22415
22526
|
};
|
|
22416
|
-
get = (fromObject,
|
|
22527
|
+
get = (fromObject, path3) => {
|
|
22417
22528
|
let cursor = fromObject;
|
|
22418
|
-
const pathComponents =
|
|
22529
|
+
const pathComponents = path3.split(".");
|
|
22419
22530
|
for (const step of pathComponents) {
|
|
22420
22531
|
if (!cursor || typeof cursor !== "object") {
|
|
22421
22532
|
return void 0;
|
|
@@ -24907,10 +25018,10 @@ ${longDate}
|
|
|
24907
25018
|
${credentialScope}
|
|
24908
25019
|
${toHex(hashedRequest)}`;
|
|
24909
25020
|
}
|
|
24910
|
-
getCanonicalPath({ path:
|
|
25021
|
+
getCanonicalPath({ path: path3 }) {
|
|
24911
25022
|
if (this.uriEscapePath) {
|
|
24912
25023
|
const normalizedPathSegments = [];
|
|
24913
|
-
for (const pathSegment of
|
|
25024
|
+
for (const pathSegment of path3.split("/")) {
|
|
24914
25025
|
if (pathSegment?.length === 0)
|
|
24915
25026
|
continue;
|
|
24916
25027
|
if (pathSegment === ".")
|
|
@@ -24921,11 +25032,11 @@ ${toHex(hashedRequest)}`;
|
|
|
24921
25032
|
normalizedPathSegments.push(pathSegment);
|
|
24922
25033
|
}
|
|
24923
25034
|
}
|
|
24924
|
-
const normalizedPath = `${
|
|
25035
|
+
const normalizedPath = `${path3?.startsWith("/") ? "/" : ""}${normalizedPathSegments.join("/")}${normalizedPathSegments.length > 0 && path3?.endsWith("/") ? "/" : ""}`;
|
|
24925
25036
|
const doubleEncoded = escapeUri(normalizedPath);
|
|
24926
25037
|
return doubleEncoded.replace(/%2F/g, "/");
|
|
24927
25038
|
}
|
|
24928
|
-
return
|
|
25039
|
+
return path3;
|
|
24929
25040
|
}
|
|
24930
25041
|
validateResolvedCredentials(credentials) {
|
|
24931
25042
|
if (typeof credentials !== "object" || typeof credentials.accessKeyId !== "string" || typeof credentials.secretAccessKey !== "string") {
|
|
@@ -29842,16 +29953,16 @@ var init_Matcher = __esm({
|
|
|
29842
29953
|
* @returns {string|undefined}
|
|
29843
29954
|
*/
|
|
29844
29955
|
getCurrentTag() {
|
|
29845
|
-
const
|
|
29846
|
-
return
|
|
29956
|
+
const path3 = this._matcher.path;
|
|
29957
|
+
return path3.length > 0 ? path3[path3.length - 1].tag : void 0;
|
|
29847
29958
|
}
|
|
29848
29959
|
/**
|
|
29849
29960
|
* Get current namespace.
|
|
29850
29961
|
* @returns {string|undefined}
|
|
29851
29962
|
*/
|
|
29852
29963
|
getCurrentNamespace() {
|
|
29853
|
-
const
|
|
29854
|
-
return
|
|
29964
|
+
const path3 = this._matcher.path;
|
|
29965
|
+
return path3.length > 0 ? path3[path3.length - 1].namespace : void 0;
|
|
29855
29966
|
}
|
|
29856
29967
|
/**
|
|
29857
29968
|
* Get current node's attribute value.
|
|
@@ -29859,9 +29970,9 @@ var init_Matcher = __esm({
|
|
|
29859
29970
|
* @returns {*}
|
|
29860
29971
|
*/
|
|
29861
29972
|
getAttrValue(attrName) {
|
|
29862
|
-
const
|
|
29863
|
-
if (
|
|
29864
|
-
return
|
|
29973
|
+
const path3 = this._matcher.path;
|
|
29974
|
+
if (path3.length === 0) return void 0;
|
|
29975
|
+
return path3[path3.length - 1].values?.[attrName];
|
|
29865
29976
|
}
|
|
29866
29977
|
/**
|
|
29867
29978
|
* Check if current node has an attribute.
|
|
@@ -29869,9 +29980,9 @@ var init_Matcher = __esm({
|
|
|
29869
29980
|
* @returns {boolean}
|
|
29870
29981
|
*/
|
|
29871
29982
|
hasAttr(attrName) {
|
|
29872
|
-
const
|
|
29873
|
-
if (
|
|
29874
|
-
const current =
|
|
29983
|
+
const path3 = this._matcher.path;
|
|
29984
|
+
if (path3.length === 0) return false;
|
|
29985
|
+
const current = path3[path3.length - 1];
|
|
29875
29986
|
return current.values !== void 0 && attrName in current.values;
|
|
29876
29987
|
}
|
|
29877
29988
|
/**
|
|
@@ -29879,18 +29990,18 @@ var init_Matcher = __esm({
|
|
|
29879
29990
|
* @returns {number}
|
|
29880
29991
|
*/
|
|
29881
29992
|
getPosition() {
|
|
29882
|
-
const
|
|
29883
|
-
if (
|
|
29884
|
-
return
|
|
29993
|
+
const path3 = this._matcher.path;
|
|
29994
|
+
if (path3.length === 0) return -1;
|
|
29995
|
+
return path3[path3.length - 1].position ?? 0;
|
|
29885
29996
|
}
|
|
29886
29997
|
/**
|
|
29887
29998
|
* Get current node's repeat counter (occurrence count of this tag name).
|
|
29888
29999
|
* @returns {number}
|
|
29889
30000
|
*/
|
|
29890
30001
|
getCounter() {
|
|
29891
|
-
const
|
|
29892
|
-
if (
|
|
29893
|
-
return
|
|
30002
|
+
const path3 = this._matcher.path;
|
|
30003
|
+
if (path3.length === 0) return -1;
|
|
30004
|
+
return path3[path3.length - 1].counter ?? 0;
|
|
29894
30005
|
}
|
|
29895
30006
|
/**
|
|
29896
30007
|
* Get current node's sibling index (alias for getPosition).
|
|
@@ -41656,12 +41767,12 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
41656
41767
|
const password = request.password ?? "";
|
|
41657
41768
|
auth = `${username}:${password}`;
|
|
41658
41769
|
}
|
|
41659
|
-
let
|
|
41770
|
+
let path3 = request.path;
|
|
41660
41771
|
if (queryString) {
|
|
41661
|
-
|
|
41772
|
+
path3 += `?${queryString}`;
|
|
41662
41773
|
}
|
|
41663
41774
|
if (request.fragment) {
|
|
41664
|
-
|
|
41775
|
+
path3 += `#${request.fragment}`;
|
|
41665
41776
|
}
|
|
41666
41777
|
let hostname = request.hostname ?? "";
|
|
41667
41778
|
if (hostname[0] === "[" && hostname.endsWith("]")) {
|
|
@@ -41673,7 +41784,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
41673
41784
|
headers: request.headers,
|
|
41674
41785
|
host: hostname,
|
|
41675
41786
|
method: request.method,
|
|
41676
|
-
path:
|
|
41787
|
+
path: path3,
|
|
41677
41788
|
port: request.port,
|
|
41678
41789
|
agent,
|
|
41679
41790
|
auth
|
|
@@ -52252,7 +52363,7 @@ var init_table_policy = __esm({
|
|
|
52252
52363
|
});
|
|
52253
52364
|
|
|
52254
52365
|
// src/ai/llm-client.ts
|
|
52255
|
-
import { createRequire as
|
|
52366
|
+
import { createRequire as createRequire3 } from "module";
|
|
52256
52367
|
var DEFAULT_MODEL, CHEAPEST_MODEL;
|
|
52257
52368
|
var init_llm_client = __esm({
|
|
52258
52369
|
"src/ai/llm-client.ts"() {
|
|
@@ -52426,7 +52537,7 @@ var init_summarize = __esm({
|
|
|
52426
52537
|
import { JSDOM } from "jsdom";
|
|
52427
52538
|
import { Readability } from "@mozilla/readability";
|
|
52428
52539
|
import { basename as basename5 } from "path";
|
|
52429
|
-
import { createRequire as
|
|
52540
|
+
import { createRequire as createRequire4 } from "module";
|
|
52430
52541
|
async function crawlUrl(rawUrl, opts = {}) {
|
|
52431
52542
|
const u2 = await assertSafeUrl(rawUrl, opts.allowPrivate ?? false);
|
|
52432
52543
|
const fetchImpl = opts.fetcher ?? fetch;
|
|
@@ -52673,7 +52784,7 @@ async function renderViaPlaywright(url, timeoutMs, warnIfMissing = false) {
|
|
|
52673
52784
|
let chromium;
|
|
52674
52785
|
try {
|
|
52675
52786
|
const importMetaUrl = import.meta.url;
|
|
52676
|
-
const req = importMetaUrl ?
|
|
52787
|
+
const req = importMetaUrl ? createRequire4(importMetaUrl) : __require;
|
|
52677
52788
|
const pw = req("playwright");
|
|
52678
52789
|
chromium = pw.chromium;
|
|
52679
52790
|
} catch {
|
|
@@ -55594,11 +55705,11 @@ function stripHtml(html) {
|
|
|
55594
55705
|
const text = decodeXmlEntities(stripTags(noScript));
|
|
55595
55706
|
return text.replace(/[ \t\f\r]+/g, " ").replace(/ *\n */g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
55596
55707
|
}
|
|
55597
|
-
async function unzip(
|
|
55708
|
+
async function unzip(path3) {
|
|
55598
55709
|
const fflate = await loadParser("fflate");
|
|
55599
55710
|
if (!fflate || typeof fflate.unzipSync !== "function") return null;
|
|
55600
55711
|
try {
|
|
55601
|
-
const buf = await readFile6(
|
|
55712
|
+
const buf = await readFile6(path3);
|
|
55602
55713
|
let total = 0;
|
|
55603
55714
|
return fflate.unzipSync(new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength), {
|
|
55604
55715
|
filter: (file) => {
|
|
@@ -55627,35 +55738,35 @@ var init_helpers2 = __esm({
|
|
|
55627
55738
|
|
|
55628
55739
|
// src/gui/ai/doc/ooxml.ts
|
|
55629
55740
|
import { readFile as readFile7 } from "fs/promises";
|
|
55630
|
-
async function extractDocx(
|
|
55741
|
+
async function extractDocx(path3) {
|
|
55631
55742
|
const mod = await loadParser("mammoth");
|
|
55632
55743
|
const lib = mod?.default ?? mod;
|
|
55633
55744
|
if (!lib || typeof lib.extractRawText !== "function") return null;
|
|
55634
55745
|
try {
|
|
55635
|
-
const { value } = await lib.extractRawText({ path:
|
|
55746
|
+
const { value } = await lib.extractRawText({ path: path3 });
|
|
55636
55747
|
return nullIfEmpty(value);
|
|
55637
55748
|
} catch {
|
|
55638
55749
|
return null;
|
|
55639
55750
|
}
|
|
55640
55751
|
}
|
|
55641
|
-
async function extractDoc(
|
|
55752
|
+
async function extractDoc(path3) {
|
|
55642
55753
|
const mod = await loadParser(
|
|
55643
55754
|
"word-extractor"
|
|
55644
55755
|
);
|
|
55645
55756
|
const Ctor = mod && "default" in mod ? mod.default : mod;
|
|
55646
55757
|
if (typeof Ctor !== "function") return null;
|
|
55647
55758
|
try {
|
|
55648
|
-
const doc = await new Ctor().extract(
|
|
55759
|
+
const doc = await new Ctor().extract(path3);
|
|
55649
55760
|
return nullIfEmpty(doc.getBody());
|
|
55650
55761
|
} catch {
|
|
55651
55762
|
return null;
|
|
55652
55763
|
}
|
|
55653
55764
|
}
|
|
55654
|
-
async function extractPdf(
|
|
55765
|
+
async function extractPdf(path3) {
|
|
55655
55766
|
const unpdf = await loadParser("unpdf");
|
|
55656
55767
|
if (!unpdf || typeof unpdf.getDocumentProxy !== "function") return null;
|
|
55657
55768
|
try {
|
|
55658
|
-
const buf = await readFile7(
|
|
55769
|
+
const buf = await readFile7(path3);
|
|
55659
55770
|
const data = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
55660
55771
|
const text = await withTimeout(
|
|
55661
55772
|
(async () => {
|
|
@@ -55687,8 +55798,8 @@ function slideText(xml) {
|
|
|
55687
55798
|
}
|
|
55688
55799
|
return paras.join("\n");
|
|
55689
55800
|
}
|
|
55690
|
-
async function extractPptx(
|
|
55691
|
-
const entries = await unzip(
|
|
55801
|
+
async function extractPptx(path3) {
|
|
55802
|
+
const entries = await unzip(path3);
|
|
55692
55803
|
if (!entries) return null;
|
|
55693
55804
|
const slides = Object.keys(entries).filter((n3) => /^ppt\/slides\/slide\d+\.xml$/.test(n3)).sort((a6, b6) => partNumber(a6) - partNumber(b6));
|
|
55694
55805
|
if (slides.length === 0) return null;
|
|
@@ -55706,8 +55817,8 @@ async function extractPptx(path2) {
|
|
|
55706
55817
|
}
|
|
55707
55818
|
return nullIfEmpty(parts.join("\n\n"));
|
|
55708
55819
|
}
|
|
55709
|
-
async function extractXlsx(
|
|
55710
|
-
const entries = await unzip(
|
|
55820
|
+
async function extractXlsx(path3) {
|
|
55821
|
+
const entries = await unzip(path3);
|
|
55711
55822
|
if (!entries) return null;
|
|
55712
55823
|
const shared = [];
|
|
55713
55824
|
const ssBytes = entries["xl/sharedStrings.xml"];
|
|
@@ -55765,8 +55876,8 @@ function odfWhitespace(s2) {
|
|
|
55765
55876
|
function odfParagraph(inner) {
|
|
55766
55877
|
return decodeXmlEntities(stripTags(odfWhitespace(inner))).trim();
|
|
55767
55878
|
}
|
|
55768
|
-
async function extractOdfText(
|
|
55769
|
-
const entries = await unzip(
|
|
55879
|
+
async function extractOdfText(path3) {
|
|
55880
|
+
const entries = await unzip(path3);
|
|
55770
55881
|
if (!entries) return null;
|
|
55771
55882
|
const contentBytes = entries["content.xml"];
|
|
55772
55883
|
if (!contentBytes) return null;
|
|
@@ -55788,8 +55899,8 @@ async function extractOdfText(path2) {
|
|
|
55788
55899
|
}
|
|
55789
55900
|
return nullIfEmpty(lines.join("\n"));
|
|
55790
55901
|
}
|
|
55791
|
-
async function extractOds(
|
|
55792
|
-
const entries = await unzip(
|
|
55902
|
+
async function extractOds(path3) {
|
|
55903
|
+
const entries = await unzip(path3);
|
|
55793
55904
|
if (!entries) return null;
|
|
55794
55905
|
const contentBytes = entries["content.xml"];
|
|
55795
55906
|
if (!contentBytes) return null;
|
|
@@ -55848,8 +55959,8 @@ function resolveHref(baseDir, href) {
|
|
|
55848
55959
|
}
|
|
55849
55960
|
return normalizeZipPath(baseDir + h6);
|
|
55850
55961
|
}
|
|
55851
|
-
async function extractEpub(
|
|
55852
|
-
const entries = await unzip(
|
|
55962
|
+
async function extractEpub(path3) {
|
|
55963
|
+
const entries = await unzip(path3);
|
|
55853
55964
|
if (!entries) return null;
|
|
55854
55965
|
let order = [];
|
|
55855
55966
|
const container = entries["META-INF/container.xml"];
|
|
@@ -55933,9 +56044,9 @@ function rtfToText(rtf) {
|
|
|
55933
56044
|
s2 = s2.replace(/[{}]/g, "");
|
|
55934
56045
|
return s2.replace(/[ \t]+/g, (m4) => m4.includes(" ") ? " " : " ").replace(/[ \t]\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
55935
56046
|
}
|
|
55936
|
-
async function extractRtf(
|
|
56047
|
+
async function extractRtf(path3) {
|
|
55937
56048
|
try {
|
|
55938
|
-
const raw = await readFile8(
|
|
56049
|
+
const raw = await readFile8(path3, "latin1");
|
|
55939
56050
|
if (!raw.startsWith("{\\rtf")) return null;
|
|
55940
56051
|
return nullIfEmpty(rtfToText(raw));
|
|
55941
56052
|
} catch {
|
|
@@ -55981,27 +56092,27 @@ var init_other = __esm({
|
|
|
55981
56092
|
});
|
|
55982
56093
|
|
|
55983
56094
|
// src/gui/ai/doc-extractors.ts
|
|
55984
|
-
async function extractDocument(
|
|
56095
|
+
async function extractDocument(path3, ext) {
|
|
55985
56096
|
switch (ext) {
|
|
55986
56097
|
case ".docx":
|
|
55987
|
-
return extractDocx(
|
|
56098
|
+
return extractDocx(path3);
|
|
55988
56099
|
case ".doc":
|
|
55989
|
-
return extractDoc(
|
|
56100
|
+
return extractDoc(path3);
|
|
55990
56101
|
case ".pdf":
|
|
55991
|
-
return extractPdf(
|
|
56102
|
+
return extractPdf(path3);
|
|
55992
56103
|
case ".pptx":
|
|
55993
|
-
return extractPptx(
|
|
56104
|
+
return extractPptx(path3);
|
|
55994
56105
|
case ".xlsx":
|
|
55995
|
-
return extractXlsx(
|
|
56106
|
+
return extractXlsx(path3);
|
|
55996
56107
|
case ".odt":
|
|
55997
56108
|
case ".odp":
|
|
55998
|
-
return extractOdfText(
|
|
56109
|
+
return extractOdfText(path3);
|
|
55999
56110
|
case ".ods":
|
|
56000
|
-
return extractOds(
|
|
56111
|
+
return extractOds(path3);
|
|
56001
56112
|
case ".epub":
|
|
56002
|
-
return extractEpub(
|
|
56113
|
+
return extractEpub(path3);
|
|
56003
56114
|
case ".rtf":
|
|
56004
|
-
return extractRtf(
|
|
56115
|
+
return extractRtf(path3);
|
|
56005
56116
|
default:
|
|
56006
56117
|
return null;
|
|
56007
56118
|
}
|
|
@@ -56024,17 +56135,17 @@ function languageOf(name) {
|
|
|
56024
56135
|
function truncate2(s2) {
|
|
56025
56136
|
return s2.length > MAX_TEXT2 ? s2.slice(0, MAX_TEXT2) : s2;
|
|
56026
56137
|
}
|
|
56027
|
-
async function parseFile(
|
|
56028
|
-
const name = originalName ?? basename7(
|
|
56138
|
+
async function parseFile(path3, mimeHint, originalName) {
|
|
56139
|
+
const name = originalName ?? basename7(path3);
|
|
56029
56140
|
const ext = extname(name).toLowerCase();
|
|
56030
56141
|
const lang = languageOf(name);
|
|
56031
56142
|
if (lang) {
|
|
56032
|
-
return { text: truncate2(await readFile9(
|
|
56143
|
+
return { text: truncate2(await readFile9(path3, "utf8")), language: lang };
|
|
56033
56144
|
}
|
|
56034
56145
|
if (mimeHint && TEXT_MIME.test(mimeHint) || TEXT_EXT.has(ext)) {
|
|
56035
|
-
return { text: truncate2(await readFile9(
|
|
56146
|
+
return { text: truncate2(await readFile9(path3, "utf8")) };
|
|
56036
56147
|
}
|
|
56037
|
-
const doc = await extractDocument(
|
|
56148
|
+
const doc = await extractDocument(path3, ext);
|
|
56038
56149
|
if (doc != null) {
|
|
56039
56150
|
return { text: truncate2(doc) };
|
|
56040
56151
|
}
|
|
@@ -56623,8 +56734,8 @@ function isWriteConflict(e6) {
|
|
|
56623
56734
|
function normalizeUrl(s2) {
|
|
56624
56735
|
try {
|
|
56625
56736
|
const u2 = new URL(s2.trim());
|
|
56626
|
-
const
|
|
56627
|
-
return `${u2.protocol}//${u2.host.toLowerCase()}${
|
|
56737
|
+
const path3 = u2.pathname.replace(/\/+$/, "");
|
|
56738
|
+
return `${u2.protocol}//${u2.host.toLowerCase()}${path3}${u2.search}`;
|
|
56628
56739
|
} catch {
|
|
56629
56740
|
return null;
|
|
56630
56741
|
}
|
|
@@ -57348,7 +57459,7 @@ var init_tools = __esm({
|
|
|
57348
57459
|
});
|
|
57349
57460
|
|
|
57350
57461
|
// src/gui/ai/chat.ts
|
|
57351
|
-
import { createRequire as
|
|
57462
|
+
import { createRequire as createRequire7 } from "module";
|
|
57352
57463
|
function capToolResult(s2) {
|
|
57353
57464
|
if (s2.length <= MAX_TOOL_RESULT_CHARS) return s2;
|
|
57354
57465
|
if (s2.length > MAX_TOOL_RESULT_SKIP)
|
|
@@ -57581,7 +57692,7 @@ async function* runChat(opts) {
|
|
|
57581
57692
|
function loadSdk() {
|
|
57582
57693
|
if (!_sdk) {
|
|
57583
57694
|
const importMetaUrl = import.meta.url;
|
|
57584
|
-
const req = importMetaUrl ?
|
|
57695
|
+
const req = importMetaUrl ? createRequire7(importMetaUrl) : __require;
|
|
57585
57696
|
try {
|
|
57586
57697
|
_sdk = req("@anthropic-ai/sdk");
|
|
57587
57698
|
} catch (err) {
|
|
@@ -58700,20 +58811,20 @@ function blobHandle(row, latticeRoot) {
|
|
|
58700
58811
|
};
|
|
58701
58812
|
}
|
|
58702
58813
|
function fsHandle(row) {
|
|
58703
|
-
const
|
|
58814
|
+
const path3 = row.ref_uri ?? "";
|
|
58704
58815
|
return {
|
|
58705
58816
|
kind: "local_ref",
|
|
58706
58817
|
provider: "fs",
|
|
58707
|
-
location:
|
|
58818
|
+
location: path3,
|
|
58708
58819
|
async readContent() {
|
|
58709
58820
|
try {
|
|
58710
|
-
return await readFile4(
|
|
58821
|
+
return await readFile4(path3);
|
|
58711
58822
|
} catch (e6) {
|
|
58712
|
-
throw new ReferenceUnavailableError(
|
|
58823
|
+
throw new ReferenceUnavailableError(path3, e6.message);
|
|
58713
58824
|
}
|
|
58714
58825
|
},
|
|
58715
58826
|
async getMetadata() {
|
|
58716
|
-
return statMeta(
|
|
58827
|
+
return statMeta(path3, row);
|
|
58717
58828
|
}
|
|
58718
58829
|
};
|
|
58719
58830
|
}
|
|
@@ -58782,9 +58893,9 @@ function meta(available, parts = {}) {
|
|
|
58782
58893
|
if (parts.extra != null) m4.extra = parts.extra;
|
|
58783
58894
|
return m4;
|
|
58784
58895
|
}
|
|
58785
|
-
async function statMeta(
|
|
58896
|
+
async function statMeta(path3, row) {
|
|
58786
58897
|
try {
|
|
58787
|
-
const s2 = await stat(
|
|
58898
|
+
const s2 = await stat(path3);
|
|
58788
58899
|
return meta(true, {
|
|
58789
58900
|
size_bytes: s2.size,
|
|
58790
58901
|
modified_at: s2.mtime.toISOString(),
|
|
@@ -59519,12 +59630,12 @@ function isBetter(next, prev) {
|
|
|
59519
59630
|
|
|
59520
59631
|
// src/ai/vision.ts
|
|
59521
59632
|
init_llm_client();
|
|
59522
|
-
import { createRequire as
|
|
59633
|
+
import { createRequire as createRequire5 } from "module";
|
|
59523
59634
|
import { readFile as readFile5 } from "fs/promises";
|
|
59524
59635
|
var DEFAULT_PROMPT = "Describe this image for a knowledge base in 2-4 factual sentences: what it shows, any visible text, and notable details. No preamble.";
|
|
59525
59636
|
var MAX_DIM = 1568;
|
|
59526
|
-
async function describeImage(auth,
|
|
59527
|
-
const data = (await normalizeImage(
|
|
59637
|
+
async function describeImage(auth, path3, opts = {}) {
|
|
59638
|
+
const data = (await normalizeImage(path3, opts.maxBytes ?? 14e5)).toString("base64");
|
|
59528
59639
|
const sender = opts.sender ?? defaultSender(auth);
|
|
59529
59640
|
const text = await sender({
|
|
59530
59641
|
media_type: "image/jpeg",
|
|
@@ -59535,8 +59646,8 @@ async function describeImage(auth, path2, opts = {}) {
|
|
|
59535
59646
|
return text.trim();
|
|
59536
59647
|
}
|
|
59537
59648
|
var DEFAULT_PDF_PROMPT = "Read this document for a knowledge base. First transcribe its readable text, then add a 2-4 sentence factual summary of what it is and its key details. It may be a scanned/image-only PDF \u2014 read the text from the page images. No preamble.";
|
|
59538
|
-
async function describePdf(auth,
|
|
59539
|
-
const buf = await readFile5(
|
|
59649
|
+
async function describePdf(auth, path3, opts = {}) {
|
|
59650
|
+
const buf = await readFile5(path3);
|
|
59540
59651
|
const maxBytes = opts.maxBytes ?? 3e7;
|
|
59541
59652
|
if (buf.length > maxBytes) {
|
|
59542
59653
|
throw new Error(
|
|
@@ -59551,19 +59662,19 @@ async function describePdf(auth, path2, opts = {}) {
|
|
|
59551
59662
|
});
|
|
59552
59663
|
return text.trim();
|
|
59553
59664
|
}
|
|
59554
|
-
async function normalizeImage(
|
|
59665
|
+
async function normalizeImage(path3, maxBytes) {
|
|
59555
59666
|
const sharpMod = await import("sharp");
|
|
59556
59667
|
const sharp = sharpMod.default;
|
|
59557
59668
|
let quality = 80;
|
|
59558
|
-
let buf = await renderJpeg(sharp,
|
|
59669
|
+
let buf = await renderJpeg(sharp, path3, quality);
|
|
59559
59670
|
while (buf.length > maxBytes && quality > 35) {
|
|
59560
59671
|
quality -= 15;
|
|
59561
|
-
buf = await renderJpeg(sharp,
|
|
59672
|
+
buf = await renderJpeg(sharp, path3, quality);
|
|
59562
59673
|
}
|
|
59563
59674
|
return buf;
|
|
59564
59675
|
}
|
|
59565
|
-
function renderJpeg(sharp,
|
|
59566
|
-
return sharp(
|
|
59676
|
+
function renderJpeg(sharp, path3, quality) {
|
|
59677
|
+
return sharp(path3).rotate().resize({ width: MAX_DIM, height: MAX_DIM, fit: "inside", withoutEnlargement: true }).jpeg({ quality }).toBuffer();
|
|
59567
59678
|
}
|
|
59568
59679
|
function buildVisionAnthropicConfig(auth) {
|
|
59569
59680
|
const config = {};
|
|
@@ -59581,7 +59692,7 @@ function buildVisionAnthropicConfig(auth) {
|
|
|
59581
59692
|
function defaultSender(auth) {
|
|
59582
59693
|
return async (input) => {
|
|
59583
59694
|
const importMetaUrl = import.meta.url;
|
|
59584
|
-
const req = importMetaUrl ?
|
|
59695
|
+
const req = importMetaUrl ? createRequire5(importMetaUrl) : __require;
|
|
59585
59696
|
const sdk = req("@anthropic-ai/sdk");
|
|
59586
59697
|
const Anthropic = sdk.Anthropic ?? sdk.default;
|
|
59587
59698
|
if (!Anthropic) throw new Error("Could not resolve Anthropic from '@anthropic-ai/sdk'");
|
|
@@ -59608,7 +59719,7 @@ function defaultSender(auth) {
|
|
|
59608
59719
|
function defaultPdfSender(auth) {
|
|
59609
59720
|
return async (input) => {
|
|
59610
59721
|
const importMetaUrl = import.meta.url;
|
|
59611
|
-
const req = importMetaUrl ?
|
|
59722
|
+
const req = importMetaUrl ? createRequire5(importMetaUrl) : __require;
|
|
59612
59723
|
const sdk = req("@anthropic-ai/sdk");
|
|
59613
59724
|
const Anthropic = sdk.Anthropic ?? sdk.default;
|
|
59614
59725
|
if (!Anthropic) throw new Error("Could not resolve Anthropic from '@anthropic-ai/sdk'");
|
|
@@ -59919,12 +60030,12 @@ init_postgres();
|
|
|
59919
60030
|
|
|
59920
60031
|
// src/gui/realtime.ts
|
|
59921
60032
|
import { EventEmitter } from "events";
|
|
59922
|
-
import { createRequire as
|
|
60033
|
+
import { createRequire as createRequire6 } from "module";
|
|
59923
60034
|
var _pgModule = null;
|
|
59924
60035
|
function loadPg() {
|
|
59925
60036
|
if (_pgModule) return _pgModule;
|
|
59926
60037
|
const importMetaUrl = import.meta.url;
|
|
59927
|
-
const requireFromHere = importMetaUrl ?
|
|
60038
|
+
const requireFromHere = importMetaUrl ? createRequire6(importMetaUrl) : (
|
|
59928
60039
|
// CJS fallback — Node provides `require` on every CJS module scope.
|
|
59929
60040
|
__require
|
|
59930
60041
|
);
|
|
@@ -61298,7 +61409,7 @@ async function applySchemaConfig(active, entry, direction, autoRender) {
|
|
|
61298
61409
|
const doc = loadConfigDoc(active.configPath);
|
|
61299
61410
|
const inv = direction === "inverse";
|
|
61300
61411
|
const ddl = [];
|
|
61301
|
-
const has = (
|
|
61412
|
+
const has = (path3) => doc.getIn(path3) !== void 0;
|
|
61302
61413
|
const reAddEntity = async (name, def) => {
|
|
61303
61414
|
if (has(["entities", name])) {
|
|
61304
61415
|
throw new Error(`Cannot restore "${name}": an entity with that name already exists`);
|
|
@@ -71860,9 +71971,9 @@ function rewriteDbLine(configPath, newValue) {
|
|
|
71860
71971
|
function parseSaveBody(body) {
|
|
71861
71972
|
const type = body.type;
|
|
71862
71973
|
if (type === "sqlite") {
|
|
71863
|
-
const
|
|
71864
|
-
if (!
|
|
71865
|
-
return { type: "sqlite", path:
|
|
71974
|
+
const path3 = typeof body.path === "string" && body.path.trim() ? body.path.trim() : "";
|
|
71975
|
+
if (!path3) return null;
|
|
71976
|
+
return { type: "sqlite", path: path3 };
|
|
71866
71977
|
}
|
|
71867
71978
|
if (type === "postgres") {
|
|
71868
71979
|
const label = typeof body.label === "string" && body.label.trim() ? body.label.trim() : "";
|
|
@@ -74643,28 +74754,28 @@ ${err.stack ?? ""}`
|
|
|
74643
74754
|
return null;
|
|
74644
74755
|
}
|
|
74645
74756
|
}
|
|
74646
|
-
async function extractImage(db,
|
|
74757
|
+
async function extractImage(db, path3, mime) {
|
|
74647
74758
|
if (!mime.startsWith("image/")) return null;
|
|
74648
74759
|
const auth = await resolveClaudeAuth(db);
|
|
74649
74760
|
if (!auth) return null;
|
|
74650
74761
|
try {
|
|
74651
|
-
const text = await describeImage(auth,
|
|
74762
|
+
const text = await describeImage(auth, path3);
|
|
74652
74763
|
return text.trim() ? { text, skip: false } : null;
|
|
74653
74764
|
} catch (e6) {
|
|
74654
74765
|
console.warn("[ingest] image vision failed:", e6.message);
|
|
74655
74766
|
return null;
|
|
74656
74767
|
}
|
|
74657
74768
|
}
|
|
74658
|
-
async function extractSource(db,
|
|
74659
|
-
const vision = await extractImage(db,
|
|
74769
|
+
async function extractSource(db, path3, mime, name) {
|
|
74770
|
+
const vision = await extractImage(db, path3, mime);
|
|
74660
74771
|
if (vision) return vision;
|
|
74661
|
-
const parsed = await parseFile(
|
|
74772
|
+
const parsed = await parseFile(path3, mime, name);
|
|
74662
74773
|
if (!parsed.skip) return parsed;
|
|
74663
74774
|
if (mime === "application/pdf") {
|
|
74664
74775
|
const auth = await resolveClaudeAuth(db);
|
|
74665
74776
|
if (auth) {
|
|
74666
74777
|
try {
|
|
74667
|
-
const text = await describePdf(auth,
|
|
74778
|
+
const text = await describePdf(auth, path3);
|
|
74668
74779
|
if (text.trim()) return { ...parsed, text, skip: false };
|
|
74669
74780
|
} catch (e6) {
|
|
74670
74781
|
console.warn("[ingest] Claude PDF read failed:", e6.message);
|
|
@@ -75077,11 +75188,11 @@ async function readImportSourceFromFile(db, fileId, latticeRoot) {
|
|
|
75077
75188
|
[fileId]
|
|
75078
75189
|
);
|
|
75079
75190
|
if (!row) throw badRequest("Unknown import file: " + fileId);
|
|
75080
|
-
const
|
|
75081
|
-
if (!
|
|
75191
|
+
const path3 = localPathOf2(row, latticeRoot);
|
|
75192
|
+
if (!path3 || !existsSync26(path3)) {
|
|
75082
75193
|
throw badRequest("The import file\u2019s bytes are not available locally.");
|
|
75083
75194
|
}
|
|
75084
|
-
const sizeBytes = statSync10(
|
|
75195
|
+
const sizeBytes = statSync10(path3).size;
|
|
75085
75196
|
if (sizeBytes > MAX_INGEST_BYTES) {
|
|
75086
75197
|
throw badRequest(
|
|
75087
75198
|
`The import file is too large (${String(Math.round(sizeBytes / 1e6))} MB); the limit is ${String(Math.round(MAX_INGEST_BYTES / 1e6))} MB.`
|
|
@@ -75090,11 +75201,11 @@ async function readImportSourceFromFile(db, fileId, latticeRoot) {
|
|
|
75090
75201
|
const name = row.original_name ?? "";
|
|
75091
75202
|
const mime = row.mime ?? "";
|
|
75092
75203
|
if (/\.xlsx?$/i.test(name) || mime.includes("spreadsheet") || mime.includes("excel")) {
|
|
75093
|
-
return excelToRecords(
|
|
75204
|
+
return excelToRecords(path3);
|
|
75094
75205
|
}
|
|
75095
75206
|
let parsed;
|
|
75096
75207
|
try {
|
|
75097
|
-
parsed = JSON.parse(readFileSync24(
|
|
75208
|
+
parsed = JSON.parse(readFileSync24(path3, "utf8"));
|
|
75098
75209
|
} catch {
|
|
75099
75210
|
throw badRequest("The import file is not valid JSON.");
|
|
75100
75211
|
}
|