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

361 lines
10 KiB
TypeScript

import { z } from 'zod'
import { defineRouteContract } from '@/lib/api/contracts/types'
import { workflowIdParamsSchema } from '@/lib/api/contracts/workflows'
import {
DEPLOYMENT_COMPONENT_STATUSES,
DEPLOYMENT_OPERATION_ACTIONS,
DEPLOYMENT_OPERATION_STATUSES,
} from '@/lib/workflows/deployment-lifecycle'
import type { WorkflowState } from '@/stores/workflows/workflow/types'
const deployedWorkflowStateSchema = z.custom<WorkflowState>(
(value) => typeof value === 'object' && value !== null,
'Expected workflow state'
)
export const deploymentVersionParamsSchema = z.object({
id: z.string().min(1, 'Invalid workflow ID'),
version: z.coerce.number().int().positive(),
})
export const deploymentVersionOrActiveParamsSchema = z.object({
id: z.string().min(1, 'Invalid workflow ID'),
version: z.union([z.number().int().positive(), z.literal('active')]),
})
export const deploymentVersionRouteParamsSchema = z.object({
id: z.string().min(1, 'Invalid workflow ID'),
version: z.string().min(1, 'Invalid version'),
})
export const updatePublicApiBodySchema = z.object({
isPublicApi: z.boolean(),
})
export type UpdatePublicApiBody = z.input<typeof updatePublicApiBodySchema>
export const deploymentVersionMetadataFieldsSchema = z.object({
name: z
.string()
.trim()
.min(1, 'Name cannot be empty')
.max(100, 'Name must be 100 characters or less')
.optional(),
description: z.string().trim().max(50_000, 'Description is too long').nullable().optional(),
})
export const updateDeploymentVersionMetadataBodySchema =
deploymentVersionMetadataFieldsSchema.refine(
(data) => data.name !== undefined || data.description !== undefined,
{
message: 'At least one of name or description must be provided',
}
)
export type UpdateDeploymentVersionMetadataBody = z.input<
typeof updateDeploymentVersionMetadataBodySchema
>
export const activateDeploymentVersionBodySchema = z.object({
isActive: z.literal(true),
})
export type ActivateDeploymentVersionBody = z.input<typeof activateDeploymentVersionBodySchema>
export const deploymentOperationStatusSchema = z.enum(DEPLOYMENT_OPERATION_STATUSES)
export const deploymentComponentReadinessSchema = z.enum([
...DEPLOYMENT_COMPONENT_STATUSES,
'not_applicable',
])
export const deploymentReadinessSchema = z.object({
webhooks: deploymentComponentReadinessSchema,
schedules: deploymentComponentReadinessSchema,
mcp: deploymentComponentReadinessSchema,
})
export const deploymentOperationSummarySchema = z.object({
id: z.string(),
deploymentVersionId: z.string(),
version: z.number().int().positive(),
action: z.enum(DEPLOYMENT_OPERATION_ACTIONS),
status: deploymentOperationStatusSchema,
isCurrent: z.boolean().optional().default(true),
readiness: deploymentReadinessSchema,
requestedAt: z.string(),
activatedAt: z.string().nullable().optional(),
error: z
.object({
code: z.string(),
message: z.string(),
retryable: z.boolean(),
})
.nullable()
.optional(),
})
export type DeploymentOperationSummary = z.output<typeof deploymentOperationSummarySchema>
export const activeDeploymentSummarySchema = z.object({
deploymentVersionId: z.string(),
version: z.number().int().positive(),
deployedAt: z.string(),
})
export const deploymentVersionPatchBodySchema = deploymentVersionMetadataFieldsSchema
.extend({
isActive: z.literal(true).optional(),
})
.refine(
(data) => data.name !== undefined || data.description !== undefined || data.isActive === true,
{
message: 'At least one of name, description, or isActive must be provided',
}
)
export const deploymentInfoResponseSchema = z.object({
isDeployed: z.boolean(),
deployedAt: z.string().nullable().optional(),
apiKey: z.string().nullable().optional(),
needsRedeployment: z.boolean().optional(),
isPublicApi: z.boolean().optional(),
warnings: z.array(z.string()).optional(),
activeDeployment: activeDeploymentSummarySchema.nullable().optional(),
latestDeploymentAttempt: deploymentOperationSummarySchema.nullable().optional(),
})
export type DeploymentInfoResponse = z.output<typeof deploymentInfoResponseSchema>
export type DeployWorkflowResponse = DeploymentInfoResponse
export type UndeployWorkflowResponse = DeploymentInfoResponse
export const deploymentVersionSchema = z.object({
id: z.string(),
version: z.number(),
name: z.string().nullable().optional(),
description: z.string().nullable().optional(),
isActive: z.boolean(),
createdAt: z.string(),
createdBy: z.string().nullable().optional(),
deployedBy: z.string().nullable().optional(),
latestOperationStatus: deploymentOperationStatusSchema.nullable().optional(),
})
export type DeploymentVersion = z.output<typeof deploymentVersionSchema>
export const deploymentVersionsResponseSchema = z.object({
versions: z.array(deploymentVersionSchema),
})
export type DeploymentVersionsResponse = z.output<typeof deploymentVersionsResponseSchema>
export const chatDeploymentStatusSchema = z.object({
isDeployed: z.boolean(),
deployment: z
.object({
id: z.string(),
identifier: z.string(),
})
.passthrough()
.nullable(),
})
export type ChatDeploymentStatus = z.output<typeof chatDeploymentStatusSchema>
export const chatDetailSchema = z.object({
id: z.string(),
identifier: z.string(),
title: z.string(),
description: z.preprocess((value) => value ?? '', z.string()),
authType: z.enum(['public', 'password', 'email', 'sso']),
allowedEmails: z.preprocess((value) => value ?? [], z.array(z.string())),
outputConfigs: z.preprocess(
(value) => value ?? [],
z.array(
z.object({
blockId: z.string(),
path: z.string(),
})
)
),
includeThinking: z.preprocess((value) => value ?? false, z.boolean()),
includeToolCalls: z.preprocess((value) => value ?? false, z.boolean()),
customizations: z.preprocess(
(value) => value ?? undefined,
z
.object({
welcomeMessage: z.string().optional(),
imageUrl: z.string().optional(),
primaryColor: z.string().optional(),
})
.optional()
),
isActive: z.boolean(),
chatUrl: z.string(),
hasPassword: z.boolean(),
})
export type ChatDetail = z.output<typeof chatDetailSchema>
export const updatePublicApiResponseSchema = z.object({
isPublicApi: z.boolean(),
})
export type UpdatePublicApiResponse = z.output<typeof updatePublicApiResponseSchema>
export const deployedWorkflowStateResponseSchema = z.object({
deployedState: deployedWorkflowStateSchema.nullable(),
})
export type DeployedWorkflowStateResponse = z.output<typeof deployedWorkflowStateResponseSchema>
export const updateDeploymentVersionMetadataResponseSchema = z.object({
name: z.string().nullable(),
description: z.string().nullable(),
})
export type UpdateDeploymentVersionMetadataResponse = z.output<
typeof updateDeploymentVersionMetadataResponseSchema
>
export const activateDeploymentVersionResponseSchema = z.object({
success: z.literal(true),
deployedAt: z.string().nullable().optional(),
warnings: z.array(z.string()).optional(),
name: z.string().nullable().optional(),
description: z.string().nullable().optional(),
activeDeployment: activeDeploymentSummarySchema.nullable().optional(),
latestDeploymentAttempt: deploymentOperationSummarySchema.nullable().optional(),
})
export type ActivateDeploymentVersionResponse = z.output<
typeof activateDeploymentVersionResponseSchema
>
export const getDeploymentInfoContract = defineRouteContract({
method: 'GET',
path: '/api/workflows/[id]/deploy',
params: workflowIdParamsSchema,
response: {
mode: 'json',
schema: deploymentInfoResponseSchema,
},
})
export const deployWorkflowContract = defineRouteContract({
method: 'POST',
path: '/api/workflows/[id]/deploy',
params: workflowIdParamsSchema,
response: {
mode: 'json',
schema: deploymentInfoResponseSchema,
},
})
export const undeployWorkflowContract = defineRouteContract({
method: 'DELETE',
path: '/api/workflows/[id]/deploy',
params: workflowIdParamsSchema,
response: {
mode: 'json',
schema: deploymentInfoResponseSchema,
},
})
export const updatePublicApiContract = defineRouteContract({
method: 'PATCH',
path: '/api/workflows/[id]/deploy',
params: workflowIdParamsSchema,
body: updatePublicApiBodySchema,
response: {
mode: 'json',
schema: updatePublicApiResponseSchema,
},
})
export const getDeployedWorkflowStateContract = defineRouteContract({
method: 'GET',
path: '/api/workflows/[id]/deployed',
params: workflowIdParamsSchema,
response: {
mode: 'json',
schema: deployedWorkflowStateResponseSchema,
},
})
export const listDeploymentVersionsContract = defineRouteContract({
method: 'GET',
path: '/api/workflows/[id]/deployments',
params: workflowIdParamsSchema,
response: {
mode: 'json',
schema: deploymentVersionsResponseSchema,
},
})
export const getDeploymentVersionStateContract = defineRouteContract({
method: 'GET',
path: '/api/workflows/[id]/deployments/[version]',
params: deploymentVersionParamsSchema,
response: {
mode: 'json',
schema: z.object({
deployedState: deployedWorkflowStateSchema,
}),
},
})
export const updateDeploymentVersionMetadataContract = defineRouteContract({
method: 'PATCH',
path: '/api/workflows/[id]/deployments/[version]',
params: deploymentVersionParamsSchema,
body: deploymentVersionPatchBodySchema,
response: {
mode: 'json',
schema: updateDeploymentVersionMetadataResponseSchema,
},
})
export const activateDeploymentVersionContract = defineRouteContract({
method: 'PATCH',
path: '/api/workflows/[id]/deployments/[version]',
params: deploymentVersionParamsSchema,
body: activateDeploymentVersionBodySchema,
response: {
mode: 'json',
schema: activateDeploymentVersionResponseSchema,
},
})
export const revertToDeploymentVersionContract = defineRouteContract({
method: 'POST',
path: '/api/workflows/[id]/deployments/[version]/revert',
params: deploymentVersionOrActiveParamsSchema,
response: {
mode: 'json',
schema: z.object({
message: z.string(),
lastSaved: z.number(),
}),
},
})
export const getChatDeploymentStatusContract = defineRouteContract({
method: 'GET',
path: '/api/workflows/[id]/chat/status',
params: workflowIdParamsSchema,
response: {
mode: 'json',
schema: chatDeploymentStatusSchema,
},
})
export const getChatDetailContract = defineRouteContract({
method: 'GET',
path: '/api/chat/manage/[id]',
params: workflowIdParamsSchema,
response: {
mode: 'json',
schema: chatDetailSchema,
},
})