Compare commits

..

18 Commits

Author SHA1 Message Date
Waleed
67aa4bb332 v0.5.95: gemini 3.1 pro, cloudflare, dataverse, revenuecat, redis, upstash, algolia tools; isolated-vm robustness improvements, tables backend (#3271)
* feat(tools): advanced fields for youtube, vercel; added cloudflare and dataverse tools (#3257)

* refactor(vercel): mark optional fields as advanced mode

Move optional/power-user fields behind the advanced toggle:
- List Deployments: project filter, target, state
- Create Deployment: project ID override, redeploy from, target
- List Projects: search
- Create/Update Project: framework, build/output/install commands
- Env Vars: variable type
- Webhooks: project IDs filter
- Checks: path, details URL
- Team Members: role filter
- All operations: team ID scope

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* style(youtube): mark optional params as advanced mode

Hide pagination, sort order, and filter fields behind the advanced
toggle for a cleaner default UX across all YouTube operations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* added advanced fields for vercel and youtube, added cloudflare and dataverse block

* addded desc for dataverse

* add more tools

* ack comment

* more

* ops

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* feat(tables): added tables (#2867)

* updates

* required

* trashy table viewer

* updates

* updates

* filtering ui

* updates

* updates

* updates

* one input mode

* format

* fix lints

* improved errors

* updates

* updates

* chages

* doc strings

* breaking down file

* update comments with ai

* updates

* comments

* changes

* revert

* updates

* dedupe

* updates

* updates

* updates

* refactoring

* renames & refactors

* refactoring

* updates

* undo

* update db

* wand

* updates

* fix comments

* fixes

* simplify comments

* u[dates

* renames

* better comments

* validation

* updates

* updates

* updates

* fix sorting

* fix appearnce

* updating prompt to make it user sort

* rm

* updates

* rename

* comments

* clean comments

* simplicifcaiton

* updates

* updates

* refactor

* reduced type confusion

* undo

* rename

* undo changes

* undo

* simplify

* updates

* updates

* revert

* updates

* db updates

* type fix

* fix

* fix error handling

* updates

* docs

* docs

* updates

* rename

* dedupe

* revert

* uncook

* updates

* fix

* fix

* fix

* fix

* prepare merge

* readd migrations

* add back missed code

* migrate enrichment logic to general abstraction

* address bugbot concerns

* adhere to size limits for tables

* remove conflicting migration

* add back migrations

* fix tables auth

* fix permissive auth

* fix lint

* reran migrations

* migrate to use tanstack query for all server state

* update table-selector

* update names

* added tables to permission groups, updated subblock types

---------

Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai>
Co-authored-by: waleed <walif6@gmail.com>

* fix(snapshot): changed insert to upsert when concurrent identical child workflows are running (#3259)

* fix(snapshot): changed insert to upsert when concurrent identical child workflows are running

* fixed ci tests failing

* fix(workflows): disallow duplicate workflow names at the same folder level (#3260)

* feat(tools): added redis, upstash, algolia, and revenuecat (#3261)

* feat(tools): added redis, upstash, algolia, and revenuecat

* ack comment

* feat(models): add gemini-3.1-pro-preview and update gemini-3-pro thinking levels (#3263)

* fix(audit-log): lazily resolve actor name/email when missing (#3262)

* fix(blocks): move type coercions from tools.config.tool to tools.config.params (#3264)

* fix(blocks): move type coercions from tools.config.tool to tools.config.params

Number() coercions in tools.config.tool ran at serialization time before
variable resolution, destroying dynamic references like <block.result.count>
by converting them to NaN/null. Moved all coercions to tools.config.params
which runs at execution time after variables are resolved.

Fixed in 15 blocks: exa, arxiv, sentry, incidentio, wikipedia, ahrefs,
posthog, elasticsearch, dropbox, hunter, lemlist, spotify, youtube, grafana,
parallel. Also added mode: 'advanced' to optional exa fields.

Closes #3258

* fix(blocks): address PR review — move remaining param mutations from tool() to params()

- Moved field mappings from tool() to params() in grafana, posthog,
  lemlist, spotify, dropbox (same dynamic reference bug)
- Fixed parallel.ts excerpts/full_content boolean logic
- Fixed parallel.ts search_queries empty case (must set undefined)
- Fixed elasticsearch.ts timeout not included when already ends with 's'
- Restored dropbox.ts tool() switch for proper default fallback

* fix(blocks): restore field renames to tool() for serialization-time validation

Field renames (e.g. personalApiKey→apiKey) must be in tool() because
validateRequiredFieldsBeforeExecution calls selectToolId()→tool() then
checks renamed field names on params. Only type coercions (Number(),
boolean) stay in params() to avoid destroying dynamic variable references.

* improvement(resolver): resovled empty sentinel to not pass through unexecuted valid refs to text inputs (#3266)

* fix(blocks): add required constraint for serviceDeskId in JSM block (#3268)

* fix(blocks): add required constraint for serviceDeskId in JSM block

* fix(blocks): rename custom field values to request field values in JSM create request

* fix(trigger): add isolated-vm support to trigger.dev container builds (#3269)

Scheduled workflow executions running in trigger.dev containers were
failing to spawn isolated-vm workers because the native module wasn't
available in the container. This caused loop condition evaluation to
silently fail and exit after one iteration.

- Add isolated-vm to build.external and additionalPackages in trigger config
- Include isolated-vm-worker.cjs via additionalFiles for child process spawning
- Add fallback path resolution for worker file in trigger.dev environment

* fix(tables): hide tables from sidebar and block registry (#3270)

* fix(tables): hide tables from sidebar and block registry

* fix(trigger): add isolated-vm support to trigger.dev container builds (#3269)

Scheduled workflow executions running in trigger.dev containers were
failing to spawn isolated-vm workers because the native module wasn't
available in the container. This caused loop condition evaluation to
silently fail and exit after one iteration.

- Add isolated-vm to build.external and additionalPackages in trigger config
- Include isolated-vm-worker.cjs via additionalFiles for child process spawning
- Add fallback path resolution for worker file in trigger.dev environment

* lint

* fix(trigger): update node version to align with main app (#3272)

* fix(build): fix corrupted sticky disk cache on blacksmith (#3273)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Lakee Sivaraya <71339072+lakeesiv@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai>
Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
2026-02-20 13:43:07 -08:00
Waleed
1b8d666c93 fix(build): fix corrupted sticky disk cache on blacksmith (#3273) 2026-02-20 13:03:23 -08:00
Waleed
71942cb53c fix(trigger): update node version to align with main app (#3272) 2026-02-20 12:32:14 -08:00
Waleed
12534163c1 fix(tables): hide tables from sidebar and block registry (#3270)
* fix(tables): hide tables from sidebar and block registry

* fix(trigger): add isolated-vm support to trigger.dev container builds (#3269)

Scheduled workflow executions running in trigger.dev containers were
failing to spawn isolated-vm workers because the native module wasn't
available in the container. This caused loop condition evaluation to
silently fail and exit after one iteration.

- Add isolated-vm to build.external and additionalPackages in trigger config
- Include isolated-vm-worker.cjs via additionalFiles for child process spawning
- Add fallback path resolution for worker file in trigger.dev environment

* lint
2026-02-20 11:58:02 -08:00
Waleed
55920e9b03 fix(trigger): add isolated-vm support to trigger.dev container builds (#3269)
Scheduled workflow executions running in trigger.dev containers were
failing to spawn isolated-vm workers because the native module wasn't
available in the container. This caused loop condition evaluation to
silently fail and exit after one iteration.

- Add isolated-vm to build.external and additionalPackages in trigger config
- Include isolated-vm-worker.cjs via additionalFiles for child process spawning
- Add fallback path resolution for worker file in trigger.dev environment
2026-02-20 11:41:28 -08:00
Waleed
958dd64740 fix(blocks): add required constraint for serviceDeskId in JSM block (#3268)
* fix(blocks): add required constraint for serviceDeskId in JSM block

* fix(blocks): rename custom field values to request field values in JSM create request
2026-02-20 11:33:52 -08:00
Vikhyath Mondreti
68f44b8df4 improvement(resolver): resovled empty sentinel to not pass through unexecuted valid refs to text inputs (#3266) 2026-02-20 01:56:33 -08:00
Waleed
9920882dc5 fix(blocks): move type coercions from tools.config.tool to tools.config.params (#3264)
* fix(blocks): move type coercions from tools.config.tool to tools.config.params

Number() coercions in tools.config.tool ran at serialization time before
variable resolution, destroying dynamic references like <block.result.count>
by converting them to NaN/null. Moved all coercions to tools.config.params
which runs at execution time after variables are resolved.

Fixed in 15 blocks: exa, arxiv, sentry, incidentio, wikipedia, ahrefs,
posthog, elasticsearch, dropbox, hunter, lemlist, spotify, youtube, grafana,
parallel. Also added mode: 'advanced' to optional exa fields.

Closes #3258

* fix(blocks): address PR review — move remaining param mutations from tool() to params()

- Moved field mappings from tool() to params() in grafana, posthog,
  lemlist, spotify, dropbox (same dynamic reference bug)
- Fixed parallel.ts excerpts/full_content boolean logic
- Fixed parallel.ts search_queries empty case (must set undefined)
- Fixed elasticsearch.ts timeout not included when already ends with 's'
- Restored dropbox.ts tool() switch for proper default fallback

* fix(blocks): restore field renames to tool() for serialization-time validation

Field renames (e.g. personalApiKey→apiKey) must be in tool() because
validateRequiredFieldsBeforeExecution calls selectToolId()→tool() then
checks renamed field names on params. Only type coercions (Number(),
boolean) stay in params() to avoid destroying dynamic variable references.
2026-02-19 21:54:16 -08:00
Waleed
9ca5254c2b fix(audit-log): lazily resolve actor name/email when missing (#3262) 2026-02-19 16:48:43 -08:00
Waleed
d7fddb2909 feat(models): add gemini-3.1-pro-preview and update gemini-3-pro thinking levels (#3263) 2026-02-19 16:20:20 -08:00
Waleed
61c7afc19e feat(tools): added redis, upstash, algolia, and revenuecat (#3261)
* feat(tools): added redis, upstash, algolia, and revenuecat

* ack comment
2026-02-19 16:13:06 -08:00
Waleed
3c470ab0f8 fix(workflows): disallow duplicate workflow names at the same folder level (#3260) 2026-02-19 14:12:43 -08:00
Waleed
2b5e436a2a fix(snapshot): changed insert to upsert when concurrent identical child workflows are running (#3259)
* fix(snapshot): changed insert to upsert when concurrent identical child workflows are running

* fixed ci tests failing
2026-02-19 13:58:35 -08:00
Lakee Sivaraya
e24c824c9a feat(tables): added tables (#2867)
* updates

* required

* trashy table viewer

* updates

* updates

* filtering ui

* updates

* updates

* updates

* one input mode

* format

* fix lints

* improved errors

* updates

* updates

* chages

* doc strings

* breaking down file

* update comments with ai

* updates

* comments

* changes

* revert

* updates

* dedupe

* updates

* updates

* updates

* refactoring

* renames & refactors

* refactoring

* updates

* undo

* update db

* wand

* updates

* fix comments

* fixes

* simplify comments

* u[dates

* renames

* better comments

* validation

* updates

* updates

* updates

* fix sorting

* fix appearnce

* updating prompt to make it user sort

* rm

* updates

* rename

* comments

* clean comments

* simplicifcaiton

* updates

* updates

* refactor

* reduced type confusion

* undo

* rename

* undo changes

* undo

* simplify

* updates

* updates

* revert

* updates

* db updates

* type fix

* fix

* fix error handling

* updates

* docs

* docs

* updates

* rename

* dedupe

* revert

* uncook

* updates

* fix

* fix

* fix

* fix

* prepare merge

* readd migrations

* add back missed code

* migrate enrichment logic to general abstraction

* address bugbot concerns

* adhere to size limits for tables

* remove conflicting migration

* add back migrations

* fix tables auth

* fix permissive auth

* fix lint

* reran migrations

* migrate to use tanstack query for all server state

* update table-selector

* update names

* added tables to permission groups, updated subblock types

---------

Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai>
Co-authored-by: waleed <walif6@gmail.com>
2026-02-19 13:11:35 -08:00
Waleed
15ace5e63f v0.5.94: vercel integration, folder insertion, migrated tracking redirects to rewrites 2026-02-18 16:53:34 -08:00
Waleed
fdca73679d v0.5.93: NextJS config changes, MCP and Blocks whitelisting, copilot keyboard shortcuts, audit logs 2026-02-18 12:10:05 -08:00
Waleed
da46a387c9 v0.5.92: shortlinks, copilot scrolling stickiness, pagination 2026-02-17 15:13:21 -08:00
Waleed
b7e377ec4b v0.5.91: docs i18n, turborepo upgrade 2026-02-16 00:36:05 -08:00
184 changed files with 11681 additions and 936 deletions

View File

@@ -454,6 +454,8 @@ Enables AI-assisted field generation.
## Tools Configuration
**Important:** `tools.config.tool` runs during serialization before variable resolution. Put `Number()` and other type coercions in `tools.config.params` instead, which runs at execution time after variables are resolved.
**Preferred:** Use tool names directly as dropdown option IDs to avoid switch cases:
```typescript
// Dropdown options use tool IDs directly

View File

@@ -144,6 +144,7 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
provenance: false
sbom: false
no-cache: true
# Build ARM64 images for GHCR (main branch only, runs in parallel)
build-ghcr-arm64:
@@ -204,6 +205,7 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
provenance: false
sbom: false
no-cache: true
# Create GHCR multi-arch manifests (only for main, after both builds)
create-ghcr-manifests:

View File

@@ -97,6 +97,7 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
provenance: false
sbom: false
no-cache: true
build-ghcr-arm64:
name: Build ARM64 (GHCR Only)
@@ -143,6 +144,7 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
provenance: false
sbom: false
no-cache: true
create-ghcr-manifests:
name: Create GHCR Manifests

View File

@@ -238,7 +238,7 @@ export const ServiceBlock: BlockConfig = {
bgColor: '#hexcolor',
icon: ServiceIcon,
subBlocks: [ /* see SubBlock Properties */ ],
tools: { access: ['service_action'], config: { tool: (p) => `service_${p.operation}` } },
tools: { access: ['service_action'], config: { tool: (p) => `service_${p.operation}`, params: (p) => ({ /* type coercions here */ }) } },
inputs: { /* ... */ },
outputs: { /* ... */ },
}
@@ -246,6 +246,8 @@ export const ServiceBlock: BlockConfig = {
Register in `blocks/registry.ts` (alphabetically).
**Important:** `tools.config.tool` runs during serialization (before variable resolution). Never do `Number()` or other type coercions there — dynamic references like `<Block.output>` will be destroyed. Use `tools.config.params` for type coercions (it runs during execution, after variables are resolved).
**SubBlock Properties:**
```typescript
{

View File

@@ -1157,6 +1157,17 @@ export function AirweaveIcon(props: SVGProps<SVGSVGElement>) {
)
}
export function AlgoliaIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg {...props} xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50'>
<path
fill='#FFFFFF'
d='M25,0C11.3,0,0.2,11,0,24.6C-0.2,38.4,11,49.9,24.8,50c4.3,0,8.4-1,12-3c0.4-0.2,0.4-0.7,0.1-1l-2.3-2.1 c-0.5-0.4-1.2-0.5-1.7-0.3c-2.5,1.1-5.3,1.6-8.2,1.6c-11.2-0.1-20.2-9.4-20-20.6C4.9,13.6,13.9,4.7,25,4.7h20.3v36L33.7,30.5 c-0.4-0.3-0.9-0.3-1.2,0.1c-1.8,2.4-4.9,4-8.2,3.7c-4.6-0.3-8.4-4-8.7-8.7c-0.4-5.5,4-10.2,9.4-10.2c4.9,0,9,3.8,9.4,8.6 c0,0.4,0.2,0.8,0.6,1.1l3,2.7c0.3,0.3,0.9,0.1,1-0.3c0.2-1.2,0.3-2.4,0.2-3.6c-0.5-7-6.2-12.7-13.2-13.1c-8.1-0.5-14.8,5.8-15,13.7 c-0.2,7.7,6.1,14.4,13.8,14.5c3.2,0.1,6.2-0.9,8.6-2.7l15,13.3c0.6,0.6,1.7,0.1,1.7-0.7v-48C50,0.4,49.5,0,49,0L25,0 C25,0,25,0,25,0z'
/>
</svg>
)
}
export function GoogleBooksIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg {...props} xmlns='http://www.w3.org/2000/svg' viewBox='0 0 478.633 540.068'>
@@ -5737,3 +5748,74 @@ export function CloudflareIcon(props: SVGProps<SVGSVGElement>) {
</svg>
)
}
export function UpstashIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg {...props} xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 341' width='24' height='24'>
<path
fill='#00C98D'
d='M0 298.417c56.554 56.553 148.247 56.553 204.801 0c56.554-56.554 56.554-148.247 0-204.801l-25.6 25.6c42.415 42.416 42.415 111.185 0 153.6c-42.416 42.416-111.185 42.416-153.601 0z'
/>
<path
fill='#00C98D'
d='M51.2 247.216c28.277 28.277 74.123 28.277 102.4 0c28.277-28.276 28.277-74.123 0-102.4l-25.6 25.6c14.14 14.138 14.14 37.061 0 51.2c-14.138 14.139-37.061 14.139-51.2 0zM256 42.415c-56.554-56.553-148.247-56.553-204.8 0c-56.555 56.555-56.555 148.247 0 204.801l25.599-25.6c-42.415-42.415-42.415-111.185 0-153.6c42.416-42.416 111.185-42.416 153.6 0z'
/>
<path
fill='#00C98D'
d='M204.8 93.616c-28.276-28.277-74.124-28.277-102.4 0c-28.278 28.277-28.278 74.123 0 102.4l25.6-25.6c-14.14-14.138-14.14-37.061 0-51.2c14.138-14.139 37.06-14.139 51.2 0z'
/>
<path
fill='#FFF'
fillOpacity='.4'
d='M256 42.415c-56.554-56.553-148.247-56.553-204.8 0c-56.555 56.555-56.555 148.247 0 204.801l25.599-25.6c-42.415-42.415-42.415-111.185 0-153.6c42.416-42.416 111.185-42.416 153.6 0z'
/>
<path
fill='#FFF'
fillOpacity='.4'
d='M204.8 93.616c-28.276-28.277-74.124-28.277-102.4 0c-28.278 28.277-28.278 74.123 0 102.4l25.6-25.6c-14.14-14.138-14.14-37.061 0-51.2c14.138-14.139 37.06-14.139 51.2 0z'
/>
</svg>
)
}
export function RevenueCatIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
{...props}
width='512'
height='512'
viewBox='0 0 512 512'
fill='none'
xmlns='http://www.w3.org/2000/svg'
>
<path
d='M95 109.774C110.152 106.108 133.612 104 154.795 104C212.046 104 246.32 123.928 246.32 174.646C246.32 205.746 233.737 226.264 214.005 237.437L261.765 318.946C258.05 321.632 250.035 323.176 238.864 323.176C226.282 323.176 217.987 321.672 211.982 318.946L172.225 248.3H167.645C157.789 248.305 147.945 247.601 138.18 246.192V319.255C134.172 321.672 127.022 323.176 116.73 323.176C106.73 323.176 99.2874 321.659 95 319.255V109.774ZM137.643 207.848C145.772 209.263 153.997 209.968 162.235 209.956C187.12 209.956 202.285 200.556 202.285 177.057C202.285 152.886 186.268 142.949 157.668 142.949C150.956 142.918 144.255 143.515 137.643 144.735V207.848Z'
fill='#FFFFFF'
/>
<path
d='M428.529 329.244C428.529 365.526 410.145 375.494 396.306 382.195C360.972 399.32 304.368 379.4 244.206 373.338C189.732 366.214 135.706 361.522 127.309 373.738C124.152 376.832 123.481 386.798 127.309 390.862C138.604 402.85 168.061 394.493 188.919 390.714C195.391 389.694 201.933 392.099 206.079 397.021C210.226 401.944 211.349 408.637 209.024 414.58C206.699 420.522 201.28 424.811 194.809 425.831C185.379 427.264 175.85 427.989 166.306 428C145.988 428 120.442 424.495 105.943 409.072C98.7232 401.4 91.3266 387.78 97.0271 366.465C107.875 326.074 172.807 336.052 248.033 343.633C300.41 348.907 357.23 366.465 379.934 350.343C385.721 346.234 396.517 337.022 390.698 329.244C384.879 321.467 375.353 325.684 362.838 325.684C300.152 325.684 263.238 285.302 263.238 217.916C263.247 167.292 284.176 131.892 318.287 115.09C333.109 107.789 350.421 104 369.587 104C386.292 104 403.269 106.931 414.11 113.366C420.847 123.032 423.778 140.305 422.306 153.201C408.247 146.466 395.36 142.949 378.669 142.949C337.365 142.949 308.947 164.039 308.947 214.985C308.947 265.932 337.065 286.149 376.611 286.149C387.869 286.035 403.1 284.67 422.306 282.053C426.455 297.498 428.529 313.228 428.529 329.244Z'
fill='#FFFFFF'
/>
</svg>
)
}
export function RedisIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
{...props}
viewBox='0 0 512 512'
xmlns='http://www.w3.org/2000/svg'
fillRule='evenodd'
clipRule='evenodd'
strokeLinejoin='round'
strokeMiterlimit='2'
>
<path
d='M479.14 279.864c-34.584 43.578-71.94 93.385-146.645 93.385-66.73 0-91.59-58.858-93.337-106.672 14.62 30.915 43.203 55.949 87.804 54.792C412.737 318.6 471.53 241.127 471.53 170.57c0-84.388-62.947-145.262-172.24-145.262-78.165 0-175.004 29.743-238.646 76.782-.689 48.42 26.286 111.369 35.972 104.452 55.17-39.67 98.918-65.203 141.35-78.01C175.153 198.58 24.451 361.219 6 389.85c2.076 26.286 34.588 96.842 50.496 96.842 4.841 0 8.993-2.768 13.835-7.61 45.433-51.046 82.472-96.816 115.412-140.933 4.627 64.658 36.42 143.702 125.307 143.702 79.55 0 158.408-57.414 194.377-186.767 4.149-15.911-15.22-28.362-26.286-15.22zm-90.616-104.449c0 40.81-40.118 60.87-76.782 60.87-19.596 0-34.648-5.145-46.554-11.832 21.906-33.168 43.59-67.182 66.887-103.593 41.08 6.953 56.449 29.788 56.449 54.555z'
fill='#FFFFFF'
fillRule='nonzero'
/>
</svg>
)
}

View File

@@ -8,6 +8,7 @@ import {
AhrefsIcon,
AirtableIcon,
AirweaveIcon,
AlgoliaIcon,
ApifyIcon,
ApolloIcon,
ArxivIcon,
@@ -98,8 +99,10 @@ import {
QdrantIcon,
RDSIcon,
RedditIcon,
RedisIcon,
ReductoIcon,
ResendIcon,
RevenueCatIcon,
S3Icon,
SalesforceIcon,
SearchIcon,
@@ -127,6 +130,7 @@ import {
TTSIcon,
TwilioIcon,
TypeformIcon,
UpstashIcon,
VercelIcon,
VideoIcon,
WealthboxIcon,
@@ -148,6 +152,7 @@ export const blockTypeToIconMap: Record<string, IconComponent> = {
ahrefs: AhrefsIcon,
airtable: AirtableIcon,
airweave: AirweaveIcon,
algolia: AlgoliaIcon,
apify: ApifyIcon,
apollo: ApolloIcon,
arxiv: ArxivIcon,
@@ -236,8 +241,10 @@ export const blockTypeToIconMap: Record<string, IconComponent> = {
qdrant: QdrantIcon,
rds: RDSIcon,
reddit: RedditIcon,
redis: RedisIcon,
reducto_v2: ReductoIcon,
resend: ResendIcon,
revenuecat: RevenueCatIcon,
s3: S3Icon,
salesforce: SalesforceIcon,
search: SearchIcon,
@@ -267,6 +274,7 @@ export const blockTypeToIconMap: Record<string, IconComponent> = {
twilio_sms: TwilioIcon,
twilio_voice: TwilioIcon,
typeform: TypeformIcon,
upstash: UpstashIcon,
vercel: VercelIcon,
video_generator_v2: VideoIcon,
vision_v2: EyeIcon,

View File

@@ -0,0 +1,404 @@
---
title: Algolia
description: Search and manage Algolia indices
---
import { BlockInfoCard } from "@/components/ui/block-info-card"
<BlockInfoCard
type="algolia"
color="#003DFF"
/>
{/* MANUAL-CONTENT-START:intro */}
[Algolia](https://www.algolia.com/) is a powerful hosted search platform that enables developers and teams to deliver fast, relevant search experiences in their apps and websites. Algolia provides full-text, faceted, and filtered search as well as analytics and advanced ranking capabilities.
With Algolia, you can:
- **Deliver lightning-fast search**: Provide instant search results as users type, with typo tolerance and synonyms
- **Manage and update records**: Easily add, update, or delete objects/records in your indices
- **Perform advanced filtering**: Use filters, facets, and custom ranking to refine and organize search results
- **Configure index settings**: Adjust relevance, ranking, attributes for search, and more to optimize user experience
- **Scale confidently**: Algolia handles massive traffic and data volumes with globally distributed infrastructure
- **Gain insights**: Track analytics, search patterns, and user engagement
In Sim, the Algolia integration allows your agents to search, manage, and configure Algolia indices directly within your workflows. Use Algolia to power dynamic data exploration, automate record updates, run batch operations, and more—all from a single tool in your workspace.
{/* MANUAL-CONTENT-END */}
## Usage Instructions
Integrate Algolia into your workflow. Search indices, manage records (add, update, delete, browse), configure index settings, and perform batch operations.
## Tools
### `algolia_search`
Search an Algolia index
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia API Key |
| `indexName` | string | Yes | Name of the Algolia index to search |
| `query` | string | Yes | Search query text |
| `hitsPerPage` | number | No | Number of hits per page \(default: 20\) |
| `page` | number | No | Page number to retrieve \(default: 0\) |
| `filters` | string | No | Filter string \(e.g., "category:electronics AND price &lt; 100"\) |
| `attributesToRetrieve` | string | No | Comma-separated list of attributes to retrieve |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `hits` | array | Array of matching records |
| ↳ `objectID` | string | Unique identifier of the record |
| ↳ `_highlightResult` | object | Highlighted attributes matching the query. Each attribute has value, matchLevel \(none, partial, full\), and matchedWords |
| ↳ `_snippetResult` | object | Snippeted attributes matching the query. Each attribute has value and matchLevel |
| ↳ `_rankingInfo` | object | Ranking information for the hit. Only present when getRankingInfo is enabled |
| ↳ `nbTypos` | number | Number of typos in the query match |
| ↳ `firstMatchedWord` | number | Position of the first matched word |
| ↳ `geoDistance` | number | Distance in meters for geo-search results |
| ↳ `nbExactWords` | number | Number of exactly matched words |
| ↳ `userScore` | number | Custom ranking score |
| ↳ `words` | number | Number of matched words |
| `nbHits` | number | Total number of matching hits |
| `page` | number | Current page number \(zero-based\) |
| `nbPages` | number | Total number of pages available |
| `hitsPerPage` | number | Number of hits per page \(1-1000, default 20\) |
| `processingTimeMS` | number | Server-side processing time in milliseconds |
| `query` | string | The search query that was executed |
| `parsedQuery` | string | The query string after normalization and stop word removal |
| `facets` | object | Facet counts keyed by facet name, each containing value-count pairs |
| `facets_stats` | object | Statistics \(min, max, avg, sum\) for numeric facets |
| `exhaustive` | object | Exhaustiveness flags for facetsCount, facetValues, nbHits, rulesMatch, and typo |
### `algolia_add_record`
Add or replace a record in an Algolia index
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia Admin API Key |
| `indexName` | string | Yes | Name of the Algolia index |
| `objectID` | string | No | Object ID for the record \(auto-generated if not provided\) |
| `record` | json | Yes | JSON object representing the record to add |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `taskID` | number | Algolia task ID for tracking the indexing operation |
| `objectID` | string | The object ID of the added or replaced record |
| `createdAt` | string | Timestamp when the record was created \(only present when objectID is auto-generated\) |
| `updatedAt` | string | Timestamp when the record was updated \(only present when replacing an existing record\) |
### `algolia_get_record`
Get a record by objectID from an Algolia index
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia API Key |
| `indexName` | string | Yes | Name of the Algolia index |
| `objectID` | string | Yes | The objectID of the record to retrieve |
| `attributesToRetrieve` | string | No | Comma-separated list of attributes to retrieve |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `objectID` | string | The objectID of the retrieved record |
| `record` | object | The record data \(all attributes\) |
### `algolia_get_records`
Retrieve multiple records by objectID from one or more Algolia indices
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia API Key |
| `indexName` | string | Yes | Default index name for all requests |
| `requests` | json | Yes | Array of objects specifying records to retrieve. Each must have "objectID" and optionally "indexName" and "attributesToRetrieve". |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `results` | array | Array of retrieved records \(null entries for records not found\) |
| ↳ `objectID` | string | Unique identifier of the record |
### `algolia_partial_update_record`
Partially update a record in an Algolia index without replacing it entirely
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia Admin API Key |
| `indexName` | string | Yes | Name of the Algolia index |
| `objectID` | string | Yes | The objectID of the record to update |
| `attributes` | json | Yes | JSON object with attributes to update. Supports built-in operations like \{"stock": \{"_operation": "Decrement", "value": 1\}\} |
| `createIfNotExists` | boolean | No | Whether to create the record if it does not exist \(default: true\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `taskID` | number | Algolia task ID for tracking the update operation |
| `objectID` | string | The objectID of the updated record |
| `updatedAt` | string | Timestamp when the record was updated |
### `algolia_delete_record`
Delete a record by objectID from an Algolia index
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia Admin API Key |
| `indexName` | string | Yes | Name of the Algolia index |
| `objectID` | string | Yes | The objectID of the record to delete |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `taskID` | number | Algolia task ID for tracking the deletion |
| `deletedAt` | string | Timestamp when the record was deleted |
### `algolia_browse_records`
Browse and iterate over all records in an Algolia index using cursor pagination
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia API Key \(must have browse ACL\) |
| `indexName` | string | Yes | Name of the Algolia index to browse |
| `query` | string | No | Search query to filter browsed records |
| `filters` | string | No | Filter string to narrow down results |
| `attributesToRetrieve` | string | No | Comma-separated list of attributes to retrieve |
| `hitsPerPage` | number | No | Number of hits per page \(default: 1000, max: 1000\) |
| `cursor` | string | No | Cursor from a previous browse response for pagination |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `hits` | array | Array of records from the index \(up to 1000 per request\) |
| ↳ `objectID` | string | Unique identifier of the record |
| `cursor` | string | Opaque cursor string for retrieving the next page of results. Absent when no more results exist. |
| `nbHits` | number | Total number of records matching the browse criteria |
| `page` | number | Current page number \(zero-based\) |
| `nbPages` | number | Total number of pages available |
| `hitsPerPage` | number | Number of hits per page \(1-1000, default 1000 for browse\) |
| `processingTimeMS` | number | Server-side processing time in milliseconds |
### `algolia_batch_operations`
Perform batch add, update, partial update, or delete operations on records in an Algolia index
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia Admin API Key |
| `indexName` | string | Yes | Name of the Algolia index |
| `requests` | json | Yes | Array of batch operations. Each item has "action" \(addObject, updateObject, partialUpdateObject, partialUpdateObjectNoCreate, deleteObject\) and "body" \(the record data, must include objectID for update/delete\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `taskID` | number | Algolia task ID for tracking the batch operation |
| `objectIDs` | array | Array of object IDs affected by the batch operation |
### `algolia_list_indices`
List all indices in an Algolia application
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia API Key |
| `page` | number | No | Page number for paginating indices \(default: not paginated\) |
| `hitsPerPage` | number | No | Number of indices per page \(default: 100\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `indices` | array | List of indices in the application |
| ↳ `name` | string | Name of the index |
| ↳ `entries` | number | Number of records in the index |
| ↳ `dataSize` | number | Size of the index data in bytes |
| ↳ `fileSize` | number | Size of the index files in bytes |
| ↳ `lastBuildTimeS` | number | Last build duration in seconds |
| ↳ `numberOfPendingTasks` | number | Number of pending indexing tasks |
| ↳ `pendingTask` | boolean | Whether the index has pending tasks |
| ↳ `createdAt` | string | Timestamp when the index was created |
| ↳ `updatedAt` | string | Timestamp when the index was last updated |
| ↳ `primary` | string | Name of the primary index \(if this is a replica\) |
| ↳ `replicas` | array | List of replica index names |
| ↳ `virtual` | boolean | Whether the index is a virtual replica |
| `nbPages` | number | Total number of pages of indices |
### `algolia_get_settings`
Retrieve the settings of an Algolia index
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia API Key |
| `indexName` | string | Yes | Name of the Algolia index |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `searchableAttributes` | array | List of searchable attributes |
| `attributesForFaceting` | array | Attributes used for faceting |
| `ranking` | array | Ranking criteria |
| `customRanking` | array | Custom ranking criteria |
| `replicas` | array | List of replica index names |
| `hitsPerPage` | number | Default number of hits per page |
| `maxValuesPerFacet` | number | Maximum number of facet values returned |
| `highlightPreTag` | string | HTML tag inserted before highlighted parts |
| `highlightPostTag` | string | HTML tag inserted after highlighted parts |
| `paginationLimitedTo` | number | Maximum number of hits accessible via pagination |
### `algolia_update_settings`
Update the settings of an Algolia index
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia Admin API Key \(must have editSettings ACL\) |
| `indexName` | string | Yes | Name of the Algolia index |
| `settings` | json | Yes | JSON object with settings to update \(e.g., \{"searchableAttributes": \["name", "description"\], "customRanking": \["desc\(popularity\)"\]\}\) |
| `forwardToReplicas` | boolean | No | Whether to apply changes to replica indices \(default: false\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `taskID` | number | Algolia task ID for tracking the settings update |
| `updatedAt` | string | Timestamp when the settings were updated |
### `algolia_delete_index`
Delete an entire Algolia index and all its records
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia Admin API Key \(must have deleteIndex ACL\) |
| `indexName` | string | Yes | Name of the Algolia index to delete |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `taskID` | number | Algolia task ID for tracking the index deletion |
| `deletedAt` | string | Timestamp when the index was deleted |
### `algolia_copy_move_index`
Copy or move an Algolia index to a new destination
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia Admin API Key |
| `indexName` | string | Yes | Name of the source index |
| `operation` | string | Yes | Operation to perform: "copy" or "move" |
| `destination` | string | Yes | Name of the destination index |
| `scope` | json | No | Array of scopes to copy \(only for "copy" operation\): \["settings", "synonyms", "rules"\]. Omit to copy everything including records. |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `taskID` | number | Algolia task ID for tracking the copy/move operation |
| `updatedAt` | string | Timestamp when the operation was performed |
### `algolia_clear_records`
Clear all records from an Algolia index while keeping settings, synonyms, and rules
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia Admin API Key \(must have deleteIndex ACL\) |
| `indexName` | string | Yes | Name of the Algolia index to clear |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `taskID` | number | Algolia task ID for tracking the clear operation |
| `updatedAt` | string | Timestamp when the records were cleared |
### `algolia_delete_by_filter`
Delete all records matching a filter from an Algolia index
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `applicationId` | string | Yes | Algolia Application ID |
| `apiKey` | string | Yes | Algolia Admin API Key \(must have deleteIndex ACL\) |
| `indexName` | string | Yes | Name of the Algolia index |
| `filters` | string | No | Filter expression to match records for deletion \(e.g., "category:outdated"\) |
| `facetFilters` | json | No | Array of facet filters \(e.g., \["brand:Acme"\]\) |
| `numericFilters` | json | No | Array of numeric filters \(e.g., \["price &gt; 100"\]\) |
| `tagFilters` | json | No | Array of tag filters using the _tags attribute \(e.g., \["published"\]\) |
| `aroundLatLng` | string | No | Coordinates for geo-search filter \(e.g., "40.71,-74.01"\) |
| `aroundRadius` | number | No | Maximum radius in meters for geo-search, or "all" for unlimited |
| `insideBoundingBox` | json | No | Bounding box coordinates as \[\[lat1, lng1, lat2, lng2\]\] for geo-search filter |
| `insidePolygon` | json | No | Polygon coordinates as \[\[lat1, lng1, lat2, lng2, lat3, lng3, ...\]\] for geo-search filter |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `taskID` | number | Algolia task ID for tracking the delete-by-filter operation |
| `updatedAt` | string | Timestamp when the operation was performed |

View File

@@ -5,6 +5,7 @@
"ahrefs",
"airtable",
"airweave",
"algolia",
"apify",
"apollo",
"arxiv",
@@ -93,8 +94,10 @@
"qdrant",
"rds",
"reddit",
"redis",
"reducto",
"resend",
"revenuecat",
"s3",
"salesforce",
"search",
@@ -125,6 +128,7 @@
"twilio_sms",
"twilio_voice",
"typeform",
"upstash",
"vercel",
"video_generator",
"vision",

View File

@@ -0,0 +1,452 @@
---
title: Redis
description: Key-value operations with Redis
---
import { BlockInfoCard } from "@/components/ui/block-info-card"
<BlockInfoCard
type="redis"
color="#FF4438"
/>
{/* MANUAL-CONTENT-START:intro */}
[Redis](https://redis.io/) is an open-source, in-memory data structure store, used as a distributed key-value database, cache, and message broker. Redis supports a variety of data structures including strings, hashes, lists, sets, and more, making it highly flexible for different application scenarios.
With Redis, you can:
- **Store and retrieve key-value data instantly**: Use Redis as a fast database, cache, or session store for high performance.
- **Work with multiple data structures**: Manage not just strings, but also lists, hashes, sets, sorted sets, streams, and bitmaps.
- **Perform atomic operations**: Safely manipulate data using atomic commands and transactions.
- **Support pub/sub messaging**: Use Rediss publisher/subscriber features for real-time event handling and messaging.
- **Set automatic expiration policies**: Assign TTLs to keys for caching and time-sensitive data.
- **Scale horizontally**: Use Redis Cluster for sharding, high availability, and scalable workloads.
In Sim, the Redis integration lets your agents connect to any Redis-compatible instance to perform key-value, hash, list, and utility operations. You can build workflows that involve storing, retrieving, or manipulating data in Redis, or manage your apps cache, sessions, or real-time messaging, directly within your Sim workspace.
{/* MANUAL-CONTENT-END */}
## Usage Instructions
Connect to any Redis instance to perform key-value, hash, list, and utility operations via a direct connection.
## Tools
### `redis_get`
Get the value of a key from Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The key to retrieve |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was retrieved |
| `value` | string | The value of the key, or null if the key does not exist |
### `redis_set`
Set the value of a key in Redis with an optional expiration time in seconds.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The key to set |
| `value` | string | Yes | The value to store |
| `ex` | number | No | Expiration time in seconds \(optional\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was set |
| `result` | string | The result of the SET operation \(typically "OK"\) |
### `redis_delete`
Delete a key from Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The key to delete |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was deleted |
| `deletedCount` | number | Number of keys deleted \(0 if key did not exist, 1 if deleted\) |
### `redis_keys`
List all keys matching a pattern in Redis. Avoid using on large databases in production; use the Redis Command tool with SCAN for large key spaces.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `pattern` | string | No | Pattern to match keys \(default: * for all keys\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `pattern` | string | The pattern used to match keys |
| `keys` | array | List of keys matching the pattern |
| `count` | number | Number of keys found |
### `redis_command`
Execute a raw Redis command as a JSON array (e.g. [
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `command` | string | Yes | Redis command as a JSON array \(e.g. \["SET", "key", "value"\]\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `command` | string | The command that was executed |
| `result` | json | The result of the command |
### `redis_hset`
Set a field in a hash stored at a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The hash key |
| `field` | string | Yes | The field name within the hash |
| `value` | string | Yes | The value to set for the field |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The hash key |
| `field` | string | The field that was set |
| `result` | number | Number of fields added \(1 if new, 0 if updated\) |
### `redis_hget`
Get the value of a field in a hash stored at a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The hash key |
| `field` | string | Yes | The field name to retrieve |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The hash key |
| `field` | string | The field that was retrieved |
| `value` | string | The field value, or null if the field or key does not exist |
### `redis_hgetall`
Get all fields and values of a hash stored at a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The hash key |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The hash key |
| `fields` | object | All field-value pairs in the hash as a key-value object. Empty object if the key does not exist. |
| `fieldCount` | number | Number of fields in the hash |
### `redis_hdel`
Delete a field from a hash stored at a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The hash key |
| `field` | string | Yes | The field name to delete |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The hash key |
| `field` | string | The field that was deleted |
| `deleted` | number | Number of fields removed \(1 if deleted, 0 if field did not exist\) |
### `redis_incr`
Increment the integer value of a key by one in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The key to increment |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was incremented |
| `value` | number | The new value after increment |
### `redis_incrby`
Increment the integer value of a key by a given amount in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The key to increment |
| `increment` | number | Yes | Amount to increment by \(negative to decrement\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was incremented |
| `value` | number | The new value after increment |
### `redis_expire`
Set an expiration time (in seconds) on a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The key to set expiration on |
| `seconds` | number | Yes | Timeout in seconds |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that expiration was set on |
| `result` | number | 1 if the timeout was set, 0 if the key does not exist |
### `redis_ttl`
Get the remaining time to live (in seconds) of a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The key to check TTL for |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was checked |
| `ttl` | number | Remaining TTL in seconds. Positive integer if TTL set, -1 if no expiration, -2 if key does not exist. |
### `redis_persist`
Remove the expiration from a key in Redis, making it persist indefinitely.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The key to persist |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was persisted |
| `result` | number | 1 if the expiration was removed, 0 if the key does not exist or has no expiration |
### `redis_lpush`
Prepend a value to a list stored at a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The list key |
| `value` | string | Yes | The value to prepend |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The list key |
| `length` | number | Length of the list after the push |
### `redis_rpush`
Append a value to the end of a list stored at a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The list key |
| `value` | string | Yes | The value to append |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The list key |
| `length` | number | Length of the list after the push |
### `redis_lpop`
Remove and return the first element of a list stored at a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The list key |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The list key |
| `value` | string | The removed element, or null if the list is empty |
### `redis_rpop`
Remove and return the last element of a list stored at a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The list key |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The list key |
| `value` | string | The removed element, or null if the list is empty |
### `redis_llen`
Get the length of a list stored at a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The list key |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The list key |
| `length` | number | The length of the list, or 0 if the key does not exist |
### `redis_lrange`
Get a range of elements from a list stored at a key in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The list key |
| `start` | number | Yes | Start index \(0-based\) |
| `stop` | number | Yes | Stop index \(-1 for all elements\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The list key |
| `values` | array | List elements in the specified range |
| `count` | number | Number of elements returned |
### `redis_exists`
Check if a key exists in Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The key to check |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was checked |
| `exists` | boolean | Whether the key exists \(true\) or not \(false\) |
### `redis_setnx`
Set the value of a key in Redis only if the key does not already exist.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | Yes | Redis connection URL \(e.g. redis://user:password@host:port\) |
| `key` | string | Yes | The key to set |
| `value` | string | Yes | The value to store |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was set |
| `wasSet` | boolean | Whether the key was set \(true\) or already existed \(false\) |

View File

@@ -0,0 +1,456 @@
---
title: RevenueCat
description: Manage in-app subscriptions and entitlements
---
import { BlockInfoCard } from "@/components/ui/block-info-card"
<BlockInfoCard
type="revenuecat"
color="#F25A5A"
/>
{/* MANUAL-CONTENT-START:intro */}
[RevenueCat](https://www.revenuecat.com/) is a subscription management platform that enables you to easily set up, manage, and analyze in-app subscriptions for your apps. With RevenueCat, you can handle the complexities of in-app purchases across platforms like iOS, Android, and web—all through a single unified API.
With RevenueCat, you can:
- **Manage subscribers**: Track user subscriptions, entitlements, and purchases across all platforms in real time
- **Simplify implementation**: Integrate RevenueCats SDKs to abstract away App Store and Play Store purchase logic
- **Automate entitlement logic**: Define and manage what features users should receive when they purchase or renew
- **Analyze revenue**: Access dashboards and analytics to view churn, LTV, revenue, active subscriptions, and more
- **Grant or revoke entitlements**: Manually adjust user access (for example, for customer support or promotions)
- **Operate globally**: Support purchases, refunds, and promotions worldwide with ease
In Sim, the RevenueCat integration allows your agents to fetch and manage subscriber data, review and update entitlements, and automate subscription-related workflows. Use RevenueCat to centralize subscription operations for your apps directly within your Sim workspace.
{/* MANUAL-CONTENT-END */}
## Usage Instructions
Integrate RevenueCat into the workflow. Manage subscribers, entitlements, offerings, and Google Play subscriptions. Retrieve customer subscription status, grant or revoke promotional entitlements, record purchases, update subscriber attributes, and manage Google Play subscription billing.
## Tools
### `revenuecat_get_customer`
Retrieve subscriber information by app user ID
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `apiKey` | string | Yes | RevenueCat secret API key \(sk_...\) |
| `appUserId` | string | Yes | The app user ID of the subscriber |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `subscriber` | object | The subscriber object with subscriptions and entitlements |
| ↳ `first_seen` | string | ISO 8601 date when subscriber was first seen |
| ↳ `original_app_user_id` | string | Original app user ID |
| ↳ `original_purchase_date` | string | ISO 8601 date of original purchase |
| ↳ `management_url` | string | URL for managing the subscriber subscriptions |
| ↳ `subscriptions` | object | Map of product identifiers to subscription objects |
| ↳ `store_transaction_id` | string | Store transaction identifier |
| ↳ `original_transaction_id` | string | Original transaction identifier |
| ↳ `purchase_date` | string | ISO 8601 purchase date |
| ↳ `original_purchase_date` | string | ISO 8601 date of the original purchase |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `is_sandbox` | boolean | Whether this is a sandbox purchase |
| ↳ `unsubscribe_detected_at` | string | ISO 8601 date when unsubscribe was detected |
| ↳ `billing_issues_detected_at` | string | ISO 8601 date when billing issues were detected |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `ownership_type` | string | Ownership type \(purchased, family_shared\) |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional, prepaid\) |
| ↳ `store` | string | Store the subscription was purchased from \(app_store, play_store, stripe, etc.\) |
| ↳ `refunded_at` | string | ISO 8601 date when subscription was refunded |
| ↳ `auto_resume_date` | string | ISO 8601 date when a paused subscription will auto-resume |
| ↳ `product_plan_identifier` | string | Google Play base plan identifier \(for products set up after Feb 2023\) |
| ↳ `entitlements` | object | Map of entitlement identifiers to entitlement objects |
| ↳ `grant_date` | string | ISO 8601 grant date |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `product_identifier` | string | Product identifier |
| ↳ `is_active` | boolean | Whether the entitlement is active |
| ↳ `will_renew` | boolean | Whether the entitlement will renew |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional\) |
| ↳ `purchase_date` | string | ISO 8601 date of the latest purchase or renewal |
| ↳ `store` | string | Store the entitlement was granted from |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `non_subscriptions` | object | Map of non-subscription product identifiers to arrays of purchase objects |
| `metadata` | object | Subscriber summary metadata |
| ↳ `app_user_id` | string | The app user ID |
| ↳ `first_seen` | string | ISO 8601 date when the subscriber was first seen |
| ↳ `active_entitlements` | number | Number of active entitlements |
| ↳ `active_subscriptions` | number | Number of active subscriptions |
### `revenuecat_delete_customer`
Permanently delete a subscriber and all associated data
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `apiKey` | string | Yes | RevenueCat secret API key \(sk_...\) |
| `appUserId` | string | Yes | The app user ID of the subscriber to delete |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `deleted` | boolean | Whether the subscriber was deleted |
| `app_user_id` | string | The deleted app user ID |
### `revenuecat_create_purchase`
Record a purchase (receipt) for a subscriber via the REST API
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `apiKey` | string | Yes | RevenueCat API key \(public or secret\) |
| `appUserId` | string | Yes | The app user ID of the subscriber |
| `fetchToken` | string | Yes | The receipt token or purchase token from the store \(App Store receipt, Google Play purchase token, or Stripe subscription ID\) |
| `productId` | string | Yes | The product identifier for the purchase |
| `price` | number | No | The price of the product in the currency specified |
| `currency` | string | No | ISO 4217 currency code \(e.g., USD, EUR\) |
| `isRestore` | boolean | No | Whether this is a restore of a previous purchase |
| `platform` | string | No | Platform of the purchase \(ios, android, amazon, macos, stripe\). Required for Stripe and Paddle purchases. |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `subscriber` | object | The updated subscriber object after recording the purchase |
| ↳ `first_seen` | string | ISO 8601 date when subscriber was first seen |
| ↳ `original_app_user_id` | string | Original app user ID |
| ↳ `original_purchase_date` | string | ISO 8601 date of original purchase |
| ↳ `management_url` | string | URL for managing the subscriber subscriptions |
| ↳ `subscriptions` | object | Map of product identifiers to subscription objects |
| ↳ `store_transaction_id` | string | Store transaction identifier |
| ↳ `original_transaction_id` | string | Original transaction identifier |
| ↳ `purchase_date` | string | ISO 8601 purchase date |
| ↳ `original_purchase_date` | string | ISO 8601 date of the original purchase |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `is_sandbox` | boolean | Whether this is a sandbox purchase |
| ↳ `unsubscribe_detected_at` | string | ISO 8601 date when unsubscribe was detected |
| ↳ `billing_issues_detected_at` | string | ISO 8601 date when billing issues were detected |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `ownership_type` | string | Ownership type \(purchased, family_shared\) |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional, prepaid\) |
| ↳ `store` | string | Store the subscription was purchased from \(app_store, play_store, stripe, etc.\) |
| ↳ `refunded_at` | string | ISO 8601 date when subscription was refunded |
| ↳ `auto_resume_date` | string | ISO 8601 date when a paused subscription will auto-resume |
| ↳ `product_plan_identifier` | string | Google Play base plan identifier \(for products set up after Feb 2023\) |
| ↳ `entitlements` | object | Map of entitlement identifiers to entitlement objects |
| ↳ `grant_date` | string | ISO 8601 grant date |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `product_identifier` | string | Product identifier |
| ↳ `is_active` | boolean | Whether the entitlement is active |
| ↳ `will_renew` | boolean | Whether the entitlement will renew |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional\) |
| ↳ `purchase_date` | string | ISO 8601 date of the latest purchase or renewal |
| ↳ `store` | string | Store the entitlement was granted from |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `non_subscriptions` | object | Map of non-subscription product identifiers to arrays of purchase objects |
### `revenuecat_grant_entitlement`
Grant a promotional entitlement to a subscriber
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `apiKey` | string | Yes | RevenueCat secret API key \(sk_...\) |
| `appUserId` | string | Yes | The app user ID of the subscriber |
| `entitlementIdentifier` | string | Yes | The entitlement identifier to grant |
| `duration` | string | Yes | Duration of the entitlement \(daily, three_day, weekly, monthly, two_month, three_month, six_month, yearly, lifetime\) |
| `startTimeMs` | number | No | Optional start time in milliseconds since Unix epoch. Set to a past time to achieve custom durations shorter than daily. |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `subscriber` | object | The updated subscriber object after granting the entitlement |
| ↳ `first_seen` | string | ISO 8601 date when subscriber was first seen |
| ↳ `original_app_user_id` | string | Original app user ID |
| ↳ `original_purchase_date` | string | ISO 8601 date of original purchase |
| ↳ `management_url` | string | URL for managing the subscriber subscriptions |
| ↳ `subscriptions` | object | Map of product identifiers to subscription objects |
| ↳ `store_transaction_id` | string | Store transaction identifier |
| ↳ `original_transaction_id` | string | Original transaction identifier |
| ↳ `purchase_date` | string | ISO 8601 purchase date |
| ↳ `original_purchase_date` | string | ISO 8601 date of the original purchase |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `is_sandbox` | boolean | Whether this is a sandbox purchase |
| ↳ `unsubscribe_detected_at` | string | ISO 8601 date when unsubscribe was detected |
| ↳ `billing_issues_detected_at` | string | ISO 8601 date when billing issues were detected |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `ownership_type` | string | Ownership type \(purchased, family_shared\) |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional, prepaid\) |
| ↳ `store` | string | Store the subscription was purchased from \(app_store, play_store, stripe, etc.\) |
| ↳ `refunded_at` | string | ISO 8601 date when subscription was refunded |
| ↳ `auto_resume_date` | string | ISO 8601 date when a paused subscription will auto-resume |
| ↳ `product_plan_identifier` | string | Google Play base plan identifier \(for products set up after Feb 2023\) |
| ↳ `entitlements` | object | Map of entitlement identifiers to entitlement objects |
| ↳ `grant_date` | string | ISO 8601 grant date |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `product_identifier` | string | Product identifier |
| ↳ `is_active` | boolean | Whether the entitlement is active |
| ↳ `will_renew` | boolean | Whether the entitlement will renew |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional\) |
| ↳ `purchase_date` | string | ISO 8601 date of the latest purchase or renewal |
| ↳ `store` | string | Store the entitlement was granted from |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `non_subscriptions` | object | Map of non-subscription product identifiers to arrays of purchase objects |
### `revenuecat_revoke_entitlement`
Revoke all promotional entitlements for a specific entitlement identifier
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `apiKey` | string | Yes | RevenueCat secret API key \(sk_...\) |
| `appUserId` | string | Yes | The app user ID of the subscriber |
| `entitlementIdentifier` | string | Yes | The entitlement identifier to revoke |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `subscriber` | object | The updated subscriber object after revoking the entitlement |
| ↳ `first_seen` | string | ISO 8601 date when subscriber was first seen |
| ↳ `original_app_user_id` | string | Original app user ID |
| ↳ `original_purchase_date` | string | ISO 8601 date of original purchase |
| ↳ `management_url` | string | URL for managing the subscriber subscriptions |
| ↳ `subscriptions` | object | Map of product identifiers to subscription objects |
| ↳ `store_transaction_id` | string | Store transaction identifier |
| ↳ `original_transaction_id` | string | Original transaction identifier |
| ↳ `purchase_date` | string | ISO 8601 purchase date |
| ↳ `original_purchase_date` | string | ISO 8601 date of the original purchase |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `is_sandbox` | boolean | Whether this is a sandbox purchase |
| ↳ `unsubscribe_detected_at` | string | ISO 8601 date when unsubscribe was detected |
| ↳ `billing_issues_detected_at` | string | ISO 8601 date when billing issues were detected |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `ownership_type` | string | Ownership type \(purchased, family_shared\) |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional, prepaid\) |
| ↳ `store` | string | Store the subscription was purchased from \(app_store, play_store, stripe, etc.\) |
| ↳ `refunded_at` | string | ISO 8601 date when subscription was refunded |
| ↳ `auto_resume_date` | string | ISO 8601 date when a paused subscription will auto-resume |
| ↳ `product_plan_identifier` | string | Google Play base plan identifier \(for products set up after Feb 2023\) |
| ↳ `entitlements` | object | Map of entitlement identifiers to entitlement objects |
| ↳ `grant_date` | string | ISO 8601 grant date |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `product_identifier` | string | Product identifier |
| ↳ `is_active` | boolean | Whether the entitlement is active |
| ↳ `will_renew` | boolean | Whether the entitlement will renew |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional\) |
| ↳ `purchase_date` | string | ISO 8601 date of the latest purchase or renewal |
| ↳ `store` | string | Store the entitlement was granted from |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `non_subscriptions` | object | Map of non-subscription product identifiers to arrays of purchase objects |
### `revenuecat_list_offerings`
List all offerings configured for the project
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `apiKey` | string | Yes | RevenueCat API key |
| `appUserId` | string | Yes | An app user ID to retrieve offerings for |
| `platform` | string | No | Platform to filter offerings \(ios, android, stripe, etc.\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `current_offering_id` | string | The identifier of the current offering |
| `offerings` | array | List of offerings |
| ↳ `identifier` | string | Offering identifier |
| ↳ `description` | string | Offering description |
| ↳ `packages` | array | List of packages in the offering |
| ↳ `identifier` | string | Package identifier |
| ↳ `platform_product_identifier` | string | Platform-specific product identifier |
| `metadata` | object | Offerings metadata |
| ↳ `count` | number | Number of offerings returned |
| ↳ `current_offering_id` | string | Current offering identifier |
### `revenuecat_update_subscriber_attributes`
Update custom subscriber attributes (e.g., $email, $displayName, or custom key-value pairs)
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `apiKey` | string | Yes | RevenueCat secret API key \(sk_...\) |
| `appUserId` | string | Yes | The app user ID of the subscriber |
| `attributes` | json | Yes | JSON object of attributes to set. Each key maps to an object with a "value" field. Example: \{"$email": \{"value": "user@example.com"\}, "$displayName": \{"value": "John"\}\} |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `updated` | boolean | Whether the subscriber attributes were successfully updated |
| `app_user_id` | string | The app user ID of the updated subscriber |
### `revenuecat_defer_google_subscription`
Defer a Google Play subscription by extending its billing date by a number of days (Google Play only)
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `apiKey` | string | Yes | RevenueCat secret API key \(sk_...\) |
| `appUserId` | string | Yes | The app user ID of the subscriber |
| `productId` | string | Yes | The Google Play product identifier of the subscription to defer \(use the part before the colon for products set up after Feb 2023\) |
| `extendByDays` | number | Yes | Number of days to extend the subscription by \(1-365\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `subscriber` | object | The updated subscriber object after deferring the Google subscription |
| ↳ `first_seen` | string | ISO 8601 date when subscriber was first seen |
| ↳ `original_app_user_id` | string | Original app user ID |
| ↳ `original_purchase_date` | string | ISO 8601 date of original purchase |
| ↳ `management_url` | string | URL for managing the subscriber subscriptions |
| ↳ `subscriptions` | object | Map of product identifiers to subscription objects |
| ↳ `store_transaction_id` | string | Store transaction identifier |
| ↳ `original_transaction_id` | string | Original transaction identifier |
| ↳ `purchase_date` | string | ISO 8601 purchase date |
| ↳ `original_purchase_date` | string | ISO 8601 date of the original purchase |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `is_sandbox` | boolean | Whether this is a sandbox purchase |
| ↳ `unsubscribe_detected_at` | string | ISO 8601 date when unsubscribe was detected |
| ↳ `billing_issues_detected_at` | string | ISO 8601 date when billing issues were detected |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `ownership_type` | string | Ownership type \(purchased, family_shared\) |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional, prepaid\) |
| ↳ `store` | string | Store the subscription was purchased from \(app_store, play_store, stripe, etc.\) |
| ↳ `refunded_at` | string | ISO 8601 date when subscription was refunded |
| ↳ `auto_resume_date` | string | ISO 8601 date when a paused subscription will auto-resume |
| ↳ `product_plan_identifier` | string | Google Play base plan identifier \(for products set up after Feb 2023\) |
| ↳ `entitlements` | object | Map of entitlement identifiers to entitlement objects |
| ↳ `grant_date` | string | ISO 8601 grant date |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `product_identifier` | string | Product identifier |
| ↳ `is_active` | boolean | Whether the entitlement is active |
| ↳ `will_renew` | boolean | Whether the entitlement will renew |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional\) |
| ↳ `purchase_date` | string | ISO 8601 date of the latest purchase or renewal |
| ↳ `store` | string | Store the entitlement was granted from |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `non_subscriptions` | object | Map of non-subscription product identifiers to arrays of purchase objects |
### `revenuecat_refund_google_subscription`
Refund and optionally revoke a Google Play subscription (Google Play only)
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `apiKey` | string | Yes | RevenueCat secret API key \(sk_...\) |
| `appUserId` | string | Yes | The app user ID of the subscriber |
| `productId` | string | Yes | The Google Play product identifier of the subscription to refund |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `subscriber` | object | The updated subscriber object after refunding the Google subscription |
| ↳ `first_seen` | string | ISO 8601 date when subscriber was first seen |
| ↳ `original_app_user_id` | string | Original app user ID |
| ↳ `original_purchase_date` | string | ISO 8601 date of original purchase |
| ↳ `management_url` | string | URL for managing the subscriber subscriptions |
| ↳ `subscriptions` | object | Map of product identifiers to subscription objects |
| ↳ `store_transaction_id` | string | Store transaction identifier |
| ↳ `original_transaction_id` | string | Original transaction identifier |
| ↳ `purchase_date` | string | ISO 8601 purchase date |
| ↳ `original_purchase_date` | string | ISO 8601 date of the original purchase |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `is_sandbox` | boolean | Whether this is a sandbox purchase |
| ↳ `unsubscribe_detected_at` | string | ISO 8601 date when unsubscribe was detected |
| ↳ `billing_issues_detected_at` | string | ISO 8601 date when billing issues were detected |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `ownership_type` | string | Ownership type \(purchased, family_shared\) |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional, prepaid\) |
| ↳ `store` | string | Store the subscription was purchased from \(app_store, play_store, stripe, etc.\) |
| ↳ `refunded_at` | string | ISO 8601 date when subscription was refunded |
| ↳ `auto_resume_date` | string | ISO 8601 date when a paused subscription will auto-resume |
| ↳ `product_plan_identifier` | string | Google Play base plan identifier \(for products set up after Feb 2023\) |
| ↳ `entitlements` | object | Map of entitlement identifiers to entitlement objects |
| ↳ `grant_date` | string | ISO 8601 grant date |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `product_identifier` | string | Product identifier |
| ↳ `is_active` | boolean | Whether the entitlement is active |
| ↳ `will_renew` | boolean | Whether the entitlement will renew |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional\) |
| ↳ `purchase_date` | string | ISO 8601 date of the latest purchase or renewal |
| ↳ `store` | string | Store the entitlement was granted from |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `non_subscriptions` | object | Map of non-subscription product identifiers to arrays of purchase objects |
### `revenuecat_revoke_google_subscription`
Immediately revoke access to a Google Play subscription and issue a refund (Google Play only)
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `apiKey` | string | Yes | RevenueCat secret API key \(sk_...\) |
| `appUserId` | string | Yes | The app user ID of the subscriber |
| `productId` | string | Yes | The Google Play product identifier of the subscription to revoke |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `subscriber` | object | The updated subscriber object after revoking the Google subscription |
| ↳ `first_seen` | string | ISO 8601 date when subscriber was first seen |
| ↳ `original_app_user_id` | string | Original app user ID |
| ↳ `original_purchase_date` | string | ISO 8601 date of original purchase |
| ↳ `management_url` | string | URL for managing the subscriber subscriptions |
| ↳ `subscriptions` | object | Map of product identifiers to subscription objects |
| ↳ `store_transaction_id` | string | Store transaction identifier |
| ↳ `original_transaction_id` | string | Original transaction identifier |
| ↳ `purchase_date` | string | ISO 8601 purchase date |
| ↳ `original_purchase_date` | string | ISO 8601 date of the original purchase |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `is_sandbox` | boolean | Whether this is a sandbox purchase |
| ↳ `unsubscribe_detected_at` | string | ISO 8601 date when unsubscribe was detected |
| ↳ `billing_issues_detected_at` | string | ISO 8601 date when billing issues were detected |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `ownership_type` | string | Ownership type \(purchased, family_shared\) |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional, prepaid\) |
| ↳ `store` | string | Store the subscription was purchased from \(app_store, play_store, stripe, etc.\) |
| ↳ `refunded_at` | string | ISO 8601 date when subscription was refunded |
| ↳ `auto_resume_date` | string | ISO 8601 date when a paused subscription will auto-resume |
| ↳ `product_plan_identifier` | string | Google Play base plan identifier \(for products set up after Feb 2023\) |
| ↳ `entitlements` | object | Map of entitlement identifiers to entitlement objects |
| ↳ `grant_date` | string | ISO 8601 grant date |
| ↳ `expires_date` | string | ISO 8601 expiration date |
| ↳ `product_identifier` | string | Product identifier |
| ↳ `is_active` | boolean | Whether the entitlement is active |
| ↳ `will_renew` | boolean | Whether the entitlement will renew |
| ↳ `period_type` | string | Period type \(normal, trial, intro, promotional\) |
| ↳ `purchase_date` | string | ISO 8601 date of the latest purchase or renewal |
| ↳ `store` | string | Store the entitlement was granted from |
| ↳ `grace_period_expires_date` | string | ISO 8601 grace period expiration date |
| ↳ `non_subscriptions` | object | Map of non-subscription product identifiers to arrays of purchase objects |

View File

@@ -0,0 +1,357 @@
---
title: Upstash
description: Serverless Redis with Upstash
---
import { BlockInfoCard } from "@/components/ui/block-info-card"
<BlockInfoCard
type="upstash"
color="#181C1E"
/>
{/* MANUAL-CONTENT-START:intro */}
[Upstash](https://upstash.com/) is a serverless data platform designed for modern applications that need fast, simple, and scalable data storage with minimal setup. Upstash specializes in providing Redis and Kafka as fully managed, pay-per-request cloud services, making it a popular choice for developers building serverless, edge, and event-driven architectures.
With Upstash Redis, you can:
- **Store and retrieve data instantly**: Read and write key-value pairs, hashes, lists, sets, and more—all over a high-performance REST API.
- **Scale serverlessly**: No infrastructure to manage. Upstash automatically scales with your app and charges only for what you use.
- **Access globally**: Deploy near your users with multi-region support and global distribution.
- **Integrate easily**: Use Upstashs REST API in serverless functions, edge workers, Next.js, Vercel, Cloudflare Workers, and more.
- **Automate with scripts**: Run Lua scripts for advanced transactions and automation.
- **Ensure security**: Protect your data with built-in authentication and TLS encryption.
In Sim, the Upstash integration empowers your agents and workflows to read, write, and manage data in Upstash Redis using simple, unified commands—perfect for building scalable automations, caching results, managing queues, and more, all without dealing with server management.
{/* MANUAL-CONTENT-END */}
## Usage Instructions
Connect to Upstash Redis to perform key-value, hash, list, and utility operations via the REST API.
## Tools
### `upstash_redis_get`
Get the value of a key from Upstash Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The key to retrieve |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was retrieved |
| `value` | json | The value of the key \(string\), or null if not found |
### `upstash_redis_set`
Set the value of a key in Upstash Redis with an optional expiration time in seconds.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The key to set |
| `value` | string | Yes | The value to store |
| `ex` | number | No | Expiration time in seconds \(optional\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was set |
| `result` | string | The result of the SET operation \(typically "OK"\) |
### `upstash_redis_delete`
Delete a key from Upstash Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The key to delete |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was deleted |
| `deletedCount` | number | Number of keys deleted \(0 if key did not exist, 1 if deleted\) |
### `upstash_redis_keys`
List keys matching a pattern in Upstash Redis. Defaults to listing all keys (*).
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `pattern` | string | No | Pattern to match keys \(e.g., "user:*"\). Defaults to "*" for all keys. |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `pattern` | string | The pattern used to match keys |
| `keys` | array | List of keys matching the pattern |
| `count` | number | Number of keys found |
### `upstash_redis_command`
Execute an arbitrary Redis command against Upstash Redis. Pass the full command as a JSON array (e.g., [
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `command` | string | Yes | Redis command as a JSON array \(e.g., \["HSET", "myhash", "field1", "value1"\]\) or a simple command string \(e.g., "PING"\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `command` | string | The command that was executed |
| `result` | json | The result of the Redis command |
### `upstash_redis_hset`
Set a field in a hash stored at a key in Upstash Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The hash key |
| `field` | string | Yes | The field name within the hash |
| `value` | string | Yes | The value to store in the hash field |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The hash key |
| `field` | string | The field that was set |
| `result` | number | Number of new fields added \(0 if field was updated, 1 if new\) |
### `upstash_redis_hget`
Get the value of a field in a hash stored at a key in Upstash Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The hash key |
| `field` | string | Yes | The field name to retrieve |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The hash key |
| `field` | string | The field that was retrieved |
| `value` | json | The value of the hash field \(string\), or null if not found |
### `upstash_redis_hgetall`
Get all fields and values of a hash stored at a key in Upstash Redis.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The hash key |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The hash key |
| `fields` | object | All field-value pairs in the hash, keyed by field name |
| `fieldCount` | number | Number of fields in the hash |
### `upstash_redis_incr`
Atomically increment the integer value of a key by one in Upstash Redis. If the key does not exist, it is set to 0 before incrementing.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The key to increment |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was incremented |
| `value` | number | The new value after incrementing |
### `upstash_redis_expire`
Set a timeout on a key in Upstash Redis. After the timeout, the key is deleted.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The key to set expiration on |
| `seconds` | number | Yes | Timeout in seconds |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that expiration was set on |
| `result` | number | 1 if the timeout was set, 0 if the key does not exist |
### `upstash_redis_ttl`
Get the remaining time to live of a key in Upstash Redis. Returns -1 if the key has no expiration, -2 if the key does not exist.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The key to check TTL for |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key checked |
| `ttl` | number | Remaining TTL in seconds. Positive integer if the key has a TTL set, -1 if the key exists with no expiration, -2 if the key does not exist. |
### `upstash_redis_lpush`
Prepend a value to the beginning of a list in Upstash Redis. Creates the list if it does not exist.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The list key |
| `value` | string | Yes | The value to prepend to the list |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The list key |
| `length` | number | The length of the list after the push |
### `upstash_redis_lrange`
Get a range of elements from a list in Upstash Redis. Use 0 and -1 for start and stop to get all elements.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The list key |
| `start` | number | Yes | Start index \(0-based, negative values count from end\) |
| `stop` | number | Yes | Stop index \(inclusive, -1 for last element\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The list key |
| `values` | array | List of elements in the specified range |
| `count` | number | Number of elements returned |
### `upstash_redis_exists`
Check if a key exists in Upstash Redis. Returns true if the key exists, false otherwise.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The key to check |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was checked |
| `exists` | boolean | Whether the key exists \(true\) or not \(false\) |
### `upstash_redis_setnx`
Set the value of a key only if it does not already exist. Returns true if the key was set, false if it already existed.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The key to set |
| `value` | string | Yes | The value to store if the key does not exist |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was attempted to set |
| `wasSet` | boolean | Whether the key was set \(true\) or already existed \(false\) |
### `upstash_redis_incrby`
Increment the integer value of a key by a given amount. Use a negative value to decrement. If the key does not exist, it is set to 0 before the operation.
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `restUrl` | string | Yes | Upstash Redis REST URL |
| `restToken` | string | Yes | Upstash Redis REST Token |
| `key` | string | Yes | The key to increment |
| `increment` | number | Yes | Amount to increment by \(use negative value to decrement\) |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `key` | string | The key that was incremented |
| `value` | number | The new value after incrementing |

View File

@@ -3,7 +3,7 @@
*
* @vitest-environment node
*/
import { createMockLogger, createMockRequest } from '@sim/testing'
import { createMockLogger, createMockRequest, mockHybridAuth } from '@sim/testing'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
describe('OAuth Token API Routes', () => {
@@ -12,7 +12,7 @@ describe('OAuth Token API Routes', () => {
const mockRefreshTokenIfNeeded = vi.fn()
const mockGetOAuthToken = vi.fn()
const mockAuthorizeCredentialUse = vi.fn()
const mockCheckSessionOrInternalAuth = vi.fn()
let mockCheckSessionOrInternalAuth: ReturnType<typeof vi.fn>
const mockLogger = createMockLogger()
@@ -41,9 +41,7 @@ describe('OAuth Token API Routes', () => {
authorizeCredentialUse: mockAuthorizeCredentialUse,
}))
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: mockCheckSessionOrInternalAuth,
}))
;({ mockCheckSessionOrInternalAuth } = mockHybridAuth())
})
afterEach(() => {
@@ -73,23 +71,18 @@ describe('OAuth Token API Routes', () => {
refreshed: false,
})
// Create mock request
const req = createMockRequest('POST', {
credentialId: 'credential-id',
})
// Import handler after setting up mocks
const { POST } = await import('@/app/api/auth/oauth/token/route')
// Call handler
const response = await POST(req)
const data = await response.json()
// Verify request was handled correctly
expect(response.status).toBe(200)
expect(data).toHaveProperty('accessToken', 'fresh-token')
// Verify mocks were called correctly
expect(mockAuthorizeCredentialUse).toHaveBeenCalled()
expect(mockGetCredential).toHaveBeenCalled()
expect(mockRefreshTokenIfNeeded).toHaveBeenCalled()

View File

@@ -3,7 +3,7 @@
*
* @vitest-environment node
*/
import { loggerMock } from '@sim/testing'
import { loggerMock, requestUtilsMock } from '@sim/testing'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
/**
@@ -94,9 +94,7 @@ vi.mock('@/lib/core/utils/sse', () => ({
},
}))
vi.mock('@/lib/core/utils/request', () => ({
generateRequestId: vi.fn().mockReturnValue('test-request-id'),
}))
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
vi.mock('@/lib/core/security/encryption', () => ({
decryptSecret: vi.fn().mockResolvedValue({ decrypted: 'test-password' }),

View File

@@ -1,4 +1,4 @@
import { databaseMock, loggerMock } from '@sim/testing'
import { databaseMock, loggerMock, requestUtilsMock } from '@sim/testing'
import type { NextResponse } from 'next/server'
/**
* Tests for chat API utils
@@ -37,9 +37,7 @@ vi.mock('@/lib/core/security/encryption', () => ({
decryptSecret: mockDecryptSecret,
}))
vi.mock('@/lib/core/utils/request', () => ({
generateRequestId: vi.fn(),
}))
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
vi.mock('@/lib/core/config/feature-flags', () => ({
isDev: true,

View File

@@ -2,6 +2,7 @@ import {
createMockRequest,
mockAuth,
mockCryptoUuid,
mockHybridAuth,
mockUuid,
setupCommonApiMocks,
} from '@sim/testing'
@@ -28,13 +29,12 @@ function setupFileApiMocks(
authMocks.setUnauthenticated()
}
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: authenticated,
userId: authenticated ? 'test-user-id' : undefined,
error: authenticated ? undefined : 'Unauthorized',
}),
}))
const { mockCheckSessionOrInternalAuth } = mockHybridAuth()
mockCheckSessionOrInternalAuth.mockResolvedValue({
success: authenticated,
userId: authenticated ? 'test-user-id' : undefined,
error: authenticated ? undefined : 'Unauthorized',
})
vi.doMock('@/app/api/files/authorization', () => ({
verifyFileAccess: vi.fn().mockResolvedValue(true),

View File

@@ -8,6 +8,7 @@ import {
createMockRequest,
mockAuth,
mockCryptoUuid,
mockHybridAuth,
mockUuid,
setupCommonApiMocks,
} from '@sim/testing'
@@ -34,13 +35,12 @@ function setupFileApiMocks(
authMocks.setUnauthenticated()
}
vi.doMock('@/lib/auth/hybrid', () => ({
checkInternalAuth: vi.fn().mockResolvedValue({
success: authenticated,
userId: authenticated ? 'test-user-id' : undefined,
error: authenticated ? undefined : 'Unauthorized',
}),
}))
const { mockCheckInternalAuth } = mockHybridAuth()
mockCheckInternalAuth.mockResolvedValue({
success: authenticated,
userId: authenticated ? 'test-user-id' : undefined,
error: authenticated ? undefined : 'Unauthorized',
})
vi.doMock('@/app/api/files/authorization', () => ({
verifyFileAccess: vi.fn().mockResolvedValue(true),

View File

@@ -1,4 +1,10 @@
import { mockAuth, mockCryptoUuid, mockUuid, setupCommonApiMocks } from '@sim/testing'
import {
mockAuth,
mockCryptoUuid,
mockHybridAuth,
mockUuid,
setupCommonApiMocks,
} from '@sim/testing'
import { NextRequest } from 'next/server'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -28,13 +34,12 @@ function setupFileApiMocks(
authMocks.setUnauthenticated()
}
vi.doMock('@/lib/auth/hybrid', () => ({
checkHybridAuth: vi.fn().mockResolvedValue({
success: authenticated,
userId: authenticated ? 'test-user-id' : undefined,
error: authenticated ? undefined : 'Unauthorized',
}),
}))
const { mockCheckHybridAuth } = mockHybridAuth()
mockCheckHybridAuth.mockResolvedValue({
success: authenticated,
userId: authenticated ? 'test-user-id' : undefined,
error: authenticated ? undefined : 'Unauthorized',
})
vi.doMock('@/app/api/files/authorization', () => ({
verifyFileAccess: vi.fn().mockResolvedValue(true),

View File

@@ -7,6 +7,7 @@ import {
defaultMockUser,
mockAuth,
mockCryptoUuid,
mockHybridAuth,
mockUuid,
setupCommonApiMocks,
} from '@sim/testing'
@@ -54,12 +55,11 @@ describe('File Serve API Route', () => {
withUploadUtils: true,
})
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: true,
userId: 'test-user-id',
}),
}))
const { mockCheckSessionOrInternalAuth: serveAuthMock } = mockHybridAuth()
serveAuthMock.mockResolvedValue({
success: true,
userId: 'test-user-id',
})
vi.doMock('@/app/api/files/authorization', () => ({
verifyFileAccess: vi.fn().mockResolvedValue(true),
@@ -164,12 +164,11 @@ describe('File Serve API Route', () => {
findLocalFile: vi.fn().mockReturnValue('/test/uploads/nested/path/file.txt'),
}))
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: true,
userId: 'test-user-id',
}),
}))
const { mockCheckSessionOrInternalAuth: serveAuthMock } = mockHybridAuth()
serveAuthMock.mockResolvedValue({
success: true,
userId: 'test-user-id',
})
vi.doMock('@/app/api/files/authorization', () => ({
verifyFileAccess: vi.fn().mockResolvedValue(true),
@@ -225,12 +224,11 @@ describe('File Serve API Route', () => {
USE_BLOB_STORAGE: false,
}))
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: true,
userId: 'test-user-id',
}),
}))
const { mockCheckSessionOrInternalAuth: serveAuthMock } = mockHybridAuth()
serveAuthMock.mockResolvedValue({
success: true,
userId: 'test-user-id',
})
vi.doMock('@/app/api/files/authorization', () => ({
verifyFileAccess: vi.fn().mockResolvedValue(true),
@@ -290,12 +288,11 @@ describe('File Serve API Route', () => {
readFile: vi.fn().mockRejectedValue(new Error('ENOENT: no such file or directory')),
}))
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: true,
userId: 'test-user-id',
}),
}))
const { mockCheckSessionOrInternalAuth: serveAuthMock } = mockHybridAuth()
serveAuthMock.mockResolvedValue({
success: true,
userId: 'test-user-id',
})
vi.doMock('@/app/api/files/authorization', () => ({
verifyFileAccess: vi.fn().mockResolvedValue(false), // File not found = no access
@@ -349,12 +346,11 @@ describe('File Serve API Route', () => {
for (const test of contentTypeTests) {
it(`should serve ${test.ext} file with correct content type`, async () => {
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: true,
userId: 'test-user-id',
}),
}))
const { mockCheckSessionOrInternalAuth: ctAuthMock } = mockHybridAuth()
ctAuthMock.mockResolvedValue({
success: true,
userId: 'test-user-id',
})
vi.doMock('@/app/api/files/authorization', () => ({
verifyFileAccess: vi.fn().mockResolvedValue(true),

View File

@@ -3,7 +3,13 @@
*
* @vitest-environment node
*/
import { mockAuth, mockCryptoUuid, mockUuid, setupCommonApiMocks } from '@sim/testing'
import {
mockAuth,
mockCryptoUuid,
mockHybridAuth,
mockUuid,
setupCommonApiMocks,
} from '@sim/testing'
import { NextRequest } from 'next/server'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -27,13 +33,12 @@ function setupFileApiMocks(
authMocks.setUnauthenticated()
}
vi.doMock('@/lib/auth/hybrid', () => ({
checkHybridAuth: vi.fn().mockResolvedValue({
success: authenticated,
userId: authenticated ? 'test-user-id' : undefined,
error: authenticated ? undefined : 'Unauthorized',
}),
}))
const { mockCheckHybridAuth } = mockHybridAuth()
mockCheckHybridAuth.mockResolvedValue({
success: authenticated,
userId: authenticated ? 'test-user-id' : undefined,
error: authenticated ? undefined : 'Unauthorized',
})
vi.doMock('@/app/api/files/authorization', () => ({
verifyFileAccess: vi.fn().mockResolvedValue(true),

View File

@@ -10,6 +10,7 @@ import {
createMockRequest,
mockConsoleLogger,
mockKnowledgeSchemas,
requestUtilsMock,
} from '@sim/testing'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -29,9 +30,7 @@ mockKnowledgeSchemas()
vi.mock('@/lib/core/config/env', () => createEnvMock({ OPENAI_API_KEY: 'test-api-key' }))
vi.mock('@/lib/core/utils/request', () => ({
generateRequestId: vi.fn(() => 'test-request-id'),
}))
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
vi.mock('@/lib/documents/utils', () => ({
retryWithExponentialBackoff: vi.fn().mockImplementation((fn) => fn()),

View File

@@ -3,10 +3,11 @@
*
* @vitest-environment node
*/
import { mockHybridAuth } from '@sim/testing'
import { NextRequest } from 'next/server'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const mockCheckHybridAuth = vi.fn()
let mockCheckHybridAuth: ReturnType<typeof vi.fn>
const mockGetUserEntityPermissions = vi.fn()
const mockGenerateInternalToken = vi.fn()
const mockDbSelect = vi.fn()
@@ -61,9 +62,7 @@ describe('MCP Serve Route', () => {
isDeployed: 'isDeployed',
},
}))
vi.doMock('@/lib/auth/hybrid', () => ({
checkHybridAuth: mockCheckHybridAuth,
}))
;({ mockCheckHybridAuth } = mockHybridAuth())
vi.doMock('@/lib/workspaces/permissions/utils', () => ({
getUserEntityPermissions: mockGetUserEntityPermissions,
}))

View File

@@ -19,6 +19,7 @@ const configSchema = z.object({
allowedModelProviders: z.array(z.string()).nullable().optional(),
hideTraceSpans: z.boolean().optional(),
hideKnowledgeBaseTab: z.boolean().optional(),
hideTablesTab: z.boolean().optional(),
hideCopilot: z.boolean().optional(),
hideApiKeysTab: z.boolean().optional(),
hideEnvironmentTab: z.boolean().optional(),

View File

@@ -20,6 +20,7 @@ const configSchema = z.object({
allowedModelProviders: z.array(z.string()).nullable().optional(),
hideTraceSpans: z.boolean().optional(),
hideKnowledgeBaseTab: z.boolean().optional(),
hideTablesTab: z.boolean().optional(),
hideCopilot: z.boolean().optional(),
hideApiKeysTab: z.boolean().optional(),
hideEnvironmentTab: z.boolean().optional(),

View File

@@ -3,7 +3,7 @@
*
* @vitest-environment node
*/
import { auditMock, databaseMock, loggerMock } from '@sim/testing'
import { auditMock, databaseMock, loggerMock, requestUtilsMock } from '@sim/testing'
import { NextRequest } from 'next/server'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -31,9 +31,7 @@ vi.mock('drizzle-orm', () => ({
eq: vi.fn(),
}))
vi.mock('@/lib/core/utils/request', () => ({
generateRequestId: () => 'test-request-id',
}))
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
vi.mock('@sim/logger', () => loggerMock)

View File

@@ -3,7 +3,7 @@
*
* @vitest-environment node
*/
import { databaseMock, loggerMock } from '@sim/testing'
import { databaseMock, loggerMock, requestUtilsMock } from '@sim/testing'
import { NextRequest } from 'next/server'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -43,9 +43,7 @@ vi.mock('drizzle-orm', () => ({
isNull: vi.fn(),
}))
vi.mock('@/lib/core/utils/request', () => ({
generateRequestId: () => 'test-request-id',
}))
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
vi.mock('@sim/logger', () => loggerMock)

View File

@@ -3,7 +3,7 @@
*
* @vitest-environment node
*/
import { createMockRequest, loggerMock } from '@sim/testing'
import { createMockRequest, loggerMock, mockHybridAuth } from '@sim/testing'
import { NextRequest } from 'next/server'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -180,13 +180,12 @@ describe('Custom Tools API Routes', () => {
getSession: vi.fn().mockResolvedValue(mockSession),
}))
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: true,
userId: 'user-123',
authType: 'session',
}),
}))
const { mockCheckSessionOrInternalAuth: hybridAuthMock } = mockHybridAuth()
hybridAuthMock.mockResolvedValue({
success: true,
userId: 'user-123',
authType: 'session',
})
vi.doMock('@/lib/workspaces/permissions/utils', () => ({
getUserEntityPermissions: vi.fn().mockResolvedValue('admin'),
@@ -261,12 +260,11 @@ describe('Custom Tools API Routes', () => {
'http://localhost:3000/api/tools/custom?workspaceId=workspace-123'
)
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: false,
error: 'Unauthorized',
}),
}))
const { mockCheckSessionOrInternalAuth: unauthMock } = mockHybridAuth()
unauthMock.mockResolvedValue({
success: false,
error: 'Unauthorized',
})
const { GET } = await import('@/app/api/tools/custom/route')
@@ -297,12 +295,11 @@ describe('Custom Tools API Routes', () => {
*/
describe('POST /api/tools/custom', () => {
it('should reject unauthorized requests', async () => {
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: false,
error: 'Unauthorized',
}),
}))
const { mockCheckSessionOrInternalAuth: unauthMock } = mockHybridAuth()
unauthMock.mockResolvedValue({
success: false,
error: 'Unauthorized',
})
const req = createMockRequest('POST', { tools: [], workspaceId: 'workspace-123' })
@@ -384,13 +381,12 @@ describe('Custom Tools API Routes', () => {
})
it('should prevent unauthorized deletion of user-scoped tool', async () => {
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: true,
userId: 'user-456',
authType: 'session',
}),
}))
const { mockCheckSessionOrInternalAuth: diffUserMock } = mockHybridAuth()
diffUserMock.mockResolvedValue({
success: true,
userId: 'user-456',
authType: 'session',
})
const userScopedTool = { ...sampleTools[0], workspaceId: null, userId: 'user-123' }
const mockLimitUserScoped = vi.fn().mockResolvedValue([userScopedTool])
@@ -408,12 +404,11 @@ describe('Custom Tools API Routes', () => {
})
it('should reject unauthorized requests', async () => {
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
success: false,
error: 'Unauthorized',
}),
}))
const { mockCheckSessionOrInternalAuth: unauthMock } = mockHybridAuth()
unauthMock.mockResolvedValue({
success: false,
error: 'Unauthorized',
})
const req = new NextRequest('http://localhost:3000/api/tools/custom?id=tool-1')

View File

@@ -0,0 +1,57 @@
import { createLogger } from '@sim/logger'
import Redis from 'ioredis'
import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { checkInternalAuth } from '@/lib/auth/hybrid'
const logger = createLogger('RedisAPI')
const RequestSchema = z.object({
url: z.string().min(1, 'Redis connection URL is required'),
command: z.string().min(1, 'Redis command is required'),
args: z.array(z.union([z.string(), z.number()])).default([]),
})
export async function POST(request: NextRequest) {
let client: Redis | null = null
try {
const auth = await checkInternalAuth(request)
if (!auth.success || !auth.userId) {
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
}
const body = await request.json()
const { url, command, args } = RequestSchema.parse(body)
client = new Redis(url, {
connectTimeout: 10000,
commandTimeout: 10000,
maxRetriesPerRequest: 1,
lazyConnect: true,
})
await client.connect()
const cmd = command.toUpperCase()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result = await (client as any).call(cmd, ...args)
await client.quit()
client = null
return NextResponse.json({ result })
} catch (error) {
logger.error('Redis command failed', { error })
const errorMessage = error instanceof Error ? error.message : 'Redis command failed'
return NextResponse.json({ error: errorMessage }, { status: 500 })
} finally {
if (client) {
try {
await client.quit()
} catch {
client.disconnect()
}
}
}
}

View File

@@ -766,7 +766,7 @@ async function transcribeWithGemini(
const error = await response.json()
if (response.status === 404) {
throw new Error(
`Model not found: ${modelName}. Use gemini-3-pro-preview, gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, or gemini-2.0-flash-exp`
`Model not found: ${modelName}. Use gemini-3.1-pro-preview, gemini-3-pro-preview, gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, or gemini-2.0-flash-exp`
)
}
const errorMessage = error.error?.message || JSON.stringify(error)

View File

@@ -3,7 +3,7 @@
*
* @vitest-environment node
*/
import { createMockRequest, loggerMock } from '@sim/testing'
import { createMockRequest, loggerMock, requestUtilsMock } from '@sim/testing'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
/** Mock execution dependencies for webhook tests */
@@ -348,9 +348,7 @@ vi.mock('postgres', () => vi.fn().mockReturnValue({}))
vi.mock('@sim/logger', () => loggerMock)
vi.mock('@/lib/core/utils/request', () => ({
generateRequestId: vi.fn().mockReturnValue('test-request-id'),
}))
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
process.env.DATABASE_URL = 'postgresql://test:test@localhost:5432/test'

View File

@@ -3,11 +3,11 @@
*
* @vitest-environment node
*/
import { loggerMock } from '@sim/testing'
import { loggerMock, mockHybridAuth } from '@sim/testing'
import { NextRequest } from 'next/server'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const mockCheckSessionOrInternalAuth = vi.fn()
let mockCheckSessionOrInternalAuth: ReturnType<typeof vi.fn>
const mockAuthorizeWorkflowByWorkspacePermission = vi.fn()
const mockDbSelect = vi.fn()
const mockDbFrom = vi.fn()
@@ -48,9 +48,7 @@ describe('Workflow Chat Status Route', () => {
workflowId: 'workflowId',
},
}))
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: mockCheckSessionOrInternalAuth,
}))
;({ mockCheckSessionOrInternalAuth } = mockHybridAuth())
vi.doMock('@/lib/workflows/utils', () => ({
authorizeWorkflowByWorkspacePermission: mockAuthorizeWorkflowByWorkspacePermission,
}))

View File

@@ -3,11 +3,11 @@
*
* @vitest-environment node
*/
import { loggerMock } from '@sim/testing'
import { loggerMock, mockHybridAuth } from '@sim/testing'
import { NextRequest } from 'next/server'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const mockCheckSessionOrInternalAuth = vi.fn()
let mockCheckSessionOrInternalAuth: ReturnType<typeof vi.fn>
const mockAuthorizeWorkflowByWorkspacePermission = vi.fn()
const mockDbSelect = vi.fn()
const mockDbFrom = vi.fn()
@@ -43,9 +43,7 @@ describe('Workflow Form Status Route', () => {
isActive: 'isActive',
},
}))
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: mockCheckSessionOrInternalAuth,
}))
;({ mockCheckSessionOrInternalAuth } = mockHybridAuth())
vi.doMock('@/lib/workflows/utils', () => ({
authorizeWorkflowByWorkspacePermission: mockAuthorizeWorkflowByWorkspacePermission,
}))

View File

@@ -5,11 +5,19 @@
* @vitest-environment node
*/
import { auditMock, loggerMock, setupGlobalFetchMock } from '@sim/testing'
import {
auditMock,
envMock,
loggerMock,
requestUtilsMock,
setupGlobalFetchMock,
telemetryMock,
} from '@sim/testing'
import { NextRequest } from 'next/server'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const mockGetSession = vi.fn()
const mockCheckHybridAuth = vi.fn()
const mockCheckSessionOrInternalAuth = vi.fn()
const mockLoadWorkflowFromNormalizedTables = vi.fn()
const mockGetWorkflowById = vi.fn()
const mockAuthorizeWorkflowByWorkspacePermission = vi.fn()
@@ -17,10 +25,34 @@ const mockDbDelete = vi.fn()
const mockDbUpdate = vi.fn()
const mockDbSelect = vi.fn()
/**
* Helper to set mock auth state consistently across getSession and hybrid auth.
*/
function mockGetSession(session: { user: { id: string } } | null) {
if (session) {
mockCheckHybridAuth.mockResolvedValue({ success: true, userId: session.user.id })
mockCheckSessionOrInternalAuth.mockResolvedValue({ success: true, userId: session.user.id })
} else {
mockCheckHybridAuth.mockResolvedValue({ success: false })
mockCheckSessionOrInternalAuth.mockResolvedValue({ success: false })
}
}
vi.mock('@/lib/auth', () => ({
getSession: () => mockGetSession(),
getSession: vi.fn(),
}))
vi.mock('@/lib/auth/hybrid', () => ({
checkHybridAuth: (...args: unknown[]) => mockCheckHybridAuth(...args),
checkSessionOrInternalAuth: (...args: unknown[]) => mockCheckSessionOrInternalAuth(...args),
}))
vi.mock('@/lib/core/config/env', () => envMock)
vi.mock('@/lib/core/telemetry', () => telemetryMock)
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
vi.mock('@sim/logger', () => loggerMock)
vi.mock('@/lib/audit/log', () => auditMock)
@@ -30,20 +62,14 @@ vi.mock('@/lib/workflows/persistence/utils', () => ({
mockLoadWorkflowFromNormalizedTables(workflowId),
}))
vi.mock('@/lib/workflows/utils', async () => {
const actual =
await vi.importActual<typeof import('@/lib/workflows/utils')>('@/lib/workflows/utils')
return {
...actual,
getWorkflowById: (workflowId: string) => mockGetWorkflowById(workflowId),
authorizeWorkflowByWorkspacePermission: (params: {
workflowId: string
userId: string
action?: 'read' | 'write' | 'admin'
}) => mockAuthorizeWorkflowByWorkspacePermission(params),
}
})
vi.mock('@/lib/workflows/utils', () => ({
getWorkflowById: (workflowId: string) => mockGetWorkflowById(workflowId),
authorizeWorkflowByWorkspacePermission: (params: {
workflowId: string
userId: string
action?: 'read' | 'write' | 'admin'
}) => mockAuthorizeWorkflowByWorkspacePermission(params),
}))
vi.mock('@sim/db', () => ({
db: {
@@ -73,7 +99,7 @@ describe('Workflow By ID API Route', () => {
describe('GET /api/workflows/[id]', () => {
it('should return 401 when user is not authenticated', async () => {
mockGetSession.mockResolvedValue(null)
mockGetSession(null)
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123')
const params = Promise.resolve({ id: 'workflow-123' })
@@ -86,9 +112,7 @@ describe('Workflow By ID API Route', () => {
})
it('should return 404 when workflow does not exist', async () => {
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(null)
@@ -118,9 +142,7 @@ describe('Workflow By ID API Route', () => {
isFromNormalizedTables: true,
}
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -158,9 +180,7 @@ describe('Workflow By ID API Route', () => {
isFromNormalizedTables: true,
}
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -190,9 +210,7 @@ describe('Workflow By ID API Route', () => {
workspaceId: 'workspace-456',
}
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -229,9 +247,7 @@ describe('Workflow By ID API Route', () => {
isFromNormalizedTables: true,
}
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -264,9 +280,7 @@ describe('Workflow By ID API Route', () => {
workspaceId: 'workspace-456',
}
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -308,9 +322,7 @@ describe('Workflow By ID API Route', () => {
workspaceId: 'workspace-456',
}
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -353,9 +365,7 @@ describe('Workflow By ID API Route', () => {
workspaceId: 'workspace-456',
}
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -392,9 +402,7 @@ describe('Workflow By ID API Route', () => {
workspaceId: 'workspace-456',
}
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -419,6 +427,16 @@ describe('Workflow By ID API Route', () => {
})
describe('PUT /api/workflows/[id]', () => {
function mockDuplicateCheck(results: Array<{ id: string }> = []) {
mockDbSelect.mockReturnValue({
from: vi.fn().mockReturnValue({
where: vi.fn().mockReturnValue({
limit: vi.fn().mockResolvedValue(results),
}),
}),
})
}
it('should allow user with write permission to update workflow', async () => {
const mockWorkflow = {
id: 'workflow-123',
@@ -430,9 +448,7 @@ describe('Workflow By ID API Route', () => {
const updateData = { name: 'Updated Workflow' }
const updatedWorkflow = { ...mockWorkflow, ...updateData, updatedAt: new Date() }
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -442,6 +458,8 @@ describe('Workflow By ID API Route', () => {
workspacePermission: 'write',
})
mockDuplicateCheck([])
mockDbUpdate.mockReturnValue({
set: vi.fn().mockReturnValue({
where: vi.fn().mockReturnValue({
@@ -474,9 +492,7 @@ describe('Workflow By ID API Route', () => {
const updateData = { name: 'Updated Workflow' }
const updatedWorkflow = { ...mockWorkflow, ...updateData, updatedAt: new Date() }
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -486,6 +502,8 @@ describe('Workflow By ID API Route', () => {
workspacePermission: 'write',
})
mockDuplicateCheck([])
mockDbUpdate.mockReturnValue({
set: vi.fn().mockReturnValue({
where: vi.fn().mockReturnValue({
@@ -517,9 +535,7 @@ describe('Workflow By ID API Route', () => {
const updateData = { name: 'Updated Workflow' }
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -551,9 +567,7 @@ describe('Workflow By ID API Route', () => {
workspaceId: 'workspace-456',
}
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -577,13 +591,238 @@ describe('Workflow By ID API Route', () => {
const data = await response.json()
expect(data.error).toBe('Invalid request data')
})
it('should reject rename when duplicate name exists in same folder', async () => {
const mockWorkflow = {
id: 'workflow-123',
userId: 'user-123',
name: 'Original Name',
folderId: 'folder-1',
workspaceId: 'workspace-456',
}
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
allowed: true,
status: 200,
workflow: mockWorkflow,
workspacePermission: 'write',
})
mockDuplicateCheck([{ id: 'workflow-other' }])
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123', {
method: 'PUT',
body: JSON.stringify({ name: 'Duplicate Name' }),
})
const params = Promise.resolve({ id: 'workflow-123' })
const response = await PUT(req, { params })
expect(response.status).toBe(409)
const data = await response.json()
expect(data.error).toBe('A workflow named "Duplicate Name" already exists in this folder')
})
it('should reject rename when duplicate name exists at root level', async () => {
const mockWorkflow = {
id: 'workflow-123',
userId: 'user-123',
name: 'Original Name',
folderId: null,
workspaceId: 'workspace-456',
}
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
allowed: true,
status: 200,
workflow: mockWorkflow,
workspacePermission: 'write',
})
mockDuplicateCheck([{ id: 'workflow-other' }])
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123', {
method: 'PUT',
body: JSON.stringify({ name: 'Duplicate Name' }),
})
const params = Promise.resolve({ id: 'workflow-123' })
const response = await PUT(req, { params })
expect(response.status).toBe(409)
const data = await response.json()
expect(data.error).toBe('A workflow named "Duplicate Name" already exists in this folder')
})
it('should allow rename when no duplicate exists in same folder', async () => {
const mockWorkflow = {
id: 'workflow-123',
userId: 'user-123',
name: 'Original Name',
folderId: 'folder-1',
workspaceId: 'workspace-456',
}
const updatedWorkflow = { ...mockWorkflow, name: 'Unique Name', updatedAt: new Date() }
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
allowed: true,
status: 200,
workflow: mockWorkflow,
workspacePermission: 'write',
})
mockDuplicateCheck([])
mockDbUpdate.mockReturnValue({
set: vi.fn().mockReturnValue({
where: vi.fn().mockReturnValue({
returning: vi.fn().mockResolvedValue([updatedWorkflow]),
}),
}),
})
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123', {
method: 'PUT',
body: JSON.stringify({ name: 'Unique Name' }),
})
const params = Promise.resolve({ id: 'workflow-123' })
const response = await PUT(req, { params })
expect(response.status).toBe(200)
const data = await response.json()
expect(data.workflow.name).toBe('Unique Name')
})
it('should allow same name in different folders', async () => {
const mockWorkflow = {
id: 'workflow-123',
userId: 'user-123',
name: 'My Workflow',
folderId: 'folder-1',
workspaceId: 'workspace-456',
}
const updatedWorkflow = { ...mockWorkflow, folderId: 'folder-2', updatedAt: new Date() }
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
allowed: true,
status: 200,
workflow: mockWorkflow,
workspacePermission: 'write',
})
// No duplicate in target folder
mockDuplicateCheck([])
mockDbUpdate.mockReturnValue({
set: vi.fn().mockReturnValue({
where: vi.fn().mockReturnValue({
returning: vi.fn().mockResolvedValue([updatedWorkflow]),
}),
}),
})
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123', {
method: 'PUT',
body: JSON.stringify({ folderId: 'folder-2' }),
})
const params = Promise.resolve({ id: 'workflow-123' })
const response = await PUT(req, { params })
expect(response.status).toBe(200)
const data = await response.json()
expect(data.workflow.folderId).toBe('folder-2')
})
it('should reject moving to a folder where same name already exists', async () => {
const mockWorkflow = {
id: 'workflow-123',
userId: 'user-123',
name: 'My Workflow',
folderId: 'folder-1',
workspaceId: 'workspace-456',
}
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
allowed: true,
status: 200,
workflow: mockWorkflow,
workspacePermission: 'write',
})
// Duplicate exists in target folder
mockDuplicateCheck([{ id: 'workflow-other' }])
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123', {
method: 'PUT',
body: JSON.stringify({ folderId: 'folder-2' }),
})
const params = Promise.resolve({ id: 'workflow-123' })
const response = await PUT(req, { params })
expect(response.status).toBe(409)
const data = await response.json()
expect(data.error).toBe('A workflow named "My Workflow" already exists in this folder')
})
it('should skip duplicate check when only updating non-name/non-folder fields', async () => {
const mockWorkflow = {
id: 'workflow-123',
userId: 'user-123',
name: 'Test Workflow',
workspaceId: 'workspace-456',
}
const updatedWorkflow = { ...mockWorkflow, color: '#FF0000', updatedAt: new Date() }
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
allowed: true,
status: 200,
workflow: mockWorkflow,
workspacePermission: 'write',
})
mockDbUpdate.mockReturnValue({
set: vi.fn().mockReturnValue({
where: vi.fn().mockReturnValue({
returning: vi.fn().mockResolvedValue([updatedWorkflow]),
}),
}),
})
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123', {
method: 'PUT',
body: JSON.stringify({ color: '#FF0000' }),
})
const params = Promise.resolve({ id: 'workflow-123' })
const response = await PUT(req, { params })
expect(response.status).toBe(200)
// db.select should NOT have been called since no name/folder change
expect(mockDbSelect).not.toHaveBeenCalled()
})
})
describe('Error handling', () => {
it.concurrent('should handle database errors gracefully', async () => {
mockGetSession.mockResolvedValue({
user: { id: 'user-123' },
})
mockGetSession({ user: { id: 'user-123' } })
mockGetWorkflowById.mockRejectedValue(new Error('Database connection timeout'))

View File

@@ -1,7 +1,7 @@
import { db } from '@sim/db'
import { templates, webhook, workflow } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { eq } from 'drizzle-orm'
import { and, eq, isNull, ne } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
@@ -411,6 +411,45 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
if (updates.folderId !== undefined) updateData.folderId = updates.folderId
if (updates.sortOrder !== undefined) updateData.sortOrder = updates.sortOrder
if (updates.name !== undefined || updates.folderId !== undefined) {
const targetName = updates.name ?? workflowData.name
const targetFolderId =
updates.folderId !== undefined ? updates.folderId : workflowData.folderId
if (!workflowData.workspaceId) {
logger.error(`[${requestId}] Workflow ${workflowId} has no workspaceId`)
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
}
const conditions = [
eq(workflow.workspaceId, workflowData.workspaceId),
eq(workflow.name, targetName),
ne(workflow.id, workflowId),
]
if (targetFolderId) {
conditions.push(eq(workflow.folderId, targetFolderId))
} else {
conditions.push(isNull(workflow.folderId))
}
const [duplicate] = await db
.select({ id: workflow.id })
.from(workflow)
.where(and(...conditions))
.limit(1)
if (duplicate) {
logger.warn(
`[${requestId}] Duplicate workflow name "${targetName}" in folder ${targetFolderId ?? 'root'}`
)
return NextResponse.json(
{ error: `A workflow named "${targetName}" already exists in this folder` },
{ status: 409 }
)
}
}
// Update the workflow
const [updatedWorkflow] = await db
.update(workflow)

View File

@@ -1,11 +1,16 @@
/**
* @vitest-environment node
*/
import { auditMock, createMockRequest, mockConsoleLogger, setupCommonApiMocks } from '@sim/testing'
import {
auditMock,
createMockRequest,
mockConsoleLogger,
mockHybridAuth,
setupCommonApiMocks,
} from '@sim/testing'
import { drizzleOrmMock } from '@sim/testing/mocks'
import { beforeEach, describe, expect, it, vi } from 'vitest'
const mockCheckSessionOrInternalAuth = vi.fn()
const mockGetUserEntityPermissions = vi.fn()
const mockDbSelect = vi.fn()
const mockDbInsert = vi.fn()
@@ -30,6 +35,7 @@ describe('Workflows API Route - POST ordering', () => {
randomUUID: vi.fn().mockReturnValue('workflow-new-id'),
})
const { mockCheckSessionOrInternalAuth } = mockHybridAuth()
mockCheckSessionOrInternalAuth.mockResolvedValue({
success: true,
userId: 'user-123',
@@ -45,10 +51,6 @@ describe('Workflows API Route - POST ordering', () => {
},
}))
vi.doMock('@/lib/auth/hybrid', () => ({
checkSessionOrInternalAuth: (...args: unknown[]) => mockCheckSessionOrInternalAuth(...args),
}))
vi.doMock('@/lib/workspaces/permissions/utils', () => ({
getUserEntityPermissions: (...args: unknown[]) => mockGetUserEntityPermissions(...args),
workspaceExists: vi.fn(),

View File

@@ -1,6 +1,7 @@
import { redirect } from 'next/navigation'
import { getSession } from '@/lib/auth'
import { verifyWorkspaceMembership } from '@/app/api/workflows/utils'
import { getUserPermissionConfig } from '@/ee/access-control/utils/permission-check'
import { TablesView } from './components'
interface TablesPageProps {
@@ -22,5 +23,10 @@ export default async function TablesPage({ params }: TablesPageProps) {
redirect('/')
}
const permissionConfig = await getUserPermissionConfig(session.user.id)
if (permissionConfig?.hideTablesTab) {
redirect(`/workspace/${workspaceId}`)
}
return <TablesView />
}

View File

@@ -1,19 +0,0 @@
import { Plus } from 'lucide-react'
import { Button } from '@/components/emcn'
interface EmptyStateProps {
onAdd: () => void
disabled: boolean
label: string
}
export function EmptyState({ onAdd, disabled, label }: EmptyStateProps) {
return (
<div className='flex items-center justify-center rounded-[4px] border border-[var(--border-1)] border-dashed py-[16px]'>
<Button variant='ghost' size='sm' onClick={onAdd} disabled={disabled}>
<Plus className='mr-[4px] h-[12px] w-[12px]' />
{label}
</Button>
</div>
)
}

View File

@@ -1,9 +1,19 @@
import { X } from 'lucide-react'
import { Button, Combobox, type ComboboxOption, Input } from '@/components/emcn'
import { useRef } from 'react'
import { Plus } from 'lucide-react'
import {
Badge,
Button,
Combobox,
type ComboboxOption,
Input,
Label,
Trash,
} from '@/components/emcn'
import { cn } from '@/lib/core/utils/cn'
import type { FilterRule } from '@/lib/table/query-builder/constants'
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
import { SubBlockInputController } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/sub-block-input-controller'
import { TagDropdown } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tag-dropdown/tag-dropdown'
import type { useSubBlockInput } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-input'
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
interface FilterRuleRowProps {
@@ -17,121 +27,196 @@ interface FilterRuleRowProps {
isReadOnly: boolean
isPreview: boolean
disabled: boolean
onAdd: () => void
onRemove: (id: string) => void
onUpdate: (id: string, field: keyof FilterRule, value: string) => void
onToggleCollapse: (id: string) => void
inputController: ReturnType<typeof useSubBlockInput>
}
export function FilterRuleRow({
blockId,
subBlockId,
rule,
index,
columns,
comparisonOptions,
logicalOptions,
isReadOnly,
isPreview,
disabled,
onAdd,
onRemove,
onUpdate,
onToggleCollapse,
inputController,
}: FilterRuleRowProps) {
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
const valueInputRef = useRef<HTMLInputElement>(null)
const overlayRef = useRef<HTMLDivElement>(null)
return (
<div className='flex items-center gap-[6px]'>
<Button
variant='ghost'
size='sm'
onClick={() => onRemove(rule.id)}
const syncOverlayScroll = (scrollLeft: number) => {
if (overlayRef.current) overlayRef.current.scrollLeft = scrollLeft
}
const cellKey = `filter-${rule.id}-value`
const fieldState = inputController.fieldHelpers.getFieldState(cellKey)
const handlers = inputController.fieldHelpers.createFieldHandlers(
cellKey,
rule.value,
(newValue) => onUpdate(rule.id, 'value', newValue)
)
const tagSelectHandler = inputController.fieldHelpers.createTagSelectHandler(
cellKey,
rule.value,
(newValue) => onUpdate(rule.id, 'value', newValue)
)
const getOperatorLabel = (value: string) => {
const option = comparisonOptions.find((op) => op.value === value)
return option?.label || value
}
const getColumnLabel = (value: string) => {
const option = columns.find((col) => col.value === value)
return option?.label || value
}
const renderHeader = () => (
<div
className='flex cursor-pointer items-center justify-between rounded-t-[4px] bg-[var(--surface-4)] px-[10px] py-[5px]'
onClick={() => onToggleCollapse(rule.id)}
>
<div className='flex min-w-0 flex-1 items-center gap-[8px]'>
<span className='block truncate font-medium text-[14px] text-[var(--text-tertiary)]'>
{rule.collapsed && rule.column ? getColumnLabel(rule.column) : `Condition ${index + 1}`}
</span>
{rule.collapsed && rule.column && (
<Badge variant='type' size='sm'>
{getOperatorLabel(rule.operator)}
</Badge>
)}
</div>
<div className='flex items-center gap-[8px] pl-[8px]' onClick={(e) => e.stopPropagation()}>
<Button variant='ghost' onClick={onAdd} disabled={isReadOnly} className='h-auto p-0'>
<Plus className='h-[14px] w-[14px]' />
<span className='sr-only'>Add Condition</span>
</Button>
<Button
variant='ghost'
onClick={() => onRemove(rule.id)}
disabled={isReadOnly}
className='h-auto p-0 text-[var(--text-error)] hover:text-[var(--text-error)]'
>
<Trash className='h-[14px] w-[14px]' />
<span className='sr-only'>Delete Condition</span>
</Button>
</div>
</div>
)
const renderValueInput = () => (
<div className='relative'>
<Input
ref={valueInputRef}
value={rule.value}
onChange={handlers.onChange}
onKeyDown={handlers.onKeyDown}
onDrop={handlers.onDrop}
onDragOver={handlers.onDragOver}
onFocus={handlers.onFocus}
onScroll={(e) => syncOverlayScroll(e.currentTarget.scrollLeft)}
onPaste={() =>
setTimeout(() => {
if (valueInputRef.current) {
syncOverlayScroll(valueInputRef.current.scrollLeft)
}
}, 0)
}
disabled={isReadOnly}
className='h-[24px] w-[24px] shrink-0 p-0 text-[var(--text-tertiary)] hover:text-[var(--text-primary)]'
autoComplete='off'
placeholder='Enter value'
className='allow-scroll w-full overflow-auto text-transparent caret-foreground'
/>
<div
ref={overlayRef}
className={cn(
'absolute inset-0 flex items-center overflow-x-auto bg-transparent px-[8px] py-[6px] font-medium font-sans text-sm',
!isReadOnly && 'pointer-events-none'
)}
>
<X className='h-[12px] w-[12px]' />
</Button>
<div className='w-full whitespace-pre' style={{ minWidth: 'fit-content' }}>
{formatDisplayText(
rule.value,
accessiblePrefixes ? { accessiblePrefixes } : { highlightAll: true }
)}
</div>
</div>
{fieldState.showTags && (
<TagDropdown
visible={fieldState.showTags}
onSelect={tagSelectHandler}
blockId={blockId}
activeSourceBlockId={fieldState.activeSourceBlockId}
inputValue={rule.value}
cursorPosition={fieldState.cursorPosition}
onClose={() => inputController.fieldHelpers.hideFieldDropdowns(cellKey)}
inputRef={valueInputRef.current ? { current: valueInputRef.current } : undefined}
/>
)}
</div>
)
<div className='w-[80px] shrink-0'>
{index === 0 ? (
const renderContent = () => (
<div className='flex flex-col gap-[8px] border-[var(--border-1)] border-t px-[10px] pt-[6px] pb-[10px]'>
{index > 0 && (
<div className='flex flex-col gap-[6px]'>
<Label className='text-[13px]'>Logic</Label>
<Combobox
size='sm'
options={[{ value: 'where', label: 'where' }]}
value='where'
disabled
/>
) : (
<Combobox
size='sm'
options={logicalOptions}
value={rule.logicalOperator}
onChange={(v) => onUpdate(rule.id, 'logicalOperator', v as 'and' | 'or')}
disabled={isReadOnly}
/>
)}
</div>
</div>
)}
<div className='w-[100px] shrink-0'>
<div className='flex flex-col gap-[6px]'>
<Label className='text-[13px]'>Column</Label>
<Combobox
size='sm'
options={columns}
value={rule.column}
onChange={(v) => onUpdate(rule.id, 'column', v)}
placeholder='Column'
disabled={isReadOnly}
placeholder='Select column'
/>
</div>
<div className='w-[110px] shrink-0'>
<div className='flex flex-col gap-[6px]'>
<Label className='text-[13px]'>Operator</Label>
<Combobox
size='sm'
options={comparisonOptions}
value={rule.operator}
onChange={(v) => onUpdate(rule.id, 'operator', v)}
disabled={isReadOnly}
placeholder='Select operator'
/>
</div>
<div className='relative min-w-[80px] flex-1'>
<SubBlockInputController
blockId={blockId}
subBlockId={`${subBlockId}_filter_${rule.id}`}
config={{ id: `filter_value_${rule.id}`, type: 'short-input' }}
value={rule.value}
onChange={(newValue) => onUpdate(rule.id, 'value', newValue)}
isPreview={isPreview}
disabled={disabled}
>
{({ ref, value: ctrlValue, onChange, onKeyDown, onDrop, onDragOver }) => {
const formattedText = formatDisplayText(ctrlValue, {
accessiblePrefixes,
highlightAll: !accessiblePrefixes,
})
return (
<div className='relative'>
<Input
ref={ref as React.RefObject<HTMLInputElement>}
className='h-[28px] w-full overflow-auto text-[12px] text-transparent caret-foreground [-ms-overflow-style:none] [scrollbar-width:none] placeholder:text-muted-foreground/50 [&::-webkit-scrollbar]:hidden'
value={ctrlValue}
onChange={onChange as (e: React.ChangeEvent<HTMLInputElement>) => void}
onKeyDown={onKeyDown as (e: React.KeyboardEvent<HTMLInputElement>) => void}
onDrop={onDrop as (e: React.DragEvent<HTMLInputElement>) => void}
onDragOver={onDragOver as (e: React.DragEvent<HTMLInputElement>) => void}
placeholder='Value'
disabled={isReadOnly}
autoComplete='off'
/>
<div
className={cn(
'pointer-events-none absolute inset-0 flex items-center overflow-x-auto bg-transparent px-[8px] py-[6px] font-medium font-sans text-[12px] text-foreground [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden',
(isPreview || disabled) && 'opacity-50'
)}
>
<div className='min-w-fit whitespace-pre'>{formattedText}</div>
</div>
</div>
)
}}
</SubBlockInputController>
<div className='flex flex-col gap-[6px]'>
<Label className='text-[13px]'>Value</Label>
{renderValueInput()}
</div>
</div>
)
return (
<div
data-filter-id={rule.id}
className={cn(
'rounded-[4px] border border-[var(--border-1)]',
rule.collapsed ? 'overflow-hidden' : 'overflow-visible'
)}
>
{renderHeader()}
{!rule.collapsed && renderContent()}
</div>
)
}

View File

@@ -1,13 +1,12 @@
'use client'
import { useMemo } from 'react'
import { Plus } from 'lucide-react'
import { Button } from '@/components/emcn'
import { useCallback, useMemo } from 'react'
import type { ComboboxOption } from '@/components/emcn'
import { useTableColumns } from '@/lib/table/hooks'
import type { FilterRule } from '@/lib/table/query-builder/constants'
import { useFilterBuilder } from '@/lib/table/query-builder/use-query-builder'
import { useSubBlockInput } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-input'
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
import { EmptyState } from './components/empty-state'
import { FilterRuleRow } from './components/filter-rule-row'
interface FilterBuilderProps {
@@ -20,6 +19,15 @@ interface FilterBuilderProps {
tableIdSubBlockId?: string
}
const createDefaultRule = (columns: ComboboxOption[]): FilterRule => ({
id: crypto.randomUUID(),
logicalOperator: 'and',
column: columns[0]?.value || '',
operator: 'eq',
value: '',
collapsed: false,
})
/** Visual builder for table filter rules in workflow blocks. */
export function FilterBuilder({
blockId,
@@ -40,7 +48,8 @@ export function FilterBuilder({
}, [propColumns, dynamicColumns])
const value = isPreview ? previewValue : storeValue
const rules: FilterRule[] = Array.isArray(value) && value.length > 0 ? value : []
const rules: FilterRule[] =
Array.isArray(value) && value.length > 0 ? value : [createDefaultRule(columns)]
const isReadOnly = isPreview || disabled
const { comparisonOptions, logicalOptions, addRule, removeRule, updateRule } = useFilterBuilder({
@@ -50,41 +59,60 @@ export function FilterBuilder({
isReadOnly,
})
const inputController = useSubBlockInput({
blockId,
subBlockId,
config: {
id: subBlockId,
type: 'filter-builder',
connectionDroppable: true,
},
isPreview,
disabled,
})
const toggleCollapse = useCallback(
(id: string) => {
if (isReadOnly) return
setStoreValue(rules.map((r) => (r.id === id ? { ...r, collapsed: !r.collapsed } : r)))
},
[isReadOnly, rules, setStoreValue]
)
const handleRemoveRule = useCallback(
(id: string) => {
if (isReadOnly) return
if (rules.length === 1) {
setStoreValue([createDefaultRule(columns)])
} else {
removeRule(id)
}
},
[isReadOnly, rules, columns, setStoreValue, removeRule]
)
return (
<div className='flex flex-col gap-[8px]'>
{rules.length === 0 ? (
<EmptyState onAdd={addRule} disabled={isReadOnly} label='Add filter rule' />
) : (
<>
{rules.map((rule, index) => (
<FilterRuleRow
key={rule.id}
blockId={blockId}
subBlockId={subBlockId}
rule={rule}
index={index}
columns={columns}
comparisonOptions={comparisonOptions}
logicalOptions={logicalOptions}
isReadOnly={isReadOnly}
isPreview={isPreview}
disabled={disabled}
onRemove={removeRule}
onUpdate={updateRule}
/>
))}
<Button
variant='ghost'
size='sm'
onClick={addRule}
disabled={isReadOnly}
className='self-start'
>
<Plus className='mr-[4px] h-[12px] w-[12px]' />
Add rule
</Button>
</>
)}
<div className='space-y-[8px]'>
{rules.map((rule, index) => (
<FilterRuleRow
key={rule.id}
blockId={blockId}
subBlockId={subBlockId}
rule={rule}
index={index}
columns={columns}
comparisonOptions={comparisonOptions}
logicalOptions={logicalOptions}
isReadOnly={isReadOnly}
isPreview={isPreview}
disabled={disabled}
onAdd={addRule}
onRemove={handleRemoveRule}
onUpdate={updateRule}
onToggleCollapse={toggleCollapse}
inputController={inputController}
/>
))}
</div>
)
}

View File

@@ -1,19 +0,0 @@
import { Plus } from 'lucide-react'
import { Button } from '@/components/emcn'
interface EmptyStateProps {
onAdd: () => void
disabled: boolean
label: string
}
export function EmptyState({ onAdd, disabled, label }: EmptyStateProps) {
return (
<div className='flex items-center justify-center rounded-[4px] border border-[var(--border-1)] border-dashed py-[16px]'>
<Button variant='ghost' size='sm' onClick={onAdd} disabled={disabled}>
<Plus className='mr-[4px] h-[12px] w-[12px]' />
{label}
</Button>
</div>
)
}

View File

@@ -1,5 +1,6 @@
import { X } from 'lucide-react'
import { Button, Combobox, type ComboboxOption } from '@/components/emcn'
import { Plus } from 'lucide-react'
import { Badge, Button, Combobox, type ComboboxOption, Label, Trash } from '@/components/emcn'
import { cn } from '@/lib/core/utils/cn'
import type { SortRule } from '@/lib/table/query-builder/constants'
interface SortRuleRowProps {
@@ -8,8 +9,10 @@ interface SortRuleRowProps {
columns: ComboboxOption[]
directionOptions: ComboboxOption[]
isReadOnly: boolean
onAdd: () => void
onRemove: (id: string) => void
onUpdate: (id: string, field: keyof SortRule, value: string) => void
onToggleCollapse: (id: string) => void
}
export function SortRuleRow({
@@ -18,50 +21,90 @@ export function SortRuleRow({
columns,
directionOptions,
isReadOnly,
onAdd,
onRemove,
onUpdate,
onToggleCollapse,
}: SortRuleRowProps) {
return (
<div className='flex items-center gap-[6px]'>
<Button
variant='ghost'
size='sm'
onClick={() => onRemove(rule.id)}
disabled={isReadOnly}
className='h-[24px] w-[24px] shrink-0 p-0 text-[var(--text-tertiary)] hover:text-[var(--text-primary)]'
>
<X className='h-[12px] w-[12px]' />
</Button>
const getDirectionLabel = (value: string) => {
const option = directionOptions.find((dir) => dir.value === value)
return option?.label || value
}
<div className='w-[90px] shrink-0'>
<Combobox
size='sm'
options={[{ value: String(index + 1), label: index === 0 ? 'order by' : 'then by' }]}
value={String(index + 1)}
disabled
/>
const getColumnLabel = (value: string) => {
const option = columns.find((col) => col.value === value)
return option?.label || value
}
const renderHeader = () => (
<div
className='flex cursor-pointer items-center justify-between rounded-t-[4px] bg-[var(--surface-4)] px-[10px] py-[5px]'
onClick={() => onToggleCollapse(rule.id)}
>
<div className='flex min-w-0 flex-1 items-center gap-[8px]'>
<span className='block truncate font-medium text-[14px] text-[var(--text-tertiary)]'>
{rule.collapsed && rule.column ? getColumnLabel(rule.column) : `Sort ${index + 1}`}
</span>
{rule.collapsed && rule.column && (
<Badge variant='type' size='sm'>
{getDirectionLabel(rule.direction)}
</Badge>
)}
</div>
<div className='flex items-center gap-[8px] pl-[8px]' onClick={(e) => e.stopPropagation()}>
<Button variant='ghost' onClick={onAdd} disabled={isReadOnly} className='h-auto p-0'>
<Plus className='h-[14px] w-[14px]' />
<span className='sr-only'>Add Sort</span>
</Button>
<Button
variant='ghost'
onClick={() => onRemove(rule.id)}
disabled={isReadOnly}
className='h-auto p-0 text-[var(--text-error)] hover:text-[var(--text-error)]'
>
<Trash className='h-[14px] w-[14px]' />
<span className='sr-only'>Delete Sort</span>
</Button>
</div>
</div>
)
<div className='min-w-[120px] flex-1'>
const renderContent = () => (
<div className='flex flex-col gap-[8px] border-[var(--border-1)] border-t px-[10px] pt-[6px] pb-[10px]'>
<div className='flex flex-col gap-[6px]'>
<Label className='text-[13px]'>Column</Label>
<Combobox
size='sm'
options={columns}
value={rule.column}
onChange={(v) => onUpdate(rule.id, 'column', v)}
placeholder='Column'
disabled={isReadOnly}
placeholder='Select column'
/>
</div>
<div className='w-[110px] shrink-0'>
<div className='flex flex-col gap-[6px]'>
<Label className='text-[13px]'>Direction</Label>
<Combobox
size='sm'
options={directionOptions}
value={rule.direction}
onChange={(v) => onUpdate(rule.id, 'direction', v as 'asc' | 'desc')}
disabled={isReadOnly}
placeholder='Select direction'
/>
</div>
</div>
)
return (
<div
data-sort-id={rule.id}
className={cn(
'rounded-[4px] border border-[var(--border-1)]',
rule.collapsed ? 'overflow-hidden' : 'overflow-visible'
)}
>
{renderHeader()}
{!rule.collapsed && renderContent()}
</div>
)
}

View File

@@ -1,13 +1,10 @@
'use client'
import { useCallback, useMemo } from 'react'
import { Plus } from 'lucide-react'
import { nanoid } from 'nanoid'
import { Button, type ComboboxOption } from '@/components/emcn'
import type { ComboboxOption } from '@/components/emcn'
import { useTableColumns } from '@/lib/table/hooks'
import { SORT_DIRECTIONS, type SortRule } from '@/lib/table/query-builder/constants'
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
import { EmptyState } from './components/empty-state'
import { SortRuleRow } from './components/sort-rule-row'
interface SortBuilderProps {
@@ -21,9 +18,10 @@ interface SortBuilderProps {
}
const createDefaultRule = (columns: ComboboxOption[]): SortRule => ({
id: nanoid(),
id: crypto.randomUUID(),
column: columns[0]?.value || '',
direction: 'asc',
collapsed: false,
})
/** Visual builder for table sort rules in workflow blocks. */
@@ -51,7 +49,8 @@ export function SortBuilder({
)
const value = isPreview ? previewValue : storeValue
const rules: SortRule[] = Array.isArray(value) && value.length > 0 ? value : []
const rules: SortRule[] =
Array.isArray(value) && value.length > 0 ? value : [createDefaultRule(columns)]
const isReadOnly = isPreview || disabled
const addRule = useCallback(() => {
@@ -62,9 +61,13 @@ export function SortBuilder({
const removeRule = useCallback(
(id: string) => {
if (isReadOnly) return
setStoreValue(rules.filter((r) => r.id !== id))
if (rules.length === 1) {
setStoreValue([createDefaultRule(columns)])
} else {
setStoreValue(rules.filter((r) => r.id !== id))
}
},
[isReadOnly, rules, setStoreValue]
[isReadOnly, rules, columns, setStoreValue]
)
const updateRule = useCallback(
@@ -75,36 +78,30 @@ export function SortBuilder({
[isReadOnly, rules, setStoreValue]
)
const toggleCollapse = useCallback(
(id: string) => {
if (isReadOnly) return
setStoreValue(rules.map((r) => (r.id === id ? { ...r, collapsed: !r.collapsed } : r)))
},
[isReadOnly, rules, setStoreValue]
)
return (
<div className='flex flex-col gap-[8px]'>
{rules.length === 0 ? (
<EmptyState onAdd={addRule} disabled={isReadOnly} label='Add sort rule' />
) : (
<>
{rules.map((rule, index) => (
<SortRuleRow
key={rule.id}
rule={rule}
index={index}
columns={columns}
directionOptions={directionOptions}
isReadOnly={isReadOnly}
onRemove={removeRule}
onUpdate={updateRule}
/>
))}
<Button
variant='ghost'
size='sm'
onClick={addRule}
disabled={isReadOnly}
className='self-start'
>
<Plus className='mr-[4px] h-[12px] w-[12px]' />
Add sort
</Button>
</>
)}
<div className='space-y-[8px]'>
{rules.map((rule, index) => (
<SortRuleRow
key={rule.id}
rule={rule}
index={index}
columns={columns}
directionOptions={directionOptions}
isReadOnly={isReadOnly}
onAdd={addRule}
onRemove={removeRule}
onUpdate={updateRule}
onToggleCollapse={toggleCollapse}
/>
))}
</div>
)
}

View File

@@ -336,6 +336,23 @@ const renderLabel = (
)}
</>
)}
{showExternalLink && (
<Tooltip.Root>
<Tooltip.Trigger asChild>
<button
type='button'
className='flex h-[12px] w-[12px] flex-shrink-0 items-center justify-center bg-transparent p-0'
onClick={externalLink?.onClick}
aria-label={externalLink?.tooltip}
>
<ExternalLink className='!h-[12px] !w-[12px] text-[var(--text-secondary)]' />
</button>
</Tooltip.Trigger>
<Tooltip.Content side='top'>
<p>{externalLink?.tooltip}</p>
</Tooltip.Content>
</Tooltip.Root>
)}
{showCanonicalToggle && (
<Tooltip.Root>
<Tooltip.Trigger asChild>
@@ -369,23 +386,6 @@ const renderLabel = (
</Tooltip.Content>
</Tooltip.Root>
)}
{showExternalLink && (
<Tooltip.Root>
<Tooltip.Trigger asChild>
<button
type='button'
className='flex h-[12px] w-[12px] flex-shrink-0 items-center justify-center bg-transparent p-0'
onClick={externalLink?.onClick}
aria-label={externalLink?.tooltip}
>
<ExternalLink className='!h-[12px] !w-[12px] text-[var(--text-secondary)]' />
</button>
</Tooltip.Trigger>
<Tooltip.Content side='top'>
<p>{externalLink?.tooltip}</p>
</Tooltip.Content>
</Tooltip.Root>
)}
</div>
</div>
)
@@ -495,23 +495,47 @@ function SubBlockComponent({
: null
const hasSelectedTable = tableId && !tableId.startsWith('<')
const knowledgeBaseId =
config.type === 'knowledge-base-selector' && subBlockValues
? (subBlockValues[config.id]?.value as string | null)
: null
const hasSelectedKnowledgeBase = knowledgeBaseId && !knowledgeBaseId.startsWith('<')
const handleNavigateToTable = useCallback(() => {
if (tableId && workspaceId) {
window.open(`/workspace/${workspaceId}/tables/${tableId}`, '_blank')
}
}, [workspaceId, tableId])
const externalLink = useMemo(
() =>
config.type === 'table-selector' && hasSelectedTable
? {
show: true,
onClick: handleNavigateToTable,
tooltip: 'View table',
}
: undefined,
[config.type, hasSelectedTable, handleNavigateToTable]
)
const handleNavigateToKnowledgeBase = useCallback(() => {
if (knowledgeBaseId && workspaceId) {
window.open(`/workspace/${workspaceId}/knowledge/${knowledgeBaseId}`, '_blank')
}
}, [workspaceId, knowledgeBaseId])
const externalLink = useMemo(() => {
if (config.type === 'table-selector' && hasSelectedTable) {
return {
show: true,
onClick: handleNavigateToTable,
tooltip: 'View table',
}
}
if (config.type === 'knowledge-base-selector' && hasSelectedKnowledgeBase) {
return {
show: true,
onClick: handleNavigateToKnowledgeBase,
tooltip: 'View knowledge base',
}
}
return undefined
}, [
config.type,
hasSelectedTable,
handleNavigateToTable,
hasSelectedKnowledgeBase,
handleNavigateToKnowledgeBase,
])
/**
* Handles wand icon click to activate inline prompt mode.

View File

@@ -119,6 +119,14 @@ export function SearchModal({
href: `/workspace/${workspaceId}/knowledge`,
hidden: permissionConfig.hideKnowledgeBaseTab,
},
// TODO: Uncomment when working on tables
// {
// id: 'tables',
// name: 'Tables',
// icon: Table,
// href: `/workspace/${workspaceId}/tables`,
// hidden: permissionConfig.hideTablesTab,
// },
{
id: 'help',
name: 'Help',

View File

@@ -2,7 +2,7 @@
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { createLogger } from '@sim/logger'
import { Database, HelpCircle, Layout, Plus, Search, Settings, Table } from 'lucide-react'
import { Database, HelpCircle, Layout, Plus, Search, Settings } from 'lucide-react'
import Link from 'next/link'
import { useParams, usePathname, useRouter } from 'next/navigation'
import { Button, Download, FolderPlus, Library, Loader, Tooltip } from '@/components/emcn'
@@ -268,12 +268,14 @@ export const Sidebar = memo(function Sidebar() {
href: `/workspace/${workspaceId}/knowledge`,
hidden: permissionConfig.hideKnowledgeBaseTab,
},
{
id: 'tables',
label: 'Tables',
icon: Table,
href: `/workspace/${workspaceId}/tables`,
},
// TODO: Uncomment when working on tables
// {
// id: 'tables',
// label: 'Tables',
// icon: Table,
// href: `/workspace/${workspaceId}/tables`,
// hidden: permissionConfig.hideTablesTab,
// },
{
id: 'help',
label: 'Help',

View File

@@ -485,14 +485,6 @@ Return ONLY the date string in YYYY-MM-DD format - no explanations, no quotes, n
],
config: {
tool: (params) => {
// Convert numeric string inputs to numbers
if (params.limit) {
params.limit = Number(params.limit)
}
if (params.offset) {
params.offset = Number(params.offset)
}
switch (params.operation) {
case 'ahrefs_domain_rating':
return 'ahrefs_domain_rating'
@@ -514,6 +506,12 @@ Return ONLY the date string in YYYY-MM-DD format - no explanations, no quotes, n
return 'ahrefs_domain_rating'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.limit) result.limit = Number(params.limit)
if (params.offset) result.offset = Number(params.offset)
return result
},
},
},
inputs: {

View File

@@ -0,0 +1,646 @@
import { AlgoliaIcon } from '@/components/icons'
import type { BlockConfig } from '@/blocks/types'
import { AuthMode } from '@/blocks/types'
export const AlgoliaBlock: BlockConfig = {
type: 'algolia',
name: 'Algolia',
description: 'Search and manage Algolia indices',
longDescription:
'Integrate Algolia into your workflow. Search indices, manage records (add, update, delete, browse), configure index settings, and perform batch operations.',
docsLink: 'https://docs.sim.ai/tools/algolia',
category: 'tools',
bgColor: '#003DFF',
icon: AlgoliaIcon,
authMode: AuthMode.ApiKey,
subBlocks: [
{
id: 'operation',
title: 'Operation',
type: 'dropdown',
options: [
{ label: 'Search', id: 'search' },
{ label: 'Add Record', id: 'add_record' },
{ label: 'Get Record', id: 'get_record' },
{ label: 'Get Records', id: 'get_records' },
{ label: 'Partial Update Record', id: 'partial_update_record' },
{ label: 'Delete Record', id: 'delete_record' },
{ label: 'Browse Records', id: 'browse_records' },
{ label: 'Batch Operations', id: 'batch_operations' },
{ label: 'List Indices', id: 'list_indices' },
{ label: 'Get Settings', id: 'get_settings' },
{ label: 'Update Settings', id: 'update_settings' },
{ label: 'Delete Index', id: 'delete_index' },
{ label: 'Copy/Move Index', id: 'copy_move_index' },
{ label: 'Clear Records', id: 'clear_records' },
{ label: 'Delete By Filter', id: 'delete_by_filter' },
],
value: () => 'search',
},
// Index name - needed for all except list_indices
{
id: 'indexName',
title: 'Index Name',
type: 'short-input',
placeholder: 'my_index',
condition: { field: 'operation', value: 'list_indices', not: true },
required: { field: 'operation', value: 'list_indices', not: true },
},
// Search fields
{
id: 'query',
title: 'Search Query',
type: 'short-input',
placeholder: 'Enter search query',
condition: { field: 'operation', value: ['search', 'browse_records'] },
required: { field: 'operation', value: 'search' },
},
{
id: 'hitsPerPage',
title: 'Hits Per Page',
type: 'short-input',
placeholder: '20',
condition: { field: 'operation', value: ['search', 'browse_records'] },
mode: 'advanced',
},
{
id: 'page',
title: 'Page',
type: 'short-input',
placeholder: '0',
condition: { field: 'operation', value: 'search' },
mode: 'advanced',
},
{
id: 'filters',
title: 'Filters',
type: 'short-input',
placeholder: 'category:electronics AND price < 100',
condition: { field: 'operation', value: ['search', 'browse_records'] },
wandConfig: {
enabled: true,
prompt: `Generate an Algolia filter expression based on the user's description.
Available operators: AND, OR, NOT
Comparison: =, !=, <, >, <=, >=
Facet filters: attribute:value
Numeric filters: attribute operator value
Boolean filters: attribute:true / attribute:false
Tag filters: _tags:value
Examples:
- "category:electronics AND price < 100"
- "brand:Apple OR brand:Samsung"
- "inStock:true AND NOT category:deprecated"
- "(category:electronics OR category:books) AND price >= 10"
Return ONLY the filter string, no quotes or explanation.`,
},
},
{
id: 'attributesToRetrieve',
title: 'Attributes to Retrieve',
type: 'short-input',
placeholder: 'name,description,price',
condition: { field: 'operation', value: ['search', 'get_record', 'browse_records'] },
mode: 'advanced',
},
// Browse cursor
{
id: 'cursor',
title: 'Cursor',
type: 'short-input',
placeholder: 'Cursor from previous browse response',
condition: { field: 'operation', value: 'browse_records' },
mode: 'advanced',
},
// Add record fields
{
id: 'record',
title: 'Record',
type: 'long-input',
placeholder: '{"name": "Product", "price": 29.99}',
condition: { field: 'operation', value: 'add_record' },
required: { field: 'operation', value: 'add_record' },
wandConfig: {
enabled: true,
prompt: `Generate a JSON object for an Algolia record based on the user's description.
### CONTEXT
{context}
### GUIDELINES
- Return ONLY a valid JSON object starting with { and ending with }
- Include relevant attributes as key-value pairs
- Do NOT include objectID unless the user explicitly specifies one
- Use appropriate types: strings, numbers, booleans, arrays
### EXAMPLE
User: "A product with name, price, and categories"
Output:
{"name": "Example Product", "price": 29.99, "categories": ["electronics", "gadgets"]}
Return ONLY the JSON object.`,
placeholder: 'Describe the record to add...',
generationType: 'json-object',
},
},
// Partial update fields
{
id: 'attributes',
title: 'Attributes to Update',
type: 'long-input',
placeholder: '{"price": 24.99, "stock": {"_operation": "Decrement", "value": 1}}',
condition: { field: 'operation', value: 'partial_update_record' },
required: { field: 'operation', value: 'partial_update_record' },
wandConfig: {
enabled: true,
prompt: `Generate a JSON object for an Algolia partial update based on the user's description.
### CONTEXT
{context}
### GUIDELINES
- Return ONLY a valid JSON object starting with { and ending with }
- For simple updates, use key-value pairs: {"price": 24.99}
- For built-in operations, use the _operation syntax:
- Increment: {"count": {"_operation": "Increment", "value": 1}}
- Decrement: {"stock": {"_operation": "Decrement", "value": 1}}
- Add to array: {"tags": {"_operation": "Add", "value": "new-tag"}}
- Remove from array: {"tags": {"_operation": "Remove", "value": "old-tag"}}
- AddUnique: {"tags": {"_operation": "AddUnique", "value": "unique-tag"}}
- IncrementFrom: {"version": {"_operation": "IncrementFrom", "value": 0}}
- IncrementSet: {"views": {"_operation": "IncrementSet", "value": 1}}
### EXAMPLE
User: "Decrease stock by 2 and add a sale tag"
Output:
{"stock": {"_operation": "Decrement", "value": 2}, "tags": {"_operation": "Add", "value": "sale"}}
Return ONLY the JSON object.`,
placeholder: 'Describe the attributes to update...',
generationType: 'json-object',
},
},
{
id: 'createIfNotExists',
title: 'Create If Not Exists',
type: 'dropdown',
options: [
{ label: 'Yes', id: 'true' },
{ label: 'No', id: 'false' },
],
condition: { field: 'operation', value: 'partial_update_record' },
value: () => 'true',
mode: 'advanced',
},
// Batch operations field
{
id: 'requests',
title: 'Batch Requests',
type: 'long-input',
placeholder:
'[{"action": "addObject", "body": {"name": "Item"}}, {"action": "deleteObject", "body": {"objectID": "123"}}]',
condition: { field: 'operation', value: 'batch_operations' },
required: { field: 'operation', value: 'batch_operations' },
wandConfig: {
enabled: true,
prompt: `Generate a JSON array of Algolia batch operations based on the user's description.
### CONTEXT
{context}
### GUIDELINES
- Return ONLY a valid JSON array starting with [ and ending with ]
- Each item must have "action" and "body" properties
- Valid actions: addObject, updateObject, partialUpdateObject, partialUpdateObjectNoCreate, deleteObject, delete, clear
- For deleteObject, body must include objectID
- For updateObject, body must include objectID
- For addObject, objectID is optional (auto-generated if omitted)
### EXAMPLE
User: "Add two products and delete one with ID old-123"
Output:
[
{"action": "addObject", "body": {"name": "Product A", "price": 19.99}},
{"action": "addObject", "body": {"name": "Product B", "price": 29.99}},
{"action": "deleteObject", "body": {"objectID": "old-123"}}
]
Return ONLY the JSON array.`,
placeholder: 'Describe the batch operations to perform...',
generationType: 'json-object',
},
},
// Update settings fields
{
id: 'settings',
title: 'Settings',
type: 'long-input',
placeholder:
'{"searchableAttributes": ["name", "description"], "customRanking": ["desc(popularity)"]}',
condition: { field: 'operation', value: 'update_settings' },
required: { field: 'operation', value: 'update_settings' },
wandConfig: {
enabled: true,
prompt: `Generate a valid Algolia index settings JSON object based on the user's description.
### CONTEXT
{context}
### GUIDELINES
- Return ONLY a valid JSON object starting with { and ending with }
- Common settings include:
- searchableAttributes: array of attribute names (ordered by priority)
- attributesForFaceting: array of attributes for filtering/faceting (prefix with "filterOnly(" or "searchable(" as needed)
- customRanking: array of "asc(attr)" or "desc(attr)" expressions
- ranking: array of ranking criteria (e.g., "typo", "geo", "words", "filters", "proximity", "attribute", "exact", "custom")
- replicas: array of replica index names
- hitsPerPage: number of results per page
- paginationLimitedTo: max pagination depth
- highlightPreTag / highlightPostTag: HTML tags for highlighting
### EXAMPLE
User: "Make name and description searchable, add category faceting, rank by popularity"
Output:
{"searchableAttributes": ["name", "description"], "attributesForFaceting": ["category"], "customRanking": ["desc(popularity)"]}
Return ONLY the JSON object.`,
placeholder: 'Describe the settings to apply...',
generationType: 'json-object',
},
},
{
id: 'forwardToReplicas',
title: 'Forward to Replicas',
type: 'dropdown',
options: [
{ label: 'No', id: 'false' },
{ label: 'Yes', id: 'true' },
],
condition: { field: 'operation', value: 'update_settings' },
value: () => 'false',
mode: 'advanced',
},
// Copy/Move index fields
{
id: 'copyMoveOperation',
title: 'Copy or Move',
type: 'dropdown',
options: [
{ label: 'Copy', id: 'copy' },
{ label: 'Move', id: 'move' },
],
condition: { field: 'operation', value: 'copy_move_index' },
value: () => 'copy',
},
{
id: 'destination',
title: 'Destination Index',
type: 'short-input',
placeholder: 'my_index_backup',
condition: { field: 'operation', value: 'copy_move_index' },
required: { field: 'operation', value: 'copy_move_index' },
},
{
id: 'scope',
title: 'Scope (Copy Only)',
type: 'short-input',
placeholder: '["settings", "synonyms", "rules"]',
condition: { field: 'operation', value: 'copy_move_index' },
mode: 'advanced',
wandConfig: {
enabled: true,
prompt: `Generate a JSON array of Algolia copy scopes based on the user's description.
### CONTEXT
{context}
### GUIDELINES
- Return ONLY a valid JSON array
- Valid scope values: "settings", "synonyms", "rules"
- Omitting scope copies everything including records
- Only applies to copy operations, not move
### EXAMPLE
User: "Copy only settings and synonyms"
Output:
["settings", "synonyms"]
Return ONLY the JSON array.`,
placeholder: 'Describe what to copy...',
generationType: 'json-object',
},
},
// Delete by filter fields
{
id: 'deleteFilters',
title: 'Filter Expression',
type: 'short-input',
placeholder: 'category:outdated AND price < 10',
condition: { field: 'operation', value: 'delete_by_filter' },
required: { field: 'operation', value: 'delete_by_filter' },
wandConfig: {
enabled: true,
prompt: `Generate an Algolia filter expression for deleting records based on the user's description.
Available operators: AND, OR, NOT
Comparison: =, !=, <, >, <=, >=
Facet filters: attribute:value
Numeric filters: attribute operator value
Examples:
- "category:outdated AND price < 10"
- "status:archived OR lastUpdated < 1609459200"
- "NOT category:active"
Return ONLY the filter string, no quotes or explanation.`,
},
},
{
id: 'facetFilters',
title: 'Facet Filters',
type: 'short-input',
placeholder: '["brand:Acme"]',
condition: { field: 'operation', value: 'delete_by_filter' },
mode: 'advanced',
},
{
id: 'numericFilters',
title: 'Numeric Filters',
type: 'short-input',
placeholder: '["price > 100"]',
condition: { field: 'operation', value: 'delete_by_filter' },
mode: 'advanced',
},
{
id: 'tagFilters',
title: 'Tag Filters',
type: 'short-input',
placeholder: '["published", "archived"]',
condition: { field: 'operation', value: 'delete_by_filter' },
mode: 'advanced',
},
{
id: 'aroundLatLng',
title: 'Around Lat/Lng',
type: 'short-input',
placeholder: '40.71,-74.01',
condition: { field: 'operation', value: 'delete_by_filter' },
mode: 'advanced',
},
{
id: 'aroundRadius',
title: 'Around Radius (m)',
type: 'short-input',
placeholder: '1000 or "all"',
condition: { field: 'operation', value: 'delete_by_filter' },
mode: 'advanced',
},
{
id: 'insideBoundingBox',
title: 'Inside Bounding Box',
type: 'short-input',
placeholder: '[[47.3165,0.757,47.3424,0.8012]]',
condition: { field: 'operation', value: 'delete_by_filter' },
mode: 'advanced',
},
{
id: 'insidePolygon',
title: 'Inside Polygon',
type: 'short-input',
placeholder: '[[47.3165,0.757,47.3424,0.8012,47.33,0.78]]',
condition: { field: 'operation', value: 'delete_by_filter' },
mode: 'advanced',
},
// Get records (batch) field
{
id: 'getRecordsRequests',
title: 'Record Requests',
type: 'long-input',
placeholder: '[{"objectID": "id1"}, {"objectID": "id2", "attributesToRetrieve": ["name"]}]',
condition: { field: 'operation', value: 'get_records' },
required: { field: 'operation', value: 'get_records' },
wandConfig: {
enabled: true,
prompt: `Generate a JSON array of Algolia get-records requests based on the user's description.
### CONTEXT
{context}
### GUIDELINES
- Return ONLY a valid JSON array starting with [ and ending with ]
- Each item must have "objectID" (required)
- Optionally include "indexName" to fetch from a different index
- Optionally include "attributesToRetrieve" as an array of attribute names
### EXAMPLE
User: "Get products with IDs abc and xyz, only returning name and price"
Output:
[{"objectID": "abc", "attributesToRetrieve": ["name", "price"]}, {"objectID": "xyz", "attributesToRetrieve": ["name", "price"]}]
Return ONLY the JSON array.`,
placeholder: 'Describe the records to retrieve...',
generationType: 'json-object',
},
},
// List indices pagination
{
id: 'listPage',
title: 'Page',
type: 'short-input',
placeholder: '0',
condition: { field: 'operation', value: 'list_indices' },
mode: 'advanced',
},
{
id: 'listHitsPerPage',
title: 'Indices Per Page',
type: 'short-input',
placeholder: '100',
condition: { field: 'operation', value: 'list_indices' },
mode: 'advanced',
},
// Object ID - for add (optional), get, partial update, delete
{
id: 'objectID',
title: 'Object ID',
type: 'short-input',
placeholder: 'my-record-123',
condition: {
field: 'operation',
value: ['add_record', 'get_record', 'partial_update_record', 'delete_record'],
},
required: {
field: 'operation',
value: ['get_record', 'partial_update_record', 'delete_record'],
},
},
// Common credentials
{
id: 'applicationId',
title: 'Application ID',
type: 'short-input',
placeholder: 'Your Algolia Application ID',
password: true,
required: true,
},
{
id: 'apiKey',
title: 'API Key',
type: 'short-input',
placeholder: 'Your Algolia API Key',
password: true,
required: true,
},
],
tools: {
access: [
'algolia_search',
'algolia_add_record',
'algolia_get_record',
'algolia_get_records',
'algolia_partial_update_record',
'algolia_delete_record',
'algolia_browse_records',
'algolia_batch_operations',
'algolia_list_indices',
'algolia_get_settings',
'algolia_update_settings',
'algolia_delete_index',
'algolia_copy_move_index',
'algolia_clear_records',
'algolia_delete_by_filter',
],
config: {
tool: (params: Record<string, unknown>) => {
const op = params.operation as string
if (op === 'partial_update_record') {
params.createIfNotExists = params.createIfNotExists !== 'false'
}
if (op === 'update_settings' && params.forwardToReplicas === 'true') {
params.forwardToReplicas = true
} else if (op === 'update_settings') {
params.forwardToReplicas = false
}
if (op === 'copy_move_index') {
params.operation = params.copyMoveOperation
}
if (op === 'delete_by_filter') {
params.filters = params.deleteFilters
}
if (op === 'get_records') {
params.requests = params.getRecordsRequests
}
if (op === 'list_indices') {
if (params.listPage !== undefined) params.page = params.listPage
if (params.listHitsPerPage !== undefined) params.hitsPerPage = params.listHitsPerPage
}
return `algolia_${op}`
},
},
},
inputs: {
operation: { type: 'string', description: 'Operation to perform' },
indexName: { type: 'string', description: 'Algolia index name' },
query: { type: 'string', description: 'Search query' },
hitsPerPage: { type: 'string', description: 'Number of hits per page' },
page: { type: 'string', description: 'Page number' },
filters: { type: 'string', description: 'Algolia filter string' },
attributesToRetrieve: { type: 'string', description: 'Attributes to retrieve' },
cursor: { type: 'string', description: 'Browse cursor for pagination' },
record: { type: 'json', description: 'Record data to add' },
attributes: { type: 'json', description: 'Attributes to partially update' },
createIfNotExists: { type: 'string', description: 'Create record if not exists' },
requests: { type: 'json', description: 'Batch operation requests' },
settings: { type: 'json', description: 'Index settings to update' },
forwardToReplicas: { type: 'string', description: 'Forward settings to replicas' },
objectID: { type: 'string', description: 'Object ID' },
copyMoveOperation: { type: 'string', description: 'Copy or move operation' },
destination: { type: 'string', description: 'Destination index name' },
scope: { type: 'json', description: 'Scopes to copy (settings, synonyms, rules)' },
deleteFilters: { type: 'string', description: 'Filter expression for delete by filter' },
facetFilters: { type: 'json', description: 'Facet filters for delete by filter' },
numericFilters: { type: 'json', description: 'Numeric filters for delete by filter' },
tagFilters: {
type: 'json',
description: 'Tag filters using the _tags attribute for delete by filter',
},
aroundLatLng: { type: 'string', description: 'Geo-search coordinates (lat,lng)' },
aroundRadius: { type: 'string', description: 'Geo-search radius in meters or "all"' },
insideBoundingBox: { type: 'json', description: 'Bounding box coordinates for geo-search' },
insidePolygon: { type: 'json', description: 'Polygon coordinates for geo-search' },
getRecordsRequests: {
type: 'json',
description: 'Array of objects with objectID to retrieve multiple records',
},
listPage: { type: 'string', description: 'Page number for list indices pagination' },
listHitsPerPage: { type: 'string', description: 'Indices per page for list indices' },
applicationId: { type: 'string', description: 'Algolia Application ID' },
apiKey: { type: 'string', description: 'Algolia API Key' },
},
outputs: {
hits: { type: 'array', description: 'Search result hits or browsed records' },
nbHits: { type: 'number', description: 'Total number of hits' },
page: { type: 'number', description: 'Current page number (zero-based)' },
nbPages: { type: 'number', description: 'Total number of pages available' },
hitsPerPage: { type: 'number', description: 'Number of hits per page' },
processingTimeMS: {
type: 'number',
description: 'Server-side processing time in milliseconds',
},
query: { type: 'string', description: 'Search query that was executed' },
parsedQuery: { type: 'string', description: 'Query after normalization and stop word removal' },
facets: { type: 'json', description: 'Facet counts by facet name' },
facets_stats: {
type: 'json',
description: 'Statistics (min, max, avg, sum) for numeric facets',
},
exhaustive: { type: 'json', description: 'Exhaustiveness flags for the search results' },
taskID: { type: 'number', description: 'Algolia task ID for tracking async operations' },
objectID: { type: 'string', description: 'Object ID of the affected record' },
objectIDs: { type: 'array', description: 'Object IDs affected by batch operations' },
createdAt: { type: 'string', description: 'ISO 8601 timestamp when the record was created' },
updatedAt: {
type: 'string',
description: 'ISO 8601 timestamp when the record or settings were updated',
},
deletedAt: {
type: 'string',
description: 'ISO 8601 timestamp when the record or index was deleted',
},
record: { type: 'json', description: 'Retrieved record data (user-defined attributes)' },
results: { type: 'array', description: 'Array of retrieved records from get_records' },
cursor: {
type: 'string',
description:
'Opaque cursor string for retrieving the next page of browse results. Absent when no more results exist.',
},
indices: { type: 'array', description: 'List of indices in the application' },
searchableAttributes: { type: 'array', description: 'List of searchable attributes' },
attributesForFaceting: { type: 'array', description: 'Attributes configured for faceting' },
ranking: { type: 'array', description: 'Ranking criteria for the index' },
customRanking: { type: 'array', description: 'Custom ranking criteria' },
replicas: { type: 'array', description: 'List of replica index names' },
maxValuesPerFacet: {
type: 'number',
description: 'Maximum number of facet values returned (default 100)',
},
highlightPreTag: {
type: 'string',
description: 'HTML tag inserted before highlighted parts (default "<em>")',
},
highlightPostTag: {
type: 'string',
description: 'HTML tag inserted after highlighted parts (default "</em>")',
},
paginationLimitedTo: {
type: 'number',
description: 'Maximum number of hits accessible via pagination (default 1000)',
},
},
}

View File

@@ -110,11 +110,6 @@ export const ArxivBlock: BlockConfig<ArxivResponse> = {
access: ['arxiv_search', 'arxiv_get_paper', 'arxiv_get_author_papers'],
config: {
tool: (params) => {
// Convert maxResults to a number for operations that use it
if (params.maxResults) {
params.maxResults = Number(params.maxResults)
}
switch (params.operation) {
case 'arxiv_search':
return 'arxiv_search'
@@ -126,6 +121,11 @@ export const ArxivBlock: BlockConfig<ArxivResponse> = {
return 'arxiv_search'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.maxResults) result.maxResults = Number(params.maxResults)
return result
},
},
},
inputs: {

View File

@@ -309,20 +309,6 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
],
config: {
tool: (params) => {
// Convert numeric params
if (params.limit) {
params.limit = Number(params.limit)
}
if (params.maxResults) {
params.maxResults = Number(params.maxResults)
}
// Normalize file input for upload operation - use canonical 'file' param
const normalizedFile = normalizeFileInput(params.file, { single: true })
if (normalizedFile) {
params.file = normalizedFile
}
switch (params.operation) {
case 'dropbox_upload':
return 'dropbox_upload'
@@ -348,6 +334,16 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
return 'dropbox_upload'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.limit) result.limit = Number(params.limit)
if (params.maxResults) result.maxResults = Number(params.maxResults)
const normalizedFile = normalizeFileInput(params.file, { single: true })
if (normalizedFile) {
result.file = normalizedFile
}
return result
},
},
},
inputs: {

View File

@@ -457,24 +457,19 @@ Return ONLY valid JSON - no explanations, no markdown code blocks.`,
],
config: {
tool: (params) => {
// Convert numeric strings to numbers
if (params.size) {
params.size = Number(params.size)
}
if (params.from) {
params.from = Number(params.from)
}
if (params.retryOnConflict) {
params.retryOnConflict = Number(params.retryOnConflict)
}
// Append 's' to timeout for Elasticsearch time format
if (params.timeout && !params.timeout.endsWith('s')) {
params.timeout = `${params.timeout}s`
}
// Return the operation as the tool ID
return params.operation || 'elasticsearch_search'
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.size) result.size = Number(params.size)
if (params.from) result.from = Number(params.from)
if (params.retryOnConflict) result.retryOnConflict = Number(params.retryOnConflict)
if (params.timeout && typeof params.timeout === 'string') {
result.timeout = params.timeout.endsWith('s') ? params.timeout : `${params.timeout}s`
}
return result
},
},
},

View File

@@ -49,6 +49,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
title: 'Use Autoprompt',
type: 'switch',
condition: { field: 'operation', value: 'exa_search' },
mode: 'advanced',
},
{
id: 'type',
@@ -62,6 +63,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
],
value: () => 'auto',
condition: { field: 'operation', value: 'exa_search' },
mode: 'advanced',
},
{
id: 'includeDomains',
@@ -69,6 +71,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
type: 'long-input',
placeholder: 'example.com, another.com (comma-separated)',
condition: { field: 'operation', value: 'exa_search' },
mode: 'advanced',
},
{
id: 'excludeDomains',
@@ -76,6 +79,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
type: 'long-input',
placeholder: 'exclude.com, another.com (comma-separated)',
condition: { field: 'operation', value: 'exa_search' },
mode: 'advanced',
},
{
id: 'category',
@@ -95,6 +99,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
],
value: () => '',
condition: { field: 'operation', value: 'exa_search' },
mode: 'advanced',
},
{
id: 'text',
@@ -107,12 +112,14 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
title: 'Include Highlights',
type: 'switch',
condition: { field: 'operation', value: 'exa_search' },
mode: 'advanced',
},
{
id: 'summary',
title: 'Include Summary',
type: 'switch',
condition: { field: 'operation', value: 'exa_search' },
mode: 'advanced',
},
{
id: 'livecrawl',
@@ -125,6 +132,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
],
value: () => 'never',
condition: { field: 'operation', value: 'exa_search' },
mode: 'advanced',
},
// Get Contents operation inputs
{
@@ -147,6 +155,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
type: 'long-input',
placeholder: 'Enter a query to guide the summary generation...',
condition: { field: 'operation', value: 'exa_get_contents' },
mode: 'advanced',
},
{
id: 'subpages',
@@ -154,6 +163,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
type: 'short-input',
placeholder: '5',
condition: { field: 'operation', value: 'exa_get_contents' },
mode: 'advanced',
},
{
id: 'subpageTarget',
@@ -161,12 +171,14 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
type: 'long-input',
placeholder: 'docs, tutorial, about (comma-separated)',
condition: { field: 'operation', value: 'exa_get_contents' },
mode: 'advanced',
},
{
id: 'highlights',
title: 'Include Highlights',
type: 'switch',
condition: { field: 'operation', value: 'exa_get_contents' },
mode: 'advanced',
},
// Find Similar Links operation inputs
{
@@ -196,6 +208,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
type: 'long-input',
placeholder: 'example.com, another.com (comma-separated)',
condition: { field: 'operation', value: 'exa_find_similar_links' },
mode: 'advanced',
},
{
id: 'excludeDomains',
@@ -203,12 +216,14 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
type: 'long-input',
placeholder: 'exclude.com, another.com (comma-separated)',
condition: { field: 'operation', value: 'exa_find_similar_links' },
mode: 'advanced',
},
{
id: 'excludeSourceDomain',
title: 'Exclude Source Domain',
type: 'switch',
condition: { field: 'operation', value: 'exa_find_similar_links' },
mode: 'advanced',
},
{
id: 'category',
@@ -228,18 +243,21 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
],
value: () => '',
condition: { field: 'operation', value: 'exa_find_similar_links' },
mode: 'advanced',
},
{
id: 'highlights',
title: 'Include Highlights',
type: 'switch',
condition: { field: 'operation', value: 'exa_find_similar_links' },
mode: 'advanced',
},
{
id: 'summary',
title: 'Include Summary',
type: 'switch',
condition: { field: 'operation', value: 'exa_find_similar_links' },
mode: 'advanced',
},
{
id: 'livecrawl',
@@ -252,6 +270,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
],
value: () => 'never',
condition: { field: 'operation', value: 'exa_find_similar_links' },
mode: 'advanced',
},
// Answer operation inputs
{
@@ -267,6 +286,7 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
title: 'Include Text',
type: 'switch',
condition: { field: 'operation', value: 'exa_answer' },
mode: 'advanced',
},
// Research operation inputs
{
@@ -309,16 +329,6 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
],
config: {
tool: (params) => {
// Convert numResults to a number for operations that use it
if (params.numResults) {
params.numResults = Number(params.numResults)
}
// Convert subpages to a number if provided
if (params.subpages) {
params.subpages = Number(params.subpages)
}
switch (params.operation) {
case 'exa_search':
return 'exa_search'
@@ -334,6 +344,16 @@ export const ExaBlock: BlockConfig<ExaResponse> = {
return 'exa_search'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.numResults) {
result.numResults = Number(params.numResults)
}
if (params.subpages) {
result.subpages = Number(params.subpages)
}
return result
},
},
},
inputs: {

View File

@@ -606,45 +606,23 @@ Return ONLY the folder title - no explanations, no quotes, no extra text.`,
],
config: {
tool: (params) => {
// Convert numeric string fields to numbers
if (params.panelId) {
params.panelId = Number(params.panelId)
}
if (params.annotationId) {
params.annotationId = Number(params.annotationId)
}
if (params.time) {
params.time = Number(params.time)
}
if (params.timeEnd) {
params.timeEnd = Number(params.timeEnd)
}
if (params.from) {
params.from = Number(params.from)
}
if (params.to) {
params.to = Number(params.to)
}
// Map subblock fields to tool parameter names
if (params.alertTitle) {
params.title = params.alertTitle
}
if (params.folderTitle) {
params.title = params.folderTitle
}
if (params.folderUidNew) {
params.uid = params.folderUidNew
}
if (params.annotationTags) {
params.tags = params.annotationTags
}
if (params.annotationDashboardUid) {
params.dashboardUid = params.annotationDashboardUid
}
if (params.alertTitle) params.title = params.alertTitle
if (params.folderTitle) params.title = params.folderTitle
if (params.folderUidNew) params.uid = params.folderUidNew
if (params.annotationTags) params.tags = params.annotationTags
if (params.annotationDashboardUid) params.dashboardUid = params.annotationDashboardUid
return params.operation
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.panelId) result.panelId = Number(params.panelId)
if (params.annotationId) result.annotationId = Number(params.annotationId)
if (params.time) result.time = Number(params.time)
if (params.timeEnd) result.timeEnd = Number(params.timeEnd)
if (params.from) result.from = Number(params.from)
if (params.to) result.to = Number(params.to)
return result
},
},
},
inputs: {

View File

@@ -204,11 +204,6 @@ Return ONLY the search query text - no explanations.`,
],
config: {
tool: (params) => {
// Convert numeric parameters
if (params.limit) {
params.limit = Number(params.limit)
}
switch (params.operation) {
case 'hunter_discover':
return 'hunter_discover'
@@ -226,6 +221,11 @@ Return ONLY the search query text - no explanations.`,
return 'hunter_domain_search'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.limit) result.limit = Number(params.limit)
return result
},
},
},
inputs: {

View File

@@ -826,16 +826,6 @@ Return ONLY the JSON array - no explanations or markdown formatting.`,
],
config: {
tool: (params) => {
// Convert page_size to a number if provided
if (params.page_size) {
params.page_size = Number(params.page_size)
}
// Convert notify_incident_channel from string to boolean
if (params.notify_incident_channel !== undefined) {
params.notify_incident_channel = params.notify_incident_channel === 'true'
}
switch (params.operation) {
case 'incidentio_incidents_list':
return 'incidentio_incidents_list'
@@ -929,6 +919,14 @@ Return ONLY the JSON array - no explanations or markdown formatting.`,
return 'incidentio_incidents_list'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.page_size) result.page_size = Number(params.page_size)
if (params.notify_incident_channel !== undefined) {
result.notify_incident_channel = params.notify_incident_channel === 'true'
}
return result
},
},
},
inputs: {

View File

@@ -100,6 +100,19 @@ export const JiraServiceManagementBlock: BlockConfig<JsmResponse> = {
title: 'Service Desk ID',
type: 'short-input',
placeholder: 'Enter service desk ID',
required: {
field: 'operation',
value: [
'get_request_types',
'create_request',
'get_customers',
'add_customer',
'get_organizations',
'add_organization',
'get_queues',
'get_request_type_fields',
],
},
condition: {
field: 'operation',
value: [
@@ -207,9 +220,10 @@ Return ONLY the description text - no explanations.`,
},
{
id: 'requestFieldValues',
title: 'Custom Field Values',
title: 'Request Field Values',
type: 'long-input',
placeholder: 'JSON object of custom field values (e.g., {"customfield_10010": "value"})',
placeholder:
'JSON object of field values (e.g., {"summary": "Title", "customfield_10010": "value"})',
condition: { field: 'operation', value: 'create_request' },
},
{
@@ -775,7 +789,7 @@ Return ONLY the comment text - no explanations.`,
description: 'Comma-separated account IDs for request participants',
},
channel: { type: 'string', description: 'Channel (e.g., portal, email)' },
requestFieldValues: { type: 'string', description: 'JSON object of custom field values' },
requestFieldValues: { type: 'string', description: 'JSON object of request field values' },
searchQuery: { type: 'string', description: 'Filter request types by name' },
groupId: { type: 'string', description: 'Filter by request type group ID' },
expand: { type: 'string', description: 'Comma-separated fields to expand' },

View File

@@ -26,15 +26,29 @@ export const KnowledgeBlock: BlockConfig = {
],
value: () => 'search',
},
// Knowledge base selector - basic mode
{
id: 'knowledgeBaseId',
id: 'knowledgeBaseSelector',
title: 'Knowledge Base',
type: 'knowledge-base-selector',
canonicalParamId: 'knowledgeBaseId',
mode: 'basic',
placeholder: 'Select knowledge base',
multiSelect: false,
required: true,
condition: { field: 'operation', value: ['search', 'upload_chunk', 'create_document'] },
},
// Knowledge base ID manual input - advanced mode
{
id: 'manualKnowledgeBaseId',
title: 'Knowledge Base ID',
type: 'short-input',
canonicalParamId: 'knowledgeBaseId',
mode: 'advanced',
placeholder: 'Enter knowledge base ID',
required: true,
condition: { field: 'operation', value: ['search', 'upload_chunk', 'create_document'] },
},
{
id: 'query',
title: 'Search Query',

View File

@@ -169,17 +169,7 @@ export const LemlistBlock: BlockConfig<LemlistResponse> = {
access: ['lemlist_get_activities', 'lemlist_get_lead', 'lemlist_send_email'],
config: {
tool: (params) => {
if (params.limit) {
params.limit = Number(params.limit)
}
if (params.offset) {
params.offset = Number(params.offset)
}
// Map filterLeadId to leadId for get_activities tool
if (params.filterLeadId) {
params.leadId = params.filterLeadId
}
if (params.filterLeadId) params.leadId = params.filterLeadId
switch (params.operation) {
case 'get_activities':
return 'lemlist_get_activities'
@@ -191,6 +181,12 @@ export const LemlistBlock: BlockConfig<LemlistResponse> = {
return 'lemlist_get_activities'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.limit) result.limit = Number(params.limit)
if (params.offset) result.offset = Number(params.offset)
return result
},
},
},
inputs: {

View File

@@ -149,66 +149,48 @@ export const ParallelBlock: BlockConfig<ToolResponse> = {
access: ['parallel_search', 'parallel_extract', 'parallel_deep_research'],
config: {
tool: (params) => {
if (params.extract_objective) params.objective = params.extract_objective
if (params.research_input) params.input = params.research_input
switch (params.operation) {
case 'search':
// Convert search_queries from comma-separated string to array (if provided)
if (params.search_queries && typeof params.search_queries === 'string') {
const queries = params.search_queries
.split(',')
.map((query: string) => query.trim())
.filter((query: string) => query.length > 0)
// Only set if we have actual queries
if (queries.length > 0) {
params.search_queries = queries
} else {
params.search_queries = undefined
}
}
// Convert numeric parameters
if (params.max_results) {
params.max_results = Number(params.max_results)
}
if (params.max_chars_per_result) {
params.max_chars_per_result = Number(params.max_chars_per_result)
}
return 'parallel_search'
case 'extract':
// Map extract_objective to objective for the tool
params.objective = params.extract_objective
// Convert boolean strings to actual booleans with defaults
if (params.excerpts === 'true' || params.excerpts === true) {
params.excerpts = true
} else if (params.excerpts === 'false' || params.excerpts === false) {
params.excerpts = false
} else {
// Default to true if not provided
params.excerpts = true
}
if (params.full_content === 'true' || params.full_content === true) {
params.full_content = true
} else if (params.full_content === 'false' || params.full_content === false) {
params.full_content = false
} else {
// Default to false if not provided
params.full_content = false
}
return 'parallel_extract'
case 'deep_research':
// Map research_input to input for the tool
params.input = params.research_input
return 'parallel_deep_research'
default:
return 'parallel_search'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
const operation = params.operation
if (operation === 'search') {
if (params.search_queries && typeof params.search_queries === 'string') {
const queries = params.search_queries
.split(',')
.map((query: string) => query.trim())
.filter((query: string) => query.length > 0)
if (queries.length > 0) {
result.search_queries = queries
} else {
result.search_queries = undefined
}
}
if (params.max_results) result.max_results = Number(params.max_results)
if (params.max_chars_per_result) {
result.max_chars_per_result = Number(params.max_chars_per_result)
}
}
if (operation === 'extract') {
result.excerpts = !(params.excerpts === 'false' || params.excerpts === false)
result.full_content = params.full_content === 'true' || params.full_content === true
}
return result
},
},
},
inputs: {

View File

@@ -1185,22 +1185,15 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
],
config: {
tool: (params) => {
// Convert numeric parameters
if (params.limit) params.limit = Number(params.limit)
if (params.offset) params.offset = Number(params.offset)
if (params.rolloutPercentage) params.rolloutPercentage = Number(params.rolloutPercentage)
// Map projectIdParam to projectId for get_project operation
// Field renames in tool() are safe (they copy values, not coerce types)
// and are needed for serialization-time validation of required fields
if (params.operation === 'posthog_get_project' && params.projectIdParam) {
params.projectId = params.projectIdParam
}
// Map personalApiKey to apiKey for all private endpoint tools
if (params.personalApiKey) {
params.apiKey = params.personalApiKey
}
// Map featureFlagId to flagId for feature flag operations
const flagOps = [
'posthog_get_feature_flag',
'posthog_update_feature_flag',
@@ -1210,7 +1203,6 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
params.flagId = params.featureFlagId
}
// Map surveyType to type for survey operations
if (
(params.operation === 'posthog_create_survey' ||
params.operation === 'posthog_update_survey') &&
@@ -1219,37 +1211,30 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
params.type = params.surveyType
}
// Map isStatic for cohorts
if (params.operation === 'posthog_create_cohort' && params.isStatic !== undefined) {
params.is_static = params.isStatic
}
// Map dateMarker to date_marker for annotations
if (params.operation === 'posthog_create_annotation' && params.dateMarker) {
params.date_marker = params.dateMarker
}
// Map propertyType to property_type
if (params.operation === 'posthog_update_property_definition' && params.propertyType) {
params.property_type = params.propertyType
}
// Map insightQuery to query for insights
if (params.operation === 'posthog_create_insight' && params.insightQuery) {
params.query = params.insightQuery
}
// Map insightTags to tags for insights
if (params.operation === 'posthog_create_insight' && params.insightTags) {
params.tags = params.insightTags
}
// Map distinctIdFilter to distinctId for list_persons
if (params.operation === 'posthog_list_persons' && params.distinctIdFilter) {
params.distinctId = params.distinctIdFilter
}
// Map experiment date fields
if (params.operation === 'posthog_create_experiment') {
if (params.experimentStartDate) {
params.startDate = params.experimentStartDate
@@ -1259,7 +1244,6 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
}
}
// Map survey date fields
if (
params.operation === 'posthog_create_survey' ||
params.operation === 'posthog_update_survey'
@@ -1272,13 +1256,17 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
}
}
// Convert responsesLimit to number
if (params.responsesLimit) {
params.responsesLimit = Number(params.responsesLimit)
}
return params.operation as string
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.limit) result.limit = Number(params.limit)
if (params.offset) result.offset = Number(params.offset)
if (params.rolloutPercentage) result.rolloutPercentage = Number(params.rolloutPercentage)
if (params.responsesLimit) result.responsesLimit = Number(params.responsesLimit)
return result
},
},
},

View File

@@ -0,0 +1,320 @@
import { RedisIcon } from '@/components/icons'
import type { BlockConfig } from '@/blocks/types'
import { AuthMode } from '@/blocks/types'
import type {
RedisCommandResponse,
RedisDeleteResponse,
RedisExistsResponse,
RedisExpireResponse,
RedisGetResponse,
RedisHDelResponse,
RedisHGetAllResponse,
RedisHGetResponse,
RedisHSetResponse,
RedisIncrbyResponse,
RedisIncrResponse,
RedisKeysResponse,
RedisLLenResponse,
RedisLPopResponse,
RedisLPushResponse,
RedisLRangeResponse,
RedisPersistResponse,
RedisRPopResponse,
RedisRPushResponse,
RedisSetnxResponse,
RedisSetResponse,
RedisTtlResponse,
} from '@/tools/redis/types'
type RedisResponse =
| RedisGetResponse
| RedisSetResponse
| RedisDeleteResponse
| RedisKeysResponse
| RedisCommandResponse
| RedisHSetResponse
| RedisHGetResponse
| RedisHGetAllResponse
| RedisHDelResponse
| RedisIncrResponse
| RedisIncrbyResponse
| RedisExpireResponse
| RedisTtlResponse
| RedisPersistResponse
| RedisLPushResponse
| RedisRPushResponse
| RedisLPopResponse
| RedisRPopResponse
| RedisLLenResponse
| RedisLRangeResponse
| RedisExistsResponse
| RedisSetnxResponse
const KEY_OPERATIONS = [
'get',
'set',
'delete',
'hset',
'hget',
'hgetall',
'hdel',
'incr',
'incrby',
'exists',
'setnx',
'lpush',
'rpush',
'lpop',
'rpop',
'llen',
'lrange',
'expire',
'persist',
'ttl',
] as const
export const RedisBlock: BlockConfig<RedisResponse> = {
type: 'redis',
name: 'Redis',
description: 'Key-value operations with Redis',
longDescription:
'Connect to any Redis instance to perform key-value, hash, list, and utility operations via a direct connection.',
docsLink: 'https://docs.sim.ai/tools/redis',
category: 'tools',
bgColor: '#FF4438',
authMode: AuthMode.ApiKey,
icon: RedisIcon,
subBlocks: [
{
id: 'operation',
title: 'Operation',
type: 'dropdown',
options: [
{ label: 'Get', id: 'get' },
{ label: 'Set', id: 'set' },
{ label: 'Delete', id: 'delete' },
{ label: 'List Keys', id: 'keys' },
{ label: 'HSET', id: 'hset' },
{ label: 'HGET', id: 'hget' },
{ label: 'HGETALL', id: 'hgetall' },
{ label: 'HDEL', id: 'hdel' },
{ label: 'INCR', id: 'incr' },
{ label: 'INCRBY', id: 'incrby' },
{ label: 'EXISTS', id: 'exists' },
{ label: 'SETNX', id: 'setnx' },
{ label: 'LPUSH', id: 'lpush' },
{ label: 'RPUSH', id: 'rpush' },
{ label: 'LPOP', id: 'lpop' },
{ label: 'RPOP', id: 'rpop' },
{ label: 'LLEN', id: 'llen' },
{ label: 'LRANGE', id: 'lrange' },
{ label: 'EXPIRE', id: 'expire' },
{ label: 'PERSIST', id: 'persist' },
{ label: 'TTL', id: 'ttl' },
{ label: 'Command', id: 'command' },
],
value: () => 'get',
},
{
id: 'url',
title: 'Connection URL',
type: 'short-input',
placeholder: 'redis://user:password@host:port',
password: true,
required: true,
},
{
id: 'key',
title: 'Key',
type: 'short-input',
placeholder: 'my-key',
condition: {
field: 'operation',
value: [...KEY_OPERATIONS],
},
required: {
field: 'operation',
value: [...KEY_OPERATIONS],
},
},
{
id: 'value',
title: 'Value',
type: 'long-input',
placeholder: 'Value to store',
condition: { field: 'operation', value: ['set', 'setnx', 'hset', 'lpush', 'rpush'] },
required: { field: 'operation', value: ['set', 'setnx', 'hset', 'lpush', 'rpush'] },
},
{
id: 'ex',
title: 'Expiration (seconds)',
type: 'short-input',
placeholder: 'Optional TTL in seconds',
condition: { field: 'operation', value: 'set' },
mode: 'advanced',
},
{
id: 'field',
title: 'Field',
type: 'short-input',
placeholder: 'Hash field name',
condition: { field: 'operation', value: ['hset', 'hget', 'hdel'] },
required: { field: 'operation', value: ['hset', 'hget', 'hdel'] },
},
{
id: 'pattern',
title: 'Pattern',
type: 'short-input',
placeholder: '* (all keys) or user:* (prefix match)',
condition: { field: 'operation', value: 'keys' },
mode: 'advanced',
},
{
id: 'seconds',
title: 'Seconds',
type: 'short-input',
placeholder: 'Timeout in seconds',
condition: { field: 'operation', value: 'expire' },
required: { field: 'operation', value: 'expire' },
},
{
id: 'increment',
title: 'Increment',
type: 'short-input',
placeholder: 'Amount to increment by (negative to decrement)',
condition: { field: 'operation', value: 'incrby' },
required: { field: 'operation', value: 'incrby' },
},
{
id: 'start',
title: 'Start Index',
type: 'short-input',
placeholder: '0',
condition: { field: 'operation', value: 'lrange' },
required: { field: 'operation', value: 'lrange' },
mode: 'advanced',
},
{
id: 'stop',
title: 'Stop Index',
type: 'short-input',
placeholder: '-1 (all elements)',
condition: { field: 'operation', value: 'lrange' },
required: { field: 'operation', value: 'lrange' },
mode: 'advanced',
},
{
id: 'command',
title: 'Command',
type: 'code',
placeholder: '["HSET", "myhash", "field1", "value1"]',
condition: { field: 'operation', value: 'command' },
required: { field: 'operation', value: 'command' },
},
],
tools: {
access: [
'redis_get',
'redis_set',
'redis_delete',
'redis_keys',
'redis_command',
'redis_hset',
'redis_hget',
'redis_hgetall',
'redis_hdel',
'redis_incr',
'redis_incrby',
'redis_expire',
'redis_ttl',
'redis_persist',
'redis_lpush',
'redis_rpush',
'redis_lpop',
'redis_rpop',
'redis_llen',
'redis_lrange',
'redis_exists',
'redis_setnx',
],
config: {
tool: (params) => {
if (params.ex) {
params.ex = Number(params.ex)
}
if (params.seconds !== undefined) {
params.seconds = Number(params.seconds)
}
if (params.start !== undefined) {
params.start = Number(params.start)
}
if (params.stop !== undefined) {
params.stop = Number(params.stop)
}
if (params.increment !== undefined) {
params.increment = Number(params.increment)
}
return `redis_${params.operation}`
},
},
},
inputs: {
operation: { type: 'string', description: 'Redis operation to perform' },
url: { type: 'string', description: 'Redis connection URL' },
key: { type: 'string', description: 'Redis key' },
value: { type: 'string', description: 'Value to store' },
ex: { type: 'number', description: 'Expiration time in seconds (SET)' },
field: { type: 'string', description: 'Hash field name (HSET/HGET/HDEL)' },
pattern: { type: 'string', description: 'Pattern to match keys (KEYS)' },
seconds: { type: 'number', description: 'Timeout in seconds (EXPIRE)' },
start: { type: 'number', description: 'Start index (LRANGE)' },
stop: { type: 'number', description: 'Stop index (LRANGE)' },
command: { type: 'string', description: 'Redis command as JSON array (Command)' },
increment: { type: 'number', description: 'Amount to increment by (INCRBY)' },
},
outputs: {
value: {
type: 'json',
description:
'Retrieved value (Get, HGET, LPOP, RPOP: string or null) or new value after increment (INCR, INCRBY: number)',
},
result: {
type: 'json',
description: 'Operation result (Set, HSET, EXPIRE, PERSIST, Command operations)',
},
deletedCount: { type: 'number', description: 'Number of keys deleted (Delete operation)' },
deleted: { type: 'number', description: 'Number of fields deleted (HDEL operation)' },
keys: { type: 'array', description: 'List of keys matching the pattern (Keys operation)' },
count: { type: 'number', description: 'Number of items found (Keys, LRANGE operations)' },
key: { type: 'string', description: 'The key operated on' },
fields: {
type: 'json',
description: 'Hash field-value pairs keyed by field name (HGETALL operation)',
},
fieldCount: { type: 'number', description: 'Number of fields in the hash (HGETALL operation)' },
field: { type: 'string', description: 'Hash field name (HSET, HGET, HDEL operations)' },
ttl: {
type: 'number',
description:
'Remaining TTL in seconds. Positive integer if TTL set, -1 if no expiration, -2 if key does not exist.',
},
length: {
type: 'number',
description: 'List length (LPUSH, RPUSH, LLEN operations)',
},
values: {
type: 'array',
description: 'List elements in the specified range (LRANGE operation)',
},
command: { type: 'string', description: 'The command that was executed (Command operation)' },
pattern: { type: 'string', description: 'The pattern used to match keys (Keys operation)' },
exists: {
type: 'boolean',
description: 'Whether the key exists (true) or not (false) (EXISTS operation)',
},
wasSet: {
type: 'boolean',
description: 'Whether the key was set (true) or already existed (false) (SETNX operation)',
},
},
}

View File

@@ -0,0 +1,327 @@
import { RevenueCatIcon } from '@/components/icons'
import type { BlockConfig } from '@/blocks/types'
import { AuthMode } from '@/blocks/types'
import type { RevenueCatResponse } from '@/tools/revenuecat/types'
export const RevenueCatBlock: BlockConfig<RevenueCatResponse> = {
type: 'revenuecat',
name: 'RevenueCat',
description: 'Manage in-app subscriptions and entitlements',
authMode: AuthMode.ApiKey,
longDescription:
'Integrate RevenueCat into the workflow. Manage subscribers, entitlements, offerings, and Google Play subscriptions. Retrieve customer subscription status, grant or revoke promotional entitlements, record purchases, update subscriber attributes, and manage Google Play subscription billing.',
docsLink: 'https://docs.sim.ai/tools/revenuecat',
category: 'tools',
bgColor: '#F25A5A',
icon: RevenueCatIcon,
subBlocks: [
{
id: 'operation',
title: 'Operation',
type: 'dropdown',
options: [
{ label: 'Get Customer', id: 'get_customer' },
{ label: 'Delete Customer', id: 'delete_customer' },
{ label: 'Create Purchase', id: 'create_purchase' },
{ label: 'Grant Entitlement', id: 'grant_entitlement' },
{ label: 'Revoke Entitlement', id: 'revoke_entitlement' },
{ label: 'List Offerings', id: 'list_offerings' },
{ label: 'Update Subscriber Attributes', id: 'update_subscriber_attributes' },
{ label: 'Defer Google Subscription', id: 'defer_google_subscription' },
{ label: 'Refund Google Subscription', id: 'refund_google_subscription' },
{ label: 'Revoke Google Subscription', id: 'revoke_google_subscription' },
],
value: () => 'get_customer',
},
{
id: 'apiKey',
title: 'API Key',
type: 'short-input',
password: true,
placeholder: 'Enter your RevenueCat API key',
required: true,
},
{
id: 'appUserId',
title: 'App User ID',
type: 'short-input',
placeholder: 'Enter the app user ID',
required: true,
},
{
id: 'entitlementIdentifier',
title: 'Entitlement Identifier',
type: 'short-input',
placeholder: 'e.g., premium, pro',
condition: {
field: 'operation',
value: ['grant_entitlement', 'revoke_entitlement'],
},
required: {
field: 'operation',
value: ['grant_entitlement', 'revoke_entitlement'],
},
},
{
id: 'duration',
title: 'Duration',
type: 'dropdown',
options: [
{ label: 'Daily', id: 'daily' },
{ label: '3 Days', id: 'three_day' },
{ label: 'Weekly', id: 'weekly' },
{ label: 'Monthly', id: 'monthly' },
{ label: '2 Months', id: 'two_month' },
{ label: '3 Months', id: 'three_month' },
{ label: '6 Months', id: 'six_month' },
{ label: 'Yearly', id: 'yearly' },
{ label: 'Lifetime', id: 'lifetime' },
],
value: () => 'monthly',
condition: {
field: 'operation',
value: 'grant_entitlement',
},
},
{
id: 'startTimeMs',
title: 'Start Time (ms)',
type: 'short-input',
placeholder: 'Optional start time in ms since epoch',
condition: {
field: 'operation',
value: 'grant_entitlement',
},
mode: 'advanced',
wandConfig: {
enabled: true,
prompt: `Generate a Unix epoch timestamp in milliseconds based on the user's description.
The timestamp should represent the start time of a promotional entitlement.
Setting a start time in the past allows shorter effective durations.
Examples:
- "right now" -> current time in milliseconds
- "1 hour ago" -> current time minus 3600000 milliseconds
- "yesterday" -> current time minus 86400000 milliseconds
Return ONLY the numeric timestamp, no text.`,
},
},
{
id: 'fetchToken',
title: 'Fetch Token',
type: 'short-input',
placeholder: 'Store receipt or purchase token (e.g., sub_...)',
condition: {
field: 'operation',
value: 'create_purchase',
},
required: {
field: 'operation',
value: 'create_purchase',
},
},
{
id: 'productId',
title: 'Product ID',
type: 'short-input',
placeholder: 'Product identifier',
condition: {
field: 'operation',
value: [
'create_purchase',
'defer_google_subscription',
'refund_google_subscription',
'revoke_google_subscription',
],
},
required: {
field: 'operation',
value: [
'create_purchase',
'defer_google_subscription',
'refund_google_subscription',
'revoke_google_subscription',
],
},
},
{
id: 'price',
title: 'Price',
type: 'short-input',
placeholder: 'e.g., 9.99',
condition: {
field: 'operation',
value: 'create_purchase',
},
mode: 'advanced',
},
{
id: 'currency',
title: 'Currency',
type: 'short-input',
placeholder: 'e.g., USD',
condition: {
field: 'operation',
value: 'create_purchase',
},
mode: 'advanced',
},
{
id: 'isRestore',
title: 'Is Restore',
type: 'dropdown',
options: [
{ label: 'No', id: 'false' },
{ label: 'Yes', id: 'true' },
],
value: () => 'false',
condition: {
field: 'operation',
value: 'create_purchase',
},
mode: 'advanced',
},
{
id: 'purchasePlatform',
title: 'Platform',
type: 'dropdown',
options: [
{ label: 'iOS', id: 'ios' },
{ label: 'Android', id: 'android' },
{ label: 'Amazon', id: 'amazon' },
{ label: 'macOS', id: 'macos' },
{ label: 'Stripe', id: 'stripe' },
],
condition: {
field: 'operation',
value: 'create_purchase',
},
mode: 'advanced',
},
{
id: 'attributes',
title: 'Attributes',
type: 'long-input',
placeholder: '{"$email": {"value": "user@example.com"}}',
condition: {
field: 'operation',
value: 'update_subscriber_attributes',
},
required: {
field: 'operation',
value: 'update_subscriber_attributes',
},
wandConfig: {
enabled: true,
prompt: `Generate a JSON object of RevenueCat subscriber attributes based on the user's description.
Each attribute key maps to an object with a "value" field.
Reserved attribute keys start with "$": $email, $displayName, $phoneNumber, $mediaSource, $campaign, $adGroup, $ad, $keyword, $creative, $iterableUserId, $iterableCampaignId, $iterableTemplateId, $onesignalId, $airshipChannelId, $cleverTapId, $firebaseAppInstanceId.
Custom attributes use plain keys without "$".
Examples:
- "set email to john@example.com and name to John" ->
{"$email": {"value": "john@example.com"}, "$displayName": {"value": "John"}}
- "set plan to premium and team to acme" ->
{"plan": {"value": "premium"}, "team": {"value": "acme"}}
Return ONLY valid JSON.`,
},
},
{
id: 'extendByDays',
title: 'Extend By Days',
type: 'short-input',
placeholder: 'Number of days to extend (1-365)',
condition: {
field: 'operation',
value: 'defer_google_subscription',
},
required: {
field: 'operation',
value: 'defer_google_subscription',
},
},
{
id: 'platform',
title: 'Platform',
type: 'dropdown',
options: [
{ label: 'iOS', id: 'ios' },
{ label: 'Android', id: 'android' },
{ label: 'Amazon', id: 'amazon' },
{ label: 'macOS', id: 'macos' },
{ label: 'Stripe', id: 'stripe' },
],
condition: {
field: 'operation',
value: 'list_offerings',
},
},
],
tools: {
access: [
'revenuecat_get_customer',
'revenuecat_delete_customer',
'revenuecat_create_purchase',
'revenuecat_grant_entitlement',
'revenuecat_revoke_entitlement',
'revenuecat_list_offerings',
'revenuecat_update_subscriber_attributes',
'revenuecat_defer_google_subscription',
'revenuecat_refund_google_subscription',
'revenuecat_revoke_google_subscription',
],
config: {
tool: (params) => {
if (params.purchasePlatform && params.operation === 'create_purchase') {
params.platform = params.purchasePlatform
}
if (params.isRestore !== undefined) {
params.isRestore = params.isRestore === 'true'
}
if (params.price !== undefined && params.price !== '') {
params.price = Number(params.price)
}
if (params.extendByDays !== undefined && params.extendByDays !== '') {
params.extendByDays = Number(params.extendByDays)
}
if (params.startTimeMs !== undefined && params.startTimeMs !== '') {
params.startTimeMs = Number(params.startTimeMs)
}
return `revenuecat_${params.operation}`
},
},
},
inputs: {
operation: { type: 'string', description: 'Operation to perform' },
apiKey: { type: 'string', description: 'RevenueCat API key' },
appUserId: { type: 'string', description: 'App user ID' },
entitlementIdentifier: { type: 'string', description: 'Entitlement identifier' },
duration: { type: 'string', description: 'Promotional entitlement duration' },
startTimeMs: { type: 'number', description: 'Custom start time in ms since epoch' },
fetchToken: { type: 'string', description: 'Store receipt or purchase token' },
productId: { type: 'string', description: 'Product identifier' },
price: { type: 'number', description: 'Product price' },
currency: { type: 'string', description: 'ISO 4217 currency code' },
isRestore: { type: 'boolean', description: 'Whether this is a restore purchase' },
purchasePlatform: { type: 'string', description: 'Platform for the purchase' },
attributes: { type: 'string', description: 'JSON object of subscriber attributes' },
extendByDays: { type: 'number', description: 'Number of days to extend (1-365)' },
platform: { type: 'string', description: 'Platform filter for offerings' },
},
outputs: {
subscriber: {
type: 'json',
description: 'Subscriber object with subscriptions and entitlements',
},
offerings: {
type: 'json',
description: 'Array of offerings with packages',
},
current_offering_id: { type: 'string', description: 'Current offering identifier' },
metadata: { type: 'json', description: 'Operation metadata' },
deleted: { type: 'boolean', description: 'Whether the subscriber was deleted' },
app_user_id: { type: 'string', description: 'The app user ID' },
updated: { type: 'boolean', description: 'Whether the attributes were updated' },
},
}

View File

@@ -602,11 +602,6 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
],
config: {
tool: (params) => {
// Convert numeric fields
if (params.limit) {
params.limit = Number(params.limit)
}
// Return the appropriate tool based on operation
switch (params.operation) {
case 'sentry_issues_list':
@@ -637,6 +632,11 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
return 'sentry_issues_list'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.limit) result.limit = Number(params.limit)
return result
},
},
},
inputs: {

View File

@@ -755,43 +755,24 @@ export const SpotifyBlock: BlockConfig<ToolResponse> = {
],
config: {
tool: (params) => {
// Convert numeric parameters
if (params.limit) {
params.limit = Number(params.limit)
}
if (params.volume_percent) {
params.volume_percent = Number(params.volume_percent)
}
if (params.range_start) {
params.range_start = Number(params.range_start)
}
if (params.insert_before) {
params.insert_before = Number(params.insert_before)
}
if (params.range_length) {
params.range_length = Number(params.range_length)
}
if (params.position_ms) {
params.position_ms = Number(params.position_ms)
}
// Map followType to type for check_following
if (params.followType) {
params.type = params.followType
}
// Map newName to name for update_playlist
if (params.newName) {
params.name = params.newName
}
// Map playUris to uris for play
if (params.playUris) {
params.uris = params.playUris
}
// Normalize file input for cover image
if (params.coverImage !== undefined) {
params.coverImage = normalizeFileInput(params.coverImage, { single: true })
}
if (params.followType) params.type = params.followType
if (params.newName) params.name = params.newName
if (params.playUris) params.uris = params.playUris
return params.operation || 'spotify_search'
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.limit) result.limit = Number(params.limit)
if (params.volume_percent) result.volume_percent = Number(params.volume_percent)
if (params.range_start) result.range_start = Number(params.range_start)
if (params.insert_before) result.insert_before = Number(params.insert_before)
if (params.range_length) result.range_length = Number(params.range_length)
if (params.position_ms) result.position_ms = Number(params.position_ms)
if (params.coverImage !== undefined) {
result.coverImage = normalizeFileInput(params.coverImage, { single: true })
}
return result
},
},
},
inputs: {

View File

@@ -94,6 +94,7 @@ export const SttBlock: BlockConfig<SttBlockResponse> = {
type: 'dropdown',
condition: { field: 'provider', value: 'gemini' },
options: [
{ label: 'Gemini 3.1 Pro', id: 'gemini-3.1-pro-preview' },
{ label: 'Gemini 3 Pro', id: 'gemini-3-pro-preview' },
{ label: 'Gemini 2.5 Pro', id: 'gemini-2.5-pro' },
{ label: 'Gemini 2.5 Flash', id: 'gemini-2.5-flash' },

View File

@@ -202,14 +202,26 @@ export const TableBlock: BlockConfig<TableQueryResponse> = {
value: () => 'query_rows',
},
// Table selector (for all operations)
// Table selector (for all operations) - basic mode
{
id: 'tableId',
id: 'tableSelector',
title: 'Table',
type: 'table-selector',
canonicalParamId: 'tableId',
mode: 'basic',
placeholder: 'Select a table',
required: true,
},
// Table ID manual input - advanced mode
{
id: 'manualTableId',
title: 'Table ID',
type: 'short-input',
canonicalParamId: 'tableId',
mode: 'advanced',
placeholder: 'Enter table ID',
required: true,
},
// Row ID for get/update/delete
{

View File

@@ -0,0 +1,313 @@
import { UpstashIcon } from '@/components/icons'
import type { BlockConfig } from '@/blocks/types'
import { AuthMode } from '@/blocks/types'
import type {
UpstashRedisCommandResponse,
UpstashRedisDeleteResponse,
UpstashRedisExistsResponse,
UpstashRedisExpireResponse,
UpstashRedisGetResponse,
UpstashRedisHGetAllResponse,
UpstashRedisHGetResponse,
UpstashRedisHSetResponse,
UpstashRedisIncrbyResponse,
UpstashRedisIncrResponse,
UpstashRedisKeysResponse,
UpstashRedisLPushResponse,
UpstashRedisLRangeResponse,
UpstashRedisSetnxResponse,
UpstashRedisSetResponse,
UpstashRedisTtlResponse,
} from '@/tools/upstash/types'
type UpstashResponse =
| UpstashRedisGetResponse
| UpstashRedisSetResponse
| UpstashRedisDeleteResponse
| UpstashRedisKeysResponse
| UpstashRedisCommandResponse
| UpstashRedisHSetResponse
| UpstashRedisHGetResponse
| UpstashRedisHGetAllResponse
| UpstashRedisIncrResponse
| UpstashRedisIncrbyResponse
| UpstashRedisExpireResponse
| UpstashRedisTtlResponse
| UpstashRedisLPushResponse
| UpstashRedisLRangeResponse
| UpstashRedisExistsResponse
| UpstashRedisSetnxResponse
export const UpstashBlock: BlockConfig<UpstashResponse> = {
type: 'upstash',
name: 'Upstash',
description: 'Serverless Redis with Upstash',
longDescription:
'Connect to Upstash Redis to perform key-value, hash, list, and utility operations via the REST API.',
docsLink: 'https://docs.sim.ai/tools/upstash',
category: 'tools',
bgColor: '#181C1E',
authMode: AuthMode.ApiKey,
icon: UpstashIcon,
subBlocks: [
{
id: 'operation',
title: 'Operation',
type: 'dropdown',
options: [
{ label: 'Get', id: 'get' },
{ label: 'Set', id: 'set' },
{ label: 'Delete', id: 'delete' },
{ label: 'List Keys', id: 'keys' },
{ label: 'HSET', id: 'hset' },
{ label: 'HGET', id: 'hget' },
{ label: 'HGETALL', id: 'hgetall' },
{ label: 'INCR', id: 'incr' },
{ label: 'INCRBY', id: 'incrby' },
{ label: 'EXISTS', id: 'exists' },
{ label: 'SETNX', id: 'setnx' },
{ label: 'LPUSH', id: 'lpush' },
{ label: 'LRANGE', id: 'lrange' },
{ label: 'EXPIRE', id: 'expire' },
{ label: 'TTL', id: 'ttl' },
{ label: 'Command', id: 'command' },
],
value: () => 'get',
},
{
id: 'restUrl',
title: 'REST URL',
type: 'short-input',
placeholder: 'https://your-database.upstash.io',
password: true,
required: true,
},
{
id: 'restToken',
title: 'REST Token',
type: 'short-input',
placeholder: 'Enter your Upstash Redis REST token',
password: true,
required: true,
},
// Key field (used by most operations)
{
id: 'key',
title: 'Key',
type: 'short-input',
placeholder: 'my-key',
condition: {
field: 'operation',
value: [
'get',
'set',
'delete',
'hset',
'hget',
'hgetall',
'incr',
'incrby',
'exists',
'setnx',
'lpush',
'lrange',
'expire',
'ttl',
],
},
required: {
field: 'operation',
value: [
'get',
'set',
'delete',
'hset',
'hget',
'hgetall',
'incr',
'incrby',
'exists',
'setnx',
'lpush',
'lrange',
'expire',
'ttl',
],
},
},
// Value field (Get/Set/HSET/LPUSH)
{
id: 'value',
title: 'Value',
type: 'long-input',
placeholder: 'Value to store',
condition: { field: 'operation', value: ['set', 'setnx', 'hset', 'lpush'] },
required: { field: 'operation', value: ['set', 'setnx', 'hset', 'lpush'] },
},
// Expiration for SET
{
id: 'ex',
title: 'Expiration (seconds)',
type: 'short-input',
placeholder: 'Optional TTL in seconds',
condition: { field: 'operation', value: 'set' },
mode: 'advanced',
},
// Hash field (HSET/HGET)
{
id: 'field',
title: 'Field',
type: 'short-input',
placeholder: 'Hash field name',
condition: { field: 'operation', value: ['hset', 'hget'] },
required: { field: 'operation', value: ['hset', 'hget'] },
},
// Pattern for KEYS
{
id: 'pattern',
title: 'Pattern',
type: 'short-input',
placeholder: '* (all keys) or user:* (prefix match)',
condition: { field: 'operation', value: 'keys' },
mode: 'advanced',
},
// Seconds for EXPIRE
{
id: 'seconds',
title: 'Seconds',
type: 'short-input',
placeholder: 'Timeout in seconds',
condition: { field: 'operation', value: 'expire' },
required: { field: 'operation', value: 'expire' },
},
// Increment for INCRBY
{
id: 'increment',
title: 'Increment',
type: 'short-input',
placeholder: 'Amount to increment by (negative to decrement)',
condition: { field: 'operation', value: 'incrby' },
required: { field: 'operation', value: 'incrby' },
},
// Start/Stop for LRANGE
{
id: 'start',
title: 'Start Index',
type: 'short-input',
placeholder: '0',
condition: { field: 'operation', value: 'lrange' },
required: { field: 'operation', value: 'lrange' },
mode: 'advanced',
},
{
id: 'stop',
title: 'Stop Index',
type: 'short-input',
placeholder: '-1 (all elements)',
condition: { field: 'operation', value: 'lrange' },
required: { field: 'operation', value: 'lrange' },
mode: 'advanced',
},
// Command for raw Redis
{
id: 'command',
title: 'Command',
type: 'code',
placeholder: '["HSET", "myhash", "field1", "value1"]',
condition: { field: 'operation', value: 'command' },
required: { field: 'operation', value: 'command' },
},
],
tools: {
access: [
'upstash_redis_get',
'upstash_redis_set',
'upstash_redis_delete',
'upstash_redis_keys',
'upstash_redis_command',
'upstash_redis_hset',
'upstash_redis_hget',
'upstash_redis_hgetall',
'upstash_redis_incr',
'upstash_redis_expire',
'upstash_redis_ttl',
'upstash_redis_lpush',
'upstash_redis_lrange',
'upstash_redis_exists',
'upstash_redis_setnx',
'upstash_redis_incrby',
],
config: {
tool: (params) => {
if (params.ex) {
params.ex = Number(params.ex)
}
if (params.seconds !== undefined) {
params.seconds = Number(params.seconds)
}
if (params.start !== undefined) {
params.start = Number(params.start)
}
if (params.stop !== undefined) {
params.stop = Number(params.stop)
}
if (params.increment !== undefined) {
params.increment = Number(params.increment)
}
return `upstash_redis_${params.operation}`
},
},
},
inputs: {
operation: { type: 'string', description: 'Redis operation to perform' },
restUrl: { type: 'string', description: 'Upstash Redis REST URL' },
restToken: { type: 'string', description: 'Upstash Redis REST token' },
key: { type: 'string', description: 'Redis key' },
value: { type: 'string', description: 'Value to store' },
ex: { type: 'number', description: 'Expiration time in seconds (SET)' },
field: { type: 'string', description: 'Hash field name (HSET/HGET)' },
pattern: { type: 'string', description: 'Pattern to match keys (KEYS)' },
seconds: { type: 'number', description: 'Timeout in seconds (EXPIRE)' },
start: { type: 'number', description: 'Start index (LRANGE)' },
stop: { type: 'number', description: 'Stop index (LRANGE)' },
command: { type: 'string', description: 'Redis command as JSON array (Command)' },
increment: { type: 'number', description: 'Amount to increment by (INCRBY)' },
},
outputs: {
value: { type: 'json', description: 'Retrieved value (Get, HGET, INCR, INCRBY operations)' },
result: {
type: 'json',
description: 'Operation result (Set, HSET, EXPIRE, Command operations)',
},
deletedCount: { type: 'number', description: 'Number of keys deleted (Delete operation)' },
keys: { type: 'array', description: 'List of keys matching the pattern (Keys operation)' },
count: { type: 'number', description: 'Number of items found (Keys, LRANGE operations)' },
key: { type: 'string', description: 'The key operated on' },
fields: {
type: 'json',
description: 'Hash field-value pairs keyed by field name (HGETALL operation)',
},
fieldCount: { type: 'number', description: 'Number of fields in the hash (HGETALL operation)' },
field: { type: 'string', description: 'Hash field name (HSET, HGET operations)' },
ttl: {
type: 'number',
description:
'Remaining TTL in seconds. Positive integer if TTL set, -1 if no expiration, -2 if key does not exist.',
},
length: { type: 'number', description: 'List length after push (LPUSH operation)' },
values: {
type: 'array',
description: 'List elements in the specified range (LRANGE operation)',
},
command: { type: 'string', description: 'The command that was executed (Command operation)' },
pattern: { type: 'string', description: 'The pattern used to match keys (Keys operation)' },
exists: {
type: 'boolean',
description: 'Whether the key exists (true) or not (false) (EXISTS operation)',
},
wasSet: {
type: 'boolean',
description: 'Whether the key was set (true) or already existed (false) (SETNX operation)',
},
},
}

View File

@@ -13,6 +13,7 @@ const VISION_MODEL_OPTIONS = [
{ label: 'Claude Opus 4.5', id: 'claude-opus-4-5' },
{ label: 'Claude Sonnet 4.5', id: 'claude-sonnet-4-5' },
{ label: 'Claude Haiku 4.5', id: 'claude-haiku-4-5' },
{ label: 'Gemini 3.1 Pro Preview', id: 'gemini-3.1-pro-preview' },
{ label: 'Gemini 3 Pro Preview', id: 'gemini-3-pro-preview' },
{ label: 'Gemini 3 Flash Preview', id: 'gemini-3-flash-preview' },
{ label: 'Gemini 2.5 Pro', id: 'gemini-2.5-pro' },

View File

@@ -64,11 +64,6 @@ export const WikipediaBlock: BlockConfig<WikipediaResponse> = {
access: ['wikipedia_summary', 'wikipedia_search', 'wikipedia_content', 'wikipedia_random'],
config: {
tool: (params) => {
// Convert searchLimit to a number for search operation
if (params.searchLimit) {
params.searchLimit = Number(params.searchLimit)
}
switch (params.operation) {
case 'wikipedia_summary':
return 'wikipedia_summary'
@@ -82,6 +77,11 @@ export const WikipediaBlock: BlockConfig<WikipediaResponse> = {
return 'wikipedia_summary'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.searchLimit) result.searchLimit = Number(params.searchLimit)
return result
},
},
},
inputs: {

View File

@@ -442,11 +442,6 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
],
config: {
tool: (params) => {
// Convert numeric parameters
if (params.maxResults) {
params.maxResults = Number(params.maxResults)
}
switch (params.operation) {
case 'youtube_search':
return 'youtube_search'
@@ -470,6 +465,11 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
return 'youtube_search'
}
},
params: (params) => {
const result: Record<string, unknown> = {}
if (params.maxResults) result.maxResults = Number(params.maxResults)
return result
},
},
},
inputs: {

View File

@@ -3,6 +3,7 @@ import { AgentBlock } from '@/blocks/blocks/agent'
import { AhrefsBlock } from '@/blocks/blocks/ahrefs'
import { AirtableBlock } from '@/blocks/blocks/airtable'
import { AirweaveBlock } from '@/blocks/blocks/airweave'
import { AlgoliaBlock } from '@/blocks/blocks/algolia'
import { ApiBlock } from '@/blocks/blocks/api'
import { ApiTriggerBlock } from '@/blocks/blocks/api_trigger'
import { ApifyBlock } from '@/blocks/blocks/apify'
@@ -108,9 +109,11 @@ import { PulseBlock, PulseV2Block } from '@/blocks/blocks/pulse'
import { QdrantBlock } from '@/blocks/blocks/qdrant'
import { RDSBlock } from '@/blocks/blocks/rds'
import { RedditBlock } from '@/blocks/blocks/reddit'
import { RedisBlock } from '@/blocks/blocks/redis'
import { ReductoBlock, ReductoV2Block } from '@/blocks/blocks/reducto'
import { ResendBlock } from '@/blocks/blocks/resend'
import { ResponseBlock } from '@/blocks/blocks/response'
import { RevenueCatBlock } from '@/blocks/blocks/revenuecat'
import { RouterBlock, RouterV2Block } from '@/blocks/blocks/router'
import { RssBlock } from '@/blocks/blocks/rss'
import { S3Block } from '@/blocks/blocks/s3'
@@ -136,7 +139,6 @@ import { StarterBlock } from '@/blocks/blocks/starter'
import { StripeBlock } from '@/blocks/blocks/stripe'
import { SttBlock, SttV2Block } from '@/blocks/blocks/stt'
import { SupabaseBlock } from '@/blocks/blocks/supabase'
import { TableBlock } from '@/blocks/blocks/table'
import { TavilyBlock } from '@/blocks/blocks/tavily'
import { TelegramBlock } from '@/blocks/blocks/telegram'
import { TextractBlock, TextractV2Block } from '@/blocks/blocks/textract'
@@ -148,6 +150,7 @@ import { TtsBlock } from '@/blocks/blocks/tts'
import { TwilioSMSBlock } from '@/blocks/blocks/twilio'
import { TwilioVoiceBlock } from '@/blocks/blocks/twilio_voice'
import { TypeformBlock } from '@/blocks/blocks/typeform'
import { UpstashBlock } from '@/blocks/blocks/upstash'
import { VariablesBlock } from '@/blocks/blocks/variables'
import { VercelBlock } from '@/blocks/blocks/vercel'
import { VideoGeneratorBlock, VideoGeneratorV2Block } from '@/blocks/blocks/video_generator'
@@ -175,6 +178,7 @@ export const registry: Record<string, BlockConfig> = {
ahrefs: AhrefsBlock,
airtable: AirtableBlock,
airweave: AirweaveBlock,
algolia: AlgoliaBlock,
api: ApiBlock,
api_trigger: ApiTriggerBlock,
apify: ApifyBlock,
@@ -293,10 +297,12 @@ export const registry: Record<string, BlockConfig> = {
qdrant: QdrantBlock,
rds: RDSBlock,
reddit: RedditBlock,
redis: RedisBlock,
reducto: ReductoBlock,
reducto_v2: ReductoV2Block,
resend: ResendBlock,
response: ResponseBlock,
revenuecat: RevenueCatBlock,
router: RouterBlock,
router_v2: RouterV2Block,
rss: RssBlock,
@@ -324,7 +330,8 @@ export const registry: Record<string, BlockConfig> = {
stt: SttBlock,
stt_v2: SttV2Block,
supabase: SupabaseBlock,
table: TableBlock,
// TODO: Uncomment when working on tables
// table: TableBlock,
tavily: TavilyBlock,
telegram: TelegramBlock,
textract: TextractBlock,
@@ -337,6 +344,7 @@ export const registry: Record<string, BlockConfig> = {
twilio_sms: TwilioSMSBlock,
twilio_voice: TwilioVoiceBlock,
typeform: TypeformBlock,
upstash: UpstashBlock,
vercel: VercelBlock,
variables: VariablesBlock,
video_generator: VideoGeneratorBlock,

View File

@@ -1157,6 +1157,17 @@ export function AirweaveIcon(props: SVGProps<SVGSVGElement>) {
)
}
export function AlgoliaIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg {...props} xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50'>
<path
fill='#FFFFFF'
d='M25,0C11.3,0,0.2,11,0,24.6C-0.2,38.4,11,49.9,24.8,50c4.3,0,8.4-1,12-3c0.4-0.2,0.4-0.7,0.1-1l-2.3-2.1 c-0.5-0.4-1.2-0.5-1.7-0.3c-2.5,1.1-5.3,1.6-8.2,1.6c-11.2-0.1-20.2-9.4-20-20.6C4.9,13.6,13.9,4.7,25,4.7h20.3v36L33.7,30.5 c-0.4-0.3-0.9-0.3-1.2,0.1c-1.8,2.4-4.9,4-8.2,3.7c-4.6-0.3-8.4-4-8.7-8.7c-0.4-5.5,4-10.2,9.4-10.2c4.9,0,9,3.8,9.4,8.6 c0,0.4,0.2,0.8,0.6,1.1l3,2.7c0.3,0.3,0.9,0.1,1-0.3c0.2-1.2,0.3-2.4,0.2-3.6c-0.5-7-6.2-12.7-13.2-13.1c-8.1-0.5-14.8,5.8-15,13.7 c-0.2,7.7,6.1,14.4,13.8,14.5c3.2,0.1,6.2-0.9,8.6-2.7l15,13.3c0.6,0.6,1.7,0.1,1.7-0.7v-48C50,0.4,49.5,0,49,0L25,0 C25,0,25,0,25,0z'
/>
</svg>
)
}
export function GoogleBooksIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg {...props} xmlns='http://www.w3.org/2000/svg' viewBox='0 0 478.633 540.068'>
@@ -5737,3 +5748,74 @@ export function CloudflareIcon(props: SVGProps<SVGSVGElement>) {
</svg>
)
}
export function UpstashIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg {...props} xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 341' width='24' height='24'>
<path
fill='#00C98D'
d='M0 298.417c56.554 56.553 148.247 56.553 204.801 0c56.554-56.554 56.554-148.247 0-204.801l-25.6 25.6c42.415 42.416 42.415 111.185 0 153.6c-42.416 42.416-111.185 42.416-153.601 0z'
/>
<path
fill='#00C98D'
d='M51.2 247.216c28.277 28.277 74.123 28.277 102.4 0c28.277-28.276 28.277-74.123 0-102.4l-25.6 25.6c14.14 14.138 14.14 37.061 0 51.2c-14.138 14.139-37.061 14.139-51.2 0zM256 42.415c-56.554-56.553-148.247-56.553-204.8 0c-56.555 56.555-56.555 148.247 0 204.801l25.599-25.6c-42.415-42.415-42.415-111.185 0-153.6c42.416-42.416 111.185-42.416 153.6 0z'
/>
<path
fill='#00C98D'
d='M204.8 93.616c-28.276-28.277-74.124-28.277-102.4 0c-28.278 28.277-28.278 74.123 0 102.4l25.6-25.6c-14.14-14.138-14.14-37.061 0-51.2c14.138-14.139 37.06-14.139 51.2 0z'
/>
<path
fill='#FFF'
fillOpacity='.4'
d='M256 42.415c-56.554-56.553-148.247-56.553-204.8 0c-56.555 56.555-56.555 148.247 0 204.801l25.599-25.6c-42.415-42.415-42.415-111.185 0-153.6c42.416-42.416 111.185-42.416 153.6 0z'
/>
<path
fill='#FFF'
fillOpacity='.4'
d='M204.8 93.616c-28.276-28.277-74.124-28.277-102.4 0c-28.278 28.277-28.278 74.123 0 102.4l25.6-25.6c-14.14-14.138-14.14-37.061 0-51.2c14.138-14.139 37.06-14.139 51.2 0z'
/>
</svg>
)
}
export function RevenueCatIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
{...props}
width='512'
height='512'
viewBox='0 0 512 512'
fill='none'
xmlns='http://www.w3.org/2000/svg'
>
<path
d='M95 109.774C110.152 106.108 133.612 104 154.795 104C212.046 104 246.32 123.928 246.32 174.646C246.32 205.746 233.737 226.264 214.005 237.437L261.765 318.946C258.05 321.632 250.035 323.176 238.864 323.176C226.282 323.176 217.987 321.672 211.982 318.946L172.225 248.3H167.645C157.789 248.305 147.945 247.601 138.18 246.192V319.255C134.172 321.672 127.022 323.176 116.73 323.176C106.73 323.176 99.2874 321.659 95 319.255V109.774ZM137.643 207.848C145.772 209.263 153.997 209.968 162.235 209.956C187.12 209.956 202.285 200.556 202.285 177.057C202.285 152.886 186.268 142.949 157.668 142.949C150.956 142.918 144.255 143.515 137.643 144.735V207.848Z'
fill='#FFFFFF'
/>
<path
d='M428.529 329.244C428.529 365.526 410.145 375.494 396.306 382.195C360.972 399.32 304.368 379.4 244.206 373.338C189.732 366.214 135.706 361.522 127.309 373.738C124.152 376.832 123.481 386.798 127.309 390.862C138.604 402.85 168.061 394.493 188.919 390.714C195.391 389.694 201.933 392.099 206.079 397.021C210.226 401.944 211.349 408.637 209.024 414.58C206.699 420.522 201.28 424.811 194.809 425.831C185.379 427.264 175.85 427.989 166.306 428C145.988 428 120.442 424.495 105.943 409.072C98.7232 401.4 91.3266 387.78 97.0271 366.465C107.875 326.074 172.807 336.052 248.033 343.633C300.41 348.907 357.23 366.465 379.934 350.343C385.721 346.234 396.517 337.022 390.698 329.244C384.879 321.467 375.353 325.684 362.838 325.684C300.152 325.684 263.238 285.302 263.238 217.916C263.247 167.292 284.176 131.892 318.287 115.09C333.109 107.789 350.421 104 369.587 104C386.292 104 403.269 106.931 414.11 113.366C420.847 123.032 423.778 140.305 422.306 153.201C408.247 146.466 395.36 142.949 378.669 142.949C337.365 142.949 308.947 164.039 308.947 214.985C308.947 265.932 337.065 286.149 376.611 286.149C387.869 286.035 403.1 284.67 422.306 282.053C426.455 297.498 428.529 313.228 428.529 329.244Z'
fill='#FFFFFF'
/>
</svg>
)
}
export function RedisIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
{...props}
viewBox='0 0 512 512'
xmlns='http://www.w3.org/2000/svg'
fillRule='evenodd'
clipRule='evenodd'
strokeLinejoin='round'
strokeMiterlimit='2'
>
<path
d='M479.14 279.864c-34.584 43.578-71.94 93.385-146.645 93.385-66.73 0-91.59-58.858-93.337-106.672 14.62 30.915 43.203 55.949 87.804 54.792C412.737 318.6 471.53 241.127 471.53 170.57c0-84.388-62.947-145.262-172.24-145.262-78.165 0-175.004 29.743-238.646 76.782-.689 48.42 26.286 111.369 35.972 104.452 55.17-39.67 98.918-65.203 141.35-78.01C175.153 198.58 24.451 361.219 6 389.85c2.076 26.286 34.588 96.842 50.496 96.842 4.841 0 8.993-2.768 13.835-7.61 45.433-51.046 82.472-96.816 115.412-140.933 4.627 64.658 36.42 143.702 125.307 143.702 79.55 0 158.408-57.414 194.377-186.767 4.149-15.911-15.22-28.362-26.286-15.22zm-90.616-104.449c0 40.81-40.118 60.87-76.782 60.87-19.596 0-34.648-5.145-46.554-11.832 21.906-33.168 43.59-67.182 66.887-103.593 41.08 6.953 56.449 29.788 56.449 54.555z'
fill='#FFFFFF'
fillRule='nonzero'
/>
</svg>
)
}

View File

@@ -295,6 +295,12 @@ export function AccessControl() {
category: 'Sidebar',
configKey: 'hideKnowledgeBaseTab' as const,
},
{
id: 'hide-tables',
label: 'Tables',
category: 'Sidebar',
configKey: 'hideTablesTab' as const,
},
{
id: 'hide-templates',
label: 'Templates',
@@ -949,6 +955,7 @@ export function AccessControl() {
onClick={() => {
const allVisible =
!editingConfig?.hideKnowledgeBaseTab &&
!editingConfig?.hideTablesTab &&
!editingConfig?.hideTemplates &&
!editingConfig?.hideCopilot &&
!editingConfig?.hideApiKeysTab &&
@@ -969,6 +976,7 @@ export function AccessControl() {
? {
...prev,
hideKnowledgeBaseTab: allVisible,
hideTablesTab: allVisible,
hideTemplates: allVisible,
hideCopilot: allVisible,
hideApiKeysTab: allVisible,
@@ -990,6 +998,7 @@ export function AccessControl() {
}}
>
{!editingConfig?.hideKnowledgeBaseTab &&
!editingConfig?.hideTablesTab &&
!editingConfig?.hideTemplates &&
!editingConfig?.hideCopilot &&
!editingConfig?.hideApiKeysTab &&

View File

@@ -15,6 +15,7 @@ const {
allowedModelProviders: null,
hideTraceSpans: false,
hideKnowledgeBaseTab: false,
hideTablesTab: false,
hideCopilot: false,
hideApiKeysTab: false,
hideEnvironmentTab: false,

View File

@@ -1,4 +1,4 @@
import { loggerMock } from '@sim/testing'
import { loggerMock, requestUtilsMock } from '@sim/testing'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { BlockType } from '@/executor/constants'
import { ConditionBlockHandler } from '@/executor/handlers/condition/condition-handler'
@@ -7,9 +7,7 @@ import type { SerializedBlock, SerializedWorkflow } from '@/serializer/types'
vi.mock('@sim/logger', () => loggerMock)
vi.mock('@/lib/core/utils/request', () => ({
generateRequestId: vi.fn(() => 'test-request-id'),
}))
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
vi.mock('@/tools', () => ({
executeTool: vi.fn(),

View File

@@ -7,7 +7,11 @@ import { BlockResolver } from '@/executor/variables/resolvers/block'
import { EnvResolver } from '@/executor/variables/resolvers/env'
import { LoopResolver } from '@/executor/variables/resolvers/loop'
import { ParallelResolver } from '@/executor/variables/resolvers/parallel'
import type { ResolutionContext, Resolver } from '@/executor/variables/resolvers/reference'
import {
RESOLVED_EMPTY,
type ResolutionContext,
type Resolver,
} from '@/executor/variables/resolvers/reference'
import { WorkflowResolver } from '@/executor/variables/resolvers/workflow'
import type { SerializedBlock, SerializedWorkflow } from '@/serializer/types'
@@ -104,7 +108,11 @@ export class VariableResolver {
loopScope,
}
return this.resolveReference(trimmed, resolutionContext)
const result = this.resolveReference(trimmed, resolutionContext)
if (result === RESOLVED_EMPTY) {
return null
}
return result
}
}
@@ -174,6 +182,13 @@ export class VariableResolver {
return match
}
if (resolved === RESOLVED_EMPTY) {
if (blockType === BlockType.FUNCTION) {
return this.blockResolver.formatValueForBlock(null, blockType, language)
}
return ''
}
return this.blockResolver.formatValueForBlock(resolved, blockType, language)
} catch (error) {
replacementError = error instanceof Error ? error : new Error(String(error))
@@ -207,7 +222,6 @@ export class VariableResolver {
let replacementError: Error | null = null
// Use generic utility for smart variable reference replacement
let result = replaceValidReferences(template, (match) => {
if (replacementError) return match
@@ -217,6 +231,10 @@ export class VariableResolver {
return match
}
if (resolved === RESOLVED_EMPTY) {
return 'null'
}
if (typeof resolved === 'string') {
const escaped = resolved.replace(/\\/g, '\\\\').replace(/'/g, "\\'")
return `'${escaped}'`

View File

@@ -2,7 +2,7 @@ import { loggerMock } from '@sim/testing'
import { describe, expect, it, vi } from 'vitest'
import { ExecutionState } from '@/executor/execution/state'
import { BlockResolver } from './block'
import type { ResolutionContext } from './reference'
import { RESOLVED_EMPTY, type ResolutionContext } from './reference'
vi.mock('@sim/logger', () => loggerMock)
vi.mock('@/blocks/registry', async () => {
@@ -134,15 +134,18 @@ describe('BlockResolver', () => {
expect(resolver.resolve('<source.items.1.id>', ctx)).toBe(2)
})
it.concurrent('should return undefined for non-existent path when no schema defined', () => {
const workflow = createTestWorkflow([{ id: 'source', type: 'unknown_block_type' }])
const resolver = new BlockResolver(workflow)
const ctx = createTestContext('current', {
source: { existing: 'value' },
})
it.concurrent(
'should return RESOLVED_EMPTY for non-existent path when no schema defined',
() => {
const workflow = createTestWorkflow([{ id: 'source', type: 'unknown_block_type' }])
const resolver = new BlockResolver(workflow)
const ctx = createTestContext('current', {
source: { existing: 'value' },
})
expect(resolver.resolve('<source.nonexistent>', ctx)).toBeUndefined()
})
expect(resolver.resolve('<source.nonexistent>', ctx)).toBe(RESOLVED_EMPTY)
}
)
it.concurrent('should throw error for path not in output schema', () => {
const workflow = createTestWorkflow([
@@ -162,7 +165,7 @@ describe('BlockResolver', () => {
expect(() => resolver.resolve('<source.invalidField>', ctx)).toThrow(/Available fields:/)
})
it.concurrent('should return undefined for path in schema but missing in data', () => {
it.concurrent('should return RESOLVED_EMPTY for path in schema but missing in data', () => {
const workflow = createTestWorkflow([
{
id: 'source',
@@ -175,7 +178,7 @@ describe('BlockResolver', () => {
})
expect(resolver.resolve('<source.stdout>', ctx)).toBe('log output')
expect(resolver.resolve('<source.result>', ctx)).toBeUndefined()
expect(resolver.resolve('<source.result>', ctx)).toBe(RESOLVED_EMPTY)
})
it.concurrent(
@@ -191,7 +194,7 @@ describe('BlockResolver', () => {
const resolver = new BlockResolver(workflow)
const ctx = createTestContext('current', {})
expect(resolver.resolve('<workflow.childTraceSpans>', ctx)).toBeUndefined()
expect(resolver.resolve('<workflow.childTraceSpans>', ctx)).toBe(RESOLVED_EMPTY)
}
)
@@ -208,7 +211,7 @@ describe('BlockResolver', () => {
const resolver = new BlockResolver(workflow)
const ctx = createTestContext('current', {})
expect(resolver.resolve('<workflowinput.childTraceSpans>', ctx)).toBeUndefined()
expect(resolver.resolve('<workflowinput.childTraceSpans>', ctx)).toBe(RESOLVED_EMPTY)
}
)
@@ -225,13 +228,13 @@ describe('BlockResolver', () => {
const resolver = new BlockResolver(workflow)
const ctx = createTestContext('current', {})
expect(resolver.resolve('<hitl.response>', ctx)).toBeUndefined()
expect(resolver.resolve('<hitl.submission>', ctx)).toBeUndefined()
expect(resolver.resolve('<hitl.resumeInput>', ctx)).toBeUndefined()
expect(resolver.resolve('<hitl.response>', ctx)).toBe(RESOLVED_EMPTY)
expect(resolver.resolve('<hitl.submission>', ctx)).toBe(RESOLVED_EMPTY)
expect(resolver.resolve('<hitl.resumeInput>', ctx)).toBe(RESOLVED_EMPTY)
}
)
it.concurrent('should return undefined for non-existent block', () => {
it.concurrent('should return undefined for block not in workflow', () => {
const workflow = createTestWorkflow([{ id: 'existing' }])
const resolver = new BlockResolver(workflow)
const ctx = createTestContext('current', {})
@@ -239,6 +242,21 @@ describe('BlockResolver', () => {
expect(resolver.resolve('<nonexistent>', ctx)).toBeUndefined()
})
it.concurrent('should return RESOLVED_EMPTY for block in workflow that did not execute', () => {
const workflow = createTestWorkflow([
{ id: 'start-block', name: 'Start', type: 'start_trigger' },
{ id: 'slack-block', name: 'Slack', type: 'slack_trigger' },
])
const resolver = new BlockResolver(workflow)
const ctx = createTestContext('current', {
'slack-block': { message: 'hello from slack' },
})
expect(resolver.resolve('<slack.message>', ctx)).toBe('hello from slack')
expect(resolver.resolve('<start>', ctx)).toBe(RESOLVED_EMPTY)
expect(resolver.resolve('<start.input>', ctx)).toBe(RESOLVED_EMPTY)
})
it.concurrent('should fall back to context blockStates', () => {
const workflow = createTestWorkflow([{ id: 'source' }])
const resolver = new BlockResolver(workflow)
@@ -1012,24 +1030,24 @@ describe('BlockResolver', () => {
expect(resolver.resolve('<source.other>', ctx)).toBe('exists')
})
it.concurrent('should handle output with undefined values', () => {
it.concurrent('should return RESOLVED_EMPTY for output with undefined values', () => {
const workflow = createTestWorkflow([{ id: 'source', type: 'unknown_block_type' }])
const resolver = new BlockResolver(workflow)
const ctx = createTestContext('current', {
source: { value: undefined, other: 'exists' },
})
expect(resolver.resolve('<source.value>', ctx)).toBeUndefined()
expect(resolver.resolve('<source.value>', ctx)).toBe(RESOLVED_EMPTY)
})
it.concurrent('should return undefined for deeply nested non-existent path', () => {
it.concurrent('should return RESOLVED_EMPTY for deeply nested non-existent path', () => {
const workflow = createTestWorkflow([{ id: 'source', type: 'unknown_block_type' }])
const resolver = new BlockResolver(workflow)
const ctx = createTestContext('current', {
source: { level1: { level2: {} } },
})
expect(resolver.resolve('<source.level1.level2.level3>', ctx)).toBeUndefined()
expect(resolver.resolve('<source.level1.level2.level3>', ctx)).toBe(RESOLVED_EMPTY)
})
})
})

View File

@@ -13,6 +13,7 @@ import {
import { formatLiteralForCode } from '@/executor/utils/code-formatting'
import {
navigatePath,
RESOLVED_EMPTY,
type ResolutionContext,
type Resolver,
} from '@/executor/variables/resolvers/reference'
@@ -84,7 +85,12 @@ export class BlockResolver implements Resolver {
return result.value
}
return this.handleBackwardsCompat(block, output, pathParts)
const backwardsCompat = this.handleBackwardsCompat(block, output, pathParts)
if (backwardsCompat !== undefined) {
return backwardsCompat
}
return RESOLVED_EMPTY
} catch (error) {
if (error instanceof InvalidFieldError) {
const fallback = this.handleBackwardsCompat(block, output, pathParts)

View File

@@ -12,6 +12,14 @@ export interface Resolver {
resolve(reference: string, context: ResolutionContext): any
}
/**
* Sentinel value indicating a reference was resolved to a known block
* that produced no output (e.g., the block exists in the workflow but
* didn't execute on this path). Distinct from `undefined`, which means
* the reference couldn't be matched to any block at all.
*/
export const RESOLVED_EMPTY = Symbol('RESOLVED_EMPTY')
/**
* Navigate through nested object properties using a path array.
* Supports dot notation and array indices.

View File

@@ -1,18 +1,24 @@
/**
* @vitest-environment node
*/
import { auditMock, databaseMock, loggerMock } from '@sim/testing'
import { auditMock, databaseMock, drizzleOrmMock, loggerMock } from '@sim/testing'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
vi.mock('@sim/db', () => ({
...databaseMock,
auditLog: { id: 'id', workspaceId: 'workspace_id' },
}))
vi.mock('@sim/db/schema', () => ({
user: { id: 'id', name: 'name', email: 'email' },
}))
vi.mock('drizzle-orm', () => drizzleOrmMock)
vi.mock('@sim/logger', () => loggerMock)
vi.mock('nanoid', () => ({ nanoid: () => 'test-id-123' }))
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
const flush = () => new Promise((resolve) => setTimeout(resolve, 10))
describe('AuditAction', () => {
it('contains all expected action categories', () => {
expect(AuditAction.WORKFLOW_CREATED).toBe('workflow.created')
@@ -45,12 +51,22 @@ describe('AuditResourceType', () => {
describe('recordAudit', () => {
const mockInsert = databaseMock.db.insert
const mockSelect = databaseMock.db.select
let mockValues: ReturnType<typeof vi.fn>
let mockLimit: ReturnType<typeof vi.fn>
beforeEach(() => {
vi.clearAllMocks()
mockValues = vi.fn(() => Promise.resolve())
mockInsert.mockReturnValue({ values: mockValues })
mockLimit = vi.fn(() => Promise.resolve([]))
mockSelect.mockReturnValue({
from: vi.fn(() => ({
where: vi.fn(() => ({
limit: mockLimit,
})),
})),
})
})
afterEach(() => {
@@ -61,15 +77,16 @@ describe('recordAudit', () => {
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
actorName: 'Test User',
actorEmail: 'test@example.com',
action: AuditAction.WORKFLOW_CREATED,
resourceType: AuditResourceType.WORKFLOW,
resourceId: 'wf-1',
})
await vi.waitFor(() => {
expect(mockInsert).toHaveBeenCalledTimes(1)
})
await flush()
expect(mockInsert).toHaveBeenCalledTimes(1)
expect(mockValues).toHaveBeenCalledWith(
expect.objectContaining({
id: 'test-id-123',
@@ -96,9 +113,7 @@ describe('recordAudit', () => {
description: 'Created folder "My Folder"',
})
await vi.waitFor(() => {
expect(mockValues).toHaveBeenCalledTimes(1)
})
await flush()
expect(mockValues).toHaveBeenCalledWith(
expect.objectContaining({
@@ -110,26 +125,6 @@ describe('recordAudit', () => {
)
})
it('sets optional fields to undefined when not provided', async () => {
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
action: AuditAction.WORKSPACE_DELETED,
resourceType: AuditResourceType.WORKSPACE,
})
await vi.waitFor(() => {
expect(mockValues).toHaveBeenCalledTimes(1)
})
const insertedValues = mockValues.mock.calls[0][0]
expect(insertedValues.resourceId).toBeUndefined()
expect(insertedValues.actorName).toBeUndefined()
expect(insertedValues.actorEmail).toBeUndefined()
expect(insertedValues.resourceName).toBeUndefined()
expect(insertedValues.description).toBeUndefined()
})
it('extracts IP address from x-forwarded-for header', async () => {
const request = new Request('https://example.com', {
headers: {
@@ -141,14 +136,14 @@ describe('recordAudit', () => {
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
actorName: 'Test',
actorEmail: 'test@test.com',
action: AuditAction.MEMBER_INVITED,
resourceType: AuditResourceType.WORKSPACE,
request,
})
await vi.waitFor(() => {
expect(mockValues).toHaveBeenCalledTimes(1)
})
await flush()
expect(mockValues).toHaveBeenCalledWith(
expect.objectContaining({
@@ -166,14 +161,14 @@ describe('recordAudit', () => {
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
actorName: 'Test',
actorEmail: 'test@test.com',
action: AuditAction.API_KEY_CREATED,
resourceType: AuditResourceType.API_KEY,
request,
})
await vi.waitFor(() => {
expect(mockValues).toHaveBeenCalledTimes(1)
})
await flush()
expect(mockValues).toHaveBeenCalledWith(
expect.objectContaining({
@@ -187,13 +182,13 @@ describe('recordAudit', () => {
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
actorName: 'Test',
actorEmail: 'test@test.com',
action: AuditAction.ENVIRONMENT_UPDATED,
resourceType: AuditResourceType.ENVIRONMENT,
})
await vi.waitFor(() => {
expect(mockValues).toHaveBeenCalledTimes(1)
})
await flush()
expect(mockValues).toHaveBeenCalledWith(expect.objectContaining({ metadata: {} }))
})
@@ -202,14 +197,14 @@ describe('recordAudit', () => {
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
actorName: 'Test',
actorEmail: 'test@test.com',
action: AuditAction.WEBHOOK_CREATED,
resourceType: AuditResourceType.WEBHOOK,
metadata: { provider: 'github', workflowId: 'wf-1' },
})
await vi.waitFor(() => {
expect(mockValues).toHaveBeenCalledTimes(1)
})
await flush()
expect(mockValues).toHaveBeenCalledWith(
expect.objectContaining({
@@ -219,28 +214,138 @@ describe('recordAudit', () => {
})
it('does not throw when the database insert fails', async () => {
mockValues.mockReturnValue(Promise.reject(new Error('DB connection lost')))
mockValues.mockImplementation(() => Promise.reject(new Error('DB connection lost')))
expect(() => {
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
actorName: 'Test',
actorEmail: 'test@test.com',
action: AuditAction.WORKFLOW_DELETED,
resourceType: AuditResourceType.WORKFLOW,
})
}).not.toThrow()
await flush()
})
it('does not block — returns void synchronously', () => {
const result = recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
actorName: 'Test',
actorEmail: 'test@test.com',
action: AuditAction.CHAT_DEPLOYED,
resourceType: AuditResourceType.CHAT,
})
expect(result).toBeUndefined()
})
describe('lazy actor resolution', () => {
it('looks up user when actorName and actorEmail are both undefined', async () => {
mockLimit.mockResolvedValue([{ name: 'Resolved Name', email: 'resolved@example.com' }])
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
action: AuditAction.DOCUMENT_UPLOADED,
resourceType: AuditResourceType.DOCUMENT,
resourceId: 'doc-1',
})
await flush()
expect(mockSelect).toHaveBeenCalledTimes(1)
expect(mockValues).toHaveBeenCalledWith(
expect.objectContaining({
actorName: 'Resolved Name',
actorEmail: 'resolved@example.com',
})
)
})
it('skips lookup when actorName is provided (even if null)', async () => {
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
actorName: null,
actorEmail: null,
action: AuditAction.DOCUMENT_UPLOADED,
resourceType: AuditResourceType.DOCUMENT,
})
await flush()
expect(mockSelect).not.toHaveBeenCalled()
})
it('skips lookup when actorName and actorEmail are provided', async () => {
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
actorName: 'Already Known',
actorEmail: 'known@example.com',
action: AuditAction.WORKFLOW_CREATED,
resourceType: AuditResourceType.WORKFLOW,
})
await flush()
expect(mockSelect).not.toHaveBeenCalled()
expect(mockValues).toHaveBeenCalledWith(
expect.objectContaining({
actorName: 'Already Known',
actorEmail: 'known@example.com',
})
)
})
it('inserts without actor info when lookup fails', async () => {
mockLimit.mockRejectedValue(new Error('DB down'))
recordAudit({
workspaceId: 'ws-1',
actorId: 'user-1',
action: AuditAction.KNOWLEDGE_BASE_CREATED,
resourceType: AuditResourceType.KNOWLEDGE_BASE,
})
await flush()
expect(mockSelect).toHaveBeenCalledTimes(1)
expect(mockValues).toHaveBeenCalledWith(
expect.objectContaining({
actorId: 'user-1',
actorName: undefined,
actorEmail: undefined,
})
)
})
it('sets actor info to null when user is not found', async () => {
mockLimit.mockResolvedValue([])
recordAudit({
workspaceId: 'ws-1',
actorId: 'deleted-user',
action: AuditAction.WORKFLOW_DELETED,
resourceType: AuditResourceType.WORKFLOW,
})
await flush()
expect(mockSelect).toHaveBeenCalledTimes(1)
expect(mockValues).toHaveBeenCalledWith(
expect.objectContaining({
actorId: 'deleted-user',
actorName: undefined,
actorEmail: undefined,
})
)
})
})
})
describe('auditMock sync', () => {

View File

@@ -1,5 +1,7 @@
import { auditLog, db } from '@sim/db'
import { user } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { eq } from 'drizzle-orm'
import { nanoid } from 'nanoid'
const logger = createLogger('AuditLog')
@@ -185,41 +187,51 @@ interface AuditLogParams {
/**
* Records an audit log entry. Fire-and-forget — never throws or blocks the caller.
* If actorName and actorEmail are both undefined (not provided by the caller),
* resolves them from the user table before inserting.
*/
export function recordAudit(params: AuditLogParams): void {
try {
const ipAddress =
params.request?.headers.get('x-forwarded-for')?.split(',')[0].trim() ??
params.request?.headers.get('x-real-ip') ??
undefined
const userAgent = params.request?.headers.get('user-agent') ?? undefined
db.insert(auditLog)
.values({
id: nanoid(),
workspaceId: params.workspaceId || null,
actorId: params.actorId,
action: params.action,
resourceType: params.resourceType,
resourceId: params.resourceId,
actorName: params.actorName ?? undefined,
actorEmail: params.actorEmail ?? undefined,
resourceName: params.resourceName,
description: params.description,
metadata: params.metadata ?? {},
ipAddress,
userAgent,
})
.then(() => {
logger.debug('Audit log recorded', {
action: params.action,
resourceType: params.resourceType,
})
})
.catch((error) => {
logger.error('Failed to record audit log', { error, action: params.action })
})
} catch (error) {
logger.error('Failed to initiate audit log', { error, action: params.action })
}
insertAuditLog(params).catch((error) => {
logger.error('Failed to record audit log', { error, action: params.action })
})
}
async function insertAuditLog(params: AuditLogParams): Promise<void> {
const ipAddress =
params.request?.headers.get('x-forwarded-for')?.split(',')[0].trim() ??
params.request?.headers.get('x-real-ip') ??
undefined
const userAgent = params.request?.headers.get('user-agent') ?? undefined
let { actorName, actorEmail } = params
if (actorName === undefined && actorEmail === undefined && params.actorId) {
try {
const [row] = await db
.select({ name: user.name, email: user.email })
.from(user)
.where(eq(user.id, params.actorId))
.limit(1)
actorName = row?.name ?? undefined
actorEmail = row?.email ?? undefined
} catch (error) {
logger.debug('Failed to resolve actor info', { error, actorId: params.actorId })
}
}
await db.insert(auditLog).values({
id: nanoid(),
workspaceId: params.workspaceId || null,
actorId: params.actorId,
action: params.action,
resourceType: params.resourceType,
resourceId: params.resourceId,
actorName: actorName ?? undefined,
actorEmail: actorEmail ?? undefined,
resourceName: params.resourceName,
description: params.description,
metadata: params.metadata ?? {},
ipAddress,
userAgent,
})
}

View File

@@ -1,20 +1,15 @@
import { loggerMock } from '@sim/testing'
import { createEnvMock, loggerMock } from '@sim/testing'
import { afterEach, describe, expect, it, vi } from 'vitest'
const mockEnv = vi.hoisted(() => ({
ENCRYPTION_KEY: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
}))
vi.mock('@/lib/core/config/env', () => ({
env: mockEnv,
isTruthy: (value: string | boolean | number | undefined) =>
typeof value === 'string' ? value.toLowerCase() === 'true' || value === '1' : Boolean(value),
isFalsy: (value: string | boolean | number | undefined) =>
typeof value === 'string' ? value.toLowerCase() === 'false' || value === '0' : value === false,
}))
vi.mock('@/lib/core/config/env', () =>
createEnvMock({
ENCRYPTION_KEY: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
})
)
vi.mock('@sim/logger', () => loggerMock)
import { env } from '@/lib/core/config/env'
import { decryptSecret, encryptSecret, generatePassword } from './encryption'
describe('encryptSecret', () => {
@@ -172,21 +167,21 @@ describe('generatePassword', () => {
})
describe('encryption key validation', () => {
const originalEnv = { ...mockEnv }
const originalEncryptionKey = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
afterEach(() => {
mockEnv.ENCRYPTION_KEY = originalEnv.ENCRYPTION_KEY
;(env as Record<string, string>).ENCRYPTION_KEY = originalEncryptionKey
})
it('should throw error when ENCRYPTION_KEY is not set', async () => {
mockEnv.ENCRYPTION_KEY = ''
;(env as Record<string, string>).ENCRYPTION_KEY = ''
await expect(encryptSecret('test')).rejects.toThrow(
'ENCRYPTION_KEY must be set to a 64-character hex string (32 bytes)'
)
})
it('should throw error when ENCRYPTION_KEY is wrong length', async () => {
mockEnv.ENCRYPTION_KEY = '0123456789abcdef'
;(env as Record<string, string>).ENCRYPTION_KEY = '0123456789abcdef'
await expect(encryptSecret('test')).rejects.toThrow(
'ENCRYPTION_KEY must be set to a 64-character hex string (32 bytes)'
)

View File

@@ -1,3 +1,4 @@
import { createEnvMock } from '@sim/testing'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { getRotatingApiKey } from '@/lib/core/config/api-keys'
import { decryptSecret, encryptSecret } from '@/lib/core/security/encryption'
@@ -30,25 +31,20 @@ vi.mock('crypto', () => ({
}),
}))
vi.mock('@/lib/core/config/env', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/lib/core/config/env')>()
return {
...actual,
env: {
...actual.env,
ENCRYPTION_KEY: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', // fake key for testing
OPENAI_API_KEY_1: 'test-openai-key-1', // fake key for testing
OPENAI_API_KEY_2: 'test-openai-key-2', // fake key for testing
OPENAI_API_KEY_3: 'test-openai-key-3', // fake key for testing
ANTHROPIC_API_KEY_1: 'test-anthropic-key-1', // fake key for testing
ANTHROPIC_API_KEY_2: 'test-anthropic-key-2', // fake key for testing
ANTHROPIC_API_KEY_3: 'test-anthropic-key-3', // fake key for testing
GEMINI_API_KEY_1: 'test-gemini-key-1', // fake key for testing
GEMINI_API_KEY_2: 'test-gemini-key-2', // fake key for testing
GEMINI_API_KEY_3: 'test-gemini-key-3', // fake key for testing
},
}
})
vi.mock('@/lib/core/config/env', () =>
createEnvMock({
ENCRYPTION_KEY: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
OPENAI_API_KEY_1: 'test-openai-key-1',
OPENAI_API_KEY_2: 'test-openai-key-2',
OPENAI_API_KEY_3: 'test-openai-key-3',
ANTHROPIC_API_KEY_1: 'test-anthropic-key-1',
ANTHROPIC_API_KEY_2: 'test-anthropic-key-2',
ANTHROPIC_API_KEY_3: 'test-anthropic-key-3',
GEMINI_API_KEY_1: 'test-gemini-key-1',
GEMINI_API_KEY_2: 'test-gemini-key-2',
GEMINI_API_KEY_3: 'test-gemini-key-3',
})
)
afterEach(() => {
vi.clearAllMocks()

View File

@@ -679,11 +679,15 @@ function spawnWorker(): Promise<WorkerInfo> {
}
const currentDir = path.dirname(fileURLToPath(import.meta.url))
const workerPath = path.join(currentDir, 'isolated-vm-worker.cjs')
const candidatePaths = [
path.join(currentDir, 'isolated-vm-worker.cjs'),
path.join(process.cwd(), 'lib', 'execution', 'isolated-vm-worker.cjs'),
]
const workerPath = candidatePaths.find((p) => fs.existsSync(p))
if (!fs.existsSync(workerPath)) {
if (!workerPath) {
settleSpawnInProgress()
reject(new Error(`Worker file not found at ${workerPath}`))
reject(new Error(`Worker file not found at any of: ${candidatePaths.join(', ')}`))
return
}

View File

@@ -1,8 +1,59 @@
import { describe, expect, it } from 'vitest'
/**
* @vitest-environment node
*/
import { databaseMock, drizzleOrmMock, loggerMock } from '@sim/testing'
import { beforeEach, describe, expect, it, vi } from 'vitest'
const { mockSchemaExports } = vi.hoisted(() => ({
mockSchemaExports: {
workflowExecutionSnapshots: {
id: 'id',
workflowId: 'workflow_id',
stateHash: 'state_hash',
stateData: 'state_data',
createdAt: 'created_at',
},
workflowExecutionLogs: {
id: 'id',
stateSnapshotId: 'state_snapshot_id',
},
},
}))
vi.mock('@sim/db', () => databaseMock)
vi.mock('@sim/db/schema', () => mockSchemaExports)
vi.mock('@sim/logger', () => loggerMock)
vi.mock('drizzle-orm', () => drizzleOrmMock)
vi.mock('uuid', () => ({ v4: vi.fn(() => 'generated-uuid-1') }))
import { SnapshotService } from '@/lib/logs/execution/snapshot/service'
import type { WorkflowState } from '@/lib/logs/types'
const mockState: WorkflowState = {
blocks: {
block1: {
id: 'block1',
name: 'Test Agent',
type: 'agent',
position: { x: 100, y: 200 },
subBlocks: {},
outputs: {},
enabled: true,
horizontalHandles: true,
advancedMode: false,
height: 0,
},
},
edges: [{ id: 'edge1', source: 'block1', target: 'block2' }],
loops: {},
parallels: {},
}
describe('SnapshotService', () => {
beforeEach(() => {
vi.clearAllMocks()
})
describe('computeStateHash', () => {
it.concurrent('should generate consistent hashes for identical states', () => {
const service = new SnapshotService()
@@ -62,7 +113,7 @@ describe('SnapshotService', () => {
blocks: {
block1: {
...baseState.blocks.block1,
position: { x: 500, y: 600 }, // Different position
position: { x: 500, y: 600 },
},
},
}
@@ -140,7 +191,7 @@ describe('SnapshotService', () => {
const state2: WorkflowState = {
blocks: {},
edges: [
{ id: 'edge2', source: 'b', target: 'c' }, // Different order
{ id: 'edge2', source: 'b', target: 'c' },
{ id: 'edge1', source: 'a', target: 'b' },
],
loops: {},
@@ -219,7 +270,6 @@ describe('SnapshotService', () => {
const hash = service.computeStateHash(complexState)
expect(hash).toHaveLength(64)
// Should be consistent
const hash2 = service.computeStateHash(complexState)
expect(hash).toBe(hash2)
})
@@ -335,4 +385,166 @@ describe('SnapshotService', () => {
expect(hash1).toHaveLength(64)
})
})
describe('createSnapshotWithDeduplication', () => {
it('should use upsert to insert a new snapshot', async () => {
const service = new SnapshotService()
const workflowId = 'wf-123'
const mockReturning = vi.fn().mockResolvedValue([
{
id: 'generated-uuid-1',
workflowId,
stateHash: 'abc123',
stateData: mockState,
createdAt: new Date('2026-02-19T00:00:00Z'),
},
])
const mockOnConflictDoUpdate = vi.fn().mockReturnValue({ returning: mockReturning })
const mockValues = vi.fn().mockReturnValue({ onConflictDoUpdate: mockOnConflictDoUpdate })
const mockInsert = vi.fn().mockReturnValue({ values: mockValues })
databaseMock.db.insert = mockInsert
const result = await service.createSnapshotWithDeduplication(workflowId, mockState)
expect(mockInsert).toHaveBeenCalled()
expect(mockValues).toHaveBeenCalledWith(
expect.objectContaining({
id: 'generated-uuid-1',
workflowId,
stateData: mockState,
})
)
expect(mockOnConflictDoUpdate).toHaveBeenCalledWith(
expect.objectContaining({
set: expect.any(Object),
})
)
expect(result.snapshot.id).toBe('generated-uuid-1')
expect(result.isNew).toBe(true)
})
it('should detect reused snapshot when returned id differs from generated id', async () => {
const service = new SnapshotService()
const workflowId = 'wf-123'
const mockReturning = vi.fn().mockResolvedValue([
{
id: 'existing-snapshot-id',
workflowId,
stateHash: 'abc123',
stateData: mockState,
createdAt: new Date('2026-02-19T00:00:00Z'),
},
])
const mockOnConflictDoUpdate = vi.fn().mockReturnValue({ returning: mockReturning })
const mockValues = vi.fn().mockReturnValue({ onConflictDoUpdate: mockOnConflictDoUpdate })
const mockInsert = vi.fn().mockReturnValue({ values: mockValues })
databaseMock.db.insert = mockInsert
const result = await service.createSnapshotWithDeduplication(workflowId, mockState)
expect(result.snapshot.id).toBe('existing-snapshot-id')
expect(result.isNew).toBe(false)
})
it('should not throw on concurrent inserts with the same hash', async () => {
const service = new SnapshotService()
const workflowId = 'wf-123'
const mockReturningNew = vi.fn().mockResolvedValue([
{
id: 'generated-uuid-1',
workflowId,
stateHash: 'abc123',
stateData: mockState,
createdAt: new Date('2026-02-19T00:00:00Z'),
},
])
const mockReturningExisting = vi.fn().mockResolvedValue([
{
id: 'existing-snapshot-id',
workflowId,
stateHash: 'abc123',
stateData: mockState,
createdAt: new Date('2026-02-19T00:00:00Z'),
},
])
let callCount = 0
databaseMock.db.insert = vi.fn().mockImplementation(() => ({
values: vi.fn().mockImplementation(() => ({
onConflictDoUpdate: vi.fn().mockImplementation(() => ({
returning: callCount++ === 0 ? mockReturningNew : mockReturningExisting,
})),
})),
}))
const [result1, result2] = await Promise.all([
service.createSnapshotWithDeduplication(workflowId, mockState),
service.createSnapshotWithDeduplication(workflowId, mockState),
])
expect(result1.snapshot.id).toBe('generated-uuid-1')
expect(result1.isNew).toBe(true)
expect(result2.snapshot.id).toBe('existing-snapshot-id')
expect(result2.isNew).toBe(false)
})
it('should pass state_data in the ON CONFLICT SET clause', async () => {
const service = new SnapshotService()
const workflowId = 'wf-123'
let capturedConflictConfig: Record<string, unknown> | undefined
const mockReturning = vi.fn().mockResolvedValue([
{
id: 'generated-uuid-1',
workflowId,
stateHash: 'abc123',
stateData: mockState,
createdAt: new Date('2026-02-19T00:00:00Z'),
},
])
databaseMock.db.insert = vi.fn().mockReturnValue({
values: vi.fn().mockReturnValue({
onConflictDoUpdate: vi.fn().mockImplementation((config: Record<string, unknown>) => {
capturedConflictConfig = config
return { returning: mockReturning }
}),
}),
})
await service.createSnapshotWithDeduplication(workflowId, mockState)
expect(capturedConflictConfig).toBeDefined()
expect(capturedConflictConfig!.target).toBeDefined()
expect(capturedConflictConfig!.set).toBeDefined()
expect(capturedConflictConfig!.set).toHaveProperty('stateData')
})
it('should always call insert, never a separate select for deduplication', async () => {
const service = new SnapshotService()
const workflowId = 'wf-123'
const mockReturning = vi.fn().mockResolvedValue([
{
id: 'generated-uuid-1',
workflowId,
stateHash: 'abc123',
stateData: mockState,
createdAt: new Date('2026-02-19T00:00:00Z'),
},
])
const mockOnConflictDoUpdate = vi.fn().mockReturnValue({ returning: mockReturning })
const mockValues = vi.fn().mockReturnValue({ onConflictDoUpdate: mockOnConflictDoUpdate })
databaseMock.db.insert = vi.fn().mockReturnValue({ values: mockValues })
databaseMock.db.select = vi.fn()
await service.createSnapshotWithDeduplication(workflowId, mockState)
expect(databaseMock.db.insert).toHaveBeenCalledTimes(1)
expect(databaseMock.db.select).not.toHaveBeenCalled()
})
})
})

View File

@@ -2,7 +2,7 @@ import { createHash } from 'crypto'
import { db } from '@sim/db'
import { workflowExecutionLogs, workflowExecutionSnapshots } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { and, eq, lt, notExists } from 'drizzle-orm'
import { and, eq, lt, notExists, sql } from 'drizzle-orm'
import { v4 as uuidv4 } from 'uuid'
import type {
SnapshotService as ISnapshotService,
@@ -28,36 +28,8 @@ export class SnapshotService implements ISnapshotService {
workflowId: string,
state: WorkflowState
): Promise<SnapshotCreationResult> {
// Hash the position-less state for deduplication (functional equivalence)
const stateHash = this.computeStateHash(state)
const existingSnapshot = await this.getSnapshotByHash(workflowId, stateHash)
if (existingSnapshot) {
let refreshedState: WorkflowState = existingSnapshot.stateData
try {
await db
.update(workflowExecutionSnapshots)
.set({ stateData: state })
.where(eq(workflowExecutionSnapshots.id, existingSnapshot.id))
refreshedState = state
} catch (error) {
logger.warn(
`Failed to refresh snapshot stateData for ${existingSnapshot.id}, continuing with existing data`,
error
)
}
logger.info(
`Reusing existing snapshot for workflow ${workflowId} (hash: ${stateHash.slice(0, 12)}...)`
)
return {
snapshot: { ...existingSnapshot, stateData: refreshedState },
isNew: false,
}
}
// Store the FULL state (including positions) so we can recreate the exact workflow
// Even though we hash without positions, we want to preserve the complete state
const snapshotData: WorkflowExecutionSnapshotInsert = {
id: uuidv4(),
workflowId,
@@ -65,21 +37,32 @@ export class SnapshotService implements ISnapshotService {
stateData: state,
}
const [newSnapshot] = await db
const [upsertedSnapshot] = await db
.insert(workflowExecutionSnapshots)
.values(snapshotData)
.onConflictDoUpdate({
target: [workflowExecutionSnapshots.workflowId, workflowExecutionSnapshots.stateHash],
set: {
stateData: sql`excluded.state_data`,
},
})
.returning()
const isNew = upsertedSnapshot.id === snapshotData.id
logger.info(
`Created new snapshot for workflow ${workflowId} (hash: ${stateHash.slice(0, 12)}..., blocks: ${Object.keys(state.blocks || {}).length})`
isNew
? `Created new snapshot for workflow ${workflowId} (hash: ${stateHash.slice(0, 12)}..., blocks: ${Object.keys(state.blocks || {}).length})`
: `Reusing existing snapshot for workflow ${workflowId} (hash: ${stateHash.slice(0, 12)}...)`
)
return {
snapshot: {
...newSnapshot,
stateData: newSnapshot.stateData as WorkflowState,
createdAt: newSnapshot.createdAt.toISOString(),
...upsertedSnapshot,
stateData: upsertedSnapshot.stateData as WorkflowState,
createdAt: upsertedSnapshot.createdAt.toISOString(),
},
isNew: true,
isNew,
}
}

View File

@@ -4,6 +4,7 @@ export interface PermissionGroupConfig {
// Platform Configuration
hideTraceSpans: boolean
hideKnowledgeBaseTab: boolean
hideTablesTab: boolean
hideCopilot: boolean
hideApiKeysTab: boolean
hideEnvironmentTab: boolean
@@ -26,6 +27,7 @@ export const DEFAULT_PERMISSION_GROUP_CONFIG: PermissionGroupConfig = {
allowedModelProviders: null,
hideTraceSpans: false,
hideKnowledgeBaseTab: false,
hideTablesTab: false,
hideCopilot: false,
hideApiKeysTab: false,
hideEnvironmentTab: false,
@@ -55,6 +57,7 @@ export function parsePermissionGroupConfig(config: unknown): PermissionGroupConf
hideTraceSpans: typeof c.hideTraceSpans === 'boolean' ? c.hideTraceSpans : false,
hideKnowledgeBaseTab:
typeof c.hideKnowledgeBaseTab === 'boolean' ? c.hideKnowledgeBaseTab : false,
hideTablesTab: typeof c.hideTablesTab === 'boolean' ? c.hideTablesTab : false,
hideCopilot: typeof c.hideCopilot === 'boolean' ? c.hideCopilot : false,
hideApiKeysTab: typeof c.hideApiKeysTab === 'boolean' ? c.hideApiKeysTab : false,
hideEnvironmentTab: typeof c.hideEnvironmentTab === 'boolean' ? c.hideEnvironmentTab : false,

View File

@@ -111,6 +111,7 @@ export interface FilterRule {
column: string
operator: string
value: string
collapsed?: boolean
}
/**
@@ -121,6 +122,7 @@ export interface SortRule {
id: string
column: string
direction: SortDirection
collapsed?: boolean
}
export interface QueryOptions {

View File

@@ -834,6 +834,23 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
},
icon: GeminiIcon,
models: [
{
id: 'gemini-3.1-pro-preview',
pricing: {
input: 2.0,
cachedInput: 0.2,
output: 12.0,
updatedAt: '2026-02-19',
},
capabilities: {
temperature: { min: 0, max: 2 },
thinking: {
levels: ['low', 'medium', 'high'],
default: 'high',
},
},
contextWindow: 1048576,
},
{
id: 'gemini-3-pro-preview',
pricing: {
@@ -845,7 +862,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
capabilities: {
temperature: { min: 0, max: 2 },
thinking: {
levels: ['low', 'high'],
levels: ['low', 'medium', 'high'],
default: 'high',
},
},
@@ -957,6 +974,23 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
toolUsageControl: true,
},
models: [
{
id: 'vertex/gemini-3.1-pro-preview',
pricing: {
input: 2.0,
cachedInput: 0.2,
output: 12.0,
updatedAt: '2026-02-19',
},
capabilities: {
temperature: { min: 0, max: 2 },
thinking: {
levels: ['low', 'medium', 'high'],
default: 'high',
},
},
contextWindow: 1048576,
},
{
id: 'vertex/gemini-3-pro-preview',
pricing: {
@@ -968,7 +1002,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
capabilities: {
temperature: { min: 0, max: 2 },
thinking: {
levels: ['low', 'high'],
levels: ['low', 'medium', 'high'],
default: 'high',
},
},

View File

@@ -0,0 +1,12 @@
<svg width="400" height="400" viewBox="0 0 400 400" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="400" height="400" fill="#0B0B0B"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M196.822 182.761C196.822 186.348 195.403 189.792 192.884 192.328L192.523 192.692C190.006 195.236 186.586 196.658 183.024 196.658H102.445C95.0246 196.658 89 202.718 89 210.191V297.332C89 304.806 95.0246 310.866 102.445 310.866H188.962C196.383 310.866 202.4 304.806 202.4 297.332V215.745C202.4 212.419 203.71 209.228 206.047 206.874C208.377 204.527 211.546 203.207 214.849 203.207H296.777C304.198 203.207 310.214 197.148 310.214 189.674V102.533C310.214 95.0596 304.198 89 296.777 89H210.26C202.839 89 196.822 95.0596 196.822 102.533V182.761ZM223.078 107.55H283.952C288.289 107.55 291.796 111.089 291.796 115.45V176.757C291.796 181.118 288.289 184.658 283.952 184.658H223.078C218.748 184.658 215.233 181.118 215.233 176.757V115.45C215.233 111.089 218.748 107.55 223.078 107.55Z" fill="#33C482"/>
<path d="M296.878 218.57H232.554C224.756 218.57 218.434 224.937 218.434 232.791V296.784C218.434 304.638 224.756 311.005 232.554 311.005H296.878C304.677 311.005 310.999 304.638 310.999 296.784V232.791C310.999 224.937 304.677 218.57 296.878 218.57Z" fill="#33C482"/>
<path d="M296.878 218.27H232.554C224.756 218.27 218.434 224.636 218.434 232.491V296.483C218.434 304.337 224.756 310.703 232.554 310.703H296.878C304.677 310.703 310.999 304.337 310.999 296.483V232.491C310.999 224.636 304.677 218.27 296.878 218.27Z" fill="url(#paint0_linear_2686_11143)" fill-opacity="0.2"/>
<defs>
<linearGradient id="paint0_linear_2686_11143" x1="218.434" y1="218.27" x2="274.629" y2="274.334" gradientUnits="userSpaceOnUse">
<stop/>
<stop offset="1" stop-opacity="0"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -0,0 +1,11 @@
<svg width="222" height="222" viewBox="0 0 222 222" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M107.822 93.7612C107.822 97.3481 106.403 100.792 103.884 103.328L103.523 103.692C101.006 106.236 97.5855 107.658 94.0236 107.658H13.4455C6.02456 107.658 0 113.718 0 121.191V208.332C0 215.806 6.02456 221.866 13.4455 221.866H99.9622C107.383 221.866 113.4 215.806 113.4 208.332V126.745C113.4 123.419 114.71 120.228 117.047 117.874C119.377 115.527 122.546 114.207 125.849 114.207H207.777C215.198 114.207 221.214 108.148 221.214 100.674V13.5333C221.214 6.05956 215.198 0 207.777 0H121.26C113.839 0 107.822 6.05956 107.822 13.5333V93.7612ZM134.078 18.55H194.952C199.289 18.55 202.796 22.0893 202.796 26.4503V87.7574C202.796 92.1178 199.289 95.6577 194.952 95.6577H134.078C129.748 95.6577 126.233 92.1178 126.233 87.7574V26.4503C126.233 22.0893 129.748 18.55 134.078 18.55Z" fill="#33C482"/>
<path d="M207.878 129.57H143.554C135.756 129.57 129.434 135.937 129.434 143.791V207.784C129.434 215.638 135.756 222.005 143.554 222.005H207.878C215.677 222.005 221.999 215.638 221.999 207.784V143.791C221.999 135.937 215.677 129.57 207.878 129.57Z" fill="#33C482"/>
<path d="M207.878 129.27H143.554C135.756 129.27 129.434 135.636 129.434 143.491V207.483C129.434 215.337 135.756 221.703 143.554 221.703H207.878C215.677 221.703 221.999 215.337 221.999 207.483V143.491C221.999 135.636 215.677 129.27 207.878 129.27Z" fill="url(#paint0_linear_2888_11298)" fill-opacity="0.2"/>
<defs>
<linearGradient id="paint0_linear_2888_11298" x1="129.434" y1="129.27" x2="185.629" y2="185.334" gradientUnits="userSpaceOnUse">
<stop/>
<stop offset="1" stop-opacity="0"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -0,0 +1,11 @@
<svg width="222" height="222" viewBox="0 0 222 222" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M107.822 93.7612C107.822 97.3481 106.403 100.792 103.884 103.328L103.523 103.692C101.006 106.236 97.5855 107.658 94.0236 107.658H13.4455C6.02456 107.658 0 113.718 0 121.191V208.332C0 215.806 6.02456 221.866 13.4455 221.866H99.9622C107.383 221.866 113.4 215.806 113.4 208.332V126.745C113.4 123.419 114.71 120.228 117.047 117.874C119.377 115.527 122.546 114.207 125.849 114.207H207.777C215.198 114.207 221.214 108.148 221.214 100.674V13.5333C221.214 6.05956 215.198 0 207.777 0H121.26C113.839 0 107.822 6.05956 107.822 13.5333V93.7612ZM134.078 18.55H194.952C199.289 18.55 202.796 22.0893 202.796 26.4503V87.7574C202.796 92.1178 199.289 95.6577 194.952 95.6577H134.078C129.748 95.6577 126.233 92.1178 126.233 87.7574V26.4503C126.233 22.0893 129.748 18.55 134.078 18.55Z" fill="white"/>
<path d="M207.882 129.57H143.558C135.76 129.57 129.438 135.937 129.438 143.791V207.784C129.438 215.638 135.76 222.005 143.558 222.005H207.882C215.681 222.005 222.003 215.638 222.003 207.784V143.791C222.003 135.937 215.681 129.57 207.882 129.57Z" fill="white"/>
<path d="M207.882 129.27H143.557C135.759 129.27 129.438 135.636 129.438 143.491V207.483C129.438 215.337 135.759 221.703 143.557 221.703H207.882C215.681 221.703 222.003 215.337 222.003 207.483V143.491C222.003 135.636 215.681 129.27 207.882 129.27Z" fill="url(#paint0_linear_2888_11298)" fill-opacity="0.2"/>
<defs>
<linearGradient id="paint0_linear_2888_11298" x1="129.438" y1="129.27" x2="185.633" y2="185.334" gradientUnits="userSpaceOnUse">
<stop/>
<stop offset="1" stop-opacity="0"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -4,7 +4,7 @@
* @vitest-environment node
*/
import { createServer, request as httpRequest } from 'http'
import { createMockLogger, databaseMock } from '@sim/testing'
import { createEnvMock, createMockLogger, databaseMock } from '@sim/testing'
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { createSocketIOServer } from '@/socket/config/socket'
import { MemoryRoomManager } from '@/socket/rooms'
@@ -30,19 +30,13 @@ vi.mock('redis', () => ({
})),
}))
// Mock env to not have REDIS_URL (use importOriginal to get helper functions)
vi.mock('@/lib/core/config/env', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/lib/core/config/env')>()
return {
...actual,
env: {
...actual.env,
DATABASE_URL: 'postgres://localhost/test',
NODE_ENV: 'test',
REDIS_URL: undefined,
},
}
})
vi.mock('@/lib/core/config/env', () =>
createEnvMock({
DATABASE_URL: 'postgres://localhost/test',
NODE_ENV: 'test',
REDIS_URL: undefined,
})
)
vi.mock('@/socket/middleware/auth', () => ({
authenticateSocket: vi.fn((socket, next) => {

View File

@@ -0,0 +1,98 @@
import type { AlgoliaAddRecordParams, AlgoliaAddRecordResponse } from '@/tools/algolia/types'
import type { ToolConfig } from '@/tools/types'
export const addRecordTool: ToolConfig<AlgoliaAddRecordParams, AlgoliaAddRecordResponse> = {
id: 'algolia_add_record',
name: 'Algolia Add Record',
description: 'Add or replace a record in an Algolia index',
version: '1.0',
params: {
applicationId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Application ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Admin API Key',
},
indexName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the Algolia index',
},
objectID: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Object ID for the record (auto-generated if not provided)',
},
record: {
type: 'json',
required: true,
visibility: 'user-or-llm',
description: 'JSON object representing the record to add',
},
},
request: {
url: (params) => {
const base = `https://${params.applicationId}.algolia.net/1/indexes/${encodeURIComponent(params.indexName)}`
if (params.objectID) {
return `${base}/${encodeURIComponent(params.objectID)}`
}
return base
},
method: (params) => (params.objectID ? 'PUT' : 'POST'),
headers: (params) => ({
'x-algolia-application-id': params.applicationId,
'x-algolia-api-key': params.apiKey,
'Content-Type': 'application/json',
}),
body: (params) => {
const record = typeof params.record === 'string' ? JSON.parse(params.record) : params.record
return record
},
},
transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
taskID: data.taskID ?? 0,
objectID: data.objectID ?? '',
createdAt: data.createdAt ?? null,
updatedAt: data.updatedAt ?? null,
},
}
},
outputs: {
taskID: {
type: 'number',
description: 'Algolia task ID for tracking the indexing operation',
},
objectID: {
type: 'string',
description: 'The object ID of the added or replaced record',
},
createdAt: {
type: 'string',
description:
'Timestamp when the record was created (only present when objectID is auto-generated)',
optional: true,
},
updatedAt: {
type: 'string',
description:
'Timestamp when the record was updated (only present when replacing an existing record)',
optional: true,
},
},
}

View File

@@ -0,0 +1,86 @@
import type {
AlgoliaBatchOperationsParams,
AlgoliaBatchOperationsResponse,
} from '@/tools/algolia/types'
import type { ToolConfig } from '@/tools/types'
export const batchOperationsTool: ToolConfig<
AlgoliaBatchOperationsParams,
AlgoliaBatchOperationsResponse
> = {
id: 'algolia_batch_operations',
name: 'Algolia Batch Operations',
description:
'Perform batch add, update, partial update, or delete operations on records in an Algolia index',
version: '1.0',
params: {
applicationId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Application ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Admin API Key',
},
indexName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the Algolia index',
},
requests: {
type: 'json',
required: true,
visibility: 'user-or-llm',
description:
'Array of batch operations. Each item has "action" (addObject, updateObject, partialUpdateObject, partialUpdateObjectNoCreate, deleteObject) and "body" (the record data, must include objectID for update/delete)',
},
},
request: {
url: (params) =>
`https://${params.applicationId}.algolia.net/1/indexes/${encodeURIComponent(params.indexName)}/batch`,
method: 'POST',
headers: (params) => ({
'x-algolia-application-id': params.applicationId,
'x-algolia-api-key': params.apiKey,
'Content-Type': 'application/json',
}),
body: (params) => {
const requests =
typeof params.requests === 'string' ? JSON.parse(params.requests) : params.requests
return { requests }
},
},
transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
taskID: data.taskID ?? 0,
objectIDs: data.objectIDs ?? [],
},
}
},
outputs: {
taskID: {
type: 'number',
description: 'Algolia task ID for tracking the batch operation',
},
objectIDs: {
type: 'array',
description: 'Array of object IDs affected by the batch operation',
items: {
type: 'string',
description: 'Unique identifier of an affected record',
},
},
},
}

View File

@@ -0,0 +1,151 @@
import type {
AlgoliaBrowseRecordsParams,
AlgoliaBrowseRecordsResponse,
} from '@/tools/algolia/types'
import type { ToolConfig } from '@/tools/types'
export const browseRecordsTool: ToolConfig<
AlgoliaBrowseRecordsParams,
AlgoliaBrowseRecordsResponse
> = {
id: 'algolia_browse_records',
name: 'Algolia Browse Records',
description: 'Browse and iterate over all records in an Algolia index using cursor pagination',
version: '1.0',
params: {
applicationId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Application ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia API Key (must have browse ACL)',
},
indexName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the Algolia index to browse',
},
query: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Search query to filter browsed records',
},
filters: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Filter string to narrow down results',
},
attributesToRetrieve: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Comma-separated list of attributes to retrieve',
},
hitsPerPage: {
type: 'number',
required: false,
visibility: 'user-or-llm',
description: 'Number of hits per page (default: 1000, max: 1000)',
},
cursor: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Cursor from a previous browse response for pagination',
},
},
request: {
url: (params) =>
`https://${params.applicationId}-dsn.algolia.net/1/indexes/${encodeURIComponent(params.indexName)}/browse`,
method: 'POST',
headers: (params) => ({
'x-algolia-application-id': params.applicationId,
'x-algolia-api-key': params.apiKey,
'Content-Type': 'application/json',
}),
body: (params) => {
if (params.cursor) {
return { cursor: params.cursor }
}
const body: Record<string, unknown> = {}
if (params.query) body.query = params.query
if (params.filters) body.filters = params.filters
if (params.attributesToRetrieve) {
body.attributesToRetrieve = params.attributesToRetrieve
.split(',')
.map((a: string) => a.trim())
}
if (params.hitsPerPage !== undefined) body.hitsPerPage = Number(params.hitsPerPage)
return body
},
},
transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
hits: data.hits ?? [],
cursor: data.cursor ?? null,
nbHits: data.nbHits ?? 0,
page: data.page ?? 0,
nbPages: data.nbPages ?? 0,
hitsPerPage: data.hitsPerPage ?? 1000,
processingTimeMS: data.processingTimeMS ?? 0,
},
}
},
outputs: {
hits: {
type: 'array',
description: 'Array of records from the index (up to 1000 per request)',
items: {
type: 'object',
description: 'A record object containing objectID plus any requested attributes',
properties: {
objectID: {
type: 'string',
description: 'Unique identifier of the record',
},
},
},
},
cursor: {
type: 'string',
description:
'Opaque cursor string for retrieving the next page of results. Absent when no more results exist.',
optional: true,
},
nbHits: {
type: 'number',
description: 'Total number of records matching the browse criteria',
},
page: {
type: 'number',
description: 'Current page number (zero-based)',
},
nbPages: {
type: 'number',
description: 'Total number of pages available',
},
hitsPerPage: {
type: 'number',
description: 'Number of hits per page (1-1000, default 1000 for browse)',
},
processingTimeMS: {
type: 'number',
description: 'Server-side processing time in milliseconds',
},
},
}

View File

@@ -0,0 +1,66 @@
import type { AlgoliaClearRecordsParams, AlgoliaClearRecordsResponse } from '@/tools/algolia/types'
import type { ToolConfig } from '@/tools/types'
export const clearRecordsTool: ToolConfig<AlgoliaClearRecordsParams, AlgoliaClearRecordsResponse> =
{
id: 'algolia_clear_records',
name: 'Algolia Clear Records',
description:
'Clear all records from an Algolia index while keeping settings, synonyms, and rules',
version: '1.0',
params: {
applicationId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Application ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Admin API Key (must have deleteIndex ACL)',
},
indexName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the Algolia index to clear',
},
},
request: {
url: (params) =>
`https://${params.applicationId}.algolia.net/1/indexes/${encodeURIComponent(params.indexName)}/clear`,
method: 'POST',
headers: (params) => ({
'x-algolia-application-id': params.applicationId,
'x-algolia-api-key': params.apiKey,
'Content-Type': 'application/json',
}),
},
transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
taskID: data.taskID ?? 0,
updatedAt: data.updatedAt ?? null,
},
}
},
outputs: {
taskID: {
type: 'number',
description: 'Algolia task ID for tracking the clear operation',
},
updatedAt: {
type: 'string',
description: 'Timestamp when the records were cleared',
optional: true,
},
},
}

View File

@@ -0,0 +1,100 @@
import type {
AlgoliaCopyMoveIndexParams,
AlgoliaCopyMoveIndexResponse,
} from '@/tools/algolia/types'
import type { ToolConfig } from '@/tools/types'
export const copyMoveIndexTool: ToolConfig<
AlgoliaCopyMoveIndexParams,
AlgoliaCopyMoveIndexResponse
> = {
id: 'algolia_copy_move_index',
name: 'Algolia Copy/Move Index',
description: 'Copy or move an Algolia index to a new destination',
version: '1.0',
params: {
applicationId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Application ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Admin API Key',
},
indexName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the source index',
},
operation: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Operation to perform: "copy" or "move"',
},
destination: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the destination index',
},
scope: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description:
'Array of scopes to copy (only for "copy" operation): ["settings", "synonyms", "rules"]. Omit to copy everything including records.',
},
},
request: {
url: (params) =>
`https://${params.applicationId}.algolia.net/1/indexes/${encodeURIComponent(params.indexName)}/operation`,
method: 'POST',
headers: (params) => ({
'x-algolia-application-id': params.applicationId,
'x-algolia-api-key': params.apiKey,
'Content-Type': 'application/json',
}),
body: (params) => {
const body: Record<string, unknown> = {
operation: params.operation,
destination: params.destination,
}
if (params.scope) {
const scope = typeof params.scope === 'string' ? JSON.parse(params.scope) : params.scope
body.scope = scope
}
return body
},
},
transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
taskID: data.taskID ?? 0,
updatedAt: data.updatedAt ?? null,
},
}
},
outputs: {
taskID: {
type: 'number',
description: 'Algolia task ID for tracking the copy/move operation',
},
updatedAt: {
type: 'string',
description: 'Timestamp when the operation was performed',
optional: true,
},
},
}

View File

@@ -0,0 +1,160 @@
import type {
AlgoliaDeleteByFilterParams,
AlgoliaDeleteByFilterResponse,
} from '@/tools/algolia/types'
import type { ToolConfig } from '@/tools/types'
export const deleteByFilterTool: ToolConfig<
AlgoliaDeleteByFilterParams,
AlgoliaDeleteByFilterResponse
> = {
id: 'algolia_delete_by_filter',
name: 'Algolia Delete By Filter',
description: 'Delete all records matching a filter from an Algolia index',
version: '1.0',
params: {
applicationId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Application ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Admin API Key (must have deleteIndex ACL)',
},
indexName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the Algolia index',
},
filters: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Filter expression to match records for deletion (e.g., "category:outdated")',
},
facetFilters: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description: 'Array of facet filters (e.g., ["brand:Acme"])',
},
numericFilters: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description: 'Array of numeric filters (e.g., ["price > 100"])',
},
tagFilters: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description: 'Array of tag filters using the _tags attribute (e.g., ["published"])',
},
aroundLatLng: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Coordinates for geo-search filter (e.g., "40.71,-74.01")',
},
aroundRadius: {
type: 'number',
required: false,
visibility: 'user-or-llm',
description: 'Maximum radius in meters for geo-search, or "all" for unlimited',
},
insideBoundingBox: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description: 'Bounding box coordinates as [[lat1, lng1, lat2, lng2]] for geo-search filter',
},
insidePolygon: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description:
'Polygon coordinates as [[lat1, lng1, lat2, lng2, lat3, lng3, ...]] for geo-search filter',
},
},
request: {
url: (params) =>
`https://${params.applicationId}.algolia.net/1/indexes/${encodeURIComponent(params.indexName)}/deleteByQuery`,
method: 'POST',
headers: (params) => ({
'x-algolia-application-id': params.applicationId,
'x-algolia-api-key': params.apiKey,
'Content-Type': 'application/json',
}),
body: (params) => {
const body: Record<string, unknown> = {}
if (params.filters) {
body.filters = params.filters
}
if (params.facetFilters) {
body.facetFilters =
typeof params.facetFilters === 'string'
? JSON.parse(params.facetFilters)
: params.facetFilters
}
if (params.numericFilters) {
body.numericFilters =
typeof params.numericFilters === 'string'
? JSON.parse(params.numericFilters)
: params.numericFilters
}
if (params.tagFilters) {
body.tagFilters =
typeof params.tagFilters === 'string' ? JSON.parse(params.tagFilters) : params.tagFilters
}
if (params.aroundLatLng) {
body.aroundLatLng = params.aroundLatLng
}
if (params.aroundRadius !== undefined) {
body.aroundRadius = params.aroundRadius === 'all' ? 'all' : Number(params.aroundRadius)
}
if (params.insideBoundingBox) {
body.insideBoundingBox =
typeof params.insideBoundingBox === 'string'
? JSON.parse(params.insideBoundingBox)
: params.insideBoundingBox
}
if (params.insidePolygon) {
body.insidePolygon =
typeof params.insidePolygon === 'string'
? JSON.parse(params.insidePolygon)
: params.insidePolygon
}
return body
},
},
transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
taskID: data.taskID ?? 0,
updatedAt: data.updatedAt ?? null,
},
}
},
outputs: {
taskID: {
type: 'number',
description: 'Algolia task ID for tracking the delete-by-filter operation',
},
updatedAt: {
type: 'string',
description: 'Timestamp when the operation was performed',
optional: true,
},
},
}

View File

@@ -0,0 +1,63 @@
import type { AlgoliaDeleteIndexParams, AlgoliaDeleteIndexResponse } from '@/tools/algolia/types'
import type { ToolConfig } from '@/tools/types'
export const deleteIndexTool: ToolConfig<AlgoliaDeleteIndexParams, AlgoliaDeleteIndexResponse> = {
id: 'algolia_delete_index',
name: 'Algolia Delete Index',
description: 'Delete an entire Algolia index and all its records',
version: '1.0',
params: {
applicationId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Application ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Admin API Key (must have deleteIndex ACL)',
},
indexName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the Algolia index to delete',
},
},
request: {
method: 'DELETE',
url: (params) =>
`https://${params.applicationId}.algolia.net/1/indexes/${encodeURIComponent(params.indexName)}`,
headers: (params) => ({
'x-algolia-application-id': params.applicationId,
'x-algolia-api-key': params.apiKey,
}),
},
transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
taskID: data.taskID ?? 0,
deletedAt: data.deletedAt ?? null,
},
}
},
outputs: {
taskID: {
type: 'number',
description: 'Algolia task ID for tracking the index deletion',
},
deletedAt: {
type: 'string',
description: 'Timestamp when the index was deleted',
optional: true,
},
},
}

View File

@@ -0,0 +1,69 @@
import type { AlgoliaDeleteRecordParams, AlgoliaDeleteRecordResponse } from '@/tools/algolia/types'
import type { ToolConfig } from '@/tools/types'
export const deleteRecordTool: ToolConfig<AlgoliaDeleteRecordParams, AlgoliaDeleteRecordResponse> =
{
id: 'algolia_delete_record',
name: 'Algolia Delete Record',
description: 'Delete a record by objectID from an Algolia index',
version: '1.0',
params: {
applicationId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Application ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Admin API Key',
},
indexName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the Algolia index',
},
objectID: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The objectID of the record to delete',
},
},
request: {
method: 'DELETE',
url: (params) =>
`https://${params.applicationId}.algolia.net/1/indexes/${encodeURIComponent(params.indexName)}/${encodeURIComponent(params.objectID)}`,
headers: (params) => ({
'x-algolia-application-id': params.applicationId,
'x-algolia-api-key': params.apiKey,
}),
},
transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
taskID: data.taskID ?? 0,
deletedAt: data.deletedAt ?? null,
},
}
},
outputs: {
taskID: {
type: 'number',
description: 'Algolia task ID for tracking the deletion',
},
deletedAt: {
type: 'string',
description: 'Timestamp when the record was deleted',
},
},
}

View File

@@ -0,0 +1,80 @@
import type { AlgoliaGetRecordParams, AlgoliaGetRecordResponse } from '@/tools/algolia/types'
import type { ToolConfig } from '@/tools/types'
export const getRecordTool: ToolConfig<AlgoliaGetRecordParams, AlgoliaGetRecordResponse> = {
id: 'algolia_get_record',
name: 'Algolia Get Record',
description: 'Get a record by objectID from an Algolia index',
version: '1.0',
params: {
applicationId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Application ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia API Key',
},
indexName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the Algolia index',
},
objectID: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The objectID of the record to retrieve',
},
attributesToRetrieve: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Comma-separated list of attributes to retrieve',
},
},
request: {
method: 'GET',
url: (params) => {
const base = `https://${params.applicationId}-dsn.algolia.net/1/indexes/${encodeURIComponent(params.indexName)}/${encodeURIComponent(params.objectID)}`
if (params.attributesToRetrieve) {
return `${base}?attributesToRetrieve=${encodeURIComponent(params.attributesToRetrieve)}`
}
return base
},
headers: (params) => ({
'x-algolia-application-id': params.applicationId,
'x-algolia-api-key': params.apiKey,
}),
},
transformResponse: async (response) => {
const data = await response.json()
const { objectID, ...rest } = data
return {
success: true,
output: {
objectID: objectID ?? '',
record: rest,
},
}
},
outputs: {
objectID: {
type: 'string',
description: 'The objectID of the retrieved record',
},
record: {
type: 'object',
description: 'The record data (all attributes)',
},
},
}

Some files were not shown because too many files have changed in this diff Show More