Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/global/core/agentSkills/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export const agentSkillsVersionCollectionName = 'agent_skills_versions';

export const skillSandboxCollectionName = 'skill_sandbox_info';

export enum AgentSkillCreationStatusEnum {
creating = 'creating',
ready = 'ready',
failed = 'failed'
}

// Agent Skill types
export enum AgentSkillTypeEnum {
folder = 'folder',
Expand Down
7 changes: 6 additions & 1 deletion packages/global/core/agentSkills/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AgentSkillSourceEnum,
AgentSkillCategoryEnum,
AgentSkillTypeEnum,
AgentSkillCreationStatusEnum,
SandboxProtocolEnum,
SandboxTypeEnum
} from './constants';
Expand All @@ -17,6 +18,7 @@ const BufferSchema = z.custom<Buffer>(
export const AgentSkillSourceSchema = z.enum(AgentSkillSourceEnum);
export const AgentSkillCategorySchema = z.enum(AgentSkillCategoryEnum);
export const AgentSkillTypeSchema = z.enum(AgentSkillTypeEnum);
export const AgentSkillCreationStatusSchema = z.enum(AgentSkillCreationStatusEnum);
export const SandboxProtocolSchema = z.enum(SandboxProtocolEnum);
export const SandboxTypeSchema = z.enum(SandboxTypeEnum);
export const SandboxStatusSchema = z.enum([
Expand Down Expand Up @@ -76,7 +78,9 @@ export const AgentSkillSchema = z.object({
deleteTime: z.coerce.date().nullable().optional(),
currentVersion: z.number(),
versionCount: z.number(),
currentStorage: AgentSkillStorageSchema.optional()
currentStorage: AgentSkillStorageSchema.optional(),
creationStatus: AgentSkillCreationStatusSchema.optional(),
creationError: z.string().optional()
});
export type AgentSkillSchemaType = z.infer<typeof AgentSkillSchema>;

Expand All @@ -91,6 +95,7 @@ export const AgentSkillListItemSchema = z.object({
author: z.string(),
category: z.array(AgentSkillCategorySchema),
avatar: z.string().optional(),
creationStatus: AgentSkillCreationStatusSchema.optional(),
createTime: z.coerce.date(),
updateTime: z.coerce.date(),
appCount: z.number().optional(),
Expand Down
3 changes: 3 additions & 0 deletions packages/global/openapi/core/agentSkills/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { z } from 'zod';
import { TeamMemberStatusEnum } from '../../../support/user/team/constant';
import {
AgentSkillCategorySchema,
AgentSkillCreationStatusSchema,
AgentSkillListItemSchema,
AgentSkillSourceSchema,
AgentSkillStorageSchema,
Expand Down Expand Up @@ -125,6 +126,8 @@ export const GetSkillDetailResponseSchema = z.object({
category: z.array(AgentSkillCategorySchema),
config: AgentSkillConfigSchema,
avatar: z.string().optional(),
creationStatus: AgentSkillCreationStatusSchema.optional(),
creationError: z.string().optional(),
teamId: z.string().optional(),
tmbId: z.string().optional(),
createTime: z.string(),
Expand Down
2 changes: 1 addition & 1 deletion packages/service/common/bullmq/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { getLogger, LogCategories } from '../logger';
import { newQueueRedisConnection, newWorkerRedisConnection } from '../redis';
import { delay } from '@fastgpt/global/common/system/utils';
import { getErrText } from '@fastgpt/global/common/error/utils';

const logger = getLogger(LogCategories.INFRA.QUEUE);

Expand All @@ -28,6 +27,7 @@ export enum QueueNames {
evaluation = 'evaluation',
s3FileDelete = 's3FileDelete',
collectionUpdate = 'collectionUpdate',
agentSkillCreate = 'agentSkillCreate',

// Delete Queue
datasetDelete = 'datasetDelete',
Expand Down
52 changes: 49 additions & 3 deletions packages/service/core/agentSkills/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MongoAgentSkills } from './schema';
import { MongoAgentSkillsVersion } from './version/schema';
import {
AgentSkillSourceEnum,
AgentSkillCreationStatusEnum,
AgentSkillTypeEnum
} from '@fastgpt/global/core/agentSkills/constants';
import type { AgentSkillSchemaType, SkillPackageType } from '@fastgpt/global/core/agentSkills/type';
Expand All @@ -27,6 +28,11 @@ type CreateSkillData = {
avatar?: string;
teamId: string;
tmbId: string;
creationStatus?: AgentSkillCreationStatusEnum;
creationPayload?: {
requirements?: string;
model?: string;
};
};

// UpdateSkillData excludes markdown to ensure consistency with version management
Expand All @@ -48,6 +54,8 @@ export async function createSkill(data: CreateSkillData, session?: ClientSession
source: AgentSkillSourceEnum.personal,
currentVersion: 0,
versionCount: 0,
creationStatus: data.creationStatus ?? AgentSkillCreationStatusEnum.ready,
creationPayload: data.creationPayload,
updateTime: new Date()
});
await skill.save({ session });
Expand Down Expand Up @@ -91,10 +99,48 @@ export async function updateCurrentStorage(
size: number;
},
session?: ClientSession
): Promise<void> {
): Promise<boolean> {
const result = await MongoAgentSkills.updateOne(
{ _id: skillId, deleteTime: null },
{
$set: {
currentStorage: storageInfo,
creationStatus: AgentSkillCreationStatusEnum.ready,
updateTime: new Date()
},
$unset: {
creationError: '',
creationPayload: ''
}
},
{ session }
);

return result.matchedCount > 0;
}

/** Mark an async-created skill as failed while keeping it visible for deletion and diagnosis. */
export async function updateSkillCreationFailed({
skillId,
error,
session
}: {
skillId: string;
error: string;
session?: ClientSession;
}): Promise<void> {
await MongoAgentSkills.updateOne(
{ _id: skillId, deleteTime: null },
{ $set: { currentStorage: storageInfo, updateTime: new Date() } },
{
$set: {
creationStatus: AgentSkillCreationStatusEnum.failed,
creationError: error,
updateTime: new Date()
},
$unset: {
creationPayload: ''
}
},
{ session }
);
}
Expand Down Expand Up @@ -402,7 +448,7 @@ export async function getSkillFolderPath(
return [];
}

const targetId = type === 'current' ? skillId : skill.parentId ?? null;
const targetId = type === 'current' ? skillId : (skill.parentId ?? null);
return await getParents(targetId);
}

Expand Down
Loading
Loading