@mosadd/mcp 3.0.0-alpha.25 → 3.0.0-alpha.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/mcp.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createMosaddServer
4
- } from "../chunk-EJQT6FXI.js";
4
+ } from "../chunk-YBSQUORF.js";
5
5
  import {
6
6
  isSessionExpired,
7
7
  loadSession,
@@ -1471,17 +1471,92 @@ var mailAliasTools = mailTools.map((tool) => ({
1471
1471
  description: `[DEPRECATED \u2014 use ${tool.name} instead. mp0st_* aliases stay through alpha.25 for back-compat; will be removed in alpha.27.] ` + tool.description
1472
1472
  }));
1473
1473
 
1474
- // src/tools/mtalk.ts
1474
+ // src/tools/mail-provenance.ts
1475
1475
  import { z as z8 } from "zod";
1476
- var RoomLabel = z8.string().min(1).max(120).regex(/^[a-zA-Z0-9._-]+$/).describe("Human-readable room label (e.g. 'ops', 'field-team'). Used to derive a stable room id.");
1477
- var RoomId2 = z8.string().min(1).describe("Room id returned by mTALK_open.");
1478
- var mTALK_open_input = z8.object({
1476
+ var DEFAULT_SUPABASE_URL2 = "https://rooffhgbxafyjcwmwpsy.supabase.co";
1477
+ function supabaseUrl2() {
1478
+ return process.env.MOSADD_SUPABASE_URL?.replace(/\/$/, "") ?? process.env.SUPABASE_URL?.replace(/\/$/, "") ?? DEFAULT_SUPABASE_URL2;
1479
+ }
1480
+ function hubKey2() {
1481
+ return process.env.MOSADD_API_KEY ?? process.env.MOSADD_HUB_KEY ?? null;
1482
+ }
1483
+ var EmailAddress2 = z8.string().email().max(254);
1484
+ var mp0st_send_as_agent_input = z8.object({
1485
+ to: z8.union([EmailAddress2, z8.array(EmailAddress2).min(1).max(50)]),
1486
+ subject: z8.string().min(1).max(998),
1487
+ body_text: z8.string().max(1048576).optional(),
1488
+ body_html: z8.string().max(1048576).optional(),
1489
+ cc: z8.array(EmailAddress2).max(50).optional(),
1490
+ bcc: z8.array(EmailAddress2).max(50).optional(),
1491
+ reply_to: EmailAddress2.optional(),
1492
+ tracking: z8.boolean().optional(),
1493
+ agent_id: z8.string().min(1).max(120).describe("Stable id of the agent doing the send. Stamped as sent_by_agent_id for provenance."),
1494
+ task_id: z8.string().min(1).max(120).optional().describe("Optional id of the task/run this send belongs to. Stamped as sent_by_task_id.")
1495
+ });
1496
+ async function mintHubClaim(agentId, taskId) {
1497
+ const key = hubKey2();
1498
+ if (!key) {
1499
+ throw new Error("mAYL_send_as_agent needs MOSADD_API_KEY (hub key) to mint a provenance claim.");
1500
+ }
1501
+ const r = await fetch(`${supabaseUrl2()}/functions/v1/hub-claim-mint`, {
1502
+ method: "POST",
1503
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
1504
+ body: JSON.stringify({ agent_id: agentId, task_id: taskId ?? null })
1505
+ });
1506
+ if (!r.ok) {
1507
+ const b = await r.text().catch(() => "");
1508
+ throw new Error(`hub-claim-mint ${r.status}: ${b.slice(0, 200)}`);
1509
+ }
1510
+ const data = await r.json();
1511
+ if (!data?.access_token) throw new Error("hub-claim-mint: no access_token in response");
1512
+ return data.access_token;
1513
+ }
1514
+ async function mAYL_send_as_agent(input, ctx) {
1515
+ if (!input.body_text && !input.body_html) {
1516
+ throw new Error("mAYL_send_as_agent requires at least one of body_text or body_html.");
1517
+ }
1518
+ const claim = await mintHubClaim(input.agent_id, input.task_id);
1519
+ ctx.log("debug", "mAYL_send_as_agent invoking mp0st-send with hub-claim", { agent_id: input.agent_id });
1520
+ const { agent_id: _ai, task_id: _ti, ...mailFields } = input;
1521
+ const r = await fetch(`${supabaseUrl2()}/functions/v1/mp0st-send`, {
1522
+ method: "POST",
1523
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${claim}` },
1524
+ body: JSON.stringify(mailFields)
1525
+ });
1526
+ if (!r.ok) {
1527
+ const b = await r.text().catch(() => "");
1528
+ throw new Error(`mp0st-send ${r.status}: ${b.slice(0, 200)}`);
1529
+ }
1530
+ const res = await r.json();
1531
+ if (res.error) throw new Error(res.error);
1532
+ return {
1533
+ message_id: res.email_id ?? "",
1534
+ status: res.status ?? "sent",
1535
+ is_internal: res.is_internal ?? false,
1536
+ sent_by: "agent"
1537
+ };
1538
+ }
1539
+ var mailProvenanceTools = [
1540
+ {
1541
+ name: "mAYL_send_as_agent",
1542
+ requires: "network",
1543
+ description: "Send an email ATTRIBUTED TO THE AGENT (provenance-stamped). Unlike mAYL_send (sends as the user), this stamps sent_by='agent' plus your agent_id and optional task_id onto the email record and audit trail \u2014 so recipients and compliance can see the mail was agent-originated. Auth: presents a hub-claim JWT (needs MOSADD_API_KEY). The mp0st-send EF verifies the claim with HUB_JWT_SECRET; body trust is never granted for provenance.",
1544
+ inputSchema: mp0st_send_as_agent_input,
1545
+ handler: mAYL_send_as_agent
1546
+ }
1547
+ ];
1548
+
1549
+ // src/tools/mtalk.ts
1550
+ import { z as z9 } from "zod";
1551
+ var RoomLabel = z9.string().min(1).max(120).regex(/^[a-zA-Z0-9._-]+$/).describe("Human-readable room label (e.g. 'ops', 'field-team'). Used to derive a stable room id.");
1552
+ var RoomId2 = z9.string().min(1).describe("Room id returned by mTALK_open.");
1553
+ var mTALK_open_input = z9.object({
1479
1554
  label: RoomLabel.optional().describe("Optional label; defaults to a personal room.")
1480
1555
  });
1481
- var mTALK_join_input = z8.object({ room_id: RoomId2 });
1482
- var mTALK_press_input = z8.object({ room_id: RoomId2 });
1483
- var mTALK_release_input = z8.object({ room_id: RoomId2 });
1484
- var mTALK_state_input = z8.object({ room_id: RoomId2 });
1556
+ var mTALK_join_input = z9.object({ room_id: RoomId2 });
1557
+ var mTALK_press_input = z9.object({ room_id: RoomId2 });
1558
+ var mTALK_release_input = z9.object({ room_id: RoomId2 });
1559
+ var mTALK_state_input = z9.object({ room_id: RoomId2 });
1485
1560
  async function mTALK_open(input, ctx) {
1486
1561
  const { roomId } = await ctx.providers.voice.createRoom(input.label);
1487
1562
  ctx.log("debug", "mTALK_open", { room_id: roomId });
@@ -1545,7 +1620,7 @@ var mtalkTools = [
1545
1620
  ];
1546
1621
 
1547
1622
  // src/tools/attachments.ts
1548
- import { z as z9 } from "zod";
1623
+ import { z as z10 } from "zod";
1549
1624
 
1550
1625
  // src/providers/blob-upload.ts
1551
1626
  function defaultBucket(kind) {
@@ -1595,14 +1670,14 @@ function decodeBase64Body(b64) {
1595
1670
 
1596
1671
  // src/tools/attachments.ts
1597
1672
  var PROTOCOL_VERSION4 = "mosadd.chat.v1";
1598
- var Base64Body = z9.string().min(1).max(2e7).describe("Attachment bytes as base64 (or a data: URL). MCP is JSON-only, so binary is base64-encoded. Max ~15 MB decoded.");
1599
- var Mime = z9.string().min(1).max(120).describe("MIME type, e.g. audio/ogg, application/pdf, image/png.");
1600
- var DurationMs = z9.number().int().positive().optional().describe("Audio clip length in ms (voice only), if known.");
1601
- var Filename = z9.string().min(1).max(255).optional().describe("Original filename (file only).");
1602
- var ReplyTo = z9.string().optional().describe("Optional id of the message being replied to.");
1603
- var ContactRef3 = z9.string().min(1).describe("Recipient identity id (UUID). Use mDM_list_contacts to find it.");
1604
- var RoomId3 = z9.string().min(1).describe("Room/channel id (UUID).");
1605
- var ThreadLabel = z9.string().max(120).regex(/^[a-zA-Z0-9._-]+$/).optional().describe("Optional thread label within the conversation (mDM USP: multiple threads per contact).");
1673
+ var Base64Body = z10.string().min(1).max(2e7).describe("Attachment bytes as base64 (or a data: URL). MCP is JSON-only, so binary is base64-encoded. Max ~15 MB decoded.");
1674
+ var Mime = z10.string().min(1).max(120).describe("MIME type, e.g. audio/ogg, application/pdf, image/png.");
1675
+ var DurationMs = z10.number().int().positive().optional().describe("Audio clip length in ms (voice only), if known.");
1676
+ var Filename = z10.string().min(1).max(255).optional().describe("Original filename (file only).");
1677
+ var ReplyTo = z10.string().optional().describe("Optional id of the message being replied to.");
1678
+ var ContactRef3 = z10.string().min(1).describe("Recipient identity id (UUID). Use mDM_list_contacts to find it.");
1679
+ var RoomId3 = z10.string().min(1).describe("Room/channel id (UUID).");
1680
+ var ThreadLabel = z10.string().max(120).regex(/^[a-zA-Z0-9._-]+$/).optional().describe("Optional thread label within the conversation (mDM USP: multiple threads per contact).");
1606
1681
  function dmThreadId3(selfId, otherId, label) {
1607
1682
  const [a, b] = [selfId, otherId].sort();
1608
1683
  return label ? `dm:${a}:${b}:${label}` : `dm:${a}:${b}`;
@@ -1645,21 +1720,21 @@ async function resolveLinkedSpaceId2(channelId) {
1645
1720
  if (!spaceId) throw new Error(`Channel ${channelId} has no linked space yet \u2014 run mIRC_join/mIRC_list first or pass space_id.`);
1646
1721
  return spaceId;
1647
1722
  }
1648
- var mDM_send_voice_input = z9.object({
1723
+ var mDM_send_voice_input = z10.object({
1649
1724
  to: ContactRef3,
1650
1725
  audio_base64: Base64Body,
1651
1726
  mime: Mime.default("audio/ogg"),
1652
1727
  duration_ms: DurationMs,
1653
- caption: z9.string().max(2e3).optional(),
1728
+ caption: z10.string().max(2e3).optional(),
1654
1729
  thread_label: ThreadLabel,
1655
1730
  reply_to_id: ReplyTo
1656
1731
  });
1657
- var mDM_send_file_input = z9.object({
1732
+ var mDM_send_file_input = z10.object({
1658
1733
  to: ContactRef3,
1659
1734
  file_base64: Base64Body,
1660
1735
  filename: Filename,
1661
1736
  mime: Mime,
1662
- caption: z9.string().max(2e3).optional(),
1737
+ caption: z10.string().max(2e3).optional(),
1663
1738
  thread_label: ThreadLabel,
1664
1739
  reply_to_id: ReplyTo
1665
1740
  });
@@ -1705,23 +1780,23 @@ async function mDM_send_file(input, ctx) {
1705
1780
  recipient_account_id: input.to
1706
1781
  });
1707
1782
  }
1708
- var mIRC_send_voice_input = z9.object({
1783
+ var mIRC_send_voice_input = z10.object({
1709
1784
  channel_id: RoomId3,
1710
1785
  audio_base64: Base64Body,
1711
1786
  mime: Mime.default("audio/ogg"),
1712
1787
  duration_ms: DurationMs,
1713
- caption: z9.string().max(2e3).optional(),
1788
+ caption: z10.string().max(2e3).optional(),
1714
1789
  reply_to_id: ReplyTo,
1715
- space_id: z9.string().optional().describe("Backing space id. Resolved automatically if omitted.")
1790
+ space_id: z10.string().optional().describe("Backing space id. Resolved automatically if omitted.")
1716
1791
  });
1717
- var mIRC_send_file_input = z9.object({
1792
+ var mIRC_send_file_input = z10.object({
1718
1793
  channel_id: RoomId3,
1719
1794
  file_base64: Base64Body,
1720
1795
  filename: Filename,
1721
1796
  mime: Mime,
1722
- caption: z9.string().max(2e3).optional(),
1797
+ caption: z10.string().max(2e3).optional(),
1723
1798
  reply_to_id: ReplyTo,
1724
- space_id: z9.string().optional()
1799
+ space_id: z10.string().optional()
1725
1800
  });
1726
1801
  async function mIRC_send_voice(input, ctx) {
1727
1802
  const space_id = input.space_id ?? await resolveLinkedSpaceId2(input.channel_id);
@@ -1766,13 +1841,54 @@ var attachmentTools = [
1766
1841
  }
1767
1842
  ];
1768
1843
 
1844
+ // src/tools/ptt-ingest.ts
1845
+ import { z as z11 } from "zod";
1846
+ var mTALK_ingest_ptt_input = z11.object({
1847
+ audio_base64: z11.string().min(1).max(2e7).describe("Recorded PTT 'over' as base64 (a 'data:audio/\u2026;base64,\u2026' prefix is stripped if present)."),
1848
+ mime_type: z11.string().min(1).max(120).default("audio/webm").describe("MIME type of the audio. Default audio/webm (browser MediaRecorder default)."),
1849
+ direction: z11.enum(["human_to_agent", "agent_to_human"]).describe("Direction the PTT crossed: who originated, who received. 'human_to_agent' = user spoke to an agent; 'agent_to_human' = agent spoke to the user."),
1850
+ message_id: z11.string().min(1).max(120).optional().describe("Optional id of the messages_meta row this PTT belongs to. When present, links the transcript back to the message for jump-to-source from RAG."),
1851
+ thread_id: z11.string().min(1).max(120).optional().describe("Optional thread id (e.g. `chat:<channel_id>` or `dm:<a>:<b>`) so the transcript carries its conversational scope into RAG.")
1852
+ });
1853
+ async function mTALK_ingest_ptt(input, ctx) {
1854
+ readSupabaseEnv();
1855
+ const audio = input.audio_base64.replace(/^data:[^;]+;base64,/, "");
1856
+ ctx.log("debug", "mTALK_ingest_ptt invoking ptt-ingest", {
1857
+ direction: input.direction,
1858
+ thread_id: input.thread_id ?? null,
1859
+ mime_type: input.mime_type
1860
+ });
1861
+ const res = await invokeFunction("ptt-ingest", {
1862
+ audio_base64: audio,
1863
+ mime_type: input.mime_type,
1864
+ direction: input.direction,
1865
+ message_id: input.message_id ?? null,
1866
+ thread_id: input.thread_id ?? null
1867
+ });
1868
+ const status = res.status ?? "pending";
1869
+ return {
1870
+ ptt_id: res.ptt_id ?? "",
1871
+ status,
1872
+ opted_in: status !== "skipped_optout"
1873
+ };
1874
+ }
1875
+ var pttIngestTools = [
1876
+ {
1877
+ name: "mTALK_ingest_ptt",
1878
+ requires: "network",
1879
+ description: "Submit a finished PTT 'over' (push-to-talk audio segment) for transcription into the caller's RAG index \u2014 so 'what did X say on PTT?' is searchable later. The PERSISTENCE of the voice message itself (the message_meta row + fan-out) is handled by mDM_send_voice / mIRC_send_voice; this tool is the transcription bridge only. Honors per-user RAG opt-in: opted-out callers get status='skipped_optout' (no transcript stored). Auth: Supabase session JWT.",
1880
+ inputSchema: mTALK_ingest_ptt_input,
1881
+ handler: mTALK_ingest_ptt
1882
+ }
1883
+ ];
1884
+
1769
1885
  // src/tools/knowledge.ts
1770
- import { z as z10 } from "zod";
1771
- var mRAG_search_input = z10.object({
1772
- query: z10.string().min(1).max(2e3).describe("Natural-language question to answer from the user's own indexed messages/emails/calls/notes."),
1773
- top_k: z10.number().int().min(1).max(25).optional().describe("Max number of source chunks to retrieve and ground the answer in. Default 8."),
1774
- source_types: z10.array(z10.enum(["message", "email", "call", "note", "contact"])).optional().describe("Restrict retrieval to these source types. Omit to search everything."),
1775
- thread_id: z10.string().optional().describe("Optional: restrict retrieval to a single thread id (e.g. a dm:/chat: thread).")
1886
+ import { z as z12 } from "zod";
1887
+ var mRAG_search_input = z12.object({
1888
+ query: z12.string().min(1).max(2e3).describe("Natural-language question to answer from the user's own indexed messages/emails/calls/notes."),
1889
+ top_k: z12.number().int().min(1).max(25).optional().describe("Max number of source chunks to retrieve and ground the answer in. Default 8."),
1890
+ source_types: z12.array(z12.enum(["message", "email", "call", "note", "contact"])).optional().describe("Restrict retrieval to these source types. Omit to search everything."),
1891
+ thread_id: z12.string().optional().describe("Optional: restrict retrieval to a single thread id (e.g. a dm:/chat: thread).")
1776
1892
  });
1777
1893
  async function mRAG_search(input, ctx) {
1778
1894
  readSupabaseEnv();
@@ -1789,12 +1905,12 @@ async function mRAG_search(input, ctx) {
1789
1905
  chunks_found: data.chunks_found ?? (data.sources?.length ?? 0)
1790
1906
  };
1791
1907
  }
1792
- var mRAG_ingest_input = z10.object({
1793
- content_text: z10.string().min(1).max(2e5).describe("Text to index into the user's private knowledge base (a note, document, transcript, pasted page\u2026). Chunked + embedded server-side."),
1794
- source_type: z10.enum(["file", "note", "message", "email", "contact", "call"]).optional().describe("What kind of source this is. Default 'file' (a document/note). Use 'note' for ad-hoc text."),
1795
- source_id: z10.string().optional().describe("Optional stable id for the source so re-ingests can be grouped."),
1796
- thread_id: z10.string().optional().describe("Optional thread id to associate this knowledge with (e.g. a dm:/chat: thread)."),
1797
- title: z10.string().max(300).optional().describe("Optional human title, stored in metadata.")
1908
+ var mRAG_ingest_input = z12.object({
1909
+ content_text: z12.string().min(1).max(2e5).describe("Text to index into the user's private knowledge base (a note, document, transcript, pasted page\u2026). Chunked + embedded server-side."),
1910
+ source_type: z12.enum(["file", "note", "message", "email", "contact", "call"]).optional().describe("What kind of source this is. Default 'file' (a document/note). Use 'note' for ad-hoc text."),
1911
+ source_id: z12.string().optional().describe("Optional stable id for the source so re-ingests can be grouped."),
1912
+ thread_id: z12.string().optional().describe("Optional thread id to associate this knowledge with (e.g. a dm:/chat: thread)."),
1913
+ title: z12.string().max(300).optional().describe("Optional human title, stored in metadata.")
1798
1914
  });
1799
1915
  async function mRAG_ingest(input, ctx) {
1800
1916
  readSupabaseEnv();
@@ -1809,15 +1925,15 @@ async function mRAG_ingest(input, ctx) {
1809
1925
  });
1810
1926
  return { indexed: data.indexed ?? 0, chunk_count: data.chunk_count ?? 0 };
1811
1927
  }
1812
- var mRAG_list_sources_input = z10.object({});
1928
+ var mRAG_list_sources_input = z12.object({});
1813
1929
  async function mRAG_list_sources(_input, ctx) {
1814
1930
  readSupabaseEnv();
1815
1931
  ctx.log("debug", "mRAG_list_sources via rag-sources");
1816
1932
  return await invokeFunction("rag-sources", { action: "list" });
1817
1933
  }
1818
- var mRAG_delete_input = z10.object({
1819
- source_id: z10.string().optional().describe("Delete every indexed chunk with this source_id (from mRAG_list_sources)."),
1820
- thread_id: z10.string().optional().describe("Delete every indexed chunk associated with this thread_id.")
1934
+ var mRAG_delete_input = z12.object({
1935
+ source_id: z12.string().optional().describe("Delete every indexed chunk with this source_id (from mRAG_list_sources)."),
1936
+ thread_id: z12.string().optional().describe("Delete every indexed chunk associated with this thread_id.")
1821
1937
  }).refine((v) => v.source_id || v.thread_id, {
1822
1938
  message: "Provide source_id or thread_id \u2014 mRAG_delete refuses to purge the whole index."
1823
1939
  });
@@ -1862,34 +1978,34 @@ var knowledgeTools = [
1862
1978
  ];
1863
1979
 
1864
1980
  // src/tools/actions.ts
1865
- import { z as z11 } from "zod";
1866
- var formField = z11.object({
1867
- name: z11.string().min(1).max(60).describe("Field key \u2014 returned verbatim in the result."),
1868
- label: z11.string().max(120).optional().describe("Human label shown to the recipient. Defaults to `name`."),
1869
- type: z11.enum(["text", "email", "number", "textarea", "tel", "url"]).optional().describe("Input type. Default 'text'."),
1870
- required: z11.boolean().optional().describe("Whether the recipient must fill this field.")
1981
+ import { z as z13 } from "zod";
1982
+ var formField = z13.object({
1983
+ name: z13.string().min(1).max(60).describe("Field key \u2014 returned verbatim in the result."),
1984
+ label: z13.string().max(120).optional().describe("Human label shown to the recipient. Defaults to `name`."),
1985
+ type: z13.enum(["text", "email", "number", "textarea", "tel", "url"]).optional().describe("Input type. Default 'text'."),
1986
+ required: z13.boolean().optional().describe("Whether the recipient must fill this field.")
1871
1987
  });
1872
- var action_create_input = z11.object({
1873
- action_type: z11.enum(["confirm", "file_request", "form", "open_url", "screen_share"]).describe(
1988
+ var action_create_input = z13.object({
1989
+ action_type: z13.enum(["confirm", "file_request", "form", "open_url", "screen_share"]).describe(
1874
1990
  "What you want the recipient to do: 'confirm' (yes/no), 'file_request' (pick a file from their computer), 'form' (fill fields), 'open_url' (open a vetted https URL), 'screen_share' (recipient shares their screen so you can SEE it via comms_action_frame_get \u2014 view only)."
1875
1991
  ),
1876
- message: z11.string().min(1).max(2e3).describe("What you're asking \u2014 shown on the consent screen above the action UI."),
1877
- creator_label: z11.string().max(80).optional().describe("How you're identified to the recipient (e.g. your agent name). Default 'Agent'."),
1992
+ message: z13.string().min(1).max(2e3).describe("What you're asking \u2014 shown on the consent screen above the action UI."),
1993
+ creator_label: z13.string().max(80).optional().describe("How you're identified to the recipient (e.g. your agent name). Default 'Agent'."),
1878
1994
  // confirm
1879
- yes_label: z11.string().max(40).optional().describe("[confirm] Affirmative button label. Default 'Tak'."),
1880
- no_label: z11.string().max(40).optional().describe("[confirm] Negative button label. Default 'Nie'."),
1995
+ yes_label: z13.string().max(40).optional().describe("[confirm] Affirmative button label. Default 'Tak'."),
1996
+ no_label: z13.string().max(40).optional().describe("[confirm] Negative button label. Default 'Nie'."),
1881
1997
  // file_request
1882
- accept: z11.string().max(200).optional().describe("[file_request] Accepted file types (HTML accept attr, e.g. 'image/*,.pdf')."),
1883
- max_bytes: z11.number().int().positive().max(5242880).optional().describe("[file_request] Max file size in bytes (\u2264 5 MB). NOTE: the returned file is NOT yet end-to-end encrypted \u2014 do not request sensitive files until Tier 1.1 ships."),
1998
+ accept: z13.string().max(200).optional().describe("[file_request] Accepted file types (HTML accept attr, e.g. 'image/*,.pdf')."),
1999
+ max_bytes: z13.number().int().positive().max(5242880).optional().describe("[file_request] Max file size in bytes (\u2264 5 MB). NOTE: the returned file is NOT yet end-to-end encrypted \u2014 do not request sensitive files until Tier 1.1 ships."),
1884
2000
  // form
1885
- fields: z11.array(formField).min(1).max(20).optional().describe("[form] Fields to collect from the recipient."),
2001
+ fields: z13.array(formField).min(1).max(20).optional().describe("[form] Fields to collect from the recipient."),
1886
2002
  // open_url
1887
- url: z11.string().url().optional().describe("[open_url] The https URL to open. The full URL is shown to the recipient before they open it."),
2003
+ url: z13.string().url().optional().describe("[open_url] The https URL to open. The full URL is shown to the recipient before they open it."),
1888
2004
  // screen_share
1889
- max_width: z11.number().int().positive().max(1920).optional().describe("[screen_share] Max captured frame width in px (default 1280). Frames are downscaled JPEGs."),
2005
+ max_width: z13.number().int().positive().max(1920).optional().describe("[screen_share] Max captured frame width in px (default 1280). Frames are downscaled JPEGs."),
1890
2006
  // lifecycle
1891
- ttl_ms: z11.number().int().positive().optional().describe("Link lifetime in milliseconds. Default 24h, capped at 7d."),
1892
- max_uses: z11.number().int().min(1).max(50).optional().describe("How many times the link can be redeemed. Default 1 (single-use).")
2007
+ ttl_ms: z13.number().int().positive().optional().describe("Link lifetime in milliseconds. Default 24h, capped at 7d."),
2008
+ max_uses: z13.number().int().min(1).max(50).optional().describe("How many times the link can be redeemed. Default 1 (single-use).")
1893
2009
  });
1894
2010
  function buildParams(input) {
1895
2011
  switch (input.action_type) {
@@ -1930,8 +2046,8 @@ async function action_create(input, ctx) {
1930
2046
  expires_at: res.expires_at ?? ""
1931
2047
  };
1932
2048
  }
1933
- var action_frame_get_input = z11.object({
1934
- action_id: z11.string().min(1).describe("The action_id returned by comms_action_create for a 'screen_share' action you created.")
2049
+ var action_frame_get_input = z13.object({
2050
+ action_id: z13.string().min(1).describe("The action_id returned by comms_action_create for a 'screen_share' action you created.")
1935
2051
  });
1936
2052
  async function action_frame_get(input, ctx) {
1937
2053
  readSupabaseEnv();
@@ -1971,37 +2087,95 @@ var actionTools = [
1971
2087
  }
1972
2088
  ];
1973
2089
 
2090
+ // src/tools/embed.ts
2091
+ import { z as z14 } from "zod";
2092
+ var EMBED_CDN = (process.env.MOSADD_EMBED_CDN ?? "https://embed.mosadd.com").replace(/\/+$/, "");
2093
+ var POSITIONS = ["inline", "sidebar-left", "sidebar-right", "floating-bl", "floating-br", "fullscreen"];
2094
+ var SKINS = ["default", "retro-irc-1990", "terminal", "minimal-dark", "minimal-light"];
2095
+ var embed_create_input = z14.object({
2096
+ channel: z14.string().min(1).max(128).regex(/^[A-Za-z0-9_-]+$/).describe("The mIRC channel id everyone on the embed shares (e.g. 'acme-support'). Auto-created on first message if new."),
2097
+ allowed_origins: z14.array(z14.string().min(1)).min(1).max(10).describe("REQUIRED. Domain(s) where the widget will be served \u2014 the key only works from these origins. Use the host(s) of the app you're building, e.g. ['app.acme.com','*.acme.com']. For local testing use mode:'test' and e.g. 'localhost:3000'."),
2098
+ name: z14.string().max(64).optional().describe("Label for the key in the owner's dashboard. Default 'embed: <channel>'."),
2099
+ position: z14.enum(POSITIONS).optional().describe("Where the widget renders. Default 'inline'."),
2100
+ skin: z14.enum(SKINS).optional().describe("Visual skin. Default 'default' (mosadd-branded retro mIRC)."),
2101
+ title: z14.string().max(60).optional().describe("Header title shown in the widget. Default 'mIRC'."),
2102
+ anon: z14.boolean().optional().describe("Allow visitors to join with just a nick (no mosadd account). Default true."),
2103
+ locale: z14.enum(["en", "pl"]).optional().describe("Widget UI language. Default 'en'."),
2104
+ mode: z14.enum(["live", "test"]).optional().describe("Key mode \u2014 'test' for local/dev origins, 'live' for production. Default 'live'.")
2105
+ });
2106
+ var attrSafe = (s) => s.replace(/["'<>]/g, "");
2107
+ function buildSnippet(input, key) {
2108
+ const attrs = [`data-channel="${attrSafe(input.channel)}"`, `data-position="${input.position ?? "inline"}"`];
2109
+ if (input.skin) attrs.push(`data-skin="${input.skin}"`);
2110
+ if (input.title) attrs.push(`data-title="${attrSafe(input.title)}"`);
2111
+ if (input.anon === false) attrs.push(`data-anon="false"`);
2112
+ if (input.locale) attrs.push(`data-locale="${input.locale}"`);
2113
+ return `<div id="mosadd-mirc" ${attrs.join(" ")}></div>
2114
+ <script src="${EMBED_CDN}/v1.js" data-key="${key}"></script>`;
2115
+ }
2116
+ async function embed_create(input, ctx) {
2117
+ readSupabaseEnv();
2118
+ ctx.log("debug", "comms_embed_create minting embed key", { channel: input.channel, origins: input.allowed_origins.length });
2119
+ const res = await invokeFunction("embed-keys", {
2120
+ name: input.name ?? `embed: ${input.channel}`,
2121
+ channels: [input.channel],
2122
+ allowed_origins: input.allowed_origins,
2123
+ mode: input.mode ?? "live"
2124
+ });
2125
+ if (res.error) throw new Error(res.error);
2126
+ if (!res.key) throw new Error("embed-keys returned no publishable key (missing `key`).");
2127
+ return {
2128
+ embed_key: res.key,
2129
+ channel: input.channel,
2130
+ allowed_origins: input.allowed_origins,
2131
+ snippet: buildSnippet(input, res.key)
2132
+ };
2133
+ }
2134
+ var embedTools = [
2135
+ {
2136
+ name: "comms_embed_create",
2137
+ requires: "network",
2138
+ description: "Embed a LIVE mosadd chat channel into an app/site you're building (great for builder-agents on Lovable/Bolt/Cursor/v0). Mints a publishable embed key scoped to a channel + the app's domain(s) and returns a ready-to-paste HTML snippet (a <div> + <script src=embed.mosadd.com/v1.js data-key=\u2026>). Visitors of the host page chat in real time (anonymous nick or mosadd login). REQUIRES `allowed_origins` \u2014 the domain(s) the app is served from (the key only works there). The publishable key is browser-safe (mints only channel-scoped JWTs); your hub key never leaves the server. Returns { embed_key, channel, allowed_origins, snippet }.",
2139
+ inputSchema: embed_create_input,
2140
+ handler: embed_create
2141
+ }
2142
+ ];
2143
+
1974
2144
  // src/tools/murl.ts
1975
- import { z as z12 } from "zod";
2145
+ import { z as z15 } from "zod";
1976
2146
  var DEFAULT_EDGE_URL2 = "https://mosadd-edge.mr-brics-33.workers.dev";
1977
2147
  function edgeUrl2() {
1978
2148
  return process.env.MOSADD_EDGE_URL?.replace(/\/$/, "") ?? DEFAULT_EDGE_URL2;
1979
2149
  }
1980
- function hubKey2() {
2150
+ function hubKey3() {
1981
2151
  const key = process.env.MOSADD_API_KEY ?? process.env.MOSADD_HUB_KEY ?? "";
1982
2152
  if (!key) throw new Error("MOSADD_API_KEY required for mURL tools (see `mosadd login` / hub-keys).");
1983
2153
  return key;
1984
2154
  }
1985
- function domainToSlug(input) {
1986
- let host = String(input).trim().toLowerCase();
1987
- host = host.replace(/^[a-z]+:\/\//, "").replace(/[/?#].*$/, "").replace(/:\d+$/, "");
2155
+ function urlToSlug(input) {
2156
+ let s = String(input).trim().toLowerCase();
2157
+ s = s.replace(/^[a-z]+:\/\//, "").replace(/[?#].*$/, "");
2158
+ const slash = s.indexOf("/");
2159
+ let host = (slash >= 0 ? s.slice(0, slash) : s).replace(/:\d+$/, "");
1988
2160
  if (host.startsWith("www.")) host = host.slice(4);
1989
2161
  if (!host || !/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(host)) {
1990
- throw new Error(`Invalid domain: "${input}" \u2014 pass a domain like "example.com" or a URL.`);
2162
+ throw new Error(`Invalid URL: "${input}" \u2014 pass a domain like "example.com" or a full URL.`);
1991
2163
  }
1992
- return { domain: host, slug: host.replace(/\./g, "-") };
2164
+ const segs = (slash >= 0 ? s.slice(slash) : "").split("/").map((seg) => seg.replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "")).filter(Boolean);
2165
+ const base = host.replace(/\./g, "-");
2166
+ return { domain: host, slug: segs.length ? `${base}__${segs.join("__")}` : base };
1993
2167
  }
1994
- var DomainArg = z12.string().min(3).max(255).describe("A domain (e.g. 'example.com') or a full URL \u2014 the channel is keyed to the domain.");
1995
- var mURL_read_channel_input = z12.object({
2168
+ var DomainArg = z15.string().min(3).max(2048).describe("A domain ('example.com') or a full URL. Keyed PER-URL: a bare domain \u2192 the domain room; a URL with a path (e.g. 'site.com/articles/abc') \u2192 that page's own room.");
2169
+ var mURL_read_channel_input = z15.object({
1996
2170
  domain: DomainArg,
1997
- limit: z12.number().int().min(1).max(100).optional().describe("Recent messages to return (max 100). Default 50.")
2171
+ limit: z15.number().int().min(1).max(100).optional().describe("Recent messages to return (max 100). Default 50.")
1998
2172
  });
1999
2173
  async function mURL_read_channel(input, ctx) {
2000
- const { domain, slug: slug2 } = domainToSlug(input.domain);
2174
+ const { domain, slug: slug2 } = urlToSlug(input.domain);
2001
2175
  const limit = input.limit ?? 50;
2002
2176
  ctx.log("debug", "mURL_read_channel", { domain });
2003
2177
  const r = await fetch(`${edgeUrl2()}/c/${slug2}/history?limit=${limit}`, {
2004
- headers: { Authorization: `Bearer ${hubKey2()}` }
2178
+ headers: { Authorization: `Bearer ${hubKey3()}` }
2005
2179
  });
2006
2180
  if (!r.ok) {
2007
2181
  const e = await r.text().catch(() => "");
@@ -2013,17 +2187,17 @@ async function mURL_read_channel(input, ctx) {
2013
2187
  messages: (data.messages ?? []).map((m) => ({ id: m.id, from: m.from ?? null, text: m.text, timestamp: m.ts }))
2014
2188
  };
2015
2189
  }
2016
- var mURL_post_input = z12.object({
2190
+ var mURL_post_input = z15.object({
2017
2191
  domain: DomainArg,
2018
- text: z12.string().min(1).max(2e3).describe("Message body (max 2000 chars, up to 3 lines \u2014 Worker-enforced)."),
2019
- from: z12.string().max(120).optional().describe("Sender hint shown to others (defaults to the hub-key owner / your agent name).")
2192
+ text: z15.string().min(1).max(2e3).describe("Message body (max 2000 chars, up to 3 lines \u2014 Worker-enforced)."),
2193
+ from: z15.string().max(120).optional().describe("Sender hint shown to others (defaults to the hub-key owner / your agent name).")
2020
2194
  });
2021
2195
  async function mURL_post(input, ctx) {
2022
- const { domain, slug: slug2 } = domainToSlug(input.domain);
2196
+ const { domain, slug: slug2 } = urlToSlug(input.domain);
2023
2197
  ctx.log("debug", "mURL_post", { domain });
2024
2198
  const r = await fetch(`${edgeUrl2()}/c/${slug2}/send`, {
2025
2199
  method: "POST",
2026
- headers: { "Content-Type": "application/json", Authorization: `Bearer ${hubKey2()}` },
2200
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${hubKey3()}` },
2027
2201
  body: JSON.stringify({ text: input.text, from: input.from })
2028
2202
  });
2029
2203
  if (!r.ok) {
@@ -2034,12 +2208,12 @@ async function mURL_post(input, ctx) {
2034
2208
  if (!data?.id) throw new Error("mosadd-edge: send returned no id");
2035
2209
  return { domain, message_id: data.id, posted_at: data.ts ?? Date.now() };
2036
2210
  }
2037
- var mURL_list_channels_input = z12.object({
2038
- action: z12.enum(["trending", "list", "mine"]).optional().describe("'trending' (default) = most active domain channels in the last N hours; 'list' = paginated catalogue filtered by status; 'mine' = channels you own (DNS-verified)."),
2039
- limit: z12.number().int().min(1).max(100).optional().describe("Max channels to return. Default 20."),
2040
- hours: z12.number().int().min(1).max(168).optional().describe("Trending window in hours. Default 24, max 168 (7d)."),
2041
- status: z12.enum(["open", "claimed", "blocked"]).optional().describe("For action='list': filter (default 'open')."),
2042
- cursor: z12.string().optional().describe("For action='list': pagination \u2014 pass previous response's next_cursor (created_at ISO).")
2211
+ var mURL_list_channels_input = z15.object({
2212
+ action: z15.enum(["trending", "list", "mine"]).optional().describe("'trending' (default) = most active domain channels in the last N hours; 'list' = paginated catalogue filtered by status; 'mine' = channels you own (DNS-verified)."),
2213
+ limit: z15.number().int().min(1).max(100).optional().describe("Max channels to return. Default 20."),
2214
+ hours: z15.number().int().min(1).max(168).optional().describe("Trending window in hours. Default 24, max 168 (7d)."),
2215
+ status: z15.enum(["open", "claimed", "blocked"]).optional().describe("For action='list': filter (default 'open')."),
2216
+ cursor: z15.string().optional().describe("For action='list': pagination \u2014 pass previous response's next_cursor (created_at ISO).")
2043
2217
  });
2044
2218
  async function mURL_list_channels(input, ctx) {
2045
2219
  readSupabaseEnv();
@@ -2053,9 +2227,9 @@ async function mURL_list_channels(input, ctx) {
2053
2227
  cursor: input.cursor ?? null
2054
2228
  });
2055
2229
  }
2056
- var mURL_presence_input = z12.object({ domain: DomainArg });
2230
+ var mURL_presence_input = z15.object({ domain: DomainArg });
2057
2231
  async function mURL_presence(input, ctx) {
2058
- const { domain, slug: slug2 } = domainToSlug(input.domain);
2232
+ const { domain, slug: slug2 } = urlToSlug(input.domain);
2059
2233
  ctx.log("debug", "mURL_presence", { domain });
2060
2234
  const r = await fetch(`${edgeUrl2()}/c/${slug2}/presence`);
2061
2235
  if (!r.ok) {
@@ -2097,7 +2271,7 @@ var murlTools = [
2097
2271
  ];
2098
2272
 
2099
2273
  // src/tools/capabilities.ts
2100
- import { z as z13 } from "zod";
2274
+ import { z as z16 } from "zod";
2101
2275
  var CONTRACT_VERSION = "1.0.0";
2102
2276
  var ALL_REQUIREMENTS = ["any", "radio", "network"];
2103
2277
  function buildCapabilityManifest(tools) {
@@ -2120,7 +2294,7 @@ function makeCapabilitiesTool(channelTools2) {
2120
2294
  name: "comms_capabilities",
2121
2295
  requires: "any",
2122
2296
  description: "Discover which mosadd tools are available and what transport each requires (any | radio | network). Carrier-aware hosts (e.g. off-grid radio devices) call this once to gate the tool list to what the current carrier supports. Returns a manifest with per-tool requirements grouped by transport.",
2123
- inputSchema: z13.object({}),
2297
+ inputSchema: z16.object({}),
2124
2298
  handler: async () => buildCapabilityManifest([...channelTools2, tool])
2125
2299
  };
2126
2300
  return tool;
@@ -2140,18 +2314,21 @@ var channelTools = [
2140
2314
  // mAYL_*: canonical email module (was mp0st_*; renamed re-arch 2026-06-27)
2141
2315
  ...mailAliasTools,
2142
2316
  // mp0st_*: back-compat aliases — DEPRECATED, removed in alpha.27
2143
- // ...mailProvenanceTools, // mp0st_send_as_agent: SCAFFOLD — calls a non-existent hub-claim-mint
2317
+ ...mailProvenanceTools,
2318
+ // mAYL_send_as_agent: agent-attributed mail send via hub-claim-mint (LINEAR-3991)
2144
2319
  // endpoint (404s every call) + sends provenance body fields the EF never reads. Unregister until
2145
2320
  // rewired onto hub-key-exchange (agent_id/task_id + mosadd_hub JWT claim). See consistency ticket.
2146
2321
  ...mtalkTools,
2147
2322
  ...attachmentTools,
2148
- // ...pttIngestTools, // mTALK_ingest_ptt: SCAFFOLD — request body doesn't match the deployed
2323
+ ...pttIngestTools,
2324
+ // mTALK_ingest_ptt: P4.1 / LINEAR-3998 — body aligned to deployed ptt-ingest EF
2149
2325
  // ptt-ingest EF (needs {direction, audio_base64, mime_type, message_id|thread_id} → 400s every
2150
2326
  // call) and the PTT→RAG path needs rework. Unregister until both are fixed. See consistency ticket.
2151
2327
  ...knowledgeTools,
2152
2328
  ...actionTools,
2153
2329
  // Action links (Tier 1): agent → user one-link browser action via action-create EF
2154
- // ...embedTools, // comms_embed_create: SCAFFOLD — embed-keys EF undeployed (404) + embed widget parked. Unregistered.
2330
+ ...embedTools,
2331
+ // comms_embed_create: P5.1 / LINEAR-4002 — EFs live, widget at embed.mosadd.com awaits owner-deploy
2155
2332
  // ...threatTools, // UNREGISTERED 2026-06-27 — killed direction; source kept for archival
2156
2333
  ...murlTools
2157
2334
  // mURL: revived as a full module (founder 2026-06-27) — read/post/presence/list_channels over live domain channels
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  createMosaddServer,
4
4
  defaultProviders,
5
5
  runWithSupabaseEnv
6
- } from "./chunk-EJQT6FXI.js";
6
+ } from "./chunk-YBSQUORF.js";
7
7
  import "./chunk-Z7WR52GE.js";
8
8
  export {
9
9
  allTools,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mosadd/mcp",
3
- "version": "3.0.0-alpha.25",
3
+ "version": "3.0.0-alpha.26",
4
4
  "mcpName": "io.github.hei33enberg/mosadd-mcp",
5
5
  "description": "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions — 74 tools (mp0st_* aliases through alpha.26) — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
6
6
  "homepage": "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
@@ -38,10 +38,10 @@
38
38
  "@modelcontextprotocol/sdk": "^1.0.4",
39
39
  "@supabase/supabase-js": "^2.48.0",
40
40
  "zod": "^4.3.6",
41
- "@mosadd/protocol": "3.0.0-alpha.25",
42
- "@mosadd/crypto": "3.0.0-alpha.25",
43
- "@mosadd/providers": "3.0.0-alpha.25",
44
- "@mosadd/threat-engine": "3.0.0-alpha.25"
41
+ "@mosadd/crypto": "3.0.0-alpha.26",
42
+ "@mosadd/threat-engine": "3.0.0-alpha.26",
43
+ "@mosadd/protocol": "3.0.0-alpha.26",
44
+ "@mosadd/providers": "3.0.0-alpha.26"
45
45
  },
46
46
  "devDependencies": {
47
47
  "tsup": "^8.3.5",
@@ -36,16 +36,15 @@ import { mircEdgeTools } from "./mirc-edge.js";
36
36
  // import { mroomMessagesTools } from "./mroom-messages.js"; // mROOM: killed (LINEAR-3414) — not registered
37
37
  import { mailTools } from "./mail.js";
38
38
  import { mailAliasTools } from "./mail-aliases.js"; // mp0st_* back-compat aliases for mAYL_*
39
+ import { mailProvenanceTools } from "./mail-provenance.js"; // mAYL_send_as_agent — LINEAR-3991
39
40
  // import { mailProvenanceTools } from "./mail-provenance.js"; // scaffold (mp0st_send_as_agent) — not registered, see below
40
41
  import { mtalkTools } from "./mtalk.js";
41
42
  import { attachmentTools } from "./attachments.js";
42
- // import { pttIngestTools } from "./ptt-ingest.js"; // scaffold (mTALK_ingest_ptt) — not registered, see below
43
+ import { pttIngestTools } from "./ptt-ingest.js"; // P4.1 / LINEAR-3998 — body aligned to deployed ptt-ingest EF
43
44
  // import { mcallTools } from "./mcall.js"; // mCALL: carrier-pending — not registered (see header note)
44
45
  import { knowledgeTools } from "./knowledge.js";
45
46
  import { actionTools } from "./actions.js";
46
- // import { embedTools } from "./embed.js"; // comms_embed_create: SCAFFOLD — its
47
- // embed-keys EF is NOT deployed to prod (404s every call) and the embed.mosadd.com
48
- // widget surface is parked. Unregister until both ship. See consistency ticket.
47
+ import { embedTools } from "./embed.js"; // P5.1 / LINEAR-4002 — embed-keys + mirc-embed-token deployed to prod 2026-06-27. Widget at embed.mosadd.com still owner-deploy (separate Vercel project).
49
48
  // import { threatTools } from "./threat.js"; // threat_*: UNREGISTERED 2026-06-27 (re-arch). Surveillance-era direction killed; source kept for archival.
50
49
  import { murlTools } from "./murl.js"; // mURL: REGISTERED — revived as a full dev module (founder 2026-06-27, re-arch). IRC-for-URLs, agent-native; backends live (mosadd-edge + murl-channels EF).
51
50
  import { makeCapabilitiesTool } from "./capabilities.js";
@@ -62,17 +61,17 @@ const channelTools: MosaddTool[] = [
62
61
  // ...mroomMessagesTools, // mROOM: killed (LINEAR-3414)
63
62
  ...mailTools, // mAYL_*: canonical email module (was mp0st_*; renamed re-arch 2026-06-27)
64
63
  ...mailAliasTools, // mp0st_*: back-compat aliases — DEPRECATED, removed in alpha.27
65
- // ...mailProvenanceTools, // mp0st_send_as_agent: SCAFFOLD — calls a non-existent hub-claim-mint
64
+ ...mailProvenanceTools, // mAYL_send_as_agent: agent-attributed mail send via hub-claim-mint (LINEAR-3991)
66
65
  // endpoint (404s every call) + sends provenance body fields the EF never reads. Unregister until
67
66
  // rewired onto hub-key-exchange (agent_id/task_id + mosadd_hub JWT claim). See consistency ticket.
68
67
  ...mtalkTools,
69
68
  ...attachmentTools,
70
- // ...pttIngestTools, // mTALK_ingest_ptt: SCAFFOLD — request body doesn't match the deployed
69
+ ...pttIngestTools, // mTALK_ingest_ptt: P4.1 / LINEAR-3998 — body aligned to deployed ptt-ingest EF
71
70
  // ptt-ingest EF (needs {direction, audio_base64, mime_type, message_id|thread_id} → 400s every
72
71
  // call) and the PTT→RAG path needs rework. Unregister until both are fixed. See consistency ticket.
73
72
  ...knowledgeTools,
74
73
  ...actionTools, // Action links (Tier 1): agent → user one-link browser action via action-create EF
75
- // ...embedTools, // comms_embed_create: SCAFFOLD — embed-keys EF undeployed (404) + embed widget parked. Unregistered.
74
+ ...embedTools, // comms_embed_create: P5.1 / LINEAR-4002 — EFs live, widget at embed.mosadd.com awaits owner-deploy
76
75
  // ...threatTools, // UNREGISTERED 2026-06-27 — killed direction; source kept for archival
77
76
  ...murlTools, // mURL: revived as a full module (founder 2026-06-27) — read/post/presence/list_channels over live domain channels
78
77
  // ...mcallTools, // mCALL: carrier-pending (no telephony carrier live) — re-register when a carrier is configured
@@ -62,53 +62,51 @@ const mp0st_send_as_agent_input = z.object({
62
62
  });
63
63
 
64
64
  /**
65
- * Exchange the hub key for a hub-claim JWT that authorizes agent-attributed
66
- * actions. TODO(Lane A): confirm endpoint + response. Mirrors the
67
- * hub-mint-channel-token pattern in mirc-edge.ts.
65
+ * Exchange the hub key for an HS256 hub-claim JWT that authorizes agent-attributed
66
+ * mail sends. The `mp0st-send` EF verifies this token with HUB_JWT_SECRET and reads
67
+ * `agent_id` + `task_id` from its claims authoritatively (body fields are NOT trusted
68
+ * for provenance). LINEAR-3991.
68
69
  */
69
70
  async function mintHubClaim(agentId: string, taskId?: string): Promise<string> {
70
71
  const key = hubKey();
71
72
  if (!key) {
72
- throw new Error("mp0st_send_as_agent needs MOSADD_API_KEY (hub key) to mint a provenance claim.");
73
+ throw new Error("mAYL_send_as_agent needs MOSADD_API_KEY (hub key) to mint a provenance claim.");
73
74
  }
74
75
  const r = await fetch(`${supabaseUrl()}/functions/v1/hub-claim-mint`, {
75
76
  method: "POST",
76
77
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
77
- body: JSON.stringify({ scope: "mail:send", agent_id: agentId, task_id: taskId ?? null }),
78
+ body: JSON.stringify({ agent_id: agentId, task_id: taskId ?? null }),
78
79
  });
79
80
  if (!r.ok) {
80
81
  const b = await r.text().catch(() => "");
81
82
  throw new Error(`hub-claim-mint ${r.status}: ${b.slice(0, 200)}`);
82
83
  }
83
- const data = (await r.json()) as { token?: string };
84
- if (!data?.token) throw new Error("hub-claim-mint: no token in response");
85
- return data.token;
84
+ const data = (await r.json()) as { access_token?: string };
85
+ if (!data?.access_token) throw new Error("hub-claim-mint: no access_token in response");
86
+ return data.access_token;
86
87
  }
87
88
 
88
- async function mp0st_send_as_agent(
89
+ async function mAYL_send_as_agent(
89
90
  input: z.infer<typeof mp0st_send_as_agent_input>,
90
91
  ctx: MosaddToolContext,
91
92
  ): Promise<{ message_id: string; status: string; is_internal: boolean; sent_by: "agent" }> {
92
93
  if (!input.body_text && !input.body_html) {
93
- throw new Error("mp0st_send_as_agent requires at least one of body_text or body_html.");
94
+ throw new Error("mAYL_send_as_agent requires at least one of body_text or body_html.");
94
95
  }
95
96
 
96
- // Present the hub-claim JWT directly to mp0st-send (NOT the user session client)
97
- // so the EF attributes the row to the agent. TODO(Lane A): confirm mp0st-send
98
- // accepts a Bearer hub-claim and reads sent_by_agent_id / sent_by_task_id.
97
+ // Mint the hub-claim JWT and present it directly to mp0st-send (NOT the user
98
+ // session client) so the EF attributes the row to the agent. mp0st-send verifies
99
+ // the HS256 signature with HUB_JWT_SECRET and stamps sent_by_agent_id /
100
+ // sent_by_task_id from the verified claims — body fields are NOT trusted for
101
+ // provenance.
99
102
  const claim = await mintHubClaim(input.agent_id, input.task_id);
100
- ctx.log("debug", "mp0st_send_as_agent invoking mp0st-send with hub-claim", { agent_id: input.agent_id });
103
+ ctx.log("debug", "mAYL_send_as_agent invoking mp0st-send with hub-claim", { agent_id: input.agent_id });
101
104
 
102
- const { agent_id, task_id, ...mailFields } = input;
105
+ const { agent_id: _ai, task_id: _ti, ...mailFields } = input;
103
106
  const r = await fetch(`${supabaseUrl()}/functions/v1/mp0st-send`, {
104
107
  method: "POST",
105
108
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${claim}` },
106
- body: JSON.stringify({
107
- ...mailFields,
108
- sent_by: "agent",
109
- sent_by_agent_id: agent_id,
110
- sent_by_task_id: task_id ?? null,
111
- }),
109
+ body: JSON.stringify(mailFields),
112
110
  });
113
111
  if (!r.ok) {
114
112
  const b = await r.text().catch(() => "");
@@ -127,11 +125,11 @@ async function mp0st_send_as_agent(
127
125
 
128
126
  export const mailProvenanceTools: MosaddTool[] = [
129
127
  {
130
- name: "mp0st_send_as_agent",
128
+ name: "mAYL_send_as_agent",
131
129
  requires: "network",
132
130
  description:
133
- "Send an email ATTRIBUTED TO THE AGENT (provenance-stamped). Unlike mp0st_send (sends as the user), this stamps sent_by='agent' plus your agent_id and optional task_id onto the email record and audit trail — so recipients and compliance can see the mail was agent-originated. Auth: presents a hub-claim JWT (needs MOSADD_API_KEY). SCAFFOLD: depends on mp0st-send honoring the hub-claim + provenance fields (TODO Lane A).",
131
+ "Send an email ATTRIBUTED TO THE AGENT (provenance-stamped). Unlike mAYL_send (sends as the user), this stamps sent_by='agent' plus your agent_id and optional task_id onto the email record and audit trail — so recipients and compliance can see the mail was agent-originated. Auth: presents a hub-claim JWT (needs MOSADD_API_KEY). The mp0st-send EF verifies the claim with HUB_JWT_SECRET; body trust is never granted for provenance.",
134
132
  inputSchema: mp0st_send_as_agent_input,
135
- handler: mp0st_send_as_agent as MosaddTool["handler"],
133
+ handler: mAYL_send_as_agent as MosaddTool["handler"],
136
134
  },
137
135
  ];
package/src/tools/murl.ts CHANGED
@@ -2,8 +2,10 @@
2
2
  * mURL — IRC-for-URLs: real-time chat attached to any web DOMAIN, AGENT-NATIVE.
3
3
  *
4
4
  * Same mosadd-edge Cloudflare Worker / Durable Object backend as mIRC edge, but the
5
- * channel id is the DOMAIN SLUG (domain lowercased, "." → "-"). A domain channel is
6
- * auto-created on first activity (status "open"); a domain owner can later verify/claim it.
5
+ * channel id is the URL SLUG: host("."→"-") + path("/"→"__") (RFC-0004). A bare domain
6
+ * → the domain room; a full URL with a path → a per-PAGE room (the per-article ask).
7
+ * Auto-created on first activity (status "open"); the domain owner can verify/claim the
8
+ * whole domain (a domain block covers all its page rooms).
7
9
  *
8
10
  * THE WEDGE: every prior "chat on a web page" (Google Sidewiki, Genius, Hypothes.is,
9
11
  * HERE.fm) died on the empty-room cold-start because they were HUMAN-ONLY — you arrive,
@@ -28,22 +30,34 @@ function hubKey(): string {
28
30
  return key;
29
31
  }
30
32
 
31
- /** A domain OR full URL → { domain, slug }. slug = host lowercased, "." → "-". */
32
- function domainToSlug(input: string): { domain: string; slug: string } {
33
- let host = String(input).trim().toLowerCase();
34
- host = host.replace(/^[a-z]+:\/\//, "").replace(/[/?#].*$/, "").replace(/:\d+$/, "");
33
+ /** A domain OR full URL → { domain, slug }. mURL is keyed PER-URL (RFC-0004):
34
+ * slug = host("."→"-") + each path segment ("/"→"__"); scheme, query, fragment and
35
+ * trailing slash are stripped and segments are sanitised to [a-z0-9-]. A bare domain
36
+ * (no path) yields the DOMAIN room (back-compat); a URL with a path yields a PER-PAGE
37
+ * room. `domain` (host only) is returned for status/branding — a domain block covers
38
+ * every page room under it. */
39
+ function urlToSlug(input: string): { domain: string; slug: string } {
40
+ let s = String(input).trim().toLowerCase();
41
+ s = s.replace(/^[a-z]+:\/\//, "").replace(/[?#].*$/, ""); // strip scheme + query + fragment
42
+ const slash = s.indexOf("/");
43
+ let host = (slash >= 0 ? s.slice(0, slash) : s).replace(/:\d+$/, "");
35
44
  if (host.startsWith("www.")) host = host.slice(4);
36
45
  if (!host || !/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(host)) {
37
- throw new Error(`Invalid domain: "${input}" — pass a domain like "example.com" or a URL.`);
46
+ throw new Error(`Invalid URL: "${input}" — pass a domain like "example.com" or a full URL.`);
38
47
  }
39
- return { domain: host, slug: host.replace(/\./g, "-") };
48
+ const segs = (slash >= 0 ? s.slice(slash) : "")
49
+ .split("/")
50
+ .map((seg) => seg.replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, ""))
51
+ .filter(Boolean);
52
+ const base = host.replace(/\./g, "-");
53
+ return { domain: host, slug: segs.length ? `${base}__${segs.join("__")}` : base };
40
54
  }
41
55
 
42
56
  const DomainArg = z
43
57
  .string()
44
58
  .min(3)
45
- .max(255)
46
- .describe("A domain (e.g. 'example.com') or a full URL — the channel is keyed to the domain.");
59
+ .max(2048)
60
+ .describe("A domain ('example.com') or a full URL. Keyed PER-URL: a bare domain → the domain room; a URL with a path (e.g. 'site.com/articles/abc') → that page's own room.");
47
61
 
48
62
  // ── read ──────────────────────────────────────────────────────────────────────
49
63
  const mURL_read_channel_input = z.object({
@@ -54,7 +68,7 @@ async function mURL_read_channel(
54
68
  input: z.infer<typeof mURL_read_channel_input>,
55
69
  ctx: MosaddToolContext,
56
70
  ): Promise<{ domain: string; messages: Array<{ id: string; from: string | null; text: string; timestamp: number }> }> {
57
- const { domain, slug } = domainToSlug(input.domain);
71
+ const { domain, slug } = urlToSlug(input.domain);
58
72
  const limit = input.limit ?? 50;
59
73
  ctx.log("debug", "mURL_read_channel", { domain });
60
74
  const r = await fetch(`${edgeUrl()}/c/${slug}/history?limit=${limit}`, {
@@ -81,7 +95,7 @@ async function mURL_post(
81
95
  input: z.infer<typeof mURL_post_input>,
82
96
  ctx: MosaddToolContext,
83
97
  ): Promise<{ domain: string; message_id: string; posted_at: number }> {
84
- const { domain, slug } = domainToSlug(input.domain);
98
+ const { domain, slug } = urlToSlug(input.domain);
85
99
  ctx.log("debug", "mURL_post", { domain });
86
100
  const r = await fetch(`${edgeUrl()}/c/${slug}/send`, {
87
101
  method: "POST",
@@ -148,7 +162,7 @@ async function mURL_presence(
148
162
  input: z.infer<typeof mURL_presence_input>,
149
163
  ctx: MosaddToolContext,
150
164
  ): Promise<{ domain: string; count: number; roster: string[]; status: string }> {
151
- const { domain, slug } = domainToSlug(input.domain);
165
+ const { domain, slug } = urlToSlug(input.domain);
152
166
  ctx.log("debug", "mURL_presence", { domain });
153
167
  const r = await fetch(`${edgeUrl()}/c/${slug}/presence`);
154
168
  if (!r.ok) {
@@ -1,82 +1,87 @@
1
1
  /**
2
- * PTT capture → ingest → RAG transcription.
2
+ * mTALK_ingest_ptt — submit a recorded PTT "over" for transcription + RAG ingest.
3
3
  *
4
- * mTALK (mtalk.ts) drives the live half-duplex FLOOR (who may transmit). What it
5
- * does NOT do is capture a finished PTT transmission as a durable, queued message
6
- * — i.e. a recorded "over" that lands in a channel's queued-PTT log AND (opt-in)
7
- * gets transcribed into RAG. That's this module.
4
+ * The actual mIRC/mDM voice-message PERSISTENCE (writing a message_meta row,
5
+ * fanning it out to listeners) is owned by the message-send/send-voice path,
6
+ * NOT by this tool. ptt-ingest exists purely to bridge a finished PTT segment
7
+ * into the user's RAG index — a row in `ptt_transcripts` (status='pending')
8
+ * + a transcribe job that lands in `user_embeddings(source_type='ptt')`.
8
9
  *
9
- * Flow (per the Lane A contract):
10
- * 1. agent records/has a PTT clip → base64 → uploadBlob(kind:'ptt') to
11
- * 'voice-blobs'.
12
- * 2. call `ptt-ingest` EF with the attachment descriptor + routing (which
13
- * channel/room the "over" belongs to). The EF persists a queued-PTT message.
14
- * 3. if the user has opted in to RAG, `rag-transcribe` runs and the transcript
15
- * lands in user_embeddings(source_type='ptt').
10
+ * Use this when an agent has a PTT audio buffer it wants searchable in the
11
+ * user's RAG later (e.g. "what did Alice tell me on PTT yesterday?"). The
12
+ * voice message itself is sent separately via mDM_send_voice / mIRC_send_voice.
16
13
  *
17
- * STATUS: scaffold — `ptt-ingest` is not yet deployed. Upload is real; the EF
18
- * call shape is best-guess (TODO Lane A).
14
+ * Auth: standard Supabase session JWT (the caller's RAG opt-in is read from
15
+ * their account; opted-out callers get status='skipped_optout').
16
+ * LINEAR-3998 (P4.1 PTT unify) — re-arch 2026-06-27.
19
17
  */
20
-
21
18
  import { z } from "zod";
22
19
  import type { MosaddTool, MosaddToolContext } from "../types.js";
23
20
  import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
24
- import { uploadBlob, decodeBase64Body } from "../providers/blob-upload.js";
25
21
 
26
22
  const mTALK_ingest_ptt_input = z.object({
27
23
  audio_base64: z
28
24
  .string()
29
25
  .min(1)
30
26
  .max(20_000_000)
31
- .describe("Recorded PTT 'over' as base64 (or data: URL)."),
32
- mime: z.string().min(1).max(120).default("audio/ogg"),
33
- duration_ms: z.number().int().positive().optional(),
34
- // Routing: exactly one of room_id / channel_id identifies where the over lands.
35
- channel_id: z.string().optional().describe("mIRC channel id — route the queued PTT into the channel's PTT log."),
36
- // room_id retained for the rare mTALK-only PTT room (no mIRC channel backing). mROOM is gone — do NOT pass an mROOM id (will 404). Prefer channel_id.
37
- room_id: z.string().optional().describe("Optional mTALK-only PTT room id (no mIRC channel backing). For mIRC channels use channel_id."),
38
- transcribe: z
39
- .boolean()
27
+ .describe("Recorded PTT 'over' as base64 (a 'data:audio/…;base64,…' prefix is stripped if present)."),
28
+ mime_type: z
29
+ .string()
30
+ .min(1)
31
+ .max(120)
32
+ .default("audio/webm")
33
+ .describe("MIME type of the audio. Default audio/webm (browser MediaRecorder default)."),
34
+ direction: z
35
+ .enum(["human_to_agent", "agent_to_human"])
36
+ .describe("Direction the PTT crossed: who originated, who received. 'human_to_agent' = user spoke to an agent; 'agent_to_human' = agent spoke to the user."),
37
+ message_id: z
38
+ .string()
39
+ .min(1)
40
+ .max(120)
40
41
  .optional()
41
- .describe("Request RAG transcription. Honored only if the user has opted in to rag ingest; ignored otherwise. Default true."),
42
+ .describe("Optional id of the messages_meta row this PTT belongs to. When present, links the transcript back to the message for jump-to-source from RAG."),
43
+ thread_id: z
44
+ .string()
45
+ .min(1)
46
+ .max(120)
47
+ .optional()
48
+ .describe("Optional thread id (e.g. `chat:<channel_id>` or `dm:<a>:<b>`) so the transcript carries its conversational scope into RAG."),
42
49
  });
43
50
 
51
+ interface PttIngestResponse {
52
+ ptt_id?: string;
53
+ status?: "pending" | "skipped_optout" | "queued";
54
+ enqueued?: boolean;
55
+ }
56
+
44
57
  async function mTALK_ingest_ptt(
45
58
  input: z.infer<typeof mTALK_ingest_ptt_input>,
46
59
  ctx: MosaddToolContext,
47
- ): Promise<{ ptt_id: string; queued: true; transcription: "queued" | "skipped" | "opted_out" }> {
60
+ ): Promise<{ ptt_id: string; status: string; opted_in: boolean }> {
48
61
  readSupabaseEnv();
49
- if (!input.channel_id && !input.room_id) {
50
- throw new Error("mTALK_ingest_ptt requires one of channel_id or room_id to route the queued PTT.");
51
- }
52
- const prefix = input.channel_id ? `chat:${input.channel_id}` : `room:${input.room_id}`;
53
- const attachment = await uploadBlob({
54
- kind: "ptt",
55
- bytes: decodeBase64Body(input.audio_base64),
56
- mime: input.mime,
57
- prefix,
58
- duration_ms: input.duration_ms,
59
- });
60
62
 
61
- ctx.log("debug", "mTALK_ingest_ptt invoking ptt-ingest", { prefix, transcribe: input.transcribe ?? true });
63
+ // Tolerate a "data:audio/…;base64,…" prefix from MediaRecorder/canvas captures.
64
+ const audio = input.audio_base64.replace(/^data:[^;]+;base64,/, "");
65
+
66
+ ctx.log("debug", "mTALK_ingest_ptt invoking ptt-ingest", {
67
+ direction: input.direction,
68
+ thread_id: input.thread_id ?? null,
69
+ mime_type: input.mime_type,
70
+ });
62
71
 
63
- // TODO(Lane A): `ptt-ingest` EF not yet deployed. Confirm request/response shape.
64
- // Expected: persists a queued-PTT message_meta row (message_type:'ptt') with the
65
- // attachment, then (if rag opt-in) enqueues rag-transcribe → user_embeddings(source_type='ptt').
66
- const res = await invokeFunction<{
67
- ptt_id?: string;
68
- transcription?: "queued" | "skipped" | "opted_out";
69
- }>("ptt-ingest", {
70
- attachment,
71
- channel_id: input.channel_id ?? null,
72
- room_id: input.room_id ?? null,
73
- transcribe: input.transcribe ?? true,
72
+ const res = await invokeFunction<PttIngestResponse>("ptt-ingest", {
73
+ audio_base64: audio,
74
+ mime_type: input.mime_type,
75
+ direction: input.direction,
76
+ message_id: input.message_id ?? null,
77
+ thread_id: input.thread_id ?? null,
74
78
  });
75
79
 
80
+ const status = res.status ?? "pending";
76
81
  return {
77
82
  ptt_id: res.ptt_id ?? "",
78
- queued: true,
79
- transcription: res.transcription ?? "queued",
83
+ status,
84
+ opted_in: status !== "skipped_optout",
80
85
  };
81
86
  }
82
87
 
@@ -85,7 +90,7 @@ export const pttIngestTools: MosaddTool[] = [
85
90
  name: "mTALK_ingest_ptt",
86
91
  requires: "network",
87
92
  description:
88
- "Capture a finished PTT transmission (an 'over') as a durable, QUEUED PTT message in an mIRC channel, and — if the user has opted in to RAG — transcribe it into searchable knowledge. Pass the clip as base64 + a route (channel_id; or room_id for an mTALK-only PTT room without a channel backing). Complements mTALK_press/release (which only manage the live floor).",
93
+ "Submit a finished PTT 'over' (push-to-talk audio segment) for transcription into the caller's RAG index — so 'what did X say on PTT?' is searchable later. The PERSISTENCE of the voice message itself (the message_meta row + fan-out) is handled by mDM_send_voice / mIRC_send_voice; this tool is the transcription bridge only. Honors per-user RAG opt-in: opted-out callers get status='skipped_optout' (no transcript stored). Auth: Supabase session JWT.",
89
94
  inputSchema: mTALK_ingest_ptt_input,
90
95
  handler: mTALK_ingest_ptt as MosaddTool["handler"],
91
96
  },