Files
pikasTech-HWLAB/internal/hwpod/runtime.ts
T
2026-07-21 04:24:39 +02:00

33 lines
1.7 KiB
TypeScript

/*
* SPEC: PJ2026-010103 HWPOD 服务;
* PJ2026-01010305 71FREQ 预装 draft-2026-06-26-71freq-v03-hwpod-preinstall。
* 实现引用: draft-2026-07-20-hwpod-temporal-split。
* 责任: HWPOD API 的 Temporal 与迁移期 Cloud API 配置解析。
*/
import { createHwpodTemporalGateway } from "./temporal.ts";
import { hwpodSpecRegistryFromEnv } from "./spec-registry.ts";
export function hwpodRuntime(env: Record<string, string | undefined> = process.env) {
const address = String(env.HWPOD_TEMPORAL_ADDRESS ?? env.TEMPORAL_ADDRESS ?? "").trim();
const namespace = String(env.HWPOD_TEMPORAL_NAMESPACE ?? "unidesk").trim();
const taskQueue = String(env.HWPOD_TEMPORAL_TASK_QUEUE ?? "hwlab-v03-hwpod").trim();
const runtimeApiUrl = String(env.HWPOD_RUNTIME_API_URL ?? "").trim().replace(/\/+$/u, "");
const runtimeApiAuthorizationValue = String(env.HWPOD_RUNTIME_API_AUTHORIZATION ?? "").trim();
const runtimeApiAuthorizationPrefix = String(env.HWPOD_RUNTIME_API_AUTHORIZATION_PREFIX ?? "").trim();
const runtimeApiAuthorization = runtimeApiAuthorizationPrefix ? `${runtimeApiAuthorizationPrefix} ${runtimeApiAuthorizationValue}` : runtimeApiAuthorizationValue;
if (!runtimeApiUrl) throw codedError("hwpod_runtime_api_url_required", "HWPOD_RUNTIME_API_URL is required");
if (!runtimeApiAuthorization) throw codedError("hwpod_runtime_api_authorization_required", "HWPOD_RUNTIME_API_AUTHORIZATION is required");
return {
address,
namespace,
taskQueue,
runtimeApiUrl,
runtimeApiAuthorization,
temporal: createHwpodTemporalGateway({ address, namespace, taskQueue }),
specRegistry: hwpodSpecRegistryFromEnv(env),
};
}
function codedError(code: string, message: string) { return Object.assign(new Error(message), { code }); }