funda-ui 4.7.604 → 4.7.608

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/Chatbox/index.js CHANGED
@@ -4410,10 +4410,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
4410
4410
  __nested_webpack_require_993__.r(__webpack_exports__);
4411
4411
  /* harmony export */
4412
4412
  __nested_webpack_require_993__.d(__webpack_exports__, {
4413
- /* harmony export */"fixAndParseJSON": function fixAndParseJSON() {
4414
- return (/* binding */_fixAndParseJSON
4415
- );
4416
- },
4417
4413
  /* harmony export */"isEmail": function isEmail() {
4418
4414
  return (/* binding */_isEmail
4419
4415
  );
@@ -4459,63 +4455,82 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
4459
4455
  }
4460
4456
  /**
4461
4457
  * Fix And Parse JSON (Support for handling complex escape JSON strings)
4458
+ * @desc recursively fix top-level key/value (recursively handles when encountering top-level values that are objects/arrays)
4462
4459
  * @private
4463
4460
  */
4464
4461
  /*
4465
- - Always try JSON.parse first;
4466
- - If parsing fails, unescape \" → ";
4467
- - Then process the outermost object or array key-by-key, value-by-value;
4468
- - If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
4469
- recursively treat that value as a new root to repair;
4470
- - For values wrapped in quotes ('...' or "..."), extract the inner text and
4471
- re-encode it using JSON.stringify (ensures internal single/double quotes
4472
- are not corrupted);
4462
+ - Still prioritize JSON.parse first;
4463
+ - After parse fails, do unescaping (\\" → ");
4464
+ - Then process the outermost layer (object or array) key by key, value by value;
4465
+ - If a top-level value is an unquoted object or array (e.g., messages: [ {...} ]), recursively treat that value as a new outermost layer for fixing;
4466
+ - For strings wrapped in quotes ('...' or "..."), only extract the outer layer and re-encode with JSON.stringify (ensuring internal single/double quotes won't be mistakenly changed);
4473
4467
  - Set MAX_DEPTH to prevent infinite recursion.
4474
4468
  */
4475
- // fixAndParseJSON - recursively repairs top-level key/value
4476
- // (when encountering outermost values that are objects/arrays, it recurses)
4477
-
4478
4469
  /*
4479
- DEMO:
4470
+ @Examples:
4480
4471
 
4481
- // ✅ Valid JSON (contains svg and single-quote content)
4472
+ // ✅ Valid JSON (contains svg and single quote content)
4482
4473
  const okJson = `{
4483
- "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
4474
+ "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> 新建会话",
4484
4475
  "value":"new",
4485
4476
  "onClick":"method.setVal(''); method.clearData();"
4486
4477
  }`;
4487
4478
 
4488
- // Single-quote JSON
4479
+ const okJson2 = `{
4480
+ label:"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> 新建会话",
4481
+ value:"new",
4482
+ onClick:"method.setVal(''); method.clearData();"
4483
+ }`;
4484
+
4485
+ // ⚠️ Single quote JSON
4489
4486
  const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
4490
4487
 
4491
- // Escaped JSON
4492
- const badJson2 = "{\\\"label\\\":\\\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\\\",\\\"value\\\":\\\"new\\\",\\\"onClick\\\":\\\"method.setVal(''); method.clearData();\\\"}";
4488
+ // ⚠️ Escaped JSON
4489
+ const badJson2 = "{\\\"label\\\":\\\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> 新建会话\\\",\\\"value\\\":\\\"new\\\",\\\"onClick\\\":\\\"method.setVal(''); method.clearData();\\\"}";
4490
+
4491
+ const badJson3 = "{\"label\":\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> 新建会话\",\"value\":\"new\",\"onClick\":\"method.setVal(''); method.clearData();\"}";
4492
+
4493
+ const badJson4 = "[{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M20.5 9a3.49 3.49 0 0 0-3.45 3h-1.1a2.49 2.49 0 0 0-4.396-1.052L8.878 9.731l3.143-4.225a2.458 2.458 0 0 0 2.98-.019L17.339 8H16v1h3V6h-1v1.243l-2.336-2.512A2.473 2.473 0 0 0 16 3.5a2.5 2.5 0 0 0-5 0 2.474 2.474 0 0 0 .343 1.243L7.947 9.308 4.955 7.947a2.404 2.404 0 0 0-.161-1.438l3.704-1.385-.44 1.371.942.333L10 4 7.172 3l-.334.943 1.01.357-3.659 1.368a2.498 2.498 0 1 0-.682 4.117l2.085 2.688-2.053 2.76a2.5 2.5 0 1 0 .87 3.864l3.484 1.587-1.055.373.334.943L10 21l-1-2.828-.943.333.435 1.354-3.608-1.645A2.471 2.471 0 0 0 5 17.5a2.5 2.5 0 0 0-.058-.527l3.053-1.405 3.476 4.48a2.498 2.498 0 1 0 4.113.075L18 17.707V19h1v-3h-3v1h1.293l-2.416 2.416a2.466 2.466 0 0 0-2.667-.047l-3.283-4.23 2.554-1.176A2.494 2.494 0 0 0 15.95 13h1.1a3.493 3.493 0 1 0 3.45-4zm-7-7A1.5 1.5 0 1 1 12 3.5 1.502 1.502 0 0 1 13.5 2zm0 18a1.5 1.5 0 1 1-1.5 1.5 1.502 1.502 0 0 1 1.5-1.5zM1 7.5a1.5 1.5 0 1 1 2.457 1.145l-.144.112A1.496 1.496 0 0 1 1 7.5zm3.32 1.703a2.507 2.507 0 0 0 .264-.326l2.752 1.251-1.124 1.512zM2.5 19A1.5 1.5 0 1 1 4 17.5 1.502 1.502 0 0 1 2.5 19zm2.037-2.941a2.518 2.518 0 0 0-.193-.234l1.885-2.532 1.136 1.464zm3.76-1.731L6.849 12.46l1.42-1.908L11.1 11.84a2.29 2.29 0 0 0-.033 1.213zM13.5 14a1.5 1.5 0 1 1 1.5-1.5 1.502 1.502 0 0 1-1.5 1.5zm7 1a2.5 2.5 0 1 1 2.5-2.5 2.502 2.502 0 0 1-2.5 2.5zm1.5-2.5a1.5 1.5 0 1 1-1.5-1.5 1.502 1.502 0 0 1 1.5 1.5z'/><path fill='none' d='M0 0h24v24H0z'/></svg> 深度思考\",\"value\":\"brief\",\"onClick\":\"if(isActive){method.executeCustomMethod('changeModel', true)}else{method.executeCustomMethod('changeModel', false)}\"},{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M19 2H5c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h3.586L12 21.414 15.414 18H19c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zm0 14h-4.414L12 18.586 9.414 16H5V4h14v12z'/></svg> 精简回答\",\"value\":\"brief\",\"onClick\":\"if(isActive){method.setContextData({systemPrompt:'请精简回答,字数控制在150个字左右, 思考过程请简洁简短',mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}else{method.setContextData({mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}\"},{\"label\":\"<svg fill='none' width='12' height='12' viewBox='0 0 16 16'><path d='M7 0.0618896V9H15.9381C15.446 12.9463 12.0796 16 8 16C3.58172 16 0 12.4183 0 8C0 3.92038 3.05369 0.553988 7 0.0618896Z' fill='currentColor'/><path d='M9 0.0618897V7H15.9381C15.4869 3.38128 12.6187 0.513137 9 0.0618897Z' fill='currentColor'/></svg> 指标分析\",\"value\":\"lab\",\"onClick\":\"return method.executeCustomMethod('getLibList')\",\"isSelect\":true,\"dynamicOptions\":true}]";
4494
+
4493
4495
 
4494
- const badJson3 = "{\"label\":\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\",\"value\":\"new\",\"onClick\":\"method.setVal(''); method.clearData();\"}";
4496
+ // Invalid JSON with missing } or ]
4497
+ const errorJson001 = "{'model':'qwen-plus','base_url':'https://dashscope.aliyuncs.com/compatible-mode/v1/','api_key':'sk-0989fb9baab8450682af4d000f5b7cba','message':'{message}','stream':'true','chatId': '{chatId}', 'token': '{token}'";
4495
4498
 
4496
- const badJson4 = "[{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M20.5 9a3.49 3.49 0 0 0-3.45 3h-1.1a2.49 2.49 0 0 0-4.396-1.052L8.878 9.731l3.143-4.225a2.458 2.458 0 0 0 2.98-.019L17.339 8H16v1h3V6h-1v1.243l-2.336-2.512A2.473 2.473 0 0 0 16 3.5a2.5 2.5 0 0 0-5 0 2.474 2.474 0 0 0 .343 1.243L7.947 9.308 4.955 7.947a2.404 2.404 0 0 0-.161-1.438l3.704-1.385-.44 1.371.942.333L10 4 7.172 3l-.334.943 1.01.357-3.659 1.368a2.498 2.498 0 1 0-.682 4.117l2.085 2.688-2.053 2.76a2.5 2.5 0 1 0 .87 3.864l3.484 1.587-1.055.373.334.943L10 21l-1-2.828-.943.333.435 1.354-3.608-1.645A2.471 2.471 0 0 0 5 17.5a2.5 2.5 0 0 0-.058-.527l3.053-1.405 3.476 4.48a2.498 2.498 0 1 0 4.113.075L18 17.707V19h1v-3h-3v1h1.293l-2.416 2.416a2.466 2.466 0 0 0-2.667-.047l-3.283-4.23 2.554-1.176A2.494 2.494 0 0 0 15.95 13h1.1a3.493 3.493 0 1 0 3.45-4zm-7-7A1.5 1.5 0 1 1 12 3.5 1.502 1.502 0 0 1 13.5 2zm0 18a1.5 1.5 0 1 1-1.5 1.5 1.502 1.502 0 0 1 1.5-1.5zM1 7.5a1.5 1.5 0 1 1 2.457 1.145l-.144.112A1.496 1.496 0 0 1 1 7.5zm3.32 1.703a2.507 2.507 0 0 0 .264-.326l2.752 1.251-1.124 1.512zM2.5 19A1.5 1.5 0 1 1 4 17.5 1.502 1.502 0 0 1 2.5 19zm2.037-2.941a2.518 2.518 0 0 0-.193-.234l1.885-2.532 1.136 1.464zm3.76-1.731L6.849 12.46l1.42-1.908L11.1 11.84a2.29 2.29 0 0 0-.033 1.213zM13.5 14a1.5 1.5 0 1 1 1.5-1.5 1.502 1.502 0 0 1-1.5 1.5zm7 1a2.5 2.5 0 1 1 2.5-2.5 2.502 2.502 0 0 1-2.5 2.5zm1.5-2.5a1.5 1.5 0 1 1-1.5-1.5 1.502 1.502 0 0 1 1.5 1.5z'/><path fill='none' d='M0 0h24v24H0z'/></svg> Deep Thought","value":"brief","onClick":"if(isActive){method.executeCustomMethod('changeModel', true)}else{method.executeCustomMethod('changeModel', false)}"},{"label":"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M19 2H5c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h3.586L12 21.414 15.414 18H19c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zm0 14h-4.414L12 18.586 9.414 16H5V4h14v12z'/></svg> Concise Answer","value":"brief","onClick":"if(isActive){method.setContextData({systemPrompt:'Please answer concisely, around 150 words, keep reasoning brief',mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}else{method.setContextData({mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}"},{"label":"<svg fill='none' width='12' height='12' viewBox='0 0 16 16'><path d='M7 0.0618896V9H15.9381C15.446 12.9463 12.0796 16 8 16C3.58172 16 0 12.4183 0 8C0 3.92038 3.05369 0.553988 7 0.0618896Z' fill='currentColor'/><path d='M9 0.0618897V7H15.9381C15.4869 3.38128 12.6187 0.513137 9 0.0618897Z' fill='currentColor'/></svg> Metrics Analysis","value":"lab","onClick":"return method.executeCustomMethod('getLibList')","isSelect":true,"dynamicOptions":true}]";
4499
+ const errorJson002 = "[{'model':'qwen-plus','base_url':'https://dashscope.aliyuncs.com/compatible-mode/v1/','api_key':'sk-0989fb9baab8450682af4d000f5b7cba','message':'{message}','stream':'true','chatId': '{chatId}', 'token': '{token}'}";
4497
4500
 
4501
+ // ❌ Invalid JSON with missing quotes
4502
+ const errorJson003 = "{'model':'qwen-plus','base_url':'https://dashscope.aliyuncs.com/compatible-mode/v1/','api_key':'sk-0989fb9baab8450682af4d000f5b7cba','message':'{message}','stream':'true','chatId': {chatId}', 'token': '{token}'}";
4503
+
4504
+
4505
+
4506
+ console.log('okJson =>', fixAndParseJSON(okJson)); // Can parse normally success = true
4507
+ console.log('okJson =>', fixAndParseJSON(okJson2)); // Can parse normally success = true
4508
+ console.log('badJson =>', fixAndParseJSON(badJson)); // Can parse after fixing success = true
4509
+ console.log('badJson =>', fixAndParseJSON(badJson2)); // Can parse after fixing success = true
4510
+ console.log('badJson =>', fixAndParseJSON(badJson3)); // Can parse after fixing success = true
4511
+ console.log('badJson =>', fixAndParseJSON(badJson4)); // Can parse after fixing success = true
4512
+ console.log('errorJson =>', fixAndParseJSON(errorJson001)); // {success: false, error: 'Invalid JSON format', details: 'Invalid object: mismatched braces'}
4513
+ console.log('errorJson =>', fixAndParseJSON(errorJson002)); // {success: false, error: 'Invalid JSON format', details: "Expected property name or '}' in JSON at position 2 (line 1 column 3)"}
4514
+ console.log('errorJson =>', fixAndParseJSON(errorJson003)); // {success: false, error: 'Invalid JSON format', details: 'Invalid object: mismatched braces'}
4498
4515
 
4499
- console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
4500
- console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
4501
- console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
4502
- console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
4503
- console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
4504
4516
  */
4505
- function _fixAndParseJSON(input) {
4517
+
4518
+ // Type definitions
4519
+
4520
+ function fixAndParseJSON(input) {
4506
4521
  var MAX_DEPTH = 6;
4507
4522
 
4508
- // 1. Fast attempt
4523
+ // 1. Quick attempt
4509
4524
  try {
4510
4525
  return {
4511
4526
  success: true,
4512
4527
  data: JSON.parse(input)
4513
4528
  };
4514
4529
  } catch (e) {
4515
- // continue to repair
4530
+ // Continue with fixing
4516
4531
  }
4517
4532
 
4518
- // 2. Simple unescape of \" (common when copied from JS literals)
4533
+ // 2. Simple unescaping of escaped \" (common case from pasted JS literals)
4519
4534
  var s = input;
4520
4535
  if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
4521
4536
  s = s.trim();
@@ -4532,24 +4547,54 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
4532
4547
  data: JSON.parse(s)
4533
4548
  };
4534
4549
  } catch (err) {
4550
+ var error = err instanceof Error ? err : new Error('Unknown error');
4535
4551
  return {
4536
4552
  success: false,
4537
4553
  error: 'Invalid JSON format',
4538
- details: err instanceof Error ? err.message : String(err)
4554
+ details: error.message
4539
4555
  };
4540
4556
  }
4541
4557
  }
4542
4558
 
4543
- /* ---------- Helper (recursive) functions ---------- */
4559
+ /* ---------- Helper (Recursive) Functions ---------- */
4544
4560
 
4545
4561
  function processTopObject(str, depth, MAX_DEPTH) {
4546
4562
  if (depth > MAX_DEPTH) return str;
4547
4563
  str = str.trim();
4548
- // Ensure it is wrapped in { ... }
4564
+
4565
+ // First check if braces match
4566
+ var braceCount = 0;
4567
+ var inString = false;
4568
+ var escapeNext = false;
4569
+ for (var i = 0; i < str.length; i++) {
4570
+ var ch = str[i];
4571
+ if (escapeNext) {
4572
+ escapeNext = false;
4573
+ continue;
4574
+ }
4575
+ if (ch === '\\') {
4576
+ escapeNext = true;
4577
+ continue;
4578
+ }
4579
+ if ((ch === '"' || ch === "'") && !escapeNext) {
4580
+ inString = !inString;
4581
+ continue;
4582
+ }
4583
+ if (!inString) {
4584
+ if (ch === '{') braceCount++;else if (ch === '}') braceCount--;
4585
+ }
4586
+ }
4587
+ if (braceCount !== 0) {
4588
+ throw new Error('Invalid object: mismatched braces');
4589
+ }
4590
+
4591
+ // Ensure both ends are { ... }
4549
4592
  if (!(str.startsWith('{') && str.endsWith('}'))) {
4550
- var f = str.indexOf('{');
4551
- var l = str.lastIndexOf('}');
4552
- if (f === -1 || l === -1 || l <= f) return str;
4593
+ var f = str.indexOf('{'),
4594
+ l = str.lastIndexOf('}');
4595
+ if (f === -1 || l === -1 || l <= f) {
4596
+ throw new Error('Invalid object format: missing or mismatched braces');
4597
+ }
4553
4598
  str = str.slice(f, l + 1);
4554
4599
  }
4555
4600
  var inner = str.slice(1, -1);
@@ -4574,8 +4619,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
4574
4619
  if (depth > MAX_DEPTH) return str;
4575
4620
  str = str.trim();
4576
4621
  if (!(str.startsWith('[') && str.endsWith(']'))) {
4577
- var f = str.indexOf('[');
4578
- var l = str.lastIndexOf(']');
4622
+ var f = str.indexOf('['),
4623
+ l = str.lastIndexOf(']');
4579
4624
  if (f === -1 || l === -1 || l <= f) return str;
4580
4625
  str = str.slice(f, l + 1);
4581
4626
  }
@@ -4591,21 +4636,21 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
4591
4636
  return '[' + processed.join(',') + ']';
4592
4637
  }
4593
4638
 
4594
- // If value is quoted, extract inside and JSON.stringify again (safe escaping)
4595
- // If value is unquoted object/array literal, recurse treating it as new root
4596
- // Otherwise return as is (numbers, booleans, null, or raw expressions)
4639
+ // If it's a string wrapped in quotes, extract the inner content and JSON.stringify (safe escaping)
4640
+ // If it's an object/array literal (not wrapped in quotes), recursively process (treat as new outermost layer)
4641
+ // Otherwise return the original fragment directly (numbers/true/false/null or JS expressions)
4597
4642
  function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
4598
4643
  var v = rawVal.trim();
4599
4644
  if (v === '') return v;
4600
4645
  if (v[0] === '"' || v[0] === "'") {
4601
4646
  var quote = v[0];
4602
- // Find the last unescaped matching quote
4647
+ // Find the last unescaped same quote
4603
4648
  var lastPos = -1;
4604
4649
  for (var i = v.length - 1; i >= 0; i--) {
4605
4650
  if (v[i] === quote) {
4606
- // check if escaped
4607
- var bs = 0;
4608
- var k = i - 1;
4651
+ // check escaped
4652
+ var bs = 0,
4653
+ k = i - 1;
4609
4654
  while (k >= 0 && v[k] === '\\') {
4610
4655
  bs++;
4611
4656
  k--;
@@ -4617,10 +4662,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
4617
4662
  }
4618
4663
  }
4619
4664
  var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
4620
- return JSON.stringify(inner); // Generate valid JSON string (auto escape)
4665
+ return JSON.stringify(inner); // Use JSON.stringify to generate valid JSON string (automatically escape internal quotes, etc.)
4621
4666
  }
4622
4667
 
4623
- // If unquoted object/array literal -> recurse
4668
+ // If it's an object or array literal (not wrapped in quotes) -> recursively treat as new outermost layer
4624
4669
  if (v.startsWith('{')) {
4625
4670
  return processTopObject(v, depth, MAX_DEPTH);
4626
4671
  }
@@ -4628,22 +4673,22 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
4628
4673
  return processTopArray(v, depth, MAX_DEPTH);
4629
4674
  }
4630
4675
 
4631
- // Other (number, boolean, null, raw expression): return as is
4676
+ // Others (numbers, boolean, null, or JS expressions): return as-is
4632
4677
  return v;
4633
4678
  }
4634
4679
 
4635
- /* --------- Utils: split by top-level commas, find colon, extract key --------- */
4680
+ /* --------- Utilities: Split by top-level commas, find top-level colon, extract key --------- */
4636
4681
 
4637
- // Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
4682
+ // Split by top-level commas (ignore strings, sub-objects, sub-arrays, commas inside parentheses)
4638
4683
  function splitTopLevel(str) {
4639
4684
  var parts = [];
4640
4685
  var buf = '';
4641
- var depthCurly = 0;
4642
- var depthSquare = 0;
4643
- var depthParen = 0;
4644
- var inSingle = false;
4645
- var inDouble = false;
4646
- var esc = false;
4686
+ var depthCurly = 0,
4687
+ depthSquare = 0,
4688
+ depthParen = 0;
4689
+ var inSingle = false,
4690
+ inDouble = false,
4691
+ esc = false;
4647
4692
  for (var i = 0; i < str.length; i++) {
4648
4693
  var ch = str[i];
4649
4694
  if (esc) {
@@ -4705,18 +4750,23 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
4705
4750
  }
4706
4751
  buf += ch;
4707
4752
  }
4753
+
4754
+ // Check for unclosed brackets or quotes
4755
+ if (depthCurly !== 0 || depthSquare !== 0 || depthParen !== 0 || inSingle || inDouble) {
4756
+ throw new Error('Invalid JSON: unclosed brackets or quotes');
4757
+ }
4708
4758
  if (buf.trim() !== '') parts.push(buf);
4709
4759
  return parts;
4710
4760
  }
4711
4761
 
4712
- // Find the first top-level colon (ignores strings and nested structures)
4762
+ // Find the first "top-level" colon index (ignore inside strings & sub-levels)
4713
4763
  function findTopLevelColon(str) {
4714
- var inSingle = false;
4715
- var inDouble = false;
4716
- var esc = false;
4717
- var depthCurly = 0;
4718
- var depthSquare = 0;
4719
- var depthParen = 0;
4764
+ var inSingle = false,
4765
+ inDouble = false,
4766
+ esc = false;
4767
+ var depthCurly = 0,
4768
+ depthSquare = 0,
4769
+ depthParen = 0;
4720
4770
  for (var i = 0; i < str.length; i++) {
4721
4771
  var ch = str[i];
4722
4772
  if (esc) {
@@ -4768,7 +4818,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
4768
4818
  return -1;
4769
4819
  }
4770
4820
 
4771
- // Extract key content (supports "key", 'key', key) returns pure string key
4821
+ // Extract key content (supports "key", 'key', key), returns pure key string
4772
4822
  function extractKeyContent(rawKey) {
4773
4823
  var r = rawKey.trim();
4774
4824
  if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
@@ -4784,7 +4834,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
4784
4834
  */
4785
4835
  function _isJSON(input) {
4786
4836
  if (typeof input === 'string' && input.length > 0) {
4787
- return _fixAndParseJSON(input).success;
4837
+ return fixAndParseJSON(input).success;
4788
4838
  } else {
4789
4839
  if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
4790
4840
  return true;
@@ -5543,8 +5593,12 @@ var Chatbox = function Chatbox(props) {
5543
5593
  _requestBodyTmpl = '{}';
5544
5594
  return {};
5545
5595
  } else {
5546
- if (JSON.parse(_requestBodyTmpl).hasOwnProperty('stream')) {
5547
- _isStream = toBoolean(JSON.parse(_requestBodyTmpl).stream) === true;
5596
+ try {
5597
+ if (JSON.parse(_requestBodyTmpl).hasOwnProperty('stream')) {
5598
+ _isStream = toBoolean(JSON.parse(_requestBodyTmpl).stream) === true;
5599
+ }
5600
+ } catch (err) {
5601
+ console.error(err);
5548
5602
  }
5549
5603
  }
5550
5604