@relayplane/proxy 1.9.25 → 1.9.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.
@@ -0,0 +1,12 @@
1
+ export interface SearchableTool {
2
+ name: string;
3
+ description: string;
4
+ }
5
+ export declare class SemanticToolSearch {
6
+ private tools;
7
+ private vectors;
8
+ get size(): number;
9
+ indexTools(tools: SearchableTool[]): void;
10
+ search(query: string, topK: number): SearchableTool[];
11
+ }
12
+ //# sourceMappingURL=tool-search-semantic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-search-semantic.d.ts","sourceRoot":"","sources":["../src/tool-search-semantic.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AA6BD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAwB;IACrC,OAAO,CAAC,OAAO,CAA6B;IAE5C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI;IAOzC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE;CAUtD"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SemanticToolSearch = void 0;
4
+ function tokenize(text) {
5
+ return text.toLowerCase().replace(/[^a-z0-9\s]/g, ' ').split(/\s+/).filter(t => t.length > 1);
6
+ }
7
+ function buildVector(tokens) {
8
+ const freq = new Map();
9
+ for (const t of tokens) {
10
+ freq.set(t, (freq.get(t) ?? 0) + 1);
11
+ }
12
+ return freq;
13
+ }
14
+ function cosineSimilarity(a, b) {
15
+ let dot = 0;
16
+ let normA = 0;
17
+ let normB = 0;
18
+ for (const [term, countA] of a) {
19
+ dot += countA * (b.get(term) ?? 0);
20
+ normA += countA * countA;
21
+ }
22
+ for (const [, countB] of b) {
23
+ normB += countB * countB;
24
+ }
25
+ if (normA === 0 || normB === 0)
26
+ return 0;
27
+ return dot / (Math.sqrt(normA) * Math.sqrt(normB));
28
+ }
29
+ class SemanticToolSearch {
30
+ tools = [];
31
+ vectors = [];
32
+ get size() {
33
+ return this.tools.length;
34
+ }
35
+ indexTools(tools) {
36
+ this.tools = [...tools];
37
+ this.vectors = tools.map(t => buildVector(tokenize(`${t.name} ${t.description}`)));
38
+ }
39
+ search(query, topK) {
40
+ if (this.tools.length === 0)
41
+ return [];
42
+ const queryVec = buildVector(tokenize(query));
43
+ const scored = this.tools.map((tool, i) => ({
44
+ tool,
45
+ score: cosineSimilarity(queryVec, this.vectors[i]),
46
+ }));
47
+ scored.sort((a, b) => b.score - a.score || a.tool.name.localeCompare(b.tool.name));
48
+ return scored.slice(0, topK).map(s => s.tool);
49
+ }
50
+ }
51
+ exports.SemanticToolSearch = SemanticToolSearch;
52
+ //# sourceMappingURL=tool-search-semantic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-search-semantic.js","sourceRoot":"","sources":["../src/tool-search-semantic.ts"],"names":[],"mappings":";;;AAKA,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAChG,CAAC;AAED,SAAS,WAAW,CAAC,MAAgB;IACnC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACtC,CAAC;IACD,OA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C,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACvC,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YAC1C,IAAI;YACJ,KAAK,EAAE,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SACnD,CAAC,CAAC,CAAC;QACJ,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACnF,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;CACF;AAzBD,gDAyBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relayplane/proxy",
3
- "version": "1.9.25",
3
+ "version": "1.9.26",
4
4
  "description": "Open source cost intelligence proxy for AI agents. Cut LLM costs ~80% with smart model routing. Dashboard, policy engine, 11 providers. MIT licensed.",
5
5
  "homepage": "https://relayplane.com",
6
6
  "repository": {