@oh-my-pi/pi-coding-agent 15.9.0 → 15.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/dist/types/cli/update-cli.d.ts +15 -1
- package/dist/types/config/append-only-context-mode.d.ts +8 -0
- package/dist/types/config/model-registry.d.ts +3 -0
- package/dist/types/config/models-config-schema.d.ts +15 -0
- package/dist/types/config/settings-schema.d.ts +3 -3
- package/dist/types/exa/mcp-client.d.ts +2 -1
- package/dist/types/mcp/json-rpc.d.ts +6 -1
- package/dist/types/mcp/tool-bridge.d.ts +4 -0
- package/dist/types/mnemopi/state.d.ts +2 -2
- package/dist/types/modes/components/agent-dashboard.d.ts +1 -0
- package/dist/types/modes/components/extensions/extension-dashboard.d.ts +1 -0
- package/dist/types/modes/components/plugin-settings.d.ts +40 -8
- package/dist/types/modes/components/session-selector.d.ts +8 -3
- package/dist/types/modes/components/settings-selector.d.ts +1 -1
- package/dist/types/modes/utils/keybinding-matchers.d.ts +4 -0
- package/dist/types/session/agent-session.d.ts +4 -1
- package/dist/types/session/history-storage.d.ts +3 -4
- package/dist/types/session/messages.d.ts +1 -0
- package/dist/types/session/session-manager.d.ts +1 -0
- package/dist/types/slash-commands/types.d.ts +17 -4
- package/dist/types/tiny/text.d.ts +17 -0
- package/dist/types/web/search/providers/base.d.ts +14 -0
- package/dist/types/web/search/providers/exa.d.ts +9 -0
- package/dist/types/web/search/providers/perplexity.d.ts +2 -2
- package/dist/types/web/search/types.d.ts +2 -1
- package/package.json +9 -9
- package/src/cli/session-picker.ts +1 -0
- package/src/cli/update-cli.ts +54 -2
- package/src/commands/completions.ts +1 -1
- package/src/config/append-only-context-mode.ts +37 -0
- package/src/config/models-config-schema.ts +1 -0
- package/src/config/settings-schema.ts +2 -2
- package/src/exa/mcp-client.ts +11 -5
- package/src/internal-urls/docs-index.generated.ts +1 -1
- package/src/main.ts +4 -2
- package/src/mcp/json-rpc.ts +8 -0
- package/src/mcp/render.ts +3 -0
- package/src/mcp/tool-bridge.ts +10 -2
- package/src/mcp/transports/http.ts +33 -16
- package/src/mnemopi/state.ts +4 -4
- package/src/modes/acp/acp-agent.ts +168 -3
- package/src/modes/components/agent-dashboard.ts +103 -31
- package/src/modes/components/extensions/extension-dashboard.ts +56 -10
- package/src/modes/components/history-search.ts +128 -14
- package/src/modes/components/plugin-settings.ts +270 -36
- package/src/modes/components/session-selector.ts +45 -14
- package/src/modes/components/settings-selector.ts +1 -1
- package/src/modes/components/tips.txt +5 -1
- package/src/modes/components/transcript-container.ts +22 -4
- package/src/modes/controllers/command-controller.ts +4 -3
- package/src/modes/controllers/input-controller.ts +10 -5
- package/src/modes/controllers/selector-controller.ts +30 -19
- package/src/modes/interactive-mode.ts +38 -3
- package/src/modes/utils/keybinding-matchers.ts +10 -0
- package/src/prompts/steering/user-interjection.md +10 -0
- package/src/prompts/system/agent-creation-architect.md +1 -26
- package/src/prompts/system/system-prompt.md +143 -145
- package/src/prompts/system/title-system.md +3 -2
- package/src/prompts/tools/browser.md +29 -29
- package/src/prompts/tools/render-mermaid.md +2 -2
- package/src/sdk.ts +5 -21
- package/src/session/agent-session.ts +30 -7
- package/src/session/history-storage.ts +11 -18
- package/src/session/messages.ts +80 -0
- package/src/session/session-manager.ts +7 -1
- package/src/slash-commands/types.ts +27 -10
- package/src/tiny/text.ts +112 -1
- package/src/tools/memory-recall.ts +1 -1
- package/src/tools/memory-reflect.ts +1 -1
- package/src/tools/ssh.ts +26 -10
- package/src/tools/write.ts +14 -2
- package/src/tui/status-line.ts +15 -4
- package/src/utils/title-generator.ts +9 -2
- package/src/web/search/index.ts +3 -1
- package/src/web/search/provider.ts +1 -1
- package/src/web/search/providers/base.ts +17 -0
- package/src/web/search/providers/exa.ts +111 -7
- package/src/web/search/providers/perplexity.ts +8 -4
- package/src/web/search/types.ts +2 -1
package/src/tools/ssh.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallback } from "@oh-my-pi/pi-agent-core";
|
|
2
2
|
import type { Component } from "@oh-my-pi/pi-tui";
|
|
3
|
-
import { Text } from "@oh-my-pi/pi-tui";
|
|
4
3
|
import { prompt } from "@oh-my-pi/pi-utils";
|
|
5
4
|
import * as z from "zod/v4";
|
|
6
5
|
import type { SSHHost } from "../capability/ssh";
|
|
@@ -18,6 +17,7 @@ import { CachedOutputBlock } from "../tui/output-block";
|
|
|
18
17
|
import type { ToolSession } from ".";
|
|
19
18
|
import { truncateForPrompt } from "./approval";
|
|
20
19
|
import { formatStyledTruncationWarning, type OutputMeta, stripOutputNotice } from "./output-meta";
|
|
20
|
+
import { replaceTabs } from "./render-utils";
|
|
21
21
|
import { ToolError } from "./tool-errors";
|
|
22
22
|
import { toolResult } from "./tool-result";
|
|
23
23
|
import { clampTimeout } from "./tool-timeouts";
|
|
@@ -230,12 +230,30 @@ interface SshRenderContext {
|
|
|
230
230
|
totalVisualLines?: number;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
function formatSshCommandLines(command: string, uiTheme: Theme): string[] {
|
|
234
|
+
const sanitized = replaceTabs(command);
|
|
235
|
+
const rawLines = sanitized.length > 0 ? sanitized.split("\n") : ["…"];
|
|
236
|
+
const prefix = uiTheme.fg("dim", "$ ");
|
|
237
|
+
return rawLines.map((line, i) => (i === 0 ? `${prefix}${line}` : line));
|
|
238
|
+
}
|
|
239
|
+
|
|
233
240
|
export const sshToolRenderer = {
|
|
234
241
|
renderCall(args: SshRenderArgs, _options: RenderResultOptions, uiTheme: Theme): Component {
|
|
235
242
|
const host = args.host || "…";
|
|
236
|
-
const command = args.command
|
|
237
|
-
const
|
|
238
|
-
|
|
243
|
+
const command = args.command ?? "";
|
|
244
|
+
const header = renderStatusLine({ icon: "pending", title: "SSH", description: `[${host}]` }, uiTheme);
|
|
245
|
+
const cmdLines = formatSshCommandLines(command, uiTheme);
|
|
246
|
+
const outputBlock = new CachedOutputBlock();
|
|
247
|
+
return {
|
|
248
|
+
render: (width: number): string[] =>
|
|
249
|
+
outputBlock.render(
|
|
250
|
+
{ header, state: "pending", sections: [{ lines: cmdLines }], width, animate: true },
|
|
251
|
+
uiTheme,
|
|
252
|
+
),
|
|
253
|
+
invalidate: () => {
|
|
254
|
+
outputBlock.invalidate();
|
|
255
|
+
},
|
|
256
|
+
};
|
|
239
257
|
},
|
|
240
258
|
|
|
241
259
|
renderResult(
|
|
@@ -249,11 +267,9 @@ export const sshToolRenderer = {
|
|
|
249
267
|
): Component {
|
|
250
268
|
const details = result.details;
|
|
251
269
|
const host = args?.host || "…";
|
|
252
|
-
const command = args?.command
|
|
253
|
-
const header = renderStatusLine(
|
|
254
|
-
|
|
255
|
-
uiTheme,
|
|
256
|
-
);
|
|
270
|
+
const command = args?.command ?? "";
|
|
271
|
+
const header = renderStatusLine({ icon: "success", title: "SSH", description: `[${host}]` }, uiTheme);
|
|
272
|
+
const cmdLines = formatSshCommandLines(command, uiTheme);
|
|
257
273
|
const textContent = result.content?.find(c => c.type === "text")?.text ?? "";
|
|
258
274
|
const outputBlock = new CachedOutputBlock();
|
|
259
275
|
|
|
@@ -303,7 +319,7 @@ export const sshToolRenderer = {
|
|
|
303
319
|
{
|
|
304
320
|
header,
|
|
305
321
|
state: "success",
|
|
306
|
-
sections: [{ label: uiTheme.fg("toolTitle", "Output"), lines: outputLines }],
|
|
322
|
+
sections: [{ lines: cmdLines }, { label: uiTheme.fg("toolTitle", "Output"), lines: outputLines }],
|
|
307
323
|
width,
|
|
308
324
|
},
|
|
309
325
|
uiTheme,
|
package/src/tools/write.ts
CHANGED
|
@@ -135,6 +135,15 @@ function maybeWriteSnapshotHeader(session: ToolSession, absolutePath: string, co
|
|
|
135
135
|
return formatHashlineHeader(formatPathRelativeToCwd(absolutePath, session.cwd), tag);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
function shouldRouteWriteThroughBridge(session: ToolSession, requestedPath: string, absolutePath: string): boolean {
|
|
139
|
+
if (isInternalUrlPath(requestedPath)) return false;
|
|
140
|
+
|
|
141
|
+
const state = session.getPlanModeState?.();
|
|
142
|
+
if (!state?.enabled || !isInternalUrlPath(state.planFilePath)) return true;
|
|
143
|
+
|
|
144
|
+
return absolutePath !== resolvePlanPath(session, state.planFilePath);
|
|
145
|
+
}
|
|
146
|
+
|
|
138
147
|
/**
|
|
139
148
|
* Append a trailing note line to the first text block of a tool result.
|
|
140
149
|
* Mutates `result` in place (the result object is owned by this call).
|
|
@@ -845,8 +854,11 @@ export class WriteTool implements AgentTool<typeof writeSchema, WriteToolDetails
|
|
|
845
854
|
await assertEditableFile(absolutePath, path);
|
|
846
855
|
}
|
|
847
856
|
|
|
848
|
-
// Try ACP bridge first
|
|
849
|
-
|
|
857
|
+
// Try ACP bridge first for editor-visible filesystem paths. Internal
|
|
858
|
+
// artifacts such as local:// plans are owned by OMP, not the editor.
|
|
859
|
+
const bridgePromise = shouldRouteWriteThroughBridge(this.session, path, absolutePath)
|
|
860
|
+
? this.#routeWriteThroughBridge(absolutePath, cleanContent)
|
|
861
|
+
: undefined;
|
|
850
862
|
if (bridgePromise !== undefined) {
|
|
851
863
|
try {
|
|
852
864
|
await bridgePromise;
|
package/src/tui/status-line.ts
CHANGED
|
@@ -15,22 +15,33 @@ export interface StatusLineOptions {
|
|
|
15
15
|
meta?: string[];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Flatten CR/LF runs in caller-supplied header fragments so a single newline
|
|
20
|
+
* embedded in `description` or `meta` cannot expand the status line into
|
|
21
|
+
* multiple rows — which would otherwise break the bordered output block the
|
|
22
|
+
* header sits on. Tab characters are left alone; tool renderers that need
|
|
23
|
+
* tab-safe text run `replaceTabs()` themselves.
|
|
24
|
+
*/
|
|
25
|
+
function flattenForHeader(text: string): string {
|
|
26
|
+
return text.replace(/\r\n?|\n/g, " ");
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
export function renderStatusLine(options: StatusLineOptions, theme: Theme): string {
|
|
19
30
|
const icon = options.icon ? formatStatusIcon(options.icon, theme, options.spinnerFrame) : "";
|
|
20
31
|
const titleColor = options.titleColor ?? "accent";
|
|
21
|
-
const title = theme.fg(titleColor, options.title);
|
|
32
|
+
const title = theme.fg(titleColor, flattenForHeader(options.title));
|
|
22
33
|
let line = icon ? `${icon} ${title}` : title;
|
|
23
34
|
|
|
24
35
|
if (options.description) {
|
|
25
|
-
line += `: ${theme.fg("muted", options.description)}`;
|
|
36
|
+
line += `: ${theme.fg("muted", flattenForHeader(options.description))}`;
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
if (options.badge) {
|
|
29
40
|
const { label, color } = options.badge;
|
|
30
|
-
line += ` ${theme.fg(color, `${theme.format.bracketLeft}${label}${theme.format.bracketRight}`)}`;
|
|
41
|
+
line += ` ${theme.fg(color, `${theme.format.bracketLeft}${flattenForHeader(label)}${theme.format.bracketRight}`)}`;
|
|
31
42
|
}
|
|
32
43
|
|
|
33
|
-
const meta = options.meta?.filter(value => value.trim().length > 0) ?? [];
|
|
44
|
+
const meta = options.meta?.map(flattenForHeader).filter(value => value.trim().length > 0) ?? [];
|
|
34
45
|
if (meta.length > 0) {
|
|
35
46
|
line += ` ${theme.fg("dim", meta.join(theme.sep.dot))}`;
|
|
36
47
|
}
|
|
@@ -10,7 +10,7 @@ import { resolveRoleSelection } from "../config/model-resolver";
|
|
|
10
10
|
import type { Settings } from "../config/settings";
|
|
11
11
|
import titleSystemPrompt from "../prompts/system/title-system.md" with { type: "text" };
|
|
12
12
|
import { ONLINE_TINY_TITLE_MODEL_KEY } from "../tiny/models";
|
|
13
|
-
import { formatTitleUserMessage, normalizeGeneratedTitle } from "../tiny/text";
|
|
13
|
+
import { formatTitleUserMessage, isLowSignalTitleInput, normalizeGeneratedTitle } from "../tiny/text";
|
|
14
14
|
import { tinyTitleClient } from "../tiny/title-client";
|
|
15
15
|
|
|
16
16
|
const TITLE_SYSTEM_PROMPT = prompt.render(titleSystemPrompt);
|
|
@@ -31,7 +31,8 @@ const setTitleTool: Tool = {
|
|
|
31
31
|
properties: {
|
|
32
32
|
title: {
|
|
33
33
|
type: "string",
|
|
34
|
-
description:
|
|
34
|
+
description:
|
|
35
|
+
'A concise 3-6 word title for the session, or exactly "none" when the message carries no concrete task yet (greeting, small talk, vague).',
|
|
35
36
|
},
|
|
36
37
|
},
|
|
37
38
|
required: ["title"],
|
|
@@ -144,6 +145,12 @@ export async function generateSessionTitle(
|
|
|
144
145
|
currentModel?: Model<Api>,
|
|
145
146
|
metadataResolver?: (provider: string) => Record<string, unknown> | undefined,
|
|
146
147
|
): Promise<string | null> {
|
|
148
|
+
// Defer titling for greetings / acknowledgements / empty input. The default
|
|
149
|
+
// tiny title model can't reliably decline trivial input, so this happens
|
|
150
|
+
// deterministically before any model is invoked; the caller retries on the
|
|
151
|
+
// next user message while the session stays unnamed.
|
|
152
|
+
if (isLowSignalTitleInput(firstMessage)) return null;
|
|
153
|
+
|
|
147
154
|
const tinyModel = settings.get("providers.tinyModel");
|
|
148
155
|
if (tinyModel === ONLINE_TINY_TITLE_MODEL_KEY) {
|
|
149
156
|
return generateTitleOnline(firstMessage, registry, settings, sessionId, currentModel, metadataResolver);
|
package/src/web/search/index.ts
CHANGED
|
@@ -131,7 +131,9 @@ async function executeSearch(
|
|
|
131
131
|
const providers =
|
|
132
132
|
params.provider && params.provider !== "auto"
|
|
133
133
|
? await getSearchProvider(params.provider).then(async provider =>
|
|
134
|
-
(await provider.
|
|
134
|
+
(await provider.isExplicitlyAvailable(authStorage))
|
|
135
|
+
? [provider]
|
|
136
|
+
: resolveProviderChain(authStorage, "auto"),
|
|
135
137
|
)
|
|
136
138
|
: await resolveProviderChain(authStorage);
|
|
137
139
|
if (providers.length === 0) {
|
|
@@ -140,7 +140,7 @@ export async function resolveProviderChain(
|
|
|
140
140
|
|
|
141
141
|
if (preferredProvider !== "auto") {
|
|
142
142
|
const provider = await getSearchProvider(preferredProvider);
|
|
143
|
-
if (await provider.
|
|
143
|
+
if (await provider.isExplicitlyAvailable(authStorage)) {
|
|
144
144
|
providers.push(provider);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
@@ -61,9 +61,26 @@ export abstract class SearchProvider {
|
|
|
61
61
|
* Indicates whether this provider has the credentials/config it needs to
|
|
62
62
|
* service a request right now. Implementations consult the passed
|
|
63
63
|
* {@link AuthStorage} — never a sibling store.
|
|
64
|
+
*
|
|
65
|
+
* Drives auto-chain admission: providers that return `false` are skipped
|
|
66
|
+
* when {@link resolveProviderChain} walks the order. Explicit selection
|
|
67
|
+
* uses {@link isExplicitlyAvailable} instead.
|
|
64
68
|
*/
|
|
65
69
|
abstract isAvailable(authStorage: AuthStorage): Promise<boolean> | boolean;
|
|
66
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Returns `true` when this provider should run when the user explicitly
|
|
73
|
+
* selects it, even if {@link isAvailable} would reject it for the auto
|
|
74
|
+
* chain. Providers that ship an unauthenticated fallback (e.g. Exa's
|
|
75
|
+
* public MCP) override this so explicit selection still routes through
|
|
76
|
+
* the fallback rather than silently falling back to another provider.
|
|
77
|
+
*
|
|
78
|
+
* Defaults to mirroring {@link isAvailable}.
|
|
79
|
+
*/
|
|
80
|
+
isExplicitlyAvailable(authStorage: AuthStorage): Promise<boolean> | boolean {
|
|
81
|
+
return this.isAvailable(authStorage);
|
|
82
|
+
}
|
|
83
|
+
|
|
67
84
|
/**
|
|
68
85
|
* Execute a search. Credentials MUST be resolved through `params.authStorage`.
|
|
69
86
|
*/
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { type AuthStorage, getEnvApiKey } from "@oh-my-pi/pi-ai";
|
|
10
10
|
import { settings } from "../../../config/settings";
|
|
11
|
+
import { callExaTool, findApiKey, isSearchResponse } from "../../../exa/mcp-client";
|
|
11
12
|
|
|
12
13
|
import type { SearchResponse, SearchSource } from "../../../web/search/types";
|
|
13
14
|
import { SearchProviderError } from "../../../web/search/types";
|
|
@@ -56,6 +57,71 @@ interface ExaSearchResponse {
|
|
|
56
57
|
costDollars?: { total: number };
|
|
57
58
|
searchTime?: number;
|
|
58
59
|
}
|
|
60
|
+
function asRecord(value: unknown): Record<string, unknown> | null {
|
|
61
|
+
if (typeof value !== "object" || value === null) return null;
|
|
62
|
+
return value as Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function parseOptionalField(section: string, label: string): string | null | undefined {
|
|
66
|
+
const regex = new RegExp(`(?:^|\\n)${label}:\\s*([^\\n]*)`);
|
|
67
|
+
const match = section.match(regex);
|
|
68
|
+
if (!match) return undefined;
|
|
69
|
+
const value = match[1].trim();
|
|
70
|
+
return value.length > 0 ? value : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function parseTextField(section: string): string | null | undefined {
|
|
74
|
+
const match = section.match(/(?:^|\n)Text:\s*([\s\S]*)$/);
|
|
75
|
+
if (!match) return undefined;
|
|
76
|
+
const value = match[1].trim();
|
|
77
|
+
return value.length > 0 ? value : null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function parseExaMcpTextPayload(payload: unknown): ExaSearchResponse | null {
|
|
81
|
+
const root = asRecord(payload);
|
|
82
|
+
if (!root) return null;
|
|
83
|
+
|
|
84
|
+
const content = root.content;
|
|
85
|
+
if (!Array.isArray(content)) return null;
|
|
86
|
+
|
|
87
|
+
const textBlocks = content
|
|
88
|
+
.map(item => {
|
|
89
|
+
const part = asRecord(item);
|
|
90
|
+
const text = typeof part?.text === "string" ? part.text : "";
|
|
91
|
+
return text.replace(/\r\n?/g, "\n").trim();
|
|
92
|
+
})
|
|
93
|
+
.filter(text => text.length > 0);
|
|
94
|
+
|
|
95
|
+
if (textBlocks.length === 0) return null;
|
|
96
|
+
|
|
97
|
+
const sections = textBlocks
|
|
98
|
+
.join("\n\n")
|
|
99
|
+
.split(/\n{2,}(?=Title:\s*[^\n]*(?:\n(?:URL|Author|Published Date|Text):))/)
|
|
100
|
+
.map(section => section.trim())
|
|
101
|
+
.filter(section => section.startsWith("Title:"));
|
|
102
|
+
|
|
103
|
+
const results: ExaSearchResult[] = [];
|
|
104
|
+
for (const section of sections) {
|
|
105
|
+
const title = parseOptionalField(section, "Title");
|
|
106
|
+
const url = parseOptionalField(section, "URL");
|
|
107
|
+
const author = parseOptionalField(section, "Author");
|
|
108
|
+
const publishedDate = parseOptionalField(section, "Published Date");
|
|
109
|
+
const text = parseTextField(section);
|
|
110
|
+
|
|
111
|
+
if (!title && !url && !text) continue;
|
|
112
|
+
|
|
113
|
+
results.push({
|
|
114
|
+
title: title ?? undefined,
|
|
115
|
+
url: url ?? undefined,
|
|
116
|
+
author: author ?? undefined,
|
|
117
|
+
publishedDate: publishedDate ?? undefined,
|
|
118
|
+
text: text ?? undefined,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (results.length === 0) return null;
|
|
123
|
+
return { results };
|
|
124
|
+
}
|
|
59
125
|
|
|
60
126
|
export function normalizeSearchType(type: ExaSearchParamType | undefined): ExaSearchType {
|
|
61
127
|
if (!type) return "auto";
|
|
@@ -133,6 +199,32 @@ async function callExaSearch(apiKey: string, params: ExaSearchParams): Promise<E
|
|
|
133
199
|
|
|
134
200
|
return response.json() as Promise<ExaSearchResponse>;
|
|
135
201
|
}
|
|
202
|
+
function buildExaMcpArgs(params: ExaSearchParams): Record<string, unknown> {
|
|
203
|
+
const args: Record<string, unknown> = { query: params.query };
|
|
204
|
+
if (params.num_results !== undefined) args.num_results = params.num_results;
|
|
205
|
+
if (params.type !== undefined) args.type = params.type;
|
|
206
|
+
if (params.include_domains !== undefined) args.include_domains = params.include_domains;
|
|
207
|
+
if (params.exclude_domains !== undefined) args.exclude_domains = params.exclude_domains;
|
|
208
|
+
if (params.start_published_date !== undefined) args.start_published_date = params.start_published_date;
|
|
209
|
+
if (params.end_published_date !== undefined) args.end_published_date = params.end_published_date;
|
|
210
|
+
return args;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async function callExaMcpSearch(params: ExaSearchParams): Promise<ExaSearchResponse> {
|
|
214
|
+
const response = await callExaTool("web_search_exa", buildExaMcpArgs(params), findApiKey(), {
|
|
215
|
+
signal: withHardTimeout(params.signal),
|
|
216
|
+
});
|
|
217
|
+
if (isSearchResponse(response)) {
|
|
218
|
+
return response as ExaSearchResponse;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const parsed = parseExaMcpTextPayload(response);
|
|
222
|
+
if (parsed) {
|
|
223
|
+
return parsed;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
throw new Error("Exa MCP search returned unexpected response shape.");
|
|
227
|
+
}
|
|
136
228
|
|
|
137
229
|
/** Execute Exa web search */
|
|
138
230
|
export async function searchExa(params: ExaSearchParams): Promise<SearchResponse> {
|
|
@@ -140,11 +232,7 @@ export async function searchExa(params: ExaSearchParams): Promise<SearchResponse
|
|
|
140
232
|
? await params.authStorage.getApiKey("exa", params.sessionId, { signal: params.signal })
|
|
141
233
|
: undefined;
|
|
142
234
|
const apiKey = storedKey ?? getEnvApiKey("exa");
|
|
143
|
-
|
|
144
|
-
throw new Error("Exa credentials not found. Set EXA_API_KEY or login with 'omp /login exa'.");
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const response = await callExaSearch(apiKey, params);
|
|
235
|
+
const response = apiKey ? await callExaSearch(apiKey, params) : await callExaMcpSearch(params);
|
|
148
236
|
|
|
149
237
|
// Convert to unified SearchResponse
|
|
150
238
|
const sources: SearchSource[] = [];
|
|
@@ -183,14 +271,30 @@ export class ExaProvider extends SearchProvider {
|
|
|
183
271
|
readonly label = "Exa";
|
|
184
272
|
|
|
185
273
|
isAvailable(authStorage: AuthStorage): boolean {
|
|
274
|
+
if (!this.#settingsAllowSearch()) return false;
|
|
275
|
+
return !!getEnvApiKey("exa") || authStorage.hasAuth("exa");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Exa ships an unauthenticated public MCP fallback, so an explicit
|
|
280
|
+
* selection (programmatic or via `providers.webSearch: exa`) routes
|
|
281
|
+
* through MCP even when no credential is configured. The auto chain
|
|
282
|
+
* still uses {@link isAvailable} so an unrelated configured provider
|
|
283
|
+
* keeps priority over the public fallback.
|
|
284
|
+
*/
|
|
285
|
+
isExplicitlyAvailable(_authStorage: AuthStorage): boolean {
|
|
286
|
+
return this.#settingsAllowSearch();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
#settingsAllowSearch(): boolean {
|
|
186
290
|
try {
|
|
187
291
|
if (settings.get("exa.enabled") === false || settings.get("exa.enableSearch") === false) {
|
|
188
292
|
return false;
|
|
189
293
|
}
|
|
190
294
|
} catch {
|
|
191
|
-
// Settings may be unavailable before CLI initialization;
|
|
295
|
+
// Settings may be unavailable before CLI initialization; assume not disabled.
|
|
192
296
|
}
|
|
193
|
-
return
|
|
297
|
+
return true;
|
|
194
298
|
}
|
|
195
299
|
|
|
196
300
|
search(params: SearchParams): Promise<SearchResponse> {
|
|
@@ -28,7 +28,7 @@ const PERPLEXITY_OAUTH_ASK_URL = "https://www.perplexity.ai/rest/sse/perplexity_
|
|
|
28
28
|
|
|
29
29
|
const DEFAULT_MAX_TOKENS = 8192;
|
|
30
30
|
const DEFAULT_TEMPERATURE = 0.2;
|
|
31
|
-
const DEFAULT_NUM_SEARCH_RESULTS =
|
|
31
|
+
const DEFAULT_NUM_SEARCH_RESULTS = 20;
|
|
32
32
|
const OAUTH_EXPIRY_BUFFER_MS = 5 * 60 * 1000;
|
|
33
33
|
const OAUTH_API_VERSION = "2.18";
|
|
34
34
|
const OAUTH_USER_AGENT = "Perplexity/641 CFNetwork/1568 Darwin/25.2.0";
|
|
@@ -155,11 +155,11 @@ export interface PerplexitySearchParams {
|
|
|
155
155
|
system_prompt?: string;
|
|
156
156
|
search_recency_filter?: "hour" | "day" | "week" | "month" | "year";
|
|
157
157
|
num_results?: number;
|
|
158
|
-
/** Maximum output tokens. Defaults to
|
|
158
|
+
/** Maximum output tokens. Defaults to 8192. */
|
|
159
159
|
max_tokens?: number;
|
|
160
160
|
/** Sampling temperature (0–1). Lower = more focused/factual. Defaults to 0.2. */
|
|
161
161
|
temperature?: number;
|
|
162
|
-
/** Number of search results to retrieve. Defaults to
|
|
162
|
+
/** Number of search results to retrieve. Defaults to 20. */
|
|
163
163
|
num_search_results?: number;
|
|
164
164
|
authStorage: AuthStorage;
|
|
165
165
|
sessionId?: string;
|
|
@@ -470,11 +470,14 @@ function parseResponse(response: PerplexityResponse): SearchResponse {
|
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
+
const relatedQuestions = (response.related_questions ?? []).filter(q => q.trim().length > 0);
|
|
474
|
+
|
|
473
475
|
return {
|
|
474
476
|
provider: "perplexity",
|
|
475
477
|
answer: answer || undefined,
|
|
476
478
|
sources,
|
|
477
479
|
citations: citations.length > 0 ? citations : undefined,
|
|
480
|
+
relatedQuestions: relatedQuestions.length > 0 ? relatedQuestions : undefined,
|
|
478
481
|
usage: response.usage
|
|
479
482
|
? {
|
|
480
483
|
inputTokens: response.usage.prompt_tokens,
|
|
@@ -532,11 +535,12 @@ export async function searchPerplexity(params: PerplexitySearchParams): Promise<
|
|
|
532
535
|
num_search_results: params.num_search_results ?? DEFAULT_NUM_SEARCH_RESULTS,
|
|
533
536
|
web_search_options: {
|
|
534
537
|
search_type: "pro",
|
|
535
|
-
search_context_size: "
|
|
538
|
+
search_context_size: "high",
|
|
536
539
|
},
|
|
537
540
|
enable_search_classifier: true,
|
|
538
541
|
reasoning_effort: "medium",
|
|
539
542
|
language_preference: "en",
|
|
543
|
+
return_related_questions: true,
|
|
540
544
|
};
|
|
541
545
|
|
|
542
546
|
if (params.search_recency_filter) {
|
package/src/web/search/types.ts
CHANGED
|
@@ -53,7 +53,7 @@ export const SEARCH_PROVIDER_OPTIONS = [
|
|
|
53
53
|
description: "OpenAI's native web_search (uses ChatGPT OAuth via /login openai-codex)",
|
|
54
54
|
},
|
|
55
55
|
{ value: "zai", label: "Z.AI", description: "Calls Z.AI webSearchPrime MCP" },
|
|
56
|
-
{ value: "exa", label: "Exa", description: "
|
|
56
|
+
{ value: "exa", label: "Exa", description: "Uses Exa API when EXA_API_KEY is set; falls back to Exa MCP" },
|
|
57
57
|
{ value: "parallel", label: "Parallel", description: "Requires PARALLEL_API_KEY" },
|
|
58
58
|
{ value: "kagi", label: "Kagi", description: "Requires KAGI_API_KEY and Kagi Search API beta access" },
|
|
59
59
|
{ value: "synthetic", label: "Synthetic", description: "Requires SYNTHETIC_API_KEY" },
|
|
@@ -472,6 +472,7 @@ export interface PerplexityResponse {
|
|
|
472
472
|
choices: PerplexityChoice[];
|
|
473
473
|
citations?: string[] | null;
|
|
474
474
|
search_results?: PerplexitySearchResult[] | null;
|
|
475
|
+
related_questions?: string[] | null;
|
|
475
476
|
type?: PerplexityCompletionResponseType | null;
|
|
476
477
|
status?: PerplexityCompletionResponseStatus | null;
|
|
477
478
|
}
|