Skip to content

Commit 490e14a

Browse files
Jasmine ZhangJasmine Zhang
authored andcommitted
fix(tavily): allow env fallback for unresolved apiKey refs
1 parent 025f8fb commit 490e14a

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

extensions/tavily/src/config.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// Tavily helper module supports config behavior.
22
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
33
import { resolvePositiveTimeoutSeconds } from "openclaw/plugin-sdk/provider-web-search";
4-
import {
5-
normalizeResolvedSecretInputString,
6-
normalizeSecretInput,
7-
} from "openclaw/plugin-sdk/secret-input";
4+
import { normalizeSecretInput, resolveSecretInputString } from "openclaw/plugin-sdk/secret-input";
85
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
96

107
export const DEFAULT_TAVILY_BASE_URL = "https://api.tavily.com";
@@ -35,12 +32,12 @@ export function resolveTavilySearchConfig(cfg?: OpenClawConfig): TavilySearchCon
3532
}
3633

3734
function normalizeConfiguredSecret(value: unknown, path: string): string | undefined {
38-
return normalizeSecretInput(
39-
normalizeResolvedSecretInputString({
40-
value,
41-
path,
42-
}),
43-
);
35+
const resolved = resolveSecretInputString({
36+
value,
37+
path,
38+
mode: "configured_unavailable",
39+
});
40+
return resolved.status === "available" ? normalizeSecretInput(resolved.value) : undefined;
4441
}
4542

4643
export function resolveTavilyApiKey(cfg?: OpenClawConfig): string | undefined {

extensions/tavily/src/tavily-tools.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,30 @@ describe("tavily tools", () => {
427427
expect(resolveTavilyExtractTimeoutSeconds()).toBe(DEFAULT_TAVILY_EXTRACT_TIMEOUT_SECONDS);
428428
});
429429

430+
it("falls back to process.env when the configured apiKey is an unresolved SecretRef", () => {
431+
vi.stubEnv("TAVILY_API_KEY", "env-key");
432+
433+
const cfg = {
434+
plugins: {
435+
entries: {
436+
tavily: {
437+
config: {
438+
webSearch: {
439+
apiKey: {
440+
source: "env",
441+
provider: "default",
442+
id: "TAVILY_API_KEY",
443+
},
444+
},
445+
},
446+
},
447+
},
448+
},
449+
} as OpenClawConfig;
450+
451+
expect(resolveTavilyApiKey(cfg)).toBe("env-key");
452+
});
453+
430454
it("accepts positive numeric timeout overrides and floors them", () => {
431455
expect(resolveTavilySearchTimeoutSeconds(19.9)).toBe(19);
432456
expect(resolveTavilyExtractTimeoutSeconds(42.7)).toBe(42);

0 commit comments

Comments
 (0)