@naplink/naplink 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -27,6 +27,7 @@
27
27
  - [事件处理](https://naplink.github.io/guide/events) - 事件系统详解
28
28
  - [最佳实践](https://naplink.github.io/guide/best-practices) - 生产环境建议
29
29
  - [架构设计](https://naplink.github.io/guide/architecture) - 内部实现
30
+ - 最佳实践项目:[NapGram](https://github.com/NapLink/NapGram) - 基于 NapLink 的 QQ ↔ Telegram 消息桥接
30
31
 
31
32
  ## 📦 安装
32
33
 
package/dist/index.d.ts CHANGED
@@ -175,6 +175,16 @@ declare class ApiClient {
175
175
  timeout?: number;
176
176
  retries?: number;
177
177
  }): Promise<T>;
178
+ /**
179
+ * 调用流式 API(NapCat stream-action)
180
+ * 会持续产出 data.type=stream 的分片包,并在 data.type=response 时结束。
181
+ */
182
+ callStream<TPacket = any, TFinal = any>(method: string, params?: any, options?: {
183
+ timeout?: number;
184
+ }): {
185
+ packets: AsyncIterable<TPacket>;
186
+ result: Promise<TFinal>;
187
+ };
178
188
  /**
179
189
  * 处理API响应
180
190
  * 由连接管理器调用
@@ -402,9 +412,37 @@ type MessageApi = {
402
412
  deleteEssenceMessage(messageId: number | string): Promise<any>;
403
413
  getEssenceMessageList(groupId: number | string): Promise<any>;
404
414
  markMessageAsRead(messageId: number | string): Promise<any>;
415
+ markGroupMsgAsRead(groupId: number | string): Promise<any>;
416
+ markPrivateMsgAsRead(userId: number | string): Promise<any>;
417
+ markAllMsgAsRead(): Promise<any>;
405
418
  getGroupAtAllRemain(groupId: number | string): Promise<number>;
406
419
  getGroupSystemMsg(): Promise<GroupSystemMessages>;
407
420
  getGroupHonorInfo(groupId: number | string, type: 'all' | 'talkative' | 'performer' | 'legend' | 'strong_newbie' | 'emotion'): Promise<GroupHonorInfo>;
421
+ getGroupMsgHistory(params: {
422
+ group_id: number | string;
423
+ message_seq: number | string;
424
+ count: number;
425
+ reverse_order?: boolean;
426
+ }): Promise<any>;
427
+ getFriendMsgHistory(params: {
428
+ user_id: number | string;
429
+ message_seq: number | string;
430
+ count: number;
431
+ reverse_order?: boolean;
432
+ }): Promise<any>;
433
+ getRecentContact(count: number): Promise<any>;
434
+ setMsgEmojiLike(messageId: number | string, emojiId: number, set: boolean): Promise<any>;
435
+ fetchEmojiLike(params: {
436
+ message_id: number | string;
437
+ emojiId: string;
438
+ emojiType: string;
439
+ group_id?: number | string;
440
+ user_id?: number | string;
441
+ count?: number;
442
+ }): Promise<any>;
443
+ sendGroupPoke(groupId: number | string, userId: number | string): Promise<any>;
444
+ sendFriendPoke(userId: number | string): Promise<any>;
445
+ sendPoke(targetId: number | string, groupId?: number | string): Promise<any>;
408
446
  };
409
447
 
410
448
  type MediaApi = {
@@ -465,6 +503,70 @@ type StreamApi = {
465
503
  verifyOnly?: boolean;
466
504
  }): Promise<any>;
467
505
  getUploadStreamStatus(streamId: string): Promise<any>;
506
+ /**
507
+ * 流式下载文件(原始分片包)
508
+ * - data_type=file_info / file_chunk / file_complete
509
+ * - type=stream / response
510
+ */
511
+ downloadFileStream(fileId: string, options?: {
512
+ chunkSize?: number;
513
+ }): {
514
+ packets: AsyncIterable<DownloadStreamPacket>;
515
+ result: Promise<DownloadStreamPacket>;
516
+ };
517
+ downloadFileStreamToFile(fileId: string, options?: {
518
+ chunkSize?: number;
519
+ filename?: string;
520
+ }): Promise<{
521
+ path: string;
522
+ info?: DownloadStreamPacket;
523
+ }>;
524
+ downloadFileImageStream(fileId: string, options?: {
525
+ chunkSize?: number;
526
+ }): {
527
+ packets: AsyncIterable<DownloadStreamPacket>;
528
+ result: Promise<DownloadStreamPacket>;
529
+ };
530
+ downloadFileImageStreamToFile(fileId: string, options?: {
531
+ chunkSize?: number;
532
+ filename?: string;
533
+ }): Promise<{
534
+ path: string;
535
+ info?: DownloadStreamPacket;
536
+ }>;
537
+ downloadFileRecordStream(fileId: string, outFormat?: string, options?: {
538
+ chunkSize?: number;
539
+ filename?: string;
540
+ }): {
541
+ packets: AsyncIterable<DownloadStreamPacket>;
542
+ result: Promise<DownloadStreamPacket>;
543
+ };
544
+ downloadFileRecordStreamToFile(fileId: string, outFormat?: string, options?: {
545
+ chunkSize?: number;
546
+ filename?: string;
547
+ }): Promise<{
548
+ path: string;
549
+ info?: DownloadStreamPacket;
550
+ }>;
551
+ cleanStreamTempFile(): Promise<any>;
552
+ };
553
+ type DownloadStreamPacket = {
554
+ type: 'stream' | 'response' | 'reset' | 'error';
555
+ data_type?: 'file_info' | 'file_chunk' | 'file_complete' | string;
556
+ file_name?: string;
557
+ file_size?: number;
558
+ chunk_size?: number;
559
+ index?: number;
560
+ data?: string;
561
+ size?: number;
562
+ progress?: number;
563
+ base64_size?: number;
564
+ total_chunks?: number;
565
+ total_bytes?: number;
566
+ message?: string;
567
+ width?: number;
568
+ height?: number;
569
+ out_format?: string;
468
570
  };
469
571
 
470
572
  type RequestApi = {
@@ -472,6 +574,103 @@ type RequestApi = {
472
574
  handleGroupRequest(flag: string, subType: 'add' | 'invite', approve?: boolean, reason?: string): Promise<any>;
473
575
  };
474
576
 
577
+ type SystemApi = {
578
+ getOnlineClients(noCache?: boolean): Promise<any>;
579
+ getRobotUinRange(): Promise<any>;
580
+ canSendImage(): Promise<any>;
581
+ canSendRecord(): Promise<any>;
582
+ getCookies(domain: string): Promise<any>;
583
+ getCsrfToken(): Promise<any>;
584
+ getCredentials(domain: string): Promise<any>;
585
+ setInputStatus(userId: number | string, eventType: number): Promise<any>;
586
+ ocrImage(image: string, dot?: boolean): Promise<any>;
587
+ translateEn2zh(words: string[]): Promise<any>;
588
+ checkUrlSafely(url: string): Promise<any>;
589
+ handleQuickOperation(context: any, operation: any): Promise<any>;
590
+ getModelShow(model: string): Promise<any>;
591
+ setModelShow(model: string, modelShow: string): Promise<any>;
592
+ getPacketStatus(): Promise<any>;
593
+ };
594
+
595
+ type NapCatApi = {
596
+ getRkeyEx(): Promise<any>;
597
+ getRkeyServer(): Promise<any>;
598
+ getRkey(): Promise<any>;
599
+ setFriendRemark(userId: number | string, remark: string): Promise<any>;
600
+ deleteFriend(userId: number | string): Promise<any>;
601
+ getUnidirectionalFriendList(): Promise<any>;
602
+ setGroupRemark(groupId: number | string, remark: string): Promise<any>;
603
+ getGroupInfoEx(groupId: number | string): Promise<any>;
604
+ getGroupDetailInfo(groupId: number | string): Promise<any>;
605
+ getGroupIgnoredNotifies(): Promise<any>;
606
+ getGroupShutList(groupId: number | string): Promise<any>;
607
+ sendPrivateForwardMessage(params: {
608
+ user_id: number | string;
609
+ messages: any[];
610
+ news?: any[];
611
+ prompt?: string;
612
+ summary?: string;
613
+ source?: string;
614
+ }): Promise<any>;
615
+ forwardFriendSingleMsg(userId: number | string, messageId: number | string): Promise<any>;
616
+ forwardGroupSingleMsg(groupId: number | string, messageId: number | string): Promise<any>;
617
+ sendForwardMsg(params: {
618
+ group_id?: number | string;
619
+ user_id?: number | string;
620
+ messages: any[];
621
+ news?: any[];
622
+ prompt?: string;
623
+ summary?: string;
624
+ source?: string;
625
+ }): Promise<any>;
626
+ sendGroupNotice(params: {
627
+ group_id: number | string;
628
+ content: string;
629
+ image?: string;
630
+ pinned?: number | string;
631
+ type?: number | string;
632
+ confirm_required?: number | string;
633
+ is_show_edit_card?: number | string;
634
+ tip_window_type?: number | string;
635
+ }): Promise<any>;
636
+ getGroupNotice(groupId: number | string): Promise<any>;
637
+ delGroupNotice(groupId: number | string, noticeId: string): Promise<any>;
638
+ setOnlineStatus(status: number | string, extStatus: number | string, batteryStatus: number | string): Promise<any>;
639
+ setDiyOnlineStatus(faceId: number | string, wording?: string, faceType?: number | string): Promise<any>;
640
+ sendArkShare(params: {
641
+ user_id?: number | string;
642
+ group_id?: number | string;
643
+ phone_number?: string;
644
+ }): Promise<any>;
645
+ sendGroupArkShare(groupId: number | string): Promise<any>;
646
+ getMiniAppArk(payload: any): Promise<any>;
647
+ getAiCharacters(groupId: number | string, chatType?: number | string): Promise<any>;
648
+ getAiRecord(groupId: number | string, character: string, text: string): Promise<any>;
649
+ sendGroupAiRecord(groupId: number | string, character: string, text: string): Promise<any>;
650
+ setGroupSign(groupId: number | string): Promise<any>;
651
+ sendGroupSign(groupId: number | string): Promise<any>;
652
+ fetchCustomFace(params?: any): Promise<any>;
653
+ getClientkey(): Promise<any>;
654
+ clickInlineKeyboardButton(params: {
655
+ group_id: number | string;
656
+ bot_appid: string;
657
+ button_id?: string;
658
+ callback_data?: string;
659
+ msg_seq?: string;
660
+ }): Promise<any>;
661
+ };
662
+
663
+ /**
664
+ * NapCatQQ ActionName 全量列表(服务端路由表)
665
+ * - 可用于“完全覆盖”服务端 action,而不必在 SDK 里为每个 action 单独写一层包装。
666
+ * - 对于包含 '.'/'_' 等前缀的 action,建议使用 bracket 访问:api.raw['.ocr_image'](...)
667
+ */
668
+ declare const NAPCAT_ACTIONS: readonly [".get_word_slices", ".handle_quick_operation", ".ocr_image", "ArkShareGroup", "ArkSharePeer", "_del_group_notice", "_get_group_notice", "_get_model_show", "_mark_all_as_read", "_send_group_notice", "_set_model_show", "bot_exit", "can_send_image", "can_send_record", "check_url_safely", "clean_cache", "clean_stream_temp_file", "click_inline_keyboard_button", "create_collection", "create_group_file_folder", "del_group_album_media", "delete_essence_msg", "delete_friend", "delete_group_file", "delete_group_folder", "delete_msg", "delete_unidirectional_friend", "do_group_album_comment", "download_file", "download_file_image_stream", "download_file_record_stream", "download_file_stream", "fetch_custom_face", "fetch_emoji_like", "forward_friend_single_msg", "forward_group_single_msg", "friend_poke", "get_ai_characters", "get_ai_record", "get_clientkey", "get_collection_list", "get_cookies", "get_credentials", "get_csrf_token", "get_doubt_friends_add_request", "get_essence_msg_list", "get_file", "get_forward_msg", "get_friend_list", "get_friend_msg_history", "get_friends_with_category", "get_group_album_media_list", "get_group_at_all_remain", "get_group_detail_info", "get_group_file_system_info", "get_group_file_url", "get_group_files_by_folder", "get_group_honor_info", "get_group_ignore_add_request", "get_group_ignored_notifies", "get_group_info", "get_group_info_ex", "get_group_list", "get_group_member_info", "get_group_member_list", "get_group_msg_history", "get_group_root_files", "get_group_shut_list", "get_group_system_msg", "get_guild_list", "get_guild_service_profile", "get_image", "get_login_info", "get_mini_app_ark", "get_msg", "get_online_clients", "get_private_file_url", "get_profile_like", "get_qun_album_list", "get_recent_contact", "get_record", "get_rkey", "get_rkey_server", "get_robot_uin_range", "get_status", "get_stranger_info", "get_unidirectional_friend_list", "get_version_info", "group_poke", "mark_group_msg_as_read", "mark_msg_as_read", "mark_private_msg_as_read", "move_group_file", "nc_get_packet_status", "nc_get_rkey", "nc_get_user_status", "ocr_image", "qidian_get_account_info", "reboot_normal", "reload_event_filter", "rename_group_file", "send_ark_share", "send_forward_msg", "send_group_ai_record", "send_group_ark_share", "send_group_forward_msg", "send_group_msg", "send_group_sign", "send_like", "send_msg", "send_packet", "send_poke", "send_private_forward_msg", "send_private_msg", "set_diy_online_status", "set_doubt_friends_add_request", "set_essence_msg", "set_friend_add_request", "set_friend_remark", "set_group_add_option", "set_group_add_request", "set_group_admin", "set_group_album_media_like", "set_group_anonymous", "set_group_anonymous_ban", "set_group_ban", "set_group_card", "set_group_kick", "set_group_kick_members", "set_group_leave", "set_group_name", "set_group_portrait", "set_group_remark", "set_group_robot_add_option", "set_group_search", "set_group_sign", "set_group_special_title", "set_group_todo", "set_group_whole_ban", "set_input_status", "set_msg_emoji_like", "set_online_status", "set_qq_avatar", "set_qq_profile", "set_restart", "set_self_longnick", "test_auto_register_01", "test_auto_register_02", "test_download_stream", "trans_group_file", "translate_en2zh", "unknown", "upload_file_stream", "upload_group_file", "upload_image_to_qun_album", "upload_private_file"];
669
+ type NapCatAction = typeof NAPCAT_ACTIONS[number];
670
+ type RawActionApi = {
671
+ [K in NapCatAction]: (params?: any) => Promise<any>;
672
+ };
673
+
475
674
  /**
476
675
  * OneBot 11 API 封装
477
676
  * 将 ApiClient 的底层 call 转为清晰的业务方法
@@ -485,9 +684,12 @@ declare class OneBotApi {
485
684
  private fileApi;
486
685
  private streamApi;
487
686
  private requestApi;
687
+ private systemApi;
688
+ private napcatApi;
689
+ readonly raw: RawActionApi;
488
690
  constructor(client: ApiClient, logger: Logger);
489
691
  }
490
- interface OneBotApi extends MessageApi, MediaApi, AccountApi, GroupApi, FileApi, StreamApi, RequestApi {
692
+ interface OneBotApi extends MessageApi, MediaApi, AccountApi, GroupApi, FileApi, StreamApi, RequestApi, SystemApi, NapCatApi {
491
693
  }
492
694
 
493
695
  /**
@@ -511,6 +713,9 @@ type OneBotApiMethods = {
511
713
  getForwardMessage(id: string): Promise<any>;
512
714
  getEssenceMessageList(groupId: number | string): Promise<any>;
513
715
  markMessageAsRead(messageId: number | string): Promise<any>;
716
+ markGroupMsgAsRead(groupId: number | string): Promise<any>;
717
+ markPrivateMsgAsRead(userId: number | string): Promise<any>;
718
+ markAllMsgAsRead(): Promise<any>;
514
719
  getGroupAtAllRemain(groupId: number | string): Promise<any>;
515
720
  getGroupSystemMsg(): Promise<any>;
516
721
  getGroupHonorInfo(groupId: number | string, type: 'all' | 'talkative' | 'performer' | 'legend' | 'strong_newbie' | 'emotion'): Promise<any>;
@@ -532,7 +737,74 @@ type OneBotApiMethods = {
532
737
  verifyOnly?: boolean;
533
738
  }): Promise<any>;
534
739
  getUploadStreamStatus(streamId: string): Promise<any>;
740
+ downloadFileStream(fileId: string, options?: {
741
+ chunkSize?: number;
742
+ }): {
743
+ packets: AsyncIterable<any>;
744
+ result: Promise<any>;
745
+ };
746
+ downloadFileStreamToFile(fileId: string, options?: {
747
+ chunkSize?: number;
748
+ filename?: string;
749
+ }): Promise<{
750
+ path: string;
751
+ info?: any;
752
+ }>;
753
+ downloadFileImageStream(fileId: string, options?: {
754
+ chunkSize?: number;
755
+ }): {
756
+ packets: AsyncIterable<any>;
757
+ result: Promise<any>;
758
+ };
759
+ downloadFileImageStreamToFile(fileId: string, options?: {
760
+ chunkSize?: number;
761
+ filename?: string;
762
+ }): Promise<{
763
+ path: string;
764
+ info?: any;
765
+ }>;
766
+ downloadFileRecordStream(fileId: string, outFormat?: string, options?: {
767
+ chunkSize?: number;
768
+ filename?: string;
769
+ }): {
770
+ packets: AsyncIterable<any>;
771
+ result: Promise<any>;
772
+ };
773
+ downloadFileRecordStreamToFile(fileId: string, outFormat?: string, options?: {
774
+ chunkSize?: number;
775
+ filename?: string;
776
+ }): Promise<{
777
+ path: string;
778
+ info?: any;
779
+ }>;
780
+ cleanStreamTempFile(): Promise<any>;
535
781
  sendGroupForwardMessage(groupId: number | string, messages: any[]): Promise<any>;
782
+ getGroupMsgHistory(params: {
783
+ group_id: number | string;
784
+ message_seq: number | string;
785
+ count: number;
786
+ reverse_order?: boolean;
787
+ }): Promise<any>;
788
+ getFriendMsgHistory(params: {
789
+ user_id: number | string;
790
+ message_seq: number | string;
791
+ count: number;
792
+ reverse_order?: boolean;
793
+ }): Promise<any>;
794
+ getRecentContact(count: number): Promise<any>;
795
+ setMsgEmojiLike(messageId: number | string, emojiId: number, set: boolean): Promise<any>;
796
+ fetchEmojiLike(params: {
797
+ message_id: number | string;
798
+ emojiId: string;
799
+ emojiType: string;
800
+ group_id?: number | string;
801
+ user_id?: number | string;
802
+ count?: number;
803
+ }): Promise<any>;
804
+ fetchCustomFace(params?: any): Promise<any>;
805
+ sendGroupPoke(groupId: number | string, userId: number | string): Promise<any>;
806
+ sendFriendPoke(userId: number | string): Promise<any>;
807
+ sendPoke(targetId: number | string, groupId?: number | string): Promise<any>;
536
808
  getImage(file: string): Promise<any>;
537
809
  getRecord(file: string, outFormat?: string): Promise<any>;
538
810
  getFile(file: string): Promise<any>;
@@ -561,6 +833,90 @@ type OneBotApiMethods = {
561
833
  getVersionInfo(): Promise<any>;
562
834
  handleFriendRequest(flag: string, approve?: boolean, remark?: string): Promise<any>;
563
835
  handleGroupRequest(flag: string, subType: 'add' | 'invite', approve?: boolean, reason?: string): Promise<any>;
836
+ getOnlineClients(noCache?: boolean): Promise<any>;
837
+ getRobotUinRange(): Promise<any>;
838
+ canSendImage(): Promise<any>;
839
+ canSendRecord(): Promise<any>;
840
+ getCookies(domain: string): Promise<any>;
841
+ getCsrfToken(): Promise<any>;
842
+ getCredentials(domain: string): Promise<any>;
843
+ setInputStatus(userId: number | string, eventType: number): Promise<any>;
844
+ ocrImage(image: string, dot?: boolean): Promise<any>;
845
+ translateEn2zh(words: string[]): Promise<any>;
846
+ checkUrlSafely(url: string): Promise<any>;
847
+ handleQuickOperation(context: any, operation: any): Promise<any>;
848
+ getModelShow(model: string): Promise<any>;
849
+ setModelShow(model: string, modelShow: string): Promise<any>;
850
+ getPacketStatus(): Promise<any>;
851
+ getRkeyEx(): Promise<any>;
852
+ getRkeyServer(): Promise<any>;
853
+ getRkey(): Promise<any>;
854
+ setFriendRemark(userId: number | string, remark: string): Promise<any>;
855
+ deleteFriend(userId: number | string): Promise<any>;
856
+ getUnidirectionalFriendList(): Promise<any>;
857
+ setGroupRemark(groupId: number | string, remark: string): Promise<any>;
858
+ getGroupInfoEx(groupId: number | string): Promise<any>;
859
+ getGroupDetailInfo(groupId: number | string): Promise<any>;
860
+ getGroupIgnoredNotifies(): Promise<any>;
861
+ getGroupShutList(groupId: number | string): Promise<any>;
862
+ sendPrivateForwardMessage(params: {
863
+ user_id: number | string;
864
+ messages: any[];
865
+ news?: any[];
866
+ prompt?: string;
867
+ summary?: string;
868
+ source?: string;
869
+ }): Promise<any>;
870
+ forwardFriendSingleMsg(userId: number | string, messageId: number | string): Promise<any>;
871
+ forwardGroupSingleMsg(groupId: number | string, messageId: number | string): Promise<any>;
872
+ sendForwardMsg(params: {
873
+ group_id?: number | string;
874
+ user_id?: number | string;
875
+ messages: any[];
876
+ news?: any[];
877
+ prompt?: string;
878
+ summary?: string;
879
+ source?: string;
880
+ }): Promise<any>;
881
+ sendGroupNotice(params: {
882
+ group_id: number | string;
883
+ content: string;
884
+ image?: string;
885
+ pinned?: number | string;
886
+ type?: number | string;
887
+ confirm_required?: number | string;
888
+ is_show_edit_card?: number | string;
889
+ tip_window_type?: number | string;
890
+ }): Promise<any>;
891
+ getGroupNotice(groupId: number | string): Promise<any>;
892
+ delGroupNotice(groupId: number | string, noticeId: string): Promise<any>;
893
+ setOnlineStatus(status: number | string, extStatus: number | string, batteryStatus: number | string): Promise<any>;
894
+ setDiyOnlineStatus(faceId: number | string, wording?: string, faceType?: number | string): Promise<any>;
895
+ sendArkShare(params: {
896
+ user_id?: number | string;
897
+ group_id?: number | string;
898
+ phone_number?: string;
899
+ }): Promise<any>;
900
+ sendGroupArkShare(groupId: number | string): Promise<any>;
901
+ getMiniAppArk(payload: any): Promise<any>;
902
+ getAiCharacters(groupId: number | string, chatType?: number | string): Promise<any>;
903
+ getAiRecord(groupId: number | string, character: string, text: string): Promise<any>;
904
+ sendGroupAiRecord(groupId: number | string, character: string, text: string): Promise<any>;
905
+ setGroupSign(groupId: number | string): Promise<any>;
906
+ sendGroupSign(groupId: number | string): Promise<any>;
907
+ getClientkey(): Promise<any>;
908
+ clickInlineKeyboardButton(params: {
909
+ group_id: number | string;
910
+ bot_appid: string;
911
+ button_id?: string;
912
+ callback_data?: string;
913
+ msg_seq?: string;
914
+ }): Promise<any>;
915
+ /**
916
+ * Raw action table (ActionName 全覆盖)
917
+ * 访问方式:client.raw['get_group_shut_list']({ group_id: 123 })
918
+ */
919
+ raw: any;
564
920
  };
565
921
 
566
922
  /**