Skip to content

Integrates You.com chatbot in web-mode using session cookie. Supports conversation history + "create" chatMode (image generation). #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

sanpinapipi
Copy link

Integrates You.com chatbot using session cookie. Supports conversation history + "create" chatMode (image generation).

Integrates You.com chatbot using session cookie. Supports conversation history + "create" chatMode (image generation).
Integrates You.com chatbot using session cookie. Supports conversation history + "create" chatMode (image generation).
Integrates You.com chatbot using session cookie. Supports conversation history + "create" chatMode (image generation).
…n history + "create" chatMode (image generation).

Integrates You.com chatbot using session cookie. Supports conversation history + "create" chatMode (image generation).1
…n history + "create" chatMode (image generation).

Integrates You.com chatbot using session cookie. Supports conversation history + "create" chatMode (image generation).
…n history + "create" chatMode (image generation).

Integrates You.com chatbot using session cookie. Supports conversation history + "create" chatMode (image generation).
@PeterDaveHello PeterDaveHello requested a review from Copilot May 31, 2025 20:18
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Integrates You.com chatbot in web mode by fetching a session cookie, streaming conversation history via SSE, and supporting “create” mode for image generation.

  • Adds getYouSessionKey alongside existing session-cookie helpers.
  • Implements generateAnswersWithYouWebApi for streaming chat responses.
  • Extends config and background logic to include You.com model keys and routing.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/services/wrappers.mjs Added getYouSessionKey to retrieve You.com session cookie.
src/services/apis/you-web.mjs New SSE-based API client for You.com chat and create modes.
src/config/index.mjs Registered You.com model keys, groups, and default modes.
src/background/index.mjs Routed You.com requests in the main execution flow.
Comments suppressed due to low confidence (2)

src/services/apis/you-web.mjs:1

  • New API wrapper generateAnswersWithYouWebApi and generateUUID helper lack associated unit tests. Please add tests to cover streaming logic, error handling, and different chat modes.
// path/to/services/apis/you-web.mjs

src/config/index.mjs:418

  • The activeApiModes array was completely replaced by You.com keys, removing all existing default modes (e.g., chatgptFree35, bingFree4). Please merge You.com entries into the existing list rather than overwriting it.
'create',

@@ -233,6 +266,33 @@ export const Models = {

gptApiInstruct: { value: 'gpt-3.5-turbo-instruct', desc: 'GPT-3.5-turbo Instruct' },
gptApiDavinci: { value: 'text-davinci-003', desc: 'GPT-3.5' },

create: { value: 'create', desc: 'YouWeb create' },
Copy link
Preview

Copilot AI May 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate create key in the Models object (also defined at line 251). Please remove or consolidate one of the definitions to avoid key collisions.

Suggested change
create: { value: 'create', desc: 'YouWeb create' },
// Removed duplicate 'create' key to avoid key collisions

Copilot uses AI. Check for mistakes.

// Handle start if needed
},
onEnd() {
finishMessage()
Copy link
Preview

Copilot AI May 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling finishMessage() here will push the record and post a completed message, but the onEnd callback also calls finishMessage(), leading to duplicate pushes and messages. Consider invoking it in only one place.

Suggested change
finishMessage()
if (!isFinished) {
finishMessage()
isFinished = true
}

Copilot uses AI. Check for mistakes.

method: 'GET',
signal: controller.signal,
headers: {
'Content-Type': 'text/event-stream;charset=utf-8',
Copy link
Preview

Copilot AI May 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] For SSE GET requests, it's more appropriate to set an Accept: 'text/event-stream' header instead of Content-Type to signal the expected response format.

Suggested change
'Content-Type': 'text/event-stream;charset=utf-8',
'Accept': 'text/event-stream',

Copilot uses AI. Check for mistakes.

@PeterDaveHello
Copy link
Member

/review

Copy link

qodo-merge-pro bot commented Jun 2, 2025

Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 Security concerns

Cookie handling:
The implementation relies on session cookies for authentication with You.com. While the code itself doesn't expose the cookies directly, ensure that the session cookie is properly secured and not accessible to malicious scripts or extensions. The cookie is being sent with every request to You.com, which is necessary for authentication but should be monitored for potential security implications.

⚡ Recommended focus areas for review

Error Handling

The error handling in the fetchSSE call could be improved. The current implementation only handles errors from the fetch itself, but doesn't properly handle API-specific errors that might be returned in the response data.

onError(error) {
  cleanController()
  port.postMessage({ error: error.message, done: true })
},
UUID Generation

The custom UUID generation function may not guarantee uniqueness in all cases. Consider using a standard UUID library instead of the custom implementation.

function generateUUID() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    var r = (Math.random() * 16) | 0,
      v = c == 'x' ? r : (r & 0x3) | 0x8
    return v.toString(16)
  })
}
Duplicate Model Definition

The 'create' model is defined twice in the Models object, once at line 252 and again at line 270, which could lead to unexpected behavior.

  create: { value: "create", desc: "You.com (Web, Create Mode)" }, // Added You.com create model

chatglmTurbo: { value: 'GLM-4-Air', desc: 'ChatGLM (GLM-4-Air, 128k)' },
chatglm4: { value: 'GLM-4-0520', desc: 'ChatGLM (GLM-4-0520, 128k)' },
chatglmEmohaa: { value: 'Emohaa', desc: 'ChatGLM (Emohaa)' },
chatglmCharGLM3: { value: 'CharGLM-3', desc: 'ChatGLM (CharGLM-3)' },

chatgptFree35Mobile: { value: 'text-davinci-002-render-sha-mobile', desc: 'ChatGPT (Mobile)' },
chatgptPlus4Mobile: { value: 'gpt-4-mobile', desc: 'ChatGPT (Mobile, GPT-4)' },

chatgptApi35_1106: { value: 'gpt-3.5-turbo-1106', desc: 'ChatGPT (GPT-3.5-turbo 1106)' },
chatgptApi35_0125: { value: 'gpt-3.5-turbo-0125', desc: 'ChatGPT (GPT-3.5-turbo 0125)' },
chatgptApi4_8k_0613: { value: 'gpt-4', desc: 'ChatGPT (GPT-4-8k 0613)' },
chatgptApi4_32k_0613: { value: 'gpt-4-32k', desc: 'ChatGPT (GPT-4-32k 0613)' },

gptApiInstruct: { value: 'gpt-3.5-turbo-instruct', desc: 'GPT-3.5-turbo Instruct' },
gptApiDavinci: { value: 'text-davinci-003', desc: 'GPT-3.5' },

create: { value: 'create', desc: 'YouWeb create' },

@PeterDaveHello
Copy link
Member

/improve

Copy link

qodo-merge-pro bot commented Jun 2, 2025

Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Impact
Possible issue
Preserve existing model options

The PR completely replaces the default activeApiModes with You.com models only,
removing all previously available models. This will disrupt existing users'
experience by removing access to ChatGPT, Claude, and other previously available
models. Consider preserving the original models alongside the new You.com
models.

src/config/index.mjs [418-443]

 export const defaultConfig = {
   // others
 
   alwaysCreateNewConversationWindow: false,
   // The handling of activeApiModes and customApiModes is somewhat complex.
   // It does not directly convert activeApiModes into customApiModes, which is for compatibility considerations.
   // It allows the content of activeApiModes to change with version updates when the user has not customized ApiModes.
   // If it were directly written into customApiModes, the value would become fixed, even if the user has not made any customizations.
   activeApiModes: [
+    'chatgptFree35',
+    'chatgptFree4o',
+    'chatgptApi35',
+    'chatgptApi4o_128k',
+    'claude2WebFree',
+    'claude35SonnetApi',
+    'bingFree4',
+    'moonshotWebFree',
+    'moonshot_v1_8k',
+    'chatglmTurbo',
+    'customModel',
+    'azureOpenAi',
     'create',
     'openai_o1',
     'openai_o1_preview',
-    'openai_o1_mini',
-    'gpt_4o_mini',
     'gpt_4o',
-    'gpt_4_turbo',
-    'gpt_4',
+    'claude_3_5_sonnet',
     'grok_2',
-    'claude_3_5_sonnet',
-    'claude_3_opus',
-    'claude_3_sonnet',
-    'claude_3_5_haiku',
-    'llama3_3_70b',
-    'llama3_2_90b',
-    'llama3_1_405b',
-    'mistral_large_2',
-    'gemini_1_5_flash',
-    'gemini_1_5_pro',
-    'databricks_dbrx_instruct',
-    'qwen2p5_72b',
-    'qwen2p5_coder_32b',
-    'command_r_plus',
-    'solar_1_mini',
-    'dolphin_2_5',
   ],

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 9

__

Why: This addresses a critical breaking change where all existing models are removed and replaced with only You.com models, which would severely disrupt user experience and break existing functionality.

High
Remove duplicate model definition

There's a duplicate definition of the create model in the Models object. It's
defined both at line 271 and earlier at line 244 with different descriptions.
This will cause inconsistent behavior when the model is referenced.

src/config/index.mjs [270]

-create: { value: 'create', desc: 'YouWeb create' },
+// Remove the duplicate and keep only one definition:
 openai_o1: { value: 'openai_o1', desc: 'YouWeb openai_o1' },
 openai_o1_preview: { value: 'openai_o1_preview', desc: 'YouWeb openai_o1_preview' },
 openai_o1_mini: { value: 'openai_o1_mini', desc: 'YouWeb openai_o1_mini' },
 gpt_4o_mini: { value: 'gpt_4o_mini', desc: 'YouWeb gpt_4o_mini' },

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 8

__

Why: This correctly identifies a duplicate create model definition that could cause inconsistent behavior and configuration conflicts when the model is referenced.

Medium
Security
Validate API input data

The conversationContext is passed directly to the API without any validation or
sanitization. If the conversation history contains malformed data, it could
cause API errors. Add validation to ensure the conversation data is properly
formatted.

src/services/apis/you-web.mjs [54]

-params.append('chat', JSON.stringify(conversationContext))
+// Validate conversation context before sending
+const validConversationContext = Array.isArray(conversationContext) ? 
+  conversationContext.filter(item => item && typeof item === 'object') : [];
+params.append('chat', JSON.stringify(validConversationContext))
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why: This is a defensive programming improvement that adds input validation, but the impact is moderate as malformed conversation data is unlikely in normal operation.

Low
  • More

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants