daybrain 0.3.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.
Files changed (51) hide show
  1. package/bin/daybrain.js +18 -0
  2. package/dist/aw.d.ts +30 -0
  3. package/dist/aw.d.ts.map +1 -0
  4. package/dist/aw.js +145 -0
  5. package/dist/aw.js.map +1 -0
  6. package/dist/baseline.d.ts +31 -0
  7. package/dist/baseline.d.ts.map +1 -0
  8. package/dist/baseline.js +130 -0
  9. package/dist/baseline.js.map +1 -0
  10. package/dist/config.d.ts +36 -0
  11. package/dist/config.d.ts.map +1 -0
  12. package/dist/config.js +139 -0
  13. package/dist/config.js.map +1 -0
  14. package/dist/db.d.ts +72 -0
  15. package/dist/db.d.ts.map +1 -0
  16. package/dist/db.js +261 -0
  17. package/dist/db.js.map +1 -0
  18. package/dist/http.d.ts +5 -0
  19. package/dist/http.d.ts.map +1 -0
  20. package/dist/http.js +411 -0
  21. package/dist/http.js.map +1 -0
  22. package/dist/index.d.ts +16 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +908 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/insights.d.ts +68 -0
  27. package/dist/insights.d.ts.map +1 -0
  28. package/dist/insights.js +523 -0
  29. package/dist/insights.js.map +1 -0
  30. package/dist/onboard.d.ts +2 -0
  31. package/dist/onboard.d.ts.map +1 -0
  32. package/dist/onboard.js +121 -0
  33. package/dist/onboard.js.map +1 -0
  34. package/dist/scheduler.d.ts +8 -0
  35. package/dist/scheduler.d.ts.map +1 -0
  36. package/dist/scheduler.js +214 -0
  37. package/dist/scheduler.js.map +1 -0
  38. package/dist/screenpipe.d.ts +25 -0
  39. package/dist/screenpipe.d.ts.map +1 -0
  40. package/dist/screenpipe.js +71 -0
  41. package/dist/screenpipe.js.map +1 -0
  42. package/dist/transport.d.ts +12 -0
  43. package/dist/transport.d.ts.map +1 -0
  44. package/dist/transport.js +152 -0
  45. package/dist/transport.js.map +1 -0
  46. package/dist/watcher.d.ts +15 -0
  47. package/dist/watcher.d.ts.map +1 -0
  48. package/dist/watcher.js +173 -0
  49. package/dist/watcher.js.map +1 -0
  50. package/package.json +58 -0
  51. package/watcher.py +139 -0
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.runOnboarding = runOnboarding;
37
+ const readline = __importStar(require("readline"));
38
+ const config_1 = require("./config");
39
+ function ask(rl, question) {
40
+ return new Promise(resolve => rl.question(question, resolve));
41
+ }
42
+ async function runOnboarding() {
43
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
44
+ const config = (0, config_1.loadConfig)();
45
+ console.log('');
46
+ console.log('🧠 DayBrain — First-Time Setup');
47
+ console.log('════════════════════════════════');
48
+ console.log('');
49
+ console.log('DayBrain gives your AI assistants context about your workday.');
50
+ console.log('Everything runs locally. Nothing leaves your machine.');
51
+ console.log('');
52
+ // Step 1: Data source
53
+ console.log('📊 DATA SOURCE');
54
+ console.log(' DayBrain can track your activity two ways:');
55
+ console.log(' 1. ActivityWatch (https://activitywatch.net) — richer data, all apps');
56
+ console.log(' 2. Built-in macOS watcher — zero permissions, browser + desktop apps');
57
+ console.log('');
58
+ const sourceChoice = await ask(rl, ' Use ActivityWatch if available? [Y/n] ');
59
+ if (sourceChoice.toLowerCase() === 'n') {
60
+ config.activitywatch.enabled = false;
61
+ console.log(' ✓ Using built-in watcher (install: pip3 install pyobjc-framework-Quartz)');
62
+ }
63
+ else {
64
+ console.log(' ✓ ActivityWatch enabled (make sure it\'s running: https://activitywatch.net)');
65
+ }
66
+ // Step 2: Slack
67
+ console.log('');
68
+ console.log('📤 NOTIFICATIONS');
69
+ console.log(' DayBrain can push insights to Slack when it detects commitments.');
70
+ const slackUrl = await ask(rl, ' Slack webhook URL? [skip] ');
71
+ if (slackUrl && slackUrl.startsWith('https://hooks.slack.com/')) {
72
+ config.transports.slack.webhookUrl = slackUrl;
73
+ console.log(' ✓ Slack configured');
74
+ }
75
+ else {
76
+ console.log(' • Skipped');
77
+ }
78
+ // Step 3: Telegram
79
+ const telegramToken = await ask(rl, ' Telegram bot token? [skip] ');
80
+ if (telegramToken && telegramToken.includes(':')) {
81
+ config.transports.telegram.botToken = telegramToken;
82
+ const chatId = await ask(rl, ' Telegram chat ID? ');
83
+ config.transports.telegram.chatId = chatId;
84
+ console.log(' ✓ Telegram configured');
85
+ }
86
+ else {
87
+ console.log(' • Skipped');
88
+ }
89
+ // Step 4: AI setup
90
+ console.log('');
91
+ console.log('🤖 AI ASSISTANT SETUP');
92
+ console.log(' Copy this config into your Claude/Cursor MCP settings:');
93
+ console.log('');
94
+ console.log(' {');
95
+ console.log(' "mcpServers": {');
96
+ console.log(' "daybrain": {');
97
+ console.log(' "command": "npx",');
98
+ console.log(' "args": ["-y", "daybrain"]');
99
+ console.log(' }');
100
+ console.log(' }');
101
+ console.log(' }');
102
+ console.log('');
103
+ // Step 5: Chrome extension
104
+ console.log('🧩 CHROME EXTENSION');
105
+ console.log(' 1. Open chrome://extensions');
106
+ console.log(' 2. Enable "Developer mode" (top right)');
107
+ console.log(' 3. Click "Load unpacked"');
108
+ console.log(' 4. Select the extension/ folder in the DayBrain install directory');
109
+ console.log('');
110
+ (0, config_1.saveConfig)(config);
111
+ console.log(`✓ Configuration saved to ${(0, config_1.getConfigPath)()}`);
112
+ console.log('');
113
+ console.log('Run "daybrain" to start the server, then open Claude.ai or ChatGPT.');
114
+ console.log('The brain button 🧠 will appear in the top-right corner.');
115
+ console.log('');
116
+ rl.close();
117
+ }
118
+ if (require.main === module) {
119
+ runOnboarding().catch(console.error);
120
+ }
121
+ //# sourceMappingURL=onboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onboard.js","sourceRoot":"","sources":["../src/onboard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,sCAgFC;AAvFD,mDAAqC;AACrC,qCAAiE;AAEjE,SAAS,GAAG,CAAC,EAAsB,EAAE,QAAgB;IACnD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAChE,CAAC;AAEM,KAAK,UAAU,aAAa;IACjC,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACtF,MAAM,MAAM,GAAG,IAAA,mBAAU,GAAE,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC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CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEhB,2BAA2B;IAC3B,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACpC,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,CAAC,qEAAqE,CAAC,CAAC;IACnF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEhB,IAAA,mBAAU,EAAC,MAAM,CAAC,CAAC;IACnB,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAA,sBAAa,GAAE,EAAE,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,qEAAqE,CAAC,CAAC;IACnF,OAAO,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAC;IACxE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEhB,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,aAAa,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare function startScheduler(intervalMinutes?: number): void;
2
+ export declare function stopScheduler(): void;
3
+ export declare function runInsightLoop(): Promise<{
4
+ eventsStored: number;
5
+ insightsGenerated: number;
6
+ errors: string[];
7
+ }>;
8
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAWA,wBAAgB,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAgB7D;AAsBD,wBAAgB,aAAa,IAAI,IAAI,CAOpC;AAED,wBAAsB,cAAc,IAAI,OAAO,CAAC;IAC9C,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC,CA6ID"}
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startScheduler = startScheduler;
4
+ exports.stopScheduler = stopScheduler;
5
+ exports.runInsightLoop = runInsightLoop;
6
+ const aw_1 = require("./aw");
7
+ const screenpipe_1 = require("./screenpipe");
8
+ const insights_1 = require("./insights");
9
+ const db_1 = require("./db");
10
+ const transport_1 = require("./transport");
11
+ const config_1 = require("./config");
12
+ let intervalHandle = null;
13
+ let isRunning = false;
14
+ let isLoopRunning = false;
15
+ function startScheduler(intervalMinutes) {
16
+ const config = (0, config_1.loadConfig)();
17
+ const interval = intervalMinutes ?? config.activitywatch.pollIntervalMinutes ?? config.insights.scheduleIntervalMinutes;
18
+ if (isRunning)
19
+ return;
20
+ isRunning = true;
21
+ const intervalMs = interval * 60 * 1000;
22
+ runInsightLoop().catch(err => {
23
+ console.error('[daybrain] Initial insight loop failed:', err instanceof Error ? err.message : String(err));
24
+ });
25
+ scheduleNextRun(intervalMs);
26
+ console.error(`[daybrain] Scheduler started, running every ${interval} minutes`);
27
+ }
28
+ function scheduleNextRun(delayMs) {
29
+ if (!isRunning)
30
+ return;
31
+ intervalHandle = setTimeout(async () => {
32
+ if (isLoopRunning) {
33
+ console.error('[daybrain] Scheduler skipped — previous loop still running');
34
+ scheduleNextRun(delayMs);
35
+ return;
36
+ }
37
+ isLoopRunning = true;
38
+ try {
39
+ await runInsightLoop();
40
+ }
41
+ catch (err) {
42
+ console.error('[daybrain] Scheduled insight loop failed:', err instanceof Error ? err.message : String(err));
43
+ }
44
+ finally {
45
+ isLoopRunning = false;
46
+ scheduleNextRun(delayMs);
47
+ }
48
+ }, delayMs);
49
+ }
50
+ function stopScheduler() {
51
+ isRunning = false;
52
+ if (intervalHandle) {
53
+ clearTimeout(intervalHandle);
54
+ intervalHandle = null;
55
+ }
56
+ console.error('[daybrain] Scheduler stopped');
57
+ }
58
+ async function runInsightLoop() {
59
+ const config = (0, config_1.loadConfig)();
60
+ const errors = [];
61
+ let eventsStored = 0;
62
+ let insightsGenerated = 0;
63
+ try {
64
+ if (config.activitywatch.enabled) {
65
+ const aw = (0, aw_1.createAWClient)();
66
+ const health = await aw.healthCheck();
67
+ if (health.ok) {
68
+ const now = new Date();
69
+ const startOfDay = new Date(now);
70
+ startOfDay.setHours(0, 0, 0, 0);
71
+ try {
72
+ const count = await aw.fetchAndStore(startOfDay.toISOString(), now.toISOString());
73
+ eventsStored += count;
74
+ }
75
+ catch (err) {
76
+ errors.push(`AW fetch error: ${err instanceof Error ? err.message : String(err)}`);
77
+ }
78
+ }
79
+ else {
80
+ errors.push(`ActivityWatch not available: ${health.error}`);
81
+ }
82
+ }
83
+ }
84
+ catch (err) {
85
+ errors.push(`AW error: ${err instanceof Error ? err.message : String(err)}`);
86
+ }
87
+ try {
88
+ if (config.screenpipe.enabled) {
89
+ const sp = (0, screenpipe_1.createScreenpipeClient)();
90
+ const health = await sp.healthCheck();
91
+ if (health.ok) {
92
+ try {
93
+ const ocrResults = await sp.getRecentOCR(100);
94
+ const audioResults = await sp.getRecentAudio(100);
95
+ const rawEvents = [
96
+ ...ocrResults.map(r => ({
97
+ source: 'screenpipe',
98
+ bucket_id: 'screenpipe-ocr',
99
+ timestamp: r.timestamp,
100
+ duration: 0,
101
+ app: r.content.app_name || '',
102
+ title: r.content.window_name || '',
103
+ url: r.content.browser_url || '',
104
+ raw_data: JSON.stringify(r.content),
105
+ })),
106
+ ...audioResults.map(r => ({
107
+ source: 'screenpipe',
108
+ bucket_id: 'screenpipe-audio',
109
+ timestamp: r.timestamp,
110
+ duration: 0,
111
+ app: r.content.app_name || '',
112
+ title: r.content.transcription || r.content.window_name || '',
113
+ url: r.content.browser_url || '',
114
+ raw_data: JSON.stringify(r.content),
115
+ })),
116
+ ];
117
+ if (rawEvents.length > 0) {
118
+ const count = (0, db_1.insertRawEvents)(rawEvents);
119
+ eventsStored += count;
120
+ }
121
+ }
122
+ catch (err) {
123
+ errors.push(`Screenpipe fetch error: ${err instanceof Error ? err.message : String(err)}`);
124
+ }
125
+ }
126
+ else {
127
+ errors.push(`Screenpipe not available: ${health.error}`);
128
+ }
129
+ }
130
+ }
131
+ catch (err) {
132
+ errors.push(`Screenpipe error: ${err instanceof Error ? err.message : String(err)}`);
133
+ }
134
+ try {
135
+ const now = new Date();
136
+ const startOfDay = new Date(now);
137
+ startOfDay.setHours(0, 0, 0, 0);
138
+ const rawEvents = (0, db_1.getRawEvents)({
139
+ periodStart: startOfDay.toISOString(),
140
+ periodEnd: now.toISOString(),
141
+ limit: 10000,
142
+ });
143
+ if (rawEvents.length > 0) {
144
+ const events = rawEvents.map((e) => ({
145
+ timestamp: e.timestamp,
146
+ duration: e.duration,
147
+ data: { app: e.app, title: e.title, url: e.url },
148
+ }));
149
+ const engine = (0, insights_1.createInsightEngine)();
150
+ const result = engine.runFullAnalysis(events);
151
+ const insightRecords = result.insights.map(i => ({
152
+ type: i.type,
153
+ period_start: i.period_start,
154
+ period_end: i.period_end,
155
+ title: i.title,
156
+ description: i.description,
157
+ confidence: i.confidence,
158
+ evidence: i.evidence,
159
+ action_text: i.action_text,
160
+ }));
161
+ if (insightRecords.length > 0) {
162
+ const stored = (0, db_1.insertInsights)(insightRecords);
163
+ insightsGenerated += stored;
164
+ }
165
+ const todayStr = now.toISOString().slice(0, 10);
166
+ (0, db_1.upsertDailySummary)({
167
+ date: todayStr,
168
+ total_active_time: result.totalActiveTime,
169
+ top_apps: JSON.stringify(result.appSummaries.slice(0, 10).map(a => ({ app: a.app, minutes: Math.round(a.totalDuration / 60) }))),
170
+ switch_count: result.contextSwitches.reduce((s, c) => s + c.count, 0),
171
+ insight_count: insightsGenerated,
172
+ raw_summary: result.summary,
173
+ });
174
+ }
175
+ }
176
+ catch (err) {
177
+ errors.push(`Insight extraction error: ${err instanceof Error ? err.message : String(err)}`);
178
+ }
179
+ try {
180
+ await pushNewInsights();
181
+ }
182
+ catch (err) {
183
+ errors.push(`Push error: ${err instanceof Error ? err.message : String(err)}`);
184
+ }
185
+ return { eventsStored, insightsGenerated, errors };
186
+ }
187
+ async function pushNewInsights() {
188
+ const config = (0, config_1.loadConfig)();
189
+ const activeTargets = [];
190
+ if (config.transports.slack.webhookUrl)
191
+ activeTargets.push('slack');
192
+ if (config.transports.telegram.botToken && config.transports.telegram.chatId)
193
+ activeTargets.push('telegram');
194
+ if (config.transports.webhook.url)
195
+ activeTargets.push('webhook');
196
+ if (activeTargets.length === 0)
197
+ return;
198
+ const recent = (0, db_1.getInsights)({ includePushed: true, limit: 50 });
199
+ for (const insight of recent) {
200
+ const pushedTargets = insight.pushed_to
201
+ ? insight.pushed_to.split(',').map((s) => s.trim())
202
+ : [];
203
+ const remaining = activeTargets.filter(t => !pushedTargets.includes(t));
204
+ if (remaining.length === 0)
205
+ continue;
206
+ const results = await (0, transport_1.pushInsightToAll)(insight.title, insight.description, insight.action_text, remaining);
207
+ for (const result of results) {
208
+ if (result.ok) {
209
+ (0, db_1.markInsightPushed)(insight.id, result.target);
210
+ }
211
+ }
212
+ }
213
+ }
214
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":";;AAWA,wCAgBC;AAsBD,sCAOC;AAED,wCAiJC;AA3MD,6BAAsC;AACtC,6CAAsD;AACtD,yCAAiD;AACjD,6BAA2J;AAC3J,2CAA4D;AAC5D,qCAAsC;AAEtC,IAAI,cAAc,GAAyC,IAAI,CAAC;AAChE,IAAI,SAAS,GAAG,KAAK,CAAC;AACt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SAAS,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACxE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QAErC,MAAM,OAAO,GAAG,MAAM,IAAA,4BAAgB,EACpC,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,WAAW,EACnB,SAAS,CACV,CAAC;QAEF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;gBACd,IAAA,sBAAiB,EAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ export interface ScreenpipeSearchResult {
2
+ type: string;
3
+ content: {
4
+ text?: string;
5
+ app_name?: string;
6
+ window_name?: string;
7
+ browser_url?: string;
8
+ transcription?: string;
9
+ [key: string]: unknown;
10
+ };
11
+ timestamp: string;
12
+ }
13
+ export declare class ScreenpipeClient {
14
+ private baseUrl;
15
+ constructor(baseUrl?: string);
16
+ healthCheck(): Promise<{
17
+ ok: boolean;
18
+ error?: string;
19
+ }>;
20
+ search(query: string, limit?: number): Promise<ScreenpipeSearchResult[]>;
21
+ getRecentOCR(limit?: number): Promise<ScreenpipeSearchResult[]>;
22
+ getRecentAudio(limit?: number): Promise<ScreenpipeSearchResult[]>;
23
+ }
24
+ export declare function createScreenpipeClient(baseUrl?: string): ScreenpipeClient;
25
+ //# sourceMappingURL=screenpipe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screenpipe.d.ts","sourceRoot":"","sources":["../src/screenpipe.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,CAAC,EAAE,MAAM;IAItB,WAAW,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAUvD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC;IAapE,YAAY,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC;IAc3D,cAAc,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC;CAapE;AAED,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAEzE"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScreenpipeClient = void 0;
4
+ exports.createScreenpipeClient = createScreenpipeClient;
5
+ const config_1 = require("./config");
6
+ class ScreenpipeClient {
7
+ baseUrl;
8
+ constructor(baseUrl) {
9
+ this.baseUrl = baseUrl || (0, config_1.getConfig)().screenpipe.baseUrl;
10
+ }
11
+ async healthCheck() {
12
+ try {
13
+ const res = await fetch(`${this.baseUrl}/health`, { signal: AbortSignal.timeout(3000) });
14
+ if (!res.ok)
15
+ return { ok: false, error: `HTTP ${res.status}` };
16
+ return { ok: true };
17
+ }
18
+ catch (err) {
19
+ return { ok: false, error: String(err) };
20
+ }
21
+ }
22
+ async search(query, limit = 50) {
23
+ try {
24
+ const res = await fetch(`${this.baseUrl}/search?q=${encodeURIComponent(query)}&limit=${limit}`, {
25
+ signal: AbortSignal.timeout(10000),
26
+ });
27
+ if (!res.ok)
28
+ throw new Error(`Search failed: HTTP ${res.status}`);
29
+ const json = await res.json();
30
+ return json.data || [];
31
+ }
32
+ catch (err) {
33
+ throw new Error(`Screenpipe search failed: ${err}`);
34
+ }
35
+ }
36
+ async getRecentOCR(limit = 20) {
37
+ try {
38
+ const res = await fetch(`${this.baseUrl}/search?content_type=ocr&limit=${limit}`, {
39
+ signal: AbortSignal.timeout(10000),
40
+ });
41
+ if (!res.ok)
42
+ throw new Error(`OCR fetch failed: HTTP ${res.status}`);
43
+ const json = await res.json();
44
+ return json.data || [];
45
+ }
46
+ catch (err) {
47
+ console.error('[daybrain] Screenpipe OCR fetch failed:', err instanceof Error ? err.message : String(err));
48
+ return [];
49
+ }
50
+ }
51
+ async getRecentAudio(limit = 20) {
52
+ try {
53
+ const res = await fetch(`${this.baseUrl}/search?content_type=audio&limit=${limit}`, {
54
+ signal: AbortSignal.timeout(10000),
55
+ });
56
+ if (!res.ok)
57
+ throw new Error(`Audio fetch failed: HTTP ${res.status}`);
58
+ const json = await res.json();
59
+ return json.data || [];
60
+ }
61
+ catch (err) {
62
+ console.error('[daybrain] Screenpipe audio fetch failed:', err instanceof Error ? err.message : String(err));
63
+ return [];
64
+ }
65
+ }
66
+ }
67
+ exports.ScreenpipeClient = ScreenpipeClient;
68
+ function createScreenpipeClient(baseUrl) {
69
+ return new ScreenpipeClient(baseUrl);
70
+ }
71
+ //# sourceMappingURL=screenpipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screenpipe.js","sourceRoot":"","sources":["../src/screenpipe.ts"],"names":[],"mappings":";;;AA0EA,wDAEC;AA5ED,qCAAqC;AAerC,MAAa,gBAAgB;IACnB,OAAO,CAAS;IAExB,YAAY,OAAgB;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,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CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAC7G,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF;AAzDD,4CAyDC;AAED,SAAgB,sBAAsB,CAAC,OAAgB;IACrD,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,12 @@
1
+ interface TransportResult {
2
+ ok: boolean;
3
+ target: string;
4
+ error?: string;
5
+ }
6
+ export declare function pushToSlack(message: string): Promise<TransportResult>;
7
+ export declare function pushToTelegram(message: string): Promise<TransportResult>;
8
+ export declare function pushToWebhook(message: string): Promise<TransportResult>;
9
+ export declare function pushInsightToAll(title: string, description: string, actionText: string, targets: string[]): Promise<TransportResult[]>;
10
+ export declare function pushSummary(summary: string, targets: string[]): Promise<TransportResult[]>;
11
+ export {};
12
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAEA,UAAU,eAAe;IACvB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAuBD,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAsB3E;AAED,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CA6B9E;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CA6B7E;AAED,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,eAAe,EAAE,CAAC,CAqB5B;AAaD,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAoBhG"}
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pushToSlack = pushToSlack;
4
+ exports.pushToTelegram = pushToTelegram;
5
+ exports.pushToWebhook = pushToWebhook;
6
+ exports.pushInsightToAll = pushInsightToAll;
7
+ exports.pushSummary = pushSummary;
8
+ const config_1 = require("./config");
9
+ async function fetchWithRetry(url, options, retries = 3) {
10
+ let lastError;
11
+ for (let attempt = 1; attempt <= retries; attempt++) {
12
+ try {
13
+ const res = await fetch(url, options);
14
+ return res;
15
+ }
16
+ catch (err) {
17
+ lastError = err;
18
+ if (attempt < retries) {
19
+ const delay = Math.min(1000 * Math.pow(2, attempt - 1), 8000);
20
+ await new Promise(r => setTimeout(r, delay));
21
+ }
22
+ }
23
+ }
24
+ throw lastError;
25
+ }
26
+ async function pushToSlack(message) {
27
+ const config = (0, config_1.getConfig)().transports.slack;
28
+ if (!config.webhookUrl) {
29
+ return { ok: false, target: 'slack', error: 'Slack webhook URL not configured' };
30
+ }
31
+ try {
32
+ const res = await fetchWithRetry(config.webhookUrl, {
33
+ method: 'POST',
34
+ headers: { 'Content-Type': 'application/json' },
35
+ body: JSON.stringify({ text: message }),
36
+ signal: AbortSignal.timeout(15000),
37
+ });
38
+ if (!res.ok) {
39
+ return { ok: false, target: 'slack', error: `HTTP ${res.status}: ${await res.text()}` };
40
+ }
41
+ return { ok: true, target: 'slack' };
42
+ }
43
+ catch (err) {
44
+ return { ok: false, target: 'slack', error: String(err) };
45
+ }
46
+ }
47
+ async function pushToTelegram(message) {
48
+ const config = (0, config_1.getConfig)().transports.telegram;
49
+ if (!config.botToken || !config.chatId) {
50
+ return { ok: false, target: 'telegram', error: 'Telegram bot token or chat ID not configured' };
51
+ }
52
+ try {
53
+ const url = `https://api.telegram.org/bot${config.botToken}/sendMessage`;
54
+ const res = await fetchWithRetry(url, {
55
+ method: 'POST',
56
+ headers: { 'Content-Type': 'application/json' },
57
+ body: JSON.stringify({
58
+ chat_id: config.chatId,
59
+ text: message,
60
+ parse_mode: 'HTML',
61
+ disable_web_page_preview: true,
62
+ }),
63
+ signal: AbortSignal.timeout(15000),
64
+ });
65
+ if (!res.ok) {
66
+ const body = await res.text();
67
+ return { ok: false, target: 'telegram', error: `HTTP ${res.status}: ${body}` };
68
+ }
69
+ return { ok: true, target: 'telegram' };
70
+ }
71
+ catch (err) {
72
+ return { ok: false, target: 'telegram', error: String(err) };
73
+ }
74
+ }
75
+ async function pushToWebhook(message) {
76
+ const config = (0, config_1.getConfig)().transports.webhook;
77
+ if (!config.url) {
78
+ return { ok: false, target: 'webhook', error: 'Webhook URL not configured' };
79
+ }
80
+ try {
81
+ const res = await fetchWithRetry(config.url, {
82
+ method: 'POST',
83
+ headers: {
84
+ 'Content-Type': 'application/json',
85
+ ...config.headers,
86
+ },
87
+ body: JSON.stringify({
88
+ text: message,
89
+ timestamp: new Date().toISOString(),
90
+ source: 'opencontext',
91
+ }),
92
+ signal: AbortSignal.timeout(15000),
93
+ });
94
+ if (!res.ok) {
95
+ return { ok: false, target: 'webhook', error: `HTTP ${res.status}` };
96
+ }
97
+ return { ok: true, target: 'webhook' };
98
+ }
99
+ catch (err) {
100
+ return { ok: false, target: 'webhook', error: String(err) };
101
+ }
102
+ }
103
+ async function pushInsightToAll(title, description, actionText, targets) {
104
+ const message = formatInsightMessage(title, description, actionText);
105
+ const results = [];
106
+ for (const target of targets) {
107
+ switch (target) {
108
+ case 'slack':
109
+ results.push(await pushToSlack(message));
110
+ break;
111
+ case 'telegram':
112
+ results.push(await pushToTelegram(message));
113
+ break;
114
+ case 'webhook':
115
+ results.push(await pushToWebhook(message));
116
+ break;
117
+ default:
118
+ results.push({ ok: false, target, error: `Unknown transport: ${target}` });
119
+ }
120
+ }
121
+ return results;
122
+ }
123
+ function formatInsightMessage(title, description, actionText) {
124
+ const esc = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
125
+ let msg = `<b>🔍 ${esc(title)}</b>\n\n`;
126
+ msg += `${esc(description)}\n`;
127
+ if (actionText) {
128
+ msg += `\n<b>💡 Suggestion:</b> ${esc(actionText)}`;
129
+ }
130
+ msg += `\n\n<code>via OpenContext</code>`;
131
+ return msg;
132
+ }
133
+ async function pushSummary(summary, targets) {
134
+ const results = [];
135
+ for (const target of targets) {
136
+ switch (target) {
137
+ case 'slack':
138
+ results.push(await pushToSlack(summary));
139
+ break;
140
+ case 'telegram':
141
+ results.push(await pushToTelegram(summary));
142
+ break;
143
+ case 'webhook':
144
+ results.push(await pushToWebhook(summary));
145
+ break;
146
+ default:
147
+ results.push({ ok: false, target, error: `Unknown transport: ${target}` });
148
+ }
149
+ }
150
+ return results;
151
+ }
152
+ //# sourceMappingURL=transport.js.map