mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 22:14:50 +00:00
refactor(agent): invoke harness.subscribe directly without typeof check
This commit is contained in:
@@ -56,6 +56,7 @@ describe('Agent Activities', () => {
|
|||||||
|
|
||||||
it('should call agentChatActivity and prompt the harness', async () => {
|
it('should call agentChatActivity and prompt the harness', async () => {
|
||||||
const mockHarness = {
|
const mockHarness = {
|
||||||
|
subscribe: vi.fn(),
|
||||||
prompt: vi.fn().mockResolvedValue({
|
prompt: vi.fn().mockResolvedValue({
|
||||||
content: [{ type: 'text', text: 'AI response' }],
|
content: [{ type: 'text', text: 'AI response' }],
|
||||||
usage: { input: 10, output: 20 },
|
usage: { input: 10, output: 20 },
|
||||||
@@ -185,6 +186,7 @@ describe('Agent Activities', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const mockHarness = {
|
const mockHarness = {
|
||||||
|
subscribe: vi.fn(),
|
||||||
prompt: vi.fn().mockReturnValue(promptPromise),
|
prompt: vi.fn().mockReturnValue(promptPromise),
|
||||||
abort: vi.fn(),
|
abort: vi.fn(),
|
||||||
}
|
}
|
||||||
@@ -252,6 +254,7 @@ describe('Agent Activities', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const mockHarness = {
|
const mockHarness = {
|
||||||
|
subscribe: vi.fn(),
|
||||||
prompt: vi.fn().mockReturnValue(promptPromise),
|
prompt: vi.fn().mockReturnValue(promptPromise),
|
||||||
abort: vi.fn(),
|
abort: vi.fn(),
|
||||||
}
|
}
|
||||||
@@ -312,6 +315,7 @@ describe('Agent Activities', () => {
|
|||||||
|
|
||||||
it('should include error message in text when stopReason is error', async () => {
|
it('should include error message in text when stopReason is error', async () => {
|
||||||
const mockHarness = {
|
const mockHarness = {
|
||||||
|
subscribe: vi.fn(),
|
||||||
prompt: vi.fn().mockResolvedValue({
|
prompt: vi.fn().mockResolvedValue({
|
||||||
content: [],
|
content: [],
|
||||||
usage: { input: 0, output: 0 },
|
usage: { input: 0, output: 0 },
|
||||||
@@ -352,6 +356,7 @@ describe('Agent Activities', () => {
|
|||||||
|
|
||||||
it('should pass thinkingLevel from agent config to createAgentSession', async () => {
|
it('should pass thinkingLevel from agent config to createAgentSession', async () => {
|
||||||
const mockHarness = {
|
const mockHarness = {
|
||||||
|
subscribe: vi.fn(),
|
||||||
prompt: vi.fn().mockResolvedValue({
|
prompt: vi.fn().mockResolvedValue({
|
||||||
content: [],
|
content: [],
|
||||||
usage: { input: 0, output: 0 },
|
usage: { input: 0, output: 0 },
|
||||||
@@ -400,6 +405,7 @@ describe('Agent Activities', () => {
|
|||||||
|
|
||||||
it('should call autofillAiActivity and run autofill tool', async () => {
|
it('should call autofillAiActivity and run autofill tool', async () => {
|
||||||
const mockHarness = {
|
const mockHarness = {
|
||||||
|
subscribe: vi.fn(),
|
||||||
prompt: vi.fn().mockResolvedValue({
|
prompt: vi.fn().mockResolvedValue({
|
||||||
content: [{ type: 'text', text: 'Captured' }],
|
content: [{ type: 'text', text: 'Captured' }],
|
||||||
usage: { input: 5, output: 5 },
|
usage: { input: 5, output: 5 },
|
||||||
@@ -1040,6 +1046,7 @@ describe('Agent Database Activities Integration', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const mockHarness = {
|
const mockHarness = {
|
||||||
|
subscribe: vi.fn(),
|
||||||
prompt: vi.fn().mockResolvedValue({
|
prompt: vi.fn().mockResolvedValue({
|
||||||
content: [{ type: 'text', text: ' "Summarized Chat Title" ' }],
|
content: [{ type: 'text', text: ' "Summarized Chat Title" ' }],
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -219,7 +219,6 @@ If you need to create files in the local filesystem (for example, a temporary fi
|
|||||||
let grandTotalTokens = 0
|
let grandTotalTokens = 0
|
||||||
let totalCost = 0
|
let totalCost = 0
|
||||||
|
|
||||||
if (typeof harness.subscribe === 'function') {
|
|
||||||
harness.subscribe(async (event) => {
|
harness.subscribe(async (event) => {
|
||||||
if (event.type === 'message_end' && event.message.role === 'assistant') {
|
if (event.type === 'message_end' && event.message.role === 'assistant') {
|
||||||
const assistantMsg = event.message
|
const assistantMsg = event.message
|
||||||
@@ -253,7 +252,6 @@ If you need to create files in the local filesystem (for example, a temporary fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
const assistantMessage = await harness.prompt(params.prompt, { images: imagesToPass })
|
const assistantMessage = await harness.prompt(params.prompt, { images: imagesToPass })
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,6 @@ export class AiUsageService {
|
|||||||
|
|
||||||
since.setMinutes(0, 0, 0)
|
since.setMinutes(0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
if (!params.userId) {
|
if (!params.userId) {
|
||||||
// Return Team-Level Usage (userId = null)
|
// Return Team-Level Usage (userId = null)
|
||||||
const teamRecords = await prisma.aiUsage.findMany({
|
const teamRecords = await prisma.aiUsage.findMany({
|
||||||
|
|||||||
Reference in New Issue
Block a user