diff --git a/packages/docs/docs/node-reference/assets/graph-output-node-example-01-2.png b/packages/docs/docs/node-reference/assets/graph-output-node-example-01-2.png new file mode 100644 index 000000000..2e8ef33ce Binary files /dev/null and b/packages/docs/docs/node-reference/assets/graph-output-node-example-01-2.png differ diff --git a/packages/docs/docs/node-reference/assets/graph-output-node-example-01.png b/packages/docs/docs/node-reference/assets/graph-output-node-example-01.png new file mode 100644 index 000000000..2a06615cd Binary files /dev/null and b/packages/docs/docs/node-reference/assets/graph-output-node-example-01.png differ diff --git a/packages/docs/docs/node-reference/assets/graph-output-node.png b/packages/docs/docs/node-reference/assets/graph-output-node.png new file mode 100644 index 000000000..6fe6f6107 Binary files /dev/null and b/packages/docs/docs/node-reference/assets/graph-output-node.png differ diff --git a/packages/docs/docs/node-reference/assets/hash-node-example-01.png b/packages/docs/docs/node-reference/assets/hash-node-example-01.png new file mode 100644 index 000000000..f2aabeff0 Binary files /dev/null and b/packages/docs/docs/node-reference/assets/hash-node-example-01.png differ diff --git a/packages/docs/docs/node-reference/assets/hash-node.png b/packages/docs/docs/node-reference/assets/hash-node.png new file mode 100644 index 000000000..c50f2bd69 Binary files /dev/null and b/packages/docs/docs/node-reference/assets/hash-node.png differ diff --git a/packages/docs/docs/node-reference/assets/http-call-node-example-01.png b/packages/docs/docs/node-reference/assets/http-call-node-example-01.png new file mode 100644 index 000000000..327810745 Binary files /dev/null and b/packages/docs/docs/node-reference/assets/http-call-node-example-01.png differ diff --git a/packages/docs/docs/node-reference/assets/http-call-node-example-02.png b/packages/docs/docs/node-reference/assets/http-call-node-example-02.png new file mode 100644 index 000000000..70e08aa36 Binary files /dev/null and b/packages/docs/docs/node-reference/assets/http-call-node-example-02.png differ diff --git a/packages/docs/docs/node-reference/assets/http-call-node.png b/packages/docs/docs/node-reference/assets/http-call-node.png new file mode 100644 index 000000000..2770a571b Binary files /dev/null and b/packages/docs/docs/node-reference/assets/http-call-node.png differ diff --git a/packages/docs/docs/node-reference/assets/if-else-node-example-01.png b/packages/docs/docs/node-reference/assets/if-else-node-example-01.png new file mode 100644 index 000000000..aad7db8c2 Binary files /dev/null and b/packages/docs/docs/node-reference/assets/if-else-node-example-01.png differ diff --git a/packages/docs/docs/node-reference/assets/if-else-node-example-02.png b/packages/docs/docs/node-reference/assets/if-else-node-example-02.png new file mode 100644 index 000000000..20ebf592d Binary files /dev/null and b/packages/docs/docs/node-reference/assets/if-else-node-example-02.png differ diff --git a/packages/docs/docs/node-reference/assets/if-else-node.png b/packages/docs/docs/node-reference/assets/if-else-node.png new file mode 100644 index 000000000..430b72e5d Binary files /dev/null and b/packages/docs/docs/node-reference/assets/if-else-node.png differ diff --git a/packages/docs/docs/node-reference/graph-output.mdx b/packages/docs/docs/node-reference/graph-output.mdx index 9fc7543e0..87dc53c76 100644 --- a/packages/docs/docs/node-reference/graph-output.mdx +++ b/packages/docs/docs/node-reference/graph-output.mdx @@ -1,5 +1,93 @@ --- -title: 'Graph Output' +id: graph-output +title: Graph Output Node +sidebar_label: Graph Output --- -# Graph Output Node +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +![Graph Output Node Screenshot](./assets/graph-output-node.png) + +## Overview + +The Graph Output Node is used to define the outputs of a graph. Each instance of this node represents an individual output of the graph. The value passed into this node becomes part of the overall output of the graph. + +When a graph is used as a subgraph, each Graph Output Node in the graph turns into an output port on the subgraph node. + + + + + +## Inputs + +| Title | Data Type | Description | Default Value | Notes | +| ----- | --------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------- | ----- | +| Value | `any` | The value to be outputted from the graph. The data type of the value should match the data type configured in the node settings. | (required) | | + + + + + +## Outputs + +| Title | Data Type | Description | Notes | +| ------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------ | ----- | +| Value Output | `any` | The value that was passed into the node. The data type of the output will match the data type configured in the node settings. | | + + + + + +## Editor Settings + +| Setting | Description | Default Value | Use Input Toggle | Input Data Type | +| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ---------------- | --------------- | +| ID | The ID of the output. This will be used as the name and ID of the output port of the graph. | `output` | No | `string` | +| Data Type | The data type of the value to be outputted from the graph. This should match the data type of the value passed into the node. If the data type of the input data does not match, it will be coerced into this type. | `string` | No | N/A | + + + + + +## Example 1: Define an output for a graph + +1. Create a [Text Node](./text.mdx) and set the value to `Hello, world!`. +2. Create a Graph Output Node and set the ID to `greeting` and the Data Type to `String`. +3. Connect the Text Node to the `Value` input of the Graph Output Node. +4. Create another graph, and add a [Subgraph Node](./subgraph.mdx) to the graph. Set the Subgraph Node's Graph ID to the ID of the graph created in step 1. +5. Run the graph. You should see the `greeting` output of the subgraph is "Hello, world!" + +![Graph Output Node Example 1](./assets/graph-output-node-example-01.png) +![Graph Output Node Example 1](./assets/graph-output-node-example-01-2.png) + +## Error Handling + +The Graph Output Node will error if the data type of the value passed into the node does not match the data type configured in the node settings. + +## FAQ + +**Q: Can I have multiple Graph Output Nodes in a graph?** + +A: Yes, you can have multiple Graph Output Nodes in a graph. Each Graph Output Node represents an individual output of the graph. The ID of each Graph Output Node should be unique. + +**Q: What happens if the ID of a Graph Output Node is not unique?** + +A: If the ID of a Graph Output Node is not unique, the output of the graph will contain the value of the last Graph Output Node with that ID that was processed. + +**Q: Can I use the Graph Output Node to output an array or an object?** + +A: Yes, you can use the Graph Output Node to output any data type. The data type of the value passed into the node should match the data type configured in the node settings. + +## See Also + +- [Graph Input Node](./graph-input.mdx) +- [Subgraph Node](./subgraph.mdx) +- [Data Types](../user-guide/data-types.md) diff --git a/packages/docs/docs/node-reference/hash.mdx b/packages/docs/docs/node-reference/hash.mdx index 93ed9de01..650cd8634 100644 --- a/packages/docs/docs/node-reference/hash.mdx +++ b/packages/docs/docs/node-reference/hash.mdx @@ -1,5 +1,88 @@ --- -title: 'Hash' +id: hash +title: Hash Node +sidebar_label: Hash --- -# Hash Node +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +![Hash Node Screenshot](./assets/hash-node.png) + +## Overview + +The Hash Node computes a hash of the input value using the configured hash function. It supports MD5, SHA-1, SHA-256, and SHA-512 hash algorithms. This node can be useful for generating unique IDs, checksums, and other purposes. + + + + + +## Inputs + +| Title | Data Type | Description | Default Value | Notes | +| ----- | --------- | ------------------------ | ------------- | -------------------------------------------------------------- | +| Input | `string` | The string to be hashed. | (required) | The input will be coerced into a string if it is not a string. | + + + + + +## Outputs + +| Title | Data Type | Description | Notes | +| ----- | --------- | ----------------------------- | ----- | +| Hash | `string` | The hash of the input string. | | + + + + + +## Editor Settings + +| Setting | Description | Default Value | Use Input Toggle | Input Data Type | +| --------- | ------------------------------------------------------------------------ | ------------- | ---------------- | --------------- | +| Algorithm | The hash algorithm to use. Options are MD5, SHA-1, SHA-256, and SHA-512. | SHA-256 | No | N/A | + + + + + +## Example 1: Hash a string + +1. Create a [Text Node](./text.mdx) and set the value to `Hello, World!`. +2. Create a Hash Node and connect the Text Node to its `Input` port. +3. Run the graph. The `Hash` output of the Hash Node should contain the hash of the string `Hello, World!`. + +![Hash Node Example 1](./assets/hash-node-example-01.png) + +## Error Handling + +The Hash Node will error if the `Input` is not provided or if an unsupported hash algorithm is specified. + +## FAQ + +**Q: Can I use the Hash Node to hash a number or other non-string value?** + +A: Yes, you can. The Hash Node will automatically convert non-string inputs into strings before hashing them. + +**Q: Can I use the Hash Node to hash a password?** + +A: It is not recommended to have passwords in Rivet. If you need to hash a password, you should do so outside of Rivet. + +**Q: Can I use the Hash Node to generate a unique ID for a piece of data?** + +A: Yes, you can use the Hash Node to generate a unique repeatable ID for a piece of data by hashing the data. This can be used with the [Vector Store Node](./vector-store.mdx) to store the data in a vector store with the ID as the key. + +## See Also + +- [Text Node](./text.mdx) +- [Number Node](./number.mdx) +- [Vector Store Node](./vector-store.mdx) +- [RNG Node](./rng.mdx) diff --git a/packages/docs/docs/node-reference/http-call.mdx b/packages/docs/docs/node-reference/http-call.mdx index ef0284ee4..d1c29bb72 100644 --- a/packages/docs/docs/node-reference/http-call.mdx +++ b/packages/docs/docs/node-reference/http-call.mdx @@ -1,5 +1,120 @@ --- -title: 'HTTP Call' +id: http-call +title: HTTP Call Node +sidebar_label: HTTP Call --- -# HTTP Call Node +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +![HTTP Call Node Screenshot](./assets/http-call-node.png) + +## Overview + +The HTTP Call Node allows you to make an HTTP call to a specified URL with a given method, headers, and body. This node is particularly useful when you need to interact with external APIs or services. + +The HTTP Call Node uses the Fetch API to make HTTP requests. It supports all HTTP methods (GET, POST, PUT, DELETE, etc.) and allows you to specify custom headers and a request body. + +:::caution +When using the default [browser executor](../user-guide/executors.md), you have to worry about [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) when making HTTP requests to external APIs. If the API you are trying to call does not support CORS to `http://tauri.local` (most do not), you will run into CORS problems. This can manifest as an error `fetch failed` in the output panel. + +This can be worked around by using the [Node executor](../user-guide/executors.md) in Rivet, which does not do CORS checks. +::: + + + + + +## Inputs + +The HTTP call node only has inputs when the [Editor Settings](#editor-settings) are set to use input toggles. See that section for more information. + + + + + +## Outputs + +| Title | Data Type | Description | Notes | +| ----------- | --------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | +| Body | `string` | The body of the HTTP response. | If the response body is not a string, this output will not be ran. | +| JSON | `object` | If the response body is a JSON object, this output will contain the parsed JSON object. | If the response body is not a JSON object, this output will not be ran. | +| Status Code | `number` | The status code of the HTTP response. | | +| Headers | `object` | The headers of the HTTP response. | | + + + + + +## Editor Settings + +| Setting | Description | Default Value | Use Input Toggle | Input Data Type | +| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ---------------- | --------------- | +| Method | The HTTP method to use for the request (GET, POST, PUT, DELETE, etc.). | GET | Yes | `string` | +| URL | The URL to make the HTTP request to. | (empty) | Yes | `string` | +| Headers | An object representing the headers to include in the HTTP request. | (empty) | Yes | `object` | +| Body | The body of the HTTP request. This is typically used for POST or PUT requests. The value passed in here is not JSON stringified, so if you need a JSON body, use the [To JSON](./to-json.mdx) node. | (empty) | Yes | `string` | +| Error on non-200 status code | If enabled, the node will error if the status code of the HTTP response is not 200. | True | No | N/A | + + + + + +## Example 1: Make a GET request to an API + +1. Create an HTTP Call Node and set the `Method` to `GET` and the `URL` to `https://jsonplaceholder.typicode.com/todos/1`. +2. Run the graph. You should see all of the response data, such as the headers, response code, and body, in the output panel. + +![HTTP Call Node Example 1](./assets/http-call-node-example-01.png) + +## Example 2: Make a POST request to an API + +1. Create an HTTP Call Node and set the `Method` to `POST` and the `URL` to `https://jsonplaceholder.typicode.com/posts`. Enable the "Use Input" toggle on the "Body" setting to enable the input port for Body. +2. Create an [Object Node](./object.mdx) and set the object to: + +```json +{ + "title": "foo", + "body": "bar", + "userId": 1 +} +``` + +3. Create a [To JSON Node](./to-json.mdx) and connect the Object Node to the `Data` input of the To JSON Node. Connect the To JSON Node to the `Body` input of the HTTP Call Node. +4. Create an [Extract Object Path](./extract-object-path.mdx) Node and connect the `JSON` output of the HTTP Call Node to the `Object` input of the Extract Object Path Node. Set the `Path` to `$.id`. +5. Run the graph. You should see the created ID of the post in the Extract Object Path Node's output panel. + +![HTTP Call Node Example 2](./assets/http-call-node-example-02.png) + +## Error Handling + +The HTTP Call Node will error if the HTTP request fails for any reason, such as a network error or if the server returns an error status code. If the `Error on non-200 status code` setting is enabled, the node will also error if the status code of the HTTP response is not 200. + +## FAQ + +**Q: Can I use the HTTP Call Node to make requests to any API?** + +A: Yes, you can use the HTTP Call Node to make requests to any API that supports the HTTP methods GET, POST, PUT, or DELETE. + +**Q: Can I use the HTTP Call Node to send JSON in the request body?** + +A: Yes, you can use a [Text Node](./text.mdx) to create a JSON string and connect it to the `Body` input of the HTTP Call Node. + +**Q: Can I use the HTTP Call Node to handle API authentication?** + +A: Yes, you can include authentication headers in the `Headers` input of the HTTP Call Node. However, for security reasons, you should not hardcode sensitive information like API keys in your graphs. Instead, consider using a [Context Node](./context.mdx) to securely pass in sensitive information from the host application. + +## See Also + +- [To JSON Node](./to-json.mdx) +- [Extract JSON Node](./extract-json.mdx) +- [Extract Object Path Node](./extract-object-path.mdx) +- [Text Node](./text.mdx) +- [Context Node](./context.mdx) diff --git a/packages/docs/docs/node-reference/if-else.mdx b/packages/docs/docs/node-reference/if-else.mdx index 0992ef694..4e871ad9e 100644 --- a/packages/docs/docs/node-reference/if-else.mdx +++ b/packages/docs/docs/node-reference/if-else.mdx @@ -1,5 +1,117 @@ --- -title: 'If/Else' +id: if-else +title: If/Else Node +sidebar_label: If/Else --- -# If/Else Node +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +![If/Else Node Screenshot](./assets/if-else-node.png) + +## Overview + +The If/Else Node is a control flow node that allows you to choose between two different values based on a condition. It takes in three inputs: a condition, a true value, and a false value. If the condition is truthy, the true value is passed through the output port. If the condition is not truthy, the false value is passed through the output port. + +This node can "consume" a `Not Ran` to continue a graph from that point. This means that if a `Not Ran` value is passed into the `If` port, the `False` value will be passed through instead. If the `False` value is not connected, then the result will again be `Not Ran`. + +The If/Else node is particularly useful for always ensuring that a graph returns a value, and the outputs of the graph always run, or ensuring that a later node in the graph always receives a value, even if intermediate nodes do not run. + + + + + +## Inputs + +| Title | Data Type | Description | Default Value | Notes | +| ----- | --------- | ---------------------------------------------------------------------------- | ------------- | -------------------------------------------------------------------------------------------------- | +| If | `any` | The condition to evaluate. If truthy, the true value is passed through. | (required) | The input will be coerced into a boolean if it is not a boolean. | +| True | `any` | The value to pass through if the condition is truthy. | (empty) | The input will be coerced into the same data type as the `False` input if it is not the same type. | +| False | `any` | The value to pass through if the condition is not truthy or is not provided. | (empty) | The input will be coerced into the same data type as the `True` input if it is not the same type. | + + + + + +## Outputs + +| Title | Data Type | Description | Notes | +| ------ | --------- | ----------------------------------------------------------------------------------------------- | ----- | +| Output | `any` | The value that was passed through based on the condition. Either the true value or false value. | | + + + + + +## Editor Settings + +This node has no configurable editor settings. + + + + + +## Example 1: Choose between two values based on a condition + +1. Create a [Boolean Node](../boolean.mdx). Set the value of the Boolean Node to `true`. +2. Create two [Text Nodes](./text.mdx). Set the text of one node to `Hello` and the other to `World`. +3. Create an If/Else Node. Connect the Boolean Node to the `If` input of the If/Else Node. Connect the Text Node with the text `Hello` to the `True` input of the If/Else Node. Connect the Text Node with the text `World` to the `False` input of the If/Else Node. +4. Run the graph. The output of the If/Else Node should be `Hello`. +5. Try changing the value of the Boolean Node to `false`. Run the graph again. The output of the If/Else Node should now be `World`. + +![If/Else Node Example 1](./assets/if-else-node-example-01.png) + +## Example 2: Provide a default value for a missing input + +1. Create an [If Node](./if.mdx) but do not connect anything to its `If` input. +2. Create two [Text Nodes](./text.mdx). Set the text of one node to `Hello` and the other to `World`. +3. Connect the Hello Text Node to the `Value` input of the If Node. +4. Create an If/Else Node. Connect the If Node to the `If` and `True` inputs of the If/Else Node. Connect the Text Node with the text `World` to the `False` input of the If/Else Node. +5. Run the graph. The output of the If/Else Node should be `World`. + +![If/Else Node Example 2](./assets/if-else-node-example-02.png) + +## Error Handling + +The If/Else node will not throw an error under normal circumstances. + +## FAQ + +**Q: What is considered truthy in Rivet?** + +A: Any value that is considered truthy in JavaScript, plus any non-empty Array, is considered truthy in Rivet. This includes: + +- `true` +- Any non-zero number +- Any non-empty string +- Any non-empty Array +- Any object +- Any function + +All other values are considered falsy, including the string value `"false"`. + +**Q: What happens if the `If` input is `Not Ran`?** + +A: If the `If` input is `Not Ran`, the `False` value will be passed through instead. If the `False` value is not connected, then the result will again be `Not Ran`. + +**Q: What happens if the `True` or `False` inputs are not provided?** + +A: If the `True` or `False` inputs are not provided, they will default to `Not Ran`. + +**Q: Can I use the If/Else Node to choose between two different types of values?** + +A: Yes, you can use the If/Else Node to choose between two different types of values. For example, you can use it to choose between a string and a number based on a condition. However, keep in mind that the output of the If/Else Node will be of the same type as the value that was passed through. + +## See Also + +- [If Node](./if.mdx) +- [Match Node](./match.mdx) +- [Coalesce Node](./coalesce.mdx) +- [Control Flow](../user-guide/control-flow.md)