Files
WeHub Mirror 6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (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 / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
WeHub snapshot of cb28d14c6f2c081de7a0d8729a8c816c9adef67a
2026-08-10 11:17:50 +08:00

163 lines
5.5 KiB
TypeScript

import { createLogger } from '@sim/logger'
import { resolveStartCandidates, StartBlockPath } from '@/lib/workflows/triggers/triggers'
import { normalizeName, startsWithUuid } from '@/executor/constants'
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
const logger = createLogger('DeploymentUtils')
interface InputField {
name: string
type: string
}
/**
* Gets the input format from the Start block
* Returns an array of field definitions with name and type
*/
export function getStartBlockInputFormat(): InputField[] {
try {
const candidates = resolveStartCandidates(useWorkflowStore.getState().blocks, {
execution: 'api',
})
const targetCandidate =
candidates.find((candidate) => candidate.path === StartBlockPath.UNIFIED) ||
candidates.find((candidate) => candidate.path === StartBlockPath.SPLIT_API) ||
candidates.find((candidate) => candidate.path === StartBlockPath.SPLIT_INPUT) ||
candidates.find((candidate) => candidate.path === StartBlockPath.LEGACY_STARTER)
const targetBlock = targetCandidate?.block
if (targetBlock) {
const inputFormat = useSubBlockStore.getState().getValue(targetBlock.id, 'inputFormat')
if (inputFormat && Array.isArray(inputFormat)) {
return inputFormat
.map((field: { name?: string; type?: string }) => ({
name: field.name || '',
type: field.type || 'string',
}))
.filter((field) => field.name)
}
}
} catch (error) {
logger.warn('Error getting start block input format:', error)
}
return []
}
/**
* Gets the input format example for a workflow's API deployment
* Returns the -d flag with example data if inputs exist, empty string otherwise
*
* @param includeStreaming - Whether to include streaming parameters in the example
* @param selectedStreamingOutputs - Array of output IDs to stream
* @returns A string containing the curl -d flag with example data, or empty string if no inputs
*/
export function getInputFormatExample(
includeStreaming = false,
selectedStreamingOutputs: string[] = []
): string {
let inputFormatExample = ''
try {
const blocks = Object.values(useWorkflowStore.getState().blocks)
const candidates = resolveStartCandidates(useWorkflowStore.getState().blocks, {
execution: 'api',
})
const targetCandidate =
candidates.find((candidate) => candidate.path === StartBlockPath.UNIFIED) ||
candidates.find((candidate) => candidate.path === StartBlockPath.SPLIT_API) ||
candidates.find((candidate) => candidate.path === StartBlockPath.SPLIT_INPUT) ||
candidates.find((candidate) => candidate.path === StartBlockPath.LEGACY_STARTER)
const targetBlock = targetCandidate?.block
if (targetBlock) {
const inputFormat = useSubBlockStore.getState().getValue(targetBlock.id, 'inputFormat')
const exampleData: Record<string, any> = {}
if (inputFormat && Array.isArray(inputFormat) && inputFormat.length > 0) {
inputFormat.forEach((field: any) => {
if (field.name) {
switch (field.type) {
case 'string':
exampleData[field.name] = 'example'
break
case 'number':
exampleData[field.name] = 42
break
case 'boolean':
exampleData[field.name] = true
break
case 'object':
exampleData[field.name] = { key: 'value' }
break
case 'array':
exampleData[field.name] = [1, 2, 3]
break
case 'file[]':
exampleData[field.name] = [
{
data: 'data:application/pdf;base64,...',
type: 'file',
name: 'document.pdf',
mime: 'application/pdf',
},
]
break
}
}
})
}
if (includeStreaming && selectedStreamingOutputs.length > 0) {
exampleData.stream = true
const convertedOutputs = selectedStreamingOutputs
.map((outputId) => {
if (startsWithUuid(outputId)) {
const underscoreIndex = outputId.indexOf('_')
if (underscoreIndex === -1) return null
const blockId = outputId.substring(0, underscoreIndex)
const attribute = outputId.substring(underscoreIndex + 1)
const block = blocks.find((b) => b.id === blockId)
if (block?.name) {
return `${normalizeName(block.name)}.${attribute}`
}
return null
}
const parts = outputId.split('.')
if (parts.length >= 2) {
const blockName = parts[0]
const block = blocks.find(
(b) => b.name && normalizeName(b.name) === normalizeName(blockName)
)
if (!block) {
return null
}
}
return outputId
})
.filter((output): output is string => output !== null)
exampleData.selectedOutputs = convertedOutputs
}
if (Object.keys(exampleData).length > 0) {
inputFormatExample = ` -d '${JSON.stringify(exampleData)}'`
}
}
} catch (error) {
logger.warn('Error generating input format example:', error)
}
return inputFormatExample
}