Skip to content

heshengtao/super-agent-party / skills/sap-extension-creator

sap-extension-creator

Verified

Create Super Agent Party (SAP) extensions. This skill should be used when users want to create, build, or scaffold a new extension for Super Agent Party - including static HTML extensions (pure frontend) and Node.js backend extensions. Triggers on requests like "create a new SAP extension", "build an extension for Super Agent Party", "scaffold a plugin", "make a chat UI extension", or when working with sap extension projects.

assets/node-template/index.html

View on GitHub
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>My SAP Node Extension</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- These assets are loaded from the extension's own directory (served by Express) -->
<link rel="stylesheet" href="github-markdown-dark.css"/>
<link rel="stylesheet" href="prism-tomorrow.min.css"/>
<script src="marked.min.js"></script>
<script src="prism.min.js"></script>
<script src="prism-python.min.js"></script>
<script src="prism-javascript.min.js"></script>
<script src="prism-css.min.js"></script>
<style>
/* ========== Theme Variables ========== */
:root {
  --bg: #ffffff;
  --bg-secondary: #f5f5f5;
  --text: #333333;
  --text-sub: #888888;
  --accent: #00c2a8;
  --accent-hover: #00a896;
  --border: rgba(0,0,0,0.08);
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,0.08);
  --transition: 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body.dark {
  --bg: #1e1f20;
  --bg-secondary: #25262a;
  --text: #e8e8e8;
  --text-sub: #8a8f9b;
  --border: #333538;
  --shadow: 0 8px 24px rgba(0,0,0,0.36);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: var(--font); }
html, body { height: 100%; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}
header {
  height: 56px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; background: var(--bg-secondary);
}
header .logo { font-weight: 600; font-size: 18px; display: flex; align-items: center; gap: 8px; }
header .logo i { color: var(--accent); }
.header-actions { display: flex; gap: 8px; align-items: center; }
.header-actions button {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(128,128,128,0.1); border: 1px solid var(--border);
  color: var(--text-sub); cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.header-actions button:hover { background: rgba(128,128,128,0.2); color: var(--text); }
.header-actions button.lang-btn { width: auto; padding: 0 10px; border-radius: 17px; font-size: 12px; font-weight: 600; }

#messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; padding: 0 24px 24px; }
.msg { display: flex; padding: 16px 0; border-bottom: 1px solid var(--border); }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }
.msg.system { justify-content: center; font-style: italic; color: var(--text-sub); font-size: 14px; }
.msg-inner { max-width: 640px; display: flex; gap: 12px; align-items: flex-start; }
.msg.user .msg-inner { flex-direction: row-reverse; }
.msg .icon { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.msg.user .icon { background: #3c3d40; color: var(--text-sub); }
.msg.assistant .icon { background: var(--accent); color: #fff; }
.msg .bubble { padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow); word-break: break-word; line-height: 1.65; }
.msg.assistant .bubble.markdown-body { background: var(--bg-secondary); color: var(--text); font-size: 15px; }
.markdown-body pre { background: #282c34 !important; padding: 12px 16px; border-radius: 6px; overflow-x: auto; }
.markdown-body code { background: rgba(0,0,0,.25); padding: 2px 4px; border-radius: 3px; font-size: 14px; }
body.dark .markdown-body code { background: rgba(255,255,255,0.08); }
.msg.user .bubble { background: var(--accent); color: #fff; }
.msg.assistant .bubble { background: var(--bg-secondary); }
#empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-sub); gap: 8px; }
#empty i { font-size: 40px; }

#inputBar { border-top: 1px solid var(--border); background: var(--bg-secondary); padding: 16px 24px; }
#inputWrap { max-width: 768px; margin: 0 auto; display: flex; gap: 12px; align-items: center; }
#userInput { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; resize: none; max-height: 120px; min-height: 44px; line-height: 1.5; font-size: 15px; color: var(--text); font-family: var(--font); }
#userInput:focus { outline: none; border-color: var(--accent); }
#sendBtn { width: 44px; height: 44px; border-radius: var(--radius); background: var(--accent); border: none; color: #fff; cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; transition: 0.2s; }
#sendBtn:hover { background: var(--accent-hover); }
#sendBtn:disabled { opacity: 0.4; cursor: not-allowed; }
#clearBtn { width: 44px; height: 44px; border-radius: var(--radius); background: transparent; border: 1px solid var(--border); color: var(--text-sub); cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
#clearBtn:hover { background: rgba(128,128,128,0.1); color: var(--accent); border-color: var(--accent); }

#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#messages::-webkit-scrollbar-thumb:hover { background: var(--text-sub); }
#messages { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ========== Responsive ========== */
@media (max-width: 900px) {
  body { font-size: 14px; }
  header { padding: 0 16px; }
  #messages { padding: 0 16px 16px; }
  #inputBar { padding: 12px 16px; }
  .msg-inner { max-width: 100%; }
}
@media (max-width: 600px) {
  header .logo { font-size: 15px; }
  header .logo span { display: none; }
  header { height: 48px; padding: 0 12px; }
  #inputWrap { gap: 8px; }
  #userInput { font-size: 14px; padding: 8px 12px; }
  #sendBtn, #clearBtn { width: 38px; height: 38px; font-size: 16px; }
  #inputBar { padding: 10px 12px; }
}

/* ========== Compact Mode (Transparent Windows) ========== */
body.compact { background: transparent !important; }
html.compact { background: transparent !important; }

body.compact header,
body.compact #inputBar { -webkit-app-region: drag; }

body.compact button,
body.compact input,
body.compact textarea,
body.compact .compact-close-btn { -webkit-app-region: no-drag; }

.compact-close-btn { display: none; }
body.compact .compact-close-btn {
  display: flex;
  position: absolute; top: 5px; right: 5px;
  width: 20px; height: 20px;
  background: rgb(255,57,57); border: none; border-radius: 50%;
  color: #fff; align-items: center; justify-content: center;
  font-size: 10px; cursor: pointer; transition: 0.2s;
  z-index: 100;
  -webkit-app-region: no-drag;
}
body.compact .compact-close-btn:hover { background: #ec4141; }

body.compact header { padding: 0 12px; height: 44px; border-bottom: none; }
body.compact header .header-actions { display: none; }
body.compact #messages { display: none; }
body.compact #inputBar { padding: 8px 16px; border-top: none; background: rgba(35,36,39,0.95); border-radius: 8px; }
body.compact #userInput { max-height: 36px; min-height: 36px; font-size: 13px; }
body.compact #sendBtn { width: 36px; height: 36px; font-size: 16px; }
body.compact #clearBtn { display: none; }
</style>
</head>
<body>
  <button class="compact-close-btn" onclick="closeWindow()" title="关闭窗口"><i class="fa-solid fa-xmark"></i></button>

  <header>
    <div class="logo"><i class="fa-solid fa-robot"></i><span id="header-title">My SAP Node Extension</span></div>
    <div class="header-actions">
      <button class="lang-btn" id="langBtn" onclick="toggleLanguage()">EN</button>
      <button onclick="toggleDarkMode()" title="Toggle theme"><i class="fa-solid fa-moon" id="darkIcon"></i></button>
    </div>
  </header>

  <main id="messages">
    <div id="empty">
      <i class="fa-regular fa-comments"></i>
      <span id="empty-text">No messages yet</span>
    </div>
  </main>

  <footer id="inputBar">
    <div id="inputWrap">
      <button id="clearBtn" title="Clear messages"><i class="fa-solid fa-trash"></i></button>
      <textarea id="userInput" placeholder="Send a message…"></textarea>
      <button id="sendBtn"><i class="fa-solid fa-paper-plane"></i></button>
    </div>
  </footer>

<script>
/* ========== SAP Extension — Node Template ========== */
const $ = s => document.querySelector(s);
const msgs = $('#messages');
const input = $('#userInput');
const btn = $('#sendBtn');
const clearBtn = $('#clearBtn');
let ws;
let MY_EXT_ID = '';

/* ---- i18n ---- */
const i18n = {
  zh: {
    title: '我的 Node 扩展',
    empty: '暂无消息',
    placeholder: '输入消息…',
    darkMode: '切换深色模式',
    langSwitch: '切换到英文',
    clear: '清空消息'
  },
  en: {
    title: 'My Node Extension',
    empty: 'No messages yet',
    placeholder: 'Send a message…',
    darkMode: 'Toggle dark mode',
    langSwitch: 'Switch to Chinese',
    clear: 'Clear messages'
  }
};
let lang = localStorage.getItem('myext_lang') || 'zh';
function t(k) { return i18n[lang]?.[k] || i18n.zh[k] || k; }
function toggleLanguage() {
  lang = lang === 'zh' ? 'en' : 'zh';
  localStorage.setItem('myext_lang', lang);
  updateAllTexts();
}
function updateAllTexts() {
  $('#header-title').textContent = t('title');
  $('#empty-text').textContent = t('empty');
  $('#userInput').placeholder = t('placeholder');
  $('#langBtn').textContent = lang === 'zh' ? 'EN' : '中';
  $('#langBtn').title = t('langSwitch');
  $('#darkIcon').parentElement.title = t('darkMode');
  $('#clearBtn').title = t('clear');
}

/* ---- Theme ---- */
(function initTheme() {
  const saved = localStorage.getItem('myext_dark');
  if (saved === 'dark' || (!saved && matchMedia('(prefers-color-scheme:dark)').matches)) {
    document.body.classList.add('dark');
  }
  updateDarkIcon();
})();
function toggleDarkMode() {
  const isDark = document.body.classList.toggle('dark');
  localStorage.setItem('myext_dark', isDark ? 'dark' : 'light');
  updateDarkIcon();
}
function updateDarkIcon() {
  const icon = $('#darkIcon');
  if (icon) icon.className = document.body.classList.contains('dark') ? 'fa-solid fa-sun' : 'fa-solid fa-moon';
}

/* ---- Extension ID ---- */
function getExtId() {
  try {
    const match = window.location.pathname.match(/\/extensions\/([^\/]+)/);
    MY_EXT_ID = match ? match[1] : 'unknown';
  } catch(e) { MY_EXT_ID = 'unknown'; }
  return MY_EXT_ID;
}

/* ================================================================
   MCP Tool Lifecycle
   
   STARTUP:  ws.onopen         → registerMcpTools()
   RUNTIME:  ws.onmessage      → handleMcpCall() when AI calls a tool
            + fetch('/api/...') for heavy lifting on the Node.js server
   SHUTDOWN: window.beforeunload → unregisterMcpTools()
   
   If your extension does NOT need to expose tools to the AI,
   delete: registerMcpTools(), unregisterMcpTools(), handleMcpCall().
   ================================================================ */

/* ---- MCP Tool Handler ---- */
// The AI agent called a tool we registered.  Execute it & return the result.
async function handleMcpCall(data) {
  const { ext_id, tool_name, tool_params, call_id } = data;
  if (ext_id !== MY_EXT_ID && !tool_name.includes(MY_EXT_ID)) return;

  let resultStr = 'success';
  try {
    let params = tool_params;
    if (typeof params === 'string') {
      try { params = JSON.parse(params); } catch(e) {}
    }

    // TODO: route to the correct tool handler based on tool_name
    // For server-side operations, call your Node.js backend:
    //   const res = await fetch(`/api/your-endpoint`, { method: 'POST', headers: {...}, body: JSON.stringify(params) });
    //   resultStr = await res.text();
    // For client-side operations (DOM access, etc.), handle directly:
    //   if (tool_name === `${MY_EXT_ID}_example_tool`) { ... }

    resultStr = `Tool ${tool_name} executed`;
  } catch(e) { resultStr = `Error: ${e.message}`; }

  // Send the result back over WebSocket
  if (ws && ws.readyState === WebSocket.OPEN) {
    ws.send(JSON.stringify({
      type: 'mcp_tool_result',
      data: { call_id, result: resultStr }
    }));
  }
}

/* ---- WebSocket ---- */
let _closing = false;

function initWS() {
  const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
  ws = new WebSocket(`${proto}//${location.host}/ws`);
  ws.onopen = () => {
    ws.send(JSON.stringify({ type: 'get_messages' }));
    registerMcpTools();   // ← MCP: register tools on startup
  };
  ws.onclose = () => {
    // If the page is being closed (_closing=true), do NOT reconnect
    if (!_closing) setTimeout(initWS, 5000);
  };
  ws.onmessage = e => {
    try {
      const d = JSON.parse(e.data);
      if (d.type === 'messages_update' || d.type === 'broadcast_messages') render(d.data.messages);
      if (d.type === 'call_mcp_tool') handleMcpCall(d.data);   // ← MCP: AI calls our tool
      if (d.type === 'mcp_registered') console.log('[MCP] Tools registered successfully');
    } catch {}
  };
}

// --- Register MCP tools (called once on WebSocket open) ---
function registerMcpTools() {
  getExtId();
  ws.send(JSON.stringify({
    type: 'register_node_extension_mcp',
    data: {
      ext_id: MY_EXT_ID,
      tools: [
        // TODO: customize or remove this example tool
        {
          name: `${MY_EXT_ID}_example_tool`,
          description: lang === 'zh' ? '示例工具:处理参数' : 'Example tool: process a parameter',
          parameters: {
            type: 'object',
            properties: {
              param: { type: 'string', description: lang === 'zh' ? '一个参数' : 'A parameter' }
            },
            required: ['param']
          }
        }
        // Add more tools here...
      ]
    }
  }));
}

// --- Unregister MCP tools (called on page close) ---
function unregisterMcpTools() {
  if (ws && ws.readyState === WebSocket.OPEN) {
    ws.send(JSON.stringify({ type: 'unregister_node_extension_mcp', data: { ext_id: MY_EXT_ID } }));
  }
}

/* ---- Message Rendering ---- */
function render(list) {
  if (!list || !list.length) {
    msgs.innerHTML = `<div id="empty"><i class="fa-regular fa-comments"></i><span id="empty-text">${t('empty')}</span></div>`;
    return;
  }
  msgs.innerHTML = list.map(m => {
    if (m.role === 'system') return '';
    const isCode = m.role === 'assistant';
    let html = isCode ? marked.parse(m.pure_content || '') : (m.pure_content || m.content || '');
    return `
      <div class="msg ${m.role}">
        <div class="msg-inner">
          <div class="icon">
            ${m.role === 'user' ? '<i class="fa-solid fa-user"></i>' : '<i class="fa-solid fa-robot"></i>'}
          </div>
          <div class="bubble ${isCode ? 'markdown-body' : ''}">${html}</div>
        </div>
      </div>`;
  }).join('');
  msgs.scrollTop = msgs.scrollHeight;
  Prism.highlightAllUnder(msgs);
}

/* ---- Send / Clear ---- */
function send() {
  const t = input.value.trim();
  if (!t) return;
  ws.send(JSON.stringify({ type: 'set_user_input', data: { text: t } }));
  ws.send(JSON.stringify({ type: 'trigger_send_message' }));
  input.value = ''; input.style.height = 'auto';
}
function clear() {
  ws.send(JSON.stringify({ type: 'trigger_clear_message' }));
}
function closeWindow() {
  _closing = true;
  unregisterMcpTools();
  window.close();
}

/* ---- Compact Mode ---- */
function checkCompactMode() {
  if (window.innerHeight < 200) {
    document.documentElement.classList.add('compact');
    document.body.classList.add('compact');
  } else {
    document.documentElement.classList.remove('compact');
    document.body.classList.remove('compact');
  }
}

/* ---- Events ---- */
input.addEventListener('input', () => {
  autoHeight();
  if (ws && ws.readyState === WebSocket.OPEN) {
    ws.send(JSON.stringify({ type: 'set_user_input', data: { text: input.value } }));
  }
});
input.addEventListener('keydown', e => {
  if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send(); }
});
btn.addEventListener('click', send);
clearBtn.addEventListener('click', clear);
function autoHeight() { input.style.height = 'auto'; input.style.height = input.scrollHeight + 'px'; }

window.addEventListener('beforeunload', () => {
  _closing = true;
  unregisterMcpTools();   // ← MCP: unregister tools on shutdown
});

/* ---- Init ---- */
checkCompactMode();
window.addEventListener('resize', checkCompactMode);
updateAllTexts();
getExtId();
initWS();
</script>
</body>
</html>
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall