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