@teamvibe/poller 0.1.15 → 0.1.17
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/auth-provider.js +28 -0
- package/dist/brain-manager.d.ts +1 -2
- package/dist/brain-manager.js +11 -4
- package/dist/config.d.ts +1 -0
- package/dist/config.js +4 -0
- package/dist/poller.js +1 -1
- package/dist/types.d.ts +0 -1
- package/package.json +1 -1
package/dist/auth-provider.js
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
+
import { POLLER_VERSION } from './config.js';
|
|
1
2
|
import { logger } from './logger.js';
|
|
2
3
|
let currentCredentials = null;
|
|
3
4
|
let currentConfig = null;
|
|
4
5
|
let refreshTimer = null;
|
|
6
|
+
let heartbeatTimer = null;
|
|
5
7
|
const REFRESH_INTERVAL_MS = 50 * 60 * 1000; // 50 minutes (before 1hr expiry)
|
|
8
|
+
const HEARTBEAT_INTERVAL_MS = 60 * 1000; // 1 minute
|
|
9
|
+
async function sendHeartbeat(apiUrl, token, version) {
|
|
10
|
+
try {
|
|
11
|
+
const response = await fetch(`${apiUrl}/heartbeat`, {
|
|
12
|
+
method: 'POST',
|
|
13
|
+
headers: {
|
|
14
|
+
Authorization: `Bearer ${token}`,
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
body: JSON.stringify({ version }),
|
|
18
|
+
});
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
logger.warn(`Heartbeat failed (${response.status})`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
logger.warn(`Heartbeat error: ${error instanceof Error ? error.message : error}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
6
27
|
async function fetchCredentials(apiUrl, token) {
|
|
7
28
|
const response = await fetch(`${apiUrl}/auth`, {
|
|
8
29
|
method: 'POST',
|
|
@@ -25,6 +46,9 @@ export async function initAuth(apiUrl, token) {
|
|
|
25
46
|
logger.info(`Authenticated successfully. Region: ${auth.config.region}`);
|
|
26
47
|
logger.info(` SQS Queue: ${auth.config.sqsQueueUrl}`);
|
|
27
48
|
logger.info(` Sessions Table: ${auth.config.sessionsTable}`);
|
|
49
|
+
// Send initial heartbeat and schedule periodic heartbeats
|
|
50
|
+
sendHeartbeat(apiUrl, token, POLLER_VERSION);
|
|
51
|
+
heartbeatTimer = setInterval(() => sendHeartbeat(apiUrl, token, POLLER_VERSION), HEARTBEAT_INTERVAL_MS);
|
|
28
52
|
// Schedule credential refresh
|
|
29
53
|
refreshTimer = setInterval(async () => {
|
|
30
54
|
try {
|
|
@@ -59,4 +83,8 @@ export function stopRefresh() {
|
|
|
59
83
|
clearInterval(refreshTimer);
|
|
60
84
|
refreshTimer = null;
|
|
61
85
|
}
|
|
86
|
+
if (heartbeatTimer) {
|
|
87
|
+
clearInterval(heartbeatTimer);
|
|
88
|
+
heartbeatTimer = null;
|
|
89
|
+
}
|
|
62
90
|
}
|
package/dist/brain-manager.d.ts
CHANGED
|
@@ -2,12 +2,11 @@ interface BrainConfig {
|
|
|
2
2
|
brainId: string;
|
|
3
3
|
gitRepoUrl: string;
|
|
4
4
|
branch: string;
|
|
5
|
-
claudePath: string;
|
|
6
5
|
}
|
|
7
6
|
/**
|
|
8
7
|
* Get or clone brain repo. Returns the working directory path.
|
|
9
8
|
*/
|
|
10
|
-
export declare function getBrainPath(brain?: BrainConfig): Promise<string>;
|
|
9
|
+
export declare function getBrainPath(brain?: BrainConfig, channelId?: string): Promise<string>;
|
|
11
10
|
/**
|
|
12
11
|
* Ensure base brain repo is cloned and up to date.
|
|
13
12
|
* Uses same cooldown pattern as channel brains.
|
package/dist/brain-manager.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { exec } from 'child_process';
|
|
2
2
|
import { promisify } from 'util';
|
|
3
|
-
import { existsSync } from 'fs';
|
|
3
|
+
import { existsSync, mkdirSync } from 'fs';
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
import { config } from './config.js';
|
|
6
6
|
import { logger } from './logger.js';
|
|
@@ -10,9 +10,17 @@ const lastUpdateTimes = new Map();
|
|
|
10
10
|
/**
|
|
11
11
|
* Get or clone brain repo. Returns the working directory path.
|
|
12
12
|
*/
|
|
13
|
-
export async function getBrainPath(brain) {
|
|
14
|
-
if (!brain?.gitRepoUrl)
|
|
13
|
+
export async function getBrainPath(brain, channelId) {
|
|
14
|
+
if (!brain?.gitRepoUrl) {
|
|
15
|
+
if (channelId) {
|
|
16
|
+
const channelDir = join(config.BRAINS_PATH, `channel_${channelId}`);
|
|
17
|
+
if (!existsSync(channelDir)) {
|
|
18
|
+
mkdirSync(channelDir, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
return channelDir;
|
|
21
|
+
}
|
|
15
22
|
return config.DEFAULT_BRAIN_PATH;
|
|
23
|
+
}
|
|
16
24
|
const brainDir = join(config.BRAINS_PATH, brain.brainId);
|
|
17
25
|
if (!existsSync(brainDir)) {
|
|
18
26
|
logger.info(`Cloning brain ${brain.brainId} from ${brain.gitRepoUrl} (branch: ${brain.branch})...`);
|
|
@@ -120,7 +128,6 @@ export async function pushBrainChanges(brainDir, brainId) {
|
|
|
120
128
|
* Ensure base paths exist
|
|
121
129
|
*/
|
|
122
130
|
export async function ensureDirectories() {
|
|
123
|
-
const { mkdirSync } = await import('fs');
|
|
124
131
|
if (!existsSync(config.BRAINS_PATH)) {
|
|
125
132
|
mkdirSync(config.BRAINS_PATH, { recursive: true });
|
|
126
133
|
}
|
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { config as dotenvConfig } from 'dotenv';
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
const pkg = require('../package.json');
|
|
6
|
+
export const POLLER_VERSION = pkg.version;
|
|
3
7
|
dotenvConfig();
|
|
4
8
|
const DEFAULT_DATA_DIR = `${process.env['HOME']}/.teamvibe`;
|
|
5
9
|
const configSchema = z.object({
|
package/dist/poller.js
CHANGED
|
@@ -82,7 +82,7 @@ async function processMessage(received) {
|
|
|
82
82
|
// Get brain path for this channel
|
|
83
83
|
let kbPath;
|
|
84
84
|
try {
|
|
85
|
-
kbPath = await getBrainPath(queueMessage.teamvibe.brain);
|
|
85
|
+
kbPath = await getBrainPath(queueMessage.teamvibe.brain, queueMessage.response_context.slack?.channel);
|
|
86
86
|
}
|
|
87
87
|
catch (error) {
|
|
88
88
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
package/dist/types.d.ts
CHANGED