Files
t3code/packages/contracts/src/assets.ts
T
Julius Marminge 85d5df6256 Unify browser asset preview routing
- Replace attachment and favicon routes with signed asset URLs
- Harden workspace and attachment asset resolution
- Update browser preview components and shared contracts
2026-06-13 22:18:37 -07:00

39 lines
1.2 KiB
TypeScript

import * as Schema from "effect/Schema";
import { ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
const ASSET_PATH_MAX_LENGTH = 1024;
export const AssetResource = Schema.Union([
Schema.TaggedStruct("workspace-file", {
threadId: ThreadId,
path: TrimmedNonEmptyString.check(Schema.isMaxLength(ASSET_PATH_MAX_LENGTH)),
}),
Schema.TaggedStruct("attachment", {
attachmentId: TrimmedNonEmptyString.check(Schema.isMaxLength(256)),
}),
Schema.TaggedStruct("project-favicon", {
cwd: TrimmedNonEmptyString.check(Schema.isMaxLength(ASSET_PATH_MAX_LENGTH)),
}),
]);
export type AssetResource = typeof AssetResource.Type;
export const AssetCreateUrlInput = Schema.Struct({
resource: AssetResource,
});
export type AssetCreateUrlInput = typeof AssetCreateUrlInput.Type;
export const AssetCreateUrlResult = Schema.Struct({
relativeUrl: TrimmedNonEmptyString.check(Schema.isMaxLength(4096)),
expiresAt: Schema.Number,
});
export type AssetCreateUrlResult = typeof AssetCreateUrlResult.Type;
export class AssetAccessError extends Schema.TaggedErrorClass<AssetAccessError>()(
"AssetAccessError",
{
message: TrimmedNonEmptyString,
cause: Schema.optional(Schema.Defect()),
},
) {}