@astralyn/pi 0.84.12 → 0.84.14
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/CHANGELOG.md +28 -0
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +2 -0
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/web-search/auth.d.ts +12 -0
- package/dist/extensions/web-search/auth.d.ts.map +1 -0
- package/dist/extensions/web-search/auth.js +90 -0
- package/dist/extensions/web-search/auth.js.map +1 -0
- package/dist/extensions/web-search/constants.d.ts +13 -0
- package/dist/extensions/web-search/constants.d.ts.map +1 -0
- package/dist/extensions/web-search/constants.js +26 -0
- package/dist/extensions/web-search/constants.js.map +1 -0
- package/dist/extensions/web-search/execute.d.ts +13 -0
- package/dist/extensions/web-search/execute.d.ts.map +1 -0
- package/dist/extensions/web-search/execute.js +101 -0
- package/dist/extensions/web-search/execute.js.map +1 -0
- package/dist/extensions/web-search/format.d.ts +12 -0
- package/dist/extensions/web-search/format.d.ts.map +1 -0
- package/dist/extensions/web-search/format.js +88 -0
- package/dist/extensions/web-search/format.js.map +1 -0
- package/dist/extensions/web-search/index.d.ts +6 -0
- package/dist/extensions/web-search/index.d.ts.map +1 -0
- package/dist/extensions/web-search/index.js +70 -0
- package/dist/extensions/web-search/index.js.map +1 -0
- package/dist/extensions/web-search/providers/deepseek.d.ts +13 -0
- package/dist/extensions/web-search/providers/deepseek.d.ts.map +1 -0
- package/dist/extensions/web-search/providers/deepseek.js +80 -0
- package/dist/extensions/web-search/providers/deepseek.js.map +1 -0
- package/dist/extensions/web-search/providers/http.d.ts +9 -0
- package/dist/extensions/web-search/providers/http.d.ts.map +1 -0
- package/dist/extensions/web-search/providers/http.js +87 -0
- package/dist/extensions/web-search/providers/http.js.map +1 -0
- package/dist/extensions/web-search/providers/minimax.d.ts +12 -0
- package/dist/extensions/web-search/providers/minimax.d.ts.map +1 -0
- package/dist/extensions/web-search/providers/minimax.js +50 -0
- package/dist/extensions/web-search/providers/minimax.js.map +1 -0
- package/dist/extensions/web-search/render.d.ts +10 -0
- package/dist/extensions/web-search/render.d.ts.map +1 -0
- package/dist/extensions/web-search/render.js +103 -0
- package/dist/extensions/web-search/render.js.map +1 -0
- package/dist/extensions/web-search/results.d.ts +28 -0
- package/dist/extensions/web-search/results.d.ts.map +1 -0
- package/dist/extensions/web-search/results.js +154 -0
- package/dist/extensions/web-search/results.js.map +1 -0
- package/dist/extensions/web-search/schema.d.ts +10 -0
- package/dist/extensions/web-search/schema.d.ts.map +1 -0
- package/dist/extensions/web-search/schema.js +36 -0
- package/dist/extensions/web-search/schema.js.map +1 -0
- package/dist/extensions/web-search/types.d.ts +49 -0
- package/dist/extensions/web-search/types.d.ts.map +1 -0
- package/dist/extensions/web-search/types.js +5 -0
- package/dist/extensions/web-search/types.js.map +1 -0
- package/docs/bundled/README.md +1 -0
- package/docs/bundled/extensions/web-search.md +46 -0
- package/docs/docs.json +4 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../../src/extensions/web-search/results.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AACpC,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AACpC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AACtC,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AACnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAC7C,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AACzC,MAAM,CAAC,M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AAC;IACxC,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC;SACrC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;IAE5B,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,eAAe,EAAE,eAAe,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS;QAC5E,iBAAiB;KACjB,CAAC;AACH,CAAC","sourcesContent":["/**\n * Result normalization, bounding, deduplication, and ranking for web_search providers.\n */\n\nimport type { ProviderSearchResult, SearchEngineSource, WebSearchHit } from \"./types.ts\";\n\nexport const MAX_OUTPUT_HITS = 12;\nexport const MAX_QUERY_LENGTH = 500;\nexport const MAX_TITLE_LENGTH = 200;\nexport const MAX_URL_LENGTH = 2048;\nexport const MAX_SNIPPET_LENGTH = 200;\nexport const MAX_DATE_LENGTH = 100;\nexport const MAX_RELATED_SEARCHES = 8;\nexport const MAX_RELATED_SEARCH_LENGTH = 200;\nexport const MAX_SYNTHESIS_LENGTH = 6000;\nexport const MAX_ERROR_MESSAGE_LENGTH = 500;\n\nconst RRF_K = 60;\nconst TRACKING_PARAMS = new Set([\n\t\"utm_source\",\n\t\"utm_medium\",\n\t\"utm_campaign\",\n\t\"utm_term\",\n\t\"utm_content\",\n\t\"ref\",\n\t\"fbclid\",\n\t\"gclid\",\n\t\"trk\",\n\t\"gi\",\n]);\n\ninterface FusionCandidate {\n\thit: WebSearchHit;\n\tranks: Map<SearchEngineSource, number>;\n}\n\nexport interface FusedSearchResults {\n\thits: WebSearchHit[];\n\trelatedSearches?: string[];\n\tdeepseekSynthesis?: string;\n}\n\nfunction truncateText(text: string, maxLength: number): string {\n\tif (text.length <= maxLength) return text;\n\tif (maxLength <= 3) return text.slice(0, maxLength);\n\treturn `${text.slice(0, maxLength - 3).trimEnd()}...`;\n}\n\n/** Normalize and bound a provider-controlled single-line text field. */\nexport function boundSingleLineText(value: string | undefined, maxLength: number): string | undefined {\n\tconst normalized = value?.replace(/\\s+/g, \" \").trim();\n\treturn normalized ? truncateText(normalized, maxLength) : undefined;\n}\n\n/** Trim and bound provider-controlled text that intentionally preserves lines. */\nexport function boundMultilineText(value: string | undefined, maxLength: number): string | undefined {\n\tconst normalized = value?.trim();\n\treturn normalized ? truncateText(normalized, maxLength) : undefined;\n}\n\n/** Normalize a usable HTTP(S) source URL without changing non-tracking query values. */\nexport function normalizeUrl(rawUrl: string): string | undefined {\n\tconst trimmed = rawUrl.trim();\n\tif (!trimmed || trimmed.length > MAX_URL_LENGTH) return undefined;\n\n\ttry {\n\t\tconst url = new URL(trimmed);\n\t\tif (url.protocol !== \"http:\" && url.protocol !== \"https:\") return undefined;\n\t\turl.hash = \"\";\n\t\tfor (const parameter of TRACKING_PARAMS) {\n\t\t\tif (url.searchParams.has(parameter)) url.searchParams.delete(parameter);\n\t\t}\n\t\tif (url.pathname.length > 1 && url.pathname.endsWith(\"/\")) {\n\t\t\turl.pathname = url.pathname.replace(/\\/+$/, \"\");\n\t\t}\n\t\tconst normalized = url.toString();\n\t\treturn normalized.length <= MAX_URL_LENGTH ? normalized : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction normalizeHit(hit: WebSearchHit, source: SearchEngineSource): WebSearchHit | undefined {\n\tconst url = normalizeUrl(hit.url);\n\tif (!url) return undefined;\n\n\treturn {\n\t\ttitle: boundSingleLineText(hit.title, MAX_TITLE_LENGTH) ?? url,\n\t\turl,\n\t\tsnippet: boundSingleLineText(hit.snippet, MAX_SNIPPET_LENGTH),\n\t\tdate: boundSingleLineText(hit.date, MAX_DATE_LENGTH),\n\t\tsources: [...new Set([...hit.sources, source])],\n\t};\n}\n\nfunction isUrlFallbackTitle(title: string, url: string): boolean {\n\tconst normalizedTitle = normalizeUrl(title);\n\treturn normalizedTitle !== undefined && normalizedTitle === normalizeUrl(url);\n}\n\nfunction reciprocalRankScore(candidate: FusionCandidate): number {\n\tlet score = 0;\n\tfor (const rank of candidate.ranks.values()) score += 1 / (RRF_K + rank);\n\treturn score;\n}\n\nfunction bestRank(candidate: FusionCandidate): number {\n\treturn Math.min(...candidate.ranks.values());\n}\n\n/** Bound provider results, deduplicate URLs, and rank them with reciprocal-rank fusion. */\nexport function fuseSearchHits(results: ProviderSearchResult[]): FusedSearchResults {\n\tconst candidates = new Map<string, FusionCandidate>();\n\tconst relatedSearches = new Set<string>();\n\tlet deepseekSynthesis: string | undefined;\n\n\tfor (const result of results) {\n\t\tfor (const related of result.relatedSearches ?? []) {\n\t\t\tif (relatedSearches.size >= MAX_RELATED_SEARCHES) break;\n\t\t\tconst normalized = boundSingleLineText(related, MAX_RELATED_SEARCH_LENGTH);\n\t\t\tif (normalized) relatedSearches.add(normalized);\n\t\t}\n\t\tconst synthesis = boundMultilineText(result.synthesisText, MAX_SYNTHESIS_LENGTH);\n\t\tif (synthesis) deepseekSynthesis = synthesis;\n\n\t\tfor (const [index, rawHit] of result.hits.entries()) {\n\t\t\tconst hit = normalizeHit(rawHit, result.source);\n\t\t\tif (!hit) continue;\n\t\t\tconst rank = index + 1;\n\t\t\tconst existing = candidates.get(hit.url);\n\n\t\t\tif (!existing) {\n\t\t\t\tcandidates.set(hit.url, { hit, ranks: new Map([[result.source, rank]]) });\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst previousRank = existing.ranks.get(result.source);\n\t\t\tif (previousRank === undefined || rank < previousRank) existing.ranks.set(result.source, rank);\n\t\t\tfor (const source of hit.sources) {\n\t\t\t\tif (!existing.hit.sources.includes(source)) existing.hit.sources.push(source);\n\t\t\t}\n\t\t\tif (isUrlFallbackTitle(existing.hit.title, existing.hit.url) && !isUrlFallbackTitle(hit.title, hit.url)) {\n\t\t\t\texisting.hit.title = hit.title;\n\t\t\t}\n\t\t\tif ((!existing.hit.snippet || existing.hit.snippet.length < (hit.snippet?.length ?? 0)) && hit.snippet) {\n\t\t\t\texisting.hit.snippet = hit.snippet;\n\t\t\t}\n\t\t\tif (!existing.hit.date && hit.date) existing.hit.date = hit.date;\n\t\t}\n\t}\n\n\tconst ranked = [...candidates.entries()]\n\t\t.sort(([leftUrl, left], [rightUrl, right]) => {\n\t\t\tconst scoreDifference = reciprocalRankScore(right) - reciprocalRankScore(left);\n\t\t\tif (scoreDifference !== 0) return scoreDifference;\n\t\t\tconst rankDifference = bestRank(left) - bestRank(right);\n\t\t\tif (rankDifference !== 0) return rankDifference;\n\t\t\treturn leftUrl.localeCompare(rightUrl);\n\t\t})\n\t\t.map(([, candidate]) => candidate.hit)\n\t\t.slice(0, MAX_OUTPUT_HITS);\n\n\treturn {\n\t\thits: ranked,\n\t\trelatedSearches: relatedSearches.size > 0 ? [...relatedSearches] : undefined,\n\t\tdeepseekSynthesis,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* schema.ts — TypeBox parameter schema and argument normalizer for web_search.
|
|
3
|
+
*/
|
|
4
|
+
import { type Static, Type } from "typebox";
|
|
5
|
+
export declare const WebSearchParamsSchema: Type.TObject<{
|
|
6
|
+
query: Type.TString;
|
|
7
|
+
}>;
|
|
8
|
+
export type WebSearchParams = Static<typeof WebSearchParamsSchema>;
|
|
9
|
+
export declare function normalizeWebSearchParams(raw: unknown): WebSearchParams;
|
|
10
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/extensions/web-search/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,eAAO,MAAM,qBAAqB;;EAMhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEnE,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CAuBtE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* schema.ts — TypeBox parameter schema and argument normalizer for web_search.
|
|
3
|
+
*/
|
|
4
|
+
import { Type } from "typebox";
|
|
5
|
+
import { MAX_QUERY_LENGTH } from "./results.js";
|
|
6
|
+
export const WebSearchParamsSchema = Type.Object({
|
|
7
|
+
query: Type.String({
|
|
8
|
+
minLength: 1,
|
|
9
|
+
maxLength: MAX_QUERY_LENGTH,
|
|
10
|
+
description: "The search query. Aim for 3-5 keywords; include a year when freshness matters.",
|
|
11
|
+
}),
|
|
12
|
+
});
|
|
13
|
+
export function normalizeWebSearchParams(raw) {
|
|
14
|
+
if (typeof raw === "string") {
|
|
15
|
+
return { query: raw.trim() };
|
|
16
|
+
}
|
|
17
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
18
|
+
return { query: String(raw ?? "").trim() };
|
|
19
|
+
}
|
|
20
|
+
const record = raw;
|
|
21
|
+
let query = "";
|
|
22
|
+
if (typeof record.query === "string") {
|
|
23
|
+
query = record.query.trim();
|
|
24
|
+
}
|
|
25
|
+
else if (typeof record.q === "string") {
|
|
26
|
+
query = record.q.trim();
|
|
27
|
+
}
|
|
28
|
+
else if (typeof record.search_query === "string") {
|
|
29
|
+
query = record.search_query.trim();
|
|
30
|
+
}
|
|
31
|
+
else if (typeof record.prompt === "string") {
|
|
32
|
+
query = record.prompt.trim();
|
|
33
|
+
}
|
|
34
|
+
return { query };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/extensions/web-search/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,CAAC,MAAM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C","sourcesContent":["/**\n * schema.ts — TypeBox parameter schema and argument normalizer for web_search.\n */\n\nimport { type Static, Type } from \"typebox\";\nimport { MAX_QUERY_LENGTH } from \"./results.ts\";\n\nexport const WebSearchParamsSchema = Type.Object({\n\tquery: Type.String({\n\t\tminLength: 1,\n\t\tmaxLength: MAX_QUERY_LENGTH,\n\t\tdescription: \"The search query. Aim for 3-5 keywords; include a year when freshness matters.\",\n\t}),\n});\n\nexport type WebSearchParams = Static<typeof WebSearchParamsSchema>;\n\nexport function normalizeWebSearchParams(raw: unknown): WebSearchParams {\n\tif (typeof raw === \"string\") {\n\t\treturn { query: raw.trim() };\n\t}\n\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) {\n\t\treturn { query: String(raw ?? \"\").trim() };\n\t}\n\n\tconst record = raw as Record<string, unknown>;\n\n\tlet query = \"\";\n\tif (typeof record.query === \"string\") {\n\t\tquery = record.query.trim();\n\t} else if (typeof record.q === \"string\") {\n\t\tquery = record.q.trim();\n\t} else if (typeof record.search_query === \"string\") {\n\t\tquery = record.search_query.trim();\n\t} else if (typeof record.prompt === \"string\") {\n\t\tquery = record.prompt.trim();\n\t}\n\n\treturn { query };\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* types.ts — Type definitions for web_search extension providers and fusion engine.
|
|
3
|
+
*/
|
|
4
|
+
export type SearchEngineType = "minimax" | "deepseek" | "dual" | "none";
|
|
5
|
+
export type SearchEngineSource = "MiniMax" | "DeepSeek";
|
|
6
|
+
export interface WebSearchHit {
|
|
7
|
+
title: string;
|
|
8
|
+
url: string;
|
|
9
|
+
snippet?: string;
|
|
10
|
+
date?: string;
|
|
11
|
+
sources: SearchEngineSource[];
|
|
12
|
+
}
|
|
13
|
+
export interface WebSearchDetails {
|
|
14
|
+
query: string;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
status: "success" | "error" | "disabled";
|
|
17
|
+
engine: SearchEngineType;
|
|
18
|
+
totalHits: number;
|
|
19
|
+
hits: WebSearchHit[];
|
|
20
|
+
relatedSearches?: string[];
|
|
21
|
+
deepseekSynthesis?: string;
|
|
22
|
+
errorMessage?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* MiniMax search credential. `host` is always present alongside `key` so
|
|
26
|
+
* callers never guard the two separately.
|
|
27
|
+
*/
|
|
28
|
+
export interface MiniMaxSearchCredential {
|
|
29
|
+
key: string;
|
|
30
|
+
host: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolved credentials: presence of a group means that engine is configured,
|
|
34
|
+
* so impossible states (mode without key, key without host) are unrepresentable.
|
|
35
|
+
* Use `configuredEngine()` from auth.ts to derive the SearchEngineType label.
|
|
36
|
+
*/
|
|
37
|
+
export interface ResolvedSearchCredentials {
|
|
38
|
+
minimax?: MiniMaxSearchCredential;
|
|
39
|
+
deepseek?: {
|
|
40
|
+
key: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface ProviderSearchResult {
|
|
44
|
+
source: SearchEngineSource;
|
|
45
|
+
hits: WebSearchHit[];
|
|
46
|
+
relatedSearches?: string[];
|
|
47
|
+
synthesisText?: string;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/extensions/web-search/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AACxE,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,UAAU,CAAC;AAExD,MAAM,WAAW,YAAY;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;IACzC,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,YAAY,EAAE,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACzC,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,QAAQ,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,IAAI,EAAE,YAAY,EAAE,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/extensions/web-search/types.ts"],"names":[],"mappings":"AAAA;;GAEG","sourcesContent":["/**\n * types.ts — Type definitions for web_search extension providers and fusion engine.\n */\n\nexport type SearchEngineType = \"minimax\" | \"deepseek\" | \"dual\" | \"none\";\nexport type SearchEngineSource = \"MiniMax\" | \"DeepSeek\";\n\nexport interface WebSearchHit {\n\ttitle: string;\n\turl: string;\n\tsnippet?: string;\n\tdate?: string;\n\tsources: SearchEngineSource[];\n}\n\nexport interface WebSearchDetails {\n\tquery: string;\n\tdurationMs: number;\n\tstatus: \"success\" | \"error\" | \"disabled\";\n\tengine: SearchEngineType;\n\ttotalHits: number;\n\thits: WebSearchHit[];\n\trelatedSearches?: string[];\n\tdeepseekSynthesis?: string;\n\terrorMessage?: string;\n}\n\n/**\n * MiniMax search credential. `host` is always present alongside `key` so\n * callers never guard the two separately.\n */\nexport interface MiniMaxSearchCredential {\n\tkey: string;\n\thost: string;\n}\n\n/**\n * Resolved credentials: presence of a group means that engine is configured,\n * so impossible states (mode without key, key without host) are unrepresentable.\n * Use `configuredEngine()` from auth.ts to derive the SearchEngineType label.\n */\nexport interface ResolvedSearchCredentials {\n\tminimax?: MiniMaxSearchCredential;\n\tdeepseek?: { key: string };\n}\n\nexport interface ProviderSearchResult {\n\tsource: SearchEngineSource;\n\thits: WebSearchHit[];\n\trelatedSearches?: string[];\n\tsynthesisText?: string;\n}\n"]}
|
package/docs/bundled/README.md
CHANGED
|
@@ -16,6 +16,7 @@ These hidden built-ins use the same public Extension API available to external e
|
|
|
16
16
|
| [Statusline](extensions/statusline.md) | Footer status | Show concise extension-managed activity state |
|
|
17
17
|
| [Subagent](extensions/subagent.md) | `subagent`, `/agents` | Delegate bounded work to isolated child Pi sessions |
|
|
18
18
|
| [Todo](extensions/todo.md) | `todo`, `/todos` | Track ordered multi-step work in a compact one-line widget |
|
|
19
|
+
| [Web Search](extensions/web-search.md) | `web_search` | Search the live web through MiniMax and DeepSeek with fused results |
|
|
19
20
|
|
|
20
21
|
## Context safety
|
|
21
22
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Web Search
|
|
2
|
+
|
|
3
|
+
`web_search` is a Pi-native tool for querying live web information through MiniMax and DeepSeek search engines.
|
|
4
|
+
|
|
5
|
+
When both engines are configured, searches run concurrently and results are fused with reciprocal-rank scoring: URLs are normalized (tracking parameters and fragments stripped), duplicates are merged, and high-ranked results from both engines remain represented.
|
|
6
|
+
|
|
7
|
+
| Engine mode | Requirement |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `dual` | Both MiniMax and DeepSeek keys configured |
|
|
10
|
+
| `minimax` | Only a MiniMax key configured |
|
|
11
|
+
| `deepseek` | Only a DeepSeek key configured |
|
|
12
|
+
| `none` | No key found — the tool reports itself disabled |
|
|
13
|
+
|
|
14
|
+
## Credentials
|
|
15
|
+
|
|
16
|
+
Keys are resolved per provider through the runtime's canonical auth chain (`ModelRuntime.getAuth`: runtime API key → `auth.json` → `models.json` → environment). When no runtime is available (or it does not know the provider), the extension falls back to reading `auth.json` directly (provider IDs `minimax-cn`, `minimax`, `deepseek`, including command-configured keys such as `"!op read ..."`) and then the environment variables `MINIMAX_CN_API_KEY`, `MINIMAX_API_KEY`, `DEEPSEEK_API_KEY`.
|
|
17
|
+
|
|
18
|
+
The MiniMax CN account (`minimax-cn`) is preferred over the global one (`minimax`) and selects the `api.minimaxi.com` search host; the global account uses `api.minimax.io`, overridable via `MINIMAX_API_HOST`.
|
|
19
|
+
|
|
20
|
+
Configure with `/login minimax-cn` or `/login deepseek`, or by exporting the environment variables above.
|
|
21
|
+
|
|
22
|
+
When no key is configured, `web_search` is removed from the model's tool set and system prompt entirely — the model never sees or calls it. This is re-evaluated on every session start (`startup`, `/new`, `/reload`, resume, fork), so a mid-session `/login` takes effect from the next session onward. The tool stays registered: it remains listed in `/tools` (where it can be force-enabled, in which case calls fail with the disabled message), and historical sessions render normally.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Parameters
|
|
27
|
+
|
|
28
|
+
- `query`: the search query, up to 500 characters — 3–5 keywords work best; include a year when freshness matters.
|
|
29
|
+
|
|
30
|
+
### Output
|
|
31
|
+
|
|
32
|
+
The model-facing payload is Markdown containing up to 12 HTTP(S) source results. Titles and snippets are bounded to 200 characters each, source URLs to 2048 characters, DeepSeek synthesis to 6000 characters, and up to 8 related searches to 200 characters each. Results found by both providers are tagged as such; this means the URL appeared in both result sets, not that its claims were independently verified. When structured source URLs are present, the tool result reminds the model to cite the relevant URLs without prescribing a heading or response format.
|
|
33
|
+
|
|
34
|
+
## Limits
|
|
35
|
+
|
|
36
|
+
- With no configured key the tool is hidden from the model (see Credentials); the disabled message only appears when the tool was force-enabled via `/tools` without keys.
|
|
37
|
+
- Engine failures are independent: if one engine errors, the other's results are still returned; the tool errors only when every configured engine fails.
|
|
38
|
+
- MiniMax search uses the Coding Plan Search endpoint (`POST /v1/coding_plan/search`), which requires a Coding Plan key — a standard MiniMax API key may be rejected upstream.
|
|
39
|
+
- DeepSeek search goes through the Anthropic-compatible endpoint (`/anthropic/v1/messages`, model `claude-sonnet-search`) with the server-side `web_search_20250305` tool; the request uses `max_tokens: 1024`, followed by the local output bound above.
|
|
40
|
+
- Requests time out after 60 seconds (MiniMax) or 90 seconds (DeepSeek) and surface as Pi tool errors. Successful upstream response bodies are limited to 2 MiB, error bodies to 200 bytes, and model-facing error messages to 500 characters.
|
|
41
|
+
|
|
42
|
+
## Implementation notes
|
|
43
|
+
|
|
44
|
+
The extension keeps presentation Pi-native: the call line shows the query, in-flight renders show the engine label with elapsed time past 2s, the collapsed result shows hit count, engines, duration, and a top-domain preview with the configured expand hint, and expanding renders the result sections from `details` — without the model-facing agent directives — falling back to the raw payload for legacy entries.
|
|
45
|
+
|
|
46
|
+
Credential resolution never inspects `getProviderAuthStatus` — that probe returns a truthy `AuthStatus` object even when nothing is configured and carries no key. Only `getAuth` returns usable key material.
|
package/docs/docs.json
CHANGED
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astralyn/pi",
|
|
3
|
-
"version": "0.84.
|
|
3
|
+
"version": "0.84.14",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@astralyn/pi",
|
|
9
|
-
"version": "0.84.
|
|
9
|
+
"version": "0.84.14",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@earendil-works/pi-agent-core": "0.84.4",
|