MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / resolveAIChatTarget

Function resolveAIChatTarget

apps/cli/src/ai/chat-command.ts:127–147  ·  view source on GitHub ↗
(
  options: Pick<ChatCommandOptions, 'sessionId' | 'aiChatId' | 'question'>,
  deps: Pick<ChatCommandDeps, 'dbManager' | 'aiChatManager'>
)

Source from the content-addressed store, hash-verified

125}
126
127export function resolveAIChatTarget(
128 options: Pick<ChatCommandOptions, 'sessionId' | 'aiChatId' | 'question'>,
129 deps: Pick<ChatCommandDeps, 'dbManager' | 'aiChatManager'>
130): ResolvedAIChatTarget {
131 if (options.aiChatId) {
132 const aiChat = deps.aiChatManager.getAIChat(options.aiChatId)
133 if (!aiChat) {
134 throw new Error(`AI chat ${options.aiChatId} not found`)
135 }
136 if (options.sessionId && options.sessionId !== aiChat.sessionId) {
137 throw new Error(`AI chat ${options.aiChatId} belongs to session ${aiChat.sessionId}, not ${options.sessionId}`)
138 }
139 assertSessionExists(deps.dbManager, aiChat.sessionId)
140 return { sessionId: aiChat.sessionId, aiChatId: aiChat.id, assistantId: aiChat.assistantId, created: false }
141 }
142
143 const sessionId = options.sessionId ?? resolveSingleSessionId(deps.dbManager)
144 assertSessionExists(deps.dbManager, sessionId)
145 const aiChat = deps.aiChatManager.createAIChat(sessionId, buildTitle(options.question), 'general_cn')
146 return { sessionId, aiChatId: aiChat.id, assistantId: aiChat.assistantId, created: true }
147}
148
149export async function runChatTurn(
150 options: Required<Pick<ChatCommandOptions, 'question'>> &

Callers 2

runChatTurnFunction · 0.85

Calls 5

assertSessionExistsFunction · 0.85
resolveSingleSessionIdFunction · 0.85
buildTitleFunction · 0.85
getAIChatMethod · 0.65
createAIChatMethod · 0.65

Tested by

no test coverage detected