UNPKG

@firefliesai/fireflies-node-sdk

Version:
118 lines (117 loc) 4.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MeetingsHelper = void 0; exports.generateGraphQLFilter = generateGraphQLFilter; const fireflies_1 = require("./fireflies"); function generateGraphQLFilter(fields) { return fields.join(" "); } class MeetingsHelper { static async delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } static async batchProcess(tasks, apiKey) { let index = 0; const results = []; const errors = []; while (index < tasks.length) { const end = Math.min(index + MeetingsHelper.CONCURRENCY_LIMIT, tasks.length); console.log(`Processing ${index} to ${end} of ${tasks.length} for apiKey: ${apiKey.split('-')[0]}`); const currentBatch = tasks.slice(index, end).map(task => { return task().catch(e => { console.error(`Error processing task at index ${index}: ${e}`); return { errors: [{ code: e.message }] }; }); }); const batchResults = await Promise.all(currentBatch); batchResults.forEach(result => { var _a, _b; if (result === null || result === void 0 ? void 0 : result.errors) { errors.push((_a = result.errors[0]) === null || _a === void 0 ? void 0 : _a.code); } else if ((_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.transcript) { results.push(result.data.transcript); } }); index += MeetingsHelper.CONCURRENCY_LIMIT; if (index < tasks.length) { await MeetingsHelper.delay(MeetingsHelper.DELAY_TIME); } } return { meetings: results, errors }; } static async getAllMeetingIds(sdk) { let skip = 0; const limit = 50; let hasMore = true; let allItems = []; while (hasMore) { try { const items = await sdk.getTranscripts({ limit, skip }, ['id']); if (items) { allItems = allItems.concat(items); } if (!items || items.length < limit) { hasMore = false; } else { skip += limit; } } catch (error) { if (error instanceof Error) { console.error("An error occurred while fetching items:", error.message); } throw error; } } return allItems.map(item => item.id); } static async getDedeuplicatedMeetingIds(apiKeys) { const allItems = {}; const uniqueItems = new Set(); for (const apiKey of apiKeys) { const sdk = new fireflies_1.FirefliesSDK({ apiKey }); const items = await MeetingsHelper.getAllMeetingIds(sdk); allItems[apiKey] = items; items.forEach(item => uniqueItems.add(item)); } console.log(`Found unique meetings: ${uniqueItems.size}`); const deduplicatedItems = Array.from(uniqueItems); const result = {}; const assignedItems = new Set(); for (const apiKey of apiKeys) { result[apiKey] = deduplicatedItems.filter(item => { const isInCurrentApiKey = allItems[apiKey].includes(item); const isAlreadyAssigned = assignedItems.has(item); if (isInCurrentApiKey && !isAlreadyAssigned) { assignedItems.add(item); return true; } return false; }); } return result; } static async handleOutput(result, apiKey, outputType) { if (outputType === 'json') { try { const fs = require('fs'); fs.writeFileSync(`RESULTS_${apiKey}.json`, JSON.stringify(result.meetings, null, 2)); if (result.errors.length > 0) { fs.writeFileSync(`ERRORS_${apiKey}.json`, JSON.stringify(result.errors, null, 2)); } } catch (e) { console.error('Error writing to file:', e); } } else { console.log('Meetings:', result.meetings); console.log('Errors:', result.errors); } } } exports.MeetingsHelper = MeetingsHelper; MeetingsHelper.CONCURRENCY_LIMIT = 5; MeetingsHelper.DELAY_TIME = 5000;