- Route recommended runtime launches through shared runtime guest token handling - Extend recommend-page anonymous play beyond jump-hop - Add regression coverage for runtime guest launch clients - Update docs to reflect the full anonymous-play matrix
112 lines
3.1 KiB
TypeScript
112 lines
3.1 KiB
TypeScript
import type {
|
|
BarkBattleFinishResponse,
|
|
BarkBattleRunFinishRequest,
|
|
BarkBattleRunStartRequest,
|
|
BarkBattleRunStartResponse,
|
|
BarkBattleRuntimeConfig,
|
|
} from '../../../packages/shared/src/contracts/barkBattle';
|
|
import {
|
|
type ApiRetryOptions,
|
|
requestJson,
|
|
} from '../apiClient';
|
|
import {
|
|
buildRuntimeGuestAuthOptions,
|
|
buildRuntimeGuestHeaders,
|
|
type RuntimeGuestRequestOptions,
|
|
} from '../runtimeGuestAuth';
|
|
|
|
const BARK_BATTLE_RUNTIME_READ_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
};
|
|
|
|
const BARK_BATTLE_RUNTIME_WRITE_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
retryUnsafeMethods: true,
|
|
};
|
|
|
|
export type BarkBattleRuntimeRequestOptions = RuntimeGuestRequestOptions;
|
|
|
|
export function getBarkBattleRuntimeConfig(
|
|
workId: string,
|
|
options: BarkBattleRuntimeRequestOptions = {},
|
|
) {
|
|
const requestOptions = buildRuntimeGuestAuthOptions(options);
|
|
return requestJson<BarkBattleRuntimeConfig>(
|
|
`/api/runtime/bark-battle/works/${encodeURIComponent(workId)}/config`,
|
|
{ method: 'GET', headers: buildRuntimeGuestHeaders(options) },
|
|
'读取汪汪声浪大作战配置失败',
|
|
{
|
|
retry: BARK_BATTLE_RUNTIME_READ_RETRY,
|
|
...requestOptions,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function startBarkBattleRun(
|
|
workId: string,
|
|
payload: Partial<BarkBattleRunStartRequest> = {},
|
|
options: BarkBattleRuntimeRequestOptions = {},
|
|
) {
|
|
const requestOptions = buildRuntimeGuestAuthOptions(options);
|
|
return requestJson<BarkBattleRunStartResponse>(
|
|
`/api/runtime/bark-battle/works/${encodeURIComponent(workId)}/runs`,
|
|
{
|
|
method: 'POST',
|
|
headers: buildRuntimeGuestHeaders(options, { 'Content-Type': 'application/json' }),
|
|
body: JSON.stringify({
|
|
...payload,
|
|
workId: payload.workId ?? workId,
|
|
}),
|
|
},
|
|
'启动汪汪声浪大作战正式局失败',
|
|
{
|
|
retry: BARK_BATTLE_RUNTIME_WRITE_RETRY,
|
|
...requestOptions,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function getBarkBattleRun(
|
|
runId: string,
|
|
options: BarkBattleRuntimeRequestOptions = {},
|
|
) {
|
|
const requestOptions = buildRuntimeGuestAuthOptions(options);
|
|
return requestJson<unknown>(
|
|
`/api/runtime/bark-battle/runs/${encodeURIComponent(runId)}`,
|
|
{ method: 'GET', headers: buildRuntimeGuestHeaders(options) },
|
|
'读取汪汪声浪大作战单局失败',
|
|
{
|
|
retry: BARK_BATTLE_RUNTIME_READ_RETRY,
|
|
...requestOptions,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function finishBarkBattleRun(
|
|
runId: string,
|
|
payload: BarkBattleRunFinishRequest,
|
|
options: BarkBattleRuntimeRequestOptions = {},
|
|
) {
|
|
const requestOptions = buildRuntimeGuestAuthOptions(options);
|
|
return requestJson<BarkBattleFinishResponse>(
|
|
`/api/runtime/bark-battle/runs/${encodeURIComponent(runId)}/finish`,
|
|
{
|
|
method: 'POST',
|
|
headers: buildRuntimeGuestHeaders(options, { 'Content-Type': 'application/json' }),
|
|
body: JSON.stringify({
|
|
...payload,
|
|
runId: payload.runId ?? runId,
|
|
}),
|
|
},
|
|
'提交汪汪声浪大作战成绩失败',
|
|
{
|
|
retry: BARK_BATTLE_RUNTIME_WRITE_RETRY,
|
|
...requestOptions,
|
|
},
|
|
);
|
|
}
|