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

Add endpoint for the Dev UI to subscribe to runtime updates #1154

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

Conversation

MichaelDoyle
Copy link
Member

Checklist (if applicable):

  • Tested (manually, unit tested, etc.)
  • [N/A] Docs updated

cc @tonybaroneee

genkit-tools/common/src/manager/manager.ts Outdated Show resolved Hide resolved
@@ -110,6 +117,14 @@ export class RuntimeManager {
);
}

subscribeToRuntimeEvents(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be manager.subscribeToRuntimeEvents(...) which makes it seem like the manager is subscribing. Maybe just onRuntimeEvents? Also please add a JSDoc explaining how to use it.

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

@@ -79,6 +79,33 @@ export async function startServer(manager: RuntimeManager, port: number) {
res.end();
});

app.get('/api/latest/runtime', async (_, res) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is latest referring to here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Latest is referring to the fact that this endpoint will only ever return the most recent runtime info.

Copy link
Collaborator

@apascal07 apascal07 Oct 31, 2024

Choose a reason for hiding this comment

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

Hmm, shouldn't it be flipped then? /api/runtimes/latest?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also any reason this shouldn't be part of the tRPC router?

Copy link
Member Author

@MichaelDoyle MichaelDoyle Nov 1, 2024

Choose a reason for hiding this comment

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

I ended up renaming this to /api/sse and made it general purpose for any events the server needs to send. I don't actually know that this will be a requirement... but... sse is limited to 6 connections for the entire browser (including tabs) under http(s). So better to set us up to have a single connection for the whole dev ui in the future.

As for why not tRPC, (a) my starting point is here (picking up from Shruti) #1053 but also (b) tRPC does not support SSE until v11, which is currently in "beta".

genkit-tools/common/src/server/server.ts Show resolved Hide resolved
@MichaelDoyle
Copy link
Member Author

@apascal07 @tonybaroneee made some more tweaks based on feedback and my own testing. PTAL.

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

Successfully merging this pull request may close these issues.

3 participants