opencandle 0.3.0 → 0.5.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/LICENSE +1 -1
- package/README.md +106 -14
- package/assets/logo.svg +187 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +40 -3
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +25 -0
- package/dist/config.js +72 -0
- package/dist/config.js.map +1 -1
- package/dist/infra/browser.d.ts +11 -3
- package/dist/infra/browser.js +2 -1
- package/dist/infra/browser.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.d.ts +4 -0
- package/dist/infra/rate-limiter.js +5 -1
- 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/manager.d.ts +9 -0
- package/dist/memory/manager.js +28 -11
- package/dist/memory/manager.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 +7 -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/memory/types.js +4 -0
- package/dist/memory/types.js.map +1 -1
- package/dist/onboarding/connect.d.ts +13 -1
- package/dist/onboarding/connect.js +21 -10
- package/dist/onboarding/connect.js.map +1 -1
- package/dist/onboarding/prompt-user.d.ts +1 -1
- package/dist/onboarding/providers.d.ts +7 -0
- package/dist/onboarding/providers.js +6 -3
- package/dist/onboarding/providers.js.map +1 -1
- package/dist/onboarding/tool-helpers.d.ts +1 -1
- package/dist/pi/opencandle-extension.d.ts +7 -1
- package/dist/pi/opencandle-extension.js +391 -21
- 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 -1
- package/dist/pi/setup.js +11 -1
- 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 +40 -3
- package/dist/prompts/context-builder.js +140 -19
- 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/policy-cards.d.ts +13 -0
- package/dist/prompts/policy-cards.js +197 -0
- package/dist/prompts/policy-cards.js.map +1 -0
- package/dist/prompts/sections.js +3 -3
- package/dist/prompts/sections.js.map +1 -1
- package/dist/prompts/workflow-prompts.d.ts +8 -0
- package/dist/prompts/workflow-prompts.js +208 -22
- package/dist/prompts/workflow-prompts.js.map +1 -1
- package/dist/providers/alpha-vantage.js +23 -1
- package/dist/providers/alpha-vantage.js.map +1 -1
- package/dist/providers/sec-edgar.d.ts +8 -1
- package/dist/providers/sec-edgar.js +172 -5
- package/dist/providers/sec-edgar.js.map +1 -1
- package/dist/providers/yahoo-finance.d.ts +2 -0
- package/dist/providers/yahoo-finance.js +203 -35
- package/dist/providers/yahoo-finance.js.map +1 -1
- package/dist/routing/classify-intent.d.ts +3 -0
- package/dist/routing/classify-intent.js +82 -3
- package/dist/routing/classify-intent.js.map +1 -1
- package/dist/routing/defaults.js +4 -4
- package/dist/routing/defaults.js.map +1 -1
- package/dist/routing/entity-extractor.d.ts +1 -0
- package/dist/routing/entity-extractor.js +158 -12
- package/dist/routing/entity-extractor.js.map +1 -1
- package/dist/routing/index.d.ts +10 -0
- package/dist/routing/index.js +7 -0
- package/dist/routing/index.js.map +1 -1
- package/dist/routing/legacy-rule-router.d.ts +9 -0
- package/dist/routing/legacy-rule-router.js +12 -0
- package/dist/routing/legacy-rule-router.js.map +1 -0
- package/dist/routing/planning.d.ts +54 -0
- package/dist/routing/planning.js +531 -0
- package/dist/routing/planning.js.map +1 -0
- package/dist/routing/route-manifest.d.ts +35 -0
- package/dist/routing/route-manifest.js +221 -0
- package/dist/routing/route-manifest.js.map +1 -0
- 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 +141 -0
- package/dist/routing/router-prompt.js.map +1 -0
- package/dist/routing/router-types.d.ts +71 -0
- package/dist/routing/router-types.js +2 -0
- package/dist/routing/router-types.js.map +1 -0
- package/dist/routing/router.d.ts +11 -0
- package/dist/routing/router.js +638 -0
- package/dist/routing/router.js.map +1 -0
- package/dist/routing/slot-resolver.js +46 -6
- package/dist/routing/slot-resolver.js.map +1 -1
- package/dist/routing/turn-context.d.ts +44 -0
- package/dist/routing/turn-context.js +45 -0
- package/dist/routing/turn-context.js.map +1 -0
- package/dist/routing/types.d.ts +13 -1
- package/dist/runtime/answer-contracts.d.ts +82 -0
- package/dist/runtime/answer-contracts.js +414 -0
- package/dist/runtime/answer-contracts.js.map +1 -0
- package/dist/runtime/artifact-contracts.d.ts +14 -0
- package/dist/runtime/artifact-contracts.js +57 -0
- package/dist/runtime/artifact-contracts.js.map +1 -0
- package/dist/runtime/planning-evidence.d.ts +99 -0
- package/dist/runtime/planning-evidence.js +445 -0
- package/dist/runtime/planning-evidence.js.map +1 -0
- package/dist/runtime/session-coordinator.d.ts +81 -3
- package/dist/runtime/session-coordinator.js +201 -17
- 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/store.js +5 -0
- package/dist/sentiment/store.js.map +1 -1
- package/dist/system-prompt.js +23 -12
- package/dist/system-prompt.js.map +1 -1
- package/dist/tool-kit.d.ts +4 -4
- package/dist/tools/fundamentals/company-overview.d.ts +1 -1
- package/dist/tools/fundamentals/company-overview.js +1 -1
- 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 +1 -1
- package/dist/tools/fundamentals/comps.js.map +1 -1
- package/dist/tools/fundamentals/dcf.d.ts +1 -1
- package/dist/tools/fundamentals/dcf.js +1 -1
- package/dist/tools/fundamentals/dcf.js.map +1 -1
- package/dist/tools/fundamentals/earnings.d.ts +1 -1
- package/dist/tools/fundamentals/earnings.js +1 -1
- package/dist/tools/fundamentals/earnings.js.map +1 -1
- package/dist/tools/fundamentals/financials.d.ts +1 -1
- package/dist/tools/fundamentals/financials.js +1 -1
- package/dist/tools/fundamentals/financials.js.map +1 -1
- package/dist/tools/fundamentals/sec-filings.d.ts +2 -1
- package/dist/tools/fundamentals/sec-filings.js +19 -2
- package/dist/tools/fundamentals/sec-filings.js.map +1 -1
- package/dist/tools/index.d.ts +29 -1
- package/dist/tools/index.js +30 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/interaction/ask-user.d.ts +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/fear-greed.js +1 -1
- package/dist/tools/macro/fear-greed.js.map +1 -1
- package/dist/tools/macro/fred-data.d.ts +1 -1
- package/dist/tools/macro/fred-data.js +29 -5
- 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-history.js +18 -2
- package/dist/tools/market/crypto-history.js.map +1 -1
- package/dist/tools/market/crypto-price.d.ts +1 -1
- package/dist/tools/market/crypto-price.js +1 -1
- package/dist/tools/market/crypto-price.js.map +1 -1
- package/dist/tools/market/search-ticker.d.ts +1 -1
- package/dist/tools/market/search-ticker.js +1 -1
- package/dist/tools/market/search-ticker.js.map +1 -1
- package/dist/tools/market/stock-history.d.ts +1 -1
- package/dist/tools/market/stock-history.js +1 -1
- package/dist/tools/market/stock-history.js.map +1 -1
- package/dist/tools/market/stock-quote.d.ts +1 -1
- package/dist/tools/market/stock-quote.js +1 -1
- package/dist/tools/market/stock-quote.js.map +1 -1
- package/dist/tools/options/greeks.js +0 -1
- package/dist/tools/options/greeks.js.map +1 -1
- package/dist/tools/options/option-chain.d.ts +1 -1
- package/dist/tools/options/option-chain.js +13 -5
- package/dist/tools/options/option-chain.js.map +1 -1
- package/dist/tools/portfolio/correlation.d.ts +1 -1
- package/dist/tools/portfolio/correlation.js +1 -1
- package/dist/tools/portfolio/correlation.js.map +1 -1
- package/dist/tools/portfolio/holdings-overlap.d.ts +8 -0
- package/dist/tools/portfolio/holdings-overlap.js +105 -0
- package/dist/tools/portfolio/holdings-overlap.js.map +1 -0
- package/dist/tools/portfolio/predictions.d.ts +1 -1
- package/dist/tools/portfolio/predictions.js +1 -1
- package/dist/tools/portfolio/predictions.js.map +1 -1
- package/dist/tools/portfolio/risk-analysis.d.ts +1 -1
- package/dist/tools/portfolio/risk-analysis.js +1 -1
- package/dist/tools/portfolio/risk-analysis.js.map +1 -1
- package/dist/tools/portfolio/tracker.d.ts +1 -1
- package/dist/tools/portfolio/tracker.js +1 -1
- package/dist/tools/portfolio/tracker.js.map +1 -1
- package/dist/tools/portfolio/watchlist.d.ts +1 -1
- package/dist/tools/portfolio/watchlist.js +12 -4
- package/dist/tools/portfolio/watchlist.js.map +1 -1
- package/dist/tools/sentiment/reddit-sentiment.d.ts +1 -1
- package/dist/tools/sentiment/reddit-sentiment.js +1 -1
- package/dist/tools/sentiment/reddit-sentiment.js.map +1 -1
- package/dist/tools/sentiment/sentiment-summary.d.ts +1 -1
- package/dist/tools/sentiment/sentiment-summary.js +57 -2
- package/dist/tools/sentiment/sentiment-summary.js.map +1 -1
- package/dist/tools/sentiment/sentiment-trend.d.ts +1 -1
- package/dist/tools/sentiment/twitter-sentiment.d.ts +1 -1
- package/dist/tools/sentiment/twitter-sentiment.js +1 -1
- package/dist/tools/sentiment/twitter-sentiment.js.map +1 -1
- package/dist/tools/sentiment/web-search.d.ts +1 -1
- package/dist/tools/sentiment/web-search.js +32 -3
- package/dist/tools/sentiment/web-search.js.map +1 -1
- package/dist/tools/sentiment/web-sentiment.d.ts +1 -1
- package/dist/tools/sentiment/web-sentiment.js +1 -1
- package/dist/tools/sentiment/web-sentiment.js.map +1 -1
- package/dist/tools/technical/backtest.d.ts +3 -3
- package/dist/tools/technical/backtest.js +41 -27
- package/dist/tools/technical/backtest.js.map +1 -1
- package/dist/tools/technical/indicators.d.ts +1 -1
- package/dist/tools/technical/indicators.js +8 -4
- package/dist/tools/technical/indicators.js.map +1 -1
- package/dist/types/options.d.ts +10 -0
- package/dist/types/portfolio.d.ts +27 -0
- package/dist/workflows/compare-assets.js +38 -2
- package/dist/workflows/compare-assets.js.map +1 -1
- package/dist/workflows/options-screener.js +94 -8
- package/dist/workflows/options-screener.js.map +1 -1
- package/dist/workflows/portfolio-builder.js +9 -5
- package/dist/workflows/portfolio-builder.js.map +1 -1
- package/gui/server/ask-user-bridge.ts +82 -0
- package/gui/server/background-quotes.ts +31 -0
- package/gui/server/chat-event-adapter.ts +142 -0
- package/gui/server/gui-session-manager.ts +5 -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 +254 -0
- package/gui/server/prompt-observation.ts +61 -0
- package/gui/server/server.ts +703 -0
- package/gui/server/session-actions.ts +31 -0
- package/gui/server/session-entry-wait.ts +81 -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-Bmp6Knu7.js +1 -0
- package/gui/web/dist/assets/index-Bxt9QpLX.css +1 -0
- package/gui/web/dist/assets/index-CZ9DHZYy.js +67 -0
- package/gui/web/dist/assets/logo-CWpt6Y2a.svg +187 -0
- package/gui/web/dist/index.html +17 -0
- package/package.json +50 -18
- package/src/analysts/contracts.ts +189 -0
- package/src/analysts/orchestrator.ts +300 -0
- package/src/cli.ts +206 -0
- package/src/config.ts +245 -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 +73 -0
- package/src/memory/index.ts +10 -0
- package/src/memory/manager.ts +192 -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 +205 -0
- package/src/memory/tool-defaults.ts +87 -0
- package/src/memory/types.ts +71 -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 +955 -0
- package/src/pi/session-storage.ts +5 -0
- package/src/pi/session.ts +81 -0
- package/src/pi/setup.ts +381 -0
- package/src/pi/tool-adapter.ts +36 -0
- package/src/prompts/context-builder.ts +315 -0
- package/src/prompts/disclaimer.ts +9 -0
- package/src/prompts/policy-cards.ts +220 -0
- package/src/prompts/sections.ts +46 -0
- package/src/prompts/workflow-prompts.ts +433 -0
- package/src/providers/alpha-vantage.ts +315 -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 +312 -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 +534 -0
- package/src/routing/classify-intent.ts +285 -0
- package/src/routing/defaults.ts +29 -0
- package/src/routing/entity-extractor.ts +291 -0
- package/src/routing/index.ts +70 -0
- package/src/routing/legacy-rule-router.ts +13 -0
- package/src/routing/planning.ts +732 -0
- package/src/routing/route-manifest.ts +287 -0
- package/src/routing/router-llm-client.ts +51 -0
- package/src/routing/router-prompt.ts +163 -0
- package/src/routing/router-types.ts +87 -0
- package/src/routing/router.ts +712 -0
- package/src/routing/slot-resolver.ts +190 -0
- package/src/routing/turn-context.ts +111 -0
- package/src/routing/types.ts +75 -0
- package/src/runtime/answer-contracts.ts +633 -0
- package/src/runtime/artifact-contracts.ts +76 -0
- package/src/runtime/evidence.ts +77 -0
- package/src/runtime/planning-evidence.ts +591 -0
- package/src/runtime/prompt-step.ts +75 -0
- package/src/runtime/provider-tracker.ts +40 -0
- package/src/runtime/run-context.ts +22 -0
- package/src/runtime/session-coordinator.ts +472 -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 +118 -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 +84 -0
- package/src/tools/index.ts +91 -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 +80 -0
- package/src/tools/market/crypto-history.ts +67 -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 +81 -0
- package/src/tools/options/option-chain.ts +96 -0
- package/src/tools/portfolio/correlation.ts +162 -0
- package/src/tools/portfolio/holdings-overlap.ts +123 -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 +159 -0
- package/src/tools/sentiment/reddit-sentiment.ts +164 -0
- package/src/tools/sentiment/sentiment-summary.ts +316 -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 +183 -0
- package/src/tools/sentiment/web-sentiment.ts +76 -0
- package/src/tools/technical/backtest.ts +267 -0
- package/src/tools/technical/indicators.ts +256 -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 +52 -0
- package/src/types/portfolio.ts +73 -0
- package/src/types/sentiment.ts +70 -0
- package/src/workflows/compare-assets.ts +75 -0
- package/src/workflows/index.ts +4 -0
- package/src/workflows/options-screener.ts +127 -0
- package/src/workflows/portfolio-builder.ts +56 -0
- package/src/workflows/types.ts +4 -0
- package/dist/runtime/index.d.ts +0 -16
- package/dist/runtime/index.js +0 -10
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/provider-ids.d.ts +0 -14
- package/dist/runtime/provider-ids.js +0 -14
- package/dist/runtime/provider-ids.js.map +0 -1
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
const normalized = dteHint?.toLowerCase().trim();
|
|
24
|
+
if (!normalized) return undefined;
|
|
25
|
+
|
|
26
|
+
if (/\bleaps?\b/.test(normalized) || /\blong[\s-]*dated\b/.test(normalized)) {
|
|
27
|
+
return "180_plus_days";
|
|
28
|
+
}
|
|
29
|
+
if (/\b(?:1|one)\s*(?:-|to|or)\s*(?:2|two)\s*weeks?\b/.test(normalized)) {
|
|
30
|
+
return "7_to_14_days";
|
|
31
|
+
}
|
|
32
|
+
if (/\bevent[_\s-]?week\b/.test(normalized)) {
|
|
33
|
+
return "0_to_7_days";
|
|
34
|
+
}
|
|
35
|
+
const explicitDays = normalized.match(/\b(\d+)\s*(?:-|to|or)\s*(\d+)\s*(?:days?|dte)\b/);
|
|
36
|
+
if (explicitDays) {
|
|
37
|
+
return `${explicitDays[1]}_to_${explicitDays[2]}_days`;
|
|
38
|
+
}
|
|
39
|
+
if (/\b(?:week|weekly|weeks?)\b/.test(normalized)) {
|
|
40
|
+
return "7_to_14_days";
|
|
41
|
+
}
|
|
42
|
+
if (/\b(?:month|monthly|months?)\b/.test(normalized)) {
|
|
43
|
+
return "25_to_45_days";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
switch (normalized) {
|
|
47
|
+
case "week":
|
|
48
|
+
return "7_to_14_days";
|
|
49
|
+
case "event_week":
|
|
50
|
+
return "0_to_7_days";
|
|
51
|
+
case "month":
|
|
52
|
+
return "25_to_45_days";
|
|
53
|
+
case "leaps":
|
|
54
|
+
return "180_plus_days";
|
|
55
|
+
default:
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function resolve<T>(
|
|
61
|
+
userValue: T | undefined,
|
|
62
|
+
prefValue: T | undefined,
|
|
63
|
+
defaultValue: T,
|
|
64
|
+
): { value: T; source: SlotSource } {
|
|
65
|
+
if (userValue !== undefined) return { value: userValue, source: "user" };
|
|
66
|
+
if (prefValue !== undefined) return { value: prefValue, source: "preference" };
|
|
67
|
+
return { value: defaultValue, source: "default" };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function resolvePortfolioSlots(
|
|
71
|
+
entities: ExtractedEntities,
|
|
72
|
+
preferences: Preferences = {},
|
|
73
|
+
): SlotResolution<PortfolioSlots> {
|
|
74
|
+
const sources = {} as Record<keyof PortfolioSlots, SlotSource>;
|
|
75
|
+
const defaultsUsed: string[] = [];
|
|
76
|
+
const missingRequired: string[] = [];
|
|
77
|
+
|
|
78
|
+
// Budget: required, no default
|
|
79
|
+
let budget = 0;
|
|
80
|
+
if (entities.budget !== undefined) {
|
|
81
|
+
budget = entities.budget;
|
|
82
|
+
sources.budget = "user";
|
|
83
|
+
} else {
|
|
84
|
+
missingRequired.push("budget");
|
|
85
|
+
sources.budget = "default";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const risk = resolve(entities.riskProfile, preferences.riskProfile, PORTFOLIO_DEFAULTS.riskProfile);
|
|
89
|
+
sources.riskProfile = risk.source;
|
|
90
|
+
if (risk.source === "default") defaultsUsed.push("riskProfile");
|
|
91
|
+
|
|
92
|
+
const horizon = resolve(entities.timeHorizon, preferences.timeHorizon, PORTFOLIO_DEFAULTS.timeHorizon);
|
|
93
|
+
sources.timeHorizon = horizon.source;
|
|
94
|
+
if (horizon.source === "default") defaultsUsed.push("timeHorizon");
|
|
95
|
+
|
|
96
|
+
const scope = resolve(entities.assetScope, preferences.assetScope, PORTFOLIO_DEFAULTS.assetScope);
|
|
97
|
+
sources.assetScope = scope.source;
|
|
98
|
+
if (scope.source === "default") defaultsUsed.push("assetScope");
|
|
99
|
+
|
|
100
|
+
const count = resolve(undefined, preferences.positionCount, PORTFOLIO_DEFAULTS.positionCount);
|
|
101
|
+
sources.positionCount = count.source;
|
|
102
|
+
if (count.source === "default") defaultsUsed.push("positionCount");
|
|
103
|
+
|
|
104
|
+
const maxPct = resolve(undefined, preferences.maxSinglePositionPct, PORTFOLIO_DEFAULTS.maxSinglePositionPct);
|
|
105
|
+
sources.maxSinglePositionPct = maxPct.source;
|
|
106
|
+
if (maxPct.source === "default") defaultsUsed.push("maxSinglePositionPct");
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
resolved: {
|
|
110
|
+
budget,
|
|
111
|
+
riskProfile: risk.value,
|
|
112
|
+
timeHorizon: horizon.value,
|
|
113
|
+
assetScope: scope.value,
|
|
114
|
+
positionCount: count.value,
|
|
115
|
+
maxSinglePositionPct: maxPct.value,
|
|
116
|
+
},
|
|
117
|
+
sources,
|
|
118
|
+
defaultsUsed,
|
|
119
|
+
missingRequired,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function resolveOptionsScreenerSlots(
|
|
124
|
+
entities: ExtractedEntities,
|
|
125
|
+
preferences: Preferences = {},
|
|
126
|
+
): SlotResolution<OptionsScreenerSlots> {
|
|
127
|
+
const sources = {} as Record<keyof OptionsScreenerSlots, SlotSource>;
|
|
128
|
+
const defaultsUsed: string[] = [];
|
|
129
|
+
const missingRequired: string[] = [];
|
|
130
|
+
|
|
131
|
+
// Symbol: required, no default
|
|
132
|
+
let symbol = "";
|
|
133
|
+
const requestedUnderlying = entities.heldSymbol ?? entities.symbols[0];
|
|
134
|
+
if (requestedUnderlying) {
|
|
135
|
+
symbol = requestedUnderlying;
|
|
136
|
+
sources.symbol = "user";
|
|
137
|
+
} else {
|
|
138
|
+
missingRequired.push("symbol");
|
|
139
|
+
sources.symbol = "default";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Direction: default to bullish unless the user specified a protective put hedge.
|
|
143
|
+
const inferredDirection = entities.optionStrategy === "protective_put"
|
|
144
|
+
? "bearish"
|
|
145
|
+
: entities.direction;
|
|
146
|
+
const dir = resolve(inferredDirection, undefined, "bullish" as const);
|
|
147
|
+
sources.direction = dir.source;
|
|
148
|
+
if (dir.source === "default") defaultsUsed.push("direction");
|
|
149
|
+
|
|
150
|
+
const dte = resolve(mapDteHintToTarget(entities.dteHint), preferences.dteTarget, OPTIONS_SCREENER_DEFAULTS.dteTarget);
|
|
151
|
+
sources.dteTarget = dte.source;
|
|
152
|
+
if (dte.source === "default") defaultsUsed.push("dteTarget");
|
|
153
|
+
|
|
154
|
+
const obj = resolve(undefined, preferences.objective, OPTIONS_SCREENER_DEFAULTS.objective);
|
|
155
|
+
sources.objective = obj.source;
|
|
156
|
+
if (obj.source === "default") defaultsUsed.push("objective");
|
|
157
|
+
|
|
158
|
+
const moneyness = resolve(undefined, preferences.moneynessPreference, OPTIONS_SCREENER_DEFAULTS.moneynessPreference);
|
|
159
|
+
sources.moneynessPreference = moneyness.source;
|
|
160
|
+
if (moneyness.source === "default") defaultsUsed.push("moneynessPreference");
|
|
161
|
+
|
|
162
|
+
const liquidity = resolve(undefined, preferences.liquidityMinimum, OPTIONS_SCREENER_DEFAULTS.liquidityMinimum);
|
|
163
|
+
sources.liquidityMinimum = liquidity.source;
|
|
164
|
+
if (liquidity.source === "default") defaultsUsed.push("liquidityMinimum");
|
|
165
|
+
|
|
166
|
+
if (entities.optionStrategy) sources.optionStrategy = "user";
|
|
167
|
+
if (entities.costBasis !== undefined) sources.costBasis = "user";
|
|
168
|
+
if (entities.shareQuantity !== undefined) sources.shareQuantity = "user";
|
|
169
|
+
if (entities.catalystSymbols !== undefined) sources.catalystSymbols = "user";
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
resolved: {
|
|
173
|
+
symbol,
|
|
174
|
+
direction: dir.value,
|
|
175
|
+
dteTarget: dte.value,
|
|
176
|
+
objective: obj.value,
|
|
177
|
+
moneynessPreference: moneyness.value,
|
|
178
|
+
liquidityMinimum: liquidity.value,
|
|
179
|
+
budget: entities.budget,
|
|
180
|
+
maxPremium: entities.maxPremium,
|
|
181
|
+
optionStrategy: entities.optionStrategy,
|
|
182
|
+
costBasis: entities.costBasis,
|
|
183
|
+
shareQuantity: entities.shareQuantity,
|
|
184
|
+
catalystSymbols: entities.catalystSymbols,
|
|
185
|
+
},
|
|
186
|
+
sources,
|
|
187
|
+
defaultsUsed,
|
|
188
|
+
missingRequired,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { MemoryCategory, MemoryEntry } from "../memory/types.js";
|
|
2
|
+
import {
|
|
3
|
+
activeToolsForBundles,
|
|
4
|
+
memoryScopesForRoute,
|
|
5
|
+
} from "./route-manifest.js";
|
|
6
|
+
import type {
|
|
7
|
+
RouterInputContext,
|
|
8
|
+
RouterOutput,
|
|
9
|
+
RouterRoute,
|
|
10
|
+
RouterRouteKind,
|
|
11
|
+
RouterSlot,
|
|
12
|
+
ToolBundleName,
|
|
13
|
+
RouterDiagnostic,
|
|
14
|
+
} from "./router-types.js";
|
|
15
|
+
import {
|
|
16
|
+
buildPlanningEnvelope,
|
|
17
|
+
type PlanningBuildOptions,
|
|
18
|
+
type PlanningEnvelope,
|
|
19
|
+
} from "./planning.js";
|
|
20
|
+
import type { ExtractedEntities, WorkflowType } from "./types.js";
|
|
21
|
+
|
|
22
|
+
export interface MemoryQueryPlan {
|
|
23
|
+
routeKind: RouterRouteKind;
|
|
24
|
+
workflow?: Exclude<WorkflowType, "unclassified">;
|
|
25
|
+
categories: MemoryCategory[];
|
|
26
|
+
symbols: string[];
|
|
27
|
+
slotKeys: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MemoryProvenance {
|
|
31
|
+
category: MemoryCategory;
|
|
32
|
+
key: string;
|
|
33
|
+
source?: string;
|
|
34
|
+
recordedAt: string;
|
|
35
|
+
confidence?: string;
|
|
36
|
+
filtered?: boolean;
|
|
37
|
+
filterReason?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ResolvedTurnContext {
|
|
41
|
+
userInput: string;
|
|
42
|
+
priorTurns: RouterInputContext["priorTurns"];
|
|
43
|
+
routeKind: RouterRouteKind;
|
|
44
|
+
legacyRoute: RouterRoute;
|
|
45
|
+
workflow?: Exclude<WorkflowType, "unclassified">;
|
|
46
|
+
entities: ExtractedEntities;
|
|
47
|
+
slots: Record<string, RouterSlot>;
|
|
48
|
+
missingRequired: string[];
|
|
49
|
+
toolBundles: ToolBundleName[];
|
|
50
|
+
activeToolNames: string[];
|
|
51
|
+
memoryQueryPlan: MemoryQueryPlan;
|
|
52
|
+
memoryProvenance: MemoryProvenance[];
|
|
53
|
+
promptPlaybook: RouterRouteKind;
|
|
54
|
+
diagnostics: RouterDiagnostic[];
|
|
55
|
+
planning: PlanningEnvelope;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function buildResolvedTurnContext(
|
|
59
|
+
input: RouterInputContext,
|
|
60
|
+
output: RouterOutput,
|
|
61
|
+
options: {
|
|
62
|
+
availableToolNames?: readonly string[];
|
|
63
|
+
memoryEntries?: readonly MemoryEntry[];
|
|
64
|
+
filteredMemory?: readonly MemoryProvenance[];
|
|
65
|
+
planning?: PlanningBuildOptions;
|
|
66
|
+
} = {},
|
|
67
|
+
): ResolvedTurnContext {
|
|
68
|
+
const memoryQueryPlan = buildMemoryQueryPlan(output);
|
|
69
|
+
const memoryProvenance = [
|
|
70
|
+
...(options.memoryEntries ?? []).map(memoryEntryToProvenance),
|
|
71
|
+
...(options.filteredMemory ?? []),
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
userInput: input.text,
|
|
76
|
+
priorTurns: input.priorTurns,
|
|
77
|
+
routeKind: output.routeKind,
|
|
78
|
+
legacyRoute: output.route,
|
|
79
|
+
workflow: output.workflow,
|
|
80
|
+
entities: output.entities,
|
|
81
|
+
slots: output.slots,
|
|
82
|
+
missingRequired: output.missing_required,
|
|
83
|
+
toolBundles: output.tool_bundles,
|
|
84
|
+
activeToolNames: activeToolsForBundles(output.tool_bundles, options.availableToolNames),
|
|
85
|
+
memoryQueryPlan,
|
|
86
|
+
memoryProvenance,
|
|
87
|
+
promptPlaybook: output.routeKind,
|
|
88
|
+
diagnostics: output.diagnostics,
|
|
89
|
+
planning: buildPlanningEnvelope(input, output, options.planning),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function buildMemoryQueryPlan(output: RouterOutput): MemoryQueryPlan {
|
|
94
|
+
return {
|
|
95
|
+
routeKind: output.routeKind,
|
|
96
|
+
workflow: output.workflow,
|
|
97
|
+
categories: memoryScopesForRoute(output.routeKind, output.workflow),
|
|
98
|
+
symbols: output.entities.symbols,
|
|
99
|
+
slotKeys: Object.keys(output.slots),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function memoryEntryToProvenance(entry: MemoryEntry): MemoryProvenance {
|
|
104
|
+
return {
|
|
105
|
+
category: entry.category,
|
|
106
|
+
key: entry.key,
|
|
107
|
+
source: entry.source,
|
|
108
|
+
recordedAt: entry.recordedAt,
|
|
109
|
+
confidence: entry.confidence,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
assetScope?: string;
|
|
16
|
+
riskProfile?: string;
|
|
17
|
+
direction?: "bullish" | "bearish";
|
|
18
|
+
dteHint?: string;
|
|
19
|
+
optionStrategy?: "covered_call" | "protective_put";
|
|
20
|
+
heldSymbol?: string;
|
|
21
|
+
catalystSymbols?: string[];
|
|
22
|
+
costBasis?: number;
|
|
23
|
+
shareQuantity?: number;
|
|
24
|
+
compareMetrics?: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ClassificationResult {
|
|
28
|
+
workflow: WorkflowType;
|
|
29
|
+
confidence: number;
|
|
30
|
+
tier: "rule" | "llm";
|
|
31
|
+
entities: ExtractedEntities;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PortfolioSlots {
|
|
35
|
+
budget: number;
|
|
36
|
+
riskProfile: string;
|
|
37
|
+
timeHorizon: string;
|
|
38
|
+
assetScope: string;
|
|
39
|
+
positionCount: number;
|
|
40
|
+
maxSinglePositionPct: number;
|
|
41
|
+
excludeSectors?: string[];
|
|
42
|
+
incomeVsGrowth?: string;
|
|
43
|
+
accountType?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface OptionsScreenerSlots {
|
|
47
|
+
symbol: string;
|
|
48
|
+
direction: "bullish" | "bearish";
|
|
49
|
+
dteTarget: string;
|
|
50
|
+
objective: string;
|
|
51
|
+
moneynessPreference: string;
|
|
52
|
+
liquidityMinimum: string;
|
|
53
|
+
budget?: number;
|
|
54
|
+
maxPremium?: number;
|
|
55
|
+
optionStrategy?: "covered_call" | "protective_put";
|
|
56
|
+
costBasis?: number;
|
|
57
|
+
shareQuantity?: number;
|
|
58
|
+
catalystSymbols?: string[];
|
|
59
|
+
ivPreference?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface CompareAssetsSlots {
|
|
63
|
+
symbols: string[];
|
|
64
|
+
timeHorizon?: string;
|
|
65
|
+
metrics?: string[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type SlotSource = "user" | "preference" | "default" | "prior_context" | "memory";
|
|
69
|
+
|
|
70
|
+
export interface SlotResolution<T> {
|
|
71
|
+
resolved: T;
|
|
72
|
+
sources: { [K in keyof T]?: SlotSource };
|
|
73
|
+
defaultsUsed: string[];
|
|
74
|
+
missingRequired: string[];
|
|
75
|
+
}
|