@muxoai/sdk 1.2.3 → 1.3.0

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.
Files changed (183) hide show
  1. package/.agents/plugins/marketplace.json +22 -0
  2. package/.claude-plugin/marketplace.json +17 -0
  3. package/.codex/config.toml +5 -0
  4. package/ARCHITECTURE.md +111 -0
  5. package/README.md +21 -12
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +894 -0
  8. package/dist/config.d.ts +20 -0
  9. package/dist/config.js +89 -0
  10. package/dist/engine.d.ts +156 -0
  11. package/dist/engine.js +876 -0
  12. package/dist/index.d.ts +7 -0
  13. package/dist/index.js +7 -0
  14. package/dist/mcp.d.ts +45 -0
  15. package/dist/mcp.js +914 -0
  16. package/dist/nl.d.ts +34 -0
  17. package/dist/nl.js +577 -0
  18. package/dist/providers/composio-instant.d.ts +14 -0
  19. package/dist/providers/composio-instant.js +814 -0
  20. package/dist/providers/composio-sdk.d.ts +41 -0
  21. package/dist/providers/composio-sdk.js +572 -0
  22. package/dist/providers/microsoft-governance.d.ts +66 -0
  23. package/dist/providers/microsoft-governance.js +415 -0
  24. package/dist/providers/stripe-billing.d.ts +41 -0
  25. package/dist/providers/stripe-billing.js +372 -0
  26. package/dist/providers/stripe-projects.d.ts +53 -0
  27. package/dist/providers/stripe-projects.js +636 -0
  28. package/dist/providers/supermemory.d.ts +64 -0
  29. package/dist/providers/supermemory.js +224 -0
  30. package/{index.d.ts → dist/sdk.d.ts} +77 -1
  31. package/dist/sdk.js +270 -0
  32. package/dist/server.d.ts +10 -0
  33. package/dist/server.js +1277 -0
  34. package/dist/store.d.ts +216 -0
  35. package/dist/store.js +1449 -0
  36. package/dist/types.d.ts +285 -0
  37. package/dist/types.js +1 -0
  38. package/dist/ui/console-html.d.ts +2 -0
  39. package/dist/ui/console-html.js +2343 -0
  40. package/package.json +66 -6
  41. package/plugins/muxo/.app.json +8 -0
  42. package/plugins/muxo/.claude-plugin/plugin.json +16 -0
  43. package/plugins/muxo/.codex-plugin/plugin.json +55 -0
  44. package/plugins/muxo/.mcp.json +40 -0
  45. package/plugins/muxo/assets/logo.png +0 -0
  46. package/plugins/muxo/assets/logo.svg +6 -0
  47. package/plugins/muxo/hooks/hooks.json +27 -0
  48. package/plugins/muxo/hooks/session-start.sh +85 -0
  49. package/plugins/muxo/hooks/user-prompt-submit.sh +45 -0
  50. package/plugins/muxo/mcp.json +38 -0
  51. package/plugins/muxo/plugin.json +59 -0
  52. package/plugins/muxo/skills/muxo/SKILL.md +25 -0
  53. package/plugins/muxo/skills/muxo/references/cli.md +57 -0
  54. package/plugins/muxo/skills/muxo/references/mcp.md +25 -0
  55. package/plugins/muxo/skills/setup/SKILL.md +28 -0
  56. package/src/catalogues/stripe-projects-catalog.json +9832 -0
  57. package/vendor/microsoft-governance/README.md +363 -0
  58. package/vendor/microsoft-governance/dist/audit.d.ts +26 -0
  59. package/vendor/microsoft-governance/dist/audit.d.ts.map +1 -0
  60. package/vendor/microsoft-governance/dist/audit.js +107 -0
  61. package/vendor/microsoft-governance/dist/audit.js.map +1 -0
  62. package/vendor/microsoft-governance/dist/cascade-containment.d.ts +84 -0
  63. package/vendor/microsoft-governance/dist/cascade-containment.d.ts.map +1 -0
  64. package/vendor/microsoft-governance/dist/cascade-containment.js +387 -0
  65. package/vendor/microsoft-governance/dist/cascade-containment.js.map +1 -0
  66. package/vendor/microsoft-governance/dist/client.d.ts +34 -0
  67. package/vendor/microsoft-governance/dist/client.d.ts.map +1 -0
  68. package/vendor/microsoft-governance/dist/client.js +112 -0
  69. package/vendor/microsoft-governance/dist/client.js.map +1 -0
  70. package/vendor/microsoft-governance/dist/context-poisoning.d.ts +58 -0
  71. package/vendor/microsoft-governance/dist/context-poisoning.d.ts.map +1 -0
  72. package/vendor/microsoft-governance/dist/context-poisoning.js +410 -0
  73. package/vendor/microsoft-governance/dist/context-poisoning.js.map +1 -0
  74. package/vendor/microsoft-governance/dist/credential-vault.d.ts +213 -0
  75. package/vendor/microsoft-governance/dist/credential-vault.d.ts.map +1 -0
  76. package/vendor/microsoft-governance/dist/credential-vault.js +567 -0
  77. package/vendor/microsoft-governance/dist/credential-vault.js.map +1 -0
  78. package/vendor/microsoft-governance/dist/discovery.d.ts +80 -0
  79. package/vendor/microsoft-governance/dist/discovery.d.ts.map +1 -0
  80. package/vendor/microsoft-governance/dist/discovery.js +404 -0
  81. package/vendor/microsoft-governance/dist/discovery.js.map +1 -0
  82. package/vendor/microsoft-governance/dist/encryption/channel.d.ts +29 -0
  83. package/vendor/microsoft-governance/dist/encryption/channel.d.ts.map +1 -0
  84. package/vendor/microsoft-governance/dist/encryption/channel.js +78 -0
  85. package/vendor/microsoft-governance/dist/encryption/channel.js.map +1 -0
  86. package/vendor/microsoft-governance/dist/encryption/index.d.ts +9 -0
  87. package/vendor/microsoft-governance/dist/encryption/index.d.ts.map +1 -0
  88. package/vendor/microsoft-governance/dist/encryption/index.js +23 -0
  89. package/vendor/microsoft-governance/dist/encryption/index.js.map +1 -0
  90. package/vendor/microsoft-governance/dist/encryption/mesh-client.d.ts +267 -0
  91. package/vendor/microsoft-governance/dist/encryption/mesh-client.d.ts.map +1 -0
  92. package/vendor/microsoft-governance/dist/encryption/mesh-client.js +1001 -0
  93. package/vendor/microsoft-governance/dist/encryption/mesh-client.js.map +1 -0
  94. package/vendor/microsoft-governance/dist/encryption/ratchet.d.ts +38 -0
  95. package/vendor/microsoft-governance/dist/encryption/ratchet.d.ts.map +1 -0
  96. package/vendor/microsoft-governance/dist/encryption/ratchet.js +223 -0
  97. package/vendor/microsoft-governance/dist/encryption/ratchet.js.map +1 -0
  98. package/vendor/microsoft-governance/dist/encryption/registry-client.d.ts +136 -0
  99. package/vendor/microsoft-governance/dist/encryption/registry-client.d.ts.map +1 -0
  100. package/vendor/microsoft-governance/dist/encryption/registry-client.js +369 -0
  101. package/vendor/microsoft-governance/dist/encryption/registry-client.js.map +1 -0
  102. package/vendor/microsoft-governance/dist/encryption/x3dh.d.ts +80 -0
  103. package/vendor/microsoft-governance/dist/encryption/x3dh.d.ts.map +1 -0
  104. package/vendor/microsoft-governance/dist/encryption/x3dh.js +238 -0
  105. package/vendor/microsoft-governance/dist/encryption/x3dh.js.map +1 -0
  106. package/vendor/microsoft-governance/dist/framework-adapter.d.ts +63 -0
  107. package/vendor/microsoft-governance/dist/framework-adapter.d.ts.map +1 -0
  108. package/vendor/microsoft-governance/dist/framework-adapter.js +253 -0
  109. package/vendor/microsoft-governance/dist/framework-adapter.js.map +1 -0
  110. package/vendor/microsoft-governance/dist/identity.d.ts +124 -0
  111. package/vendor/microsoft-governance/dist/identity.d.ts.map +1 -0
  112. package/vendor/microsoft-governance/dist/identity.js +446 -0
  113. package/vendor/microsoft-governance/dist/identity.js.map +1 -0
  114. package/vendor/microsoft-governance/dist/index.d.ts +39 -0
  115. package/vendor/microsoft-governance/dist/index.d.ts.map +1 -0
  116. package/vendor/microsoft-governance/dist/index.js +95 -0
  117. package/vendor/microsoft-governance/dist/index.js.map +1 -0
  118. package/vendor/microsoft-governance/dist/kill-switch.d.ts +22 -0
  119. package/vendor/microsoft-governance/dist/kill-switch.d.ts.map +1 -0
  120. package/vendor/microsoft-governance/dist/kill-switch.js +60 -0
  121. package/vendor/microsoft-governance/dist/kill-switch.js.map +1 -0
  122. package/vendor/microsoft-governance/dist/lifecycle.d.ts +50 -0
  123. package/vendor/microsoft-governance/dist/lifecycle.d.ts.map +1 -0
  124. package/vendor/microsoft-governance/dist/lifecycle.js +113 -0
  125. package/vendor/microsoft-governance/dist/lifecycle.js.map +1 -0
  126. package/vendor/microsoft-governance/dist/mcp.d.ts +41 -0
  127. package/vendor/microsoft-governance/dist/mcp.d.ts.map +1 -0
  128. package/vendor/microsoft-governance/dist/mcp.js +233 -0
  129. package/vendor/microsoft-governance/dist/mcp.js.map +1 -0
  130. package/vendor/microsoft-governance/dist/metrics.d.ts +123 -0
  131. package/vendor/microsoft-governance/dist/metrics.d.ts.map +1 -0
  132. package/vendor/microsoft-governance/dist/metrics.js +289 -0
  133. package/vendor/microsoft-governance/dist/metrics.js.map +1 -0
  134. package/vendor/microsoft-governance/dist/oci-manifest.d.ts +49 -0
  135. package/vendor/microsoft-governance/dist/oci-manifest.d.ts.map +1 -0
  136. package/vendor/microsoft-governance/dist/oci-manifest.js +182 -0
  137. package/vendor/microsoft-governance/dist/oci-manifest.js.map +1 -0
  138. package/vendor/microsoft-governance/dist/policy-backends/cedar.d.ts +15 -0
  139. package/vendor/microsoft-governance/dist/policy-backends/cedar.d.ts.map +1 -0
  140. package/vendor/microsoft-governance/dist/policy-backends/cedar.js +88 -0
  141. package/vendor/microsoft-governance/dist/policy-backends/cedar.js.map +1 -0
  142. package/vendor/microsoft-governance/dist/policy-backends/opa.d.ts +17 -0
  143. package/vendor/microsoft-governance/dist/policy-backends/opa.d.ts.map +1 -0
  144. package/vendor/microsoft-governance/dist/policy-backends/opa.js +74 -0
  145. package/vendor/microsoft-governance/dist/policy-backends/opa.js.map +1 -0
  146. package/vendor/microsoft-governance/dist/policy.d.ts +77 -0
  147. package/vendor/microsoft-governance/dist/policy.d.ts.map +1 -0
  148. package/vendor/microsoft-governance/dist/policy.js +760 -0
  149. package/vendor/microsoft-governance/dist/policy.js.map +1 -0
  150. package/vendor/microsoft-governance/dist/prompt-defense.d.ts +37 -0
  151. package/vendor/microsoft-governance/dist/prompt-defense.d.ts.map +1 -0
  152. package/vendor/microsoft-governance/dist/prompt-defense.js +229 -0
  153. package/vendor/microsoft-governance/dist/prompt-defense.js.map +1 -0
  154. package/vendor/microsoft-governance/dist/protocol-facets.d.ts +87 -0
  155. package/vendor/microsoft-governance/dist/protocol-facets.d.ts.map +1 -0
  156. package/vendor/microsoft-governance/dist/protocol-facets.js +728 -0
  157. package/vendor/microsoft-governance/dist/protocol-facets.js.map +1 -0
  158. package/vendor/microsoft-governance/dist/rings.d.ts +17 -0
  159. package/vendor/microsoft-governance/dist/rings.d.ts.map +1 -0
  160. package/vendor/microsoft-governance/dist/rings.js +61 -0
  161. package/vendor/microsoft-governance/dist/rings.js.map +1 -0
  162. package/vendor/microsoft-governance/dist/sandbox.d.ts +61 -0
  163. package/vendor/microsoft-governance/dist/sandbox.d.ts.map +1 -0
  164. package/vendor/microsoft-governance/dist/sandbox.js +199 -0
  165. package/vendor/microsoft-governance/dist/sandbox.js.map +1 -0
  166. package/vendor/microsoft-governance/dist/surface-parity.d.ts +45 -0
  167. package/vendor/microsoft-governance/dist/surface-parity.d.ts.map +1 -0
  168. package/vendor/microsoft-governance/dist/surface-parity.js +216 -0
  169. package/vendor/microsoft-governance/dist/surface-parity.js.map +1 -0
  170. package/vendor/microsoft-governance/dist/trust.d.ts +28 -0
  171. package/vendor/microsoft-governance/dist/trust.d.ts.map +1 -0
  172. package/vendor/microsoft-governance/dist/trust.js +209 -0
  173. package/vendor/microsoft-governance/dist/trust.js.map +1 -0
  174. package/vendor/microsoft-governance/dist/types.d.ts +422 -0
  175. package/vendor/microsoft-governance/dist/types.d.ts.map +1 -0
  176. package/vendor/microsoft-governance/dist/types.js +29 -0
  177. package/vendor/microsoft-governance/dist/types.js.map +1 -0
  178. package/vendor/microsoft-governance/dist/verify.d.ts +135 -0
  179. package/vendor/microsoft-governance/dist/verify.d.ts.map +1 -0
  180. package/vendor/microsoft-governance/dist/verify.js +356 -0
  181. package/vendor/microsoft-governance/dist/verify.js.map +1 -0
  182. package/vendor/microsoft-governance/package.json +64 -0
  183. package/index.js +0 -1
package/dist/nl.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import type { ToolDescriptor } from "./types.js";
2
+ export interface NaturalLanguageResolution {
3
+ resolved: boolean;
4
+ tool: ToolDescriptor | null;
5
+ toolSlug: string | null;
6
+ input: Record<string, unknown>;
7
+ extractedInput: Record<string, unknown>;
8
+ reason: string;
9
+ confidence: number;
10
+ resolutionMethod: "exact_slug" | "byok_llm" | "semantic_router";
11
+ byokUsed: string | null;
12
+ humanSummary: string;
13
+ missingInputs: string[];
14
+ needsConnection: boolean;
15
+ suggestedByokProvider: string | null;
16
+ alternatives: Array<{
17
+ slug: string;
18
+ name: string;
19
+ riskLevel: string;
20
+ creditCost: number;
21
+ }>;
22
+ }
23
+ export declare function extractParametersFromNaturalLanguage(prompt: string, tool: ToolDescriptor, explicitInput?: Record<string, unknown>): {
24
+ input: Record<string, unknown>;
25
+ missingInputs: string[];
26
+ };
27
+ export declare function resolveNaturalLanguageIntent(params: {
28
+ prompt: string;
29
+ tools: ToolDescriptor[];
30
+ explicitInput?: Record<string, unknown>;
31
+ byokKeys?: Record<string, string>;
32
+ activeConnectionProviders?: Set<string>;
33
+ preferByokLlm?: boolean;
34
+ }): Promise<NaturalLanguageResolution>;
package/dist/nl.js ADDED
@@ -0,0 +1,577 @@
1
+ function extractUrlFromText(text) {
2
+ const fullMatch = text.match(/https?:\/\/[^\s"'<>]+/i);
3
+ if (fullMatch) {
4
+ return fullMatch[0].replace(/[.,;!?)]+$/, "");
5
+ }
6
+ const domainMatch = text.match(/\b((?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+(?:ai|com|io|dev|org|net|app|co|xyz)(?:\/[^\s"'<>]*)?)\b/i);
7
+ if (domainMatch && !text.includes(`@${domainMatch[1]}`)) {
8
+ return `https://${domainMatch[1].replace(/[.,;!?)]+$/, "")}`;
9
+ }
10
+ return null;
11
+ }
12
+ function extractEmailFromText(text) {
13
+ const m = text.match(/\b([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})\b/);
14
+ return m ? m[1] : null;
15
+ }
16
+ function extractNumberAfterKeyword(text, keywords, fallback) {
17
+ for (const kw of keywords) {
18
+ const reAfter = new RegExp(`\\b${kw}\\s+(?:of\\s+|to\\s+|=\\s*)?(\\d[\\d,]*)`, "i");
19
+ const m1 = text.match(reAfter);
20
+ if (m1) {
21
+ const n = Number(m1[1].replace(/,/g, ""));
22
+ if (!Number.isNaN(n) && n > 0)
23
+ return n;
24
+ }
25
+ const reBefore = new RegExp(`(\\d[\\d,]*)\\s+${kw}\\b`, "i");
26
+ const m2 = text.match(reBefore);
27
+ if (m2) {
28
+ const n = Number(m2[1].replace(/,/g, ""));
29
+ if (!Number.isNaN(n) && n > 0)
30
+ return n;
31
+ }
32
+ }
33
+ return fallback;
34
+ }
35
+ export function extractParametersFromNaturalLanguage(prompt, tool, explicitInput) {
36
+ const input = { ...(explicitInput || {}) };
37
+ const slug = tool.slug;
38
+ const text = prompt.trim();
39
+ if (slug === "instant.seo.audit") {
40
+ if (!input.url) {
41
+ const url = extractUrlFromText(text);
42
+ if (url)
43
+ input.url = url;
44
+ }
45
+ if (input.checkBrokenLinks === undefined) {
46
+ input.checkBrokenLinks = !/\b(skip|no)\s+broken\s+links\b/i.test(text);
47
+ }
48
+ }
49
+ else if (slug === "instant.web.crawl") {
50
+ if (!input.url) {
51
+ const url = extractUrlFromText(text);
52
+ if (url)
53
+ input.url = url;
54
+ }
55
+ if (input.maxPages === undefined) {
56
+ input.maxPages = extractNumberAfterKeyword(text, ["maxPages", "pages", "limit"], 5);
57
+ }
58
+ if (input.maxDepth === undefined) {
59
+ input.maxDepth = extractNumberAfterKeyword(text, ["maxDepth", "depth"], 2);
60
+ }
61
+ }
62
+ else if (slug === "instant.web.scrape") {
63
+ if (!input.url) {
64
+ const url = extractUrlFromText(text);
65
+ if (url)
66
+ input.url = url;
67
+ }
68
+ if (!input.formats) {
69
+ input.formats = ["markdown"];
70
+ }
71
+ }
72
+ else if (slug === "instant.web.search") {
73
+ if (!input.query) {
74
+ const cleaned = text
75
+ .replace(/^(?:please\s+)?(?:can\s+you\s+)?(?:search\s+(?:the\s+)?web\s+(?:for|about)|search\s+(?:for|about)|find\s+(?:info|information|articles)\s+(?:on|about|for)|google|lookup|look\s+up)\s+/i, "")
76
+ .trim();
77
+ input.query = cleaned || text;
78
+ }
79
+ if (input.numResults === undefined) {
80
+ input.numResults = extractNumberAfterKeyword(text, ["results", "limit", "top"], 5);
81
+ }
82
+ }
83
+ else if (slug === "instant.code.execute") {
84
+ if (!input.language) {
85
+ input.language = /\b(javascript|js|node|typescript|ts)\b/i.test(text)
86
+ ? "javascript"
87
+ : "python";
88
+ }
89
+ if (!input.code) {
90
+ const codeBlock = text.match(/```(?:\w+)?\n([\s\S]*?)```/);
91
+ if (codeBlock) {
92
+ input.code = codeBlock[1].trim();
93
+ }
94
+ else {
95
+ const inlineCode = text.match(/`([^`]+)`/);
96
+ if (inlineCode)
97
+ input.code = inlineCode[1].trim();
98
+ }
99
+ }
100
+ }
101
+ else if (slug.startsWith("resource.")) {
102
+ if (!input.resource_name && !input.name) {
103
+ const namedMatch = text.match(/\b(?:named|called|name|resource)\s+["']?([a-zA-Z0-9_-]+)["']?/i);
104
+ const defaultPrefix = slug.split(".")[1] || "app";
105
+ const resolvedName = namedMatch ? namedMatch[1] : `${defaultPrefix}-main`;
106
+ input.resource_name = resolvedName;
107
+ }
108
+ else if (input.name && !input.resource_name) {
109
+ input.resource_name = input.name;
110
+ }
111
+ }
112
+ else if (slug === "billing.credits.topup") {
113
+ if (input.credits === undefined) {
114
+ input.credits = extractNumberAfterKeyword(text, ["credits", "credit", "pack", "topup", "top-up", "add"], 1000);
115
+ }
116
+ if (!input.description) {
117
+ input.description = `Natural language top-up: ${text.slice(0, 80)}`;
118
+ }
119
+ }
120
+ else if (slug === "billing.subscription.upgrade") {
121
+ if (!input.tier) {
122
+ input.tier = "starter";
123
+ }
124
+ }
125
+ else if (slug === "billing.checkout.create") {
126
+ if (!input.kind) {
127
+ input.kind = /\b(starter|subscription|upgrade|monthly|plan)\b/i.test(text)
128
+ ? "starter_subscription"
129
+ : "credit_topup";
130
+ }
131
+ }
132
+ else if (slug === "app.gmail.send_email") {
133
+ if (!input.recipient_email) {
134
+ const email = extractEmailFromText(text);
135
+ if (email)
136
+ input.recipient_email = email;
137
+ }
138
+ if (!input.subject) {
139
+ const subjMatch = text.match(/\bsubject\s*[:=]?\s*["']([^"']+)["']|\bsubject\s+([^\n]+?)(?:\s+body\b|\s+saying\b|$)/i);
140
+ input.subject = subjMatch
141
+ ? (subjMatch[1] || subjMatch[2]).trim()
142
+ : "Message from Muxo Agent";
143
+ }
144
+ if (!input.body) {
145
+ const bodyMatch = text.match(/\b(?:body|saying|message)\s*[:=]?\s*["']?([\s\S]+?)["']?$/i);
146
+ input.body = bodyMatch ? bodyMatch[1].trim() : text;
147
+ }
148
+ }
149
+ else if (slug === "app.gmail.fetch_emails" || slug === "app.gmail.list_messages") {
150
+ if (!input.query) {
151
+ const qMatch = text.match(/\b(?:matching|query|from|about)\s+["']?([^"'\n]+)["']?/i);
152
+ if (qMatch)
153
+ input.query = qMatch[1].trim();
154
+ }
155
+ if (input.max_results === undefined) {
156
+ input.max_results = extractNumberAfterKeyword(text, ["emails", "messages", "limit", "last"], 10);
157
+ }
158
+ }
159
+ else if (slug === "app.slack.send_message" || slug === "app.slack.post_message") {
160
+ if (!input.channel) {
161
+ const chMatch = text.match(/#([a-zA-Z0-9_-]+)|\bchannel\s+([a-zA-Z0-9_-]+)/i);
162
+ input.channel = chMatch ? chMatch[1] || chMatch[2] : "general";
163
+ }
164
+ if (!input.text) {
165
+ const msgMatch = text.match(/\b(?:saying|message|text)\s*[:=]?\s*["']?([\s\S]+?)["']?$/i);
166
+ input.text = msgMatch ? msgMatch[1].trim() : text;
167
+ }
168
+ }
169
+ else if (slug === "app.github.create_issue" || slug === "app.github.list_pull_requests" || slug === "app.github.list_issues") {
170
+ const repoMatch = text.match(/\b([a-zA-Z0-9_.-]+)\/([a-zA-Z0-9_.-]+)\b/);
171
+ if (repoMatch && !repoMatch[0].includes(".ai") && !repoMatch[0].includes(".com")) {
172
+ if (!input.owner)
173
+ input.owner = repoMatch[1];
174
+ if (!input.repo)
175
+ input.repo = repoMatch[2];
176
+ }
177
+ if (slug === "app.github.create_issue" && !input.title) {
178
+ const titleMatch = text.match(/\b(?:titled|title)\s*[:=]?\s*["']?([^"'\n]+)["']?/i);
179
+ input.title = titleMatch ? titleMatch[1].trim() : text.slice(0, 80);
180
+ }
181
+ }
182
+ else if (slug === "app.notion.search_pages") {
183
+ if (!input.query) {
184
+ const cleaned = text
185
+ .replace(/^(?:search\s+notion\s+(?:pages\s+)?(?:for)?|find\s+in\s+notion)\s*/i, "")
186
+ .trim();
187
+ input.query = cleaned || text;
188
+ }
189
+ }
190
+ else if (slug === "instant.dns.lookup") {
191
+ if (!input.domain) {
192
+ const domainMatch = text.match(/\b((?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+(?:ai|com|io|dev|org|net|app|co|xyz))\b/i);
193
+ if (domainMatch) {
194
+ input.domain = domainMatch[1].toLowerCase();
195
+ }
196
+ else if (typeof input.hostname === "string") {
197
+ input.domain = input.hostname;
198
+ }
199
+ }
200
+ if (!input.type) {
201
+ const typeMatch = text.match(/\b(AAAA|CNAME|TXT|MX|NS|A)\b/i);
202
+ input.type = typeMatch ? typeMatch[1].toUpperCase() : "A";
203
+ }
204
+ }
205
+ else if (slug === "instant.hackernews.top_stories") {
206
+ if (input.limit === undefined) {
207
+ input.limit = extractNumberAfterKeyword(text, ["top", "stories", "items", "limit", "posts"], 5);
208
+ }
209
+ }
210
+ const schemaReq = Array.isArray(tool.inputSchema?.required)
211
+ ? tool.inputSchema.required
212
+ : [];
213
+ const missingInputs = schemaReq.filter((k) => input[k] === undefined || input[k] === null || input[k] === "");
214
+ return { input, missingInputs };
215
+ }
216
+ function scoreToolForPrompt(prompt, tool) {
217
+ const q = prompt.trim().toLowerCase();
218
+ if (!q)
219
+ return 0;
220
+ if (q === tool.slug.toLowerCase() || q === tool.upstreamSlug.toLowerCase()) {
221
+ return 1000;
222
+ }
223
+ let score = 0;
224
+ const slug = tool.slug.toLowerCase();
225
+ // High-signal intent rules
226
+ if (/\b(seo|meta\s+tag|open\s*graph|json-ld|jsonld|canonical|heading\s+hierarchy|audit\s+site|audit\s+page|seo\s+audit)\b/i.test(q)) {
227
+ if (slug === "instant.seo.audit")
228
+ score += 120;
229
+ }
230
+ if (/\b(crawl|spider|multi-page|sitemap|discover\s+links|all\s+pages)\b/i.test(q)) {
231
+ if (slug === "instant.web.crawl")
232
+ score += 110;
233
+ }
234
+ if (/\b(scrape|extract\s+markdown|fetch\s+page|read\s+url|read\s+webpage|scrape\s+url)\b/i.test(q)) {
235
+ if (slug === "instant.web.scrape")
236
+ score += 110;
237
+ }
238
+ if (/\b(search\s+the\s+web|web\s+search|search\s+for|look\s+up|find\s+news|exa|google)\b/i.test(q)) {
239
+ if (slug === "instant.web.search")
240
+ score += 105;
241
+ }
242
+ if (/\b(run\s+python|execute\s+code|run\s+script|sandbox|calculate|e2b)\b/i.test(q)) {
243
+ if (slug === "instant.code.execute")
244
+ score += 105;
245
+ }
246
+ if (/\b(top\s*up|add\s+credits|buy\s+credits|refill\s+credits|more\s+credits|\d+\s+credits)\b/i.test(q)) {
247
+ if (slug === "billing.credits.topup")
248
+ score += 130;
249
+ }
250
+ if (/\b(upgrade\s+to\s+starter|upgrade\s+plan|starter\s+plan|starter\s+tier|upgrade\s+subscription|upgrade\s+workspace)\b/i.test(q)) {
251
+ if (slug === "billing.subscription.upgrade")
252
+ score += 130;
253
+ }
254
+ if (/\b(stripe\s+checkout|checkout\s+session|payment\s+link|billing\s+link)\b/i.test(q)) {
255
+ if (slug === "billing.checkout.create")
256
+ score += 125;
257
+ }
258
+ if (/\b(turso|libsql|sqlite\s+database|sqlite\s+db)\b/i.test(q)) {
259
+ if (slug.startsWith("resource.turso."))
260
+ score += 120;
261
+ if (slug.includes("database"))
262
+ score += 15;
263
+ }
264
+ if (/\b(neon|postgres|postgresql|pg\s+database)\b/i.test(q)) {
265
+ if (slug.startsWith("resource.neon."))
266
+ score += 120;
267
+ }
268
+ if (/\b(upstash|redis|cache\s+store|kv\s+store)\b/i.test(q)) {
269
+ if (slug.startsWith("resource.upstash."))
270
+ score += 120;
271
+ }
272
+ if (/\b(supabase)\b/i.test(q)) {
273
+ if (slug.startsWith("resource.supabase."))
274
+ score += 120;
275
+ }
276
+ if (/\b(mongodb|mongo)\b/i.test(q)) {
277
+ if (slug.startsWith("resource.mongodb."))
278
+ score += 120;
279
+ }
280
+ if (/\b(hacker\s*news|hn\s+stories|top\s+stories)\b/i.test(q)) {
281
+ if (slug === "instant.hackernews.top_stories")
282
+ score += 125;
283
+ }
284
+ if (/\b(dns|doh|txt\s+records?|mx\s+records?|a\s+records?|cname|nameserver|lookup\s+dns|check\s+dns)\b/i.test(q)) {
285
+ if (slug === "instant.dns.lookup")
286
+ score += 135;
287
+ }
288
+ if (/\b(send\s+an?\s+email|send\s+email|email\s+to|compose\s+email)\b/i.test(q)) {
289
+ if (slug === "app.gmail.send_email")
290
+ score += 120;
291
+ }
292
+ if (/\b(list\s+emails|read\s+emails|check\s+inbox|recent\s+emails|list\s+messages|fetch\s+emails|gmail\s+inbox)\b/i.test(q)) {
293
+ if (slug === "app.gmail.fetch_emails" || slug === "app.gmail.list_messages")
294
+ score += 115;
295
+ }
296
+ if (/\b(post\s+to\s+slack|send\s+slack|slack\s+message|message\s+#)\b/i.test(q)) {
297
+ if (slug === "app.slack.send_message" || slug === "app.slack.post_message")
298
+ score += 120;
299
+ }
300
+ if (/\b(create\s+(?:a\s+)?github\s+issue|open\s+(?:a\s+)?github\s+issue|file\s+an?\s+issue)\b/i.test(q)) {
301
+ if (slug === "app.github.create_issue")
302
+ score += 120;
303
+ }
304
+ if (/\b(list\s+github\s+(?:issues|prs|pull\s+requests)|check\s+github|pull\s+requests)\b/i.test(q)) {
305
+ if (slug === "app.github.list_pull_requests" || slug === "app.github.list_issues")
306
+ score += 110;
307
+ }
308
+ if (/\b(notion\s+page|search\s+notion)\b/i.test(q)) {
309
+ if (slug === "app.notion.search_pages")
310
+ score += 115;
311
+ }
312
+ if (/\b(linear\s+issue|create\s+linear)\b/i.test(q)) {
313
+ if (slug === "app.linear.create_issue")
314
+ score += 115;
315
+ }
316
+ if (/\b(google\s+calendar|schedule\s+meeting|list\s+events|calendar\s+events)\b/i.test(q)) {
317
+ if (slug.includes("calendar") || slug.includes("gcal"))
318
+ score += 110;
319
+ }
320
+ // Generic token overlap fallback
321
+ const haystack = `${tool.slug} ${tool.name} ${tool.description} ${tool.providerSlug} ${(tool.categories || []).join(" ")}`.toLowerCase();
322
+ const tokens = q.split(/[^a-z0-9_.-]+/).filter((t) => t.length >= 2);
323
+ for (const token of tokens) {
324
+ if (slug.includes(token))
325
+ score += 18;
326
+ else if (tool.providerSlug.toLowerCase().includes(token))
327
+ score += 14;
328
+ else if (haystack.includes(token))
329
+ score += 6;
330
+ }
331
+ // If prompt contains a URL and no specific verb was matched, default toward scrape/audit
332
+ if (extractUrlFromText(prompt) && score < 40) {
333
+ if (slug === "instant.web.scrape")
334
+ score += 45;
335
+ if (slug === "instant.seo.audit")
336
+ score += 40;
337
+ if (slug === "instant.web.crawl")
338
+ score += 38;
339
+ }
340
+ return score;
341
+ }
342
+ async function tryByokLlmClassification(params) {
343
+ const openaiKey = params.byokKeys.OPENAI_API_KEY || "";
344
+ const openrouterKey = params.byokKeys.OPENROUTER_API_KEY || "";
345
+ const anthropicKey = params.byokKeys.ANTHROPIC_API_KEY || "";
346
+ if (!openaiKey && !openrouterKey && !anthropicKey) {
347
+ return null;
348
+ }
349
+ const catalogBrief = params.tools
350
+ .slice(0, 35)
351
+ .map((t) => `- ${t.slug} (${t.riskLevel}, ${t.creditCost}cr): ${t.description} | schema keys: ${Object.keys(t.inputSchema?.properties || {}).join(", ")}`)
352
+ .join("\n");
353
+ const systemPrompt = [
354
+ "You are the Muxo Natural Language Intent Router.",
355
+ "Map the user's natural language request to the single best toolSlug from the catalog below and extract its JSON arguments.",
356
+ "Return ONLY valid JSON with shape: {\"toolSlug\": string, \"input\": object, \"reason\": string}.",
357
+ "Catalog:",
358
+ catalogBrief,
359
+ ].join("\n");
360
+ try {
361
+ if (openaiKey || openrouterKey) {
362
+ const isOpenRouter = !openaiKey && Boolean(openrouterKey);
363
+ const endpoint = isOpenRouter
364
+ ? "https://openrouter.ai/api/v1/chat/completions"
365
+ : "https://api.openai.com/v1/chat/completions";
366
+ const res = await fetch(endpoint, {
367
+ method: "POST",
368
+ headers: {
369
+ Authorization: `Bearer ${openaiKey || openrouterKey}`,
370
+ "Content-Type": "application/json",
371
+ },
372
+ body: JSON.stringify({
373
+ model: isOpenRouter ? "openai/gpt-4o-mini" : "gpt-4o-mini",
374
+ temperature: 0,
375
+ response_format: { type: "json_object" },
376
+ messages: [
377
+ { role: "system", content: systemPrompt },
378
+ { role: "user", content: params.prompt },
379
+ ],
380
+ }),
381
+ signal: AbortSignal.timeout(4500),
382
+ });
383
+ if (res.ok) {
384
+ const data = (await res.json());
385
+ const content = data?.choices?.[0]?.message?.content;
386
+ if (typeof content === "string") {
387
+ const parsed = JSON.parse(content);
388
+ if (parsed && typeof parsed.toolSlug === "string") {
389
+ return {
390
+ toolSlug: parsed.toolSlug,
391
+ input: parsed.input && typeof parsed.input === "object"
392
+ ? parsed.input
393
+ : {},
394
+ reason: String(parsed.reason || params.prompt),
395
+ providerUsed: isOpenRouter ? "openrouter" : "openai",
396
+ };
397
+ }
398
+ }
399
+ }
400
+ }
401
+ else if (anthropicKey) {
402
+ const res = await fetch("https://api.anthropic.com/v1/messages", {
403
+ method: "POST",
404
+ headers: {
405
+ "x-api-key": anthropicKey,
406
+ "anthropic-version": "2023-06-01",
407
+ "Content-Type": "application/json",
408
+ },
409
+ body: JSON.stringify({
410
+ model: "claude-3-5-haiku-latest",
411
+ max_tokens: 400,
412
+ system: systemPrompt,
413
+ messages: [{ role: "user", content: params.prompt }],
414
+ }),
415
+ signal: AbortSignal.timeout(4500),
416
+ });
417
+ if (res.ok) {
418
+ const data = (await res.json());
419
+ const text = data?.content?.[0]?.text;
420
+ if (typeof text === "string") {
421
+ const jsonMatch = text.match(/\{[\s\S]*\}/);
422
+ if (jsonMatch) {
423
+ const parsed = JSON.parse(jsonMatch[0]);
424
+ if (parsed && typeof parsed.toolSlug === "string") {
425
+ return {
426
+ toolSlug: parsed.toolSlug,
427
+ input: parsed.input && typeof parsed.input === "object"
428
+ ? parsed.input
429
+ : {},
430
+ reason: String(parsed.reason || params.prompt),
431
+ providerUsed: "anthropic",
432
+ };
433
+ }
434
+ }
435
+ }
436
+ }
437
+ }
438
+ }
439
+ catch {
440
+ // Fall back to deterministic semantic router
441
+ }
442
+ return null;
443
+ }
444
+ export async function resolveNaturalLanguageIntent(params) {
445
+ const prompt = params.prompt.trim();
446
+ const tools = params.tools;
447
+ // 1. Check exact slug match first
448
+ const exactTool = tools.find((t) => t.slug.toLowerCase() === prompt.toLowerCase() ||
449
+ t.upstreamSlug.toLowerCase() === prompt.toLowerCase());
450
+ if (exactTool) {
451
+ const { input, missingInputs } = extractParametersFromNaturalLanguage(prompt, exactTool, params.explicitInput);
452
+ const needsConnection = exactTool.requiresAuth &&
453
+ !(params.activeConnectionProviders?.has(exactTool.providerSlug) ?? false);
454
+ return {
455
+ resolved: true,
456
+ tool: exactTool,
457
+ toolSlug: exactTool.slug,
458
+ input,
459
+ extractedInput: input,
460
+ reason: `Direct execution of ${exactTool.slug}`,
461
+ confidence: 1.0,
462
+ resolutionMethod: "exact_slug",
463
+ byokUsed: null,
464
+ humanSummary: `${exactTool.name} (${exactTool.slug})`,
465
+ missingInputs,
466
+ needsConnection,
467
+ suggestedByokProvider: suggestByokProviderForTool(exactTool),
468
+ alternatives: [],
469
+ };
470
+ }
471
+ // 2. Try BYOK LLM router if a user LLM key is configured in the workspace vault
472
+ if (params.preferByokLlm !== false && params.byokKeys) {
473
+ const llmRes = await tryByokLlmClassification({
474
+ prompt,
475
+ tools,
476
+ byokKeys: params.byokKeys,
477
+ });
478
+ if (llmRes) {
479
+ const matchedTool = tools.find((t) => t.slug.toLowerCase() === llmRes.toolSlug.toLowerCase());
480
+ if (matchedTool) {
481
+ const mergedExplicit = {
482
+ ...llmRes.input,
483
+ ...(params.explicitInput || {}),
484
+ };
485
+ const { input, missingInputs } = extractParametersFromNaturalLanguage(prompt, matchedTool, mergedExplicit);
486
+ const needsConnection = matchedTool.requiresAuth &&
487
+ !(params.activeConnectionProviders?.has(matchedTool.providerSlug) ?? false);
488
+ return {
489
+ resolved: true,
490
+ tool: matchedTool,
491
+ toolSlug: matchedTool.slug,
492
+ input,
493
+ extractedInput: input,
494
+ reason: llmRes.reason || prompt,
495
+ confidence: 0.96,
496
+ resolutionMethod: "byok_llm",
497
+ byokUsed: llmRes.providerUsed,
498
+ humanSummary: `${matchedTool.name} via ${matchedTool.slug}`,
499
+ missingInputs,
500
+ needsConnection,
501
+ suggestedByokProvider: suggestByokProviderForTool(matchedTool),
502
+ alternatives: [],
503
+ };
504
+ }
505
+ }
506
+ }
507
+ // 3. Deterministic Semantic + Regex Router (0 latency, works without LLM API keys)
508
+ const scored = tools
509
+ .map((tool) => ({ tool, score: scoreToolForPrompt(prompt, tool) }))
510
+ .filter((item) => item.score > 0)
511
+ .sort((a, b) => b.score - a.score);
512
+ const best = scored[0]?.tool || null;
513
+ const bestScore = scored[0]?.score || 0;
514
+ const alternatives = scored.slice(1, 5).map((s) => ({
515
+ slug: s.tool.slug,
516
+ name: s.tool.name,
517
+ riskLevel: s.tool.riskLevel,
518
+ creditCost: s.tool.creditCost,
519
+ }));
520
+ if (!best || bestScore < 12) {
521
+ return {
522
+ resolved: false,
523
+ tool: null,
524
+ toolSlug: null,
525
+ input: params.explicitInput || {},
526
+ extractedInput: params.explicitInput || {},
527
+ reason: prompt,
528
+ confidence: 0,
529
+ resolutionMethod: "semantic_router",
530
+ byokUsed: null,
531
+ humanSummary: `Could not confidently match "${prompt}" to a Muxo tool. Try specifying a tool keyword (e.g. "audit seo https://muxo.ai", "search web for AI agents", "top up 1000 credits", "create turso database").`,
532
+ missingInputs: [],
533
+ needsConnection: false,
534
+ suggestedByokProvider: "openai",
535
+ alternatives: tools.slice(0, 5).map((t) => ({
536
+ slug: t.slug,
537
+ name: t.name,
538
+ riskLevel: t.riskLevel,
539
+ creditCost: t.creditCost,
540
+ })),
541
+ };
542
+ }
543
+ const { input, missingInputs } = extractParametersFromNaturalLanguage(prompt, best, params.explicitInput);
544
+ const needsConnection = best.requiresAuth &&
545
+ !(params.activeConnectionProviders?.has(best.providerSlug) ?? false);
546
+ const confidence = Math.min(0.95, Math.round((bestScore / 130) * 100) / 100);
547
+ return {
548
+ resolved: true,
549
+ tool: best,
550
+ toolSlug: best.slug,
551
+ input,
552
+ extractedInput: input,
553
+ reason: prompt,
554
+ confidence,
555
+ resolutionMethod: "semantic_router",
556
+ byokUsed: null,
557
+ humanSummary: `${best.name} (${best.slug})`,
558
+ missingInputs,
559
+ needsConnection,
560
+ suggestedByokProvider: suggestByokProviderForTool(best),
561
+ alternatives,
562
+ };
563
+ }
564
+ function suggestByokProviderForTool(tool) {
565
+ if (tool.slug.startsWith("billing."))
566
+ return "stripe";
567
+ if (tool.lane === "composio_sdk")
568
+ return "composio";
569
+ if (tool.lane === "stripe_projects")
570
+ return "stripe";
571
+ if (tool.slug.includes("scrape") || tool.slug.includes("crawl") || tool.slug.includes("seo")) {
572
+ return "firecrawl";
573
+ }
574
+ if (tool.slug.includes("search"))
575
+ return "exa";
576
+ return "composio";
577
+ }
@@ -0,0 +1,14 @@
1
+ import type { MuxoConfig } from "../config.js";
2
+ import type { MuxoTool } from "../types.js";
3
+ export declare class ComposioInstantAdapter {
4
+ private readonly config;
5
+ constructor(config: MuxoConfig);
6
+ getTools(): MuxoTool[];
7
+ searchTools(query?: string, limit?: number): MuxoTool[];
8
+ inspectTool(slug: string): MuxoTool | null;
9
+ executeTool(params: {
10
+ workspaceId: string;
11
+ tool: MuxoTool;
12
+ input: Record<string, unknown>;
13
+ }): Promise<Record<string, unknown>>;
14
+ }