toolnexus 0.24.0 → 0.26.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 (63) hide show
  1. package/README.md +151 -1
  2. package/dist/acp.d.ts +37 -6
  3. package/dist/acp.js +239 -52
  4. package/dist/classifier.d.ts +189 -31
  5. package/dist/classifier.js +589 -30
  6. package/dist/client.d.ts +38 -8
  7. package/dist/client.js +102 -23
  8. package/dist/index.d.ts +2 -0
  9. package/dist/index.js +2 -0
  10. package/dist/judge.d.ts +6 -3
  11. package/dist/judge.js +13 -1
  12. package/dist/mcp.d.ts +32 -7
  13. package/dist/mcp.js +125 -36
  14. package/dist/mcp2026/auth.d.ts +137 -0
  15. package/dist/mcp2026/auth.js +446 -0
  16. package/dist/mcp2026/client.d.ts +48 -0
  17. package/dist/mcp2026/client.js +160 -0
  18. package/dist/mcp2026/protocol.d.ts +54 -0
  19. package/dist/mcp2026/protocol.js +113 -0
  20. package/dist/mcp2026/skills.d.ts +5 -0
  21. package/dist/mcp2026/skills.js +25 -0
  22. package/dist/mcp2026/source.d.ts +86 -0
  23. package/dist/mcp2026/source.js +372 -0
  24. package/dist/mcp2026/stdio.d.ts +24 -0
  25. package/dist/mcp2026/stdio.js +99 -0
  26. package/dist/mcp2026/toolsearch.d.ts +5 -0
  27. package/dist/mcp2026/toolsearch.js +58 -0
  28. package/dist/mcphandler.d.ts +169 -0
  29. package/dist/mcphandler.js +1145 -0
  30. package/dist/mcpheader.d.ts +5 -0
  31. package/dist/mcpheader.js +18 -0
  32. package/dist/mcpserve.d.ts +24 -15
  33. package/dist/mcpserve.js +105 -2
  34. package/dist/mcpserverauth.d.ts +48 -0
  35. package/dist/mcpserverauth.js +203 -0
  36. package/dist/serve.js +7 -0
  37. package/dist/skill.d.ts +21 -0
  38. package/dist/skill.js +44 -0
  39. package/dist/toolkit.d.ts +20 -1
  40. package/dist/toolkit.js +25 -3
  41. package/dist/types.d.ts +22 -0
  42. package/package.json +4 -3
  43. package/src/acp.ts +258 -55
  44. package/src/classifier.ts +677 -46
  45. package/src/client.ts +130 -27
  46. package/src/index.ts +2 -0
  47. package/src/judge.ts +19 -4
  48. package/src/mcp.ts +162 -43
  49. package/src/mcp2026/auth.ts +473 -0
  50. package/src/mcp2026/client.ts +161 -0
  51. package/src/mcp2026/protocol.ts +135 -0
  52. package/src/mcp2026/skills.ts +22 -0
  53. package/src/mcp2026/source.ts +407 -0
  54. package/src/mcp2026/stdio.ts +102 -0
  55. package/src/mcp2026/toolsearch.ts +56 -0
  56. package/src/mcphandler.ts +1252 -0
  57. package/src/mcpheader.ts +19 -0
  58. package/src/mcpserve.ts +115 -2
  59. package/src/mcpserverauth.ts +216 -0
  60. package/src/serve.ts +7 -0
  61. package/src/skill.ts +50 -0
  62. package/src/toolkit.ts +31 -4
  63. package/src/types.ts +23 -0
@@ -0,0 +1,56 @@
1
+ // Lazy tool search: with client.toolSearch the LLM sees two small tools instead of all N:
2
+ // search_tools(query) -> ranked {name, description, inputSchema, server}, and
3
+ // call_tool(name, arguments) to run one it found. Ranking is BM25 over name (x2) + description.
4
+ import type { Obj } from "./protocol.js"
5
+
6
+ /** BM25 (k1 1.2, b 0.75) over name tokens twice + description tokens; best first, ties keep list order. */
7
+ export function rank(tools: Obj[], query: string, limit: number): Obj[] {
8
+ const docs = tools.map((t) => {
9
+ const nt = tokens(String(t.name ?? ""))
10
+ return [...nt, ...nt, ...tokens(String(t.description ?? ""))]
11
+ })
12
+ const df = new Map<string, number>()
13
+ let total = 0
14
+ for (const d of docs) {
15
+ total += d.length
16
+ for (const w of new Set(d)) df.set(w, (df.get(w) ?? 0) + 1)
17
+ }
18
+ const avg = total / Math.max(1, tools.length)
19
+ const qs = tokens(query)
20
+ const hits: { i: number; score: number }[] = []
21
+ docs.forEach((d, i) => {
22
+ const tf = new Map<string, number>()
23
+ for (const w of d) tf.set(w, (tf.get(w) ?? 0) + 1)
24
+ let s = 0
25
+ for (const q of qs) {
26
+ const f = tf.get(q) ?? 0
27
+ if (f === 0) continue
28
+ const n = df.get(q) ?? 0
29
+ const idf = Math.log(1 + (tools.length - n + 0.5) / (n + 0.5))
30
+ s += (idf * f * 2.2) / (f + 1.2 * (0.25 + (0.75 * d.length) / avg))
31
+ }
32
+ if (s > 0) hits.push({ i, score: s })
33
+ })
34
+ hits.sort((a, b) => b.score - a.score) // stable
35
+ return hits.slice(0, Math.max(0, limit)).map((h) => tools[h.i])
36
+ }
37
+
38
+ /** Lowercases and splits on non-alphanumerics and camelCase boundaries. */
39
+ export function tokens(s: string): string[] {
40
+ const out: string[] = []
41
+ let cur = ""
42
+ let prevLower = false
43
+ for (const r of s) {
44
+ if (/\p{Lu}/u.test(r) && prevLower) {
45
+ if (cur) out.push(cur.toLowerCase())
46
+ cur = r
47
+ } else if (/[\p{L}\p{N}]/u.test(r)) cur += r
48
+ else if (cur) {
49
+ out.push(cur.toLowerCase())
50
+ cur = ""
51
+ }
52
+ prevLower = /\p{Ll}/u.test(r)
53
+ }
54
+ if (cur) out.push(cur.toLowerCase())
55
+ return out
56
+ }