@harperfast/agent 0.11.3 → 0.11.5
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/agent.js +55 -81
- package/package.json +1 -2
package/dist/agent.js
CHANGED
|
@@ -682,7 +682,10 @@ import chalk4 from "chalk";
|
|
|
682
682
|
import { existsSync as existsSync3 } from "fs";
|
|
683
683
|
import { join as join5 } from "path";
|
|
684
684
|
function sayHi() {
|
|
685
|
+
const pkg = getOwnPackageJson();
|
|
686
|
+
const packageVersion = pkg.version;
|
|
685
687
|
const harperAppExists = existsSync3(join5(trackedState.cwd, "config.yaml"));
|
|
688
|
+
console.log(chalk4.dim(`Version: ${chalk4.cyan(packageVersion)}`) + ` ${chalk4.redBright("ALPHA")}`);
|
|
686
689
|
console.log(chalk4.dim(`Working directory: ${chalk4.cyan(trackedState.cwd)}`));
|
|
687
690
|
console.log(chalk4.dim(`Harper app detected: ${chalk4.cyan(harperAppExists ? "Yes" : "No")}`));
|
|
688
691
|
console.log(chalk4.dim(`Press Ctrl+C or hit enter twice to exit.
|
|
@@ -2432,58 +2435,65 @@ Stack: ${String(err.stack).split("\n").slice(0, 8).join("\n")}` : "";
|
|
|
2432
2435
|
|
|
2433
2436
|
// utils/sessions/DiskSession.ts
|
|
2434
2437
|
import { MemorySession } from "@openai/agents";
|
|
2435
|
-
import
|
|
2438
|
+
import { existsSync as existsSync8 } from "fs";
|
|
2439
|
+
import { mkdir as mkdir2, readFile as readFile6, rename, writeFile as writeFile4 } from "fs/promises";
|
|
2440
|
+
import { dirname as dirname5 } from "path";
|
|
2436
2441
|
var DiskSession = class extends MemorySession {
|
|
2437
|
-
|
|
2442
|
+
filePath;
|
|
2438
2443
|
ready;
|
|
2439
|
-
|
|
2440
|
-
constructor(dbPath, options) {
|
|
2444
|
+
constructor(filePath, options) {
|
|
2441
2445
|
super(options);
|
|
2442
|
-
this.
|
|
2446
|
+
this.filePath = filePath;
|
|
2443
2447
|
this.ready = this.init(options);
|
|
2444
2448
|
}
|
|
2445
2449
|
async init(options) {
|
|
2446
|
-
await this.
|
|
2447
|
-
CREATE TABLE IF NOT EXISTS session_items (
|
|
2448
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
2449
|
-
sessionId TEXT,
|
|
2450
|
-
data JSONB
|
|
2451
|
-
)
|
|
2452
|
-
`);
|
|
2453
|
-
try {
|
|
2454
|
-
await this.get("SELECT jsonb('{}')");
|
|
2455
|
-
this.useJsonb = true;
|
|
2456
|
-
} catch {
|
|
2457
|
-
this.useJsonb = false;
|
|
2458
|
-
}
|
|
2450
|
+
const storage = await this.loadStorage();
|
|
2459
2451
|
let sessionId = this.sessionId;
|
|
2460
2452
|
if (!options?.sessionId) {
|
|
2461
|
-
const
|
|
2462
|
-
if (
|
|
2463
|
-
sessionId =
|
|
2453
|
+
const sessionIds = Object.keys(storage.sessions);
|
|
2454
|
+
if (sessionIds.length > 0) {
|
|
2455
|
+
sessionId = sessionIds[0];
|
|
2464
2456
|
this.sessionId = sessionId;
|
|
2465
2457
|
}
|
|
2466
2458
|
}
|
|
2467
2459
|
if (!sessionId) {
|
|
2468
2460
|
sessionId = this.sessionId || "default-session";
|
|
2469
2461
|
}
|
|
2470
|
-
const
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
);
|
|
2474
|
-
if (rows.length > 0) {
|
|
2475
|
-
const itemsFromDb = rows.map((row) => JSON.parse(row.data));
|
|
2476
|
-
this.items = itemsFromDb;
|
|
2462
|
+
const itemsFromStorage = storage.sessions[sessionId];
|
|
2463
|
+
if (itemsFromStorage) {
|
|
2464
|
+
this.items = itemsFromStorage;
|
|
2477
2465
|
} else {
|
|
2478
2466
|
const items = this.items || [];
|
|
2479
2467
|
if (items.length > 0) {
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
}
|
|
2468
|
+
await this.updateStorage((s) => {
|
|
2469
|
+
s.sessions[sessionId] = items;
|
|
2470
|
+
});
|
|
2484
2471
|
}
|
|
2485
2472
|
}
|
|
2486
2473
|
}
|
|
2474
|
+
async loadStorage() {
|
|
2475
|
+
if (existsSync8(this.filePath)) {
|
|
2476
|
+
try {
|
|
2477
|
+
const data = await readFile6(this.filePath, "utf-8");
|
|
2478
|
+
return JSON.parse(data);
|
|
2479
|
+
} catch (e) {
|
|
2480
|
+
console.error(`Failed to read session file ${this.filePath}:`, e);
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
return { sessions: {} };
|
|
2484
|
+
}
|
|
2485
|
+
async updateStorage(update) {
|
|
2486
|
+
const storage = await this.loadStorage();
|
|
2487
|
+
update(storage);
|
|
2488
|
+
const dir = dirname5(this.filePath);
|
|
2489
|
+
if (!existsSync8(dir)) {
|
|
2490
|
+
await mkdir2(dir, { recursive: true });
|
|
2491
|
+
}
|
|
2492
|
+
const data = JSON.stringify(storage, null, 2);
|
|
2493
|
+
const tempPath = `${this.filePath}.tmp`;
|
|
2494
|
+
await writeFile4(tempPath, data, "utf-8");
|
|
2495
|
+
await rename(tempPath, this.filePath);
|
|
2496
|
+
}
|
|
2487
2497
|
async getSessionId() {
|
|
2488
2498
|
await this.ready;
|
|
2489
2499
|
return super.getSessionId();
|
|
@@ -2496,28 +2506,23 @@ var DiskSession = class extends MemorySession {
|
|
|
2496
2506
|
await this.ready;
|
|
2497
2507
|
await super.addItems(items);
|
|
2498
2508
|
const sessionId = await this.getSessionId();
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2509
|
+
await this.updateStorage((storage) => {
|
|
2510
|
+
if (!storage.sessions[sessionId]) {
|
|
2511
|
+
storage.sessions[sessionId] = [];
|
|
2512
|
+
}
|
|
2513
|
+
storage.sessions[sessionId].push(...items);
|
|
2514
|
+
});
|
|
2503
2515
|
}
|
|
2504
2516
|
async popItem() {
|
|
2505
2517
|
await this.ready;
|
|
2506
2518
|
const item = await super.popItem();
|
|
2507
2519
|
if (item) {
|
|
2508
2520
|
const sessionId = await this.getSessionId();
|
|
2509
|
-
await this.
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
WHERE sessionId = ?
|
|
2515
|
-
ORDER BY id DESC
|
|
2516
|
-
LIMIT 1
|
|
2517
|
-
)
|
|
2518
|
-
`,
|
|
2519
|
-
sessionId
|
|
2520
|
-
);
|
|
2521
|
+
await this.updateStorage((storage) => {
|
|
2522
|
+
if (storage.sessions[sessionId]) {
|
|
2523
|
+
storage.sessions[sessionId].pop();
|
|
2524
|
+
}
|
|
2525
|
+
});
|
|
2521
2526
|
}
|
|
2522
2527
|
return item;
|
|
2523
2528
|
}
|
|
@@ -2525,39 +2530,8 @@ var DiskSession = class extends MemorySession {
|
|
|
2525
2530
|
await this.ready;
|
|
2526
2531
|
await super.clearSession();
|
|
2527
2532
|
const sessionId = await this.getSessionId();
|
|
2528
|
-
await this.
|
|
2529
|
-
|
|
2530
|
-
run(sql, ...params) {
|
|
2531
|
-
return new Promise((resolve2, reject) => {
|
|
2532
|
-
this.db.run(sql, ...params, (err) => {
|
|
2533
|
-
if (err) {
|
|
2534
|
-
reject(err);
|
|
2535
|
-
} else {
|
|
2536
|
-
resolve2();
|
|
2537
|
-
}
|
|
2538
|
-
});
|
|
2539
|
-
});
|
|
2540
|
-
}
|
|
2541
|
-
get(sql, ...params) {
|
|
2542
|
-
return new Promise((resolve2, reject) => {
|
|
2543
|
-
this.db.get(sql, ...params, (err, row) => {
|
|
2544
|
-
if (err) {
|
|
2545
|
-
reject(err);
|
|
2546
|
-
} else {
|
|
2547
|
-
resolve2(row);
|
|
2548
|
-
}
|
|
2549
|
-
});
|
|
2550
|
-
});
|
|
2551
|
-
}
|
|
2552
|
-
all(sql, ...params) {
|
|
2553
|
-
return new Promise((resolve2, reject) => {
|
|
2554
|
-
this.db.all(sql, ...params, (err, rows) => {
|
|
2555
|
-
if (err) {
|
|
2556
|
-
reject(err);
|
|
2557
|
-
} else {
|
|
2558
|
-
resolve2(rows);
|
|
2559
|
-
}
|
|
2560
|
-
});
|
|
2533
|
+
await this.updateStorage((storage) => {
|
|
2534
|
+
delete storage.sessions[sessionId];
|
|
2561
2535
|
});
|
|
2562
2536
|
}
|
|
2563
2537
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harperfast/agent",
|
|
3
3
|
"description": "AI to help you with Harper app management",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.5",
|
|
5
5
|
"main": "dist/agent.js",
|
|
6
6
|
"repository": "github:HarperFast/harper-agent",
|
|
7
7
|
"bugs": {
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"cross-spawn": "^7.0.6",
|
|
53
53
|
"dotenv": "^17.2.3",
|
|
54
54
|
"ollama-ai-provider-v2": "^3.0.3",
|
|
55
|
-
"sqlite3": "^5.1.7",
|
|
56
55
|
"zod": "^4.3.6"
|
|
57
56
|
},
|
|
58
57
|
"devDependencies": {
|