@introspection-ai/recipes 0.50.0 → 0.51.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/dist/connector-tools.d.ts.map +1 -1
- package/dist/connector-tools.js +1 -4
- package/dist/connector-tools.js.map +1 -1
- package/dist/documents/module.d.ts.map +1 -1
- package/dist/documents/module.js +1 -3
- package/dist/documents/module.js.map +1 -1
- package/dist/egress.d.ts +23 -0
- package/dist/egress.d.ts.map +1 -0
- package/dist/egress.js +36 -0
- package/dist/egress.js.map +1 -0
- package/dist/productivity/http.d.ts.map +1 -1
- package/dist/productivity/http.js +8 -21
- package/dist/productivity/http.js.map +1 -1
- package/dist/productivity/module.d.ts.map +1 -1
- package/dist/productivity/module.js +1 -3
- package/dist/productivity/module.js.map +1 -1
- package/dist/recipe/companions.d.ts +2 -1
- package/dist/recipe/companions.d.ts.map +1 -1
- package/dist/recipe/companions.js +11 -9
- package/dist/recipe/companions.js.map +1 -1
- package/dist/recipe/manifest.generated.d.ts +2 -1
- package/dist/recipe/manifest.generated.d.ts.map +1 -1
- package/dist/recipe/manifest.generated.js +3 -2
- package/dist/recipe/manifest.generated.js.map +1 -1
- package/dist/search/egress.d.ts +12 -0
- package/dist/search/egress.d.ts.map +1 -0
- package/dist/search/egress.js +24 -0
- package/dist/search/egress.js.map +1 -0
- package/dist/search/http.d.ts +16 -0
- package/dist/search/http.d.ts.map +1 -0
- package/dist/search/http.js +75 -0
- package/dist/search/http.js.map +1 -0
- package/dist/search/index.d.ts +9 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +5 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/mcp.d.ts +58 -0
- package/dist/search/mcp.d.ts.map +1 -0
- package/dist/search/mcp.js +84 -0
- package/dist/search/mcp.js.map +1 -0
- package/dist/search/module.d.ts +16 -0
- package/dist/search/module.d.ts.map +1 -0
- package/dist/search/module.js +27 -0
- package/dist/search/module.js.map +1 -0
- package/dist/search/tool.d.ts +96 -0
- package/dist/search/tool.d.ts.map +1 -0
- package/dist/search/tool.js +505 -0
- package/dist/search/tool.js.map +1 -0
- package/dist/search/types.d.ts +247 -0
- package/dist/search/types.d.ts.map +1 -0
- package/dist/search/types.js +60 -0
- package/dist/search/types.js.map +1 -0
- package/docs/README.md +1 -0
- package/docs/mcp-configuration.md +2 -1
- package/docs/search/README.md +801 -0
- package/package.json +10 -5
- package/skills/search/SKILL.md +72 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { parseRetryAfter } from "../egress.js";
|
|
2
|
+
import { SearchProviderError, } from "./types.js";
|
|
3
|
+
/** Sends one request for a provider and maps a failure to a typed error. */
|
|
4
|
+
export async function requestJson(provider, context, path, init) {
|
|
5
|
+
let response;
|
|
6
|
+
try {
|
|
7
|
+
response = await context.fetch(`${context.baseUrl}${path}`, {
|
|
8
|
+
method: init.method,
|
|
9
|
+
headers: {
|
|
10
|
+
Accept: "application/json",
|
|
11
|
+
...(init.body !== undefined
|
|
12
|
+
? { "Content-Type": "application/json" }
|
|
13
|
+
: {}),
|
|
14
|
+
...init.headers,
|
|
15
|
+
...context.credentialHeaders,
|
|
16
|
+
},
|
|
17
|
+
...(init.body !== undefined ? { body: JSON.stringify(init.body) } : {}),
|
|
18
|
+
...(context.signal ? { signal: context.signal } : {}),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (context.signal?.aborted)
|
|
23
|
+
throw error;
|
|
24
|
+
throw new SearchProviderError({
|
|
25
|
+
code: "unavailable",
|
|
26
|
+
message: `${provider} could not be reached: ${error instanceof Error ? error.message : String(error)}`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
const detail = (await response.text().catch(() => "")).slice(0, 200);
|
|
31
|
+
const retryAfter = retryAfterSeconds(response.headers.get("retry-after"), context.now());
|
|
32
|
+
throw new SearchProviderError({
|
|
33
|
+
code: codeFor(response.status),
|
|
34
|
+
message: `${provider} answered ${response.status}${response.status === 402 ? ": the provider account is out of credit" : ""}${detail ? `: ${detail}` : ""}`,
|
|
35
|
+
status: response.status,
|
|
36
|
+
...(retryAfter ? { retry_after_seconds: retryAfter } : {}),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return response.json();
|
|
40
|
+
}
|
|
41
|
+
function codeFor(status) {
|
|
42
|
+
if (status === 429)
|
|
43
|
+
return "too_many_requests";
|
|
44
|
+
if (status === 401 || status === 403)
|
|
45
|
+
return "not_configured";
|
|
46
|
+
if (status === 402)
|
|
47
|
+
return "out_of_credit";
|
|
48
|
+
if (status === 400 || status === 422)
|
|
49
|
+
return "invalid_request";
|
|
50
|
+
if (status >= 500)
|
|
51
|
+
return "unavailable";
|
|
52
|
+
return "provider_error";
|
|
53
|
+
}
|
|
54
|
+
/** `Retry-After` as whole seconds from now, when there is a wait left. */
|
|
55
|
+
function retryAfterSeconds(value, now) {
|
|
56
|
+
const seconds = parseRetryAfter(value, now.getTime());
|
|
57
|
+
return seconds !== undefined && seconds > 0 ? Math.ceil(seconds) : undefined;
|
|
58
|
+
}
|
|
59
|
+
const REGIONS = new Intl.DisplayNames(["en"], { type: "region" });
|
|
60
|
+
/** Region codes ICU names that are not countries: the EU, the eurozone, the UN, outlying Oceania. */
|
|
61
|
+
const NOT_COUNTRIES = new Set(["EU", "EZ", "UN", "QO"]);
|
|
62
|
+
/** An assigned ISO 3166-1 alpha-2 code: one with an English name of its own. */
|
|
63
|
+
export function isCountryCode(code) {
|
|
64
|
+
if (!/^[A-Z]{2}$/.test(code) || NOT_COUNTRIES.has(code))
|
|
65
|
+
return false;
|
|
66
|
+
try {
|
|
67
|
+
const name = REGIONS.of(code);
|
|
68
|
+
// ICU names an unassigned code "Unknown Region" rather than echoing it.
|
|
69
|
+
return Boolean(name) && name !== code && name !== "Unknown Region";
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
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
1
|
+
export { boundSearchProviders, createWebSearch, formatWebSearch, registerWebSearchTool, SEARCH_SKILL, SEARCH_TOOL_NAME, webSearchMcpToolNames, webSearchParameters, } from "./tool.js";
|
|
2
|
+
export type { SearchBindings, WebSearch, WebSearchCall, WebSearchOptions, } from "./tool.js";
|
|
3
|
+
export type { McpCallToolResult, PiToolInfo } from "./mcp.js";
|
|
4
|
+
export { egressCredentialHeaders } from "./egress.js";
|
|
5
|
+
export type { SearchEnvironment } from "./egress.js";
|
|
6
|
+
export { loadSearchProviders, SEARCH_PROVIDERS_PACKAGE } from "./module.js";
|
|
7
|
+
export { SEARCH_CONTENT, SEARCH_CONTENT_CHARS, SEARCH_DEFAULT_RESULTS, SEARCH_ERROR_CODES, SEARCH_FRESHNESS, SEARCH_MAX_RESULTS, SEARCH_MODES, SEARCH_OPTIONS, SEARCH_PROVIDER_API_VERSION, SEARCH_PROVIDER_IDS, SearchProviderError, } from "./types.js";
|
|
8
|
+
export type { RecipeSearchModule, SearchCallContext, SearchCapabilities, SearchContent, SearchErrorCode, SearchErrorInfo, SearchFetch, SearchFreshness, SearchMcpAdapter, SearchMcpPlan, SearchMode, SearchModeMapping, SearchNote, SearchOption, SearchProviderId, SearchProviderModule, SearchProviderResult, SearchProviders, SearchRequest, SearchResultItem, SearchSupport, SearchUnits, WebSearchArgs, WebSearchResult, } from "./types.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,gBAAgB,GACjB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,eAAe,EACf,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,aAAa,EACb,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { boundSearchProviders, createWebSearch, formatWebSearch, registerWebSearchTool, SEARCH_SKILL, SEARCH_TOOL_NAME, webSearchMcpToolNames, webSearchParameters, } from "./tool.js";
|
|
2
|
+
export { egressCredentialHeaders } from "./egress.js";
|
|
3
|
+
export { loadSearchProviders, SEARCH_PROVIDERS_PACKAGE } from "./module.js";
|
|
4
|
+
export { SEARCH_CONTENT, SEARCH_CONTENT_CHARS, SEARCH_DEFAULT_RESULTS, SEARCH_ERROR_CODES, SEARCH_FRESHNESS, SEARCH_MAX_RESULTS, SEARCH_MODES, SEARCH_OPTIONS, SEARCH_PROVIDER_API_VERSION, SEARCH_PROVIDER_IDS, SearchProviderError, } from "./types.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AAQnB,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ToolInfo } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type Tracer } from "@opentelemetry/api";
|
|
3
|
+
/** An MCP `CallToolResult`, without `_meta`: what a search provider's MCP tool answers. */
|
|
4
|
+
export interface McpCallToolResult {
|
|
5
|
+
content?: Array<{
|
|
6
|
+
type: string;
|
|
7
|
+
text?: string;
|
|
8
|
+
}>;
|
|
9
|
+
structuredContent?: unknown;
|
|
10
|
+
isError?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The MCP calls `web_search` makes: whether a bound server offers a tool,
|
|
14
|
+
* and one call to it. Pi's built-in MCP client backs it in a session
|
|
15
|
+
* ({@link piSearchMcpClient}); any other client, or a test, can too.
|
|
16
|
+
*/
|
|
17
|
+
export interface SearchMcpClient {
|
|
18
|
+
hasTool(server: string, tool: string): boolean;
|
|
19
|
+
callTool(server: string, tool: string, args: Record<string, unknown>, signal?: AbortSignal): Promise<McpCallToolResult>;
|
|
20
|
+
}
|
|
21
|
+
/** The part of Pi's tool context `web_search` uses (`ExtensionToolContext`). */
|
|
22
|
+
export interface PiToolContext {
|
|
23
|
+
readonly tools: readonly {
|
|
24
|
+
name: string;
|
|
25
|
+
}[];
|
|
26
|
+
executeTool(name: string, args: unknown, options?: {
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
isError: boolean;
|
|
30
|
+
result: {
|
|
31
|
+
content: Array<{
|
|
32
|
+
type: string;
|
|
33
|
+
text?: string;
|
|
34
|
+
}>;
|
|
35
|
+
structuredContent?: unknown;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
/** What Pi says of a registered tool (`pi.getAllTools()`), enough to tell its MCP server. */
|
|
40
|
+
export type PiToolInfo = Pick<ToolInfo, "name" | "namespace">;
|
|
41
|
+
/**
|
|
42
|
+
* The MCP client over Pi's built-in one: each server a Recipe binds on Pi's
|
|
43
|
+
* client (`mcp.mode: codemode`, or any mode with `behind`) is connected in
|
|
44
|
+
* the Pi process, and its tools are reachable as `mcpToolName(server, tool)`
|
|
45
|
+
* through `ctx.executeTool`. `toolInfos` (the extension's `pi.getAllTools`)
|
|
46
|
+
* confirms that a tool so named is the server's by Pi's namespace; without
|
|
47
|
+
* it, the name alone decides. Pi returns the whole `CallToolResult` as the
|
|
48
|
+
* nested call's `structuredContent`; a call Pi refuses (unknown tool,
|
|
49
|
+
* blocked) has none.
|
|
50
|
+
*/
|
|
51
|
+
export declare function piSearchMcpClient(ctx: PiToolContext, toolInfos?: () => readonly PiToolInfo[]): SearchMcpClient;
|
|
52
|
+
/**
|
|
53
|
+
* One MCP tool call inside a client span, a child of the `web_search` span,
|
|
54
|
+
* after the MCP semantic conventions (as the Google productivity provider
|
|
55
|
+
* records its own). An `isError` result maps to `provider_error`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function tracedMcpCall(tracer: Tracer, client: SearchMcpClient, server: string, tool: string, args: Record<string, unknown>, signal?: AbortSignal): Promise<McpCallToolResult>;
|
|
58
|
+
//# sourceMappingURL=mc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C,EAAE,OAAO,CAAC;SAC7B,CAAC;KACH,CAAC,CAAC;CACJ;AAED,6FAA6F;AAC7F,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC;AAE9D;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,aAAa,EAClB,SAAS,CAAC,EAAE,MAAM,SAAS,UAAU,EAAE,GACtC,eAAe,CA4BjB;AAUD;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,iBAAiB,CAAC,CAmC5B"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
2
|
+
import { isPiMcpServerTool, mcpToolName } from "../mcp/pi-client.js";
|
|
3
|
+
import { SearchProviderError } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* The MCP client over Pi's built-in one: each server a Recipe binds on Pi's
|
|
6
|
+
* client (`mcp.mode: codemode`, or any mode with `behind`) is connected in
|
|
7
|
+
* the Pi process, and its tools are reachable as `mcpToolName(server, tool)`
|
|
8
|
+
* through `ctx.executeTool`. `toolInfos` (the extension's `pi.getAllTools`)
|
|
9
|
+
* confirms that a tool so named is the server's by Pi's namespace; without
|
|
10
|
+
* it, the name alone decides. Pi returns the whole `CallToolResult` as the
|
|
11
|
+
* nested call's `structuredContent`; a call Pi refuses (unknown tool,
|
|
12
|
+
* blocked) has none.
|
|
13
|
+
*/
|
|
14
|
+
export function piSearchMcpClient(ctx, toolInfos) {
|
|
15
|
+
return {
|
|
16
|
+
hasTool(server, tool) {
|
|
17
|
+
const name = mcpToolName(server, tool);
|
|
18
|
+
if (!ctx.tools.some((candidate) => candidate.name === name))
|
|
19
|
+
return false;
|
|
20
|
+
const info = toolInfos?.().find((candidate) => candidate.name === name);
|
|
21
|
+
return info ? isPiMcpServerTool(info, server) : true;
|
|
22
|
+
},
|
|
23
|
+
async callTool(server, tool, args, signal) {
|
|
24
|
+
const outcome = await ctx.executeTool(mcpToolName(server, tool), args, signal ? { signal } : {});
|
|
25
|
+
const result = outcome.result.structuredContent;
|
|
26
|
+
if (result && typeof result === "object" && "content" in result)
|
|
27
|
+
return result;
|
|
28
|
+
const text = outcome.result.content
|
|
29
|
+
.map((block) => block.text ?? "")
|
|
30
|
+
.join(" ")
|
|
31
|
+
.trim();
|
|
32
|
+
throw new SearchProviderError({
|
|
33
|
+
code: "unavailable",
|
|
34
|
+
message: `MCP tool ${server}/${tool} could not be called${text ? `: ${text.slice(0, 200)}` : ""}`,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** The text of a result's text blocks, joined. */
|
|
40
|
+
function mcpResultText(result) {
|
|
41
|
+
return (result.content ?? [])
|
|
42
|
+
.filter((block) => block.type === "text" && typeof block.text === "string")
|
|
43
|
+
.map((block) => block.text)
|
|
44
|
+
.join("\n");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* One MCP tool call inside a client span, a child of the `web_search` span,
|
|
48
|
+
* after the MCP semantic conventions (as the Google productivity provider
|
|
49
|
+
* records its own). An `isError` result maps to `provider_error`.
|
|
50
|
+
*/
|
|
51
|
+
export async function tracedMcpCall(tracer, client, server, tool, args, signal) {
|
|
52
|
+
const span = tracer.startSpan(`tools/call ${tool}`, {
|
|
53
|
+
kind: SpanKind.CLIENT,
|
|
54
|
+
attributes: {
|
|
55
|
+
"mcp.method.name": "tools/call",
|
|
56
|
+
"gen_ai.tool.name": tool,
|
|
57
|
+
"search.mcp.server": server,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
try {
|
|
61
|
+
const result = await client.callTool(server, tool, args, signal);
|
|
62
|
+
if (result.isError) {
|
|
63
|
+
span.setAttribute("error.type", "tool_error");
|
|
64
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
65
|
+
throw new SearchProviderError({
|
|
66
|
+
code: "provider_error",
|
|
67
|
+
message: `${server}/${tool} failed: ${mcpResultText(result).slice(0, 300) || "the tool reported an error"}`,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (!(error instanceof SearchProviderError &&
|
|
74
|
+
error.search.code === "provider_error")) {
|
|
75
|
+
span.setAttribute("error.type", error instanceof SearchProviderError ? error.search.code : "_OTHER");
|
|
76
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
77
|
+
}
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
span.end();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/search/mcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAe,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AA2CjD;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAC/B,GAAkB,EAClB,SAAuC;IAEvC,OAAO;QACL,OAAO,CAAC,MAAM,EAAE,IAAI;YAClB,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACvC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC;gBAAE,OA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AC;QACf,IAAI,CAAC,CACH,KAAK,YAAY,mBAAmB;YACpC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,gBAAgB,CACvC,EAAE,CAAC;YACF,IAAI,CAAC,YAAY,CACf,YAAY,EACZ,KAAK,YAAY,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CACpE,CAAC;YACF,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type SearchProviders } from "./types.js";
|
|
2
|
+
/** The package that serves `web_search`'s providers, a companion of Recipes. */
|
|
3
|
+
export declare const SEARCH_PROVIDERS_PACKAGE = "@introspection-ai/recipe-search";
|
|
4
|
+
/**
|
|
5
|
+
* The search providers for the Recipe at `recipeDir`, from
|
|
6
|
+
* `@introspection-ai/recipe-search`: the Recipe's own copy when it pins one,
|
|
7
|
+
* else the one installed beside Recipes. With neither installed there are
|
|
8
|
+
* none, and `web_search` offers no provider (`not_bound`). A package that is
|
|
9
|
+
* installed but does not load, or implements another contract version, fails.
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadSearchProviders(options: {
|
|
12
|
+
recipeDir: string;
|
|
13
|
+
/** Where companion packages resolve from. Default: where `@introspection-ai/recipes` is installed. */
|
|
14
|
+
hostDir?: string;
|
|
15
|
+
}): Promise<SearchProviders>;
|
|
16
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/search/module.ts"],"names":[],"mappings":"AAIA,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,YAAY,CAAC;AAEpB,gFAAgF;AAChF,eAAO,MAAM,wBAAwB,oCAAoC,CAAC;AAE1E;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,sGAAsG;IACtG,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC,eAAe,CAAC,CAgC3B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { loadRecipePackageModule, resolveRecipePackage, } from "../recipe/companions.js";
|
|
2
|
+
import { SEARCH_PROVIDER_API_VERSION, SEARCH_PROVIDER_IDS, } from "./types.js";
|
|
3
|
+
/** The package that serves `web_search`'s providers, a companion of Recipes. */
|
|
4
|
+
export const SEARCH_PROVIDERS_PACKAGE = "@introspection-ai/recipe-search";
|
|
5
|
+
/**
|
|
6
|
+
* The search providers for the Recipe at `recipeDir`, from
|
|
7
|
+
* `@introspection-ai/recipe-search`: the Recipe's own copy when it pins one,
|
|
8
|
+
* else the one installed beside Recipes. With neither installed there are
|
|
9
|
+
* none, and `web_search` offers no provider (`not_bound`). A package that is
|
|
10
|
+
* installed but does not load, or implements another contract version, fails.
|
|
11
|
+
*/
|
|
12
|
+
export async function loadSearchProviders(options) {
|
|
13
|
+
if (!resolveRecipePackage(options.recipeDir, SEARCH_PROVIDERS_PACKAGE, options.hostDir))
|
|
14
|
+
return {};
|
|
15
|
+
const module = (await loadRecipePackageModule(options.recipeDir, SEARCH_PROVIDERS_PACKAGE, {
|
|
16
|
+
what: "web_search",
|
|
17
|
+
api: { name: "search provider", version: SEARCH_PROVIDER_API_VERSION },
|
|
18
|
+
...(options.hostDir !== undefined ? { hostDir: options.hostDir } : {}),
|
|
19
|
+
}));
|
|
20
|
+
if (!module ||
|
|
21
|
+
module.kind !== "search" ||
|
|
22
|
+
!module.providers ||
|
|
23
|
+
typeof module.providers !== "object")
|
|
24
|
+
throw new Error(`${SEARCH_PROVIDERS_PACKAGE} has an invalid module contract`);
|
|
25
|
+
return Object.fromEntries(Object.entries(module.providers).filter(([id]) => SEARCH_PROVIDER_IDS.includes(id)));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/search/module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,GAGpB,MAAM,YAAY,CAAC;AAEpB,gFAAgF;AAChF,MAAM,CAAC,MAAM,wBAAwB,GAAG,iCAAiC,CAAC;AAE1E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAIzC;IACC,IACE,CAAC,oBAAoB,CACnB,OAAO,CAAC,SAAS,EACjB,wBAAwB,EACxB,OAAO,CAAC,OAAO,CAChB;QAED,OAAO,EAAE,CAAC;IACZ,MAAM,MAAM,GAAG,CAAC,MAAM,uBAAuB,CAC3C,OAAO,CAAC,SAAS,EACjB,wBAAwB,EACxB;QACE,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,2BAA2B,EAAE;QACtE,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,CACF,CAA4C,CAAC;IAC9C,IACE,CAAC,MAAM;QACP,MAAM,CAAC,IAAI,KAAK,QAAQ;QACxB,CAAC,MAAM,CAAC,SAAS;QACjB,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ;QAEpC,MAAM,IAAI,KAAK,CACb,GAAG,wBAAwB,iCAAiC,CAC7D,CAAC;IACJ,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAC9C,mBAAyC,CAAC,QAAQ,CAAC,EAAE,CAAC,CACxD,CACiB,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type Tracer } from "@opentelemetry/api";
|
|
2
|
+
import { type TSchema } from "typebox";
|
|
3
|
+
import { type SearchEnvironment } from "./egress.js";
|
|
4
|
+
import { type PiToolInfo } from "./mcp.js";
|
|
5
|
+
import { type SearchFetch, type SearchProviderId, type SearchProviderModule, type SearchProviders, type WebSearchArgs, type WebSearchResult } from "./types.js";
|
|
6
|
+
export declare const SEARCH_TOOL_NAME = "web_search";
|
|
7
|
+
/** The `search` skill, offered with the tool. It ships beside `dist/`. */
|
|
8
|
+
export declare const SEARCH_SKILL: string;
|
|
9
|
+
/** What a runtime binds that `web_search` can reach. */
|
|
10
|
+
export interface SearchBindings {
|
|
11
|
+
/** The hosts the runtime's egress holds a credential for. */
|
|
12
|
+
hosts?: Iterable<string>;
|
|
13
|
+
/**
|
|
14
|
+
* The MCP servers the Recipe declares for `web_search` (`behind:
|
|
15
|
+
* [web_search]`) and the runtime binds, each with its bound URL.
|
|
16
|
+
*/
|
|
17
|
+
mcpServers?: Iterable<{
|
|
18
|
+
id: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The bound set, in `providers` order (docs/search/README.md, Bound
|
|
24
|
+
* providers). A provider with a hosted MCP server is bound when the Recipe
|
|
25
|
+
* binds that server: one whose bound URL has the adapter's host, or, for a
|
|
26
|
+
* fake on another host, whose id is the provider's. Its REST endpoint, when
|
|
27
|
+
* the egress holds one, is then the fallback. A REST-only provider is bound
|
|
28
|
+
* by its endpoint host alone.
|
|
29
|
+
*/
|
|
30
|
+
export declare function boundSearchProviders(bindings: SearchBindings, providers: SearchProviders): Pick<WebSearchOptions, "bound" | "mcpServers">;
|
|
31
|
+
/**
|
|
32
|
+
* The tool's parameters. `provider` lists only the bound providers, and is
|
|
33
|
+
* left out when exactly one is bound unless `withProvider` keeps it.
|
|
34
|
+
*/
|
|
35
|
+
export declare function webSearchParameters(bound: readonly SearchProviderId[], withProvider?: boolean): TSchema;
|
|
36
|
+
export interface WebSearchOptions {
|
|
37
|
+
/**
|
|
38
|
+
* The providers whose REST API is bound to this runtime (an endpoint and
|
|
39
|
+
* credential on its egress). One not implemented here is not offered.
|
|
40
|
+
* {@link boundSearchProviders} derives it with `mcpServers`.
|
|
41
|
+
*/
|
|
42
|
+
bound: readonly SearchProviderId[];
|
|
43
|
+
/**
|
|
44
|
+
* The providers whose hosted MCP server the Recipe binds, by MCP server id
|
|
45
|
+
* (`{ tavily: "tavily" }`). Their MCP tool serves a call when the call
|
|
46
|
+
* carries an MCP client; the REST API, if bound too, is the fallback.
|
|
47
|
+
*/
|
|
48
|
+
mcpServers?: Readonly<Partial<Record<SearchProviderId, string>>>;
|
|
49
|
+
/**
|
|
50
|
+
* The provider modules, from `@introspection-ai/recipe-search`
|
|
51
|
+
* ({@link loadSearchProviders}). A provider without one is not offered.
|
|
52
|
+
*/
|
|
53
|
+
providers: SearchProviders;
|
|
54
|
+
env?: SearchEnvironment;
|
|
55
|
+
fetch?: SearchFetch;
|
|
56
|
+
/** Base URLs by provider, in place of `https://<capabilities.host>`. */
|
|
57
|
+
baseUrls?: Readonly<Partial<Record<SearchProviderId, string>>>;
|
|
58
|
+
/** Replaces the egress credential path, for hosts with their own. */
|
|
59
|
+
credentialHeaders?: (provider: SearchProviderModule) => Record<string, string>;
|
|
60
|
+
now?: () => Date;
|
|
61
|
+
tracer?: Tracer;
|
|
62
|
+
/**
|
|
63
|
+
* The session id providers receive (Parallel's free-tier rate limit keys
|
|
64
|
+
* on it). Default: a random UUID per `createWebSearch`, which the host
|
|
65
|
+
* creates once per task.
|
|
66
|
+
*/
|
|
67
|
+
sessionId?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The most calls this function sends to providers, for the task it serves;
|
|
70
|
+
* the next is refused with `max_uses_exceeded`. Set by Recipe code, never
|
|
71
|
+
* by the model. Unset: no cap.
|
|
72
|
+
*/
|
|
73
|
+
maxUses?: number;
|
|
74
|
+
}
|
|
75
|
+
/** What one call may carry beside its arguments. */
|
|
76
|
+
export interface WebSearchCall {
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
}
|
|
79
|
+
export type WebSearch = (args: WebSearchArgs, call?: WebSearchCall) => Promise<WebSearchResult>;
|
|
80
|
+
/** The Pi tool names `web_search` may call through `ctx.executeTool`. */
|
|
81
|
+
export declare function webSearchMcpToolNames(options: WebSearchOptions): string[];
|
|
82
|
+
/**
|
|
83
|
+
* `web_search` as a function for Recipe code. Each call may name any bound
|
|
84
|
+
* provider and any mode, reaches it over REST, and records a span with the
|
|
85
|
+
* provider, mode, setting and billed units. A provider's MCP server is
|
|
86
|
+
* reached only through the registered `web_search` tool.
|
|
87
|
+
*/
|
|
88
|
+
export declare function createWebSearch(options: WebSearchOptions): WebSearch;
|
|
89
|
+
/** The text the model reads: numbered results, then a line per ignored or approximated argument. */
|
|
90
|
+
export declare function formatWebSearch(result: WebSearchResult): string;
|
|
91
|
+
/** Registers `web_search` for the providers bound to the runtime. */
|
|
92
|
+
export declare function registerWebSearchTool(pi: {
|
|
93
|
+
registerTool(...args: never[]): unknown;
|
|
94
|
+
getAllTools?(): readonly PiToolInfo[];
|
|
95
|
+
}, options: WebSearchOptions): WebSearch;
|
|
96
|
+
//# sourceMappingURL=tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/search/tool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAQ,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAI7C,OAAO,EAA2B,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE9E,OAAO,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