Skip to content

Graft

Connect editors like Zed to an authorized Shiitake Session over the Agent Client Protocol, for hosts that embed ACP themselves.

  • @fungi.computer/graft
  • v0.1.4
  • MIT

Fastest path

  1. Install

    Add it to your project with npm, pnpm, Yarn or Bun.

    TERMINAL
    npm install @fungi.computer/graft
  2. Answer an ACP initialize call

    The fetch adapter calls the server in-process: no network, model or credentials. Prints the protocol version the server answers with.

    home.ts
    import * as acp from "@agentclientprotocol/sdk";
    import { createHttpStream } from "@agentclientprotocol/sdk/experimental/http-client";
    import {
    agentAcpMethods,
    type AuthorizedShiitakeSessionDirectory,
    } from "@fungi.computer/graft";
    import { createShiitakeAcpServer } from "@fungi.computer/graft/server";
    const refuse = () => Promise.reject(new Error("Session access is not granted"));
    const directory: AuthorizedShiitakeSessionDirectory = {
    create: refuse,
    load: refuse,
    };
    const server = createShiitakeAcpServer(directory);
    const stream = createHttpStream("https://agent.test/acp", {
    fetch: (input, init) => server.handleRequest(new Request(input, init)),
    });
    try {
    await acp
    .client({ name: "graft-example" })
    .connectWith(stream, async (ctx) => {
    const result = await ctx.request(agentAcpMethods.initialize, {
    protocolVersion: acp.PROTOCOL_VERSION,
    });
    console.log(result.protocolVersion); // "1"
    });
    } finally {
    await stream.writable.close();
    await server.close();
    }