mem0ai 3.0.0 → 3.0.2

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.
@@ -40,7 +40,8 @@ var MemoryConfigSchema = z.object({
40
40
  model: z.union([z.string(), z.any()]).optional(),
41
41
  modelProperties: z.record(z.string(), z.any()).optional(),
42
42
  baseURL: z.string().optional(),
43
- url: z.string().optional()
43
+ url: z.string().optional(),
44
+ timeout: z.number().optional()
44
45
  })
45
46
  }),
46
47
  historyDbPath: z.string().optional(),
@@ -211,7 +212,8 @@ var OpenAILLM = class {
211
212
  constructor(config) {
212
213
  this.openai = new OpenAI3({
213
214
  apiKey: config.apiKey,
214
- baseURL: config.baseURL
215
+ baseURL: config.baseURL,
216
+ ...config.timeout != null && { timeout: config.timeout }
215
217
  });
216
218
  this.model = config.model || "gpt-5-mini";
217
219
  }
@@ -264,7 +266,11 @@ var OpenAILLM = class {
264
266
  import OpenAI4 from "openai";
265
267
  var OpenAIStructuredLLM = class {
266
268
  constructor(config) {
267
- this.openai = new OpenAI4({ apiKey: config.apiKey });
269
+ this.openai = new OpenAI4({
270
+ apiKey: config.apiKey,
271
+ baseURL: config.baseURL,
272
+ ...config.timeout != null && { timeout: config.timeout }
273
+ });
268
274
  this.model = config.model || "gpt-5-mini";
269
275
  }
270
276
  async generateResponse(messages, responseFormat, tools) {
@@ -3489,17 +3495,105 @@ function removeCodeBlocks(text) {
3489
3495
  return stripped.replace(/<think>[\s\S]*?<\/think>/g, "").trim();
3490
3496
  }
3491
3497
  function extractJson(text) {
3492
- const cleaned = removeCodeBlocks(text);
3498
+ let cleaned = text.replace(/<\|end_of_text\|>/g, "").replace(/<\|eot_id\|>/g, "").replace(/<\|im_end\|>/g, "").replace(/<\|im_start\|>/g, "").replace(/<\|endoftext\|>/g, "");
3499
+ cleaned = removeCodeBlocks(cleaned);
3493
3500
  const trimmed = cleaned.trim();
3501
+ if (!trimmed) return "";
3502
+ const braceIndices = [];
3503
+ for (let i = 0; i < trimmed.length; i++) {
3504
+ if (trimmed[i] === "{") braceIndices.push(i);
3505
+ }
3506
+ for (const start of braceIndices) {
3507
+ let depth = 0;
3508
+ let inString = false;
3509
+ let escapeNext = false;
3510
+ for (let i = start; i < trimmed.length; i++) {
3511
+ const char = trimmed[i];
3512
+ if (escapeNext) {
3513
+ escapeNext = false;
3514
+ continue;
3515
+ }
3516
+ if (char === "\\") {
3517
+ escapeNext = true;
3518
+ continue;
3519
+ }
3520
+ if (char === '"' && !escapeNext) {
3521
+ inString = !inString;
3522
+ continue;
3523
+ }
3524
+ if (inString) continue;
3525
+ if (char === "{") depth++;
3526
+ else if (char === "}") {
3527
+ depth--;
3528
+ if (depth === 0) {
3529
+ const candidate = trimmed.substring(start, i + 1);
3530
+ try {
3531
+ JSON.parse(candidate);
3532
+ return candidate;
3533
+ } catch (e) {
3534
+ break;
3535
+ }
3536
+ }
3537
+ }
3538
+ }
3539
+ }
3494
3540
  const firstBrace = trimmed.indexOf("{");
3495
3541
  const lastBrace = trimmed.lastIndexOf("}");
3496
3542
  if (firstBrace !== -1 && lastBrace > firstBrace) {
3497
- return trimmed.substring(firstBrace, lastBrace + 1);
3543
+ const candidate = trimmed.substring(firstBrace, lastBrace + 1);
3544
+ try {
3545
+ JSON.parse(candidate);
3546
+ return candidate;
3547
+ } catch (e) {
3548
+ }
3549
+ }
3550
+ const bracketIndices = [];
3551
+ for (let i = 0; i < trimmed.length; i++) {
3552
+ if (trimmed[i] === "[") bracketIndices.push(i);
3553
+ }
3554
+ for (const start of bracketIndices) {
3555
+ let depth = 0;
3556
+ let inString = false;
3557
+ let escapeNext = false;
3558
+ for (let i = start; i < trimmed.length; i++) {
3559
+ const char = trimmed[i];
3560
+ if (escapeNext) {
3561
+ escapeNext = false;
3562
+ continue;
3563
+ }
3564
+ if (char === "\\") {
3565
+ escapeNext = true;
3566
+ continue;
3567
+ }
3568
+ if (char === '"' && !escapeNext) {
3569
+ inString = !inString;
3570
+ continue;
3571
+ }
3572
+ if (inString) continue;
3573
+ if (char === "[") depth++;
3574
+ else if (char === "]") {
3575
+ depth--;
3576
+ if (depth === 0) {
3577
+ const candidate = trimmed.substring(start, i + 1);
3578
+ try {
3579
+ JSON.parse(candidate);
3580
+ return candidate;
3581
+ } catch (e) {
3582
+ break;
3583
+ }
3584
+ }
3585
+ }
3586
+ }
3498
3587
  }
3499
3588
  const firstBracket = trimmed.indexOf("[");
3500
3589
  const lastBracket = trimmed.lastIndexOf("]");
3501
3590
  if (firstBracket !== -1 && lastBracket > firstBracket) {
3502
- return trimmed.substring(firstBracket, lastBracket + 1);
3591
+ const candidate = trimmed.substring(firstBracket, lastBracket + 1);
3592
+ try {
3593
+ JSON.parse(candidate);
3594
+ return candidate;
3595
+ } catch (e) {
3596
+ }
3503
3597
  }
3504
3598
  return trimmed;
3505
3599
  }
@@ -4869,7 +4963,7 @@ var parse_vision_messages = async (messages) => {
4869
4963
  };
4870
4964
 
4871
4965
  // src/oss/src/utils/telemetry.ts
4872
- var version = "2.1.34";
4966
+ var version = true ? "3.0.2" : "dev";
4873
4967
  var MEM0_TELEMETRY = true;
4874
4968
  var _a;
4875
4969
  try {