@stevederico/dotbot 0.27.0 → 0.29.0
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 +22 -0
- package/README.md +64 -12
- package/bin/dotbot.js +389 -99
- package/core/agent.js +1 -1
- package/core/cdp.js +5 -58
- package/dotbot.db +0 -0
- package/index.js +0 -7
- package/package.json +1 -1
- package/storage/SQLiteCronAdapter.js +8 -92
- package/storage/index.js +0 -3
- package/tools/appgen.js +1 -10
- package/tools/browser.js +0 -15
- package/tools/code.js +0 -28
- package/tools/images.js +0 -10
- package/tools/index.js +2 -4
- package/tools/jobs.js +0 -2
- package/tools/tasks.js +0 -2
- package/tools/web.js +0 -36
- package/examples/sqlite-session-example.js +0 -69
- package/observer/index.js +0 -164
package/core/cdp.js
CHANGED
|
@@ -184,35 +184,22 @@ export class CDPClient {
|
|
|
184
184
|
return result.result?.value;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
/**
|
|
188
|
-
* Get the page title.
|
|
189
|
-
* @returns {Promise<string>}
|
|
190
|
-
*/
|
|
187
|
+
/** Get the page title. */
|
|
191
188
|
async getTitle() {
|
|
192
189
|
return this.evaluate('document.title');
|
|
193
190
|
}
|
|
194
191
|
|
|
195
|
-
/**
|
|
196
|
-
* Get the current URL.
|
|
197
|
-
* @returns {Promise<string>}
|
|
198
|
-
*/
|
|
192
|
+
/** Get the current URL. */
|
|
199
193
|
async getUrl() {
|
|
200
194
|
return this.evaluate('window.location.href');
|
|
201
195
|
}
|
|
202
196
|
|
|
203
|
-
/**
|
|
204
|
-
* Get text content of the page body.
|
|
205
|
-
* @returns {Promise<string>}
|
|
206
|
-
*/
|
|
197
|
+
/** Get text content of the page body. */
|
|
207
198
|
async getBodyText() {
|
|
208
199
|
return this.evaluate('document.body?.innerText || ""');
|
|
209
200
|
}
|
|
210
201
|
|
|
211
|
-
/**
|
|
212
|
-
* Get text content of an element by CSS selector.
|
|
213
|
-
* @param {string} selector - CSS selector
|
|
214
|
-
* @returns {Promise<string>}
|
|
215
|
-
*/
|
|
202
|
+
/** Get text content of an element by CSS selector. */
|
|
216
203
|
async getText(selector) {
|
|
217
204
|
const escaped = selector.replace(/"/g, '\\"');
|
|
218
205
|
return this.evaluate(`document.querySelector("${escaped}")?.innerText || ""`);
|
|
@@ -308,26 +295,6 @@ export class CDPClient {
|
|
|
308
295
|
});
|
|
309
296
|
}
|
|
310
297
|
|
|
311
|
-
/**
|
|
312
|
-
* Click an element by CSS selector.
|
|
313
|
-
* @param {string} selector - CSS selector
|
|
314
|
-
*/
|
|
315
|
-
async clickSelector(selector) {
|
|
316
|
-
const el = await this.querySelector(selector);
|
|
317
|
-
if (!el) throw new Error(`Element not found: ${selector}`);
|
|
318
|
-
await this.click(el.x, el.y);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Click an element by visible text.
|
|
323
|
-
* @param {string} text - Text content to find
|
|
324
|
-
*/
|
|
325
|
-
async clickText(text) {
|
|
326
|
-
const el = await this.getByText(text);
|
|
327
|
-
if (!el) throw new Error(`Element with text "${text}" not found`);
|
|
328
|
-
await this.click(el.x, el.y);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
298
|
/**
|
|
332
299
|
* Type text character by character.
|
|
333
300
|
* @param {string} text - Text to type
|
|
@@ -453,9 +420,7 @@ export class CDPClient {
|
|
|
453
420
|
});
|
|
454
421
|
}
|
|
455
422
|
|
|
456
|
-
/**
|
|
457
|
-
* Close the connection.
|
|
458
|
-
*/
|
|
423
|
+
/** Close the CDP connection. */
|
|
459
424
|
close() {
|
|
460
425
|
if (this.ws) {
|
|
461
426
|
this.ws.close();
|
|
@@ -490,24 +455,6 @@ export class CDPClient {
|
|
|
490
455
|
throw lastError;
|
|
491
456
|
}
|
|
492
457
|
|
|
493
|
-
/**
|
|
494
|
-
* Wait for an element to appear in the DOM.
|
|
495
|
-
* @param {string} selector - CSS selector
|
|
496
|
-
* @param {Object} options - Wait options
|
|
497
|
-
* @param {number} options.timeout - Timeout in ms (default: 5000)
|
|
498
|
-
* @param {number} options.interval - Poll interval in ms (default: 100)
|
|
499
|
-
* @returns {Promise<{x: number, y: number, nodeId: number}>} Element info
|
|
500
|
-
*/
|
|
501
|
-
async waitForSelector(selector, { timeout = 5000, interval = 100 } = {}) {
|
|
502
|
-
const start = Date.now();
|
|
503
|
-
while (Date.now() - start < timeout) {
|
|
504
|
-
const el = await this.querySelector(selector);
|
|
505
|
-
if (el) return el;
|
|
506
|
-
await new Promise(r => setTimeout(r, interval));
|
|
507
|
-
}
|
|
508
|
-
throw new Error(`Timeout waiting for selector: ${selector}`);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
458
|
/**
|
|
512
459
|
* Wait for network to be idle (no requests for a period).
|
|
513
460
|
* @param {Object} options - Wait options
|
package/dotbot.db
CHANGED
|
Binary file
|
package/index.js
CHANGED
|
@@ -18,10 +18,8 @@ import {
|
|
|
18
18
|
notifyTools,
|
|
19
19
|
createBrowserTools,
|
|
20
20
|
taskTools,
|
|
21
|
-
goalTools,
|
|
22
21
|
triggerTools,
|
|
23
22
|
jobTools,
|
|
24
|
-
cronTools,
|
|
25
23
|
eventTools,
|
|
26
24
|
appgenTools,
|
|
27
25
|
} from './tools/index.js';
|
|
@@ -40,9 +38,6 @@ export {
|
|
|
40
38
|
runWithConcurrency,
|
|
41
39
|
TaskStore,
|
|
42
40
|
SQLiteTaskStore,
|
|
43
|
-
// Backwards compatibility aliases
|
|
44
|
-
GoalStore,
|
|
45
|
-
SQLiteGoalStore,
|
|
46
41
|
TriggerStore,
|
|
47
42
|
SQLiteTriggerStore,
|
|
48
43
|
SQLiteMemoryStore,
|
|
@@ -65,10 +60,8 @@ export {
|
|
|
65
60
|
browserTools,
|
|
66
61
|
createBrowserTools,
|
|
67
62
|
taskTools,
|
|
68
|
-
goalTools, // backwards compatibility alias
|
|
69
63
|
triggerTools,
|
|
70
64
|
jobTools,
|
|
71
|
-
cronTools, // backwards compatibility alias
|
|
72
65
|
eventTools,
|
|
73
66
|
appgenTools,
|
|
74
67
|
} from './tools/index.js';
|
package/package.json
CHANGED
|
@@ -220,16 +220,7 @@ export class SQLiteCronStore extends CronStore {
|
|
|
220
220
|
"SELECT * FROM cron_tasks WHERE session_id = ? AND name != 'heartbeat' ORDER BY next_run_at ASC"
|
|
221
221
|
).all(sessionId || 'default');
|
|
222
222
|
|
|
223
|
-
return rows.map(r => (
|
|
224
|
-
id: r.id,
|
|
225
|
-
name: r.name,
|
|
226
|
-
prompt: r.prompt,
|
|
227
|
-
nextRunAt: new Date(r.next_run_at),
|
|
228
|
-
recurring: !!r.recurring,
|
|
229
|
-
intervalMs: r.interval_ms,
|
|
230
|
-
enabled: !!r.enabled,
|
|
231
|
-
lastRunAt: r.last_run_at ? new Date(r.last_run_at) : null,
|
|
232
|
-
}));
|
|
223
|
+
return rows.map(r => this._rowToTask(r));
|
|
233
224
|
}
|
|
234
225
|
|
|
235
226
|
/**
|
|
@@ -257,18 +248,7 @@ export class SQLiteCronStore extends CronStore {
|
|
|
257
248
|
|
|
258
249
|
const rows = this.db.prepare(query).all(...params);
|
|
259
250
|
|
|
260
|
-
return rows.map(r => (
|
|
261
|
-
id: r.id,
|
|
262
|
-
name: r.name,
|
|
263
|
-
prompt: r.prompt,
|
|
264
|
-
sessionId: r.session_id,
|
|
265
|
-
nextRunAt: new Date(r.next_run_at),
|
|
266
|
-
recurring: !!r.recurring,
|
|
267
|
-
intervalMs: r.interval_ms,
|
|
268
|
-
enabled: !!r.enabled,
|
|
269
|
-
lastRunAt: r.last_run_at ? new Date(r.last_run_at) : null,
|
|
270
|
-
createdAt: new Date(r.created_at),
|
|
271
|
-
}));
|
|
251
|
+
return rows.map(r => this._rowToTask(r));
|
|
272
252
|
}
|
|
273
253
|
|
|
274
254
|
/**
|
|
@@ -374,53 +354,6 @@ export class SQLiteCronStore extends CronStore {
|
|
|
374
354
|
return null;
|
|
375
355
|
}
|
|
376
356
|
|
|
377
|
-
/**
|
|
378
|
-
* Ensure a Morning Brief job exists for the user (disabled by default).
|
|
379
|
-
* Creates a daily recurring job at 8:00 AM if not present.
|
|
380
|
-
*
|
|
381
|
-
* @param {string} userId - User ID
|
|
382
|
-
* @returns {Promise<Object|null>} Created task or null if already exists
|
|
383
|
-
*/
|
|
384
|
-
async ensureMorningBrief(userId) {
|
|
385
|
-
if (!this.db || !userId) return null;
|
|
386
|
-
|
|
387
|
-
// Check if Morning Brief already exists for this user
|
|
388
|
-
const existing = this.db.prepare(
|
|
389
|
-
`SELECT id FROM cron_tasks WHERE user_id = ? AND name = 'Morning Brief' LIMIT 1`
|
|
390
|
-
).get(userId);
|
|
391
|
-
if (existing) return null;
|
|
392
|
-
|
|
393
|
-
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
394
|
-
const MORNING_BRIEF_PROMPT = `Good morning! Give me a brief summary to start my day:
|
|
395
|
-
1. What's on my calendar today?
|
|
396
|
-
2. Any important reminders or tasks due?
|
|
397
|
-
3. A quick weather update for my location.
|
|
398
|
-
Keep it concise and actionable.`;
|
|
399
|
-
|
|
400
|
-
// Calculate next 8:00 AM
|
|
401
|
-
const now = new Date();
|
|
402
|
-
const today8AM = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 8, 0, 0, 0);
|
|
403
|
-
const nextRun = now.getTime() < today8AM.getTime()
|
|
404
|
-
? today8AM.getTime()
|
|
405
|
-
: today8AM.getTime() + DAY_MS;
|
|
406
|
-
|
|
407
|
-
const id = crypto.randomUUID();
|
|
408
|
-
const nowMs = Date.now();
|
|
409
|
-
|
|
410
|
-
const result = this.db.prepare(`
|
|
411
|
-
INSERT OR IGNORE INTO cron_tasks (id, name, prompt, session_id, user_id, next_run_at, interval_ms, recurring, enabled, created_at, last_run_at)
|
|
412
|
-
VALUES (?, 'Morning Brief', ?, 'default', ?, ?, ?, 1, 0, ?, NULL)
|
|
413
|
-
`).run(id, MORNING_BRIEF_PROMPT, userId, nextRun, DAY_MS, nowMs);
|
|
414
|
-
|
|
415
|
-
if (result.changes > 0) {
|
|
416
|
-
const runTime = new Date(nextRun);
|
|
417
|
-
console.log(`[cron] created Morning Brief for user ${userId}, next run at ${runTime.toLocaleTimeString()} (disabled by default)`);
|
|
418
|
-
return { id };
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
return null;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
357
|
/**
|
|
425
358
|
* Get heartbeat status for a user
|
|
426
359
|
*
|
|
@@ -455,35 +388,18 @@ Keep it concise and actionable.`;
|
|
|
455
388
|
async resetHeartbeat(userId) {
|
|
456
389
|
if (!this.db || !userId) return null;
|
|
457
390
|
|
|
458
|
-
|
|
391
|
+
this.db.prepare(
|
|
459
392
|
"DELETE FROM cron_tasks WHERE user_id = ? AND name = 'heartbeat'"
|
|
460
393
|
).run(userId);
|
|
461
394
|
console.log(`[cron] deleted existing heartbeat(s) for user ${userId}`);
|
|
462
395
|
|
|
463
|
-
const
|
|
464
|
-
const now = Date.now();
|
|
465
|
-
const id = crypto.randomUUID();
|
|
396
|
+
const result = await this.ensureHeartbeat(userId);
|
|
466
397
|
|
|
467
|
-
|
|
468
|
-
INSERT INTO cron_tasks (id, name, prompt, session_id, user_id, next_run_at, interval_ms, recurring, enabled, created_at, last_run_at)
|
|
469
|
-
VALUES (?, 'heartbeat', ?, 'default', ?, ?, ?, 1, 1, ?, NULL)
|
|
470
|
-
`).run(id, HEARTBEAT_PROMPT, userId, now + jitter, HEARTBEAT_INTERVAL_MS, now);
|
|
471
|
-
|
|
472
|
-
console.log(`[cron] created new heartbeat for user ${userId}, first run in ${Math.round(jitter / 60000)}m`);
|
|
398
|
+
if (!result) return null;
|
|
473
399
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
prompt: HEARTBEAT_PROMPT,
|
|
478
|
-
userId,
|
|
479
|
-
sessionId: 'default',
|
|
480
|
-
nextRunAt: new Date(now + jitter),
|
|
481
|
-
intervalMs: HEARTBEAT_INTERVAL_MS,
|
|
482
|
-
recurring: true,
|
|
483
|
-
enabled: true,
|
|
484
|
-
createdAt: new Date(now),
|
|
485
|
-
lastRunAt: null,
|
|
486
|
-
};
|
|
400
|
+
// Return the full task object for the newly created heartbeat
|
|
401
|
+
const row = this.db.prepare('SELECT * FROM cron_tasks WHERE id = ?').get(result.id);
|
|
402
|
+
return row ? this._rowToTask(row) : null;
|
|
487
403
|
}
|
|
488
404
|
|
|
489
405
|
/**
|
package/storage/index.js
CHANGED
|
@@ -5,9 +5,6 @@ export { CronStore } from './CronStore.js';
|
|
|
5
5
|
export { SQLiteCronStore, parseInterval, HEARTBEAT_INTERVAL_MS, HEARTBEAT_PROMPT } from './SQLiteCronAdapter.js';
|
|
6
6
|
export { TaskStore } from './TaskStore.js';
|
|
7
7
|
export { SQLiteTaskStore } from './SQLiteTaskAdapter.js';
|
|
8
|
-
// Backwards compatibility aliases
|
|
9
|
-
export { TaskStore as GoalStore } from './TaskStore.js';
|
|
10
|
-
export { SQLiteTaskStore as SQLiteGoalStore } from './SQLiteTaskAdapter.js';
|
|
11
8
|
export { TriggerStore } from './TriggerStore.js';
|
|
12
9
|
export { SQLiteTriggerStore } from './SQLiteTriggerAdapter.js';
|
|
13
10
|
export { SQLiteMemoryStore } from './SQLiteMemoryAdapter.js';
|
package/tools/appgen.js
CHANGED
|
@@ -57,14 +57,7 @@ export function cleanGeneratedCode(code) {
|
|
|
57
57
|
if (!code) return { code: '', windowSize: { width: 800, height: 650 } };
|
|
58
58
|
|
|
59
59
|
let cleanCode = code
|
|
60
|
-
|
|
61
|
-
.replace(/```javascript/gi, '')
|
|
62
|
-
.replace(/```jsx/gi, '')
|
|
63
|
-
.replace(/```js/gi, '')
|
|
64
|
-
.replace(/```react/gi, '')
|
|
65
|
-
.replace(/```typescript/gi, '')
|
|
66
|
-
.replace(/```tsx/gi, '')
|
|
67
|
-
.replace(/```/g, '')
|
|
60
|
+
.replace(/```(?:javascript|jsx|js|react|typescript|tsx)?/gi, '')
|
|
68
61
|
// Remove HTML document wrappers
|
|
69
62
|
.replace(/<html[^>]*>[\s\S]*<\/html>/gi, '')
|
|
70
63
|
.replace(/<head[^>]*>[\s\S]*<\/head>/gi, '')
|
|
@@ -307,5 +300,3 @@ export const appgenTools = [
|
|
|
307
300
|
}
|
|
308
301
|
}
|
|
309
302
|
];
|
|
310
|
-
|
|
311
|
-
export default appgenTools;
|
package/tools/browser.js
CHANGED
|
@@ -616,21 +616,6 @@ export function createBrowserTools(screenshotUrlPattern = (filename) => `/api/ag
|
|
|
616
616
|
pageSummary += `\n\nPage structure:\n${trimmed}`;
|
|
617
617
|
}
|
|
618
618
|
|
|
619
|
-
// Log to activity so Photos app can list the screenshot
|
|
620
|
-
if (context?.databaseManager) {
|
|
621
|
-
try {
|
|
622
|
-
await context.databaseManager.logAgentActivity(
|
|
623
|
-
context.dbConfig.dbType,
|
|
624
|
-
context.dbConfig.db,
|
|
625
|
-
context.dbConfig.connectionString,
|
|
626
|
-
context.userID,
|
|
627
|
-
{ type: 'image_generation', prompt: `Screenshot: ${title}`, url: screenshotUrl, source: 'browser' }
|
|
628
|
-
);
|
|
629
|
-
} catch {
|
|
630
|
-
/* best effort */
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
619
|
// Return image JSON so frontend renders the screenshot inline
|
|
635
620
|
return JSON.stringify({ type: 'image', url: screenshotUrl, prompt: pageSummary });
|
|
636
621
|
} catch (err) {
|
package/tools/code.js
CHANGED
|
@@ -52,20 +52,6 @@ export const codeTools = [
|
|
|
52
52
|
|
|
53
53
|
await unlink(tmpFile).catch(() => {});
|
|
54
54
|
|
|
55
|
-
if (context?.databaseManager) {
|
|
56
|
-
try {
|
|
57
|
-
await context.databaseManager.logAgentActivity(
|
|
58
|
-
context.dbConfig.dbType, context.dbConfig.db, context.dbConfig.connectionString,
|
|
59
|
-
context.userID, {
|
|
60
|
-
type: 'code_execution',
|
|
61
|
-
code: input.code.slice(0, 500),
|
|
62
|
-
output: (stdout || stderr || '').slice(0, 500),
|
|
63
|
-
success: !stderr
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
} catch (e) { /* best effort */ }
|
|
67
|
-
}
|
|
68
|
-
|
|
69
55
|
if (stderr) {
|
|
70
56
|
return `Stderr:\n${stderr}\n\nStdout:\n${stdout}`;
|
|
71
57
|
}
|
|
@@ -74,20 +60,6 @@ export const codeTools = [
|
|
|
74
60
|
} catch (err) {
|
|
75
61
|
await unlink(tmpFile).catch(() => {});
|
|
76
62
|
|
|
77
|
-
if (context?.databaseManager) {
|
|
78
|
-
try {
|
|
79
|
-
await context.databaseManager.logAgentActivity(
|
|
80
|
-
context.dbConfig.dbType, context.dbConfig.db, context.dbConfig.connectionString,
|
|
81
|
-
context.userID, {
|
|
82
|
-
type: 'code_execution',
|
|
83
|
-
code: input.code.slice(0, 500),
|
|
84
|
-
output: (err.stderr || err.message || '').slice(0, 500),
|
|
85
|
-
success: false
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
} catch (e) { /* best effort */ }
|
|
89
|
-
}
|
|
90
|
-
|
|
91
63
|
if (err.killed) {
|
|
92
64
|
return "Error: code execution timed out (10s limit)";
|
|
93
65
|
}
|
package/tools/images.js
CHANGED
|
@@ -176,16 +176,6 @@ export const imageTools = [
|
|
|
176
176
|
return result.error;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
// Log to activity for persistence
|
|
180
|
-
if (context?.databaseManager) {
|
|
181
|
-
try {
|
|
182
|
-
await context.databaseManager.logAgentActivity(
|
|
183
|
-
context.dbConfig.dbType, context.dbConfig.db, context.dbConfig.connectionString,
|
|
184
|
-
context.userID, { type: 'image_generation', prompt: input.prompt, url: result.url, source: 'agent' }
|
|
185
|
-
);
|
|
186
|
-
} catch (e) { /* best effort */ }
|
|
187
|
-
}
|
|
188
|
-
|
|
189
179
|
return JSON.stringify({ type: 'image', url: result.url, prompt: input.prompt });
|
|
190
180
|
},
|
|
191
181
|
},
|
package/tools/index.js
CHANGED
|
@@ -13,9 +13,9 @@ import { imageTools } from './images.js';
|
|
|
13
13
|
import { weatherTools } from './weather.js';
|
|
14
14
|
import { notifyTools } from './notify.js';
|
|
15
15
|
import { browserTools, createBrowserTools } from './browser.js';
|
|
16
|
-
import { taskTools
|
|
16
|
+
import { taskTools } from './tasks.js';
|
|
17
17
|
import { triggerTools } from './triggers.js';
|
|
18
|
-
import { jobTools
|
|
18
|
+
import { jobTools } from './jobs.js';
|
|
19
19
|
import { eventTools } from './events.js';
|
|
20
20
|
import { appgenTools } from './appgen.js';
|
|
21
21
|
|
|
@@ -88,10 +88,8 @@ export {
|
|
|
88
88
|
browserTools,
|
|
89
89
|
createBrowserTools,
|
|
90
90
|
taskTools,
|
|
91
|
-
goalTools, // backwards compatibility alias
|
|
92
91
|
triggerTools,
|
|
93
92
|
jobTools,
|
|
94
|
-
cronTools, // backwards compatibility alias
|
|
95
93
|
eventTools,
|
|
96
94
|
appgenTools,
|
|
97
95
|
};
|
package/tools/jobs.js
CHANGED
package/tools/tasks.js
CHANGED
package/tools/web.js
CHANGED
|
@@ -70,15 +70,6 @@ export const webTools = [
|
|
|
70
70
|
result += "\n\nSources:\n" + [...citations].slice(0, 5).map((url, i) => `${i + 1}. ${url}`).join("\n");
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
if (context?.databaseManager) {
|
|
74
|
-
try {
|
|
75
|
-
await context.databaseManager.logAgentActivity(
|
|
76
|
-
context.dbConfig.dbType, context.dbConfig.db, context.dbConfig.connectionString,
|
|
77
|
-
context.userID, { type: 'web_search', query: input.query, provider: 'grok', resultPreview: result.slice(0, 300) }
|
|
78
|
-
);
|
|
79
|
-
} catch (e) { /* best effort */ }
|
|
80
|
-
}
|
|
81
|
-
|
|
82
73
|
return result || "No results found.";
|
|
83
74
|
} else {
|
|
84
75
|
const errText = await res.text();
|
|
@@ -120,15 +111,6 @@ export const webTools = [
|
|
|
120
111
|
|
|
121
112
|
const result = parts.join("\n\n");
|
|
122
113
|
|
|
123
|
-
if (context?.databaseManager) {
|
|
124
|
-
try {
|
|
125
|
-
await context.databaseManager.logAgentActivity(
|
|
126
|
-
context.dbConfig.dbType, context.dbConfig.db, context.dbConfig.connectionString,
|
|
127
|
-
context.userID, { type: 'web_search', query: input.query, provider: 'duckduckgo', resultPreview: parts.slice(0, 2).join('\n').slice(0, 300) }
|
|
128
|
-
);
|
|
129
|
-
} catch (e) { /* best effort */ }
|
|
130
|
-
}
|
|
131
|
-
|
|
132
114
|
return result;
|
|
133
115
|
},
|
|
134
116
|
},
|
|
@@ -176,15 +158,6 @@ export const webTools = [
|
|
|
176
158
|
text = text.slice(0, maxChars) + `\n\n... [truncated, ${text.length} chars total]`;
|
|
177
159
|
}
|
|
178
160
|
|
|
179
|
-
if (context?.databaseManager) {
|
|
180
|
-
try {
|
|
181
|
-
await context.databaseManager.logAgentActivity(
|
|
182
|
-
context.dbConfig.dbType, context.dbConfig.db, context.dbConfig.connectionString,
|
|
183
|
-
context.userID, { type: 'grokipedia_search', query: input.query, url }
|
|
184
|
-
);
|
|
185
|
-
} catch (e) { /* best effort */ }
|
|
186
|
-
}
|
|
187
|
-
|
|
188
161
|
return text;
|
|
189
162
|
} catch (err) {
|
|
190
163
|
return `Error looking up Grokipedia: ${err.message}`;
|
|
@@ -260,15 +233,6 @@ export const webTools = [
|
|
|
260
233
|
.trim();
|
|
261
234
|
}
|
|
262
235
|
|
|
263
|
-
if (context?.databaseManager) {
|
|
264
|
-
try {
|
|
265
|
-
await context.databaseManager.logAgentActivity(
|
|
266
|
-
context.dbConfig.dbType, context.dbConfig.db, context.dbConfig.connectionString,
|
|
267
|
-
context.userID, { type: 'web_fetch', url: input.url, status: res.status }
|
|
268
|
-
);
|
|
269
|
-
} catch (e) { /* best effort */ }
|
|
270
|
-
}
|
|
271
|
-
|
|
272
236
|
const maxChars = 8000;
|
|
273
237
|
if (text.length > maxChars) {
|
|
274
238
|
return text.slice(0, maxChars) + `\n\n... [truncated, ${text.length} chars total]`;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQLiteSessionStore Usage Example
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates how to use SQLite as a session storage backend
|
|
5
|
-
* for the @dottie/agent library. Requires Node.js 22.5+.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { createAgent, SQLiteSessionStore, coreTools } from '@dottie/agent';
|
|
9
|
-
|
|
10
|
-
// Initialize SQLite session store
|
|
11
|
-
const sessionStore = new SQLiteSessionStore();
|
|
12
|
-
await sessionStore.init('./sessions.db', {
|
|
13
|
-
// Optional: Fetch user preferences from your database
|
|
14
|
-
prefsFetcher: async (userId) => {
|
|
15
|
-
// Example: fetch from a user database
|
|
16
|
-
return {
|
|
17
|
-
agentName: 'Dottie',
|
|
18
|
-
agentPersonality: 'helpful and concise',
|
|
19
|
-
};
|
|
20
|
-
},
|
|
21
|
-
// Optional: Ensure user heartbeat for cron tasks
|
|
22
|
-
heartbeatEnsurer: async (userId) => {
|
|
23
|
-
// Example: update last_seen timestamp in user database
|
|
24
|
-
console.log(`User ${userId} active`);
|
|
25
|
-
return null;
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// Create agent with SQLite session storage
|
|
30
|
-
const agent = createAgent({
|
|
31
|
-
sessionStore,
|
|
32
|
-
providers: {
|
|
33
|
-
anthropic: { apiKey: process.env.ANTHROPIC_API_KEY },
|
|
34
|
-
},
|
|
35
|
-
tools: coreTools,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Example 1: Create a new session
|
|
39
|
-
const session = await agent.createSession('user-123', 'claude-sonnet-4-5', 'anthropic');
|
|
40
|
-
console.log('Created session:', session.id);
|
|
41
|
-
|
|
42
|
-
// Example 2: Chat with the agent
|
|
43
|
-
for await (const event of agent.chat({
|
|
44
|
-
sessionId: session.id,
|
|
45
|
-
message: 'What can you help me with?',
|
|
46
|
-
provider: 'anthropic',
|
|
47
|
-
model: 'claude-sonnet-4-5',
|
|
48
|
-
})) {
|
|
49
|
-
if (event.type === 'content_block_delta' && event.delta?.type === 'text_delta') {
|
|
50
|
-
process.stdout.write(event.delta.text);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
console.log('\n');
|
|
54
|
-
|
|
55
|
-
// Example 3: List all sessions for a user
|
|
56
|
-
const sessions = await sessionStore.listSessions('user-123');
|
|
57
|
-
console.log('User sessions:', sessions);
|
|
58
|
-
|
|
59
|
-
// Example 4: Get or create default session
|
|
60
|
-
const defaultSession = await sessionStore.getOrCreateDefaultSession('user-123');
|
|
61
|
-
console.log('Default session:', defaultSession.id);
|
|
62
|
-
|
|
63
|
-
// Example 5: Clear session history
|
|
64
|
-
await sessionStore.clearSession(session.id);
|
|
65
|
-
console.log('Session cleared');
|
|
66
|
-
|
|
67
|
-
// Example 6: Delete a session
|
|
68
|
-
await sessionStore.deleteSession(session.id, 'user-123');
|
|
69
|
-
console.log('Session deleted');
|