refactor(cleanup): share failure composition and retain native UI owners

Validation: integrated changes passed formatting, typecheck, lint, resolved module-boundary verification and git diff --check. Tests and real-provider workflows were not run.
This commit is contained in:
morluto
2026-10-11 00:03:18 +08:00
parent 6543405252
commit 2a0b58e440
12 changed files with 225 additions and 63 deletions
+8 -3
View File
@@ -15,7 +15,10 @@ import {
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import { type AnalysisError } from "../domain/analysisErrorBase.js";
import { err, ok, type Result } from "../domain/result.js";
import { createNativeUiHelperRuntime } from "./NativeUiHelperRuntime.js";
import {
createNativeUiHelperRuntime,
type NativeUiHelperRuntime,
} from "./NativeUiHelperRuntime.js";
import {
NATIVE_UI_OUTPUT_BUDGET_BYTES,
NATIVE_UI_OUTPUT_WEIGHT,
@@ -47,16 +50,18 @@ export const observeNativeUi = async (
environment: Readonly<NodeJS.ProcessEnv>;
signal?: AbortSignal | undefined;
invoke?: NativeUiHelper;
runtime?: NativeUiHelperRuntime;
},
): Promise<Result<z.infer<typeof nativeUiResultSchema>, AnalysisError>> => {
const runtime = createNativeUiHelperRuntime(options.environment);
const runtime =
options.runtime ?? createNativeUiHelperRuntime(options.environment);
try {
return await observeWithHelper(target, operation, parameters, {
...options,
invoke: options.invoke ?? runtime.invoke,
});
} finally {
await runtime.close();
if (options.runtime === undefined) await runtime.close();
}
};