diff --git a/front/lib/api/workspace.ts b/front/lib/api/workspace.ts index 72930066ac81..ce31dd71566c 100644 --- a/front/lib/api/workspace.ts +++ b/front/lib/api/workspace.ts @@ -127,7 +127,8 @@ export async function upgradeWorkspace(workspaceId: number) { plan.limits.dataSources.count = -1; plan.limits.dataSources.documents.count = -1; - plan.limits.dataSources.documents.sizeMb = -1; + // Enforce 1MB limitation even for upgraded workspaces. + plan.limits.dataSources.documents.sizeMb = 1; plan.limits.dataSources.managed = true; plan.limits.largeModels = true; diff --git a/front/migrations/20230929_enforce_1mb_even_for_upgraded_workspaces.ts b/front/migrations/20230929_enforce_1mb_even_for_upgraded_workspaces.ts new file mode 100644 index 000000000000..7f4cd3f0b65a --- /dev/null +++ b/front/migrations/20230929_enforce_1mb_even_for_upgraded_workspaces.ts @@ -0,0 +1,58 @@ +import { Op } from "sequelize"; + +import { planForWorkspace } from "@app/lib/auth"; +import { Workspace } from "@app/lib/models"; + +const { LIVE = false } = process.env; + +async function main() { + console.log("Fetching Upgraded Worspaces..."); + const workspaces = await Workspace.findAll({ + where: { + upgradedAt: { + [Op.not]: null, + }, + }, + }); + console.log( + `Found ${workspaces.length} workspaces for which to add largeModels = true` + ); + + const chunkSize = 16; + const chunks = []; + for (let i = 0; i < workspaces.length; i += chunkSize) { + chunks.push(workspaces.slice(i, i + chunkSize)); + } + + for (let i = 0; i < chunks.length; i++) { + console.log(`Processing chunk ${i}/${chunks.length}...`); + const chunk = chunks[i]; + await Promise.all( + chunk.map((workspace: Workspace) => { + return set1MBLimit(!!LIVE, workspace); + }) + ); + } +} + +async function set1MBLimit(live: boolean, workspace: Workspace) { + const plan = planForWorkspace(workspace); + plan.limits.dataSources.documents.sizeMb = 1; + if (live) { + await workspace.update({ + plan: JSON.stringify(plan), + }); + } else { + console.log(`Would have mutated ${workspace.sId}`); + } +} + +main() + .then(() => { + console.log("done"); + process.exit(0); + }) + .catch((err) => { + console.error(err); + process.exit(1); + }); diff --git a/front/pages/api/v1/w/[wId]/data_sources/[name]/documents/[documentId]/index.ts b/front/pages/api/v1/w/[wId]/data_sources/[name]/documents/[documentId]/index.ts index 401134481243..14ec7845cb4c 100644 --- a/front/pages/api/v1/w/[wId]/data_sources/[name]/documents/[documentId]/index.ts +++ b/front/pages/api/v1/w/[wId]/data_sources/[name]/documents/[documentId]/index.ts @@ -270,7 +270,7 @@ async function handler( api_error: { type: "data_source_quota_error", message: - "Data sources document upload size is limited to 1MB on our free plan. Contact team@dust.tt if you want to increase it.", + "Data sources document upload size is limited to 1MB. Contact team@dust.tt if you want to increase it.", }, }); } diff --git a/front/pages/api/w/[wId]/data_sources/[name]/documents/[documentId]/index.ts b/front/pages/api/w/[wId]/data_sources/[name]/documents/[documentId]/index.ts index 3777933d3f0a..6933f5791e9f 100644 --- a/front/pages/api/w/[wId]/data_sources/[name]/documents/[documentId]/index.ts +++ b/front/pages/api/w/[wId]/data_sources/[name]/documents/[documentId]/index.ts @@ -187,7 +187,7 @@ async function handler( api_error: { type: "data_source_quota_error", message: - "Data sources document upload size is limited to 1MB on our free plan. Contact team@dust.tt if you want to increase it.", + "Data sources document upload size is limited to 1MB. Contact team@dust.tt if you want to increase it.", }, }); } diff --git a/front/pages/poke/[wId]/index.tsx b/front/pages/poke/[wId]/index.tsx index c07dc290960d..2d20250a2165 100644 --- a/front/pages/poke/[wId]/index.tsx +++ b/front/pages/poke/[wId]/index.tsx @@ -248,14 +248,6 @@ const WorkspacePage = ({ (ds) => !!ds.connectorProvider ); - // @todo remove fallback on workspace plan - const isFullyUpgraded = - workspace.upgradedAt !== null || - (workspace.plan?.limits.dataSources.count === -1 && - workspace.plan?.limits.dataSources.documents.count === -1 && - workspace.plan?.limits.dataSources.documents.sizeMb === -1 && - workspace.plan?.limits.dataSources.managed === true); - return (
@@ -275,7 +267,7 @@ const WorkspacePage = ({

Plan:

- {isFullyUpgraded ? ( + {workspace.upgradedAt ? (

This workspace was fully upgraded {workspace.upgradedAt && @@ -294,18 +286,20 @@ const WorkspacePage = ({ label="Downgrade" variant="secondaryWarning" onClick={onDowngrade} - disabled={!isFullyUpgraded || workspaceHasManagedDataSources} + disabled={ + !workspace.upgradedAt || workspaceHasManagedDataSources + } />

- {isFullyUpgraded && workspaceHasManagedDataSources && ( + {workspace.upgradedAt && workspaceHasManagedDataSources && (

Delete managed data sources before downgrading. diff --git a/front/pages/w/[wId]/builder/data-sources/[name]/upsert.tsx b/front/pages/w/[wId]/builder/data-sources/[name]/upsert.tsx index 0df87e106ad3..434dc0d4f73c 100644 --- a/front/pages/w/[wId]/builder/data-sources/[name]/upsert.tsx +++ b/front/pages/w/[wId]/builder/data-sources/[name]/upsert.tsx @@ -116,10 +116,27 @@ export default function DataSourceUpsert({ } }, [dataSource.name, loadDocumentId, owner.sId]); + const alertDataSourcesLimit = () => { + window.alert( + "DataSource document upload size is limited to " + + `${owner.plan.limits.dataSources.documents.sizeMb}MB (of raw text)` + + ". Contact team@dust.tt if you want to increase this limit." + ); + }; + const handleFileLoadedText = (e: any) => { const content = e.target.result; - setText(content); setUploading(false); + + // Enforce plan limits: DataSource documents size. + if ( + owner.plan.limits.dataSources.documents.sizeMb != -1 && + text.length > 1024 * 1024 * owner.plan.limits.dataSources.documents.sizeMb + ) { + alertDataSourcesLimit(); + return; + } + setText(content); }; const handleFileLoadedPDF = async (e: any) => { @@ -133,21 +150,21 @@ export default function DataSourceUpsert({ const strings = content.items.map((item: any) => item.str); text += strings.join(" ") + "\n"; } - setText(text); + setUploading(false); - }; - const handleFileUpload = async (file: File) => { // Enforce plan limits: DataSource documents size. if ( owner.plan.limits.dataSources.documents.sizeMb != -1 && - file.size > 1024 * 1024 * owner.plan.limits.dataSources.documents.sizeMb + text.length > 1024 * 1024 * owner.plan.limits.dataSources.documents.sizeMb ) { - window.alert( - "DataSource document upload size is limited to 1MB on our free plan. Contact team@dust.tt if you want to increase this limit." - ); + alertDataSourcesLimit(); return; } + setText(text); + }; + + const handleFileUpload = async (file: File) => { setUploading(true); if (file.type === "application/pdf") { const fileReader = new FileReader();