Skip to content

didww/ai / skills/didww-to-livekit

didww-to-livekit

Verified

Connect a DIDWW phone number to a LiveKit Agents worker over SIP, on LiveKit Cloud or self-hosted: inbound trunk, dispatch rule to a named agent, optional outbound trunk. Use whenever the user wants a LiveKit agent (any STT, LLM and TTS combination, including Claude as the brain) answering a real number via DIDWW, mentions sip.livekit.cloud, SIP inbound trunks or dispatch rules, lk sip commands, agent_name dispatch, or debugging calls between DIDWW and LiveKit. This is the bring-your-own-brain pairing: the agent is code the user runs.

FileKindSize
.npmignoreother66 B
LICENSEother1.1 KB
README.mdmarkdown1.3 KB
SKILL.mdskill md10.9 KB
bin/install.jsexecutablescript5.3 KB
install.shexecutablescript1.0 KB
package.jsonmanifest924 B
publish.shexecutablescript604 B
scripts/connect.pyscript12.7 KB
test.shexecutablescript488 B
tests/test_connect.pyscript12.2 KB

tests/test_connect.py

View on GitHub
#!/usr/bin/env python3
"""Tests for didww-to-livekit/scripts/connect.py with stubbed HTTP."""
import base64, contextlib, hashlib, hmac, io, json, os, runpy, sys, urllib.error, urllib.request
sys.dont_write_bytecode = True
P = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "scripts", "connect.py"); results = []
def check(name, ok, detail=""):
    results.append(bool(ok)); print(f"{'PASS' if ok else 'FAIL'}  {name}  {detail}")
ENV = {"LIVEKIT_URL": "https://myproj.livekit.cloud", "LIVEKIT_API_KEY": "APIkey123", "LIVEKIT_API_SECRET": "s3cret"}
def canned_for(url):
    m = url.rsplit("/", 1)[-1]
    return {"CreateSIPInboundTrunk": {"sipTrunkId": "ST_in1", "name": "n"},
            "CreateSIPDispatchRule": {"sipDispatchRuleId": "SDR_1"},
            "CreateSIPOutboundTrunk": {"sipTrunkId": "ST_out1"},
            "ListSIPInboundTrunk": {"items": [{"sipTrunkId": "ST_in1", "name": "DIDWW +33144556677", "numbers": ["+33144556677"], "authUsername": "u"}]},
            "ListSIPDispatchRule": {"items": [{"sipDispatchRuleId": "SDR_1", "name": "DIDWW +33144556677", "trunkIds": ["ST_in1"], "roomConfig": {"agents": [{"agentName": "my-agent"}]}}]},
            "ListSIPOutboundTrunk": {"items": [{"sipTrunkId": "ST_out1", "address": "fra.eu.out.didww.com", "numbers": ["+33144556677"]}]}}.get(m, {})
def run(argv, env=ENV, fail=None):
    reqs = []
    class R:
        def __init__(s, d): s.d = json.dumps(d).encode()
        def read(s): return s.d
        def __enter__(s): return s
        def __exit__(s, *a): pass
    def fake_urlopen(req, timeout=None):
        reqs.append({"url": req.full_url, "method": req.get_method(), "headers": {k.lower(): v for k, v in req.header_items()}, "body": json.loads(req.data) if req.data else None})
        if fail: raise urllib.error.HTTPError(req.full_url, fail, "err", {}, io.BytesIO(b'{"msg":"invalid token"}'))
        return R(canned_for(req.full_url))
    old_env, old_argv, old_open = dict(os.environ), sys.argv, urllib.request.urlopen
    for k in ENV: os.environ.pop(k, None)
    os.environ.update(env); sys.argv = [P] + argv; urllib.request.urlopen = fake_urlopen
    out = io.StringIO(); code = 0
    try:
        with contextlib.redirect_stdout(out), contextlib.redirect_stderr(out): runpy.run_path(P, run_name="__main__")
    except SystemExit as e:  # sys.exit("msg") prints msg to stderr only at interpreter exit; mirror that here
        code = e.code if isinstance(e.code, int) else (0 if e.code is None else 1)
        if isinstance(e.code, str): out.write(e.code + "\n")
    finally:
        urllib.request.urlopen = old_open; sys.argv = old_argv; os.environ.clear(); os.environ.update(old_env)
    return reqs, out.getvalue(), code
def b64d(s): return base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))
def jwt(auth):
    tok = auth.split(" ", 1)[1]; h, p, sig = tok.split(".")
    ok = hmac.compare_digest(b64d(sig), hmac.new(b"s3cret", f"{h}.{p}".encode(), hashlib.sha256).digest())
    return ok, json.loads(b64d(h)), json.loads(b64d(p))
FULL = ["--number", "+33144556677", "--agent", "my-agent", "--inbound-user", "iu", "--inbound-pass", "ip",
        "--outbound-host", "fra.eu.out.didww.com", "--outbound-user", "ou", "--outbound-pass", "op",
        "--sip-uri", "sip:vjnxecm0tjk.sip.livekit.cloud"]
M = "https://myproj.livekit.cloud/twirp/livekit.SIP/"

reqs, out, code = run(["--help"], env={})
check("--help exits 0 without env or API calls", code == 0 and not reqs and "Usage" in out)
reqs, out, code = run(FULL, env={})
check("refuses without LIVEKIT_URL/KEY/SECRET", code != 0 and not reqs)
reqs, out, code = run(FULL)
check("three Twirp POSTs in order: inbound trunk, dispatch rule, outbound trunk",
      [r["url"] for r in reqs] == [M + m for m in ("CreateSIPInboundTrunk", "CreateSIPDispatchRule", "CreateSIPOutboundTrunk")], [r["url"] for r in reqs])
t = reqs[0]["body"].get("trunk", {}) if reqs else {}
check("inbound trunk: E.164 number + digest auth_username/auth_password", t.get("numbers") == ["+33144556677"] and t.get("auth_username") == "iu" and t.get("auth_password") == "ip", json.dumps(t))
G711 = [{"name": "PCMA", "rate": 8000}, {"name": "PCMU", "rate": 8000}]
SECURE = {"only_listed_codecs": True, "codecs": G711, "encryption": "SIP_MEDIA_ENCRYPT_REQUIRE"}
check("inbound trunk: G.711 only, SRTP required by default, no deprecated media_encryption",
      t.get("media") == SECURE and "media_encryption" not in t, json.dumps(t.get("media")))
d = reqs[1]["body"].get("dispatch_rule", {}) if len(reqs) > 1 else {}
check("dispatch rule: bound to the new trunk id, one room per call, agent by name",
      d.get("trunk_ids") == ["ST_in1"] and "room_prefix" in d.get("rule", {}).get("dispatch_rule_individual", {}) and d.get("room_config", {}).get("agents", [{}])[0].get("agent_name") == "my-agent", json.dumps(d))
o = reqs[2]["body"].get("trunk", {}) if len(reqs) > 2 else {}
check("outbound trunk: DIDWW host only, TLS and SRTP by default, DIDWW auth pair, number",
      o.get("address") == "fra.eu.out.didww.com" and o.get("transport") == "SIP_TRANSPORT_TLS" and o.get("auth_username") == "ou" and o.get("auth_password") == "op" and o.get("numbers") == ["+33144556677"] and o.get("media") == SECURE, json.dumps(o))
check("prints the DIDWW side: host without sip:, {DID}, codecs, TLS 5061, SRTP SDES, Cloud ranges, and the DIDWW trunk note",
      "Host vjnxecm0tjk.sip.livekit.cloud" in out and "{DID}" in out and "PCMA and PCMU" in out and "SRTP Mode SRTP SDES" in out and "143.223.88.0/21" in out and "5061, Transport TLS" in out
      and "NOTE for the DIDWW trunks" in out and "500 No suitable media" in out and "400 Bad Request" in out, out[-900:])
ok, h, p = jwt(reqs[0]["headers"]["authorization"]) if reqs else (False, {}, {})
check("JWT: HS256 signed with the API secret, iss = key, sip.admin grant, short expiry",
      ok and h.get("alg") == "HS256" and p.get("iss") == "APIkey123" and p.get("sip", {}).get("admin") is True and 0 < p.get("exp", 0) - p.get("nbf", 0) <= 3600, json.dumps(p))
check("all requests: JSON body, non-Python User-Agent",
      bool(reqs) and all("json" in r["headers"].get("content-type", "") and not r["headers"].get("user-agent", "python").lower().startswith("python") for r in reqs))
check("prints the ids and the LiveKit SIP URI for the DIDWW trunk", "ST_in1" in out and "SDR_1" in out and "ST_out1" in out and "sip:vjnxecm0tjk.sip.livekit.cloud" in out and "myproj.sip" not in out, out[-300:])
reqs, out, code = run(FULL, env={**ENV, "LIVEKIT_URL": "wss://myproj.livekit.cloud/"})
check("wss:// project URL becomes the https API host", bool(reqs) and reqs[0]["url"].startswith("https://myproj.livekit.cloud/twirp"))
reqs, out, code = run(FULL + ["--transport", "TCP", "--srtp", "disable"])
check("--transport tcp --srtp disable gives plain trunks and says they are not encrypted",
      len(reqs) == 3 and reqs[2]["body"]["trunk"]["transport"] == "SIP_TRANSPORT_TCP" and "encryption" not in reqs[0]["body"]["trunk"]["media"] and "encryption" not in reqs[2]["body"]["trunk"]["media"]
      and "5060, Transport TCP" in out and "SRTP Mode Disabled" in out and "NOT encrypted" in out and "NOTE for the DIDWW trunks" not in out, out[-500:])
reqs, out, code = run(FULL + ["--transport", "tcp"])
check("SRTP without TLS is created but flagged as unverified", len(reqs) == 3 and "NOTE: SRTP was only verified" in out and "5060, Transport TCP" in out)
OUT = ["--outbound-only", "--number", "+33144556677", "--outbound-host", "fra.eu.out.didww.com", "--outbound-user", "ou", "--outbound-pass", "op"]
reqs, out, code = run(OUT)
o = reqs[0]["body"]["trunk"] if reqs else {}
check("--outbound-only creates just the outbound trunk, no agent or inbound flags needed",
      code == 0 and [r["url"].rsplit("/", 1)[-1] for r in reqs] == ["CreateSIPOutboundTrunk"] and o.get("address") == "fra.eu.out.didww.com" and o.get("transport") == "SIP_TRANSPORT_TLS" and o.get("media") == SECURE
      and "ST_out1" in out and "DIDWW inbound trunk" not in out and "DIDWW panel" in out and "143.223.88.0/21" in out, out[-600:])
reqs, out, code = run(["--outbound-only", "--number", "+33144556677"])
check("--outbound-only without the outbound flags is refused", code != 0 and not reqs)
reqs, out, code = run(OUT[:-2])
check("--outbound-only without credentials is refused", code != 0 and not reqs)
reqs, out, code = run(FULL + ["--transport", "sctp"])
check("unknown transport is rejected before any API call", code != 0 and not reqs)
reqs, out, code = run(FULL[:8])
check("without outbound flags only the inbound trunk and the rule are created", len(reqs) == 2 and code == 0)
reqs, out, code = run(FULL[:8] + ["--outbound-host", "fra.eu.out.didww.com"])
check("--outbound-host without credentials is refused", code != 0 and not reqs)
reqs, out, code = run(["--number", "+33144556677", "--agent", "a"])
check("refuses an inbound trunk with neither digest nor allowlist", code != 0 and not reqs)
reqs, out, code = run(["--number", "+33144556677", "--agent", "a", "--inbound-user", "u"])
check("refuses --inbound-user without --inbound-pass", code != 0 and not reqs)
reqs, out, code = run(["--number", "33144556677", "--agent", "a", "--inbound-user", "u", "--inbound-pass", "p"])
check("refuses a number without the + prefix (LiveKit matches E.164 exactly)", code != 0 and not reqs)
reqs, out, code = run(["--number", "+33144556677", "--inbound-user", "u", "--inbound-pass", "p"])
check("refuses without --agent", code != 0 and not reqs)
reqs, out, code = run(["--number", "+33144556677", "--agent", "a", "--allow-ip", "1.2.3.0/24", "--allow-ip", "5.6.7.8"])
t = reqs[0]["body"]["trunk"] if reqs else {}
check("--allow-ip alone: allowed_addresses sent, warns that Cloud enables it via support",
      t.get("allowed_addresses") == ["1.2.3.0/24", "5.6.7.8"] and "auth_username" not in t and "support" in out.lower(), out[-200:])
reqs, out, code = run(["--number", "+33144556677", "--agent", "a", "--inbound-user", "u", "--inbound-pass", "p", "--allow-ip", "1.2.3.4"])
t = reqs[0]["body"]["trunk"] if reqs else {}
check("digest and allowlist can be combined", t.get("auth_username") == "u" and t.get("allowed_addresses") == ["1.2.3.4"])
reqs, out, code = run(["--show"])
check("without --sip-uri the SIP URI is a placeholder, never derived from the project URL",
      code == 0 and "myproj.sip" not in out and "Project settings" in out, out[:200])
reqs, out, code = run(["--show", "--sip-uri", "sip:vjnxecm0tjk.sip.livekit.cloud;transport=tcp"])
check("--show lists trunks and rules, creates nothing, prints the SIP URI",
      [r["url"].rsplit("/", 1)[-1] for r in reqs] == ["ListSIPInboundTrunk", "ListSIPDispatchRule", "ListSIPOutboundTrunk"] and code == 0 and "sip:vjnxecm0tjk.sip.livekit.cloud" in out and ";transport" not in out and "ST_in1" in out and "my-agent" in out and "fra.eu.out.didww.com" in out, out[-300:])
reqs, out, code = run(FULL, fail=401)
check("API error exits nonzero with status and body, no traceback", code != 0 and "401" in out and "invalid token" in out and "Traceback" not in out, out[-200:])
reqs, out, code = run([])
check("no args prints usage and exits nonzero", code != 0 and not reqs and "Usage" in out)
reqs, out, code = run(FULL, env={**ENV, "LIVEKIT_URL": "http://livekit.example.com:7880"})
check("plain http:// LIVEKIT_URL on a remote host refused (token would travel unencrypted)", code != 0 and not reqs and "https" in out)
reqs, out, code = run(FULL, env={**ENV, "LIVEKIT_URL": "ws://livekit.example.com:7880"})
check("plain ws:// LIVEKIT_URL on a remote host refused", code != 0 and not reqs)
reqs, out, code = run(FULL, env={**ENV, "LIVEKIT_URL": "ws://localhost:7880"})
check("ws://localhost (local self-hosted) allowed, mapped to http://localhost", code == 0 and reqs and reqs[0]["url"].startswith("http://localhost:7880/twirp/"), reqs[0]["url"] if reqs else out[-120:])
envpw = [x for x in FULL if x not in ("--inbound-pass", "ip", "--outbound-pass", "op")]
reqs, out, code = run(envpw, env={**ENV, "LIVEKIT_INBOUND_PASS": "envi", "DIDWW_TRUNK_PASS": "envo"})
ib = next((r["body"] for r in reqs if r["url"].endswith("CreateSIPInboundTrunk")), {}); ob = next((r["body"] for r in reqs if r["url"].endswith("CreateSIPOutboundTrunk")), {})
check("passwords can come from LIVEKIT_INBOUND_PASS / DIDWW_TRUNK_PASS", code == 0 and json.dumps(ib).count("envi") == 1 and json.dumps(ob).count("envo") == 1, out[-150:])
print(f"\n{sum(results)}/{len(results)} passed"); sys.exit(0 if all(results) else 1)
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall