@getnote/mcp 1.5.3 → 1.7.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/src/client.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import axios, { AxiosInstance, AxiosError } from "axios";
2
2
 
3
- const BASE_URL = "https://openapi.biji.com/open/api/v1";
3
+ const DEFAULT_BASE_URL = "https://openapi.biji.com/open/api/v1";
4
+
5
+ function normalizeBaseURL(value?: string): string {
6
+ const base = (value || DEFAULT_BASE_URL).replace(/\/+$/, "");
7
+ if (base.endsWith("/open/api/v1")) return base;
8
+ if (base.endsWith("/open")) return `${base}/api/v1`;
9
+ return `${base}/open/api/v1`;
10
+ }
4
11
 
5
12
  /**
6
13
  * Preserves long-integer ID fields as JSON strings before JSON.parse, so JS
@@ -12,11 +19,14 @@ const BASE_URL = "https://openapi.biji.com/open/api/v1";
12
19
  * Matches only when the captured field value has 16+ digits, so short IDs
13
20
  * remain numbers.
14
21
  */
15
- function parseJsonPreservingLargeIntegerStrings(data: unknown) {
22
+ export function parseJsonPreservingLargeIntegerStrings(data: unknown) {
16
23
  if (typeof data !== "string" || data.trim() === "") return data;
17
24
  const safe = data.replace(
18
- /"(note_id|next_cursor|cursor|id|parent_id|topic_id|since_id|share_id)"\s*:\s*(\d{16,})/g,
25
+ /"(note_id|next_cursor|cursor|id|parent_id|topic_id|since_id|share_id|follow_id|live_id)"\s*:\s*(\d{16,})/g,
19
26
  '"$1":"$2"'
27
+ ).replace(
28
+ /([:[,]\s*)(-?\d{16,})(?=\s*[,}\]])/g,
29
+ '$1"$2"'
20
30
  );
21
31
  return JSON.parse(safe);
22
32
  }
@@ -26,7 +36,11 @@ export class GetNoteAPIError extends Error {
26
36
  public readonly code: number,
27
37
  public readonly reason: string,
28
38
  message: string,
29
- public readonly requestId?: string
39
+ public readonly requestId?: string,
40
+ public readonly retryable: boolean = false,
41
+ public readonly field?: string,
42
+ public readonly constraint?: string,
43
+ public readonly expectedType?: string
30
44
  ) {
31
45
  super(message);
32
46
  this.name = "GetNoteAPIError";
@@ -36,9 +50,9 @@ export class GetNoteAPIError extends Error {
36
50
  export class GetNoteClient {
37
51
  private http: AxiosInstance;
38
52
 
39
- constructor(apiKey: string, clientId: string) {
53
+ constructor(apiKey: string, clientId: string, baseURL?: string) {
40
54
  this.http = axios.create({
41
- baseURL: BASE_URL,
55
+ baseURL: normalizeBaseURL(baseURL || process.env.GETNOTE_API_URL),
42
56
  headers: {
43
57
  Authorization: `Bearer ${apiKey}`,
44
58
  "X-Client-ID": clientId,
@@ -66,7 +80,7 @@ export class GetNoteClient {
66
80
  const res = await this.http.request<{
67
81
  success: boolean;
68
82
  data: T;
69
- error?: { code: number; message: string; reason: string };
83
+ error?: APIErrorBody;
70
84
  request_id?: string;
71
85
  }>({
72
86
  method,
@@ -82,7 +96,11 @@ export class GetNoteClient {
82
96
  err?.code ?? -1,
83
97
  err?.reason ?? "unknown",
84
98
  err?.message ?? "API request failed",
85
- body.request_id
99
+ body.request_id,
100
+ err?.retryable ?? false,
101
+ err?.field,
102
+ err?.constraint,
103
+ err?.expected_type
86
104
  );
87
105
  }
88
106
 
@@ -93,7 +111,7 @@ export class GetNoteClient {
93
111
  if (axios.isAxiosError(err) && err.response) {
94
112
  const body = err.response.data as {
95
113
  success?: boolean;
96
- error?: { code: number; message: string; reason: string };
114
+ error?: APIErrorBody;
97
115
  request_id?: string;
98
116
  };
99
117
  if (body?.error) {
@@ -101,7 +119,11 @@ export class GetNoteClient {
101
119
  body.error.code,
102
120
  body.error.reason,
103
121
  body.error.message,
104
- body.request_id
122
+ body.request_id,
123
+ body.error.retryable ?? false,
124
+ body.error.field,
125
+ body.error.constraint,
126
+ body.error.expected_type
105
127
  );
106
128
  }
107
129
  throw new Error(`HTTP ${err.response.status}: ${err.message}`);
@@ -119,7 +141,7 @@ export class GetNoteClient {
119
141
  });
120
142
  }
121
143
 
122
- async getNote(id: number | string, image_quality?: string) {
144
+ async getNote(id: string | number, image_quality?: string) {
123
145
  return this.request<GetNoteResp>("GET", "/resource/note/detail", { id, image_quality });
124
146
  }
125
147
 
@@ -198,29 +220,29 @@ export class GetNoteClient {
198
220
  const FormData = (await import("form-data")).default;
199
221
  const form = new FormData();
200
222
 
223
+ form.append("key", token.object_key);
201
224
  form.append("OSSAccessKeyId", token.accessid);
202
225
  form.append("policy", token.policy);
203
- form.append("Signature", token.signature);
204
- form.append("key", token.object_key);
226
+ form.append("signature", token.signature);
205
227
  form.append("callback", token.callback);
206
- form.append("success_action_status", "200");
228
+ form.append("Content-Type", token.oss_content_type);
207
229
  form.append("file", imageData, {
208
230
  filename: "image",
209
231
  contentType: token.oss_content_type,
210
232
  });
211
233
 
212
- const response = await fetch(token.host, {
213
- method: "POST",
214
- body: form as unknown as BodyInit,
234
+ const response = await axios.post(token.host, form, {
215
235
  headers: form.getHeaders(),
236
+ maxBodyLength: Infinity,
237
+ validateStatus: () => true,
216
238
  });
217
239
 
218
- if (!response.ok) {
240
+ if (response.status < 200 || response.status >= 300) {
219
241
  throw new Error(`OSS upload failed: ${response.status}`);
220
242
  }
221
243
 
222
244
  // 解析回调响应: {"h":{"c":0},"c":{"image":{"id":"xxx"}}}
223
- const result = await response.json() as { h: { c: number }; c: { image: { id: string } } };
245
+ const result = response.data as { h: { c: number }; c: { image: { id: string } } };
224
246
  if (result.h?.c !== 0) {
225
247
  throw new Error("OSS callback failed");
226
248
  }
@@ -273,7 +295,7 @@ export class GetNoteClient {
273
295
  );
274
296
  }
275
297
 
276
- async batchAddNotesToTopic(body: { topic_id: string; note_ids: string[] }) {
298
+ async batchAddNotesToTopic(body: { topic_id: string; note_ids: string[]; directory_id?: string }) {
277
299
  return this.request<BatchAddNotesResp>(
278
300
  "POST",
279
301
  "/resource/knowledge/note/batch-add",
@@ -282,6 +304,24 @@ export class GetNoteClient {
282
304
  );
283
305
  }
284
306
 
307
+ async listTopicDirectories(params: { topic_id: string; directory_id?: string }) {
308
+ return this.request<KnowledgeDirectoryListResp>(
309
+ "GET", "/resource/knowledge/directories", params
310
+ );
311
+ }
312
+
313
+ async createTopicDirectory(body: { topic_id: string; name: string; parent_id?: string }) {
314
+ return this.request<KnowledgeDirectory>("POST", "/resource/knowledge/directory/create", undefined, body);
315
+ }
316
+
317
+ async updateTopicDirectory(body: { topic_id: string; directory_id: string; name?: string; parent_id?: string }) {
318
+ return this.request<Record<string, unknown>>("POST", "/resource/knowledge/directory/update", undefined, body);
319
+ }
320
+
321
+ async deleteTopicDirectory(body: { topic_id: string; directory_id: string }) {
322
+ return this.request<Record<string, unknown>>("POST", "/resource/knowledge/directory/delete", undefined, body);
323
+ }
324
+
285
325
  async removeNoteFromTopic(body: { topic_id: string; note_ids: string[] }) {
286
326
  return this.request<RemoveNoteResp>(
287
327
  "POST",
@@ -301,6 +341,13 @@ export class GetNoteClient {
301
341
  );
302
342
  }
303
343
 
344
+ async followTopicBlogger(params: { topic_id: string; link: string; platform?: string }) {
345
+ return this.request<Record<string, unknown>>(
346
+ "POST", "/resource/knowledge/blogger/follow", undefined,
347
+ { topic_id: params.topic_id, link: params.link, platform: params.platform ?? "douyin" }
348
+ );
349
+ }
350
+
304
351
  async listTopicBloggerContents(params: {
305
352
  topic_id: string;
306
353
  follow_id: number | string;
@@ -432,6 +479,16 @@ export interface NoteDetail extends NoteItem {
432
479
  /** 链接原文(网页正文内容) */
433
480
  content?: string;
434
481
  };
482
+ quick_note?: string;
483
+ timeline?: {
484
+ version: number;
485
+ moments: { start_ms: number; end_ms: number; text: string }[];
486
+ resources: { type: string; url: string; action_time: number }[];
487
+ };
488
+ meeting_todos?: {
489
+ source: "summary_markdown_rules";
490
+ items: { text: string; completed: boolean }[];
491
+ };
435
492
  share_id?: string;
436
493
  version?: number;
437
494
  }
@@ -454,12 +511,13 @@ export interface GetNoteResp {
454
511
  }
455
512
 
456
513
  export interface SaveNoteReq {
457
- id?: number | string;
458
514
  title?: string;
459
515
  content?: string;
460
516
  note_type?: "plain_text" | "link" | "img_text";
461
517
  tags?: string[];
462
- parent_id?: number | string;
518
+ topic_id?: string;
519
+ parent_id?: string | number;
520
+ client_request_id?: string;
463
521
  link_url?: string;
464
522
  image_urls?: string[];
465
523
  }
@@ -472,11 +530,15 @@ export interface NoteTaskItem {
472
530
  }
473
531
 
474
532
  export interface SaveNoteResp {
475
- id: string;
476
- title: string;
477
- created_at: string;
478
- updated_at: string;
533
+ /** Legacy numeric field; transformed to a string when it exceeds JS safe range. */
534
+ id?: string | number;
535
+ /** Canonical lossless note ID. */
536
+ note_id?: string;
537
+ title?: string;
538
+ created_at?: string;
539
+ updated_at?: string;
479
540
  message?: string;
541
+ result?: "created" | "accepted";
480
542
  /** 链接笔记创建时返回的任务列表 */
481
543
  tasks?: NoteTaskItem[];
482
544
  /** 成功创建的笔记数量 */
@@ -485,6 +547,8 @@ export interface SaveNoteResp {
485
547
  duplicate_count?: number;
486
548
  /** 无效的链接数量 */
487
549
  invalid_count?: number;
550
+ duplicate_urls?: string[];
551
+ invalid_urls?: string[];
488
552
  }
489
553
 
490
554
  export interface NoteTaskProgress {
@@ -599,6 +663,30 @@ export interface RemoveNoteResp {
599
663
  failed_note_ids: string[];
600
664
  }
601
665
 
666
+ export interface KnowledgeDirectory {
667
+ id: string;
668
+ topic_id: string;
669
+ parent_id: string;
670
+ name: string;
671
+ type: string;
672
+ resource_desc?: string;
673
+ }
674
+
675
+ export interface KnowledgeDirectoryListResp {
676
+ current_directory?: KnowledgeDirectory;
677
+ directories: KnowledgeDirectory[];
678
+ resources: Array<{
679
+ id: string;
680
+ directory_id: string;
681
+ note_id?: string;
682
+ name: string;
683
+ url?: string;
684
+ type: string;
685
+ status: string;
686
+ }>;
687
+ total: number;
688
+ }
689
+
602
690
  export interface QuotaInfo {
603
691
  limit: number;
604
692
  used: number;
@@ -620,7 +708,8 @@ export interface GetQuotaResp {
620
708
  // ─── Blogger Types ───────────────────────────────────────────────────────────
621
709
 
622
710
  export interface BloggerItem {
623
- follow_id: number;
711
+ follow_id: string | number;
712
+ follow_id_str?: string;
624
713
  account_name: string;
625
714
  account_avatar: string;
626
715
  notes_count: number;
@@ -663,8 +752,9 @@ export interface BloggerContentDetail extends BloggerContentItem {
663
752
  // ─── Live Types ──────────────────────────────────────────────────────────────
664
753
 
665
754
  export interface LiveItem {
666
- live_id: string | number; // API may return string or number
667
- follow_id: number;
755
+ live_id: string;
756
+ follow_id: string | number;
757
+ follow_id_str?: string;
668
758
  name: string;
669
759
  cover: string;
670
760
  sub_title: string;
@@ -697,7 +787,8 @@ export interface LiveDetail {
697
787
  // ─── Follow Topic Live Types ─────────────────────────────────────────────────
698
788
 
699
789
  export interface FollowTopicLiveResp {
700
- follow_id: number;
790
+ follow_id: string | number;
791
+ follow_id_str?: string;
701
792
  url: string;
702
793
  platform: string;
703
794
  type: string;
@@ -729,6 +820,16 @@ export interface UpdateNoteReq {
729
820
  tags?: string[];
730
821
  }
731
822
 
823
+ interface APIErrorBody {
824
+ code: number;
825
+ message: string;
826
+ reason: string;
827
+ retryable?: boolean;
828
+ field?: string;
829
+ constraint?: string;
830
+ expected_type?: string;
831
+ }
832
+
732
833
  export interface UpdateNoteResp {
733
834
  note_id: string;
734
835
  title: string;