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

Chore: use SSE to deliver change event for knowledgefiles #1106

Merged
merged 3 commits into from
Jan 6, 2025

Conversation

StrongMonkey
Copy link
Contributor

@StrongMonkey StrongMonkey commented Jan 3, 2025

We used to pull knowledge at an interval but this is not effiencient. Switching to use SSE events to watch for changes.

@@ -141,9 +141,6 @@ export default function FileTreeNode({
filePathPrefixInclude,
filePathPrefixExclude,
});

// We should manually approve/unapprove all files in the folder at once so that we don't rely on backend reconciliation logic as it will cause delay in updating the UI.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems not ideal to approve files in frontend just for fast feedback from UI. I think it is ok to just rely on backend to reconcile all the files to be approved.


eventSource.onmessage = (event) => {
const payload = JSON.parse(event.data);
const { eventType, knowledgeFile } = payload;
Copy link
Contributor

Choose a reason for hiding this comment

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

can you create a type for this?

Signed-off-by: Daishan Peng <[email protected]>

for event := range w.ResultChan() {
if knowledgeFile, ok := event.Object.(*v1.KnowledgeFile); ok {
payload := map[string]interface{}{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
payload := map[string]interface{}{
payload := map[string]any{

@@ -11,7 +11,7 @@ import (
func Router(services *services.Services) (http.Handler, error) {
mux := services.APIServer

agents := handlers.NewAgentHandler(services.GPTClient, services.Invoker, services.ServerURL)
agents := handlers.NewAgentHandler(services.GPTClient, services.Invoker, services.ServerURL, services.StorageClient)
Copy link
Contributor

Choose a reason for hiding this comment

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

The api.Context object passed to each of these handlers already has a client. Can we just use that one instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! addressed

Signed-off-by: Daishan Peng <[email protected]>
@StrongMonkey StrongMonkey requested a review from thedadams January 6, 2025 16:27
@StrongMonkey StrongMonkey merged commit dd853d9 into obot-platform:main Jan 6, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants