@introspection-ai/recipes 0.49.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.
Files changed (160) hide show
  1. package/dist/api/mcp.d.ts +1 -0
  2. package/dist/api/mcp.d.ts.map +1 -1
  3. package/dist/api/mcp.js +1 -0
  4. package/dist/api/mcp.js.map +1 -1
  5. package/dist/channels/tools.d.ts.map +1 -1
  6. package/dist/channels/tools.js +2 -17
  7. package/dist/channels/tools.js.map +1 -1
  8. package/dist/command-parameters.d.ts +10 -0
  9. package/dist/command-parameters.d.ts.map +1 -0
  10. package/dist/command-parameters.js +25 -0
  11. package/dist/command-parameters.js.map +1 -0
  12. package/dist/connector-tools.d.ts +1 -1
  13. package/dist/connector-tools.d.ts.map +1 -1
  14. package/dist/connector-tools.js +13 -5
  15. package/dist/connector-tools.js.map +1 -1
  16. package/dist/documents/module.d.ts.map +1 -1
  17. package/dist/documents/module.js +2 -4
  18. package/dist/documents/module.js.map +1 -1
  19. package/dist/documents/profile.d.ts +1 -1
  20. package/dist/documents/profile.js +1 -1
  21. package/dist/egress.d.ts +23 -0
  22. package/dist/egress.d.ts.map +1 -0
  23. package/dist/egress.js +36 -0
  24. package/dist/egress.js.map +1 -0
  25. package/dist/extensions.d.ts +1 -1
  26. package/dist/extensions.d.ts.map +1 -1
  27. package/dist/extensions.js +23 -2
  28. package/dist/extensions.js.map +1 -1
  29. package/dist/introspection-open.d.ts +46 -0
  30. package/dist/introspection-open.d.ts.map +1 -0
  31. package/dist/introspection-open.js +278 -0
  32. package/dist/introspection-open.js.map +1 -0
  33. package/dist/mcp/index.d.ts +37 -0
  34. package/dist/mcp/index.d.ts.map +1 -1
  35. package/dist/mcp/index.js +14 -4
  36. package/dist/mcp/index.js.map +1 -1
  37. package/dist/mcp/pi-client.d.ts +97 -0
  38. package/dist/mcp/pi-client.d.ts.map +1 -0
  39. package/dist/mcp/pi-client.js +342 -0
  40. package/dist/mcp/pi-client.js.map +1 -0
  41. package/dist/mcp/policy.d.ts +2 -0
  42. package/dist/mcp/policy.d.ts.map +1 -1
  43. package/dist/mcp/policy.js +6 -0
  44. package/dist/mcp/policy.js.map +1 -1
  45. package/dist/mcp-chunks/{chunk-3M4OCQR5.js → chunk-PO2SOBEN.js} +1 -0
  46. package/dist/mcp-daemon.js +1 -1
  47. package/dist/mcp-run-worker.js +1 -1
  48. package/dist/open.d.ts +82 -0
  49. package/dist/open.d.ts.map +1 -0
  50. package/dist/open.js +152 -0
  51. package/dist/open.js.map +1 -0
  52. package/dist/pi-extension.d.ts.map +1 -1
  53. package/dist/pi-extension.js +99 -8
  54. package/dist/pi-extension.js.map +1 -1
  55. package/dist/productivity/content.d.ts +25 -0
  56. package/dist/productivity/content.d.ts.map +1 -0
  57. package/dist/productivity/content.js +94 -0
  58. package/dist/productivity/content.js.map +1 -0
  59. package/dist/productivity/handles.d.ts +72 -0
  60. package/dist/productivity/handles.d.ts.map +1 -0
  61. package/dist/productivity/handles.js +111 -0
  62. package/dist/productivity/handles.js.map +1 -0
  63. package/dist/productivity/http.d.ts +35 -0
  64. package/dist/productivity/http.d.ts.map +1 -0
  65. package/dist/productivity/http.js +203 -0
  66. package/dist/productivity/http.js.map +1 -0
  67. package/dist/productivity/index.d.ts +11 -0
  68. package/dist/productivity/index.d.ts.map +1 -0
  69. package/dist/productivity/index.js +7 -0
  70. package/dist/productivity/index.js.map +1 -0
  71. package/dist/productivity/module.d.ts +63 -0
  72. package/dist/productivity/module.d.ts.map +1 -0
  73. package/dist/productivity/module.js +119 -0
  74. package/dist/productivity/module.js.map +1 -0
  75. package/dist/productivity/paging.d.ts +32 -0
  76. package/dist/productivity/paging.d.ts.map +1 -0
  77. package/dist/productivity/paging.js +42 -0
  78. package/dist/productivity/paging.js.map +1 -0
  79. package/dist/productivity/tools.d.ts +40 -0
  80. package/dist/productivity/tools.d.ts.map +1 -0
  81. package/dist/productivity/tools.js +969 -0
  82. package/dist/productivity/tools.js.map +1 -0
  83. package/dist/productivity/types.d.ts +538 -0
  84. package/dist/productivity/types.d.ts.map +1 -0
  85. package/dist/productivity/types.js +119 -0
  86. package/dist/productivity/types.js.map +1 -0
  87. package/dist/recipe/agent.d.ts +6 -1
  88. package/dist/recipe/agent.d.ts.map +1 -1
  89. package/dist/recipe/agent.js +48 -7
  90. package/dist/recipe/agent.js.map +1 -1
  91. package/dist/recipe/companions.d.ts +2 -1
  92. package/dist/recipe/companions.d.ts.map +1 -1
  93. package/dist/recipe/companions.js +14 -11
  94. package/dist/recipe/companions.js.map +1 -1
  95. package/dist/recipe/manifest.generated.d.ts +4 -1
  96. package/dist/recipe/manifest.generated.d.ts.map +1 -1
  97. package/dist/recipe/manifest.generated.js +5 -2
  98. package/dist/recipe/manifest.generated.js.map +1 -1
  99. package/dist/recipe/package.d.ts +12 -0
  100. package/dist/recipe/package.d.ts.map +1 -1
  101. package/dist/recipe/package.js +93 -0
  102. package/dist/recipe/package.js.map +1 -1
  103. package/dist/review.d.ts +1 -0
  104. package/dist/review.d.ts.map +1 -1
  105. package/dist/review.js +1 -0
  106. package/dist/review.js.map +1 -1
  107. package/dist/search/egress.d.ts +12 -0
  108. package/dist/search/egress.d.ts.map +1 -0
  109. package/dist/search/egress.js +24 -0
  110. package/dist/search/egress.js.map +1 -0
  111. package/dist/search/http.d.ts +16 -0
  112. package/dist/search/http.d.ts.map +1 -0
  113. package/dist/search/http.js +75 -0
  114. package/dist/search/http.js.map +1 -0
  115. package/dist/search/index.d.ts +9 -0
  116. package/dist/search/index.d.ts.map +1 -0
  117. package/dist/search/index.js +5 -0
  118. package/dist/search/index.js.map +1 -0
  119. package/dist/search/mcp.d.ts +58 -0
  120. package/dist/search/mcp.d.ts.map +1 -0
  121. package/dist/search/mcp.js +84 -0
  122. package/dist/search/mcp.js.map +1 -0
  123. package/dist/search/module.d.ts +16 -0
  124. package/dist/search/module.d.ts.map +1 -0
  125. package/dist/search/module.js +27 -0
  126. package/dist/search/module.js.map +1 -0
  127. package/dist/search/tool.d.ts +96 -0
  128. package/dist/search/tool.d.ts.map +1 -0
  129. package/dist/search/tool.js +505 -0
  130. package/dist/search/tool.js.map +1 -0
  131. package/dist/search/types.d.ts +247 -0
  132. package/dist/search/types.d.ts.map +1 -0
  133. package/dist/search/types.js +60 -0
  134. package/dist/search/types.js.map +1 -0
  135. package/dist/session.d.ts.map +1 -1
  136. package/dist/session.js +175 -15
  137. package/dist/session.js.map +1 -1
  138. package/dist/skill-progress.d.ts.map +1 -1
  139. package/dist/skill-progress.js +5 -1
  140. package/dist/skill-progress.js.map +1 -1
  141. package/dist/tool-search.d.ts +2 -2
  142. package/dist/tool-search.d.ts.map +1 -1
  143. package/dist/tool-search.js +4 -2
  144. package/dist/tool-search.js.map +1 -1
  145. package/docs/{index.md → README.md} +10 -3
  146. package/docs/{slack.md → channels/slack.md} +1 -1
  147. package/docs/{documents.md → documents/README.md} +4 -4
  148. package/docs/interactions.md +90 -31
  149. package/docs/mcp-configuration.md +77 -2
  150. package/docs/productivity/README.md +360 -0
  151. package/docs/productivity/google.md +226 -0
  152. package/docs/productivity/microsoft.md +143 -0
  153. package/docs/recipe-format.md +24 -3
  154. package/docs/search/README.md +801 -0
  155. package/package.json +19 -8
  156. package/skills/README.md +12 -0
  157. package/skills/productivity/SKILL.md +76 -0
  158. package/skills/search/SKILL.md +72 -0
  159. /package/docs/{channels.md → channels/README.md} +0 -0
  160. /package/{documents → skills/documents}/SKILL.md +0 -0
@@ -0,0 +1,247 @@
1
+ import type { McpCallToolResult } from "./mcp.js";
2
+ /**
3
+ * The search provider contract this host implements. A provider module, and
4
+ * the package that exports them, declare the version they were written
5
+ * against, and the host refuses one that differs; bump it on any breaking
6
+ * change to `SearchProviderModule` or the types it uses.
7
+ */
8
+ export declare const SEARCH_PROVIDER_API_VERSION: 1;
9
+ /** The providers `web_search` knows, by the id a call names. */
10
+ export declare const SEARCH_PROVIDER_IDS: readonly ["tavily", "parallel", "exa", "keenable", "perplexity", "brave"];
11
+ export type SearchProviderId = (typeof SEARCH_PROVIDER_IDS)[number];
12
+ /** One quality scale for every provider; each maps it to its own setting. */
13
+ export declare const SEARCH_MODES: readonly ["fast", "default", "deep"];
14
+ export type SearchMode = (typeof SEARCH_MODES)[number];
15
+ export declare const SEARCH_FRESHNESS: readonly ["day", "week", "month", "year"];
16
+ export type SearchFreshness = (typeof SEARCH_FRESHNESS)[number];
17
+ /**
18
+ * `snippets`: a short excerpt per result. `context`: extracted, query-relevant
19
+ * page text for grounding (Brave's LLM Context, others' text or highlights).
20
+ */
21
+ export declare const SEARCH_CONTENT: readonly ["snippets", "context"];
22
+ export type SearchContent = (typeof SEARCH_CONTENT)[number];
23
+ export declare const SEARCH_MAX_RESULTS = 10;
24
+ export declare const SEARCH_DEFAULT_RESULTS = 5;
25
+ /** Characters kept per result for each content level. */
26
+ export declare const SEARCH_CONTENT_CHARS: Readonly<Record<SearchContent, number>>;
27
+ /** The arguments a call may set, beyond the query, provider and mode. */
28
+ export declare const SEARCH_OPTIONS: readonly ["freshness", "include_sites", "exclude_sites", "context", "country"];
29
+ export type SearchOption = (typeof SEARCH_OPTIONS)[number];
30
+ /**
31
+ * How a provider serves an argument: `native` maps it to the provider's own
32
+ * parameter with the same meaning, `approximate` to something close (the
33
+ * descriptor's note says what), `none` cannot serve it.
34
+ */
35
+ export type SearchSupport = "native" | "approximate" | "none";
36
+ export interface SearchModeMapping {
37
+ /** The provider's own value for this mode (Tavily `advanced`, Exa `auto`). */
38
+ setting: string;
39
+ /** Set when the provider has no setting that means this mode: what it does instead. */
40
+ approximate?: string;
41
+ }
42
+ export interface SearchCapabilities {
43
+ modes: Readonly<Record<SearchMode, SearchModeMapping>>;
44
+ /** The provider parameter `modes` sets, for docs and traces. */
45
+ mode_parameter: string;
46
+ /** The most results one request returns. */
47
+ max_results: number;
48
+ options: Readonly<Record<SearchOption, SearchSupport>>;
49
+ /** The ISO 3166-1 alpha-2 codes `country` accepts, where the provider names a closed set. */
50
+ countries?: readonly string[];
51
+ /**
52
+ * Whether one request may carry both included and excluded sites. When it
53
+ * may not (Perplexity answers 400, Parallel drops the exclusions), a call
54
+ * with both sends only the included sites and notes the rest as ignored.
55
+ */
56
+ combine_sites: boolean;
57
+ /**
58
+ * The most sites a request may restrict to, where the provider takes fewer
59
+ * than a call may list (Keenable takes one): the first are sent, and the
60
+ * rest noted as ignored.
61
+ */
62
+ max_include_sites?: number;
63
+ /** One sentence per approximated option, saying what it becomes. */
64
+ notes?: Partial<Record<SearchOption, string>>;
65
+ /** The longest query the provider accepts, in characters and in words, where it states one. */
66
+ max_query_chars?: number;
67
+ max_query_words?: number;
68
+ /** The host the provider calls: the endpoint the runtime must bind. */
69
+ host: string;
70
+ /** The header the provider's key travels in, and its prefix. */
71
+ credential: {
72
+ header: string;
73
+ prefix?: string;
74
+ };
75
+ /** How the provider bills a request, per setting where it differs. */
76
+ billing: string;
77
+ }
78
+ /** One call, normalized: options the provider cannot serve already removed. */
79
+ export interface SearchRequest {
80
+ query: string;
81
+ mode: SearchMode;
82
+ /** `capabilities.modes[mode].setting`. */
83
+ setting: string;
84
+ max_results: number;
85
+ freshness?: SearchFreshness;
86
+ include_sites: string[];
87
+ exclude_sites: string[];
88
+ content: SearchContent;
89
+ /** Characters to keep per result. */
90
+ max_chars: number;
91
+ /** ISO 3166-1 alpha-2, upper case: results for this country. */
92
+ country?: string;
93
+ /**
94
+ * Stable across the calls of one `createWebSearch`, the task it serves, for
95
+ * providers that group or rate-limit by session. Never the task id.
96
+ */
97
+ session: string;
98
+ }
99
+ export interface SearchResultItem {
100
+ url: string;
101
+ title?: string;
102
+ snippet?: string;
103
+ published_at?: string;
104
+ score?: number;
105
+ site?: string;
106
+ }
107
+ export interface SearchNote {
108
+ option: SearchOption | "max_results" | "mode";
109
+ outcome: "ignored" | "approximated";
110
+ detail: string;
111
+ }
112
+ export interface SearchUnits {
113
+ name: string;
114
+ count: number;
115
+ }
116
+ /** What a provider returns for one request. */
117
+ export interface SearchProviderResult {
118
+ results: SearchResultItem[];
119
+ /** Billing units the provider reported (credits, dollars), if any. */
120
+ units?: SearchUnits;
121
+ }
122
+ export type SearchFetch = (input: string, init?: {
123
+ method?: string;
124
+ headers?: Record<string, string>;
125
+ body?: string;
126
+ signal?: AbortSignal;
127
+ }) => Promise<{
128
+ ok: boolean;
129
+ status: number;
130
+ headers: {
131
+ get(name: string): string | null;
132
+ };
133
+ json(): Promise<unknown>;
134
+ text(): Promise<string>;
135
+ }>;
136
+ /** What the host hands a provider for each request. */
137
+ export interface SearchCallContext {
138
+ /**
139
+ * Sends one JSON request to `path` on the provider's host, with the
140
+ * credential its egress lane needs, and throws `SearchProviderError` for a
141
+ * failure (429 with its retry delay, 401, 402, 5xx…). Resolves to the
142
+ * parsed body.
143
+ */
144
+ request(path: string, init: {
145
+ method: "GET" | "POST";
146
+ body?: unknown;
147
+ headers?: Record<string, string>;
148
+ }): Promise<unknown>;
149
+ now: () => Date;
150
+ signal?: AbortSignal;
151
+ }
152
+ export declare const SEARCH_ERROR_CODES: readonly ["not_bound", "not_configured", "out_of_credit", "invalid_request", "query_too_long", "max_uses_exceeded", "too_many_requests", "unavailable", "provider_error"];
153
+ export type SearchErrorCode = (typeof SEARCH_ERROR_CODES)[number];
154
+ export interface SearchErrorInfo {
155
+ code: SearchErrorCode;
156
+ message: string;
157
+ status?: number;
158
+ retry_after_seconds?: number;
159
+ /** For `query_too_long` and `max_uses_exceeded`: the limit the call passed. */
160
+ limit?: number;
161
+ }
162
+ /** Thrown by a provider (or the host) to report a typed failure. */
163
+ export declare class SearchProviderError extends Error {
164
+ readonly search: SearchErrorInfo;
165
+ constructor(info: SearchErrorInfo);
166
+ }
167
+ /** How one request maps onto a provider's MCP tool. */
168
+ export interface SearchMcpPlan {
169
+ tool: string;
170
+ args: Record<string, unknown>;
171
+ /** What the tool cannot express; with REST bound too, the call goes to REST instead. */
172
+ unsupported: Array<SearchOption | "mode">;
173
+ /**
174
+ * The provider setting the tool runs, when it is not the mode's: its fixed
175
+ * setting, or null when the server picks one it does not report.
176
+ */
177
+ setting?: string | null;
178
+ }
179
+ /** A provider's hosted MCP server, which `web_search` prefers to its REST API. */
180
+ export interface SearchMcpAdapter {
181
+ /** The provider's hosted server, for docs and bindings; the bound URL may differ. */
182
+ url: string;
183
+ /** The header its key travels in, injected by the egress like a REST key. */
184
+ credential: {
185
+ header: string;
186
+ prefix?: string;
187
+ };
188
+ /** The tools it may call, in order of preference. */
189
+ tools: readonly string[];
190
+ /** The call for this request, given the tools the bound server offers; undefined when it offers none of them. */
191
+ plan(request: SearchRequest, hasTool: (tool: string) => boolean, now: Date): SearchMcpPlan | undefined;
192
+ /** An error it throws that is not a `SearchProviderError` is reported as `provider_error`. */
193
+ parse(result: McpCallToolResult, request: SearchRequest, plan: SearchMcpPlan): SearchProviderResult;
194
+ }
195
+ /** A search provider: a descriptor, its REST call and, optionally, its MCP server. */
196
+ export interface SearchProviderModule {
197
+ kind: "search";
198
+ apiVersion: typeof SEARCH_PROVIDER_API_VERSION;
199
+ id: SearchProviderId;
200
+ capabilities: SearchCapabilities;
201
+ mcp?: SearchMcpAdapter;
202
+ search(request: SearchRequest, context: SearchCallContext): Promise<SearchProviderResult>;
203
+ }
204
+ export type SearchProviders = Readonly<Partial<Record<SearchProviderId, SearchProviderModule>>>;
205
+ /**
206
+ * What a search provider package exports as its default
207
+ * (`@introspection-ai/recipe-search`): its providers by id. It needs no
208
+ * run-time import of `@introspection-ai/recipes`, only these types.
209
+ */
210
+ export interface RecipeSearchModule {
211
+ kind: "search";
212
+ apiVersion: typeof SEARCH_PROVIDER_API_VERSION;
213
+ providers: SearchProviders;
214
+ }
215
+ /** The arguments of one call, from the model or from Recipe code. */
216
+ export interface WebSearchArgs {
217
+ query: string;
218
+ provider?: SearchProviderId;
219
+ mode?: SearchMode;
220
+ max_results?: number;
221
+ freshness?: SearchFreshness;
222
+ /** `"arxiv.org"` restricts to a site; `"-pinterest.com"` excludes one. */
223
+ sites?: string[];
224
+ /** ISO 3166-1 alpha-2 (`"US"`, `"DE"`): results for that country. */
225
+ country?: string;
226
+ content?: SearchContent;
227
+ }
228
+ /** One call's structured result, for the host and its trace; the model reads text. */
229
+ export interface WebSearchResult {
230
+ results: SearchResultItem[];
231
+ provider: SearchProviderId;
232
+ mode: SearchMode;
233
+ /**
234
+ * The provider's own setting that ran: the mode's, unless an MCP tool ran
235
+ * its own; null when the server does not report which.
236
+ */
237
+ setting: string | null;
238
+ /** Whether the provider's MCP server or its REST API served the call. */
239
+ transport: "mcp" | "rest";
240
+ content: SearchContent;
241
+ notes: SearchNote[];
242
+ usage: {
243
+ requests: number;
244
+ units?: SearchUnits;
245
+ };
246
+ }
247
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/search/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAG,CAAU,CAAC;AAEtD,gEAAgE;AAChE,eAAO,MAAM,mBAAmB,YAC9B,QAAQ,EACR,UAAU,EACV,KAAK,EACL,UAAU,EACV,YAAY,EACZ,OAAO,CACC,CAAC;AACX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,6EAA6E;AAC7E,eAAO,MAAM,YAAY,YAAI,MAAM,EAAE,SAAS,EAAE,MAAM,CAAU,CAAC;AACjE,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,eAAO,MAAM,gBAAgB,YAAI,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAU,CAAC;AAC1E,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,cAAc,YAAI,UAAU,EAA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UAAU,EAAE,CAAC;IACpB,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,WAAW,CAAA;KAAE,CAAC;CAClD"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The search provider contract this host implements. A provider module, and
3
+ * the package that exports them, declare the version they were written
4
+ * against, and the host refuses one that differs; bump it on any breaking
5
+ * change to `SearchProviderModule` or the types it uses.
6
+ */
7
+ export const SEARCH_PROVIDER_API_VERSION = 1;
8
+ /** The providers `web_search` knows, by the id a call names. */
9
+ export const SEARCH_PROVIDER_IDS = [
10
+ "tavily",
11
+ "parallel",
12
+ "exa",
13
+ "keenable",
14
+ "perplexity",
15
+ "brave",
16
+ ];
17
+ /** One quality scale for every provider; each maps it to its own setting. */
18
+ export const SEARCH_MODES = ["fast", "default", "deep"];
19
+ export const SEARCH_FRESHNESS = ["day", "week", "month", "year"];
20
+ /**
21
+ * `snippets`: a short excerpt per result. `context`: extracted, query-relevant
22
+ * page text for grounding (Brave's LLM Context, others' text or highlights).
23
+ */
24
+ export const SEARCH_CONTENT = ["snippets", "context"];
25
+ export const SEARCH_MAX_RESULTS = 10;
26
+ export const SEARCH_DEFAULT_RESULTS = 5;
27
+ /** Characters kept per result for each content level. */
28
+ export const SEARCH_CONTENT_CHARS = {
29
+ snippets: 300,
30
+ context: 1500,
31
+ };
32
+ /** The arguments a call may set, beyond the query, provider and mode. */
33
+ export const SEARCH_OPTIONS = [
34
+ "freshness",
35
+ "include_sites",
36
+ "exclude_sites",
37
+ "context",
38
+ "country",
39
+ ];
40
+ export const SEARCH_ERROR_CODES = [
41
+ "not_bound",
42
+ "not_configured",
43
+ "out_of_credit",
44
+ "invalid_request",
45
+ "query_too_long",
46
+ "max_uses_exceeded",
47
+ "too_many_requests",
48
+ "unavailable",
49
+ "provider_error",
50
+ ];
51
+ /** Thrown by a provider (or the host) to report a typed failure. */
52
+ export class SearchProviderError extends Error {
53
+ search;
54
+ constructor(info) {
55
+ super(info.message);
56
+ this.name = "SearchProviderError";
57
+ this.search = info;
58
+ }
59
+ }
60
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/search/types.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAU,CAAC;AAEtD,gEAAgE;AAChE,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,QAAQ;IACR,UAAU;IACV,KAAK;IACL,UAAU;IACV,YAAY;IACZ,OAAO;CACC,CAAC;AAGX,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAU,CAAC;AAGjE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAU,CAAC;AAG1E;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,SAAS,CAAU,CAAC;AAG/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACxC,yDAAyD;AACzD,MAAM,CAAC,MAAM,oBAAoB,GAA4C;IAC3E,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,IAAI;CACd,CAAC;AAEF,yEAAyE;AACzE,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,WAAW;IACX,eAAe;IACf,eAAe;IACf,SAAS;IACT,SAAS;CACD,CAAC;AAwIX,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,WAAW;IACX,gBAAgB;IAChB,eAAe;IACf,iBAAiB;IACjB,gBAAgB;IAChB,mBAAmB;IACnB,mBAAmB;IACnB,aAAa;IACb,gBAAgB;CACR,CAAC;AAYX,oEAAoE;AACpE,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,MAAM,CAAkB;IACjC,Y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,EAAE,yBAAyB,EAAE,CAAC;AAqG9E,qBAAa,8BAA+B,SAAQ,KAAK;IACvD,SAAkB,IAAI,oCAAoC;IAE1D,cAIC;CACF;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,mBAAmB,EAC3B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,IAAI,GAAE,IAAI,CAAC,yBAAyB,EAAE,aAAa,GAAG,iBAAiB,CAAM,GAC5E,OAAO,CAAC;IAAE,YAAY,EAAE,OAAO,CAAA;CAAE,CAAC,CAmBpC;AAivBD,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,mBAAmB,CAAC,CAK9B;AAED,sEAAsE;AACtE,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,iCAAiC,GACtC,OAAO,CAAC,mBAAmB,CAAC,CAE9B"}
package/dist/session.js CHANGED
@@ -1,15 +1,19 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { rm } from "node:fs/promises";
3
+ import { join } from "node:path";
3
4
  import { getModel } from "@earendil-works/pi-ai/compat";
4
- import { createBashToolDefinition, createAgentSessionFromServices, createAgentSessionServices, ModelRuntime, SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
5
+ import { createBashToolDefinition, createCodemodeExtension, createAgentSessionFromServices, createAgentSessionServices, ModelRuntime, SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
5
6
  import { instrumentSession, } from "@introspection-sdk/introspection-pi";
6
7
  import { createAgentTool, MAX_AGENT_RUN_DEPTH, } from "./agents.js";
7
8
  import { askUserQuestionExtension, wantsAskUserQuestion, } from "./ask-user-question.js";
9
+ import { introspectionOpenExtension, wantsIntrospectionOpen, } from "./introspection-open.js";
8
10
  import { artifactViewerExtension, wantsArtifactViewer, } from "./artifact-viewer.js";
9
11
  import { loadRecipeConnectors } from "./connector-tools.js";
10
12
  import { activateRecipePython, prepareRecipePython, RECIPE_PYTHON_ROOT_ENV, } from "./recipe/python.js";
11
13
  import { clearMcpCatalogPreload, preloadMcpCatalogs } from "./mcp/catalog.js";
12
- import { createIsolatedMcpEnvironment, configureMcpLocalConfigPath, isolateMcpEnvironment, materializeMcpSession, materializeSessionMcpCli, readMcpSessionConfig, restoreMcpEnvironment, resolveAgentMcpSelections, snapshotMcpEnvironment, stopMcpDaemon, } from "./mcp/index.js";
14
+ import { createIsolatedMcpEnvironment, configureMcpLocalConfigPath, endpointBindings, isolateMcpEnvironment, materializeMcpSession, materializeSessionMcpCli, readMcpSessionConfig, restoreMcpEnvironment, resolveAgentMcpSelections, resolveMcpSessionServers, snapshotMcpEnvironment, stopMcpDaemon, } from "./mcp/index.js";
15
+ import { mcpServersBehindTools } from "./mcp/policy.js";
16
+ import { createMcpBehindGuard, createPiMcpServersExtension, hideServersBehindTools, createRecipeMcpClientExtension, piMcpToolNamePrefix, PI_MCP_RESOURCE_TOOL_NAMES, piMcpServerRegistrations, piMcpToolOrigin, serverBehindTools, waitForPiMcpServers, } from "./mcp/pi-client.js";
13
17
  import { createMcpToolSet, } from "./mcp/tools.js";
14
18
  import { createRecipeToolSearchTools, LEGACY_MCP_TOOL_SEARCH_NAME, RECIPE_TOOL_SEARCH_NAME, } from "./tool-search.js";
15
19
  import { assertRecipeModelTransport, RecipeCredentialError, RecipeModelError, RecipeModelTransportError, resolveRecipeCredentials, } from "./model-binding.js";
@@ -102,6 +106,7 @@ function scopedMcpSelections(recipe) {
102
106
  return resolveAgentMcpSelections(recipe.mcp);
103
107
  }
104
108
  const leasedMcpEnvironments = new WeakSet();
109
+ const CODEMODE_TOOL_NAME = "codemode";
105
110
  export class RecipeMcpEnvironmentInUseError extends Error {
106
111
  name = "RecipeMcpEnvironmentInUseError";
107
112
  constructor() {
@@ -114,7 +119,7 @@ export class RecipeMcpEnvironmentInUseError extends Error {
114
119
  * sessions with `mcpProvisioning: "host"`.
115
120
  */
116
121
  export async function materializeRecipeSessionMcp(recipe, cwd, env, opts = {}) {
117
- const selections = scopedMcpSelections(recipe);
122
+ const selections = splitMcpSelections(recipe).runtime;
118
123
  if (selections.length === 0)
119
124
  return { materialized: false };
120
125
  if (opts.mcpBindingsPath) {
@@ -135,10 +140,67 @@ export async function materializeRecipeSessionMcp(recipe, cwd, env, opts = {}) {
135
140
  });
136
141
  return { materialized: true };
137
142
  }
138
- async function configureSessionMcp(recipe, cwd, env, opts) {
143
+ /**
144
+ * The selections the agent's MCP mode runs, and those kept on Pi's client
145
+ * behind a tool: every server is on Pi's client in codemode, so nothing is
146
+ * split off there.
147
+ */
148
+ function splitMcpSelections(recipe) {
139
149
  const selections = scopedMcpSelections(recipe);
150
+ const behind = mcpServersBehindTools(recipe.mcp);
151
+ if (recipe.mcp?.mode === "codemode" || behind.size === 0) {
152
+ return { runtime: selections, behind: [] };
153
+ }
154
+ return {
155
+ runtime: selections.filter((entry) => !behind.has(entry.serverId)),
156
+ behind: selections.filter((entry) => behind.has(entry.serverId)),
157
+ };
158
+ }
159
+ /** Servers behind a tool outside codemode: on Pi's client, never written for the `mcp` command or daemon. */
160
+ function piServersBehindTools(recipe, selections, cwd, env, opts) {
161
+ if (selections.length === 0)
162
+ return { piServers: [], servers: [] };
163
+ const bindingEnv = { ...env };
164
+ if (opts.mcpBindingsPath) {
165
+ bindingEnv.PI_RECIPES_MCP_LOCAL_CONFIG = opts.mcpBindingsPath;
166
+ }
167
+ else if (!opts.mcpBindings) {
168
+ configureMcpLocalConfigPath({
169
+ cwd,
170
+ recipeDir: recipe.recipeDir,
171
+ env: bindingEnv,
172
+ });
173
+ }
174
+ const { servers } = resolveMcpSessionServers({
175
+ cwd: opts.mcpRuntimeDir ?? cwd,
176
+ manifest: recipe.manifest,
177
+ agentMcp: selections,
178
+ env: bindingEnv,
179
+ ...(opts.mcpBindings ? { localConfig: opts.mcpBindings } : {}),
180
+ });
181
+ return {
182
+ servers,
183
+ piServers: piMcpServerRegistrations({
184
+ session: { version: 1, servers },
185
+ bindings: endpointBindings(bindingEnv, cwd, opts.mcpBindings),
186
+ mcp: recipe.mcp,
187
+ env: bindingEnv,
188
+ }),
189
+ };
190
+ }
191
+ async function configureSessionMcp(recipe, cwd, env, opts) {
192
+ const { runtime: selections, behind } = splitMcpSelections(recipe);
193
+ const behindTools = piServersBehindTools(recipe, behind, cwd, env, opts);
194
+ const behindOrigin = (name, tools) => piMcpToolOrigin({ version: 1, servers: behindTools.servers }, tools?.getToolDefinition(name));
140
195
  if (selections.length === 0) {
141
- return { available: false, materialized: false };
196
+ return behindTools.piServers.length > 0
197
+ ? {
198
+ available: false,
199
+ materialized: false,
200
+ piServers: behindTools.piServers,
201
+ mcpToolOrigin: behindOrigin,
202
+ }
203
+ : { available: false, materialized: false };
142
204
  }
143
205
  const mode = recipe.mcp?.mode ?? "cli";
144
206
  const hostProvisioned = opts.mcpProvisioning === "host";
@@ -170,7 +232,7 @@ async function configureSessionMcp(recipe, cwd, env, opts) {
170
232
  }
171
233
  };
172
234
  try {
173
- if (!hostProvisioned && mode === "tools") {
235
+ if (!hostProvisioned && (mode === "tools" || mode === "codemode")) {
174
236
  const isolated = await createIsolatedMcpEnvironment(env);
175
237
  runtimeEnv = isolated.env;
176
238
  privateDirectory = isolated.directory;
@@ -205,6 +267,21 @@ async function configureSessionMcp(recipe, cwd, env, opts) {
205
267
  : {}),
206
268
  });
207
269
  }
270
+ if (mode === "codemode") {
271
+ const piServers = piMcpServerRegistrations({
272
+ session,
273
+ bindings: endpointBindings(runtimeEnv, cwd, opts.mcpBindings),
274
+ mcp: recipe.mcp,
275
+ env: runtimeEnv,
276
+ });
277
+ return {
278
+ available: true,
279
+ materialized: !hostProvisioned,
280
+ piServers,
281
+ mcpToolOrigin: (name, tools) => piMcpToolOrigin(session, tools?.getToolDefinition(name)),
282
+ release,
283
+ };
284
+ }
208
285
  if (mode === "tools") {
209
286
  const catalogs = session.servers.length > 0
210
287
  ? await preloadMcpCatalogs({
@@ -225,7 +302,8 @@ async function configureSessionMcp(recipe, cwd, env, opts) {
225
302
  tools: materialized.tools,
226
303
  initialActiveToolNames: materialized.initialActiveToolNames,
227
304
  deferredToolNames: materialized.deferredToolNames,
228
- mcpToolOrigin: materialized.mcpToolOrigin,
305
+ mcpToolOrigin: (name, tools) => materialized.mcpToolOrigin(name) ?? behindOrigin(name, tools),
306
+ piServers: behindTools.piServers,
229
307
  release,
230
308
  };
231
309
  }
@@ -236,6 +314,8 @@ async function configureSessionMcp(recipe, cwd, env, opts) {
236
314
  return {
237
315
  available: true,
238
316
  materialized: !hostProvisioned,
317
+ piServers: behindTools.piServers,
318
+ mcpToolOrigin: behindOrigin,
239
319
  release,
240
320
  };
241
321
  }
@@ -310,6 +390,8 @@ async function createSessionForAgent(recipe, opts) {
310
390
  python: python.packages,
311
391
  });
312
392
  const mcp = await configureSessionMcp(recipe, cwd, env, opts);
393
+ const { piServers, usesPiMcp, codemodeToolNames, piMcpResourceToolNames, piMcpSessionOptions, } = piMcpSessionTools(mcp.piServers, recipe.mcp);
394
+ let piMcp;
313
395
  const cleanup = async () => {
314
396
  try {
315
397
  unsubscribe?.();
@@ -378,6 +460,8 @@ async function createSessionForAgent(recipe, opts) {
378
460
  ...((mcp.deferredToolNames?.length ?? 0) > 0
379
461
  ? [LEGACY_MCP_TOOL_SEARCH_NAME]
380
462
  : []),
463
+ ...codemodeToolNames,
464
+ ...piMcpResourceToolNames,
381
465
  ]) {
382
466
  recipeRegistrations.claim("tool", toolName, "<host>");
383
467
  }
@@ -392,7 +476,7 @@ async function createSessionForAgent(recipe, opts) {
392
476
  ...((mcp.deferredToolNames?.length ?? 0) > 0
393
477
  ? [LEGACY_MCP_TOOL_SEARCH_NAME]
394
478
  : []),
395
- ])));
479
+ ]), usesPiMcp));
396
480
  }
397
481
  for (const extensionPath of recipe.extensionPaths) {
398
482
  inlineExtensions.push(bindRecipeExtensionFactory(await loadRecipeExtensionFactory(recipe.recipeDir, extensionPath), recipeExtensionContext, recipeRegistrations, extensionPath, recipeExtensionToolAllowlist(recipe.tools, wantsSubagents, [
@@ -404,13 +488,14 @@ async function createSessionForAgent(recipe, opts) {
404
488
  ...((mcp.deferredToolNames?.length ?? 0) > 0
405
489
  ? [LEGACY_MCP_TOOL_SEARCH_NAME]
406
490
  : []),
407
- ])));
491
+ ]), usesPiMcp));
408
492
  }
493
+ inlineExtensions.push(...piMcpExtensions(piServers, codemodeToolNames.length > 0, opts.mcpRuntimeDir, cwd, (pi) => {
494
+ piMcp = pi;
495
+ }));
409
496
  // The first-party ask_user_question tool loads after the Recipe's own
410
497
  // extensions, so a Recipe that still ships its own keeps it.
411
- if (wantsAskUserQuestion(recipe.tools)) {
412
- inlineExtensions.push(askUserQuestionExtension(recipeRegistrations, env));
413
- }
498
+ inlineExtensions.push(...interactionToolExtensions(recipe.tools, recipeRegistrations, env));
414
499
  // Likewise the first-party artifact viewer (show_artifact and /recipe view).
415
500
  if (wantsArtifactViewer(recipe.tools)) {
416
501
  inlineExtensions.push(artifactViewerExtension(recipeRegistrations, {
@@ -543,7 +628,7 @@ async function createSessionForAgent(recipe, opts) {
543
628
  getAllTools: () => session?.getAllTools() ?? [],
544
629
  getActiveTools: () => session?.getActiveToolNames() ?? [],
545
630
  setActiveTools: (names) => session?.setActiveToolsByName(names),
546
- }, (mcp.deferredToolNames?.length ?? 0) > 0)
631
+ }, (mcp.deferredToolNames?.length ?? 0) > 0, (tool) => serverBehindTools(piServers, tool) !== undefined)
547
632
  : [];
548
633
  const occupiedSearchTool = toolSearchTools.find((tool) => occupiedToolNames.has(tool.name));
549
634
  if (occupiedSearchTool) {
@@ -554,6 +639,12 @@ async function createSessionForAgent(recipe, opts) {
554
639
  ...connectorLoadout.toolNames,
555
640
  ...mcpToolNames,
556
641
  ...toolSearchTools.map((tool) => tool.name),
642
+ ...codemodeToolNames,
643
+ // Naming the Recipe's servers keeps their tools and drops any other MCP
644
+ // server's; each tool's exposure then decides what the model sees. A
645
+ // prefix that also covers another of these servers is harmless, as only
646
+ // the Recipe's servers are on this session's MCP client.
647
+ ...piServers.map((server) => `${piMcpToolNamePrefix(server.id)}*`),
557
648
  ];
558
649
  // The bash tool runs in `env` when the session's MCP CLI lives there, and
559
650
  // in the Recipe's Python shell environment when it declares one.
@@ -594,6 +685,7 @@ async function createSessionForAgent(recipe, opts) {
594
685
  model,
595
686
  ...(recipe.thinkingLevel ? { thinkingLevel: recipe.thinkingLevel } : {}),
596
687
  tools: selectedToolNames,
688
+ ...piMcpSessionOptions,
597
689
  customTools,
598
690
  });
599
691
  session = created.session;
@@ -603,8 +695,9 @@ async function createSessionForAgent(recipe, opts) {
603
695
  normalizeSessionToolsForModel(session, model);
604
696
  applyRecipeAgentModelConfigToSession(session, recipe.modelConfig);
605
697
  await session.bindExtensions({});
698
+ await waitForRequiredPiMcpServers(piMcp, piServers, opts.mcpDiscovery, env);
606
699
  const registered = new Set(session.getAllTools().map((tool) => tool.name));
607
- const missingDeclaredTools = selectedToolNames.filter((name) => !registered.has(name));
700
+ const missingDeclaredTools = selectedToolNames.filter((name) => !name.includes("*") && !registered.has(name));
608
701
  if (missingDeclaredTools.length > 0) {
609
702
  throw new Error(`Recipe agent "${recipe.name}" declares unavailable tool(s): ${missingDeclaredTools.join(", ")}`);
610
703
  }
@@ -634,7 +727,9 @@ async function createSessionForAgent(recipe, opts) {
634
727
  detachInstrumentation = otel
635
728
  ? instrumentSession(session, {
636
729
  ...otel,
637
- ...(mcp.mcpToolOrigin ? { mcpTool: mcp.mcpToolOrigin } : {}),
730
+ ...(mcp.mcpToolOrigin
731
+ ? { mcpTool: sessionMcpToolOrigin(mcp.mcpToolOrigin, session) }
732
+ : {}),
638
733
  }).detach
639
734
  : undefined;
640
735
  const liveSession = session;
@@ -667,4 +762,69 @@ export async function createAgentSession(opts) {
667
762
  export async function createAgentSessionInternal(opts) {
668
763
  return createSessionForAgent(opts.recipe.selectAgent(opts.agentName), opts);
669
764
  }
765
+ function sessionMcpToolOrigin(origin, session) {
766
+ return (piName) => origin(piName, session);
767
+ }
768
+ /**
769
+ * Pi's MCP client with the Recipe's servers on it (every server in codemode,
770
+ * else those behind a tool), codemode in codemode, and the guard keeping
771
+ * servers behind their tools.
772
+ */
773
+ function piMcpExtensions(piServers, codemode, runtimeDir, cwd, onPi) {
774
+ if (piServers.length === 0)
775
+ return [];
776
+ // A script's `models.*` calls would spend on models the Recipe never
777
+ // declared, so scripts get tools only.
778
+ return [
779
+ ...(codemode ? [createCodemodeExtension({ models: false })] : []),
780
+ createRecipeMcpClientExtension(join(runtimeDir ?? cwd, ".pi", "mcp.log")),
781
+ createPiMcpServersExtension(piServers, onPi),
782
+ ...(piServers.some((server) => server.behind)
783
+ ? [
784
+ createMcpBehindGuard(() => piServers),
785
+ (pi) => {
786
+ pi.on("before_agent_start", (event) => hideServersBehindTools(event.systemPromptOptions.sections, piServers));
787
+ },
788
+ ]
789
+ : []),
790
+ ];
791
+ }
792
+ /**
793
+ * Pi connects in the background; a required server must be up before the
794
+ * first turn, as its catalog must be on the daemon stack.
795
+ */
796
+ async function waitForRequiredPiMcpServers(piMcp, piServers, mcpDiscovery, env) {
797
+ if (!piMcp)
798
+ return;
799
+ await waitForPiMcpServers(piMcp, piServers
800
+ .filter((server) => server.required &&
801
+ !(mcpDiscovery === "defer" && server.deferrableDiscovery))
802
+ .map((server) => server.id), env);
803
+ }
804
+ /** What `mcp.mode: codemode` adds to a session's tools; nothing when no server is on Pi's client. */
805
+ function piMcpSessionTools(servers, mcp) {
806
+ const codemode = mcp?.mode === "codemode";
807
+ const piServers = servers ?? [];
808
+ const usesPiMcp = piServers.length > 0;
809
+ return {
810
+ piServers,
811
+ usesPiMcp,
812
+ codemodeToolNames: usesPiMcp && codemode ? [CODEMODE_TOOL_NAME] : [],
813
+ piMcpResourceToolNames: usesPiMcp ? [...PI_MCP_RESOURCE_TOOL_NAMES] : [],
814
+ piMcpSessionOptions: usesPiMcp
815
+ ? { excludeTools: [...PI_MCP_RESOURCE_TOOL_NAMES] }
816
+ : {},
817
+ };
818
+ }
819
+ /** The first-party interaction tools the agent lists, after the Recipe's own extensions so a Recipe's own tool wins. */
820
+ function interactionToolExtensions(tools, registrations, env) {
821
+ return [
822
+ ...(wantsAskUserQuestion(tools)
823
+ ? [askUserQuestionExtension(registrations, env)]
824
+ : []),
825
+ ...(wantsIntrospectionOpen(tools)
826
+ ? [introspectionOpenExtension(registrations, env)]
827
+ : []),
828
+ ];
829
+ }
670
830
  //# sourceMappingURL=session.js.map