@mcoda/codali 0.1.121 → 0.1.122
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.
|
@@ -15,6 +15,7 @@ import type { DocdexClient } from "../../docdex/DocdexClient.js";
|
|
|
15
15
|
export declare const toRepoRelativePath: (value: string | undefined, workspaceRoot?: string) => string | undefined;
|
|
16
16
|
/** Test seam: forget any open circuit. */
|
|
17
17
|
export declare const resetWebResearchBackoff: () => void;
|
|
18
|
+
export declare const normalizeWebQuery: (value: unknown) => string | undefined;
|
|
18
19
|
/**
|
|
19
20
|
* Judges whether search results actually answer the question.
|
|
20
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocdexTools.d.ts","sourceRoot":"","sources":["../../../src/tools/docdex/DocdexTools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAuFjE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,GAC7B,OAAO,MAAM,GAAG,SAAS,EACzB,gBAAgB,MAAM,KACrB,MAAM,GAAG,SAWX,CAAC;AAwCF,0CAA0C;AAC1C,eAAO,MAAM,uBAAuB,QAAO,IAG1C,CAAC;
|
|
1
|
+
{"version":3,"file":"DocdexTools.d.ts","sourceRoot":"","sources":["../../../src/tools/docdex/DocdexTools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAuFjE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,GAC7B,OAAO,MAAM,GAAG,SAAS,EACzB,gBAAgB,MAAM,KACrB,MAAM,GAAG,SAWX,CAAC;AAwCF,0CAA0C;AAC1C,eAAO,MAAM,uBAAuB,QAAO,IAG1C,CAAC;AA0DF,eAAO,MAAM,iBAAiB,GAAI,OAAO,OAAO,KAAG,MAAM,GAAG,SAO3D,CAAC;AAoHF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEvB,MAAM,WAAW,iBAAiB;IAChC,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,YAAY,EACpB,UAAS,iBAAsB,KAC9B,cAAc,EAAgE,CAAC"}
|
|
@@ -186,6 +186,28 @@ const noteWebRefusal = (error) => {
|
|
|
186
186
|
(backoff < 60000 ? `${Math.round(backoff / 1000)}s` : `${Math.round(backoff / 60000)}m`);
|
|
187
187
|
};
|
|
188
188
|
const webResearchBlocked = () => Date.now() < webUnavailableUntilMs ? webUnavailableReason : undefined;
|
|
189
|
+
/**
|
|
190
|
+
* Normalises a query before it costs a metered request.
|
|
191
|
+
*
|
|
192
|
+
* The schema asks for a string and a model can satisfy that with whitespace, or
|
|
193
|
+
* with a whole paragraph of pasted context. Both are rejected upstream, and a
|
|
194
|
+
* rejected request still spends the allowance: measured at the gateway, a third
|
|
195
|
+
* of an hour's traffic was 400s rather than answers.
|
|
196
|
+
*
|
|
197
|
+
* A search query is a phrase. Beyond a couple of hundred characters it is not a
|
|
198
|
+
* query any more, and the useful part is at the front.
|
|
199
|
+
*/
|
|
200
|
+
const MAX_WEB_QUERY_CHARS = 400;
|
|
201
|
+
export const normalizeWebQuery = (value) => {
|
|
202
|
+
if (typeof value !== "string")
|
|
203
|
+
return undefined;
|
|
204
|
+
const collapsed = value.replace(/\s+/g, " ").trim();
|
|
205
|
+
if (!collapsed)
|
|
206
|
+
return undefined;
|
|
207
|
+
return collapsed.length > MAX_WEB_QUERY_CHARS
|
|
208
|
+
? collapsed.slice(0, MAX_WEB_QUERY_CHARS).trimEnd()
|
|
209
|
+
: collapsed;
|
|
210
|
+
};
|
|
189
211
|
/** Pages to keep from a web research call, and how much of each. */
|
|
190
212
|
const MAX_WEB_PAGES = 6;
|
|
191
213
|
const MAX_WEB_PAGE_CHARS = 6000;
|
|
@@ -354,9 +376,10 @@ const docdexToolDefinitions = (client, options) => [
|
|
|
354
376
|
// A judge that fails must not block a search that already succeeded.
|
|
355
377
|
}
|
|
356
378
|
}
|
|
357
|
-
|
|
379
|
+
const webQuery = normalizeWebQuery(query);
|
|
380
|
+
if (!localAnswers && webQuery && !webResearchBlocked()) {
|
|
358
381
|
try {
|
|
359
|
-
const web = await client.search(
|
|
382
|
+
const web = await client.search(webQuery, { limit, forceWeb: true });
|
|
360
383
|
if (hasWebFindings(web)) {
|
|
361
384
|
return toOutput(web);
|
|
362
385
|
}
|
|
@@ -629,6 +652,11 @@ const docdexToolDefinitions = (client, options) => [
|
|
|
629
652
|
// a central bank's interest rate came back sourced to this repository's
|
|
630
653
|
// own documentation. Anything genuinely local is what `docdex_search` is
|
|
631
654
|
// for; a caller can still ask for the mixed behaviour explicitly.
|
|
655
|
+
const normalizedQuery = normalizeWebQuery(query);
|
|
656
|
+
if (!normalizedQuery) {
|
|
657
|
+
// Spending a metered request to be told this is malformed helps nobody.
|
|
658
|
+
return toOutput({ query, pages: [], unavailable: "empty query" });
|
|
659
|
+
}
|
|
632
660
|
const blocked = webResearchBlocked();
|
|
633
661
|
if (blocked) {
|
|
634
662
|
// Answering "the web is unavailable" costs nothing; asking again costs
|
|
@@ -637,7 +665,7 @@ const docdexToolDefinitions = (client, options) => [
|
|
|
637
665
|
}
|
|
638
666
|
let result;
|
|
639
667
|
try {
|
|
640
|
-
result = await client.webResearch(
|
|
668
|
+
result = await client.webResearch(normalizedQuery, {
|
|
641
669
|
forceWeb: forceWeb ?? true,
|
|
642
670
|
skipLocalSearch,
|
|
643
671
|
webLimit,
|
|
@@ -657,7 +685,7 @@ const docdexToolDefinitions = (client, options) => [
|
|
|
657
685
|
// was standing in for.
|
|
658
686
|
if (!noCache && !hasWebContent(result)) {
|
|
659
687
|
try {
|
|
660
|
-
const fresh = await client.webResearch(
|
|
688
|
+
const fresh = await client.webResearch(normalizedQuery, {
|
|
661
689
|
forceWeb: forceWeb ?? true,
|
|
662
690
|
skipLocalSearch,
|
|
663
691
|
webLimit,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcoda/codali",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.122",
|
|
4
4
|
"description": "Standalone tool-runner adapter for mcoda.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@modelcontextprotocol/sdk": "1.30.0",
|
|
38
|
-
"@mcoda/db": "0.1.
|
|
39
|
-
"@mcoda/shared": "0.1.
|
|
38
|
+
"@mcoda/db": "0.1.122",
|
|
39
|
+
"@mcoda/shared": "0.1.122"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "tsc -p tsconfig.json",
|