Files
simstudioai--sim/apps/sim/lib/logs/get-trigger-options.ts
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

114 lines
3.3 KiB
TypeScript

import { getLatestBlock } from '@/blocks/registry'
import { getAllTriggers } from '@/triggers'
export interface TriggerOption {
value: string
label: string
color: string
}
let cachedTriggerOptions: TriggerOption[] | null = null
let cachedTriggerMetadataMap: Map<string, { label: string; color: string }> | null = null
/**
* Reset cache - useful for HMR in development or testing
*/
export function resetTriggerOptionsCache() {
cachedTriggerOptions = null
cachedTriggerMetadataMap = null
}
/**
* Dynamically generates trigger filter options from the trigger registry and block definitions.
* Results are cached after first call for performance (~98% faster on subsequent calls).
*/
export function getTriggerOptions(): TriggerOption[] {
if (cachedTriggerOptions) {
return cachedTriggerOptions
}
const triggers = getAllTriggers()
const providerMap = new Map<string, TriggerOption>()
const coreTypes: TriggerOption[] = [
{ value: 'manual', label: 'Manual', color: '#6b7280' },
{ value: 'api', label: 'API', color: '#2563eb' },
{ value: 'schedule', label: 'Schedule', color: '#059669' },
{ value: 'chat', label: 'Chat', color: '#7c3aed' },
{ value: 'webhook', label: 'Webhook', color: '#ea580c' },
{ value: 'mcp', label: 'MCP', color: '#dc2626' },
{ value: 'copilot', label: 'Sim agent', color: '#ec4899' },
{ value: 'mothership', label: 'Sim agent', color: '#ec4899' },
{ value: 'workflow', label: 'Workflow', color: '#0369a1' },
]
for (const trigger of triggers) {
const provider = trigger.provider
// Skip generic webhook and already processed providers
if (!provider || providerMap.has(provider) || provider === 'generic') {
continue
}
const block = getLatestBlock(provider)
providerMap.set(provider, {
value: provider,
label: block?.name || formatProviderName(provider),
color: block?.bgColor || '#6b7280',
})
}
const integrationOptions = Array.from(providerMap.values()).sort((a, b) =>
a.label.localeCompare(b.label)
)
cachedTriggerOptions = [...coreTypes, ...integrationOptions]
return cachedTriggerOptions
}
/**
* Formats a provider name into a display-friendly label
* e.g., "microsoft_teams" -> "Microsoft Teams"
*/
function formatProviderName(provider: string): string {
return provider
.split(/[-_]/)
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ')
}
/**
* Internal: Initialize metadata map for O(1) lookups
* Converts array of options to Map for fast access
*/
function initializeTriggerMetadataMap(): Map<string, { label: string; color: string }> {
if (cachedTriggerMetadataMap) {
return cachedTriggerMetadataMap
}
const options = getTriggerOptions()
cachedTriggerMetadataMap = new Map(
options.map((opt) => [opt.value, { label: opt.label, color: opt.color }])
)
return cachedTriggerMetadataMap
}
/**
* Gets integration metadata (label and color) for a specific trigger type.
*/
export function getIntegrationMetadata(triggerType: string): { label: string; color: string } {
const metadataMap = initializeTriggerMetadataMap()
const found = metadataMap.get(triggerType)
if (found) {
return found
}
return {
label: formatProviderName(triggerType),
color: '#6b7280', // gray
}
}