@cobrowser/chatgpt 0.7.27 → 0.7.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.
@@ -6,9 +6,8 @@ export declare const MESSAGE_TYPES: {
6
6
  text: string;
7
7
  button: string;
8
8
  };
9
- export declare const SECURITY_PROMPT = "\n **SECURITY \u2014 XSS PROTECTION (MANDATORY, HIGHEST PRIORITY)**\n\n 1. **CANONICALIZE INPUT**: decode HTML entities, percent-decode, decode `\\x..` / `\\u....`, normalize Unicode (NFKC), collapse whitespace and hidden chars.\n\n 2. **DETECT & REMOVE**: detect any HTML tags, suspicious URIs, data: URIs, event handlers (`on*`), `javascript:`, `data:`, `vbscript:`, inline SVG/CSS payloads, or any obfuscated variant (e.g. encoded, spaced, or double-encoded). \n\n If detected \u2192 **OMIT COMPLETELY**. Do **NOT** echo, describe, forward, or reproduce the removed content in any form.\n\n 3. **ALLOWED URLS**: plain URL strings (e.g. `https://example.com`, `www.example.com`) may be shown **only as plain text**. **Do not render as markdown links, HTML anchors, or any clickable element**.\n\n 4. **NEVER GENERATE** any HTML/markup that can execute (no `<script>`, `<img>`, `<svg>`, `<iframe>`, `<style>`, `<a>` with hrefs, data: URIs, `<object>`, `javascript:`, etc.).\n\n 5. **IF UNCERTAIN** about safety, **do not reproduce the fragment** \u2014 return the useful reply with the unsafe portion removed. If you must note removal, use a generic message **without** including the removed content, e.g.:\n \"[Removed for security \u2014 potential XSS]\"\n\n 6. **OUTPUT FORMAT**: final response must be plain text with no active HTML/HTML-like anchors. Escape or remove `<`, `>`, `&` if they would render as HTML.\n\n **ENFORCE THESE BEFORE ANY OTHER TASK** \u2014 XSS protection takes precedence over fidelity or literal echoing.\n";
10
- export declare const DEFAULT_PROMPT: string;
9
+ export declare const DEFAULT_PROMPT = "\n You are a helpful assistant. Your role is to address visitor \n queries related to the ongoing conversation and the last message received. Please ensure \n that responses remain within the ongoing conversation. Politely decline any user queries \n that is not present in the ongoing conversation. \n\n You will always respond with a JSON. It will be in the format: \n\n { answer: '', suggestions: [], connectWithAgent: true or false }\n\n Fields in the JSON:\n\n Answer: It will consist of the user's query answer based on the ongoing conversation. \n Restrict this field to 100 characters.\n\n Suggestions: Request 2 suggestions from user's perspective that he can ask. \n It should be an array of strings. Restrict each suggestion to 50 characters.\n \n ConnectWithAgent: It is a boolean. It should be set to true if the user's query is \n not found in the ongoing conversation. Politely tell the user to talk to a real agent. \n Also when it is true, do not provide any suggestions.\n";
11
10
  export declare const DESTINATION_LANGUAGE = "English";
12
- export declare const LANGUAGE_DETECTION_SYSTEM_ROLE: string;
13
- export declare const WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE: string;
14
- export declare const TRANSLATION_SYSTEM_ROLE: string;
11
+ export declare const LANGUAGE_DETECTION_SYSTEM_ROLE = "\n You are a language detection assistant. Your task is to analyze short text input and determine \n its language using ISO language code. Respond only in JSON format with two key-value pairs: \n - 'languageCode': the detected language's ISO code (or undefined if detection fails).\n - 'isError': a boolean value (true if detection fails, false otherwise).\n";
12
+ export declare const WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE = "\n You are a language detection assistant. Your task is to analyze the most frequently occurring words in the given text \n and determine the language based on those words. Respond only in JSON format with two key-value pairs: \n - 'languageCode': the detected language's ISO code (or undefined if detection fails).\n - 'isError': a boolean value (true if detection fails, false otherwise).\n";
13
+ export declare const TRANSLATION_SYSTEM_ROLE = "\n You are a translator that responds exclusively in JSON format. Your response must be a JSON object containing:\n - 'data': it is an array of objects. Each object in the array must contain:\n - 'translated_message': The original input message before translation.\n - 'translation: The translated version of 'translated_message', ensuring it is natural, culturally appropriate, and commonly used by native speakers.\n - 'isError': a boolean value (true if translation fails, false otherwise).\n\n **You MUST return the JSON format even if you fail to translate the text. In this case, data field will be empty array and isError should be true.** \n\n Ensure that 'translation' accurately represents the meaning of 'translated_message' while considering cultural nuances, usual expressions, and natural phrasing in the target language.\n\n Your response must follow this structure strictly.\n";
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TRANSLATION_SYSTEM_ROLE = exports.WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE = exports.LANGUAGE_DETECTION_SYSTEM_ROLE = exports.DESTINATION_LANGUAGE = exports.DEFAULT_PROMPT = exports.SECURITY_PROMPT = exports.MESSAGE_TYPES = exports.MESSAGE_SENDER = void 0;
3
+ exports.TRANSLATION_SYSTEM_ROLE = exports.WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE = exports.LANGUAGE_DETECTION_SYSTEM_ROLE = exports.DESTINATION_LANGUAGE = exports.DEFAULT_PROMPT = exports.MESSAGE_TYPES = exports.MESSAGE_SENDER = void 0;
4
4
  // Message sender in conversation history
5
5
  exports.MESSAGE_SENDER = {
6
6
  visitor: 'visitor',
@@ -11,31 +11,8 @@ exports.MESSAGE_TYPES = {
11
11
  text: 'text',
12
12
  button: 'button'
13
13
  };
14
- // Security Prompt
15
- exports.SECURITY_PROMPT = `
16
- **SECURITY — XSS PROTECTION (MANDATORY, HIGHEST PRIORITY)**
17
-
18
- 1. **CANONICALIZE INPUT**: decode HTML entities, percent-decode, decode \`\\x..\` / \`\\u....\`, normalize Unicode (NFKC), collapse whitespace and hidden chars.
19
-
20
- 2. **DETECT & REMOVE**: detect any HTML tags, suspicious URIs, data: URIs, event handlers (\`on*\`), \`javascript:\`, \`data:\`, \`vbscript:\`, inline SVG/CSS payloads, or any obfuscated variant (e.g. encoded, spaced, or double-encoded).
21
-
22
- If detected → **OMIT COMPLETELY**. Do **NOT** echo, describe, forward, or reproduce the removed content in any form.
23
-
24
- 3. **ALLOWED URLS**: plain URL strings (e.g. \`https://example.com\`, \`www.example.com\`) may be shown **only as plain text**. **Do not render as markdown links, HTML anchors, or any clickable element**.
25
-
26
- 4. **NEVER GENERATE** any HTML/markup that can execute (no \`<script>\`, \`<img>\`, \`<svg>\`, \`<iframe>\`, \`<style>\`, \`<a>\` with hrefs, data: URIs, \`<object>\`, \`javascript:\`, etc.).
27
-
28
- 5. **IF UNCERTAIN** about safety, **do not reproduce the fragment** — return the useful reply with the unsafe portion removed. If you must note removal, use a generic message **without** including the removed content, e.g.:
29
- "[Removed for security — potential XSS]"
30
-
31
- 6. **OUTPUT FORMAT**: final response must be plain text with no active HTML/HTML-like anchors. Escape or remove \`<\`, \`>\`, \`&\` if they would render as HTML.
32
-
33
- **ENFORCE THESE BEFORE ANY OTHER TASK** — XSS protection takes precedence over fidelity or literal echoing.
34
- `;
35
14
  // Default prompt for ChatGPT
36
15
  exports.DEFAULT_PROMPT = `
37
- ${exports.SECURITY_PROMPT}
38
-
39
16
  You are a helpful assistant. Your role is to address visitor
40
17
  queries related to the ongoing conversation and the last message received. Please ensure
41
18
  that responses remain within the ongoing conversation. Politely decline any user queries
@@ -61,8 +38,6 @@ exports.DEFAULT_PROMPT = `
61
38
  exports.DESTINATION_LANGUAGE = 'English';
62
39
  // Language detection system role
63
40
  exports.LANGUAGE_DETECTION_SYSTEM_ROLE = `
64
- ${exports.SECURITY_PROMPT}
65
-
66
41
  You are a language detection assistant. Your task is to analyze short text input and determine
67
42
  its language using ISO language code. Respond only in JSON format with two key-value pairs:
68
43
  - 'languageCode': the detected language's ISO code (or undefined if detection fails).
@@ -70,8 +45,6 @@ exports.LANGUAGE_DETECTION_SYSTEM_ROLE = `
70
45
  `;
71
46
  // Word frequency language detection system role
72
47
  exports.WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE = `
73
- ${exports.SECURITY_PROMPT}
74
-
75
48
  You are a language detection assistant. Your task is to analyze the most frequently occurring words in the given text
76
49
  and determine the language based on those words. Respond only in JSON format with two key-value pairs:
77
50
  - 'languageCode': the detected language's ISO code (or undefined if detection fails).
@@ -79,14 +52,15 @@ exports.WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE = `
79
52
  `;
80
53
  // Message translation system role
81
54
  exports.TRANSLATION_SYSTEM_ROLE = `
82
- ${exports.SECURITY_PROMPT}
83
-
84
55
  You are a translator that responds exclusively in JSON format. Your response must be a JSON object containing:
85
56
  - 'data': it is an array of objects. Each object in the array must contain:
86
57
  - 'translated_message': The original input message before translation.
87
58
  - 'translation: The translated version of 'translated_message', ensuring it is natural, culturally appropriate, and commonly used by native speakers.
88
59
  - 'isError': a boolean value (true if translation fails, false otherwise).
89
60
 
90
- Ensure that 'translation' accurately represents the meaning of 'translated_message' while considering cultural nuances, usual expressions, and natural phrasing in the target language.
61
+ **You MUST return the JSON format even if you fail to translate the text. In this case, data field will be empty array and isError should be true.**
62
+
63
+ Ensure that 'translation' accurately represents the meaning of 'translated_message' while considering cultural nuances, usual expressions, and natural phrasing in the target language.
64
+
91
65
  Your response must follow this structure strictly.
92
66
  `;
@@ -118,7 +118,7 @@ class BaseService {
118
118
  catch (error) { }
119
119
  }
120
120
  const sanitized = xss_validation_1.XSSProtector.sanitize(data), encoded = xss_validation_1.XSSProtector.encode(sanitized);
121
- console.log('sanitized: ', sanitized);
121
+ console.log('sanitized 1111: ', sanitized);
122
122
  console.log('encoded: ', encoded);
123
123
  logger_1.default.info({ data, sanitized, encoded }, ':: Sanitized Response ::');
124
124
  return shouldStringify ? JSON.stringify(encoded) : encoded;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobrowser/chatgpt",
3
- "version": "0.7.27",
3
+ "version": "0.7.29",
4
4
  "description": "chatgpt services to connect our projects with chatgpt api",
5
5
  "keywords": [
6
6
  "chatgpt",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@cobrowser/logger": "^2.0.2",
25
- "@cobrowser/xss-validation": "^2.0.0",
25
+ "@cobrowser/xss-validation": "^2.0.1",
26
26
  "axios": "^1.6.1",
27
27
  "axios-mock-adapter": "^1.22.0",
28
28
  "openai": "^4.86.2"
@@ -40,5 +40,5 @@
40
40
  "bugs": {
41
41
  "url": "https://bitbucket.org/cobrowser/cb_utils/issues"
42
42
  },
43
- "gitHead": "c626a06693076aba35e66006e8561bb2dc87e1fa"
43
+ "gitHead": "ecfc310a3e7ecd1c6e5d7193a671928528349f67"
44
44
  }