Merge remote-tracking branch 'origin/canary' into beta

This commit is contained in:
LongYinan
2024-04-25 16:46:19 +08:00
5 changed files with 96 additions and 93 deletions
Generated
+3 -3
View File
@@ -823,7 +823,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
dependencies = [
"cfg-if",
"windows-targets 0.52.5",
"windows-targets 0.48.5",
]
[[package]]
@@ -1393,9 +1393,9 @@ dependencies = [
[[package]]
name = "rustls"
version = "0.21.10"
version = "0.21.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba"
checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4"
dependencies = [
"ring",
"rustls-webpki",
+1 -1
View File
@@ -118,7 +118,7 @@
"c8": "^9.1.0",
"nodemon": "^3.1.0",
"sinon": "^17.0.1",
"supertest": "^6.3.4"
"supertest": "^7.0.0"
},
"ava": {
"timeout": "1m",
@@ -593,37 +593,35 @@ export const prompts: Prompt[] = [
];
export async function refreshPrompts(db: PrismaClient) {
await db.$transaction(async tx => {
for (const prompt of prompts) {
await tx.aiPrompt.upsert({
create: {
name: prompt.name,
action: prompt.action,
model: prompt.model,
messages: {
create: prompt.messages.map((message, idx) => ({
idx,
role: message.role,
content: message.content,
params: message.params,
})),
},
for (const prompt of prompts) {
await db.aiPrompt.upsert({
create: {
name: prompt.name,
action: prompt.action,
model: prompt.model,
messages: {
create: prompt.messages.map((message, idx) => ({
idx,
role: message.role,
content: message.content,
params: message.params,
})),
},
where: { name: prompt.name },
update: {
action: prompt.action,
model: prompt.model,
messages: {
deleteMany: {},
create: prompt.messages.map((message, idx) => ({
idx,
role: message.role,
content: message.content,
params: message.params,
})),
},
},
where: { name: prompt.name },
update: {
action: prompt.action,
model: prompt.model,
messages: {
deleteMany: {},
create: prompt.messages.map((message, idx) => ({
idx,
role: message.role,
content: message.content,
params: message.params,
})),
},
});
}
});
},
});
}
}
@@ -13,56 +13,62 @@ export async function upgradeQuotaVersion(
// add new quota
await upsertFeature(db, quota);
// migrate all users that using old quota to new quota
await db.$transaction(async tx => {
const latestQuotaVersion = await tx.features.findFirstOrThrow({
where: { feature: quota.feature },
orderBy: { version: 'desc' },
select: { id: true },
});
await db.$transaction(
async tx => {
const latestQuotaVersion = await tx.features.findFirstOrThrow({
where: { feature: quota.feature },
orderBy: { version: 'desc' },
select: { id: true },
});
// find all users that have old free plan
const userIds = await tx.user.findMany({
where: {
features: {
some: {
feature: {
type: FeatureKind.Quota,
feature: quota.feature,
version: { lt: quota.version },
// find all users that have old free plan
const userIds = await tx.user.findMany({
where: {
features: {
some: {
feature: {
type: FeatureKind.Quota,
feature: quota.feature,
version: { lt: quota.version },
},
activated: true,
},
activated: true,
},
},
},
select: { id: true },
});
select: { id: true },
});
// deactivate all old quota for the user
await tx.userFeatures.updateMany({
where: {
id: undefined,
userId: {
in: userIds.map(({ id }) => id),
// deactivate all old quota for the user
await tx.userFeatures.updateMany({
where: {
id: undefined,
userId: {
in: userIds.map(({ id }) => id),
},
feature: {
type: FeatureKind.Quota,
},
activated: true,
},
feature: {
type: FeatureKind.Quota,
data: {
activated: false,
},
activated: true,
},
data: {
activated: false,
},
});
});
await tx.userFeatures.createMany({
data: userIds.map(({ id: userId }) => ({
userId,
featureId: latestQuotaVersion.id,
reason,
activated: true,
})),
});
});
await tx.userFeatures.createMany({
data: userIds.map(({ id: userId }) => ({
userId,
featureId: latestQuotaVersion.id,
reason,
activated: true,
})),
});
},
{
maxWait: 10000,
timeout: 20000,
}
);
}
export async function upsertLatestQuotaVersion(
+15 -16
View File
@@ -740,7 +740,7 @@ __metadata:
sinon: "npm:^17.0.1"
socket.io: "npm:^4.7.5"
stripe: "npm:^15.0.0"
supertest: "npm:^6.3.4"
supertest: "npm:^7.0.0"
tiktoken: "npm:^1.0.13"
ts-node: "npm:^10.9.2"
typescript: "npm:^5.4.5"
@@ -22847,15 +22847,14 @@ __metadata:
languageName: node
linkType: hard
"formidable@npm:^2.1.2":
version: 2.1.2
resolution: "formidable@npm:2.1.2"
"formidable@npm:^3.5.1":
version: 3.5.1
resolution: "formidable@npm:3.5.1"
dependencies:
dezalgo: "npm:^1.0.4"
hexoid: "npm:^1.0.0"
once: "npm:^1.4.0"
qs: "npm:^6.11.0"
checksum: 10/d385180e0461f65e6f7b70452859fe1c32aa97a290c2ca33f00cdc33145ef44fa68bbc9b93af2c3af73ae726e42c3477c6619c49f3c34b49934e9481275b7b4c
checksum: 10/c9a7bbbd4ca8142893da88b51cf7797adee022344ea180cf157a108bf999bed5ad8bc07a10a28d8a39fcbfaa02e8cba07f4ba336fbeb330deb23907336ba1fc2
languageName: node
linkType: hard
@@ -34751,21 +34750,21 @@ __metadata:
languageName: node
linkType: hard
"superagent@npm:^8.1.2":
version: 8.1.2
resolution: "superagent@npm:8.1.2"
"superagent@npm:^9.0.1":
version: 9.0.1
resolution: "superagent@npm:9.0.1"
dependencies:
component-emitter: "npm:^1.3.0"
cookiejar: "npm:^2.1.4"
debug: "npm:^4.3.4"
fast-safe-stringify: "npm:^2.1.1"
form-data: "npm:^4.0.0"
formidable: "npm:^2.1.2"
formidable: "npm:^3.5.1"
methods: "npm:^1.1.2"
mime: "npm:2.6.0"
qs: "npm:^6.11.0"
semver: "npm:^7.3.8"
checksum: 10/33d0072e051baf91c7d68131c70682a0650dd1bd0b8dfb6f88e5bdfcb02e18cc2b42a66e44b32fd405ac6bcf5fd57c6e267bf80e2a8ce57a18166a9d3a78f57d
checksum: 10/a6e7cd5b93aa51b297cc66ede2f08c5143d4645d3ec424f9ee45dd890e6ba33637e63ce0d724c2a9536f83a8d913c0e0a52575fd9c02e0043a5a7d61708a0a45
languageName: node
linkType: hard
@@ -34781,13 +34780,13 @@ __metadata:
languageName: node
linkType: hard
"supertest@npm:^6.3.4":
version: 6.3.4
resolution: "supertest@npm:6.3.4"
"supertest@npm:^7.0.0":
version: 7.0.0
resolution: "supertest@npm:7.0.0"
dependencies:
methods: "npm:^1.1.2"
superagent: "npm:^8.1.2"
checksum: 10/93015318f5a90398915a032747973d9eacf9aebec3f07b413eba9d8b3db83ff48fbf6f5a92f9526578cae50153b0f76a37de197141030d856db4371a711b86ee
superagent: "npm:^9.0.1"
checksum: 10/73bf2a37e13856a1b3e6a37b9df5cec8e506aa0360a5f5ecd989d1f4b0edf168883e306012e81e371d5252c17d4c7bef4ba30633dbf3877cbf52fc7af51cca9b
languageName: node
linkType: hard