Foundations

eve adapter

useLoomEve: connects Loom components to an eve agent through useEveAgent.

npx shadcn@latest add https://loom.mkhonta.com/r/eve.json

lib/loom/eve.ts

"use client";

import { useMemo } from "react";
import { activeTurn, activity } from "eve/events";
import { useEveAgent, type UseEveAgentOptions } from "eve/react";

import type { LoomActivity, LoomChat } from "@/lib/loom/types";

/**
 * Connects Loom components to an eve agent. Takes the same options as `useEveAgent` and returns a
 * `LoomChat`; pass it to any Loom chat component. This is the only file in the kit that imports
 * eve.
 *
 * @example
 * const chat = useLoomEve({ agent: "support" });
 * return <LoomThread chat={chat} />;
 */
export function useLoomEve(options?: UseEveAgentOptions): LoomChat & { readonly agent: ReturnType<typeof useEveAgent> } {
  const agent = useEveAgent(options);
  const { view } = agent;

  const current = useMemo<LoomActivity>(() => {
    const now = activity(view);
    return now.kind === "waiting-on-tasks" ? { kind: "waiting-on-tasks" } : now;
  }, [view]);

  return {
    messages: agent.messages,
    status: agent.status,
    activity: current,
    error: agent.error,
    canCancel: activeTurn(view) !== undefined,
    send: agent.send,
    respond: agent.respond,
    cancel: agent.cancel,
    newSession: agent.newSession,
    // The full eve binding, for anything the kit doesn't cover (events, resume, compact, end).
    agent,
  };
}

Usage

const chat = useLoomEve({ agent: "support" });

Props and details are in the docs.

Installs

  • lib/loom/eve.ts
  • eve@^1.5.0
NextCore →