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

135 lines
5.3 KiB
TypeScript

export const PRIVATE_TOOL_METADATA_REQUEST_HEADER = 'x-sim-request-private-tool-metadata'
export const PRIVATE_TOOL_METADATA_RESPONSE_HEADER = 'x-sim-private-tool-metadata'
export const MAX_PRIVATE_TOOL_METADATA_OVERHEAD_BYTES = 10 * 1024 * 1024
export const RESOLVED_SECRET_NAMES_METADATA_V1 = 'resolved-secret-names-v1'
export const RESOLVED_SECRET_NAMES_DURABLE_FILES_METADATA_V2 =
'resolved-secret-names-durable-files-v2'
export const RESOLVED_SECRET_PROVENANCE_METADATA_V1 = 'resolved-secret-provenance-v1'
export const RESOLVED_SECRET_NAMES_FIELD = '__resolvedSecretNames'
export const RESOLVED_SECRET_PROVENANCE_FIELD = '__resolvedSecretTraceProvenance'
export const PRIVATE_SECRET_PROVENANCE_HEADER = 'x-sim-private-secret-provenance'
export const PRIVATE_SECRET_PROVENANCE_FIELD = '__privateSecretProvenance'
export const PRIVATE_SECRET_PROVENANCE_BUNDLE_V1 = 'private-secret-provenance-bundle-v1'
export const MOUNTED_WORKSPACE_FILES_PROVENANCE_KEY = 'mounted-workspace-files'
export type PrivateToolMetadataType =
| typeof RESOLVED_SECRET_NAMES_METADATA_V1
| typeof RESOLVED_SECRET_NAMES_DURABLE_FILES_METADATA_V2
| typeof RESOLVED_SECRET_PROVENANCE_METADATA_V1
export type PrivateToolMetadataResponseCapability =
| { status: 'supported' }
| { status: 'unsupported' }
| { status: 'mismatched'; receivedType: string }
export type PrivateToolMetadataEnvelopeInspection =
| { status: 'verified'; value: unknown }
| { status: 'unsupported' }
| { status: 'invalid' }
type PrivateToolMetadataResponseNegotiation =
| { status: 'not-requested' }
| { status: 'accepted' }
| { status: 'rejected' }
interface PrivateToolMetadataResponseEnvelope {
body: Record<string, unknown>
headers: Record<typeof PRIVATE_TOOL_METADATA_RESPONSE_HEADER, PrivateToolMetadataType>
}
interface HeaderReader {
get(name: string): string | null
}
export function requestsPrivateToolMetadata(
headers: HeaderReader,
expectedType: PrivateToolMetadataType
): boolean {
return headers.get(PRIVATE_TOOL_METADATA_REQUEST_HEADER) === expectedType
}
/** Negotiates an authenticated private response without loading domain provenance. */
export function negotiatePrivateToolMetadataResponse(
headers: HeaderReader,
expectedType: PrivateToolMetadataType,
authenticated: boolean
): PrivateToolMetadataResponseNegotiation {
const requestedType = headers.get(PRIVATE_TOOL_METADATA_REQUEST_HEADER)
if (requestedType === null) return { status: 'not-requested' }
return requestedType === expectedType && authenticated
? { status: 'accepted' }
: { status: 'rejected' }
}
/**
* Distinguishes a legacy producer from a producer that declared an incompatible protocol.
* Callers can reject one unsupported response without corrupting otherwise valid run state.
*/
export function inspectPrivateToolMetadataResponseCapability(
headers: HeaderReader,
expectedType: PrivateToolMetadataType
): PrivateToolMetadataResponseCapability {
const receivedType = headers.get(PRIVATE_TOOL_METADATA_RESPONSE_HEADER)
if (receivedType === expectedType) return { status: 'supported' }
if (receivedType === null) return { status: 'unsupported' }
return { status: 'mismatched', receivedType }
}
function getPrivateToolMetadataField(
type: PrivateToolMetadataType
): typeof RESOLVED_SECRET_NAMES_FIELD | typeof RESOLVED_SECRET_PROVENANCE_FIELD {
return type === RESOLVED_SECRET_NAMES_METADATA_V1 ||
type === RESOLVED_SECRET_NAMES_DURABLE_FILES_METADATA_V2
? RESOLVED_SECRET_NAMES_FIELD
: RESOLVED_SECRET_PROVENANCE_FIELD
}
/** Serializes private metadata without changing the functional response fields. */
export function serializePrivateToolMetadataResponseEnvelope(
body: Record<string, unknown>,
type: PrivateToolMetadataType,
value: unknown
): PrivateToolMetadataResponseEnvelope {
return {
body: { ...body, [getPrivateToolMetadataField(type)]: value },
headers: { [PRIVATE_TOOL_METADATA_RESPONSE_HEADER]: type },
}
}
/**
* Validates the response capability marker and its private payload as one protocol envelope.
* An unmarked payload with no private fields is a legacy response; every partial or mismatched
* envelope is invalid and must never be exposed as functional content.
*/
export function inspectPrivateToolMetadataEnvelope(
headers: HeaderReader,
payload: unknown,
expectedType: PrivateToolMetadataType
): PrivateToolMetadataEnvelopeInspection {
const capability = inspectPrivateToolMetadataResponseCapability(headers, expectedType)
const record =
payload !== null && typeof payload === 'object' && !Array.isArray(payload)
? (payload as Record<string, unknown>)
: undefined
const hasNames = record ? Object.hasOwn(record, RESOLVED_SECRET_NAMES_FIELD) : false
const hasProvenance = record ? Object.hasOwn(record, RESOLVED_SECRET_PROVENANCE_FIELD) : false
if (capability.status === 'unsupported' && !hasNames && !hasProvenance) {
return { status: 'unsupported' }
}
if (capability.status !== 'supported' || !record) return { status: 'invalid' }
const expectedField = getPrivateToolMetadataField(expectedType)
const unexpectedField =
expectedField === RESOLVED_SECRET_NAMES_FIELD
? RESOLVED_SECRET_PROVENANCE_FIELD
: RESOLVED_SECRET_NAMES_FIELD
if (!Object.hasOwn(record, expectedField) || Object.hasOwn(record, unexpectedField)) {
return { status: 'invalid' }
}
return { status: 'verified', value: record[expectedField] }
}