opencandle 0.2.0 → 0.4.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/assets/logo.svg +187 -0
- package/dist/analysts/orchestrator.js +1 -2
- package/dist/analysts/orchestrator.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +38 -2
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +34 -5
- package/dist/config.js +29 -8
- package/dist/config.js.map +1 -1
- package/dist/infra/browser.d.ts +10 -0
- package/dist/infra/browser.js +1 -0
- package/dist/infra/browser.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/native-dependencies.d.ts +1 -0
- package/dist/infra/native-dependencies.js +10 -0
- package/dist/infra/native-dependencies.js.map +1 -0
- package/dist/infra/node-version.d.ts +2 -0
- package/dist/infra/node-version.js +23 -0
- package/dist/infra/node-version.js.map +1 -0
- package/dist/infra/rate-limiter.js +6 -0
- package/dist/infra/rate-limiter.js.map +1 -1
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +1 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/sqlite.js +42 -4
- package/dist/memory/sqlite.js.map +1 -1
- package/dist/memory/storage.d.ts +6 -0
- package/dist/memory/storage.js +3 -3
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/tool-defaults.d.ts +8 -0
- package/dist/memory/tool-defaults.js +59 -0
- package/dist/memory/tool-defaults.js.map +1 -0
- package/dist/onboarding/connect.d.ts +35 -0
- package/dist/onboarding/connect.js +118 -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 +116 -0
- package/dist/onboarding/providers.js +239 -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.d.ts +7 -1
- package/dist/pi/opencandle-extension.js +488 -13
- package/dist/pi/opencandle-extension.js.map +1 -1
- package/dist/pi/session-storage.d.ts +2 -0
- package/dist/pi/session-storage.js +5 -0
- package/dist/pi/session-storage.js.map +1 -0
- package/dist/pi/session.d.ts +4 -1
- package/dist/pi/session.js +25 -3
- package/dist/pi/session.js.map +1 -1
- package/dist/pi/setup.d.ts +1 -2
- package/dist/pi/setup.js +67 -120
- package/dist/pi/setup.js.map +1 -1
- package/dist/pi/tool-adapter.d.ts +2 -2
- package/dist/pi/tool-adapter.js +14 -1
- package/dist/pi/tool-adapter.js.map +1 -1
- package/dist/prompts/context-builder.d.ts +22 -0
- package/dist/prompts/context-builder.js +47 -11
- package/dist/prompts/context-builder.js.map +1 -1
- package/dist/prompts/disclaimer.d.ts +6 -0
- package/dist/prompts/disclaimer.js +9 -0
- package/dist/prompts/disclaimer.js.map +1 -0
- package/dist/prompts/workflow-prompts.d.ts +8 -0
- package/dist/prompts/workflow-prompts.js +39 -5
- package/dist/prompts/workflow-prompts.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/providers/yahoo-finance.js +70 -33
- package/dist/providers/yahoo-finance.js.map +1 -1
- package/dist/routing/classify-intent.js +22 -0
- package/dist/routing/classify-intent.js.map +1 -1
- package/dist/routing/defaults.js +1 -1
- package/dist/routing/defaults.js.map +1 -1
- package/dist/routing/index.d.ts +4 -0
- package/dist/routing/index.js +3 -0
- package/dist/routing/index.js.map +1 -1
- package/dist/routing/router-llm-client.d.ts +11 -0
- package/dist/routing/router-llm-client.js +42 -0
- package/dist/routing/router-llm-client.js.map +1 -0
- package/dist/routing/router-prompt.d.ts +2 -0
- package/dist/routing/router-prompt.js +138 -0
- package/dist/routing/router-prompt.js.map +1 -0
- package/dist/routing/router-types.d.ts +62 -0
- package/dist/routing/router-types.js +2 -0
- package/dist/routing/router-types.js.map +1 -0
- package/dist/routing/router.d.ts +10 -0
- package/dist/routing/router.js +194 -0
- package/dist/routing/router.js.map +1 -0
- package/dist/runtime/session-coordinator.d.ts +63 -4
- package/dist/runtime/session-coordinator.js +155 -4
- package/dist/runtime/session-coordinator.js.map +1 -1
- package/dist/runtime/tool-defaults-wrapper.d.ts +3 -0
- package/dist/runtime/tool-defaults-wrapper.js +25 -0
- package/dist/runtime/tool-defaults-wrapper.js.map +1 -0
- 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 +182 -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 +29 -13
- package/dist/system-prompt.js.map +1 -1
- package/dist/tool-kit.d.ts +4 -4
- package/dist/tools/fundamentals/company-overview.d.ts +4 -2
- package/dist/tools/fundamentals/company-overview.js +27 -27
- package/dist/tools/fundamentals/company-overview.js.map +1 -1
- package/dist/tools/fundamentals/comps.d.ts +1 -1
- package/dist/tools/fundamentals/comps.js +45 -45
- package/dist/tools/fundamentals/comps.js.map +1 -1
- package/dist/tools/fundamentals/dcf.d.ts +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 +4 -2
- package/dist/tools/fundamentals/earnings.js +25 -25
- package/dist/tools/fundamentals/earnings.js.map +1 -1
- package/dist/tools/fundamentals/financials.d.ts +4 -2
- package/dist/tools/fundamentals/financials.js +23 -23
- package/dist/tools/fundamentals/financials.js.map +1 -1
- package/dist/tools/fundamentals/sec-filings.d.ts +1 -1
- package/dist/tools/index.d.ts +28 -1
- package/dist/tools/index.js +35 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/interaction/ask-user.d.ts +1 -1
- package/dist/tools/interaction/ask-user.js +28 -64
- package/dist/tools/interaction/ask-user.js.map +1 -1
- package/dist/tools/interaction/twitter-login.d.ts +1 -1
- package/dist/tools/macro/fear-greed.d.ts +1 -1
- package/dist/tools/macro/fred-data.d.ts +4 -2
- package/dist/tools/macro/fred-data.js +26 -26
- package/dist/tools/macro/fred-data.js.map +1 -1
- package/dist/tools/market/crypto-history.d.ts +1 -1
- package/dist/tools/market/crypto-price.d.ts +1 -1
- package/dist/tools/market/search-ticker.d.ts +1 -1
- package/dist/tools/market/stock-history.d.ts +1 -1
- package/dist/tools/market/stock-quote.d.ts +1 -1
- package/dist/tools/options/option-chain.d.ts +1 -1
- package/dist/tools/options/option-chain.js +4 -1
- package/dist/tools/options/option-chain.js.map +1 -1
- package/dist/tools/portfolio/correlation.d.ts +1 -1
- package/dist/tools/portfolio/predictions.d.ts +1 -1
- package/dist/tools/portfolio/risk-analysis.d.ts +1 -1
- package/dist/tools/portfolio/tracker.d.ts +1 -1
- package/dist/tools/portfolio/watchlist.d.ts +1 -1
- package/dist/tools/sentiment/reddit-sentiment.d.ts +4 -2
- 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.d.ts +1 -1
- 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/tools/technical/backtest.d.ts +1 -1
- package/dist/tools/technical/indicators.d.ts +1 -1
- package/dist/tools/technical/indicators.js +7 -1
- package/dist/tools/technical/indicators.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/sentiment.d.ts +21 -0
- package/dist/workflows/options-screener.js +7 -2
- package/dist/workflows/options-screener.js.map +1 -1
- package/dist/workflows/portfolio-builder.js +3 -3
- package/dist/workflows/portfolio-builder.js.map +1 -1
- package/gui/server/background-quotes.ts +31 -0
- package/gui/server/chat-event-adapter.ts +142 -0
- package/gui/server/invoke-tool.ts +89 -0
- package/gui/server/live-chat-event-adapter.ts +181 -0
- package/gui/server/model-setup.ts +100 -0
- package/gui/server/package.json +5 -0
- package/gui/server/projector.ts +212 -0
- package/gui/server/server.ts +592 -0
- package/gui/server/session-actions.ts +31 -0
- package/gui/server/tool-metadata.ts +88 -0
- package/gui/server/websocket.ts +128 -0
- package/gui/server/writer-lock.ts +118 -0
- package/gui/shared/chat-events.ts +118 -0
- package/gui/shared/event-reducer.ts +186 -0
- package/gui/web/dist/assets/CatalogOverlay-D1ImSJTe.js +1 -0
- package/gui/web/dist/assets/index-DBrWq43L.css +1 -0
- package/gui/web/dist/assets/index-RflHaj0y.js +67 -0
- package/gui/web/dist/assets/logo-CWpt6Y2a.svg +187 -0
- package/gui/web/dist/index.html +17 -0
- package/package.json +62 -20
- package/src/analysts/contracts.ts +189 -0
- package/src/analysts/orchestrator.ts +300 -0
- package/src/cli.ts +205 -0
- package/src/config.ts +161 -0
- package/src/index.ts +5 -0
- package/src/infra/browser.ts +111 -0
- package/src/infra/cache.ts +103 -0
- package/src/infra/http-client.ts +68 -0
- package/src/infra/index.ts +18 -0
- package/src/infra/native-dependencies.ts +12 -0
- package/src/infra/node-version.ts +24 -0
- package/src/infra/open-url.ts +28 -0
- package/src/infra/opencandle-paths.ts +64 -0
- package/src/infra/rate-limiter.ts +64 -0
- package/src/memory/index.ts +10 -0
- package/src/memory/manager.ts +159 -0
- package/src/memory/preference-extractor.ts +106 -0
- package/src/memory/retrieval.ts +70 -0
- package/src/memory/sqlite.ts +172 -0
- package/src/memory/storage.ts +204 -0
- package/src/memory/tool-defaults.ts +87 -0
- package/src/memory/types.ts +67 -0
- package/src/onboarding/connect.ts +184 -0
- package/src/onboarding/credential-interceptor.ts +134 -0
- package/src/onboarding/degradation-accumulator.ts +79 -0
- package/src/onboarding/prompt-user.ts +85 -0
- package/src/onboarding/providers.ts +315 -0
- package/src/onboarding/state.ts +218 -0
- package/src/onboarding/tool-helpers.ts +111 -0
- package/src/onboarding/tool-tags.ts +201 -0
- package/src/onboarding/validation.ts +158 -0
- package/src/pi/opencandle-extension.ts +724 -0
- package/src/pi/session-storage.ts +5 -0
- package/src/pi/session.ts +81 -0
- package/src/pi/setup.ts +371 -0
- package/src/pi/tool-adapter.ts +36 -0
- package/src/prompts/context-builder.ts +204 -0
- package/src/prompts/disclaimer.ts +9 -0
- package/src/prompts/sections.ts +46 -0
- package/src/prompts/workflow-prompts.ts +279 -0
- package/src/providers/alpha-vantage.ts +292 -0
- package/src/providers/coingecko.ts +96 -0
- package/src/providers/exa-search.ts +373 -0
- package/src/providers/fear-greed.ts +45 -0
- package/src/providers/finnhub.ts +124 -0
- package/src/providers/fred.ts +83 -0
- package/src/providers/index.ts +9 -0
- package/src/providers/provider-credential-error.ts +23 -0
- package/src/providers/reddit.ts +151 -0
- package/src/providers/sec-edgar.ts +96 -0
- package/src/providers/twitter.ts +173 -0
- package/src/providers/web-search.ts +293 -0
- package/src/providers/with-fallback.ts +41 -0
- package/src/providers/wrap-provider.ts +64 -0
- package/src/providers/yahoo-finance.ts +367 -0
- package/src/routing/classify-intent.ts +194 -0
- package/src/routing/defaults.ts +29 -0
- package/src/routing/entity-extractor.ts +140 -0
- package/src/routing/index.ts +26 -0
- package/src/routing/router-llm-client.ts +51 -0
- package/src/routing/router-prompt.ts +159 -0
- package/src/routing/router-types.ts +66 -0
- package/src/routing/router.ts +213 -0
- package/src/routing/slot-resolver.ts +152 -0
- package/src/routing/types.ts +63 -0
- package/src/runtime/evidence.ts +77 -0
- package/src/runtime/index.ts +55 -0
- package/src/runtime/prompt-step.ts +75 -0
- package/src/runtime/provider-ids.ts +15 -0
- package/src/runtime/provider-tracker.ts +40 -0
- package/src/runtime/run-context.ts +22 -0
- package/src/runtime/session-coordinator.ts +406 -0
- package/src/runtime/tool-defaults-wrapper.ts +35 -0
- package/src/runtime/validation.ts +214 -0
- package/src/runtime/workflow-events.ts +75 -0
- package/src/runtime/workflow-runner.ts +188 -0
- package/src/runtime/workflow-types.ts +102 -0
- package/src/sentiment/adapters/finnhub.ts +44 -0
- package/src/sentiment/adapters/reddit.ts +65 -0
- package/src/sentiment/adapters/twitter.ts +36 -0
- package/src/sentiment/adapters/web.ts +44 -0
- package/src/sentiment/index.ts +58 -0
- package/src/sentiment/keywords.ts +9 -0
- package/src/sentiment/pipeline.ts +68 -0
- package/src/sentiment/scorer.ts +78 -0
- package/src/sentiment/store.ts +260 -0
- package/src/sentiment/trends.ts +90 -0
- package/src/sentiment/types.ts +108 -0
- package/src/system-prompt.ts +115 -0
- package/src/tool-kit.ts +68 -0
- package/src/tools/AGENTS.md +36 -0
- package/src/tools/fundamentals/company-overview.ts +54 -0
- package/src/tools/fundamentals/comps.ts +156 -0
- package/src/tools/fundamentals/dcf.ts +267 -0
- package/src/tools/fundamentals/earnings.ts +47 -0
- package/src/tools/fundamentals/financials.ts +54 -0
- package/src/tools/fundamentals/sec-filings.ts +61 -0
- package/src/tools/index.ts +88 -0
- package/src/tools/interaction/ask-user.ts +81 -0
- package/src/tools/interaction/twitter-login.ts +93 -0
- package/src/tools/macro/fear-greed.ts +41 -0
- package/src/tools/macro/fred-data.ts +54 -0
- package/src/tools/market/crypto-history.ts +51 -0
- package/src/tools/market/crypto-price.ts +53 -0
- package/src/tools/market/search-ticker.ts +53 -0
- package/src/tools/market/stock-history.ts +79 -0
- package/src/tools/market/stock-quote.ts +64 -0
- package/src/tools/options/greeks.ts +82 -0
- package/src/tools/options/option-chain.ts +91 -0
- package/src/tools/portfolio/correlation.ts +162 -0
- package/src/tools/portfolio/predictions.ts +253 -0
- package/src/tools/portfolio/risk-analysis.ts +134 -0
- package/src/tools/portfolio/tracker.ts +147 -0
- package/src/tools/portfolio/watchlist.ts +153 -0
- package/src/tools/sentiment/reddit-sentiment.ts +164 -0
- package/src/tools/sentiment/sentiment-summary.ts +256 -0
- package/src/tools/sentiment/sentiment-trend.ts +58 -0
- package/src/tools/sentiment/twitter-sentiment.ts +96 -0
- package/src/tools/sentiment/web-search.ts +150 -0
- package/src/tools/sentiment/web-sentiment.ts +76 -0
- package/src/tools/technical/backtest.ts +246 -0
- package/src/tools/technical/indicators.ts +258 -0
- package/src/types/fundamentals.ts +46 -0
- package/src/types/index.ts +20 -0
- package/src/types/macro.ts +27 -0
- package/src/types/market.ts +43 -0
- package/src/types/options.ts +35 -0
- package/src/types/portfolio.ts +41 -0
- package/src/types/sentiment.ts +70 -0
- package/src/workflows/compare-assets.ts +39 -0
- package/src/workflows/index.ts +4 -0
- package/src/workflows/options-screener.ts +49 -0
- package/src/workflows/portfolio-builder.ts +52 -0
- package/src/workflows/types.ts +4 -0
- 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,152 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtractedEntities,
|
|
3
|
+
PortfolioSlots,
|
|
4
|
+
OptionsScreenerSlots,
|
|
5
|
+
SlotResolution,
|
|
6
|
+
SlotSource,
|
|
7
|
+
} from "./types.js";
|
|
8
|
+
import { PORTFOLIO_DEFAULTS, OPTIONS_SCREENER_DEFAULTS } from "./defaults.js";
|
|
9
|
+
|
|
10
|
+
interface Preferences {
|
|
11
|
+
riskProfile?: string;
|
|
12
|
+
timeHorizon?: string;
|
|
13
|
+
assetScope?: string;
|
|
14
|
+
positionCount?: number;
|
|
15
|
+
maxSinglePositionPct?: number;
|
|
16
|
+
dteTarget?: string;
|
|
17
|
+
objective?: string;
|
|
18
|
+
moneynessPreference?: string;
|
|
19
|
+
liquidityMinimum?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function mapDteHintToTarget(dteHint: string | undefined): string | undefined {
|
|
23
|
+
switch (dteHint) {
|
|
24
|
+
case "week":
|
|
25
|
+
return "7_to_14_days";
|
|
26
|
+
case "month":
|
|
27
|
+
return "25_to_45_days";
|
|
28
|
+
case "leaps":
|
|
29
|
+
return "180_plus_days";
|
|
30
|
+
default:
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function resolve<T>(
|
|
36
|
+
userValue: T | undefined,
|
|
37
|
+
prefValue: T | undefined,
|
|
38
|
+
defaultValue: T,
|
|
39
|
+
): { value: T; source: SlotSource } {
|
|
40
|
+
if (userValue !== undefined) return { value: userValue, source: "user" };
|
|
41
|
+
if (prefValue !== undefined) return { value: prefValue, source: "preference" };
|
|
42
|
+
return { value: defaultValue, source: "default" };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function resolvePortfolioSlots(
|
|
46
|
+
entities: ExtractedEntities,
|
|
47
|
+
preferences: Preferences = {},
|
|
48
|
+
): SlotResolution<PortfolioSlots> {
|
|
49
|
+
const sources = {} as Record<keyof PortfolioSlots, SlotSource>;
|
|
50
|
+
const defaultsUsed: string[] = [];
|
|
51
|
+
const missingRequired: string[] = [];
|
|
52
|
+
|
|
53
|
+
// Budget: required, no default
|
|
54
|
+
let budget = 0;
|
|
55
|
+
if (entities.budget !== undefined) {
|
|
56
|
+
budget = entities.budget;
|
|
57
|
+
sources.budget = "user";
|
|
58
|
+
} else {
|
|
59
|
+
missingRequired.push("budget");
|
|
60
|
+
sources.budget = "default";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const risk = resolve(entities.riskProfile, preferences.riskProfile, PORTFOLIO_DEFAULTS.riskProfile);
|
|
64
|
+
sources.riskProfile = risk.source;
|
|
65
|
+
if (risk.source === "default") defaultsUsed.push("riskProfile");
|
|
66
|
+
|
|
67
|
+
const horizon = resolve(entities.timeHorizon, preferences.timeHorizon, PORTFOLIO_DEFAULTS.timeHorizon);
|
|
68
|
+
sources.timeHorizon = horizon.source;
|
|
69
|
+
if (horizon.source === "default") defaultsUsed.push("timeHorizon");
|
|
70
|
+
|
|
71
|
+
const scope = resolve(undefined, preferences.assetScope, PORTFOLIO_DEFAULTS.assetScope);
|
|
72
|
+
sources.assetScope = scope.source;
|
|
73
|
+
if (scope.source === "default") defaultsUsed.push("assetScope");
|
|
74
|
+
|
|
75
|
+
const count = resolve(undefined, preferences.positionCount, PORTFOLIO_DEFAULTS.positionCount);
|
|
76
|
+
sources.positionCount = count.source;
|
|
77
|
+
if (count.source === "default") defaultsUsed.push("positionCount");
|
|
78
|
+
|
|
79
|
+
const maxPct = resolve(undefined, preferences.maxSinglePositionPct, PORTFOLIO_DEFAULTS.maxSinglePositionPct);
|
|
80
|
+
sources.maxSinglePositionPct = maxPct.source;
|
|
81
|
+
if (maxPct.source === "default") defaultsUsed.push("maxSinglePositionPct");
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
resolved: {
|
|
85
|
+
budget,
|
|
86
|
+
riskProfile: risk.value,
|
|
87
|
+
timeHorizon: horizon.value,
|
|
88
|
+
assetScope: scope.value,
|
|
89
|
+
positionCount: count.value,
|
|
90
|
+
maxSinglePositionPct: maxPct.value,
|
|
91
|
+
},
|
|
92
|
+
sources,
|
|
93
|
+
defaultsUsed,
|
|
94
|
+
missingRequired,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function resolveOptionsScreenerSlots(
|
|
99
|
+
entities: ExtractedEntities,
|
|
100
|
+
preferences: Preferences = {},
|
|
101
|
+
): SlotResolution<OptionsScreenerSlots> {
|
|
102
|
+
const sources = {} as Record<keyof OptionsScreenerSlots, SlotSource>;
|
|
103
|
+
const defaultsUsed: string[] = [];
|
|
104
|
+
const missingRequired: string[] = [];
|
|
105
|
+
|
|
106
|
+
// Symbol: required, no default
|
|
107
|
+
let symbol = "";
|
|
108
|
+
if (entities.symbols.length > 0) {
|
|
109
|
+
symbol = entities.symbols[0];
|
|
110
|
+
sources.symbol = "user";
|
|
111
|
+
} else {
|
|
112
|
+
missingRequired.push("symbol");
|
|
113
|
+
sources.symbol = "default";
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Direction: default to bullish
|
|
117
|
+
const dir = resolve(entities.direction, undefined, "bullish" as const);
|
|
118
|
+
sources.direction = dir.source;
|
|
119
|
+
if (dir.source === "default") defaultsUsed.push("direction");
|
|
120
|
+
|
|
121
|
+
const dte = resolve(mapDteHintToTarget(entities.dteHint), preferences.dteTarget, OPTIONS_SCREENER_DEFAULTS.dteTarget);
|
|
122
|
+
sources.dteTarget = dte.source;
|
|
123
|
+
if (dte.source === "default") defaultsUsed.push("dteTarget");
|
|
124
|
+
|
|
125
|
+
const obj = resolve(undefined, preferences.objective, OPTIONS_SCREENER_DEFAULTS.objective);
|
|
126
|
+
sources.objective = obj.source;
|
|
127
|
+
if (obj.source === "default") defaultsUsed.push("objective");
|
|
128
|
+
|
|
129
|
+
const moneyness = resolve(undefined, preferences.moneynessPreference, OPTIONS_SCREENER_DEFAULTS.moneynessPreference);
|
|
130
|
+
sources.moneynessPreference = moneyness.source;
|
|
131
|
+
if (moneyness.source === "default") defaultsUsed.push("moneynessPreference");
|
|
132
|
+
|
|
133
|
+
const liquidity = resolve(undefined, preferences.liquidityMinimum, OPTIONS_SCREENER_DEFAULTS.liquidityMinimum);
|
|
134
|
+
sources.liquidityMinimum = liquidity.source;
|
|
135
|
+
if (liquidity.source === "default") defaultsUsed.push("liquidityMinimum");
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
resolved: {
|
|
139
|
+
symbol,
|
|
140
|
+
direction: dir.value,
|
|
141
|
+
dteTarget: dte.value,
|
|
142
|
+
objective: obj.value,
|
|
143
|
+
moneynessPreference: moneyness.value,
|
|
144
|
+
liquidityMinimum: liquidity.value,
|
|
145
|
+
budget: entities.budget,
|
|
146
|
+
maxPremium: entities.maxPremium,
|
|
147
|
+
},
|
|
148
|
+
sources,
|
|
149
|
+
defaultsUsed,
|
|
150
|
+
missingRequired,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type WorkflowType =
|
|
2
|
+
| "single_asset_analysis"
|
|
3
|
+
| "portfolio_builder"
|
|
4
|
+
| "options_screener"
|
|
5
|
+
| "compare_assets"
|
|
6
|
+
| "watchlist_or_tracking"
|
|
7
|
+
| "general_finance_qa"
|
|
8
|
+
| "unclassified";
|
|
9
|
+
|
|
10
|
+
export interface ExtractedEntities {
|
|
11
|
+
symbols: string[];
|
|
12
|
+
budget?: number;
|
|
13
|
+
maxPremium?: number;
|
|
14
|
+
timeHorizon?: string;
|
|
15
|
+
riskProfile?: string;
|
|
16
|
+
direction?: "bullish" | "bearish";
|
|
17
|
+
dteHint?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ClassificationResult {
|
|
21
|
+
workflow: WorkflowType;
|
|
22
|
+
confidence: number;
|
|
23
|
+
tier: "rule" | "llm";
|
|
24
|
+
entities: ExtractedEntities;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface PortfolioSlots {
|
|
28
|
+
budget: number;
|
|
29
|
+
riskProfile: string;
|
|
30
|
+
timeHorizon: string;
|
|
31
|
+
assetScope: string;
|
|
32
|
+
positionCount: number;
|
|
33
|
+
maxSinglePositionPct: number;
|
|
34
|
+
excludeSectors?: string[];
|
|
35
|
+
incomeVsGrowth?: string;
|
|
36
|
+
accountType?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface OptionsScreenerSlots {
|
|
40
|
+
symbol: string;
|
|
41
|
+
direction: "bullish" | "bearish";
|
|
42
|
+
dteTarget: string;
|
|
43
|
+
objective: string;
|
|
44
|
+
moneynessPreference: string;
|
|
45
|
+
liquidityMinimum: string;
|
|
46
|
+
budget?: number;
|
|
47
|
+
maxPremium?: number;
|
|
48
|
+
ivPreference?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface CompareAssetsSlots {
|
|
52
|
+
symbols: string[];
|
|
53
|
+
metrics?: string[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type SlotSource = "user" | "preference" | "default";
|
|
57
|
+
|
|
58
|
+
export interface SlotResolution<T> {
|
|
59
|
+
resolved: T;
|
|
60
|
+
sources: { [K in keyof T]?: SlotSource };
|
|
61
|
+
defaultsUsed: string[];
|
|
62
|
+
missingRequired: string[];
|
|
63
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Source of a value flowing through the runtime. */
|
|
2
|
+
export type ProvenanceSource =
|
|
3
|
+
| "user"
|
|
4
|
+
| "preference"
|
|
5
|
+
| "default"
|
|
6
|
+
| "fetched"
|
|
7
|
+
| "computed"
|
|
8
|
+
| "unavailable"
|
|
9
|
+
| "stale_cache";
|
|
10
|
+
|
|
11
|
+
/** Tracks where a value came from, when, and with what confidence. */
|
|
12
|
+
export interface Provenance {
|
|
13
|
+
source: ProvenanceSource;
|
|
14
|
+
timestamp?: string;
|
|
15
|
+
provider?: string;
|
|
16
|
+
confidence?: number;
|
|
17
|
+
reason?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A labeled data point with its provenance. */
|
|
21
|
+
export interface EvidenceRecord {
|
|
22
|
+
label: string;
|
|
23
|
+
value: unknown;
|
|
24
|
+
provenance: Provenance;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Successful provider result. */
|
|
28
|
+
export interface ProviderResultOk<T> {
|
|
29
|
+
status: "ok";
|
|
30
|
+
data: T;
|
|
31
|
+
timestamp: string;
|
|
32
|
+
stale?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Failed/unavailable provider result. */
|
|
36
|
+
export interface ProviderResultUnavailable {
|
|
37
|
+
status: "unavailable";
|
|
38
|
+
reason: string;
|
|
39
|
+
provider: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Union of provider outcomes — every provider call returns one of these. */
|
|
43
|
+
export type ProviderResult<T> = ProviderResultOk<T> | ProviderResultUnavailable;
|
|
44
|
+
|
|
45
|
+
/** Type guard for successful provider results. */
|
|
46
|
+
export function isProviderOk<T>(result: ProviderResult<T>): result is ProviderResultOk<T> {
|
|
47
|
+
return result.status === "ok";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Convert a ProviderResult into an EvidenceRecord. */
|
|
51
|
+
export function toEvidenceRecord<T>(
|
|
52
|
+
label: string,
|
|
53
|
+
result: ProviderResult<T>,
|
|
54
|
+
providerId?: string,
|
|
55
|
+
): EvidenceRecord {
|
|
56
|
+
if (isProviderOk(result)) {
|
|
57
|
+
return {
|
|
58
|
+
label,
|
|
59
|
+
value: result.data,
|
|
60
|
+
provenance: {
|
|
61
|
+
source: result.stale ? "stale_cache" : "fetched",
|
|
62
|
+
timestamp: result.timestamp,
|
|
63
|
+
provider: providerId,
|
|
64
|
+
confidence: result.stale ? 0.5 : undefined,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
label,
|
|
70
|
+
value: null,
|
|
71
|
+
provenance: {
|
|
72
|
+
source: "unavailable",
|
|
73
|
+
reason: result.reason,
|
|
74
|
+
provider: result.provider,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
Provenance,
|
|
3
|
+
ProvenanceSource,
|
|
4
|
+
EvidenceRecord,
|
|
5
|
+
ProviderResult,
|
|
6
|
+
ProviderResultOk,
|
|
7
|
+
ProviderResultUnavailable,
|
|
8
|
+
} from "./evidence.js";
|
|
9
|
+
export { isProviderOk, toEvidenceRecord } from "./evidence.js";
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
StepStatus,
|
|
13
|
+
RunStatus,
|
|
14
|
+
WorkflowStep,
|
|
15
|
+
StepOutput,
|
|
16
|
+
AnalystSignal,
|
|
17
|
+
AnalystOutput,
|
|
18
|
+
WorkflowRun,
|
|
19
|
+
} from "./workflow-types.js";
|
|
20
|
+
export {
|
|
21
|
+
isValidStepTransition,
|
|
22
|
+
transitionStepStatus,
|
|
23
|
+
createWorkflowRun,
|
|
24
|
+
} from "./workflow-types.js";
|
|
25
|
+
|
|
26
|
+
export type {
|
|
27
|
+
ValidationEntry,
|
|
28
|
+
ValidationResult,
|
|
29
|
+
ValidatorConfig,
|
|
30
|
+
} from "./validation.js";
|
|
31
|
+
export {
|
|
32
|
+
emptyValidationResult,
|
|
33
|
+
checkTimestamps,
|
|
34
|
+
checkOptionsExpiries,
|
|
35
|
+
checkRequiredFields,
|
|
36
|
+
checkNumberMatch,
|
|
37
|
+
RuntimeValidator,
|
|
38
|
+
DEFAULT_MARKET_SENSITIVE_LABELS,
|
|
39
|
+
} from "./validation.js";
|
|
40
|
+
|
|
41
|
+
export type { WorkflowEventType, WorkflowEvent } from "./workflow-events.js";
|
|
42
|
+
export { WorkflowEventLogger } from "./workflow-events.js";
|
|
43
|
+
|
|
44
|
+
export { ProviderTracker } from "./provider-tracker.js";
|
|
45
|
+
|
|
46
|
+
export type { ProviderId } from "./provider-ids.js";
|
|
47
|
+
export { PROVIDER_ID } from "./provider-ids.js";
|
|
48
|
+
|
|
49
|
+
export { setRunContext, clearRunContext, getProviderTracker } from "./run-context.js";
|
|
50
|
+
|
|
51
|
+
export type { StepExecutor, StepExecutionContext, WorkflowRunnerOptions } from "./workflow-runner.js";
|
|
52
|
+
export { WorkflowRunner } from "./workflow-runner.js";
|
|
53
|
+
|
|
54
|
+
export type { PromptStep, WorkflowDefinition } from "./prompt-step.js";
|
|
55
|
+
export { promptStep, promptStepOutput, toStepDefinitions, toWorkflowPlan } from "./prompt-step.js";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { WorkflowStep, StepOutput } from "./workflow-types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A workflow step definition that carries its prompt text.
|
|
5
|
+
* In Pi's model, each step is a prompt sent to the LLM.
|
|
6
|
+
*/
|
|
7
|
+
export interface PromptStep extends Omit<WorkflowStep, "status"> {
|
|
8
|
+
prompt: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A complete workflow definition: typed step metadata + prompt text for each step.
|
|
13
|
+
* Replaces the old WorkflowPlan { initialPrompt, followUps }.
|
|
14
|
+
*/
|
|
15
|
+
export interface WorkflowDefinition {
|
|
16
|
+
workflowType: string;
|
|
17
|
+
steps: PromptStep[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create a prompt-based step definition.
|
|
22
|
+
*/
|
|
23
|
+
export function promptStep(
|
|
24
|
+
stepType: string,
|
|
25
|
+
description: string,
|
|
26
|
+
prompt: string,
|
|
27
|
+
options: {
|
|
28
|
+
skippable?: boolean;
|
|
29
|
+
requiredInputs?: string[];
|
|
30
|
+
expectedOutputs?: string[];
|
|
31
|
+
} = {},
|
|
32
|
+
): PromptStep {
|
|
33
|
+
return {
|
|
34
|
+
stepType,
|
|
35
|
+
description,
|
|
36
|
+
prompt,
|
|
37
|
+
skippable: options.skippable ?? false,
|
|
38
|
+
requiredInputs: options.requiredInputs ?? [],
|
|
39
|
+
expectedOutputs: options.expectedOutputs ?? [],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create a StepOutput for a prompt-based step (no structured evidence yet).
|
|
45
|
+
* Evidence will be captured separately via tool call hooks.
|
|
46
|
+
*/
|
|
47
|
+
export function promptStepOutput(stepIndex: number, stepType: string): StepOutput {
|
|
48
|
+
return {
|
|
49
|
+
stepIndex,
|
|
50
|
+
stepType,
|
|
51
|
+
evidence: [],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Extract just the WorkflowStep metadata from PromptStep definitions
|
|
57
|
+
* (dropping the prompt field) for passing to WorkflowRunner.
|
|
58
|
+
*/
|
|
59
|
+
export function toStepDefinitions(steps: PromptStep[]): Omit<WorkflowStep, "status">[] {
|
|
60
|
+
return steps.map(({ prompt: _prompt, ...step }) => step);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Convert a WorkflowDefinition to the old WorkflowPlan format for backward compatibility.
|
|
65
|
+
*/
|
|
66
|
+
export function toWorkflowPlan(definition: WorkflowDefinition): {
|
|
67
|
+
initialPrompt: string;
|
|
68
|
+
followUps: string[];
|
|
69
|
+
} {
|
|
70
|
+
const [first, ...rest] = definition.steps;
|
|
71
|
+
return {
|
|
72
|
+
initialPrompt: first?.prompt ?? "",
|
|
73
|
+
followUps: rest.map((s) => s.prompt),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical provider IDs. These match the keys used in
|
|
3
|
+
* src/infra/rate-limiter.ts for providers that have rate limits.
|
|
4
|
+
*/
|
|
5
|
+
export const PROVIDER_ID = {
|
|
6
|
+
YAHOO: "yahoo",
|
|
7
|
+
ALPHA_VANTAGE: "alphavantage",
|
|
8
|
+
COINGECKO: "coingecko",
|
|
9
|
+
FRED: "fred",
|
|
10
|
+
SEC_EDGAR: "sec-edgar",
|
|
11
|
+
REDDIT: "reddit",
|
|
12
|
+
FEAR_GREED: "feargreed",
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export type ProviderId = (typeof PROVIDER_ID)[keyof typeof PROVIDER_ID];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ProviderResult } from "./evidence.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tracks provider failures within a workflow run and short-circuits
|
|
5
|
+
* calls to providers that have exceeded the failure threshold.
|
|
6
|
+
*/
|
|
7
|
+
export class ProviderTracker {
|
|
8
|
+
private readonly failures = new Map<string, number>();
|
|
9
|
+
|
|
10
|
+
constructor(private readonly maxFailures: number = 2) {}
|
|
11
|
+
|
|
12
|
+
/** Record a failure for a provider. */
|
|
13
|
+
recordFailure(provider: string): void {
|
|
14
|
+
this.failures.set(provider, (this.failures.get(provider) ?? 0) + 1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Check whether a provider's circuit is open (too many failures). */
|
|
18
|
+
isCircuitOpen(provider: string): boolean {
|
|
19
|
+
return (this.failures.get(provider) ?? 0) >= this.maxFailures;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Get a short-circuit unavailable result for a provider. */
|
|
23
|
+
shortCircuit<T>(provider: string): ProviderResult<T> {
|
|
24
|
+
return {
|
|
25
|
+
status: "unavailable",
|
|
26
|
+
reason: "provider_circuit_open",
|
|
27
|
+
provider,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Reset failure count for a provider. */
|
|
32
|
+
reset(provider: string): void {
|
|
33
|
+
this.failures.delete(provider);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Reset all tracked failures. */
|
|
37
|
+
resetAll(): void {
|
|
38
|
+
this.failures.clear();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ProviderTracker } from "./provider-tracker.js";
|
|
2
|
+
|
|
3
|
+
interface RunContext {
|
|
4
|
+
providerTracker: ProviderTracker;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
let activeContext: RunContext | null = null;
|
|
8
|
+
|
|
9
|
+
/** Set the active run context. Called by SessionCoordinator at workflow start. */
|
|
10
|
+
export function setRunContext(ctx: RunContext): void {
|
|
11
|
+
activeContext = ctx;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Clear the active run context. Called when a workflow ends or is cancelled. */
|
|
15
|
+
export function clearRunContext(): void {
|
|
16
|
+
activeContext = null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Get the current run's ProviderTracker, or undefined outside a workflow. */
|
|
20
|
+
export function getProviderTracker(): ProviderTracker | undefined {
|
|
21
|
+
return activeContext?.providerTracker;
|
|
22
|
+
}
|