@lobehub/lobehub 2.0.0-next.47 → 2.0.0-next.49
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/.env.example +11 -0
- package/CHANGELOG.md +50 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/apps/desktop/src/main/controllers/AuthCtr.ts +27 -2
- package/apps/desktop/src/main/core/infrastructure/ProtocolManager.ts +9 -4
- package/changelog/v1.json +17 -0
- package/docs/development/database-schema.dbml +2 -0
- package/docs/self-hosting/environment-variables/basic.mdx +49 -3
- package/docs/self-hosting/environment-variables/basic.zh-CN.mdx +49 -4
- package/locales/ar/chat.json +1 -0
- package/locales/ar/discover.json +45 -0
- package/locales/ar/marketAuth.json +42 -0
- package/locales/ar/setting.json +94 -1
- package/locales/ar/topic.json +1 -0
- package/locales/bg-BG/chat.json +1 -0
- package/locales/bg-BG/discover.json +45 -0
- package/locales/bg-BG/marketAuth.json +42 -0
- package/locales/bg-BG/setting.json +94 -1
- package/locales/bg-BG/topic.json +1 -0
- package/locales/de-DE/chat.json +1 -0
- package/locales/de-DE/discover.json +45 -0
- package/locales/de-DE/marketAuth.json +42 -0
- package/locales/de-DE/setting.json +94 -1
- package/locales/de-DE/topic.json +1 -0
- package/locales/en-US/chat.json +1 -0
- package/locales/en-US/discover.json +45 -0
- package/locales/en-US/marketAuth.json +42 -0
- package/locales/en-US/setting.json +94 -1
- package/locales/en-US/topic.json +1 -0
- package/locales/es-ES/chat.json +1 -0
- package/locales/es-ES/discover.json +45 -0
- package/locales/es-ES/marketAuth.json +42 -0
- package/locales/es-ES/setting.json +94 -1
- package/locales/es-ES/topic.json +1 -0
- package/locales/fa-IR/chat.json +1 -0
- package/locales/fa-IR/discover.json +45 -0
- package/locales/fa-IR/marketAuth.json +42 -0
- package/locales/fa-IR/setting.json +94 -1
- package/locales/fa-IR/topic.json +1 -0
- package/locales/fr-FR/chat.json +1 -0
- package/locales/fr-FR/discover.json +45 -0
- package/locales/fr-FR/marketAuth.json +42 -0
- package/locales/fr-FR/setting.json +94 -1
- package/locales/fr-FR/topic.json +1 -0
- package/locales/it-IT/chat.json +1 -0
- package/locales/it-IT/discover.json +45 -0
- package/locales/it-IT/marketAuth.json +42 -0
- package/locales/it-IT/setting.json +94 -1
- package/locales/it-IT/topic.json +1 -0
- package/locales/ja-JP/chat.json +1 -0
- package/locales/ja-JP/discover.json +45 -0
- package/locales/ja-JP/marketAuth.json +42 -0
- package/locales/ja-JP/setting.json +94 -1
- package/locales/ja-JP/topic.json +1 -0
- package/locales/ko-KR/chat.json +1 -0
- package/locales/ko-KR/discover.json +45 -0
- package/locales/ko-KR/marketAuth.json +42 -0
- package/locales/ko-KR/setting.json +94 -1
- package/locales/ko-KR/topic.json +1 -0
- package/locales/nl-NL/chat.json +1 -0
- package/locales/nl-NL/discover.json +45 -0
- package/locales/nl-NL/marketAuth.json +42 -0
- package/locales/nl-NL/setting.json +94 -1
- package/locales/nl-NL/topic.json +1 -0
- package/locales/pl-PL/chat.json +1 -0
- package/locales/pl-PL/discover.json +45 -0
- package/locales/pl-PL/marketAuth.json +42 -0
- package/locales/pl-PL/setting.json +94 -1
- package/locales/pl-PL/topic.json +1 -0
- package/locales/pt-BR/chat.json +1 -0
- package/locales/pt-BR/discover.json +45 -0
- package/locales/pt-BR/marketAuth.json +42 -0
- package/locales/pt-BR/setting.json +94 -1
- package/locales/pt-BR/topic.json +1 -0
- package/locales/ru-RU/chat.json +1 -0
- package/locales/ru-RU/discover.json +45 -0
- package/locales/ru-RU/marketAuth.json +42 -0
- package/locales/ru-RU/setting.json +94 -1
- package/locales/ru-RU/topic.json +1 -0
- package/locales/tr-TR/chat.json +1 -0
- package/locales/tr-TR/discover.json +45 -0
- package/locales/tr-TR/marketAuth.json +42 -0
- package/locales/tr-TR/setting.json +94 -1
- package/locales/tr-TR/topic.json +1 -0
- package/locales/vi-VN/chat.json +1 -0
- package/locales/vi-VN/discover.json +45 -0
- package/locales/vi-VN/marketAuth.json +42 -0
- package/locales/vi-VN/setting.json +94 -1
- package/locales/vi-VN/topic.json +1 -0
- package/locales/zh-CN/chat.json +1 -0
- package/locales/zh-CN/discover.json +45 -0
- package/locales/zh-CN/marketAuth.json +42 -0
- package/locales/zh-CN/setting.json +94 -1
- package/locales/zh-CN/topic.json +1 -0
- package/locales/zh-TW/chat.json +1 -0
- package/locales/zh-TW/discover.json +45 -0
- package/locales/zh-TW/marketAuth.json +42 -0
- package/locales/zh-TW/setting.json +94 -1
- package/locales/zh-TW/topic.json +1 -0
- package/package.json +34 -27
- package/packages/agent-runtime/src/core/InterventionChecker.ts +5 -16
- package/packages/agent-runtime/src/core/__tests__/InterventionChecker.test.ts +27 -80
- package/packages/agent-runtime/src/core/__tests__/runtime.test.ts +32 -13
- package/packages/agent-runtime/src/core/runtime.ts +7 -3
- package/packages/agent-runtime/src/types/event.ts +2 -1
- package/packages/agent-runtime/src/types/generalAgent.ts +1 -0
- package/packages/agent-runtime/src/types/instruction.ts +3 -2
- package/packages/agent-runtime/src/types/state.ts +3 -1
- package/packages/const/src/url.ts +1 -0
- package/packages/conversation-flow/src/transformation/FlatListBuilder.ts +4 -1
- package/packages/database/migrations/0044_add_tool_intervention.sql +1 -0
- package/packages/database/migrations/0044_high_toxin.sql +1 -0
- package/packages/database/migrations/0045_add_tool_intervention.sql +1 -0
- package/packages/database/migrations/meta/0039_snapshot.json +1 -1
- package/packages/database/migrations/meta/0044_snapshot.json +7813 -0
- package/packages/database/migrations/meta/0045_snapshot.json +8431 -0
- package/packages/database/migrations/meta/_journal.json +14 -0
- package/packages/database/src/core/migrations.json +36 -7
- package/packages/database/src/models/message.ts +4 -1
- package/packages/database/src/models/session.ts +42 -1
- package/packages/database/src/schemas/agent.ts +1 -0
- package/packages/database/src/schemas/message.ts +5 -8
- package/packages/electron-client-ipc/src/events/index.ts +6 -1
- package/packages/electron-client-ipc/src/events/remoteServer.ts +8 -0
- package/packages/fetch-sse/package.json +29 -0
- package/packages/{utils/src/fetch → fetch-sse/src}/__tests__/fetchSSE.test.ts +4 -4
- package/packages/{utils/src/fetch → fetch-sse/src}/__tests__/parseError.test.ts +7 -4
- package/packages/{utils/src/fetch → fetch-sse/src}/fetchSSE.ts +2 -2
- package/packages/{utils/src/fetch → fetch-sse/src}/parseError.ts +3 -3
- package/packages/model-bank/src/aiModels/mistral.ts +2 -1
- package/packages/model-runtime/src/core/contextBuilders/anthropic.test.ts +17 -11
- package/packages/model-runtime/src/core/contextBuilders/anthropic.ts +1 -1
- package/packages/model-runtime/src/core/contextBuilders/google.test.ts +1 -1
- package/packages/model-runtime/src/core/contextBuilders/google.ts +3 -6
- package/packages/model-runtime/src/core/contextBuilders/openai.test.ts +4 -2
- package/packages/model-runtime/src/core/contextBuilders/openai.ts +1 -1
- package/packages/model-runtime/src/core/openaiCompatibleFactory/createImage.test.ts +1 -1
- package/packages/model-runtime/src/core/openaiCompatibleFactory/createImage.ts +1 -1
- package/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts +3 -6
- package/packages/model-runtime/src/core/streams/openai/responsesStream.test.ts +1 -1
- package/packages/model-runtime/src/helpers/mergeChatMethodOptions.ts +2 -1
- package/packages/model-runtime/src/providers/aihubmix/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/anthropic/generateObject.test.ts +1 -1
- package/packages/model-runtime/src/providers/anthropic/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/baichuan/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/bedrock/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/bfl/createImage.test.ts +4 -4
- package/packages/model-runtime/src/providers/bfl/createImage.ts +1 -1
- package/packages/model-runtime/src/providers/cloudflare/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/cohere/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/google/createImage.test.ts +2 -2
- package/packages/model-runtime/src/providers/google/createImage.ts +1 -1
- package/packages/model-runtime/src/providers/google/generateObject.test.ts +1 -1
- package/packages/model-runtime/src/providers/google/index.test.ts +1 -4
- package/packages/model-runtime/src/providers/groq/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/hunyuan/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/minimax/createImage.test.ts +1 -1
- package/packages/model-runtime/src/providers/mistral/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/moonshot/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/novita/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/ollama/index.test.ts +43 -32
- package/packages/model-runtime/src/providers/ollama/index.ts +31 -7
- package/packages/model-runtime/src/providers/openrouter/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/perplexity/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/ppio/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/qwen/createImage.test.ts +1 -1
- package/packages/model-runtime/src/providers/search1api/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/siliconcloud/createImage.ts +1 -1
- package/packages/model-runtime/src/providers/taichu/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/wenxin/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/zhipu/index.test.ts +1 -1
- package/packages/model-runtime/src/utils/errorResponse.test.ts +1 -1
- package/packages/obervability-otel/src/node.ts +15 -1
- package/packages/ssrf-safe-fetch/index.browser.ts +14 -0
- package/packages/ssrf-safe-fetch/package.json +8 -1
- package/packages/types/src/discover/assistants.ts +16 -0
- package/packages/types/src/index.ts +1 -0
- package/packages/types/src/message/common/base.ts +2 -2
- package/packages/types/src/message/common/tools.ts +16 -0
- package/packages/types/src/message/db/item.ts +15 -1
- package/packages/types/src/message/ui/chat.ts +7 -1
- package/packages/types/src/message/ui/params.ts +15 -1
- package/packages/types/src/meta.ts +4 -0
- package/packages/types/src/session/agentSession.ts +2 -0
- package/packages/types/src/tool/intervention.ts +2 -3
- package/packages/types/src/user/settings/tool.ts +15 -28
- package/packages/utils/src/imageToBase64.ts +17 -10
- package/packages/utils/src/index.ts +1 -1
- package/renovate.json +28 -11
- package/src/app/(backend)/market/agent/[[...segments]]/route.ts +153 -0
- package/src/app/(backend)/market/oidc/[[...segments]]/route.ts +207 -0
- package/src/app/[variants]/(main)/(mobile)/me/settings/features/useCategory.tsx +1 -0
- package/src/app/[variants]/(main)/_layout/Desktop/SideBar/PinList/index.tsx +4 -2
- package/src/app/[variants]/(main)/chat/components/topic/features/Topic/TopicListContent/TopicItem/TopicContent.tsx +1 -1
- package/src/app/[variants]/(main)/chat/session/features/SessionListContent/List/Item/Actions.tsx +1 -1
- package/src/app/[variants]/(main)/chat/settings/features/AgentInfoDescription/index.tsx +349 -0
- package/src/app/[variants]/(main)/chat/settings/features/HeaderContent.tsx +2 -2
- package/src/app/[variants]/(main)/chat/settings/features/PublishResultModal/index.tsx +64 -0
- package/src/app/[variants]/(main)/chat/settings/features/SmartAgentActionButton/MarketPublishButton.tsx +196 -0
- package/src/app/[variants]/(main)/chat/settings/features/SmartAgentActionButton/MarketPublishModal.tsx +358 -0
- package/src/app/[variants]/(main)/chat/settings/features/SmartAgentActionButton/index.tsx +75 -0
- package/src/app/[variants]/(main)/discover/(detail)/assistant/AssistantDetailPage.tsx +11 -2
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/Client.tsx +12 -1
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Nav.tsx +19 -12
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Overview/TagList.tsx +14 -5
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Overview/index.tsx +2 -0
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Related/index.tsx +14 -5
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/SystemRole/TagList.tsx +14 -5
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/SystemRole/index.tsx +43 -29
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Versions/index.tsx +137 -0
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/index.tsx +2 -0
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Header.tsx +9 -10
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Sidebar/ActionButton/AddAgent.tsx +105 -14
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Sidebar/Related/index.tsx +20 -6
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/StatusPage/index.tsx +113 -0
- package/src/app/[variants]/(main)/discover/(detail)/features/Breadcrumb.tsx +4 -3
- package/src/app/[variants]/(main)/discover/(list)/_layout/Desktop/Nav.tsx +3 -1
- package/src/app/[variants]/(main)/discover/(list)/assistant/AssistantPage.tsx +4 -1
- package/src/app/[variants]/(main)/discover/(list)/assistant/Client.tsx +6 -2
- package/src/app/[variants]/(main)/discover/(list)/assistant/features/Category/index.tsx +7 -3
- package/src/app/[variants]/(main)/discover/(list)/assistant/features/List/Item.tsx +13 -2
- package/src/app/[variants]/(main)/discover/(list)/assistant/features/MarketSourceSwitch.tsx +64 -0
- package/src/app/[variants]/(main)/discover/(list)/features/SortButton/index.tsx +26 -7
- package/src/app/[variants]/(main)/profile/_layout/Desktop/index.tsx +10 -10
- package/src/app/[variants]/(main)/settings/_layout/type.ts +1 -1
- package/src/app/[variants]/(main)/settings/agent/index.tsx +11 -10
- package/src/app/[variants]/(main)/settings/common/index.tsx +1 -1
- package/src/app/[variants]/(main)/settings/page.tsx +13 -10
- package/src/app/[variants]/(main)/settings/provider/ProviderMenu/Item.tsx +35 -36
- package/src/app/[variants]/(main)/settings/provider/ProviderMenu/SearchResult.tsx +5 -5
- package/src/app/[variants]/(main)/settings/provider/_layout/Desktop/Container.tsx +10 -4
- package/src/app/market-auth-callback/layout.tsx +15 -0
- package/src/app/market-auth-callback/page.tsx +196 -0
- package/src/features/AgentSetting/AgentPrompt/TokenTag.tsx +3 -2
- package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +1 -1
- package/src/features/AgentSetting/store/action.ts +1 -1
- package/src/features/ChatInput/ActionBar/STT/browser.tsx +1 -1
- package/src/features/ChatInput/ActionBar/STT/openai.tsx +1 -1
- package/src/features/Conversation/Messages/Group/GroupChildren.tsx +20 -15
- package/src/features/Conversation/Messages/Group/GroupContext.tsx +15 -0
- package/src/features/Conversation/Messages/Group/Tool/Inspector/BuiltinPluginTitle.tsx +2 -4
- package/src/features/Conversation/Messages/Group/Tool/Inspector/ToolTitle.tsx +3 -5
- package/src/features/Conversation/Messages/Group/Tool/Inspector/index.tsx +19 -7
- package/src/features/Conversation/Messages/Group/Tool/Render/Arguments/index.tsx +14 -12
- package/src/features/Conversation/Messages/Group/Tool/Render/Intervention/ApprovalActions.tsx +143 -0
- package/src/features/Conversation/Messages/Group/Tool/Render/Intervention/KeyValueEditor.tsx +213 -0
- package/src/features/Conversation/Messages/Group/Tool/Render/Intervention/ModeSelector.tsx +134 -0
- package/src/features/Conversation/Messages/Group/Tool/Render/Intervention/index.tsx +99 -0
- package/src/features/Conversation/Messages/Group/Tool/Render/RejectedResponse.tsx +45 -0
- package/src/features/Conversation/Messages/Group/Tool/Render/index.tsx +23 -1
- package/src/features/Conversation/Messages/Group/Tool/index.tsx +42 -18
- package/src/features/Conversation/Messages/Group/Tools.tsx +3 -1
- package/src/features/Conversation/components/Extras/TTS/InitPlayer.tsx +1 -1
- package/src/features/PluginTag/PluginStatus.tsx +1 -1
- package/src/hooks/useAgentOwnershipCheck.ts +143 -0
- package/src/instrumentation.node.ts +3 -2
- package/src/layout/AuthProvider/MarketAuth/MarketAuthProvider.tsx +364 -0
- package/src/layout/AuthProvider/MarketAuth/errors.ts +75 -0
- package/src/layout/AuthProvider/MarketAuth/index.ts +2 -0
- package/src/layout/AuthProvider/MarketAuth/oidc.ts +382 -0
- package/src/layout/AuthProvider/MarketAuth/types.ts +64 -0
- package/src/layout/AuthProvider/index.tsx +17 -4
- package/src/locales/default/chat.ts +22 -0
- package/src/locales/default/common.ts +1 -0
- package/src/locales/default/discover.ts +46 -0
- package/src/locales/default/index.ts +2 -0
- package/src/locales/default/marketAuth.ts +42 -0
- package/src/locales/default/setting.ts +94 -1
- package/src/locales/default/topic.ts +1 -0
- package/src/server/globalConfig/genServerAiProviderConfig.test.ts +5 -5
- package/src/server/globalConfig/genServerAiProviderConfig.ts +1 -1
- package/src/server/routers/lambda/market/index.ts +36 -14
- package/src/server/routers/lambda/message.ts +6 -3
- package/src/server/services/discover/index.test.ts +153 -11
- package/src/server/services/discover/index.ts +339 -40
- package/src/server/services/message/index.ts +13 -0
- package/src/server/sitemap.ts +49 -35
- package/src/services/_url.ts +15 -1
- package/src/services/chat/chat.test.ts +5 -5
- package/src/services/chat/clientModelRuntime.test.ts +1 -1
- package/src/services/chat/index.ts +6 -6
- package/src/services/chat/types.ts +1 -2
- package/src/services/discover.ts +16 -5
- package/src/services/electron/remoteServer.ts +8 -1
- package/src/services/marketApi.ts +124 -0
- package/src/services/message/index.ts +17 -2
- package/src/services/models.ts +2 -1
- package/src/store/chat/agents/GeneralChatAgent.ts +141 -24
- package/src/store/chat/agents/__tests__/GeneralChatAgent.test.ts +605 -0
- package/src/store/chat/agents/createAgentExecutors.ts +144 -26
- package/src/store/chat/agents/createToolEngine.ts +22 -0
- package/src/store/chat/slices/aiChat/actions/conversationControl.ts +106 -0
- package/src/store/chat/slices/aiChat/actions/streamingExecutor.ts +54 -26
- package/src/store/chat/slices/message/reducer.ts +2 -1
- package/src/store/chat/slices/plugin/actions/optimisticUpdate.ts +26 -1
- package/src/store/discover/slices/assistant/action.ts +20 -7
- package/src/store/user/slices/settings/action.ts +15 -0
- package/{packages/utils/src → src/utils}/electron/desktopRemoteRPCFetch.ts +1 -1
- package/{packages/utils/src → src/utils/server}/parseModels.ts +1 -2
- package/vitest.config.mts +2 -0
- package/packages/model-runtime/src/utils/imageToBase64.test.ts +0 -91
- package/packages/model-runtime/src/utils/imageToBase64.ts +0 -62
- package/src/app/[variants]/(main)/chat/settings/features/SubmitAgentButton/SubmitAgentModal.tsx +0 -98
- package/src/app/[variants]/(main)/chat/settings/features/SubmitAgentButton/index.tsx +0 -35
- package/src/app/[variants]/(main)/chat/settings/features/SubmitAgentButton/style.ts +0 -47
- /package/packages/{utils/src/fetch → fetch-sse/src}/headers.ts +0 -0
- /package/packages/{utils/src/fetch → fetch-sse/src}/index.ts +0 -0
- /package/packages/{utils/src/fetch → fetch-sse/src}/request.ts +0 -0
- /package/{packages/utils/src → src/utils/server}/__snapshots__/parseModels.test.ts.snap +0 -0
- /package/{packages/utils/src → src/utils/server}/parseModels.test.ts +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @vitest-environment node
|
|
2
|
-
import { LobeOpenAICompatibleRuntime } from '@lobechat/model-runtime';
|
|
3
2
|
import { ModelProvider } from 'model-bank';
|
|
4
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
4
|
|
|
5
|
+
import { LobeOpenAICompatibleRuntime } from '../../core/BaseAI';
|
|
6
6
|
import { testProvider } from '../../providerTestUtils';
|
|
7
7
|
import { LobeWenxinAI, params } from './index';
|
|
8
8
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @vitest-environment node
|
|
2
|
-
import { LobeOpenAICompatibleRuntime } from '@lobechat/model-runtime';
|
|
3
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
3
|
|
|
4
|
+
import { LobeOpenAICompatibleRuntime } from '../../core/BaseAI';
|
|
5
5
|
import { testProvider } from '../../providerTestUtils';
|
|
6
6
|
import { LobeZhipuAI, params } from './index';
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AgentRuntimeErrorType } from '@lobechat/model-runtime';
|
|
2
1
|
import { ChatErrorType } from '@lobechat/types';
|
|
3
2
|
import { describe, expect, it, vi } from 'vitest';
|
|
4
3
|
|
|
4
|
+
import { AgentRuntimeErrorType } from '../types/error';
|
|
5
5
|
import { createErrorResponse } from './errorResponse';
|
|
6
6
|
|
|
7
7
|
describe('createErrorResponse', () => {
|
|
@@ -8,6 +8,7 @@ import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
|
8
8
|
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
|
|
9
9
|
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
10
10
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
|
|
11
|
+
import { env } from 'node:process';
|
|
11
12
|
|
|
12
13
|
export function register(options?: { debug?: true | DiagLogLevel; version?: string }) {
|
|
13
14
|
const attributes: Record<string, string> = {
|
|
@@ -23,13 +24,26 @@ export function register(options?: { debug?: true | DiagLogLevel; version?: stri
|
|
|
23
24
|
);
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
let metricsExporterInterval = 1000;
|
|
28
|
+
if (env.OTEL_METRICS_EXPORTER_INTERVAL) {
|
|
29
|
+
const parsed = parseInt(env.OTEL_METRICS_EXPORTER_INTERVAL, 10);
|
|
30
|
+
if (!isNaN(parsed)) {
|
|
31
|
+
metricsExporterInterval = parsed;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
const sdk = new NodeSDK({
|
|
27
36
|
instrumentations: [
|
|
28
37
|
new PgInstrumentation(),
|
|
29
38
|
new HttpInstrumentation(),
|
|
30
39
|
getNodeAutoInstrumentations(),
|
|
31
40
|
],
|
|
32
|
-
metricReaders: [
|
|
41
|
+
metricReaders: [
|
|
42
|
+
new PeriodicExportingMetricReader({
|
|
43
|
+
exportIntervalMillis: metricsExporterInterval,
|
|
44
|
+
exporter: new OTLPMetricExporter(),
|
|
45
|
+
}),
|
|
46
|
+
],
|
|
33
47
|
resource: resourceFromAttributes(attributes),
|
|
34
48
|
traceExporter: new OTLPTraceExporter(),
|
|
35
49
|
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser version of SSRF-safe fetch
|
|
3
|
+
* In browser environments, we simply use the native fetch API
|
|
4
|
+
* as SSRF attacks are not applicable in client-side code
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Browser-safe fetch implementation
|
|
9
|
+
* Uses native fetch API in browser environments
|
|
10
|
+
*/
|
|
11
|
+
// eslint-disable-next-line no-undef
|
|
12
|
+
export const ssrfSafeFetch = async (url: string, options?: RequestInit): Promise<Response> => {
|
|
13
|
+
return fetch(url, options);
|
|
14
|
+
};
|
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
"name": "ssrf-safe-fetch",
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"private": true,
|
|
5
|
-
"description": "",
|
|
5
|
+
"description": "SSRF-safe fetch implementation with browser/node conditional exports",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"browser": "./index.browser.ts",
|
|
9
|
+
"node": "./index.ts",
|
|
10
|
+
"default": "./index.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
6
13
|
"main": "index.ts",
|
|
7
14
|
"scripts": {
|
|
8
15
|
"test": "vitest run"
|
|
@@ -24,6 +24,7 @@ export enum AssistantSorts {
|
|
|
24
24
|
CreatedAt = 'createdAt',
|
|
25
25
|
Identifier = 'identifier',
|
|
26
26
|
KnowledgeCount = 'knowledgeCount',
|
|
27
|
+
MyOwn = 'myown',
|
|
27
28
|
PluginCount = 'pluginCount',
|
|
28
29
|
Title = 'title',
|
|
29
30
|
TokenUsage = 'tokenUsage',
|
|
@@ -34,6 +35,7 @@ export enum AssistantNavKey {
|
|
|
34
35
|
Overview = 'overview',
|
|
35
36
|
Related = 'related',
|
|
36
37
|
SystemRole = 'systemRole',
|
|
38
|
+
Version = 'version'
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
export interface DiscoverAssistantItem extends Omit<LobeAgentSettings, 'meta'>, MetaData {
|
|
@@ -47,14 +49,18 @@ export interface DiscoverAssistantItem extends Omit<LobeAgentSettings, 'meta'>,
|
|
|
47
49
|
tokenUsage: number;
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
export type AssistantMarketSource = 'legacy' | 'new';
|
|
53
|
+
|
|
50
54
|
export interface AssistantQueryParams {
|
|
51
55
|
category?: string;
|
|
52
56
|
locale?: string;
|
|
53
57
|
order?: 'asc' | 'desc';
|
|
58
|
+
ownerId?: string;
|
|
54
59
|
page?: number;
|
|
55
60
|
pageSize?: number;
|
|
56
61
|
q?: string;
|
|
57
62
|
sort?: AssistantSorts;
|
|
63
|
+
source?: AssistantMarketSource;
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
export interface AssistantListResponse {
|
|
@@ -66,7 +72,17 @@ export interface AssistantListResponse {
|
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
export interface DiscoverAssistantDetail extends DiscoverAssistantItem {
|
|
75
|
+
currentVersion?: string;
|
|
69
76
|
examples?: FewShots;
|
|
70
77
|
related: DiscoverAssistantItem[];
|
|
71
78
|
summary?: string;
|
|
79
|
+
versions?: DiscoverAssistantVersion[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface DiscoverAssistantVersion {
|
|
83
|
+
createdAt?: string;
|
|
84
|
+
isLatest?: boolean;
|
|
85
|
+
isValidated?: boolean;
|
|
86
|
+
status?: 'published' | 'unpublished' | 'archived' | 'deprecated';
|
|
87
|
+
version: string;
|
|
72
88
|
}
|
|
@@ -9,13 +9,13 @@ import { ErrorType } from '../../fetch';
|
|
|
9
9
|
*/
|
|
10
10
|
export interface ChatMessageError {
|
|
11
11
|
body?: any;
|
|
12
|
-
message
|
|
12
|
+
message?: string;
|
|
13
13
|
type: ErrorType | IPluginErrorType | ILobeAgentRuntimeErrorType;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const ChatMessageErrorSchema = z.object({
|
|
17
17
|
body: z.any().optional(),
|
|
18
|
-
message: z.string(),
|
|
18
|
+
message: z.string().optional(),
|
|
19
19
|
type: z.union([z.string(), z.number()]),
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -4,10 +4,22 @@ import { z } from 'zod';
|
|
|
4
4
|
|
|
5
5
|
import { LobeToolRenderType } from '../../tool';
|
|
6
6
|
|
|
7
|
+
// ToolIntervention must be defined first to avoid circular dependency
|
|
8
|
+
export interface ToolIntervention {
|
|
9
|
+
rejectedReason?: string;
|
|
10
|
+
status?: 'pending' | 'approved' | 'rejected' | 'none';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const ToolInterventionSchema = z.object({
|
|
14
|
+
rejectedReason: z.string().optional(),
|
|
15
|
+
status: z.enum(['pending', 'approved', 'rejected', 'none']).optional(),
|
|
16
|
+
});
|
|
17
|
+
|
|
7
18
|
export interface ChatPluginPayload {
|
|
8
19
|
apiName: string;
|
|
9
20
|
arguments: string;
|
|
10
21
|
identifier: string;
|
|
22
|
+
intervention?: ToolIntervention;
|
|
11
23
|
type: LobeToolRenderType;
|
|
12
24
|
}
|
|
13
25
|
|
|
@@ -16,6 +28,7 @@ export interface ChatToolPayload {
|
|
|
16
28
|
arguments: string;
|
|
17
29
|
id: string;
|
|
18
30
|
identifier: string;
|
|
31
|
+
intervention?: ToolIntervention;
|
|
19
32
|
result_msg_id?: string;
|
|
20
33
|
type: LobeToolRenderType;
|
|
21
34
|
}
|
|
@@ -34,7 +47,9 @@ export interface ChatToolResult {
|
|
|
34
47
|
* Chat tool payload with merged execution result
|
|
35
48
|
*/
|
|
36
49
|
export interface ChatToolPayloadWithResult extends ChatToolPayload {
|
|
50
|
+
intervention?: ToolIntervention;
|
|
37
51
|
result?: ChatToolResult;
|
|
52
|
+
result_msg_id?: string;
|
|
38
53
|
}
|
|
39
54
|
|
|
40
55
|
export interface ToolsCallingContext {
|
|
@@ -91,6 +106,7 @@ export const ChatToolPayloadSchema = z.object({
|
|
|
91
106
|
arguments: z.string(),
|
|
92
107
|
id: z.string(),
|
|
93
108
|
identifier: z.string(),
|
|
109
|
+
intervention: ToolInterventionSchema.optional(),
|
|
94
110
|
result_msg_id: z.string().optional(),
|
|
95
111
|
type: z.string(),
|
|
96
112
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
|
|
2
2
|
import { GroundingSearch } from '../../search';
|
|
3
|
-
import { MessageMetadata, ModelReasoning } from '../common';
|
|
3
|
+
import { MessageMetadata, ModelReasoning, ToolIntervention } from '../common';
|
|
4
4
|
|
|
5
5
|
export interface DBMessageItem {
|
|
6
6
|
id: string;
|
|
@@ -33,3 +33,17 @@ export interface DBMessageItem {
|
|
|
33
33
|
updatedAt: Date;
|
|
34
34
|
createdAt: Date;
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
export interface MessagePluginItem {
|
|
38
|
+
id: string;
|
|
39
|
+
toolCallId?: string;
|
|
40
|
+
type: string;
|
|
41
|
+
intervention?: ToolIntervention;
|
|
42
|
+
apiName?: string;
|
|
43
|
+
arguments?: string;
|
|
44
|
+
identifier?: string;
|
|
45
|
+
state?: any;
|
|
46
|
+
error?: any;
|
|
47
|
+
clientId?: string;
|
|
48
|
+
userId: string;
|
|
49
|
+
}
|
|
@@ -8,7 +8,12 @@ import {
|
|
|
8
8
|
ModelReasoning,
|
|
9
9
|
ModelUsage,
|
|
10
10
|
} from '../common';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
ChatPluginPayload,
|
|
13
|
+
ChatToolPayload,
|
|
14
|
+
ChatToolPayloadWithResult,
|
|
15
|
+
ToolIntervention,
|
|
16
|
+
} from '../common/tools';
|
|
12
17
|
import { ChatMessageExtra } from './extra';
|
|
13
18
|
import { ChatFileChunk } from './rag';
|
|
14
19
|
import { ChatVideoItem } from './video';
|
|
@@ -95,6 +100,7 @@ export interface UIChatMessage {
|
|
|
95
100
|
performance?: ModelPerformance;
|
|
96
101
|
plugin?: ChatPluginPayload;
|
|
97
102
|
pluginError?: any;
|
|
103
|
+
pluginIntervention?: ToolIntervention;
|
|
98
104
|
pluginState?: any;
|
|
99
105
|
provider?: string | null;
|
|
100
106
|
/**
|
|
@@ -4,7 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
import { UploadFileItem } from '../../files';
|
|
5
5
|
import { MessageSemanticSearchChunk } from '../../rag';
|
|
6
6
|
import { ChatMessageError, ChatMessageErrorSchema } from '../common/base';
|
|
7
|
-
import { ChatPluginPayload } from '../common/tools';
|
|
7
|
+
import { ChatPluginPayload, ToolInterventionSchema } from '../common/tools';
|
|
8
8
|
import { UIChatMessage } from './chat';
|
|
9
9
|
import { SemanticSearchChunkSchema } from './rag';
|
|
10
10
|
|
|
@@ -148,3 +148,17 @@ export const CreateNewMessageParamsSchema = z
|
|
|
148
148
|
fileChunks: z.array(SemanticSearchChunkSchema).optional(),
|
|
149
149
|
})
|
|
150
150
|
.passthrough();
|
|
151
|
+
|
|
152
|
+
export const UpdateMessagePluginSchema = z.object({
|
|
153
|
+
id: z.string().optional(),
|
|
154
|
+
toolCallId: z.string().optional(),
|
|
155
|
+
type: z.string().optional(),
|
|
156
|
+
intervention: ToolInterventionSchema.optional(),
|
|
157
|
+
apiName: z.string().optional(),
|
|
158
|
+
arguments: z.string().optional(),
|
|
159
|
+
identifier: z.string().optional(),
|
|
160
|
+
state: z.any().optional(),
|
|
161
|
+
error: z.any().optional(),
|
|
162
|
+
clientId: z.string().optional(),
|
|
163
|
+
userId: z.string().optional(),
|
|
164
|
+
});
|
|
@@ -10,6 +10,10 @@ export const LobeMetaDataSchema = z.object({
|
|
|
10
10
|
*/
|
|
11
11
|
backgroundColor: z.string().optional(),
|
|
12
12
|
description: z.string().optional(),
|
|
13
|
+
/**
|
|
14
|
+
* Market agent identifier for published agents
|
|
15
|
+
*/
|
|
16
|
+
marketIdentifier: z.string().optional(),
|
|
13
17
|
|
|
14
18
|
tags: z.array(z.string()).optional(),
|
|
15
19
|
/**
|
|
@@ -5,10 +5,9 @@ import { z } from 'zod';
|
|
|
5
5
|
*/
|
|
6
6
|
export type HumanInterventionPolicy =
|
|
7
7
|
| 'never' // Never intervene, auto-execute
|
|
8
|
-
| '
|
|
9
|
-
| 'first'; // Require intervention on first call only
|
|
8
|
+
| 'require'; // Always require intervention
|
|
10
9
|
|
|
11
|
-
export const HumanInterventionPolicySchema = z.enum(['never', '
|
|
10
|
+
export const HumanInterventionPolicySchema = z.enum(['never', 'require']);
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Argument Matcher for parameter-level filtering
|
|
@@ -1,42 +1,29 @@
|
|
|
1
|
-
import type { HumanInterventionConfig } from '../../tool';
|
|
2
|
-
|
|
3
1
|
export interface UserToolConfig {
|
|
2
|
+
/**
|
|
3
|
+
* Tool approval mode
|
|
4
|
+
* - auto-run: Automatically approve all tools without user consent
|
|
5
|
+
* - allow-list: Only approve tools in the allow list
|
|
6
|
+
* - manual: Require manual approval for each tool execution
|
|
7
|
+
*/
|
|
8
|
+
approvalMode?: 'auto-run' | 'allow-list' | 'manual';
|
|
9
|
+
|
|
4
10
|
dalle: {
|
|
5
11
|
autoGenerate: boolean;
|
|
6
12
|
};
|
|
13
|
+
|
|
7
14
|
/**
|
|
8
|
-
*
|
|
15
|
+
* Tool intervention configuration
|
|
9
16
|
*/
|
|
10
17
|
humanIntervention?: {
|
|
11
18
|
/**
|
|
12
|
-
*
|
|
13
|
-
* Format: "identifier/apiName"
|
|
19
|
+
* Allow list of approved tools (used in 'allow-list' mode)
|
|
20
|
+
* Format: "identifier/apiName"
|
|
14
21
|
*
|
|
15
22
|
* Examples:
|
|
16
23
|
* - "web-browsing/crawlSinglePage"
|
|
17
|
-
* - "bash/bash
|
|
18
|
-
|
|
19
|
-
confirmed?: string[];
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Whether human intervention is enabled globally
|
|
23
|
-
* @default true
|
|
24
|
-
*/
|
|
25
|
-
enabled: boolean;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Per-tool intervention policy overrides
|
|
29
|
-
* Key format: "identifier/apiName"
|
|
30
|
-
*
|
|
31
|
-
* Example:
|
|
32
|
-
* {
|
|
33
|
-
* "web-browsing/crawlSinglePage": "confirm",
|
|
34
|
-
* "bash/bash": [
|
|
35
|
-
* { match: { command: "git add:*" }, policy: "auto" },
|
|
36
|
-
* { policy: "confirm" }
|
|
37
|
-
* ]
|
|
38
|
-
* }
|
|
24
|
+
* - "bash/bash"
|
|
25
|
+
* - "search/search"
|
|
39
26
|
*/
|
|
40
|
-
|
|
27
|
+
allowList?: string[];
|
|
41
28
|
};
|
|
42
29
|
}
|
|
@@ -36,23 +36,30 @@ export const imageToBase64 = ({
|
|
|
36
36
|
return canvas.toDataURL(type);
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Convert image URL to base64
|
|
41
|
+
* Uses SSRF-safe fetch on server-side to prevent SSRF attacks
|
|
42
|
+
*/
|
|
39
43
|
export const imageUrlToBase64 = async (
|
|
40
44
|
imageUrl: string,
|
|
41
45
|
): Promise<{ base64: string; mimeType: string }> => {
|
|
42
46
|
try {
|
|
43
|
-
const
|
|
47
|
+
const isServer = typeof window === 'undefined';
|
|
48
|
+
|
|
49
|
+
// Use SSRF-safe fetch on server-side to prevent SSRF attacks
|
|
50
|
+
const res = isServer
|
|
51
|
+
? await import('ssrf-safe-fetch').then((m) => m.ssrfSafeFetch(imageUrl))
|
|
52
|
+
: await fetch(imageUrl);
|
|
53
|
+
|
|
44
54
|
const blob = await res.blob();
|
|
45
55
|
const arrayBuffer = await blob.arrayBuffer();
|
|
46
56
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
),
|
|
54
|
-
)
|
|
55
|
-
: Buffer.from(arrayBuffer).toString('base64');
|
|
57
|
+
// Client-side uses btoa, server-side uses Buffer
|
|
58
|
+
const base64 = isServer
|
|
59
|
+
? Buffer.from(arrayBuffer).toString('base64')
|
|
60
|
+
: btoa(
|
|
61
|
+
new Uint8Array(arrayBuffer).reduce((data, byte) => data + String.fromCharCode(byte), ''),
|
|
62
|
+
);
|
|
56
63
|
|
|
57
64
|
return { base64, mimeType: blob.type };
|
|
58
65
|
} catch (error) {
|
|
@@ -4,9 +4,9 @@ export * from './detectChinese';
|
|
|
4
4
|
export * from './format';
|
|
5
5
|
export * from './imageToBase64';
|
|
6
6
|
export * from './keyboard';
|
|
7
|
+
export * from './merge';
|
|
7
8
|
export * from './number';
|
|
8
9
|
export * from './object';
|
|
9
|
-
export * from './parseModels';
|
|
10
10
|
export * from './pricing';
|
|
11
11
|
export * from './safeParseJSON';
|
|
12
12
|
export * from './sleep';
|
package/renovate.json
CHANGED
|
@@ -17,22 +17,39 @@
|
|
|
17
17
|
"ignoreDeps": [],
|
|
18
18
|
"labels": ["dependencies"],
|
|
19
19
|
"packageRules": [
|
|
20
|
-
// 1) Pinned deps: isolate (OK to use separate* here because there's no matchUpdateTypes)
|
|
21
20
|
{
|
|
22
|
-
"description": "
|
|
21
|
+
"description": "Un-group tilde ranges",
|
|
23
22
|
"matchManagers": ["npm", "pnpm", "yarn", "bun"],
|
|
24
|
-
"matchCurrentValue": "
|
|
23
|
+
"matchCurrentValue": "^~.*$",
|
|
25
24
|
"groupName": null,
|
|
26
|
-
"
|
|
27
|
-
"separateMajorMinor": true
|
|
25
|
+
"groupSlug": null,
|
|
26
|
+
"separateMajorMinor": true,
|
|
27
|
+
"separateMinorPatch": true
|
|
28
28
|
},
|
|
29
|
-
// 2) Non-pinned deps: Patch versions, grouped together
|
|
30
29
|
{
|
|
31
|
-
"description": "
|
|
30
|
+
"description": "Un-group pinned deps (exact x.y.z)",
|
|
32
31
|
"matchManagers": ["npm", "pnpm", "yarn", "bun"],
|
|
33
|
-
"matchCurrentValue": "
|
|
34
|
-
"groupName":
|
|
35
|
-
"
|
|
32
|
+
"matchCurrentValue": "/^\\d+\\.\\d+\\.\\d+([+-][0-9A-Za-z.-]+)?$/",
|
|
33
|
+
"groupName": null,
|
|
34
|
+
"groupSlug": null,
|
|
35
|
+
"separateMajorMinor": true,
|
|
36
|
+
"separateMinorPatch": true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"description": "Un-group experimental caret ranges (^0.x)",
|
|
40
|
+
"matchManagers": ["npm", "pnpm", "yarn", "bun"],
|
|
41
|
+
"matchCurrentValue": "^\\^0\\.\\d+(\\.\\d+)?([+-][0-9A-Za-z.-]+)?$",
|
|
42
|
+
"groupName": null,
|
|
43
|
+
"separateMajorMinor": true,
|
|
44
|
+
"separateMinorPatch": true
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"description": "Group ^>=1 ranges for patch/minor",
|
|
48
|
+
"matchManagers": ["npm", "pnpm", "yarn", "bun"],
|
|
49
|
+
"matchCurrentValue": "/^\\^[1-9]+[0-9]*(\\.\\d+){0,2}([+-][0-9A-Za-z.-]+)?$/",
|
|
50
|
+
"matchUpdateTypes": ["minor", "patch"],
|
|
51
|
+
"groupName": "all non-major dependencies",
|
|
52
|
+
"groupSlug": "all-non-major-dependencies"
|
|
36
53
|
}
|
|
37
54
|
],
|
|
38
55
|
"postUpdateOptions": ["yarnDedupeHighest"],
|
|
@@ -41,7 +58,7 @@
|
|
|
41
58
|
"rangeStrategy": "bump",
|
|
42
59
|
"rebaseWhen": "conflicted",
|
|
43
60
|
"schedule": "on sunday before 6:00am",
|
|
61
|
+
"separateMinorPatch": false,
|
|
44
62
|
"separateMajorMinor": true,
|
|
45
|
-
"separateMultipleMajor": true,
|
|
46
63
|
"timezone": "UTC"
|
|
47
64
|
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { MarketSDK } from '@lobehub/market-sdk';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
|
|
4
|
+
type RouteContext = {
|
|
5
|
+
params: Promise<{
|
|
6
|
+
segments?: string[];
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const MARKET_BASE_URL = process.env.NEXT_PUBLIC_MARKET_BASE_URL || 'http://127.0.0.1:8787';
|
|
11
|
+
|
|
12
|
+
const extractAccessToken = (req: NextRequest) => {
|
|
13
|
+
const authorization = req.headers.get('authorization');
|
|
14
|
+
if (!authorization) return undefined;
|
|
15
|
+
|
|
16
|
+
const [scheme, token] = authorization.split(' ');
|
|
17
|
+
if (scheme?.toLowerCase() !== 'bearer' || !token) return undefined;
|
|
18
|
+
|
|
19
|
+
return token;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const methodNotAllowed = (methods: string[]) =>
|
|
23
|
+
NextResponse.json(
|
|
24
|
+
{
|
|
25
|
+
error: 'method_not_allowed',
|
|
26
|
+
message: `Allowed methods: ${methods.join(', ')}`,
|
|
27
|
+
status: 'error',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
headers: { Allow: methods.join(', ') },
|
|
31
|
+
status: 405,
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const badRequest = (error: string, message: string) =>
|
|
36
|
+
NextResponse.json(
|
|
37
|
+
{
|
|
38
|
+
error,
|
|
39
|
+
message,
|
|
40
|
+
status: 'error',
|
|
41
|
+
},
|
|
42
|
+
{ status: 400 },
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const notFound = (reason: string) =>
|
|
46
|
+
NextResponse.json(
|
|
47
|
+
{
|
|
48
|
+
error: 'not_found',
|
|
49
|
+
message: reason,
|
|
50
|
+
status: 'error',
|
|
51
|
+
},
|
|
52
|
+
{ status: 404 },
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const handleAgent = async (req: NextRequest, segments: string[]) => {
|
|
56
|
+
const accessToken = extractAccessToken(req);
|
|
57
|
+
const market = new MarketSDK({
|
|
58
|
+
accessToken,
|
|
59
|
+
baseURL: MARKET_BASE_URL,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (segments.length === 0) {
|
|
63
|
+
return notFound('Missing agent action.');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const [action, ...rest] = segments;
|
|
67
|
+
|
|
68
|
+
if (action === 'create') {
|
|
69
|
+
if (req.method !== 'POST') return methodNotAllowed(['POST']);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const payload = await req.json();
|
|
73
|
+
const response = await market.agents.createAgent(payload);
|
|
74
|
+
return NextResponse.json(response);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error('[Market] Failed to create agent:', error);
|
|
77
|
+
return NextResponse.json(
|
|
78
|
+
{
|
|
79
|
+
error: 'create_agent_failed',
|
|
80
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
81
|
+
status: 'error',
|
|
82
|
+
},
|
|
83
|
+
{ status: 500 },
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (action === 'versions') {
|
|
89
|
+
if (rest.length !== 1 || rest[0] !== 'create') {
|
|
90
|
+
return notFound('Requested agent version endpoint is not available.');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (req.method !== 'POST') return methodNotAllowed(['POST']);
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
const payload = await req.json();
|
|
97
|
+
if (typeof payload !== 'object' || payload === null) {
|
|
98
|
+
return badRequest('invalid_payload', 'Request body must be a JSON object.');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const identifier = (payload as { identifier?: string }).identifier;
|
|
102
|
+
if (!identifier) {
|
|
103
|
+
return badRequest('missing_identifier', 'Identifier is required to create agent version.');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const response = await market.agents.createAgentVersion(payload);
|
|
107
|
+
return NextResponse.json(response);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error('[Market] Failed to create agent version:', error);
|
|
110
|
+
return NextResponse.json(
|
|
111
|
+
{
|
|
112
|
+
error: 'create_agent_version_failed',
|
|
113
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
114
|
+
status: 'error',
|
|
115
|
+
},
|
|
116
|
+
{ status: 500 },
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (segments.length === 1) {
|
|
122
|
+
if (req.method !== 'GET') return methodNotAllowed(['GET']);
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
const response = await market.agents.getAgentDetail(action);
|
|
126
|
+
return NextResponse.json(response);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error('[Market] Failed to get agent detail:', error);
|
|
129
|
+
return NextResponse.json(
|
|
130
|
+
{
|
|
131
|
+
error: 'get_agent_detail_failed',
|
|
132
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
133
|
+
status: 'error',
|
|
134
|
+
},
|
|
135
|
+
{ status: 500 },
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return notFound('Requested agent endpoint is not available.');
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const handleProxy = async (req: NextRequest, context: RouteContext) => {
|
|
144
|
+
const { segments } = await context.params;
|
|
145
|
+
const normalizedSegments = segments?.map((segment) => decodeURIComponent(segment)) ?? [];
|
|
146
|
+
|
|
147
|
+
return handleAgent(req, normalizedSegments);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const GET = (req: NextRequest, context: RouteContext) => handleProxy(req, context);
|
|
151
|
+
export const POST = (req: NextRequest, context: RouteContext) => handleProxy(req, context);
|
|
152
|
+
|
|
153
|
+
export const dynamic = 'force-dynamic';
|