diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..e9261abc --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Yiling-J + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/bun.lock b/bun.lock index f0ecc23f..0ed16b11 100644 --- a/bun.lock +++ b/bun.lock @@ -111,8 +111,6 @@ "name": "@shumai/core", "version": "0.1.0", "dependencies": { - "@aws-sdk/client-s3": "^3.1031.0", - "@aws-sdk/s3-request-presigner": "^3.1031.0", "@shumai/db": "workspace:*", "@shumai/dtos": "workspace:*", "@sinclair/typebox": "^0.34.49", @@ -294,10 +292,6 @@ "@aws-crypto/crc32": ["@aws-crypto/crc32@5.2.0", "", { "dependencies": { "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "tslib": "^2.6.2" } }, "sha512-nLbCWqQNgUiwwtFsen1AdzAtvuLRsQS8rYgMuxCrdKf9kOssamGLuPwyTY9wyYblNr9+1XM8v6zoDTPPSIeANg=="], - "@aws-crypto/crc32c": ["@aws-crypto/crc32c@5.2.0", "", { "dependencies": { "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "tslib": "^2.6.2" } }, "sha512-+iWb8qaHLYKrNvGRbiYRHSdKRWhto5XlZUEBwDjYNf+ly5SVYG6zEoYIdxvf5R3zyeP16w4PLBn3rH1xc74Rag=="], - - "@aws-crypto/sha1-browser": ["@aws-crypto/sha1-browser@5.2.0", "", { "dependencies": { "@aws-crypto/supports-web-crypto": "^5.2.0", "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "@aws-sdk/util-locate-window": "^3.0.0", "@smithy/util-utf8": "^2.0.0", "tslib": "^2.6.2" } }, "sha512-OH6lveCFfcDjX4dbAvCFSYUjJZjDr/3XJ3xHtjn3Oj5b9RjojQo8npoLeA/bNwkOkrSQ0wgrHzXk4tDRxGKJeg=="], - "@aws-crypto/sha256-browser": ["@aws-crypto/sha256-browser@5.2.0", "", { "dependencies": { "@aws-crypto/sha256-js": "^5.2.0", "@aws-crypto/supports-web-crypto": "^5.2.0", "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "@aws-sdk/util-locate-window": "^3.0.0", "@smithy/util-utf8": "^2.0.0", "tslib": "^2.6.2" } }, "sha512-AXfN/lGotSQwu6HNcEsIASo7kWXZ5HYWvfOmSNKDsEqC4OashTp8alTmaz+F7TC2L083SFv5RdB+qU3Vs1kZqw=="], "@aws-crypto/sha256-js": ["@aws-crypto/sha256-js@5.2.0", "", { "dependencies": { "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "tslib": "^2.6.2" } }, "sha512-FFQQyu7edu4ufvIZ+OadFpHHOt+eSTBaYaki44c+akjg7qZg9oOQeLlk77F6tSYqjDAFClrHJk9tMf0HdVyOvA=="], @@ -308,12 +302,8 @@ "@aws-sdk/client-bedrock-runtime": ["@aws-sdk/client-bedrock-runtime@3.1048.0", "", { "dependencies": { "@aws-crypto/sha256-browser": "5.2.0", "@aws-crypto/sha256-js": "5.2.0", "@aws-sdk/core": "^3.974.11", "@aws-sdk/credential-provider-node": "^3.972.42", "@aws-sdk/eventstream-handler-node": "^3.972.16", "@aws-sdk/middleware-eventstream": "^3.972.12", "@aws-sdk/middleware-websocket": "^3.972.19", "@aws-sdk/token-providers": "3.1048.0", "@aws-sdk/types": "^3.973.8", "@smithy/core": "^3.24.2", "@smithy/fetch-http-handler": "^5.4.2", "@smithy/node-http-handler": "^4.7.2", "@smithy/types": "^4.14.1", "tslib": "^2.6.2" } }, "sha512-u+NT61JZEkRFtpL0CAw1N1dwxnaLgwVXQl/zjJxTGgLyS/jTIdg2SdoEoCTHxgDyCnqa1HEi9QOoE9/pYRNpOQ=="], - "@aws-sdk/client-s3": ["@aws-sdk/client-s3@3.1058.0", "", { "dependencies": { "@aws-crypto/sha1-browser": "5.2.0", "@aws-crypto/sha256-browser": "5.2.0", "@aws-crypto/sha256-js": "5.2.0", "@aws-sdk/core": "^3.974.15", "@aws-sdk/credential-provider-node": "^3.972.48", "@aws-sdk/middleware-bucket-endpoint": "^3.972.17", "@aws-sdk/middleware-expect-continue": "^3.972.14", "@aws-sdk/middleware-flexible-checksums": "^3.974.23", "@aws-sdk/middleware-location-constraint": "^3.972.11", "@aws-sdk/middleware-sdk-s3": "^3.972.44", "@aws-sdk/middleware-ssec": "^3.972.11", "@aws-sdk/signature-v4-multi-region": "^3.996.30", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/fetch-http-handler": "^5.4.5", "@smithy/node-http-handler": "^4.7.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-AfED3hhaBZ121NuiBImgnlF98kQRMk6hGPMGfj/Oo1hSaoMFRzM+N4nlICCasUSM2R8QaIRZRYGpZ3fy0ilGZQ=="], - "@aws-sdk/core": ["@aws-sdk/core@3.974.15", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@aws-sdk/xml-builder": "^3.972.26", "@aws/lambda-invoke-store": "^0.2.2", "@smithy/core": "^3.24.5", "@smithy/signature-v4": "^5.4.5", "@smithy/types": "^4.14.2", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-UpA0rTGW/tHGITcCqHisbuuEPraYg9GG+mWmXjY5+RxZBMLGe6aL9oe0ix50LztwAcPIkGZLH0yWdMIkCM10hw=="], - "@aws-sdk/crc64-nvme": ["@aws-sdk/crc64-nvme@3.972.9", "", { "dependencies": { "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-P+QGozmXn2mZZI7sDgk+aUm+RTI61MPSFB+Ir2vjEjEbEsE4e7hYtzrDvAUxZy9ko81h53e11+F/GYlvwDkaOQ=="], - "@aws-sdk/credential-provider-env": ["@aws-sdk/credential-provider-env@3.972.41", "", { "dependencies": { "@aws-sdk/core": "^3.974.15", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-n1EbJ98yvPWWdHZZv8bRBMqqDQJrtgtxyJ4xLy2Uqrh25BCOZQ7nnS1CsFXvuH8r0b0KVHDZEGEH5FxmEMP8jg=="], "@aws-sdk/credential-provider-http": ["@aws-sdk/credential-provider-http@3.972.43", "", { "dependencies": { "@aws-sdk/core": "^3.974.15", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/fetch-http-handler": "^5.4.5", "@smithy/node-http-handler": "^4.7.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-TT76RN1NkI9WoyZqCNxOw6/WBMF7pYOTJcXbMokNFU+euSG40Kaf/t/FhDACVZWP+43wEM6ZynIPIkzS1wR1iA=="], @@ -332,26 +322,12 @@ "@aws-sdk/eventstream-handler-node": ["@aws-sdk/eventstream-handler-node@3.972.18", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-QPQhwY/fstR8fMZFWrsJRNoTP6D1RjRPHGRX7u9/VkF3opCsvD0oXPz6qzkX94SchzvuS5vyFZbJbPcMEs2Jeg=="], - "@aws-sdk/middleware-bucket-endpoint": ["@aws-sdk/middleware-bucket-endpoint@3.972.17", "", { "dependencies": { "@aws-sdk/core": "^3.974.15", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-lbDmWuHenc+kiwCNrxz4MyN6nkxCWyTXPIWuspJN0ibziu+8CXci7vI1bK9MAkwy8cwJOEXNu0gBM5S0uTGRIg=="], - "@aws-sdk/middleware-eventstream": ["@aws-sdk/middleware-eventstream@3.972.14", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-DoZ4djVj/74XQ6M/IwxuKh543tTvLCL7u1Dx+VDHMgW9yGNrFSJJ1l0LrUQRaekic5CB12wUiiOoHL0VI6H0gg=="], - "@aws-sdk/middleware-expect-continue": ["@aws-sdk/middleware-expect-continue@3.972.14", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-3TNFEVGO4sWZj9TEXOCZLzGEctXHnaO4fk2EQ8KVaboTbwHmEPEQrm17Xb9koImUIXEw0sgi2xtHjg7LuTS3rA=="], - - "@aws-sdk/middleware-flexible-checksums": ["@aws-sdk/middleware-flexible-checksums@3.974.23", "", { "dependencies": { "@aws-crypto/crc32": "5.2.0", "@aws-crypto/crc32c": "5.2.0", "@aws-crypto/util": "5.2.0", "@aws-sdk/core": "^3.974.15", "@aws-sdk/crc64-nvme": "^3.972.9", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-4nPKARo2lfKvQGUt2fPA5NlS/mEohckdxpuC9ecbjVfj7B7NFFYHeTg+Bf5BEQwdn3yRfUIzFiEkPp8Yuaw3wA=="], - - "@aws-sdk/middleware-location-constraint": ["@aws-sdk/middleware-location-constraint@3.972.11", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-hkfspNUP4criAH6ton6BGKgnm5dZx+7bUOy1YqlTfejDeUPAM23D81q/IX+hdlS3KUsfwGz5ADTqZWKBEUpf4A=="], - - "@aws-sdk/middleware-sdk-s3": ["@aws-sdk/middleware-sdk-s3@3.972.44", "", { "dependencies": { "@aws-sdk/core": "^3.974.15", "@aws-sdk/signature-v4-multi-region": "^3.996.30", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-8HQsRg1NpX8vR4vNl1E8pyLnqZroq9VSL2vZQVSgBqp6wv6365LzYD08/c9FFh/9FTg7YRc7aTtEmXF0ir/pqg=="], - - "@aws-sdk/middleware-ssec": ["@aws-sdk/middleware-ssec@3.972.11", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-7PQvGNhtveKlvVqNahqWx5yrwxP7ecwAoB1dYBf8eKwfo2tzzCbNnW+q2nO3N066ktQaB4iBQbDRWtizm+amoQ=="], - "@aws-sdk/middleware-websocket": ["@aws-sdk/middleware-websocket@3.972.23", "", { "dependencies": { "@aws-sdk/core": "^3.974.15", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/fetch-http-handler": "^5.4.5", "@smithy/signature-v4": "^5.4.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-F0d4A9pJFiwljyKgSwU1Z5n+CXSv8bp+V5SthbS2rftB8wBN9z1K2Yyv3xbeK0AM2T0g4q6Ptf0shFF+oQZyiA=="], "@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.997.13", "", { "dependencies": { "@aws-crypto/sha256-browser": "5.2.0", "@aws-crypto/sha256-js": "5.2.0", "@aws-sdk/core": "^3.974.15", "@aws-sdk/signature-v4-multi-region": "^3.996.30", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/fetch-http-handler": "^5.4.5", "@smithy/node-http-handler": "^4.7.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-2pA6eyb5nSo/ZD2cayhOTEMoGQYgspq0RI05GDLkzQ3ajZ6isS6waV6E92Am/hz4LIlLUTrbwPLurJ/fuiHvkg=="], - "@aws-sdk/s3-request-presigner": ["@aws-sdk/s3-request-presigner@3.1058.0", "", { "dependencies": { "@aws-sdk/core": "^3.974.15", "@aws-sdk/signature-v4-multi-region": "^3.996.30", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-IRgNfn8U3zfsZ0JkpmwjS59R/XyHMHxpuwW6HVuJhik+FsbClhNkujEO0w1WqJvXrF4FX+7qIAwUrvlwNvaZ7Q=="], - "@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.30", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@smithy/signature-v4": "^5.4.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-HULDLMVzkmTSEv6//7kx2kRevp/VYUpm8hJNNFbmhxDn0fUiGTxVcM9yg31TukvTq8nyOBDUN2gH0o5IRbKjdw=="], "@aws-sdk/token-providers": ["@aws-sdk/token-providers@3.1048.0", "", { "dependencies": { "@aws-sdk/core": "^3.974.11", "@aws-sdk/nested-clients": "^3.997.9", "@aws-sdk/types": "^3.973.8", "@smithy/core": "^3.24.2", "@smithy/types": "^4.14.1", "tslib": "^2.6.2" } }, "sha512-k0y/GcuesuSfWyUM0WamrGyeZmltRYaPbHO82UDA6mZ/doB+FOHKutikPAtSXMn/hDz970cF+iRuuiYO9VEbAA=="], @@ -1016,7 +992,7 @@ "@smithy/is-array-buffer": ["@smithy/is-array-buffer@2.2.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA=="], - "@smithy/node-http-handler": ["@smithy/node-http-handler@4.7.6", "", { "dependencies": { "@smithy/core": "^3.24.6", "@smithy/types": "^4.14.3", "tslib": "^2.6.2" } }, "sha512-3fya8i7GrJilQouk4cZJKdy5k8MWQBpjfXrRNaXDedH8r779tr0jcxyH3+yoTmsluc2+vF4S343yFbnvu8ExDQ=="], + "@smithy/node-http-handler": ["@smithy/node-http-handler@4.7.3", "", { "dependencies": { "@smithy/core": "^3.24.3", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-/jPhevcTFPMVl6KNjbaI47iOg1zxC7IsnX4PQDGVZKMFceOXtB8IEYaB7a9VvkP/3oC60WzTeKocvSI7vLT0vA=="], "@smithy/signature-v4": ["@smithy/signature-v4@5.4.6", "", { "dependencies": { "@smithy/core": "^3.24.6", "@smithy/types": "^4.14.3", "tslib": "^2.6.2" } }, "sha512-Ojg4B6oIDlIr1R86xCDJt1zJWnYa0VINmqdjfe9qxWjdRivHalZ3iSlQgVqYbW0MdpFOC5XfHEWsnbmdnpIILQ=="], @@ -2680,8 +2656,14 @@ "@anthropic-ai/sandbox-runtime/zod": ["zod@3.25.76", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="], + "@aws-sdk/client-bedrock-runtime/@smithy/node-http-handler": ["@smithy/node-http-handler@4.7.6", "", { "dependencies": { "@smithy/core": "^3.24.6", "@smithy/types": "^4.14.3", "tslib": "^2.6.2" } }, "sha512-3fya8i7GrJilQouk4cZJKdy5k8MWQBpjfXrRNaXDedH8r779tr0jcxyH3+yoTmsluc2+vF4S343yFbnvu8ExDQ=="], + + "@aws-sdk/credential-provider-http/@smithy/node-http-handler": ["@smithy/node-http-handler@4.7.6", "", { "dependencies": { "@smithy/core": "^3.24.6", "@smithy/types": "^4.14.3", "tslib": "^2.6.2" } }, "sha512-3fya8i7GrJilQouk4cZJKdy5k8MWQBpjfXrRNaXDedH8r779tr0jcxyH3+yoTmsluc2+vF4S343yFbnvu8ExDQ=="], + "@aws-sdk/credential-provider-sso/@aws-sdk/token-providers": ["@aws-sdk/token-providers@3.1056.0", "", { "dependencies": { "@aws-sdk/core": "^3.974.15", "@aws-sdk/nested-clients": "^3.997.13", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-81duvlltQlsfn5K+o8zILcystBRdbT1G2JJYVCML5NZHBz4CL/zf+sAemCtBh/uh6RQUMyInGeZLQ7/8igZhbA=="], + "@aws-sdk/nested-clients/@smithy/node-http-handler": ["@smithy/node-http-handler@4.7.6", "", { "dependencies": { "@smithy/core": "^3.24.6", "@smithy/types": "^4.14.3", "tslib": "^2.6.2" } }, "sha512-3fya8i7GrJilQouk4cZJKdy5k8MWQBpjfXrRNaXDedH8r779tr0jcxyH3+yoTmsluc2+vF4S343yFbnvu8ExDQ=="], + "@earendil-works/pi-agent-core/@earendil-works/pi-ai": ["@earendil-works/pi-ai@0.78.0", "", { "dependencies": { "@anthropic-ai/sdk": "0.91.1", "@aws-sdk/client-bedrock-runtime": "3.1048.0", "@google/genai": "1.52.0", "@mistralai/mistralai": "2.2.1", "@smithy/node-http-handler": "4.7.3", "http-proxy-agent": "7.0.2", "https-proxy-agent": "7.0.6", "openai": "6.26.0", "partial-json": "0.1.7", "typebox": "1.1.38" }, "bin": { "pi-ai": "dist/cli.js" } }, "sha512-q0hUrvT6ngT6cgBX0oIbzfQfmzztgdkZobP8OTL+sCOOBlnG6+1YRt8g7zO9CC/4NdeYEqa7uGqWdQhH0fjCLA=="], "@earendil-works/pi-agent-core/ignore": ["ignore@7.0.5", "", {}, "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg=="], @@ -3092,8 +3074,6 @@ "yauzl/buffer-crc32": ["buffer-crc32@0.2.13", "", {}, "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ=="], - "@earendil-works/pi-agent-core/@earendil-works/pi-ai/@smithy/node-http-handler": ["@smithy/node-http-handler@4.7.3", "", { "dependencies": { "@smithy/core": "^3.24.3", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-/jPhevcTFPMVl6KNjbaI47iOg1zxC7IsnX4PQDGVZKMFceOXtB8IEYaB7a9VvkP/3oC60WzTeKocvSI7vLT0vA=="], - "@isaacs/cliui/string-width/emoji-regex": ["emoji-regex@9.2.2", "", {}, "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg=="], "@isaacs/cliui/strip-ansi/ansi-regex": ["ansi-regex@6.2.2", "", {}, "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg=="], diff --git a/packages/agent/src/activities/agent.ts b/packages/agent/src/activities/agent.ts index 90d7d3dd..9b3ba599 100644 --- a/packages/agent/src/activities/agent.ts +++ b/packages/agent/src/activities/agent.ts @@ -866,12 +866,6 @@ export async function executeAgentToolActivity(params: ExecuteAgentToolParams): creatorId: userId, }) - // Increment fileCount of parent folder - await prisma.asset.update({ - where: { id: parent }, - data: { fileCount: { increment: 1 } }, - }) - return { id: newFolder.id, name: newFolder.name, @@ -930,12 +924,8 @@ export async function executeAgentToolActivity(params: ExecuteAgentToolParams): creatorId: userId, }) - // Increment fileCount of parent and update ancestor size + // Increment update ancestor size await prisma.$transaction(async (tx) => { - await tx.asset.update({ - where: { id: parent }, - data: { fileCount: { increment: 1 } }, - }) // eslint-disable-next-line @typescript-eslint/no-explicit-any await assetService.updateAncestorsSize(tx as any, parent, fileSize) @@ -1026,11 +1016,10 @@ export async function executeAgentToolActivity(params: ExecuteAgentToolParams): where: { id: newFile.id }, data: { sortIndex: newSortIndex }, }) - // Increment stack's fileCount and size + // Increment stack's size (fileCount is incremented by createAsset already) const updatedStack = await tx.asset.update({ where: { id: stackId }, data: { - fileCount: { increment: 1 }, sizeByte: { increment: fileSize }, }, }) diff --git a/packages/api/src/api/s3.test.ts b/packages/api/src/api/s3.test.ts index 6b320b9c..9a89d76f 100644 --- a/packages/api/src/api/s3.test.ts +++ b/packages/api/src/api/s3.test.ts @@ -1,5 +1,4 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import { s3Service } from '@shumai/core/src/s3/s3' import { Hono } from 'hono' const { mockServeStatic } = vi.hoisted(() => ({ @@ -14,6 +13,7 @@ vi.mock('hono/bun', () => ({ describe('S3 API', () => { beforeEach(() => { vi.clearAllMocks() + vi.resetModules() }) it('GET /files/* calls serveStatic with correct options', async () => { @@ -39,10 +39,49 @@ describe('S3 API', () => { } }) + it('GET /files/* with filename query parameter sets Content-Disposition header', async () => { + // We need to capture the onFound callback from serveStatic options + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let onFoundCallback: ((path: string, c: any) => void) | undefined + // eslint-disable-next-line @typescript-eslint/no-explicit-any + mockServeStatic.mockImplementationOnce((options: any) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + onFoundCallback = (options as any).onFound + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (c: any) => c.text('static-file') + }) + + const { default: route } = await import('./s3') + const app = new Hono().route('/files', route) + + // First, verify onFound is called through the mock + await app.request('/files/b1/test.webp?filename=my-file.txt') + + expect(onFoundCallback).toBeDefined() + + // Test the callback directly + const mockContext = { + req: { + query: (key: string) => (key === 'filename' ? 'my-file.txt' : undefined), + }, + header: vi.fn(), + } + + if (onFoundCallback) { + onFoundCallback('/files/b1/test.webp', mockContext) + expect(mockContext.header).toHaveBeenCalledWith( + 'Content-Disposition', + 'attachment; filename="my-file.txt"', + ) + } + }) + it('PUT /files/:bucket/:key calls s3Service.putObject', async () => { + const { s3Service: service } = await import('@shumai/core/src/s3/s3') + const mockPut = vi.spyOn(service, 'putObject').mockResolvedValue(undefined) + const { default: route } = await import('./s3') const app = new Hono().route('/files', route) - const mockPut = vi.spyOn(s3Service, 'putObject').mockResolvedValue(undefined) const body = new TextEncoder().encode('test-data') const res = await app.request('/files/b1/test.webp', { diff --git a/packages/api/src/api/s3.ts b/packages/api/src/api/s3.ts index 2976d7b2..80055908 100644 --- a/packages/api/src/api/s3.ts +++ b/packages/api/src/api/s3.ts @@ -8,6 +8,13 @@ const route = new Hono() serveStatic({ root: './data', rewriteRequestPath: (path) => path.replace(/^\/files\//, ''), + onFound: (_path, c) => { + const filename = c.req.query('filename') + if (filename) { + const safeFilename = filename.replace(/["\r\n]/g, '_') + c.header('Content-Disposition', `attachment; filename="${safeFilename}"`) + } + }, }), ) .put('/:bucket/:key{.+}', async (c) => { diff --git a/packages/api/src/api/team.test.ts b/packages/api/src/api/team.test.ts index 422ca9ad..842c72fa 100644 --- a/packages/api/src/api/team.test.ts +++ b/packages/api/src/api/team.test.ts @@ -175,7 +175,11 @@ describe('team api', () => { permission: Permission.Read, }), ) - expect(mockGetTeamMembers).toHaveBeenCalledWith({ teamId: 't1', includeAgents: false }) + expect(mockGetTeamMembers).toHaveBeenCalledWith({ + teamId: 't1', + userId: 'user1', + includeAgents: false, + }) }) it('GET /teams/:teamId/settings returns settings', async () => { diff --git a/packages/api/src/api/team.ts b/packages/api/src/api/team.ts index c3009f7e..ac143429 100644 --- a/packages/api/src/api/team.ts +++ b/packages/api/src/api/team.ts @@ -108,6 +108,7 @@ const route = new Hono<{ Variables: { user: User } }>() const members = await teamService.getTeamMembers({ teamId, + userId: user.id, includeAgents: includeAgents, }) diff --git a/packages/core/package.json b/packages/core/package.json index 718538ad..b439d7c7 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -8,8 +8,6 @@ "dependencies": { "@shumai/db": "workspace:*", "@shumai/dtos": "workspace:*", - "@aws-sdk/client-s3": "^3.1031.0", - "@aws-sdk/s3-request-presigner": "^3.1031.0", "@sinclair/typebox": "^0.34.49", "adm-zip": "^0.5.17", "better-auth": "1.6.11", diff --git a/packages/core/src/asset/asset.test.ts b/packages/core/src/asset/asset.test.ts index 9bb17e54..75e977d4 100644 --- a/packages/core/src/asset/asset.test.ts +++ b/packages/core/src/asset/asset.test.ts @@ -559,6 +559,63 @@ describe('AssetService', () => { }) }) + describe('fileCount verification', () => { + it('createAsset should increment parent fileCount', async () => { + const { user, assets, project } = await setupBasicAssets() + + const parent = assets.folderA + const initialCount = parent.fileCount // should be 2 from setup (fileA1, fileA2) + + // Create a new folder inside folderA + await assetService.createAsset({ + name: 'newFolder', + type: 'folder', + parentId: parent.id, + projectId: project.id, + creatorId: user.id, + }) + + const updatedParent = await prisma.asset.findUnique({ where: { id: parent.id } }) + expect(updatedParent?.fileCount).toBe(initialCount + 1) + + // Create a new file inside folderA + await assetService.createAsset({ + name: 'newFile', + type: 'file', + parentId: parent.id, + projectId: project.id, + creatorId: user.id, + }) + + const updatedParent2 = await prisma.asset.findUnique({ where: { id: parent.id } }) + expect(updatedParent2?.fileCount).toBe(initialCount + 2) + }) + + it('reparentAssets should update fileCount when moving folders', async () => { + const { user, assets } = await setupBasicAssets() + + const sourceParent = assets.root + const targetParent = assets.folderB + const folderToMove = assets.folderA + + // folderA is a child of root. + // root children: folderA, folderB, fileRoot1. count=3. + // folderB children: stackB, fileB2. count=2. + + await assetService.reparentAssets({ + assetIds: [folderToMove.id], + newParentId: targetParent.id, + creatorId: user.id, + }) + + const updatedSourceParent = await prisma.asset.findUnique({ where: { id: sourceParent.id } }) + expect(updatedSourceParent?.fileCount).toBe(2) + + const updatedTargetParent = await prisma.asset.findUnique({ where: { id: targetParent.id } }) + expect(updatedTargetParent?.fileCount).toBe(3) + }) + }) + it('handles reparenting - Version Stack: dissolve with 1 remaining', async () => { const { user, assets } = await setupBasicAssets() await assetService.reparentAssets({ diff --git a/packages/core/src/asset/asset.ts b/packages/core/src/asset/asset.ts index 4cb8b4bd..b28b50a6 100644 --- a/packages/core/src/asset/asset.ts +++ b/packages/core/src/asset/asset.ts @@ -172,8 +172,8 @@ export class AssetService { } } - async reparentAssets(req: ReparentAssetsRequest): Promise { - await this.prismaClient.$transaction(async (tx) => { + async reparentAssets(req: ReparentAssetsRequest, tx?: Prisma.TransactionClient): Promise { + const runInTx = async (tx: Prisma.TransactionClient) => { const newParent = await tx.asset.findUnique({ where: { id: req.newParentId }, include: { project: { include: { team: true } } }, @@ -269,7 +269,13 @@ export class AssetService { if (oldParent) { await this.dissolveStackIfEmpty(tx, oldParent) } - }) + } + + if (tx) { + await runInTx(tx) + } else { + await this.prismaClient.$transaction(runInTx) + } } async copyAssets(req: CopyAssetsRequest): Promise { @@ -722,30 +728,41 @@ export class AssetService { if (req.contentType) data.mediaType = req.contentType if (req.creatorId) data.creator = { connect: { id: req.creatorId } } - const asset = await this.prismaClient.asset.create({ - data, - include: { - creator: true, - metadataValues: true, - storageKey: true, - target: { - include: { - creator: true, - metadataValues: true, - storageKey: true, - children: { - include: { creator: true, metadataValues: true, storageKey: true }, - take: 3, - orderBy: { sortIndex: 'asc' }, + const asset = await this.prismaClient.$transaction(async (tx) => { + const createdAsset = await tx.asset.create({ + data, + include: { + creator: true, + metadataValues: true, + storageKey: true, + target: { + include: { + creator: true, + metadataValues: true, + storageKey: true, + children: { + include: { creator: true, metadataValues: true, storageKey: true }, + take: 3, + orderBy: { sortIndex: 'asc' }, + }, }, }, + children: { + include: { creator: true, metadataValues: true, storageKey: true }, + take: 3, + orderBy: { sortIndex: 'asc' }, + }, }, - children: { - include: { creator: true, metadataValues: true, storageKey: true }, - take: 3, - orderBy: { sortIndex: 'asc' }, - }, - }, + }) + + if (parent) { + await tx.asset.update({ + where: { id: parent.id }, + data: { fileCount: { increment: 1 } }, + }) + } + + return createdAsset }) const infos = await this.toAssetInfos([asset]) @@ -824,6 +841,7 @@ export class AssetService { process.env.S3_BUCKET || 'shumai', info.media.original.key, 'GET', + a.name, ) } } @@ -1548,9 +1566,18 @@ export class AssetService { const key = latestVersion.storageKey?.key if (media && key) { + const fileName = + a.type === AssetType.version_stack && (a.name === '' || !a.name) + ? latestVersion.name + : a.name media.original = { key, - downloadUrl: await s3Service.presign(process.env.S3_BUCKET || 'shumai', key, 'GET'), + downloadUrl: await s3Service.presign( + process.env.S3_BUCKET || 'shumai', + key, + 'GET', + fileName, + ), filesizeInBytes: latestVersion.sizeByte, codec: '', // TODO: extract from metadata if needed } diff --git a/packages/core/src/project/project.ts b/packages/core/src/project/project.ts index 3359fe2b..c840e444 100644 --- a/packages/core/src/project/project.ts +++ b/packages/core/src/project/project.ts @@ -225,6 +225,7 @@ export class ProjectService { name: pm.teamMember.user.name, role: pm.role, image: await getAvatarUrl(pm.teamMember.user.image), + scope: pm.teamMember.scope, })), ) } diff --git a/packages/core/src/s3/s3.test.ts b/packages/core/src/s3/s3.test.ts index e10354cf..5d1255df 100644 --- a/packages/core/src/s3/s3.test.ts +++ b/packages/core/src/s3/s3.test.ts @@ -3,36 +3,41 @@ import * as fs from 'fs' import * as path from 'path' import { LocalStorageService, S3StorageService } from './s3' -// Mock the AWS SDK +// Mock Bun S3Client const s3ClientConstructorSpy = vi.fn() -vi.mock('@aws-sdk/client-s3', () => { +const s3FileSpy = vi.fn() +const s3WriteSpy = vi.fn() +const s3DeleteSpy = vi.fn() +const s3ListSpy = vi.fn() +const s3ExistsSpy = vi.fn() +const s3PresignSpy = vi.fn() + +vi.mock('bun', () => { return { S3Client: class { constructor(params: unknown) { s3ClientConstructorSpy(params) } - send = vi.fn().mockResolvedValue({}) + file = s3FileSpy.mockReturnValue({ + size: Promise.resolve(123), + exists: vi.fn().mockResolvedValue(true), + arrayBuffer: vi.fn().mockResolvedValue(new ArrayBuffer(10)), + type: 'text/plain', + }) + write = s3WriteSpy.mockResolvedValue({}) + delete = s3DeleteSpy.mockResolvedValue({}) + list = s3ListSpy.mockResolvedValue({ contents: [], isTruncated: false }) + exists = s3ExistsSpy.mockResolvedValue(true) + presign = s3PresignSpy.mockReturnValue('http://presigned-url') }, - HeadObjectCommand: class {}, - PutObjectCommand: class {}, - GetObjectCommand: class {}, - ListObjectsV2Command: class {}, - } -}) - -vi.mock('@aws-sdk/s3-request-presigner', () => { - return { - getSignedUrl: vi.fn().mockResolvedValue('http://presigned-url'), } }) describe('S3Service implementations', () => { beforeEach(async () => { - const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner') - vi.mocked(getSignedUrl).mockReset() - vi.mocked(getSignedUrl).mockResolvedValue('http://presigned-url') vi.clearAllMocks() delete process.env.PRESIGNED_URL_EXPIRES_IN + s3PresignSpy.mockReturnValue('http://presigned-url') }) describe('S3StorageService', () => { @@ -64,56 +69,65 @@ describe('S3Service implementations', () => { const s3 = new S3StorageService('localhost:9000', 'key', 'secret', 'test-bucket', false) const url = await s3.presign('bucket', 'key', 'GET') expect(url).toBe('http://presigned-url') + expect(s3PresignSpy).toHaveBeenCalledWith('key', expect.objectContaining({ method: 'GET' })) }) it('should cache GET presign URLs', async () => { const s3 = new S3StorageService('localhost:9000', 'key', 'secret', 'test-bucket', false) - const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner') - vi.mocked(getSignedUrl).mockClear() - vi.mocked(getSignedUrl).mockResolvedValueOnce('http://presigned-url-1') - vi.mocked(getSignedUrl).mockResolvedValueOnce('http://presigned-url-2') + s3PresignSpy.mockClear() + s3PresignSpy.mockReturnValueOnce('http://presigned-url-1') + s3PresignSpy.mockReturnValueOnce('http://presigned-url-2') const url1 = await s3.presign('bucket', 'key', 'GET') const url2 = await s3.presign('bucket', 'key', 'GET') expect(url1).toBe('http://presigned-url-1') expect(url2).toBe('http://presigned-url-1') - expect(vi.mocked(getSignedUrl)).toHaveBeenCalledTimes(1) + expect(s3PresignSpy).toHaveBeenCalledTimes(1) }) it('should NOT cache PUT presign URLs', async () => { const s3 = new S3StorageService('localhost:9000', 'key', 'secret', 'test-bucket', false) - const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner') - vi.mocked(getSignedUrl).mockClear() - vi.mocked(getSignedUrl).mockResolvedValueOnce('http://put-url-1') - vi.mocked(getSignedUrl).mockResolvedValueOnce('http://put-url-2') + s3PresignSpy.mockReset() + s3PresignSpy.mockReturnValueOnce('http://unique-put-url-1') + s3PresignSpy.mockReturnValueOnce('http://unique-put-url-2') const url1 = await s3.presign('bucket', 'key', 'PUT') const url2 = await s3.presign('bucket', 'key', 'PUT') - expect(url1).toBe('http://put-url-1') - expect(url2).toBe('http://put-url-2') - expect(vi.mocked(getSignedUrl)).toHaveBeenCalledTimes(2) + expect(url1).toBe('http://unique-put-url-1') + expect(url2).toBe('http://unique-put-url-2') + expect(s3PresignSpy).toHaveBeenCalledTimes(2) }) it('should respect PRESIGNED_URL_EXPIRES_IN env', async () => { process.env.PRESIGNED_URL_EXPIRES_IN = '10' const s3 = new S3StorageService('localhost:9000', 'key', 'secret', 'test-bucket', false) - const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner') - vi.mocked(getSignedUrl).mockClear() + s3PresignSpy.mockClear() await s3.presign('bucket', 'key', 'GET') - expect(vi.mocked(getSignedUrl)).toHaveBeenCalledWith( - expect.anything(), - expect.anything(), + expect(s3PresignSpy).toHaveBeenCalledWith( + 'key', expect.objectContaining({ expiresIn: 10 * 3600 }), ) delete process.env.PRESIGNED_URL_EXPIRES_IN }) + + it('should pass filename to presign', async () => { + const s3 = new S3StorageService('localhost:9000', 'key', 'secret', 'test-bucket', false) + await s3.presign('bucket', 'key', 'GET', 'test.txt') + + expect(s3PresignSpy).toHaveBeenCalledWith( + 'key', + expect.objectContaining({ + contentDisposition: 'attachment; filename="test.txt"', + }), + ) + }) }) describe('LocalStorageService', () => { @@ -168,6 +182,11 @@ describe('S3Service implementations', () => { expect(url).toBe('http://localhost:3000/files/my-bucket/dir/file.txt') }) + it('should generate a local presign URL with filename', async () => { + const url = await localS3.presign('my-bucket', 'dir/file.txt', 'GET', 'original.txt') + expect(url).toBe('http://localhost:3000/files/my-bucket/dir/file.txt?filename=original.txt') + }) + it('should throw an error for unsupported presign methods', async () => { await expect(localS3.presign('b', 'k', 'POST')).rejects.toThrow() }) diff --git a/packages/core/src/s3/s3.ts b/packages/core/src/s3/s3.ts index 0b57ff69..993bcfd2 100644 --- a/packages/core/src/s3/s3.ts +++ b/packages/core/src/s3/s3.ts @@ -1,17 +1,7 @@ import { ObjectInfo } from '@shumai/dtos' -import { - CopyObjectCommand, - DeleteObjectCommand, - GetObjectCommand, - HeadObjectCommand, - ListObjectsV2Command, - PutObjectCommand, - S3Client, -} from '@aws-sdk/client-s3' -import { getSignedUrl } from '@aws-sdk/s3-request-presigner' +import { S3Client } from 'bun' import * as crypto from 'crypto' import * as fs from 'fs' -import { readFileSync, statSync } from 'fs' import * as path from 'path' import { ulid } from 'ulid' import { LruTtlCache } from '../cache/lru-ttl-cache' @@ -64,7 +54,7 @@ export interface S3Service { listObjects(bucket: string, prefix: string): Promise uploadFile(filePath: string, contentType: string): Promise uploadFileToKey(filePath: string, key: string, contentType: string): Promise - presign(bucket: string, key: string, method: string): Promise + presign(bucket: string, key: string, method: string, filename?: string): Promise } export class S3StorageService implements S3Service { @@ -89,54 +79,36 @@ export class S3StorageService implements S3Service { this.client = new S3Client({ region, endpoint: fullEndpoint, - credentials: { - accessKeyId, - secretAccessKey, - }, - forcePathStyle: false, + accessKeyId, + secretAccessKey, + bucket, }) this.bucket = bucket } async getObjectSize(bucket: string, key: string): Promise { - const command = new HeadObjectCommand({ - Bucket: bucket, - Key: key, - }) - const response = await this.client.send(command) - return response.ContentLength || 0 + return await this.client.size(key, { bucket }) } async putObject( bucket: string, key: string, body: Buffer | Uint8Array | string, - size: number, + _size: number, contentType?: string, ): Promise { - const command = new PutObjectCommand({ - Bucket: bucket, - Key: key, - Body: body, - ContentLength: size, - ContentType: contentType, + await this.client.write(key, body, { + bucket, + type: contentType, }) - await this.client.send(command) } async getObject(bucket: string, key: string): Promise { - const command = new GetObjectCommand({ - Bucket: bucket, - Key: key, - }) - const response = await this.client.send(command) - if (!response.Body) { - throw new Error('Empty response body') - } - const byteArray = await response.Body.transformToByteArray() + const file = this.client.file(key, { bucket }) + const arrayBuffer = await file.arrayBuffer() return { - buffer: Buffer.from(byteArray), - contentType: response.ContentType || 'application/octet-stream', + buffer: Buffer.from(arrayBuffer), + contentType: file.type || 'application/octet-stream', } } @@ -146,54 +118,22 @@ export class S3StorageService implements S3Service { destBucket: string, destKey: string, ): Promise { - const command = new CopyObjectCommand({ - Bucket: destBucket, - Key: destKey, - // eslint-disable-next-line @typescript-eslint/naming-convention - CopySource: `${sourceBucket}/${sourceKey}`, - }) - await this.client.send(command) + const sourceFile = this.client.file(sourceKey, { bucket: sourceBucket }) + await this.client.write(destKey, sourceFile, { bucket: destBucket }) } async downloadToFile(bucket: string, key: string, filePath: string): Promise { - const command = new GetObjectCommand({ - Bucket: bucket, - Key: key, - }) - const response = await this.client.send(command) - if (!response.Body) { - throw new Error('Empty response body') - } - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const stream = response.Body as any - const writeStream = fs.createWriteStream(filePath) - - await new Promise((resolve, reject) => { - stream - .pipe(writeStream) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - .on('error', (err: any) => { - writeStream.close() - reject(err) - }) - .on('finish', () => { - writeStream.close() - resolve(null) - }) - }) + const file = this.client.file(key, { bucket }) + await Bun.write(filePath, file) } async deleteObject(bucket: string, key: string): Promise { - const command = new DeleteObjectCommand({ - Bucket: bucket, - Key: key, - }) try { - await this.client.send(command) + const exists = await this.client.exists(key, { bucket }) + if (!exists) return 0 + await this.client.delete(key, { bucket }) return 1 } catch { - // If object doesn't exist, we return 0 return 0 } } @@ -207,17 +147,20 @@ export class S3StorageService implements S3Service { } async headObject(bucket: string, key: string): Promise { - const command = new HeadObjectCommand({ - Bucket: bucket, - Key: key, - }) - const response = await this.client.send(command) + const file = this.client.file(key, { bucket }) + const exists = await file.exists() + if (!exists) { + throw new Error(`NoSuchKey: The specified key does not exist.`) + } + + // Bun.S3File doesn't expose lastModified or eTag directly in a way that matches ObjectInfo easily + // but we can try to get them if available. For now, using defaults for fields not provided. return { key, - size: response.ContentLength || 0, - lastModified: response.LastModified || new Date(), - contentType: response.ContentType || 'application/octet-stream', - eTag: response.ETag || '', + size: await file.size, + lastModified: new Date(), // Bun doesn't expose this yet via S3File + contentType: file.type || 'application/octet-stream', + eTag: '', } } @@ -227,23 +170,21 @@ export class S3StorageService implements S3Service { let continuationToken: string | undefined = undefined while (isTruncated) { - const command: ListObjectsV2Command = new ListObjectsV2Command({ - Bucket: bucket, - Prefix: prefix, - ContinuationToken: continuationToken, + const response = await this.client.list({ + prefix, + continuationToken, }) - const response = await this.client.send(command) - if (response.Contents) { - for (const item of response.Contents) { - if (item.Key) { - keys.push(item.Key) + if (response.contents) { + for (const item of response.contents) { + if (item.key) { + keys.push(item.key) } } } - isTruncated = response.IsTruncated || false - continuationToken = response.NextContinuationToken + isTruncated = response.isTruncated || false + continuationToken = response.nextContinuationToken } return keys @@ -256,50 +197,39 @@ export class S3StorageService implements S3Service { } async uploadFileToKey(filePath: string, key: string, contentType: string): Promise { - const fileStats = statSync(filePath) - const fileContent = readFileSync(filePath) - - const command = new PutObjectCommand({ - Bucket: this.bucket, - Key: key, - Body: fileContent, - ContentLength: fileStats.size, - ContentType: contentType, + await this.client.write(key, Bun.file(filePath), { + bucket: this.bucket, + type: contentType, }) - - await this.client.send(command) } - async presign(bucket: string, key: string, method: string): Promise { + async presign(bucket: string, key: string, method: string, filename?: string): Promise { const expireHours = parseInt(process.env.PRESIGNED_URL_EXPIRES_IN || '5', 10) const expiresInSeconds = expireHours * 3600 // Cache time is 2/3 of expire time, rounded to minute const cacheMinutes = Math.round((expireHours * 60 * 2) / 3) const cacheTtlMs = cacheMinutes * 60 * 1000 - const cacheKey = `${bucket}:${key}` + const cacheKey = `${bucket}:${key}:${filename || ''}` if (method === 'GET') { const cached = this.presignCache.get(cacheKey) if (cached) return cached } - let command: GetObjectCommand | PutObjectCommand - if (method === 'GET') { - command = new GetObjectCommand({ - Bucket: bucket, - Key: key, - }) - } else if (method === 'PUT') { - command = new PutObjectCommand({ - Bucket: bucket, - Key: key, - }) - } else { - throw new Error(`Invalid method: ${method}`) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const options: any = { + bucket, + expiresIn: expiresInSeconds, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + method: method as any, } - const url = await getSignedUrl(this.client, command, { expiresIn: expiresInSeconds }) + if (filename) { + options.contentDisposition = `attachment; filename="${filename}"` + } + + const url = this.client.presign(key, options) if (method === 'GET') { this.presignCache.set(cacheKey, url, cacheTtlMs) @@ -505,14 +435,18 @@ export class LocalStorageService implements S3Service { await fs.promises.copyFile(filePath, destPath) } - async presign(bucket: string, key: string, method: string): Promise { + async presign(bucket: string, key: string, method: string, filename?: string): Promise { if (method !== 'GET' && method !== 'PUT') { throw new Error(`Invalid method: ${method}`) } if (method === 'PUT') { return `${this.endpoint}${signLocalUrl(bucket, key)}` } - return `${this.endpoint}/files/${bucket}/${key}` + let url = `${this.endpoint}/files/${bucket}/${key}` + if (filename) { + url += `?filename=${encodeURIComponent(filename)}` + } + return url } } diff --git a/packages/core/src/team/team.test.ts b/packages/core/src/team/team.test.ts index 3f29e89c..a6e89535 100644 --- a/packages/core/src/team/team.test.ts +++ b/packages/core/src/team/team.test.ts @@ -127,6 +127,7 @@ describe('TeamService', () => { const members = await teamService.getTeamMembers({ teamId: team.id, + userId: user1.id, }) expect(members).toHaveLength(2) @@ -169,6 +170,7 @@ describe('TeamService', () => { // Should hide bots by default const members = await teamService.getTeamMembers({ teamId: team.id, + userId: user.id, }) expect(members).toHaveLength(1) expect(members[0].id).toBe(user.id) @@ -176,11 +178,73 @@ describe('TeamService', () => { // Should include bots if requested const allMembers = await teamService.getTeamMembers({ teamId: team.id, + userId: user.id, includeAgents: true, }) expect(allMembers).toHaveLength(2) }) + it('should filter members for project-scoped members', async () => { + const owner = await prisma.user.create({ + data: { name: 'Owner', email: `owner-${Date.now()}@example.com`, password: 'pw' }, + }) + const team = await teamService.createTeam(owner, { name: 'Test Team' }) + + const teamMember = await prisma.user.create({ + data: { name: 'Team Member', email: `tm-${Date.now()}@example.com`, password: 'pw' }, + }) + await teamService.joinTeam({ teamId: team.id, userId: teamMember.id }) + + const projectMember1 = await prisma.user.create({ + data: { name: 'Proj Member 1', email: `pm1-${Date.now()}@example.com`, password: 'pw' }, + }) + const tm1 = await prisma.teamMember.create({ + data: { teamId: team.id, userId: projectMember1.id, scope: 'project', role: 'editor' }, + }) + + const projectMember2 = await prisma.user.create({ + data: { name: 'Proj Member 2', email: `pm2-${Date.now()}@example.com`, password: 'pw' }, + }) + const tm2 = await prisma.teamMember.create({ + data: { teamId: team.id, userId: projectMember2.id, scope: 'project', role: 'editor' }, + }) + + const project = await prisma.project.create({ + data: { name: 'Shared Project', teamId: team.id }, + }) + + await prisma.projectMember.createMany({ + data: [ + { projectId: project.id, teamMemberId: tm1.id, role: 'editor' }, + { projectId: project.id, teamMemberId: tm2.id, role: 'editor' }, + ], + }) + + const projectMember3 = await prisma.user.create({ + data: { name: 'Proj Member 3', email: `pm3-${Date.now()}@example.com`, password: 'pw' }, + }) + await prisma.teamMember.create({ + data: { teamId: team.id, userId: projectMember3.id, scope: 'project', role: 'editor' }, + }) + + // Owner (team scope) should see everyone (4 users) + const ownerView = await teamService.getTeamMembers({ teamId: team.id, userId: owner.id }) + expect(ownerView).toHaveLength(5) // Owner, Team Member, PM1, PM2, PM3 + + // PM1 (project scope) should see: Owner, Team Member, PM2 (shares project), but NOT PM3 + const pm1View = await teamService.getTeamMembers({ teamId: team.id, userId: projectMember1.id }) + const pm1ViewIds = pm1View.map((m) => m.id) + expect(pm1View).toHaveLength(4) + expect(pm1ViewIds).toContain(owner.id) + expect(pm1ViewIds).toContain(teamMember.id) + expect(pm1ViewIds).toContain(projectMember2.id) + expect(pm1ViewIds).not.toContain(projectMember3.id) + + // Check scopes are returned + expect(pm1View.find((m) => m.id === owner.id)?.scope).toBe('team') + expect(pm1View.find((m) => m.id === projectMember2.id)?.scope).toBe('project') + }) + it('should get and update settings', async () => { const user = await prisma.user.create({ data: { name: 'Test User', email: `test-${Date.now()}@example.com`, password: 'pw' }, diff --git a/packages/core/src/team/team.ts b/packages/core/src/team/team.ts index 0b761f4e..f3edd6f9 100644 --- a/packages/core/src/team/team.ts +++ b/packages/core/src/team/team.ts @@ -174,6 +174,19 @@ export class TeamService { } async getTeamMembers(req: ServiceGetTeamMembersRequest): Promise { + const requester = await prisma.teamMember.findUnique({ + where: { + teamIdUserId: { + teamId: req.teamId, + userId: req.userId, + }, + }, + }) + + if (!requester) { + throw new HTTPException(403, { message: 'Requester is not a team member' }) + } + const members = await prisma.teamMember.findMany({ where: { teamId: req.teamId, @@ -194,17 +207,39 @@ export class TeamService { } : { user: { type: { not: 'agent' } } }), }, - include: { user: true }, + include: { + user: true, + projectMembers: true, + }, }) + let filteredMembers = members + + if (requester.scope === 'project') { + const requesterProjectIds = await prisma.projectMember + .findMany({ + where: { teamMemberId: requester.id }, + select: { projectId: true }, + }) + .then((pms) => pms.map((pm) => pm.projectId)) + + filteredMembers = members.filter((m) => { + // Team-scoped members are always visible + if (m.scope === 'team') return true + // Project-scoped members are visible if they share a project + return m.projectMembers.some((pm) => requesterProjectIds.includes(pm.projectId)) + }) + } + return Promise.all( - members.map(async (m) => ({ + filteredMembers.map(async (m) => ({ id: m.user.id, name: m.user.name, email: undefined, role: m.role, type: m.user.type || undefined, image: await getAvatarUrl(m.user.image), + scope: m.scope, })), ) } diff --git a/packages/core/src/upload/upload.test.ts b/packages/core/src/upload/upload.test.ts index 7730e4ca..4fbece50 100644 --- a/packages/core/src/upload/upload.test.ts +++ b/packages/core/src/upload/upload.test.ts @@ -93,6 +93,67 @@ describe('UploadService', () => { expect(hidden).toBeNull() }) + it('should correctly increment fileCount for parent folders when uploading folders', async () => { + const req = { + parentId: parentId, + files: [ + { + name: 'folder1', + id: '1', + type: 'folder' as const, + size: 0, + children: [ + { + name: 'folder2', + id: '2', + type: 'folder' as const, + size: 0, + children: [], + }, + { + name: 'file1.txt', + id: '3', + type: 'file' as const, + size: 100, + mediaType: 'text/plain', + children: [], + }, + ], + }, + ], + } + + await uploadService.createUploadTask(userId, req) + + // parentId folder should have folder1 as a direct child + const parent = await prisma.asset.findUnique({ where: { id: parentId } }) + expect(parent?.fileCount).toBe(1) + + // folder1 should have folder2 and file1.txt as direct children + // folder2 is a folder, so it is counted immediately. + // file1.txt is a file, so it is counted after confirmFileUpload. + const folder1 = await prisma.asset.findFirst({ where: { name: 'folder1' } }) + expect(folder1?.parentId).toBe(parentId) + expect(folder1?.fileCount).toBe(1) + + const folder2 = await prisma.asset.findFirst({ where: { name: 'folder2' } }) + expect(folder2?.parentId).toBe(folder1?.id) + expect(folder2?.fileCount).toBe(0) + + const file1 = await prisma.asset.findFirst({ where: { name: 'file1.txt' } }) + expect(file1?.parentId).toBe(folder1?.id) + expect(file1?.status).toBe(AssetStatus.uploading) + + // Confirm upload for file1.txt + const task = await prisma.task.findFirst({ where: { total: 1 } }) + await uploadService.confirmFileUpload(userId, task!.id, { + fileId: file1!.id, + }) + + const folder1After = await prisma.asset.findUnique({ where: { id: folder1!.id } }) + expect(folder1After?.fileCount).toBe(2) + }) + it('should confirm file upload and create transcode tasks for video', async () => { const task = await prisma.task.create({ data: { creatorId: userId, total: 1, uploaded: 0, type: 'upload' }, diff --git a/packages/core/src/upload/upload.ts b/packages/core/src/upload/upload.ts index 313b37f2..bbcc08ff 100644 --- a/packages/core/src/upload/upload.ts +++ b/packages/core/src/upload/upload.ts @@ -1,8 +1,15 @@ -import { prisma } from '@shumai/db' -import { ulid } from 'ulid' -import { generateKeyBetween } from 'jittered-fractional-indexing' -import { s3Service } from '@shumai/core/src/s3/s3' import { assetService } from '@shumai/core/src/asset/asset' +import { PaginatedData, PaginationParams, paginateQuery } from '@shumai/core/src/pagination' +import { s3Service } from '@shumai/core/src/s3/s3' +import { + AssetStatus, + AssetType, + Prisma, + TaskStatus, + WorkflowTaskStatus, + WorkflowTaskType, + prisma, +} from '@shumai/db' import { ConfirmFileUploadRequest, CreateUploadTaskRequest, @@ -11,16 +18,9 @@ import { PresignedUrl, TaskInfo, } from '@shumai/dtos' -import { - AssetStatus, - AssetType, - Prisma, - TaskStatus, - WorkflowTaskStatus, - WorkflowTaskType, -} from '@shumai/db' -import { PaginationParams, paginateQuery, PaginatedData } from '@shumai/core/src/pagination' -import { VideoTranscoder, ImageTranscoder } from '@shumai/transcode' +import { ImageTranscoder, VideoTranscoder } from '@shumai/transcode' +import { generateKeyBetween } from 'jittered-fractional-indexing' +import { ulid } from 'ulid' export class UploadService { constructor(private readonly prismaClient: typeof prisma = prisma) {} @@ -67,24 +67,32 @@ export class UploadService { const isParentFile = parentAsset.type === AssetType.file const targetParentId = isParentFile ? parentAsset.parentId! : parentAsset.id - const createdAssetIds = await this.createAssetsRecursively( - userId, - task.id, - parentAsset.projectId, - targetParentId, - req.files, - presignedUrls, - ) + await this.prismaClient.$transaction(async (tx) => { + const ids = await this.createAssetsRecursively( + tx, + userId, + task.id, + parentAsset.projectId!, + targetParentId, + req.files, + presignedUrls, + ) - if (isParentFile && createdAssetIds.length > 0) { - for (const assetId of createdAssetIds) { - await assetService.reparentAssets({ - assetIds: [assetId], - newParentId: parentAsset.id, - creatorId: userId, - }) + if (isParentFile && ids.length > 0) { + for (const assetId of ids) { + await assetService.reparentAssets( + { + assetIds: [assetId], + newParentId: parentAsset.id, + creatorId: userId, + }, + tx, + ) + } } - } + + return ids + }) return { taskId: task.id, @@ -93,6 +101,7 @@ export class UploadService { } private async createAssetsRecursively( + tx: Prisma.TransactionClient, userId: string, taskId: string, projectId: string, @@ -100,7 +109,7 @@ export class UploadService { files: FileNode[], presignedUrls: PresignedUrl[], ): Promise { - const firstFile = await this.prismaClient.asset.findFirst({ + const firstFile = await tx.asset.findFirst({ where: { parentId }, orderBy: { sortIndex: 'asc' }, }) @@ -119,14 +128,14 @@ export class UploadService { key = `files/${ulid()}/raw` } - const newAsset = await this.prismaClient.asset.create({ + const newAsset = await tx.asset.create({ data: { name: file.name, type: assetType, storageKey: key ? { create: { key } } : undefined, sortIndex: newSortIndex, mediaType: file.mediaType, - status: AssetStatus.uploading, + status: assetType === AssetType.folder ? AssetStatus.uploaded : AssetStatus.uploading, sizeByte: file.size, creator: userId ? { connect: { id: userId } } : undefined, parent: parentId ? { connect: { id: parentId } } : undefined, @@ -136,8 +145,16 @@ export class UploadService { }) createdIds.push(newAsset.id) + if (assetType === AssetType.folder && parentId) { + await tx.asset.update({ + where: { id: parentId }, + data: { fileCount: { increment: 1 } }, + }) + } + if (file.children && file.children.length > 0) { await this.createAssetsRecursively( + tx, userId, taskId, projectId, @@ -212,9 +229,8 @@ export class UploadService { where: { id: asset.parentId }, data: { fileCount: { increment: 1 } }, }) - // The transaction context is compatible with the asset service's requirements - // eslint-disable-next-line @typescript-eslint/no-explicit-any - await assetService.updateAncestorsSize(tx as any, asset.parentId, updatedAsset.sizeByte) + + await assetService.updateAncestorsSize(tx, asset.parentId, updatedAsset.sizeByte) } // Update task diff --git a/packages/dtos/src/project.ts b/packages/dtos/src/project.ts index 088c9a51..2df3c210 100644 --- a/packages/dtos/src/project.ts +++ b/packages/dtos/src/project.ts @@ -46,8 +46,9 @@ export type GetProjectTeamResponse = z.infer @@ -96,7 +97,7 @@ export interface ServiceListProjectsRequest { export interface ServiceAddProjectMemberRequest { projectId: string userId: string - role: string + role: 'owner' | 'editor' | 'reviewer' | 'bot' | 'unknown' } export interface ServiceListProjectMembersRequest { diff --git a/packages/dtos/src/team.ts b/packages/dtos/src/team.ts index e0099286..e4b53310 100644 --- a/packages/dtos/src/team.ts +++ b/packages/dtos/src/team.ts @@ -33,7 +33,7 @@ export const getMeResponseSchema = z.object({ id: z.string(), name: z.string(), email: z.string().optional(), - role: z.string(), + role: z.enum(['owner', 'editor', 'reviewer', 'bot', 'unknown']), image: z.string().optional(), unreadNotificationCount: z.number().optional(), }) @@ -48,10 +48,11 @@ export type UpdateMeRequest = z.infer export const userInfoSchema = z.object({ id: z.string(), name: z.string(), - role: z.string(), + role: z.enum(['owner', 'editor', 'reviewer', 'bot', 'unknown']), email: z.string().optional(), type: z.enum(['human', 'agent']).optional(), image: z.string().optional(), + scope: z.enum(['team', 'project']).optional(), }) export type UserInfo = z.infer @@ -112,6 +113,7 @@ export interface ServiceGetMeRequest { export interface ServiceGetTeamMembersRequest { teamId: string + userId: string includeAgents?: boolean } diff --git a/packages/transcode/src/transcode.test.ts b/packages/transcode/src/transcode.test.ts index 563d0992..a67b770c 100644 --- a/packages/transcode/src/transcode.test.ts +++ b/packages/transcode/src/transcode.test.ts @@ -106,7 +106,7 @@ describe('TranscodeService', () => { expect(info.originalHeight).toBe(600) expect(info.mimeType).toBe('png') expect(info.duration).toBe(0) - expect(sharp).toHaveBeenCalledWith('test.png') + expect(sharp).toHaveBeenCalledWith('test.png', { limitInputPixels: false }) }) it('should construct correct ffmpeg arguments for video transcoding', async () => { @@ -147,9 +147,9 @@ describe('TranscodeService', () => { const outputFile = path.join(tempDir, 'output.webp') await transcodeService.transcodeImage('input.png', outputFile, 480, 80) - expect(sharp).toHaveBeenCalledWith('input.png') + expect(sharp).toHaveBeenCalledWith('input.png', { limitInputPixels: false }) const mockSharp = vi.mocked(sharp).mock.results[0].value - expect(mockSharp.resize).toHaveBeenCalledWith(480, null, expect.any(Object)) + expect(mockSharp.resize).toHaveBeenCalledWith(480, 7680, expect.any(Object)) expect(mockSharp.webp).toHaveBeenCalledWith({ quality: 80 }) expect(mockSharp.toFile).toHaveBeenCalledWith(outputFile) }) @@ -166,7 +166,7 @@ describe('TranscodeService', () => { await transcodeService.transcodeImage('http://example.com/image.png', outputFile, 480, 80) expect(global.fetch).toHaveBeenCalledWith('http://example.com/image.png') - expect(sharp).toHaveBeenCalledWith(expect.any(Buffer)) + expect(sharp).toHaveBeenCalledWith(expect.any(Buffer), { limitInputPixels: false }) }) it('should support Buffer as input for image transcoding', async () => { @@ -174,9 +174,9 @@ describe('TranscodeService', () => { const outputFile = path.join(tempDir, 'output-buffer.webp') await transcodeService.transcodeImage(inputBuffer, outputFile, 480, 80) - expect(sharp).toHaveBeenCalledWith(inputBuffer) + expect(sharp).toHaveBeenCalledWith(inputBuffer, { limitInputPixels: false }) const mockSharp = vi.mocked(sharp).mock.results[vi.mocked(sharp).mock.results.length - 1].value - expect(mockSharp.resize).toHaveBeenCalledWith(480, null, expect.any(Object)) + expect(mockSharp.resize).toHaveBeenCalledWith(480, 7680, expect.any(Object)) expect(mockSharp.webp).toHaveBeenCalledWith({ quality: 80 }) expect(mockSharp.toFile).toHaveBeenCalledWith(outputFile) }) diff --git a/packages/transcode/src/transcode.ts b/packages/transcode/src/transcode.ts index 422e6a27..46a5ccb7 100644 --- a/packages/transcode/src/transcode.ts +++ b/packages/transcode/src/transcode.ts @@ -1,14 +1,13 @@ -import { prisma } from '@shumai/db' -import { WorkflowTaskStatus, WorkflowTaskType } from '@shumai/db' +import { s3Service } from '@shumai/core/src/s3/s3' +import { prisma, WorkflowTaskStatus, WorkflowTaskType } from '@shumai/db' import '@shumai/db/src/prisma-json-types' import { execFile } from 'child_process' import * as fs from 'fs' import * as os from 'os' import * as path from 'path' import sharp from 'sharp' -import { promisify } from 'util' -import { s3Service } from '@shumai/core/src/s3/s3' import { ulid } from 'ulid' +import { promisify } from 'util' const execFileAsync = promisify(execFile) @@ -237,7 +236,7 @@ export class TranscodeService { input = Buffer.from(await resp.arrayBuffer()) } - const metadata = await sharp(input).metadata() + const metadata = await sharp(input, { limitInputPixels: false }).metadata() return { originalWidth: metadata.width || 0, originalHeight: metadata.height || 0, @@ -289,17 +288,16 @@ export class TranscodeService { input = Buffer.from(await resp.arrayBuffer()) } - const sharpInstance = sharp(input) + const sharpInstance = sharp(input, { limitInputPixels: false }) - const w = width > 0 ? width : null - const h = height && height > 0 ? height : null + const WEBP_MAX_DIMENSION = 7680 + const targetW = width > 0 ? Math.min(width, WEBP_MAX_DIMENSION) : WEBP_MAX_DIMENSION + const targetH = height && height > 0 ? Math.min(height, WEBP_MAX_DIMENSION) : WEBP_MAX_DIMENSION - if (w || h) { - sharpInstance.resize(w, h, { - withoutEnlargement: true, - fit: 'inside', - }) - } + sharpInstance.resize(targetW, targetH, { + withoutEnlargement: true, + fit: 'inside', + }) await sharpInstance.webp({ quality }).toFile(outputFile) } @@ -497,14 +495,14 @@ export class TranscodeService { params.annotations && params.annotations.length > 0 ) { - const meta = await sharp(localShotPath).metadata() + const meta = await sharp(localShotPath, { limitInputPixels: false }).metadata() const width = meta.width || 1280 const height = meta.height || 720 const svgStr = renderAnnotationsToSvg(width, height, params.annotations) const tempCompositedPath = path.join(tmpDir, `composite-${outName}`) - await sharp(localShotPath) + await sharp(localShotPath, { limitInputPixels: false }) .composite([{ input: Buffer.from(svgStr), top: 0, left: 0 }]) .toFile(tempCompositedPath) @@ -539,7 +537,7 @@ export class TranscodeService { await s3Service.downloadToFile(bucket, params.assetKey, imgPath) // 2. Read dimensions - const meta = await sharp(imgPath).metadata() + const meta = await sharp(imgPath, { limitInputPixels: false }).metadata() const width = meta.width || 1920 const height = meta.height || 1080 @@ -550,8 +548,9 @@ export class TranscodeService { const outName = `annotation-${ulid()}.webp` const localOutPath = path.join(tmpDir, outName) - await sharp(imgPath) + await sharp(imgPath, { limitInputPixels: false }) .composite([{ input: Buffer.from(svgStr), top: 0, left: 0 }]) + .resize(16383, 16383, { fit: 'inside', withoutEnlargement: true }) .webp({ quality: 90 }) .toFile(localOutPath) diff --git a/packages/webui/api/client.ts b/packages/webui/api/client.ts index 278e4c8d..da2da7c1 100644 --- a/packages/webui/api/client.ts +++ b/packages/webui/api/client.ts @@ -11,6 +11,7 @@ const customFetch = async (input: RequestInfo | URL, init?: RequestInit) => { // Don't redirect if we are already on login page, it's an auth request, or we are on a public share page if ( !window.location.pathname.includes('/login') && + !window.location.pathname.includes('/signup') && !window.location.pathname.startsWith('/share/') && !url.includes('/api/authn') ) { diff --git a/packages/webui/components/auth-layout.tsx b/packages/webui/components/auth-layout.tsx new file mode 100644 index 00000000..3a60e4eb --- /dev/null +++ b/packages/webui/components/auth-layout.tsx @@ -0,0 +1,74 @@ +import { ShumaiLogo } from '@/ui/components/ui/icons' +import { CheckCircle2 } from 'lucide-react' +import { ReactNode } from 'react' + +export function AuthLayout({ children }: { children: ReactNode }) { + return ( +
+ {/* Drifting Background Mesh Blobs */} +
+
+ + {/* Main Glassmorphic Split-Pane Card */} +
+ {/* Left Pane (Brand Showcase) */} +
+ {/* Subtle Grid Overlay */} +
+ + {/* Logo & Brand */} +
+ + + Shumai + +
+ + {/* Marketing Copy / Feature Points */} +
+

+ One workspace +
+ for all your +
+ + creative assets. + +

+

+ Upload and index your files, enrich them with custom metadata schemas, draw + annotations directly on media, and gather instant feedback — all in one modern + workspace built for creators. +

+ +
    + {[ + 'Instant asset uploads & high-fidelity media players', + 'Custom metadata schemas & drawing canvas reviews', + 'Frictionless team workspaces & secure sharing', + ].map((text, i) => ( +
  • + + {text} +
  • + ))} +
+
+ + {/* Footer Label */} +
+

+ Join our community of developers and designers. +

+
+
+ + {/* Right Pane (Form Container) */} +
{children}
+
+
+ ) +} diff --git a/packages/webui/components/file-browser/file-browser.tsx b/packages/webui/components/file-browser/file-browser.tsx index 8f1b2acd..a11c1fd1 100644 --- a/packages/webui/components/file-browser/file-browser.tsx +++ b/packages/webui/components/file-browser/file-browser.tsx @@ -530,6 +530,10 @@ export function FileBrowser({ const selectedFiles = Array.from(selectedIds).filter((id) => displayedFiles.find((item) => item.id === id), ).length + const selectedSize = Array.from(selectedIds).reduce((acc, id) => { + const item = folders.find((f) => f.id === id) || displayedFiles.find((f) => f.id === id) + return acc + (item?.sizeByte || 0) + }, 0) const handleUploadFilesClick = () => { fileInputRef.current?.click() @@ -876,20 +880,20 @@ export function FileBrowser({
{selectedFolders > 0 && selectedFiles > 0 && ( - {selectedFolders} folder - {selectedFolders !== 1 ? 's' : ''}, {selectedFiles} file - {selectedFiles !== 1 ? 's' : ''} selected + {selectedCount} Item{selectedCount !== 1 ? 's' : ''} selected •{' '} + {formatSize(selectedSize)} )} {selectedFolders > 0 && selectedFiles === 0 && ( - {selectedFolders} folder - {selectedFolders !== 1 ? 's' : ''} selected + {selectedFolders} folder{selectedFolders !== 1 ? 's' : ''} selected •{' '} + {formatSize(selectedSize)} )} {selectedFolders === 0 && selectedFiles > 0 && ( - {selectedFiles} file{selectedFiles !== 1 ? 's' : ''} selected + {selectedFiles} file{selectedFiles !== 1 ? 's' : ''} selected •{' '} + {formatSize(selectedSize)} )}
diff --git a/packages/webui/components/folder-tree.tsx b/packages/webui/components/folder-tree.tsx index fa37c92e..00c8e46d 100644 --- a/packages/webui/components/folder-tree.tsx +++ b/packages/webui/components/folder-tree.tsx @@ -531,7 +531,7 @@ export function FolderTree({ {!hideShares && (
diff --git a/packages/webui/components/members-dialog.tsx b/packages/webui/components/members-dialog.tsx index 950fef47..52e59f75 100644 --- a/packages/webui/components/members-dialog.tsx +++ b/packages/webui/components/members-dialog.tsx @@ -28,6 +28,7 @@ export interface Member { name?: string role?: string image?: string + scope?: 'team' | 'project' } interface MembersDialogProps { @@ -154,7 +155,19 @@ export function MembersDialog({
{member.name} - {member.role} +
+ + {member.role} + + {member.scope && ( + <> + • + + {member.scope === 'team' ? 'Team Member' : 'Project Member'} + + + )} +
diff --git a/packages/webui/routes/__root.tsx b/packages/webui/routes/__root.tsx index ca31d281..62a916b7 100644 --- a/packages/webui/routes/__root.tsx +++ b/packages/webui/routes/__root.tsx @@ -5,7 +5,6 @@ import { TopNav } from '@/ui/components/top-nav' import { HomeIcon, NotificationFillIcon, UploadCloudIcon } from '@/ui/components/ui/icons' import { Toaster } from '@/ui/components/ui/sonner' import { UploadTasks } from '@/ui/components/upload-tasks' -import { usePermissions } from '@/ui/hooks/use-permissions' import { useAuthStore } from '@/ui/stores/auth' import { useTeamContextStore } from '@/ui/stores/team-context' import { useUploadStore } from '@/ui/stores/upload' @@ -21,7 +20,6 @@ import { useEffect } from 'react' function RootComponent() { const user = useAuthStore((state) => state.user) const { uploading } = useUploadStore() - const { canEdit } = usePermissions() const pathname = useRouterState({ select: (s) => s.location.pathname }) const navigate = useNavigate() @@ -90,19 +88,17 @@ function RootComponent() { } label="Notifications" badge={badge}> - {canEdit && ( - 0} - className={uploading > 0 ? 'text-blue-500' : ''} - /> - } - label="Uploads" - > - - - )} + 0} + className={uploading > 0 ? 'text-blue-500' : ''} + /> + } + label="Uploads" + > + +
diff --git a/packages/webui/routes/login.tsx b/packages/webui/routes/login.tsx index e1ecfadf..e9e58551 100644 --- a/packages/webui/routes/login.tsx +++ b/packages/webui/routes/login.tsx @@ -10,8 +10,9 @@ import { useEffect, useState } from 'react' import { useForm } from 'react-hook-form' import { z } from 'zod' import { signIn } from '@/ui/lib/auth-client' -import { Loader2, Mail, Lock, ArrowRight, LogIn, CheckCircle2 } from 'lucide-react' +import { Loader2, Mail, Lock, ArrowRight, LogIn } from 'lucide-react' import { ShumaiLogo } from '@/ui/components/ui/icons' +import { AuthLayout } from '@/ui/components/auth-layout' const loginSchema = z.object({ email: z.string().email('Invalid email address'), @@ -77,165 +78,100 @@ function LoginPage() { } return ( -
- {/* Drifting Background Mesh Blobs */} -
-
- - {/* Main Glassmorphic Split-Pane Card */} -
- {/* Left Pane (Brand Showcase) */} -
- {/* Subtle Grid Overlay */} -
- - {/* Logo & Brand */} -
- - - Shumai - -
- - {/* Marketing Copy / Feature Points */} -
-

- One workspace -
- for all your -
- - creative assets. - -

-

- Upload and index your files, enrich them with custom metadata schemas, draw - annotations directly on media, and gather instant feedback — all in one modern - workspace built for creators. -

- -
    - {[ - 'Instant asset uploads & high-fidelity media players', - 'Custom metadata schemas & drawing canvas reviews', - 'Frictionless team workspaces & secure sharing', - ].map((text, i) => ( -
  • - - {text} -
  • - ))} -
-
- - {/* Footer Label */} -
-

- Join our community of developers and designers. -

-
-
- - {/* Right Pane (Form Container) */} -
-
-

- Welcome Back -

-

- Enter your credentials to access your account. -

-
- - {error && ( -
- {error} -
- )} - -
-
- -
- - -
- {form.formState.errors.email && ( -

- {form.formState.errors.email.message} -

- )} -
- -
- -
- - -
- {form.formState.errors.password && ( -

- {form.formState.errors.password.message} -

- )} -
- - -
- -
- Don't have an account? - - Sign up - -
-
+ +
+

+ Welcome Back +

+

+ Enter your credentials to access your account. +

-
+ + {error && ( +
+ {error} +
+ )} + +
+
+ +
+ + +
+ {form.formState.errors.email && ( +

+ {form.formState.errors.email.message} +

+ )} +
+ +
+ +
+ + +
+ {form.formState.errors.password && ( +

+ {form.formState.errors.password.message} +

+ )} +
+ + +
+ +
+ Don't have an account? + + Sign up + +
+ ) } diff --git a/packages/webui/routes/signup.tsx b/packages/webui/routes/signup.tsx index 4edc0dd1..230b9a5b 100644 --- a/packages/webui/routes/signup.tsx +++ b/packages/webui/routes/signup.tsx @@ -4,7 +4,7 @@ import { Button } from '@/ui/components/ui/button' import { Card, CardDescription, CardFooter, CardHeader, CardTitle } from '@/ui/components/ui/card' import { Input } from '@/ui/components/ui/input' import { Label } from '@/ui/components/ui/label' -import { Loader2, Mail, Lock, CheckCircle2, ArrowRight, UserPlus } from 'lucide-react' +import { Loader2, Mail, Lock, ArrowRight, UserPlus } from 'lucide-react' import { useAuthStore } from '@/ui/stores/auth' import { zodResolver } from '@hookform/resolvers/zod' import { createFileRoute, redirect, useNavigate } from '@tanstack/react-router' @@ -13,6 +13,7 @@ import { z } from 'zod' import { signUp } from '@/ui/lib/auth-client' import { useState } from 'react' import { ShumaiLogo } from '@/ui/components/ui/icons' +import { AuthLayout } from '@/ui/components/auth-layout' const signupSchema = z.object({ email: z.string().email('Invalid email address'), @@ -135,183 +136,118 @@ function SignupPage() { } return ( -
- {/* Drifting Background Mesh Blobs */} -
-
+ +
+

+ Create Account +

+

+ Start building and organizing your space. +

- {/* Main Glassmorphic Split-Pane Card */} -
- {/* Left Pane (Brand Showcase) */} -
- {/* Subtle Grid Overlay */} -
- - {/* Logo & Brand */} -
- - - Shumai + {/* Context Banners (First User / Invite Info) */} + {isFirstUser && ( +
+ 🎉 + You will be the owner of the default workspace as the first user! +
+ )} + {inviteInfo && !('error' in inviteInfo) && ( +
+ 👋 + + {inviteInfo.inviterName} invited you to join{' '} + {inviteInfo.projectName || inviteInfo.teamName} as a{' '} + {inviteInfo.role}.
- - {/* Marketing Copy / Feature Points */} -
-

- One workspace -
- for all your -
- - creative assets. - -

-

- Upload and index your files, enrich them with custom metadata schemas, draw - annotations directly on media, and gather instant feedback — all in one modern - workspace built for creators. -

- -
    - {[ - 'Instant asset uploads & high-fidelity media players', - 'Custom metadata schemas & drawing canvas reviews', - 'Frictionless team workspaces & secure sharing', - ].map((text, i) => ( -
  • - - {text} -
  • - ))} -
-
- - {/* Context Banners (First User / Invite Info) */} -
- {isFirstUser && ( -
- 🎉 - You will be the owner of the default workspace as the first user! -
- )} - {inviteInfo && !('error' in inviteInfo) && ( -
- 👋 - - {inviteInfo.inviterName} invited you to join{' '} - {inviteInfo.teamName || inviteInfo.projectName} as a{' '} - {inviteInfo.role}. - -
- )} - {!isFirstUser && !inviteInfo && ( -

- Join our community of developers and designers. -

- )} -
-
- - {/* Right Pane (Form Container) */} -
-
-

- Create Account -

-

- Start building and organizing your space. -

-
- - {error && ( -
- {error} -
- )} - -
-
- -
- - -
- {form.formState.errors.email && ( -

- {form.formState.errors.email.message} -

- )} -
- -
- -
- - -
- {form.formState.errors.password && ( -

- {form.formState.errors.password.message} -

- )} -
- - -
- -
- Already have an account? - - Login - -
-
+ )}
-
+ + {error && ( +
+ {error} +
+ )} + +
+
+ +
+ + +
+ {form.formState.errors.email && ( +

+ {form.formState.errors.email.message} +

+ )} +
+ +
+ +
+ + +
+ {form.formState.errors.password && ( +

+ {form.formState.errors.password.message} +

+ )} +
+ + +
+ +
+ Already have an account? + + Login + +
+ ) } diff --git a/packages/webui/routes/teams/$teamId/settings.tsx b/packages/webui/routes/teams/$teamId/settings.tsx index 1b06d64e..8553b675 100644 --- a/packages/webui/routes/teams/$teamId/settings.tsx +++ b/packages/webui/routes/teams/$teamId/settings.tsx @@ -233,21 +233,23 @@ function TeamSettingsPage() { )} - + {me?.role === 'owner' && ( + + )} -
- AI -
+ {me?.role === 'owner' && ( + <> +
+ AI +
- + - + - + - + + + )}