@lobehub/lobehub 2.0.0-next.150 → 2.0.0-next.152
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/changelog/v1.json +18 -0
- package/docs/development/database-schema.dbml +1 -0
- package/locales/ar/auth.json +1 -0
- package/locales/ar/models.json +0 -9
- package/locales/bg-BG/auth.json +1 -0
- package/locales/bg-BG/models.json +0 -9
- package/locales/de-DE/auth.json +1 -0
- package/locales/de-DE/models.json +0 -9
- package/locales/en-US/auth.json +1 -0
- package/locales/en-US/models.json +0 -9
- package/locales/es-ES/auth.json +1 -0
- package/locales/es-ES/models.json +0 -9
- package/locales/fa-IR/auth.json +1 -0
- package/locales/fa-IR/models.json +0 -9
- package/locales/fr-FR/auth.json +1 -0
- package/locales/fr-FR/models.json +0 -9
- package/locales/it-IT/auth.json +1 -0
- package/locales/it-IT/models.json +0 -9
- package/locales/ja-JP/auth.json +1 -0
- package/locales/ja-JP/models.json +0 -9
- package/locales/ko-KR/auth.json +1 -0
- package/locales/ko-KR/models.json +0 -9
- package/locales/nl-NL/auth.json +1 -0
- package/locales/nl-NL/models.json +0 -9
- package/locales/pl-PL/auth.json +1 -0
- package/locales/pl-PL/models.json +0 -9
- package/locales/pt-BR/auth.json +1 -0
- package/locales/pt-BR/models.json +0 -9
- package/locales/ru-RU/auth.json +1 -0
- package/locales/ru-RU/models.json +0 -9
- package/locales/tr-TR/auth.json +1 -0
- package/locales/tr-TR/models.json +0 -9
- package/locales/vi-VN/auth.json +1 -0
- package/locales/vi-VN/models.json +0 -9
- package/locales/zh-CN/auth.json +1 -0
- package/locales/zh-CN/models.json +0 -9
- package/locales/zh-TW/auth.json +1 -0
- package/locales/zh-TW/models.json +0 -9
- package/package.json +3 -1
- package/packages/database/migrations/0057_add_topic_user_memory_extract_status.sql +1 -0
- package/packages/database/migrations/meta/0057_snapshot.json +8426 -0
- package/packages/database/migrations/meta/_journal.json +7 -0
- package/packages/database/src/core/migrations.json +40 -11
- package/packages/database/src/schemas/topic.ts +5 -0
- package/packages/model-runtime/package.json +1 -0
- package/packages/model-runtime/src/utils/asyncifyPolling.ts +127 -104
- package/packages/types/src/topic/topic.ts +12 -0
- package/src/app/(backend)/api/auth/check-user/route.ts +8 -1
- package/src/app/[variants]/(auth)/signin/page.tsx +23 -10
- package/src/auth.ts +2 -1
- package/src/components/NextAuth/AuthIcons.tsx +2 -2
- package/src/server/services/mcp/index.test.ts +4 -20
- package/src/server/services/mcp/index.ts +39 -39
- package/src/store/serverConfig/action.ts +5 -1
- package/src/store/serverConfig/store.ts +2 -0
|
@@ -4,6 +4,7 @@ import { LobeChatPluginApi, LobeChatPluginManifest, PluginSchema } from '@lobehu
|
|
|
4
4
|
import { DeploymentOption } from '@lobehub/market-sdk';
|
|
5
5
|
import { McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
import { TRPCError } from '@trpc/server';
|
|
7
|
+
import retry from 'async-retry';
|
|
7
8
|
import debug from 'debug';
|
|
8
9
|
|
|
9
10
|
import {
|
|
@@ -36,48 +37,47 @@ export class MCPService {
|
|
|
36
37
|
// --- MCP Interaction ---
|
|
37
38
|
|
|
38
39
|
// listTools now accepts MCPClientParams
|
|
39
|
-
async listTools(
|
|
40
|
-
params: MCPClientParams,
|
|
41
|
-
{ retryTime, skipCache }: { retryTime?: number; skipCache?: boolean } = {},
|
|
42
|
-
): Promise<LobeChatPluginApi[]> {
|
|
43
|
-
const client = await this.getClient(params, skipCache); // Get client using params
|
|
40
|
+
async listTools(params: MCPClientParams): Promise<LobeChatPluginApi[]> {
|
|
44
41
|
const loggableParams = this.sanitizeForLogging(params);
|
|
45
|
-
log(`Listing tools using client for params: %O`, loggableParams);
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
const result = await client.listTools();
|
|
49
|
-
log(
|
|
50
|
-
`Tools listed successfully for params: %O, result count: %d`,
|
|
51
|
-
loggableParams,
|
|
52
|
-
result.length,
|
|
53
|
-
);
|
|
54
|
-
return result.map<LobeChatPluginApi>((item) => ({
|
|
55
|
-
// Assuming identifier is the unique name/id
|
|
56
|
-
description: item.description,
|
|
57
|
-
name: item.name,
|
|
58
|
-
parameters: item.inputSchema as PluginSchema,
|
|
59
|
-
}));
|
|
60
|
-
} catch (error) {
|
|
61
|
-
let nextReTryTime = retryTime || 0;
|
|
62
42
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
43
|
+
return retry(
|
|
44
|
+
async (bail, attemptNumber) => {
|
|
45
|
+
// Skip cache on retry attempts
|
|
46
|
+
const skipCache = attemptNumber > 1;
|
|
47
|
+
const client = await this.getClient(params, skipCache);
|
|
48
|
+
log(`Listing tools using client for params: %O (attempt ${attemptNumber})`, loggableParams);
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const result = await client.listTools();
|
|
52
|
+
log(
|
|
53
|
+
`Tools listed successfully for params: %O, result count: %d`,
|
|
54
|
+
loggableParams,
|
|
55
|
+
result.length,
|
|
56
|
+
);
|
|
57
|
+
return result.map<LobeChatPluginApi>((item) => ({
|
|
58
|
+
// Assuming identifier is the unique name/id
|
|
59
|
+
description: item.description,
|
|
60
|
+
name: item.name,
|
|
61
|
+
parameters: item.inputSchema as PluginSchema,
|
|
62
|
+
}));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// Only retry for NoValidSessionId errors
|
|
65
|
+
if ((error as Error).message !== 'NoValidSessionId') {
|
|
66
|
+
console.error(`Error listing tools for params %O:`, loggableParams, error);
|
|
67
|
+
bail(
|
|
68
|
+
new TRPCError({
|
|
69
|
+
cause: error,
|
|
70
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
71
|
+
message: `Error listing tools from MCP server: ${(error as Error).message}`,
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
return []; // This line will never be reached due to bail, but needed for type safety
|
|
75
|
+
}
|
|
76
|
+
throw error; // Rethrow to trigger retry
|
|
68
77
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
console.error(`Error listing tools for params %O:`, loggableParams, error);
|
|
74
|
-
// Propagate a TRPCError for better handling upstream
|
|
75
|
-
throw new TRPCError({
|
|
76
|
-
cause: error,
|
|
77
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
78
|
-
message: `Error listing tools from MCP server: ${(error as Error).message}`,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
78
|
+
},
|
|
79
|
+
{ maxRetryTime: 1000, minTimeout: 100, retries: 3 },
|
|
80
|
+
);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// listTools now accepts MCPClientParams
|
|
@@ -25,7 +25,11 @@ export const createServerConfigSlice: StateCreator<
|
|
|
25
25
|
{
|
|
26
26
|
onSuccess: (data) => {
|
|
27
27
|
set(
|
|
28
|
-
{
|
|
28
|
+
{
|
|
29
|
+
featureFlags: data.serverFeatureFlags,
|
|
30
|
+
serverConfig: data.serverConfig,
|
|
31
|
+
serverConfigInit: true,
|
|
32
|
+
},
|
|
29
33
|
false,
|
|
30
34
|
'initServerConfig',
|
|
31
35
|
);
|
|
@@ -21,12 +21,14 @@ interface ServerConfigState {
|
|
|
21
21
|
isMobile?: boolean;
|
|
22
22
|
segmentVariants?: string;
|
|
23
23
|
serverConfig: GlobalServerConfig;
|
|
24
|
+
serverConfigInit: boolean;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
const initialState: ServerConfigState = {
|
|
27
28
|
featureFlags: mapFeatureFlagsEnvToState(DEFAULT_FEATURE_FLAGS),
|
|
28
29
|
segmentVariants: '',
|
|
29
30
|
serverConfig: { aiProvider: {}, telemetry: {} },
|
|
31
|
+
serverConfigInit: false,
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
// =============== 聚合 createStoreFn ============ //
|