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
183 lines
6.1 KiB
TypeScript
183 lines
6.1 KiB
TypeScript
function makeCanonicalPlaceholdersJsonParseable(value: string): string {
|
|
let result = ''
|
|
let inString = false
|
|
let escaped = false
|
|
|
|
for (let index = 0; index < value.length; index++) {
|
|
const character = value[index]
|
|
if (inString) {
|
|
result += character
|
|
if (escaped) {
|
|
escaped = false
|
|
} else if (character === '\\') {
|
|
escaped = true
|
|
} else if (character === '"') {
|
|
inString = false
|
|
}
|
|
continue
|
|
}
|
|
|
|
if (character === '"') {
|
|
inString = true
|
|
result += character
|
|
continue
|
|
}
|
|
|
|
if (character === '{' && value[index + 1] === '{') {
|
|
const end = value.indexOf('}}', index + 2)
|
|
if (end !== -1) {
|
|
const placeholder = value.slice(index, end + 2)
|
|
const name = value.slice(index + 2, end).trim()
|
|
if (/^[A-Za-z0-9_]+$/.test(name)) {
|
|
result += JSON.stringify(placeholder)
|
|
index = end + 1
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
|
|
result += character
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
function canonicalPlaceholder(value: string): string | undefined {
|
|
const match = /^\{\{([^{}]+)\}\}$/.exec(value.trim())
|
|
if (!match || !/^[A-Za-z0-9_]+$/.test(match[1].trim())) return undefined
|
|
return value.trim()
|
|
}
|
|
|
|
function projectStructuredLeaves(value: unknown, placeholder: string): unknown {
|
|
if (value === null || typeof value !== 'object') return placeholder
|
|
|
|
const projectedRoot: unknown[] | Record<string, unknown> = Array.isArray(value) ? [] : {}
|
|
const pending: Array<{
|
|
source: unknown[] | Record<string, unknown>
|
|
target: unknown[] | Record<string, unknown>
|
|
}> = [{ source: value as unknown[] | Record<string, unknown>, target: projectedRoot }]
|
|
|
|
while (pending.length > 0) {
|
|
const { source, target } = pending.pop()!
|
|
for (const [key, child] of Object.entries(source)) {
|
|
if (child !== null && typeof child === 'object') {
|
|
const projectedChild: unknown[] | Record<string, unknown> = Array.isArray(child) ? [] : {}
|
|
;(target as Record<string, unknown>)[key] = projectedChild
|
|
pending.push({
|
|
source: child as unknown[] | Record<string, unknown>,
|
|
target: projectedChild,
|
|
})
|
|
} else {
|
|
;(target as Record<string, unknown>)[key] = placeholder
|
|
}
|
|
}
|
|
}
|
|
|
|
return projectedRoot
|
|
}
|
|
|
|
function projectFileReferenceString(
|
|
key: string,
|
|
value: string,
|
|
placeholder: string
|
|
): string | undefined {
|
|
if (key !== 'key' && key !== 'path' && key !== 'url' && key !== 'base64') return undefined
|
|
if ((key === 'url' || key === 'path') && value.startsWith('https://')) {
|
|
return `https://${placeholder}`
|
|
}
|
|
if ((key === 'url' || key === 'path') && value.startsWith('http://')) {
|
|
return `http://${placeholder}`
|
|
}
|
|
if (key === 'path' && value.startsWith('/')) return `/${placeholder}`
|
|
return placeholder
|
|
}
|
|
|
|
function isFileDescriptor(value: unknown): boolean {
|
|
if (Array.isArray(value)) return value.length > 0 && value.every(isFileDescriptor)
|
|
return (
|
|
value !== null &&
|
|
typeof value === 'object' &&
|
|
['key', 'path', 'url'].some(
|
|
(key) => typeof (value as Record<string, unknown>)[key] === 'string'
|
|
)
|
|
)
|
|
}
|
|
|
|
function projectFileReferenceLeaves(
|
|
value: unknown,
|
|
placeholder: string
|
|
): { value: unknown; projectedReferences: number } | undefined {
|
|
if (!isFileDescriptor(value)) return undefined
|
|
|
|
const projectedRoot: unknown[] | Record<string, unknown> = Array.isArray(value) ? [] : {}
|
|
const pending: Array<{
|
|
source: unknown[] | Record<string, unknown>
|
|
target: unknown[] | Record<string, unknown>
|
|
}> = [{ source: value as unknown[] | Record<string, unknown>, target: projectedRoot }]
|
|
let projectedReferences = 0
|
|
while (pending.length > 0) {
|
|
const { source, target } = pending.pop()!
|
|
for (const [key, child] of Object.entries(source)) {
|
|
if (child !== null && typeof child === 'object') {
|
|
const projectedChild: unknown[] | Record<string, unknown> = Array.isArray(child) ? [] : {}
|
|
;(target as Record<string, unknown>)[key] = projectedChild
|
|
pending.push({
|
|
source: child as unknown[] | Record<string, unknown>,
|
|
target: projectedChild,
|
|
})
|
|
continue
|
|
}
|
|
|
|
const projectedReference =
|
|
typeof child === 'string' ? projectFileReferenceString(key, child, placeholder) : undefined
|
|
;(target as Record<string, unknown>)[key] = projectedReference ?? child
|
|
if (projectedReference !== undefined) projectedReferences += 1
|
|
}
|
|
}
|
|
return { value: projectedRoot, projectedReferences }
|
|
}
|
|
|
|
/**
|
|
* Makes only schema-declared structured inputs parseable on a private placeholder projection.
|
|
* Raw execution inputs are never passed to or changed by this helper.
|
|
*/
|
|
export function prepareResolvedSecretProjectedInputs(
|
|
inputs: Record<string, unknown>,
|
|
inputSchemas: Record<string, unknown> | undefined,
|
|
rawInputs?: Record<string, unknown>,
|
|
options: { preserveFileDescriptorGrammar?: boolean } = {}
|
|
): Record<string, unknown> {
|
|
if (!inputSchemas) return inputs
|
|
const prepared = { ...inputs }
|
|
for (const [key, inputSchema] of Object.entries(inputSchemas)) {
|
|
const inputType =
|
|
inputSchema && typeof inputSchema === 'object'
|
|
? (inputSchema as { type?: unknown }).type
|
|
: inputSchema
|
|
if (inputType !== 'json' && inputType !== 'array') continue
|
|
const value = prepared[key]
|
|
if (typeof value === 'string') {
|
|
const placeholder = canonicalPlaceholder(value)
|
|
const rawValue = rawInputs?.[key]
|
|
if (placeholder && typeof rawValue === 'string') {
|
|
try {
|
|
const parsedRawValue = JSON.parse(rawValue.trim())
|
|
if (parsedRawValue !== null && typeof parsedRawValue === 'object') {
|
|
const fileProjection = options.preserveFileDescriptorGrammar
|
|
? projectFileReferenceLeaves(parsedRawValue, placeholder)
|
|
: undefined
|
|
prepared[key] = JSON.stringify(
|
|
fileProjection && fileProjection.projectedReferences > 0
|
|
? fileProjection.value
|
|
: projectStructuredLeaves(parsedRawValue, placeholder)
|
|
)
|
|
continue
|
|
}
|
|
} catch {}
|
|
}
|
|
prepared[key] = makeCanonicalPlaceholdersJsonParseable(value)
|
|
}
|
|
}
|
|
return prepared
|
|
}
|