agentsclimarketplace

Deploy webrtc

Skill Napster/omniagent-api-skills/skills/deploy-webrtc

Deploy an Omniagent to the web — browser audio + video via the Napster Web SDK. Use when the developer says "embed the agent", "add the avatar to my page", "put it on my website", "wire up the Web SDK", or wants an in-browser voice/video experience. Detects the project framework (React, Next.js, Vue, Nuxt, Svelte, Remix, plain HTML), adapts the default panel structure, sets up a server-side token endpoint, and wires the SDK event loop. For audio-only use [[deploy-websocket]]; for phone use [[deploy-phone]].From its SKILL.md

Install
npx -y skills add Napster/omniagent-api-skills --skill deploy-webrtc

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

16.0 KB, as published. Nobody here has run it

deploy-webrtc

This takes a developer from "I have an agent ID" to "the agent is live in my web app — greeting the user, speaking, and handling tool calls." WebRTC is the browser channel: real-time audio and video through the Web SDK (@touchcastllc/napster-companion-api).

There is no "deploy to web" API call. You deploy by (1) standing up a server-side endpoint that mints a connection token and (2) handing that token to the Web SDK in the browser. The agent owns the persona, voice, tools, and knowledge — the connection inherits them.

Prerequisites

  • An agent ID (agent_…). If you don't have one, route to [[create-agent]].

1. Set up the token endpoint (ask first)

The browser must never hold the API key. A server-side endpoint calls the API and returns a short-lived token. Ask the developer how they want to handle it — don't assume:

To use the SDK in the browser you need a small server-side endpoint that calls the Napster API for a short-lived connection token. Your API key stays on the server; the browser only sees the token. How do you want to handle that?

  1. I already have a backend — add the token endpoint to it.
  2. I don't have a backend yet — drop in a local Node script to prototype, move it to production later.
  3. Skip for now.

Path 1 — existing backend. Detect the stack from the project (Express, Fastify, Hono, Next.js route handlers, FastAPI, Flask, Django, Vercel/Cloudflare functions, …) or ask. Add a route that does this and nothing the browser can see:

// Example: an endpoint in the developer's own backend (Express shown).
app.post("/api/token", async (req, res) => {
  const r = await fetch(
    `https://companion-api.napster.com/public/agents/${process.env.AGENT_ID}/connections`,
    {
      method: "POST",
      headers: { "X-Api-Key": process.env.NAPSTER_API_KEY!, "Content-Type": "application/json" },
      body: JSON.stringify({ channelType: "webrtc" }), // optionally externalClientId, externalClientProfile
    },
  );
  if (!r.ok) return res.status(502).json({ error: await r.text() });
  res.json(await r.json()); // { token, connection: { id, … } }
});
# FastAPI shown.
@app.post("/api/token")
async def token():
    r = requests.post(
        f"https://companion-api.napster.com/public/agents/{os.environ['AGENT_ID']}/connections",
        headers={"X-Api-Key": os.environ["NAPSTER_API_KEY"]},
        json={"channelType": "webrtc"},
    )
    r.raise_for_status()
    return r.json()  # { token, connection: { id, … } }

Path 2 — prototype scaffold. Create a local-token-server/ folder in the project root and fetch each file by raw URL from the public skills repo:

  • token-server.js — https://raw.githubusercontent.com/Napster/omniagent-api-skills/main/assets/local-token-server/token-server.js
  • package.json — https://raw.githubusercontent.com/Napster/omniagent-api-skills/main/assets/local-token-server/package.json
  • .env.example — https://raw.githubusercontent.com/Napster/omniagent-api-skills/main/assets/local-token-server/.env.example
  • gitignore.template — https://raw.githubusercontent.com/Napster/omniagent-api-skills/main/assets/local-token-server/gitignore.template
  • README.md — https://raw.githubusercontent.com/Napster/omniagent-api-skills/main/assets/local-token-server/README.md

Copy .env.example to .env and set NAPSTER_API_KEY and AGENT_ID. Append gitignore.template to the project's .gitignore. Run node local-token-server/token-server.js — its POST /token proxies the agent connection call above. Tell the developer: "When you're ready for production, I'll port /token into your real backend."

Path 3 — skip. Note the developer is responsible for token issuance and continue; the browser code below still calls POST /token.

The preferred connection call is always POST /public/agents/{agentId}/connections with { "channelType": "webrtc" }. The per-session POST /public/connections (companionId + providerConfig) exists only as a fallback for assembling a session without an agent — see [[session-runtime]].

2. Install the Web SDK

For any project with a bundler (React, Next, Vue, Nuxt, Svelte, Remix, Vite, Webpack, …), install and import directly:

npm install @touchcastllc/napster-companion-api @reduxjs/toolkit
import { NapsterCompanionApiSdk } from "@touchcastllc/napster-companion-api";
import "@touchcastllc/napster-companion-api/styles";

@reduxjs/toolkit is a peer dependency — install it alongside.

For a plain HTML project with no bundler, copy the standalone bundle and CSS out of node_modules into a served folder and load via tags (fallback path, not the default):

npm install @touchcastllc/napster-companion-api
mkdir -p sdk
cp node_modules/@touchcastllc/napster-companion-api/lib/index.standalone.js sdk/napster-companion-api.js
cp node_modules/@touchcastllc/napster-companion-api/lib/index.css           sdk/napster-companion-api.css
<link rel="stylesheet" href="/sdk/napster-companion-api.css" />
<script src="/sdk/napster-companion-api.js"></script>
<!-- global available as window.napsterCompanionApiSDK -->
<Callout type="warn"> Before writing SDK code, check the current init signature and option set against the docs — the Web SDK has its own docs section. Verify install/init/options at `fetch-page` slugs `sdks/web-sdk/installation`, `sdks/web-sdk/initialization`, and `sdks/web-sdk/configuration`, framework wiring at `sdks/web-sdk/framework-examples`, and event shapes at `deploying-your-omniagent/messaging/server-events`. Don't invent methods from memory. </Callout>

3. Build the panel from the canonical reference

The skills ship one canonical panel structure and one stylesheet, both hosted in the public skills repo:

  • Panel reference (header + mount + "Powered by Napster" footer): https://raw.githubusercontent.com/Napster/omniagent-api-skills/main/assets/omniagent-panel-reference.html
  • Stylesheet: https://raw.githubusercontent.com/Napster/omniagent-api-skills/main/assets/omniagent-ui.css

Don't inline panel markup from memory — fetch both URLs and adapt.

  1. Read package.json (or equivalent) to detect the framework.
  2. Fetch the panel reference (URL above) to learn the structure.
  3. Reproduce that structure in the framework's idiom:
    • React / Next / Remix → a JSX component, mount = a ref'd <div className="omniagent-mount">.
    • Vue / Nuxt → a <template> with a ref'd mount div.
    • Svelte → markup with bind:this on the mount div.
    • Plain HTML → drop the reference contents straight into <body>.
  4. Fetch the stylesheet (URL above) and copy it into the project unchanged, then load it (import in bundlers, <link> in plain HTML).
  5. Set the agent's name in the header. Keep the footer (see [[troubleshoot-omniagent]] for the attribution policy) unless the developer explicitly asks to remove it.

4. Wire the SDK to the mount

The init call returns a Promise that resolves to the instance — you must await it, or instance.sendCommand is undefined. Do a mic preflight first so a denied permission surfaces a clear error instead of failing silently inside the SDK.

React example (bundler import path):

import { useEffect, useRef } from "react";
import { NapsterCompanionApiSdk } from "@touchcastllc/napster-companion-api";
import "@touchcastllc/napster-companion-api/styles";

export function OmniagentPanel() {
  const mountRef = useRef<HTMLDivElement>(null);
  const instanceRef = useRef<any>(null);

  useEffect(() => {
    let cancelled = false;
    (async () => {
      // 1. Mic preflight — surface the prompt and a clear error path.
      try {
        const s = await navigator.mediaDevices.getUserMedia({ audio: true });
        s.getTracks().forEach((t) => t.stop());
      } catch (e) {
        console.error("[mic] denied", e);
        return;
      }
      // 2. Get a short-lived token from your server endpoint.
      const res = await fetch("/api/token", { method: "POST" });
      if (!res.ok) return console.error("[token]", res.status, await res.text());
      const { token } = await res.json();
      if (cancelled || !mountRef.current) return;
      // 3. Init — AWAIT it.
      instanceRef.current = await NapsterCompanionApiSdk.init(token, {
        mountContainer: mountRef.current,
        className: "omniagent-sdk-root",     // styling hook — see "Fitting the SDK" below
        avatarStyle: { view: "rectangle" },  // matches the omniagent-panel-reference layout
        onData: handleData,
      });
    })();
    return () => {
      cancelled = true;
      instanceRef.current?.destroy();
    };
  }, []);

  return (
    <div className="omniagent-panel">
      <header className="omniagent-header">
        <h2 className="omniagent-title">Support Agent</h2>
        <span className="omniagent-status">Live</span>
      </header>
      <div className="omniagent-mount" ref={mountRef}>
        <div className="omniagent-loading">Connecting</div>
      </div>
      <a className="omniagent-footer" href="https://developers.napster.com" target="_blank" rel="noopener noreferrer">
        <span>Powered by</span><span className="omniagent-footer__brand">Napster</span>
      </a>
    </div>
  );
}

Plain HTML / standalone global:

<script type="module">
  async function start() {
    try {
      const s = await navigator.mediaDevices.getUserMedia({ audio: true });
      s.getTracks().forEach((t) => t.stop());
    } catch (e) {
      document.querySelector(".omniagent-loading").textContent = "Microphone access required";
      return;
    }
    const res = await fetch("/token", { method: "POST" }); // local-token-server endpoint
    const { token } = await res.json();
    const instance = await window.napsterCompanionApiSDK.init(token, {
      mountContainer: "#omniagent-mount",
      className: "omniagent-sdk-root",     // styling hook — see "Fitting the SDK" below
      avatarStyle: { view: "rectangle" },  // matches the omniagent-panel-reference layout
      onData: handleData,
    });
    window.__omniagent = instance; // debugging only — remove in production
  }
  start();
</script>

Key points the docs call out:

  • await init. Without it you hold a Promise, not the instance; every method throws.

  • mountContainer accepts a DOM element or a selector string.

  • Pass onData to receive every server event (see [[session-runtime]] for the event names, the greeting nudge, and the function-call loop).

  • Fitting the SDK into your own layout. The mount container (.omniagent-mount) has its own visual layout — bounded size, rounded corners, panel chrome. To make the SDK fill that space cleanly without overflow or alignment issues, you need both of these together (the init samples above already include them):

    await NapsterCompanionApiSdk.init(token, {
      mountContainer: mountRef.current,
      className: "omniagent-sdk-root",     // styling hook attached to the SDK
      avatarStyle: { view: "rectangle" },  // matches the panel layout
      onData: handleData,
    });
    

    The fill rule for .omniagent-sdk-root is already baked into omniagent-ui.css — you don't need to write your own CSS. Just pass the two init options above and it Just Works. If you want to add your own styling on top (custom borders, backgrounds, rounded corners), you can scope to the same .omniagent-sdk-root class.

Inside an iframe

The iframe must grant the permissions the SDK uses, or the mic preflight fails even when the top-level page works:

<iframe src="…" allow="microphone; camera; autoplay"></iframe>

5. Multi-page site? Turn on persistence

Ask this early: does navigation reload the page? On a single-page app the session survives on its own — skip this. On a traditional multi-page site, every navigation is a full page load that tears the session down mid-conversation, so enable it:

NapsterCompanionApiSdk.init(token, {
  persistence: { enabled: true },
});

The full treatment — when the wrap happens, break-out rules and exclude, routing programmatic navigation through PERSIST_NAVIGATE_EVENT, and the verification pass — is its own skill: [[persist-web-session]]. Invoke it whenever this question answers "multi-page".

6. (Optional) Faster start with videoPolicy: "deferred"

By default (videoPolicy: "required") the session becomes ready only when audio and video are both up — one avatar_state_changed: ready. Set "deferred" on the WebRTC channel config to let the conversation start on audio first, with the video avatar coming up moments later:

curl -X PUT https://companion-api.napster.com/public/agents/agent_abc123/channels/webrtc \
  -H "X-Api-Key: $NAPSTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "videoPolicy": "deferred" }'

WebRTC-only (WebSocket sessions have no video). Contract change: under "deferred" the session emits ready TWICE — first with details: { mode: "audio_only" }, again with details: { mode: "audio_video" } when video is up. Any handler keyed on avatar_state_changed: ready must latch (run once); onAvatarReady is unaffected (fires once, at video render — which under "deferred" is after the conversation is already live). See [[session-runtime]] for the event handling.

7. (Optional) Green-screen background for compositing

Skip this unless you need to composite the agent over your own UI (no backdrop, the person "floating" on the page). The default avatarStyle.view: "rectangle" already works for the standard embedded panel above; only switch to silhouette if you need to chroma-key the avatar yourself.

If you do, set it in two places — server-side and SDK-side — and they have to match.

Server side — WebRTC channel config. Tell the server to emit a chroma-keyed (green) stream:

curl -X PUT https://companion-api.napster.com/public/agents/agent_abc123/channels/webrtc \
  -H "X-Api-Key: $NAPSTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "useGreenVideo": true }'

SDK side — change avatarStyle.view from the default "rectangle" to "silhouette". Tell the Web SDK to consume the green stream by keying it out and rendering only the person:

await NapsterCompanionApiSdk.init(token, {
  mountContainer: mountRef.current,
  className: "omniagent-sdk-root",
  avatarStyle: { view: "silhouette" },  // overrides the default "rectangle"
  onData: handleData,
});

The two settings have to be in sync. If the server sends a green-screened stream but the SDK isn't using silhouette, the chroma color shows through; if the SDK is in silhouette but the server isn't sending the green stream, there's nothing to key out.

8. Production

The local token server is a prototype. Before shipping, port /token into your backend with: per-user authentication, rate limiting, and per-session context (externalClientId / externalClientProfile) resolved from the signed-in user. The browser's fetch('/token') line doesn't change. The API key never reaches the browser.

Hand back to the developer

  • Where the panel component/markup lives and how it's mounted.
  • The token endpoint (real backend route, or local-token-server/ on :5173).
  • Voice and turn-detection settings in effect (from the agent).
  • Whether persistence is on and why (multi-page vs SPA), and any exclude routes configured.
  • A reminder to gitignore the env file and port /token to production.
  • Pointers to [[session-runtime]] (events, commands, tool loop) and [[troubleshoot-omniagent]].

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.