fix: unblock local news page generation

This commit is contained in:
john
2026-07-25 21:55:00 +08:00
parent 793e64bfbc
commit 6b6f9ed01c
16 changed files with 1075 additions and 47 deletions
+35 -20
View File
@@ -1896,28 +1896,43 @@ export function createTkmindProxy({
requestId,
timeoutMs,
});
const replyResponse = await apiFetch(
target,
apiSecret,
`/sessions/${encodeURIComponent(sessionId)}/reply`,
{
method: 'POST',
body: JSON.stringify(body),
},
// Prevent unhandled rejection from killing the Portal process when reply
// setup fails before we await Finish (e.g. provider Error frames arrive later).
const trackedFinish = finishPromise.then(
(value) => ({ ok: true, value }),
(error) => ({ ok: false, error }),
);
if (!replyResponse.ok) {
const text = await replyResponse.text().catch(() => '');
throw new Error(text || `发送失败 (${replyResponse.status})`);
try {
const replyResponse = await apiFetch(
target,
apiSecret,
`/sessions/${encodeURIComponent(sessionId)}/reply`,
{
method: 'POST',
body: JSON.stringify(body),
},
);
if (!replyResponse.ok) {
const text = await replyResponse.text().catch(() => '');
eventsResponse.body?.cancel?.().catch?.(() => {});
throw new Error(text || `发送失败 (${replyResponse.status})`);
}
replyResponse.body?.cancel?.().catch?.(() => {});
const finishResult = await trackedFinish;
if (!finishResult.ok) throw finishResult.error;
const finish = finishResult.value;
const tokenState = await resolveSessionBillingTokenState(sessionId, finish.tokenState);
if (tokenState && userAuth.billSessionUsage) {
await userAuth
.billSessionUsage(userId, sessionId, tokenState, requestId)
.catch(() => {});
}
return { ok: true, ...finish, tokenState };
} catch (err) {
eventsResponse.body?.cancel?.().catch?.(() => {});
await trackedFinish.catch?.(() => {});
throw err;
}
replyResponse.body?.cancel?.().catch?.(() => {});
const finish = await finishPromise;
const tokenState = await resolveSessionBillingTokenState(sessionId, finish.tokenState);
if (tokenState && userAuth.billSessionUsage) {
await userAuth
.billSessionUsage(userId, sessionId, tokenState, requestId)
.catch(() => {});
}
return { ok: true, ...finish, tokenState };
}
const requireUser = async (req, res, next) => {