import React from "react"; import { createRoot } from "react-dom/client"; import { defineClientAction } from "../client-action.js"; import { AgentNativeExtensionSlot } from "./AgentNativeExtensionFrame.js"; const extensionContent = `
pending


`;

interface ExtensionE2EWindow {
  __extensionE2EResult?: unknown;
  __extensionE2ECommands?: Array<{ command: string; payload: unknown }>;
}

const hostWindow = window as Window & ExtensionE2EWindow;

const extension = {
  id: "allowed-extension",
  name: "Allowed extension",
  content: extensionContent,
  manifest: {
    slots: ["crm.customer.sidebar"],
    requestedActions: ["allowed-action"],
    requestedCommands: ["refreshData"],
    storageScopes: ["user"],
  },
};

const wrongSlotExtension = {
  id: "wrong-slot-extension",
  name: "Wrong slot extension",
  content: "
should not render
", manifest: { slots: ["crm.billing.sidebar"] }, }; hostWindow.__extensionE2ECommands = []; window.addEventListener("message", (event) => { if (event.data?.type !== "extension-e2e.done") return; hostWindow.__extensionE2EResult = event.data.result; const results = document.getElementById("host-results"); if (results) results.textContent = JSON.stringify(event.data.result); }); const actions = [ defineClientAction<{ value: number }, { doubled: number }>({ name: "allowed-action", description: "Allowed test action", schema: { type: "object", properties: { value: { type: "number" } }, required: ["value"], }, run: async (args) => ({ doubled: args.value * 2 }), }), defineClientAction, { shouldNotRun: true }>({ name: "blocked-action", description: "Blocked test action", schema: { type: "object", properties: {} }, run: async () => ({ shouldNotRun: true }), }), ]; function Host() { return (
{hostWindow.__extensionE2ECommands?.length}
({ resource: { type: "customer", id: "customer-1", name: "Ada Co" }, })} commands={{ refreshData: async ({ payload }) => { hostWindow.__extensionE2ECommands?.push({ command: "refreshData", payload, }); const count = document.getElementById("command-count"); if (count) { count.textContent = String( hostWindow.__extensionE2ECommands?.length ?? 0, ); } return { refreshed: true, payload }; }, }} />
); } createRoot(document.getElementById("root") as HTMLElement).render();