@cobrowser/chatgpt 0.7.26 → 0.7.27

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,8 +6,9 @@ export declare const MESSAGE_TYPES: {
6
6
  text: string;
7
7
  button: string;
8
8
  };
9
- export declare const DEFAULT_PROMPT = "You are a helpful assistant. Your role is to address visitor \nqueries related to the ongoing conversation and the last message received. Please ensure \nthat responses remain within the ongoing conversation. Politely decline any user queries \nthat is not present in the ongoing conversation. \n\nYou will always respond with a JSON. It will be in the format: \n\n{ answer: '', suggestions: [], connectWithAgent: true or false }\n\nFields in the JSON:\n\nAnswer: It will consist of the user's query answer based on the ongoing conversation. \nRestrict this field to 100 characters.\n\nSuggestions: Request 2 suggestions from user's perspective that he can ask. \nIt should be an array of strings. Restrict each suggestion to 50 characters.\n \nConnectWithAgent: It is a boolean. It should be set to true if the user's query is \nnot found in the ongoing conversation. Politely tell the user to talk to a real agent. \nAlso when it is true, do not provide any suggestions.\n";
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;
10
11
  export declare const DESTINATION_LANGUAGE = "English";
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 Ensure that 'translation' accurately represents the meaning of 'translated_message' while considering cultural nuances, usual expressions, and natural phrasing in the target language. \n Your response must follow this structure strictly.\n";
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;
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.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.SECURITY_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,32 +11,58 @@ 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
+ `;
14
35
  // Default prompt for ChatGPT
15
- exports.DEFAULT_PROMPT = `You are a helpful assistant. Your role is to address visitor
16
- queries related to the ongoing conversation and the last message received. Please ensure
17
- that responses remain within the ongoing conversation. Politely decline any user queries
18
- that is not present in the ongoing conversation.
36
+ exports.DEFAULT_PROMPT = `
37
+ ${exports.SECURITY_PROMPT}
38
+
39
+ You are a helpful assistant. Your role is to address visitor
40
+ queries related to the ongoing conversation and the last message received. Please ensure
41
+ that responses remain within the ongoing conversation. Politely decline any user queries
42
+ that is not present in the ongoing conversation.
19
43
 
20
- You will always respond with a JSON. It will be in the format:
44
+ You will always respond with a JSON. It will be in the format:
21
45
 
22
- { answer: '', suggestions: [], connectWithAgent: true or false }
46
+ { answer: '', suggestions: [], connectWithAgent: true or false }
23
47
 
24
- Fields in the JSON:
48
+ Fields in the JSON:
25
49
 
26
- Answer: It will consist of the user's query answer based on the ongoing conversation.
27
- Restrict this field to 100 characters.
50
+ Answer: It will consist of the user's query answer based on the ongoing conversation.
51
+ Restrict this field to 100 characters.
28
52
 
29
- Suggestions: Request 2 suggestions from user's perspective that he can ask.
30
- It should be an array of strings. Restrict each suggestion to 50 characters.
31
-
32
- ConnectWithAgent: It is a boolean. It should be set to true if the user's query is
33
- not found in the ongoing conversation. Politely tell the user to talk to a real agent.
34
- Also when it is true, do not provide any suggestions.
53
+ Suggestions: Request 2 suggestions from user's perspective that he can ask.
54
+ It should be an array of strings. Restrict each suggestion to 50 characters.
55
+
56
+ ConnectWithAgent: It is a boolean. It should be set to true if the user's query is
57
+ not found in the ongoing conversation. Politely tell the user to talk to a real agent.
58
+ Also when it is true, do not provide any suggestions.
35
59
  `;
36
60
  // Default destination language
37
61
  exports.DESTINATION_LANGUAGE = 'English';
38
62
  // Language detection system role
39
63
  exports.LANGUAGE_DETECTION_SYSTEM_ROLE = `
64
+ ${exports.SECURITY_PROMPT}
65
+
40
66
  You are a language detection assistant. Your task is to analyze short text input and determine
41
67
  its language using ISO language code. Respond only in JSON format with two key-value pairs:
42
68
  - 'languageCode': the detected language's ISO code (or undefined if detection fails).
@@ -44,6 +70,8 @@ exports.LANGUAGE_DETECTION_SYSTEM_ROLE = `
44
70
  `;
45
71
  // Word frequency language detection system role
46
72
  exports.WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE = `
73
+ ${exports.SECURITY_PROMPT}
74
+
47
75
  You are a language detection assistant. Your task is to analyze the most frequently occurring words in the given text
48
76
  and determine the language based on those words. Respond only in JSON format with two key-value pairs:
49
77
  - 'languageCode': the detected language's ISO code (or undefined if detection fails).
@@ -51,6 +79,8 @@ exports.WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE = `
51
79
  `;
52
80
  // Message translation system role
53
81
  exports.TRANSLATION_SYSTEM_ROLE = `
82
+ ${exports.SECURITY_PROMPT}
83
+
54
84
  You are a translator that responds exclusively in JSON format. Your response must be a JSON object containing:
55
85
  - 'data': it is an array of objects. Each object in the array must contain:
56
86
  - 'translated_message': The original input message before translation.
@@ -106,6 +106,7 @@ class BaseService {
106
106
  * @param data
107
107
  */
108
108
  output(data, shouldStringify = false) {
109
+ console.log('DATA: ', data);
109
110
  if (!data) {
110
111
  return;
111
112
  }
@@ -117,6 +118,8 @@ class BaseService {
117
118
  catch (error) { }
118
119
  }
119
120
  const sanitized = xss_validation_1.XSSProtector.sanitize(data), encoded = xss_validation_1.XSSProtector.encode(sanitized);
121
+ console.log('sanitized: ', sanitized);
122
+ console.log('encoded: ', encoded);
120
123
  logger_1.default.info({ data, sanitized, encoded }, ':: Sanitized Response ::');
121
124
  return shouldStringify ? JSON.stringify(encoded) : encoded;
122
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobrowser/chatgpt",
3
- "version": "0.7.26",
3
+ "version": "0.7.27",
4
4
  "description": "chatgpt services to connect our projects with chatgpt api",
5
5
  "keywords": [
6
6
  "chatgpt",
@@ -40,5 +40,5 @@
40
40
  "bugs": {
41
41
  "url": "https://bitbucket.org/cobrowser/cb_utils/issues"
42
42
  },
43
- "gitHead": "c2f7354d047df3043a1caa770b4ac509ca60bf32"
43
+ "gitHead": "c626a06693076aba35e66006e8561bb2dc87e1fa"
44
44
  }