@teamvibe/poller 0.1.16 → 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.
@@ -1,3 +1,4 @@
1
+ import { POLLER_VERSION } from './config.js';
1
2
  import { logger } from './logger.js';
2
3
  let currentCredentials = null;
3
4
  let currentConfig = null;
@@ -5,13 +6,15 @@ let refreshTimer = null;
5
6
  let heartbeatTimer = null;
6
7
  const REFRESH_INTERVAL_MS = 50 * 60 * 1000; // 50 minutes (before 1hr expiry)
7
8
  const HEARTBEAT_INTERVAL_MS = 60 * 1000; // 1 minute
8
- async function sendHeartbeat(apiUrl, token) {
9
+ async function sendHeartbeat(apiUrl, token, version) {
9
10
  try {
10
11
  const response = await fetch(`${apiUrl}/heartbeat`, {
11
12
  method: 'POST',
12
13
  headers: {
13
14
  Authorization: `Bearer ${token}`,
15
+ 'Content-Type': 'application/json',
14
16
  },
17
+ body: JSON.stringify({ version }),
15
18
  });
16
19
  if (!response.ok) {
17
20
  logger.warn(`Heartbeat failed (${response.status})`);
@@ -44,8 +47,8 @@ export async function initAuth(apiUrl, token) {
44
47
  logger.info(` SQS Queue: ${auth.config.sqsQueueUrl}`);
45
48
  logger.info(` Sessions Table: ${auth.config.sessionsTable}`);
46
49
  // Send initial heartbeat and schedule periodic heartbeats
47
- sendHeartbeat(apiUrl, token);
48
- heartbeatTimer = setInterval(() => sendHeartbeat(apiUrl, token), HEARTBEAT_INTERVAL_MS);
50
+ sendHeartbeat(apiUrl, token, POLLER_VERSION);
51
+ heartbeatTimer = setInterval(() => sendHeartbeat(apiUrl, token, POLLER_VERSION), HEARTBEAT_INTERVAL_MS);
49
52
  // Schedule credential refresh
50
53
  refreshTimer = setInterval(async () => {
51
54
  try {
@@ -6,7 +6,7 @@ interface BrainConfig {
6
6
  /**
7
7
  * Get or clone brain repo. Returns the working directory path.
8
8
  */
9
- export declare function getBrainPath(brain?: BrainConfig): Promise<string>;
9
+ export declare function getBrainPath(brain?: BrainConfig, channelId?: string): Promise<string>;
10
10
  /**
11
11
  * Ensure base brain repo is cloned and up to date.
12
12
  * Uses same cooldown pattern as channel brains.
@@ -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
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ export declare const POLLER_VERSION: string;
2
3
  declare const configSchema: z.ZodObject<{
3
4
  AWS_REGION: z.ZodDefault<z.ZodString>;
4
5
  SQS_QUEUE_URL: z.ZodOptional<z.ZodString>;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamvibe/poller",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {