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.

💄 style: improve rich text link display (#9816)

Arvin Xuaf33543cba25
diff --git a/package.json b/package.json
index 80abfd5e8a0..41f65e688e8 100644
--- a/package.json
+++ b/package.json
@@ -164,7 +164,7 @@
"@lobehub/charts": "^2.1.2",
"@lobehub/chat-plugin-sdk": "^1.32.4",
"@lobehub/chat-plugins-gateway": "^1.9.0",
- "@lobehub/editor": "^1.16.1",
+ "@lobehub/editor": "^1.20.2",
"@lobehub/icons": "^2.42.0",
"@lobehub/market-sdk": "^0.22.7",
"@lobehub/tts": "^2.0.1",
diff --git a/packages/database/src/models/__tests__/message.test.ts b/packages/database/src/models/__tests__/message.test.ts
index 8ad6471597b..1709bf97e54 100644
--- a/packages/database/src/models/__tests__/message.test.ts
+++ b/packages/database/src/models/__tests__/message.test.ts
@@ -7,10 +7,10 @@ import { uuid } from '@/utils/uuid';
import { getTestDB } from '../../models/__tests__/_util';
import {
- chunks,
- embeddings,
agents,
chatGroups,
+ chunks,
+ embeddings,
fileChunks,
files,
messagePlugins,
@@ -1290,6 +1290,204 @@ describe('MessageModel', () => {
});
});
+ describe('updateMetadata', () => {
+ it('should update metadata for an existing message', async () => {
+ // 创建测试数据
+ await serverDB.insert(messages).values({
+ id: 'msg-with-metadata',
+ userId,
+ role: 'user',
+ content: 'test message',
+ metadata: { existingKey: 'existingValue' },
+ });
+
+ // 调用 updateMetadata 方法
+ await messageModel.updateMetadata('msg-with-metadata', { newKey: 'newValue' });
+
+ // 断言结果
+ const result = await serverDB
+ .select()
+ .from(messages)
+ .where(eq(messages.id, 'msg-with-metadata'));
+
+ expect(result[0].metadata).toEqual({
+ existingKey: 'existingValue',
+ newKey: 'newValue',
+ });
+ });
+
+ it('should merge new metadata with existing metadata using lodash merge behavior', async () => {
+ // 创建测试数据
+ await serverDB.insert(messages).values({
+ id: 'msg-merge-metadata',
+ userId,
+ role: 'assistant',
+ content: 'test message',
+ metadata: {
+ level1: {
+ level2a: 'original',
+ level2b: { level3: 'deep' },
+ },
+ array: [1, 2, 3],
+ },
+ });
+
+ // 调用 updateMetadata 方法
+ await messageModel.updateMetadata('msg-merge-metadata', {
+ level1: {
+ level2a: 'updated',
+ level2c: 'new',
+ },
+ newTopLevel: 'value',
+ });
+
+ // 断言结果 - 应该使用 lodash merge 行为
+ const result = await serverDB
+ .select()
+ .from(messages)
+ .where(eq(messages.id, 'msg-merge-metadata'));
+
+ expect(result[0].metadata).toEqual({
+ level1: {
+ level2a: 'updated',
+ level2b: { level3: 'deep' },
+ level2c: 'new',
+ },
+ array: [1, 2, 3],
+ newTopLevel: 'value',
+ });
+ });
+
+ it('should handle non-existent message IDs', async () => {
+ // 调用 updateMetadata 方法,尝试更新不存在的消息
+ const result = await messageModel.updateMetadata('non-existent-id', { key: 'value' });
+
+ // 断言结果 - 应该返回 undefined
+ expect(result).toBeUndefined();
+ });
+
+ it('should handle empty metadata updates', async () => {
+ // 创建测试数据
+ await serverDB.insert(messages).values({
+ id: 'msg-empty-metadata',
+ userId,
+ role: 'user',
+ content: 'test message',
+ metadata: { originalKey: 'originalValue' },
+ });
+
+ // 调用 updateMetadata 方法,传递空对象
+ await messageModel.updateMetadata('msg-empty-metadata', {});
+
+ // 断言结果 - 原始 metadata 应该保持不变
+ const result = await serverDB
+ .select()
+ .from(messages)
+ .where(eq(messages.id, 'msg-empty-metadata'));
+
+ expect(result[0].metadata).toEqual({ originalKey: 'originalValue' });
+ });
+
+ it('should handle message with null metadata', async () => {
+ // 创建测试数据
+ await serverDB.insert(messages).values({
+ id: 'msg-null-metadata',
+ userId,
+ role: 'user',
+ content: 'test message',
+ metadata: null,
+ });
+
+ // 调用 updateMetadata 方法
+ await messageModel.updateMetadata('msg-null-metadata', { key: 'value' });
+
+ // 断言结果 - 应该创建新的 metadata
+ const result = await serverDB
+ .select()
+ .from(messages)
+ .where(eq(messages.id, 'msg-null-metadata'));
+
+ expect(result[0].metadata).toEqual({ key: 'value' });
+ });
+
+ it('should only update messages belonging to the current user', async () => {
+ // 创建测试数据 - 其他用户的消息
+ await serverDB.insert(messages).values({
+ id: 'msg-other-user',
+ userId: '456',
+ role: 'user',
+ content: 'test message',
+ metadata: { originalKey: 'originalValue' },
+ });
+
+ // 调用 updateMetadata 方法
+ const result = await messageModel.updateMetadata('msg-other-user', {
+ hackedKey: 'hackedValue',
+ });
+
+ // 断言结果 - 应该返回 undefined
+ expect(result).toBeUndefined();
+
+ // 验证原始 metadata 未被修改
+ const dbResult = await serverDB
+ .select()
+ .from(messages)
+ .where(eq(messages.id, 'msg-other-user'));
+
+ expect(dbResult[0].metadata).toEqual({ originalKey: 'originalValue' });
+ });
+
+ it('should handle complex nested metadata updates', async () => {
+ // 创建测试数据
+ await serverDB.insert(messages).values({
+ id: 'msg-complex-metadata',
+ userId,
+ role: 'assistant',
+ content: 'test message',
+ metadata: {
+ config: {
+ settings: {
+ enabled: true,
+ options: ['a', 'b'],
+ },
+ version: 1,
+ },
+ },
+ });
+
+ // 调用 updateMetadata 方法
+ await messageModel.updateMetadata('msg-complex-metadata', {
+ config: {
+ settings: {
+ enabled: false,
+ timeout: 5000,
+ },
+ newField: 'value',
+ },
+ stats: { count: 10 },
+ });
+
+ // 断言结果
+ const result = await serverDB
+ .select()
+ .from(messages)
+ .where(eq(messages.id, 'msg-complex-metadata'));
+
+ expect(result[0].metadata).toEqual({
+ config: {
+ settings: {
+ enabled: false,
+ options: ['a', 'b'],
+ timeout: 5000,
+ },
+ version: 1,
+ newField: 'value',
+ },
+ stats: { count: 10 },
+ });
+ });
+ });
+
describe('updateTranslate', () => {
it('should insert a new record if message does not exist in messageTranslates table', async () => {
// 创建测试数据
diff --git a/packages/database/src/models/message.ts b/packages/database/src/models/message.ts
index 1e76d8201fc..69f10db9936 100644
--- a/packages/database/src/models/message.ts
+++ b/packages/database/src/models/message.ts
@@ -570,6 +570,19 @@ export class MessageModel {
});
};
+ updateMetadata = async (id: string, metadata: Record<string, any>) => {
+ const item = await this.db.query.messages.findFirst({
+ where: and(eq(messages.id, id), eq(messages.userId, this.userId)),
+ });
+
+ if (!item) return;
+
+ return this.db
+ .update(messages)
+ .set({ metadata: merge(item.metadata || {}, metadata) })
+ .where(and(eq(messages.userId, this.userId), eq(messages.id, id)));
+ };
+
updatePluginState = async (id: string, state: Record<string, any>) => {
const item = await this.db.query.messagePlugins.findFirst({
where: eq(messagePlugins.id, id),
diff --git a/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts b/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts
index 246a4c5750e..aa3da936a31 100644
--- a/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts
+++ b/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts
@@ -2048,6 +2048,319 @@ describe('LobeOpenAICompatibleFactory', () => {
});
});
+ describe('handleSchema option', () => {
+ let instanceWithSchemaHandler: any;
+ const mockSchemaHandler = vi.fn((schema: any) => {
+ const filtered: any = {};
+ for (const [key, value] of Object.entries(schema)) {
+ if (key !== 'maxLength' && key !== 'pattern') {
+ filtered[key] = value;
+ }
+ }
+ return filtered;
+ });
+
+ beforeEach(() => {
+ mockSchemaHandler.mockClear();
+ const RuntimeClass = createOpenAICompatibleRuntime({
+ baseURL: 'https://api.test.com',
+ generateObject: {
+ handleSchema: mockSchemaHandler,
+ },
+ provider: 'test-provider',
+ });
+
+ instanceWithSchemaHandler = new RuntimeClass({ apiKey: 'test-key' });
+ });
+
+ it('should apply schema transformation with Responses API', async () => {
+ const mockResponse = {
+ output_text: '{"name":"Alice","age":30}',
+ };
+
+ vi.spyOn(instanceWithSchemaHandler['client'].responses, 'create').mockResolvedValue(
+ mockResponse as any,
+ );
+
+ const payload = {
+ messages: [{ content: 'Extract person', role: 'user' as const }],
+ model: 'gpt-4o',
+ responseApi: true,
+ schema: {
+ name: 'person',
+ schema: {
+ maxLength: 100,
+ pattern: '^[a-z]+$',
+ properties: {
+ age: { type: 'number' },
+ name: { type: 'string' },
+ },
+ type: 'object' as const,
+ },
+ },
+ };
+
+ await instanceWithSchemaHandler.generateObject(payload);
+
+ expect(mockSchemaHandler).toHaveBeenCalledWith(payload.schema.schema);
+ expect(instanceWithSchemaHandler['client'].responses.create).toHaveBeenCalledWith(
+ expect.objectContaining({
+ text: expect.objectContaining({
+ format: expect.objectContaining({
+ schema: {
+ properties: {
+ age: { type: 'number' },
+ name: { type: 'string' },
+ },
+ type: 'object',
+ },
+ }),
+ }),
+ }),
+ expect.any(Object),
+ );
+ });
+
+ it('should apply schema transformation with Chat Completions API', async () => {
+ const mockResponse = {
+ choices: [
+ {
+ message: {
+ content: '{"name":"Bob","age":25}',
+ },
+ },
+ ],
+ };
+
+ vi.spyOn(instanceWithSchemaHandler['client'].chat.completions, 'create').mockResolvedValue(
+ mockResponse as any,
+ );
+
+ const payload = {
+ messages: [{ content: 'Extract person', role: 'user' as const }],
+ model: 'test-model',
+ schema: {
+ name: 'person',
+ schema: {
+ maxLength: 100,
+ pattern: '^[a-z]+$',
+ properties: {
+ age: { type: 'number' },
+ name: { type: 'string' },
+ },
+ type: 'object' as const,
+ },
+ },
+ };
+
+ await instanceWithSchemaHandler.generateObject(payload);
+
+ expect(mockSchemaHandler).toHaveBeenCalledWith(payload.schema.schema);
+ expect(instanceWithSchemaHandler['client'].chat.completions.create).toHaveBeenCalledWith(
+ expect.objectContaining({
+ response_format: expect.objectContaining({
+ json_schema: expect.objectContaining({
+ schema: {
+ properties: {
+ age: { type: 'number' },
+ name: { type: 'string' },
+ },
+ type: 'object',
+ },
+ }),
+ }),
+ }),
+ expect.any(Object),
+ );
+ });
+
+ it('should apply schema transformation with tool calling fallback', async () => {
+ const RuntimeClass = createOpenAICompatibleRuntime({
+ baseURL: 'https://api.test.com',
+ generateObject: {
+ handleSchema: mockSchemaHandler,
+ useToolsCalling: true,
+ },
+ provider: 'test-provider',
+ });
+
+ const instance = new RuntimeClass({ apiKey: 'test-key' });
+
+ const mockResponse = {
+ choices: [
+ {
+ message: {
+ tool_calls: [
+ {
+ function: {
+ arguments: '{"name":"Charlie","age":35}',
+ name: 'person',
+ },
+ type: 'function' as const,
+ },
+ ],
+ },
+ },
+ ],
+ };
+
+ vi.spyOn(instance['client'].chat.completions, 'create').mockResolvedValue(
+ mockResponse as any,
+ );
+
+ const payload = {
+ messages: [{ content: 'Extract person', role: 'user' as const }],
+ model: 'test-model',
+ schema: {
+ name: 'person',
+ schema: {
+ maxLength: 100,
+ pattern: '^[a-z]+$',
+ properties: {
+ age: { type: 'number' },
+ name: { type: 'string' },
+ },
+ type: 'object' as const,
+ },
+ },
+ };
+
+ await instance.generateObject(payload);
+
+ expect(mockSchemaHandler).toHaveBeenCalledWith(payload.schema.schema);
+ expect(instance['client'].chat.completions.create).toHaveBeenCalledWith(
+ expect.objectContaining({
+ tools: [
+ expect.objectContaining({
+ function: expect.objectContaining({
+ parameters: {
+ properties: {
+ age: { type: 'number' },
+ name: { type: 'string' },
+ },
+ type: 'object',
+ },
+ }),
+ }),
+ ],
+ }),
+ expect.any(Object),
+ );
+ });
+
+ it('should not apply schema transformation when handleSchema is not configured', async () => {
+ const RuntimeClass = createOpenAICompatibleRuntime({
+ baseURL: 'https://api.test.com',
+ provider: 'test-provider',
+ });
+
+ const instance = new RuntimeClass({ apiKey: 'test-key' });
+
+ const mockResponse = {
+ choices: [
+ {
+ message: {
+ content: '{"name":"Test"}',
+ },
+ },
+ ],
+ };
+
+ vi.spyOn(instance['client'].chat.completions, 'create').mockResolvedValue(
+ mockResponse as any,
+ );
+
+ const payload = {
+ messages: [{ content: 'Extract data', role: 'user' as const }],
+ model: 'test-model',
+ schema: {
+ name: 'test',
+ schema: {
+ maxLength: 100,
+ properties: {
+ name: { type: 'string' },
+ },
+ type: 'object' as const,
+ },
+ },
+ };
+
+ await instance.generateObject(payload);
+
+ expect(instance['client'].chat.completions.create).toHaveBeenCalledWith(
+ expect.objectContaining({
+ response_format: expect.objectContaining({
+ json_schema: expect.objectContaining({
+ schema: {
+ maxLength: 100,
+ properties: {
+ name: { type: 'string' },
+ },
+ type: 'object',
+ },
+ }),
+ }),
+ }),
+ expect.any(Object),
+ );
+ });
+
+ it('should preserve original schema properties while filtering', async () => {
+ const mockResponse = {
+ output_text: '{"result":"success"}',
+ };
+
+ vi.spyOn(instanceWithSchemaHandler['client'].responses, 'create').mockResolvedValue(
+ mockResponse as any,
+ );
+
+ const payload = {
+ messages: [{ content: 'Test', role: 'user' as const }],
+ model: 'gpt-4o',
+ responseApi: true,
+ schema: {
+ description: 'Test schema',
+ name: 'test',
+ schema: {
+ description: 'Inner schema description',
+ maxLength: 100,
+ pattern: '^test$',
+ properties: {
+ result: { type: 'string' },
+ },
+ required: ['result'],
+ type: 'object' as const,
+ },
+ strict: true,
+ },
+ };
+
+ await instanceWithSchemaHandler.generateObject(payload);
+
+ expect(mockSchemaHandler).toHaveBeenCalledWith(payload.schema.schema);
+ expect(instanceWithSchemaHandler['client'].responses.create).toHaveBeenCalledWith(
+ expect.objectContaining({
+ text: expect.objectContaining({
+ format: expect.objectContaining({
+ description: 'Test schema',
+ name: 'test',
+ schema: {
+ description: 'Inner schema description',
+ properties: {
+ result: { type: 'string' },
+ },
+ required: ['result'],
+ type: 'object',
+ },
+ strict: true,
+ }),
+ }),
+ }),
+ expect.any(Object),
+ );
+ });
+ });
+
describe('tool calling fallback', () => {
let instanceWithToolCalling: any;
diff --git a/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts b/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts
index c76f79cbf47..83897ad0db4 100644
--- a/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts
+++ b/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts
@@ -119,6 +119,10 @@ export interface OpenAICompatibleFactoryOptions<T extends Record<string, any> =
invalidAPIKey: ILobeAgentRuntimeErrorType;
};
generateObject?: {
+ /**
+ * Transform schema before sending to the provider (e.g., filter unsupported properties)
+ */
+ handleSchema?: (schema: any) => any;
/**
* If true, route generateObject requests to Responses API path directly
*/
@@ -454,12 +458,19 @@ export const createOpenAICompatibleRuntime = <T extends Record<string, any> = an
// Use tool calling fallback if configured
if (generateObjectConfig?.useToolsCalling) {
log('using tool calling fallback for structured output');
+
+ // Apply schema transformation if configured
+ const processedSchema = generateObjectConfig.handleSchema
+ ? { ...schema, schema: generateObjectConfig.handleSchema(schema.schema) }
+ : schema;
+
const tool: ChatCompletionTool = {
function: {
description:
- schema.description || 'Generate structured output according to the provided schema',
- name: schema.name || 'structured_output',
- parameters: schema.schema,
+ processedSchema.description ||
+ 'Generate structured output according to the provided schema',
+ name: processedSchema.name || 'structured_output',
+ parameters: processedSchema.schema,
},
type: 'function',
};
@@ -531,13 +542,18 @@ export const createOpenAICompatibleRuntime = <T extends Record<string, any> = an
return false;
})();
+ // Apply schema transformation if configured
+ const processedSchema = generateObjectConfig?.handleSchema
+ ? { ...schema, schema: generateObjectConfig.handleSchema(schema.schema) }
+ : schema;
+
if (shouldUseResponses) {
log('calling responses.create for structured output');
const res = await this.client!.responses.create(
{
input: messages,
model,
- text: { format: { strict: true, type: 'json_schema', ...schema } },
+ text: { format: { strict: true, type: 'json_schema', ...processedSchema } },
user: options?.user,
},
{ headers: options?.headers, signal: options?.signal },
@@ -561,7 +577,7 @@ export const createOpenAICompatibleRuntime = <T extends Record<string, any> = an
{
messages,
model,
- response_format: { json_schema: schema, type: 'json_schema' },
+ response_format: { json_schema: processedSchema, type: 'json_schema' },
user: options?.user,
},
{ headers: options?.headers, signal: options?.signal },
diff --git a/packages/model-runtime/src/providers/groq/index.test.ts b/packages/model-runtime/src/providers/groq/index.test.ts
index d9034cab81e..b359db7c0be 100644
--- a/packages/model-runtime/src/providers/groq/index.test.ts
+++ b/packages/model-runtime/src/providers/groq/index.test.ts
@@ -33,6 +33,455 @@ afterEach(() => {
});
describe('LobeGroq - custom features', () => {
+ describe('filterAdvancedFields', () => {
+ const filterAdvancedFields = params.generateObject!.handleSchema!;
+
+ it('should filter out maxItems from schema', () => {
+ const schema = {
+ items: { type: 'string' },
+ maxItems: 5,
+ type: 'array',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ items: { type: 'string' },
+ type: 'array',
+ });
+ expect(result.maxItems).toBeUndefined();
+ });
+
+ it('should filter out minItems from schema', () => {
+ const schema = {
+ items: { type: 'string' },
+ minItems: 2,
+ type: 'array',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ items: { type: 'string' },
+ type: 'array',
+ });
+ expect(result.minItems).toBeUndefined();
+ });
+
+ it('should filter out maxLength from schema', () => {
+ const schema = {
+ maxLength: 100,
+ type: 'string',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'string',
+ });
+ expect(result.maxLength).toBeUndefined();
+ });
+
+ it('should filter out minLength from schema', () => {
+ const schema = {
+ minLength: 5,
+ type: 'string',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'string',
+ });
+ expect(result.minLength).toBeUndefined();
+ });
+
+ it('should filter out pattern from schema', () => {
+ const schema = {
+ pattern: '^[a-z]+$',
+ type: 'string',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'string',
+ });
+ expect(result.pattern).toBeUndefined();
+ });
+
+ it('should filter out format from schema', () => {
+ const schema = {
+ format: 'email',
+ type: 'string',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'string',
+ });
+ expect(result.format).toBeUndefined();
+ });
+
+ it('should filter out uniqueItems from schema', () => {
+ const schema = {
+ items: { type: 'number' },
+ type: 'array',
+ uniqueItems: true,
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ items: { type: 'number' },
+ type: 'array',
+ });
+ expect(result.uniqueItems).toBeUndefined();
+ });
+
+ it('should filter out maxProperties from schema', () => {
+ const schema = {
+ maxProperties: 10,
+ type: 'object',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'object',
+ });
+ expect(result.maxProperties).toBeUndefined();
+ });
+
+ it('should filter out minProperties from schema', () => {
+ const schema = {
+ minProperties: 2,
+ type: 'object',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'object',
+ });
+ expect(result.minProperties).toBeUndefined();
+ });
+
+ it('should filter out multipleOf from schema', () => {
+ const schema = {
+ multipleOf: 5,
+ type: 'number',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'number',
+ });
+ expect(result.multipleOf).toBeUndefined();
+ });
+
+ it('should filter out maximum from schema', () => {
+ const schema = {
+ maximum: 100,
+ type: 'number',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'number',
+ });
+ expect(result.maximum).toBeUndefined();
+ });
+
+ it('should filter out minimum from schema', () => {
+ const schema = {
+ minimum: 0,
+ type: 'number',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'number',
+ });
+ expect(result.minimum).toBeUndefined();
+ });
+
+ it('should filter out exclusiveMaximum from schema', () => {
+ const schema = {
+ exclusiveMaximum: 100,
+ type: 'number',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'number',
+ });
+ expect(result.exclusiveMaximum).toBeUndefined();
+ });
+
+ it('should filter out exclusiveMinimum from schema', () => {
+ const schema = {
+ exclusiveMinimum: 0,
+ type: 'number',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'number',
+ });
+ expect(result.exclusiveMinimum).toBeUndefined();
+ });
+
+ it('should filter out multiple unsupported properties at once', () => {
+ const schema = {
+ format: 'email',
+ maxLength: 100,
+ minLength: 5,
+ pattern: '^[a-z]+$',
+ type: 'string',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ type: 'string',
+ });
+ expect(result.maxLength).toBeUndefined();
+ expect(result.minLength).toBeUndefined();
+ expect(result.pattern).toBeUndefined();
+ expect(result.format).toBeUndefined();
+ });
+
+ it('should preserve supported properties', () => {
+ const schema = {
+ description: 'A test field',
+ enum: ['a', 'b', 'c'],
+ maxLength: 10,
+ type: 'string',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ description: 'A test field',
+ enum: ['a', 'b', 'c'],
+ type: 'string',
+ });
+ });
+
+ it('should handle nested objects recursively', () => {
+ const schema = {
+ properties: {
+ email: {
+ format: 'email',
+ maxLength: 100,
+ type: 'string',
+ },
+ name: {
+ minLength: 2,
+ type: 'string',
+ },
+ },
+ type: 'object',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ properties: {
+ email: {
+ type: 'string',
+ },
+ name: {
+ type: 'string',
+ },
+ },
+ type: 'object',
+ });
+ });
+
+ it('should handle deeply nested objects', () => {
+ const schema = {
+ properties: {
+ user: {
+ properties: {
+ address: {
+ maxProperties: 5,
+ properties: {
+ city: {
+ maxLength: 50,
+ type: 'string',
+ },
+ zip: {
+ pattern: '^\\d{5}$',
+ type: 'string',
+ },
+ },
+ type: 'object',
+ },
+ name: {
+ minLength: 1,
+ type: 'string',
+ },
+ },
+ type: 'object',
+ },
+ },
+ type: 'object',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ properties: {
+ user: {
+ properties: {
+ address: {
+ properties: {
+ city: {
+ type: 'string',
+ },
+ zip: {
+ type: 'string',
+ },
+ },
+ type: 'object',
+ },
+ name: {
+ type: 'string',
+ },
+ },
+ type: 'object',
+ },
+ },
+ type: 'object',
+ });
+ });
+
+ it('should handle arrays in schema', () => {
+ const schema = {
+ items: {
+ maxLength: 50,
+ type: 'string',
+ },
+ maxItems: 10,
+ minItems: 1,
+ type: 'array',
+ uniqueItems: true,
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ items: {
+ type: 'string',
+ },
+ type: 'array',
+ });
+ });
+
+ it('should handle arrays of objects', () => {
+ const schema = {
+ items: {
+ properties: {
+ age: {
+ maximum: 120,
+ minimum: 0,
+ type: 'number',
+ },
+ name: {
+ maxLength: 100,
+ type: 'string',
+ },
+ },
+ type: 'object',
+ },
+ type: 'array',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ items: {
+ properties: {
+ age: {
+ type: 'number',
+ },
+ name: {
+ type: 'string',
+ },
+ },
+ type: 'object',
+ },
+ type: 'array',
+ });
+ });
+
+ it('should handle null values', () => {
+ const result = filterAdvancedFields(null);
+ expect(result).toBeNull();
+ });
+
+ it('should handle primitive values', () => {
+ expect(filterAdvancedFields('string')).toBe('string');
+ expect(filterAdvancedFields(123)).toBe(123);
+ expect(filterAdvancedFields(true)).toBe(true);
+ });
+
+ it('should handle empty objects', () => {
+ const schema = {};
+ const result = filterAdvancedFields(schema);
+ expect(result).toEqual({});
+ });
+
+ it('should preserve required and other common fields', () => {
+ const schema = {
+ additionalProperties: false,
+ description: 'A person object',
+ maxProperties: 10,
+ properties: {
+ age: {
+ description: 'Person age',
+ maximum: 150,
+ type: 'number',
+ },
+ name: {
+ description: 'Person name',
+ maxLength: 100,
+ type: 'string',
+ },
+ },
+ required: ['name', 'age'],
+ type: 'object',
+ };
+
+ const result = filterAdvancedFields(schema);
+
+ expect(result).toEqual({
+ additionalProperties: false,
+ description: 'A person object',
+ properties: {
+ age: {
+ description: 'Person age',
+ type: 'number',
+ },
+ name: {
+ description: 'Person name',
+ type: 'string',
+ },
+ },
+ required: ['name', 'age'],
+ type: 'object',
+ });
+ });
+ });
+
describe('Debug Configuration', () => {
it('should disable debug by default', () => {
delete process.env.DEBUG_GROQ_CHAT_COMPLETION;
diff --git a/packages/model-runtime/src/providers/groq/index.ts b/packages/model-runtime/src/providers/groq/index.ts
index f6843ae9f41..f78e734be2d 100644
--- a/packages/model-runtime/src/providers/groq/index.ts
+++ b/packages/model-runtime/src/providers/groq/index.ts
@@ -13,6 +13,49 @@ export interface GroqModelCard {
id: string;
}
+/**
+ * Filter out advanced JSON Schema properties that Groq doesn't support
+ */
+const filterAdvancedFields = (schema: any): any => {
+ if (typeof schema !== 'object' || schema === null) {
+ return schema;
+ }
+
+ if (Array.isArray(schema)) {
+ return schema.map(filterAdvancedFields);
+ }
+
+ const filtered: any = {};
+
+ // List of advanced properties to filter out
+ const unsupportedProperties = new Set([
+ 'maxItems',
+ 'minItems',
+ 'maxLength',
+ 'minLength',
+ 'pattern',
+ 'format',
+ 'uniqueItems',
+ 'maxProperties',
+ 'minProperties',
+ 'multipleOf',
+ 'maximum',
+ 'minimum',
+ 'exclusiveMaximum',
+ 'exclusiveMinimum',
+ ]);
+
+ for (const [key, value] of Object.entries(schema)) {
+ if (unsupportedProperties.has(key)) {
+ continue;
+ }
+
+ filtered[key] = filterAdvancedFields(value);
+ }
+
+ return filtered;
+};
+
export const params = {
baseURL: 'https://api.groq.com/openai/v1',
chatCompletion: {
@@ -40,6 +83,9 @@ export const params = {
debug: {
chatCompletion: () => process.env.DEBUG_GROQ_CHAT_COMPLETION === '1',
},
+ generateObject: {
+ handleSchema: filterAdvancedFields,
+ },
models: async ({ client }) => {
const { LOBE_DEFAULT_MODEL_LIST } = await import('model-bank');
diff --git a/src/features/ChatInput/InputEditor/index.tsx b/src/features/ChatInput/InputEditor/index.tsx
index 69ff8667918..ee97969d3a5 100644
--- a/src/features/ChatInput/InputEditor/index.tsx
+++ b/src/features/ChatInput/InputEditor/index.tsx
@@ -7,6 +7,7 @@ import {
ReactCodePlugin,
ReactCodeblockPlugin,
ReactHRPlugin,
+ ReactLinkHighlightPlugin,
ReactListPlugin,
ReactMathPlugin,
ReactTablePlugin,
@@ -92,6 +93,7 @@ const InputEditor = memo<{ defaultRows?: number }>(({ defaultRows = 2 }) => {
ReactCodePlugin,
ReactCodeblockPlugin,
ReactHRPlugin,
+ ReactLinkHighlightPlugin,
ReactTablePlugin,
Editor.withProps(ReactMathPlugin, {
renderComp: expand
diff --git a/src/server/globalConfig/parseSystemAgent.ts b/src/server/globalConfig/parseSystemAgent.ts
index dd63ac413c1..f12514b08de 100644
--- a/src/server/globalConfig/parseSystemAgent.ts
+++ b/src/server/globalConfig/parseSystemAgent.ts
@@ -3,6 +3,8 @@ import { UserSystemAgentConfig } from '@/types/user/settings';
const protectedKeys = Object.keys(DEFAULT_SYSTEM_AGENT_CONFIG);
+const defaultTrueLey = new Set(['queryRewrite', 'autoSuggestion']);
+
export const parseSystemAgent = (envString: string = ''): Partial<UserSystemAgentConfig> => {
if (!envString) return {};
@@ -38,7 +40,7 @@ export const parseSystemAgent = (envString: string = ''): Partial<UserSystemAgen
if (protectedKeys.includes(key)) {
config[key as keyof UserSystemAgentConfig] = {
- enabled: key === 'queryRewrite' ? true : undefined,
+ enabled: defaultTrueLey.has(key) ? true : undefined,
model: model.trim(),
provider: provider.trim(),
} as any;
@@ -53,7 +55,7 @@ export const parseSystemAgent = (envString: string = ''): Partial<UserSystemAgen
for (const key of protectedKeys) {
if (!config[key as keyof UserSystemAgentConfig]) {
config[key as keyof UserSystemAgentConfig] = {
- enabled: key === 'queryRewrite' ? true : undefined,
+ enabled: defaultTrueLey.has(key) ? true : undefined,
model: defaultSetting.model,
provider: defaultSetting.provider,
} as any;
diff --git a/src/server/routers/lambda/message.ts b/src/server/routers/lambda/message.ts
index e9ccd0e5d4d..8bf64f967f7 100644
--- a/src/server/routers/lambda/message.ts
+++ b/src/server/routers/lambda/message.ts
@@ -198,6 +198,17 @@ export const messageRouter = router({
await ctx.messageModel.updateMessageRAG(input.id, input.value);
}),
+ updateMetadata: messageProcedure
+ .input(
+ z.object({
+ id: z.string(),
+ value: z.object({}).passthrough(),
+ }),
+ )
+ .mutation(async ({ input, ctx }) => {
+ return ctx.messageModel.updateMetadata(input.id, input.value);
+ }),
+
updatePluginError: messageProcedure
.input(
z.object({