@rocapine/community 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -88,6 +88,14 @@ export function parseTranslationResponse(
|
|
|
88
88
|
return { sourceLocale, translations: out };
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/** OpenAI request timeout: output grows with text length × target count, so a
|
|
92
|
+
* flat limit fails every long post (measured on Eve's Rhythm: 7 locales of a
|
|
93
|
+
* ~1,500-character post take over 20 s). 20 s base plus 5 ms per character per
|
|
94
|
+
* target, capped at 90 s (inside the edge-function wall clock). */
|
|
95
|
+
export function translationTimeoutMs(contentLength: number, targetCount: number): number {
|
|
96
|
+
return Math.min(90_000, 20_000 + 5 * contentLength * Math.max(1, targetCount));
|
|
97
|
+
}
|
|
98
|
+
|
|
91
99
|
/** One OpenAI call. Returns null on any failure (caller writes nothing). */
|
|
92
100
|
export async function translateItem(input: {
|
|
93
101
|
content: string;
|
|
@@ -155,7 +163,7 @@ export async function translateItem(input: {
|
|
|
155
163
|
// effort=minimal shows up as sweep failures in Slack.
|
|
156
164
|
...(/^gpt-5/.test(TRANSLATION_MODEL) ? { reasoning: { effort: "minimal" } } : {}),
|
|
157
165
|
}),
|
|
158
|
-
signal: AbortSignal.timeout(
|
|
166
|
+
signal: AbortSignal.timeout(translationTimeoutMs(input.content.length, input.targets.length)),
|
|
159
167
|
});
|
|
160
168
|
if (!res.ok) {
|
|
161
169
|
console.error("translation api error", res.status, (await res.text()).slice(0, 300));
|