Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(artifact): package local site assets for hosting (#18728)

Inneia07c4291e572
diff --git a/locales/en-US/portal.json b/locales/en-US/portal.json
index 6efdb7f4849..462eda1030b 100644
--- a/locales/en-US/portal.json
+++ b/locales/en-US/portal.json
@@ -9,7 +9,9 @@
"artifacts.deploy.copy": "Copy URL",
"artifacts.deploy.copySuccess": "Deployment URL copied",
"artifacts.deploy.failed": "Deployment failed",
+ "artifacts.deploy.highestPlanCapacityLimitReached": "Current self-service deployment capacity has been reached. Manage published projects or reduce deployment usage.",
"artifacts.deploy.highestPlanLimitReached": "Public deployment limit reached ({{used}} / {{limit}}). Unpublish a project to free a slot.",
+ "artifacts.deploy.highestPlanSizeLimitReached": "This site is {{actual}}, above the {{limit}} self-service limit. Reduce its assets before publishing.",
"artifacts.deploy.history": "Revision history",
"artifacts.deploy.limitReached": "Public deployment limit reached ({{used}} / {{limit}}). Unpublish a project or upgrade your plan.",
"artifacts.deploy.open": "Open deployment",
@@ -17,6 +19,7 @@
"artifacts.deploy.publish": "Publish",
"artifacts.deploy.publishNewVersion": "Publish this version",
"artifacts.deploy.quotaUnavailable": "Deployment quota validation is temporarily unavailable. Try again later.",
+ "artifacts.deploy.serviceOverloaded": "Artifact hosting is temporarily overloaded. Try publishing again shortly.",
"artifacts.deploy.success": "Published",
"artifacts.deploy.writeInProgress": "Another deployment change is in progress. Try again shortly.",
"artifacts.display.code": "Code",
diff --git a/locales/en-US/subscription.json b/locales/en-US/subscription.json
index f8dd413f374..a3ec209d1e3 100644
--- a/locales/en-US/subscription.json
+++ b/locales/en-US/subscription.json
@@ -361,6 +361,9 @@
"payment.upgradeFailed.title": "Upgrade Failed",
"payment.upgradeSuccess.desc": "Your subscription plan has been upgraded successfully",
"payment.upgradeSuccess.title": "Upgrade Successful",
+ "plans.artifactHosting.deployments": "Up to {{count}} active Artifact sites",
+ "plans.artifactHosting.siteSize": "Up to {{size}} per published site",
+ "plans.artifactHosting.title": "Artifact Hosting",
"plans.btn.contact": "Contact Us",
"plans.btn.noAction": "Plan Locked",
"plans.btn.payment": "Purchase",
@@ -473,8 +476,8 @@
"plans.workspace.maxMembers": "Up to {{count}} members",
"plans.workspace.noSharedCredits": "No shared credits",
"plans.workspace.sharedCredits": "~{{count}} Credits / mo",
- "plansModal.artifactDeploymentLimit.desc": "Your public Artifact deployment limit has been reached. Upgrade your plan to publish more projects.",
- "plansModal.artifactDeploymentLimit.title": "Publish more Artifacts",
+ "plansModal.artifactDeploymentLimit.desc": "Your Artifact hosting capacity has been reached. Upgrade to increase active deployments and per-site size limits.",
+ "plansModal.artifactDeploymentLimit.title": "Increase Artifact hosting capacity",
"plansModal.creditLimit.desc": "Upgrade your plan to unlock more monthly credits and keep working without interruption.",
"plansModal.creditLimit.title": "You’re out of credits",
"plansModal.default.desc": "Unlock more capacity and advanced features.",
diff --git a/locales/zh-CN/portal.json b/locales/zh-CN/portal.json
index 315bad1c8dc..d9b6220d924 100644
--- a/locales/zh-CN/portal.json
+++ b/locales/zh-CN/portal.json
@@ -9,7 +9,9 @@
"artifacts.deploy.copy": "复制链接",
"artifacts.deploy.copySuccess": "部署链接已复制",
"artifacts.deploy.failed": "发布失败",
+ "artifacts.deploy.highestPlanCapacityLimitReached": "已达到当前自助部署容量,请管理已发布项目或减少部署用量。",
"artifacts.deploy.highestPlanLimitReached": "已达到公开部署上限({{used}} / {{limit}})。请取消发布一个项目以释放额度。",
+ "artifacts.deploy.highestPlanSizeLimitReached": "此站点大小为 {{actual}},超过 {{limit}} 的自助发布上限。请精简资源后再发布。",
"artifacts.deploy.history": "修订历史",
"artifacts.deploy.limitReached": "已达到公开部署上限({{used}} / {{limit}})。请取消发布一个项目或升级套餐。",
"artifacts.deploy.open": "打开部署",
@@ -17,6 +19,7 @@
"artifacts.deploy.publish": "发布",
"artifacts.deploy.publishNewVersion": "发布此版本",
"artifacts.deploy.quotaUnavailable": "暂时无法校验部署配额,请稍后重试。",
+ "artifacts.deploy.serviceOverloaded": "Artifact 托管服务当前繁忙,请稍后重新发布。",
"artifacts.deploy.success": "已发布",
"artifacts.deploy.writeInProgress": "另一个部署变更正在进行,请稍后重试。",
"artifacts.display.code": "代码",
diff --git a/locales/zh-CN/subscription.json b/locales/zh-CN/subscription.json
index 05d0d6483f1..c5f0314568f 100644
--- a/locales/zh-CN/subscription.json
+++ b/locales/zh-CN/subscription.json
@@ -361,6 +361,9 @@
"payment.upgradeFailed.title": "升级失败",
"payment.upgradeSuccess.desc": "您的订阅计划已成功升级",
"payment.upgradeSuccess.title": "升级成功",
+ "plans.artifactHosting.deployments": "最多 {{count}} 个活跃 Artifact 站点",
+ "plans.artifactHosting.siteSize": "每个发布站点最高 {{size}}",
+ "plans.artifactHosting.title": "Artifact 托管",
"plans.btn.contact": "联系我们",
"plans.btn.noAction": "计划已锁定",
"plans.btn.payment": "立即购买",
@@ -473,8 +476,8 @@
"plans.workspace.maxMembers": "最多 {{count}} 名成员",
"plans.workspace.noSharedCredits": "无共享积分",
"plans.workspace.sharedCredits": "~{{count}} 积分 / 月",
- "plansModal.artifactDeploymentLimit.desc": "公开 Artifact 部署数量已达上限,升级套餐以发布更多项目。",
- "plansModal.artifactDeploymentLimit.title": "发布更多 Artifact",
+ "plansModal.artifactDeploymentLimit.desc": "Artifact 托管容量已达上限,升级套餐可提高活跃部署数量和单站体积额度。",
+ "plansModal.artifactDeploymentLimit.title": "提升 Artifact 托管容量",
"plansModal.creditLimit.desc": "升级方案以解锁更多每月积分,畅用不中断。",
"plansModal.creditLimit.title": "积分已用尽",
"plansModal.default.desc": "解锁更多容量与高级功能。",
diff --git a/packages/locales/src/default/portal.ts b/packages/locales/src/default/portal.ts
index 090255aaff0..9b2cf265494 100644
--- a/packages/locales/src/default/portal.ts
+++ b/packages/locales/src/default/portal.ts
@@ -13,8 +13,12 @@ export default {
'artifacts.deploy.confirm.title': 'Before you publish this artifact',
'artifacts.deploy.failed': 'Deployment failed',
'artifacts.deploy.history': 'Revision history',
+ 'artifacts.deploy.highestPlanCapacityLimitReached':
+ 'Current self-service deployment capacity has been reached. Manage published projects or reduce deployment usage.',
'artifacts.deploy.highestPlanLimitReached':
'Public deployment limit reached ({{used}} / {{limit}}). Unpublish a project to free a slot.',
+ 'artifacts.deploy.highestPlanSizeLimitReached':
+ 'This site is {{actual}}, above the {{limit}} self-service limit. Reduce its assets before publishing.',
'artifacts.deploy.limitReached':
'Public deployment limit reached ({{used}} / {{limit}}). Unpublish a project or upgrade your plan.',
'artifacts.deploy.open': 'Open deployment',
@@ -23,6 +27,8 @@ export default {
'artifacts.deploy.publishNewVersion': 'Publish this version',
'artifacts.deploy.quotaUnavailable':
'Deployment quota validation is temporarily unavailable. Try again later.',
+ 'artifacts.deploy.serviceOverloaded':
+ 'Artifact hosting is temporarily overloaded. Try publishing again shortly.',
'artifacts.deploy.success': 'Published',
'artifacts.deploy.writeInProgress':
'Another deployment change is in progress. Try again shortly.',
diff --git a/packages/locales/src/default/subscription.ts b/packages/locales/src/default/subscription.ts
index f78bfa252f6..de0b76dfbec 100644
--- a/packages/locales/src/default/subscription.ts
+++ b/packages/locales/src/default/subscription.ts
@@ -460,6 +460,9 @@ export default {
'plans.embeddingStorage.title': 'Vector Storage',
'plans.embeddingStorage.tooltip':
'One document page (1000-1500 characters) generates approximately 1 vector entry. (Estimated using OpenAI Embeddings, may vary by model)',
+ 'plans.artifactHosting.deployments': 'Up to {{count}} active Artifact sites',
+ 'plans.artifactHosting.siteSize': 'Up to {{size}} per published site',
+ 'plans.artifactHosting.title': 'Artifact Hosting',
'plans.features.agents': 'Curated Agent Market',
'plans.features.ceAgents': 'Community Agent Market',
'plans.features.cePlugins': 'Community Plugin Market',
@@ -547,8 +550,8 @@ export default {
'plans.target': 'Target Plan',
'plans.unlimited': 'Unlimited',
'plansModal.artifactDeploymentLimit.desc':
- 'Your public Artifact deployment limit has been reached. Upgrade your plan to publish more projects.',
- 'plansModal.artifactDeploymentLimit.title': 'Publish more Artifacts',
+ 'Your Artifact hosting capacity has been reached. Upgrade to increase active deployments and per-site size limits.',
+ 'plansModal.artifactDeploymentLimit.title': 'Increase Artifact hosting capacity',
'plansModal.creditLimit.desc':
'Upgrade your plan to unlock more monthly credits and keep working without interruption.',
'plansModal.creditLimit.title': 'You’re out of credits',
diff --git a/src/features/Portal/LocalFile/gatherWorkspaceHtmlArtifact.test.ts b/src/features/Portal/LocalFile/gatherWorkspaceHtmlArtifact.test.ts
index cb3ab24a70b..afd057c750b 100644
--- a/src/features/Portal/LocalFile/gatherWorkspaceHtmlArtifact.test.ts
+++ b/src/features/Portal/LocalFile/gatherWorkspaceHtmlArtifact.test.ts
@@ -48,20 +48,23 @@ describe('gatherWorkspaceHtmlArtifact', () => {
expect(result.blocked).toBeUndefined();
});
- it('lists missing and oversized refs without blocking the rest', async () => {
+ it('blocks publishing when any referenced asset exceeds the hard site limit', async () => {
const result = await gatherWorkspaceHtmlArtifact({
htmlContent:
'<html><link rel="stylesheet" href="app.css"><img src="gone.png"><img src="huge.png"></html>',
htmlFilePath: '/project/index.html',
readAsset: async (absolutePath) => {
if (absolutePath.endsWith('app.css')) return textAsset('body{}', 'text/css');
- if (absolutePath.endsWith('huge.png')) return { ok: false, reason: 'oversized' };
+ if (absolutePath.endsWith('huge.png')) {
+ return { ok: false, reason: 'oversized', sizeBytes: 51 * 1024 * 1024 };
+ }
return { ok: false, reason: 'missing' };
},
workingDirectory: '/project',
});
- expect(result.files.map((file) => file.path).sort()).toEqual(['app.css', 'index.html']);
+ expect(result.blocked).toBe('too-large');
+ expect(result.files).toEqual([]);
expect(result.missing).toEqual(['gone.png']);
expect(result.oversized).toEqual(['huge.png']);
});
@@ -217,7 +220,7 @@ describe('gatherWorkspaceHtmlArtifact', () => {
});
expect(result.blocked).toBe('too-large');
- expect(reads).toBe(5);
+ expect(reads).toBe(10);
});
it('reads a file once when it is referenced through several spellings', async () => {
diff --git a/src/features/Portal/LocalFile/gatherWorkspaceHtmlArtifact.ts b/src/features/Portal/LocalFile/gatherWorkspaceHtmlArtifact.ts
index d24517fc0c1..155b0ead006 100644
--- a/src/features/Portal/LocalFile/gatherWorkspaceHtmlArtifact.ts
+++ b/src/features/Portal/LocalFile/gatherWorkspaceHtmlArtifact.ts
@@ -121,11 +121,24 @@ export const gatherWorkspaceHtmlArtifact = async ({
else if (totalBytes > WORKSPACE_HTML_ARTIFACT_MAX_TOTAL_BYTES) blocked = 'too-large';
};
+ const registerReadFailure = (
+ asset: Extract<ReadWorkspaceAssetResult, { ok: false }>,
+ href: string,
+ ) => {
+ if (asset.reason !== 'oversized') {
+ missing.push(href);
+ return;
+ }
+
+ oversized.push(href);
+ totalBytes += asset.sizeBytes ?? WORKSPACE_HTML_ARTIFACT_MAX_TOTAL_BYTES + 1;
+ blocked = 'too-large';
+ };
+
const readLeafAsset = async (ref: CollectedLocalResourceRef) => {
const asset = await readAsset(ref.absolutePath);
if (!asset.ok) {
- if (asset.reason === 'oversized') oversized.push(ref.href);
- else missing.push(ref.href);
+ registerReadFailure(asset, ref.href);
return;
}
@@ -145,8 +158,7 @@ export const gatherWorkspaceHtmlArtifact = async ({
const asset = await readAsset(walkRef.absolutePath);
if (!asset.ok) {
- if (asset.reason === 'oversized') oversized.push(walkRef.href);
- else missing.push(walkRef.href);
+ registerReadFailure(asset, walkRef.href);
continue;
}
diff --git a/src/features/Portal/LocalFile/prepareWorkspaceHtmlPublish.test.ts b/src/features/Portal/LocalFile/prepareWorkspaceHtmlPublish.test.ts
index eabcd96c3ac..c6e379cbb80 100644
--- a/src/features/Portal/LocalFile/prepareWorkspaceHtmlPublish.test.ts
+++ b/src/features/Portal/LocalFile/prepareWorkspaceHtmlPublish.test.ts
@@ -1,8 +1,18 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
-import { prepareWorkspaceHtmlPublish } from './prepareWorkspaceHtmlPublish';
+import {
+ getWorkspaceHtmlPublishSizeBytes,
+ prepareWorkspaceHtmlPublish,
+ publishPreparedWorkspaceHtml,
+} from './prepareWorkspaceHtmlPublish';
const readWorkspaceAsset = vi.hoisted(() => vi.fn());
+const toastError = vi.hoisted(() => vi.fn());
+const toastSuccess = vi.hoisted(() => vi.fn());
+
+vi.mock('@lobehub/ui/base-ui', () => ({
+ toast: { error: toastError, success: toastSuccess },
+}));
vi.mock('./readWorkspaceAsset', async (importOriginal) => {
const actual = await importOriginal();
@@ -15,6 +25,8 @@ vi.mock('./readWorkspaceAsset', async (importOriginal) => {
describe('prepareWorkspaceHtmlPublish', () => {
beforeEach(() => {
readWorkspaceAsset.mockReset();
+ toastError.mockReset();
+ toastSuccess.mockReset();
});
it('packs provided HTML without reading the file', async () => {
@@ -64,4 +76,54 @@ describe('prepareWorkspaceHtmlPublish', () => {
}),
).resolves.toEqual({ blocked: 'unreadable' });
});
+
+ it('measures the packed HTML and decoded sidecars sent to hosting', () => {
+ expect(
+ getWorkspaceHtmlPublishSizeBytes({
+ gathered: {} as never,
+ packed: {
+ html: '页',
+ inlinedPaths: [],
+ sidecars: [
+ {
+ content: 'AQID',
+ contentType: 'image/png',
+ encoding: 'base64',
+ path: 'hero.png',
+ },
+ {
+ content: 'ok',
+ contentType: 'text/css',
+ encoding: 'utf8',
+ path: 'app.css',
+ },
+ ],
+ unresolvedHrefs: [],
+ },
+ }),
+ ).toBe(8);
+ });
+
+ it('lets the commercial layer consume a known publish error without a generic toast', async () => {
+ const plan = await prepareWorkspaceHtmlPublish({
+ content: '<html><title>Demo</title></html>',
+ filePath: '/repo/index.html',
+ workingDirectory: '/repo',
+ });
+ if ('blocked' in plan) throw new Error('expected ready plan');
+ const error = new Error('ARTIFACT_DEPLOYMENT_LIMIT_REACHED:3:3');
+ const onError = vi.fn(() => true);
+
+ await expect(
+ publishPreparedWorkspaceHtml({
+ onError,
+ plan,
+ publish: vi.fn().mockRejectedValue(error),
+ topicId: 'topic-1',
+ }),
+ ).resolves.toBeUndefined();
+
+ expect(onError).toHaveBeenCalledWith(error);
+ expect(toastError).not.toHaveBeenCalled();
+ });
});
diff --git a/src/features/Portal/LocalFile/prepareWorkspaceHtmlPublish.ts b/src/features/Portal/LocalFile/prepareWorkspaceHtmlPublish.ts
index d37786d831b..5e99ea4e0ec 100644
--- a/src/features/Portal/LocalFile/prepareWorkspaceHtmlPublish.ts
+++ b/src/features/Portal/LocalFile/prepareWorkspaceHtmlPublish.ts
@@ -20,6 +20,23 @@ export interface ReadyWorkspaceHtmlPublishPlan {
packed: PackedWorkspaceHtmlSite;
}
+const base64ByteLength = (content: string): number => {
+ const compact = content.replaceAll(/\s+/g, '');
+ const padding = compact.endsWith('==') ? 2 : compact.endsWith('=') ? 1 : 0;
+ return Math.max(0, Math.floor((compact.length * 3) / 4) - padding);
+};
+
+export const getWorkspaceHtmlPublishSizeBytes = (plan: ReadyWorkspaceHtmlPublishPlan): number =>
+ new TextEncoder().encode(plan.packed.html).byteLength +
+ plan.packed.sidecars.reduce(
+ (total, file) =>
+ total +
+ (file.encoding === 'base64'
+ ? base64ByteLength(file.content)
+ : new TextEncoder().encode(file.content).byteLength),
+ 0,
+ );
+
export type WorkspaceHtmlPublishPlan =
| {
blocked: 'too-large' | 'too-many';
@@ -117,17 +134,18 @@ const workspaceHtmlPublishErrorMessage = (error: unknown): string => {
if (error instanceof Error && error.message === 'unresolved-local-assets') {
return t('workingPanel.localFile.publish.unresolvedLocals', { ns: 'chat' });
}
- if (error instanceof Error && error.message) return error.message;
return t('workingPanel.localFile.publish.failed', { ns: 'chat' });
};
export const publishPreparedWorkspaceHtml = async ({
agentId,
+ onError,
plan,
publish,
topicId,
}: {
agentId?: string | null;
+ onError?: (error: unknown) => boolean;
plan: ReadyWorkspaceHtmlPublishPlan;
publish: WorkspaceHtmlArtifactPublisher['publish'];
topicId: string;
@@ -146,7 +164,7 @@ export const publishPreparedWorkspaceHtml = async ({
toast.success(t('workingPanel.localFile.publish.success', { ns: 'chat' }));
return result;
} catch (error) {
- toast.error(workspaceHtmlPublishErrorMessage(error));
+ if (!onError?.(error)) toast.error(workspaceHtmlPublishErrorMessage(error));
return;
}
};
diff --git a/src/features/Portal/LocalFile/readWorkspaceAsset.test.ts b/src/features/Portal/LocalFile/readWorkspaceAsset.test.ts
index 337b73ded4d..4a4c7979822 100644
--- a/src/features/Portal/LocalFile/readWorkspaceAsset.test.ts
+++ b/src/features/Portal/LocalFile/readWorkspaceAsset.test.ts
@@ -1,6 +1,8 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
-const callTool = vi.fn();
+const callTool = vi.hoisted(() => vi.fn());
+const getLocalFilePreview = vi.hoisted(() => vi.fn());
+const readProjectFileBytes = vi.hoisted(() => vi.fn());
vi.mock('@/services/cloudSandbox', () => ({
cloudSandboxService: {
@@ -10,8 +12,8 @@ vi.mock('@/services/cloudSandbox', () => ({
vi.mock('@/services/projectFile', () => ({
projectFileService: {
- getLocalFilePreview: vi.fn(),
- readProjectFileBytes: vi.fn(),
+ getLocalFilePreview,
+ readProjectFileBytes,
},
}));
@@ -33,6 +35,8 @@ describe('resolveWorkspaceAssetContentType', () => {
describe('readWorkspaceAsset', () => {
beforeEach(() => {
callTool.mockReset();
+ getLocalFilePreview.mockReset();
+ readProjectFileBytes.mockReset();
});
it('reads sandbox text files through readLocalFile', async () => {
@@ -105,4 +109,28 @@ describe('readWorkspaceAsset', () => {
}),
).resolves.toEqual({ ok: false, reason: 'unreadable' });
});
+
+ it('accepts a local asset larger than the former 8 MiB packaging cap', async () => {
+ const bytes = new Uint8Array(9 * 1024 * 1024);
+ getLocalFilePreview.mockResolvedValue({ type: 'unsupported' });
+ readProjectFileBytes.mockResolvedValue({ bytes, contentType: 'application/javascript' });
+
+ const result = await readWorkspaceAsset({
+ path: '/tmp/runtime.js',
+ workingDirectory: '/tmp',
+ });
+
+ expect(result.ok).toBe(true);
+ if (result.ok) expect(result.bytes).toBe(bytes);
+ });
+
+ it('reports the measured size when a local asset exceeds the hosting hard limit', async () => {
+ const bytes = new Uint8Array(50 * 1024 * 1024 + 1);
+ getLocalFilePreview.mockResolvedValue({ type: 'unsupported' });
+ readProjectFileBytes.mockResolvedValue({ bytes, contentType: 'application/javascript' });
+
+ await expect(
+ readWorkspaceAsset({ path: '/tmp/runtime.js', workingDirectory: '/tmp' }),
+ ).resolves.toEqual({ ok: false, reason: 'oversized', sizeBytes: bytes.byteLength });
+ });
});
diff --git a/src/features/Portal/LocalFile/readWorkspaceAsset.ts b/src/features/Portal/LocalFile/readWorkspaceAsset.ts
index 35fc5718dc6..e85d54feff3 100644
--- a/src/features/Portal/LocalFile/readWorkspaceAsset.ts
+++ b/src/features/Portal/LocalFile/readWorkspaceAsset.ts
@@ -3,8 +3,8 @@ import { base64ToBytes, getMimeType } from '@lobechat/utils';
import { cloudSandboxService } from '@/services/cloudSandbox';
import { type LocalFilePreview, projectFileService } from '@/services/projectFile';
-export const WORKSPACE_HTML_ARTIFACT_MAX_FILE_BYTES = 8 * 1024 * 1024;
-export const WORKSPACE_HTML_ARTIFACT_MAX_TOTAL_BYTES = 20 * 1024 * 1024;
+export const WORKSPACE_HTML_ARTIFACT_MAX_FILE_BYTES = 50 * 1024 * 1024;
+export const WORKSPACE_HTML_ARTIFACT_MAX_TOTAL_BYTES = 50 * 1024 * 1024;
export const WORKSPACE_HTML_ARTIFACT_MAX_FILES = 64;
export const WORKSPACE_HTML_ARTIFACT_INLINE_MAX_BYTES = 32 * 1024;
@@ -20,6 +20,7 @@ export interface ReadWorkspaceAssetSuccess {
export interface ReadWorkspaceAssetError {
ok: false;
reason: ReadWorkspaceAssetFailure;
+ sizeBytes?: number;
}
export type ReadWorkspaceAssetResult = ReadWorkspaceAssetError | ReadWorkspaceAssetSuccess;
@@ -100,7 +101,7 @@ const previewToBytes = async (
if (preview.type === 'text') {
const bytes = new TextEncoder().encode(preview.content);
if (bytes.byteLength > WORKSPACE_HTML_ARTIFACT_MAX_FILE_BYTES) {
- return { ok: false, reason: 'oversized' };
+ return { ok: false, reason: 'oversized', sizeBytes: bytes.byteLength };
}
return {
bytes,
@@ -112,7 +113,7 @@ const previewToBytes = async (
if (preview.type === 'image' || preview.type === 'document') {
if (preview.blob.size > WORKSPACE_HTML_ARTIFACT_MAX_FILE_BYTES) {
- return { ok: false, reason: 'oversized' };
+ return { ok: false, reason: 'oversized', sizeBytes: preview.blob.size };
}
const bytes = new Uint8Array(await preview.blob.arrayBuffer());
const text = isTextContentType(preview.contentType)
@@ -151,7 +152,7 @@ export const readWorkspaceAsset = async ({
const text = result.result.content;
const bytes = new TextEncoder().encode(text);
if (bytes.byteLength > WORKSPACE_HTML_ARTIFACT_MAX_FILE_BYTES) {
- return { ok: false, reason: 'oversized' };
+ return { ok: false, reason: 'oversized', sizeBytes: bytes.byteLength };
}
return {
@@ -165,7 +166,7 @@ export const readWorkspaceAsset = async ({
const bytes = await readSandboxBytes(path, sandboxTopicId);
if (!bytes) return { ok: false, reason: 'unreadable' };
if (bytes.byteLength > WORKSPACE_HTML_ARTIFACT_MAX_FILE_BYTES) {
- return { ok: false, reason: 'oversized' };
+ return { ok: false, reason: 'oversized', sizeBytes: bytes.byteLength };
}
return { bytes, contentType, ok: true };
@@ -192,7 +193,7 @@ export const readWorkspaceAsset = async ({
});
if (!bytesResult) return { ok: false, reason: 'unreadable' };
if (bytesResult.bytes.byteLength > WORKSPACE_HTML_ARTIFACT_MAX_FILE_BYTES) {
- return { ok: false, reason: 'oversized' };
+ return { ok: false, reason: 'oversized', sizeBytes: bytesResult.bytes.byteLength };
}
const contentType = resolveWorkspaceAssetContentType(path, bytesResult.contentType);