connectbase-client 3.16.2 → 3.17.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/dist/index.d.mts CHANGED
@@ -168,6 +168,24 @@ declare class HttpClient {
168
168
  updateConfig(config: Partial<HttpClientConfig>): void;
169
169
  setTokens(accessToken: string, refreshToken: string): void;
170
170
  clearTokens(): void;
171
+ /**
172
+ * OAuth redirect callback 직후 호출되어 HttpOnly cookie 를 부트스트랩한다.
173
+ *
174
+ * 배경: 콜백 흐름에서 서버가 redirect 응답에 Set-Cookie 를 함께 발급하지만, 일부 deployment /
175
+ * 브라우저 정책 / 사용자 설정 (3rd-party cookie 차단 등) 환경에서 이 Set-Cookie 가 브라우저에
176
+ * 저장되지 않는다. `persistence='none'` 모드에서는 토큰이 메모리에만 있고 cookie 가 없는 상태로
177
+ * 페이지 새로고침이 발생하면 `/v1/auth/re-issue` 가 401 으로 떨어져 강제 로그아웃되는 회귀가
178
+ * 있다 (platform-issue 019e3960, 2026-05-18).
179
+ *
180
+ * 이 메서드는 메모리의 refresh token 으로 한 번 `/v1/auth/re-issue` 를 호출해 서버가 cookie 를
181
+ * 명시적으로 발급하도록 유도한다. 백엔드는 Bearer + `X-Public-Key` 조합을 SDK 호출 신호로
182
+ * 인식해 응답에 `cb_member_refresh_token` cookie 를 함께 내려준다.
183
+ *
184
+ * persistence='localStorage' / 'sessionStorage' 모드는 새로고침 후에도 메모리 복구가 가능하므로
185
+ * 호출하지 않는다 (rotation 만 일어나 비용만 증가). 비-브라우저 환경에서도 cookie 자체가 없으므로
186
+ * 호출하지 않는다.
187
+ */
188
+ bootstrapRefreshCookie(): Promise<void>;
171
189
  private get persistence();
172
190
  private getStorage;
173
191
  /**
@@ -6920,6 +6938,20 @@ interface CreateDocumentRequest {
6920
6938
  source_type?: 'file' | 'text' | 'url';
6921
6939
  content?: string;
6922
6940
  source_url?: string;
6941
+ /**
6942
+ * source_type='file' 일 때 사용. 바이너리를 base64 로 인코딩해서 보낸다.
6943
+ * 서버가 PDF / DOCX / text 류를 자동으로 텍스트 추출 → 청킹·인덱싱 한다.
6944
+ * 파일 50MB 상한, 이미지 OCR / 스캔 PDF 는 미지원.
6945
+ * 일반적으로는 [`KnowledgeAPI.addDocumentFromFile`](../api/knowledge.ts) 헬퍼를 사용하면
6946
+ * Blob / File 로 직접 넘길 수 있다.
6947
+ */
6948
+ file_content?: string;
6949
+ /**
6950
+ * file_content 의 MIME (예: 'application/pdf',
6951
+ * 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'text/markdown').
6952
+ * 비어있으면 서버가 매직 바이트로 자동 추정 — 정확도를 위해 명시 권장.
6953
+ */
6954
+ mime_type?: string;
6923
6955
  metadata?: Record<string, unknown>;
6924
6956
  }
6925
6957
  interface DocumentResponse {
@@ -6988,6 +7020,18 @@ interface KnowledgeSearchResponse {
6988
7020
  total: number;
6989
7021
  }
6990
7022
 
7023
+ /**
7024
+ * `addDocumentFromFile` 입력 형식.
7025
+ *
7026
+ * - `File` (DOM) — 브라우저 `<input type="file">` 결과를 그대로 사용. name / type 이 자동 추출됨.
7027
+ * - `Blob` (DOM) — Blob.type 이 MIME 으로 사용됨 (없으면 서버 자동 추정).
7028
+ * - `{ data, mimeType?, name? }` — Node.js Buffer / Uint8Array. mimeType 명시 권장.
7029
+ */
7030
+ type KnowledgeFileInput = File | Blob | {
7031
+ data: Uint8Array | ArrayBuffer;
7032
+ mimeType?: string;
7033
+ name?: string;
7034
+ };
6991
7035
  /**
6992
7036
  * Knowledge Base API
6993
7037
  *
@@ -7055,6 +7099,50 @@ declare class KnowledgeAPI {
7055
7099
  * ```
7056
7100
  */
7057
7101
  addDocument(kbID: string, data: CreateDocumentRequest): Promise<DocumentResponse>;
7102
+ /**
7103
+ * 파일을 KB 에 추가 (PDF / DOCX / text 파일).
7104
+ *
7105
+ * 브라우저에서 `<input type="file">` 로 받은 `File` 또는 `Blob` 을 그대로 넘기면 SDK 가
7106
+ * base64 로 인코딩 + MIME 추정 후 서버에 보낸다. 서버는 PDF / DOCX / text 류를 자동
7107
+ * 텍스트 추출하여 기존 청킹·인덱싱 파이프라인을 태운다.
7108
+ *
7109
+ * 지원 MIME (2026-05 기준):
7110
+ * - `application/pdf` (텍스트 PDF — 스캔 이미지 PDF 는 미지원)
7111
+ * - `application/vnd.openxmlformats-officedocument.wordprocessingml.document` (DOCX)
7112
+ * - `text/*` (plain / markdown / csv / html)
7113
+ * - `application/json`
7114
+ *
7115
+ * 비지원 MIME (이미지 OCR / 한글 HWP / XLSX 등) 은 향후 추가될 예정 — 현재는 명시적 에러.
7116
+ *
7117
+ * 파일 크기 상한: 50MB (원본 바이너리 기준).
7118
+ *
7119
+ * @param kbID - Knowledge Base ID
7120
+ * @param file - 업로드할 파일. `File` (DOM) / `Blob` / `{ data, mimeType, name }` (Node) 모두 가능
7121
+ * @param options - name 오버라이드 + metadata
7122
+ * @returns 생성된 문서 정보 (서버에서 status='processing' → 청킹 완료 후 'ready')
7123
+ *
7124
+ * @example
7125
+ * ```typescript
7126
+ * // 브라우저: <input type="file"> 로 받은 File
7127
+ * const file = event.target.files[0]
7128
+ * const doc = await cb.knowledge.addDocumentFromFile('kb-id', file, {
7129
+ * metadata: { tag: 'manual' }
7130
+ * })
7131
+ *
7132
+ * // Node.js: fs.readFileSync 로 읽은 Buffer
7133
+ * import { readFileSync } from 'node:fs'
7134
+ * const data = readFileSync('./report.pdf')
7135
+ * const doc = await cb.knowledge.addDocumentFromFile('kb-id', {
7136
+ * data,
7137
+ * mimeType: 'application/pdf',
7138
+ * name: 'report.pdf',
7139
+ * })
7140
+ * ```
7141
+ */
7142
+ addDocumentFromFile(kbID: string, file: KnowledgeFileInput, options?: {
7143
+ name?: string;
7144
+ metadata?: Record<string, unknown>;
7145
+ }): Promise<DocumentResponse>;
7058
7146
  /**
7059
7147
  * 문서 목록 조회
7060
7148
  *
package/dist/index.d.ts CHANGED
@@ -168,6 +168,24 @@ declare class HttpClient {
168
168
  updateConfig(config: Partial<HttpClientConfig>): void;
169
169
  setTokens(accessToken: string, refreshToken: string): void;
170
170
  clearTokens(): void;
171
+ /**
172
+ * OAuth redirect callback 직후 호출되어 HttpOnly cookie 를 부트스트랩한다.
173
+ *
174
+ * 배경: 콜백 흐름에서 서버가 redirect 응답에 Set-Cookie 를 함께 발급하지만, 일부 deployment /
175
+ * 브라우저 정책 / 사용자 설정 (3rd-party cookie 차단 등) 환경에서 이 Set-Cookie 가 브라우저에
176
+ * 저장되지 않는다. `persistence='none'` 모드에서는 토큰이 메모리에만 있고 cookie 가 없는 상태로
177
+ * 페이지 새로고침이 발생하면 `/v1/auth/re-issue` 가 401 으로 떨어져 강제 로그아웃되는 회귀가
178
+ * 있다 (platform-issue 019e3960, 2026-05-18).
179
+ *
180
+ * 이 메서드는 메모리의 refresh token 으로 한 번 `/v1/auth/re-issue` 를 호출해 서버가 cookie 를
181
+ * 명시적으로 발급하도록 유도한다. 백엔드는 Bearer + `X-Public-Key` 조합을 SDK 호출 신호로
182
+ * 인식해 응답에 `cb_member_refresh_token` cookie 를 함께 내려준다.
183
+ *
184
+ * persistence='localStorage' / 'sessionStorage' 모드는 새로고침 후에도 메모리 복구가 가능하므로
185
+ * 호출하지 않는다 (rotation 만 일어나 비용만 증가). 비-브라우저 환경에서도 cookie 자체가 없으므로
186
+ * 호출하지 않는다.
187
+ */
188
+ bootstrapRefreshCookie(): Promise<void>;
171
189
  private get persistence();
172
190
  private getStorage;
173
191
  /**
@@ -6920,6 +6938,20 @@ interface CreateDocumentRequest {
6920
6938
  source_type?: 'file' | 'text' | 'url';
6921
6939
  content?: string;
6922
6940
  source_url?: string;
6941
+ /**
6942
+ * source_type='file' 일 때 사용. 바이너리를 base64 로 인코딩해서 보낸다.
6943
+ * 서버가 PDF / DOCX / text 류를 자동으로 텍스트 추출 → 청킹·인덱싱 한다.
6944
+ * 파일 50MB 상한, 이미지 OCR / 스캔 PDF 는 미지원.
6945
+ * 일반적으로는 [`KnowledgeAPI.addDocumentFromFile`](../api/knowledge.ts) 헬퍼를 사용하면
6946
+ * Blob / File 로 직접 넘길 수 있다.
6947
+ */
6948
+ file_content?: string;
6949
+ /**
6950
+ * file_content 의 MIME (예: 'application/pdf',
6951
+ * 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'text/markdown').
6952
+ * 비어있으면 서버가 매직 바이트로 자동 추정 — 정확도를 위해 명시 권장.
6953
+ */
6954
+ mime_type?: string;
6923
6955
  metadata?: Record<string, unknown>;
6924
6956
  }
6925
6957
  interface DocumentResponse {
@@ -6988,6 +7020,18 @@ interface KnowledgeSearchResponse {
6988
7020
  total: number;
6989
7021
  }
6990
7022
 
7023
+ /**
7024
+ * `addDocumentFromFile` 입력 형식.
7025
+ *
7026
+ * - `File` (DOM) — 브라우저 `<input type="file">` 결과를 그대로 사용. name / type 이 자동 추출됨.
7027
+ * - `Blob` (DOM) — Blob.type 이 MIME 으로 사용됨 (없으면 서버 자동 추정).
7028
+ * - `{ data, mimeType?, name? }` — Node.js Buffer / Uint8Array. mimeType 명시 권장.
7029
+ */
7030
+ type KnowledgeFileInput = File | Blob | {
7031
+ data: Uint8Array | ArrayBuffer;
7032
+ mimeType?: string;
7033
+ name?: string;
7034
+ };
6991
7035
  /**
6992
7036
  * Knowledge Base API
6993
7037
  *
@@ -7055,6 +7099,50 @@ declare class KnowledgeAPI {
7055
7099
  * ```
7056
7100
  */
7057
7101
  addDocument(kbID: string, data: CreateDocumentRequest): Promise<DocumentResponse>;
7102
+ /**
7103
+ * 파일을 KB 에 추가 (PDF / DOCX / text 파일).
7104
+ *
7105
+ * 브라우저에서 `<input type="file">` 로 받은 `File` 또는 `Blob` 을 그대로 넘기면 SDK 가
7106
+ * base64 로 인코딩 + MIME 추정 후 서버에 보낸다. 서버는 PDF / DOCX / text 류를 자동
7107
+ * 텍스트 추출하여 기존 청킹·인덱싱 파이프라인을 태운다.
7108
+ *
7109
+ * 지원 MIME (2026-05 기준):
7110
+ * - `application/pdf` (텍스트 PDF — 스캔 이미지 PDF 는 미지원)
7111
+ * - `application/vnd.openxmlformats-officedocument.wordprocessingml.document` (DOCX)
7112
+ * - `text/*` (plain / markdown / csv / html)
7113
+ * - `application/json`
7114
+ *
7115
+ * 비지원 MIME (이미지 OCR / 한글 HWP / XLSX 등) 은 향후 추가될 예정 — 현재는 명시적 에러.
7116
+ *
7117
+ * 파일 크기 상한: 50MB (원본 바이너리 기준).
7118
+ *
7119
+ * @param kbID - Knowledge Base ID
7120
+ * @param file - 업로드할 파일. `File` (DOM) / `Blob` / `{ data, mimeType, name }` (Node) 모두 가능
7121
+ * @param options - name 오버라이드 + metadata
7122
+ * @returns 생성된 문서 정보 (서버에서 status='processing' → 청킹 완료 후 'ready')
7123
+ *
7124
+ * @example
7125
+ * ```typescript
7126
+ * // 브라우저: <input type="file"> 로 받은 File
7127
+ * const file = event.target.files[0]
7128
+ * const doc = await cb.knowledge.addDocumentFromFile('kb-id', file, {
7129
+ * metadata: { tag: 'manual' }
7130
+ * })
7131
+ *
7132
+ * // Node.js: fs.readFileSync 로 읽은 Buffer
7133
+ * import { readFileSync } from 'node:fs'
7134
+ * const data = readFileSync('./report.pdf')
7135
+ * const doc = await cb.knowledge.addDocumentFromFile('kb-id', {
7136
+ * data,
7137
+ * mimeType: 'application/pdf',
7138
+ * name: 'report.pdf',
7139
+ * })
7140
+ * ```
7141
+ */
7142
+ addDocumentFromFile(kbID: string, file: KnowledgeFileInput, options?: {
7143
+ name?: string;
7144
+ metadata?: Record<string, unknown>;
7145
+ }): Promise<DocumentResponse>;
7058
7146
  /**
7059
7147
  * 문서 목록 조회
7060
7148
  *
package/dist/index.js CHANGED
@@ -193,6 +193,32 @@ var HttpClient = class {
193
193
  this.config.refreshToken = void 0;
194
194
  this.removePersistedTokens();
195
195
  }
196
+ /**
197
+ * OAuth redirect callback 직후 호출되어 HttpOnly cookie 를 부트스트랩한다.
198
+ *
199
+ * 배경: 콜백 흐름에서 서버가 redirect 응답에 Set-Cookie 를 함께 발급하지만, 일부 deployment /
200
+ * 브라우저 정책 / 사용자 설정 (3rd-party cookie 차단 등) 환경에서 이 Set-Cookie 가 브라우저에
201
+ * 저장되지 않는다. `persistence='none'` 모드에서는 토큰이 메모리에만 있고 cookie 가 없는 상태로
202
+ * 페이지 새로고침이 발생하면 `/v1/auth/re-issue` 가 401 으로 떨어져 강제 로그아웃되는 회귀가
203
+ * 있다 (platform-issue 019e3960, 2026-05-18).
204
+ *
205
+ * 이 메서드는 메모리의 refresh token 으로 한 번 `/v1/auth/re-issue` 를 호출해 서버가 cookie 를
206
+ * 명시적으로 발급하도록 유도한다. 백엔드는 Bearer + `X-Public-Key` 조합을 SDK 호출 신호로
207
+ * 인식해 응답에 `cb_member_refresh_token` cookie 를 함께 내려준다.
208
+ *
209
+ * persistence='localStorage' / 'sessionStorage' 모드는 새로고침 후에도 메모리 복구가 가능하므로
210
+ * 호출하지 않는다 (rotation 만 일어나 비용만 증가). 비-브라우저 환경에서도 cookie 자체가 없으므로
211
+ * 호출하지 않는다.
212
+ */
213
+ async bootstrapRefreshCookie() {
214
+ if (typeof window === "undefined") return;
215
+ if (this.persistence !== "none") return;
216
+ if (!this.config.refreshToken) return;
217
+ try {
218
+ await this.refreshAccessToken();
219
+ } catch {
220
+ }
221
+ }
196
222
  // ===== Token Persistence =====
197
223
  get persistence() {
198
224
  return this.config.persistence ?? "none";
@@ -4758,6 +4784,7 @@ var OAuthAPI = class {
4758
4784
  return result;
4759
4785
  }
4760
4786
  this.http.setTokens(accessToken, refreshToken);
4787
+ void this.http.bootstrapRefreshCookie();
4761
4788
  return result;
4762
4789
  }
4763
4790
  /**
@@ -4796,6 +4823,7 @@ var OAuthAPI = class {
4796
4823
  return result;
4797
4824
  }
4798
4825
  this.http.setTokens(result.access_token, result.refresh_token);
4826
+ void this.http.bootstrapRefreshCookie();
4799
4827
  return result;
4800
4828
  }
4801
4829
  };
@@ -7939,6 +7967,40 @@ var NativeAPI = class {
7939
7967
  };
7940
7968
 
7941
7969
  // src/api/knowledge.ts
7970
+ async function readFileInput(file) {
7971
+ if (typeof Blob !== "undefined" && file instanceof Blob) {
7972
+ const buffer = await file.arrayBuffer();
7973
+ const name = "name" in file ? file.name : void 0;
7974
+ return {
7975
+ data: bytesToBase64(new Uint8Array(buffer)),
7976
+ mimeType: file.type || "",
7977
+ defaultName: name
7978
+ };
7979
+ }
7980
+ const obj = file;
7981
+ if (!obj || obj.data === void 0) {
7982
+ throw new Error("addDocumentFromFile: file must be a Blob/File or { data, mimeType?, name? }");
7983
+ }
7984
+ const bytes = obj.data instanceof Uint8Array ? obj.data : new Uint8Array(obj.data);
7985
+ return {
7986
+ data: bytesToBase64(bytes),
7987
+ mimeType: obj.mimeType ?? "",
7988
+ defaultName: obj.name
7989
+ };
7990
+ }
7991
+ function bytesToBase64(bytes) {
7992
+ const g = globalThis;
7993
+ if (g.Buffer) {
7994
+ return g.Buffer.from(bytes).toString("base64");
7995
+ }
7996
+ const chunkSize = 8192;
7997
+ let binary = "";
7998
+ for (let i = 0; i < bytes.length; i += chunkSize) {
7999
+ const chunk = bytes.subarray(i, Math.min(i + chunkSize, bytes.length));
8000
+ binary += String.fromCharCode.apply(null, Array.from(chunk));
8001
+ }
8002
+ return btoa(binary);
8003
+ }
7942
8004
  var KnowledgeAPI = class {
7943
8005
  constructor(http) {
7944
8006
  this.http = http;
@@ -7976,6 +8038,57 @@ var KnowledgeAPI = class {
7976
8038
  data
7977
8039
  );
7978
8040
  }
8041
+ /**
8042
+ * 파일을 KB 에 추가 (PDF / DOCX / text 파일).
8043
+ *
8044
+ * 브라우저에서 `<input type="file">` 로 받은 `File` 또는 `Blob` 을 그대로 넘기면 SDK 가
8045
+ * base64 로 인코딩 + MIME 추정 후 서버에 보낸다. 서버는 PDF / DOCX / text 류를 자동
8046
+ * 텍스트 추출하여 기존 청킹·인덱싱 파이프라인을 태운다.
8047
+ *
8048
+ * 지원 MIME (2026-05 기준):
8049
+ * - `application/pdf` (텍스트 PDF — 스캔 이미지 PDF 는 미지원)
8050
+ * - `application/vnd.openxmlformats-officedocument.wordprocessingml.document` (DOCX)
8051
+ * - `text/*` (plain / markdown / csv / html)
8052
+ * - `application/json`
8053
+ *
8054
+ * 비지원 MIME (이미지 OCR / 한글 HWP / XLSX 등) 은 향후 추가될 예정 — 현재는 명시적 에러.
8055
+ *
8056
+ * 파일 크기 상한: 50MB (원본 바이너리 기준).
8057
+ *
8058
+ * @param kbID - Knowledge Base ID
8059
+ * @param file - 업로드할 파일. `File` (DOM) / `Blob` / `{ data, mimeType, name }` (Node) 모두 가능
8060
+ * @param options - name 오버라이드 + metadata
8061
+ * @returns 생성된 문서 정보 (서버에서 status='processing' → 청킹 완료 후 'ready')
8062
+ *
8063
+ * @example
8064
+ * ```typescript
8065
+ * // 브라우저: <input type="file"> 로 받은 File
8066
+ * const file = event.target.files[0]
8067
+ * const doc = await cb.knowledge.addDocumentFromFile('kb-id', file, {
8068
+ * metadata: { tag: 'manual' }
8069
+ * })
8070
+ *
8071
+ * // Node.js: fs.readFileSync 로 읽은 Buffer
8072
+ * import { readFileSync } from 'node:fs'
8073
+ * const data = readFileSync('./report.pdf')
8074
+ * const doc = await cb.knowledge.addDocumentFromFile('kb-id', {
8075
+ * data,
8076
+ * mimeType: 'application/pdf',
8077
+ * name: 'report.pdf',
8078
+ * })
8079
+ * ```
8080
+ */
8081
+ async addDocumentFromFile(kbID, file, options) {
8082
+ const { data, mimeType, defaultName } = await readFileInput(file);
8083
+ const name = options?.name ?? defaultName ?? "document";
8084
+ return this.addDocument(kbID, {
8085
+ name,
8086
+ source_type: "file",
8087
+ file_content: data,
8088
+ mime_type: mimeType,
8089
+ metadata: options?.metadata
8090
+ });
8091
+ }
7979
8092
  /**
7980
8093
  * 문서 목록 조회
7981
8094
  *
package/dist/index.mjs CHANGED
@@ -150,6 +150,32 @@ var HttpClient = class {
150
150
  this.config.refreshToken = void 0;
151
151
  this.removePersistedTokens();
152
152
  }
153
+ /**
154
+ * OAuth redirect callback 직후 호출되어 HttpOnly cookie 를 부트스트랩한다.
155
+ *
156
+ * 배경: 콜백 흐름에서 서버가 redirect 응답에 Set-Cookie 를 함께 발급하지만, 일부 deployment /
157
+ * 브라우저 정책 / 사용자 설정 (3rd-party cookie 차단 등) 환경에서 이 Set-Cookie 가 브라우저에
158
+ * 저장되지 않는다. `persistence='none'` 모드에서는 토큰이 메모리에만 있고 cookie 가 없는 상태로
159
+ * 페이지 새로고침이 발생하면 `/v1/auth/re-issue` 가 401 으로 떨어져 강제 로그아웃되는 회귀가
160
+ * 있다 (platform-issue 019e3960, 2026-05-18).
161
+ *
162
+ * 이 메서드는 메모리의 refresh token 으로 한 번 `/v1/auth/re-issue` 를 호출해 서버가 cookie 를
163
+ * 명시적으로 발급하도록 유도한다. 백엔드는 Bearer + `X-Public-Key` 조합을 SDK 호출 신호로
164
+ * 인식해 응답에 `cb_member_refresh_token` cookie 를 함께 내려준다.
165
+ *
166
+ * persistence='localStorage' / 'sessionStorage' 모드는 새로고침 후에도 메모리 복구가 가능하므로
167
+ * 호출하지 않는다 (rotation 만 일어나 비용만 증가). 비-브라우저 환경에서도 cookie 자체가 없으므로
168
+ * 호출하지 않는다.
169
+ */
170
+ async bootstrapRefreshCookie() {
171
+ if (typeof window === "undefined") return;
172
+ if (this.persistence !== "none") return;
173
+ if (!this.config.refreshToken) return;
174
+ try {
175
+ await this.refreshAccessToken();
176
+ } catch {
177
+ }
178
+ }
153
179
  // ===== Token Persistence =====
154
180
  get persistence() {
155
181
  return this.config.persistence ?? "none";
@@ -4715,6 +4741,7 @@ var OAuthAPI = class {
4715
4741
  return result;
4716
4742
  }
4717
4743
  this.http.setTokens(accessToken, refreshToken);
4744
+ void this.http.bootstrapRefreshCookie();
4718
4745
  return result;
4719
4746
  }
4720
4747
  /**
@@ -4753,6 +4780,7 @@ var OAuthAPI = class {
4753
4780
  return result;
4754
4781
  }
4755
4782
  this.http.setTokens(result.access_token, result.refresh_token);
4783
+ void this.http.bootstrapRefreshCookie();
4756
4784
  return result;
4757
4785
  }
4758
4786
  };
@@ -7896,6 +7924,40 @@ var NativeAPI = class {
7896
7924
  };
7897
7925
 
7898
7926
  // src/api/knowledge.ts
7927
+ async function readFileInput(file) {
7928
+ if (typeof Blob !== "undefined" && file instanceof Blob) {
7929
+ const buffer = await file.arrayBuffer();
7930
+ const name = "name" in file ? file.name : void 0;
7931
+ return {
7932
+ data: bytesToBase64(new Uint8Array(buffer)),
7933
+ mimeType: file.type || "",
7934
+ defaultName: name
7935
+ };
7936
+ }
7937
+ const obj = file;
7938
+ if (!obj || obj.data === void 0) {
7939
+ throw new Error("addDocumentFromFile: file must be a Blob/File or { data, mimeType?, name? }");
7940
+ }
7941
+ const bytes = obj.data instanceof Uint8Array ? obj.data : new Uint8Array(obj.data);
7942
+ return {
7943
+ data: bytesToBase64(bytes),
7944
+ mimeType: obj.mimeType ?? "",
7945
+ defaultName: obj.name
7946
+ };
7947
+ }
7948
+ function bytesToBase64(bytes) {
7949
+ const g = globalThis;
7950
+ if (g.Buffer) {
7951
+ return g.Buffer.from(bytes).toString("base64");
7952
+ }
7953
+ const chunkSize = 8192;
7954
+ let binary = "";
7955
+ for (let i = 0; i < bytes.length; i += chunkSize) {
7956
+ const chunk = bytes.subarray(i, Math.min(i + chunkSize, bytes.length));
7957
+ binary += String.fromCharCode.apply(null, Array.from(chunk));
7958
+ }
7959
+ return btoa(binary);
7960
+ }
7899
7961
  var KnowledgeAPI = class {
7900
7962
  constructor(http) {
7901
7963
  this.http = http;
@@ -7933,6 +7995,57 @@ var KnowledgeAPI = class {
7933
7995
  data
7934
7996
  );
7935
7997
  }
7998
+ /**
7999
+ * 파일을 KB 에 추가 (PDF / DOCX / text 파일).
8000
+ *
8001
+ * 브라우저에서 `<input type="file">` 로 받은 `File` 또는 `Blob` 을 그대로 넘기면 SDK 가
8002
+ * base64 로 인코딩 + MIME 추정 후 서버에 보낸다. 서버는 PDF / DOCX / text 류를 자동
8003
+ * 텍스트 추출하여 기존 청킹·인덱싱 파이프라인을 태운다.
8004
+ *
8005
+ * 지원 MIME (2026-05 기준):
8006
+ * - `application/pdf` (텍스트 PDF — 스캔 이미지 PDF 는 미지원)
8007
+ * - `application/vnd.openxmlformats-officedocument.wordprocessingml.document` (DOCX)
8008
+ * - `text/*` (plain / markdown / csv / html)
8009
+ * - `application/json`
8010
+ *
8011
+ * 비지원 MIME (이미지 OCR / 한글 HWP / XLSX 등) 은 향후 추가될 예정 — 현재는 명시적 에러.
8012
+ *
8013
+ * 파일 크기 상한: 50MB (원본 바이너리 기준).
8014
+ *
8015
+ * @param kbID - Knowledge Base ID
8016
+ * @param file - 업로드할 파일. `File` (DOM) / `Blob` / `{ data, mimeType, name }` (Node) 모두 가능
8017
+ * @param options - name 오버라이드 + metadata
8018
+ * @returns 생성된 문서 정보 (서버에서 status='processing' → 청킹 완료 후 'ready')
8019
+ *
8020
+ * @example
8021
+ * ```typescript
8022
+ * // 브라우저: <input type="file"> 로 받은 File
8023
+ * const file = event.target.files[0]
8024
+ * const doc = await cb.knowledge.addDocumentFromFile('kb-id', file, {
8025
+ * metadata: { tag: 'manual' }
8026
+ * })
8027
+ *
8028
+ * // Node.js: fs.readFileSync 로 읽은 Buffer
8029
+ * import { readFileSync } from 'node:fs'
8030
+ * const data = readFileSync('./report.pdf')
8031
+ * const doc = await cb.knowledge.addDocumentFromFile('kb-id', {
8032
+ * data,
8033
+ * mimeType: 'application/pdf',
8034
+ * name: 'report.pdf',
8035
+ * })
8036
+ * ```
8037
+ */
8038
+ async addDocumentFromFile(kbID, file, options) {
8039
+ const { data, mimeType, defaultName } = await readFileInput(file);
8040
+ const name = options?.name ?? defaultName ?? "document";
8041
+ return this.addDocument(kbID, {
8042
+ name,
8043
+ source_type: "file",
8044
+ file_content: data,
8045
+ mime_type: mimeType,
8046
+ metadata: options?.metadata
8047
+ });
8048
+ }
7936
8049
  /**
7937
8050
  * 문서 목록 조회
7938
8051
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "connectbase-client",
3
- "version": "3.16.2",
3
+ "version": "3.17.0",
4
4
  "description": "Connect Base JavaScript/TypeScript SDK for browser and Node.js",
5
5
  "repository": {
6
6
  "type": "git",