Skip to content

Triggering docs and adding options to all trigger hooks #1528

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
Dec 3, 2024

Conversation

ericallam
Copy link
Member

@ericallam ericallam commented Dec 2, 2024

Summary by CodeRabbit

  • New Features

    • Introduced trigger options for all trigger hooks, enhancing customization and flexibility.
    • New documentation files created for @trigger.dev/react-hooks, detailing usage and integration.
    • Added new hooks for real-time task triggering and subscription, including useTaskTrigger, useRealtimeTaskTrigger, and useRealtimeTaskTriggerWithStreams.
  • Documentation

    • Updated documentation for creating Public Access Tokens, focusing on authentication and expiration settings.
    • Removed outdated sections on write scopes for Public Access Tokens.
    • Enhanced navigation structure for improved accessibility in documentation.
    • Revised task triggering documentation with new functions and improved clarity.
  • Bug Fixes

    • Clarified error handling and usage examples in the documentation for various hooks.

Copy link

changeset-bot bot commented Dec 2, 2024

🦋 Changeset detected

Latest commit: c603b7c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@trigger.dev/react-hooks Patch
@trigger.dev/build Patch
@trigger.dev/core Patch
@trigger.dev/rsc Patch
@trigger.dev/sdk Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
trigger.dev Patch
@internal/redis-worker Patch
@internal/zod-worker Patch
@internal/testcontainers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request enhance the @trigger.dev/react-hooks package by introducing trigger options for all trigger hooks, allowing for more flexible configurations. Additionally, the documentation has been updated to reflect these changes, including the removal and addition of various sections related to Public Access Tokens and task triggering methods. New documentation files have been created for better organization, while existing files have been deleted or modified to streamline information on using the hooks and their functionalities.

Changes

File Path Change Summary
.changeset/nine-vans-perform.md Added trigger options for all trigger hooks in @trigger.dev/react-hooks.
docs/frontend/overview.mdx Updated documentation for Public Access Tokens, removed write scopes, clarified expiration settings.
docs/frontend/react-hooks.mdx Deleted comprehensive documentation for @trigger.dev/react-hooks.
docs/frontend/react-hooks/overview.mdx Created new documentation file for @trigger.dev/react-hooks, covering installation and usage.
docs/frontend/react-hooks/realtime.mdx Created new documentation for real-time hooks, detailing their usage and options.
docs/frontend/react-hooks/triggering.mdx Created new documentation for task triggering hooks, including examples and demo application link.
docs/mint.json Enhanced navigation structure and added redirect rules for documentation.
docs/triggering.mdx Updated task triggering methods with new functions and improved clarity on usage.
packages/react-hooks/src/hooks/useTaskTrigger.ts Modified useTaskTrigger to include TriggerOptions for flexible task submissions.

Possibly related PRs

🐰 In the garden where options bloom,
New hooks sprout, dispelling gloom.
With tokens bright, our tasks take flight,
React now dances, a joyful sight!
So hop along, let’s trigger away,
In the world of code, we’ll play all day! 🌼

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/react-hooks/src/hooks/useTaskTrigger.ts

Oops! Something went wrong! :(

ESLint: 8.45.0

ESLint couldn't find the config "custom" to extend from. Please check that the name of the config is correct.

The config "custom" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b4ce9fa and c603b7c.

📒 Files selected for processing (9)
  • .changeset/nine-vans-perform.md (1 hunks)
  • docs/frontend/overview.mdx (0 hunks)
  • docs/frontend/react-hooks.mdx (0 hunks)
  • docs/frontend/react-hooks/overview.mdx (1 hunks)
  • docs/frontend/react-hooks/realtime.mdx (1 hunks)
  • docs/frontend/react-hooks/triggering.mdx (1 hunks)
  • docs/mint.json (2 hunks)
  • docs/triggering.mdx (1 hunks)
  • packages/react-hooks/src/hooks/useTaskTrigger.ts (3 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (13)
.changeset/nine-vans-perform.md (1)

1-5: Enhance the changeset description with more details.

While the patch version bump is appropriate for adding new options, the description could be more informative. Consider expanding it to include:

  • List of trigger options that were added
  • Impact on existing hook usage
  • Any migration steps if needed

Example of a more detailed description:

---
"@trigger.dev/react-hooks": patch
---

-Add trigger options to all trigger hooks
+Add trigger options to all trigger hooks
+
+This patch introduces new configuration options for all trigger hooks in the package:
+- List the key options added
+- Mention any default values
+
+These options allow for more flexible hook configurations while maintaining backward compatibility.
+
+## Usage
+Brief example of how to use the new options
docs/frontend/react-hooks/triggering.mdx (4)

68-69: Enhance warning for multiple use tokens

The warning about multiple use tokens should be more prominent and explain the security implications.

-  multipleUse: true, // ❌ Use this with caution!
+  multipleUse: true, // ⚠️ SECURITY RISK: Multiple use tokens can be reused by attackers if intercepted. Use only for development or when absolutely necessary.

97-99: Enhance error handling example

The error handling could be more informative for users.

   if (error) {
-    return <div>Error: {error.message}</div>;
+    return (
+      <div role="alert" className="error-message">
+        <h3>Error occurred while triggering task</h3>
+        <p>{error.message}</p>
+        {error.cause && <p>Cause: {error.cause.message}</p>}
+      </div>
+    );
   }

177-178: Add cleanup documentation

Add information about cleanup when the component unmounts.

Add the following note after the example:

<Note>
The hook automatically handles cleanup of realtime subscriptions when the component unmounts. No manual cleanup is required.
</Note>

217-220: Enhance stream types documentation

The stream type example could be more comprehensive.

 type STREAMS = {
-  openai: string; // this is the type of each "part" of the stream
+  openai: string; // Stream parts for OpenAI responses
+  progress: number; // Stream parts for progress updates
+  logs: { level: 'info' | 'error'; message: string }; // Stream parts for log messages
 };
docs/frontend/react-hooks/overview.mdx (2)

7-7: Fix grammatical issues

There are two minor grammatical issues to address:

-Our react hooks package provides
+Our React hooks package provides
-If you are using Next.js with the App Router, you have to make sure the component that uses the `TriggerAuthContext` is a client component. So for example, the following code will not work:
+If you are using Next.js with the App Router, you have to make sure the component that uses the `TriggerAuthContext` is a client component. So, for example, the following code will not work:

Also applies to: 87-87

🧰 Tools
🪛 LanguageTool

[grammar] ~7-~7: “React” is a proper noun and needs to be capitalized.
Context: ...I from your React application. --- Our react hooks package provides a set of hooks t...

(A_GOOGLE)


305-306: Enhance polling interval guidance

The polling warning could provide more specific guidance.

-  Poll for updates at the specified interval (in milliseconds). Polling is not recommended for most
-  use-cases. Use the Realtime hooks instead.
+  Poll for updates at the specified interval (in milliseconds). Polling is not recommended due to API rate limits
+  and increased latency. For real-time updates, use the Realtime hooks which provide immediate updates via WebSocket
+  connections without polling overhead.
docs/frontend/react-hooks/realtime.mdx (4)

91-91: Fix grammatical error in the sentence.

Add an apostrophe to make it possessive.

-To correctly type the runs payload and output, you can provide the type of your task to the `useRealtimeRunsWithTag` hook:
+To correctly type the run's payload and output, you can provide the type of your task to the `useRealtimeRunsWithTag` hook:
🧰 Tools
🪛 LanguageTool

[uncategorized] ~91-~91: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: .../div> ); } ``` To correctly type the runs payload and output, you can provide the...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)


205-205: Fix grammatical error in the sentence.

Use singular "type" with plural "streams".

-You can provide the type of the streams to the `useRealtimeRunWithStreams` hook:
+You can provide the types of the streams to the `useRealtimeRunWithStreams` hook:
🧰 Tools
🪛 LanguageTool

[grammar] ~205-~205: In this context, ‘type’ should agree in number with the noun after ‘of’.
Context: ... ); } ``` You can provide the type of the streams to the useRealtimeRunWithStreams hook...

(TYPE_OF_PLURAL)


239-239: Add missing comma in the sentence.

Add a comma after "If instead of a pure text stream".

-As you can see above, each stream is an array of the type you provided, keyed by the stream name. If instead of a pure text stream you have a stream of objects, you can provide the type of the object:
+As you can see above, each stream is an array of the type you provided, keyed by the stream name. If instead of a pure text stream, you have a stream of objects, you can provide the type of the object:
🧰 Tools
🪛 LanguageTool

[uncategorized] ~239-~239: Possible missing comma found.
Context: ... stream name. If instead of a pure text stream you have a stream of objects, you can p...

(AI_HYDRA_LEO_MISSING_COMMA)


34-34: Add error type information in error handling examples.

The error handling examples should include information about the possible error types to help developers handle specific error cases appropriately.

Add error type information in the examples:

-  if (error) return <div>Error: {error.message}</div>;
+  if (error) {
+    // error is of type RealtimeError which can be:
+    // - ConnectionError: When the connection to the server fails
+    // - AuthenticationError: When the access token is invalid
+    // - SubscriptionError: When there's an error with the subscription
+    return <div>Error: {error.message}</div>;
+  }

Also applies to: 57-57, 79-79, 156-156, 190-190, 226-226, 258-258

docs/triggering.mdx (2)

Line range hint 146-146: Fix typo in the sentence.

Remove the extra "the" in the sentence.

-The `useRealtimeBatch` hook allows you to subscribe to a batch of runs by its the batch ID.
+The `useRealtimeBatch` hook allows you to subscribe to a batch of runs by its batch ID.
🧰 Tools
🪛 LanguageTool

[style] ~701-~701: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...# Triggering from your frontend If you want to trigger a task directly from a frontend...

(REP_WANT_TO_VB)


701-702: Add missing information about frontend triggering.

The section about triggering from frontend is incomplete. Consider adding a brief overview before redirecting to the React hooks documentation.

Add a brief overview:

 ## Triggering from your frontend

+When triggering tasks from frontend applications, you need to consider:
+- Authentication using Public Access Tokens
+- Error handling and retry strategies
+- Real-time updates and progress tracking
+
 If you want to trigger a task directly from a frontend application, you can use our [React
 hooks](/frontend/react-hooks/triggering).
🧰 Tools
🪛 LanguageTool

[style] ~701-~701: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...# Triggering from your frontend If you want to trigger a task directly from a frontend...

(REP_WANT_TO_VB)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cf7dc8d and b4ce9fa.

📒 Files selected for processing (9)
  • .changeset/nine-vans-perform.md (1 hunks)
  • docs/frontend/overview.mdx (0 hunks)
  • docs/frontend/react-hooks.mdx (0 hunks)
  • docs/frontend/react-hooks/overview.mdx (1 hunks)
  • docs/frontend/react-hooks/realtime.mdx (1 hunks)
  • docs/frontend/react-hooks/triggering.mdx (1 hunks)
  • docs/mint.json (2 hunks)
  • docs/triggering.mdx (1 hunks)
  • packages/react-hooks/src/hooks/useTaskTrigger.ts (3 hunks)
💤 Files with no reviewable changes (2)
  • docs/frontend/react-hooks.mdx
  • docs/frontend/overview.mdx
🧰 Additional context used
🪛 LanguageTool
docs/frontend/react-hooks/overview.mdx

[grammar] ~7-~7: “React” is a proper noun and needs to be capitalized.
Context: ...I from your React application. --- Our react hooks package provides a set of hooks t...

(A_GOOGLE)


[uncategorized] ~87-~87: Possible missing comma found.
Context: ...ggerAuthContext` is a client component. So for example, the following code will no...

(AI_HYDRA_LEO_MISSING_COMMA)

docs/frontend/react-hooks/triggering.mdx

[uncategorized] ~115-~115: Loose punctuation mark.
Context: ...th the following properties: - submit: A function that triggers the task. It t...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~116-~116: Loose punctuation mark.
Context: ...d of the task as an argument. - handle: The run handle object. This object cont...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~117-~117: Loose punctuation mark.
Context: ...be used to access the run. - isLoading: A boolean that indicates whether the ta...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~118-~118: Loose punctuation mark.
Context: ... is currently being triggered. - error: An error object that contains any error...

(UNLIKELY_OPENING_PUNCTUATION)

docs/frontend/react-hooks/realtime.mdx

[uncategorized] ~91-~91: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: .../div> ); } ``` To correctly type the runs payload and output, you can provide the...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)


[grammar] ~205-~205: In this context, ‘type’ should agree in number with the noun after ‘of’.
Context: ... ); } ``` You can provide the type of the streams to the useRealtimeRunWithStreams hook...

(TYPE_OF_PLURAL)


[uncategorized] ~239-~239: Possible missing comma found.
Context: ... stream name. If instead of a pure text stream you have a stream of objects, you can p...

(AI_HYDRA_LEO_MISSING_COMMA)

🔇 Additional comments (6)
packages/react-hooks/src/hooks/useTaskTrigger.ts (3)

11-11: LGTM: Clean import addition

The TriggerOptions type import is correctly added and necessary for the interface changes.


Line range hint 65-84: LGTM: Comprehensive options handling

The implementation thoroughly processes all trigger options with proper type safety. The idempotencyKey is correctly handled using makeIdempotencyKey, and all option fields are properly passed to the apiClient.


121-121: LGTM: Consistent interface updates

The addition of optional TriggerOptions is consistent across all interfaces and maintains backward compatibility.

Let's verify that all consumers of these interfaces are updated correctly:

Also applies to: 169-169

docs/mint.json (1)

113-116: LGTM: Documentation structure changes

The changes to redirects and navigation structure are well-organized and maintain consistency with the new documentation layout.

Also applies to: 214-221

docs/frontend/react-hooks/realtime.mdx (1)

1-391: Documentation structure and examples are well organized.

The documentation provides clear explanations, proper TypeScript examples, and covers important aspects like error handling, type safety, and configuration options.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~91-~91: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: .../div> ); } ``` To correctly type the runs payload and output, you can provide the...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)


[grammar] ~205-~205: In this context, ‘type’ should agree in number with the noun after ‘of’.
Context: ... ); } ``` You can provide the type of the streams to the useRealtimeRunWithStreams hook...

(TYPE_OF_PLURAL)


[uncategorized] ~239-~239: Possible missing comma found.
Context: ... stream name. If instead of a pure text stream you have a stream of objects, you can p...

(AI_HYDRA_LEO_MISSING_COMMA)

docs/triggering.mdx (1)

Line range hint 1-1000: Documentation is comprehensive and well-structured.

The documentation provides thorough coverage of task triggering, including:

  • Clear explanations of different triggering methods
  • Proper code examples with TypeScript
  • Important warnings and notes about potential pitfalls
  • Comprehensive coverage of options and configurations
🧰 Tools
🪛 LanguageTool

[style] ~701-~701: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...# Triggering from your frontend If you want to trigger a task directly from a frontend...

(REP_WANT_TO_VB)

```

```bash yarn
yarn install @trigger.dev/react-hooks
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix yarn installation command

The yarn installation command is incorrect and would fail.

-yarn install @trigger.dev/react-hooks
+yarn add @trigger.dev/react-hooks
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
yarn install @trigger.dev/react-hooks
yarn add @trigger.dev/react-hooks

Copy link

pkg-pr-new bot commented Dec 2, 2024

@trigger.dev/react-hooks

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/react-hooks@1528

@trigger.dev/rsc

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/rsc@1528

@trigger.dev/build

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/build@1528

trigger.dev

npm i https://pkg.pr.new/triggerdotdev/trigger.dev@1528

@trigger.dev/sdk

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/sdk@1528

@trigger.dev/core

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/core@1528

commit: b4ce9fa

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.

1 participant