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

89 lines
3.0 KiB
TypeScript

import { generateId } from '@sim/utils/id'
import { randomFloat } from '@sim/utils/random'
import { isUuid, sanitizeFileName } from '@/executor/constants'
import type { UserFile } from '@/executor/types'
/**
* Execution context for file operations
*/
export interface ExecutionContext {
workspaceId: string
workflowId: string
executionId: string
}
/**
* Generate the deterministic storage key for a large-value execution payload.
* Format: execution/workspace_id/workflow_id/execution_id/large-value-<id>.json
*
* Takes the payload id rather than a file name so no user-supplied name can
* reach a key without a uniquifier — that is what silently overwrote same-named
* files before {@link generateUniqueExecutionFileKey} existed. Determinism is
* load-bearing here: the cleanup job matches these keys by LIKE pattern and
* re-storing the same payload must be idempotent.
*/
export function generateLargeValuePayloadKey(context: ExecutionContext, id: string): string {
const { workspaceId, workflowId, executionId } = context
const safeFileName = sanitizeFileName(`large-value-${id}.json`)
return `execution/${workspaceId}/${workflowId}/${executionId}/${safeFileName}`
}
/**
* Generate a collision-free execution-scoped storage key.
* Format: execution/workspace_id/workflow_id/execution_id/unique_id/filename
*
* One execution routinely carries several files sharing a display name (two
* `image.png` screenshots in one Slack message, repeated tool outputs in a
* loop), which the deterministic key would overwrite. The unique id is its own
* path segment rather than a filename prefix so the last segment stays the
* original name — presigned URLs carry no content-disposition, so that segment
* is what a consumer sees.
*
* Large-value payloads, whose ids are already unique, keep using
* {@link generateLargeValuePayloadKey}.
*/
export function generateUniqueExecutionFileKey(
context: ExecutionContext,
fileName: string
): string {
const { workspaceId, workflowId, executionId } = context
const safeFileName = sanitizeFileName(fileName)
return `execution/${workspaceId}/${workflowId}/${executionId}/${generateId()}/${safeFileName}`
}
/**
* Generate unique file ID for execution files
*/
export function generateFileId(): string {
return `file_${Date.now()}_${randomFloat().toString(36).substring(2, 9)}`
}
/**
* Execution keys: execution/workspaceId/workflowId/executionId/[uniqueId/]filename
*/
function matchesExecutionFilePattern(key: string): boolean {
if (!key || key.startsWith('/api/') || key.startsWith('http')) {
return false
}
const parts = key.split('/')
if (parts[0] === 'execution' && parts.length >= 5) {
const [, workspaceId, workflowId, executionId] = parts
return isUuid(workspaceId) && isUuid(workflowId) && isUuid(executionId)
}
return false
}
/**
* Check if a file is from execution storage based on its key pattern
*/
export function isExecutionFile(file: UserFile): boolean {
if (!file.key) {
return false
}
return matchesExecutionFilePattern(file.key)
}