@openspecui/core 3.11.3 → 3.11.4
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/dist/{document-translation-BrlCvnLZ.mjs → document-translation-B3QRXIXx.mjs} +1 -1
- package/dist/{document-translation-Cv6BIGL5.d.mts → document-translation-QMSrWNT-.d.mts} +2 -2
- package/dist/document-translation.d.mts +1 -1
- package/dist/document-translation.mjs +2 -2
- package/dist/index.d.mts +120 -30
- package/dist/index.mjs +114 -4
- package/dist/{local-download-profiles-GKs2OOqJ.d.mts → local-download-profiles-DHF9dW4e.d.mts} +1 -1
- package/dist/local-download-profiles.d.mts +2 -2
- package/dist/{notifications-CJQ_F_Un.d.mts → notifications-D9yMeQqN.d.mts} +18 -18
- package/dist/notifications.d.mts +2 -2
- package/dist/{openspec-projection-BbuPTbvj.d.mts → openspec-projection-e-sOj4vr.d.mts} +1 -1
- package/dist/openspec-projection.d.mts +2 -2
- package/dist/{opsx-entity-BO9G2SCW.d.mts → opsx-entity-C89YFQNB.d.mts} +9 -9
- package/dist/opsx-entity.d.mts +2 -2
- package/dist/{opsx-schema-detail-DTajJW4g.d.mts → opsx-schema-detail-DIscOp9f.d.mts} +1 -1
- package/dist/opsx-schema-detail.d.mts +3 -3
- package/dist/{schemas-DQzd1hgp.d.mts → schemas-B6ZBedD4.d.mts} +44 -44
- package/dist/{sounds-3yEx1YXT.d.mts → sounds-BjSZxrQO.d.mts} +5 -5
- package/dist/sounds.d.mts +1 -1
- package/dist/{terminal-audio-UCLlM1qN.d.mts → terminal-audio-6x0ceNBw.d.mts} +2 -2
- package/dist/terminal-audio.d.mts +2 -2
- package/dist/terminal-control.d.mts +2 -2
- package/dist/{terminal-invocation-DCPc8hmm.d.mts → terminal-invocation-C2e1WSWM.d.mts} +91 -91
- package/dist/terminal-invocation.d.mts +1 -1
- package/dist/{translator-Car0_7uk.mjs → translator-B98pejVa.mjs} +134 -6
- package/dist/{translator-prn3W9lf.d.mts → translator-jn94xmWZ.d.mts} +241 -167
- package/dist/translator.d.mts +2 -2
- package/dist/translator.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as renderTerminalSpawnCommand, C as TerminalSpawnCommand, D as getTerminalCommandParameters, E as getTerminalCommandDefaultValues, M as resolveTerminalShellDefaults, O as quoteTerminalShellArg, S as TerminalShellQuoteStyleSchema, T as fieldsToTerminalCommandParameters, _ as TerminalShellDefaults, a as TerminalCommandBuilder, b as TerminalShellProfileSchema, c as TerminalCommandFieldSchema, d as TerminalCommandJsonSchema, f as TerminalCommandJsonSchemaProperty, g as TerminalInvocationSettingsSchema, h as TerminalInvocationSettings, i as TerminalCommandArgument, j as renderTerminalSpawnCommandLine, k as renderTerminalCommandArgs, l as TerminalCommandFieldValue, m as TerminalCommandRenderResult, n as TERMINAL_COMMAND_FIELD_TYPE_VALUES, o as TerminalCommandBuilderPart, p as TerminalCommandParameters, r as TERMINAL_SHELL_QUOTE_STYLE_VALUES, s as TerminalCommandField, t as BUILTIN_TERMINAL_SPAWN_COMMANDS, u as TerminalCommandFieldValues, v as TerminalShellEnv, w as TerminalSpawnCommandSchema, x as TerminalShellQuoteStyle, y as TerminalShellProfile } from "./terminal-invocation-
|
|
1
|
+
import { A as renderTerminalSpawnCommand, C as TerminalSpawnCommand, D as getTerminalCommandParameters, E as getTerminalCommandDefaultValues, M as resolveTerminalShellDefaults, O as quoteTerminalShellArg, S as TerminalShellQuoteStyleSchema, T as fieldsToTerminalCommandParameters, _ as TerminalShellDefaults, a as TerminalCommandBuilder, b as TerminalShellProfileSchema, c as TerminalCommandFieldSchema, d as TerminalCommandJsonSchema, f as TerminalCommandJsonSchemaProperty, g as TerminalInvocationSettingsSchema, h as TerminalInvocationSettings, i as TerminalCommandArgument, j as renderTerminalSpawnCommandLine, k as renderTerminalCommandArgs, l as TerminalCommandFieldValue, m as TerminalCommandRenderResult, n as TERMINAL_COMMAND_FIELD_TYPE_VALUES, o as TerminalCommandBuilderPart, p as TerminalCommandParameters, r as TERMINAL_SHELL_QUOTE_STYLE_VALUES, s as TerminalCommandField, t as BUILTIN_TERMINAL_SPAWN_COMMANDS, u as TerminalCommandFieldValues, v as TerminalShellEnv, w as TerminalSpawnCommandSchema, x as TerminalShellQuoteStyle, y as TerminalShellProfile } from "./terminal-invocation-C2e1WSWM.mjs";
|
|
2
2
|
export { BUILTIN_TERMINAL_SPAWN_COMMANDS, TERMINAL_COMMAND_FIELD_TYPE_VALUES, TERMINAL_SHELL_QUOTE_STYLE_VALUES, TerminalCommandArgument, TerminalCommandBuilder, TerminalCommandBuilderPart, TerminalCommandField, TerminalCommandFieldSchema, TerminalCommandFieldValue, TerminalCommandFieldValues, TerminalCommandJsonSchema, TerminalCommandJsonSchemaProperty, TerminalCommandParameters, TerminalCommandRenderResult, TerminalInvocationSettings, TerminalInvocationSettingsSchema, TerminalShellDefaults, TerminalShellEnv, TerminalShellProfile, TerminalShellProfileSchema, TerminalShellQuoteStyle, TerminalShellQuoteStyleSchema, TerminalSpawnCommand, TerminalSpawnCommandSchema, fieldsToTerminalCommandParameters, getTerminalCommandDefaultValues, getTerminalCommandParameters, quoteTerminalShellArg, renderTerminalCommandArgs, renderTerminalSpawnCommand, renderTerminalSpawnCommandLine, resolveTerminalShellDefaults };
|
|
@@ -1,5 +1,123 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
|
+
//#region src/translation-task-control.ts
|
|
4
|
+
const BATCH_TRANSLATION_ERROR_KINDS = [
|
|
5
|
+
"timeout",
|
|
6
|
+
"memory-limit",
|
|
7
|
+
"runtime",
|
|
8
|
+
"abort"
|
|
9
|
+
];
|
|
10
|
+
async function runControlledTranslationTask(task, options = {}) {
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const cleanupCallbacks = [];
|
|
13
|
+
const parentSignal = options.signal;
|
|
14
|
+
const timeoutMs = normalizeTimeoutMs(options.timeoutMs);
|
|
15
|
+
if (parentSignal) if (parentSignal.aborted) controller.abort(parentSignal.reason);
|
|
16
|
+
else {
|
|
17
|
+
const onAbort = () => controller.abort(parentSignal.reason);
|
|
18
|
+
parentSignal.addEventListener("abort", onAbort, { once: true });
|
|
19
|
+
cleanupCallbacks.push(() => parentSignal.removeEventListener("abort", onAbort));
|
|
20
|
+
}
|
|
21
|
+
if (controller.signal.aborted) {
|
|
22
|
+
cleanupCallbacks.forEach((callback) => callback());
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
error: normalizeBatchTranslationError(controller.signal.reason, parentSignal)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
let timer;
|
|
29
|
+
let timeoutError;
|
|
30
|
+
const taskPromise = Promise.resolve().then(() => task(controller.signal));
|
|
31
|
+
taskPromise.catch(() => void 0);
|
|
32
|
+
const races = [taskPromise];
|
|
33
|
+
if (!controller.signal.aborted) races.push(new Promise((_, reject) => {
|
|
34
|
+
const onAbort = () => reject(new DOMException("Translation cancelled.", "AbortError"));
|
|
35
|
+
controller.signal.addEventListener("abort", onAbort, { once: true });
|
|
36
|
+
cleanupCallbacks.push(() => controller.signal.removeEventListener("abort", onAbort));
|
|
37
|
+
}));
|
|
38
|
+
if (timeoutMs !== void 0) races.push(new Promise((_, reject) => {
|
|
39
|
+
timer = setTimeout(() => {
|
|
40
|
+
timeoutError = /* @__PURE__ */ new Error(`Translation task timed out after ${timeoutMs}ms.`);
|
|
41
|
+
controller.abort(timeoutError);
|
|
42
|
+
reject(timeoutError);
|
|
43
|
+
}, timeoutMs);
|
|
44
|
+
}));
|
|
45
|
+
try {
|
|
46
|
+
return {
|
|
47
|
+
ok: true,
|
|
48
|
+
value: await Promise.race(races)
|
|
49
|
+
};
|
|
50
|
+
} catch (error) {
|
|
51
|
+
controller.abort(error);
|
|
52
|
+
if (timeoutError && controller.signal.reason === timeoutError) return {
|
|
53
|
+
ok: false,
|
|
54
|
+
error: {
|
|
55
|
+
kind: "timeout",
|
|
56
|
+
message: timeoutError.message
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
ok: false,
|
|
61
|
+
error: normalizeBatchTranslationError(error, parentSignal)
|
|
62
|
+
};
|
|
63
|
+
} finally {
|
|
64
|
+
if (timer) clearTimeout(timer);
|
|
65
|
+
cleanupCallbacks.forEach((callback) => callback());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function normalizeBatchTranslationError(error, parentSignal) {
|
|
69
|
+
if (isBatchTranslationError(error)) return error;
|
|
70
|
+
if (parentSignal?.aborted) return {
|
|
71
|
+
kind: "abort",
|
|
72
|
+
message: readAbortMessage(parentSignal.reason) ?? "Translation cancelled."
|
|
73
|
+
};
|
|
74
|
+
if (error instanceof DOMException && error.name === "AbortError") return {
|
|
75
|
+
kind: "abort",
|
|
76
|
+
message: readAbortMessage(error) ?? "Translation cancelled."
|
|
77
|
+
};
|
|
78
|
+
const message = getErrorMessage(error);
|
|
79
|
+
if (isTimeoutMessage(message)) return {
|
|
80
|
+
kind: "timeout",
|
|
81
|
+
message
|
|
82
|
+
};
|
|
83
|
+
if (isMemoryLimitMessage(message)) return {
|
|
84
|
+
kind: "memory-limit",
|
|
85
|
+
message
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
kind: "runtime",
|
|
89
|
+
message
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function isBatchTranslationAbort(error, signal) {
|
|
93
|
+
return error.kind === "abort" && !!signal?.aborted;
|
|
94
|
+
}
|
|
95
|
+
function normalizeTimeoutMs(timeoutMs) {
|
|
96
|
+
return typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0 ? Math.floor(timeoutMs) : void 0;
|
|
97
|
+
}
|
|
98
|
+
function getErrorMessage(error) {
|
|
99
|
+
if (error instanceof Error && error.message.trim().length > 0) return error.message;
|
|
100
|
+
if (typeof error === "string" && error.trim().length > 0) return error;
|
|
101
|
+
return "Translation failed.";
|
|
102
|
+
}
|
|
103
|
+
function readAbortMessage(reason) {
|
|
104
|
+
if (reason instanceof Error && reason.message.trim().length > 0) return reason.message;
|
|
105
|
+
if (typeof reason === "string" && reason.trim().length > 0) return reason;
|
|
106
|
+
}
|
|
107
|
+
function isTimeoutMessage(message) {
|
|
108
|
+
return /\btime(?:d)?\s*out\b/i.test(message);
|
|
109
|
+
}
|
|
110
|
+
function isMemoryLimitMessage(message) {
|
|
111
|
+
return /out of memory/i.test(message) || /memory limit/i.test(message) || /insufficient memory/i.test(message) || /ERR_WORKER_OUT_OF_MEMORY/i.test(message);
|
|
112
|
+
}
|
|
113
|
+
function isBatchTranslationError(value) {
|
|
114
|
+
if (typeof value !== "object" || value === null) return false;
|
|
115
|
+
const kind = Reflect.get(value, "kind");
|
|
116
|
+
const message = Reflect.get(value, "message");
|
|
117
|
+
return typeof kind === "string" && BATCH_TRANSLATION_ERROR_KINDS.includes(kind) && typeof message === "string" && message.length > 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
3
121
|
//#region src/translator.ts
|
|
4
122
|
const TRANSLATOR_CONTRACT_VERSION = 3;
|
|
5
123
|
const TRANSLATION_ENGINE_IDS = [
|
|
@@ -24,6 +142,7 @@ const SERVICE_TRANSLATION_ENGINE_IDS = [
|
|
|
24
142
|
"openai"
|
|
25
143
|
];
|
|
26
144
|
const ServiceTranslationEngineIdSchema = z.enum(SERVICE_TRANSLATION_ENGINE_IDS);
|
|
145
|
+
const DEFAULT_BATCH_TRANSLATION_TIMEOUT_MS = 15e3;
|
|
27
146
|
const LocalModelDownloadStatusSchema = z.enum([
|
|
28
147
|
"not-downloaded",
|
|
29
148
|
"queued",
|
|
@@ -375,19 +494,23 @@ const TranslationOpenAISettingsSchema = z.object({
|
|
|
375
494
|
const TranslationLocalSettingsSchema = z.object({
|
|
376
495
|
model: z.string().default("Xenova/nllb-200-distilled-600M"),
|
|
377
496
|
selectedGroupId: z.string().optional(),
|
|
378
|
-
hfEndpoint: z.string().default("")
|
|
497
|
+
hfEndpoint: z.string().default(""),
|
|
498
|
+
memoryBudgetPercent: z.number().min(0).max(100).default(25)
|
|
379
499
|
});
|
|
380
500
|
const TranslationLocalCt2SettingsSchema = z.object({
|
|
381
501
|
model: z.string().default("ooeoeo/opus-mt-en-zh-ct2-float16"),
|
|
382
502
|
selectedGroupId: z.string().optional(),
|
|
383
|
-
hfEndpoint: z.string().default("")
|
|
503
|
+
hfEndpoint: z.string().default(""),
|
|
504
|
+
memoryBudgetPercent: z.number().min(0).max(100).default(25)
|
|
384
505
|
});
|
|
385
506
|
const TranslationLocalLlamaSettingsSchema = z.object({
|
|
386
507
|
model: z.string().default("bartowski/Qwen2.5-0.5B-Instruct-GGUF"),
|
|
387
508
|
selectedGroupId: z.string().optional(),
|
|
388
|
-
hfEndpoint: z.string().default("")
|
|
509
|
+
hfEndpoint: z.string().default(""),
|
|
510
|
+
memoryBudgetPercent: z.number().min(0).max(100).default(25)
|
|
389
511
|
});
|
|
390
512
|
const TranslationEngineGlobalSettingsSchema = z.object({
|
|
513
|
+
engineId: TranslationEngineIdSchema.default(DEFAULT_TRANSLATION_ENGINE_ID),
|
|
391
514
|
openai: TranslationOpenAISettingsSchema.default(TranslationOpenAISettingsSchema.parse({})),
|
|
392
515
|
local: TranslationLocalSettingsSchema.default(TranslationLocalSettingsSchema.parse({})),
|
|
393
516
|
localCt2: TranslationLocalCt2SettingsSchema.default(TranslationLocalCt2SettingsSchema.parse({})),
|
|
@@ -401,12 +524,17 @@ const BatchTranslateInputSchema = z.object({
|
|
|
401
524
|
selectedGroupId: z.string().min(1).optional(),
|
|
402
525
|
inputs: z.array(z.string()).min(1),
|
|
403
526
|
instructions: z.string().optional(),
|
|
404
|
-
context: z.string().optional()
|
|
527
|
+
context: z.string().optional(),
|
|
528
|
+
timeoutMs: z.number().int().positive().default(DEFAULT_BATCH_TRANSLATION_TIMEOUT_MS)
|
|
405
529
|
});
|
|
406
530
|
const BatchTranslateEventSchema = z.object({
|
|
407
531
|
index: z.number().int().nonnegative(),
|
|
408
|
-
output: z.string()
|
|
532
|
+
output: z.string().optional(),
|
|
533
|
+
error: z.object({
|
|
534
|
+
kind: z.enum(BATCH_TRANSLATION_ERROR_KINDS),
|
|
535
|
+
message: z.string().min(1)
|
|
536
|
+
}).optional()
|
|
409
537
|
});
|
|
410
538
|
|
|
411
539
|
//#endregion
|
|
412
|
-
export {
|
|
540
|
+
export { TranslationEngineInstallLogEventSchema as A, createTranslationEngineLifecycleStatus as B, TranslationDownloadGroupPlanSchema as C, TranslationEngineDependencyStatusSchema as D, TranslationEngineDependencyStateSchema as E, TranslationEngineRuntimeStatusSchema as F, isManagedLocalTranslationEngineId as G, getTranslationEngineLifecycleMessage as H, TranslationLocalCt2SettingsSchema as I, shouldShowTranslationEngineInstallGate as J, isTranslationEngineDependencyReady as K, TranslationLocalLlamaSettingsSchema as L, TranslationEngineLifecycleEventSchema as M, TranslationEngineLifecycleStatusSchema as N, TranslationEngineGlobalSettingsSchema as O, TranslationEngineRuntimeStateSchema as P, TranslationLocalSettingsSchema as R, TranslationDownloadFilePlanSchema as S, TranslationEngineAssetStatusSchema as T, getTranslationEngineManifest as U, getManagedLocalTranslationEngineManifest as V, isDirectionalManagedLocalTranslationEngineId as W, normalizeBatchTranslationError as X, isBatchTranslationAbort as Y, runControlledTranslationTask as Z, SERVICE_TRANSLATION_ENGINE_IDS as _, LocalModelAssetLogSchema as a, TRANSLATION_ENGINE_MANIFESTS as b, LocalModelDownloadStatusSchema as c, LocalModelProfileLoadStateSchema as d, LocalModelProfileManifestFileSchema as f, ManagedLocalCatalogSourceSchema as g, LocalModelProfileStatusSchema as h, DEFAULT_TRANSLATION_ENGINE_ID as i, TranslationEngineInstallLogStreamSchema as j, TranslationEngineIdSchema as k, LocalModelLifecycleFileStateSchema as l, LocalModelProfileManifestSchema as m, BatchTranslateInputSchema as n, LocalModelAssetPlanSnapshotSchema as o, LocalModelProfileManifestGroupSchema as p, isTranslationEngineRuntimeReady as q, DEFAULT_BATCH_TRANSLATION_TIMEOUT_MS as r, LocalModelAssetStateSchema as s, BatchTranslateEventSchema as t, LocalModelLifecycleGroupStateSchema as u, ServiceTranslationEngineIdSchema as v, TranslationEngineAssetStateSchema as w, TRANSLATOR_CONTRACT_VERSION as x, TRANSLATION_ENGINE_IDS as y, TranslationOpenAISettingsSchema as z };
|