Skip to content

Adds summarize action to the public API (proxy to TRPC mutation) #1088

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

Merged
merged 1 commit into from
Mar 9, 2025

Conversation

erik-nilcoast
Copy link
Contributor

I added this in two commits. One is just for me. I had a few issues getting this running locally on a Linux box. It could just be a me problem :|

The second commit has the addition of a subroute for the summary mutation. It should return the bookmark object with the summarized contents. Please feel free to add or remove any commits and I'll do my best to address any feedback.

Thanks for a fantastic project.

Addresses: #523

export const POST = (req: NextRequest) =>
buildHandler({
req,
searchParamsSchema: z.object({ bookmarkId: z.string() }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put this in a query param for now testing, but let me know if it'd be more idiomatic for this code base to use a routeParam (e.g. /api/v1/bookmarks/summary/:bookmark-id), a queryParam, or a structured POST body like: { bookmarkId: foo-id }. Let me know what you prefer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it'll be more idiomatic if we do it as

POST /bookmarks/[bookmarkId]/summarize

to do that, you can move this file to

apps/web/app/api/v1/bookmarks/[bookmarkId]/summarize/route.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for me!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want a GET then?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No POST is still the right verb here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

package.json Outdated
@@ -32,10 +32,5 @@
"turbo": "^2.1.2"
},
"prettier": "@hoarder/prettier-config",
"packageManager": "pnpm@9.0.0-alpha.8+sha256.a433a59569b00389a951352956faf25d1fdf43b568213fbde591c36274d4bc30",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove all of these once the question above is resolved. I just need this for now to keep working :)

Copy link
Collaborator

@MohamedBassem MohamedBassem left a comment

Choose a reason for hiding this comment

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

Hey, thanks for opening the PR. Left a small comment about the endpoint!

export const POST = (req: NextRequest) =>
buildHandler({
req,
searchParamsSchema: z.object({ bookmarkId: z.string() }),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it'll be more idiomatic if we do it as

POST /bookmarks/[bookmarkId]/summarize

to do that, you can move this file to

apps/web/app/api/v1/bookmarks/[bookmarkId]/summarize/route.ts

@erik-nilcoast
Copy link
Contributor Author

erik-nilcoast commented Mar 8, 2025

Switched to a GET POST subroute, let me know if this needs anything else and I've removed my build hacks.

@ebenoist ebenoist force-pushed the erik/subscribe branch 3 times, most recently from c9fcd1d to c6eb789 Compare March 8, 2025 14:35
@erik-nilcoast
Copy link
Contributor Author

Looks green. I'll test locally. Is there somewhere I need to add for docs or are those all autogenerated?

@MohamedBassem
Copy link
Collaborator

@erik-nilcoast Oh good catch, we need to update the docs here: https://github.com/hoarder-app/hoarder/blob/main/packages/open-api/lib/bookmarks.ts

and then call pnpm run generate inside packages/open-api to generate the openAPI files.

Also, can we call the endpoint summarize instead of summary? I feel like here you're not posting a summary but instead triggering a summarize action.

@erik-nilcoast
Copy link
Contributor Author

erik-nilcoast commented Mar 8, 2025 via email

@erik-nilcoast
Copy link
Contributor Author

Build works great on a mac. ¯_(ツ)_/¯

@MohamedBassem docs are updated and I moved the route to summarize

Proxy to the TRPC Summarize mutation for use in the public API
@erik-nilcoast erik-nilcoast changed the title Adds /summary as a subroute of api/v1/bookmarks for triggering the summary mutation Adds summarize action to the public API (proxy to TRPC mutation) Mar 9, 2025
@erik-nilcoast
Copy link
Contributor Author

I think this is likely good to go. Let me know if there's anything else I can do to get this on the release schedule (I'd love to get off my fork).

I may need to add some additional API endpoints in the near future. I'm looking at deploying Hoarder for a client, but would love to give back where I can.

RSS of bookmark collections and email newsletter hoarding are things I'm looking to add.

@MohamedBassem MohamedBassem merged commit 9fb8051 into karakeep-app:main Mar 9, 2025
4 checks passed
@MohamedBassem
Copy link
Collaborator

Thanks a lot @erik-nilcoast (hope your client enjoys hoarder!). If you're planning to be active in the development, you might want to join us in the #development channel on discord :) Also I'd highly recommend before working on a new feature to make sure we have an issue for it with the status/approved tag, to make sure we're aligned on how this feature will look like!

@erik-nilcoast
Copy link
Contributor Author

@MohamedBassem Will do, I'll join y'all.

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.

2 participants