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 +49 -66
- package/dist/index.d.ts +1 -3
- package/dist/mjs/index.js +49 -62
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -283,7 +283,7 @@ class Lens {
|
|
|
283
283
|
this.baseURL = baseURL;
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
|
|
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
|
|
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.
|
|
333
|
+
let response = yield this.request(requestParam);
|
|
350
334
|
if (stream) {
|
|
351
335
|
return response;
|
|
352
336
|
}
|
|
353
337
|
else {
|
|
354
|
-
|
|
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
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
295
|
+
let response = await this.request(requestParam);
|
|
310
296
|
if (stream) {
|
|
311
297
|
return response;
|
|
312
298
|
}
|
|
313
299
|
else {
|
|
314
|
-
|
|
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
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
|
|
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 {
|