1
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { beforeEach, expect, test, vi } from 'vitest';
|
||||
|
||||
const { requestJsonMock } = vi.hoisted(() => ({
|
||||
requestJsonMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../apiClient', () => ({
|
||||
fetchWithApiAuth: vi.fn(),
|
||||
requestJson: requestJsonMock,
|
||||
}));
|
||||
|
||||
import { createCreationAgentClient } from './creationAgentClientFactory';
|
||||
|
||||
beforeEach(() => {
|
||||
requestJsonMock.mockReset();
|
||||
requestJsonMock.mockResolvedValue({ session: { sessionId: 'session-1' } });
|
||||
});
|
||||
|
||||
test('creation agent action requests are not auto-retried by default', async () => {
|
||||
const client = createCreationAgentClient<
|
||||
Record<string, never>,
|
||||
{ session: { sessionId: string } },
|
||||
{ session: { sessionId: string } },
|
||||
{ sessionId: string },
|
||||
{ text: string },
|
||||
{ session: { sessionId: string } },
|
||||
{ action: string },
|
||||
{ session: { sessionId: string } }
|
||||
>({
|
||||
apiBase: '/api/runtime/puzzle/agent/sessions',
|
||||
messages: {
|
||||
createSession: '创建失败',
|
||||
getSession: '读取失败',
|
||||
sendMessage: '发送失败',
|
||||
streamIncomplete: '流式结果不完整',
|
||||
executeAction: '执行失败',
|
||||
},
|
||||
});
|
||||
|
||||
await client.executeAction('session-1', { action: 'compile_puzzle_draft' });
|
||||
|
||||
expect(requestJsonMock).toHaveBeenCalledWith(
|
||||
'/api/runtime/puzzle/agent/sessions/session-1/actions',
|
||||
expect.objectContaining({ method: 'POST' }),
|
||||
'执行失败',
|
||||
expect.objectContaining({
|
||||
retry: expect.objectContaining({ maxRetries: 0 }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -22,6 +22,7 @@ type CreationAgentClientOptions = {
|
||||
executeActionTimeoutMs?: number;
|
||||
readRetry?: ApiRetryOptions;
|
||||
writeRetry?: ApiRetryOptions;
|
||||
executeActionRetry?: ApiRetryOptions;
|
||||
};
|
||||
|
||||
const DEFAULT_CREATION_AGENT_READ_RETRY: ApiRetryOptions = {
|
||||
@@ -37,6 +38,10 @@ const DEFAULT_CREATION_AGENT_WRITE_RETRY: ApiRetryOptions = {
|
||||
retryUnsafeMethods: true,
|
||||
};
|
||||
|
||||
const DEFAULT_CREATION_AGENT_ACTION_RETRY: ApiRetryOptions = {
|
||||
maxRetries: 0,
|
||||
};
|
||||
|
||||
function buildJsonPostInit(payload: unknown): RequestInit {
|
||||
return {
|
||||
method: 'POST',
|
||||
@@ -88,6 +93,7 @@ export function createCreationAgentClient<
|
||||
executeActionTimeoutMs,
|
||||
readRetry = DEFAULT_CREATION_AGENT_READ_RETRY,
|
||||
writeRetry = DEFAULT_CREATION_AGENT_WRITE_RETRY,
|
||||
executeActionRetry = DEFAULT_CREATION_AGENT_ACTION_RETRY,
|
||||
}: CreationAgentClientOptions) {
|
||||
const createSession = (
|
||||
payload: TCreateSessionPayload,
|
||||
@@ -153,7 +159,7 @@ export function createCreationAgentClient<
|
||||
buildJsonPostInit(payload),
|
||||
messages.executeAction,
|
||||
{
|
||||
retry: writeRetry,
|
||||
retry: executeActionRetry,
|
||||
timeoutMs: executeActionTimeoutMs,
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user