mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 21:04:59 +00:00
fix(agent): use current comment ID for media tools in subsequent turns of a session
This commit is contained in:
@@ -55,6 +55,7 @@ async function executeAgentPrompt(params: {
|
|||||||
agentsInstruction: string
|
agentsInstruction: string
|
||||||
sessionId?: string
|
sessionId?: string
|
||||||
userId?: string
|
userId?: string
|
||||||
|
userCommentId?: string | null
|
||||||
tools?: AgentTool[]
|
tools?: AgentTool[]
|
||||||
context: AgentExecutionContext
|
context: AgentExecutionContext
|
||||||
}): Promise<{ text: string; usage: Usage; sessionId: string }> {
|
}): Promise<{ text: string; usage: Usage; sessionId: string }> {
|
||||||
@@ -109,6 +110,7 @@ If you need to create files in the local filesystem (for example, a temporary fi
|
|||||||
allowedDomains,
|
allowedDomains,
|
||||||
sessionId: params.sessionId,
|
sessionId: params.sessionId,
|
||||||
userId: params.userId,
|
userId: params.userId,
|
||||||
|
userCommentId: params.userCommentId,
|
||||||
customTools: params.tools || [],
|
customTools: params.tools || [],
|
||||||
providers: dbProviders.map((p) => ({
|
providers: dbProviders.map((p) => ({
|
||||||
name: p.name,
|
name: p.name,
|
||||||
@@ -197,6 +199,7 @@ export interface AgentChatParams {
|
|||||||
agentsInstruction?: string
|
agentsInstruction?: string
|
||||||
sessionId: string
|
sessionId: string
|
||||||
userId?: string
|
userId?: string
|
||||||
|
userCommentId?: string | null
|
||||||
explicitMention?: boolean
|
explicitMention?: boolean
|
||||||
context: AgentExecutionContext
|
context: AgentExecutionContext
|
||||||
}
|
}
|
||||||
@@ -213,6 +216,7 @@ export async function agentChatActivity(params: AgentChatParams) {
|
|||||||
agentsInstruction: params.agentsInstruction || '',
|
agentsInstruction: params.agentsInstruction || '',
|
||||||
sessionId,
|
sessionId,
|
||||||
userId: params.userId,
|
userId: params.userId,
|
||||||
|
userCommentId: params.userCommentId,
|
||||||
context: params.context,
|
context: params.context,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import { DatabaseSessionStorage } from './database-session-storage'
|
|||||||
import { agentService } from '@shumai/core/src/agent/agent'
|
import { agentService } from '@shumai/core/src/agent/agent'
|
||||||
import { createAgentSession } from './index'
|
import { createAgentSession } from './index'
|
||||||
import * as sandboxedBashModule from './tools/sandboxed-bash'
|
import * as sandboxedBashModule from './tools/sandboxed-bash'
|
||||||
|
import * as analyzeImageModule from './tools/analyze-image'
|
||||||
|
import * as screenshotModule from './tools/screenshot'
|
||||||
|
|
||||||
describe('DatabaseSessionStorage', () => {
|
describe('DatabaseSessionStorage', () => {
|
||||||
setupTestDbHooks()
|
setupTestDbHooks()
|
||||||
@@ -387,4 +389,55 @@ describe('DatabaseSessionStorage', () => {
|
|||||||
expect(entries[1].id).toBe('01B')
|
expect(entries[1].id).toBe('01B')
|
||||||
expect(entries[2].id).toBe('01C')
|
expect(entries[2].id).toBe('01C')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should use the current comment ID for media tools in subsequent turns', async () => {
|
||||||
|
const { agent, user, team } = await setupTestData()
|
||||||
|
|
||||||
|
// Create a project and asset to satisfy FK constraints
|
||||||
|
const project = await prisma.project.create({
|
||||||
|
data: { name: 'Test Project', teamId: team.id },
|
||||||
|
})
|
||||||
|
const asset = await prisma.asset.create({
|
||||||
|
data: {
|
||||||
|
id: 'asset-123',
|
||||||
|
name: 'test.png',
|
||||||
|
type: 'file',
|
||||||
|
mediaType: 'image/png',
|
||||||
|
projectId: project.id,
|
||||||
|
status: 'uploaded',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// 1. Create a session with an original comment ID and an asset ID using the storage class
|
||||||
|
const initialStorage = await DatabaseSessionStorage.create({
|
||||||
|
agentId: agent.id,
|
||||||
|
userId: user.id,
|
||||||
|
cwd: '/test/cwd',
|
||||||
|
assetId: asset.id,
|
||||||
|
userCommentId: 'original-comment-123',
|
||||||
|
})
|
||||||
|
const sessionId = initialStorage.sessionId
|
||||||
|
|
||||||
|
// 2. Spy on media tools constructors
|
||||||
|
const createAnalyzeImageToolSpy = vi.spyOn(analyzeImageModule, 'createAnalyzeImageTool')
|
||||||
|
const createScreenshotToolSpy = vi.spyOn(screenshotModule, 'createScreenshotTool')
|
||||||
|
|
||||||
|
// 3. Resume the session via createAgentSession with a NEW comment ID
|
||||||
|
await createAgentSession({
|
||||||
|
agentId: agent.id,
|
||||||
|
providerName: 'test-provider',
|
||||||
|
modelId: 'test-model',
|
||||||
|
systemPrompt: 'Test prompt',
|
||||||
|
teamSkills: [],
|
||||||
|
allowedDomains: [],
|
||||||
|
sessionId: sessionId,
|
||||||
|
userId: user.id,
|
||||||
|
userCommentId: 'new-comment-456',
|
||||||
|
providers: [],
|
||||||
|
})
|
||||||
|
|
||||||
|
// 4. Assert that the tools were instantiated using the new comment ID, not the original one
|
||||||
|
expect(createAnalyzeImageToolSpy).toHaveBeenCalledWith(asset.id, 'new-comment-456')
|
||||||
|
expect(createScreenshotToolSpy).toHaveBeenCalledWith(asset.id, 'new-comment-456')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export interface CreateAgentSessionParams {
|
|||||||
allowedDomains: string[]
|
allowedDomains: string[]
|
||||||
sessionId?: string
|
sessionId?: string
|
||||||
userId?: string
|
userId?: string
|
||||||
|
userCommentId?: string | null
|
||||||
customTools?: AgentTool[]
|
customTools?: AgentTool[]
|
||||||
providers: Array<{
|
providers: Array<{
|
||||||
name: string
|
name: string
|
||||||
@@ -47,6 +48,7 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
|
|||||||
allowedDomains,
|
allowedDomains,
|
||||||
sessionId,
|
sessionId,
|
||||||
userId,
|
userId,
|
||||||
|
userCommentId: passedUserCommentId,
|
||||||
customTools = [],
|
customTools = [],
|
||||||
} = params
|
} = params
|
||||||
|
|
||||||
@@ -156,7 +158,8 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
|
|||||||
|
|
||||||
const metadata = await storage.getMetadata()
|
const metadata = await storage.getMetadata()
|
||||||
const assetId = metadata.assetId
|
const assetId = metadata.assetId
|
||||||
const userCommentId = metadata.userCommentId
|
const userCommentId =
|
||||||
|
passedUserCommentId !== undefined ? passedUserCommentId : metadata.userCommentId
|
||||||
|
|
||||||
const mediaTools: AgentTool[] = []
|
const mediaTools: AgentTool[] = []
|
||||||
if (assetId) {
|
if (assetId) {
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
|
|||||||
agentsInstruction: instruction,
|
agentsInstruction: instruction,
|
||||||
sessionId,
|
sessionId,
|
||||||
userId: payload.agent?.userId,
|
userId: payload.agent?.userId,
|
||||||
|
userCommentId,
|
||||||
explicitMention: payload.agent?.explicitMention,
|
explicitMention: payload.agent?.explicitMention,
|
||||||
context,
|
context,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user