From 4b9bdb1c51cb906f859636bb03dbdf8b9b69a6c9 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sun, 18 Oct 2026 11:33:21 +0000 Subject: [PATCH] feat(marketplace): agents find, install and update marketplace plugins find_plugins and install_plugin over MCP and in chat (install waits for the person's yes), GET /api/v1/marketplaces/plugins across marketplaces, and an installed plugin says when its marketplace lists another version. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019zfsgxTM4YuEChceSQkbvK --- README.md | 3 +- changelog.d/extensions-marketplace-agents.md | 6 + docs/assistant.md | 7 + docs/mcp.md | 5 +- docs/requirements.md | 1 + fastapi_backend/app/api/mcp_tools.py | 64 +++++ .../app/api/v1/routes/marketplaces.py | 15 +- fastapi_backend/app/domain/ai_tools.py | 37 +++ fastapi_backend/app/domain/marketplace.py | 42 +++- fastapi_backend/app/schemas/extensions.py | 7 + .../tests/api/test_marketplaces.py | 69 ++++++ fastapi_backend/tests/api/test_mcp.py | 1 + .../__tests__/marketplace-ui.test.tsx | 23 ++ nextjs-frontend/app/openapi-client/index.ts | 6 + nextjs-frontend/app/openapi-client/sdk.gen.ts | 16 ++ .../app/openapi-client/types.gen.ts | 125 ++++++++++ .../extensions/marketplace-page.tsx | 10 +- nextjs-frontend/openapi.json | 226 ++++++++++++++++++ 18 files changed, 649 insertions(+), 14 deletions(-) create mode 100644 changelog.d/extensions-marketplace-agents.md diff --git a/README.md b/README.md index a5eb642ca..d81db74d4 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,8 @@ listed under [In progress](#in-progress), and what comes next under [Planned](#p skills, hooks and MCP servers, by code, on the canvas or just by asking. Remote MCP servers connect by address, and ones that run as a program (`npx`, `uvx`) run in a sandboxed container of their own, off until you turn it on. Add one with a form or by pasting another app's config, its tokens sealed and each of its tools switched on or off. - Install skills and plugins from marketplaces in the open plugin format, or from a repository or an archive. + Install skills and plugins from marketplaces in the open plugin format, or from a repository or an archive; agents + find and install them too, and an installed plugin says when a new version is listed. ([Extending the assistant](docs/assistant.md#extending-the-assistant-tools-skills-hooks-and-plugins), [adding an MCP server](docs/assistant.md#adding-an-mcp-server), [the MCP runner](docs/assistant.md#the-mcp-runner); [checks](docs/requirements.md#extend-the-assistant)) diff --git a/changelog.d/extensions-marketplace-agents.md b/changelog.d/extensions-marketplace-agents.md new file mode 100644 index 000000000..cc7b9c2e3 --- /dev/null +++ b/changelog.d/extensions-marketplace-agents.md @@ -0,0 +1,6 @@ +- **Agents find, install and update marketplace plugins.** `find_plugins` and `install_plugin` (over MCP, and in + chat, where installing waits for your yes) look across every marketplace added and install a plugin as your own + extension. A plugin you installed now says which version you have, and its button reads **Update to** the version + its marketplace lists when that's another; `GET /api/v1/marketplaces/plugins` finds plugins across marketplaces + (`?updates=true` for those with another version) + ([Skills and plugins from marketplaces](docs/assistant.md#skills-and-plugins-from-marketplaces)). diff --git a/docs/assistant.md b/docs/assistant.md index cf2e71869..5ba116c68 100644 --- a/docs/assistant.md +++ b/docs/assistant.md @@ -819,6 +819,13 @@ Lens reads Anthropic's open plugin and skill formats as they are, so what's made and any other is added by its address (`owner/repo`, a GitHub or GitLab link, or a link to its marketplace.json), which is how a team runs a custom one. Everyone who can edit browses them, previews a plugin (what it adds and what Lens leaves out) and installs it. +- **Finding and updating**: `GET /api/v1/marketplaces/plugins?q=` looks for a plugin across every marketplace added, + by the words in its name, description, category or author. A plugin you installed says which version you have, and + when its marketplace (read again on **Refresh**) lists another, its button reads **Update to** that version; + `?updates=true` lists only those. +- **For agents**: over [MCP](mcp.md), `find_plugins` finds them (`updates` for the ones with another version) and + `install_plugin` installs one, or with `preview` says what it would add. In chat the assistant has the same two + tools, and installing waits for your yes, like saving an extension. - **Links and files** (`POST /api/v1/extensions/import`, `/import/archive`): a plugin or a skill from a GitHub or GitLab repository or folder, or a `.zip`, `.skill` or `.tar.gz`. diff --git a/docs/mcp.md b/docs/mcp.md index 773f67d58..27929ac0a 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -142,6 +142,8 @@ For an app that speaks OpenAI's API rather than MCP, the namespace can also answ | `set_picture_descriptions` | choose what describes pictures (`engine` `llm`, `florence-2` or `moondream`), the provider's `vision_model`, Florence-2's size (`florence_model`), which Moondream (`moondream_model`) and `describe_max`. Admins only, with a write-scope token | | `mcp_servers` | the MCP servers the assistant calls ([Adding an MCP server](assistant.md#adding-an-mcp-server)): each one's address or command, the names of its headers and env (never their values), whether it's on, its tools and those switched off, and its page; and the ready-made ones (browser, github), whether each is added and what it needs. Admins only | | `add_mcp_server` | add one: a ready-made one (`preset`, with `values` for its token) or your own (`server`: `{url, headers}` or `{command, args, env}`, with `off`, `ask` and `keep`); Lens lists its tools first, so it must answer, and seals its tokens. Admins only, with an API key that has the write scope (not an app given access) | +| `find_plugins` | plugins and skills in the marketplaces an admin added ([Skills and plugins from marketplaces](assistant.md#skills-and-plugins-from-marketplaces)) that have every word of `query`, or with `updates` only those you installed that their marketplace lists another version of: each one's marketplace, version, whether Lens can install it and your extension installed from it | +| `install_plugin` | install one as your own extension, private until you share it, or bring yours to the version listed now; `preview` installs nothing and says what it would add and what Lens leaves out. Needs a write-scope token | | `install_settings` | whether other devices on the network reach Lens and its edition (full or lean), whether the machine's upgrade agent can change them, and the install line to run when it can't. Admins only | | `set_install_settings` | open Lens to the network or keep it to this machine, or change the edition: the machine sets itself up again and Lens restarts ([Updates](updates.md#setting-the-machine-up-again)). Admins only, with a write-scope token | | `news_feeds` | the news feeds (RSS or Atom) Lens follows, the namespaces each brings posts into and how the last scan went; addresses stay sealed. Admins only | @@ -167,7 +169,8 @@ which records an undoable change (proposed by default), `undo_graph_change`, `ed app (merges and deletes can be undone), `write_note`, which adds a note, `create_podcast`, which queues an episode, `create_feed` and `publish_to_feed`, which make and fill a [published feed](feeds.md), `write_spec`, which queues a spec, `set_nsfw` and `mark_nsfw`, which change [NSFW classification](nsfw.md) (owners or admins, and -editors), `set_namespace_integrations`, which turns a namespace's own MCP server or chat completions on or off (owners), `set_picture_descriptions`, which changes what describes pictures (admins), `set_file_storage`, which changes where new files are kept (admins), `set_secret_reference`, which points a secret field at a password manager's item (admins), `add_mcp_server`, which adds an +editors), `set_namespace_integrations`, which turns a namespace's own MCP server or chat completions on or off (owners), `set_picture_descriptions`, which changes what describes pictures (admins), `set_file_storage`, which changes where new files are kept (admins), `set_secret_reference`, which points a secret field at a password manager's item (admins), `install_plugin`, which +installs a plugin from a marketplace as your own extension, `add_mcp_server`, which adds an MCP server (admins), `subscribe_feed` and `unsubscribe_feed`, which follow and stop following news feeds (admins), and `set_monitoring`, `set_service`, `set_sandbox_gateway` (the [code sandbox](assistant.md#code-sandbox)'s gateway) and `set_install_settings`, which have the machine change how Lens runs (admins). Importing stays in the web app and the API. diff --git a/docs/requirements.md b/docs/requirements.md index 6fa07c2e5..4e11e3b26 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -108,6 +108,7 @@ request, to another check that proves the same thing; loosening a requirement or | MCP servers that run as a program (`npx`, `uvx`) run in a sandboxed container of their own | [test_mcp_servers.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_mcp_servers.py) `test_a_server_that_runs_as_a_program_runs_in_the_runner`; [mcp-runner.yml](https://github.com/adeelahmad/lense/blob/main/.github/workflows/mcp-runner.yml) `Runs an npm server and a PyPI server` | | An MCP server added by form or a pasted config, its tokens sealed and each tool switched on or off | [test_mcp_servers.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_mcp_servers.py) `test_a_pasted_config_reads_as_servers_to_add`, `test_its_secrets_are_sealed_and_never_shown`, `test_each_tool_is_switched_and_says_whether_it_asks`; [mcp-server-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/mcp-server-ui.test.tsx) `adding an MCP server` | | Skills and plugins from marketplaces in the open plugin format, a repository or an archive | [test_marketplaces.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_marketplaces.py) `test_a_marketplace_an_admin_adds`, `test_imported_from_a_link_or_a_file` | +| Plugins found across marketplaces, updates shown, and installed by agents over MCP, the API or chat | [test_marketplaces.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_marketplaces.py) `test_found_updated_and_installed_by_agents`; [marketplace-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/marketplace-ui.test.tsx) `an installed plugin with another version listed offers the update` | ## Bring in everything diff --git a/fastapi_backend/app/api/mcp_tools.py b/fastapi_backend/app/api/mcp_tools.py index 822f4d0e5..0d386bd4c 100644 --- a/fastapi_backend/app/api/mcp_tools.py +++ b/fastapi_backend/app/api/mcp_tools.py @@ -83,6 +83,7 @@ from app.domain import classify as classifymod from app.domain import entities as ents from app.domain import find as findmod +from app.domain import marketplace as marketmod from app.domain import sandbox as sandboxmod from app.domain import speakers as spk from app.domain import topics as topicmod @@ -2990,6 +2991,69 @@ def add_mcp_server( return _server_line(ctx, extensions.visible_one(ctx.db, _extension_me(ctx), eid)) +# ---------- plugins and skills from the marketplaces an admin added (marketplace.py) ---------- +@tool( + "find_plugins", + "Find plugins", + "Plugins and skills in the marketplaces an admin added (Anthropic's open plugin format): those whose name, " + "description, category or author has every word of query, or all of them; updates true lists only the ones you " + "installed that their marketplace now lists another version of. Each says its marketplace, version, whether Lens " + "can install it (why_not when it can't), and your extension installed from it. Install one with install_plugin.", + Arg("query", "string", "words to look for", max_length=200), + Arg("marketplace", "integer", "only this marketplace's plugins"), + Arg("updates", "boolean", "only the ones you installed that have another version listed", default=False), + Arg("limit", "integer", "at most this many", default=50, minimum=1, maximum=500), + personal=True, +) +def find_plugins(ctx: Context, query: str | None, marketplace: int | None, updates: bool, limit: int) -> dict[str, Any]: + found, matched = marketmod.find(ctx.db, _extension_me(ctx), query, marketplace, bool(updates), limit) + out: dict[str, Any] = {"plugins": found, "matched": matched, "page": f"{ctx.web}/extensions/marketplace"} + if marketplace is None and not ctx.db.one("SELECT id FROM marketplace LIMIT 1"): + out["note"] = "no marketplace is added yet: an admin adds one in the web app (Anthropic's are one click there)" + return out + + +@tool( + "install_plugin", + "Install a plugin", + "Install a plugin or skill from a marketplace (find_plugins gives the marketplace and plugin) as your own " + "extension, private until you share it and switched on; installing it again brings the version the marketplace " + "lists now. preview true installs nothing and says what it would add to the assistant (tools, skills, MCP servers) " + "and what Lens leaves out. Needs an API key with the write scope.", + Arg("marketplace", "integer", "the marketplace's id", required=True), + Arg("plugin", "string", "the plugin's name in it", required=True, max_length=200), + Arg("preview", "boolean", "only say what it would add", default=False), + writes=True, + personal=True, +) +def install_plugin(ctx: Context, marketplace: int, plugin: str, preview: bool) -> dict[str, Any]: + _writer(ctx, "install plugins") + me = _extension_me(ctx) + try: + if preview: + got = marketmod.preview(ctx.db, ctx.cfg, me, marketplace, plugin) + m = got["manifest"] + items = [store.clean({"kind": i["kind"], "name": i["name"], "description": i.get("description")}) for i in m.get("items") or []] + return { + "name": m["name"], + "description": m.get("description"), + "adds": items, + "leaves_out": got["skipped"], + "source": got["source"], + } + eid, n = marketmod.install(ctx.db, ctx.cfg, me, marketplace, plugin) + except PermissionError as e: + raise ToolError(str(e)) from None + auth.audit( + ctx.db, + ctx.user.as_audit(), + "extension.import", + f"extension:{eid}", + {"marketplace": marketplace, "plugin": plugin, "version": n, "via": "mcp"}, + ) + return {"id": eid, "version": n, "page": f"{ctx.web}/extensions/{eid}"} + + # ---------- how install.sh set this machine up: reachable on the network, and the edition (admins) ---------- @tool( "install_settings", diff --git a/fastapi_backend/app/api/v1/routes/marketplaces.py b/fastapi_backend/app/api/v1/routes/marketplaces.py index bb112b19a..caad54905 100644 --- a/fastapi_backend/app/api/v1/routes/marketplaces.py +++ b/fastapi_backend/app/api/v1/routes/marketplaces.py @@ -3,7 +3,7 @@ from __future__ import annotations -from fastapi import APIRouter +from fastapi import APIRouter, Query from app.api.deps import AdminWriter, Cfg, CurrentUser, Db, Writer from app.api.v1.routes.extensions import _errors, me @@ -15,6 +15,7 @@ Marketplace, MarketplaceCreate, MarketplacePlugin, + MarketplacePluginFound, MarketplaceSuggestion, ) @@ -32,6 +33,18 @@ def suggested_marketplaces(user: CurrentUser, db: Db) -> list[MarketplaceSuggest return marketplace.suggested(db) +@router.get("/plugins") +def find_marketplace_plugins( + user: CurrentUser, + db: Db, + q: str | None = Query(None, max_length=200, description="words its name, description, category or author has"), + updates: bool = Query(False, description="only plugins you installed that their marketplace lists another version of"), + limit: int = Query(50, ge=1, le=500), +) -> list[MarketplacePluginFound]: + """Plugins across every marketplace added, to find one to install or see which have updates.""" + return marketplace.find(db, me(user), q, updates=updates, limit=limit)[0] + + @router.post("") def add_marketplace(body: MarketplaceCreate, user: AdminWriter, db: Db, cfg: Cfg) -> Created: """Add a marketplace by its address; its list of plugins is read now.""" diff --git a/fastapi_backend/app/domain/ai_tools.py b/fastapi_backend/app/domain/ai_tools.py index 3131599b4..b3f8d1184 100644 --- a/fastapi_backend/app/domain/ai_tools.py +++ b/fastapi_backend/app/domain/ai_tools.py @@ -30,6 +30,7 @@ graph_history, llm, manual, + marketplace as marketmod, notebook, ns_assistant, ops_tools, @@ -479,6 +480,23 @@ ["name", "enabled"], True, ), + ( + "find_plugins", + "Plugins and skills in the marketplaces an admin added that have every word of query in their name, " + "description, category or author (or all of them); updates true: only the person's installed ones with another " + "version listed. Each gives its marketplace id, version, whether Lens can install it and whether it's installed.", + {"query": _S, "marketplace": _I, "updates": {"type": "boolean"}}, + [], + False, + ), + ( + "install_plugin", + "Install a plugin or skill from a marketplace (find_plugins gives marketplace and plugin) as the person's own " + "extension, or bring an installed one to the version listed now. Needs the person's approval.", + {"marketplace": _I, "plugin": _S}, + ["marketplace", "plugin"], + True, + ), ] # automations (automations.py): saving one is made at once, switched off; switching one on or running it now acts, so @@ -1324,6 +1342,20 @@ def t_switch_extension(self, name, enabled): what = f"Switch {g['kind']} {name} {'on' if enabled else 'off'}" return self._approval("switch_extension", {"extension": g["id"], "name": name, "enabled": bool(enabled)}, what) + def t_find_plugins(self, query=None, marketplace=None, updates=False): + found, n = marketmod.find(self.db, self.me, query, marketplace, bool(updates), 30) + keep = ("marketplace", "marketplace_name", "name", "description", "version", "installable", "why_not", "installed", "update") + out = [{k: p[k] for k in keep if k in p} for p in found] + return {"plugins": out, "matched": n}, f"Found {n} plugin{'' if n == 1 else 's'}" + + def t_install_plugin(self, marketplace, plugin): + got = marketmod.preview(self.db, self.cfg, self.me, int(marketplace), plugin) + items = ", ".join(f"{i['kind']} {i['name']}" for i in got["manifest"].get("items") or []) or "nothing" + have = next((p for p in marketmod.plugins(self.db, self.me, int(marketplace)) if p["name"] == plugin), {}) + verb = "Update" if have.get("installed") else "Install" + what = f"{verb} the plugin {plugin} from {got['source']}: {items}" + return self._approval("install_plugin", {"marketplace": int(marketplace), "plugin": plugin}, what[:300]) + # ---- the namespace's memory (ns_assistant.py) ---- def t_remember(self, fact, source_ref=None): sid, name, _ = self.home @@ -2291,6 +2323,11 @@ def _carry_out(db, cfg, a, user, editable, decision, base, admin, readable, via= result = run_extension(db, cfg, args, user, admin, box.readable, box) elif a["tool"] in ("save_extension", "switch_extension"): result = author_extension(db, a["tool"], args, user, admin, readable if readable is not None else editable, editable) + elif a["tool"] == "install_plugin": + rd = readable if readable is not None else editable + me = extensions.who(user["id"], user.get("email"), admin, {s: "editor" if s in editable else "viewer" for s in rd}) + eid, n = marketmod.install(db, cfg, me, args["marketplace"], args["plugin"]) + result = {"extension": eid, "version": n} elif a["tool"] in ("switch_automation", "run_automation"): result = _automation_approved(db, cfg, a["tool"], args, user, admin) elif a["tool"] in ("run_python", "run_bash"): # a run that can reach another host, asked first (Toolbox._sandbox_run) diff --git a/fastapi_backend/app/domain/marketplace.py b/fastapi_backend/app/domain/marketplace.py index a5ee26a8b..62b96bdf9 100644 --- a/fastapi_backend/app/domain/marketplace.py +++ b/fastapi_backend/app/domain/marketplace.py @@ -635,21 +635,24 @@ def suggested(db): def _installed(db, me): - """{(marketplace, plugin): extension id} for this person's installs.""" + """{(marketplace, plugin): (extension id, the version installed)} for this person's installs.""" out = {} for d in db.rows( "SELECT record::id(id) AS id, source FROM extension WHERE deleted_at = NONE AND owner = $o AND source != NONE", o=me["id"] ): s = d.get("source") or {} if s.get("marketplace"): - out[(s["marketplace"], s.get("plugin"))] = d["id"] + out[(s["marketplace"], s.get("plugin"))] = (d["id"], s.get("version")) return out def plugins(db, me, mid): - """A marketplace's plugins, each saying whether Lens can install it and whether this person has.""" - d = _row(db, mid) - mine = _installed(db, me) + """A marketplace's plugins, each saying whether Lens can install it, whether this person has, and whether the + marketplace lists another version than theirs.""" + return _plugins(_row(db, mid), _installed(db, me)) + + +def _plugins(d, mine): out = [] for p in d.get("plugins") or []: why = None @@ -658,24 +661,47 @@ def plugins(db, me, mid): except ValueError as e: why = str(e) author = p.get("author") + have, had = mine.get((d["id"], p["name"])) or (None, None) + version = str(p["version"]) if p.get("version") else None out.append( store.clean( { "name": p["name"], "description": p.get("description") if isinstance(p.get("description"), str) else None, - "version": str(p["version"]) if p.get("version") else None, + "version": version, "category": p.get("category") if isinstance(p.get("category"), str) else None, "author": author.get("name") if isinstance(author, dict) else author if isinstance(author, str) else None, "homepage": p.get("homepage") if isinstance(p.get("homepage"), str) else None, "installable": why is None, "why_not": why, - "installed": mine.get((d["id"], p["name"])), + "installed": have, + "installed_version": had, + # a version listed that isn't the one installed; unknown (false) when either has none + "update": bool(have and version and had and version != had), } ) ) return out +def find(db, me, query=None, mid=None, updates=False, limit=50): + """Plugins across the marketplaces (or marketplace `mid`) whose name, description, category or author has every + word of `query`, each with its marketplace; `updates`: only those this person installed that their marketplace now + lists another version of. (plugins, how many matched)""" + words = (query or "").lower().split() + rows = [_row(db, mid)] if mid is not None else db.rows(f"SELECT {FIELDS}, plugins FROM marketplace ORDER BY id") + mine = _installed(db, me) + out = [] + for d in rows: + for p in _plugins(d, mine): + if updates and not p["update"]: + continue + text = " ".join(str(p.get(k) or "") for k in ("name", "description", "category", "author")).lower() + if all(w in text for w in words): + out.append({**p, "marketplace": d["id"], "marketplace_name": d.get("title") or d["name"]}) + return out[: max(1, int(limit))], len(out) + + def _entry(db, mid, name): d = _row(db, mid) for p in d.get("plugins") or []: @@ -717,7 +743,7 @@ def install(db, cfg, me, mid, name): source = store.clean( {"marketplace": d["id"], "plugin": p["name"], "version": str(p["version"]) if p.get("version") else None, "url": show_source(src)} ) - return _save(db, me, manifest, source, _installed(db, me).get((d["id"], p["name"]))) + return _save(db, me, manifest, source, (_installed(db, me).get((d["id"], p["name"])) or (None,))[0]) def _same(db, me, key, value): diff --git a/fastapi_backend/app/schemas/extensions.py b/fastapi_backend/app/schemas/extensions.py index e3ffd9e36..811c4d4b1 100644 --- a/fastapi_backend/app/schemas/extensions.py +++ b/fastapi_backend/app/schemas/extensions.py @@ -168,6 +168,13 @@ class MarketplacePlugin(ResponseModel): installable: bool = Field(description="whether Lens can read it (why_not says why when it can't)") why_not: str | None = None installed: int | None = Field(None, description="your extension installed from it, if you installed it") + installed_version: str | None = Field(None, description="the version you installed, when the marketplace gave one") + update: bool = Field(False, description="the marketplace lists another version than the one you installed") + + +class MarketplacePluginFound(MarketplacePlugin): + marketplace: int = Field(description="the marketplace that lists it") + marketplace_name: str class ExtensionSkipped(ResponseModel): diff --git a/fastapi_backend/tests/api/test_marketplaces.py b/fastapi_backend/tests/api/test_marketplaces.py index 335537dfa..03f215bff 100644 --- a/fastapi_backend/tests/api/test_marketplaces.py +++ b/fastapi_backend/tests/api/test_marketplaces.py @@ -257,3 +257,72 @@ def test_a_skills_files_in_a_conversation(app, db, cfg, folder, new_client, web, assert "file" in use["function"]["parameters"]["properties"] tool_msgs = [m["content"] for b in llm.seen if b.get("tools") for m in b["messages"] if m["role"] == "tool"] assert '"files": ["FORMS.md"]' in tool_msgs[0] and "field by field" in tool_msgs[-1] + + +def test_found_updated_and_installed_by_agents(app, db, cfg, folder, new_client, web, llm, monkeypatch): + """Plugins are found across marketplaces and installed over MCP, the REST API or in chat (after the person's + yes), and an installed plugin says when its marketplace lists another version.""" + from tests.api.test_mcp import rpc + + s = Assist(app, db, cfg, folder, new_client) + c, h = s.cl["editor"] + ca, ha = s.cl["admin"] + + def mcp(tool, **args): + res = rpc(c, h, "tools/call", {"name": tool, "arguments": args})["result"] + return json.loads(res["content"][0]["text"]) if res["isError"] else res["structuredContent"] + + assert "no marketplace is added yet" in mcp("find_plugins")["note"] + mid = ca.post("/api/v1/marketplaces", headers=ha, json={"source": "anthropics/skills", "title": "Skills"}).json()["id"] + + # found by any of its words, with the marketplace it's in + got = c.get("/api/v1/marketplaces/plugins", headers=h, params={"q": "ACME tools"}).json() + assert [(p["name"], p["marketplace"], p["marketplace_name"], p["update"]) for p in got] == [("acme-tools", mid, "Skills", False)] + assert len(c.get("/api/v1/marketplaces/plugins", headers=h).json()) == 4 + found = mcp("find_plugins", query="every") + assert ([p["name"] for p in found["plugins"]], found["matched"]) == (["all-skills"], 1) + assert "note" not in found and found["page"].endswith("/extensions/marketplace") + + # previewed, then installed, over MCP + pre = mcp("install_plugin", marketplace=mid, plugin="acme-tools", preview=True) + assert {(i["kind"], i["name"]) for i in pre["adds"]} == {("skill", "meeting_notes"), ("skill", "review"), ("tool", "critic")} + assert {x["kind"] for x in pre["leaves_out"]} == {"hooks", "mcp"} and c.get("/api/v1/extensions", headers=h).json() == [] + out = mcp("install_plugin", marketplace=mid, plugin="acme-tools") + assert out["version"] == 1 and out["page"].endswith(f"/extensions/{out['id']}") + assert "not found" in mcp("install_plugin", marketplace=mid, plugin="nope")["error"] + mine = c.get(f"/api/v1/marketplaces/{mid}/plugins", headers=h).json() + acme = next(p for p in mine if p["name"] == "acme-tools") + assert (acme["installed"], acme["installed_version"], acme["update"]) == (out["id"], "1.2.0", False) + assert mcp("find_plugins", updates=True)["plugins"] == [] + + # the marketplace now lists 1.3.0: an update shows, for the one who installed it + served = marketplace._fetch + index = json.loads(SKILLS_REPO[".claude-plugin/marketplace.json"]) + index["plugins"][2]["version"] = "1.3.0" + + def fetch(cfg, url, out, limit): + if url.endswith("/marketplace.json"): + return out.write(json.dumps(index).encode()) + return served(cfg, url, out, limit) + + monkeypatch.setattr(marketplace, "_fetch", fetch) + assert ca.post(f"/api/v1/marketplaces/{mid}/refresh", headers=ha).status_code == 200 + ups = c.get("/api/v1/marketplaces/plugins", headers=h, params={"updates": True}).json() + assert [(p["name"], p["version"], p["installed_version"], p["update"]) for p in ups] == [("acme-tools", "1.3.0", "1.2.0", True)] + assert ca.get("/api/v1/marketplaces/plugins", headers=ha, params={"updates": True}).json() == [] # not the admin's + + # in chat: found, and updated once the person says yes + llm.tool_script = [ + {"content": "", "tool_calls": [call(1, "find_plugins", {"updates": True})]}, + {"content": "", "tool_calls": [call(2, "install_plugin", {"marketplace": mid, "plugin": "acme-tools"})]}, + {"content": "acme-tools has 1.3.0; approve it to update."}, + ] + cid = c.post("/api/v1/chats", headers=h, json={}).json()["id"] + ev = sse(c.post(f"/api/v1/chats/{cid}/messages", headers=h, json={"content": "any plugin updates?"}).text) + assert ev["step"][0]["summary"] == "Found 1 plugin" + appr = ev["approval"][0] + assert appr["summary"].startswith("Update the plugin acme-tools from https://github.com/acme/tools: ") + assert c.get(f"/api/v1/extensions/{out['id']}", headers=h).json()["version"] == 1 # nothing until the yes + done = c.post(f"/api/v1/approvals/{appr['id']}", headers=h, json={"decision": "approve"}).json() + assert (done["extension"], done["version"]) == (out["id"], 2) + assert c.get("/api/v1/marketplaces/plugins", headers=h, params={"updates": True}).json() == [] diff --git a/fastapi_backend/tests/api/test_mcp.py b/fastapi_backend/tests/api/test_mcp.py index 70b38b1c3..b4fc92b9d 100644 --- a/fastapi_backend/tests/api/test_mcp.py +++ b/fastapi_backend/tests/api/test_mcp.py @@ -102,6 +102,7 @@ def test_clients_are_sent_to_sign_in(client, app, env): "set_service", "set_sandbox_gateway", "add_mcp_server", + "install_plugin", "set_install_settings", "subscribe_feed", "unsubscribe_feed", diff --git a/nextjs-frontend/__tests__/marketplace-ui.test.tsx b/nextjs-frontend/__tests__/marketplace-ui.test.tsx index 557131336..82503a15b 100644 --- a/nextjs-frontend/__tests__/marketplace-ui.test.tsx +++ b/nextjs-frontend/__tests__/marketplace-ui.test.tsx @@ -99,6 +99,29 @@ test("browses a marketplace, previews a plugin and installs it", async () => { await waitFor(() => expect(toast).toHaveBeenCalledWith(expect.objectContaining({ title: "Installed" }))); }); +test("an installed plugin with another version listed offers the update", async () => { + m(Extensions.listMarketplacePlugins).mockReturnValue( + ok([ + { + name: "document-skills", + installable: true, + installed: 9, + version: "1.3.0", + installed_version: "1.2.0", + update: true, + }, + ]), + ); + wrap(); + expect(await screen.findByRole("link", { name: "Installed 1.2.0" })).toHaveAttribute("href", "/extensions/9"); + fireEvent.click(screen.getByRole("button", { name: "Update to 1.3.0" })); + await waitFor(() => + expect(Extensions.previewMarketplacePlugin).toHaveBeenCalledWith( + expect.objectContaining({ path: { mid: 1, name: "document-skills" } }), + ), + ); +}); + test("an admin adds a suggested marketplace; others don't see the form", async () => { const { unmount } = wrap(); fireEvent.click(await screen.findByRole("button", { name: "Add Anthropic plugins" })); diff --git a/nextjs-frontend/app/openapi-client/index.ts b/nextjs-frontend/app/openapi-client/index.ts index 70ebfe157..0a39e2186 100644 --- a/nextjs-frontend/app/openapi-client/index.ts +++ b/nextjs-frontend/app/openapi-client/index.ts @@ -1142,6 +1142,11 @@ export type { FindGraphPathResponse, FindGraphPathResponses, FindItem, + FindMarketplacePluginsData, + FindMarketplacePluginsError, + FindMarketplacePluginsErrors, + FindMarketplacePluginsResponse, + FindMarketplacePluginsResponses, FindMoment, FindNamed, FindQuery, @@ -2334,6 +2339,7 @@ export type { Marketplace, MarketplaceCreate, MarketplacePlugin, + MarketplacePluginFound, MarketplaceSuggestion, MarkIn, MarkRecordingNsfwData, diff --git a/nextjs-frontend/app/openapi-client/sdk.gen.ts b/nextjs-frontend/app/openapi-client/sdk.gen.ts index 59f8508e1..1beb9b653 100644 --- a/nextjs-frontend/app/openapi-client/sdk.gen.ts +++ b/nextjs-frontend/app/openapi-client/sdk.gen.ts @@ -513,6 +513,9 @@ import type { FindGraphPathData, FindGraphPathErrors, FindGraphPathResponses, + FindMarketplacePluginsData, + FindMarketplacePluginsErrors, + FindMarketplacePluginsResponses, FindResourcesData, FindResourcesErrors, FindResourcesResponses, @@ -10431,6 +10434,19 @@ export class Extensions { }); } + /** + * Find Marketplace Plugins + * + * Plugins across every marketplace added, to find one to install or see which have updates. + */ + public static findMarketplacePlugins( + options?: Options, + ): RequestResult { + return (options?.client ?? client).get( + { url: "/api/v1/marketplaces/plugins", ...options }, + ); + } + /** * Refresh Marketplace * diff --git a/nextjs-frontend/app/openapi-client/types.gen.ts b/nextjs-frontend/app/openapi-client/types.gen.ts index 18d919ff8..be1456bdc 100644 --- a/nextjs-frontend/app/openapi-client/types.gen.ts +++ b/nextjs-frontend/app/openapi-client/types.gen.ts @@ -12148,6 +12148,87 @@ export type MarketplacePlugin = { * your extension installed from it, if you installed it */ installed?: number | null; + /** + * Installed Version + * + * the version you installed, when the marketplace gave one + */ + installed_version?: string | null; + /** + * Update + * + * the marketplace lists another version than the one you installed + */ + update?: boolean; + [key: string]: unknown; +}; + +/** + * MarketplacePluginFound + */ +export type MarketplacePluginFound = { + /** + * Name + */ + name: string; + /** + * Description + */ + description?: string | null; + /** + * Version + */ + version?: string | null; + /** + * Category + */ + category?: string | null; + /** + * Author + */ + author?: string | null; + /** + * Homepage + */ + homepage?: string | null; + /** + * Installable + * + * whether Lens can read it (why_not says why when it can't) + */ + installable: boolean; + /** + * Why Not + */ + why_not?: string | null; + /** + * Installed + * + * your extension installed from it, if you installed it + */ + installed?: number | null; + /** + * Installed Version + * + * the version you installed, when the marketplace gave one + */ + installed_version?: string | null; + /** + * Update + * + * the marketplace lists another version than the one you installed + */ + update?: boolean; + /** + * Marketplace + * + * the marketplace that lists it + */ + marketplace: number; + /** + * Marketplace Name + */ + marketplace_name: string; [key: string]: unknown; }; @@ -43434,6 +43515,50 @@ export type SuggestedMarketplacesResponses = { export type SuggestedMarketplacesResponse = SuggestedMarketplacesResponses[keyof SuggestedMarketplacesResponses]; +export type FindMarketplacePluginsData = { + body?: never; + path?: never; + query?: { + /** + * Q + * + * words its name, description, category or author has + */ + q?: string | null; + /** + * Updates + * + * only plugins you installed that their marketplace lists another version of + */ + updates?: boolean; + /** + * Limit + */ + limit?: number; + }; + url: "/api/v1/marketplaces/plugins"; +}; + +export type FindMarketplacePluginsErrors = { + /** + * Validation Error + */ + 422: HttpValidationError; +}; + +export type FindMarketplacePluginsError = FindMarketplacePluginsErrors[keyof FindMarketplacePluginsErrors]; + +export type FindMarketplacePluginsResponses = { + /** + * Response Extensions-Find Marketplace Plugins + * + * Successful Response + */ + 200: Array; +}; + +export type FindMarketplacePluginsResponse = FindMarketplacePluginsResponses[keyof FindMarketplacePluginsResponses]; + export type RefreshMarketplaceData = { body?: never; path: { diff --git a/nextjs-frontend/components/extensions/marketplace-page.tsx b/nextjs-frontend/components/extensions/marketplace-page.tsx index 83602fba4..31d374712 100644 --- a/nextjs-frontend/components/extensions/marketplace-page.tsx +++ b/nextjs-frontend/components/extensions/marketplace-page.tsx @@ -218,11 +218,15 @@ function Plugins({ market, onInstall }: { market: Marketplace; onInstall: (name: href={`/extensions/${p.installed}`} className="text-[12.5px] text-fg-accent hover:underline" > - Installed + {p.installed_version ? `Installed ${p.installed_version}` : "Installed"} ) : null} - ) : ( diff --git a/nextjs-frontend/openapi.json b/nextjs-frontend/openapi.json index b65f3ea62..884db353f 100644 --- a/nextjs-frontend/openapi.json +++ b/nextjs-frontend/openapi.json @@ -25554,6 +25554,87 @@ } } }, + "/api/v1/marketplaces/plugins": { + "get": { + "tags": [ + "extensions" + ], + "summary": "Find Marketplace Plugins", + "description": "Plugins across every marketplace added, to find one to install or see which have updates.", + "operationId": "find_marketplace_plugins", + "parameters": [ + { + "name": "q", + "in": "query", + "required": false, + "schema": { + "anyOf": [ + { + "type": "string", + "maxLength": 200 + }, + { + "type": "null" + } + ], + "description": "words its name, description, category or author has", + "title": "Q" + }, + "description": "words its name, description, category or author has" + }, + { + "name": "updates", + "in": "query", + "required": false, + "schema": { + "type": "boolean", + "description": "only plugins you installed that their marketplace lists another version of", + "default": false, + "title": "Updates" + }, + "description": "only plugins you installed that their marketplace lists another version of" + }, + { + "name": "limit", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "maximum": 500, + "minimum": 1, + "default": 50, + "title": "Limit" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MarketplacePluginFound" + }, + "title": "Response Extensions-Find Marketplace Plugins" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, "/api/v1/marketplaces/{mid}/refresh": { "post": { "tags": [ @@ -55335,6 +55416,24 @@ ], "title": "Installed", "description": "your extension installed from it, if you installed it" + }, + "installed_version": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Installed Version", + "description": "the version you installed, when the marketplace gave one" + }, + "update": { + "type": "boolean", + "title": "Update", + "description": "the marketplace lists another version than the one you installed", + "default": false } }, "additionalProperties": true, @@ -55345,6 +55444,133 @@ ], "title": "MarketplacePlugin" }, + "MarketplacePluginFound": { + "properties": { + "name": { + "type": "string", + "title": "Name" + }, + "description": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Description" + }, + "version": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Version" + }, + "category": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Category" + }, + "author": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Author" + }, + "homepage": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Homepage" + }, + "installable": { + "type": "boolean", + "title": "Installable", + "description": "whether Lens can read it (why_not says why when it can't)" + }, + "why_not": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Why Not" + }, + "installed": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Installed", + "description": "your extension installed from it, if you installed it" + }, + "installed_version": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Installed Version", + "description": "the version you installed, when the marketplace gave one" + }, + "update": { + "type": "boolean", + "title": "Update", + "description": "the marketplace lists another version than the one you installed", + "default": false + }, + "marketplace": { + "type": "integer", + "title": "Marketplace", + "description": "the marketplace that lists it" + }, + "marketplace_name": { + "type": "string", + "title": "Marketplace Name" + } + }, + "additionalProperties": true, + "type": "object", + "required": [ + "name", + "installable", + "marketplace", + "marketplace_name" + ], + "title": "MarketplacePluginFound" + }, "MarketplaceSuggestion": { "properties": { "name": {