fireflies-api 0.5.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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/action-items-CC9yUxHY.d.cts +380 -0
- package/dist/action-items-CC9yUxHY.d.ts +380 -0
- package/dist/cli/index.cjs +3909 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +2 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +3906 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.cjs +3389 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +966 -0
- package/dist/index.d.ts +966 -0
- package/dist/index.js +3344 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/express.cjs +2491 -0
- package/dist/middleware/express.cjs.map +1 -0
- package/dist/middleware/express.d.cts +36 -0
- package/dist/middleware/express.d.ts +36 -0
- package/dist/middleware/express.js +2489 -0
- package/dist/middleware/express.js.map +1 -0
- package/dist/middleware/fastify.cjs +2501 -0
- package/dist/middleware/fastify.cjs.map +1 -0
- package/dist/middleware/fastify.d.cts +66 -0
- package/dist/middleware/fastify.d.ts +66 -0
- package/dist/middleware/fastify.js +2498 -0
- package/dist/middleware/fastify.js.map +1 -0
- package/dist/middleware/hono.cjs +2493 -0
- package/dist/middleware/hono.cjs.map +1 -0
- package/dist/middleware/hono.d.cts +37 -0
- package/dist/middleware/hono.d.ts +37 -0
- package/dist/middleware/hono.js +2490 -0
- package/dist/middleware/hono.js.map +1 -0
- package/dist/schemas/index.cjs +307 -0
- package/dist/schemas/index.cjs.map +1 -0
- package/dist/schemas/index.d.cts +926 -0
- package/dist/schemas/index.d.ts +926 -0
- package/dist/schemas/index.js +268 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/speaker-analytics-Dr46LKyP.d.ts +275 -0
- package/dist/speaker-analytics-l45LXqO1.d.cts +275 -0
- package/dist/types-BX-3JcRI.d.cts +41 -0
- package/dist/types-C_XxdRd1.d.cts +1546 -0
- package/dist/types-CaHcwnKw.d.ts +41 -0
- package/dist/types-DIPZmUl3.d.ts +1546 -0
- package/package.json +126 -0
|
@@ -0,0 +1,3909 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var url = require('url');
|
|
7
|
+
var commander = require('commander');
|
|
8
|
+
var socket_ioClient = require('socket.io-client');
|
|
9
|
+
var promises = require('fs/promises');
|
|
10
|
+
|
|
11
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
12
|
+
// src/cli/index.ts
|
|
13
|
+
|
|
14
|
+
// src/errors.ts
|
|
15
|
+
var FirefliesError = class extends Error {
|
|
16
|
+
code = "FIREFLIES_ERROR";
|
|
17
|
+
status;
|
|
18
|
+
constructor(message, options) {
|
|
19
|
+
super(message, { cause: options?.cause });
|
|
20
|
+
this.name = "FirefliesError";
|
|
21
|
+
this.status = options?.status;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var AuthenticationError = class extends FirefliesError {
|
|
25
|
+
code = "AUTHENTICATION_ERROR";
|
|
26
|
+
constructor(message = "Invalid or missing API key") {
|
|
27
|
+
super(message, { status: 401 });
|
|
28
|
+
this.name = "AuthenticationError";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var RateLimitError = class extends FirefliesError {
|
|
32
|
+
code = "RATE_LIMIT_ERROR";
|
|
33
|
+
/** Suggested wait time in milliseconds before retrying. */
|
|
34
|
+
retryAfter;
|
|
35
|
+
constructor(message = "Rate limit exceeded", retryAfter) {
|
|
36
|
+
super(message, { status: 429 });
|
|
37
|
+
this.name = "RateLimitError";
|
|
38
|
+
this.retryAfter = retryAfter;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var NotFoundError = class extends FirefliesError {
|
|
42
|
+
code = "NOT_FOUND";
|
|
43
|
+
constructor(message = "Resource not found") {
|
|
44
|
+
super(message, { status: 404 });
|
|
45
|
+
this.name = "NotFoundError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var ValidationError = class extends FirefliesError {
|
|
49
|
+
code = "VALIDATION_ERROR";
|
|
50
|
+
constructor(message) {
|
|
51
|
+
super(message, { status: 400 });
|
|
52
|
+
this.name = "ValidationError";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var GraphQLError = class extends FirefliesError {
|
|
56
|
+
code = "GRAPHQL_ERROR";
|
|
57
|
+
errors;
|
|
58
|
+
constructor(message, errors) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = "GraphQLError";
|
|
61
|
+
this.errors = errors;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var TimeoutError = class extends FirefliesError {
|
|
65
|
+
code = "TIMEOUT_ERROR";
|
|
66
|
+
constructor(message = "Request timed out") {
|
|
67
|
+
super(message, { status: 408 });
|
|
68
|
+
this.name = "TimeoutError";
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var NetworkError = class extends FirefliesError {
|
|
72
|
+
code = "NETWORK_ERROR";
|
|
73
|
+
constructor(message, cause) {
|
|
74
|
+
super(message, { cause });
|
|
75
|
+
this.name = "NetworkError";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var RealtimeError = class extends FirefliesError {
|
|
79
|
+
code = "REALTIME_ERROR";
|
|
80
|
+
constructor(message, options) {
|
|
81
|
+
super(message, options);
|
|
82
|
+
this.name = "RealtimeError";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var ConnectionError = class extends RealtimeError {
|
|
86
|
+
code = "CONNECTION_ERROR";
|
|
87
|
+
constructor(message = "Failed to establish realtime connection", options) {
|
|
88
|
+
super(message, options);
|
|
89
|
+
this.name = "ConnectionError";
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var StreamClosedError = class extends RealtimeError {
|
|
93
|
+
code = "STREAM_CLOSED";
|
|
94
|
+
constructor(message = "Stream has been closed") {
|
|
95
|
+
super(message);
|
|
96
|
+
this.name = "StreamClosedError";
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
function parseErrorResponse(status, body, defaultMessage) {
|
|
100
|
+
const message = extractErrorMessage(body) ?? defaultMessage;
|
|
101
|
+
switch (status) {
|
|
102
|
+
case 401:
|
|
103
|
+
return new AuthenticationError(message);
|
|
104
|
+
case 404:
|
|
105
|
+
return new NotFoundError(message);
|
|
106
|
+
case 429: {
|
|
107
|
+
const retryAfter = extractRetryAfter(body);
|
|
108
|
+
return new RateLimitError(message, retryAfter);
|
|
109
|
+
}
|
|
110
|
+
case 400:
|
|
111
|
+
return new ValidationError(message);
|
|
112
|
+
default:
|
|
113
|
+
return new FirefliesError(message, { status });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function extractErrorMessage(body) {
|
|
117
|
+
if (typeof body === "object" && body !== null) {
|
|
118
|
+
const obj = body;
|
|
119
|
+
if (typeof obj.message === "string") {
|
|
120
|
+
return obj.message;
|
|
121
|
+
}
|
|
122
|
+
if (typeof obj.error === "string") {
|
|
123
|
+
return obj.error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return void 0;
|
|
127
|
+
}
|
|
128
|
+
function extractRetryAfter(body) {
|
|
129
|
+
if (typeof body === "object" && body !== null) {
|
|
130
|
+
const obj = body;
|
|
131
|
+
if (typeof obj.retryAfter === "number") {
|
|
132
|
+
return obj.retryAfter;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/utils/rate-limit-tracker.ts
|
|
139
|
+
var RATE_LIMIT_REMAINING_HEADER = "x-ratelimit-remaining-api";
|
|
140
|
+
var RATE_LIMIT_LIMIT_HEADER = "x-ratelimit-limit-api";
|
|
141
|
+
var RATE_LIMIT_RESET_HEADER = "x-ratelimit-reset-api";
|
|
142
|
+
var RateLimitTracker = class {
|
|
143
|
+
_remaining;
|
|
144
|
+
_limit;
|
|
145
|
+
_resetInSeconds;
|
|
146
|
+
_updatedAt;
|
|
147
|
+
warningThreshold;
|
|
148
|
+
/**
|
|
149
|
+
* Create a new RateLimitTracker.
|
|
150
|
+
* @param warningThreshold - Threshold below which isLow returns true
|
|
151
|
+
*/
|
|
152
|
+
constructor(warningThreshold = 10) {
|
|
153
|
+
this._remaining = void 0;
|
|
154
|
+
this._limit = void 0;
|
|
155
|
+
this._resetInSeconds = void 0;
|
|
156
|
+
this._updatedAt = 0;
|
|
157
|
+
this.warningThreshold = warningThreshold;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get the current rate limit state.
|
|
161
|
+
*/
|
|
162
|
+
get state() {
|
|
163
|
+
return {
|
|
164
|
+
remaining: this._remaining,
|
|
165
|
+
limit: this._limit,
|
|
166
|
+
resetInSeconds: this._resetInSeconds,
|
|
167
|
+
updatedAt: this._updatedAt
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Check if remaining requests are below the warning threshold.
|
|
172
|
+
* Returns false if remaining is undefined (header not received).
|
|
173
|
+
*/
|
|
174
|
+
get isLow() {
|
|
175
|
+
return this._remaining !== void 0 && this._remaining < this.warningThreshold;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Update state from response headers.
|
|
179
|
+
* Extracts x-ratelimit-remaining-api, x-ratelimit-limit-api, and x-ratelimit-reset-api headers.
|
|
180
|
+
*
|
|
181
|
+
* @param headers - Response headers (Headers object or plain object)
|
|
182
|
+
*/
|
|
183
|
+
update(headers) {
|
|
184
|
+
const remaining = this.getHeader(headers, RATE_LIMIT_REMAINING_HEADER);
|
|
185
|
+
if (remaining !== null) {
|
|
186
|
+
const parsed = Number.parseInt(remaining, 10);
|
|
187
|
+
if (!Number.isNaN(parsed) && parsed >= 0) {
|
|
188
|
+
this._remaining = parsed;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const limit = this.getHeader(headers, RATE_LIMIT_LIMIT_HEADER);
|
|
192
|
+
if (limit !== null) {
|
|
193
|
+
const parsed = Number.parseInt(limit, 10);
|
|
194
|
+
if (!Number.isNaN(parsed) && parsed >= 0) {
|
|
195
|
+
this._limit = parsed;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const reset = this.getHeader(headers, RATE_LIMIT_RESET_HEADER);
|
|
199
|
+
if (reset !== null) {
|
|
200
|
+
const parsed = Number.parseInt(reset, 10);
|
|
201
|
+
if (!Number.isNaN(parsed) && parsed >= 0) {
|
|
202
|
+
this._resetInSeconds = parsed;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
this._updatedAt = Date.now();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Reset the tracker to initial state.
|
|
209
|
+
*/
|
|
210
|
+
reset() {
|
|
211
|
+
this._remaining = void 0;
|
|
212
|
+
this._limit = void 0;
|
|
213
|
+
this._resetInSeconds = void 0;
|
|
214
|
+
this._updatedAt = 0;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Calculate the delay to apply before the next request.
|
|
218
|
+
* Returns 0 if throttling is disabled or not needed.
|
|
219
|
+
*
|
|
220
|
+
* Uses linear interpolation: more delay as remaining approaches 0.
|
|
221
|
+
* - remaining >= startThreshold: no delay
|
|
222
|
+
* - remaining = 0: maxDelay
|
|
223
|
+
* - remaining in between: proportional delay
|
|
224
|
+
*
|
|
225
|
+
* @param config - Throttle configuration
|
|
226
|
+
* @returns Delay in milliseconds
|
|
227
|
+
*/
|
|
228
|
+
getThrottleDelay(config) {
|
|
229
|
+
if (!config?.enabled) {
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
if (this._remaining === void 0) {
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
235
|
+
const startThreshold = Math.max(1, config.startThreshold ?? 20);
|
|
236
|
+
let minDelay = config.minDelay ?? 100;
|
|
237
|
+
let maxDelay = config.maxDelay ?? 2e3;
|
|
238
|
+
if (minDelay > maxDelay) {
|
|
239
|
+
[minDelay, maxDelay] = [maxDelay, minDelay];
|
|
240
|
+
}
|
|
241
|
+
if (this._remaining >= startThreshold) {
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
if (this._remaining <= 0) {
|
|
245
|
+
return maxDelay;
|
|
246
|
+
}
|
|
247
|
+
const ratio = 1 - this._remaining / startThreshold;
|
|
248
|
+
return Math.round(minDelay + ratio * (maxDelay - minDelay));
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Extract a header value from Headers object or plain object.
|
|
252
|
+
* For plain objects, performs case-insensitive key lookup.
|
|
253
|
+
*/
|
|
254
|
+
getHeader(headers, name) {
|
|
255
|
+
if (headers instanceof Headers) {
|
|
256
|
+
return headers.get(name);
|
|
257
|
+
}
|
|
258
|
+
const lowerName = name.toLowerCase();
|
|
259
|
+
for (const key of Object.keys(headers)) {
|
|
260
|
+
if (key.toLowerCase() === lowerName) {
|
|
261
|
+
return headers[key] ?? null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// src/utils/retry.ts
|
|
269
|
+
var DEFAULT_OPTIONS = {
|
|
270
|
+
maxRetries: 3,
|
|
271
|
+
baseDelay: 1e3,
|
|
272
|
+
maxDelay: 3e4
|
|
273
|
+
};
|
|
274
|
+
async function retry(fn, options) {
|
|
275
|
+
const maxRetries = options?.maxRetries ?? DEFAULT_OPTIONS.maxRetries;
|
|
276
|
+
const baseDelay = options?.baseDelay ?? DEFAULT_OPTIONS.baseDelay;
|
|
277
|
+
const maxDelay = options?.maxDelay ?? DEFAULT_OPTIONS.maxDelay;
|
|
278
|
+
const shouldRetry = options?.shouldRetry ?? isRetryableError;
|
|
279
|
+
let lastError;
|
|
280
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
281
|
+
try {
|
|
282
|
+
return await fn();
|
|
283
|
+
} catch (error) {
|
|
284
|
+
lastError = error;
|
|
285
|
+
if (attempt >= maxRetries || !shouldRetry(error, attempt)) {
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
const delay = calculateDelay(error, attempt, baseDelay, maxDelay);
|
|
289
|
+
await sleep(delay);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
throw lastError;
|
|
293
|
+
}
|
|
294
|
+
function isRetryableError(error) {
|
|
295
|
+
if (error instanceof RateLimitError) {
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
if (error instanceof TimeoutError) {
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
if (error instanceof NetworkError) {
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
if (error instanceof Error && "status" in error && typeof error.status === "number") {
|
|
305
|
+
return error.status >= 500 && error.status < 600;
|
|
306
|
+
}
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
function calculateDelay(error, attempt, baseDelay, maxDelay) {
|
|
310
|
+
if (error instanceof RateLimitError && error.retryAfter !== void 0) {
|
|
311
|
+
return Math.min(error.retryAfter, maxDelay);
|
|
312
|
+
}
|
|
313
|
+
const exponentialDelay = baseDelay * 2 ** attempt;
|
|
314
|
+
const jitter = Math.random() * 0.1 * exponentialDelay;
|
|
315
|
+
return Math.min(exponentialDelay + jitter, maxDelay);
|
|
316
|
+
}
|
|
317
|
+
function sleep(ms) {
|
|
318
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// src/graphql/client.ts
|
|
322
|
+
var DEFAULT_BASE_URL = "https://api.fireflies.ai/graphql";
|
|
323
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
324
|
+
var GraphQLClient = class {
|
|
325
|
+
apiKey;
|
|
326
|
+
baseUrl;
|
|
327
|
+
timeout;
|
|
328
|
+
retryOptions;
|
|
329
|
+
rateLimitTracker;
|
|
330
|
+
rateLimitConfig;
|
|
331
|
+
lastWarningRemaining;
|
|
332
|
+
constructor(config) {
|
|
333
|
+
if (!config.apiKey) {
|
|
334
|
+
throw new FirefliesError("API key is required");
|
|
335
|
+
}
|
|
336
|
+
this.apiKey = config.apiKey;
|
|
337
|
+
this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
338
|
+
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
339
|
+
this.retryOptions = buildRetryOptions(config.retry);
|
|
340
|
+
if (config.rateLimit) {
|
|
341
|
+
const warningThreshold = config.rateLimit.warningThreshold ?? 10;
|
|
342
|
+
this.rateLimitTracker = new RateLimitTracker(warningThreshold);
|
|
343
|
+
this.rateLimitConfig = config.rateLimit;
|
|
344
|
+
} else {
|
|
345
|
+
this.rateLimitTracker = null;
|
|
346
|
+
this.rateLimitConfig = null;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get the current rate limit state.
|
|
351
|
+
* Returns undefined if rate limit tracking is not configured.
|
|
352
|
+
*/
|
|
353
|
+
get rateLimitState() {
|
|
354
|
+
return this.rateLimitTracker?.state;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Execute a GraphQL query or mutation.
|
|
358
|
+
*
|
|
359
|
+
* @param query - GraphQL query string
|
|
360
|
+
* @param variables - Optional query variables
|
|
361
|
+
* @returns The data from the GraphQL response
|
|
362
|
+
* @throws GraphQLError if the response contains errors
|
|
363
|
+
* @throws AuthenticationError if the API key is invalid
|
|
364
|
+
* @throws RateLimitError if rate limits are exceeded
|
|
365
|
+
*/
|
|
366
|
+
async execute(query, variables) {
|
|
367
|
+
return retry(() => this.executeOnce(query, variables), this.retryOptions);
|
|
368
|
+
}
|
|
369
|
+
async executeOnce(query, variables) {
|
|
370
|
+
await this.applyThrottleDelay();
|
|
371
|
+
const controller = new AbortController();
|
|
372
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
373
|
+
try {
|
|
374
|
+
const response = await fetch(this.baseUrl, {
|
|
375
|
+
method: "POST",
|
|
376
|
+
headers: {
|
|
377
|
+
"Content-Type": "application/json",
|
|
378
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
379
|
+
},
|
|
380
|
+
body: JSON.stringify({ query, variables }),
|
|
381
|
+
signal: controller.signal
|
|
382
|
+
});
|
|
383
|
+
clearTimeout(timeoutId);
|
|
384
|
+
this.updateRateLimitState(response.headers);
|
|
385
|
+
if (!response.ok) {
|
|
386
|
+
const body = await this.safeParseJson(response);
|
|
387
|
+
if (response.status === 429) {
|
|
388
|
+
const retryAfter = this.parseRetryAfter(response.headers);
|
|
389
|
+
this.invokeRateLimitedCallback(retryAfter);
|
|
390
|
+
throw parseErrorResponse(
|
|
391
|
+
response.status,
|
|
392
|
+
body,
|
|
393
|
+
`GraphQL request failed with status ${response.status}`
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
throw parseErrorResponse(
|
|
397
|
+
response.status,
|
|
398
|
+
body,
|
|
399
|
+
`GraphQL request failed with status ${response.status}`
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
const json = await response.json();
|
|
403
|
+
if (json.errors && json.errors.length > 0) {
|
|
404
|
+
throw this.parseGraphQLErrors(json.errors);
|
|
405
|
+
}
|
|
406
|
+
if (json.data === void 0) {
|
|
407
|
+
throw new FirefliesError("GraphQL response missing data field");
|
|
408
|
+
}
|
|
409
|
+
return json.data;
|
|
410
|
+
} catch (error) {
|
|
411
|
+
clearTimeout(timeoutId);
|
|
412
|
+
if (error instanceof FirefliesError) {
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
415
|
+
if (error instanceof Error) {
|
|
416
|
+
if (error.name === "AbortError") {
|
|
417
|
+
throw new TimeoutError(`Request timed out after ${this.timeout}ms`);
|
|
418
|
+
}
|
|
419
|
+
throw new NetworkError(`Network request failed: ${error.message}`, error);
|
|
420
|
+
}
|
|
421
|
+
throw new NetworkError("Unknown network error occurred", error);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
async safeParseJson(response) {
|
|
425
|
+
try {
|
|
426
|
+
return await response.json();
|
|
427
|
+
} catch {
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Apply throttle delay before request if configured.
|
|
433
|
+
*/
|
|
434
|
+
async applyThrottleDelay() {
|
|
435
|
+
if (!this.rateLimitTracker || !this.rateLimitConfig?.throttle) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const delay = this.rateLimitTracker.getThrottleDelay(this.rateLimitConfig.throttle);
|
|
439
|
+
if (delay > 0) {
|
|
440
|
+
await sleep2(delay);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Update rate limit state from response headers and invoke callbacks.
|
|
445
|
+
*/
|
|
446
|
+
updateRateLimitState(headers) {
|
|
447
|
+
if (!this.rateLimitTracker || !this.rateLimitConfig) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const wasLow = this.rateLimitTracker.isLow;
|
|
451
|
+
this.rateLimitTracker.update(headers);
|
|
452
|
+
const state = this.rateLimitTracker.state;
|
|
453
|
+
this.safeCallback(() => this.rateLimitConfig?.onUpdate?.(state));
|
|
454
|
+
if (this.rateLimitTracker.isLow) {
|
|
455
|
+
const shouldWarn = !wasLow || // Just crossed threshold
|
|
456
|
+
state.remaining !== void 0 && this.lastWarningRemaining !== void 0 && state.remaining < this.lastWarningRemaining;
|
|
457
|
+
if (shouldWarn) {
|
|
458
|
+
this.lastWarningRemaining = state.remaining;
|
|
459
|
+
this.safeCallback(() => this.rateLimitConfig?.onWarning?.(state));
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Parse Retry-After header value.
|
|
465
|
+
*/
|
|
466
|
+
parseRetryAfter(headers) {
|
|
467
|
+
const value = headers.get("retry-after");
|
|
468
|
+
if (!value) return void 0;
|
|
469
|
+
const parsed = Number.parseInt(value, 10);
|
|
470
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Invoke the onRateLimited callback.
|
|
474
|
+
*/
|
|
475
|
+
invokeRateLimitedCallback(retryAfter) {
|
|
476
|
+
if (!this.rateLimitTracker || !this.rateLimitConfig?.onRateLimited) {
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
const state = this.rateLimitTracker.state;
|
|
480
|
+
this.safeCallback(() => this.rateLimitConfig?.onRateLimited?.(state, retryAfter));
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Safely invoke a callback, catching any errors to prevent user code from breaking the SDK.
|
|
484
|
+
*/
|
|
485
|
+
safeCallback(fn) {
|
|
486
|
+
try {
|
|
487
|
+
fn();
|
|
488
|
+
} catch {
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
parseGraphQLErrors(errors) {
|
|
492
|
+
const firstError = errors[0];
|
|
493
|
+
if (!firstError) {
|
|
494
|
+
return new GraphQLError("Unknown GraphQL error", errors);
|
|
495
|
+
}
|
|
496
|
+
const message = firstError.message;
|
|
497
|
+
if (message.toLowerCase().includes("unauthorized") || message.toLowerCase().includes("authentication")) {
|
|
498
|
+
return parseErrorResponse(401, { message }, message);
|
|
499
|
+
}
|
|
500
|
+
if (message.toLowerCase().includes("not found")) {
|
|
501
|
+
return parseErrorResponse(404, { message }, message);
|
|
502
|
+
}
|
|
503
|
+
return new GraphQLError(message, errors);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
function buildRetryOptions(config) {
|
|
507
|
+
if (!config) {
|
|
508
|
+
return {};
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
maxRetries: config.maxRetries,
|
|
512
|
+
baseDelay: config.baseDelay,
|
|
513
|
+
maxDelay: config.maxDelay
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function sleep2(ms) {
|
|
517
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// src/graphql/mutations/audio.ts
|
|
521
|
+
function createAudioAPI(client) {
|
|
522
|
+
return {
|
|
523
|
+
async upload(params) {
|
|
524
|
+
const mutation = `
|
|
525
|
+
mutation UploadAudio($input: AudioUploadInput!) {
|
|
526
|
+
uploadAudio(input: $input) {
|
|
527
|
+
success
|
|
528
|
+
title
|
|
529
|
+
message
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
`;
|
|
533
|
+
const data = await client.execute(mutation, {
|
|
534
|
+
input: params
|
|
535
|
+
});
|
|
536
|
+
return data.uploadAudio;
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/graphql/mutations/transcripts.ts
|
|
542
|
+
function createTranscriptsMutationsAPI(client) {
|
|
543
|
+
return {
|
|
544
|
+
async delete(id) {
|
|
545
|
+
const mutation = `
|
|
546
|
+
mutation deleteTranscript($id: String!) {
|
|
547
|
+
deleteTranscript(id: $id) {
|
|
548
|
+
id
|
|
549
|
+
title
|
|
550
|
+
organizer_email
|
|
551
|
+
date
|
|
552
|
+
duration
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
`;
|
|
556
|
+
const data = await client.execute(mutation, { id });
|
|
557
|
+
return data.deleteTranscript;
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// src/graphql/mutations/users.ts
|
|
563
|
+
function createUsersMutationsAPI(client) {
|
|
564
|
+
return {
|
|
565
|
+
async setRole(userId, role) {
|
|
566
|
+
const mutation = `
|
|
567
|
+
mutation setUserRole($userId: String!, $role: Role!) {
|
|
568
|
+
setUserRole(user_id: $userId, role: $role) {
|
|
569
|
+
id
|
|
570
|
+
name
|
|
571
|
+
email
|
|
572
|
+
role
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
`;
|
|
576
|
+
const data = await client.execute(mutation, {
|
|
577
|
+
userId,
|
|
578
|
+
role
|
|
579
|
+
});
|
|
580
|
+
return data.setUserRole;
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// src/helpers/pagination.ts
|
|
586
|
+
async function* paginate(fetcher, pageSize = 50) {
|
|
587
|
+
let skip = 0;
|
|
588
|
+
let hasMore = true;
|
|
589
|
+
while (hasMore) {
|
|
590
|
+
const page = await fetcher(skip, pageSize);
|
|
591
|
+
for (const item of page) {
|
|
592
|
+
yield item;
|
|
593
|
+
}
|
|
594
|
+
if (page.length < pageSize) {
|
|
595
|
+
hasMore = false;
|
|
596
|
+
} else {
|
|
597
|
+
skip += pageSize;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// src/graphql/queries/ai-apps.ts
|
|
603
|
+
var AI_APP_OUTPUT_FIELDS = `
|
|
604
|
+
transcript_id
|
|
605
|
+
user_id
|
|
606
|
+
app_id
|
|
607
|
+
created_at
|
|
608
|
+
title
|
|
609
|
+
prompt
|
|
610
|
+
response
|
|
611
|
+
`;
|
|
612
|
+
function createAIAppsAPI(client) {
|
|
613
|
+
return {
|
|
614
|
+
async list(params) {
|
|
615
|
+
const query = `
|
|
616
|
+
query GetAIAppsOutputs(
|
|
617
|
+
$appId: String
|
|
618
|
+
$transcriptId: String
|
|
619
|
+
$skip: Float
|
|
620
|
+
$limit: Float
|
|
621
|
+
) {
|
|
622
|
+
apps(
|
|
623
|
+
app_id: $appId
|
|
624
|
+
transcript_id: $transcriptId
|
|
625
|
+
skip: $skip
|
|
626
|
+
limit: $limit
|
|
627
|
+
) {
|
|
628
|
+
outputs { ${AI_APP_OUTPUT_FIELDS} }
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
`;
|
|
632
|
+
const data = await client.execute(query, {
|
|
633
|
+
appId: params?.app_id,
|
|
634
|
+
transcriptId: params?.transcript_id,
|
|
635
|
+
skip: params?.skip,
|
|
636
|
+
limit: params?.limit ?? 10
|
|
637
|
+
});
|
|
638
|
+
return data.apps.outputs;
|
|
639
|
+
},
|
|
640
|
+
listAll(params) {
|
|
641
|
+
return paginate((skip, limit) => this.list({ ...params, skip, limit }), 10);
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// src/graphql/queries/bites.ts
|
|
647
|
+
var BITE_FIELDS = `
|
|
648
|
+
id
|
|
649
|
+
transcript_id
|
|
650
|
+
user_id
|
|
651
|
+
name
|
|
652
|
+
status
|
|
653
|
+
summary
|
|
654
|
+
summary_status
|
|
655
|
+
media_type
|
|
656
|
+
start_time
|
|
657
|
+
end_time
|
|
658
|
+
created_at
|
|
659
|
+
thumbnail
|
|
660
|
+
preview
|
|
661
|
+
captions {
|
|
662
|
+
index
|
|
663
|
+
text
|
|
664
|
+
start_time
|
|
665
|
+
end_time
|
|
666
|
+
speaker_id
|
|
667
|
+
speaker_name
|
|
668
|
+
}
|
|
669
|
+
sources {
|
|
670
|
+
src
|
|
671
|
+
type
|
|
672
|
+
}
|
|
673
|
+
user {
|
|
674
|
+
id
|
|
675
|
+
name
|
|
676
|
+
first_name
|
|
677
|
+
last_name
|
|
678
|
+
picture
|
|
679
|
+
}
|
|
680
|
+
created_from {
|
|
681
|
+
id
|
|
682
|
+
name
|
|
683
|
+
type
|
|
684
|
+
description
|
|
685
|
+
duration
|
|
686
|
+
}
|
|
687
|
+
privacies
|
|
688
|
+
`;
|
|
689
|
+
function createBitesAPI(client) {
|
|
690
|
+
return {
|
|
691
|
+
async get(id) {
|
|
692
|
+
const query = `
|
|
693
|
+
query Bite($biteId: ID!) {
|
|
694
|
+
bite(id: $biteId) { ${BITE_FIELDS} }
|
|
695
|
+
}
|
|
696
|
+
`;
|
|
697
|
+
const data = await client.execute(query, { biteId: id });
|
|
698
|
+
return data.bite;
|
|
699
|
+
},
|
|
700
|
+
async list(params) {
|
|
701
|
+
const query = `
|
|
702
|
+
query Bites(
|
|
703
|
+
$transcriptId: ID
|
|
704
|
+
$mine: Boolean
|
|
705
|
+
$myTeam: Boolean
|
|
706
|
+
$limit: Int
|
|
707
|
+
$skip: Int
|
|
708
|
+
) {
|
|
709
|
+
bites(
|
|
710
|
+
transcript_id: $transcriptId
|
|
711
|
+
mine: $mine
|
|
712
|
+
my_team: $myTeam
|
|
713
|
+
limit: $limit
|
|
714
|
+
skip: $skip
|
|
715
|
+
) { ${BITE_FIELDS} }
|
|
716
|
+
}
|
|
717
|
+
`;
|
|
718
|
+
const data = await client.execute(query, {
|
|
719
|
+
transcriptId: params.transcript_id,
|
|
720
|
+
mine: params.mine,
|
|
721
|
+
myTeam: params.my_team,
|
|
722
|
+
limit: params.limit ?? 50,
|
|
723
|
+
skip: params.skip
|
|
724
|
+
});
|
|
725
|
+
return data.bites;
|
|
726
|
+
},
|
|
727
|
+
listAll(params) {
|
|
728
|
+
return paginate((skip, limit) => this.list({ ...params, skip, limit }), 50);
|
|
729
|
+
},
|
|
730
|
+
async create(params) {
|
|
731
|
+
const mutation = `
|
|
732
|
+
mutation CreateBite(
|
|
733
|
+
$transcriptId: ID!
|
|
734
|
+
$startTime: Float!
|
|
735
|
+
$endTime: Float!
|
|
736
|
+
$name: String
|
|
737
|
+
$mediaType: String
|
|
738
|
+
$summary: String
|
|
739
|
+
$privacies: [BitePrivacy!]
|
|
740
|
+
) {
|
|
741
|
+
createBite(
|
|
742
|
+
transcript_Id: $transcriptId
|
|
743
|
+
start_time: $startTime
|
|
744
|
+
end_time: $endTime
|
|
745
|
+
name: $name
|
|
746
|
+
media_type: $mediaType
|
|
747
|
+
summary: $summary
|
|
748
|
+
privacies: $privacies
|
|
749
|
+
) {
|
|
750
|
+
id
|
|
751
|
+
name
|
|
752
|
+
status
|
|
753
|
+
summary
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
`;
|
|
757
|
+
const data = await client.execute(mutation, {
|
|
758
|
+
transcriptId: params.transcript_id,
|
|
759
|
+
startTime: params.start_time,
|
|
760
|
+
endTime: params.end_time,
|
|
761
|
+
name: params.name,
|
|
762
|
+
mediaType: params.media_type,
|
|
763
|
+
summary: params.summary,
|
|
764
|
+
privacies: params.privacies
|
|
765
|
+
});
|
|
766
|
+
return data.createBite;
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// src/graphql/queries/meetings.ts
|
|
772
|
+
var ACTIVE_MEETING_FIELDS = `
|
|
773
|
+
id
|
|
774
|
+
title
|
|
775
|
+
organizer_email
|
|
776
|
+
meeting_link
|
|
777
|
+
start_time
|
|
778
|
+
end_time
|
|
779
|
+
privacy
|
|
780
|
+
state
|
|
781
|
+
`;
|
|
782
|
+
function createMeetingsAPI(client) {
|
|
783
|
+
return {
|
|
784
|
+
async active(params) {
|
|
785
|
+
const query = `
|
|
786
|
+
query ActiveMeetings($email: String, $states: [MeetingState!]) {
|
|
787
|
+
active_meetings(input: { email: $email, states: $states }) {
|
|
788
|
+
${ACTIVE_MEETING_FIELDS}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
`;
|
|
792
|
+
const data = await client.execute(query, {
|
|
793
|
+
email: params?.email,
|
|
794
|
+
states: params?.states
|
|
795
|
+
});
|
|
796
|
+
return data.active_meetings;
|
|
797
|
+
},
|
|
798
|
+
async addBot(params) {
|
|
799
|
+
const mutation = `
|
|
800
|
+
mutation AddToLiveMeeting(
|
|
801
|
+
$meetingLink: String!
|
|
802
|
+
$title: String
|
|
803
|
+
$meetingPassword: String
|
|
804
|
+
$duration: Int
|
|
805
|
+
$language: String
|
|
806
|
+
) {
|
|
807
|
+
addToLiveMeeting(
|
|
808
|
+
meeting_link: $meetingLink
|
|
809
|
+
title: $title
|
|
810
|
+
meeting_password: $meetingPassword
|
|
811
|
+
duration: $duration
|
|
812
|
+
language: $language
|
|
813
|
+
) {
|
|
814
|
+
success
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
`;
|
|
818
|
+
const data = await client.execute(mutation, {
|
|
819
|
+
meetingLink: params.meeting_link,
|
|
820
|
+
title: params.title,
|
|
821
|
+
meetingPassword: params.password,
|
|
822
|
+
duration: params.duration,
|
|
823
|
+
language: params.language
|
|
824
|
+
});
|
|
825
|
+
return data.addToLiveMeeting;
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// src/helpers/action-items.ts
|
|
831
|
+
var ASSIGNEE_PATTERNS = [
|
|
832
|
+
{ pattern: /@(\w+)/i, group: 1 },
|
|
833
|
+
// @Alice
|
|
834
|
+
{ pattern: /^(\w+):/i, group: 1 },
|
|
835
|
+
// Alice: at start
|
|
836
|
+
{ pattern: /assigned to (\w+)/i, group: 1 },
|
|
837
|
+
// assigned to Alice
|
|
838
|
+
{ pattern: /(\w+) will\b/i, group: 1 },
|
|
839
|
+
// Alice will
|
|
840
|
+
{ pattern: /(\w+) to\b/i, group: 1 },
|
|
841
|
+
// Alice to (do something)
|
|
842
|
+
{ pattern: /\s-\s*(\w+)$/i, group: 1 }
|
|
843
|
+
// ... - Alice
|
|
844
|
+
];
|
|
845
|
+
var DUE_DATE_PATTERNS = [
|
|
846
|
+
{ pattern: /by (monday|tuesday|wednesday|thursday|friday|saturday|sunday)/i, group: 1 },
|
|
847
|
+
{ pattern: /by (tomorrow|today)/i, group: 1 },
|
|
848
|
+
{ pattern: /by (EOD|end of day)/i, group: 1 },
|
|
849
|
+
{ pattern: /by (EOW|end of week)/i, group: 1 },
|
|
850
|
+
{ pattern: /due (\d{4}-\d{2}-\d{2})/i, group: 1 },
|
|
851
|
+
{ pattern: /due (jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+\d+/i, group: 0 },
|
|
852
|
+
{ pattern: /by (\d{1,2}\/\d{1,2})/i, group: 1 }
|
|
853
|
+
];
|
|
854
|
+
var LIST_PREFIX_PATTERN = /^(?:[-•*]|\d+\.)\s*/;
|
|
855
|
+
var SECTION_HEADER_PATTERN = /^\*\*(.+)\*\*$/;
|
|
856
|
+
function extractActionItems(transcript, options = {}) {
|
|
857
|
+
const actionItemsText = transcript.summary?.action_items;
|
|
858
|
+
if (!actionItemsText || actionItemsText.trim().length === 0) {
|
|
859
|
+
return emptyResult();
|
|
860
|
+
}
|
|
861
|
+
const config = {
|
|
862
|
+
detectAssignees: options.detectAssignees ?? true,
|
|
863
|
+
detectDueDates: options.detectDueDates ?? true,
|
|
864
|
+
includeSourceSentences: options.includeSourceSentences ?? false,
|
|
865
|
+
participantNames: options.participantNames ?? []
|
|
866
|
+
};
|
|
867
|
+
const taskSentences = config.includeSourceSentences ? buildTaskSentenceLookup(transcript) : [];
|
|
868
|
+
const lines = actionItemsText.split(/\n/);
|
|
869
|
+
return parseAllLines(lines, config, taskSentences);
|
|
870
|
+
}
|
|
871
|
+
function parseAllLines(lines, config, taskSentences) {
|
|
872
|
+
const items = [];
|
|
873
|
+
const assigneeSet = /* @__PURE__ */ new Set();
|
|
874
|
+
let currentSectionAssignee;
|
|
875
|
+
for (let i = 0; i < lines.length; i++) {
|
|
876
|
+
const result = processLine(lines[i], i + 1, config, taskSentences, currentSectionAssignee);
|
|
877
|
+
if (result.type === "header") {
|
|
878
|
+
currentSectionAssignee = result.assignee;
|
|
879
|
+
} else if (result.type === "item" && result.item) {
|
|
880
|
+
items.push(result.item);
|
|
881
|
+
if (result.item.assignee) {
|
|
882
|
+
assigneeSet.add(result.item.assignee);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return buildResult(items, assigneeSet);
|
|
887
|
+
}
|
|
888
|
+
function processLine(line, lineNumber, config, taskSentences, sectionAssignee) {
|
|
889
|
+
if (!line) return { type: "skip" };
|
|
890
|
+
const trimmed = line.trim();
|
|
891
|
+
if (trimmed.length === 0) return { type: "skip" };
|
|
892
|
+
const headerMatch = trimmed.match(SECTION_HEADER_PATTERN);
|
|
893
|
+
if (headerMatch?.[1]) {
|
|
894
|
+
const headerName = headerMatch[1];
|
|
895
|
+
const assignee = headerName.toLowerCase() === "unassigned" ? void 0 : headerName;
|
|
896
|
+
return { type: "header", assignee };
|
|
897
|
+
}
|
|
898
|
+
const item = parseLine(line, lineNumber, config, taskSentences, sectionAssignee);
|
|
899
|
+
if (item) {
|
|
900
|
+
return { type: "item", item };
|
|
901
|
+
}
|
|
902
|
+
return { type: "skip" };
|
|
903
|
+
}
|
|
904
|
+
function parseLine(line, lineNumber, config, taskSentences, sectionAssignee) {
|
|
905
|
+
if (!line) return null;
|
|
906
|
+
const trimmed = line.trim();
|
|
907
|
+
if (trimmed.length === 0) return null;
|
|
908
|
+
const text = trimmed.replace(LIST_PREFIX_PATTERN, "");
|
|
909
|
+
if (text.length === 0) return null;
|
|
910
|
+
const inlineAssignee = config.detectAssignees ? detectAssignee(text, config.participantNames) : void 0;
|
|
911
|
+
const assignee = inlineAssignee ?? sectionAssignee;
|
|
912
|
+
const dueDate = config.detectDueDates ? detectDueDate(text) : void 0;
|
|
913
|
+
const sourceSentence = config.includeSourceSentences ? findSourceSentence(text, taskSentences) : void 0;
|
|
914
|
+
return { text, assignee, dueDate, lineNumber, sourceSentence };
|
|
915
|
+
}
|
|
916
|
+
function buildResult(items, assigneeSet) {
|
|
917
|
+
return {
|
|
918
|
+
items,
|
|
919
|
+
totalItems: items.length,
|
|
920
|
+
assignedItems: items.filter((i) => i.assignee !== void 0).length,
|
|
921
|
+
datedItems: items.filter((i) => i.dueDate !== void 0).length,
|
|
922
|
+
assignees: Array.from(assigneeSet)
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
function emptyResult() {
|
|
926
|
+
return {
|
|
927
|
+
items: [],
|
|
928
|
+
totalItems: 0,
|
|
929
|
+
assignedItems: 0,
|
|
930
|
+
datedItems: 0,
|
|
931
|
+
assignees: []
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
function detectAssignee(text, participantNames) {
|
|
935
|
+
const participantSet = new Set(participantNames.map((n) => n.toLowerCase()));
|
|
936
|
+
const filterByParticipants = participantSet.size > 0;
|
|
937
|
+
for (const { pattern, group } of ASSIGNEE_PATTERNS) {
|
|
938
|
+
const match = text.match(pattern);
|
|
939
|
+
if (match?.[group]) {
|
|
940
|
+
const name = match[group];
|
|
941
|
+
if (filterByParticipants) {
|
|
942
|
+
if (participantSet.has(name.toLowerCase())) {
|
|
943
|
+
return name;
|
|
944
|
+
}
|
|
945
|
+
continue;
|
|
946
|
+
}
|
|
947
|
+
return name;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
return void 0;
|
|
951
|
+
}
|
|
952
|
+
function detectDueDate(text) {
|
|
953
|
+
for (const { pattern, group } of DUE_DATE_PATTERNS) {
|
|
954
|
+
const match = text.match(pattern);
|
|
955
|
+
if (match) {
|
|
956
|
+
if (group === 0 && match[0]) {
|
|
957
|
+
const fullMatch = match[0];
|
|
958
|
+
const dateMatch = fullMatch.match(
|
|
959
|
+
/(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+\d+/i
|
|
960
|
+
);
|
|
961
|
+
if (dateMatch?.[0]) {
|
|
962
|
+
return dateMatch[0];
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
if (match[group]) {
|
|
966
|
+
return match[group];
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return void 0;
|
|
971
|
+
}
|
|
972
|
+
function buildTaskSentenceLookup(transcript) {
|
|
973
|
+
const sentences = transcript.sentences ?? [];
|
|
974
|
+
const result = [];
|
|
975
|
+
for (const sentence of sentences) {
|
|
976
|
+
const task = sentence.ai_filters?.task;
|
|
977
|
+
if (task) {
|
|
978
|
+
result.push({
|
|
979
|
+
text: sentence.text,
|
|
980
|
+
task: task.toLowerCase(),
|
|
981
|
+
speakerName: sentence.speaker_name,
|
|
982
|
+
startTime: Number.parseFloat(sentence.start_time)
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
return result;
|
|
987
|
+
}
|
|
988
|
+
function findSourceSentence(actionItemText, taskSentences) {
|
|
989
|
+
const normalizedItem = actionItemText.toLowerCase();
|
|
990
|
+
for (const sentence of taskSentences) {
|
|
991
|
+
if (normalizedItem.includes(sentence.task) || sentence.task.includes(normalizedItem)) {
|
|
992
|
+
return {
|
|
993
|
+
speakerName: sentence.speakerName,
|
|
994
|
+
text: sentence.text,
|
|
995
|
+
startTime: sentence.startTime
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
const itemWords = new Set(normalizedItem.split(/\s+/).filter((w) => w.length > 3));
|
|
999
|
+
const taskWords = sentence.task.split(/\s+/).filter((w) => w.length > 3);
|
|
1000
|
+
const matchingWords = taskWords.filter((w) => itemWords.has(w));
|
|
1001
|
+
if (taskWords.length > 0 && matchingWords.length / taskWords.length >= 0.5) {
|
|
1002
|
+
return {
|
|
1003
|
+
speakerName: sentence.speakerName,
|
|
1004
|
+
text: sentence.text,
|
|
1005
|
+
startTime: sentence.startTime
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
return void 0;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// src/helpers/action-items-format.ts
|
|
1013
|
+
function filterActionItems(items, options) {
|
|
1014
|
+
const { assignees, assignedOnly, datedOnly } = options;
|
|
1015
|
+
const normalizedAssignees = assignees?.map((a) => a.toLowerCase());
|
|
1016
|
+
return items.filter((item) => {
|
|
1017
|
+
if (normalizedAssignees && normalizedAssignees.length > 0) {
|
|
1018
|
+
if (!item.assignee) return false;
|
|
1019
|
+
if (!normalizedAssignees.includes(item.assignee.toLowerCase())) return false;
|
|
1020
|
+
}
|
|
1021
|
+
if (assignedOnly && !item.assignee) {
|
|
1022
|
+
return false;
|
|
1023
|
+
}
|
|
1024
|
+
if (datedOnly && !item.dueDate) {
|
|
1025
|
+
return false;
|
|
1026
|
+
}
|
|
1027
|
+
return true;
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
function aggregateActionItems(transcripts, extractionOptions, filterOptions) {
|
|
1031
|
+
if (transcripts.length === 0) {
|
|
1032
|
+
return emptyAggregatedResult();
|
|
1033
|
+
}
|
|
1034
|
+
const allItems = [];
|
|
1035
|
+
let transcriptsWithItems = 0;
|
|
1036
|
+
for (const transcript of transcripts) {
|
|
1037
|
+
const extracted = extractActionItems(transcript, extractionOptions);
|
|
1038
|
+
if (extracted.items.length > 0) {
|
|
1039
|
+
transcriptsWithItems++;
|
|
1040
|
+
for (const item of extracted.items) {
|
|
1041
|
+
allItems.push({
|
|
1042
|
+
...item,
|
|
1043
|
+
transcriptId: transcript.id,
|
|
1044
|
+
transcriptTitle: transcript.title,
|
|
1045
|
+
transcriptDate: transcript.dateString
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
const filteredItems = filterOptions ? filterActionItems(allItems, filterOptions) : allItems;
|
|
1051
|
+
return buildAggregatedResult(filteredItems, transcripts.length, transcriptsWithItems);
|
|
1052
|
+
}
|
|
1053
|
+
function emptyAggregatedResult() {
|
|
1054
|
+
return {
|
|
1055
|
+
items: [],
|
|
1056
|
+
totalItems: 0,
|
|
1057
|
+
transcriptsProcessed: 0,
|
|
1058
|
+
transcriptsWithItems: 0,
|
|
1059
|
+
assignedItems: 0,
|
|
1060
|
+
datedItems: 0,
|
|
1061
|
+
assignees: [],
|
|
1062
|
+
dateRange: { earliest: "", latest: "" }
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
function buildAggregatedResult(items, transcriptsProcessed, transcriptsWithItems) {
|
|
1066
|
+
const assigneeSet = /* @__PURE__ */ new Set();
|
|
1067
|
+
let assignedItems = 0;
|
|
1068
|
+
let datedItems = 0;
|
|
1069
|
+
for (const item of items) {
|
|
1070
|
+
if (item.assignee) {
|
|
1071
|
+
assigneeSet.add(item.assignee);
|
|
1072
|
+
assignedItems++;
|
|
1073
|
+
}
|
|
1074
|
+
if (item.dueDate) {
|
|
1075
|
+
datedItems++;
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
const dates = items.map((i) => i.transcriptDate).filter(Boolean).sort();
|
|
1079
|
+
return {
|
|
1080
|
+
items,
|
|
1081
|
+
totalItems: items.length,
|
|
1082
|
+
transcriptsProcessed,
|
|
1083
|
+
transcriptsWithItems,
|
|
1084
|
+
assignedItems,
|
|
1085
|
+
datedItems,
|
|
1086
|
+
assignees: Array.from(assigneeSet),
|
|
1087
|
+
dateRange: {
|
|
1088
|
+
earliest: dates[0] ?? "",
|
|
1089
|
+
latest: dates[dates.length - 1] ?? ""
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
function isAggregatedResult(result) {
|
|
1094
|
+
return "transcriptsProcessed" in result;
|
|
1095
|
+
}
|
|
1096
|
+
function isAggregatedItem(item) {
|
|
1097
|
+
return "transcriptId" in item;
|
|
1098
|
+
}
|
|
1099
|
+
function escapeMarkdown(text) {
|
|
1100
|
+
return text.replace(/\\/g, "\\\\").replace(/\*/g, "\\*").replace(/#/g, "\\#").replace(/\[/g, "\\[").replace(/\]/g, "\\]").replace(/_/g, "\\_").replace(/`/g, "\\`");
|
|
1101
|
+
}
|
|
1102
|
+
function getPresetOptions(preset) {
|
|
1103
|
+
switch (preset) {
|
|
1104
|
+
case "notion":
|
|
1105
|
+
return {
|
|
1106
|
+
style: "checkbox",
|
|
1107
|
+
includeAssignee: true,
|
|
1108
|
+
includeDueDate: true
|
|
1109
|
+
};
|
|
1110
|
+
case "obsidian":
|
|
1111
|
+
return {
|
|
1112
|
+
style: "checkbox",
|
|
1113
|
+
includeAssignee: false,
|
|
1114
|
+
includeDueDate: true
|
|
1115
|
+
};
|
|
1116
|
+
case "github":
|
|
1117
|
+
return {
|
|
1118
|
+
style: "checkbox",
|
|
1119
|
+
includeAssignee: true,
|
|
1120
|
+
includeDueDate: true
|
|
1121
|
+
};
|
|
1122
|
+
default:
|
|
1123
|
+
return {};
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
function formatItem(item, index, options) {
|
|
1127
|
+
const { style, includeAssignee, includeDueDate, includeMeetingTitle } = options;
|
|
1128
|
+
let prefix;
|
|
1129
|
+
switch (style) {
|
|
1130
|
+
case "bullet":
|
|
1131
|
+
prefix = "-";
|
|
1132
|
+
break;
|
|
1133
|
+
case "numbered":
|
|
1134
|
+
prefix = `${index + 1}.`;
|
|
1135
|
+
break;
|
|
1136
|
+
default:
|
|
1137
|
+
prefix = "- [ ]";
|
|
1138
|
+
break;
|
|
1139
|
+
}
|
|
1140
|
+
let text = escapeMarkdown(item.text);
|
|
1141
|
+
const metadata = [];
|
|
1142
|
+
if (includeAssignee && item.assignee) {
|
|
1143
|
+
metadata.push(`@${item.assignee}`);
|
|
1144
|
+
}
|
|
1145
|
+
if (includeDueDate && item.dueDate) {
|
|
1146
|
+
metadata.push(`due: ${item.dueDate}`);
|
|
1147
|
+
}
|
|
1148
|
+
if (includeMeetingTitle && isAggregatedItem(item)) {
|
|
1149
|
+
metadata.push(`*${item.transcriptTitle}*`);
|
|
1150
|
+
}
|
|
1151
|
+
if (metadata.length > 0) {
|
|
1152
|
+
text += ` (${metadata.join(", ")})`;
|
|
1153
|
+
}
|
|
1154
|
+
return `${prefix} ${text}`;
|
|
1155
|
+
}
|
|
1156
|
+
function groupBy(items, keyFn) {
|
|
1157
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1158
|
+
for (const item of items) {
|
|
1159
|
+
const key = keyFn(item);
|
|
1160
|
+
const group = groups.get(key);
|
|
1161
|
+
if (group) {
|
|
1162
|
+
group.push(item);
|
|
1163
|
+
} else {
|
|
1164
|
+
groups.set(key, [item]);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
return groups;
|
|
1168
|
+
}
|
|
1169
|
+
function formatSummaryLine(result) {
|
|
1170
|
+
return `**Summary:** ${result.totalItems} items from ${result.transcriptsProcessed} meetings (${result.assignedItems} assigned, ${result.datedItems} with due dates)`;
|
|
1171
|
+
}
|
|
1172
|
+
function sortGroupKeys(keys) {
|
|
1173
|
+
return keys.sort((a, b) => {
|
|
1174
|
+
if (a === "Unassigned") return 1;
|
|
1175
|
+
if (b === "Unassigned") return -1;
|
|
1176
|
+
return a.localeCompare(b);
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
function formatGroupedItems(result, groupByOption, itemOptions) {
|
|
1180
|
+
const lines = [];
|
|
1181
|
+
const keyFn = getGroupKeyFn(groupByOption);
|
|
1182
|
+
const groups = groupBy(result.items, keyFn);
|
|
1183
|
+
const sortedKeys = sortGroupKeys(Array.from(groups.keys()));
|
|
1184
|
+
for (const key of sortedKeys) {
|
|
1185
|
+
const groupItems = groups.get(key);
|
|
1186
|
+
if (!groupItems) continue;
|
|
1187
|
+
lines.push(`### ${key}`);
|
|
1188
|
+
lines.push("");
|
|
1189
|
+
groupItems.forEach((item, index) => {
|
|
1190
|
+
lines.push(formatItem(item, index, itemOptions));
|
|
1191
|
+
});
|
|
1192
|
+
lines.push("");
|
|
1193
|
+
}
|
|
1194
|
+
return lines;
|
|
1195
|
+
}
|
|
1196
|
+
function formatFlatItems(items, itemOptions) {
|
|
1197
|
+
return items.map((item, index) => formatItem(item, index, itemOptions));
|
|
1198
|
+
}
|
|
1199
|
+
function formatActionItemsMarkdown(result, options = {}) {
|
|
1200
|
+
if (result.items.length === 0) {
|
|
1201
|
+
return "";
|
|
1202
|
+
}
|
|
1203
|
+
const presetOptions = getPresetOptions(options.preset);
|
|
1204
|
+
const mergedOptions = { ...presetOptions, ...options };
|
|
1205
|
+
const {
|
|
1206
|
+
style = "checkbox",
|
|
1207
|
+
groupBy: groupByOption = "none",
|
|
1208
|
+
includeAssignee = false,
|
|
1209
|
+
includeDueDate = false,
|
|
1210
|
+
includeMeetingTitle = false,
|
|
1211
|
+
includeSummary = false
|
|
1212
|
+
} = mergedOptions;
|
|
1213
|
+
const lines = [];
|
|
1214
|
+
if (includeSummary && isAggregatedResult(result)) {
|
|
1215
|
+
lines.push(formatSummaryLine(result));
|
|
1216
|
+
lines.push("");
|
|
1217
|
+
}
|
|
1218
|
+
const itemOptions = { style, includeAssignee, includeDueDate, includeMeetingTitle };
|
|
1219
|
+
const shouldGroup = groupByOption !== "none" && isAggregatedResult(result);
|
|
1220
|
+
if (shouldGroup) {
|
|
1221
|
+
lines.push(...formatGroupedItems(result, groupByOption, itemOptions));
|
|
1222
|
+
} else {
|
|
1223
|
+
lines.push(...formatFlatItems(result.items, itemOptions));
|
|
1224
|
+
}
|
|
1225
|
+
return lines.join("\n").trim();
|
|
1226
|
+
}
|
|
1227
|
+
function getGroupKeyFn(groupBy2) {
|
|
1228
|
+
switch (groupBy2) {
|
|
1229
|
+
case "assignee":
|
|
1230
|
+
return (item) => item.assignee ?? "Unassigned";
|
|
1231
|
+
case "transcript":
|
|
1232
|
+
return (item) => item.transcriptTitle;
|
|
1233
|
+
case "date":
|
|
1234
|
+
return (item) => item.transcriptDate;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// src/helpers/domain-utils.ts
|
|
1239
|
+
function extractDomain(email) {
|
|
1240
|
+
const atIndex = email.indexOf("@");
|
|
1241
|
+
if (atIndex < 0) return "";
|
|
1242
|
+
const domain = email.slice(atIndex + 1).toLowerCase();
|
|
1243
|
+
return domain || "";
|
|
1244
|
+
}
|
|
1245
|
+
function hasExternalParticipants(participants, internalDomain) {
|
|
1246
|
+
const normalizedInternal = internalDomain.toLowerCase();
|
|
1247
|
+
return participants.some((email) => {
|
|
1248
|
+
const domain = extractDomain(email);
|
|
1249
|
+
return domain !== "" && domain !== normalizedInternal;
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// src/helpers/meeting-insights.ts
|
|
1254
|
+
function analyzeMeetings(transcripts, options = {}) {
|
|
1255
|
+
const { speakers, groupBy: groupBy2, topSpeakersCount = 10, topParticipantsCount = 10 } = options;
|
|
1256
|
+
if (transcripts.length === 0) {
|
|
1257
|
+
return emptyInsights();
|
|
1258
|
+
}
|
|
1259
|
+
const totalDurationMinutes = sumDurations(transcripts);
|
|
1260
|
+
const averageDurationMinutes = totalDurationMinutes / transcripts.length;
|
|
1261
|
+
const byDayOfWeek = calculateDayOfWeekStats(transcripts);
|
|
1262
|
+
const byTimeGroup = groupBy2 ? calculateTimeGroupStats(transcripts, groupBy2) : void 0;
|
|
1263
|
+
const participantData = aggregateParticipants(transcripts);
|
|
1264
|
+
const totalUniqueParticipants = participantData.uniqueEmails.size;
|
|
1265
|
+
const averageParticipantsPerMeeting = calculateAverageParticipants(transcripts);
|
|
1266
|
+
const topParticipants = buildTopParticipants(participantData.stats, topParticipantsCount);
|
|
1267
|
+
const speakerData = aggregateSpeakers(transcripts, speakers);
|
|
1268
|
+
const totalUniqueSpeakers = speakerData.uniqueNames.size;
|
|
1269
|
+
const topSpeakers = buildTopSpeakers(speakerData.stats, topSpeakersCount);
|
|
1270
|
+
const { earliestMeeting, latestMeeting } = findDateRange(transcripts);
|
|
1271
|
+
return {
|
|
1272
|
+
totalMeetings: transcripts.length,
|
|
1273
|
+
totalDurationMinutes,
|
|
1274
|
+
averageDurationMinutes,
|
|
1275
|
+
byDayOfWeek,
|
|
1276
|
+
byTimeGroup,
|
|
1277
|
+
totalUniqueParticipants,
|
|
1278
|
+
averageParticipantsPerMeeting,
|
|
1279
|
+
topParticipants,
|
|
1280
|
+
totalUniqueSpeakers,
|
|
1281
|
+
topSpeakers,
|
|
1282
|
+
earliestMeeting,
|
|
1283
|
+
latestMeeting
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
function emptyInsights() {
|
|
1287
|
+
return {
|
|
1288
|
+
totalMeetings: 0,
|
|
1289
|
+
totalDurationMinutes: 0,
|
|
1290
|
+
averageDurationMinutes: 0,
|
|
1291
|
+
byDayOfWeek: emptyDayOfWeekStats(),
|
|
1292
|
+
byTimeGroup: void 0,
|
|
1293
|
+
totalUniqueParticipants: 0,
|
|
1294
|
+
averageParticipantsPerMeeting: 0,
|
|
1295
|
+
topParticipants: [],
|
|
1296
|
+
totalUniqueSpeakers: 0,
|
|
1297
|
+
topSpeakers: [],
|
|
1298
|
+
earliestMeeting: "",
|
|
1299
|
+
latestMeeting: ""
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
function emptyDayOfWeekStats() {
|
|
1303
|
+
const emptyDay = () => ({ count: 0, totalMinutes: 0 });
|
|
1304
|
+
return {
|
|
1305
|
+
monday: emptyDay(),
|
|
1306
|
+
tuesday: emptyDay(),
|
|
1307
|
+
wednesday: emptyDay(),
|
|
1308
|
+
thursday: emptyDay(),
|
|
1309
|
+
friday: emptyDay(),
|
|
1310
|
+
saturday: emptyDay(),
|
|
1311
|
+
sunday: emptyDay()
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
function sumDurations(transcripts) {
|
|
1315
|
+
return transcripts.reduce((sum, t) => sum + (t.duration ?? 0), 0);
|
|
1316
|
+
}
|
|
1317
|
+
function calculateDayOfWeekStats(transcripts) {
|
|
1318
|
+
const stats = emptyDayOfWeekStats();
|
|
1319
|
+
const dayNames = [
|
|
1320
|
+
"sunday",
|
|
1321
|
+
"monday",
|
|
1322
|
+
"tuesday",
|
|
1323
|
+
"wednesday",
|
|
1324
|
+
"thursday",
|
|
1325
|
+
"friday",
|
|
1326
|
+
"saturday"
|
|
1327
|
+
];
|
|
1328
|
+
for (const t of transcripts) {
|
|
1329
|
+
const date = parseDate(t.dateString);
|
|
1330
|
+
if (!date) continue;
|
|
1331
|
+
const dayIndex = date.getUTCDay();
|
|
1332
|
+
const dayName = dayNames[dayIndex];
|
|
1333
|
+
if (dayName) {
|
|
1334
|
+
stats[dayName].count++;
|
|
1335
|
+
stats[dayName].totalMinutes += t.duration ?? 0;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
return stats;
|
|
1339
|
+
}
|
|
1340
|
+
function calculateTimeGroupStats(transcripts, groupBy2) {
|
|
1341
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1342
|
+
for (const t of transcripts) {
|
|
1343
|
+
const date = parseDate(t.dateString);
|
|
1344
|
+
if (!date) continue;
|
|
1345
|
+
const period = formatPeriod(date, groupBy2);
|
|
1346
|
+
const existing = groups.get(period) ?? { count: 0, totalMinutes: 0 };
|
|
1347
|
+
existing.count++;
|
|
1348
|
+
existing.totalMinutes += t.duration ?? 0;
|
|
1349
|
+
groups.set(period, existing);
|
|
1350
|
+
}
|
|
1351
|
+
const result = [];
|
|
1352
|
+
for (const [period, data] of groups) {
|
|
1353
|
+
result.push({
|
|
1354
|
+
period,
|
|
1355
|
+
count: data.count,
|
|
1356
|
+
totalMinutes: data.totalMinutes,
|
|
1357
|
+
averageMinutes: data.totalMinutes / data.count
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
result.sort((a, b) => a.period.localeCompare(b.period));
|
|
1361
|
+
return result;
|
|
1362
|
+
}
|
|
1363
|
+
function formatPeriod(date, groupBy2) {
|
|
1364
|
+
const year = date.getUTCFullYear();
|
|
1365
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
1366
|
+
const day = String(date.getUTCDate()).padStart(2, "0");
|
|
1367
|
+
switch (groupBy2) {
|
|
1368
|
+
case "day":
|
|
1369
|
+
return `${year}-${month}-${day}`;
|
|
1370
|
+
case "week":
|
|
1371
|
+
return getISOWeek(date);
|
|
1372
|
+
case "month":
|
|
1373
|
+
return `${year}-${month}`;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
function getISOWeek(date) {
|
|
1377
|
+
const d = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
|
1378
|
+
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
|
|
1379
|
+
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
|
1380
|
+
const weekNumber = Math.ceil(((d.getTime() - yearStart.getTime()) / 864e5 + 1) / 7);
|
|
1381
|
+
return `${d.getUTCFullYear()}-W${String(weekNumber).padStart(2, "0")}`;
|
|
1382
|
+
}
|
|
1383
|
+
function aggregateParticipants(transcripts) {
|
|
1384
|
+
const uniqueEmails = /* @__PURE__ */ new Set();
|
|
1385
|
+
const stats = /* @__PURE__ */ new Map();
|
|
1386
|
+
for (const t of transcripts) {
|
|
1387
|
+
const participants = t.participants ?? [];
|
|
1388
|
+
const seenInMeeting = /* @__PURE__ */ new Set();
|
|
1389
|
+
for (const email of participants) {
|
|
1390
|
+
const normalizedEmail = email.toLowerCase();
|
|
1391
|
+
uniqueEmails.add(normalizedEmail);
|
|
1392
|
+
if (seenInMeeting.has(normalizedEmail)) continue;
|
|
1393
|
+
seenInMeeting.add(normalizedEmail);
|
|
1394
|
+
const existing = stats.get(normalizedEmail) ?? { meetingCount: 0, totalMinutes: 0 };
|
|
1395
|
+
existing.meetingCount++;
|
|
1396
|
+
existing.totalMinutes += t.duration ?? 0;
|
|
1397
|
+
stats.set(normalizedEmail, existing);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
return { uniqueEmails, stats };
|
|
1401
|
+
}
|
|
1402
|
+
function calculateAverageParticipants(transcripts) {
|
|
1403
|
+
if (transcripts.length === 0) return 0;
|
|
1404
|
+
let totalParticipants = 0;
|
|
1405
|
+
for (const t of transcripts) {
|
|
1406
|
+
const unique = new Set((t.participants ?? []).map((p) => p.toLowerCase()));
|
|
1407
|
+
totalParticipants += unique.size;
|
|
1408
|
+
}
|
|
1409
|
+
return totalParticipants / transcripts.length;
|
|
1410
|
+
}
|
|
1411
|
+
function buildTopParticipants(stats, limit) {
|
|
1412
|
+
const result = [];
|
|
1413
|
+
for (const [email, data] of stats) {
|
|
1414
|
+
result.push({
|
|
1415
|
+
email,
|
|
1416
|
+
meetingCount: data.meetingCount,
|
|
1417
|
+
totalMinutes: data.totalMinutes
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
result.sort((a, b) => b.meetingCount - a.meetingCount);
|
|
1421
|
+
return result.slice(0, limit);
|
|
1422
|
+
}
|
|
1423
|
+
function aggregateSpeakers(transcripts, filterSpeakers) {
|
|
1424
|
+
const uniqueNames = /* @__PURE__ */ new Set();
|
|
1425
|
+
const stats = /* @__PURE__ */ new Map();
|
|
1426
|
+
const filterSet = filterSpeakers ? new Set(filterSpeakers) : null;
|
|
1427
|
+
for (const t of transcripts) {
|
|
1428
|
+
const sentences = t.sentences ?? [];
|
|
1429
|
+
for (const sentence of sentences) {
|
|
1430
|
+
const speakerName = sentence.speaker_name;
|
|
1431
|
+
if (filterSet && !filterSet.has(speakerName)) continue;
|
|
1432
|
+
uniqueNames.add(speakerName);
|
|
1433
|
+
const existing = stats.get(speakerName) ?? {
|
|
1434
|
+
meetingCount: 0,
|
|
1435
|
+
totalTalkTimeSeconds: 0,
|
|
1436
|
+
meetings: /* @__PURE__ */ new Set()
|
|
1437
|
+
};
|
|
1438
|
+
const duration = parseSentenceDuration(sentence);
|
|
1439
|
+
existing.totalTalkTimeSeconds += duration;
|
|
1440
|
+
if (!existing.meetings.has(t.id)) {
|
|
1441
|
+
existing.meetings.add(t.id);
|
|
1442
|
+
existing.meetingCount++;
|
|
1443
|
+
}
|
|
1444
|
+
stats.set(speakerName, existing);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
return { uniqueNames, stats };
|
|
1448
|
+
}
|
|
1449
|
+
function parseSentenceDuration(sentence) {
|
|
1450
|
+
const start = Number.parseFloat(sentence.start_time);
|
|
1451
|
+
const end = Number.parseFloat(sentence.end_time);
|
|
1452
|
+
return Math.max(0, end - start);
|
|
1453
|
+
}
|
|
1454
|
+
function buildTopSpeakers(stats, limit) {
|
|
1455
|
+
const result = [];
|
|
1456
|
+
for (const [name, data] of stats) {
|
|
1457
|
+
result.push({
|
|
1458
|
+
name,
|
|
1459
|
+
meetingCount: data.meetingCount,
|
|
1460
|
+
totalTalkTimeSeconds: data.totalTalkTimeSeconds,
|
|
1461
|
+
averageTalkTimeSeconds: data.meetingCount > 0 ? data.totalTalkTimeSeconds / data.meetingCount : 0
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
result.sort((a, b) => b.totalTalkTimeSeconds - a.totalTalkTimeSeconds);
|
|
1465
|
+
return result.slice(0, limit);
|
|
1466
|
+
}
|
|
1467
|
+
function findDateRange(transcripts) {
|
|
1468
|
+
let earliest = null;
|
|
1469
|
+
let latest = null;
|
|
1470
|
+
for (const t of transcripts) {
|
|
1471
|
+
const date = parseDate(t.dateString);
|
|
1472
|
+
if (!date) continue;
|
|
1473
|
+
if (!earliest || date < earliest) {
|
|
1474
|
+
earliest = date;
|
|
1475
|
+
}
|
|
1476
|
+
if (!latest || date > latest) {
|
|
1477
|
+
latest = date;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
return {
|
|
1481
|
+
earliestMeeting: earliest ? formatDateOnly(earliest) : "",
|
|
1482
|
+
latestMeeting: latest ? formatDateOnly(latest) : ""
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
function parseDate(dateString) {
|
|
1486
|
+
if (!dateString) return null;
|
|
1487
|
+
const date = new Date(dateString);
|
|
1488
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
1489
|
+
}
|
|
1490
|
+
function formatDateOnly(date) {
|
|
1491
|
+
const year = date.getUTCFullYear();
|
|
1492
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
1493
|
+
const day = String(date.getUTCDate()).padStart(2, "0");
|
|
1494
|
+
return `${year}-${month}-${day}`;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
// src/helpers/search.ts
|
|
1498
|
+
function escapeRegex(str) {
|
|
1499
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1500
|
+
}
|
|
1501
|
+
function matchesSpeaker(sentence, speakerSet) {
|
|
1502
|
+
if (!speakerSet) return true;
|
|
1503
|
+
return speakerSet.has(sentence.speaker_name.toLowerCase());
|
|
1504
|
+
}
|
|
1505
|
+
function matchesAIFilters(sentence, filterQuestions, filterTasks) {
|
|
1506
|
+
if (!filterQuestions && !filterTasks) return true;
|
|
1507
|
+
const hasQuestion = Boolean(sentence.ai_filters?.question);
|
|
1508
|
+
const hasTask = Boolean(sentence.ai_filters?.task);
|
|
1509
|
+
if (filterQuestions && filterTasks) {
|
|
1510
|
+
return hasQuestion || hasTask;
|
|
1511
|
+
}
|
|
1512
|
+
if (filterQuestions) return hasQuestion;
|
|
1513
|
+
if (filterTasks) return hasTask;
|
|
1514
|
+
return true;
|
|
1515
|
+
}
|
|
1516
|
+
function extractContext(sentences, index, contextLines) {
|
|
1517
|
+
const beforeStart = Math.max(0, index - contextLines);
|
|
1518
|
+
const afterEnd = Math.min(sentences.length, index + contextLines + 1);
|
|
1519
|
+
return {
|
|
1520
|
+
before: sentences.slice(beforeStart, index).map((s) => ({
|
|
1521
|
+
speakerName: s.speaker_name,
|
|
1522
|
+
text: s.text
|
|
1523
|
+
})),
|
|
1524
|
+
after: sentences.slice(index + 1, afterEnd).map((s) => ({
|
|
1525
|
+
speakerName: s.speaker_name,
|
|
1526
|
+
text: s.text
|
|
1527
|
+
}))
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
function sentenceToMatch(sentence, transcript, context) {
|
|
1531
|
+
return {
|
|
1532
|
+
transcriptId: transcript.id,
|
|
1533
|
+
transcriptTitle: transcript.title,
|
|
1534
|
+
transcriptDate: transcript.dateString,
|
|
1535
|
+
transcriptUrl: transcript.transcript_url,
|
|
1536
|
+
sentence: {
|
|
1537
|
+
index: sentence.index,
|
|
1538
|
+
text: sentence.text,
|
|
1539
|
+
speakerName: sentence.speaker_name,
|
|
1540
|
+
startTime: Number.parseFloat(sentence.start_time),
|
|
1541
|
+
endTime: Number.parseFloat(sentence.end_time),
|
|
1542
|
+
isQuestion: Boolean(sentence.ai_filters?.question),
|
|
1543
|
+
isTask: Boolean(sentence.ai_filters?.task)
|
|
1544
|
+
},
|
|
1545
|
+
context
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
function searchTranscript(transcript, options) {
|
|
1549
|
+
const {
|
|
1550
|
+
query,
|
|
1551
|
+
caseSensitive = false,
|
|
1552
|
+
speakers,
|
|
1553
|
+
filterQuestions = false,
|
|
1554
|
+
filterTasks = false,
|
|
1555
|
+
contextLines = 1
|
|
1556
|
+
} = options;
|
|
1557
|
+
if (!query || query.trim() === "") {
|
|
1558
|
+
return [];
|
|
1559
|
+
}
|
|
1560
|
+
const sentences = transcript.sentences ?? [];
|
|
1561
|
+
if (sentences.length === 0) {
|
|
1562
|
+
return [];
|
|
1563
|
+
}
|
|
1564
|
+
const escapedQuery = escapeRegex(query);
|
|
1565
|
+
const regex = new RegExp(escapedQuery, caseSensitive ? "" : "i");
|
|
1566
|
+
const speakerSet = speakers ? new Set(speakers.map((s) => s.toLowerCase())) : null;
|
|
1567
|
+
const matches = [];
|
|
1568
|
+
for (let i = 0; i < sentences.length; i++) {
|
|
1569
|
+
const sentence = sentences[i];
|
|
1570
|
+
if (!sentence) continue;
|
|
1571
|
+
if (!regex.test(sentence.text)) continue;
|
|
1572
|
+
if (!matchesSpeaker(sentence, speakerSet)) continue;
|
|
1573
|
+
if (!matchesAIFilters(sentence, filterQuestions, filterTasks)) continue;
|
|
1574
|
+
const context = extractContext(sentences, i, contextLines);
|
|
1575
|
+
matches.push(sentenceToMatch(sentence, transcript, context));
|
|
1576
|
+
}
|
|
1577
|
+
return matches;
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// src/graphql/queries/transcripts.ts
|
|
1581
|
+
var TRANSCRIPT_BASE_FIELDS = `
|
|
1582
|
+
id
|
|
1583
|
+
title
|
|
1584
|
+
organizer_email
|
|
1585
|
+
host_email
|
|
1586
|
+
user {
|
|
1587
|
+
user_id
|
|
1588
|
+
email
|
|
1589
|
+
name
|
|
1590
|
+
}
|
|
1591
|
+
speakers {
|
|
1592
|
+
id
|
|
1593
|
+
name
|
|
1594
|
+
}
|
|
1595
|
+
transcript_url
|
|
1596
|
+
participants
|
|
1597
|
+
meeting_attendees {
|
|
1598
|
+
displayName
|
|
1599
|
+
email
|
|
1600
|
+
phoneNumber
|
|
1601
|
+
name
|
|
1602
|
+
location
|
|
1603
|
+
}
|
|
1604
|
+
meeting_attendance {
|
|
1605
|
+
name
|
|
1606
|
+
join_time
|
|
1607
|
+
leave_time
|
|
1608
|
+
}
|
|
1609
|
+
fireflies_users
|
|
1610
|
+
workspace_users
|
|
1611
|
+
duration
|
|
1612
|
+
dateString
|
|
1613
|
+
date
|
|
1614
|
+
audio_url
|
|
1615
|
+
video_url
|
|
1616
|
+
calendar_id
|
|
1617
|
+
meeting_info {
|
|
1618
|
+
fred_joined
|
|
1619
|
+
silent_meeting
|
|
1620
|
+
summary_status
|
|
1621
|
+
}
|
|
1622
|
+
cal_id
|
|
1623
|
+
calendar_type
|
|
1624
|
+
apps_preview {
|
|
1625
|
+
outputs {
|
|
1626
|
+
transcript_id
|
|
1627
|
+
user_id
|
|
1628
|
+
app_id
|
|
1629
|
+
created_at
|
|
1630
|
+
title
|
|
1631
|
+
prompt
|
|
1632
|
+
response
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
meeting_link
|
|
1636
|
+
analytics {
|
|
1637
|
+
sentiments {
|
|
1638
|
+
negative_pct
|
|
1639
|
+
neutral_pct
|
|
1640
|
+
positive_pct
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
channels {
|
|
1644
|
+
id
|
|
1645
|
+
title
|
|
1646
|
+
is_private
|
|
1647
|
+
created_at
|
|
1648
|
+
updated_at
|
|
1649
|
+
created_by
|
|
1650
|
+
members {
|
|
1651
|
+
user_id
|
|
1652
|
+
email
|
|
1653
|
+
name
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
`;
|
|
1657
|
+
var SENTENCES_FIELDS = `
|
|
1658
|
+
sentences {
|
|
1659
|
+
index
|
|
1660
|
+
text
|
|
1661
|
+
raw_text
|
|
1662
|
+
start_time
|
|
1663
|
+
end_time
|
|
1664
|
+
speaker_id
|
|
1665
|
+
speaker_name
|
|
1666
|
+
ai_filters {
|
|
1667
|
+
task
|
|
1668
|
+
pricing
|
|
1669
|
+
metric
|
|
1670
|
+
question
|
|
1671
|
+
date_and_time
|
|
1672
|
+
text_cleanup
|
|
1673
|
+
sentiment
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
`;
|
|
1677
|
+
var SUMMARY_FIELDS = `
|
|
1678
|
+
summary {
|
|
1679
|
+
action_items
|
|
1680
|
+
keywords
|
|
1681
|
+
outline
|
|
1682
|
+
overview
|
|
1683
|
+
shorthand_bullet
|
|
1684
|
+
notes
|
|
1685
|
+
gist
|
|
1686
|
+
bullet_gist
|
|
1687
|
+
short_summary
|
|
1688
|
+
short_overview
|
|
1689
|
+
meeting_type
|
|
1690
|
+
topics_discussed
|
|
1691
|
+
transcript_chapters
|
|
1692
|
+
extended_sections {
|
|
1693
|
+
title
|
|
1694
|
+
content
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
`;
|
|
1698
|
+
function buildTranscriptFields(params) {
|
|
1699
|
+
const includeSentences = params?.includeSentences !== false;
|
|
1700
|
+
const includeSummary = params?.includeSummary !== false;
|
|
1701
|
+
let fields = TRANSCRIPT_BASE_FIELDS;
|
|
1702
|
+
if (includeSentences) {
|
|
1703
|
+
fields += SENTENCES_FIELDS;
|
|
1704
|
+
}
|
|
1705
|
+
if (includeSummary) {
|
|
1706
|
+
fields += SUMMARY_FIELDS;
|
|
1707
|
+
}
|
|
1708
|
+
return fields;
|
|
1709
|
+
}
|
|
1710
|
+
var TRANSCRIPT_LIST_FIELDS = `
|
|
1711
|
+
id
|
|
1712
|
+
title
|
|
1713
|
+
organizer_email
|
|
1714
|
+
transcript_url
|
|
1715
|
+
participants
|
|
1716
|
+
duration
|
|
1717
|
+
dateString
|
|
1718
|
+
date
|
|
1719
|
+
video_url
|
|
1720
|
+
meeting_info {
|
|
1721
|
+
fred_joined
|
|
1722
|
+
silent_meeting
|
|
1723
|
+
summary_status
|
|
1724
|
+
}
|
|
1725
|
+
`;
|
|
1726
|
+
function createTranscriptsAPI(client) {
|
|
1727
|
+
return {
|
|
1728
|
+
async get(id, params) {
|
|
1729
|
+
const fields = buildTranscriptFields(params);
|
|
1730
|
+
const query = `
|
|
1731
|
+
query GetTranscript($id: String!) {
|
|
1732
|
+
transcript(id: $id) {
|
|
1733
|
+
${fields}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
`;
|
|
1737
|
+
const data = await client.execute(query, { id });
|
|
1738
|
+
return normalizeTranscript(data.transcript);
|
|
1739
|
+
},
|
|
1740
|
+
async list(params) {
|
|
1741
|
+
const query = `
|
|
1742
|
+
query ListTranscripts(
|
|
1743
|
+
$keyword: String
|
|
1744
|
+
$scope: String
|
|
1745
|
+
$organizers: [String!]
|
|
1746
|
+
$participants: [String!]
|
|
1747
|
+
$user_id: String
|
|
1748
|
+
$mine: Boolean
|
|
1749
|
+
$channel_id: String
|
|
1750
|
+
$fromDate: DateTime
|
|
1751
|
+
$toDate: DateTime
|
|
1752
|
+
$limit: Int
|
|
1753
|
+
$skip: Int
|
|
1754
|
+
$title: String
|
|
1755
|
+
$host_email: String
|
|
1756
|
+
$organizer_email: String
|
|
1757
|
+
$participant_email: String
|
|
1758
|
+
$date: Float
|
|
1759
|
+
) {
|
|
1760
|
+
transcripts(
|
|
1761
|
+
keyword: $keyword
|
|
1762
|
+
scope: $scope
|
|
1763
|
+
organizers: $organizers
|
|
1764
|
+
participants: $participants
|
|
1765
|
+
user_id: $user_id
|
|
1766
|
+
mine: $mine
|
|
1767
|
+
channel_id: $channel_id
|
|
1768
|
+
fromDate: $fromDate
|
|
1769
|
+
toDate: $toDate
|
|
1770
|
+
limit: $limit
|
|
1771
|
+
skip: $skip
|
|
1772
|
+
title: $title
|
|
1773
|
+
host_email: $host_email
|
|
1774
|
+
organizer_email: $organizer_email
|
|
1775
|
+
participant_email: $participant_email
|
|
1776
|
+
date: $date
|
|
1777
|
+
) {
|
|
1778
|
+
${TRANSCRIPT_LIST_FIELDS}
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
`;
|
|
1782
|
+
const variables = buildListVariables(params);
|
|
1783
|
+
const data = await client.execute(query, variables);
|
|
1784
|
+
return data.transcripts.map(normalizeTranscript);
|
|
1785
|
+
},
|
|
1786
|
+
async getSummary(id) {
|
|
1787
|
+
const query = `
|
|
1788
|
+
query GetTranscriptSummary($id: String!) {
|
|
1789
|
+
transcript(id: $id) {
|
|
1790
|
+
summary {
|
|
1791
|
+
action_items
|
|
1792
|
+
keywords
|
|
1793
|
+
outline
|
|
1794
|
+
overview
|
|
1795
|
+
shorthand_bullet
|
|
1796
|
+
notes
|
|
1797
|
+
gist
|
|
1798
|
+
bullet_gist
|
|
1799
|
+
short_summary
|
|
1800
|
+
short_overview
|
|
1801
|
+
meeting_type
|
|
1802
|
+
topics_discussed
|
|
1803
|
+
transcript_chapters
|
|
1804
|
+
extended_sections {
|
|
1805
|
+
title
|
|
1806
|
+
content
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
`;
|
|
1812
|
+
const data = await client.execute(query, { id });
|
|
1813
|
+
return data.transcript.summary;
|
|
1814
|
+
},
|
|
1815
|
+
listAll(params) {
|
|
1816
|
+
return paginate((skip, limit) => this.list({ ...params, skip, limit }), 50);
|
|
1817
|
+
},
|
|
1818
|
+
async search(query, params = {}) {
|
|
1819
|
+
const {
|
|
1820
|
+
caseSensitive = false,
|
|
1821
|
+
scope = "sentences",
|
|
1822
|
+
speakers,
|
|
1823
|
+
filterQuestions,
|
|
1824
|
+
filterTasks,
|
|
1825
|
+
contextLines = 1,
|
|
1826
|
+
limit,
|
|
1827
|
+
...listParams
|
|
1828
|
+
} = params;
|
|
1829
|
+
const transcripts = [];
|
|
1830
|
+
for await (const t of this.listAll({
|
|
1831
|
+
keyword: query,
|
|
1832
|
+
scope,
|
|
1833
|
+
...listParams
|
|
1834
|
+
})) {
|
|
1835
|
+
transcripts.push(t);
|
|
1836
|
+
if (limit && transcripts.length >= limit) break;
|
|
1837
|
+
}
|
|
1838
|
+
const allMatches = [];
|
|
1839
|
+
let transcriptsWithMatches = 0;
|
|
1840
|
+
for (const t of transcripts) {
|
|
1841
|
+
const full = await this.get(t.id, { includeSentences: true });
|
|
1842
|
+
const matches = searchTranscript(full, {
|
|
1843
|
+
query,
|
|
1844
|
+
caseSensitive,
|
|
1845
|
+
speakers,
|
|
1846
|
+
filterQuestions,
|
|
1847
|
+
filterTasks,
|
|
1848
|
+
contextLines
|
|
1849
|
+
});
|
|
1850
|
+
if (matches.length > 0) {
|
|
1851
|
+
transcriptsWithMatches++;
|
|
1852
|
+
allMatches.push(...matches);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
return {
|
|
1856
|
+
query,
|
|
1857
|
+
options: params,
|
|
1858
|
+
totalMatches: allMatches.length,
|
|
1859
|
+
transcriptsSearched: transcripts.length,
|
|
1860
|
+
transcriptsWithMatches,
|
|
1861
|
+
matches: allMatches
|
|
1862
|
+
};
|
|
1863
|
+
},
|
|
1864
|
+
async insights(params = {}) {
|
|
1865
|
+
const {
|
|
1866
|
+
fromDate,
|
|
1867
|
+
toDate,
|
|
1868
|
+
mine,
|
|
1869
|
+
organizers,
|
|
1870
|
+
participants,
|
|
1871
|
+
user_id,
|
|
1872
|
+
channel_id,
|
|
1873
|
+
limit,
|
|
1874
|
+
external,
|
|
1875
|
+
speakers,
|
|
1876
|
+
groupBy: groupBy2,
|
|
1877
|
+
topSpeakersCount,
|
|
1878
|
+
topParticipantsCount
|
|
1879
|
+
} = params;
|
|
1880
|
+
let internalDomain;
|
|
1881
|
+
if (external) {
|
|
1882
|
+
const userQuery = "query { user { email } }";
|
|
1883
|
+
const userData = await client.execute(userQuery);
|
|
1884
|
+
internalDomain = extractDomain(userData.user.email);
|
|
1885
|
+
}
|
|
1886
|
+
const transcripts = [];
|
|
1887
|
+
for await (const t of this.listAll({
|
|
1888
|
+
fromDate,
|
|
1889
|
+
toDate,
|
|
1890
|
+
mine,
|
|
1891
|
+
organizers,
|
|
1892
|
+
participants,
|
|
1893
|
+
user_id,
|
|
1894
|
+
channel_id
|
|
1895
|
+
})) {
|
|
1896
|
+
if (internalDomain && !hasExternalParticipants(t.participants, internalDomain)) {
|
|
1897
|
+
continue;
|
|
1898
|
+
}
|
|
1899
|
+
const full = await this.get(t.id, { includeSentences: true, includeSummary: false });
|
|
1900
|
+
transcripts.push(full);
|
|
1901
|
+
if (limit && transcripts.length >= limit) break;
|
|
1902
|
+
}
|
|
1903
|
+
return analyzeMeetings(transcripts, {
|
|
1904
|
+
speakers,
|
|
1905
|
+
groupBy: groupBy2,
|
|
1906
|
+
topSpeakersCount,
|
|
1907
|
+
topParticipantsCount
|
|
1908
|
+
});
|
|
1909
|
+
},
|
|
1910
|
+
async exportActionItems(params = {}) {
|
|
1911
|
+
const { fromDate, toDate, mine, organizers, participants, limit, filterOptions } = params;
|
|
1912
|
+
const transcripts = [];
|
|
1913
|
+
for await (const t of this.listAll({
|
|
1914
|
+
fromDate,
|
|
1915
|
+
toDate,
|
|
1916
|
+
mine,
|
|
1917
|
+
organizers,
|
|
1918
|
+
participants
|
|
1919
|
+
})) {
|
|
1920
|
+
const full = await this.get(t.id, { includeSentences: false, includeSummary: true });
|
|
1921
|
+
transcripts.push(full);
|
|
1922
|
+
if (limit && transcripts.length >= limit) break;
|
|
1923
|
+
}
|
|
1924
|
+
return aggregateActionItems(transcripts, {}, filterOptions);
|
|
1925
|
+
}
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1928
|
+
function orUndefined(value) {
|
|
1929
|
+
return value ?? void 0;
|
|
1930
|
+
}
|
|
1931
|
+
function orEmptyArray(value) {
|
|
1932
|
+
return value ?? [];
|
|
1933
|
+
}
|
|
1934
|
+
function normalizeRequiredFields(raw) {
|
|
1935
|
+
return {
|
|
1936
|
+
id: raw.id,
|
|
1937
|
+
title: raw.title ?? "",
|
|
1938
|
+
organizer_email: raw.organizer_email ?? "",
|
|
1939
|
+
transcript_url: raw.transcript_url ?? "",
|
|
1940
|
+
duration: raw.duration ?? 0,
|
|
1941
|
+
dateString: raw.dateString ?? "",
|
|
1942
|
+
date: raw.date ?? 0
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
function normalizeArrayFields(raw) {
|
|
1946
|
+
return {
|
|
1947
|
+
speakers: orEmptyArray(raw.speakers),
|
|
1948
|
+
participants: orEmptyArray(raw.participants),
|
|
1949
|
+
meeting_attendees: orEmptyArray(raw.meeting_attendees),
|
|
1950
|
+
meeting_attendance: orEmptyArray(raw.meeting_attendance),
|
|
1951
|
+
fireflies_users: orEmptyArray(raw.fireflies_users),
|
|
1952
|
+
workspace_users: orEmptyArray(raw.workspace_users),
|
|
1953
|
+
sentences: orEmptyArray(raw.sentences),
|
|
1954
|
+
channels: orEmptyArray(raw.channels)
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
function normalizeOptionalFields(raw) {
|
|
1958
|
+
return {
|
|
1959
|
+
host_email: orUndefined(raw.host_email),
|
|
1960
|
+
user: orUndefined(raw.user),
|
|
1961
|
+
audio_url: orUndefined(raw.audio_url),
|
|
1962
|
+
video_url: orUndefined(raw.video_url),
|
|
1963
|
+
calendar_id: orUndefined(raw.calendar_id),
|
|
1964
|
+
summary: orUndefined(raw.summary),
|
|
1965
|
+
meeting_info: orUndefined(raw.meeting_info),
|
|
1966
|
+
cal_id: orUndefined(raw.cal_id),
|
|
1967
|
+
calendar_type: orUndefined(raw.calendar_type),
|
|
1968
|
+
apps_preview: orUndefined(raw.apps_preview),
|
|
1969
|
+
meeting_link: orUndefined(raw.meeting_link),
|
|
1970
|
+
analytics: orUndefined(raw.analytics)
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1973
|
+
function normalizeTranscript(raw) {
|
|
1974
|
+
return {
|
|
1975
|
+
...normalizeRequiredFields(raw),
|
|
1976
|
+
...normalizeArrayFields(raw),
|
|
1977
|
+
...normalizeOptionalFields(raw)
|
|
1978
|
+
};
|
|
1979
|
+
}
|
|
1980
|
+
function buildListVariables(params) {
|
|
1981
|
+
if (!params) {
|
|
1982
|
+
return { limit: 50 };
|
|
1983
|
+
}
|
|
1984
|
+
return {
|
|
1985
|
+
keyword: params.keyword,
|
|
1986
|
+
scope: params.scope,
|
|
1987
|
+
organizers: params.organizers,
|
|
1988
|
+
participants: params.participants,
|
|
1989
|
+
user_id: params.user_id,
|
|
1990
|
+
mine: params.mine,
|
|
1991
|
+
channel_id: params.channel_id,
|
|
1992
|
+
fromDate: params.fromDate,
|
|
1993
|
+
toDate: params.toDate,
|
|
1994
|
+
limit: params.limit ?? 50,
|
|
1995
|
+
skip: params.skip,
|
|
1996
|
+
title: params.title,
|
|
1997
|
+
host_email: params.host_email,
|
|
1998
|
+
organizer_email: params.organizer_email,
|
|
1999
|
+
participant_email: params.participant_email,
|
|
2000
|
+
date: params.date
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
// src/graphql/queries/users.ts
|
|
2005
|
+
var USER_FIELDS = `
|
|
2006
|
+
user_id
|
|
2007
|
+
email
|
|
2008
|
+
name
|
|
2009
|
+
num_transcripts
|
|
2010
|
+
recent_meeting
|
|
2011
|
+
recent_transcript
|
|
2012
|
+
minutes_consumed
|
|
2013
|
+
is_admin
|
|
2014
|
+
integrations
|
|
2015
|
+
user_groups {
|
|
2016
|
+
id
|
|
2017
|
+
name
|
|
2018
|
+
handle
|
|
2019
|
+
members {
|
|
2020
|
+
user_id
|
|
2021
|
+
email
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
`;
|
|
2025
|
+
function createUsersAPI(client) {
|
|
2026
|
+
return {
|
|
2027
|
+
async me() {
|
|
2028
|
+
const query = `query { user { ${USER_FIELDS} } }`;
|
|
2029
|
+
const data = await client.execute(query);
|
|
2030
|
+
return data.user;
|
|
2031
|
+
},
|
|
2032
|
+
async get(id) {
|
|
2033
|
+
const query = `
|
|
2034
|
+
query User($userId: String!) {
|
|
2035
|
+
user(id: $userId) { ${USER_FIELDS} }
|
|
2036
|
+
}
|
|
2037
|
+
`;
|
|
2038
|
+
const data = await client.execute(query, { userId: id });
|
|
2039
|
+
return data.user;
|
|
2040
|
+
},
|
|
2041
|
+
async list() {
|
|
2042
|
+
const query = `query Users { users { ${USER_FIELDS} } }`;
|
|
2043
|
+
const data = await client.execute(query);
|
|
2044
|
+
return data.users;
|
|
2045
|
+
}
|
|
2046
|
+
};
|
|
2047
|
+
}
|
|
2048
|
+
var DEFAULT_WS_URL = "wss://api.fireflies.ai";
|
|
2049
|
+
var DEFAULT_WS_PATH = "/ws/realtime";
|
|
2050
|
+
var DEFAULT_TIMEOUT2 = 2e4;
|
|
2051
|
+
var DEFAULT_CHUNK_TIMEOUT = 2e4;
|
|
2052
|
+
var DEFAULT_RECONNECT_DELAY = 5e3;
|
|
2053
|
+
var DEFAULT_MAX_RECONNECT_DELAY = 6e4;
|
|
2054
|
+
var DEFAULT_MAX_RECONNECT_ATTEMPTS = 10;
|
|
2055
|
+
var RealtimeConnection = class {
|
|
2056
|
+
socket = null;
|
|
2057
|
+
config;
|
|
2058
|
+
constructor(config) {
|
|
2059
|
+
this.config = {
|
|
2060
|
+
wsUrl: DEFAULT_WS_URL,
|
|
2061
|
+
wsPath: DEFAULT_WS_PATH,
|
|
2062
|
+
timeout: DEFAULT_TIMEOUT2,
|
|
2063
|
+
chunkTimeout: DEFAULT_CHUNK_TIMEOUT,
|
|
2064
|
+
reconnect: true,
|
|
2065
|
+
maxReconnectAttempts: DEFAULT_MAX_RECONNECT_ATTEMPTS,
|
|
2066
|
+
reconnectDelay: DEFAULT_RECONNECT_DELAY,
|
|
2067
|
+
maxReconnectDelay: DEFAULT_MAX_RECONNECT_DELAY,
|
|
2068
|
+
...config
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
* Establish connection and wait for auth success.
|
|
2073
|
+
*/
|
|
2074
|
+
async connect() {
|
|
2075
|
+
if (this.socket?.connected) {
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2078
|
+
const socket = socket_ioClient.io(this.config.wsUrl, {
|
|
2079
|
+
path: this.config.wsPath,
|
|
2080
|
+
auth: {
|
|
2081
|
+
token: `Bearer ${this.config.apiKey}`,
|
|
2082
|
+
transcriptId: this.config.transcriptId
|
|
2083
|
+
},
|
|
2084
|
+
// Force WebSocket transport (proven more reliable than polling)
|
|
2085
|
+
transports: ["websocket"],
|
|
2086
|
+
reconnection: this.config.reconnect,
|
|
2087
|
+
reconnectionDelay: this.config.reconnectDelay,
|
|
2088
|
+
reconnectionDelayMax: this.config.maxReconnectDelay,
|
|
2089
|
+
reconnectionAttempts: this.config.maxReconnectAttempts,
|
|
2090
|
+
// Exponential backoff factor (default 2x matches our fireflies-whiteboard pattern)
|
|
2091
|
+
randomizationFactor: 0.5,
|
|
2092
|
+
timeout: this.config.timeout,
|
|
2093
|
+
autoConnect: false
|
|
2094
|
+
});
|
|
2095
|
+
this.socket = socket;
|
|
2096
|
+
return new Promise((resolve, reject) => {
|
|
2097
|
+
const timeoutId = setTimeout(() => {
|
|
2098
|
+
socket.disconnect();
|
|
2099
|
+
reject(new TimeoutError(`Realtime connection timed out after ${this.config.timeout}ms`));
|
|
2100
|
+
}, this.config.timeout);
|
|
2101
|
+
const cleanup = () => clearTimeout(timeoutId);
|
|
2102
|
+
socket.once("auth.success", () => {
|
|
2103
|
+
cleanup();
|
|
2104
|
+
resolve();
|
|
2105
|
+
});
|
|
2106
|
+
socket.once("auth.failed", (data) => {
|
|
2107
|
+
cleanup();
|
|
2108
|
+
socket.disconnect();
|
|
2109
|
+
reject(new AuthenticationError(`Realtime auth failed: ${formatData(data)}`));
|
|
2110
|
+
});
|
|
2111
|
+
socket.once("connection.error", (data) => {
|
|
2112
|
+
cleanup();
|
|
2113
|
+
socket.disconnect();
|
|
2114
|
+
reject(new ConnectionError(`Realtime connection error: ${formatData(data)}`));
|
|
2115
|
+
});
|
|
2116
|
+
socket.once("connect_error", (error) => {
|
|
2117
|
+
cleanup();
|
|
2118
|
+
socket.disconnect();
|
|
2119
|
+
const message = error.message || "Connection failed";
|
|
2120
|
+
if (message.includes("auth") || message.includes("401") || message.includes("unauthorized")) {
|
|
2121
|
+
reject(new AuthenticationError(`Realtime auth failed: ${message}`));
|
|
2122
|
+
} else {
|
|
2123
|
+
reject(
|
|
2124
|
+
new ConnectionError(`Realtime connection failed: ${message}`, {
|
|
2125
|
+
cause: error
|
|
2126
|
+
})
|
|
2127
|
+
);
|
|
2128
|
+
}
|
|
2129
|
+
});
|
|
2130
|
+
socket.connect();
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Register a chunk handler.
|
|
2135
|
+
* Handles both { payload: {...} } and direct payload shapes.
|
|
2136
|
+
*/
|
|
2137
|
+
onChunk(handler) {
|
|
2138
|
+
this.socket?.on("transcription.broadcast", (data) => {
|
|
2139
|
+
const chunk = "payload" in data ? data.payload : data;
|
|
2140
|
+
handler(chunk);
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2144
|
+
* Register a disconnect handler.
|
|
2145
|
+
*/
|
|
2146
|
+
onDisconnect(handler) {
|
|
2147
|
+
this.socket?.on("disconnect", handler);
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* Register a reconnect handler.
|
|
2151
|
+
*/
|
|
2152
|
+
onReconnect(handler) {
|
|
2153
|
+
this.socket?.io.on("reconnect", handler);
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* Register a reconnect attempt handler.
|
|
2157
|
+
*/
|
|
2158
|
+
onReconnectAttempt(handler) {
|
|
2159
|
+
this.socket?.io.on("reconnect_attempt", handler);
|
|
2160
|
+
}
|
|
2161
|
+
/**
|
|
2162
|
+
* Register an error handler.
|
|
2163
|
+
*/
|
|
2164
|
+
onError(handler) {
|
|
2165
|
+
this.socket?.on("connect_error", handler);
|
|
2166
|
+
}
|
|
2167
|
+
/**
|
|
2168
|
+
* Disconnect and cleanup.
|
|
2169
|
+
*/
|
|
2170
|
+
disconnect() {
|
|
2171
|
+
if (this.socket) {
|
|
2172
|
+
this.socket.disconnect();
|
|
2173
|
+
this.socket = null;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
get connected() {
|
|
2177
|
+
return this.socket?.connected ?? false;
|
|
2178
|
+
}
|
|
2179
|
+
};
|
|
2180
|
+
function formatData(data) {
|
|
2181
|
+
if (data === void 0 || data === null) {
|
|
2182
|
+
return String(data);
|
|
2183
|
+
}
|
|
2184
|
+
try {
|
|
2185
|
+
return JSON.stringify(data);
|
|
2186
|
+
} catch {
|
|
2187
|
+
return String(data);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
// src/realtime/stream.ts
|
|
2192
|
+
var RealtimeStream = class {
|
|
2193
|
+
connection;
|
|
2194
|
+
listeners = /* @__PURE__ */ new Map();
|
|
2195
|
+
buffer = [];
|
|
2196
|
+
waiters = [];
|
|
2197
|
+
closed = false;
|
|
2198
|
+
lastChunkId = null;
|
|
2199
|
+
lastChunk = null;
|
|
2200
|
+
constructor(config) {
|
|
2201
|
+
this.connection = new RealtimeConnection(config);
|
|
2202
|
+
}
|
|
2203
|
+
/**
|
|
2204
|
+
* Connect to the realtime stream.
|
|
2205
|
+
* @throws AuthenticationError if authentication fails
|
|
2206
|
+
* @throws ConnectionError if connection fails
|
|
2207
|
+
* @throws TimeoutError if connection times out
|
|
2208
|
+
*/
|
|
2209
|
+
async connect() {
|
|
2210
|
+
await this.connection.connect();
|
|
2211
|
+
this.setupHandlers();
|
|
2212
|
+
this.emit("connected");
|
|
2213
|
+
}
|
|
2214
|
+
setupHandlers() {
|
|
2215
|
+
this.connection.onChunk((rawChunk) => {
|
|
2216
|
+
const isNewChunk = this.lastChunkId !== null && rawChunk.chunk_id !== this.lastChunkId;
|
|
2217
|
+
if (isNewChunk && this.lastChunk) {
|
|
2218
|
+
const finalChunk = { ...this.lastChunk, isFinal: true };
|
|
2219
|
+
this.emitChunk(finalChunk);
|
|
2220
|
+
}
|
|
2221
|
+
const chunk = { ...rawChunk, isFinal: false };
|
|
2222
|
+
this.lastChunkId = chunk.chunk_id;
|
|
2223
|
+
this.lastChunk = chunk;
|
|
2224
|
+
this.emit("chunk", chunk);
|
|
2225
|
+
});
|
|
2226
|
+
this.connection.onDisconnect((reason) => {
|
|
2227
|
+
if (this.lastChunk) {
|
|
2228
|
+
const finalChunk = { ...this.lastChunk, isFinal: true };
|
|
2229
|
+
this.emitChunk(finalChunk);
|
|
2230
|
+
this.lastChunk = null;
|
|
2231
|
+
}
|
|
2232
|
+
this.emit("disconnected", reason);
|
|
2233
|
+
if (!this.connection.connected) {
|
|
2234
|
+
this.closed = true;
|
|
2235
|
+
for (const waiter of this.waiters) {
|
|
2236
|
+
waiter(null);
|
|
2237
|
+
}
|
|
2238
|
+
this.waiters = [];
|
|
2239
|
+
}
|
|
2240
|
+
});
|
|
2241
|
+
this.connection.onReconnectAttempt((attempt) => {
|
|
2242
|
+
this.emit("reconnecting", attempt);
|
|
2243
|
+
});
|
|
2244
|
+
this.connection.onReconnect(() => {
|
|
2245
|
+
this.emit("connected");
|
|
2246
|
+
});
|
|
2247
|
+
this.connection.onError((error) => {
|
|
2248
|
+
this.emit("error", error);
|
|
2249
|
+
});
|
|
2250
|
+
}
|
|
2251
|
+
/**
|
|
2252
|
+
* Register an event listener.
|
|
2253
|
+
* @param event - Event name
|
|
2254
|
+
* @param handler - Event handler
|
|
2255
|
+
*/
|
|
2256
|
+
on(event, handler) {
|
|
2257
|
+
let handlers = this.listeners.get(event);
|
|
2258
|
+
if (!handlers) {
|
|
2259
|
+
handlers = /* @__PURE__ */ new Set();
|
|
2260
|
+
this.listeners.set(event, handlers);
|
|
2261
|
+
}
|
|
2262
|
+
handlers.add(handler);
|
|
2263
|
+
return this;
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* Remove an event listener.
|
|
2267
|
+
* @param event - Event name
|
|
2268
|
+
* @param handler - Event handler to remove
|
|
2269
|
+
*/
|
|
2270
|
+
off(event, handler) {
|
|
2271
|
+
this.listeners.get(event)?.delete(handler);
|
|
2272
|
+
return this;
|
|
2273
|
+
}
|
|
2274
|
+
/**
|
|
2275
|
+
* Emit a chunk to both event listeners and async iterator buffer.
|
|
2276
|
+
* Used for final chunks that should be yielded by the iterator.
|
|
2277
|
+
*/
|
|
2278
|
+
emitChunk(chunk) {
|
|
2279
|
+
this.emit("chunk", chunk);
|
|
2280
|
+
if (chunk.isFinal) {
|
|
2281
|
+
if (this.waiters.length > 0) {
|
|
2282
|
+
const waiter = this.waiters.shift();
|
|
2283
|
+
waiter?.(chunk);
|
|
2284
|
+
} else {
|
|
2285
|
+
this.buffer.push(chunk);
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
emit(event, ...args) {
|
|
2290
|
+
const handlers = this.listeners.get(event);
|
|
2291
|
+
handlers?.forEach((handler) => {
|
|
2292
|
+
try {
|
|
2293
|
+
handler(...args);
|
|
2294
|
+
} catch {
|
|
2295
|
+
}
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* AsyncIterable implementation for `for await` loops.
|
|
2300
|
+
*/
|
|
2301
|
+
async *[Symbol.asyncIterator]() {
|
|
2302
|
+
if (this.closed) {
|
|
2303
|
+
throw new StreamClosedError();
|
|
2304
|
+
}
|
|
2305
|
+
while (!this.closed) {
|
|
2306
|
+
const buffered = this.buffer.shift();
|
|
2307
|
+
if (buffered) {
|
|
2308
|
+
yield buffered;
|
|
2309
|
+
continue;
|
|
2310
|
+
}
|
|
2311
|
+
const chunk = await new Promise((resolve) => {
|
|
2312
|
+
if (this.closed) {
|
|
2313
|
+
resolve(null);
|
|
2314
|
+
return;
|
|
2315
|
+
}
|
|
2316
|
+
this.waiters.push(resolve);
|
|
2317
|
+
});
|
|
2318
|
+
if (chunk === null) {
|
|
2319
|
+
break;
|
|
2320
|
+
}
|
|
2321
|
+
yield chunk;
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* Close the stream and disconnect.
|
|
2326
|
+
*/
|
|
2327
|
+
close() {
|
|
2328
|
+
if (this.lastChunk) {
|
|
2329
|
+
const finalChunk = { ...this.lastChunk, isFinal: true };
|
|
2330
|
+
this.emitChunk(finalChunk);
|
|
2331
|
+
this.lastChunk = null;
|
|
2332
|
+
}
|
|
2333
|
+
this.closed = true;
|
|
2334
|
+
this.connection.disconnect();
|
|
2335
|
+
this.buffer = [];
|
|
2336
|
+
this.lastChunkId = null;
|
|
2337
|
+
for (const waiter of this.waiters) {
|
|
2338
|
+
waiter(null);
|
|
2339
|
+
}
|
|
2340
|
+
this.waiters = [];
|
|
2341
|
+
}
|
|
2342
|
+
/**
|
|
2343
|
+
* Whether the stream is currently connected.
|
|
2344
|
+
*/
|
|
2345
|
+
get connected() {
|
|
2346
|
+
return this.connection.connected;
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
|
|
2350
|
+
// src/realtime/api.ts
|
|
2351
|
+
function createRealtimeAPI(apiKey, baseConfig) {
|
|
2352
|
+
return {
|
|
2353
|
+
async connect(transcriptId) {
|
|
2354
|
+
const stream = new RealtimeStream({
|
|
2355
|
+
apiKey,
|
|
2356
|
+
transcriptId,
|
|
2357
|
+
...baseConfig
|
|
2358
|
+
});
|
|
2359
|
+
await stream.connect();
|
|
2360
|
+
return stream;
|
|
2361
|
+
},
|
|
2362
|
+
async *stream(transcriptId) {
|
|
2363
|
+
const stream = new RealtimeStream({
|
|
2364
|
+
apiKey,
|
|
2365
|
+
transcriptId,
|
|
2366
|
+
...baseConfig
|
|
2367
|
+
});
|
|
2368
|
+
try {
|
|
2369
|
+
await stream.connect();
|
|
2370
|
+
yield* stream;
|
|
2371
|
+
} finally {
|
|
2372
|
+
stream.close();
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
// src/client.ts
|
|
2379
|
+
var FirefliesClient = class {
|
|
2380
|
+
graphql;
|
|
2381
|
+
/**
|
|
2382
|
+
* Transcript operations: list, get, search, delete.
|
|
2383
|
+
*/
|
|
2384
|
+
transcripts;
|
|
2385
|
+
/**
|
|
2386
|
+
* User operations: me, get, list, setRole.
|
|
2387
|
+
*/
|
|
2388
|
+
users;
|
|
2389
|
+
/**
|
|
2390
|
+
* Bite operations: get, list, create.
|
|
2391
|
+
*/
|
|
2392
|
+
bites;
|
|
2393
|
+
/**
|
|
2394
|
+
* Meeting operations: active meetings, add bot.
|
|
2395
|
+
*/
|
|
2396
|
+
meetings;
|
|
2397
|
+
/**
|
|
2398
|
+
* Audio operations: upload audio for transcription.
|
|
2399
|
+
*/
|
|
2400
|
+
audio;
|
|
2401
|
+
/**
|
|
2402
|
+
* AI Apps operations: list outputs.
|
|
2403
|
+
*/
|
|
2404
|
+
aiApps;
|
|
2405
|
+
/**
|
|
2406
|
+
* Realtime transcription streaming.
|
|
2407
|
+
*/
|
|
2408
|
+
realtime;
|
|
2409
|
+
/**
|
|
2410
|
+
* Create a new Fireflies client.
|
|
2411
|
+
*
|
|
2412
|
+
* @param config - Client configuration
|
|
2413
|
+
* @throws FirefliesError if API key is missing
|
|
2414
|
+
*/
|
|
2415
|
+
constructor(config) {
|
|
2416
|
+
this.graphql = new GraphQLClient(config);
|
|
2417
|
+
const transcriptsQueries = createTranscriptsAPI(this.graphql);
|
|
2418
|
+
const transcriptsMutations = createTranscriptsMutationsAPI(this.graphql);
|
|
2419
|
+
this.transcripts = { ...transcriptsQueries, ...transcriptsMutations };
|
|
2420
|
+
const usersQueries = createUsersAPI(this.graphql);
|
|
2421
|
+
const usersMutations = createUsersMutationsAPI(this.graphql);
|
|
2422
|
+
this.users = { ...usersQueries, ...usersMutations };
|
|
2423
|
+
this.bites = createBitesAPI(this.graphql);
|
|
2424
|
+
this.meetings = createMeetingsAPI(this.graphql);
|
|
2425
|
+
this.audio = createAudioAPI(this.graphql);
|
|
2426
|
+
this.aiApps = createAIAppsAPI(this.graphql);
|
|
2427
|
+
this.realtime = createRealtimeAPI(config.apiKey);
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
2430
|
+
* Get the current rate limit state.
|
|
2431
|
+
* Returns undefined if rate limit tracking is not configured.
|
|
2432
|
+
*
|
|
2433
|
+
* @example
|
|
2434
|
+
* ```typescript
|
|
2435
|
+
* const client = new FirefliesClient({
|
|
2436
|
+
* apiKey: '...',
|
|
2437
|
+
* rateLimit: { warningThreshold: 10 }
|
|
2438
|
+
* });
|
|
2439
|
+
*
|
|
2440
|
+
* await client.users.me();
|
|
2441
|
+
* console.log(client.rateLimits);
|
|
2442
|
+
* // { remaining: 59, limit: 60, resetInSeconds: 60, updatedAt: 1706299500000 }
|
|
2443
|
+
* ```
|
|
2444
|
+
*/
|
|
2445
|
+
get rateLimits() {
|
|
2446
|
+
return this.graphql.rateLimitState;
|
|
2447
|
+
}
|
|
2448
|
+
};
|
|
2449
|
+
|
|
2450
|
+
// src/cli/utils/client.ts
|
|
2451
|
+
function getClient(cmd) {
|
|
2452
|
+
const opts = cmd.optsWithGlobals();
|
|
2453
|
+
const apiKey = opts.apiKey ?? process.env["FIREFLIES_API_KEY"];
|
|
2454
|
+
if (!apiKey) {
|
|
2455
|
+
console.error("Error: API key required. Set FIREFLIES_API_KEY or use --api-key");
|
|
2456
|
+
process.exit(1);
|
|
2457
|
+
}
|
|
2458
|
+
return new FirefliesClient({ apiKey });
|
|
2459
|
+
}
|
|
2460
|
+
function getOutputFormat(cmd) {
|
|
2461
|
+
const opts = cmd.optsWithGlobals();
|
|
2462
|
+
return opts.output ?? "json";
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
// src/cli/utils/error.ts
|
|
2466
|
+
function handleError(error) {
|
|
2467
|
+
if (error instanceof AuthenticationError) {
|
|
2468
|
+
console.error("Authentication failed: Check your API key");
|
|
2469
|
+
process.exit(1);
|
|
2470
|
+
}
|
|
2471
|
+
if (error instanceof NotFoundError) {
|
|
2472
|
+
console.error(`Not found: ${error.message}`);
|
|
2473
|
+
process.exit(1);
|
|
2474
|
+
}
|
|
2475
|
+
if (error instanceof RateLimitError) {
|
|
2476
|
+
console.error(`Rate limited: ${error.message}`);
|
|
2477
|
+
process.exit(1);
|
|
2478
|
+
}
|
|
2479
|
+
if (error instanceof ValidationError) {
|
|
2480
|
+
console.error(`Validation error: ${error.message}`);
|
|
2481
|
+
process.exit(1);
|
|
2482
|
+
}
|
|
2483
|
+
if (error instanceof FirefliesError) {
|
|
2484
|
+
console.error(`Error: ${error.message}`);
|
|
2485
|
+
process.exit(1);
|
|
2486
|
+
}
|
|
2487
|
+
if (error instanceof Error) {
|
|
2488
|
+
console.error(`Error: ${error.message}`);
|
|
2489
|
+
process.exit(1);
|
|
2490
|
+
}
|
|
2491
|
+
console.error("An unexpected error occurred");
|
|
2492
|
+
process.exit(1);
|
|
2493
|
+
}
|
|
2494
|
+
function withErrorHandling(fn) {
|
|
2495
|
+
return async (...args) => {
|
|
2496
|
+
try {
|
|
2497
|
+
await fn(...args);
|
|
2498
|
+
} catch (error) {
|
|
2499
|
+
handleError(error);
|
|
2500
|
+
}
|
|
2501
|
+
};
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
// src/cli/utils/output.ts
|
|
2505
|
+
function writeLine(line) {
|
|
2506
|
+
process.stdout.write(`${line}
|
|
2507
|
+
`);
|
|
2508
|
+
}
|
|
2509
|
+
function outputLine(data) {
|
|
2510
|
+
writeLine(JSON.stringify(data));
|
|
2511
|
+
}
|
|
2512
|
+
function output(data, format) {
|
|
2513
|
+
switch (format) {
|
|
2514
|
+
case "json":
|
|
2515
|
+
console.log(JSON.stringify(data, null, 2));
|
|
2516
|
+
break;
|
|
2517
|
+
case "jsonl":
|
|
2518
|
+
if (Array.isArray(data)) {
|
|
2519
|
+
for (const item of data) {
|
|
2520
|
+
writeLine(JSON.stringify(item));
|
|
2521
|
+
}
|
|
2522
|
+
} else {
|
|
2523
|
+
writeLine(JSON.stringify(data));
|
|
2524
|
+
}
|
|
2525
|
+
break;
|
|
2526
|
+
case "tsv":
|
|
2527
|
+
printTsv(data);
|
|
2528
|
+
break;
|
|
2529
|
+
case "table":
|
|
2530
|
+
if (Array.isArray(data)) {
|
|
2531
|
+
printTable(data);
|
|
2532
|
+
} else if (data && typeof data === "object") {
|
|
2533
|
+
printKeyValue(data);
|
|
2534
|
+
} else {
|
|
2535
|
+
console.log(data);
|
|
2536
|
+
}
|
|
2537
|
+
break;
|
|
2538
|
+
case "plain":
|
|
2539
|
+
if (typeof data === "string") {
|
|
2540
|
+
console.log(data);
|
|
2541
|
+
} else {
|
|
2542
|
+
console.log(JSON.stringify(data));
|
|
2543
|
+
}
|
|
2544
|
+
break;
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
function printTable(rows) {
|
|
2548
|
+
if (rows.length === 0) {
|
|
2549
|
+
console.log("(no data)");
|
|
2550
|
+
return;
|
|
2551
|
+
}
|
|
2552
|
+
const firstRow = rows[0];
|
|
2553
|
+
if (!firstRow) return;
|
|
2554
|
+
const keys = Object.keys(firstRow);
|
|
2555
|
+
const widths = {};
|
|
2556
|
+
for (const key of keys) {
|
|
2557
|
+
widths[key] = key.length;
|
|
2558
|
+
for (const row of rows) {
|
|
2559
|
+
const value = formatValue(row[key]);
|
|
2560
|
+
widths[key] = Math.max(widths[key] ?? 0, value.length);
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
const header = keys.map((k) => k.padEnd(widths[k] ?? 0)).join(" ");
|
|
2564
|
+
console.log(header);
|
|
2565
|
+
console.log(keys.map((k) => "-".repeat(widths[k] ?? 0)).join(" "));
|
|
2566
|
+
for (const row of rows) {
|
|
2567
|
+
const line = keys.map((k) => formatValue(row[k]).padEnd(widths[k] ?? 0)).join(" ");
|
|
2568
|
+
console.log(line);
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
function printKeyValue(obj) {
|
|
2572
|
+
const maxKeyLen = Math.max(...Object.keys(obj).map((k) => k.length));
|
|
2573
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2574
|
+
console.log(`${key.padEnd(maxKeyLen)} ${formatValue(value)}`);
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
function formatValue(value) {
|
|
2578
|
+
if (value === null || value === void 0) {
|
|
2579
|
+
return "";
|
|
2580
|
+
}
|
|
2581
|
+
if (typeof value === "object") {
|
|
2582
|
+
if (Array.isArray(value)) {
|
|
2583
|
+
return `[${value.length} items]`;
|
|
2584
|
+
}
|
|
2585
|
+
return "[object]";
|
|
2586
|
+
}
|
|
2587
|
+
return String(value);
|
|
2588
|
+
}
|
|
2589
|
+
function printTsv(data) {
|
|
2590
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
2591
|
+
return;
|
|
2592
|
+
}
|
|
2593
|
+
const firstRow = data[0];
|
|
2594
|
+
const keys = Object.keys(firstRow);
|
|
2595
|
+
writeLine(keys.join(" "));
|
|
2596
|
+
for (const row of data) {
|
|
2597
|
+
writeLine(keys.map((k) => formatTsvValue(row[k])).join(" "));
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
function formatTsvValue(value) {
|
|
2601
|
+
if (value === null || value === void 0) {
|
|
2602
|
+
return "";
|
|
2603
|
+
}
|
|
2604
|
+
if (typeof value === "object") {
|
|
2605
|
+
return JSON.stringify(value);
|
|
2606
|
+
}
|
|
2607
|
+
return String(value).replace(/\t/g, " ").replace(/\n/g, " ");
|
|
2608
|
+
}
|
|
2609
|
+
function outputSpeakerAnalytics(analytics, format) {
|
|
2610
|
+
if (format === "plain") {
|
|
2611
|
+
const mins = Math.round(analytics.totalDuration / 60);
|
|
2612
|
+
writeLine(
|
|
2613
|
+
`Meeting: ${mins} min, ${analytics.speakers.length} speakers, balance: ${analytics.balance}`
|
|
2614
|
+
);
|
|
2615
|
+
writeLine(`Dominant: ${analytics.dominantSpeaker} (${analytics.dominantSpeakerPercentage}%)`);
|
|
2616
|
+
writeLine("");
|
|
2617
|
+
for (const s of analytics.speakers) {
|
|
2618
|
+
writeLine(
|
|
2619
|
+
`${s.name}: ${Math.round(s.talkTime)}s (${s.talkTimePercentage}%) | ${s.wordCount} words | ${s.wordsPerMinute} wpm | ${s.turnCount} turns`
|
|
2620
|
+
);
|
|
2621
|
+
}
|
|
2622
|
+
return;
|
|
2623
|
+
}
|
|
2624
|
+
if (format === "table" || format === "tsv") {
|
|
2625
|
+
const rows = analytics.speakers.map((s) => ({
|
|
2626
|
+
name: s.name,
|
|
2627
|
+
talkTime: Math.round(s.talkTime),
|
|
2628
|
+
"talkTime%": s.talkTimePercentage,
|
|
2629
|
+
words: s.wordCount,
|
|
2630
|
+
wpm: s.wordsPerMinute,
|
|
2631
|
+
sentences: s.sentenceCount,
|
|
2632
|
+
turns: s.turnCount
|
|
2633
|
+
}));
|
|
2634
|
+
output(rows, format);
|
|
2635
|
+
return;
|
|
2636
|
+
}
|
|
2637
|
+
output(analytics, format);
|
|
2638
|
+
}
|
|
2639
|
+
function outputActionItems(result, format) {
|
|
2640
|
+
if (format === "plain") {
|
|
2641
|
+
const assignedCount = result.assignedItems;
|
|
2642
|
+
writeLine(`Action Items (${result.totalItems} total, ${assignedCount} assigned):`);
|
|
2643
|
+
writeLine("");
|
|
2644
|
+
for (const item of result.items) {
|
|
2645
|
+
writeLine(`${item.lineNumber}. ${item.text}`);
|
|
2646
|
+
const parts = [];
|
|
2647
|
+
if (item.assignee) {
|
|
2648
|
+
parts.push(`Assignee: ${item.assignee}`);
|
|
2649
|
+
}
|
|
2650
|
+
if (item.dueDate) {
|
|
2651
|
+
parts.push(`Due: ${item.dueDate}`);
|
|
2652
|
+
}
|
|
2653
|
+
if (parts.length > 0) {
|
|
2654
|
+
writeLine(` ${parts.join(" | ")}`);
|
|
2655
|
+
}
|
|
2656
|
+
writeLine("");
|
|
2657
|
+
}
|
|
2658
|
+
return;
|
|
2659
|
+
}
|
|
2660
|
+
if (format === "table" || format === "tsv") {
|
|
2661
|
+
const rows = result.items.map((item) => ({
|
|
2662
|
+
"#": item.lineNumber,
|
|
2663
|
+
text: item.text,
|
|
2664
|
+
assignee: item.assignee ?? "-",
|
|
2665
|
+
dueDate: item.dueDate ?? "-"
|
|
2666
|
+
}));
|
|
2667
|
+
output(rows, format);
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
output(result, format);
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
// src/cli/commands/ai-apps.ts
|
|
2674
|
+
function registerAiAppsCommand(program2) {
|
|
2675
|
+
const cmd = program2.command("ai-apps").description("AI Apps output");
|
|
2676
|
+
cmd.command("list").description("List AI App outputs").requiredOption("--transcript <id>", "Transcript ID (required)").option("--app <id>", "Filter by app ID").option("--limit <n>", "Max results (default: 10)", "10").action(
|
|
2677
|
+
withErrorHandling(async (opts) => {
|
|
2678
|
+
const client = getClient(program2);
|
|
2679
|
+
const format = getOutputFormat(program2);
|
|
2680
|
+
const apps = await client.aiApps.list({
|
|
2681
|
+
transcript_id: opts.transcript,
|
|
2682
|
+
app_id: opts.app,
|
|
2683
|
+
limit: Number.parseInt(opts.limit, 10)
|
|
2684
|
+
});
|
|
2685
|
+
const formatted = apps.map((a) => ({
|
|
2686
|
+
app_id: a.app_id,
|
|
2687
|
+
title: a.title,
|
|
2688
|
+
transcript_id: a.transcript_id,
|
|
2689
|
+
created_at: a.created_at,
|
|
2690
|
+
response: a.response?.substring(0, 100) + (a.response && a.response.length > 100 ? "..." : "")
|
|
2691
|
+
}));
|
|
2692
|
+
output(formatted, format);
|
|
2693
|
+
})
|
|
2694
|
+
);
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
// src/cli/utils/parse.ts
|
|
2698
|
+
function formatDuration(seconds) {
|
|
2699
|
+
if (!Number.isFinite(seconds) || seconds < 0) {
|
|
2700
|
+
return "0s";
|
|
2701
|
+
}
|
|
2702
|
+
const totalSeconds = Math.round(seconds);
|
|
2703
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
2704
|
+
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
2705
|
+
const secs = totalSeconds % 60;
|
|
2706
|
+
if (hours > 0) {
|
|
2707
|
+
if (minutes > 0) {
|
|
2708
|
+
return `${hours}h ${minutes}m`;
|
|
2709
|
+
}
|
|
2710
|
+
return `${hours}h`;
|
|
2711
|
+
}
|
|
2712
|
+
if (minutes > 0) {
|
|
2713
|
+
if (secs > 0) {
|
|
2714
|
+
return `${minutes}m ${secs}s`;
|
|
2715
|
+
}
|
|
2716
|
+
return `${minutes}m`;
|
|
2717
|
+
}
|
|
2718
|
+
return `${secs}s`;
|
|
2719
|
+
}
|
|
2720
|
+
function parseTime(value) {
|
|
2721
|
+
if (value.includes(":")) {
|
|
2722
|
+
const parts = value.split(":");
|
|
2723
|
+
if (parts.length === 2) {
|
|
2724
|
+
const [mins, secs] = parts;
|
|
2725
|
+
return Number.parseInt(mins ?? "0", 10) * 60 + Number.parseFloat(secs ?? "0");
|
|
2726
|
+
}
|
|
2727
|
+
if (parts.length === 3) {
|
|
2728
|
+
const [hours, mins, secs] = parts;
|
|
2729
|
+
return Number.parseInt(hours ?? "0", 10) * 3600 + Number.parseInt(mins ?? "0", 10) * 60 + Number.parseFloat(secs ?? "0");
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
return Number.parseFloat(value);
|
|
2733
|
+
}
|
|
2734
|
+
function parseAttendee(value) {
|
|
2735
|
+
if (value.includes(":")) {
|
|
2736
|
+
const colonIndex = value.indexOf(":");
|
|
2737
|
+
const displayName = value.slice(0, colonIndex);
|
|
2738
|
+
const email = value.slice(colonIndex + 1);
|
|
2739
|
+
return { displayName, email };
|
|
2740
|
+
}
|
|
2741
|
+
return { email: value };
|
|
2742
|
+
}
|
|
2743
|
+
var VALID_PRIVACIES = ["public", "team", "participants"];
|
|
2744
|
+
function validatePrivacy(value) {
|
|
2745
|
+
if (VALID_PRIVACIES.includes(value)) {
|
|
2746
|
+
return value;
|
|
2747
|
+
}
|
|
2748
|
+
return null;
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
// src/cli/commands/audio.ts
|
|
2752
|
+
function collectAttendees(value, previous) {
|
|
2753
|
+
return previous.concat([parseAttendee(value)]);
|
|
2754
|
+
}
|
|
2755
|
+
function registerAudioCommand(program2) {
|
|
2756
|
+
const cmd = program2.command("audio").description("Audio/video upload for transcription");
|
|
2757
|
+
cmd.command("upload <url>").description("Upload audio/video file for transcription").option("--title <title>", "Title for the transcript (max 256 chars)").option("--webhook <url>", "Webhook URL for completion notification").option("--language <code>", "Language code (e.g., en, de, fr)").option("--save-video", "Save video if applicable").option(
|
|
2758
|
+
"--attendee <name:email>",
|
|
2759
|
+
'Meeting attendee (repeatable, format: "Name:email@example.com" or just "email@example.com")',
|
|
2760
|
+
collectAttendees,
|
|
2761
|
+
[]
|
|
2762
|
+
).option("--reference-id <id>", "Custom reference ID for tracking (max 128 chars)").option("--bypass-size-check", "Allow files smaller than 50kb").action(
|
|
2763
|
+
withErrorHandling(async (url, opts) => {
|
|
2764
|
+
const client = getClient(program2);
|
|
2765
|
+
const format = getOutputFormat(program2);
|
|
2766
|
+
const result = await client.audio.upload({
|
|
2767
|
+
url,
|
|
2768
|
+
title: opts.title,
|
|
2769
|
+
webhook: opts.webhook,
|
|
2770
|
+
custom_language: opts.language,
|
|
2771
|
+
save_video: opts.saveVideo,
|
|
2772
|
+
attendees: opts.attendee.length > 0 ? opts.attendee : void 0,
|
|
2773
|
+
client_reference_id: opts.referenceId,
|
|
2774
|
+
bypass_size_check: opts.bypassSizeCheck
|
|
2775
|
+
});
|
|
2776
|
+
output(result, format);
|
|
2777
|
+
})
|
|
2778
|
+
);
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
// src/cli/commands/bites.ts
|
|
2782
|
+
function collectPrivacies(value, previous) {
|
|
2783
|
+
const validated = validatePrivacy(value);
|
|
2784
|
+
if (!validated) {
|
|
2785
|
+
console.error(`Invalid privacy value: ${value}. Must be one of: public, team, participants`);
|
|
2786
|
+
process.exit(1);
|
|
2787
|
+
}
|
|
2788
|
+
return previous.concat([validated]);
|
|
2789
|
+
}
|
|
2790
|
+
function registerBitesCommand(program2) {
|
|
2791
|
+
const cmd = program2.command("bites").description("Soundbites/clips");
|
|
2792
|
+
cmd.command("list").description("List bites").option("--transcript <id>", "Filter by transcript ID").option("--limit <n>", "Max results (default: 20)", "20").option("--mine", "Only my bites").option("--team", "All team bites").action(
|
|
2793
|
+
withErrorHandling(async (opts) => {
|
|
2794
|
+
const client = getClient(program2);
|
|
2795
|
+
const format = getOutputFormat(program2);
|
|
2796
|
+
const bites = await client.bites.list({
|
|
2797
|
+
transcript_id: opts.transcript,
|
|
2798
|
+
limit: Number.parseInt(opts.limit, 10),
|
|
2799
|
+
mine: opts.mine,
|
|
2800
|
+
my_team: opts.team
|
|
2801
|
+
});
|
|
2802
|
+
const formatted = bites.map((b) => ({
|
|
2803
|
+
id: b.id,
|
|
2804
|
+
name: b.name,
|
|
2805
|
+
transcript_id: b.transcript_id,
|
|
2806
|
+
status: b.status,
|
|
2807
|
+
start_time: b.start_time,
|
|
2808
|
+
end_time: b.end_time,
|
|
2809
|
+
created_at: b.created_at
|
|
2810
|
+
}));
|
|
2811
|
+
output(formatted, format);
|
|
2812
|
+
})
|
|
2813
|
+
);
|
|
2814
|
+
cmd.command("get <id>").description("Get bite details").action(
|
|
2815
|
+
withErrorHandling(async (id) => {
|
|
2816
|
+
const client = getClient(program2);
|
|
2817
|
+
const format = getOutputFormat(program2);
|
|
2818
|
+
const bite = await client.bites.get(id);
|
|
2819
|
+
output(bite, format);
|
|
2820
|
+
})
|
|
2821
|
+
);
|
|
2822
|
+
cmd.command("create").description("Create a bite/soundbite from a transcript").requiredOption("--transcript <id>", "Transcript ID (required)").requiredOption("--start <time>", "Start time in seconds or MM:SS format (required)").requiredOption("--end <time>", "End time in seconds or MM:SS format (required)").option("--name <name>", "Bite name (max 256 chars)").option("--media-type <type>", "Media type: video or audio").option("--summary <text>", "Summary (max 500 chars)").option(
|
|
2823
|
+
"--privacy <level>",
|
|
2824
|
+
"Privacy: public, team, or participants (repeatable)",
|
|
2825
|
+
collectPrivacies,
|
|
2826
|
+
[]
|
|
2827
|
+
).action(
|
|
2828
|
+
withErrorHandling(async (opts) => {
|
|
2829
|
+
const client = getClient(program2);
|
|
2830
|
+
const format = getOutputFormat(program2);
|
|
2831
|
+
const startTime = parseTime(opts.start);
|
|
2832
|
+
const endTime = parseTime(opts.end);
|
|
2833
|
+
if (endTime <= startTime) {
|
|
2834
|
+
console.error("Error: End time must be greater than start time");
|
|
2835
|
+
process.exit(1);
|
|
2836
|
+
}
|
|
2837
|
+
const result = await client.bites.create({
|
|
2838
|
+
transcript_id: opts.transcript,
|
|
2839
|
+
start_time: startTime,
|
|
2840
|
+
end_time: endTime,
|
|
2841
|
+
name: opts.name,
|
|
2842
|
+
media_type: opts.mediaType,
|
|
2843
|
+
summary: opts.summary,
|
|
2844
|
+
privacies: opts.privacy.length > 0 ? opts.privacy : void 0
|
|
2845
|
+
});
|
|
2846
|
+
output(result, format);
|
|
2847
|
+
})
|
|
2848
|
+
);
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
// src/helpers/markdown.ts
|
|
2852
|
+
var DEFAULT_OPTIONS2 = {
|
|
2853
|
+
includeMetadata: true,
|
|
2854
|
+
includeSummary: true,
|
|
2855
|
+
includeActionItems: true,
|
|
2856
|
+
actionItemFormat: "checkbox",
|
|
2857
|
+
includeTimestamps: false,
|
|
2858
|
+
speakerFormat: "bold",
|
|
2859
|
+
groupBySpeaker: true
|
|
2860
|
+
};
|
|
2861
|
+
async function transcriptToMarkdown(transcript, options = {}) {
|
|
2862
|
+
const opts = { ...DEFAULT_OPTIONS2, ...options };
|
|
2863
|
+
const sections = [];
|
|
2864
|
+
if (opts.includeMetadata) {
|
|
2865
|
+
sections.push(formatMetadata(transcript));
|
|
2866
|
+
}
|
|
2867
|
+
if (opts.includeSummary && transcript.summary) {
|
|
2868
|
+
sections.push(formatSummary(transcript.summary, opts));
|
|
2869
|
+
}
|
|
2870
|
+
if (transcript.sentences && transcript.sentences.length > 0) {
|
|
2871
|
+
sections.push(formatTranscript(transcript.sentences, opts));
|
|
2872
|
+
}
|
|
2873
|
+
const content = sections.join("\n\n---\n\n");
|
|
2874
|
+
await writeIfOutputPath(content, options.outputPath);
|
|
2875
|
+
return content;
|
|
2876
|
+
}
|
|
2877
|
+
function formatMetadata(transcript) {
|
|
2878
|
+
const lines = [`# ${transcript.title || "Untitled Meeting"}`];
|
|
2879
|
+
if (transcript.dateString) {
|
|
2880
|
+
lines.push(`
|
|
2881
|
+
**Date:** ${formatDate(transcript.dateString)}`);
|
|
2882
|
+
}
|
|
2883
|
+
const duration = calculateDuration(transcript);
|
|
2884
|
+
if (duration > 0) {
|
|
2885
|
+
lines.push(`**Duration:** ${formatDuration2(duration)}`);
|
|
2886
|
+
}
|
|
2887
|
+
const participants = getParticipantNames(transcript);
|
|
2888
|
+
if (participants.length > 0) {
|
|
2889
|
+
lines.push(`**Participants:** ${participants.join(", ")}`);
|
|
2890
|
+
}
|
|
2891
|
+
return lines.join("\n");
|
|
2892
|
+
}
|
|
2893
|
+
function calculateDuration(transcript) {
|
|
2894
|
+
if (transcript.sentences && transcript.sentences.length > 0) {
|
|
2895
|
+
const lastSentence = transcript.sentences[transcript.sentences.length - 1];
|
|
2896
|
+
if (lastSentence) {
|
|
2897
|
+
return parseFloat(lastSentence.end_time);
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
return transcript.duration || 0;
|
|
2901
|
+
}
|
|
2902
|
+
function formatSummary(summary, opts) {
|
|
2903
|
+
const sections = ["## Summary"];
|
|
2904
|
+
if (summary.gist) {
|
|
2905
|
+
sections.push("", summary.gist);
|
|
2906
|
+
}
|
|
2907
|
+
if (summary.bullet_gist) {
|
|
2908
|
+
const bullets = parseMultilineField(summary.bullet_gist);
|
|
2909
|
+
if (bullets.length > 0) {
|
|
2910
|
+
sections.push("", "### Key Points");
|
|
2911
|
+
sections.push(bullets.map((p) => `- ${p}`).join("\n"));
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
if (opts.includeActionItems && summary.action_items) {
|
|
2915
|
+
const items = parseMultilineField(summary.action_items);
|
|
2916
|
+
if (items.length > 0) {
|
|
2917
|
+
sections.push("", "### Action Items");
|
|
2918
|
+
const prefix = opts.actionItemFormat === "checkbox" ? "- [ ] " : "- ";
|
|
2919
|
+
sections.push(items.map((a) => `${prefix}${a}`).join("\n"));
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
return sections.join("\n");
|
|
2923
|
+
}
|
|
2924
|
+
function formatTranscript(sentences, opts) {
|
|
2925
|
+
const lines = ["## Transcript"];
|
|
2926
|
+
if (opts.groupBySpeaker) {
|
|
2927
|
+
const groups = groupSentencesBySpeaker(sentences);
|
|
2928
|
+
for (const group of groups) {
|
|
2929
|
+
lines.push("", formatSpeakerGroup(group, opts));
|
|
2930
|
+
}
|
|
2931
|
+
} else {
|
|
2932
|
+
for (const sentence of sentences) {
|
|
2933
|
+
lines.push("", formatSentence(sentence, opts));
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
return lines.join("\n");
|
|
2937
|
+
}
|
|
2938
|
+
function groupSentencesBySpeaker(sentences) {
|
|
2939
|
+
const groups = [];
|
|
2940
|
+
let current = null;
|
|
2941
|
+
for (const sentence of sentences) {
|
|
2942
|
+
if (!current || current.speakerName !== sentence.speaker_name) {
|
|
2943
|
+
current = { speakerName: sentence.speaker_name, sentences: [] };
|
|
2944
|
+
groups.push(current);
|
|
2945
|
+
}
|
|
2946
|
+
current.sentences.push(sentence);
|
|
2947
|
+
}
|
|
2948
|
+
return groups;
|
|
2949
|
+
}
|
|
2950
|
+
function formatSpeakerGroup(group, opts) {
|
|
2951
|
+
const speaker = formatSpeakerName(group.speakerName, opts.speakerFormat);
|
|
2952
|
+
const text = group.sentences.map((s) => s.text).join(" ");
|
|
2953
|
+
const firstSentence = group.sentences[0];
|
|
2954
|
+
if (opts.includeTimestamps && firstSentence) {
|
|
2955
|
+
const timestamp = formatTimestamp(firstSentence.start_time);
|
|
2956
|
+
return `${timestamp} ${speaker} ${text}`;
|
|
2957
|
+
}
|
|
2958
|
+
return `${speaker} ${text}`;
|
|
2959
|
+
}
|
|
2960
|
+
function formatSentence(sentence, opts) {
|
|
2961
|
+
const speaker = formatSpeakerName(sentence.speaker_name, opts.speakerFormat);
|
|
2962
|
+
if (opts.includeTimestamps) {
|
|
2963
|
+
const timestamp = formatTimestamp(sentence.start_time);
|
|
2964
|
+
return `${timestamp} ${speaker} ${sentence.text}`;
|
|
2965
|
+
}
|
|
2966
|
+
return `${speaker} ${sentence.text}`;
|
|
2967
|
+
}
|
|
2968
|
+
function formatSpeakerName(name, format) {
|
|
2969
|
+
switch (format) {
|
|
2970
|
+
case "bold":
|
|
2971
|
+
return `**${name}:**`;
|
|
2972
|
+
case "plain":
|
|
2973
|
+
return `${name}:`;
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
function formatTimestamp(startTime) {
|
|
2977
|
+
const seconds = parseFloat(startTime);
|
|
2978
|
+
const mins = Math.floor(seconds / 60);
|
|
2979
|
+
const secs = Math.floor(seconds % 60);
|
|
2980
|
+
return `[${mins}:${secs.toString().padStart(2, "0")}]`;
|
|
2981
|
+
}
|
|
2982
|
+
function formatDuration2(seconds) {
|
|
2983
|
+
const hours = Math.floor(seconds / 3600);
|
|
2984
|
+
const mins = Math.floor(seconds % 3600 / 60);
|
|
2985
|
+
if (hours > 0) {
|
|
2986
|
+
return `${hours}h ${mins}m`;
|
|
2987
|
+
}
|
|
2988
|
+
return `${mins} minutes`;
|
|
2989
|
+
}
|
|
2990
|
+
function formatDate(isoString) {
|
|
2991
|
+
return new Date(isoString).toLocaleDateString("en-US", {
|
|
2992
|
+
weekday: "long",
|
|
2993
|
+
year: "numeric",
|
|
2994
|
+
month: "long",
|
|
2995
|
+
day: "numeric"
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
function getParticipantNames(transcript) {
|
|
2999
|
+
if (transcript.meeting_attendees?.length) {
|
|
3000
|
+
return transcript.meeting_attendees.map((a) => a.displayName || a.name || a.email).filter(Boolean);
|
|
3001
|
+
}
|
|
3002
|
+
return transcript.speakers?.map((s) => s.name) || [];
|
|
3003
|
+
}
|
|
3004
|
+
function parseMultilineField(value) {
|
|
3005
|
+
return value.split(/\n/).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
3006
|
+
}
|
|
3007
|
+
async function writeIfOutputPath(content, outputPath) {
|
|
3008
|
+
if (outputPath) {
|
|
3009
|
+
const { writeFile: writeFile2 } = await import('fs/promises');
|
|
3010
|
+
await writeFile2(outputPath, content, "utf-8");
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
|
|
3014
|
+
// src/cli/commands/export.ts
|
|
3015
|
+
function registerExportCommand(program2) {
|
|
3016
|
+
program2.command("export <transcript-id> [output-file]").description("Export transcript to markdown").option("--no-summary", "Exclude summary section").option("--no-timestamps", "Exclude timestamps").option("--format <format>", "Output format: markdown, json", "markdown").action(
|
|
3017
|
+
withErrorHandling(async (transcriptId, outputFile, opts) => {
|
|
3018
|
+
const client = getClient(program2);
|
|
3019
|
+
const cliFormat = getOutputFormat(program2);
|
|
3020
|
+
const transcript = await client.transcripts.get(transcriptId);
|
|
3021
|
+
if (opts.format === "json") {
|
|
3022
|
+
if (outputFile) {
|
|
3023
|
+
await promises.writeFile(outputFile, JSON.stringify(transcript, null, 2), "utf-8");
|
|
3024
|
+
console.log(`Exported to ${outputFile}`);
|
|
3025
|
+
} else {
|
|
3026
|
+
output(transcript, cliFormat);
|
|
3027
|
+
}
|
|
3028
|
+
return;
|
|
3029
|
+
}
|
|
3030
|
+
const markdown = await transcriptToMarkdown(transcript, {
|
|
3031
|
+
includeSummary: opts.summary,
|
|
3032
|
+
includeTimestamps: opts.timestamps
|
|
3033
|
+
});
|
|
3034
|
+
if (outputFile) {
|
|
3035
|
+
await promises.writeFile(outputFile, markdown, "utf-8");
|
|
3036
|
+
console.log(`Exported to ${outputFile}`);
|
|
3037
|
+
} else {
|
|
3038
|
+
console.log(markdown);
|
|
3039
|
+
}
|
|
3040
|
+
})
|
|
3041
|
+
);
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
// src/cli/utils/date.ts
|
|
3045
|
+
function daysAgo(days) {
|
|
3046
|
+
const date = /* @__PURE__ */ new Date();
|
|
3047
|
+
date.setDate(date.getDate() - days);
|
|
3048
|
+
date.setHours(0, 0, 0, 0);
|
|
3049
|
+
return date.toISOString();
|
|
3050
|
+
}
|
|
3051
|
+
function startOfToday() {
|
|
3052
|
+
const date = /* @__PURE__ */ new Date();
|
|
3053
|
+
date.setHours(0, 0, 0, 0);
|
|
3054
|
+
return date.toISOString();
|
|
3055
|
+
}
|
|
3056
|
+
function resolveDateRange(opts) {
|
|
3057
|
+
if (opts.today) {
|
|
3058
|
+
return { fromDate: startOfToday() };
|
|
3059
|
+
}
|
|
3060
|
+
if (opts.yesterday) {
|
|
3061
|
+
return { fromDate: daysAgo(1), toDate: startOfToday() };
|
|
3062
|
+
}
|
|
3063
|
+
if (opts.lastWeek) {
|
|
3064
|
+
return { fromDate: daysAgo(7) };
|
|
3065
|
+
}
|
|
3066
|
+
if (opts.lastMonth) {
|
|
3067
|
+
return { fromDate: daysAgo(30) };
|
|
3068
|
+
}
|
|
3069
|
+
if (opts.days) {
|
|
3070
|
+
const numDays = Number.parseInt(opts.days, 10);
|
|
3071
|
+
if (!Number.isNaN(numDays) && numDays > 0) {
|
|
3072
|
+
return { fromDate: daysAgo(numDays) };
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
return { fromDate: opts.from, toDate: opts.to };
|
|
3076
|
+
}
|
|
3077
|
+
|
|
3078
|
+
// src/cli/commands/insights.ts
|
|
3079
|
+
function collect(value, previous) {
|
|
3080
|
+
return previous.concat([value]);
|
|
3081
|
+
}
|
|
3082
|
+
function registerInsightsCommand(program2) {
|
|
3083
|
+
program2.command("insights").description("Get aggregate meeting insights").option("--from <date>", "From date (YYYY-MM-DD or ISO 8601)").option("--to <date>", "To date (YYYY-MM-DD or ISO 8601)").option("--today", "Meetings from today").option("--yesterday", "Meetings from yesterday").option("--last-week", "Meetings from last 7 days").option("--last-month", "Meetings from last 30 days").option("--days <n>", "Meetings from last N days").option("--mine", "Only my transcripts").option("--organizer <email>", "Filter by organizer email (repeatable)", collect, []).option("--participant <email>", "Filter by participant email (repeatable)", collect, []).option("--user-id <id>", "Filter by user ID").option("--channel <id>", "Filter by channel ID").option("--limit <n>", "Max transcripts to analyze").option("--external", "Only meetings with external (non-company) participants").option("--speaker <name>", "Only stats for specific speaker(s) (repeatable)", collect, []).option("--group-by <period>", "Group by: day, week, month").option("--top <n>", "Top N speakers/participants (default: 10)").action(
|
|
3084
|
+
withErrorHandling(async (opts) => {
|
|
3085
|
+
const client = getClient(program2);
|
|
3086
|
+
const format = getOutputFormat(program2);
|
|
3087
|
+
const { fromDate, toDate } = resolveDateRange(opts);
|
|
3088
|
+
const insights = await client.transcripts.insights(
|
|
3089
|
+
buildInsightsParams(opts, fromDate, toDate)
|
|
3090
|
+
);
|
|
3091
|
+
outputInsights(insights, format);
|
|
3092
|
+
})
|
|
3093
|
+
);
|
|
3094
|
+
}
|
|
3095
|
+
function buildInsightsParams(opts, fromDate, toDate) {
|
|
3096
|
+
const topCount = opts.top ? Number.parseInt(opts.top, 10) : void 0;
|
|
3097
|
+
return {
|
|
3098
|
+
fromDate,
|
|
3099
|
+
toDate,
|
|
3100
|
+
mine: opts.mine,
|
|
3101
|
+
organizers: opts.organizer.length > 0 ? opts.organizer : void 0,
|
|
3102
|
+
participants: opts.participant.length > 0 ? opts.participant : void 0,
|
|
3103
|
+
user_id: opts.userId,
|
|
3104
|
+
channel_id: opts.channel,
|
|
3105
|
+
limit: opts.limit ? Number.parseInt(opts.limit, 10) : void 0,
|
|
3106
|
+
external: opts.external,
|
|
3107
|
+
speakers: opts.speaker.length > 0 ? opts.speaker : void 0,
|
|
3108
|
+
groupBy: opts.groupBy,
|
|
3109
|
+
topSpeakersCount: topCount,
|
|
3110
|
+
topParticipantsCount: topCount
|
|
3111
|
+
};
|
|
3112
|
+
}
|
|
3113
|
+
function outputInsights(insights, format) {
|
|
3114
|
+
if (format === "plain") {
|
|
3115
|
+
outputInsightsPlain(insights);
|
|
3116
|
+
return;
|
|
3117
|
+
}
|
|
3118
|
+
if (format === "table") {
|
|
3119
|
+
outputInsightsTable(insights);
|
|
3120
|
+
return;
|
|
3121
|
+
}
|
|
3122
|
+
output(insights, format);
|
|
3123
|
+
}
|
|
3124
|
+
function outputInsightsPlain(insights) {
|
|
3125
|
+
outputHeader(insights);
|
|
3126
|
+
outputSummaryStats(insights);
|
|
3127
|
+
outputDayOfWeekStats(insights.byDayOfWeek);
|
|
3128
|
+
outputTimeGroupStats(insights.byTimeGroup);
|
|
3129
|
+
outputParticipantStats(insights);
|
|
3130
|
+
outputSpeakerStats(insights);
|
|
3131
|
+
}
|
|
3132
|
+
function outputHeader(insights) {
|
|
3133
|
+
const dateRange = formatDateRangeHeader(insights.earliestMeeting, insights.latestMeeting);
|
|
3134
|
+
writeLine(`Meeting Insights (${dateRange})`);
|
|
3135
|
+
writeLine("=".repeat(50));
|
|
3136
|
+
writeLine("");
|
|
3137
|
+
}
|
|
3138
|
+
function outputSummaryStats(insights) {
|
|
3139
|
+
writeLine(`Total meetings: ${insights.totalMeetings}`);
|
|
3140
|
+
writeLine(`Total duration: ${formatDuration(insights.totalDurationMinutes * 60)}`);
|
|
3141
|
+
writeLine(`Average duration: ${Math.round(insights.averageDurationMinutes)} min`);
|
|
3142
|
+
writeLine("");
|
|
3143
|
+
}
|
|
3144
|
+
function outputDayOfWeekStats(byDayOfWeek) {
|
|
3145
|
+
writeLine("Meetings by Day:");
|
|
3146
|
+
const sortedDays = getSortedDays(byDayOfWeek);
|
|
3147
|
+
for (const { day, stats } of sortedDays) {
|
|
3148
|
+
if (stats.count > 0) {
|
|
3149
|
+
const duration = formatDuration(stats.totalMinutes * 60);
|
|
3150
|
+
writeLine(` ${capitalize(day)}: ${stats.count} meetings (${duration})`);
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
writeLine("");
|
|
3154
|
+
}
|
|
3155
|
+
function outputTimeGroupStats(byTimeGroup) {
|
|
3156
|
+
if (!byTimeGroup || byTimeGroup.length === 0) return;
|
|
3157
|
+
writeLine("By Period:");
|
|
3158
|
+
for (const group of byTimeGroup) {
|
|
3159
|
+
const duration = formatDuration(group.totalMinutes * 60);
|
|
3160
|
+
const avg = Math.round(group.averageMinutes);
|
|
3161
|
+
writeLine(` ${group.period}: ${group.count} meetings (${duration}, avg ${avg} min)`);
|
|
3162
|
+
}
|
|
3163
|
+
writeLine("");
|
|
3164
|
+
}
|
|
3165
|
+
function outputParticipantStats(insights) {
|
|
3166
|
+
const avgPart = insights.averageParticipantsPerMeeting.toFixed(1);
|
|
3167
|
+
writeLine(
|
|
3168
|
+
`Participants: ${insights.totalUniqueParticipants} unique (avg ${avgPart} per meeting)`
|
|
3169
|
+
);
|
|
3170
|
+
if (insights.topParticipants.length > 0) {
|
|
3171
|
+
writeLine("Top Participants:");
|
|
3172
|
+
outputTopParticipants(insights.topParticipants.slice(0, 5));
|
|
3173
|
+
}
|
|
3174
|
+
writeLine("");
|
|
3175
|
+
}
|
|
3176
|
+
function outputTopParticipants(participants) {
|
|
3177
|
+
for (let i = 0; i < participants.length; i++) {
|
|
3178
|
+
const p = participants[i];
|
|
3179
|
+
if (p) {
|
|
3180
|
+
writeLine(` ${i + 1}. ${p.email} (${p.meetingCount} meetings)`);
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
function outputSpeakerStats(insights) {
|
|
3185
|
+
writeLine(`Speakers: ${insights.totalUniqueSpeakers} unique`);
|
|
3186
|
+
if (insights.topSpeakers.length > 0) {
|
|
3187
|
+
writeLine("Top Speakers:");
|
|
3188
|
+
outputTopSpeakers(insights.topSpeakers.slice(0, 5));
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
function outputTopSpeakers(speakers) {
|
|
3192
|
+
for (let i = 0; i < speakers.length; i++) {
|
|
3193
|
+
const s = speakers[i];
|
|
3194
|
+
if (s) {
|
|
3195
|
+
const talkTime = formatDuration(s.totalTalkTimeSeconds);
|
|
3196
|
+
writeLine(` ${i + 1}. ${s.name} (${s.meetingCount} meetings, ${talkTime} talk time)`);
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
function outputInsightsTable(insights) {
|
|
3201
|
+
const summary = {
|
|
3202
|
+
totalMeetings: insights.totalMeetings,
|
|
3203
|
+
totalDuration: formatDuration(insights.totalDurationMinutes * 60),
|
|
3204
|
+
avgDuration: `${Math.round(insights.averageDurationMinutes)} min`,
|
|
3205
|
+
dateRange: `${insights.earliestMeeting} to ${insights.latestMeeting}`,
|
|
3206
|
+
uniqueParticipants: insights.totalUniqueParticipants,
|
|
3207
|
+
avgParticipants: insights.averageParticipantsPerMeeting.toFixed(1),
|
|
3208
|
+
uniqueSpeakers: insights.totalUniqueSpeakers
|
|
3209
|
+
};
|
|
3210
|
+
output(summary, "table");
|
|
3211
|
+
}
|
|
3212
|
+
function formatDateRangeHeader(earliest, latest) {
|
|
3213
|
+
if (!earliest && !latest) return "All time";
|
|
3214
|
+
if (earliest === latest) return formatReadableDate(earliest);
|
|
3215
|
+
return `${formatReadableDate(earliest)} - ${formatReadableDate(latest)}`;
|
|
3216
|
+
}
|
|
3217
|
+
function formatReadableDate(dateStr) {
|
|
3218
|
+
if (!dateStr) return "Unknown";
|
|
3219
|
+
const date = new Date(dateStr);
|
|
3220
|
+
return date.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" });
|
|
3221
|
+
}
|
|
3222
|
+
function getSortedDays(byDayOfWeek) {
|
|
3223
|
+
const dayOrder = [
|
|
3224
|
+
"monday",
|
|
3225
|
+
"tuesday",
|
|
3226
|
+
"wednesday",
|
|
3227
|
+
"thursday",
|
|
3228
|
+
"friday",
|
|
3229
|
+
"saturday",
|
|
3230
|
+
"sunday"
|
|
3231
|
+
];
|
|
3232
|
+
return dayOrder.map((day) => ({ day, stats: byDayOfWeek[day] })).sort((a, b) => b.stats.count - a.stats.count);
|
|
3233
|
+
}
|
|
3234
|
+
function capitalize(str) {
|
|
3235
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
// src/cli/commands/meetings.ts
|
|
3239
|
+
function registerMeetingsCommand(program2) {
|
|
3240
|
+
const cmd = program2.command("meetings").description("Active meetings and bot control");
|
|
3241
|
+
cmd.command("list").description("List active meetings").option("--state <state>", "Filter by state: active, paused").option("--email <email>", "Filter by user email (admin only)").action(
|
|
3242
|
+
withErrorHandling(async (opts) => {
|
|
3243
|
+
const client = getClient(program2);
|
|
3244
|
+
const format = getOutputFormat(program2);
|
|
3245
|
+
const states = opts.state ? [opts.state] : void 0;
|
|
3246
|
+
const meetings = await client.meetings.active({
|
|
3247
|
+
states,
|
|
3248
|
+
email: opts.email
|
|
3249
|
+
});
|
|
3250
|
+
const formatted = meetings.map((m) => ({
|
|
3251
|
+
id: m.id,
|
|
3252
|
+
title: m.title,
|
|
3253
|
+
organizer: m.organizer_email,
|
|
3254
|
+
state: m.state,
|
|
3255
|
+
start_time: m.start_time
|
|
3256
|
+
}));
|
|
3257
|
+
output(formatted, format);
|
|
3258
|
+
})
|
|
3259
|
+
);
|
|
3260
|
+
cmd.command("add-bot <url>").description("Add Fireflies bot to a meeting").option("--title <title>", "Meeting title").option("--duration <min>", "Max duration in minutes (15-120)", "60").option("--password <password>", "Meeting password").option("--language <lang>", "Language code").action(
|
|
3261
|
+
withErrorHandling(async (url, opts) => {
|
|
3262
|
+
const client = getClient(program2);
|
|
3263
|
+
const format = getOutputFormat(program2);
|
|
3264
|
+
const result = await client.meetings.addBot({
|
|
3265
|
+
meeting_link: url,
|
|
3266
|
+
title: opts.title,
|
|
3267
|
+
duration: Number.parseInt(opts.duration, 10),
|
|
3268
|
+
password: opts.password,
|
|
3269
|
+
language: opts.language
|
|
3270
|
+
});
|
|
3271
|
+
output(result, format);
|
|
3272
|
+
})
|
|
3273
|
+
);
|
|
3274
|
+
}
|
|
3275
|
+
|
|
3276
|
+
// src/cli/commands/realtime.ts
|
|
3277
|
+
function registerRealtimeCommand(program2) {
|
|
3278
|
+
program2.command("realtime <meeting-id>").description("Stream live transcription to stdout").action(
|
|
3279
|
+
withErrorHandling(async (meetingId) => {
|
|
3280
|
+
const client = getClient(program2);
|
|
3281
|
+
const format = getOutputFormat(program2);
|
|
3282
|
+
let closing = false;
|
|
3283
|
+
const shutdown = () => {
|
|
3284
|
+
if (!closing) {
|
|
3285
|
+
closing = true;
|
|
3286
|
+
process.exit(0);
|
|
3287
|
+
}
|
|
3288
|
+
};
|
|
3289
|
+
process.on("SIGINT", shutdown);
|
|
3290
|
+
process.on("SIGTERM", shutdown);
|
|
3291
|
+
for await (const chunk of client.realtime.stream(meetingId)) {
|
|
3292
|
+
if (closing) break;
|
|
3293
|
+
if (format === "plain" || format === "table") {
|
|
3294
|
+
writeLine(`[${chunk.speaker_name}]: ${chunk.text}`);
|
|
3295
|
+
} else {
|
|
3296
|
+
outputLine(chunk);
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
})
|
|
3300
|
+
);
|
|
3301
|
+
}
|
|
3302
|
+
|
|
3303
|
+
// src/cli/commands/search.ts
|
|
3304
|
+
function collect2(value, previous) {
|
|
3305
|
+
return previous.concat([value]);
|
|
3306
|
+
}
|
|
3307
|
+
function formatTime(seconds) {
|
|
3308
|
+
const mins = Math.floor(seconds / 60);
|
|
3309
|
+
const secs = Math.floor(seconds % 60);
|
|
3310
|
+
return `${mins}:${secs.toString().padStart(2, "0")}`;
|
|
3311
|
+
}
|
|
3312
|
+
function buildFlags(match) {
|
|
3313
|
+
const flags = [];
|
|
3314
|
+
if (match.sentence.isQuestion) flags.push("Q");
|
|
3315
|
+
if (match.sentence.isTask) flags.push("T");
|
|
3316
|
+
return flags.length > 0 ? ` [${flags.join(",")}]` : "";
|
|
3317
|
+
}
|
|
3318
|
+
function outputMatchPlain(match) {
|
|
3319
|
+
for (const ctx of match.context.before) {
|
|
3320
|
+
writeLine(` [${ctx.speakerName}] ${ctx.text}`);
|
|
3321
|
+
}
|
|
3322
|
+
const time = formatTime(match.sentence.startTime);
|
|
3323
|
+
const flagStr = buildFlags(match);
|
|
3324
|
+
writeLine(`> [${time}] [${match.sentence.speakerName}]${flagStr} ${match.sentence.text}`);
|
|
3325
|
+
for (const ctx of match.context.after) {
|
|
3326
|
+
writeLine(` [${ctx.speakerName}] ${ctx.text}`);
|
|
3327
|
+
}
|
|
3328
|
+
writeLine("");
|
|
3329
|
+
}
|
|
3330
|
+
function outputPlain(results) {
|
|
3331
|
+
writeLine(
|
|
3332
|
+
`Found ${results.totalMatches} matches in ${results.transcriptsWithMatches}/${results.transcriptsSearched} transcripts`
|
|
3333
|
+
);
|
|
3334
|
+
writeLine("");
|
|
3335
|
+
let currentTranscript = "";
|
|
3336
|
+
for (const match of results.matches) {
|
|
3337
|
+
if (match.transcriptId !== currentTranscript) {
|
|
3338
|
+
currentTranscript = match.transcriptId;
|
|
3339
|
+
writeLine(`--- ${match.transcriptTitle} (${match.transcriptDate.split("T")[0]}) ---`);
|
|
3340
|
+
writeLine(` ${match.transcriptUrl}`);
|
|
3341
|
+
writeLine("");
|
|
3342
|
+
}
|
|
3343
|
+
outputMatchPlain(match);
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
function outputTabular(results, format) {
|
|
3347
|
+
const rows = results.matches.map((match) => ({
|
|
3348
|
+
transcript: match.transcriptTitle.slice(0, 40),
|
|
3349
|
+
date: match.transcriptDate.split("T")[0],
|
|
3350
|
+
time: formatTime(match.sentence.startTime),
|
|
3351
|
+
speaker: match.sentence.speakerName,
|
|
3352
|
+
text: match.sentence.text.slice(0, 80),
|
|
3353
|
+
isQuestion: match.sentence.isQuestion ? "Y" : "",
|
|
3354
|
+
isTask: match.sentence.isTask ? "Y" : ""
|
|
3355
|
+
}));
|
|
3356
|
+
output(rows, format);
|
|
3357
|
+
}
|
|
3358
|
+
function outputSearchResults(results, format) {
|
|
3359
|
+
if (format === "plain") {
|
|
3360
|
+
outputPlain(results);
|
|
3361
|
+
return;
|
|
3362
|
+
}
|
|
3363
|
+
if (format === "table" || format === "tsv") {
|
|
3364
|
+
outputTabular(results, format);
|
|
3365
|
+
return;
|
|
3366
|
+
}
|
|
3367
|
+
output(results, format);
|
|
3368
|
+
}
|
|
3369
|
+
function registerSearchCommand(program2) {
|
|
3370
|
+
program2.command("search <query>").description("Search across transcripts for matching sentences").option("--speaker <name>", "Filter results by speaker name (repeatable)", collect2, []).option("--questions", "Only show sentences marked as questions").option("--tasks", "Only show sentences marked as tasks/action items").option("--context <n>", "Number of context sentences (default: 1)", "1").option("--case-sensitive", "Match case when searching").option(
|
|
3371
|
+
"--scope <scope>",
|
|
3372
|
+
"Search scope: title, sentences, all (default: sentences)",
|
|
3373
|
+
"sentences"
|
|
3374
|
+
).option("--from <date>", "From date (YYYY-MM-DD or ISO 8601)").option("--to <date>", "To date (YYYY-MM-DD or ISO 8601)").option("--today", "Search transcripts from today").option("--yesterday", "Search transcripts from yesterday").option("--last-week", "Search transcripts from last 7 days").option("--last-month", "Search transcripts from last 30 days").option("--days <n>", "Search transcripts from last N days").option("--mine", "Only my transcripts").option("--organizer <email>", "Filter by organizer email (repeatable)", collect2, []).option("--participant <email>", "Filter by participant email (repeatable)", collect2, []).option("--limit <n>", "Max transcripts to search").action(
|
|
3375
|
+
withErrorHandling(async (query, opts) => {
|
|
3376
|
+
const client = getClient(program2);
|
|
3377
|
+
const format = getOutputFormat(program2);
|
|
3378
|
+
const { fromDate, toDate } = resolveDateRange(opts);
|
|
3379
|
+
const results = await client.transcripts.search(query, {
|
|
3380
|
+
caseSensitive: opts.caseSensitive,
|
|
3381
|
+
scope: opts.scope,
|
|
3382
|
+
speakers: opts.speaker.length > 0 ? opts.speaker : void 0,
|
|
3383
|
+
filterQuestions: opts.questions,
|
|
3384
|
+
filterTasks: opts.tasks,
|
|
3385
|
+
contextLines: Number.parseInt(opts.context, 10),
|
|
3386
|
+
fromDate,
|
|
3387
|
+
toDate,
|
|
3388
|
+
mine: opts.mine,
|
|
3389
|
+
organizers: opts.organizer.length > 0 ? opts.organizer : void 0,
|
|
3390
|
+
participants: opts.participant.length > 0 ? opts.participant : void 0,
|
|
3391
|
+
limit: opts.limit ? Number.parseInt(opts.limit, 10) : void 0
|
|
3392
|
+
});
|
|
3393
|
+
outputSearchResults(results, format);
|
|
3394
|
+
})
|
|
3395
|
+
);
|
|
3396
|
+
}
|
|
3397
|
+
|
|
3398
|
+
// src/helpers/normalize.ts
|
|
3399
|
+
var DEFAULT_OPTIONS3 = {
|
|
3400
|
+
timeUnit: "seconds",
|
|
3401
|
+
includeRawData: false,
|
|
3402
|
+
includeAIFilters: true,
|
|
3403
|
+
includeSummary: true,
|
|
3404
|
+
resolveSpeakerName: (speaker) => speaker.name,
|
|
3405
|
+
enrichParticipant: () => ({})
|
|
3406
|
+
};
|
|
3407
|
+
function normalizeTranscript2(transcript, options) {
|
|
3408
|
+
const opts = { ...DEFAULT_OPTIONS3, ...options };
|
|
3409
|
+
const speakers = normalizeSpeakers(transcript.speakers ?? [], transcript, opts);
|
|
3410
|
+
const sentences = normalizeSentences(transcript.sentences ?? [], opts);
|
|
3411
|
+
const participants = normalizeParticipants(transcript, opts);
|
|
3412
|
+
const summary = opts.includeSummary ? normalizeSummary(transcript.summary) : void 0;
|
|
3413
|
+
const attendees = normalizeAttendees(transcript.meeting_attendance ?? []);
|
|
3414
|
+
const channels = normalizeChannels(transcript.channels ?? []);
|
|
3415
|
+
const analytics = normalizeAnalytics(transcript.analytics);
|
|
3416
|
+
return {
|
|
3417
|
+
id: `fireflies:${transcript.id}`,
|
|
3418
|
+
title: transcript.title,
|
|
3419
|
+
date: new Date(transcript.date),
|
|
3420
|
+
duration: transcript.duration * 60,
|
|
3421
|
+
// minutes → seconds
|
|
3422
|
+
url: transcript.transcript_url,
|
|
3423
|
+
speakers,
|
|
3424
|
+
sentences,
|
|
3425
|
+
participants,
|
|
3426
|
+
summary,
|
|
3427
|
+
attendees,
|
|
3428
|
+
channels,
|
|
3429
|
+
analytics,
|
|
3430
|
+
source: {
|
|
3431
|
+
provider: "fireflies",
|
|
3432
|
+
originalId: transcript.id,
|
|
3433
|
+
rawData: opts.includeRawData ? transcript : void 0
|
|
3434
|
+
}
|
|
3435
|
+
};
|
|
3436
|
+
}
|
|
3437
|
+
function normalizeSpeakers(speakers, transcript, opts) {
|
|
3438
|
+
return speakers.map((speaker) => ({
|
|
3439
|
+
id: speaker.id,
|
|
3440
|
+
name: opts.resolveSpeakerName(speaker, transcript)
|
|
3441
|
+
}));
|
|
3442
|
+
}
|
|
3443
|
+
function normalizeSentences(sentences, opts) {
|
|
3444
|
+
const timeMultiplier = opts.timeUnit === "milliseconds" ? 1e3 : 1;
|
|
3445
|
+
return sentences.map((sentence) => {
|
|
3446
|
+
const normalized = {
|
|
3447
|
+
index: sentence.index,
|
|
3448
|
+
speakerId: sentence.speaker_id,
|
|
3449
|
+
speakerName: sentence.speaker_name,
|
|
3450
|
+
text: sentence.text,
|
|
3451
|
+
rawText: sentence.raw_text,
|
|
3452
|
+
startTime: parseTime2(sentence.start_time) * timeMultiplier,
|
|
3453
|
+
endTime: parseTime2(sentence.end_time) * timeMultiplier
|
|
3454
|
+
};
|
|
3455
|
+
if (opts.includeAIFilters && sentence.ai_filters) {
|
|
3456
|
+
const sentiment = mapSentiment(sentence.ai_filters.sentiment);
|
|
3457
|
+
if (sentiment) {
|
|
3458
|
+
normalized.sentiment = sentiment;
|
|
3459
|
+
}
|
|
3460
|
+
if (sentence.ai_filters.question) {
|
|
3461
|
+
normalized.isQuestion = true;
|
|
3462
|
+
}
|
|
3463
|
+
if (sentence.ai_filters.task) {
|
|
3464
|
+
normalized.isActionItem = true;
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
return normalized;
|
|
3468
|
+
});
|
|
3469
|
+
}
|
|
3470
|
+
function parseTime2(timeStr) {
|
|
3471
|
+
const parsed = Number.parseFloat(timeStr);
|
|
3472
|
+
return Number.isNaN(parsed) ? 0 : parsed;
|
|
3473
|
+
}
|
|
3474
|
+
function mapSentiment(sentiment) {
|
|
3475
|
+
if (!sentiment) return void 0;
|
|
3476
|
+
const lower = sentiment.toLowerCase();
|
|
3477
|
+
if (lower === "positive") return "positive";
|
|
3478
|
+
if (lower === "negative") return "negative";
|
|
3479
|
+
if (lower === "neutral") return "neutral";
|
|
3480
|
+
return void 0;
|
|
3481
|
+
}
|
|
3482
|
+
function normalizeParticipants(transcript, opts) {
|
|
3483
|
+
const participants = transcript.participants ?? [];
|
|
3484
|
+
const attendeeMap = /* @__PURE__ */ new Map();
|
|
3485
|
+
for (const attendee of transcript.meeting_attendees ?? []) {
|
|
3486
|
+
if (attendee.email && attendee.name) {
|
|
3487
|
+
attendeeMap.set(attendee.email.toLowerCase(), attendee.name);
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
return participants.map((email) => {
|
|
3491
|
+
const isOrganizer = email.toLowerCase() === transcript.organizer_email.toLowerCase();
|
|
3492
|
+
const attendeeName = attendeeMap.get(email.toLowerCase());
|
|
3493
|
+
const enrichment = opts.enrichParticipant(email, transcript);
|
|
3494
|
+
return {
|
|
3495
|
+
name: enrichment.name ?? attendeeName ?? "",
|
|
3496
|
+
email,
|
|
3497
|
+
role: enrichment.role ?? (isOrganizer ? "organizer" : "attendee")
|
|
3498
|
+
};
|
|
3499
|
+
});
|
|
3500
|
+
}
|
|
3501
|
+
function normalizeSummary(summary) {
|
|
3502
|
+
if (!summary) return void 0;
|
|
3503
|
+
const keyPoints = parseKeyPoints(summary.shorthand_bullet);
|
|
3504
|
+
return {
|
|
3505
|
+
overview: summary.overview,
|
|
3506
|
+
keyPoints: keyPoints.length > 0 ? keyPoints : void 0,
|
|
3507
|
+
actionItems: summary.action_items,
|
|
3508
|
+
outline: summary.outline,
|
|
3509
|
+
topics: summary.topics_discussed
|
|
3510
|
+
};
|
|
3511
|
+
}
|
|
3512
|
+
function parseKeyPoints(shorthandBullet) {
|
|
3513
|
+
if (!shorthandBullet) return [];
|
|
3514
|
+
return shorthandBullet.split("\n").map((line) => line.replace(/^[-*•]\s*/, "").trim()).filter((line) => line.length > 0);
|
|
3515
|
+
}
|
|
3516
|
+
function normalizeAttendees(attendance) {
|
|
3517
|
+
return attendance.map((a) => ({
|
|
3518
|
+
name: a.name,
|
|
3519
|
+
joinTime: a.join_time ? new Date(a.join_time) : void 0,
|
|
3520
|
+
leaveTime: a.leave_time ? new Date(a.leave_time) : void 0
|
|
3521
|
+
}));
|
|
3522
|
+
}
|
|
3523
|
+
function normalizeChannels(channels) {
|
|
3524
|
+
return channels.map((ch) => ({
|
|
3525
|
+
id: ch.id,
|
|
3526
|
+
title: ch.title,
|
|
3527
|
+
isPrivate: ch.is_private ?? false
|
|
3528
|
+
}));
|
|
3529
|
+
}
|
|
3530
|
+
function normalizeAnalytics(analytics) {
|
|
3531
|
+
if (!analytics?.sentiments) return void 0;
|
|
3532
|
+
return {
|
|
3533
|
+
sentiments: {
|
|
3534
|
+
positive: analytics.sentiments.positive_pct ?? 0,
|
|
3535
|
+
neutral: analytics.sentiments.neutral_pct ?? 0,
|
|
3536
|
+
negative: analytics.sentiments.negative_pct ?? 0
|
|
3537
|
+
}
|
|
3538
|
+
};
|
|
3539
|
+
}
|
|
3540
|
+
|
|
3541
|
+
// src/helpers/speaker-analytics.ts
|
|
3542
|
+
function analyzeSpeakers(transcript, options = {}) {
|
|
3543
|
+
const {
|
|
3544
|
+
mergeSpeakersByName = true,
|
|
3545
|
+
roundPercentages = true,
|
|
3546
|
+
unbalancedThreshold = 40,
|
|
3547
|
+
dominatedThreshold = 60
|
|
3548
|
+
} = options;
|
|
3549
|
+
const sentences = transcript.sentences ?? [];
|
|
3550
|
+
if (sentences.length === 0) {
|
|
3551
|
+
return emptyAnalytics();
|
|
3552
|
+
}
|
|
3553
|
+
const speakerMap = /* @__PURE__ */ new Map();
|
|
3554
|
+
let prevSpeakerKey = null;
|
|
3555
|
+
for (const sentence of sentences) {
|
|
3556
|
+
const groupKey = mergeSpeakersByName ? sentence.speaker_name : sentence.speaker_id;
|
|
3557
|
+
const data = getOrCreateSpeakerData(speakerMap, groupKey, sentence);
|
|
3558
|
+
data.sentences.push(sentence);
|
|
3559
|
+
data.talkTime += parseDuration(sentence);
|
|
3560
|
+
data.wordCount += countWords(sentence.text);
|
|
3561
|
+
if (groupKey !== prevSpeakerKey) {
|
|
3562
|
+
data.turnCount++;
|
|
3563
|
+
prevSpeakerKey = groupKey;
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
const totalTalkTime = sumTalkTime(speakerMap);
|
|
3567
|
+
const totalDuration = calculateDuration2(sentences);
|
|
3568
|
+
const totalWords = sumWords(speakerMap);
|
|
3569
|
+
const speakers = buildSpeakerStats(speakerMap, totalTalkTime, roundPercentages);
|
|
3570
|
+
speakers.sort((a, b) => b.talkTime - a.talkTime);
|
|
3571
|
+
const dominant = speakers[0];
|
|
3572
|
+
return {
|
|
3573
|
+
speakers,
|
|
3574
|
+
totalDuration,
|
|
3575
|
+
totalTalkTime,
|
|
3576
|
+
totalSentences: sentences.length,
|
|
3577
|
+
totalWords,
|
|
3578
|
+
dominantSpeaker: dominant?.name ?? "",
|
|
3579
|
+
dominantSpeakerPercentage: dominant?.talkTimePercentage ?? 0,
|
|
3580
|
+
balance: classifyBalance(speakers, unbalancedThreshold, dominatedThreshold)
|
|
3581
|
+
};
|
|
3582
|
+
}
|
|
3583
|
+
function emptyAnalytics() {
|
|
3584
|
+
return {
|
|
3585
|
+
speakers: [],
|
|
3586
|
+
totalDuration: 0,
|
|
3587
|
+
totalTalkTime: 0,
|
|
3588
|
+
totalSentences: 0,
|
|
3589
|
+
totalWords: 0,
|
|
3590
|
+
dominantSpeaker: "",
|
|
3591
|
+
dominantSpeakerPercentage: 0,
|
|
3592
|
+
balance: "balanced"
|
|
3593
|
+
};
|
|
3594
|
+
}
|
|
3595
|
+
function getOrCreateSpeakerData(speakerMap, groupKey, sentence) {
|
|
3596
|
+
let data = speakerMap.get(groupKey);
|
|
3597
|
+
if (!data) {
|
|
3598
|
+
data = {
|
|
3599
|
+
id: sentence.speaker_id,
|
|
3600
|
+
// Use first encountered ID
|
|
3601
|
+
name: sentence.speaker_name,
|
|
3602
|
+
sentences: [],
|
|
3603
|
+
talkTime: 0,
|
|
3604
|
+
wordCount: 0,
|
|
3605
|
+
turnCount: 0
|
|
3606
|
+
};
|
|
3607
|
+
speakerMap.set(groupKey, data);
|
|
3608
|
+
}
|
|
3609
|
+
return data;
|
|
3610
|
+
}
|
|
3611
|
+
function parseDuration(sentence) {
|
|
3612
|
+
const start = Number.parseFloat(sentence.start_time);
|
|
3613
|
+
const end = Number.parseFloat(sentence.end_time);
|
|
3614
|
+
return Math.max(0, end - start);
|
|
3615
|
+
}
|
|
3616
|
+
function countWords(text) {
|
|
3617
|
+
if (!text || text.length === 0) return 0;
|
|
3618
|
+
return text.trim().split(/\s+/).filter((w) => w.length > 0).length;
|
|
3619
|
+
}
|
|
3620
|
+
function sumTalkTime(speakerMap) {
|
|
3621
|
+
let total = 0;
|
|
3622
|
+
for (const data of speakerMap.values()) {
|
|
3623
|
+
total += data.talkTime;
|
|
3624
|
+
}
|
|
3625
|
+
return total;
|
|
3626
|
+
}
|
|
3627
|
+
function sumWords(speakerMap) {
|
|
3628
|
+
let total = 0;
|
|
3629
|
+
for (const data of speakerMap.values()) {
|
|
3630
|
+
total += data.wordCount;
|
|
3631
|
+
}
|
|
3632
|
+
return total;
|
|
3633
|
+
}
|
|
3634
|
+
function calculateDuration2(sentences) {
|
|
3635
|
+
if (sentences.length === 0) return 0;
|
|
3636
|
+
const lastSentence = sentences[sentences.length - 1];
|
|
3637
|
+
return Number.parseFloat(lastSentence?.end_time ?? "0");
|
|
3638
|
+
}
|
|
3639
|
+
function buildSpeakerStats(speakerMap, totalTalkTime, roundPercentages) {
|
|
3640
|
+
const speakers = [];
|
|
3641
|
+
for (const data of speakerMap.values()) {
|
|
3642
|
+
const percentage = totalTalkTime > 0 ? data.talkTime / totalTalkTime * 100 : 0;
|
|
3643
|
+
const sentenceCount = data.sentences.length;
|
|
3644
|
+
const talkTimeMinutes = data.talkTime / 60;
|
|
3645
|
+
const wordsPerMinute = talkTimeMinutes > 0 ? data.wordCount / talkTimeMinutes : 0;
|
|
3646
|
+
const averageSentenceLength = sentenceCount > 0 ? data.wordCount / sentenceCount : 0;
|
|
3647
|
+
speakers.push({
|
|
3648
|
+
name: data.name,
|
|
3649
|
+
id: data.id,
|
|
3650
|
+
talkTime: data.talkTime,
|
|
3651
|
+
talkTimePercentage: roundPercentages ? Math.round(percentage) : percentage,
|
|
3652
|
+
sentenceCount,
|
|
3653
|
+
wordCount: data.wordCount,
|
|
3654
|
+
wordsPerMinute: roundPercentages ? Math.round(wordsPerMinute) : wordsPerMinute,
|
|
3655
|
+
averageSentenceLength,
|
|
3656
|
+
turnCount: data.turnCount
|
|
3657
|
+
});
|
|
3658
|
+
}
|
|
3659
|
+
return speakers;
|
|
3660
|
+
}
|
|
3661
|
+
function classifyBalance(speakers, unbalancedThreshold, dominatedThreshold) {
|
|
3662
|
+
if (speakers.length <= 2) return "balanced";
|
|
3663
|
+
const top = speakers[0]?.talkTimePercentage ?? 0;
|
|
3664
|
+
if (top > dominatedThreshold) return "dominated";
|
|
3665
|
+
if (top > unbalancedThreshold) return "unbalanced";
|
|
3666
|
+
return "balanced";
|
|
3667
|
+
}
|
|
3668
|
+
|
|
3669
|
+
// src/cli/commands/transcripts.ts
|
|
3670
|
+
function collect3(value, previous) {
|
|
3671
|
+
return previous.concat([value]);
|
|
3672
|
+
}
|
|
3673
|
+
function buildActionItemFilterOptions(opts) {
|
|
3674
|
+
const filterOptions = {};
|
|
3675
|
+
if (opts.assignee?.length) {
|
|
3676
|
+
filterOptions.assignees = opts.assignee;
|
|
3677
|
+
}
|
|
3678
|
+
if (opts.assignedOnly) {
|
|
3679
|
+
filterOptions.assignedOnly = true;
|
|
3680
|
+
}
|
|
3681
|
+
if (opts.datedOnly) {
|
|
3682
|
+
filterOptions.datedOnly = true;
|
|
3683
|
+
}
|
|
3684
|
+
return Object.keys(filterOptions).length > 0 ? filterOptions : void 0;
|
|
3685
|
+
}
|
|
3686
|
+
function buildMarkdownOptions(opts) {
|
|
3687
|
+
return {
|
|
3688
|
+
style: opts.style,
|
|
3689
|
+
groupBy: opts.groupBy,
|
|
3690
|
+
preset: opts.preset,
|
|
3691
|
+
includeAssignee: opts.includeAssignee,
|
|
3692
|
+
includeDueDate: opts.includeDueDate,
|
|
3693
|
+
includeMeetingTitle: opts.includeMeeting,
|
|
3694
|
+
includeSummary: opts.includeSummary
|
|
3695
|
+
};
|
|
3696
|
+
}
|
|
3697
|
+
async function writeToFile(path, content, itemCount) {
|
|
3698
|
+
const fs = await import('fs/promises');
|
|
3699
|
+
await fs.writeFile(path, content);
|
|
3700
|
+
console.log(`Wrote ${itemCount} action items to ${path}`);
|
|
3701
|
+
}
|
|
3702
|
+
function arrayOrUndefined(arr) {
|
|
3703
|
+
return arr?.length ? arr : void 0;
|
|
3704
|
+
}
|
|
3705
|
+
function registerTranscriptsCommand(program2) {
|
|
3706
|
+
const cmd = program2.command("transcripts").description("Manage transcripts");
|
|
3707
|
+
cmd.command("list").description("List transcripts").option("--limit <n>", "Max results (default: 20)", "20").option("--from <date>", "From date (YYYY-MM-DD or ISO 8601)").option("--to <date>", "To date (YYYY-MM-DD or ISO 8601)").option("--today", "Transcripts from today").option("--yesterday", "Transcripts from yesterday").option("--last-week", "Transcripts from last 7 days").option("--last-month", "Transcripts from last 30 days").option("--days <n>", "Transcripts from last N days").option("--mine", "Only my transcripts").option("--keyword <text>", "Search keyword").option("--scope <scope>", "Search scope: title, sentences, all (default: all)").option("--organizer <email>", "Filter by organizer email (repeatable)", collect3, []).option("--participant <email>", "Filter by participant email (repeatable)", collect3, []).option("--participant-me", "Only meetings where I am a participant").option("--user-id <id>", "Filter by user ID").option("--channel <id>", "Filter by channel ID").option("--normalize", "Output in normalized provider-agnostic format").action(
|
|
3708
|
+
withErrorHandling(async (opts) => {
|
|
3709
|
+
const client = getClient(program2);
|
|
3710
|
+
const format = getOutputFormat(program2);
|
|
3711
|
+
const { fromDate, toDate } = resolveDateRange(opts);
|
|
3712
|
+
const participants = [...opts.participant];
|
|
3713
|
+
if (opts.participantMe) {
|
|
3714
|
+
const me = await client.users.me();
|
|
3715
|
+
participants.push(me.email);
|
|
3716
|
+
}
|
|
3717
|
+
const transcripts = await client.transcripts.list({
|
|
3718
|
+
limit: Number.parseInt(opts.limit, 10),
|
|
3719
|
+
fromDate,
|
|
3720
|
+
toDate,
|
|
3721
|
+
mine: opts.mine,
|
|
3722
|
+
keyword: opts.keyword,
|
|
3723
|
+
scope: opts.scope,
|
|
3724
|
+
organizers: opts.organizer.length > 0 ? opts.organizer : void 0,
|
|
3725
|
+
participants: participants.length > 0 ? participants : void 0,
|
|
3726
|
+
user_id: opts.userId,
|
|
3727
|
+
channel_id: opts.channel
|
|
3728
|
+
});
|
|
3729
|
+
if (opts.normalize) {
|
|
3730
|
+
const fullTranscripts = await Promise.all(
|
|
3731
|
+
transcripts.map((t) => client.transcripts.get(t.id))
|
|
3732
|
+
);
|
|
3733
|
+
const normalized = fullTranscripts.map((t) => normalizeTranscript2(t));
|
|
3734
|
+
output(normalized, format);
|
|
3735
|
+
return;
|
|
3736
|
+
}
|
|
3737
|
+
const useHumanDuration = format === "table" || format === "plain";
|
|
3738
|
+
const formatted = transcripts.map((t) => ({
|
|
3739
|
+
id: t.id,
|
|
3740
|
+
title: t.title,
|
|
3741
|
+
date: t.dateString,
|
|
3742
|
+
duration: useHumanDuration ? formatDuration(t.duration * 60) : Math.round(t.duration),
|
|
3743
|
+
organizer: t.organizer_email
|
|
3744
|
+
}));
|
|
3745
|
+
output(formatted, format);
|
|
3746
|
+
})
|
|
3747
|
+
);
|
|
3748
|
+
cmd.command("get <id>").description("Get transcript details").option("--sentences", "Include sentences", true).option("--no-sentences", "Exclude sentences").option("--summary", "Include summary", true).option("--no-summary", "Exclude summary").option("--speakers", "Include speaker analytics").option("--no-merge", "Disable speaker merging (with --speakers)").option("--action-items", "Include extracted action items").action(
|
|
3749
|
+
withErrorHandling(async (id, opts) => {
|
|
3750
|
+
const client = getClient(program2);
|
|
3751
|
+
const format = getOutputFormat(program2);
|
|
3752
|
+
const transcript = await client.transcripts.get(id, {
|
|
3753
|
+
includeSentences: opts.sentences,
|
|
3754
|
+
includeSummary: opts.summary || opts.actionItems
|
|
3755
|
+
});
|
|
3756
|
+
let result = { ...transcript };
|
|
3757
|
+
if (opts.speakers) {
|
|
3758
|
+
const analytics = analyzeSpeakers(transcript, {
|
|
3759
|
+
mergeSpeakersByName: opts.merge !== false
|
|
3760
|
+
});
|
|
3761
|
+
result = { ...result, speakerAnalytics: analytics };
|
|
3762
|
+
}
|
|
3763
|
+
if (opts.actionItems) {
|
|
3764
|
+
const actionItems = extractActionItems(transcript);
|
|
3765
|
+
result = { ...result, actionItems };
|
|
3766
|
+
}
|
|
3767
|
+
output(result, format);
|
|
3768
|
+
})
|
|
3769
|
+
);
|
|
3770
|
+
cmd.command("speakers <id>").description("Analyze speaker participation in a transcript").option("--no-merge", "Show separate entries for speakers with same name").option("--raw-percentages", "Show decimal percentages").action(
|
|
3771
|
+
withErrorHandling(async (id, opts) => {
|
|
3772
|
+
const client = getClient(program2);
|
|
3773
|
+
const format = getOutputFormat(program2);
|
|
3774
|
+
const transcript = await client.transcripts.get(id);
|
|
3775
|
+
const analytics = analyzeSpeakers(transcript, {
|
|
3776
|
+
mergeSpeakersByName: opts.merge !== false,
|
|
3777
|
+
roundPercentages: !opts.rawPercentages
|
|
3778
|
+
});
|
|
3779
|
+
outputSpeakerAnalytics(analytics, format);
|
|
3780
|
+
})
|
|
3781
|
+
);
|
|
3782
|
+
const actionItemsCmd = cmd.command("action-items").description("Extract and export action items from transcripts");
|
|
3783
|
+
actionItemsCmd.command("get <id>").description("Extract action items from a single transcript").option("--no-assignees", "Skip assignee detection").option("--no-due-dates", "Skip due date detection").option("--include-source", "Include source sentences from transcript").action(
|
|
3784
|
+
withErrorHandling(async (id, opts) => {
|
|
3785
|
+
const client = getClient(program2);
|
|
3786
|
+
const format = getOutputFormat(program2);
|
|
3787
|
+
const transcript = await client.transcripts.get(id, {
|
|
3788
|
+
includeSummary: true,
|
|
3789
|
+
includeSentences: opts.includeSource
|
|
3790
|
+
});
|
|
3791
|
+
const result = extractActionItems(transcript, {
|
|
3792
|
+
detectAssignees: opts.assignees !== false,
|
|
3793
|
+
detectDueDates: opts.dueDates !== false,
|
|
3794
|
+
includeSourceSentences: opts.includeSource
|
|
3795
|
+
});
|
|
3796
|
+
outputActionItems(result, format);
|
|
3797
|
+
})
|
|
3798
|
+
);
|
|
3799
|
+
actionItemsCmd.command("export").description("Export action items from multiple transcripts").option("--from <date>", "From date (YYYY-MM-DD or ISO 8601)").option("--to <date>", "To date (YYYY-MM-DD or ISO 8601)").option("--today", "Transcripts from today").option("--yesterday", "Transcripts from yesterday").option("--last-week", "Transcripts from last 7 days").option("--last-month", "Transcripts from last 30 days").option("--days <n>", "Transcripts from last N days").option("--mine", "Only my transcripts").option("--limit <n>", "Max transcripts to process").option("--organizer <email>", "Filter by organizer email (repeatable)", collect3, []).option("--participant <email>", "Filter by participant email (repeatable)", collect3, []).option("--assignee <name>", "Filter by assignee (repeatable)", collect3, []).option("--assigned-only", "Only items with assignees").option("--dated-only", "Only items with due dates").option("--style <style>", "List style: checkbox (default), bullet, numbered").option("--group-by <by>", "Group by: none (default), assignee, transcript, date").option("--preset <preset>", "Format preset: default, notion, obsidian, github").option("--include-assignee", "Show assignee inline").option("--include-due-date", "Show due date inline").option("--include-meeting", "Show meeting title inline").option("--include-summary", "Include stats summary").option("-o, --output <file>", "Write to file").action(
|
|
3800
|
+
withErrorHandling(async (opts) => {
|
|
3801
|
+
const client = getClient(program2);
|
|
3802
|
+
const format = getOutputFormat(program2);
|
|
3803
|
+
const { fromDate, toDate } = resolveDateRange(opts);
|
|
3804
|
+
const filterOptions = buildActionItemFilterOptions(opts);
|
|
3805
|
+
const result = await client.transcripts.exportActionItems({
|
|
3806
|
+
fromDate,
|
|
3807
|
+
toDate,
|
|
3808
|
+
mine: opts.mine,
|
|
3809
|
+
organizers: arrayOrUndefined(opts.organizer),
|
|
3810
|
+
participants: arrayOrUndefined(opts.participant),
|
|
3811
|
+
limit: opts.limit ? Number.parseInt(opts.limit, 10) : void 0,
|
|
3812
|
+
filterOptions
|
|
3813
|
+
});
|
|
3814
|
+
if (format === "plain") {
|
|
3815
|
+
const markdown = formatActionItemsMarkdown(result, buildMarkdownOptions(opts));
|
|
3816
|
+
return opts.output ? writeToFile(opts.output, markdown, result.totalItems) : writeLine(markdown);
|
|
3817
|
+
}
|
|
3818
|
+
const content = format === "jsonl" ? result.items.map((i) => JSON.stringify(i)).join("\n") : JSON.stringify(result, null, 2);
|
|
3819
|
+
return opts.output ? writeToFile(opts.output, content, result.totalItems) : output(result, format);
|
|
3820
|
+
})
|
|
3821
|
+
);
|
|
3822
|
+
cmd.command("delete <id>").description("Delete a transcript").option("--confirm", "Skip confirmation (required for non-interactive)").action(
|
|
3823
|
+
withErrorHandling(async (id, opts) => {
|
|
3824
|
+
if (!opts.confirm) {
|
|
3825
|
+
console.error("Error: --confirm flag required for delete operations");
|
|
3826
|
+
process.exit(1);
|
|
3827
|
+
}
|
|
3828
|
+
const client = getClient(program2);
|
|
3829
|
+
const format = getOutputFormat(program2);
|
|
3830
|
+
const result = await client.transcripts.delete(id);
|
|
3831
|
+
output({ success: result, id }, format);
|
|
3832
|
+
})
|
|
3833
|
+
);
|
|
3834
|
+
}
|
|
3835
|
+
|
|
3836
|
+
// src/cli/commands/users.ts
|
|
3837
|
+
function registerUsersCommand(program2) {
|
|
3838
|
+
const cmd = program2.command("users").description("User management");
|
|
3839
|
+
cmd.command("me").description("Show current user info").action(
|
|
3840
|
+
withErrorHandling(async () => {
|
|
3841
|
+
const client = getClient(program2);
|
|
3842
|
+
const format = getOutputFormat(program2);
|
|
3843
|
+
const user = await client.users.me();
|
|
3844
|
+
output(user, format);
|
|
3845
|
+
})
|
|
3846
|
+
);
|
|
3847
|
+
cmd.command("list").description("List team users").action(
|
|
3848
|
+
withErrorHandling(async () => {
|
|
3849
|
+
const client = getClient(program2);
|
|
3850
|
+
const format = getOutputFormat(program2);
|
|
3851
|
+
const users = await client.users.list();
|
|
3852
|
+
const formatted = users.map((u) => ({
|
|
3853
|
+
id: u.user_id,
|
|
3854
|
+
name: u.name,
|
|
3855
|
+
email: u.email,
|
|
3856
|
+
role: u.role
|
|
3857
|
+
}));
|
|
3858
|
+
output(formatted, format);
|
|
3859
|
+
})
|
|
3860
|
+
);
|
|
3861
|
+
cmd.command("get <id>").description("Get user details").action(
|
|
3862
|
+
withErrorHandling(async (id) => {
|
|
3863
|
+
const client = getClient(program2);
|
|
3864
|
+
const format = getOutputFormat(program2);
|
|
3865
|
+
const user = await client.users.get(id);
|
|
3866
|
+
output(user, format);
|
|
3867
|
+
})
|
|
3868
|
+
);
|
|
3869
|
+
cmd.command("set-role <user-id>").description("Set user role (admin only)").requiredOption("--role <role>", "Role: admin or user (required)").action(
|
|
3870
|
+
withErrorHandling(async (userId, opts) => {
|
|
3871
|
+
const role = opts.role;
|
|
3872
|
+
if (role !== "admin" && role !== "user") {
|
|
3873
|
+
console.error('Error: Role must be "admin" or "user"');
|
|
3874
|
+
process.exit(1);
|
|
3875
|
+
}
|
|
3876
|
+
const client = getClient(program2);
|
|
3877
|
+
const format = getOutputFormat(program2);
|
|
3878
|
+
const result = await client.users.setRole(userId, role);
|
|
3879
|
+
output(result, format);
|
|
3880
|
+
})
|
|
3881
|
+
);
|
|
3882
|
+
}
|
|
3883
|
+
|
|
3884
|
+
// src/cli/index.ts
|
|
3885
|
+
function getVersion() {
|
|
3886
|
+
try {
|
|
3887
|
+
const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
3888
|
+
const packagePath = path.join(__dirname, "..", "..", "package.json");
|
|
3889
|
+
const pkg = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
|
|
3890
|
+
return pkg.version;
|
|
3891
|
+
} catch {
|
|
3892
|
+
return "0.0.0";
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
var program = new commander.Command();
|
|
3896
|
+
program.name("fireflies").description("CLI for Fireflies.ai API").version(getVersion()).option("-k, --api-key <key>", "API key (or FIREFLIES_API_KEY env)").option("-o, --output <format>", "Output format: json, jsonl, table, tsv, plain", "json");
|
|
3897
|
+
registerTranscriptsCommand(program);
|
|
3898
|
+
registerSearchCommand(program);
|
|
3899
|
+
registerInsightsCommand(program);
|
|
3900
|
+
registerMeetingsCommand(program);
|
|
3901
|
+
registerUsersCommand(program);
|
|
3902
|
+
registerBitesCommand(program);
|
|
3903
|
+
registerAiAppsCommand(program);
|
|
3904
|
+
registerAudioCommand(program);
|
|
3905
|
+
registerRealtimeCommand(program);
|
|
3906
|
+
registerExportCommand(program);
|
|
3907
|
+
program.parse();
|
|
3908
|
+
//# sourceMappingURL=index.cjs.map
|
|
3909
|
+
//# sourceMappingURL=index.cjs.map
|