Open History to see the last commit
1import {
2 ORCHESTRATION_PROTOCOL_QUERY_PARAM,
3 ORCHESTRATION_PROTOCOL_VERSION,
4 type ExecutionEnvironmentDescriptor,
5} from "@t3tools/contracts";
6
7import { ConnectionBlockedError } from "./model.ts";
8
9export function orchestrationProtocolCompatibilityError(
10 descriptor: ExecutionEnvironmentDescriptor,
11): ConnectionBlockedError | null {
12 if (descriptor.orchestrationProtocolVersion === ORCHESTRATION_PROTOCOL_VERSION) {
13 return null;
14 }
15 const hostProtocol = descriptor.orchestrationProtocolVersion;
16 const detail =
17 hostProtocol === undefined
18 ? `Update T3 Code on ${descriptor.label} before reconnecting. This host predates orchestration protocol ${ORCHESTRATION_PROTOCOL_VERSION}.`
19 : `Update T3 Code on ${descriptor.label} and this client before reconnecting. The host uses orchestration protocol ${hostProtocol}, while this client requires ${ORCHESTRATION_PROTOCOL_VERSION}.`;
20 return new ConnectionBlockedError({ reason: "unsupported", detail });
21}
22
23export function appendOrchestrationProtocol(socketUrl: string): string {
24 const url = new URL(socketUrl);
25 url.searchParams.set(ORCHESTRATION_PROTOCOL_QUERY_PARAM, String(ORCHESTRATION_PROTOCOL_VERSION));
26 return url.toString();
27}