toolnexus 0.23.0 → 0.25.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.
- package/README.md +139 -1
- package/dist/acp.d.ts +37 -6
- package/dist/acp.js +239 -52
- package/dist/agents/loop.js +4 -1
- package/dist/agents/runtime.js +4 -1
- package/dist/client.d.ts +55 -9
- package/dist/client.js +154 -41
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/mcp.d.ts +32 -7
- package/dist/mcp.js +125 -36
- package/dist/mcp2026/auth.d.ts +137 -0
- package/dist/mcp2026/auth.js +446 -0
- package/dist/mcp2026/client.d.ts +48 -0
- package/dist/mcp2026/client.js +160 -0
- package/dist/mcp2026/protocol.d.ts +54 -0
- package/dist/mcp2026/protocol.js +113 -0
- package/dist/mcp2026/skills.d.ts +5 -0
- package/dist/mcp2026/skills.js +25 -0
- package/dist/mcp2026/source.d.ts +86 -0
- package/dist/mcp2026/source.js +372 -0
- package/dist/mcp2026/stdio.d.ts +24 -0
- package/dist/mcp2026/stdio.js +99 -0
- package/dist/mcp2026/toolsearch.d.ts +5 -0
- package/dist/mcp2026/toolsearch.js +58 -0
- package/dist/mcphandler.d.ts +169 -0
- package/dist/mcphandler.js +1145 -0
- package/dist/mcpheader.d.ts +5 -0
- package/dist/mcpheader.js +18 -0
- package/dist/mcpserve.d.ts +24 -15
- package/dist/mcpserve.js +105 -2
- package/dist/mcpserverauth.d.ts +48 -0
- package/dist/mcpserverauth.js +203 -0
- package/dist/media.d.ts +126 -0
- package/dist/media.js +540 -0
- package/dist/skill.d.ts +21 -0
- package/dist/skill.js +44 -0
- package/dist/toolconcurrency.d.ts +16 -0
- package/dist/toolconcurrency.js +59 -0
- package/dist/toolkit.d.ts +23 -1
- package/dist/toolkit.js +26 -4
- package/dist/types.d.ts +26 -1
- package/package.json +5 -3
- package/src/acp.ts +258 -55
- package/src/agents/loop.ts +4 -1
- package/src/agents/runtime.ts +4 -1
- package/src/client.ts +196 -48
- package/src/index.ts +4 -0
- package/src/mcp.ts +162 -43
- package/src/mcp2026/auth.ts +473 -0
- package/src/mcp2026/client.ts +161 -0
- package/src/mcp2026/protocol.ts +135 -0
- package/src/mcp2026/skills.ts +22 -0
- package/src/mcp2026/source.ts +407 -0
- package/src/mcp2026/stdio.ts +102 -0
- package/src/mcp2026/toolsearch.ts +56 -0
- package/src/mcphandler.ts +1252 -0
- package/src/mcpheader.ts +19 -0
- package/src/mcpserve.ts +115 -2
- package/src/mcpserverauth.ts +216 -0
- package/src/media.ts +604 -0
- package/src/skill.ts +50 -0
- package/src/toolconcurrency.ts +67 -0
- package/src/toolkit.ts +35 -5
- package/src/types.ts +27 -1
|
@@ -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
|
+
}
|