vectocore4 0.0.30 → 0.0.32

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/cjs/index.js CHANGED
@@ -414,7 +414,7 @@ class AIMS {
414
414
  this.baseURL = baseURL;
415
415
  }
416
416
  }
417
- requestStream(requestBody) {
417
+ request(requestBody) {
418
418
  return __awaiter(this, void 0, void 0, function* () {
419
419
  let header = {
420
420
  "x-tenant-key": this.tenantKey ? this.tenantKey : "",
@@ -425,108 +425,137 @@ class AIMS {
425
425
  body: JSON.stringify(requestBody),
426
426
  };
427
427
  const response = yield fetch(this.baseURL, request);
428
- return response.body;
429
- });
430
- }
431
- genStreamResponse(streamRes) {
432
- return __awaiter(this, void 0, void 0, function* () {
433
- const reader = streamRes === null || streamRes === void 0 ? void 0 : streamRes.getReader();
434
- const decoder = new TextDecoder();
435
- let done = false;
436
- let content = "";
437
- while (!done) {
438
- const { value, done: doneReading } = yield reader.read();
439
- done = doneReading; // 스트림 완료시 true
440
- const chunkValue = decoder.decode(value);
441
- content = content + chunkValue;
442
- }
443
- const payload = JSON.parse(content);
444
- return payload;
428
+ return response;
445
429
  });
446
430
  }
447
- keypoint(text) {
431
+ /**
432
+ * Keypoint AI 에이전트는 입력된 문자열을 분석하여 유용한 키워드들을 분류하여 응답하는 기능을 수행합니다.
433
+ * @param text: string (필수) 키워드를 추출할 원문 텍스트
434
+ * @param stream: boolean (선택) Default : true
435
+ * @returns
436
+ * - `stream: true` 인 경우: 브라우저 표준 {@link Response} 객체 (ReadableStream 포함)
437
+ * - `stream: false` 인 경우: JSON 데이터
438
+ */
439
+ keypoint(text, stream) {
448
440
  return __awaiter(this, void 0, void 0, function* () {
449
441
  const requestParam = {
450
442
  command: "keywords",
451
443
  text: text,
444
+ stream: stream !== null && stream !== void 0 ? stream : true,
452
445
  };
453
- const response = yield this.requestStream(requestParam);
454
- const res = yield this.genStreamResponse(response);
455
- return res;
446
+ const response = yield this.request(requestParam);
447
+ if (stream) {
448
+ return response;
449
+ }
450
+ else {
451
+ return response.json();
452
+ }
456
453
  });
457
454
  }
458
- imCap(imageUrl) {
455
+ /**
456
+ * ImCap AI 에이전트는 이미지를 AI로 분석하여 캡셔닝하는 AI 에이전트 입니다.
457
+ * @param imageUrl: string (필수) 설명을 추출할 이미지의 URL
458
+ * @param stream: boolean (선택) Default : true
459
+ * @returns
460
+ * - `stream: true` 인 경우: 브라우저 표준 {@link Response} 객체 (ReadableStream 포함)
461
+ * - `stream: false` 인 경우: JSON 데이터
462
+ */
463
+ imCap(imageUrl, stream) {
459
464
  return __awaiter(this, void 0, void 0, function* () {
460
465
  const requestParam = {
461
466
  command: "imCap",
462
467
  imageUrl: imageUrl,
468
+ stream: stream !== null && stream !== void 0 ? stream : true,
463
469
  };
464
- const response = yield this.requestStream(requestParam);
465
- const res = yield this.genStreamResponse(response);
466
- return res;
470
+ const response = yield this.request(requestParam);
471
+ if (stream) {
472
+ return response;
473
+ }
474
+ else {
475
+ return response.json();
476
+ }
467
477
  });
468
478
  }
469
- translate(_a) {
470
- return __awaiter(this, arguments, void 0, function* ({ language, text, stream }) {
479
+ /**
480
+ * Translate는 AI 번역을 제공하는 AI 에이전트 입니다.
481
+ * @param language : (필수) 번역할 국가의 언어명(korean, english, Spanish ...)
482
+ * @param text : (필수) 번역할 원문
483
+ * @param stream : boolean (선택) Default : true
484
+ * @returns
485
+ * - `stream: true` 인 경우: 브라우저 표준 {@link Response} 객체 (ReadableStream 포함)
486
+ * - `stream: false` 인 경우: JSON 데이터
487
+ */
488
+ translate(language, text, stream) {
489
+ return __awaiter(this, void 0, void 0, function* () {
471
490
  const requestParam = {
472
491
  command: "translate",
473
492
  language: language,
474
493
  text: text,
494
+ stream: stream !== null && stream !== void 0 ? stream : true,
475
495
  };
476
- let response = yield this.requestStream(requestParam);
496
+ const response = yield this.request(requestParam);
477
497
  if (stream) {
478
498
  return response;
479
499
  }
480
500
  else {
481
- const res = yield this.genStreamResponse(response);
482
- return res;
501
+ return response.json();
483
502
  }
484
503
  });
485
504
  }
486
505
  jsonAutoComplete(jsonString) {
487
- const dataCloseChar = {
488
- "{": "}",
489
- "[": "]",
490
- '"': '"',
491
- };
492
506
  if (!jsonString)
493
507
  return null;
494
- let string = jsonString
495
- .trim()
496
- .replace(/(\r\n|\n|\r|\s{2,})/gm, "")
497
- // 속성명이 따옴표 없이 나올 경우 null 치환
498
- .replace(/:\s*([a-zA-Z0-9_]+)(?=\s*[,\}])/g, ": null")
499
- // 속성명이 따옴표 없이 시작하는 경우 → 강제로 따옴표 감싸기
500
- .replace(/([{,])\s*([a-zA-Z0-9_]+)\s*:/g, '$1"$2":');
501
- let missingChars = [];
502
- for (let i = 0; i < string.length; i++) {
503
- const char = string[i];
504
- if (char === missingChars[missingChars.length - 1]) {
505
- missingChars.pop();
508
+ const stack = [];
509
+ let isInsideString = false;
510
+ let isEscaped = false;
511
+ for (let i = 0; i < jsonString.length; i++) {
512
+ const char = jsonString[i];
513
+ if (isEscaped) {
514
+ isEscaped = false;
515
+ continue;
506
516
  }
507
- else if (dataCloseChar[char]) {
508
- missingChars.push(dataCloseChar[char]);
509
- if (char === "{") {
510
- missingChars.push(":");
517
+ if (char === "\\") {
518
+ isEscaped = true;
519
+ continue;
520
+ }
521
+ if (char === '"') {
522
+ isInsideString = !isInsideString;
523
+ continue;
524
+ }
525
+ if (!isInsideString) {
526
+ if (char === "{")
527
+ stack.push("}");
528
+ else if (char === "[")
529
+ stack.push("]");
530
+ else if (char === "}" || char === "]") {
531
+ if (stack.length > 0 && stack[stack.length - 1] === char) {
532
+ stack.pop();
533
+ }
511
534
  }
512
535
  }
513
536
  }
514
- if (missingChars[missingChars.length - 1] === ":") {
515
- if (string[string.length - 1] !== "{") {
516
- missingChars[missingChars.length - 1] = ": null";
517
- }
518
- else {
519
- missingChars.pop();
537
+ let result = jsonString.trim();
538
+ // 1. 문자열이 열린 채로 끝났다면 따옴표 닫기
539
+ if (isInsideString) {
540
+ result += '"';
541
+ }
542
+ // 2. trailing comma 제거 (중요: ", ]" 또는 ", }" 방지)
543
+ result = result.replace(/,\s*$/, "");
544
+ // 3. 스택을 역순으로 닫기 전에, 속성 이름만 있고 값이 없는 경우 처리
545
+ // 예: "key": 문자로 끝난 경우
546
+ if (result.endsWith(":")) {
547
+ result += "null";
548
+ }
549
+ // 4. 남아있는 모든 괄호 닫기
550
+ for (let i = stack.length - 1; i >= 0; i--) {
551
+ const closingChar = stack[i];
552
+ // 배열 중간에서 끊겼을 때를 위한 보정 (예: [{}, { -> [{}, {}])
553
+ if (closingChar === "]" && result.endsWith(",")) {
554
+ result = result.slice(0, -1);
520
555
  }
556
+ result += closingChar;
521
557
  }
522
- const missingCharsString = missingChars.reverse().join("");
523
- const completeString = string + missingCharsString;
524
- const cleanedString = completeString
525
- .replace(/"":/g, "")
526
- .replace(/":}|": }/g, '": null }')
527
- .replace(/,""}|,}|,\"\w+\"}/g, "}")
528
- .replace(/},]/g, "}]");
529
- return cleanedString;
558
+ return result;
530
559
  }
531
560
  }
532
561
  exports.AIMS = AIMS;
package/dist/index.d.ts CHANGED
@@ -210,11 +210,6 @@ export interface ChatHistoryParams {
210
210
  sessionKey: string;
211
211
  limit?: number;
212
212
  }
213
- export interface TranslateParams {
214
- language: string;
215
- text: string;
216
- stream?: boolean | undefined;
217
- }
218
213
  export declare class Vectocore {
219
214
  tenantKey: string | undefined;
220
215
  baseURL: string;
@@ -337,11 +332,35 @@ export declare class AIMS {
337
332
  * @param {string | undefined} [opts.tenantKey=process.env['VECTOCORE4_TENANT_KEY'] ?? undefined]
338
333
  */
339
334
  constructor({ baseURL, tenantKey }?: ClientOptions);
340
- protected requestStream(requestBody: any): Promise<ReadableStream<Uint8Array> | null>;
341
- protected genStreamResponse(streamRes: ReadableStream): Promise<any>;
342
- keypoint(text: string): Promise<any>;
343
- imCap(imageUrl: string): Promise<any>;
344
- translate({ language, text, stream }: TranslateParams): Promise<any>;
335
+ protected request(requestBody: any): Promise<Response>;
336
+ /**
337
+ * Keypoint AI 에이전트는 입력된 문자열을 분석하여 유용한 키워드들을 분류하여 응답하는 기능을 수행합니다.
338
+ * @param text: string (필수) 키워드를 추출할 원문 텍스트
339
+ * @param stream: boolean (선택) Default : true
340
+ * @returns
341
+ * - `stream: true` 인 경우: 브라우저 표준 {@link Response} 객체 (ReadableStream 포함)
342
+ * - `stream: false` 인 경우: JSON 데이터
343
+ */
344
+ keypoint(text: string, stream: boolean): Promise<any>;
345
+ /**
346
+ * ImCap AI 에이전트는 이미지를 AI로 분석하여 캡셔닝하는 AI 에이전트 입니다.
347
+ * @param imageUrl: string (필수) 설명을 추출할 이미지의 URL
348
+ * @param stream: boolean (선택) Default : true
349
+ * @returns
350
+ * - `stream: true` 인 경우: 브라우저 표준 {@link Response} 객체 (ReadableStream 포함)
351
+ * - `stream: false` 인 경우: JSON 데이터
352
+ */
353
+ imCap(imageUrl: string, stream: boolean): Promise<any>;
354
+ /**
355
+ * Translate는 AI 번역을 제공하는 AI 에이전트 입니다.
356
+ * @param language : (필수) 번역할 국가의 언어명(korean, english, Spanish ...)
357
+ * @param text : (필수) 번역할 원문
358
+ * @param stream : boolean (선택) Default : true
359
+ * @returns
360
+ * - `stream: true` 인 경우: 브라우저 표준 {@link Response} 객체 (ReadableStream 포함)
361
+ * - `stream: false` 인 경우: JSON 데이터
362
+ */
363
+ translate(language: string, text: string, stream: boolean): Promise<any>;
345
364
  jsonAutoComplete(jsonString: string): string | null;
346
365
  }
347
366
  export {};
package/dist/mjs/index.js CHANGED
@@ -376,7 +376,7 @@ export class AIMS {
376
376
  this.baseURL = baseURL;
377
377
  }
378
378
  }
379
- async requestStream(requestBody) {
379
+ async request(requestBody) {
380
380
  let header = {
381
381
  "x-tenant-key": this.tenantKey ? this.tenantKey : "",
382
382
  };
@@ -386,98 +386,129 @@ export class AIMS {
386
386
  body: JSON.stringify(requestBody),
387
387
  };
388
388
  const response = await fetch(this.baseURL, request);
389
- return response.body;
390
- }
391
- async genStreamResponse(streamRes) {
392
- const reader = streamRes?.getReader();
393
- const decoder = new TextDecoder();
394
- let done = false;
395
- let content = "";
396
- while (!done) {
397
- const { value, done: doneReading } = await reader.read();
398
- done = doneReading; // 스트림 완료시 true
399
- const chunkValue = decoder.decode(value);
400
- content = content + chunkValue;
401
- }
402
- const payload = JSON.parse(content);
403
- return payload;
389
+ return response;
404
390
  }
405
- async keypoint(text) {
391
+ /**
392
+ * Keypoint AI 에이전트는 입력된 문자열을 분석하여 유용한 키워드들을 분류하여 응답하는 기능을 수행합니다.
393
+ * @param text: string (필수) 키워드를 추출할 원문 텍스트
394
+ * @param stream: boolean (선택) Default : true
395
+ * @returns
396
+ * - `stream: true` 인 경우: 브라우저 표준 {@link Response} 객체 (ReadableStream 포함)
397
+ * - `stream: false` 인 경우: JSON 데이터
398
+ */
399
+ async keypoint(text, stream) {
406
400
  const requestParam = {
407
401
  command: "keywords",
408
402
  text: text,
403
+ stream: stream ?? true,
409
404
  };
410
- const response = await this.requestStream(requestParam);
411
- const res = await this.genStreamResponse(response);
412
- return res;
405
+ const response = await this.request(requestParam);
406
+ if (stream) {
407
+ return response;
408
+ }
409
+ else {
410
+ return response.json();
411
+ }
413
412
  }
414
- async imCap(imageUrl) {
413
+ /**
414
+ * ImCap AI 에이전트는 이미지를 AI로 분석하여 캡셔닝하는 AI 에이전트 입니다.
415
+ * @param imageUrl: string (필수) 설명을 추출할 이미지의 URL
416
+ * @param stream: boolean (선택) Default : true
417
+ * @returns
418
+ * - `stream: true` 인 경우: 브라우저 표준 {@link Response} 객체 (ReadableStream 포함)
419
+ * - `stream: false` 인 경우: JSON 데이터
420
+ */
421
+ async imCap(imageUrl, stream) {
415
422
  const requestParam = {
416
423
  command: "imCap",
417
424
  imageUrl: imageUrl,
425
+ stream: stream ?? true,
418
426
  };
419
- const response = await this.requestStream(requestParam);
420
- const res = await this.genStreamResponse(response);
421
- return res;
427
+ const response = await this.request(requestParam);
428
+ if (stream) {
429
+ return response;
430
+ }
431
+ else {
432
+ return response.json();
433
+ }
422
434
  }
423
- async translate({ language, text, stream }) {
435
+ /**
436
+ * Translate는 AI 번역을 제공하는 AI 에이전트 입니다.
437
+ * @param language : (필수) 번역할 국가의 언어명(korean, english, Spanish ...)
438
+ * @param text : (필수) 번역할 원문
439
+ * @param stream : boolean (선택) Default : true
440
+ * @returns
441
+ * - `stream: true` 인 경우: 브라우저 표준 {@link Response} 객체 (ReadableStream 포함)
442
+ * - `stream: false` 인 경우: JSON 데이터
443
+ */
444
+ async translate(language, text, stream) {
424
445
  const requestParam = {
425
446
  command: "translate",
426
447
  language: language,
427
448
  text: text,
449
+ stream: stream ?? true,
428
450
  };
429
- let response = await this.requestStream(requestParam);
451
+ const response = await this.request(requestParam);
430
452
  if (stream) {
431
453
  return response;
432
454
  }
433
455
  else {
434
- const res = await this.genStreamResponse(response);
435
- return res;
456
+ return response.json();
436
457
  }
437
458
  }
438
459
  jsonAutoComplete(jsonString) {
439
- const dataCloseChar = {
440
- "{": "}",
441
- "[": "]",
442
- '"': '"',
443
- };
444
460
  if (!jsonString)
445
461
  return null;
446
- let string = jsonString
447
- .trim()
448
- .replace(/(\r\n|\n|\r|\s{2,})/gm, "")
449
- // 속성명이 따옴표 없이 나올 경우 null 치환
450
- .replace(/:\s*([a-zA-Z0-9_]+)(?=\s*[,\}])/g, ": null")
451
- // 속성명이 따옴표 없이 시작하는 경우 → 강제로 따옴표 감싸기
452
- .replace(/([{,])\s*([a-zA-Z0-9_]+)\s*:/g, '$1"$2":');
453
- let missingChars = [];
454
- for (let i = 0; i < string.length; i++) {
455
- const char = string[i];
456
- if (char === missingChars[missingChars.length - 1]) {
457
- missingChars.pop();
462
+ const stack = [];
463
+ let isInsideString = false;
464
+ let isEscaped = false;
465
+ for (let i = 0; i < jsonString.length; i++) {
466
+ const char = jsonString[i];
467
+ if (isEscaped) {
468
+ isEscaped = false;
469
+ continue;
470
+ }
471
+ if (char === "\\") {
472
+ isEscaped = true;
473
+ continue;
474
+ }
475
+ if (char === '"') {
476
+ isInsideString = !isInsideString;
477
+ continue;
458
478
  }
459
- else if (dataCloseChar[char]) {
460
- missingChars.push(dataCloseChar[char]);
461
- if (char === "{") {
462
- missingChars.push(":");
479
+ if (!isInsideString) {
480
+ if (char === "{")
481
+ stack.push("}");
482
+ else if (char === "[")
483
+ stack.push("]");
484
+ else if (char === "}" || char === "]") {
485
+ if (stack.length > 0 && stack[stack.length - 1] === char) {
486
+ stack.pop();
487
+ }
463
488
  }
464
489
  }
465
490
  }
466
- if (missingChars[missingChars.length - 1] === ":") {
467
- if (string[string.length - 1] !== "{") {
468
- missingChars[missingChars.length - 1] = ": null";
469
- }
470
- else {
471
- missingChars.pop();
491
+ let result = jsonString.trim();
492
+ // 1. 문자열이 열린 채로 끝났다면 따옴표 닫기
493
+ if (isInsideString) {
494
+ result += '"';
495
+ }
496
+ // 2. trailing comma 제거 (중요: ", ]" 또는 ", }" 방지)
497
+ result = result.replace(/,\s*$/, "");
498
+ // 3. 스택을 역순으로 닫기 전에, 속성 이름만 있고 값이 없는 경우 처리
499
+ // 예: "key": 문자로 끝난 경우
500
+ if (result.endsWith(":")) {
501
+ result += "null";
502
+ }
503
+ // 4. 남아있는 모든 괄호 닫기
504
+ for (let i = stack.length - 1; i >= 0; i--) {
505
+ const closingChar = stack[i];
506
+ // 배열 중간에서 끊겼을 때를 위한 보정 (예: [{}, { -> [{}, {}])
507
+ if (closingChar === "]" && result.endsWith(",")) {
508
+ result = result.slice(0, -1);
472
509
  }
510
+ result += closingChar;
473
511
  }
474
- const missingCharsString = missingChars.reverse().join("");
475
- const completeString = string + missingCharsString;
476
- const cleanedString = completeString
477
- .replace(/"":/g, "")
478
- .replace(/":}|": }/g, '": null }')
479
- .replace(/,""}|,}|,\"\w+\"}/g, "}")
480
- .replace(/},]/g, "}]");
481
- return cleanedString;
512
+ return result;
482
513
  }
483
514
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vectocore4",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/cjs/index.js",