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
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import { BlockType, isTriggerBehavior, isTriggerInternalKey } from '@/executor/constants'
|
|
import type { BlockHandler, ExecutionContext } from '@/executor/types'
|
|
import type { SerializedBlock } from '@/serializer/types'
|
|
|
|
const logger = createLogger('TriggerBlockHandler')
|
|
|
|
export class TriggerBlockHandler implements BlockHandler {
|
|
canHandle(block: SerializedBlock): boolean {
|
|
return isTriggerBehavior(block)
|
|
}
|
|
|
|
async execute(
|
|
ctx: ExecutionContext,
|
|
block: SerializedBlock,
|
|
inputs: Record<string, any>
|
|
): Promise<any> {
|
|
logger.info(`Executing trigger block: ${block.id} (Type: ${block.metadata?.id})`)
|
|
|
|
if (block.metadata?.id === BlockType.STARTER) {
|
|
return this.executeStarterBlock(ctx, block, inputs)
|
|
}
|
|
|
|
const existingState = ctx.blockStates.get(block.id)
|
|
if (existingState?.output) {
|
|
return existingState.output
|
|
}
|
|
|
|
const starterBlock = ctx.workflow?.blocks?.find((b) => b.metadata?.id === 'starter')
|
|
if (starterBlock) {
|
|
const starterState = ctx.blockStates.get(starterBlock.id)
|
|
if (starterState?.output && Object.keys(starterState.output).length > 0) {
|
|
const starterOutput = starterState.output
|
|
|
|
if (starterOutput.webhook?.data) {
|
|
const cleanOutput: Record<string, unknown> = {}
|
|
for (const [key, value] of Object.entries(starterOutput)) {
|
|
if (!isTriggerInternalKey(key)) {
|
|
cleanOutput[key] = value
|
|
}
|
|
}
|
|
return cleanOutput
|
|
}
|
|
|
|
return starterOutput
|
|
}
|
|
}
|
|
|
|
if (inputs && Object.keys(inputs).length > 0) {
|
|
return inputs
|
|
}
|
|
|
|
return {}
|
|
}
|
|
|
|
private executeStarterBlock(
|
|
ctx: ExecutionContext,
|
|
block: SerializedBlock,
|
|
inputs: Record<string, any>
|
|
): any {
|
|
logger.info(`Executing starter block: ${block.id}`, {
|
|
blockName: block.metadata?.name,
|
|
})
|
|
|
|
const existingState = ctx.blockStates.get(block.id)
|
|
if (existingState?.output && Object.keys(existingState.output).length > 0) {
|
|
return existingState.output
|
|
}
|
|
|
|
logger.warn('Starter block output not found in context, returning empty output', {
|
|
blockId: block.id,
|
|
})
|
|
|
|
return {
|
|
input: inputs.input || '',
|
|
}
|
|
}
|
|
}
|