@dsh-cc/tool-search 0.9.4 → 0.9.5-rc.1
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.i18n.yaml +2 -2
- package/README.md +42 -1
- package/README.zh.md +42 -1
- package/lib/discovery-cache.d.ts +208 -0
- package/lib/discovery-cache.d.ts.map +1 -0
- package/lib/discovery-cache.js +296 -0
- package/lib/discovery-cache.js.map +1 -0
- package/lib/discovery-contract.d.ts +144 -0
- package/lib/discovery-contract.d.ts.map +1 -0
- package/lib/discovery-contract.js +144 -0
- package/lib/discovery-contract.js.map +1 -0
- package/lib/discovery-runtime.d.ts +137 -0
- package/lib/discovery-runtime.d.ts.map +1 -0
- package/lib/discovery-runtime.js +343 -0
- package/lib/discovery-runtime.js.map +1 -0
- package/lib/discovery-settings.d.ts +134 -0
- package/lib/discovery-settings.d.ts.map +1 -0
- package/lib/discovery-settings.js +269 -0
- package/lib/discovery-settings.js.map +1 -0
- package/lib/discovery.d.ts +267 -0
- package/lib/discovery.d.ts.map +1 -0
- package/lib/discovery.js +278 -0
- package/lib/discovery.js.map +1 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +84 -88
- package/lib/index.js.map +1 -1
- package/lib/search-message.d.ts +32 -0
- package/lib/search-message.d.ts.map +1 -0
- package/lib/search-message.js +50 -0
- package/lib/search-message.js.map +1 -0
- package/lib/search-scoring.d.ts +31 -0
- package/lib/search-scoring.d.ts.map +1 -0
- package/lib/search-scoring.js +53 -0
- package/lib/search-scoring.js.map +1 -0
- package/package.json +12 -4
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model-facing copy of one ToolSearch outcome.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `index.ts` when S1-05 added the discovery wiring: the
|
|
5
|
+
* rendering is a pure function of the activated results and the pool state, it
|
|
6
|
+
* is the same on every path (`mode: off`, every lexical fallback, and an active
|
|
7
|
+
* judgment), and it must stay byte-identical to the pre-S1-05 output — keeping
|
|
8
|
+
* it in one small module makes that invariant reviewable and keeps `index.ts`
|
|
9
|
+
* inside the repo's per-file budget.
|
|
10
|
+
*
|
|
11
|
+
* @module @dsh-cc/tool-search/search-message
|
|
12
|
+
*/
|
|
13
|
+
/** One activated (or refused) result as the model sees it. */
|
|
14
|
+
export interface SearchResultEntry {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly description: string;
|
|
17
|
+
readonly status: string;
|
|
18
|
+
readonly reason?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Compose the full model-facing ToolSearch outcome, branching on pool state so
|
|
22
|
+
* an empty search never reads as "you lack the capability" — the trap this
|
|
23
|
+
* copy exists to defuse is a model concluding it has no filesystem/shell tools
|
|
24
|
+
* when in fact the deferred pool is simply empty (or already fully loaded).
|
|
25
|
+
* @param query - the model's raw query.
|
|
26
|
+
* @param results - the activated/refused entries, in activation order.
|
|
27
|
+
* @param total - non-alwaysLoad deferred entries the scope can see.
|
|
28
|
+
* @param searchable - of those, the ones not yet activated.
|
|
29
|
+
* @returns the `message` field of the tool result.
|
|
30
|
+
*/
|
|
31
|
+
export declare function composeSearchMessage(query: string, results: readonly SearchResultEntry[], total: number, searchable: number): string;
|
|
32
|
+
//# sourceMappingURL=search-message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-message.d.ts","sourceRoot":"","sources":["../src/search-message.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,8DAA8D;AAC9D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,iBAAiB,EAAE,EACrC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,MAAM,CASR"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model-facing copy of one ToolSearch outcome.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `index.ts` when S1-05 added the discovery wiring: the
|
|
5
|
+
* rendering is a pure function of the activated results and the pool state, it
|
|
6
|
+
* is the same on every path (`mode: off`, every lexical fallback, and an active
|
|
7
|
+
* judgment), and it must stay byte-identical to the pre-S1-05 output — keeping
|
|
8
|
+
* it in one small module makes that invariant reviewable and keeps `index.ts`
|
|
9
|
+
* inside the repo's per-file budget.
|
|
10
|
+
*
|
|
11
|
+
* @module @dsh-cc/tool-search/search-message
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Compose the full model-facing ToolSearch outcome, branching on pool state so
|
|
15
|
+
* an empty search never reads as "you lack the capability" — the trap this
|
|
16
|
+
* copy exists to defuse is a model concluding it has no filesystem/shell tools
|
|
17
|
+
* when in fact the deferred pool is simply empty (or already fully loaded).
|
|
18
|
+
* @param query - the model's raw query.
|
|
19
|
+
* @param results - the activated/refused entries, in activation order.
|
|
20
|
+
* @param total - non-alwaysLoad deferred entries the scope can see.
|
|
21
|
+
* @param searchable - of those, the ones not yet activated.
|
|
22
|
+
* @returns the `message` field of the tool result.
|
|
23
|
+
*/
|
|
24
|
+
export function composeSearchMessage(query, results, total, searchable) {
|
|
25
|
+
if (results.length > 0)
|
|
26
|
+
return renderToolSearchText(query, results);
|
|
27
|
+
if (total === 0) {
|
|
28
|
+
return 'No deferred tools are available to you in this session — every tool you can use is already in your function list; call it directly.';
|
|
29
|
+
}
|
|
30
|
+
if (searchable === 0) {
|
|
31
|
+
return 'All deferred tools available to you are already loaded; call them directly.';
|
|
32
|
+
}
|
|
33
|
+
return `No deferred tools matched "${query}". This directory lists deferred tools only; tools that registered eagerly (including eager MCP tools) never appear here — they are already in your function list, call them directly.`;
|
|
34
|
+
}
|
|
35
|
+
/** Compose the model-facing summary of a ToolSearch outcome. */
|
|
36
|
+
function renderToolSearchText(query, results) {
|
|
37
|
+
if (results.length === 0) {
|
|
38
|
+
return `No deferred tools matched "${query}".`;
|
|
39
|
+
}
|
|
40
|
+
const lines = results.map((result) => {
|
|
41
|
+
const statusLabel = result.status === 'loaded' ? 'now available'
|
|
42
|
+
: result.status === 'already-loaded' ? 'already available'
|
|
43
|
+
: result.status === 'denied' ? 'denied'
|
|
44
|
+
: 'not found';
|
|
45
|
+
const tail = result.status === 'denied' && result.reason !== undefined ? ` — ${result.reason}` : '';
|
|
46
|
+
return `- ${result.name}: ${result.description} (${statusLabel})${tail}`;
|
|
47
|
+
});
|
|
48
|
+
return `ToolSearch "${query}":\n${lines.join('\n')}`;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=search-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-message.js","sourceRoot":"","sources":["../src/search-message.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAa,EACb,OAAqC,EACrC,KAAa,EACb,UAAkB;IAElB,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IACnE,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,qIAAqI,CAAA;IAC9I,CAAC;IACD,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,6EAA6E,CAAA;IACtF,CAAC;IACD,OAAO,8BAA8B,KAAK,wLAAwL,CAAA;AACpO,CAAC;AAED,gEAAgE;AAChE,SAAS,oBAAoB,CAAC,KAAa,EAAE,OAAqC;IAChF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,8BAA8B,KAAK,IAAI,CAAA;IAChD,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QACnC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe;YAC9D,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,gBAAgB,CAAC,CAAC,CAAC,mBAAmB;gBACxD,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ;oBACrC,CAAC,CAAC,WAAW,CAAA;QACnB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QACnG,OAAO,KAAK,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,WAAW,KAAK,WAAW,IAAI,IAAI,EAAE,CAAA;IAC1E,CAAC,CAAC,CAAA;IACF,OAAO,eAAe,KAAK,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AACtD,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lexical baseline of ToolSearch: token overlap between a free-text query
|
|
3
|
+
* and a deferred tool's name, search hint and description.
|
|
4
|
+
*
|
|
5
|
+
* Extracted verbatim from `index.ts` when S1-05 added the discovery wiring. It
|
|
6
|
+
* stays the untouched original ranking (`mode: off` and every discovery
|
|
7
|
+
* fallback execute it byte-for-byte), and the discovery layer reads the same
|
|
8
|
+
* score as an untrusted tie-break input only — never as a filter — so keeping
|
|
9
|
+
* the two in one small pure module makes that boundary explicit.
|
|
10
|
+
*
|
|
11
|
+
* @module @dsh-cc/tool-search/search-scoring
|
|
12
|
+
*/
|
|
13
|
+
/** The searchable metadata of one deferred registration. */
|
|
14
|
+
export interface ScorableDeferred {
|
|
15
|
+
readonly reg: {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly description: string;
|
|
18
|
+
readonly searchHint?: string | undefined;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* How much a deferred tool matches a query, summed over query tokens and the
|
|
23
|
+
* weighted name/description/searchHint fields. `name` carries the most weight,
|
|
24
|
+
* `searchHint` next, then `description`; an exact name match is conclusive.
|
|
25
|
+
* Pure and deterministic: used only to rank the candidate set.
|
|
26
|
+
* @param stored - the deferred registration.
|
|
27
|
+
* @param query - the raw ToolSearch query.
|
|
28
|
+
* @returns a non-negative score; `0` means no match.
|
|
29
|
+
*/
|
|
30
|
+
export declare function scoreStored(stored: ScorableDeferred, query: string): number;
|
|
31
|
+
//# sourceMappingURL=search-scoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-scoring.d.ts","sourceRoot":"","sources":["../src/search-scoring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,4DAA4D;AAC5D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE;QACZ,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;QACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;QAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KACzC,CAAA;CACF;AAOD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAsB3E"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lexical baseline of ToolSearch: token overlap between a free-text query
|
|
3
|
+
* and a deferred tool's name, search hint and description.
|
|
4
|
+
*
|
|
5
|
+
* Extracted verbatim from `index.ts` when S1-05 added the discovery wiring. It
|
|
6
|
+
* stays the untouched original ranking (`mode: off` and every discovery
|
|
7
|
+
* fallback execute it byte-for-byte), and the discovery layer reads the same
|
|
8
|
+
* score as an untrusted tie-break input only — never as a filter — so keeping
|
|
9
|
+
* the two in one small pure module makes that boundary explicit.
|
|
10
|
+
*
|
|
11
|
+
* @module @dsh-cc/tool-search/search-scoring
|
|
12
|
+
*/
|
|
13
|
+
/** Lowercase the input and split into alphanumeric tokens, dropping empty ones. */
|
|
14
|
+
function tokenize(value) {
|
|
15
|
+
return value.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* How much a deferred tool matches a query, summed over query tokens and the
|
|
19
|
+
* weighted name/description/searchHint fields. `name` carries the most weight,
|
|
20
|
+
* `searchHint` next, then `description`; an exact name match is conclusive.
|
|
21
|
+
* Pure and deterministic: used only to rank the candidate set.
|
|
22
|
+
* @param stored - the deferred registration.
|
|
23
|
+
* @param query - the raw ToolSearch query.
|
|
24
|
+
* @returns a non-negative score; `0` means no match.
|
|
25
|
+
*/
|
|
26
|
+
export function scoreStored(stored, query) {
|
|
27
|
+
const q = query.toLowerCase().trim();
|
|
28
|
+
if (q.length === 0)
|
|
29
|
+
return 0;
|
|
30
|
+
const qTokens = tokenize(q);
|
|
31
|
+
const fields = [
|
|
32
|
+
[stored.reg.name.toLowerCase(), 10],
|
|
33
|
+
[(stored.reg.searchHint ?? '').toLowerCase(), 4],
|
|
34
|
+
[stored.reg.description.toLowerCase(), 2],
|
|
35
|
+
];
|
|
36
|
+
let total = 0;
|
|
37
|
+
for (const [text, weight] of fields) {
|
|
38
|
+
if (text.length === 0)
|
|
39
|
+
continue;
|
|
40
|
+
for (const token of qTokens) {
|
|
41
|
+
if (token.length === 0)
|
|
42
|
+
continue;
|
|
43
|
+
if (text.includes(token)) {
|
|
44
|
+
total += weight;
|
|
45
|
+
}
|
|
46
|
+
else if (tokenize(text).some(word => word.startsWith(token) || token.startsWith(word))) {
|
|
47
|
+
total += Math.max(1, Math.floor(weight / 2));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return total;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=search-scoring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-scoring.js","sourceRoot":"","sources":["../src/search-scoring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAWH,mFAAmF;AACnF,SAAS,QAAQ,CAAC,KAAa;IAC7B,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AAChE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,MAAwB,EAAE,KAAa;IACjE,MAAM,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAA;IACpC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAA;IAC5B,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC3B,MAAM,MAAM,GAAqC;QAC/C,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,EAAE,CAAC;QACnC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAChD,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;KAC1C,CAAA;IACD,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACpC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,SAAQ;QAC/B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAQ;YAChC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,KAAK,IAAI,MAAM,CAAA;YACjB,CAAC;iBAAM,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;gBACzF,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAA;YAC9C,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-cc/tool-search",
|
|
3
3
|
"description": "Deferred tool registration and a ToolSearch model tool that loads heavy tools on demand",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.5-rc.1",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/dsh-cc/dsh-cc.git",
|
|
@@ -21,10 +21,16 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"peerDependencies": {
|
|
24
|
+
"@deepseek-ai/cordis": ">=0.2.0-rc.2",
|
|
24
25
|
"@deepseek-ai/dsh-scope": ">=0.2.2-rc.1",
|
|
25
26
|
"@deepseek-ai/dsh-system-prompt": ">=0.2.2-rc.1",
|
|
26
|
-
"@deepseek-ai/
|
|
27
|
-
"@dsh-cc/
|
|
27
|
+
"@deepseek-ai/schemastery": "^3.18.1",
|
|
28
|
+
"@dsh-cc/settings": "^0.9.5-rc.1",
|
|
29
|
+
"@dsh-cc/tools": "^0.9.5-rc.1"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@dsh-cc/settings": "^0.9.5-rc.1",
|
|
33
|
+
"@dsh-cc/systemone": "^0.9.5-rc.1"
|
|
28
34
|
},
|
|
29
35
|
"devDependencies": {
|
|
30
36
|
"@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
|
|
@@ -34,7 +40,9 @@
|
|
|
34
40
|
"@deepseek-ai/dsh-session": "link:../../../../deepseek-harness/packages/core/session",
|
|
35
41
|
"@deepseek-ai/dsh-system-prompt": "link:../../../../deepseek-harness/packages/core/system-prompt",
|
|
36
42
|
"@deepseek-ai/dsh-tool-testkit": "link:../../../../deepseek-harness/packages/test-support/tool-testkit",
|
|
37
|
-
"@
|
|
43
|
+
"@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery",
|
|
44
|
+
"@dsh-cc/tools": "^0.9.5-rc.1",
|
|
45
|
+
"@dsh-cc/settings": "^0.9.5-rc.1"
|
|
38
46
|
},
|
|
39
47
|
"publishConfig": {
|
|
40
48
|
"access": "public"
|