Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(server): answer 4xx or fall back where expected conditions surfaced as 500 (#23058)

Innei993eaea31f08
diff --git a/apps/server/src/routers/lambda/__tests__/agentDocument.toolOutcome.test.ts b/apps/server/src/routers/lambda/__tests__/agentDocument.toolOutcome.test.ts
index d6b59bfa406..dde0ae44f57 100644
--- a/apps/server/src/routers/lambda/__tests__/agentDocument.toolOutcome.test.ts
+++ b/apps/server/src/routers/lambda/__tests__/agentDocument.toolOutcome.test.ts
@@ -6,6 +6,7 @@ import { TaskModel } from '@/database/models/task';
import { createCallerFactory } from '@/libs/trpc/lambda';
import { createContextInner } from '@/libs/trpc/lambda/context';
import { AgentDocumentsService } from '@/server/services/agentDocuments';
+import { AgentDocumentEditRejectedError } from '@/server/services/agentDocuments/editRejectedError';
import { emitAgentDocumentToolOutcomeSafely } from '@/server/services/agentDocuments/toolOutcome';
import { agentDocumentRouter } from '../agentDocument';
@@ -70,6 +71,7 @@ interface MockAgentDocumentsService {
createDocument: ReturnType<typeof vi.fn>;
createForTopic: ReturnType<typeof vi.fn>;
getDocumentById: ReturnType<typeof vi.fn>;
+ modifyDocumentNodesById: ReturnType<typeof vi.fn>;
removeDocumentById: ReturnType<typeof vi.fn>;
renameDocumentById: ReturnType<typeof vi.fn>;
}
@@ -100,6 +102,7 @@ describe('agentDocumentRouter tool outcomes', () => {
createDocument: vi.fn().mockResolvedValue(createdDocument),
createForTopic: vi.fn().mockResolvedValue(createdDocument),
getDocumentById: vi.fn().mockResolvedValue(createdDocument),
+ modifyDocumentNodesById: vi.fn().mockResolvedValue(createdDocument),
removeDocumentById: vi.fn().mockResolvedValue(true),
renameDocumentById: vi.fn().mockResolvedValue({ ...createdDocument, title: 'Renamed' }),
};
@@ -230,6 +233,23 @@ describe('agentDocumentRouter tool outcomes', () => {
expect(agentDocumentMocks.registerDocument).not.toHaveBeenCalled();
});
+ it('answers a bad request when a node edit is rejected', async () => {
+ const message =
+ 'Operation 1 of 1 (remove) failed: node "stale-node" not found in the document.';
+ serviceImpl.modifyDocumentNodesById.mockRejectedValue(
+ new AgentDocumentEditRejectedError(message),
+ );
+ const caller = createCaller(await createContextInner({ userId: 'user-1' }));
+
+ await expect(
+ caller.modifyNodes({
+ agentId: 'agent-1',
+ id: 'agent-document-1',
+ operations: [{ action: 'remove', id: 'stale-node' }],
+ }),
+ ).rejects.toMatchObject({ code: 'BAD_REQUEST', message });
+ });
+
it('does not register document work on the lambda for attributed renameDocument', async () => {
const caller = createCaller(await createContextInner({ userId: 'user-1' }));
diff --git a/apps/server/src/routers/lambda/agentDocument/toolDocuments.ts b/apps/server/src/routers/lambda/agentDocument/toolDocuments.ts
index 54e72eae8f2..c99710c111b 100644
--- a/apps/server/src/routers/lambda/agentDocument/toolDocuments.ts
+++ b/apps/server/src/routers/lambda/agentDocument/toolDocuments.ts
@@ -5,6 +5,7 @@ import { z } from 'zod';
import { TaskModel } from '@/database/models/task';
import { router } from '@/libs/trpc/lambda';
+import { AgentDocumentEditRejectedError } from '@/server/services/agentDocuments/editRejectedError';
import { emitAgentDocumentToolOutcomeSafely } from '@/server/services/agentDocuments/toolOutcome';
import { assertCanPerformResourceAction } from '@/server/services/resourcePermission';
import { resolveTaskOrThrow } from '@/server/services/task/utils';
@@ -360,13 +361,18 @@ export const toolDocumentsRouter = router({
.and(agentDocumentToolTriggerSchema),
)
.mutation(async ({ ctx, input }) => {
- const doc = await ctx.agentDocumentService.modifyDocumentNodesById(
- input.id,
- input.operations,
- input.agentId,
- );
-
- return doc;
+ try {
+ return await ctx.agentDocumentService.modifyDocumentNodesById(
+ input.id,
+ input.operations,
+ input.agentId,
+ );
+ } catch (error) {
+ if (error instanceof AgentDocumentEditRejectedError) {
+ throw new TRPCError({ cause: error, code: 'BAD_REQUEST', message: error.message });
+ }
+ throw error;
+ }
}),
/**
* Tool-oriented: replace document content by id
diff --git a/apps/server/src/routers/lambda/upload.test.ts b/apps/server/src/routers/lambda/upload.test.ts
index 066b0edb246..8c28513a57c 100644
--- a/apps/server/src/routers/lambda/upload.test.ts
+++ b/apps/server/src/routers/lambda/upload.test.ts
@@ -231,6 +231,28 @@ describe('uploadRouter', () => {
expect(routerMocks.model.markCompleted).toHaveBeenCalledWith(upload.id);
});
+ it('answers a conflict when storage holds neither the multipart upload nor the object', async () => {
+ const partSize = 32 * 1024 * 1024;
+ const upload = createUpload({
+ multipartPartSize: partSize,
+ multipartUploadId: 'multipart-1',
+ size: partSize + 5,
+ });
+ routerMocks.fileUploadService.touchActive.mockResolvedValue(upload);
+ routerMocks.completeMultipartUpload.mockRejectedValue(
+ Object.assign(new Error('The specified upload does not exist.'), { name: 'NoSuchUpload' }),
+ );
+
+ await expect(
+ caller.completeS3MultipartUpload({
+ partCount: 2,
+ pathname: 'files/test.bin',
+ uploadId: 'multipart-1',
+ }),
+ ).rejects.toMatchObject({ code: 'CONFLICT' });
+ expect(routerMocks.model.markCompleted).not.toHaveBeenCalled();
+ });
+
it('rejects multipart operations for a different upload id', async () => {
routerMocks.fileUploadService.touchActive.mockResolvedValue(
createUpload({ multipartPartSize: 32 * 1024 * 1024, multipartUploadId: 'multipart-1' }),
diff --git a/apps/server/src/routers/lambda/upload.ts b/apps/server/src/routers/lambda/upload.ts
index 89d3ba7e143..d8a067169e2 100644
--- a/apps/server/src/routers/lambda/upload.ts
+++ b/apps/server/src/routers/lambda/upload.ts
@@ -9,7 +9,11 @@ import { router } from '@/libs/trpc/lambda';
import { serverDatabase } from '@/libs/trpc/lambda/middleware';
import { FileS3 } from '@/server/modules/S3';
import { FileUploadService } from '@/server/services/fileUpload';
-import { reserveUpload, uploadConflict } from '@/server/services/fileUploadReservation';
+import {
+ isMissingObject,
+ reserveUpload,
+ uploadConflict,
+} from '@/server/services/fileUploadReservation';
const MAX_MULTIPART_PARTS = 10_000;
const MULTIPART_PART_SIZE = 32 * 1024 * 1024;
@@ -163,8 +167,13 @@ export const uploadRouter = router({
} catch (error) {
if (!isMissingMultipartUpload(error)) throw error;
- const { contentLength } = await s3.getFileMetadata(upload.pathname);
- if (contentLength !== upload.size) throw error;
+ const metadata = await s3.getFileMetadata(upload.pathname).catch((headError) => {
+ if (isMissingObject(headError)) {
+ throw uploadConflict('Multipart upload no longer exists in storage');
+ }
+ throw headError;
+ });
+ if (metadata.contentLength !== upload.size) throw error;
}
await ctx.fileUploadService.model.markCompleted(upload.id);
diff --git a/apps/server/src/services/agentDocuments/editRejectedError.ts b/apps/server/src/services/agentDocuments/editRejectedError.ts
new file mode 100644
index 00000000000..7895d546b7d
--- /dev/null
+++ b/apps/server/src/services/agentDocuments/editRejectedError.ts
@@ -0,0 +1,3 @@
+export class AgentDocumentEditRejectedError extends Error {
+ override name = 'AgentDocumentEditRejectedError';
+}
diff --git a/apps/server/src/services/agentDocuments/headlessEditor.test.ts b/apps/server/src/services/agentDocuments/headlessEditor.test.ts
index db799435ba3..2c8a17652b7 100644
--- a/apps/server/src/services/agentDocuments/headlessEditor.test.ts
+++ b/apps/server/src/services/agentDocuments/headlessEditor.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
import { isValidEditorData } from '@/libs/editor/isValidEditorData';
+import { AgentDocumentEditRejectedError } from './editRejectedError';
import {
applyLiteXMLOperations,
createAgentMarkdownSnapshot,
@@ -225,6 +226,21 @@ describe('agent document headless editor', () => {
).rejects.toThrow('Operation 1 of 1 (insert) failed: node "missing-node" not found');
});
+ it("should mark a rejected node edit as the caller's error", async () => {
+ const initial = await exportEditorDataSnapshot({
+ fallbackContent: 'Original',
+ litexml: true,
+ });
+
+ await expect(
+ applyLiteXMLOperations({
+ editorData: initial.editorData,
+ fallbackContent: initial.content,
+ operations: [{ action: 'remove', id: 'missing-node' }],
+ }),
+ ).rejects.toBeInstanceOf(AgentDocumentEditRejectedError);
+ });
+
describe('LiteXML that is not well-formed', () => {
// Fragment from a real modifyNodes insert that was reported as
// "the editor rejected it": the text holds a raw `<model>`.
diff --git a/apps/server/src/services/agentDocuments/headlessEditor.ts b/apps/server/src/services/agentDocuments/headlessEditor.ts
index 1edeed5f767..0528892348a 100644
--- a/apps/server/src/services/agentDocuments/headlessEditor.ts
+++ b/apps/server/src/services/agentDocuments/headlessEditor.ts
@@ -17,6 +17,8 @@ import type { SerializedEditorState, SerializedLexicalNode } from 'lexical';
import { EMPTY_EDITOR_STATE } from '@/libs/editor/constants';
import { isValidEditorData } from '@/libs/editor/isValidEditorData';
+import { AgentDocumentEditRejectedError } from './editRejectedError';
+
export type AgentDocumentEditorData = Record<string, any>;
export type AgentDocumentLiteXMLOperation =
@@ -331,13 +333,17 @@ export const applyLiteXMLOperations = async ({
const malformed = 'litexml' in operation && findMalformedLiteXML(operation.litexml);
if (malformed) {
- throw new Error(
+ throw new AgentDocumentEditRejectedError(
`${label} failed: ${malformed}. No operations were saved; fix the litexml and retry the whole batch.`,
);
}
const problem = findLiteXMLEditStepProblem(operation, document);
- if (problem) throw new Error(`${label} failed: ${problem}. ${NOTHING_SAVED_HINT}`);
+ if (problem) {
+ throw new AgentDocumentEditRejectedError(
+ `${label} failed: ${problem}. ${NOTHING_SAVED_HINT}`,
+ );
+ }
await editor.applyLiteXML(
toHeadlessLiteXMLOperation(operation, canApplyAsReviewDiff(operation, document)),
@@ -348,7 +354,7 @@ export const applyLiteXMLOperations = async ({
next.litexml === current.litexml &&
JSON.stringify(next.editorData) === JSON.stringify(current.editorData)
) {
- throw new Error(
+ throw new AgentDocumentEditRejectedError(
`${label} did not change the document; the editor rejected it. ${NOTHING_SAVED_HINT}`,
);
}
diff --git a/apps/server/src/services/fileUploadReservation.ts b/apps/server/src/services/fileUploadReservation.ts
index 0aee6eda6a3..9aff64593d0 100644
--- a/apps/server/src/services/fileUploadReservation.ts
+++ b/apps/server/src/services/fileUploadReservation.ts
@@ -15,7 +15,7 @@ const matchesReservation = (
) =>
upload?.size === params.size && upload.multipartPartSize === (params.multipartPartSize ?? null);
-const isMissingObject = (error: unknown) => {
+export const isMissingObject = (error: unknown) => {
if (!error || typeof error !== 'object') return false;
const value = error as { $metadata?: { httpStatusCode?: number }; name?: string };
return value.name === 'NotFound' || value.$metadata?.httpStatusCode === 404;
diff --git a/apps/server/src/services/skillManagement/SkillManagementDocumentService.test.ts b/apps/server/src/services/skillManagement/SkillManagementDocumentService.test.ts
index c04b6736c6c..381dd0ca8ee 100644
--- a/apps/server/src/services/skillManagement/SkillManagementDocumentService.test.ts
+++ b/apps/server/src/services/skillManagement/SkillManagementDocumentService.test.ts
@@ -8,6 +8,7 @@ import {
DocumentLoadRule,
PolicyLoad,
} from '@/database/models/agentDocuments';
+import { isUuid } from '@/database/utils/uuid';
import type { AgentDocumentEditorSnapshot } from '../agentDocuments/headlessEditor';
import type { DocumentService } from '../document';
@@ -136,7 +137,7 @@ class InMemoryAgentDocumentModel implements SkillManagementAgentDocumentModel {
): Promise<SkillAgentDocument> {
this.createCalls.push({ agentId, content, filename, params });
- const id = `agent-doc-${this.nextId}`;
+ const id = `00000000-0000-4000-8000-${String(this.nextId).padStart(12, '0')}`;
const documentId = `document-${this.nextId}`;
this.nextId += 1;
@@ -162,6 +163,10 @@ class InMemoryAgentDocumentModel implements SkillManagementAgentDocumentModel {
}
async findById(agentDocumentId: string): Promise<SkillAgentDocument | undefined> {
+ if (!isUuid(agentDocumentId)) {
+ throw new Error(`invalid input syntax for type uuid: "${agentDocumentId}"`);
+ }
+
return this.documents.find((doc) => doc.id === agentDocumentId && !doc.deletedAt);
}
@@ -360,9 +365,9 @@ describe('SkillManagementDocumentService', () => {
name: 'release-writer',
}),
);
- expect(detail?.bundle.agentDocumentId).toBe('agent-doc-1');
+ expect(detail?.bundle.agentDocumentId).toBe('00000000-0000-4000-8000-000000000001');
expect(detail?.bundle.documentId).toBe('document-1');
- expect(detail?.index.agentDocumentId).toBe('agent-doc-2');
+ expect(detail?.index.agentDocumentId).toBe('00000000-0000-4000-8000-000000000002');
expect(detail?.index.documentId).toBe('document-2');
});
@@ -633,6 +638,117 @@ describe('SkillManagementDocumentService', () => {
).resolves.toBeUndefined();
});
+ it('reads a skill whose stored frontmatter is unclosed from its last saved metadata', async () => {
+ const { agentDocumentModel, service } = createService();
+ const created = await service.createSkill({
+ agentId: 'agent-1',
+ bodyMarkdown: skillBody(),
+ description: 'Writes release notes',
+ name: 'broken-index',
+ title: 'Broken Index',
+ });
+ const brokenContent = '---\nname: broken-index\ndescription: Edited by hand\n\n# Skill';
+ const index = agentDocumentModel.documents.find(
+ (doc) => doc.id === created.index.agentDocumentId,
+ )!;
+ index.content = brokenContent;
+
+ const detail = await service.getSkill({
+ agentId: 'agent-1',
+ includeContent: true,
+ name: 'broken-index',
+ });
+
+ expect(detail).toEqual(
+ expect.objectContaining({
+ content: brokenContent,
+ description: 'Writes release notes',
+ frontmatter: { description: 'Writes release notes', name: 'broken-index' },
+ frontmatterError: 'Skill index content must close frontmatter',
+ name: 'broken-index',
+ }),
+ );
+ await expect(service.listSkills({ agentId: 'agent-1' })).resolves.toEqual([
+ expect.objectContaining({
+ frontmatterError: 'Skill index content must close frontmatter',
+ name: 'broken-index',
+ }),
+ ]);
+ });
+
+ it('reads a broken skill index with an empty description when no metadata was saved', async () => {
+ const { agentDocumentModel, service } = createService();
+ const created = await service.createSkill({
+ agentId: 'agent-1',
+ bodyMarkdown: skillBody(),
+ description: 'Has no metadata',
+ name: 'no-metadata',
+ title: 'No Metadata',
+ });
+ const index = agentDocumentModel.documents.find(
+ (doc) => doc.id === created.index.agentDocumentId,
+ )!;
+ index.content = '# Skill without frontmatter';
+ index.metadata = null;
+
+ await expect(service.getSkill({ agentId: 'agent-1', name: 'no-metadata' })).resolves.toEqual(
+ expect.objectContaining({
+ description: '',
+ frontmatterError: 'Skill index content must start with frontmatter',
+ name: 'no-metadata',
+ }),
+ );
+ });
+
+ it('leaves frontmatterError unset for a well-formed skill index', async () => {
+ const { service } = createService();
+ await service.createSkill({
+ agentId: 'agent-1',
+ bodyMarkdown: skillBody(),
+ description: 'Well formed',
+ name: 'well-formed',
+ title: 'Well Formed',
+ });
+
+ const detail = await service.getSkill({ agentId: 'agent-1', name: 'well-formed' });
+
+ expect(detail).not.toHaveProperty('frontmatterError');
+ });
+
+ it('falls back to the name selector when the agent document id is not a uuid', async () => {
+ const { service } = createService();
+ const created = await service.createSkill({
+ agentId: 'agent-1',
+ bodyMarkdown: skillBody(),
+ description: 'Malformed id lookup',
+ name: 'malformed-id-skill',
+ title: 'Malformed Id Skill',
+ });
+
+ await expect(
+ service.getSkill({
+ agentDocumentId: 'docs_AbCdEf123456',
+ agentId: 'agent-1',
+ name: 'malformed-id-skill',
+ }),
+ ).resolves.toEqual(expect.objectContaining({ bundle: created.bundle, index: created.index }));
+ });
+
+ it('stays not-found when the agent document id is not a uuid and no name is given', async () => {
+ const { service } = createService();
+ await service.createSkill({
+ agentId: 'agent-1',
+ bodyMarkdown: skillBody(),
+ description: 'Malformed id only',
+ name: 'malformed-id-only',
+ title: 'Malformed Id Only',
+ });
+
+ await expect(
+ service.getSkill({ agentDocumentId: 'docs_AbCdEf123456', agentId: 'agent-1' }),
+ ).resolves.toBeUndefined();
+ });
+
it('renames bundle identity and synchronizes index frontmatter content', async () => {
const { agentDocumentModel, documentService, service } = createService();
const created = await service.createSkill({
diff --git a/apps/server/src/services/skillManagement/SkillManagementDocumentService.ts b/apps/server/src/services/skillManagement/SkillManagementDocumentService.ts
index 174a79e0869..a6716c9d311 100644
--- a/apps/server/src/services/skillManagement/SkillManagementDocumentService.ts
+++ b/apps/server/src/services/skillManagement/SkillManagementDocumentService.ts
@@ -2,6 +2,7 @@ import type { LobeChatDatabase } from '@lobechat/database';
import { sha256 } from 'js-sha256';
import { AgentDocumentModel, PolicyLoad } from '@/database/models/agentDocuments';
+import { isUuid } from '@/database/utils/uuid';
import type { AgentDocumentEditorSnapshot } from '../agentDocuments/headlessEditor';
import { createMarkdownEditorSnapshot as createDefaultMarkdownEditorSnapshot } from '../agentDocuments/headlessEditor';
@@ -14,6 +15,7 @@ import {
SKILL_MANAGEMENT_SOURCE,
SKILL_MANAGEMENT_SOURCE_TYPE,
} from './constants';
+import type { SkillFrontmatter } from './frontmatter';
import {
normalizeSkillIndexContent,
parseSkillFrontmatter,
@@ -77,6 +79,38 @@ const buildSkillMetadata = (
skill: { frontmatter },
});
+const readSavedDescription = (index: SkillAgentDocument): string => {
+ const saved = (index.metadata as { skill?: { frontmatter?: { description?: unknown } } } | null)
+ ?.skill?.frontmatter?.description;
+
+ return typeof saved === 'string' ? saved : '';
+};
+
+// A SKILL.md edited outside this service can hold frontmatter no write here
+// would accept. Reads answer from the bundle name and the last saved metadata
+// instead of failing, so one broken index cannot take down the skill list.
+const readIndexFrontmatter = (
+ bundle: SkillAgentDocument,
+ index: SkillAgentDocument,
+): { frontmatter: SkillFrontmatter; frontmatterError?: string } => {
+ try {
+ return { frontmatter: parseSkillFrontmatter(index.content) };
+ } catch (error) {
+ const frontmatterError = error instanceof Error ? error.message : String(error);
+ console.warn(
+ '[skill-management] unreadable SKILL.md frontmatter for skill %s of agent %s: %s',
+ bundle.filename,
+ bundle.agentId,
+ frontmatterError,
+ );
+
+ return {
+ frontmatter: { description: readSavedDescription(index), name: bundle.filename },
+ frontmatterError,
+ };
+ }
+};
+
/**
* Owns managed skill bundle and index document invariants.
*
@@ -156,9 +190,10 @@ export class SkillManagementDocumentService {
// Direct Agent Document VFS writes, including `lb agent space fs`, can create skill-shaped
// bundle/index documents without going through this service. Should we support importing or
// normalizing those compatibility documents here so they become first-class managed skills?
- const sourceDocument = input.sourceAgentDocumentId
- ? await this.agentDocumentModel.findById(input.sourceAgentDocumentId)
- : undefined;
+ const sourceDocument =
+ input.sourceAgentDocumentId && isUuid(input.sourceAgentDocumentId)
+ ? await this.agentDocumentModel.findById(input.sourceAgentDocumentId)
+ : undefined;
if (input.sourceAgentDocumentId && !sourceDocument) {
throw new Error(`Source agent document not found: ${input.sourceAgentDocumentId}`);
@@ -456,7 +491,7 @@ export class SkillManagementDocumentService {
agentId: string,
target: SkillTargetInput,
): Promise<SkillAgentDocument | undefined> {
- if (target.agentDocumentId) {
+ if (target.agentDocumentId && isUuid(target.agentDocumentId)) {
const doc = await this.agentDocumentModel.findById(target.agentDocumentId);
if (doc && doc.agentId === agentId) {
if (doc.fileType === SKILL_BUNDLE_FILE_TYPE) return doc;
@@ -510,12 +545,15 @@ export class SkillManagementDocumentService {
return indexes[0]!;
}
- private toSkillSummary(bundle: SkillAgentDocument, index: SkillAgentDocument): SkillSummary {
- const frontmatter = parseSkillFrontmatter(index.content);
-
+ private toSkillSummary(
+ bundle: SkillAgentDocument,
+ index: SkillAgentDocument,
+ read = readIndexFrontmatter(bundle, index),
+ ): SkillSummary {
return {
bundle: toDocumentRef(bundle),
- description: frontmatter.description,
+ description: read.frontmatter.description,
+ ...(read.frontmatterError && { frontmatterError: read.frontmatterError }),
index: toDocumentRef(index),
name: bundle.filename,
title: bundle.title,
@@ -527,12 +565,12 @@ export class SkillManagementDocumentService {
index: SkillAgentDocument,
options?: { includeContent?: boolean },
): SkillDetail {
- const frontmatter = parseSkillFrontmatter(index.content);
+ const read = readIndexFrontmatter(bundle, index);
return {
- ...this.toSkillSummary(bundle, index),
+ ...this.toSkillSummary(bundle, index, read),
...(options?.includeContent && { content: index.content }),
- frontmatter,
+ frontmatter: read.frontmatter,
};
}
}
diff --git a/apps/server/src/services/skillManagement/types.ts b/apps/server/src/services/skillManagement/types.ts
index 48e997a7808..ff2669167c7 100644
--- a/apps/server/src/services/skillManagement/types.ts
+++ b/apps/server/src/services/skillManagement/types.ts
@@ -34,6 +34,8 @@ export interface SkillSummary {
bundle: SkillDocumentRef;
/** Skill description parsed from index frontmatter. */
description: string;
+ /** Why the SKILL.md frontmatter could not be parsed; set only when name and description fell back to saved values. */
+ frontmatterError?: string;
/** Child index document reference. */
index: SkillDocumentRef;
/** Stable skill bundle name. */
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index fde849264bd..48bf546defb 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -67,6 +67,7 @@
"agentSignal.receipts.revert.unsupported": "Unsupported",
"agentSignal.receipts.skill.detail": "Self-refined how this agent handles similar requests",
"agentSignal.receipts.skill.title": "Auto-learned a new skill",
+ "agentSkillModal.frontmatterInvalid": "This skill's SKILL.md has malformed frontmatter, so its name and description come from the last saved version. Open the document to fix it.",
"agentSkillModal.loadFailed": "Couldn't load this skill",
"agentSkillModal.notFound": "This skill no longer exists. It may have been deleted.",
"agentSkillModal.openDocument": "Open in documents",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index cefd9486ea3..f6b5ca9c111 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -67,6 +67,7 @@
"agentSignal.receipts.revert.unsupported": "不支持撤销",
"agentSignal.receipts.skill.detail": "已自主优化处理相似请求的方式",
"agentSignal.receipts.skill.title": "已自动习得新技能",
+ "agentSkillModal.frontmatterInvalid": "这个技能的 SKILL.md frontmatter 格式有误,名称和描述取自上一次保存的版本。请打开文档修复。",
"agentSkillModal.loadFailed": "技能加载失败",
"agentSkillModal.notFound": "这个技能已不存在,可能已被删除。",
"agentSkillModal.openDocument": "在文档中打开",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index 9f64d2d1a84..b1c55b193b0 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -328,6 +328,8 @@ export default {
'permission.configAccess.groupRoleRestricted':
'Your workspace role cannot configure Agent Groups. You were returned to chat.',
'agentNotFound.title': 'Agent Unavailable',
+ 'agentSkillModal.frontmatterInvalid':
+ "This skill's SKILL.md has malformed frontmatter, so its name and description come from the last saved version. Open the document to fix it.",
'agentSkillModal.loadFailed': "Couldn't load this skill",
'agentSkillModal.notFound': 'This skill no longer exists. It may have been deleted.',
'agentSkillModal.openDocument': 'Open in documents',
diff --git a/src/features/AgentSkillModal/AgentSkillModalContent.tsx b/src/features/AgentSkillModal/AgentSkillModalContent.tsx
index d8e69cc38dc..e5a556abb45 100644
--- a/src/features/AgentSkillModal/AgentSkillModalContent.tsx
+++ b/src/features/AgentSkillModal/AgentSkillModalContent.tsx
@@ -1,6 +1,6 @@
'use client';
-import { Button, Center, Empty } from '@lobehub/ui';
+import { Alert, Button, Center, Empty, Flexbox } from '@lobehub/ui';
import { SkillsIcon } from '@lobehub/ui/icons';
import { FileWarningIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';
@@ -42,7 +42,7 @@ const AgentSkillModalContent = ({ agentDocumentId, agentId }: AgentSkillModalCon
);
}
- return (
+ const viewer = (
<SkillViewer
content={skill.content}
entityId={`agent-skill:${skill.index.documentId}`}
@@ -50,6 +50,17 @@ const AgentSkillModalContent = ({ agentDocumentId, agentId }: AgentSkillModalCon
filesPosition={'start'}
/>
);
+
+ if (!skill.frontmatterError) return viewer;
+
+ return (
+ <Flexbox flex={1} style={{ minHeight: 0 }}>
+ <Flexbox flex={'none'} padding={12}>
+ <Alert showIcon message={t('agentSkillModal.frontmatterInvalid')} type={'warning'} />
+ </Flexbox>
+ {viewer}
+ </Flexbox>
+ );
};
export default AgentSkillModalContent;