opencandle 0.2.0 → 0.3.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/README.md +110 -87
- package/dist/analysts/orchestrator.js +1 -2
- package/dist/analysts/orchestrator.js.map +1 -1
- package/dist/config.d.ts +25 -5
- package/dist/config.js +16 -8
- package/dist/config.js.map +1 -1
- package/dist/infra/cache.d.ts +4 -0
- package/dist/infra/cache.js +4 -0
- package/dist/infra/cache.js.map +1 -1
- package/dist/infra/rate-limiter.js +6 -0
- package/dist/infra/rate-limiter.js.map +1 -1
- package/dist/onboarding/connect.d.ts +23 -0
- package/dist/onboarding/connect.js +107 -0
- package/dist/onboarding/connect.js.map +1 -0
- package/dist/onboarding/credential-interceptor.d.ts +44 -0
- package/dist/onboarding/credential-interceptor.js +72 -0
- package/dist/onboarding/credential-interceptor.js.map +1 -0
- package/dist/onboarding/degradation-accumulator.d.ts +21 -0
- package/dist/onboarding/degradation-accumulator.js +55 -0
- package/dist/onboarding/degradation-accumulator.js.map +1 -0
- package/dist/onboarding/prompt-user.d.ts +23 -0
- package/dist/onboarding/prompt-user.js +61 -0
- package/dist/onboarding/prompt-user.js.map +1 -0
- package/dist/onboarding/providers.d.ts +109 -0
- package/dist/onboarding/providers.js +236 -0
- package/dist/onboarding/providers.js.map +1 -0
- package/dist/onboarding/state.d.ts +31 -2
- package/dist/onboarding/state.js +141 -13
- package/dist/onboarding/state.js.map +1 -1
- package/dist/onboarding/tool-helpers.d.ts +34 -0
- package/dist/onboarding/tool-helpers.js +80 -0
- package/dist/onboarding/tool-helpers.js.map +1 -0
- package/dist/onboarding/tool-tags.d.ts +37 -0
- package/dist/onboarding/tool-tags.js +149 -0
- package/dist/onboarding/tool-tags.js.map +1 -0
- package/dist/onboarding/validation.d.ts +19 -0
- package/dist/onboarding/validation.js +117 -0
- package/dist/onboarding/validation.js.map +1 -0
- package/dist/pi/opencandle-extension.js +303 -4
- package/dist/pi/opencandle-extension.js.map +1 -1
- package/dist/pi/setup.d.ts +0 -1
- package/dist/pi/setup.js +66 -119
- package/dist/pi/setup.js.map +1 -1
- package/dist/prompts/context-builder.js +2 -1
- package/dist/prompts/context-builder.js.map +1 -1
- package/dist/providers/alpha-vantage.js +20 -1
- package/dist/providers/alpha-vantage.js.map +1 -1
- package/dist/providers/exa-search.d.ts +39 -0
- package/dist/providers/exa-search.js +276 -0
- package/dist/providers/exa-search.js.map +1 -0
- package/dist/providers/finnhub.d.ts +17 -0
- package/dist/providers/finnhub.js +94 -0
- package/dist/providers/finnhub.js.map +1 -0
- package/dist/providers/fred.js +13 -1
- package/dist/providers/fred.js.map +1 -1
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/provider-credential-error.d.ts +8 -0
- package/dist/providers/provider-credential-error.js +22 -0
- package/dist/providers/provider-credential-error.js.map +1 -0
- package/dist/providers/reddit.d.ts +8 -0
- package/dist/providers/reddit.js +36 -9
- package/dist/providers/reddit.js.map +1 -1
- package/dist/providers/twitter.js +2 -8
- package/dist/providers/twitter.js.map +1 -1
- package/dist/providers/web-search.d.ts +17 -0
- package/dist/providers/web-search.js +224 -0
- package/dist/providers/web-search.js.map +1 -0
- package/dist/providers/wrap-provider.d.ts +7 -0
- package/dist/providers/wrap-provider.js +15 -0
- package/dist/providers/wrap-provider.js.map +1 -1
- package/dist/routing/classify-intent.js +22 -0
- package/dist/routing/classify-intent.js.map +1 -1
- package/dist/runtime/session-coordinator.d.ts +0 -1
- package/dist/runtime/session-coordinator.js.map +1 -1
- package/dist/sentiment/adapters/finnhub.d.ts +7 -0
- package/dist/sentiment/adapters/finnhub.js +39 -0
- package/dist/sentiment/adapters/finnhub.js.map +1 -0
- package/dist/sentiment/adapters/reddit.d.ts +11 -0
- package/dist/sentiment/adapters/reddit.js +54 -0
- package/dist/sentiment/adapters/reddit.js.map +1 -0
- package/dist/sentiment/adapters/twitter.d.ts +9 -0
- package/dist/sentiment/adapters/twitter.js +32 -0
- package/dist/sentiment/adapters/twitter.js.map +1 -0
- package/dist/sentiment/adapters/web.d.ts +9 -0
- package/dist/sentiment/adapters/web.js +40 -0
- package/dist/sentiment/adapters/web.js.map +1 -0
- package/dist/sentiment/index.d.ts +16 -0
- package/dist/sentiment/index.js +44 -0
- package/dist/sentiment/index.js.map +1 -0
- package/dist/sentiment/keywords.d.ts +2 -0
- package/dist/sentiment/keywords.js +9 -0
- package/dist/sentiment/keywords.js.map +1 -0
- package/dist/sentiment/pipeline.d.ts +9 -0
- package/dist/sentiment/pipeline.js +57 -0
- package/dist/sentiment/pipeline.js.map +1 -0
- package/dist/sentiment/scorer.d.ts +9 -0
- package/dist/sentiment/scorer.js +64 -0
- package/dist/sentiment/scorer.js.map +1 -0
- package/dist/sentiment/store.d.ts +24 -0
- package/dist/sentiment/store.js +177 -0
- package/dist/sentiment/store.js.map +1 -0
- package/dist/sentiment/trends.d.ts +13 -0
- package/dist/sentiment/trends.js +73 -0
- package/dist/sentiment/trends.js.map +1 -0
- package/dist/sentiment/types.d.ts +66 -0
- package/dist/sentiment/types.js +54 -0
- package/dist/sentiment/types.js.map +1 -0
- package/dist/system-prompt.js +9 -1
- package/dist/system-prompt.js.map +1 -1
- package/dist/tools/fundamentals/company-overview.d.ts +3 -1
- package/dist/tools/fundamentals/company-overview.js +27 -27
- package/dist/tools/fundamentals/company-overview.js.map +1 -1
- package/dist/tools/fundamentals/comps.js +45 -45
- package/dist/tools/fundamentals/comps.js.map +1 -1
- package/dist/tools/fundamentals/dcf.js +82 -82
- package/dist/tools/fundamentals/dcf.js.map +1 -1
- package/dist/tools/fundamentals/earnings.d.ts +3 -1
- package/dist/tools/fundamentals/earnings.js +25 -25
- package/dist/tools/fundamentals/earnings.js.map +1 -1
- package/dist/tools/fundamentals/financials.d.ts +3 -1
- package/dist/tools/fundamentals/financials.js +23 -23
- package/dist/tools/fundamentals/financials.js.map +1 -1
- package/dist/tools/index.js +8 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/interaction/ask-user.js +28 -64
- package/dist/tools/interaction/ask-user.js.map +1 -1
- package/dist/tools/macro/fred-data.d.ts +3 -1
- package/dist/tools/macro/fred-data.js +26 -26
- package/dist/tools/macro/fred-data.js.map +1 -1
- package/dist/tools/sentiment/reddit-sentiment.d.ts +3 -1
- package/dist/tools/sentiment/reddit-sentiment.js +107 -22
- package/dist/tools/sentiment/reddit-sentiment.js.map +1 -1
- package/dist/tools/sentiment/sentiment-summary.d.ts +7 -0
- package/dist/tools/sentiment/sentiment-summary.js +230 -0
- package/dist/tools/sentiment/sentiment-summary.js.map +1 -0
- package/dist/tools/sentiment/sentiment-trend.d.ts +22 -0
- package/dist/tools/sentiment/sentiment-trend.js +39 -0
- package/dist/tools/sentiment/sentiment-trend.js.map +1 -0
- package/dist/tools/sentiment/twitter-sentiment.js +17 -0
- package/dist/tools/sentiment/twitter-sentiment.js.map +1 -1
- package/dist/tools/sentiment/web-search.d.ts +11 -0
- package/dist/tools/sentiment/web-search.js +115 -0
- package/dist/tools/sentiment/web-search.js.map +1 -0
- package/dist/tools/sentiment/web-sentiment.d.ts +8 -0
- package/dist/tools/sentiment/web-sentiment.js +66 -0
- package/dist/tools/sentiment/web-sentiment.js.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/sentiment.d.ts +21 -0
- package/package.json +19 -3
- package/dist/tools/sentiment/news-sentiment.d.ts +0 -7
- package/dist/tools/sentiment/news-sentiment.js +0 -55
- package/dist/tools/sentiment/news-sentiment.js.map +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ProviderId } from "./providers.js";
|
|
2
|
+
import type { OnboardingState } from "./state.js";
|
|
3
|
+
import type { CredentialRequiredReason } from "./tool-tags.js";
|
|
4
|
+
export interface InterceptInput {
|
|
5
|
+
/** The provider id parsed from the tagged tool-result content. */
|
|
6
|
+
provider: ProviderId;
|
|
7
|
+
/** Why the credential was flagged as required. */
|
|
8
|
+
reason: CredentialRequiredReason;
|
|
9
|
+
/** Current persistent onboarding state (providers map, welcome flag). */
|
|
10
|
+
state: OnboardingState;
|
|
11
|
+
/** Providers already prompted at least once in this session (across workflows). */
|
|
12
|
+
sessionPromptedSet: ReadonlySet<ProviderId>;
|
|
13
|
+
/**
|
|
14
|
+
* Whether a hard-tier provider has already fired a prompt earlier in the
|
|
15
|
+
* current workflow invocation. When true, subsequent hard-provider prompts
|
|
16
|
+
* in the same workflow SHALL be silenced per the "at most one prompt per
|
|
17
|
+
* workflow" requirement in `conversational-provider-setup.spec.md`.
|
|
18
|
+
*/
|
|
19
|
+
hardPromptFiredInWorkflow: boolean;
|
|
20
|
+
/** Injected clock for deterministic snooze-expiry tests. */
|
|
21
|
+
now: Date;
|
|
22
|
+
}
|
|
23
|
+
/** Outcome of the interception decision. */
|
|
24
|
+
export type InterceptAction = {
|
|
25
|
+
action: "prompt";
|
|
26
|
+
provider: ProviderId;
|
|
27
|
+
reason: CredentialRequiredReason;
|
|
28
|
+
} | {
|
|
29
|
+
action: "skip";
|
|
30
|
+
provider: ProviderId;
|
|
31
|
+
remediation: string;
|
|
32
|
+
/** True when the skip is due to explicit never_ask — downstream gap-note
|
|
33
|
+
* synthesis should suppress the `/connect` remediation in that case. */
|
|
34
|
+
silenced: boolean;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Pure decision function — given an `InterceptInput`, return either a
|
|
38
|
+
* `prompt` action (the extension handler should pause and call `promptUser`)
|
|
39
|
+
* or a `skip` action (the handler should replace the tool result with a
|
|
40
|
+
* `[OPENCANDLE_SKIPPED ...]` placeholder).
|
|
41
|
+
*
|
|
42
|
+
* No side effects. No Pi imports. Trivially unit-testable.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveCredentialRequired(input: InterceptInput): InterceptAction;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Pure decision function for handling `[OPENCANDLE_CREDENTIAL_REQUIRED ...]`
|
|
2
|
+
// tool results. This module has NO Pi dependencies so it can be tested in
|
|
3
|
+
// isolation — the Pi extension `tool_result` handler is a thin wrapper that
|
|
4
|
+
// calls this function, inspects the returned `InterceptAction`, and drives
|
|
5
|
+
// the appropriate side effects (promptUser, state mutation, tool rerun).
|
|
6
|
+
//
|
|
7
|
+
// Decision table — see design.md Decision 3 for the canonical version.
|
|
8
|
+
import { getProvider } from "./providers.js";
|
|
9
|
+
function buildRemediation(providerId) {
|
|
10
|
+
const descriptor = getProvider(providerId);
|
|
11
|
+
// Prefer the first alias as the friendly target; fall back to the id.
|
|
12
|
+
const alias = descriptor.aliases[0] ?? providerId;
|
|
13
|
+
return `run /connect ${alias} to unlock`;
|
|
14
|
+
}
|
|
15
|
+
function skip(providerId, silenced) {
|
|
16
|
+
return {
|
|
17
|
+
action: "skip",
|
|
18
|
+
provider: providerId,
|
|
19
|
+
remediation: buildRemediation(providerId),
|
|
20
|
+
silenced,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Pure decision function — given an `InterceptInput`, return either a
|
|
25
|
+
* `prompt` action (the extension handler should pause and call `promptUser`)
|
|
26
|
+
* or a `skip` action (the handler should replace the tool result with a
|
|
27
|
+
* `[OPENCANDLE_SKIPPED ...]` placeholder).
|
|
28
|
+
*
|
|
29
|
+
* No side effects. No Pi imports. Trivially unit-testable.
|
|
30
|
+
*/
|
|
31
|
+
export function resolveCredentialRequired(input) {
|
|
32
|
+
const { provider, reason, state, sessionPromptedSet, hardPromptFiredInWorkflow, now, } = input;
|
|
33
|
+
const descriptor = getProvider(provider);
|
|
34
|
+
const entry = state.providers[provider];
|
|
35
|
+
// 1. Never-ask: always skip, marked silenced so the gap-note copy drops the
|
|
36
|
+
// `/connect` remediation.
|
|
37
|
+
if (entry?.status === "never_ask") {
|
|
38
|
+
return skip(provider, true);
|
|
39
|
+
}
|
|
40
|
+
// 2. Completed + missing (defensive — shouldn't normally happen because the
|
|
41
|
+
// tool layer only emits `missing` when `hasCredential` returns false, and
|
|
42
|
+
// a completed state implies the credential was persisted).
|
|
43
|
+
if (entry?.status === "completed" && reason === "missing") {
|
|
44
|
+
return skip(provider, false);
|
|
45
|
+
}
|
|
46
|
+
// 3. Session-level dedup: a previous prompt this session already settled
|
|
47
|
+
// the user's answer for this provider. Don't re-ask until next session.
|
|
48
|
+
if (sessionPromptedSet.has(provider)) {
|
|
49
|
+
return skip(provider, false);
|
|
50
|
+
}
|
|
51
|
+
// 4. Per-workflow cap: at most one hard-provider prompt per workflow run.
|
|
52
|
+
if (hardPromptFiredInWorkflow && descriptor.tier === "hard") {
|
|
53
|
+
return skip(provider, false);
|
|
54
|
+
}
|
|
55
|
+
// 5. Active snooze: skip without decrementing the session set (the user
|
|
56
|
+
// will see the prompt again if they try a workflow after snoozeUntil).
|
|
57
|
+
if (entry?.status === "snoozed") {
|
|
58
|
+
const until = Date.parse(entry.snoozeUntil);
|
|
59
|
+
if (!Number.isNaN(until) && now.getTime() < until) {
|
|
60
|
+
return skip(provider, false);
|
|
61
|
+
}
|
|
62
|
+
// snoozed but expired → fall through to prompt.
|
|
63
|
+
}
|
|
64
|
+
// 6. Completed + stale: re-prompt. This is the ONE stale-credential path
|
|
65
|
+
// this change ships — the full failure-as-invitation story is deferred.
|
|
66
|
+
if (entry?.status === "completed" && reason === "stale") {
|
|
67
|
+
return { action: "prompt", provider, reason };
|
|
68
|
+
}
|
|
69
|
+
// 7. Default: prompt.
|
|
70
|
+
return { action: "prompt", provider, reason };
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=credential-interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-interceptor.js","sourceRoot":"","sources":["../../src/onboarding/credential-interceptor.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAC1E,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,EAAE;AACF,uEAAuE;AAGvE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAwC7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,IAAI,yBAAyB,IAAI,UAAU,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,wEAAwE;IACxE,0EAA0E;IAC1E,IAAI,KAAK,EAAE,MAAM,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,gDAAgD;IAClD,CAAC;IAED,yEAAyE;IACzE,2EAA2E;IAC3E,IAAI,KAAK,EAAE,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QACxD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAChD,CAAC;IAED,sBAAsB;IACtB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProviderId } from "./providers.js";
|
|
2
|
+
import type { OnboardingState } from "./state.js";
|
|
3
|
+
export interface DegradationAccumulator {
|
|
4
|
+
/** Record that a soft-tier provider fell back during this turn. Idempotent. */
|
|
5
|
+
record(provider: ProviderId): void;
|
|
6
|
+
/** Number of distinct providers recorded since the last reset. */
|
|
7
|
+
size(): number;
|
|
8
|
+
/** True when nothing has been recorded since the last reset. */
|
|
9
|
+
isEmpty(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Build a newline-delimited list of `[OPENCANDLE_SKIPPED ...]` tags — one
|
|
12
|
+
* per distinct recorded provider. Providers whose `state.providers[id]`
|
|
13
|
+
* entry has `status: "never_ask"` get the `(silenced)` suffix in their
|
|
14
|
+
* remediation so the system prompt instruction suppresses the `/connect`
|
|
15
|
+
* link in the final answer. Returns `null` when no providers are recorded.
|
|
16
|
+
*/
|
|
17
|
+
buildCombinedAnnotation(state: OnboardingState): string | null;
|
|
18
|
+
/** Clear all recorded providers. Call this at turn_start. */
|
|
19
|
+
reset(): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function createDegradationAccumulator(): DegradationAccumulator;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Per-turn accumulator for soft-tier provider degradations. When a soft
|
|
2
|
+
// provider falls back to a keyless alternative (e.g. Brave → DuckDuckGo, Exa →
|
|
3
|
+
// keyless MCP, Finnhub → cached/free source), the tool result content carries
|
|
4
|
+
// a `[OPENCANDLE_SOFT_DEGRADED ...]` tag. The extension's `tool_result` hook
|
|
5
|
+
// records the provider id in this accumulator WITHOUT mutating the tool
|
|
6
|
+
// result; at `turn_end` the accumulator builds a single combined
|
|
7
|
+
// `[OPENCANDLE_SKIPPED ...]`-style annotation that gets appended to the
|
|
8
|
+
// session as a sidecar entry for observability.
|
|
9
|
+
//
|
|
10
|
+
// Per-provider state (never_ask / snoozed / completed) lives in the persistent
|
|
11
|
+
// OnboardingState on disk — the accumulator stays pure and consults the
|
|
12
|
+
// caller-supplied state snapshot at `buildCombinedAnnotation` time. This keeps
|
|
13
|
+
// the accumulator trivially testable without mocking the filesystem.
|
|
14
|
+
import { getProvider } from "./providers.js";
|
|
15
|
+
import { buildSkippedTag } from "./tool-tags.js";
|
|
16
|
+
export function createDegradationAccumulator() {
|
|
17
|
+
const recorded = new Set();
|
|
18
|
+
return {
|
|
19
|
+
record(provider) {
|
|
20
|
+
recorded.add(provider);
|
|
21
|
+
},
|
|
22
|
+
size() {
|
|
23
|
+
return recorded.size;
|
|
24
|
+
},
|
|
25
|
+
isEmpty() {
|
|
26
|
+
return recorded.size === 0;
|
|
27
|
+
},
|
|
28
|
+
buildCombinedAnnotation(state) {
|
|
29
|
+
if (recorded.size === 0)
|
|
30
|
+
return null;
|
|
31
|
+
const lines = [];
|
|
32
|
+
for (const provider of recorded) {
|
|
33
|
+
const descriptor = getProvider(provider);
|
|
34
|
+
const entry = state.providers[provider];
|
|
35
|
+
const silenced = entry?.status === "never_ask";
|
|
36
|
+
const alias = descriptor.aliases[0] ?? descriptor.id;
|
|
37
|
+
const baseRemediation = `run /connect ${alias} to unlock`;
|
|
38
|
+
const remediation = silenced
|
|
39
|
+
? `${baseRemediation} (silenced)`
|
|
40
|
+
: baseRemediation;
|
|
41
|
+
lines.push(buildSkippedTag({
|
|
42
|
+
provider,
|
|
43
|
+
reason: "credential_not_provided",
|
|
44
|
+
remediation,
|
|
45
|
+
silenced: silenced || undefined,
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
return lines.join("\n");
|
|
49
|
+
},
|
|
50
|
+
reset() {
|
|
51
|
+
recorded.clear();
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=degradation-accumulator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"degradation-accumulator.js","sourceRoot":"","sources":["../../src/onboarding/degradation-accumulator.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,wEAAwE;AACxE,iEAAiE;AACjE,wEAAwE;AACxE,gDAAgD;AAChD,EAAE;AACF,+EAA+E;AAC/E,wEAAwE;AACxE,+EAA+E;AAC/E,qEAAqE;AAGrE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAqBjD,MAAM,UAAU,4BAA4B;IAC1C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAc,CAAC;IAEvC,OAAO;QACL,MAAM,CAAC,QAAoB;YACzB,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;QACD,IAAI;YACF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QACD,OAAO;YACL,OAAO,QAAQ,CAAC,IAAI,KAAK,CAAC,CAAC;QAC7B,CAAC;QACD,uBAAuB,CAAC,KAAsB;YAC5C,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC;YACrC,MAAM,KAAK,GAAa,EAAE,CAAC;YAC3B,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE,CAAC;gBAChC,MAAM,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;gBACzC,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBACxC,MAAM,QAAQ,GAAG,KAAK,EAAE,MAAM,KAAK,WAAW,CAAC;gBAC/C,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC;gBACrD,MAAM,eAAe,GAAG,gBAAgB,KAAK,YAAY,CAAC;gBAC1D,MAAM,WAAW,GAAG,QAAQ;oBAC1B,CAAC,CAAC,GAAG,eAAe,aAAa;oBACjC,CAAC,CAAC,eAAe,CAAC;gBACpB,KAAK,CAAC,IAAI,CACR,eAAe,CAAC;oBACd,QAAQ;oBACR,MAAM,EAAE,yBAAyB;oBACjC,WAAW;oBACX,QAAQ,EAAE,QAAQ,IAAI,SAAS;iBAChC,CAAC,CACH,CAAC;YACJ,CAAC;YACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QACD,KAAK;YACH,QAAQ,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import type { AskUserHandler } from "../types/index.js";
|
|
3
|
+
export interface PromptOptions {
|
|
4
|
+
question: string;
|
|
5
|
+
questionType: "select" | "text" | "confirm";
|
|
6
|
+
options?: string[];
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
reason?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PromptResult {
|
|
11
|
+
answer: string | null;
|
|
12
|
+
cancelled: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Ask the user a structured question, routing to the appropriate UI primitive
|
|
16
|
+
* (`ctx.ui.select` / `ctx.ui.input` / `ctx.ui.confirm`).
|
|
17
|
+
*
|
|
18
|
+
* When an `askUserHandler` is injected (test harness, programmatic runs), the
|
|
19
|
+
* handler takes precedence over `ctx.ui` and provides the answer directly.
|
|
20
|
+
*
|
|
21
|
+
* When neither a handler nor a UI is available, returns `{answer: null, cancelled: true}`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function promptUser(ctx: ExtensionContext, opts: PromptOptions, handler?: AskUserHandler): Promise<PromptResult>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Shared prompt primitive used by both the `ask_user` tool and the
|
|
2
|
+
// credential-interception handler in the Pi `tool_result` hook.
|
|
3
|
+
//
|
|
4
|
+
// The original `ask_user` tool embedded its UI routing in a closure inside
|
|
5
|
+
// `execute()`. Extracting it here means the `tool_result` handler can call
|
|
6
|
+
// the same logic without synthesizing a fake tool call (Pi has no "execute
|
|
7
|
+
// a tool now" API), and the headless harness's `askUserHandler` injection
|
|
8
|
+
// point is preserved for automated flows.
|
|
9
|
+
/**
|
|
10
|
+
* Ask the user a structured question, routing to the appropriate UI primitive
|
|
11
|
+
* (`ctx.ui.select` / `ctx.ui.input` / `ctx.ui.confirm`).
|
|
12
|
+
*
|
|
13
|
+
* When an `askUserHandler` is injected (test harness, programmatic runs), the
|
|
14
|
+
* handler takes precedence over `ctx.ui` and provides the answer directly.
|
|
15
|
+
*
|
|
16
|
+
* When neither a handler nor a UI is available, returns `{answer: null, cancelled: true}`.
|
|
17
|
+
*/
|
|
18
|
+
export async function promptUser(ctx, opts, handler) {
|
|
19
|
+
// Priority: injected handler > UI > no-UI fallback.
|
|
20
|
+
if (handler) {
|
|
21
|
+
const result = await handler({
|
|
22
|
+
question: opts.question,
|
|
23
|
+
questionType: opts.questionType,
|
|
24
|
+
options: opts.options,
|
|
25
|
+
placeholder: opts.placeholder,
|
|
26
|
+
reason: opts.reason,
|
|
27
|
+
});
|
|
28
|
+
if (result.cancelled) {
|
|
29
|
+
return { answer: null, cancelled: true };
|
|
30
|
+
}
|
|
31
|
+
return { answer: result.answer ?? null, cancelled: false };
|
|
32
|
+
}
|
|
33
|
+
if (!ctx?.hasUI) {
|
|
34
|
+
return { answer: null, cancelled: true };
|
|
35
|
+
}
|
|
36
|
+
switch (opts.questionType) {
|
|
37
|
+
case "select": {
|
|
38
|
+
const options = opts.options ?? [];
|
|
39
|
+
if (options.length === 0) {
|
|
40
|
+
return { answer: null, cancelled: true };
|
|
41
|
+
}
|
|
42
|
+
const choice = await ctx.ui.select(opts.question, options);
|
|
43
|
+
if (choice === undefined) {
|
|
44
|
+
return { answer: null, cancelled: true };
|
|
45
|
+
}
|
|
46
|
+
return { answer: choice, cancelled: false };
|
|
47
|
+
}
|
|
48
|
+
case "text": {
|
|
49
|
+
const input = await ctx.ui.input(opts.question, opts.placeholder ?? "");
|
|
50
|
+
if (input === undefined || input.trim() === "") {
|
|
51
|
+
return { answer: null, cancelled: true };
|
|
52
|
+
}
|
|
53
|
+
return { answer: input.trim(), cancelled: false };
|
|
54
|
+
}
|
|
55
|
+
case "confirm": {
|
|
56
|
+
const confirmed = await ctx.ui.confirm(opts.question, opts.reason ?? "");
|
|
57
|
+
return { answer: confirmed ? "Yes" : "No", cancelled: false };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=prompt-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-user.js","sourceRoot":"","sources":["../../src/onboarding/prompt-user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CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC3D,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YAC3C,CAAC;YACD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QAC9C,CAAC;QAED,KAAK,MAAM,CAAC,CAAC,CAAC;YACZ,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;YACxE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;gBAC/C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YAC3C,CAAC;YACD,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QACpD,CAAC;QAED,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;YACzE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QAChE,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export type ProviderId = "alpha_vantage" | "fred" | "finnhub" | "brave" | "exa";
|
|
2
|
+
export type ProviderCategory = "fundamentals" | "macro" | "news" | "web_search";
|
|
3
|
+
export type ProviderTier = "hard" | "soft";
|
|
4
|
+
export interface ProviderDescriptor {
|
|
5
|
+
readonly id: ProviderId;
|
|
6
|
+
readonly displayName: string;
|
|
7
|
+
readonly category: ProviderCategory;
|
|
8
|
+
/**
|
|
9
|
+
* `hard` providers pause the workflow with a just-in-time prompt when their
|
|
10
|
+
* credential is missing; they have no meaningful fallback.
|
|
11
|
+
*
|
|
12
|
+
* `soft` providers silently use a fallback path and surface a post-answer
|
|
13
|
+
* gap note in the final output.
|
|
14
|
+
*/
|
|
15
|
+
readonly tier: ProviderTier;
|
|
16
|
+
/** Lowercase friendly aliases accepted by `/connect` in addition to the id. */
|
|
17
|
+
readonly aliases: readonly string[];
|
|
18
|
+
readonly signupUrl: string;
|
|
19
|
+
readonly freeTier: boolean;
|
|
20
|
+
readonly envVar: string;
|
|
21
|
+
/** Nested key path into `OpenCandleFileConfig` where the key is persisted. */
|
|
22
|
+
readonly configPath: readonly string[];
|
|
23
|
+
readonly unlocks: readonly string[];
|
|
24
|
+
/**
|
|
25
|
+
* Human copy describing the degraded experience when missing, or `null`
|
|
26
|
+
* when there is no fallback (hard tier).
|
|
27
|
+
*/
|
|
28
|
+
readonly fallbackDescription: string | null;
|
|
29
|
+
readonly snoozeDurationDays: number;
|
|
30
|
+
readonly instructionsHint: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const PROVIDERS: readonly [{
|
|
33
|
+
readonly id: "alpha_vantage";
|
|
34
|
+
readonly displayName: "Alpha Vantage";
|
|
35
|
+
readonly category: "fundamentals";
|
|
36
|
+
readonly tier: "hard";
|
|
37
|
+
readonly aliases: readonly ["financials", "fundamentals", "company-financials", "alphavantage"];
|
|
38
|
+
readonly signupUrl: "https://www.alphavantage.co/support/#api-key";
|
|
39
|
+
readonly freeTier: true;
|
|
40
|
+
readonly envVar: "ALPHA_VANTAGE_API_KEY";
|
|
41
|
+
readonly configPath: readonly ["providers", "alphaVantage", "apiKey"];
|
|
42
|
+
readonly unlocks: readonly ["company fundamentals", "income/balance/cashflow statements", "DCF valuation", "earnings history"];
|
|
43
|
+
readonly fallbackDescription: null;
|
|
44
|
+
readonly snoozeDurationDays: 7;
|
|
45
|
+
readonly instructionsHint: "Free, about 30 seconds, signup opens in your browser";
|
|
46
|
+
}, {
|
|
47
|
+
readonly id: "fred";
|
|
48
|
+
readonly displayName: "FRED";
|
|
49
|
+
readonly category: "macro";
|
|
50
|
+
readonly tier: "hard";
|
|
51
|
+
readonly aliases: readonly ["economy", "macro", "economic-data", "st-louis-fed"];
|
|
52
|
+
readonly signupUrl: "https://fredaccount.stlouisfed.org/apikeys";
|
|
53
|
+
readonly freeTier: true;
|
|
54
|
+
readonly envVar: "FRED_API_KEY";
|
|
55
|
+
readonly configPath: readonly ["providers", "fred", "apiKey"];
|
|
56
|
+
readonly unlocks: readonly ["interest rates", "inflation data", "yield curve", "economic indicators"];
|
|
57
|
+
readonly fallbackDescription: null;
|
|
58
|
+
readonly snoozeDurationDays: 7;
|
|
59
|
+
readonly instructionsHint: "Free, about 30 seconds, requires a St. Louis Fed account";
|
|
60
|
+
}, {
|
|
61
|
+
readonly id: "finnhub";
|
|
62
|
+
readonly displayName: "Finnhub";
|
|
63
|
+
readonly category: "news";
|
|
64
|
+
readonly tier: "soft";
|
|
65
|
+
readonly aliases: readonly ["news", "company-news", "finnhub-news"];
|
|
66
|
+
readonly signupUrl: "https://finnhub.io/register";
|
|
67
|
+
readonly freeTier: true;
|
|
68
|
+
readonly envVar: "FINNHUB_API_KEY";
|
|
69
|
+
readonly configPath: readonly ["providers", "finnhub", "apiKey"];
|
|
70
|
+
readonly unlocks: readonly ["ticker-tagged company news", "sentiment enrichment with a dedicated news source"];
|
|
71
|
+
readonly fallbackDescription: "Other sentiment sources (Reddit, Twitter, web search) continue to work without Finnhub";
|
|
72
|
+
readonly snoozeDurationDays: 7;
|
|
73
|
+
readonly instructionsHint: "Free, about 30 seconds, signup opens in your browser";
|
|
74
|
+
}, {
|
|
75
|
+
readonly id: "brave";
|
|
76
|
+
readonly displayName: "Brave Search";
|
|
77
|
+
readonly category: "web_search";
|
|
78
|
+
readonly tier: "soft";
|
|
79
|
+
readonly aliases: readonly ["brave", "brave-search"];
|
|
80
|
+
readonly signupUrl: "https://brave.com/search/api/";
|
|
81
|
+
readonly freeTier: true;
|
|
82
|
+
readonly envVar: "BRAVE_API_KEY";
|
|
83
|
+
readonly configPath: readonly ["providers", "brave", "apiKey"];
|
|
84
|
+
readonly unlocks: readonly ["tier-2 web search with freshness control", "independent search index outside of DuckDuckGo"];
|
|
85
|
+
readonly fallbackDescription: "Web search continues to work via DuckDuckGo (free, no key needed, lower-quality freshness)";
|
|
86
|
+
readonly snoozeDurationDays: 7;
|
|
87
|
+
readonly instructionsHint: "Free tier available, signup opens in your browser";
|
|
88
|
+
}, {
|
|
89
|
+
readonly id: "exa";
|
|
90
|
+
readonly displayName: "Exa";
|
|
91
|
+
readonly category: "web_search";
|
|
92
|
+
readonly tier: "soft";
|
|
93
|
+
readonly aliases: readonly ["exa", "exa-search"];
|
|
94
|
+
readonly signupUrl: "https://dashboard.exa.ai/";
|
|
95
|
+
readonly freeTier: false;
|
|
96
|
+
readonly envVar: "EXA_API_KEY";
|
|
97
|
+
readonly configPath: readonly ["providers", "exa", "apiKey"];
|
|
98
|
+
readonly unlocks: readonly ["tier-1 semantic web search", "full article text and highlights", "higher freshness accuracy than DuckDuckGo"];
|
|
99
|
+
readonly fallbackDescription: "Exa search continues to work via the keyless Exa MCP endpoint, which has lower rate limits but similar quality";
|
|
100
|
+
readonly snoozeDurationDays: 7;
|
|
101
|
+
readonly instructionsHint: "Paid with free tier, signup opens in your browser";
|
|
102
|
+
}];
|
|
103
|
+
export declare function listAllProviders(): readonly ProviderDescriptor[];
|
|
104
|
+
export declare function getProvider(id: ProviderId): ProviderDescriptor;
|
|
105
|
+
export declare function getProvidersByCategory(category: ProviderCategory): readonly ProviderDescriptor[];
|
|
106
|
+
export declare function getProvidersByTier(tier: ProviderTier): readonly ProviderDescriptor[];
|
|
107
|
+
export declare function hasCredential(id: ProviderId): boolean;
|
|
108
|
+
export declare function getCredentialSource(id: ProviderId): "env" | "file" | "absent";
|
|
109
|
+
export declare function resolveProviderFromArgument(arg: string): ProviderDescriptor | readonly ProviderDescriptor[] | undefined;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// Provider registry — single source of truth for OpenCandle's credentialed
|
|
2
|
+
// third-party data providers. Every setup pathway iterates this registry:
|
|
3
|
+
// first-run startup, the `/connect` command, the `tool_result` credential
|
|
4
|
+
// interception handler, and the gap-note generator all read from here.
|
|
5
|
+
//
|
|
6
|
+
// Adding a new credentialed provider is a two-step change: add its `ProviderId`
|
|
7
|
+
// to the literal union below, and add its descriptor to the `PROVIDERS` array.
|
|
8
|
+
// The `satisfies` check ensures TypeScript fails the build if the union and
|
|
9
|
+
// the array ever disagree.
|
|
10
|
+
import { getConfig, loadFileConfig } from "../config.js";
|
|
11
|
+
// Declaration order matters: picker display order, per-workflow prompt priority,
|
|
12
|
+
// getProvidersByCategory/getProvidersByTier iteration order.
|
|
13
|
+
export const PROVIDERS = [
|
|
14
|
+
{
|
|
15
|
+
id: "alpha_vantage",
|
|
16
|
+
displayName: "Alpha Vantage",
|
|
17
|
+
category: "fundamentals",
|
|
18
|
+
tier: "hard",
|
|
19
|
+
aliases: ["financials", "fundamentals", "company-financials", "alphavantage"],
|
|
20
|
+
signupUrl: "https://www.alphavantage.co/support/#api-key",
|
|
21
|
+
freeTier: true,
|
|
22
|
+
envVar: "ALPHA_VANTAGE_API_KEY",
|
|
23
|
+
configPath: ["providers", "alphaVantage", "apiKey"],
|
|
24
|
+
unlocks: [
|
|
25
|
+
"company fundamentals",
|
|
26
|
+
"income/balance/cashflow statements",
|
|
27
|
+
"DCF valuation",
|
|
28
|
+
"earnings history",
|
|
29
|
+
],
|
|
30
|
+
fallbackDescription: null,
|
|
31
|
+
snoozeDurationDays: 7,
|
|
32
|
+
instructionsHint: "Free, about 30 seconds, signup opens in your browser",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: "fred",
|
|
36
|
+
displayName: "FRED",
|
|
37
|
+
category: "macro",
|
|
38
|
+
tier: "hard",
|
|
39
|
+
aliases: ["economy", "macro", "economic-data", "st-louis-fed"],
|
|
40
|
+
signupUrl: "https://fredaccount.stlouisfed.org/apikeys",
|
|
41
|
+
freeTier: true,
|
|
42
|
+
envVar: "FRED_API_KEY",
|
|
43
|
+
configPath: ["providers", "fred", "apiKey"],
|
|
44
|
+
unlocks: [
|
|
45
|
+
"interest rates",
|
|
46
|
+
"inflation data",
|
|
47
|
+
"yield curve",
|
|
48
|
+
"economic indicators",
|
|
49
|
+
],
|
|
50
|
+
fallbackDescription: null,
|
|
51
|
+
snoozeDurationDays: 7,
|
|
52
|
+
instructionsHint: "Free, about 30 seconds, requires a St. Louis Fed account",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "finnhub",
|
|
56
|
+
displayName: "Finnhub",
|
|
57
|
+
category: "news",
|
|
58
|
+
tier: "soft",
|
|
59
|
+
aliases: ["news", "company-news", "finnhub-news"],
|
|
60
|
+
signupUrl: "https://finnhub.io/register",
|
|
61
|
+
freeTier: true,
|
|
62
|
+
envVar: "FINNHUB_API_KEY",
|
|
63
|
+
configPath: ["providers", "finnhub", "apiKey"],
|
|
64
|
+
unlocks: [
|
|
65
|
+
"ticker-tagged company news",
|
|
66
|
+
"sentiment enrichment with a dedicated news source",
|
|
67
|
+
],
|
|
68
|
+
// Finnhub is a soft enrichment source — sentiment-summary continues to work
|
|
69
|
+
// with Twitter/Reddit/web search when Finnhub is missing. The fallback is
|
|
70
|
+
// "the other sentiment sources still run".
|
|
71
|
+
fallbackDescription: "Other sentiment sources (Reddit, Twitter, web search) continue to work without Finnhub",
|
|
72
|
+
snoozeDurationDays: 7,
|
|
73
|
+
instructionsHint: "Free, about 30 seconds, signup opens in your browser",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "brave",
|
|
77
|
+
displayName: "Brave Search",
|
|
78
|
+
category: "web_search",
|
|
79
|
+
tier: "soft",
|
|
80
|
+
aliases: ["brave", "brave-search"],
|
|
81
|
+
signupUrl: "https://brave.com/search/api/",
|
|
82
|
+
freeTier: true,
|
|
83
|
+
envVar: "BRAVE_API_KEY",
|
|
84
|
+
configPath: ["providers", "brave", "apiKey"],
|
|
85
|
+
unlocks: [
|
|
86
|
+
"tier-2 web search with freshness control",
|
|
87
|
+
"independent search index outside of DuckDuckGo",
|
|
88
|
+
],
|
|
89
|
+
fallbackDescription: "Web search continues to work via DuckDuckGo (free, no key needed, lower-quality freshness)",
|
|
90
|
+
snoozeDurationDays: 7,
|
|
91
|
+
instructionsHint: "Free tier available, signup opens in your browser",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "exa",
|
|
95
|
+
displayName: "Exa",
|
|
96
|
+
category: "web_search",
|
|
97
|
+
tier: "soft",
|
|
98
|
+
// Note: "search" is a multi-provider alias shared with Brave. The registry
|
|
99
|
+
// exposes it via resolveProviderFromArgument as a sub-picker case, not as a
|
|
100
|
+
// single-provider alias — so it intentionally does NOT appear in either
|
|
101
|
+
// provider's `aliases` array here. Keeping aliases unique-per-provider lets
|
|
102
|
+
// resolveProviderFromArgument cleanly distinguish the alias case from the
|
|
103
|
+
// sub-picker case.
|
|
104
|
+
aliases: ["exa", "exa-search"],
|
|
105
|
+
signupUrl: "https://dashboard.exa.ai/",
|
|
106
|
+
freeTier: false,
|
|
107
|
+
envVar: "EXA_API_KEY",
|
|
108
|
+
configPath: ["providers", "exa", "apiKey"],
|
|
109
|
+
unlocks: [
|
|
110
|
+
"tier-1 semantic web search",
|
|
111
|
+
"full article text and highlights",
|
|
112
|
+
"higher freshness accuracy than DuckDuckGo",
|
|
113
|
+
],
|
|
114
|
+
fallbackDescription: "Exa search continues to work via the keyless Exa MCP endpoint, which has lower rate limits but similar quality",
|
|
115
|
+
snoozeDurationDays: 7,
|
|
116
|
+
instructionsHint: "Paid with free tier, signup opens in your browser",
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
// -----------------------------------------------------------------------------
|
|
120
|
+
// Lookup helpers
|
|
121
|
+
// -----------------------------------------------------------------------------
|
|
122
|
+
// Lazy-built index — populated on first helper call so module import has no
|
|
123
|
+
// side effects. The test `importing the registry does not read the filesystem`
|
|
124
|
+
// relies on this.
|
|
125
|
+
let providersById;
|
|
126
|
+
function byId() {
|
|
127
|
+
if (!providersById) {
|
|
128
|
+
providersById = new Map(PROVIDERS.map((p) => [p.id, p]));
|
|
129
|
+
}
|
|
130
|
+
return providersById;
|
|
131
|
+
}
|
|
132
|
+
export function listAllProviders() {
|
|
133
|
+
return PROVIDERS;
|
|
134
|
+
}
|
|
135
|
+
export function getProvider(id) {
|
|
136
|
+
const found = byId().get(id);
|
|
137
|
+
if (!found) {
|
|
138
|
+
throw new Error(`Unknown provider id: "${id}"`);
|
|
139
|
+
}
|
|
140
|
+
return found;
|
|
141
|
+
}
|
|
142
|
+
export function getProvidersByCategory(category) {
|
|
143
|
+
return PROVIDERS.filter((p) => p.category === category);
|
|
144
|
+
}
|
|
145
|
+
export function getProvidersByTier(tier) {
|
|
146
|
+
return PROVIDERS.filter((p) => p.tier === tier);
|
|
147
|
+
}
|
|
148
|
+
// -----------------------------------------------------------------------------
|
|
149
|
+
// Credential source helpers
|
|
150
|
+
// -----------------------------------------------------------------------------
|
|
151
|
+
function readConfigValueByPath(obj, path) {
|
|
152
|
+
let cursor = obj;
|
|
153
|
+
for (const segment of path) {
|
|
154
|
+
if (cursor && typeof cursor === "object" && segment in cursor) {
|
|
155
|
+
cursor = cursor[segment];
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return typeof cursor === "string" && cursor.length > 0 ? cursor : undefined;
|
|
162
|
+
}
|
|
163
|
+
// Provider-id → `Config` field mapping. `Config` (in src/config.ts) is the
|
|
164
|
+
// canonical env-or-file resolved shape that tool implementations already use.
|
|
165
|
+
// `hasCredential` reads from `getConfig()` so that tests mocking `getConfig`
|
|
166
|
+
// see a consistent view; `getCredentialSource` reads `process.env` +
|
|
167
|
+
// `loadFileConfig` directly because it needs to distinguish env from file.
|
|
168
|
+
const CONFIG_FIELD_BY_ID = {
|
|
169
|
+
alpha_vantage: "alphaVantageApiKey",
|
|
170
|
+
fred: "fredApiKey",
|
|
171
|
+
finnhub: "finnhubApiKey",
|
|
172
|
+
brave: "braveApiKey",
|
|
173
|
+
exa: "exaApiKey",
|
|
174
|
+
};
|
|
175
|
+
export function hasCredential(id) {
|
|
176
|
+
const field = CONFIG_FIELD_BY_ID[id];
|
|
177
|
+
const value = getConfig()[field];
|
|
178
|
+
return typeof value === "string" && value.length > 0;
|
|
179
|
+
}
|
|
180
|
+
export function getCredentialSource(id) {
|
|
181
|
+
const descriptor = getProvider(id);
|
|
182
|
+
const envValue = process.env[descriptor.envVar];
|
|
183
|
+
if (envValue && envValue.length > 0)
|
|
184
|
+
return "env";
|
|
185
|
+
// Lazy file-config read — only invoked when env is absent.
|
|
186
|
+
const fileConfig = loadFileConfig();
|
|
187
|
+
const fileValue = readConfigValueByPath(fileConfig, descriptor.configPath);
|
|
188
|
+
if (fileValue)
|
|
189
|
+
return "file";
|
|
190
|
+
return "absent";
|
|
191
|
+
}
|
|
192
|
+
// -----------------------------------------------------------------------------
|
|
193
|
+
// /connect argument resolution
|
|
194
|
+
// -----------------------------------------------------------------------------
|
|
195
|
+
export function resolveProviderFromArgument(arg) {
|
|
196
|
+
const needle = arg.trim().toLowerCase();
|
|
197
|
+
if (!needle)
|
|
198
|
+
return undefined;
|
|
199
|
+
// 1. Exact provider id match (case-insensitive).
|
|
200
|
+
for (const p of PROVIDERS) {
|
|
201
|
+
if (p.id === needle)
|
|
202
|
+
return p;
|
|
203
|
+
}
|
|
204
|
+
// 2. Exact alias match.
|
|
205
|
+
for (const p of PROVIDERS) {
|
|
206
|
+
if (p.aliases.includes(needle))
|
|
207
|
+
return p;
|
|
208
|
+
}
|
|
209
|
+
// 3. Category match: if the needle matches a category name, return the
|
|
210
|
+
// providers in that category. One match → single descriptor. Multiple
|
|
211
|
+
// matches → array (triggers the sub-picker in the /connect handler).
|
|
212
|
+
const categories = [
|
|
213
|
+
"fundamentals",
|
|
214
|
+
"macro",
|
|
215
|
+
"news",
|
|
216
|
+
"web_search",
|
|
217
|
+
];
|
|
218
|
+
const normalizedCategory = needle.replace("-", "_");
|
|
219
|
+
if (categories.includes(normalizedCategory)) {
|
|
220
|
+
const group = getProvidersByCategory(normalizedCategory);
|
|
221
|
+
if (group.length === 1)
|
|
222
|
+
return group[0];
|
|
223
|
+
if (group.length > 1)
|
|
224
|
+
return group;
|
|
225
|
+
}
|
|
226
|
+
// 4. Special shared alias: "search" → both web_search providers.
|
|
227
|
+
if (needle === "search" || needle === "web" || needle === "web-search") {
|
|
228
|
+
const searchProviders = getProvidersByCategory("web_search");
|
|
229
|
+
if (searchProviders.length === 1)
|
|
230
|
+
return searchProviders[0];
|
|
231
|
+
if (searchProviders.length > 1)
|
|
232
|
+
return searchProviders;
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../src/onboarding/providers.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,0EAA0E;AAC1E,0EAA0E;AAC1E,uEAAuE;AACvE,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,2BAA2B;AAE3B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA8CzD,iFAAiF;AACjF,6DAA6D;AAC7D,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;QACE,EAAE,EAAE,eAAe;QACnB,WAAW,EAAE,eAAe;QAC5B,QAAQ,EAAE,cAAc;QACxB,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,oBAAoB,E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