Files
FastGPT/packages/service/core/ai/sandbox/schema.ts
T
Archer b884631363 feat: sandbox readfile tool (#6679)
* feat: sandbox readfile tool

* perf: read stream

* fix: schema name

* update sdk version

* udpate enum

* perf: time
2026-03-31 13:50:26 +08:00

74 lines
1.8 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
},
storage: {
type: Schema.Types.Mixed
},
metadata: {
type: Schema.Types.Mixed
}
});
SandboxInstanceSchema.index(
{ provider: 1, 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
);