vectocore4 0.0.27 → 0.0.29

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
@@ -283,7 +283,7 @@ class Lens {
283
283
  this.baseURL = baseURL;
284
284
  }
285
285
  }
286
- requestStream(requestBody) {
286
+ request(requestBody) {
287
287
  return __awaiter(this, void 0, void 0, function* () {
288
288
  let header = {
289
289
  "x-tenant-key": this.tenantKey ? this.tenantKey : "",
@@ -294,23 +294,7 @@ class Lens {
294
294
  body: JSON.stringify(requestBody),
295
295
  };
296
296
  const response = yield fetch(this.baseURL, request);
297
- return response.body;
298
- });
299
- }
300
- genStreamResponse(streamRes) {
301
- return __awaiter(this, void 0, void 0, function* () {
302
- const reader = streamRes === null || streamRes === void 0 ? void 0 : streamRes.getReader();
303
- const decoder = new TextDecoder();
304
- let done = false;
305
- let content = "";
306
- while (!done) {
307
- const { value, done: doneReading } = yield reader.read();
308
- done = doneReading; // 스트림 완료시 true
309
- const chunkValue = decoder.decode(value);
310
- content = content + chunkValue;
311
- }
312
- const payload = JSON.parse(content);
313
- return payload;
297
+ return response;
314
298
  });
315
299
  }
316
300
  chat(_a) {
@@ -346,70 +330,69 @@ class Lens {
346
330
  requestParam.params.static_info = staticInfo;
347
331
  if (customSystemPrompt)
348
332
  requestParam.params.custom_system_prompt = customSystemPrompt;
349
- let response = yield this.requestStream(requestParam);
333
+ let response = yield this.request(requestParam);
350
334
  if (stream) {
351
335
  return response;
352
336
  }
353
337
  else {
354
- const res = yield this.genStreamResponse(response);
355
- return res;
338
+ return response.json();
356
339
  }
357
340
  });
358
341
  }
359
- history(_a) {
360
- return __awaiter(this, arguments, void 0, function* ({ sessionKey, limit }) {
361
- const requestParam = {
362
- command: "lensChatHistory",
363
- sessionKey: sessionKey,
364
- };
365
- if (limit)
366
- requestParam.limit = limit;
367
- let response = yield this.requestStream(requestParam);
368
- const res = yield this.genStreamResponse(response);
369
- return res;
370
- });
371
- }
372
342
  jsonAutoComplete(jsonString) {
373
- const dataCloseChar = {
374
- "{": "}",
375
- "[": "]",
376
- '"': '"',
377
- };
378
343
  if (!jsonString)
379
344
  return null;
380
- let string = jsonString
381
- .trim()
382
- .replace(/(\r\n|\n|\r|\s{2,})/gm, "")
383
- .replace(/(?<=:)([a-zA-Z]+)(?=\s*(?![,\}])(?:[,\}\s]|$))/g, " null");
384
- let missingChars = [];
385
- for (let i = 0; i < string.length; i++) {
386
- const char = string[i];
387
- if (char === missingChars[missingChars.length - 1]) {
388
- missingChars.pop();
345
+ const stack = [];
346
+ let isInsideString = false;
347
+ let isEscaped = false;
348
+ for (let i = 0; i < jsonString.length; i++) {
349
+ const char = jsonString[i];
350
+ if (isEscaped) {
351
+ isEscaped = false;
352
+ continue;
389
353
  }
390
- else if (dataCloseChar[char]) {
391
- missingChars.push(dataCloseChar[char]);
392
- if (char === "{") {
393
- missingChars.push(":");
354
+ if (char === "\\") {
355
+ isEscaped = true;
356
+ continue;
357
+ }
358
+ if (char === '"') {
359
+ isInsideString = !isInsideString;
360
+ continue;
361
+ }
362
+ if (!isInsideString) {
363
+ if (char === "{")
364
+ stack.push("}");
365
+ else if (char === "[")
366
+ stack.push("]");
367
+ else if (char === "}" || char === "]") {
368
+ if (stack.length > 0 && stack[stack.length - 1] === char) {
369
+ stack.pop();
370
+ }
394
371
  }
395
372
  }
396
373
  }
397
- if (missingChars[missingChars.length - 1] === ":") {
398
- if (string[string.length - 1] !== "{") {
399
- missingChars[missingChars.length - 1] = ": null";
400
- }
401
- else {
402
- missingChars.pop();
374
+ let result = jsonString.trim();
375
+ // 1. 문자열이 열린 채로 끝났다면 따옴표 닫기
376
+ if (isInsideString) {
377
+ result += '"';
378
+ }
379
+ // 2. trailing comma 제거 (중요: ", ]" 또는 ", }" 방지)
380
+ result = result.replace(/,\s*$/, "");
381
+ // 3. 스택을 역순으로 닫기 전에, 속성 이름만 있고 값이 없는 경우 처리
382
+ // 예: "key": 문자로 끝난 경우
383
+ if (result.endsWith(":")) {
384
+ result += "null";
385
+ }
386
+ // 4. 남아있는 모든 괄호 닫기
387
+ for (let i = stack.length - 1; i >= 0; i--) {
388
+ const closingChar = stack[i];
389
+ // 배열 중간에서 끊겼을 때를 위한 보정 (예: [{}, { -> [{}, {}])
390
+ if (closingChar === "]" && result.endsWith(",")) {
391
+ result = result.slice(0, -1);
403
392
  }
393
+ result += closingChar;
404
394
  }
405
- const missingCharsString = missingChars.reverse().join("");
406
- const completeString = string + missingCharsString;
407
- const cleanedString = completeString
408
- .replace(/"":/g, "")
409
- .replace(/":}|": }/g, '": null }')
410
- .replace(/,""}|,}|,\"\w+\"}/g, "}")
411
- .replace(/},]/g, "}]");
412
- return cleanedString;
395
+ return result;
413
396
  }
414
397
  }
415
398
  exports.Lens = Lens;
package/dist/index.d.ts CHANGED
@@ -324,10 +324,8 @@ export declare class Lens {
324
324
  * @param {string | undefined} [opts.tenantKey=process.env['VECTOCORE4_TENANT_KEY'] ?? undefined]
325
325
  */
326
326
  constructor({ tenantKey, baseURL }: ClientOptions);
327
- protected requestStream(requestBody: any): Promise<ReadableStream<Uint8Array> | null>;
328
- protected genStreamResponse(streamRes: ReadableStream): Promise<any>;
327
+ protected request(requestBody: any): Promise<Response>;
329
328
  chat({ question, stream, model, xfinder, webSearch, agentic, imageUrls, fileUrls, customContext, sessionKey, maxHisCount, withStatus, staticInfo, customSystemPrompt, }: LensChatParams): Promise<any>;
330
- history({ sessionKey, limit }: ChatHistoryParams): Promise<any>;
331
329
  jsonAutoComplete(jsonString: string): string | null;
332
330
  }
333
331
  export declare class AIMS {
package/dist/mjs/index.js CHANGED
@@ -248,7 +248,7 @@ export class Lens {
248
248
  this.baseURL = baseURL;
249
249
  }
250
250
  }
251
- async requestStream(requestBody) {
251
+ async request(requestBody) {
252
252
  let header = {
253
253
  "x-tenant-key": this.tenantKey ? this.tenantKey : "",
254
254
  };
@@ -258,21 +258,7 @@ export class Lens {
258
258
  body: JSON.stringify(requestBody),
259
259
  };
260
260
  const response = await fetch(this.baseURL, request);
261
- return response.body;
262
- }
263
- async genStreamResponse(streamRes) {
264
- const reader = streamRes?.getReader();
265
- const decoder = new TextDecoder();
266
- let done = false;
267
- let content = "";
268
- while (!done) {
269
- const { value, done: doneReading } = await reader.read();
270
- done = doneReading; // 스트림 완료시 true
271
- const chunkValue = decoder.decode(value);
272
- content = content + chunkValue;
273
- }
274
- const payload = JSON.parse(content);
275
- return payload;
261
+ return response;
276
262
  }
277
263
  async chat({ question, stream, model, xfinder, webSearch, agentic, imageUrls, fileUrls, customContext, sessionKey, maxHisCount, withStatus, staticInfo, customSystemPrompt, }) {
278
264
  const requestParam = {
@@ -306,67 +292,68 @@ export class Lens {
306
292
  requestParam.params.static_info = staticInfo;
307
293
  if (customSystemPrompt)
308
294
  requestParam.params.custom_system_prompt = customSystemPrompt;
309
- let response = await this.requestStream(requestParam);
295
+ let response = await this.request(requestParam);
310
296
  if (stream) {
311
297
  return response;
312
298
  }
313
299
  else {
314
- const res = await this.genStreamResponse(response);
315
- return res;
300
+ return response.json();
316
301
  }
317
302
  }
318
- async history({ sessionKey, limit }) {
319
- const requestParam = {
320
- command: "lensChatHistory",
321
- sessionKey: sessionKey,
322
- };
323
- if (limit)
324
- requestParam.limit = limit;
325
- let response = await this.requestStream(requestParam);
326
- const res = await this.genStreamResponse(response);
327
- return res;
328
- }
329
303
  jsonAutoComplete(jsonString) {
330
- const dataCloseChar = {
331
- "{": "}",
332
- "[": "]",
333
- '"': '"',
334
- };
335
304
  if (!jsonString)
336
305
  return null;
337
- let string = jsonString
338
- .trim()
339
- .replace(/(\r\n|\n|\r|\s{2,})/gm, "")
340
- .replace(/(?<=:)([a-zA-Z]+)(?=\s*(?![,\}])(?:[,\}\s]|$))/g, " null");
341
- let missingChars = [];
342
- for (let i = 0; i < string.length; i++) {
343
- const char = string[i];
344
- if (char === missingChars[missingChars.length - 1]) {
345
- missingChars.pop();
306
+ const stack = [];
307
+ let isInsideString = false;
308
+ let isEscaped = false;
309
+ for (let i = 0; i < jsonString.length; i++) {
310
+ const char = jsonString[i];
311
+ if (isEscaped) {
312
+ isEscaped = false;
313
+ continue;
346
314
  }
347
- else if (dataCloseChar[char]) {
348
- missingChars.push(dataCloseChar[char]);
349
- if (char === "{") {
350
- missingChars.push(":");
315
+ if (char === "\\") {
316
+ isEscaped = true;
317
+ continue;
318
+ }
319
+ if (char === '"') {
320
+ isInsideString = !isInsideString;
321
+ continue;
322
+ }
323
+ if (!isInsideString) {
324
+ if (char === "{")
325
+ stack.push("}");
326
+ else if (char === "[")
327
+ stack.push("]");
328
+ else if (char === "}" || char === "]") {
329
+ if (stack.length > 0 && stack[stack.length - 1] === char) {
330
+ stack.pop();
331
+ }
351
332
  }
352
333
  }
353
334
  }
354
- if (missingChars[missingChars.length - 1] === ":") {
355
- if (string[string.length - 1] !== "{") {
356
- missingChars[missingChars.length - 1] = ": null";
357
- }
358
- else {
359
- missingChars.pop();
335
+ let result = jsonString.trim();
336
+ // 1. 문자열이 열린 채로 끝났다면 따옴표 닫기
337
+ if (isInsideString) {
338
+ result += '"';
339
+ }
340
+ // 2. trailing comma 제거 (중요: ", ]" 또는 ", }" 방지)
341
+ result = result.replace(/,\s*$/, "");
342
+ // 3. 스택을 역순으로 닫기 전에, 속성 이름만 있고 값이 없는 경우 처리
343
+ // 예: "key": 문자로 끝난 경우
344
+ if (result.endsWith(":")) {
345
+ result += "null";
346
+ }
347
+ // 4. 남아있는 모든 괄호 닫기
348
+ for (let i = stack.length - 1; i >= 0; i--) {
349
+ const closingChar = stack[i];
350
+ // 배열 중간에서 끊겼을 때를 위한 보정 (예: [{}, { -> [{}, {}])
351
+ if (closingChar === "]" && result.endsWith(",")) {
352
+ result = result.slice(0, -1);
360
353
  }
354
+ result += closingChar;
361
355
  }
362
- const missingCharsString = missingChars.reverse().join("");
363
- const completeString = string + missingCharsString;
364
- const cleanedString = completeString
365
- .replace(/"":/g, "")
366
- .replace(/":}|": }/g, '": null }')
367
- .replace(/,""}|,}|,\"\w+\"}/g, "}")
368
- .replace(/},]/g, "}]");
369
- return cleanedString;
356
+ return result;
370
357
  }
371
358
  }
372
359
  export class AIMS {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vectocore4",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/cjs/index.js",