chattercatcher 0.1.28 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -221,6 +221,7 @@ interface GenerateCronJobMessageInput {
221
221
  model: ChatModel;
222
222
  tools: RagSearchTool[];
223
223
  now: Date;
224
+ memberPrompt?: string;
224
225
  maxModelTurns?: number;
225
226
  maxToolCalls?: number;
226
227
  }
@@ -239,6 +240,9 @@ interface CronJobRecord {
239
240
  schedule: string;
240
241
  prompt: string;
241
242
  imageFileName?: string;
243
+ mentionTargetName?: string;
244
+ mentionOpenId?: string;
245
+ mentionUserId?: string;
242
246
  status: CronJobStatus;
243
247
  lastRunAt?: string;
244
248
  nextRunAt: string;
@@ -259,6 +263,9 @@ declare class CronJobRepository {
259
263
  schedule: string;
260
264
  prompt: string;
261
265
  imageFileName?: string;
266
+ mentionTargetName?: string;
267
+ mentionOpenId?: string;
268
+ mentionUserId?: string;
262
269
  }): CronJobRecord;
263
270
  get(id: string): CronJobRecord | null;
264
271
  list(limit?: number): CronJobRecord[];
@@ -274,6 +281,98 @@ declare function isValidCronSchedule(schedule: string): boolean;
274
281
  declare function matchesCronSchedule(schedule: string, date: Date): boolean;
275
282
  declare function getNextCronRun(schedule: string, after: Date): Date | null;
276
283
 
284
+ interface FeishuTextMention {
285
+ openId: string;
286
+ name: string;
287
+ }
288
+ interface SendTextOptions {
289
+ mentions?: FeishuTextMention[];
290
+ }
291
+ interface MessageSender {
292
+ sendTextToChat(chatId: string, text: string, options?: SendTextOptions): Promise<void>;
293
+ sendImageToChat?(chatId: string, imagePath: string): Promise<void>;
294
+ replyTextToMessage?(messageId: string, text: string): Promise<void>;
295
+ addReactionToMessage?(messageId: string, emojiType: string): Promise<void>;
296
+ }
297
+ interface FeishuClientLike {
298
+ im: {
299
+ v1?: {
300
+ message: {
301
+ create(payload: {
302
+ data: {
303
+ receive_id: string;
304
+ msg_type: string;
305
+ content: string;
306
+ };
307
+ params: {
308
+ receive_id_type: "chat_id";
309
+ };
310
+ }): Promise<unknown>;
311
+ reply?: (payload: {
312
+ path: {
313
+ message_id: string;
314
+ };
315
+ data: {
316
+ msg_type: string;
317
+ content: string;
318
+ };
319
+ }) => Promise<unknown>;
320
+ };
321
+ image?: {
322
+ create(payload: {
323
+ data: {
324
+ image_type: "message";
325
+ image: Buffer;
326
+ };
327
+ }): Promise<unknown>;
328
+ };
329
+ messageReaction?: {
330
+ create(payload: {
331
+ path: {
332
+ message_id: string;
333
+ };
334
+ data: {
335
+ reaction_type: {
336
+ emoji_type: string;
337
+ };
338
+ };
339
+ }): Promise<unknown>;
340
+ };
341
+ };
342
+ message?: {
343
+ create(payload: {
344
+ data: {
345
+ receive_id: string;
346
+ msg_type: string;
347
+ content: string;
348
+ };
349
+ params: {
350
+ receive_id_type: "chat_id";
351
+ };
352
+ }): Promise<unknown>;
353
+ reply?: (payload: {
354
+ path: {
355
+ message_id: string;
356
+ };
357
+ data: {
358
+ msg_type: string;
359
+ content: string;
360
+ };
361
+ }) => Promise<unknown>;
362
+ };
363
+ };
364
+ }
365
+ declare function mapDomain(domain: AppConfig["feishu"]["domain"]): lark.Domain;
366
+ declare class FeishuMessageSender implements MessageSender {
367
+ private readonly client;
368
+ constructor(client: FeishuClientLike);
369
+ static fromConfig(config: AppConfig, secrets: AppSecrets): FeishuMessageSender;
370
+ sendTextToChat(chatId: string, text: string, options?: SendTextOptions): Promise<void>;
371
+ sendImageToChat(chatId: string, imagePath: string): Promise<void>;
372
+ replyTextToMessage(messageId: string, text: string): Promise<void>;
373
+ addReactionToMessage(messageId: string, emojiType: string): Promise<void>;
374
+ }
375
+
277
376
  interface CronJobScheduler {
278
377
  start(): void;
279
378
  stop(): void;
@@ -282,7 +381,7 @@ interface CronJobScheduler {
282
381
  interface CreateCronJobSchedulerOptions {
283
382
  repository: Pick<CronJobRepository, "listDue" | "markSuccess" | "markFailure">;
284
383
  generateMessage: (job: CronJobRecord, now: Date) => Promise<string>;
285
- sendTextToChat: (chatId: string, text: string) => Promise<void>;
384
+ sendTextToChat: (chatId: string, text: string, options?: SendTextOptions) => Promise<void>;
286
385
  sendImageToChat?: (chatId: string, imageFileName: string) => Promise<void>;
287
386
  now?: () => Date;
288
387
  setIntervalFn?: typeof setInterval;
@@ -291,6 +390,51 @@ interface CreateCronJobSchedulerOptions {
291
390
  }
292
391
  declare function createCronJobScheduler(options: CreateCronJobSchedulerOptions): CronJobScheduler;
293
392
 
393
+ interface FeishuChatMemberRecord {
394
+ chatId: string;
395
+ openId: string;
396
+ userId?: string;
397
+ userName: string;
398
+ updatedAt: string;
399
+ }
400
+ interface FeishuChatMemberApiRecord {
401
+ openId: string;
402
+ userId?: string;
403
+ userName: string;
404
+ }
405
+ interface FeishuChatMembersClient {
406
+ listChatMembers(payload: {
407
+ chatId: string;
408
+ memberIdType: "open_id";
409
+ }): Promise<FeishuChatMemberApiRecord[]>;
410
+ }
411
+ interface FeishuMemberResolverOptions {
412
+ repository: FeishuMemberRepository;
413
+ client: FeishuChatMembersClient;
414
+ logger?: Pick<Console, "warn">;
415
+ now?: () => Date;
416
+ ttlMs?: number;
417
+ }
418
+ declare class FeishuMemberRepository {
419
+ private readonly database;
420
+ constructor(database: SqliteDatabase);
421
+ upsert(record: FeishuChatMemberRecord): void;
422
+ get(chatId: string, openId: string): FeishuChatMemberRecord | null;
423
+ listByChat(chatId: string): FeishuChatMemberRecord[];
424
+ findUniqueByName(chatId: string, userName: string): FeishuChatMemberRecord | null;
425
+ }
426
+ declare class FeishuMemberResolver {
427
+ private readonly options;
428
+ private readonly now;
429
+ private readonly ttlMs;
430
+ private readonly logger?;
431
+ constructor(options: FeishuMemberResolverOptions);
432
+ resolveOpenIdName(chatId: string, openId: string): Promise<string>;
433
+ resolveUniqueName(chatId: string, userName: string): Promise<FeishuChatMemberRecord | null>;
434
+ private isExpired;
435
+ private refreshChatMembers;
436
+ }
437
+
294
438
  interface CronJobTool extends ChatTool {
295
439
  execute(input: unknown): Promise<string>;
296
440
  }
@@ -298,6 +442,7 @@ interface CreateCronJobToolsInput {
298
442
  repository: CronJobRepository;
299
443
  chatId: string;
300
444
  createdByOpenId?: string;
445
+ memberResolver?: Pick<FeishuMemberResolver, "resolveUniqueName">;
301
446
  }
302
447
  declare function createCronJobTools(input: CreateCronJobToolsInput): CronJobTool[];
303
448
 
@@ -573,11 +718,16 @@ interface GatewayIngestAndDownloadResult extends GatewayIngestResult {
573
718
  attachment?: GatewayAttachmentIngestResult;
574
719
  }
575
720
  declare class GatewayIngestor {
721
+ readonly database: SqliteDatabase;
576
722
  private readonly messages;
577
723
  private readonly jobs;
578
724
  private readonly imageTasks;
579
725
  constructor(database: SqliteDatabase);
580
726
  ingestFeishuEvent(payload: FeishuReceiveMessageEvent): GatewayIngestResult;
727
+ ingestFeishuEventWithMembers(input: {
728
+ payload: FeishuReceiveMessageEvent;
729
+ memberResolver: Pick<FeishuMemberResolver, "resolveOpenIdName">;
730
+ }): Promise<GatewayIngestResult>;
581
731
  ingestFeishuEventAndDownloadAttachments(input: {
582
732
  payload: FeishuReceiveMessageEvent;
583
733
  downloader: FeishuResourceDownloader;
@@ -587,6 +737,7 @@ declare class GatewayIngestor {
587
737
  chunks: number;
588
738
  vectors: number;
589
739
  }>;
740
+ memberResolver?: Pick<FeishuMemberResolver, "resolveOpenIdName">;
590
741
  }): Promise<GatewayIngestAndDownloadResult>;
591
742
  }
592
743
 
@@ -596,97 +747,14 @@ interface IndexingScheduler {
596
747
  runDueNow(): Promise<void>;
597
748
  }
598
749
 
599
- interface MessageSender {
600
- sendTextToChat(chatId: string, text: string): Promise<void>;
601
- sendImageToChat?(chatId: string, imagePath: string): Promise<void>;
602
- replyTextToMessage?(messageId: string, text: string): Promise<void>;
603
- addReactionToMessage?(messageId: string, emojiType: string): Promise<void>;
604
- }
605
- interface FeishuClientLike {
606
- im: {
607
- v1?: {
608
- message: {
609
- create(payload: {
610
- data: {
611
- receive_id: string;
612
- msg_type: string;
613
- content: string;
614
- };
615
- params: {
616
- receive_id_type: "chat_id";
617
- };
618
- }): Promise<unknown>;
619
- reply?: (payload: {
620
- path: {
621
- message_id: string;
622
- };
623
- data: {
624
- msg_type: string;
625
- content: string;
626
- };
627
- }) => Promise<unknown>;
628
- };
629
- image?: {
630
- create(payload: {
631
- data: {
632
- image_type: "message";
633
- image: Buffer;
634
- };
635
- }): Promise<unknown>;
636
- };
637
- messageReaction?: {
638
- create(payload: {
639
- path: {
640
- message_id: string;
641
- };
642
- data: {
643
- reaction_type: {
644
- emoji_type: string;
645
- };
646
- };
647
- }): Promise<unknown>;
648
- };
649
- };
650
- message?: {
651
- create(payload: {
652
- data: {
653
- receive_id: string;
654
- msg_type: string;
655
- content: string;
656
- };
657
- params: {
658
- receive_id_type: "chat_id";
659
- };
660
- }): Promise<unknown>;
661
- reply?: (payload: {
662
- path: {
663
- message_id: string;
664
- };
665
- data: {
666
- msg_type: string;
667
- content: string;
668
- };
669
- }) => Promise<unknown>;
670
- };
671
- };
672
- }
673
- declare function mapDomain(domain: AppConfig["feishu"]["domain"]): lark.Domain;
674
- declare class FeishuMessageSender implements MessageSender {
675
- private readonly client;
676
- constructor(client: FeishuClientLike);
677
- static fromConfig(config: AppConfig, secrets: AppSecrets): FeishuMessageSender;
678
- sendTextToChat(chatId: string, text: string): Promise<void>;
679
- sendImageToChat(chatId: string, imagePath: string): Promise<void>;
680
- replyTextToMessage(messageId: string, text: string): Promise<void>;
681
- addReactionToMessage(messageId: string, emojiType: string): Promise<void>;
682
- }
683
-
684
750
  interface FeishuQuestionHandlerOptions {
685
751
  config: AppConfig;
686
752
  secrets: AppSecrets;
687
753
  database: SqliteDatabase;
688
754
  model: ChatModel;
689
755
  sender: MessageSender;
756
+ memberRepository?: FeishuMemberRepository;
757
+ memberResolver?: Pick<FeishuMemberResolver, "resolveUniqueName">;
690
758
  thinkingEmojiType?: string;
691
759
  }
692
760
  interface FeishuQuestionDecision {
@@ -699,7 +767,9 @@ declare function isFeishuMessageAddressedToBot(payload: FeishuReceiveMessageEven
699
767
  declare function getFeishuQuestionDecision(payload: FeishuReceiveMessageEvent, config: AppConfig): FeishuQuestionDecision;
700
768
  declare class FeishuQuestionHandler {
701
769
  private readonly options;
770
+ private memberResolver?;
702
771
  constructor(options: FeishuQuestionHandlerOptions);
772
+ setMemberResolver(memberResolver: Pick<FeishuMemberResolver, "resolveUniqueName">): void;
703
773
  private sendResponse;
704
774
  private acknowledgeQuestion;
705
775
  handle(payload: FeishuReceiveMessageEvent, options?: {
@@ -762,6 +832,7 @@ declare function createFeishuEventDispatcher(options: {
762
832
  config: AppConfig;
763
833
  secrets: AppSecrets;
764
834
  ingestor: GatewayIngestor;
835
+ memberResolver?: FeishuMemberResolver;
765
836
  questionHandler?: FeishuQuestionHandler;
766
837
  resourceDownloader?: FeishuResourceDownloader;
767
838
  attachmentVectorIndexer?: (messageId: string) => Promise<{
@@ -1105,4 +1176,4 @@ interface WebAppOptions {
1105
1176
  declare function createWebApp(config: AppConfig, options?: WebAppOptions): FastifyInstance;
1106
1177
  declare function startWebServer(config: AppConfig, options?: WebAppOptions): Promise<void>;
1107
1178
 
1108
- export { type AppConfig, type AppSecrets, type AskWithRagInput, type BuildEvidencePromptInput, type BuildEvidencePromptOptions, type ChatMessage, type ChatModel, type ChatRecord, type ChatTool, type Citation, type CreateImageSummaryMessageInput, type CronJobRecord, CronJobRepository, type CronJobScheduler, type CronJobStatus, type CronJobTool, type DataExportResult, type DataRestoreResult, type DeleteLocalDataResult, type DeleteTargetType, type DoctorCheck, type DoctorOptions, type DoctorStatus, type EmbeddingModel, type EpisodeListItem, type EpisodeMessage, EpisodeRepository, type EpisodeSearchResult, type EpisodeSummaryRecord, type EpisodeWindow, type EvidenceBlock, type EvidencePrompt, type EvidenceSource, type FeishuAttachmentMetadata, type FeishuDownloadResourceInput, type FeishuDownloadedResource, type FeishuGatewayOptions, type FeishuGatewayRuntime, FeishuMessageSender, type FeishuQuestionDecision, FeishuQuestionHandler, type FeishuQuestionHandlerOptions, type FeishuReceiveMessageEvent, FeishuResourceDownloader, type FileJobRecord, FileJobRepository, type FileJobStatus, type FileRecord, type GatewayAttachmentIngestResult, type GatewayIngestAndDownloadResult, type GatewayIngestResult, GatewayIngestor, type GatewayPidRecord, type GatewayRuntimeState, type GroundedAnswer, HybridRetriever, type HybridRetrieverOptions, type IngestLocalFileResult, type IngestMessageInput, type LogFileInfo, type LogTailResult, type ManualMessageIndexResult, MemoryVectorStore, MessageFtsRetriever, type MessageRecord, MessageRepository, type MessageSearchResult, type MessageSearchScope, type MessageSender, OpenAICompatibleChatModel, type OpenAICompatibleChatOptions, OpenAICompatibleEmbeddingModel, type OpenAICompatibleEmbeddingOptions, type ParsedFile, type ProcessEpisodesResult, type SourceType, type SqliteDatabase, type StopGatewayResult, type TextChunk, type ToolCall, type ToolChatResult, type VectorIndexStats, type VectorRecord, VectorRetriever, type VectorSearchResult, type VectorStore, type WebAppOptions, appConfigSchema, appSecretsSchema, applySecretInput, askWithRag, buildEvidencePrompt, chunkText, cosineSimilarity, createAgenticRagSearchTools, createChatModel, createCronJobScheduler, createCronJobTools, createDefaultConfig, createDefaultSecrets, createEmbeddingModel, createFeishuEventDispatcher, createFeishuGateway, createHybridRetriever, createWebApp, deleteLocalData, describeSupportedParseTypes, ensureConfigFiles, exportLocalData, extractFeishuAttachment, followLogFile, formatCitation, formatCitations, formatDoctorChecks, generateCronJobMessage, generateGroundedAnswer, getDatabasePath, getFeishuQuestionDecision, getGatewayLogPath, getGatewayPidPath, getGatewayRuntimeState, getLogsDirectory, getNextCronRun, hasEmbeddingConfig, indexMessageChunks, ingestLocalFile, isFeishuMessageAddressedToBot, isProcessRunning, isSupportedParseFile, isSupportedTextFile, isValidCronSchedule, listLogFiles, loadConfig, loadSecrets, mapDomain, maskSecret, matchesCronSchedule, migrateDatabase, normalizeFeishuReceiveMessageEvent, normalizeLineCount, openDatabase, parseFileToText, processEpisodesNow, processMessagesNow, rankEvidenceForPrompt, readGatewayPidRecord, readLatestLogTail, readLogTail, removeGatewayPidRecord, resetConfigFiles, resolveEmbeddingApiKey, resolveLogPath, restoreLocalData, runDoctor, sanitizeEpisodeSummary, saveConfig, saveSecrets, startWebServer, stopGatewayProcess, summarizeEpisodeWindow, writeGatewayPidRecord };
1179
+ export { type AppConfig, type AppSecrets, type AskWithRagInput, type BuildEvidencePromptInput, type BuildEvidencePromptOptions, type ChatMessage, type ChatModel, type ChatRecord, type ChatTool, type Citation, type CreateImageSummaryMessageInput, type CronJobRecord, CronJobRepository, type CronJobScheduler, type CronJobStatus, type CronJobTool, type DataExportResult, type DataRestoreResult, type DeleteLocalDataResult, type DeleteTargetType, type DoctorCheck, type DoctorOptions, type DoctorStatus, type EmbeddingModel, type EpisodeListItem, type EpisodeMessage, EpisodeRepository, type EpisodeSearchResult, type EpisodeSummaryRecord, type EpisodeWindow, type EvidenceBlock, type EvidencePrompt, type EvidenceSource, type FeishuAttachmentMetadata, type FeishuDownloadResourceInput, type FeishuDownloadedResource, type FeishuGatewayOptions, type FeishuGatewayRuntime, FeishuMessageSender, type FeishuQuestionDecision, FeishuQuestionHandler, type FeishuQuestionHandlerOptions, type FeishuReceiveMessageEvent, FeishuResourceDownloader, type FeishuTextMention, type FileJobRecord, FileJobRepository, type FileJobStatus, type FileRecord, type GatewayAttachmentIngestResult, type GatewayIngestAndDownloadResult, type GatewayIngestResult, GatewayIngestor, type GatewayPidRecord, type GatewayRuntimeState, type GroundedAnswer, HybridRetriever, type HybridRetrieverOptions, type IngestLocalFileResult, type IngestMessageInput, type LogFileInfo, type LogTailResult, type ManualMessageIndexResult, MemoryVectorStore, MessageFtsRetriever, type MessageRecord, MessageRepository, type MessageSearchResult, type MessageSearchScope, type MessageSender, OpenAICompatibleChatModel, type OpenAICompatibleChatOptions, OpenAICompatibleEmbeddingModel, type OpenAICompatibleEmbeddingOptions, type ParsedFile, type ProcessEpisodesResult, type SendTextOptions, type SourceType, type SqliteDatabase, type StopGatewayResult, type TextChunk, type ToolCall, type ToolChatResult, type VectorIndexStats, type VectorRecord, VectorRetriever, type VectorSearchResult, type VectorStore, type WebAppOptions, appConfigSchema, appSecretsSchema, applySecretInput, askWithRag, buildEvidencePrompt, chunkText, cosineSimilarity, createAgenticRagSearchTools, createChatModel, createCronJobScheduler, createCronJobTools, createDefaultConfig, createDefaultSecrets, createEmbeddingModel, createFeishuEventDispatcher, createFeishuGateway, createHybridRetriever, createWebApp, deleteLocalData, describeSupportedParseTypes, ensureConfigFiles, exportLocalData, extractFeishuAttachment, followLogFile, formatCitation, formatCitations, formatDoctorChecks, generateCronJobMessage, generateGroundedAnswer, getDatabasePath, getFeishuQuestionDecision, getGatewayLogPath, getGatewayPidPath, getGatewayRuntimeState, getLogsDirectory, getNextCronRun, hasEmbeddingConfig, indexMessageChunks, ingestLocalFile, isFeishuMessageAddressedToBot, isProcessRunning, isSupportedParseFile, isSupportedTextFile, isValidCronSchedule, listLogFiles, loadConfig, loadSecrets, mapDomain, maskSecret, matchesCronSchedule, migrateDatabase, normalizeFeishuReceiveMessageEvent, normalizeLineCount, openDatabase, parseFileToText, processEpisodesNow, processMessagesNow, rankEvidenceForPrompt, readGatewayPidRecord, readLatestLogTail, readLogTail, removeGatewayPidRecord, resetConfigFiles, resolveEmbeddingApiKey, resolveLogPath, restoreLocalData, runDoctor, sanitizeEpisodeSummary, saveConfig, saveSecrets, startWebServer, stopGatewayProcess, summarizeEpisodeWindow, writeGatewayPidRecord };