fix: clean up onboarding + channel selection types
This commit is contained in:
@@ -63,7 +63,7 @@ export function downgradeGeminiThinkingBlocks(messages: AgentMessage[]): AgentMe
|
||||
const trimmed = thinking.trim();
|
||||
hasDowngraded = true;
|
||||
if (!trimmed) return [];
|
||||
return [{ type: "text", text: thinking }];
|
||||
return [{ type: "text" as const, text: thinking }];
|
||||
});
|
||||
|
||||
if (!hasDowngraded) {
|
||||
|
||||
@@ -246,15 +246,19 @@ export async function setupChannels(
|
||||
|
||||
options?.onSelection?.(selection);
|
||||
|
||||
const selectionNotes = new Map(
|
||||
[
|
||||
...installedPlugins.map((plugin) => [plugin.id, plugin.meta]),
|
||||
...catalogEntries.map((entry) => [entry.id, entry.meta]),
|
||||
].map(([id, meta]) => [
|
||||
id,
|
||||
formatChannelSelectionLine(meta, formatDocsLink),
|
||||
]),
|
||||
);
|
||||
const selectionNotes = new Map<string, string>();
|
||||
for (const plugin of installedPlugins) {
|
||||
selectionNotes.set(
|
||||
plugin.id,
|
||||
formatChannelSelectionLine(plugin.meta, formatDocsLink),
|
||||
);
|
||||
}
|
||||
for (const entry of catalogEntries) {
|
||||
selectionNotes.set(
|
||||
entry.id,
|
||||
formatChannelSelectionLine(entry.meta, formatDocsLink),
|
||||
);
|
||||
}
|
||||
const selectedLines = selection
|
||||
.map((channel) => selectionNotes.get(channel))
|
||||
.filter((line): line is string => Boolean(line));
|
||||
|
||||
@@ -6,7 +6,9 @@ import type { WizardPrompter } from "../../../wizard/prompts.js";
|
||||
export const makeRuntime = (overrides: Partial<RuntimeEnv> = {}): RuntimeEnv => ({
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn(),
|
||||
exit: vi.fn((code: number) => {
|
||||
throw new Error(`exit:${code}`);
|
||||
}) as RuntimeEnv["exit"],
|
||||
...overrides,
|
||||
});
|
||||
|
||||
|
||||
@@ -82,24 +82,26 @@ async function promptInstallChoice(params: {
|
||||
prompter: WizardPrompter;
|
||||
}): Promise<InstallChoice> {
|
||||
const { entry, localPath, prompter } = params;
|
||||
const localOptions: Array<{ value: InstallChoice; label: string; hint?: string }> = localPath
|
||||
? [
|
||||
{
|
||||
value: "local",
|
||||
label: "Use local plugin path",
|
||||
hint: localPath,
|
||||
},
|
||||
]
|
||||
: [];
|
||||
const options: Array<{ value: InstallChoice; label: string; hint?: string }> = [
|
||||
{ value: "npm", label: `Download from npm (${entry.install.npmSpec})` },
|
||||
...(localPath
|
||||
? [
|
||||
{
|
||||
value: "local",
|
||||
label: "Use local plugin path",
|
||||
hint: localPath,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...localOptions,
|
||||
{ value: "skip", label: "Skip for now" },
|
||||
];
|
||||
return (await prompter.select({
|
||||
const initialValue: InstallChoice = localPath ? "local" : "npm";
|
||||
return await prompter.select<InstallChoice>({
|
||||
message: `Install ${entry.meta.label} plugin?`,
|
||||
options,
|
||||
initialValue: localPath ? "local" : "npm",
|
||||
})) as InstallChoice;
|
||||
initialValue,
|
||||
});
|
||||
}
|
||||
|
||||
export async function ensureOnboardingPluginInstalled(params: {
|
||||
|
||||
@@ -111,8 +111,9 @@ export const agentHandlers: GatewayRequestHandlers = {
|
||||
}
|
||||
const rawChannel = typeof request.channel === "string" ? request.channel.trim() : "";
|
||||
if (rawChannel) {
|
||||
const isKnownGatewayChannel = (value: string): boolean => isGatewayMessageChannel(value);
|
||||
const normalized = normalizeMessageChannel(rawChannel);
|
||||
if (normalized && normalized !== "last" && !isGatewayMessageChannel(normalized)) {
|
||||
if (normalized && normalized !== "last" && !isKnownGatewayChannel(normalized)) {
|
||||
respond(
|
||||
false,
|
||||
undefined,
|
||||
|
||||
@@ -4,13 +4,21 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { createGatewayPluginRequestHandler } from "./plugins-http.js";
|
||||
import { createTestRegistry } from "./__tests__/test-utils.js";
|
||||
|
||||
const makeResponse = () =>
|
||||
({
|
||||
const makeResponse = (): {
|
||||
res: ServerResponse;
|
||||
setHeader: ReturnType<typeof vi.fn>;
|
||||
end: ReturnType<typeof vi.fn>;
|
||||
} => {
|
||||
const setHeader = vi.fn();
|
||||
const end = vi.fn();
|
||||
const res = {
|
||||
headersSent: false,
|
||||
statusCode: 200,
|
||||
setHeader: vi.fn(),
|
||||
end: vi.fn(),
|
||||
}) as unknown as ServerResponse;
|
||||
setHeader,
|
||||
end,
|
||||
} as unknown as ServerResponse;
|
||||
return { res, setHeader, end };
|
||||
};
|
||||
|
||||
describe("createGatewayPluginRequestHandler", () => {
|
||||
it("returns false when no handlers are registered", async () => {
|
||||
@@ -21,7 +29,8 @@ describe("createGatewayPluginRequestHandler", () => {
|
||||
registry: createTestRegistry(),
|
||||
log,
|
||||
});
|
||||
const handled = await handler({} as IncomingMessage, makeResponse());
|
||||
const { res } = makeResponse();
|
||||
const handled = await handler({} as IncomingMessage, res);
|
||||
expect(handled).toBe(false);
|
||||
});
|
||||
|
||||
@@ -38,7 +47,8 @@ describe("createGatewayPluginRequestHandler", () => {
|
||||
log: { warn: vi.fn() } as unknown as Parameters<typeof createGatewayPluginRequestHandler>[0]["log"],
|
||||
});
|
||||
|
||||
const handled = await handler({} as IncomingMessage, makeResponse());
|
||||
const { res } = makeResponse();
|
||||
const handled = await handler({} as IncomingMessage, res);
|
||||
expect(handled).toBe(true);
|
||||
expect(first).toHaveBeenCalledTimes(1);
|
||||
expect(second).toHaveBeenCalledTimes(1);
|
||||
@@ -63,15 +73,15 @@ describe("createGatewayPluginRequestHandler", () => {
|
||||
log,
|
||||
});
|
||||
|
||||
const res = makeResponse();
|
||||
const { res, setHeader, end } = makeResponse();
|
||||
const handled = await handler({} as IncomingMessage, res);
|
||||
expect(handled).toBe(true);
|
||||
expect(log.warn).toHaveBeenCalledWith(expect.stringContaining("boom"));
|
||||
expect(res.statusCode).toBe(500);
|
||||
expect(res.setHeader).toHaveBeenCalledWith(
|
||||
expect(setHeader).toHaveBeenCalledWith(
|
||||
"Content-Type",
|
||||
"text/plain; charset=utf-8",
|
||||
);
|
||||
expect(res.end).toHaveBeenCalledWith("Internal Server Error");
|
||||
expect(end).toHaveBeenCalledWith("Internal Server Error");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ export type MessageChannelId = DeliverableMessageChannel;
|
||||
|
||||
const getMessageChannels = () => listDeliverableMessageChannels();
|
||||
|
||||
function isKnownChannel(value: string): value is MessageChannelId {
|
||||
function isKnownChannel(value: string): boolean {
|
||||
return getMessageChannels().includes(value as MessageChannelId);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export async function listConfiguredMessageChannels(
|
||||
for (const plugin of listChannelPlugins()) {
|
||||
if (!isKnownChannel(plugin.id)) continue;
|
||||
if (await isPluginConfigured(plugin, cfg)) {
|
||||
channels.push(plugin.id);
|
||||
channels.push(plugin.id as MessageChannelId);
|
||||
}
|
||||
}
|
||||
return channels;
|
||||
@@ -62,7 +62,7 @@ export async function resolveMessageChannelSelection(params: {
|
||||
throw new Error(`Unknown channel: ${normalized}`);
|
||||
}
|
||||
return {
|
||||
channel: normalized,
|
||||
channel: normalized as MessageChannelId,
|
||||
configured: await listConfiguredMessageChannels(params.cfg),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user