mirror of
https://github.com/simstudioai/sim.git
synced 2026-03-15 03:00:33 -04:00
Compare commits
1 Commits
staging
...
improvemen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33cf0de31e |
@@ -14,11 +14,18 @@ import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
||||
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
|
||||
|
||||
/**
|
||||
* Dropdown option type - can be a simple string or an object with label, id, and optional icon
|
||||
* Dropdown option type - can be a simple string or an object with label, id, and optional icon.
|
||||
* Options with `hidden: true` are excluded from the picker but still resolve for label display,
|
||||
* so existing workflows that reference them continue to work.
|
||||
*/
|
||||
type DropdownOption =
|
||||
| string
|
||||
| { label: string; id: string; icon?: React.ComponentType<{ className?: string }> }
|
||||
| {
|
||||
label: string
|
||||
id: string
|
||||
icon?: React.ComponentType<{ className?: string }>
|
||||
hidden?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Props for the Dropdown component
|
||||
@@ -185,13 +192,12 @@ export const Dropdown = memo(function Dropdown({
|
||||
return fetchedOptions.map((opt) => ({ label: opt.label, id: opt.id }))
|
||||
}, [fetchedOptions])
|
||||
|
||||
const availableOptions = useMemo(() => {
|
||||
const allOptions = useMemo(() => {
|
||||
let opts: DropdownOption[] =
|
||||
fetchOptions && normalizedFetchedOptions.length > 0
|
||||
? normalizedFetchedOptions
|
||||
: evaluatedOptions
|
||||
|
||||
// Merge hydrated option if not already present
|
||||
if (hydratedOption) {
|
||||
const alreadyPresent = opts.some((o) =>
|
||||
typeof o === 'string' ? o === hydratedOption.id : o.id === hydratedOption.id
|
||||
@@ -204,11 +210,12 @@ export const Dropdown = memo(function Dropdown({
|
||||
return opts
|
||||
}, [fetchOptions, normalizedFetchedOptions, evaluatedOptions, hydratedOption])
|
||||
|
||||
/**
|
||||
* Convert dropdown options to Combobox format
|
||||
*/
|
||||
const selectableOptions = useMemo(() => {
|
||||
return allOptions.filter((opt) => typeof opt === 'string' || !opt.hidden)
|
||||
}, [allOptions])
|
||||
|
||||
const comboboxOptions = useMemo((): ComboboxOption[] => {
|
||||
return availableOptions.map((opt) => {
|
||||
return selectableOptions.map((opt) => {
|
||||
if (typeof opt === 'string') {
|
||||
return { label: opt.toLowerCase(), value: opt }
|
||||
}
|
||||
@@ -218,11 +225,16 @@ export const Dropdown = memo(function Dropdown({
|
||||
icon: 'icon' in opt ? opt.icon : undefined,
|
||||
}
|
||||
})
|
||||
}, [availableOptions])
|
||||
}, [selectableOptions])
|
||||
|
||||
const optionMap = useMemo(() => {
|
||||
return new Map(comboboxOptions.map((opt) => [opt.value, opt.label]))
|
||||
}, [comboboxOptions])
|
||||
return new Map(
|
||||
allOptions.map((opt) => {
|
||||
if (typeof opt === 'string') return [opt, opt.toLowerCase()]
|
||||
return [opt.id, opt.label.toLowerCase()]
|
||||
})
|
||||
)
|
||||
}, [allOptions])
|
||||
|
||||
const defaultOptionValue = useMemo(() => {
|
||||
if (multiSelect) return undefined
|
||||
|
||||
@@ -268,15 +268,17 @@ Return ONLY the search term - no explanations, no quotes, no extra text.`,
|
||||
type: 'dropdown',
|
||||
mode: 'trigger',
|
||||
options: grainTriggerOptions,
|
||||
value: () => 'grain_webhook',
|
||||
value: () => 'grain_item_added',
|
||||
required: true,
|
||||
},
|
||||
...getTrigger('grain_item_added').subBlocks,
|
||||
...getTrigger('grain_item_updated').subBlocks,
|
||||
...getTrigger('grain_webhook').subBlocks,
|
||||
...getTrigger('grain_recording_created').subBlocks,
|
||||
...getTrigger('grain_recording_updated').subBlocks,
|
||||
...getTrigger('grain_highlight_created').subBlocks,
|
||||
...getTrigger('grain_highlight_updated').subBlocks,
|
||||
...getTrigger('grain_story_created').subBlocks,
|
||||
...getTrigger('grain_webhook').subBlocks,
|
||||
],
|
||||
tools: {
|
||||
access: [
|
||||
@@ -447,12 +449,14 @@ Return ONLY the search term - no explanations, no quotes, no extra text.`,
|
||||
triggers: {
|
||||
enabled: true,
|
||||
available: [
|
||||
'grain_item_added',
|
||||
'grain_item_updated',
|
||||
'grain_webhook',
|
||||
'grain_recording_created',
|
||||
'grain_recording_updated',
|
||||
'grain_highlight_created',
|
||||
'grain_highlight_updated',
|
||||
'grain_story_created',
|
||||
'grain_webhook',
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
@@ -233,12 +233,14 @@ export interface SubBlockConfig {
|
||||
id: string
|
||||
icon?: React.ComponentType<{ className?: string }>
|
||||
group?: string
|
||||
hidden?: boolean
|
||||
}[]
|
||||
| (() => {
|
||||
label: string
|
||||
id: string
|
||||
icon?: React.ComponentType<{ className?: string }>
|
||||
group?: string
|
||||
hidden?: boolean
|
||||
}[])
|
||||
min?: number
|
||||
max?: number
|
||||
|
||||
@@ -1258,6 +1258,8 @@ export async function createGrainWebhookSubscription(
|
||||
}
|
||||
|
||||
const actionMap: Record<string, Array<'added' | 'updated' | 'removed'>> = {
|
||||
grain_item_added: ['added'],
|
||||
grain_item_updated: ['updated'],
|
||||
grain_recording_created: ['added'],
|
||||
grain_recording_updated: ['updated'],
|
||||
grain_highlight_created: ['added'],
|
||||
@@ -1267,6 +1269,8 @@ export async function createGrainWebhookSubscription(
|
||||
|
||||
const eventTypeMap: Record<string, string[]> = {
|
||||
grain_webhook: [],
|
||||
grain_item_added: [],
|
||||
grain_item_updated: [],
|
||||
grain_recording_created: ['recording_added'],
|
||||
grain_recording_updated: ['recording_updated'],
|
||||
grain_highlight_created: ['highlight_added'],
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
export { grainHighlightCreatedTrigger } from './highlight_created'
|
||||
export { grainHighlightUpdatedTrigger } from './highlight_updated'
|
||||
export { grainItemAddedTrigger } from './item_added'
|
||||
export { grainItemUpdatedTrigger } from './item_updated'
|
||||
export { grainRecordingCreatedTrigger } from './recording_created'
|
||||
export { grainRecordingUpdatedTrigger } from './recording_updated'
|
||||
export { grainStoryCreatedTrigger } from './story_created'
|
||||
|
||||
76
apps/sim/triggers/grain/item_added.ts
Normal file
76
apps/sim/triggers/grain/item_added.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { GrainIcon } from '@/components/icons'
|
||||
import type { TriggerConfig } from '@/triggers/types'
|
||||
import { buildGenericOutputs, grainV2SetupInstructions } from './utils'
|
||||
|
||||
export const grainItemAddedTrigger: TriggerConfig = {
|
||||
id: 'grain_item_added',
|
||||
name: 'Grain Item Added',
|
||||
provider: 'grain',
|
||||
description: 'Trigger when a new item is added to a Grain view (recording, highlight, or story)',
|
||||
version: '1.0.0',
|
||||
icon: GrainIcon,
|
||||
|
||||
subBlocks: [
|
||||
{
|
||||
id: 'apiKey',
|
||||
title: 'API Key',
|
||||
type: 'short-input',
|
||||
placeholder: 'Enter your Grain API key (Personal Access Token)',
|
||||
description: 'Required to create the webhook in Grain.',
|
||||
password: true,
|
||||
required: true,
|
||||
mode: 'trigger',
|
||||
condition: {
|
||||
field: 'selectedTriggerId',
|
||||
value: 'grain_item_added',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'viewId',
|
||||
title: 'View ID',
|
||||
type: 'short-input',
|
||||
placeholder: 'Enter Grain view UUID',
|
||||
description:
|
||||
'The view determines which content type fires events (recordings, highlights, or stories).',
|
||||
required: true,
|
||||
mode: 'trigger',
|
||||
condition: {
|
||||
field: 'selectedTriggerId',
|
||||
value: 'grain_item_added',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'triggerSave',
|
||||
title: '',
|
||||
type: 'trigger-save',
|
||||
hideFromPreview: true,
|
||||
mode: 'trigger',
|
||||
triggerId: 'grain_item_added',
|
||||
condition: {
|
||||
field: 'selectedTriggerId',
|
||||
value: 'grain_item_added',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'triggerInstructions',
|
||||
title: 'Setup Instructions',
|
||||
hideFromPreview: true,
|
||||
type: 'text',
|
||||
defaultValue: grainV2SetupInstructions('item added'),
|
||||
mode: 'trigger',
|
||||
condition: {
|
||||
field: 'selectedTriggerId',
|
||||
value: 'grain_item_added',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
outputs: buildGenericOutputs(),
|
||||
|
||||
webhook: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
},
|
||||
}
|
||||
76
apps/sim/triggers/grain/item_updated.ts
Normal file
76
apps/sim/triggers/grain/item_updated.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { GrainIcon } from '@/components/icons'
|
||||
import type { TriggerConfig } from '@/triggers/types'
|
||||
import { buildGenericOutputs, grainV2SetupInstructions } from './utils'
|
||||
|
||||
export const grainItemUpdatedTrigger: TriggerConfig = {
|
||||
id: 'grain_item_updated',
|
||||
name: 'Grain Item Updated',
|
||||
provider: 'grain',
|
||||
description: 'Trigger when an item is updated in a Grain view (recording, highlight, or story)',
|
||||
version: '1.0.0',
|
||||
icon: GrainIcon,
|
||||
|
||||
subBlocks: [
|
||||
{
|
||||
id: 'apiKey',
|
||||
title: 'API Key',
|
||||
type: 'short-input',
|
||||
placeholder: 'Enter your Grain API key (Personal Access Token)',
|
||||
description: 'Required to create the webhook in Grain.',
|
||||
password: true,
|
||||
required: true,
|
||||
mode: 'trigger',
|
||||
condition: {
|
||||
field: 'selectedTriggerId',
|
||||
value: 'grain_item_updated',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'viewId',
|
||||
title: 'View ID',
|
||||
type: 'short-input',
|
||||
placeholder: 'Enter Grain view UUID',
|
||||
description:
|
||||
'The view determines which content type fires events (recordings, highlights, or stories).',
|
||||
required: true,
|
||||
mode: 'trigger',
|
||||
condition: {
|
||||
field: 'selectedTriggerId',
|
||||
value: 'grain_item_updated',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'triggerSave',
|
||||
title: '',
|
||||
type: 'trigger-save',
|
||||
hideFromPreview: true,
|
||||
mode: 'trigger',
|
||||
triggerId: 'grain_item_updated',
|
||||
condition: {
|
||||
field: 'selectedTriggerId',
|
||||
value: 'grain_item_updated',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'triggerInstructions',
|
||||
title: 'Setup Instructions',
|
||||
hideFromPreview: true,
|
||||
type: 'text',
|
||||
defaultValue: grainV2SetupInstructions('item updated'),
|
||||
mode: 'trigger',
|
||||
condition: {
|
||||
field: 'selectedTriggerId',
|
||||
value: 'grain_item_updated',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
outputs: buildGenericOutputs(),
|
||||
|
||||
webhook: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1,15 +1,19 @@
|
||||
import type { TriggerOutput } from '@/triggers/types'
|
||||
|
||||
/**
|
||||
* Shared trigger dropdown options for all Grain triggers
|
||||
* Trigger dropdown options for Grain triggers.
|
||||
* New options (Item Added / Item Updated / All Events) correctly scope by view_id only.
|
||||
* Legacy options are hidden from the picker but still resolve for existing workflows.
|
||||
*/
|
||||
export const grainTriggerOptions = [
|
||||
{ label: 'General Webhook (All Events)', id: 'grain_webhook' },
|
||||
{ label: 'Recording Created', id: 'grain_recording_created' },
|
||||
{ label: 'Recording Updated', id: 'grain_recording_updated' },
|
||||
{ label: 'Highlight Created', id: 'grain_highlight_created' },
|
||||
{ label: 'Highlight Updated', id: 'grain_highlight_updated' },
|
||||
{ label: 'Story Created', id: 'grain_story_created' },
|
||||
{ label: 'Item Added', id: 'grain_item_added' },
|
||||
{ label: 'Item Updated', id: 'grain_item_updated' },
|
||||
{ label: 'All Events', id: 'grain_webhook' },
|
||||
{ label: 'Recording Created', id: 'grain_recording_created', hidden: true },
|
||||
{ label: 'Recording Updated', id: 'grain_recording_updated', hidden: true },
|
||||
{ label: 'Highlight Created', id: 'grain_highlight_created', hidden: true },
|
||||
{ label: 'Highlight Updated', id: 'grain_highlight_updated', hidden: true },
|
||||
{ label: 'Story Created', id: 'grain_story_created', hidden: true },
|
||||
]
|
||||
|
||||
/**
|
||||
@@ -32,6 +36,25 @@ export function grainSetupInstructions(eventType: string): string {
|
||||
.join('')
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup instructions for the v2 triggers that correctly explain view-based scoping.
|
||||
*/
|
||||
export function grainV2SetupInstructions(action: string): string {
|
||||
const instructions = [
|
||||
'Enter your Grain API Key (Personal Access Token). You can find or create one in Grain at <strong>Workspace Settings > API</strong> under Integrations on <a href="https://grain.com/app/settings/integrations?tab=api" target="_blank" rel="noopener noreferrer">grain.com</a>.',
|
||||
`Enter a Grain <strong>view ID</strong>. Each view has a type — <em>recordings</em>, <em>highlights</em>, or <em>stories</em> — and only items matching that type will fire the <strong>${action}</strong> event.`,
|
||||
'To find your view IDs, use the <strong>List Views</strong> operation on this block or call <code>GET /_/public-api/views</code> directly.',
|
||||
'The webhook is created automatically when you save and will be deleted when you remove this trigger.',
|
||||
]
|
||||
|
||||
return instructions
|
||||
.map(
|
||||
(instruction, index) =>
|
||||
`<div class="mb-3"><strong>${index + 1}.</strong> ${instruction}</div>`
|
||||
)
|
||||
.join('')
|
||||
}
|
||||
|
||||
/**
|
||||
* Build output schema for recording events
|
||||
* Webhook payload structure: { type, user_id, data: { ...recording } }
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { GrainIcon } from '@/components/icons'
|
||||
import type { TriggerConfig } from '@/triggers/types'
|
||||
import { buildGenericOutputs, grainSetupInstructions } from './utils'
|
||||
import { buildGenericOutputs, grainV2SetupInstructions } from './utils'
|
||||
|
||||
export const grainWebhookTrigger: TriggerConfig = {
|
||||
id: 'grain_webhook',
|
||||
name: 'Grain Webhook',
|
||||
name: 'Grain All Events',
|
||||
provider: 'grain',
|
||||
description: 'Generic webhook trigger for all actions in a selected Grain view',
|
||||
description: 'Trigger on all actions (added, updated, removed) in a Grain view',
|
||||
version: '1.0.0',
|
||||
icon: GrainIcon,
|
||||
|
||||
@@ -30,7 +30,8 @@ export const grainWebhookTrigger: TriggerConfig = {
|
||||
title: 'View ID',
|
||||
type: 'short-input',
|
||||
placeholder: 'Enter Grain view UUID',
|
||||
description: 'Required by Grain to create the webhook subscription.',
|
||||
description:
|
||||
'The view determines which content type fires events (recordings, highlights, or stories).',
|
||||
required: true,
|
||||
mode: 'trigger',
|
||||
condition: {
|
||||
@@ -55,7 +56,7 @@ export const grainWebhookTrigger: TriggerConfig = {
|
||||
title: 'Setup Instructions',
|
||||
hideFromPreview: true,
|
||||
type: 'text',
|
||||
defaultValue: grainSetupInstructions('All events'),
|
||||
defaultValue: grainV2SetupInstructions('all'),
|
||||
mode: 'trigger',
|
||||
condition: {
|
||||
field: 'selectedTriggerId',
|
||||
|
||||
@@ -89,6 +89,8 @@ import { googleFormsWebhookTrigger } from '@/triggers/googleforms'
|
||||
import {
|
||||
grainHighlightCreatedTrigger,
|
||||
grainHighlightUpdatedTrigger,
|
||||
grainItemAddedTrigger,
|
||||
grainItemUpdatedTrigger,
|
||||
grainRecordingCreatedTrigger,
|
||||
grainRecordingUpdatedTrigger,
|
||||
grainStoryCreatedTrigger,
|
||||
@@ -245,6 +247,8 @@ export const TRIGGER_REGISTRY: TriggerRegistry = {
|
||||
fathom_webhook: fathomWebhookTrigger,
|
||||
gmail_poller: gmailPollingTrigger,
|
||||
grain_webhook: grainWebhookTrigger,
|
||||
grain_item_added: grainItemAddedTrigger,
|
||||
grain_item_updated: grainItemUpdatedTrigger,
|
||||
grain_recording_created: grainRecordingCreatedTrigger,
|
||||
grain_recording_updated: grainRecordingUpdatedTrigger,
|
||||
grain_highlight_created: grainHighlightCreatedTrigger,
|
||||
|
||||
Reference in New Issue
Block a user