69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import type {
|
|
BigFishRunResponse,
|
|
SubmitBigFishInputRequest,
|
|
} from '../../../packages/shared/src/contracts/bigFish';
|
|
import { type ApiRetryOptions, requestJson } from '../apiClient';
|
|
|
|
const BIG_FISH_RUNTIME_API_BASE = '/api/runtime/big-fish';
|
|
const BIG_FISH_RUNTIME_READ_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
};
|
|
const BIG_FISH_RUNTIME_WRITE_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
retryUnsafeMethods: true,
|
|
};
|
|
|
|
export async function startBigFishRuntimeRun(sessionId: string) {
|
|
return requestJson<BigFishRunResponse>(
|
|
`${BIG_FISH_RUNTIME_API_BASE}/sessions/${encodeURIComponent(sessionId)}/runs`,
|
|
{
|
|
method: 'POST',
|
|
},
|
|
'启动大鱼吃小鱼测试玩法失败',
|
|
{
|
|
retry: BIG_FISH_RUNTIME_WRITE_RETRY,
|
|
},
|
|
);
|
|
}
|
|
|
|
export async function getBigFishRuntimeRun(runId: string) {
|
|
return requestJson<BigFishRunResponse>(
|
|
`${BIG_FISH_RUNTIME_API_BASE}/runs/${encodeURIComponent(runId)}`,
|
|
{
|
|
method: 'GET',
|
|
},
|
|
'读取大鱼吃小鱼运行快照失败',
|
|
{
|
|
retry: BIG_FISH_RUNTIME_READ_RETRY,
|
|
},
|
|
);
|
|
}
|
|
|
|
export async function submitBigFishRuntimeInput(
|
|
runId: string,
|
|
payload: SubmitBigFishInputRequest,
|
|
) {
|
|
return requestJson<BigFishRunResponse>(
|
|
`${BIG_FISH_RUNTIME_API_BASE}/runs/${encodeURIComponent(runId)}/input`,
|
|
{
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload),
|
|
},
|
|
'提交大鱼吃小鱼移动输入失败',
|
|
{
|
|
retry: BIG_FISH_RUNTIME_WRITE_RETRY,
|
|
},
|
|
);
|
|
}
|
|
|
|
export const bigFishRuntimeClient = {
|
|
startRun: startBigFishRuntimeRun,
|
|
getRun: getBigFishRuntimeRun,
|
|
submitInput: submitBigFishRuntimeInput,
|
|
};
|