Files
FastGPT/packages/service/core/ai/sandbox/schema.ts
T
Archer 9959707fb3 V4.14.9 fix issue (#6573)
* fix: session error

* fix: session error

* fix: workflow runtime and add e2b
2026-03-19 11:15:14 +08:00

68 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { connectionMongo, getMongoModel } from '../../../common/mongo';
const { Schema } = connectionMongo;
import type { SandboxInstanceSchemaType } from './type';
import { SandboxStatusEnum } from '@fastgpt/global/core/ai/sandbox/constants';
import { AppCollectionName } from '../../app/schema';
import { SandboxLimitSchema, SandboxProviderSchema } from './type';
export const collectionName = 'agent_sandbox_instances';
const SandboxInstanceSchema = new Schema({
provider: {
type: String,
enum: SandboxProviderSchema.options,
required: true
},
// 唯一 idchat 模式下,由 3 个 id hash 获取。
sandboxId: {
type: String,
required: true
},
// Chat 模式下会关联会话。Skill editor 不需要 appId,userId,chatId
appId: {
type: Schema.Types.ObjectId,
ref: AppCollectionName
},
userId: String,
chatId: String,
status: {
type: String,
enum: Object.values(SandboxStatusEnum),
default: SandboxStatusEnum.running,
required: true
},
lastActiveAt: {
type: Date,
default: () => new Date(),
required: true
},
createdAt: {
type: Date,
default: () => new Date(),
required: true
},
limit: {
type: SandboxLimitSchema.shape
}
});
SandboxInstanceSchema.index(
{ appId: 1, userId: 1, chatId: 1 },
{
unique: true,
partialFilterExpression: {
appId: { $exists: true },
userId: { $exists: true },
chatId: { $exists: true }
}
}
);
SandboxInstanceSchema.index({ status: 1, lastActiveAt: 1 });
SandboxInstanceSchema.index({ provider: 1, sandboxId: 1 }, { unique: true });
export const MongoSandboxInstance = getMongoModel<SandboxInstanceSchemaType>(
collectionName,
SandboxInstanceSchema
);