huskies: merge 921
This commit is contained in:
@@ -54,6 +54,21 @@ export interface ServerMode {
|
||||
mode: "gateway" | "standard";
|
||||
}
|
||||
|
||||
/// Type guard: verify that an unknown value has the AllProjectsPipeline shape.
|
||||
/// Prevents silent "no active stories" when the backend response shape drifts.
|
||||
function isAllProjectsPipeline(value: unknown): value is AllProjectsPipeline {
|
||||
if (typeof value !== "object" || value === null) return false;
|
||||
const v = value as Record<string, unknown>;
|
||||
if (typeof v.active !== "string") return false;
|
||||
if (typeof v.projects !== "object" || v.projects === null) return false;
|
||||
for (const proj of Object.values(v.projects as Record<string, unknown>)) {
|
||||
if (typeof proj !== "object" || proj === null) return false;
|
||||
const p = proj as Record<string, unknown>;
|
||||
if (!Array.isArray(p.active) && typeof p.error !== "string") return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function gatewayRequest<T>(
|
||||
path: string,
|
||||
options: RequestInit = {},
|
||||
@@ -164,11 +179,15 @@ export const gatewayApi = {
|
||||
const text = await res.text();
|
||||
throw new Error(text || `Request failed (${res.status})`);
|
||||
}
|
||||
const rpc = await res.json() as { result?: AllProjectsPipeline; error?: { message: string } };
|
||||
const rpc = await res.json() as { result?: unknown; error?: { message: string } };
|
||||
if (rpc.error) {
|
||||
throw new Error(rpc.error.message);
|
||||
}
|
||||
return rpc.result!;
|
||||
const result = rpc.result;
|
||||
if (!isAllProjectsPipeline(result)) {
|
||||
throw new Error("pipeline.get returned unexpected shape");
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
/// Switch the active project via the MCP switch_project tool.
|
||||
|
||||
Reference in New Issue
Block a user