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
132 lines
3.5 KiB
TypeScript
132 lines
3.5 KiB
TypeScript
import type { UserFile } from '@/executor/types'
|
|
|
|
export type UserFileLike = Pick<UserFile, 'id' | 'name' | 'url' | 'key'> &
|
|
Partial<Pick<UserFile, 'size' | 'type' | 'context' | 'base64'>>
|
|
|
|
/**
|
|
* Fields exposed for UserFile objects in UI (tag dropdown) and logs.
|
|
* Internal fields like 'key' and 'context' are not exposed.
|
|
*/
|
|
export const USER_FILE_DISPLAY_FIELDS = ['id', 'name', 'url', 'size', 'type', 'base64'] as const
|
|
|
|
export type UserFileDisplayField = (typeof USER_FILE_DISPLAY_FIELDS)[number]
|
|
|
|
/**
|
|
* Checks if a value matches the minimal UserFile shape.
|
|
*/
|
|
export function isUserFile(value: unknown): value is UserFileLike {
|
|
if (!value || typeof value !== 'object') {
|
|
return false
|
|
}
|
|
|
|
const candidate = value as Record<string, unknown>
|
|
|
|
return (
|
|
typeof candidate.id === 'string' &&
|
|
typeof candidate.key === 'string' &&
|
|
typeof candidate.url === 'string' &&
|
|
typeof candidate.name === 'string'
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Checks if a value matches the full UserFile metadata shape.
|
|
*/
|
|
export function isUserFileWithMetadata(value: unknown): value is UserFile {
|
|
if (!isUserFile(value)) {
|
|
return false
|
|
}
|
|
|
|
const candidate = value as Record<string, unknown>
|
|
|
|
return typeof candidate.size === 'number' && typeof candidate.type === 'string'
|
|
}
|
|
|
|
/**
|
|
* Finds storage keys for UserFile objects embedded in a value.
|
|
*/
|
|
export function collectUserFileKeys(value: unknown): string[] {
|
|
const keys = new Set<string>()
|
|
collectUserFileKeysInto(value, keys, new WeakSet<object>())
|
|
return Array.from(keys)
|
|
}
|
|
|
|
function collectUserFileKeysInto(value: unknown, keys: Set<string>, seen: WeakSet<object>): void {
|
|
if (!value || typeof value !== 'object') {
|
|
return
|
|
}
|
|
|
|
if (seen.has(value)) {
|
|
return
|
|
}
|
|
seen.add(value)
|
|
|
|
if (isUserFileWithMetadata(value)) {
|
|
keys.add(value.key)
|
|
return
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
|
for (const item of value) {
|
|
collectUserFileKeysInto(item, keys, seen)
|
|
}
|
|
return
|
|
}
|
|
|
|
for (const item of Object.values(value)) {
|
|
collectUserFileKeysInto(item, keys, seen)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Checks if a value matches the display-safe UserFile metadata shape after internal fields are stripped.
|
|
*/
|
|
export function isUserFileDisplayMetadata(value: unknown): value is Record<string, unknown> {
|
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
return false
|
|
}
|
|
|
|
const candidate = value as Record<string, unknown>
|
|
const url = typeof candidate.url === 'string' ? candidate.url : ''
|
|
|
|
return (
|
|
typeof candidate.id === 'string' &&
|
|
typeof candidate.name === 'string' &&
|
|
url.length > 0 &&
|
|
typeof candidate.size === 'number' &&
|
|
typeof candidate.type === 'string' &&
|
|
(candidate.id.startsWith('file_') || url.includes('/api/files/serve/'))
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Filters a UserFile object to only include display fields.
|
|
* Used for both UI display and log sanitization.
|
|
*/
|
|
export function filterUserFileForDisplay(data: Record<string, unknown>): Record<string, unknown> {
|
|
const filtered: Record<string, unknown> = {}
|
|
for (const field of USER_FILE_DISPLAY_FIELDS) {
|
|
if (field in data) {
|
|
filtered[field] = data[field]
|
|
}
|
|
}
|
|
return filtered
|
|
}
|
|
|
|
/**
|
|
* Extracts base64 content from either a raw base64 string or a UserFile object.
|
|
* Useful for tools that accept file input in either format.
|
|
* @returns The base64 string, or undefined if not found
|
|
*/
|
|
export function extractBase64FromFileInput(
|
|
input: string | UserFileLike | null | undefined
|
|
): string | undefined {
|
|
if (typeof input === 'string') {
|
|
return input
|
|
}
|
|
if (input?.base64) {
|
|
return input.base64
|
|
}
|
|
return undefined
|
|
}
|