Skip to content
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

fix phind #793

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

asyncButNeverAwaits
Copy link
Contributor

@asyncButNeverAwaits asyncButNeverAwaits commented Apr 11, 2024

make mainWindow as global to use in other file
phind need to generate challenge seed which is dynamic only can open the phind window and get the seend

Close: #763
Close: #701
Close: #690
Close: #623

Copy link

vercel bot commented Apr 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
chatall ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 23, 2024 10:43pm

@sunner
Copy link
Owner

sunner commented Apr 18, 2024

Thank you for contribution.

The diff is huge and I can't understand the code in windows well. Could you kindly explain it?

@asyncButNeverAwaits
Copy link
Contributor Author

This is a different approach to sending a prompt to Phind because Phind requires the challenge value in the request.

Image

I found that the challenge value is calculated in their script using a function. This function takes challengeSeeds, which change regularly within the script, so they can't be hardcoded.

Image

So, one way to get the challenge value is to intercept the network request, get all the POST data, and then send it.

When the Phind _sendPrompt function is called, it triggers the background function create-chat-window. This function opens a Phind chat page window with a debugger attached and Fetch.enable enabled to intercept network requests.

Once the Phind chat window is open, we need to run a script to send the prompt, so that the network request is sent out and we can intercept it.

For Phind, this is the script that needs to be run in the Phind chat window:

send.js

Before running this script, we need to inject the waitForElement script first. I've made it into a separate script so that it can be shared:

waitForElement.js

These scripts are run when the request to https://www.phind.com/api/stripe/subscriptions is intercepted. When this request is intercepted, meaning the Phind chat window is ready to send prompt.

Then, after running the send.js script, the request to https://https.api.phind.com/agent/ will be intercepted, and we'll run global.mainWindow.webContents.send("phind-request", data);, the data will have all POST data.

After that, it will go back to the renderer, and PhindBot will send a request with the POST data received from phind-request.


I also done this way for https://yiyan.baidu.com/

after this is merge i will open another PR for yiyan because some codes is shared in this PR

@asyncButNeverAwaits
Copy link
Contributor Author

asyncButNeverAwaits commented Apr 19, 2024

make mainWindow as global to use in other file
phind need to generate challenge seed which is dynamic only can open the phind window and get the seend
@sunner
Copy link
Owner

sunner commented Apr 24, 2024

I tested it on macOS. Unfortunately, I can't get correct result.

The chat window was created but the prompt was not send. I need more time to find the reason. Have you ever met this?

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