mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-12-03 13:34:05 +01:00
Agents pane: CLI-only MCP, yaak mcp --http, and plugin deprecation (#761)
This commit is contained in:
1 parent
349e6f9197
commit
6132171791
32 files changed
+950
-524
No files matched your search
@@ -123,8 +123,6 @@ export default function Settings({ tab, hide }: Props) {
|
||||
<CountBadge count={settings.clientCertificates.length} />
|
||||
) : value === TAB_PLUGINS ? (
|
||||
<CountBadge count={plugins.filter((p) => p.source !== "bundled").length} />
|
||||
) : value === TAB_AGENTS && settings.mcpServerEnabled ? (
|
||||
<CountBadge count />
|
||||
) : value === TAB_PROXY && settings.proxy?.type === "enabled" ? (
|
||||
<CountBadge count />
|
||||
) : value === TAB_LICENSE && licenseCheck.check.data?.status === "personal_use" ? (
|
||||
|
||||
@@ -1,145 +1,72 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { settingsAtom } from "@yaakapp-internal/models";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
import { Heading, Icon, InlineCode, VStack } from "@yaakapp-internal/ui";
|
||||
import type { AppMetaData } from "@yaakapp-internal/rpc-schema";
|
||||
import { useAtomValue } from "jotai";
|
||||
import type { AgentSetupStatus, AppMetaData } from "@yaakapp-internal/rpc-schema";
|
||||
import { Banner, Heading, Icon, InlineCode, VStack } from "@yaakapp-internal/ui";
|
||||
import { useEffect } from "react";
|
||||
import { useKeyValue } from "../../hooks/useKeyValue";
|
||||
import { appInfo } from "../../lib/appInfo";
|
||||
import { usePluginInfos } from "../../hooks/usePluginInfo";
|
||||
import {
|
||||
AGENT_CLIENTS,
|
||||
type AgentClient,
|
||||
type AgentSetup,
|
||||
appSetup,
|
||||
cliSetup,
|
||||
skillInstallCommand,
|
||||
} from "../../lib/agentSetup";
|
||||
import { appInfo } from "../../lib/appInfo";
|
||||
import { rpc } from "../../lib/rpc";
|
||||
import { CopyIconButton } from "../CopyIconButton";
|
||||
import { Button } from "../core/Button";
|
||||
import { Editor } from "../core/Editor/LazyEditor";
|
||||
import { IconButton } from "../core/IconButton";
|
||||
import { Link } from "../core/Link";
|
||||
import { SegmentedControl } from "../core/SegmentedControl";
|
||||
import {
|
||||
ModelSettingRowBoolean,
|
||||
SettingRow,
|
||||
SettingValue,
|
||||
SettingCommand,
|
||||
SettingSnippet,
|
||||
SettingsList,
|
||||
SettingsSection,
|
||||
} from "../core/SettingRow";
|
||||
import { DeprecatedPluginBanner } from "./SettingsPlugins";
|
||||
|
||||
const MCP_URL = "http://127.0.0.1:64343/mcp";
|
||||
const CLI_INSTALL_COMMAND = "npm install -g @yaakapp/cli";
|
||||
const SKILL_INSTALL_COMMAND = "yaak agent install";
|
||||
const MCP_SERVER_PLUGIN = "@yaak/mcp-server";
|
||||
|
||||
export function SettingsAgents() {
|
||||
const settings = useAtomValue(settingsAtom);
|
||||
const { value: token } = useKeyValue<string | null>({
|
||||
namespace: "no_sync",
|
||||
key: "mcp_server_token",
|
||||
fallback: null,
|
||||
});
|
||||
const queryClient = useQueryClient();
|
||||
const { value: storedClient, set: setClient } = useKeyValue<AgentClient>({
|
||||
key: "agents_setup_client",
|
||||
fallback: "claude_code",
|
||||
});
|
||||
const client = AGENT_CLIENTS.find((c) => c.value === storedClient)?.value ?? "claude_code";
|
||||
const clientLabel = AGENT_CLIENTS.find((c) => c.value === client)?.label ?? "your agent";
|
||||
const cliVersion = useQuery({
|
||||
queryKey: ["cli_version"],
|
||||
queryFn: async () => (await rpc<AppMetaData>("cmd_metadata")).cliVersion,
|
||||
initialData: appInfo.cliVersion,
|
||||
});
|
||||
const setupStatus = useQuery({
|
||||
queryKey: ["agent_setup_status", client],
|
||||
queryFn: () => rpc<AgentSetupStatus>("cmd_agent_setup_status", { agent: client }),
|
||||
});
|
||||
const mcpServerPlugin = usePluginInfos().find(({ info }) => info.name === MCP_SERVER_PLUGIN);
|
||||
|
||||
useEffect(() => {
|
||||
return platform.window.onFocusChanged((focused) => {
|
||||
if (!focused) return;
|
||||
void queryClient.invalidateQueries({ queryKey: ["cli_version"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["agent_setup_status"] });
|
||||
});
|
||||
}, [queryClient]);
|
||||
|
||||
const cliInstalled = cliVersion.data != null;
|
||||
const cli = cliSetup(client);
|
||||
|
||||
return (
|
||||
<VStack space={1.5} className="mb-4">
|
||||
<div className="mb-3">
|
||||
<Heading>Agents</Heading>
|
||||
<p className="text-text-subtle">
|
||||
Connect AI coding agents like Claude Code and Cursor to Yaak, so they can read, edit, and
|
||||
send your requests.
|
||||
Connect AI coding agents like Claude Code and Cursor to Yaak.
|
||||
</p>
|
||||
</div>
|
||||
<SettingsList className="space-y-8">
|
||||
<SettingsSection
|
||||
title="Yaak CLI"
|
||||
description="Lets agents use Yaak from the command line, even with the app closed."
|
||||
>
|
||||
<SettingRow
|
||||
title="Status"
|
||||
description={
|
||||
cliVersion.data == null
|
||||
? "The Yaak CLI is not installed."
|
||||
: `Yaak CLI ${cliVersion.data} is installed.`
|
||||
}
|
||||
controlClassName="gap-2"
|
||||
>
|
||||
<IconButton
|
||||
size="sm"
|
||||
icon="refresh"
|
||||
title="Check again"
|
||||
spin={cliVersion.isFetching}
|
||||
onClick={() => cliVersion.refetch()}
|
||||
/>
|
||||
{cliVersion.data == null && (
|
||||
<Button
|
||||
variant="border"
|
||||
color="secondary"
|
||||
size="sm"
|
||||
onClick={() => platform.openUrl("https://yaak.app/docs/cli")}
|
||||
rightSlot={<Icon icon="external_link" />}
|
||||
>
|
||||
Install CLI
|
||||
</Button>
|
||||
)}
|
||||
</SettingRow>
|
||||
{cliVersion.data == null ? (
|
||||
<SettingRow title="Install" description="Install it with npm.">
|
||||
<SettingValue value={CLI_INSTALL_COMMAND} />
|
||||
</SettingRow>
|
||||
) : (
|
||||
<SettingRow
|
||||
title="Agent skill"
|
||||
description={
|
||||
<>
|
||||
Teach Claude Code, Cursor, Codex, and opencode to drive the{" "}
|
||||
<InlineCode>yaak</InlineCode> command, wherever they're installed.
|
||||
</>
|
||||
}
|
||||
>
|
||||
<SettingValue value={SKILL_INSTALL_COMMAND} />
|
||||
</SettingRow>
|
||||
)}
|
||||
</SettingsSection>
|
||||
|
||||
<SettingsSection
|
||||
title="MCP server in the app"
|
||||
description="For agents that connect over HTTP, or to act on the workspaces open in Yaak."
|
||||
>
|
||||
<ModelSettingRowBoolean
|
||||
model={settings}
|
||||
modelKey="mcpServerEnabled"
|
||||
title="Enable MCP server"
|
||||
description={
|
||||
<>
|
||||
Serve Yaak's tools at <InlineCode>{MCP_URL}</InlineCode> while Yaak is open.
|
||||
</>
|
||||
}
|
||||
/>
|
||||
{settings.mcpServerEnabled && token != null && (
|
||||
<SettingRow
|
||||
title="Token"
|
||||
description="Agents send this as a bearer token."
|
||||
controlClassName="min-w-0 max-w-[min(24rem,40vw)] gap-2"
|
||||
>
|
||||
<SettingValue value={token} />
|
||||
</SettingRow>
|
||||
)}
|
||||
</SettingsSection>
|
||||
|
||||
<SettingsSection
|
||||
title="Connect an agent"
|
||||
description="Pick your agent or editor to see how to add Yaak's MCP tools to it."
|
||||
>
|
||||
<div className="py-4 border-b border-border-subtle">
|
||||
<SettingsList>
|
||||
<SettingsSection title={null}>
|
||||
<div className="pb-4 border-b border-border-subtle">
|
||||
<SegmentedControl
|
||||
name="agents_setup_client"
|
||||
label="Agent"
|
||||
@@ -149,59 +76,65 @@ export function SettingsAgents() {
|
||||
options={AGENT_CLIENTS}
|
||||
/>
|
||||
</div>
|
||||
<SetupRow
|
||||
title="Through the Yaak CLI"
|
||||
description={
|
||||
cliVersion.data == null
|
||||
? "Recommended. Install the Yaak CLI above first."
|
||||
: `Recommended. ${cliSetup(client).where}`
|
||||
}
|
||||
setup={cliSetup(client)}
|
||||
/>
|
||||
{settings.mcpServerEnabled && token != null ? (
|
||||
<SetupRow
|
||||
title="Through the app"
|
||||
description={appSetup(client, MCP_URL, token).where}
|
||||
setup={appSetup(client, MCP_URL, token)}
|
||||
/>
|
||||
{cliInstalled ? (
|
||||
<div className="flex items-center gap-2 py-3 text-sm text-text-subtle border-b border-border-subtle">
|
||||
<Icon icon="check" size="sm" color="success" />
|
||||
<span>
|
||||
Yaak CLI <span className="text-text">{cliVersion.data}</span> is installed.
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<SettingRow
|
||||
title="Through the app"
|
||||
description="Turn on the MCP server above to connect this way."
|
||||
>
|
||||
<span />
|
||||
</SettingRow>
|
||||
<div className="py-4 border-b border-border-subtle">
|
||||
<Banner color="info">
|
||||
<div className="flex items-center gap-2 text text-text">
|
||||
<Icon icon="square_terminal" color="info" />
|
||||
Install the Yaak CLI first
|
||||
</div>
|
||||
<p className="mt-1 text-sm text-text-subtle">
|
||||
Agents launch it to reach Yaak, even with the app closed.
|
||||
</p>
|
||||
<SettingSnippet className="mt-3" language="shell" snippet={CLI_INSTALL_COMMAND} />
|
||||
<div className="mt-3 mb-1 flex items-center gap-4 text-sm">
|
||||
<Link href="https://yaak.app/docs/cli">Docs</Link>
|
||||
<span className="text-text-subtlest">
|
||||
Checks again when you come back to Yaak.
|
||||
</span>
|
||||
</div>
|
||||
</Banner>
|
||||
</div>
|
||||
)}
|
||||
{mcpServerPlugin != null && (
|
||||
<div className="py-4 border-b border-border-subtle">
|
||||
<DeprecatedPluginBanner
|
||||
plugin={mcpServerPlugin.plugin}
|
||||
name={mcpServerPlugin.info.displayName}
|
||||
>
|
||||
The two steps below replace it. Uninstall it once your agent is connected.
|
||||
</DeprecatedPluginBanner>
|
||||
</div>
|
||||
)}
|
||||
<SettingCommand
|
||||
title="Add the MCP server"
|
||||
description={cli.where}
|
||||
snippet={cli.snippet}
|
||||
language={cli.language}
|
||||
disabled={!cliInstalled}
|
||||
done={setupStatus.data?.mcpServer ? "Added" : null}
|
||||
/>
|
||||
<SettingCommand
|
||||
title="Install the skill"
|
||||
description={
|
||||
<>
|
||||
Lets {clientLabel} run the <InlineCode>yaak</InlineCode> command directly.
|
||||
</>
|
||||
}
|
||||
snippet={skillInstallCommand(client)}
|
||||
language="shell"
|
||||
disabled={!cliInstalled}
|
||||
done={setupStatus.data?.skill ? "Installed" : null}
|
||||
/>
|
||||
</SettingsSection>
|
||||
</SettingsList>
|
||||
</VStack>
|
||||
);
|
||||
}
|
||||
|
||||
function SetupRow({
|
||||
title,
|
||||
description,
|
||||
setup,
|
||||
}: {
|
||||
title: string;
|
||||
description: string;
|
||||
setup: AgentSetup;
|
||||
}) {
|
||||
return (
|
||||
<div className="py-4 border-b border-border-subtle">
|
||||
<div className="text text-text">{title}</div>
|
||||
<div className="mt-1 text-sm text-text-subtle">{description}</div>
|
||||
<Editor
|
||||
readOnly
|
||||
hideGutter
|
||||
wrapLines
|
||||
heightMode="auto"
|
||||
stateKey={null}
|
||||
language={setup.language}
|
||||
defaultValue={setup.snippet}
|
||||
className="mt-3 border border-border-subtle rounded-md px-2"
|
||||
actions={<CopyIconButton size="sm" variant="border" text={setup.snippet} title="Copy setup" />}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2,13 +2,9 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import type { Plugin } from "@yaakapp-internal/models";
|
||||
import { patchModel, pluginsAtom } from "@yaakapp-internal/models";
|
||||
import type { PluginVersion } from "@yaakapp-internal/plugins";
|
||||
import { checkPluginUpdates, installPlugin, searchPlugins } from "@yaakapp-internal/plugins";
|
||||
import {
|
||||
checkPluginUpdates,
|
||||
installPlugin,
|
||||
searchPlugins,
|
||||
uninstallPlugin,
|
||||
} from "@yaakapp-internal/plugins";
|
||||
import {
|
||||
Banner,
|
||||
HStack,
|
||||
Icon,
|
||||
InlineCode,
|
||||
@@ -24,12 +20,11 @@ import {
|
||||
} from "@yaakapp-internal/ui";
|
||||
import classNames from "classnames";
|
||||
import { useAtomValue } from "jotai";
|
||||
import { useState } from "react";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { useInstallPlugin } from "../../hooks/useInstallPlugin";
|
||||
import { usePluginInfo } from "../../hooks/usePluginInfo";
|
||||
import { usePluginInfo, usePluginInfos } from "../../hooks/usePluginInfo";
|
||||
import { usePluginsKey, useRefreshPlugins } from "../../hooks/usePlugins";
|
||||
import { showConfirmDelete } from "../../lib/confirm";
|
||||
import { minPromiseMillis } from "../../lib/minPromiseMillis";
|
||||
import { usePromptUninstallPlugin } from "../../hooks/useUninstallPlugin";
|
||||
import { Button } from "../core/Button";
|
||||
import { Checkbox } from "../core/Checkbox";
|
||||
import { IconButton } from "../core/IconButton";
|
||||
@@ -205,7 +200,7 @@ function PluginTableRow({
|
||||
mutationKey: ["install_plugin", name],
|
||||
mutationFn: (name: string) => installPlugin(name, null),
|
||||
});
|
||||
const uninstall = usePromptUninstall(plugin?.id ?? null, displayName);
|
||||
const uninstall = usePromptUninstallPlugin(plugin?.id ?? null, displayName);
|
||||
const refreshPlugins = useRefreshPlugins();
|
||||
|
||||
return (
|
||||
@@ -296,7 +291,10 @@ function PluginSearch() {
|
||||
const debouncedQuery = useDebouncedValue(query);
|
||||
const results = useQuery({
|
||||
queryKey: ["plugins", debouncedQuery],
|
||||
queryFn: () => searchPlugins(query),
|
||||
queryFn: async () => {
|
||||
const { plugins } = await searchPlugins(query);
|
||||
return { plugins: plugins.filter((p) => p.deprecated == null) };
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -349,22 +347,77 @@ function InstalledPlugins({ plugins, className }: { plugins: Plugin[]; className
|
||||
</EmptyStateText>
|
||||
</div>
|
||||
) : (
|
||||
<Table scrollable className={className}>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableHeaderCell className="w-0" />
|
||||
<TableHeaderCell>Display Name</TableHeaderCell>
|
||||
<TableHeaderCell>Name</TableHeaderCell>
|
||||
<TableHeaderCell>Version</TableHeaderCell>
|
||||
<TableHeaderCell />
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<tbody className="divide-y divide-surface-highlight">
|
||||
{plugins.map((p) => (
|
||||
<PluginTableRowForInstalledPlugin key={p.id} plugin={p} />
|
||||
))}
|
||||
</tbody>
|
||||
</Table>
|
||||
<div className={classNames(className, "h-full grid grid-rows-[auto_minmax(0,1fr)]")}>
|
||||
<DeprecatedPluginBanners />
|
||||
<Table scrollable>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableHeaderCell className="w-0" />
|
||||
<TableHeaderCell>Display Name</TableHeaderCell>
|
||||
<TableHeaderCell>Name</TableHeaderCell>
|
||||
<TableHeaderCell>Version</TableHeaderCell>
|
||||
<TableHeaderCell />
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<tbody className="divide-y divide-surface-highlight">
|
||||
{plugins.map((p) => (
|
||||
<PluginTableRowForInstalledPlugin key={p.id} plugin={p} />
|
||||
))}
|
||||
</tbody>
|
||||
</Table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function DeprecatedPluginBanners() {
|
||||
const deprecated = usePluginInfos().filter(
|
||||
({ plugin, info }) => plugin.source !== "bundled" && info.deprecated != null,
|
||||
);
|
||||
return (
|
||||
<div className={classNames("flex flex-col gap-2", deprecated.length > 0 && "pb-3")}>
|
||||
{deprecated.map(({ plugin, info }) => (
|
||||
<DeprecatedPluginBanner key={plugin.id} plugin={plugin} name={info.displayName}>
|
||||
{withInlineCode(info.deprecated ?? "")}
|
||||
</DeprecatedPluginBanner>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Backtick spans in a package.json string, set as code. */
|
||||
function withInlineCode(text: string): ReactNode {
|
||||
return text
|
||||
.split("`")
|
||||
.map((part, i) => (i % 2 === 1 ? <InlineCode key={i}>{part}</InlineCode> : part));
|
||||
}
|
||||
|
||||
export function DeprecatedPluginBanner({
|
||||
children,
|
||||
name,
|
||||
plugin,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
name: string;
|
||||
plugin: Plugin;
|
||||
}) {
|
||||
const uninstall = usePromptUninstallPlugin(plugin.id, name);
|
||||
return (
|
||||
<Banner color="info" className="flex items-center gap-4">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="text text-text">The {name} plugin is deprecated.</div>
|
||||
<p className="mt-1 text-sm text-text-subtle">{children}</p>
|
||||
</div>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="border"
|
||||
title="Uninstall plugin"
|
||||
className="shrink-0"
|
||||
isLoading={uninstall?.isPending}
|
||||
onClick={() => uninstall?.mutate()}
|
||||
>
|
||||
Uninstall
|
||||
</Button>
|
||||
</Banner>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -393,31 +446,6 @@ function BundledPlugins({ plugins }: { plugins: Plugin[] }) {
|
||||
);
|
||||
}
|
||||
|
||||
function usePromptUninstall(pluginId: string | null, name: string) {
|
||||
const mut = useMutation({
|
||||
mutationKey: ["uninstall_plugin", pluginId],
|
||||
mutationFn: async () => {
|
||||
if (pluginId == null) return;
|
||||
|
||||
const confirmed = await showConfirmDelete({
|
||||
id: `uninstall-plugin-${pluginId}`,
|
||||
title: "Uninstall Plugin",
|
||||
confirmText: "Uninstall",
|
||||
description: (
|
||||
<>
|
||||
Permanently uninstall <InlineCode>{name}</InlineCode>?
|
||||
</>
|
||||
),
|
||||
});
|
||||
if (confirmed) {
|
||||
await minPromiseMillis(uninstallPlugin(pluginId), 700);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return pluginId == null ? null : mut;
|
||||
}
|
||||
|
||||
function usePluginUpdates() {
|
||||
return useQuery({
|
||||
queryKey: ["plugin_updates", usePluginsKey()],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AnyModel } from "@yaakapp-internal/models";
|
||||
import { patchModel } from "@yaakapp-internal/models";
|
||||
import { Icon } from "@yaakapp-internal/ui";
|
||||
import classNames from "classnames";
|
||||
import type { ReactNode } from "react";
|
||||
import { CopyIconButton } from "../CopyIconButton";
|
||||
@@ -139,6 +140,90 @@ export function SettingValue({
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A command or config to copy, set as a block: its title, an optional line
|
||||
* saying which file it goes in, then the snippet at full width with the copy
|
||||
* button on it. One-line shell commands and multi-line JSON get the same block.
|
||||
*/
|
||||
export function SettingCommand({
|
||||
className,
|
||||
description,
|
||||
disabled,
|
||||
done,
|
||||
language,
|
||||
snippet,
|
||||
title,
|
||||
}: {
|
||||
description?: ReactNode;
|
||||
disabled?: boolean;
|
||||
/** A short word shown with a check beside the title once the step is detected as done */
|
||||
done?: ReactNode;
|
||||
language: SettingSnippetLanguage;
|
||||
snippet: string;
|
||||
title: ReactNode;
|
||||
} & Pick<SettingRowBaseProps, "className">) {
|
||||
return (
|
||||
<div
|
||||
aria-disabled={disabled || undefined}
|
||||
className={classNames(
|
||||
className,
|
||||
"border-b border-border-subtle py-4",
|
||||
disabled && "opacity-disabled",
|
||||
)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-2 text text-text">
|
||||
<span>{title}</span>
|
||||
{done != null && done !== false && (
|
||||
<span className="inline-flex items-center gap-1 text-sm text-success">
|
||||
<Icon icon="check" size="sm" />
|
||||
{done}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{description != null && (
|
||||
<div className="mt-1 max-w-2xl text-sm text-text-subtle">{description}</div>
|
||||
)}
|
||||
<SettingSnippet className="mt-3" language={language} snippet={snippet} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export type SettingSnippetLanguage = "shell" | "json" | "text";
|
||||
|
||||
/** The snippet half of a `SettingCommand`, for places with their own title, like a banner. */
|
||||
export function SettingSnippet({
|
||||
className,
|
||||
language,
|
||||
snippet,
|
||||
}: {
|
||||
className?: string;
|
||||
language: SettingSnippetLanguage;
|
||||
snippet: string;
|
||||
}) {
|
||||
const prompt = language === "shell";
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
className,
|
||||
"flex items-start gap-2 rounded-md border border-border-subtle bg-surface-highlight/40 py-1.5 pr-1.5 pl-3",
|
||||
)}
|
||||
>
|
||||
<div className="flex min-h-sm min-w-0 flex-1 items-center font-mono text-editor text-text">
|
||||
<span className="cursor-text select-text whitespace-pre-wrap [overflow-wrap:anywhere]">
|
||||
{prompt && (
|
||||
<span aria-hidden className="mr-2 select-none text-text-subtlest">
|
||||
$
|
||||
</span>
|
||||
)}
|
||||
{snippet}
|
||||
</span>
|
||||
</div>
|
||||
<CopyIconButton size="sm" variant="border" title="Copy" text={snippet} className="shrink-0" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
type SettingValueAction = {
|
||||
icon: IconButtonProps["icon"];
|
||||
onClick: () => void;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useQueries, useQuery } from "@tanstack/react-query";
|
||||
import type { Plugin } from "@yaakapp-internal/models";
|
||||
import { pluginsAtom } from "@yaakapp-internal/models";
|
||||
import type { PluginMetadata } from "@yaakapp-internal/plugins";
|
||||
@@ -24,6 +24,22 @@ export function usePluginInfo(id: string | null) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Every plugin with its metadata, once loaded; the ones still loading are left out. */
|
||||
export function usePluginInfos() {
|
||||
const plugins = useAtomValue(pluginsAtom);
|
||||
return useQueries({
|
||||
queries: plugins.map((plugin) => ({
|
||||
queryKey: pluginInfoKey(plugin.id, plugin),
|
||||
queryFn: () => rpc<PluginMetadata>("cmd_plugin_info", { id: plugin.id }),
|
||||
})),
|
||||
combine: (results) =>
|
||||
results.flatMap((result, i) => {
|
||||
const plugin = plugins[i];
|
||||
return result.data == null || plugin == null ? [] : [{ plugin, info: result.data }];
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export function invalidateAllPluginInfo() {
|
||||
queryClient.invalidateQueries({ queryKey: ["plugin_info"] }).catch(console.error);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { uninstallPlugin } from "@yaakapp-internal/plugins";
|
||||
import { InlineCode } from "@yaakapp-internal/ui";
|
||||
import { showConfirmDelete } from "../lib/confirm";
|
||||
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
||||
|
||||
/** Confirms, then uninstalls. Null until there is a plugin to uninstall. */
|
||||
export function usePromptUninstallPlugin(pluginId: string | null, name: string) {
|
||||
const mut = useMutation({
|
||||
mutationKey: ["uninstall_plugin", pluginId],
|
||||
mutationFn: async () => {
|
||||
if (pluginId == null) return;
|
||||
|
||||
const confirmed = await showConfirmDelete({
|
||||
id: `uninstall-plugin-${pluginId}`,
|
||||
title: "Uninstall Plugin",
|
||||
confirmText: "Uninstall",
|
||||
description: (
|
||||
<>
|
||||
Permanently uninstall <InlineCode>{name}</InlineCode>?
|
||||
</>
|
||||
),
|
||||
});
|
||||
if (confirmed) {
|
||||
await minPromiseMillis(uninstallPlugin(pluginId), 700);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return pluginId == null ? null : mut;
|
||||
}
|
||||
@@ -1,15 +1,20 @@
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { AGENT_CLIENTS, appSetup, cliSetup } from "./agentSetup";
|
||||
|
||||
const URL = "http://127.0.0.1:64343/mcp";
|
||||
const TOKEN = "abc123";
|
||||
import { AGENT_CLIENTS, cliSetup, skillInstallCommand } from "./agentSetup";
|
||||
|
||||
describe("cliSetup", () => {
|
||||
test("uses each client's own add command", () => {
|
||||
expect(cliSetup("claude_code").snippet).toBe("claude mcp add yaak -- yaak mcp");
|
||||
expect(cliSetup("claude_code").snippet).toBe("claude mcp add -s user yaak -- yaak mcp");
|
||||
expect(cliSetup("codex").snippet).toBe("codex mcp add yaak -- yaak mcp");
|
||||
});
|
||||
|
||||
test("names a file only when the snippet goes in one", () => {
|
||||
expect(cliSetup("claude_code").where).toBeNull();
|
||||
expect(cliSetup("codex").where).toBeNull();
|
||||
expect(cliSetup("cursor").where).toBe("Add to ~/.cursor/mcp.json.");
|
||||
expect(cliSetup("vscode").where).toContain("mcp.json");
|
||||
expect(cliSetup("other").where).not.toBeNull();
|
||||
});
|
||||
|
||||
test("writes the config shape each client reads", () => {
|
||||
expect(JSON.parse(cliSetup("cursor").snippet)).toEqual({
|
||||
mcpServers: { yaak: { command: "yaak", args: ["mcp"] } },
|
||||
@@ -21,42 +26,27 @@ describe("cliSetup", () => {
|
||||
mcpServers: { yaak: { command: "yaak", args: ["mcp"] } },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("appSetup", () => {
|
||||
test("passes the token as a bearer header", () => {
|
||||
expect(appSetup("claude_code", URL, TOKEN).snippet).toBe(
|
||||
`claude mcp add --transport http yaak ${URL} --header "Authorization: Bearer ${TOKEN}"`,
|
||||
);
|
||||
expect(appSetup("codex", URL, TOKEN).snippet).toBe(
|
||||
`[mcp_servers.yaak]\nurl = "${URL}"\nhttp_headers = { "Authorization" = "Bearer ${TOKEN}" }`,
|
||||
);
|
||||
expect(JSON.parse(appSetup("cursor", URL, TOKEN).snippet)).toEqual({
|
||||
mcpServers: { yaak: { url: URL, headers: { Authorization: `Bearer ${TOKEN}` } } },
|
||||
});
|
||||
expect(JSON.parse(appSetup("vscode", URL, TOKEN).snippet)).toEqual({
|
||||
servers: { yaak: { type: "http", url: URL, headers: { Authorization: `Bearer ${TOKEN}` } } },
|
||||
});
|
||||
expect(JSON.parse(appSetup("other", URL, TOKEN).snippet)).toEqual({
|
||||
mcpServers: {
|
||||
yaak: {
|
||||
command: "npx",
|
||||
args: ["-y", "mcp-remote", URL, "--header", `Authorization: Bearer ${TOKEN}`],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("keeps argument lists on one line", () => {
|
||||
expect(appSetup("other", URL, TOKEN).snippet).toContain(
|
||||
`"args": ["-y", "mcp-remote", "${URL}", "--header", "Authorization: Bearer ${TOKEN}"]`,
|
||||
);
|
||||
expect(cliSetup("cursor").snippet).toContain(`"args": ["mcp"]`);
|
||||
});
|
||||
|
||||
test("covers every listed client", () => {
|
||||
for (const { value } of AGENT_CLIENTS) {
|
||||
expect(cliSetup(value).snippet).not.toBe("");
|
||||
expect(appSetup(value, URL, TOKEN).snippet).toContain(TOKEN);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("skillInstallCommand", () => {
|
||||
test("targets the agents the installer knows by name", () => {
|
||||
expect(skillInstallCommand("claude_code")).toBe("yaak agent install --agent claude-code");
|
||||
expect(skillInstallCommand("codex")).toBe("yaak agent install --agent codex");
|
||||
expect(skillInstallCommand("cursor")).toBe("yaak agent install --agent cursor");
|
||||
});
|
||||
|
||||
test("installs everywhere for agents it cannot target", () => {
|
||||
expect(skillInstallCommand("vscode")).toBe("yaak agent install");
|
||||
expect(skillInstallCommand("other")).toBe("yaak agent install");
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,6 @@
|
||||
export type AgentClient = "claude_code" | "codex" | "cursor" | "vscode" | "other";
|
||||
import type { AgentClient } from "@yaakapp-internal/rpc-schema";
|
||||
|
||||
export type { AgentClient };
|
||||
|
||||
export const AGENT_CLIENTS: { label: string; value: AgentClient }[] = [
|
||||
{ label: "Claude Code", value: "claude_code" },
|
||||
@@ -9,21 +11,34 @@ export const AGENT_CLIENTS: { label: string; value: AgentClient }[] = [
|
||||
];
|
||||
|
||||
export interface AgentSetup {
|
||||
/** Where the snippet goes, as a sentence */
|
||||
where: string;
|
||||
/** The file the snippet goes in, as a sentence, when it is a file rather than a command */
|
||||
where: string | null;
|
||||
snippet: string;
|
||||
language: "shell" | "json" | "text";
|
||||
}
|
||||
|
||||
const RUN_IN_TERMINAL = "Run in a terminal.";
|
||||
/** `yaak agent install`, targeted at `client` when the installer knows it by name. */
|
||||
export function skillInstallCommand(client: AgentClient): string {
|
||||
switch (client) {
|
||||
case "claude_code":
|
||||
return "yaak agent install --agent claude-code";
|
||||
case "codex":
|
||||
return "yaak agent install --agent codex";
|
||||
case "cursor":
|
||||
return "yaak agent install --agent cursor";
|
||||
case "vscode":
|
||||
case "other":
|
||||
return "yaak agent install";
|
||||
}
|
||||
}
|
||||
|
||||
/** Setup for `yaak mcp`, which the client launches over stdio. */
|
||||
export function cliSetup(client: AgentClient): AgentSetup {
|
||||
switch (client) {
|
||||
case "claude_code":
|
||||
return { where: RUN_IN_TERMINAL, snippet: "claude mcp add yaak -- yaak mcp", language: "shell" };
|
||||
return { where: null, snippet: "claude mcp add -s user yaak -- yaak mcp", language: "shell" };
|
||||
case "codex":
|
||||
return { where: RUN_IN_TERMINAL, snippet: "codex mcp add yaak -- yaak mcp", language: "shell" };
|
||||
return { where: null, snippet: "codex mcp add yaak -- yaak mcp", language: "shell" };
|
||||
case "cursor":
|
||||
return {
|
||||
where: "Add to ~/.cursor/mcp.json.",
|
||||
@@ -45,56 +60,6 @@ export function cliSetup(client: AgentClient): AgentSetup {
|
||||
}
|
||||
}
|
||||
|
||||
/** Setup for the app's MCP server at `url`, which needs `token` as a bearer token. */
|
||||
export function appSetup(client: AgentClient, url: string, token: string): AgentSetup {
|
||||
const authorization = `Bearer ${token}`;
|
||||
switch (client) {
|
||||
case "claude_code":
|
||||
return {
|
||||
where: RUN_IN_TERMINAL,
|
||||
snippet: `claude mcp add --transport http yaak ${url} --header "Authorization: ${authorization}"`,
|
||||
language: "shell",
|
||||
};
|
||||
case "codex":
|
||||
return {
|
||||
where: "Add to ~/.codex/config.toml.",
|
||||
snippet: [
|
||||
"[mcp_servers.yaak]",
|
||||
`url = ${JSON.stringify(url)}`,
|
||||
`http_headers = { "Authorization" = ${JSON.stringify(authorization)} }`,
|
||||
].join("\n"),
|
||||
language: "text",
|
||||
};
|
||||
case "cursor":
|
||||
return {
|
||||
where: "Add to ~/.cursor/mcp.json.",
|
||||
snippet: json({ mcpServers: { yaak: { url, headers: { Authorization: authorization } } } }),
|
||||
language: "json",
|
||||
};
|
||||
case "vscode":
|
||||
return {
|
||||
where: "Add to your user mcp.json (MCP: Open User Configuration).",
|
||||
snippet: json({
|
||||
servers: { yaak: { type: "http", url, headers: { Authorization: authorization } } },
|
||||
}),
|
||||
language: "json",
|
||||
};
|
||||
case "other":
|
||||
return {
|
||||
where: "For clients that read an mcpServers config, through the mcp-remote bridge.",
|
||||
snippet: json({
|
||||
mcpServers: {
|
||||
yaak: {
|
||||
command: "npx",
|
||||
args: ["-y", "mcp-remote", url, "--header", `Authorization: ${authorization}`],
|
||||
},
|
||||
},
|
||||
}),
|
||||
language: "json",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** Pretty JSON with arrays of plain values kept on one line. */
|
||||
function json(value: unknown): string {
|
||||
return JSON.stringify(value, null, 2).replace(
|
||||
|
||||
Reference in new issue
Block a user