split router

This commit is contained in:
Stephen Zhou
2026-01-25 16:11:24 +08:00
parent 55f80c568b
commit bd14023af3
4 changed files with 58 additions and 52 deletions

View File

@ -2,50 +2,4 @@
import { oc } from '@orpc/contract'
import { getChatAppFeedbacksContract } from './api/app.gen'
import { createAnnotationContract, deleteAnnotationContract, getAnnotationListContract, getInitialAnnotationReplySettingsStatusContract, initialAnnotationReplySettingsContract, updateAnnotationContract } from './api/apps.gen'
import { audioToTextContract } from './api/audio-to-text.gen'
import { sendChatMessageContract, stopChatMessageGenerationContract } from './api/chat-messages.gen'
import { deleteConversationContract, getConversationsListContract, getConversationVariablesContract, renameConversationContract } from './api/conversations.gen'
import { previewChatFileContract, uploadChatFileContract } from './api/files.gen'
import { getChatAppInfoContract } from './api/info.gen'
import { getConversationHistoryContract, getSuggestedQuestionsContract, postChatMessageFeedbackContract } from './api/messages.gen'
import { getChatAppMetaContract } from './api/meta.gen'
import { getChatAppParametersContract } from './api/parameters.gen'
import { getChatWebAppSettingsContract } from './api/site.gen'
import { textToAudioChatContract } from './api/text-to-audio.gen'
export const base = oc.$route({ inputStructure: 'detailed', outputStructure: 'detailed' })
export const contracts = {
chatMessages: { send: sendChatMessageContract, stopGeneration: stopChatMessageGenerationContract },
files: { upload: uploadChatFileContract, preview: previewChatFileContract },
messages: {
postFeedback: postChatMessageFeedbackContract,
getSuggestedQuestions: getSuggestedQuestionsContract,
getConversationHistory: getConversationHistoryContract,
},
app: { getFeedbacks: getChatAppFeedbacksContract },
conversations: {
getList: getConversationsListContract,
delete: deleteConversationContract,
rename: renameConversationContract,
getVariables: getConversationVariablesContract,
},
audioToText: { audioToText: audioToTextContract },
textToAudio: { textToAudio: textToAudioChatContract },
info: { get: getChatAppInfoContract },
parameters: { get: getChatAppParametersContract },
meta: { get: getChatAppMetaContract },
site: { getSettings: getChatWebAppSettingsContract },
apps: {
getAnnotationList: getAnnotationListContract,
createAnnotation: createAnnotationContract,
deleteAnnotation: deleteAnnotationContract,
updateAnnotation: updateAnnotationContract,
initialAnnotationReplySettings: initialAnnotationReplySettingsContract,
getInitialAnnotationReplySettingsStatus: getInitialAnnotationReplySettingsStatusContract,
},
}
export type Contracts = typeof contracts

View File

@ -0,0 +1,47 @@
// This file is auto-generated by @hey-api/openapi-ts
import { getChatAppFeedbacksContract } from './api/app.gen'
import { createAnnotationContract, deleteAnnotationContract, getAnnotationListContract, getInitialAnnotationReplySettingsStatusContract, initialAnnotationReplySettingsContract, updateAnnotationContract } from './api/apps.gen'
import { audioToTextContract } from './api/audio-to-text.gen'
import { sendChatMessageContract, stopChatMessageGenerationContract } from './api/chat-messages.gen'
import { deleteConversationContract, getConversationsListContract, getConversationVariablesContract, renameConversationContract } from './api/conversations.gen'
import { previewChatFileContract, uploadChatFileContract } from './api/files.gen'
import { getChatAppInfoContract } from './api/info.gen'
import { getConversationHistoryContract, getSuggestedQuestionsContract, postChatMessageFeedbackContract } from './api/messages.gen'
import { getChatAppMetaContract } from './api/meta.gen'
import { getChatAppParametersContract } from './api/parameters.gen'
import { getChatWebAppSettingsContract } from './api/site.gen'
import { textToAudioChatContract } from './api/text-to-audio.gen'
export const router = {
chatMessages: { send: sendChatMessageContract, stopGeneration: stopChatMessageGenerationContract },
files: { upload: uploadChatFileContract, preview: previewChatFileContract },
messages: {
postFeedback: postChatMessageFeedbackContract,
getSuggestedQuestions: getSuggestedQuestionsContract,
getConversationHistory: getConversationHistoryContract,
},
app: { getFeedbacks: getChatAppFeedbacksContract },
conversations: {
getList: getConversationsListContract,
delete: deleteConversationContract,
rename: renameConversationContract,
getVariables: getConversationVariablesContract,
},
audioToText: { audioToText: audioToTextContract },
textToAudio: { textToAudio: textToAudioChatContract },
info: { get: getChatAppInfoContract },
parameters: { get: getChatAppParametersContract },
meta: { get: getChatAppMetaContract },
site: { getSettings: getChatWebAppSettingsContract },
apps: {
getAnnotationList: getAnnotationListContract,
createAnnotation: createAnnotationContract,
deleteAnnotation: deleteAnnotationContract,
updateAnnotation: updateAnnotationContract,
initialAnnotationReplySettings: initialAnnotationReplySettingsContract,
getInitialAnnotationReplySettingsStatus: getInitialAnnotationReplySettingsStatusContract,
},
}
export type Router = typeof router

View File

@ -74,6 +74,9 @@ function getFilePath(symbol: { meta?: SymbolMeta }): string | undefined {
// Handle orpc plugin symbols
if (meta.pluginName === 'orpc') {
if (meta.resource === 'router') {
return 'orpc/router'
}
if (meta.resource === 'operation') {
const segment = getApiSegment(meta.path)
return `orpc/api/${segment ?? 'common'}`

View File

@ -295,11 +295,12 @@ export const handler: OrpcPlugin['Handler'] = ({ plugin }) => {
plugin.node(contractNode)
}
// Create contracts object export grouped by API path segment
const contractsSymbol = plugin.symbol('contracts', {
// Create contracts object export grouped by API path segment (in separate router file)
const contractsSymbol = plugin.symbol('router', {
exported: true,
meta: {
pluginName: 'orpc',
resource: 'router',
},
})
@ -335,16 +336,17 @@ export const handler: OrpcPlugin['Handler'] = ({ plugin }) => {
.assign(contractsObject)
plugin.node(contractsNode)
// Create type export: export type Contracts = typeof contracts
const contractsTypeSymbol = plugin.symbol('Contracts', {
// Create type export: export type Router = typeof router (in separate router file)
const routerTypeSymbol = plugin.symbol('Router', {
exported: true,
meta: {
pluginName: 'orpc',
resource: 'router',
},
})
const contractsTypeNode = $.type.alias(contractsTypeSymbol)
const routerTypeNode = $.type.alias(routerTypeSymbol)
.export()
.type($.type.query($(contractsSymbol)))
plugin.node(contractsTypeNode)
plugin.node(routerTypeNode)
}