Skip to content

Commit 300668b

Browse files
authored
fix(server): keep router health target server-owned (anomalyco#1240)
Remove client-provided router host and port overrides so OpenWork resolves OpenCodeRouter health and apply requests from trusted server-side config only. Co-authored-by: src-opn <[email protected]>
1 parent 8eb4e34 commit 300668b

2 files changed

Lines changed: 132 additions & 298 deletions

File tree

‎apps/app/src/app/lib/openwork-server.ts‎

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -956,14 +956,12 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
956956
capabilities: () => requestJson<OpenworkServerCapabilities>(baseUrl, "/capabilities", { token, hostToken, timeoutMs: timeouts.capabilities }),
957957
opencodeRouterHealth: () =>
958958
requestJsonRaw<OpenworkOpenCodeRouterHealthSnapshot>(baseUrl, "/opencode-router/health", { token, hostToken, timeoutMs: timeouts.opencodeRouter }),
959-
getOpenCodeRouterHealth: (workspaceId: string, options?: { healthPort?: number | null }) => {
960-
const query = typeof options?.healthPort === "number" ? `?healthPort=${encodeURIComponent(String(options.healthPort))}` : "";
961-
return requestJsonRaw<OpenworkOpenCodeRouterHealthSnapshot>(
959+
getOpenCodeRouterHealth: (workspaceId: string) =>
960+
requestJsonRaw<OpenworkOpenCodeRouterHealthSnapshot>(
962961
baseUrl,
963-
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/health${query}`,
962+
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/health`,
964963
{ token, hostToken, timeoutMs: timeouts.opencodeRouter },
965-
);
966-
},
964+
),
967965
opencodeRouterBindings: (filters?: { channel?: string; identityId?: string }) => {
968966
const search = new URLSearchParams();
969967
if (filters?.channel?.trim()) search.set("channel", filters.channel.trim());
@@ -1079,7 +1077,6 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
10791077
setOpenCodeRouterTelegramToken: (
10801078
workspaceId: string,
10811079
tokenValue: string,
1082-
healthPort?: number | null,
10831080
) =>
10841081
requestJson<OpenworkOpenCodeRouterTelegramResult>(
10851082
baseUrl,
@@ -1088,15 +1085,14 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
10881085
token,
10891086
hostToken,
10901087
method: "POST",
1091-
body: { token: tokenValue, healthPort },
1088+
body: { token: tokenValue },
10921089
timeoutMs: timeouts.opencodeRouter,
10931090
},
10941091
),
10951092
setOpenCodeRouterSlackTokens: (
10961093
workspaceId: string,
10971094
botToken: string,
10981095
appToken: string,
1099-
healthPort?: number | null,
11001096
) =>
11011097
requestJson<OpenworkOpenCodeRouterSlackResult>(
11021098
baseUrl,
@@ -1105,7 +1101,7 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
11051101
token,
11061102
hostToken,
11071103
method: "POST",
1108-
body: { botToken, appToken, healthPort },
1104+
body: { botToken, appToken },
11091105
timeoutMs: timeouts.opencodeRouter,
11101106
},
11111107
),
@@ -1115,18 +1111,15 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
11151111
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/telegram`,
11161112
{ token, hostToken, timeoutMs: timeouts.opencodeRouter },
11171113
),
1118-
getOpenCodeRouterTelegramIdentities: (workspaceId: string, options?: { healthPort?: number | null }) => {
1119-
const query = typeof options?.healthPort === "number" ? `?healthPort=${encodeURIComponent(String(options.healthPort))}` : "";
1120-
return requestJson<OpenworkOpenCodeRouterTelegramIdentitiesResult>(
1114+
getOpenCodeRouterTelegramIdentities: (workspaceId: string) =>
1115+
requestJson<OpenworkOpenCodeRouterTelegramIdentitiesResult>(
11211116
baseUrl,
1122-
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/identities/telegram${query}`,
1117+
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/identities/telegram`,
11231118
{ token, hostToken, timeoutMs: timeouts.opencodeRouter },
1124-
);
1125-
},
1119+
),
11261120
upsertOpenCodeRouterTelegramIdentity: (
11271121
workspaceId: string,
11281122
input: { id?: string; token: string; enabled?: boolean; access?: "public" | "private"; pairingCode?: string },
1129-
options?: { healthPort?: number | null },
11301123
) =>
11311124
requestJson<OpenworkOpenCodeRouterTelegramIdentityUpsertResult>(
11321125
baseUrl,
@@ -1141,30 +1134,24 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
11411134
...(typeof input.enabled === "boolean" ? { enabled: input.enabled } : {}),
11421135
...(input.access ? { access: input.access } : {}),
11431136
...(input.pairingCode?.trim() ? { pairingCode: input.pairingCode.trim() } : {}),
1144-
healthPort: options?.healthPort ?? null,
11451137
},
11461138
},
11471139
),
1148-
deleteOpenCodeRouterTelegramIdentity: (workspaceId: string, identityId: string, options?: { healthPort?: number | null }) => {
1149-
const query = typeof options?.healthPort === "number" ? `?healthPort=${encodeURIComponent(String(options.healthPort))}` : "";
1150-
return requestJson<OpenworkOpenCodeRouterTelegramIdentityDeleteResult>(
1140+
deleteOpenCodeRouterTelegramIdentity: (workspaceId: string, identityId: string) =>
1141+
requestJson<OpenworkOpenCodeRouterTelegramIdentityDeleteResult>(
11511142
baseUrl,
1152-
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/identities/telegram/${encodeURIComponent(identityId)}${query}`,
1143+
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/identities/telegram/${encodeURIComponent(identityId)}`,
11531144
{ token, hostToken, method: "DELETE" },
1154-
);
1155-
},
1156-
getOpenCodeRouterSlackIdentities: (workspaceId: string, options?: { healthPort?: number | null }) => {
1157-
const query = typeof options?.healthPort === "number" ? `?healthPort=${encodeURIComponent(String(options.healthPort))}` : "";
1158-
return requestJson<OpenworkOpenCodeRouterSlackIdentitiesResult>(
1145+
),
1146+
getOpenCodeRouterSlackIdentities: (workspaceId: string) =>
1147+
requestJson<OpenworkOpenCodeRouterSlackIdentitiesResult>(
11591148
baseUrl,
1160-
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/identities/slack${query}`,
1149+
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/identities/slack`,
11611150
{ token, hostToken },
1162-
);
1163-
},
1151+
),
11641152
upsertOpenCodeRouterSlackIdentity: (
11651153
workspaceId: string,
11661154
input: { id?: string; botToken: string; appToken: string; enabled?: boolean },
1167-
options?: { healthPort?: number | null },
11681155
) =>
11691156
requestJson<OpenworkOpenCodeRouterSlackIdentityUpsertResult>(
11701157
baseUrl,
@@ -1178,26 +1165,22 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
11781165
botToken: input.botToken,
11791166
appToken: input.appToken,
11801167
...(typeof input.enabled === "boolean" ? { enabled: input.enabled } : {}),
1181-
healthPort: options?.healthPort ?? null,
11821168
},
11831169
},
11841170
),
1185-
deleteOpenCodeRouterSlackIdentity: (workspaceId: string, identityId: string, options?: { healthPort?: number | null }) => {
1186-
const query = typeof options?.healthPort === "number" ? `?healthPort=${encodeURIComponent(String(options.healthPort))}` : "";
1187-
return requestJson<OpenworkOpenCodeRouterSlackIdentityDeleteResult>(
1171+
deleteOpenCodeRouterSlackIdentity: (workspaceId: string, identityId: string) =>
1172+
requestJson<OpenworkOpenCodeRouterSlackIdentityDeleteResult>(
11881173
baseUrl,
1189-
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/identities/slack/${encodeURIComponent(identityId)}${query}`,
1174+
`/workspace/${encodeURIComponent(workspaceId)}/opencode-router/identities/slack/${encodeURIComponent(identityId)}`,
11901175
{ token, hostToken, method: "DELETE" },
1191-
);
1192-
},
1176+
),
11931177
getOpenCodeRouterBindings: (
11941178
workspaceId: string,
1195-
filters?: { channel?: string; identityId?: string; healthPort?: number | null },
1179+
filters?: { channel?: string; identityId?: string },
11961180
) => {
11971181
const search = new URLSearchParams();
11981182
if (filters?.channel?.trim()) search.set("channel", filters.channel.trim());
11991183
if (filters?.identityId?.trim()) search.set("identityId", filters.identityId.trim());
1200-
if (typeof filters?.healthPort === "number") search.set("healthPort", String(filters.healthPort));
12011184
const suffix = search.toString();
12021185
return requestJson<OpenworkOpenCodeRouterBindingsResult>(
12031186
baseUrl,
@@ -1208,7 +1191,6 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
12081191
setOpenCodeRouterBinding: (
12091192
workspaceId: string,
12101193
input: { channel: string; identityId?: string; peerId: string; directory?: string },
1211-
options?: { healthPort?: number | null },
12121194
) =>
12131195
requestJson<OpenworkOpenCodeRouterBindingUpdateResult>(
12141196
baseUrl,
@@ -1222,7 +1204,6 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
12221204
...(input.identityId?.trim() ? { identityId: input.identityId.trim() } : {}),
12231205
peerId: input.peerId,
12241206
...(input.directory?.trim() ? { directory: input.directory.trim() } : {}),
1225-
healthPort: options?.healthPort ?? null,
12261207
},
12271208
},
12281209
),
@@ -1236,7 +1217,6 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
12361217
peerId?: string;
12371218
autoBind?: boolean;
12381219
},
1239-
options?: { healthPort?: number | null },
12401220
) => {
12411221
const payload = {
12421222
channel: input.channel,
@@ -1245,7 +1225,6 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
12451225
...(input.directory?.trim() ? { directory: input.directory.trim() } : {}),
12461226
...(input.peerId?.trim() ? { peerId: input.peerId.trim() } : {}),
12471227
...(input.autoBind === true ? { autoBind: true } : {}),
1248-
healthPort: options?.healthPort ?? null,
12491228
};
12501229

12511230
const primaryPath = `/workspace/${encodeURIComponent(workspaceId)}/opencode-router/send`;
@@ -1277,7 +1256,7 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
12771256
setOpenCodeRouterTelegramEnabled: (
12781257
workspaceId: string,
12791258
enabled: boolean,
1280-
options?: { clearToken?: boolean; healthPort?: number | null },
1259+
options?: { clearToken?: boolean },
12811260
) =>
12821261
requestJson<OpenworkOpenCodeRouterTelegramEnabledResult>(
12831262
baseUrl,
@@ -1286,7 +1265,7 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
12861265
token,
12871266
hostToken,
12881267
method: "POST",
1289-
body: { enabled, clearToken: options?.clearToken ?? false, healthPort: options?.healthPort ?? null },
1268+
body: { enabled, clearToken: options?.clearToken ?? false },
12901269
},
12911270
),
12921271
patchConfig: (workspaceId: string, payload: { opencode?: Record<string, unknown>; openwork?: Record<string, unknown> }) =>

0 commit comments

Comments
 (0)