fix: show agent messages before workspace lookup and bump to 1.2.24
This commit is contained in:
@@ -3679,9 +3679,13 @@ function LocalPcWorkspaceMockup({
|
||||
const submitAgentRequest = async (content: string, attachments: ChatAttachment[] = []): Promise<void> => {
|
||||
if (agentActionControllerRef.current || agentApplying) return
|
||||
try {
|
||||
const modules = await collectAgentWorkspace([], await readAgentModules())
|
||||
await requestAgentPlan(content, modules, [], {
|
||||
await requestAgentPlan(content, [], [], {
|
||||
attachments,
|
||||
loadInitialContext: async (signal) => {
|
||||
const modules = await readAgentModules()
|
||||
if (signal.aborted) throw new DOMException('Aborted', 'AbortError')
|
||||
return { modules: await collectAgentWorkspace([], modules), runtimeLogs: [] }
|
||||
},
|
||||
loadRequestedContext: loadAgentRequestedContext,
|
||||
executeTool: executeWorkspaceAgentTool,
|
||||
environment: remoteWorkspace ? 'remote' : 'local',
|
||||
|
||||
@@ -316,6 +316,7 @@ export function useAiAgent({ accessToken, studentEmail, courseId, weekNumber, ap
|
||||
options: {
|
||||
showUserMessage?: boolean
|
||||
attachments?: ChatAttachment[]
|
||||
loadInitialContext?: (signal: AbortSignal) => Promise<AgentContext>
|
||||
loadRequestedContext?: (request: AgentContextRequest) => Promise<AgentContext>
|
||||
executeTool?: (request: AgentToolRequest) => Promise<AgentToolResult>
|
||||
environment?: 'local' | 'remote'
|
||||
@@ -346,6 +347,13 @@ export function useAiAgent({ accessToken, studentEmail, courseId, weekNumber, ap
|
||||
}
|
||||
|
||||
try {
|
||||
let initialContext: AgentContext = { modules, runtimeLogs, ...(options.toolResults?.length ? { toolResults: options.toolResults } : {}) }
|
||||
if (options.loadInitialContext) {
|
||||
setActivity('모듈 상태 조회 중')
|
||||
const loaded = await options.loadInitialContext(abortController.signal)
|
||||
if (!currentRequest()) return
|
||||
initialContext = { ...initialContext, ...loaded }
|
||||
}
|
||||
const textAttachments = (options.attachments ?? []).flatMap(file => file.kind === 'image' ? [] : [{ name: file.name, content: file.content }])
|
||||
const imageAttachments: AgentImageReference[] = []
|
||||
for (const file of options.attachments ?? []) {
|
||||
@@ -358,15 +366,15 @@ export function useAiAgent({ accessToken, studentEmail, courseId, weekNumber, ap
|
||||
if (Number.isInteger(weekNumber) && weekNumber >= 1) body.append('week', String(weekNumber))
|
||||
body.append('file', file.file, file.name)
|
||||
const uploaded = await requestApi<AgentImageReference>('/chat/agent/attachments/images', { method: 'POST', body, signal: abortController.signal })
|
||||
if (!currentRequest()) return
|
||||
imageAttachments.push(uploaded)
|
||||
if (options.showUserMessage !== false) updateMessages(current => current.map(item => item.id === userMessage.id ? { ...item, imageAttachments: [...imageAttachments] } : item))
|
||||
if (abortController.signal.aborted) return
|
||||
appendStep({ id: `image-${imageAttachments.length}`, kind: 'image', status: 'ok', name: file.name })
|
||||
}
|
||||
const imageTokens = imageAttachments.map(image => image.token)
|
||||
setActivity('요청 분석 중')
|
||||
const response = await resolveAgentContext({
|
||||
initialContext: { modules, runtimeLogs, ...(options.toolResults?.length ? { toolResults: options.toolResults } : {}) },
|
||||
initialContext,
|
||||
signal: abortController.signal,
|
||||
loadRequestedContext: options.loadRequestedContext,
|
||||
executeTool: options.executeTool,
|
||||
@@ -378,7 +386,7 @@ export function useAiAgent({ accessToken, studentEmail, courseId, weekNumber, ap
|
||||
body: JSON.stringify({ courseId, week: weekNumber, ...selection, request: agentPlanRequestText(request, finalize), ...(options.executeTool ? { toolProtocol: 1, environment: options.environment, workspaceTarget: options.workspaceTarget } : {}), ...(textAttachments.length ? { attachments: textAttachments } : {}), ...(imageTokens.length ? { imageTokens } : {}), ...context })
|
||||
})
|
||||
})
|
||||
if (abortController.signal.aborted) return
|
||||
if (!currentRequest()) return
|
||||
const plan: AgentPlan = {
|
||||
...response.plan,
|
||||
requestedModules: response.plan.requestedModules ?? [],
|
||||
@@ -402,7 +410,7 @@ export function useAiAgent({ accessToken, studentEmail, courseId, weekNumber, ap
|
||||
}])
|
||||
onResponseRef.current?.()
|
||||
} catch (error) {
|
||||
if (abortController.signal.aborted) return
|
||||
if (!currentRequest()) return
|
||||
updateMessages((current) => [...current, {
|
||||
id: `agent-error-${Date.now()}`,
|
||||
role: 'assistant',
|
||||
|
||||
@@ -741,6 +741,7 @@
|
||||
"소스 파일": "Source files",
|
||||
"{{count}}건": "{{count}} items",
|
||||
"요청 분석 중": "Analyzing request",
|
||||
"모듈 상태 조회 중": "Checking module status",
|
||||
"조회 결과 분석 중": "Analyzing retrieved results",
|
||||
"추가 자료 조회 중": "Retrieving additional context",
|
||||
"최종 답변 정리 중": "Preparing the final answer",
|
||||
|
||||
Reference in New Issue
Block a user