opencandle 0.4.0 → 0.6.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 +186 -117
- package/dist/analysts/contracts.d.ts +1 -3
- package/dist/analysts/contracts.js +1 -11
- package/dist/analysts/contracts.js.map +1 -1
- package/dist/analysts/orchestrator.d.ts +1 -3
- package/dist/analysts/orchestrator.js +1 -26
- package/dist/analysts/orchestrator.js.map +1 -1
- package/dist/cli.js +32 -8
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +19 -3
- package/dist/config.js +69 -3
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/infra/browser.d.ts +1 -3
- package/dist/infra/browser.js +4 -2
- package/dist/infra/browser.js.map +1 -1
- package/dist/infra/cache.d.ts +8 -11
- package/dist/infra/cache.js +17 -15
- package/dist/infra/cache.js.map +1 -1
- package/dist/infra/http-client.d.ts +4 -1
- package/dist/infra/http-client.js +59 -6
- package/dist/infra/http-client.js.map +1 -1
- package/dist/infra/index.d.ts +3 -3
- package/dist/infra/index.js +3 -3
- package/dist/infra/index.js.map +1 -1
- package/dist/infra/native-dependencies.js +2 -2
- package/dist/infra/native-dependencies.js.map +1 -1
- package/dist/infra/node-version.js.map +1 -1
- package/dist/infra/opencandle-paths.d.ts +0 -3
- package/dist/infra/opencandle-paths.js +4 -11
- package/dist/infra/opencandle-paths.js.map +1 -1
- package/dist/infra/rate-limiter.d.ts +4 -0
- package/dist/infra/rate-limiter.js +17 -10
- package/dist/infra/rate-limiter.js.map +1 -1
- package/dist/market-state/alert-conditions.d.ts +34 -0
- package/dist/market-state/alert-conditions.js +23 -0
- package/dist/market-state/alert-conditions.js.map +1 -0
- package/dist/market-state/alert-runner.d.ts +55 -0
- package/dist/market-state/alert-runner.js +634 -0
- package/dist/market-state/alert-runner.js.map +1 -0
- package/dist/market-state/daily-report.d.ts +26 -0
- package/dist/market-state/daily-report.js +179 -0
- package/dist/market-state/daily-report.js.map +1 -0
- package/dist/market-state/local-automation-service.d.ts +25 -0
- package/dist/market-state/local-automation-service.js +119 -0
- package/dist/market-state/local-automation-service.js.map +1 -0
- package/dist/market-state/notification-delivery.d.ts +14 -0
- package/dist/market-state/notification-delivery.js +139 -0
- package/dist/market-state/notification-delivery.js.map +1 -0
- package/dist/market-state/resolve-for-mutation.d.ts +10 -0
- package/dist/market-state/resolve-for-mutation.js +15 -0
- package/dist/market-state/resolve-for-mutation.js.map +1 -0
- package/dist/market-state/resolve.d.ts +14 -0
- package/dist/market-state/resolve.js +89 -0
- package/dist/market-state/resolve.js.map +1 -0
- package/dist/market-state/service.d.ts +527 -0
- package/dist/market-state/service.js +1099 -0
- package/dist/market-state/service.js.map +1 -0
- package/dist/memory/index.d.ts +7 -7
- package/dist/memory/index.js +6 -6
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/manager.d.ts +9 -0
- package/dist/memory/manager.js +39 -22
- package/dist/memory/manager.js.map +1 -1
- package/dist/memory/retrieval.js +7 -4
- package/dist/memory/retrieval.js.map +1 -1
- package/dist/memory/sqlite.js +385 -3
- package/dist/memory/sqlite.js.map +1 -1
- package/dist/memory/storage.d.ts +3 -2
- package/dist/memory/storage.js +1 -2
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/tool-defaults.js +64 -28
- package/dist/memory/tool-defaults.js.map +1 -1
- package/dist/memory/types.js +4 -0
- package/dist/memory/types.js.map +1 -1
- package/dist/monitor.d.ts +2 -0
- package/dist/monitor.js +104 -0
- package/dist/monitor.js.map +1 -0
- package/dist/onboarding/connect.js +4 -6
- package/dist/onboarding/connect.js.map +1 -1
- package/dist/onboarding/credential-interceptor.js +1 -1
- package/dist/onboarding/credential-interceptor.js.map +1 -1
- package/dist/onboarding/degradation-accumulator.js +1 -3
- package/dist/onboarding/degradation-accumulator.js.map +1 -1
- package/dist/onboarding/providers.js +3 -16
- package/dist/onboarding/providers.js.map +1 -1
- package/dist/onboarding/state.js.map +1 -1
- package/dist/onboarding/tool-helpers.js +1 -1
- package/dist/onboarding/tool-helpers.js.map +1 -1
- package/dist/onboarding/tool-tags.js +6 -4
- package/dist/onboarding/tool-tags.js.map +1 -1
- package/dist/onboarding/validation.js +1 -1
- package/dist/onboarding/validation.js.map +1 -1
- package/dist/pi/opencandle-extension.d.ts +8 -0
- package/dist/pi/opencandle-extension.js +637 -59
- package/dist/pi/opencandle-extension.js.map +1 -1
- package/dist/pi/session.d.ts +1 -1
- package/dist/pi/session.js +3 -1
- package/dist/pi/session.js.map +1 -1
- package/dist/pi/setup.js +17 -2
- package/dist/pi/setup.js.map +1 -1
- package/dist/pi/tool-adapter.js +5 -2
- package/dist/pi/tool-adapter.js.map +1 -1
- package/dist/prompts/context-builder.d.ts +18 -3
- package/dist/prompts/context-builder.js +117 -18
- package/dist/prompts/context-builder.js.map +1 -1
- package/dist/prompts/disclaimer.js +1 -1
- package/dist/prompts/disclaimer.js.map +1 -1
- 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.d.ts +1 -1
- package/dist/prompts/sections.js +3 -3
- package/dist/prompts/sections.js.map +1 -1
- package/dist/prompts/symbol-preflight.d.ts +20 -0
- package/dist/prompts/symbol-preflight.js +49 -0
- package/dist/prompts/symbol-preflight.js.map +1 -0
- package/dist/prompts/workflow-prompts.d.ts +1 -1
- package/dist/prompts/workflow-prompts.js +209 -19
- package/dist/prompts/workflow-prompts.js.map +1 -1
- package/dist/providers/alpha-vantage.d.ts +1 -1
- package/dist/providers/alpha-vantage.js +49 -8
- package/dist/providers/alpha-vantage.js.map +1 -1
- package/dist/providers/coingecko.js +1 -1
- package/dist/providers/coingecko.js.map +1 -1
- package/dist/providers/errors.d.ts +5 -0
- package/dist/providers/errors.js +11 -0
- package/dist/providers/errors.js.map +1 -0
- package/dist/providers/exa-search.d.ts +2 -2
- package/dist/providers/exa-search.js +19 -11
- package/dist/providers/exa-search.js.map +1 -1
- package/dist/providers/fear-greed.js +1 -1
- package/dist/providers/fear-greed.js.map +1 -1
- package/dist/providers/finnhub.js +3 -5
- package/dist/providers/finnhub.js.map +1 -1
- package/dist/providers/fred.js +2 -2
- package/dist/providers/fred.js.map +1 -1
- package/dist/providers/index.d.ts +7 -6
- package/dist/providers/index.js +6 -5
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/reddit.js +2 -2
- package/dist/providers/reddit.js.map +1 -1
- package/dist/providers/sec-edgar.d.ts +9 -1
- package/dist/providers/sec-edgar.js +181 -6
- package/dist/providers/sec-edgar.js.map +1 -1
- package/dist/providers/tradingview.d.ts +47 -0
- package/dist/providers/tradingview.js +275 -0
- package/dist/providers/tradingview.js.map +1 -0
- package/dist/providers/twitter.js +6 -8
- package/dist/providers/twitter.js.map +1 -1
- package/dist/providers/web-search.js +26 -12
- package/dist/providers/web-search.js.map +1 -1
- package/dist/providers/with-fallback.js +4 -2
- package/dist/providers/with-fallback.js.map +1 -1
- package/dist/providers/wrap-provider.d.ts +2 -3
- package/dist/providers/wrap-provider.js +14 -8
- package/dist/providers/wrap-provider.js.map +1 -1
- package/dist/providers/yahoo-finance.d.ts +3 -1
- package/dist/providers/yahoo-finance.js +226 -11
- package/dist/providers/yahoo-finance.js.map +1 -1
- package/dist/routing/classify-intent.d.ts +9 -0
- package/dist/routing/classify-intent.js +153 -3
- package/dist/routing/classify-intent.js.map +1 -1
- package/dist/routing/defaults.d.ts +1 -1
- package/dist/routing/defaults.js +3 -3
- package/dist/routing/defaults.js.map +1 -1
- package/dist/routing/entity-extractor.d.ts +2 -0
- package/dist/routing/entity-extractor.js +377 -26
- package/dist/routing/entity-extractor.js.map +1 -1
- package/dist/routing/fund-symbols.d.ts +2 -0
- package/dist/routing/fund-symbols.js +55 -0
- package/dist/routing/fund-symbols.js.map +1 -0
- package/dist/routing/horizon.d.ts +1 -0
- package/dist/routing/horizon.js +10 -0
- package/dist/routing/horizon.js.map +1 -0
- package/dist/routing/index.d.ts +12 -6
- package/dist/routing/index.js +8 -4
- 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 +562 -0
- package/dist/routing/planning.js.map +1 -0
- package/dist/routing/route-manifest.d.ts +35 -0
- package/dist/routing/route-manifest.js +242 -0
- package/dist/routing/route-manifest.js.map +1 -0
- package/dist/routing/router-llm-client.js.map +1 -1
- package/dist/routing/router-prompt.js +46 -45
- package/dist/routing/router-prompt.js.map +1 -1
- package/dist/routing/router-types.d.ts +10 -0
- package/dist/routing/router.d.ts +1 -0
- package/dist/routing/router.js +572 -13
- package/dist/routing/router.js.map +1 -1
- package/dist/routing/slot-resolver.d.ts +1 -1
- package/dist/routing/slot-resolver.js +45 -7
- package/dist/routing/slot-resolver.js.map +1 -1
- package/dist/routing/symbol-disambiguator.d.ts +11 -0
- package/dist/routing/symbol-disambiguator.js +52 -0
- package/dist/routing/symbol-disambiguator.js.map +1 -0
- 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 +15 -1
- package/dist/runtime/answer-contracts.d.ts +82 -0
- package/dist/runtime/answer-contracts.js +442 -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 +466 -0
- package/dist/runtime/planning-evidence.js.map +1 -0
- package/dist/runtime/prompt-step.d.ts +1 -9
- package/dist/runtime/prompt-step.js +0 -10
- package/dist/runtime/prompt-step.js.map +1 -1
- package/dist/runtime/run-context.d.ts +5 -2
- package/dist/runtime/run-context.js +8 -1
- package/dist/runtime/run-context.js.map +1 -1
- package/dist/runtime/session-coordinator.d.ts +29 -3
- package/dist/runtime/session-coordinator.js +204 -31
- package/dist/runtime/session-coordinator.js.map +1 -1
- package/dist/runtime/session-title.d.ts +14 -0
- package/dist/runtime/session-title.js +50 -0
- package/dist/runtime/session-title.js.map +1 -0
- package/dist/runtime/tool-defaults-wrapper.js +1 -3
- package/dist/runtime/tool-defaults-wrapper.js.map +1 -1
- package/dist/runtime/validation.js.map +1 -1
- package/dist/runtime/workflow-events.js.map +1 -1
- package/dist/runtime/workflow-runner.d.ts +3 -3
- package/dist/runtime/workflow-runner.js +1 -1
- package/dist/runtime/workflow-runner.js.map +1 -1
- package/dist/sentiment/adapters/finnhub.d.ts +1 -1
- package/dist/sentiment/adapters/finnhub.js +6 -1
- package/dist/sentiment/adapters/finnhub.js.map +1 -1
- package/dist/sentiment/adapters/reddit.d.ts +2 -2
- package/dist/sentiment/adapters/twitter.d.ts +1 -1
- package/dist/sentiment/adapters/web.d.ts +1 -1
- package/dist/sentiment/index.d.ts +9 -11
- package/dist/sentiment/index.js +9 -20
- package/dist/sentiment/index.js.map +1 -1
- package/dist/sentiment/keywords.js +26 -4
- package/dist/sentiment/keywords.js.map +1 -1
- package/dist/sentiment/pipeline.d.ts +2 -2
- package/dist/sentiment/pipeline.js +1 -1
- package/dist/sentiment/pipeline.js.map +1 -1
- package/dist/sentiment/scorer.js +1 -1
- package/dist/sentiment/store.d.ts +1 -1
- package/dist/sentiment/store.js +1 -1
- package/dist/sentiment/store.js.map +1 -1
- package/dist/sentiment/trends.d.ts +1 -1
- package/dist/sentiment/trends.js.map +1 -1
- package/dist/sentiment/types.js.map +1 -1
- package/dist/system-prompt.js +7 -3
- package/dist/system-prompt.js.map +1 -1
- package/dist/tool-kit.d.ts +7 -7
- package/dist/tool-kit.js +4 -4
- package/dist/tool-kit.js.map +1 -1
- package/dist/tools/fundamentals/company-overview.js +12 -7
- package/dist/tools/fundamentals/company-overview.js.map +1 -1
- package/dist/tools/fundamentals/comps.js +19 -10
- package/dist/tools/fundamentals/comps.js.map +1 -1
- package/dist/tools/fundamentals/dcf.js +24 -12
- package/dist/tools/fundamentals/dcf.js.map +1 -1
- package/dist/tools/fundamentals/earnings.js +9 -4
- package/dist/tools/fundamentals/earnings.js.map +1 -1
- package/dist/tools/fundamentals/financials.js +9 -4
- package/dist/tools/fundamentals/financials.js.map +1 -1
- package/dist/tools/fundamentals/sec-filings.d.ts +1 -0
- package/dist/tools/fundamentals/sec-filings.js +36 -4
- package/dist/tools/fundamentals/sec-filings.js.map +1 -1
- package/dist/tools/index.d.ts +23 -18
- package/dist/tools/index.js +53 -38
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/interaction/ask-user.js +15 -3
- package/dist/tools/interaction/ask-user.js.map +1 -1
- package/dist/tools/interaction/twitter-login.js +13 -3
- package/dist/tools/interaction/twitter-login.js.map +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 +44 -9
- package/dist/tools/macro/fred-data.js.map +1 -1
- package/dist/tools/market/crypto-history.js +21 -3
- package/dist/tools/market/crypto-history.js.map +1 -1
- package/dist/tools/market/crypto-price.js +4 -2
- package/dist/tools/market/crypto-price.js.map +1 -1
- package/dist/tools/market/screen-stocks.d.ts +18 -0
- package/dist/tools/market/screen-stocks.js +252 -0
- package/dist/tools/market/screen-stocks.js.map +1 -0
- package/dist/tools/market/search-ticker.js +161 -9
- package/dist/tools/market/search-ticker.js.map +1 -1
- package/dist/tools/market/stock-history.d.ts +2 -2
- package/dist/tools/market/stock-history.js +27 -8
- package/dist/tools/market/stock-history.js.map +1 -1
- package/dist/tools/market/stock-quote.js +6 -4
- package/dist/tools/market/stock-quote.js.map +1 -1
- package/dist/tools/options/greeks.js +1 -2
- package/dist/tools/options/greeks.js.map +1 -1
- package/dist/tools/options/option-chain.js +27 -9
- package/dist/tools/options/option-chain.js.map +1 -1
- package/dist/tools/portfolio/alerts.d.ts +15 -0
- package/dist/tools/portfolio/alerts.js +357 -0
- package/dist/tools/portfolio/alerts.js.map +1 -0
- package/dist/tools/portfolio/correlation.d.ts +1 -1
- package/dist/tools/portfolio/correlation.js +34 -14
- package/dist/tools/portfolio/correlation.js.map +1 -1
- package/dist/tools/portfolio/daily-report.d.ts +8 -0
- package/dist/tools/portfolio/daily-report.js +83 -0
- package/dist/tools/portfolio/daily-report.js.map +1 -0
- package/dist/tools/portfolio/holdings-overlap.d.ts +8 -0
- package/dist/tools/portfolio/holdings-overlap.js +112 -0
- package/dist/tools/portfolio/holdings-overlap.js.map +1 -0
- package/dist/tools/portfolio/notifications.d.ts +7 -0
- package/dist/tools/portfolio/notifications.js +43 -0
- package/dist/tools/portfolio/notifications.js.map +1 -0
- package/dist/tools/portfolio/predictions.d.ts +12 -6
- package/dist/tools/portfolio/predictions.js +338 -88
- 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 +46 -7
- package/dist/tools/portfolio/risk-analysis.js.map +1 -1
- package/dist/tools/portfolio/tracker.d.ts +4 -3
- package/dist/tools/portfolio/tracker.js +247 -102
- package/dist/tools/portfolio/tracker.js.map +1 -1
- package/dist/tools/portfolio/watchlist.d.ts +6 -4
- package/dist/tools/portfolio/watchlist.js +209 -101
- package/dist/tools/portfolio/watchlist.js.map +1 -1
- package/dist/tools/sentiment/reddit-sentiment.js +24 -11
- package/dist/tools/sentiment/reddit-sentiment.js.map +1 -1
- package/dist/tools/sentiment/sentiment-summary.js +71 -14
- package/dist/tools/sentiment/sentiment-summary.js.map +1 -1
- package/dist/tools/sentiment/sentiment-trend.d.ts +1 -1
- package/dist/tools/sentiment/sentiment-trend.js +12 -2
- package/dist/tools/sentiment/sentiment-trend.js.map +1 -1
- package/dist/tools/sentiment/twitter-sentiment.js +13 -6
- package/dist/tools/sentiment/twitter-sentiment.js.map +1 -1
- package/dist/tools/sentiment/untrusted-text.d.ts +2 -0
- package/dist/tools/sentiment/untrusted-text.js +17 -0
- package/dist/tools/sentiment/untrusted-text.js.map +1 -0
- package/dist/tools/sentiment/web-search.js +37 -12
- package/dist/tools/sentiment/web-search.js.map +1 -1
- package/dist/tools/sentiment/web-sentiment.js +16 -4
- 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 +65 -44
- package/dist/tools/technical/backtest.js.map +1 -1
- package/dist/tools/technical/indicators.js +24 -8
- package/dist/tools/technical/indicators.js.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/market.d.ts +1 -0
- package/dist/types/options.d.ts +10 -0
- package/dist/types/portfolio.d.ts +41 -4
- package/dist/workflows/compare-assets.d.ts +0 -3
- package/dist/workflows/compare-assets.js +55 -10
- package/dist/workflows/compare-assets.js.map +1 -1
- package/dist/workflows/index.d.ts +3 -4
- package/dist/workflows/index.js +3 -3
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/options-screener.d.ts +0 -3
- package/dist/workflows/options-screener.js +88 -14
- package/dist/workflows/options-screener.js.map +1 -1
- package/dist/workflows/portfolio-builder.d.ts +0 -3
- package/dist/workflows/portfolio-builder.js +7 -11
- package/dist/workflows/portfolio-builder.js.map +1 -1
- package/gui/server/ask-user-bridge.ts +82 -0
- package/gui/server/automation-heartbeat.ts +97 -0
- package/gui/server/background-quotes.ts +97 -1
- package/gui/server/chat-event-adapter.ts +32 -10
- package/gui/server/chat-run-session.ts +16 -0
- package/gui/server/gui-session-manager.ts +5 -0
- package/gui/server/invoke-tool.ts +144 -1
- package/gui/server/live-chat-event-adapter.ts +21 -6
- package/gui/server/market-state-api.ts +315 -0
- package/gui/server/model-setup.ts +149 -2
- package/gui/server/private-api-access.ts +62 -0
- package/gui/server/projector.ts +58 -11
- package/gui/server/prompt-observation.ts +58 -0
- package/gui/server/quote-snapshot-store.ts +50 -0
- package/gui/server/server.ts +236 -376
- package/gui/server/session-actions.ts +186 -1
- package/gui/server/session-entry-wait.ts +81 -0
- package/gui/server/shutdown.ts +47 -0
- package/gui/server/tool-invoke-ack.ts +49 -0
- package/gui/server/tool-metadata.ts +23 -10
- package/gui/server/websocket.ts +13 -3
- package/gui/server/writer-lock.ts +6 -2
- package/gui/server/ws-hub.ts +292 -0
- package/gui/shared/chat-events.ts +16 -1
- package/gui/shared/event-reducer.ts +24 -6
- package/gui/web/dist/assets/CatalogOverlay-eJ2cBk33.js +1 -0
- package/gui/web/dist/assets/index-2KZtKBmu.css +1 -0
- package/gui/web/dist/assets/index-CveNgtDg.js +69 -0
- package/gui/web/dist/index.html +2 -2
- package/package.json +22 -12
- package/src/analysts/contracts.ts +10 -23
- package/src/analysts/orchestrator.ts +8 -43
- package/src/cli.ts +37 -13
- package/src/config.ts +99 -7
- package/src/index.ts +1 -1
- package/src/infra/browser.ts +4 -2
- package/src/infra/cache.ts +41 -30
- package/src/infra/http-client.ts +72 -6
- package/src/infra/index.ts +7 -10
- package/src/infra/native-dependencies.ts +8 -3
- package/src/infra/node-version.ts +3 -1
- package/src/infra/opencandle-paths.ts +3 -14
- package/src/infra/rate-limiter.ts +32 -20
- package/src/market-state/alert-conditions.ts +82 -0
- package/src/market-state/alert-runner.ts +863 -0
- package/src/market-state/daily-report.ts +247 -0
- package/src/market-state/local-automation-service.ts +162 -0
- package/src/market-state/notification-delivery.ts +158 -0
- package/src/market-state/resolve-for-mutation.ts +24 -0
- package/src/market-state/resolve.ts +112 -0
- package/src/market-state/service.ts +2344 -0
- package/src/memory/index.ts +7 -7
- package/src/memory/manager.ts +57 -26
- package/src/memory/retrieval.ts +8 -7
- package/src/memory/sqlite.ts +407 -6
- package/src/memory/storage.ts +8 -17
- package/src/memory/tool-defaults.ts +60 -39
- package/src/memory/types.ts +7 -3
- package/src/monitor.ts +121 -0
- package/src/onboarding/connect.ts +10 -33
- package/src/onboarding/credential-interceptor.ts +3 -15
- package/src/onboarding/degradation-accumulator.ts +1 -3
- package/src/onboarding/providers.ts +9 -40
- package/src/onboarding/state.ts +4 -15
- package/src/onboarding/tool-helpers.ts +2 -9
- package/src/onboarding/tool-tags.ts +6 -6
- package/src/onboarding/validation.ts +14 -20
- package/src/pi/opencandle-extension.ts +795 -120
- package/src/pi/session.ts +7 -5
- package/src/pi/setup.ts +61 -33
- package/src/pi/tool-adapter.ts +5 -2
- package/src/prompts/context-builder.ts +143 -21
- package/src/prompts/disclaimer.ts +1 -1
- package/src/prompts/policy-cards.ts +220 -0
- package/src/prompts/sections.ts +4 -4
- package/src/prompts/symbol-preflight.ts +80 -0
- package/src/prompts/workflow-prompts.ts +231 -28
- package/src/providers/alpha-vantage.ts +82 -40
- package/src/providers/coingecko.ts +2 -5
- package/src/providers/errors.ts +9 -0
- package/src/providers/exa-search.ts +24 -22
- package/src/providers/fear-greed.ts +1 -1
- package/src/providers/finnhub.ts +7 -6
- package/src/providers/fred.ts +3 -3
- package/src/providers/index.ts +14 -6
- package/src/providers/reddit.ts +17 -6
- package/src/providers/sec-edgar.ts +235 -5
- package/src/providers/tradingview.ts +399 -0
- package/src/providers/twitter.ts +6 -8
- package/src/providers/web-search.ts +30 -20
- package/src/providers/with-fallback.ts +8 -7
- package/src/providers/wrap-provider.ts +15 -10
- package/src/providers/yahoo-finance.ts +292 -20
- package/src/routing/classify-intent.ts +186 -4
- package/src/routing/defaults.ts +4 -4
- package/src/routing/entity-extractor.ts +428 -28
- package/src/routing/fund-symbols.ts +58 -0
- package/src/routing/horizon.ts +7 -0
- package/src/routing/index.ts +60 -16
- package/src/routing/legacy-rule-router.ts +13 -0
- package/src/routing/planning.ts +823 -0
- package/src/routing/route-manifest.ts +309 -0
- package/src/routing/router-llm-client.ts +4 -4
- package/src/routing/router-prompt.ts +52 -52
- package/src/routing/router-types.ts +18 -0
- package/src/routing/router.ts +717 -20
- package/src/routing/slot-resolver.ts +75 -14
- package/src/routing/symbol-disambiguator.ts +72 -0
- package/src/routing/turn-context.ts +108 -0
- package/src/routing/types.ts +15 -1
- package/src/runtime/answer-contracts.ts +672 -0
- package/src/runtime/artifact-contracts.ts +77 -0
- package/src/runtime/planning-evidence.ts +682 -0
- package/src/runtime/prompt-step.ts +1 -16
- package/src/runtime/run-context.ts +12 -2
- package/src/runtime/session-coordinator.ts +297 -56
- package/src/runtime/session-title.ts +60 -0
- package/src/runtime/tool-defaults-wrapper.ts +1 -3
- package/src/runtime/validation.ts +1 -4
- package/src/runtime/workflow-events.ts +7 -7
- package/src/runtime/workflow-runner.ts +5 -11
- package/src/sentiment/adapters/finnhub.ts +7 -2
- package/src/sentiment/adapters/reddit.ts +2 -2
- package/src/sentiment/adapters/twitter.ts +1 -1
- package/src/sentiment/adapters/web.ts +1 -1
- package/src/sentiment/index.ts +16 -26
- package/src/sentiment/keywords.ts +26 -4
- package/src/sentiment/pipeline.ts +15 -4
- package/src/sentiment/scorer.ts +1 -1
- package/src/sentiment/store.ts +2 -2
- package/src/sentiment/trends.ts +9 -3
- package/src/sentiment/types.ts +5 -4
- package/src/system-prompt.ts +7 -3
- package/src/tool-kit.ts +10 -9
- package/src/tools/fundamentals/company-overview.ts +20 -10
- package/src/tools/fundamentals/comps.ts +69 -56
- package/src/tools/fundamentals/dcf.ts +146 -96
- package/src/tools/fundamentals/earnings.ts +17 -7
- package/src/tools/fundamentals/financials.ts +17 -8
- package/src/tools/fundamentals/sec-filings.ts +52 -8
- package/src/tools/index.ts +53 -38
- package/src/tools/interaction/ask-user.ts +22 -10
- package/src/tools/interaction/twitter-login.ts +17 -5
- package/src/tools/macro/fear-greed.ts +2 -2
- package/src/tools/macro/fred-data.ts +80 -42
- package/src/tools/market/crypto-history.ts +25 -4
- package/src/tools/market/crypto-price.ts +7 -7
- package/src/tools/market/screen-stocks.ts +279 -0
- package/src/tools/market/search-ticker.ts +219 -18
- package/src/tools/market/stock-history.ts +38 -13
- package/src/tools/market/stock-quote.ts +11 -8
- package/src/tools/options/greeks.ts +5 -6
- package/src/tools/options/option-chain.ts +47 -18
- package/src/tools/portfolio/alerts.ts +457 -0
- package/src/tools/portfolio/correlation.ts +48 -21
- package/src/tools/portfolio/daily-report.ts +101 -0
- package/src/tools/portfolio/holdings-overlap.ts +139 -0
- package/src/tools/portfolio/notifications.ts +45 -0
- package/src/tools/portfolio/predictions.ts +407 -107
- package/src/tools/portfolio/risk-analysis.ts +47 -8
- package/src/tools/portfolio/tracker.ts +271 -110
- package/src/tools/portfolio/watchlist.ts +251 -116
- package/src/tools/sentiment/reddit-sentiment.ts +51 -25
- package/src/tools/sentiment/sentiment-summary.ts +116 -35
- package/src/tools/sentiment/sentiment-trend.ts +24 -7
- package/src/tools/sentiment/twitter-sentiment.ts +23 -16
- package/src/tools/sentiment/untrusted-text.ts +21 -0
- package/src/tools/sentiment/web-search.ts +52 -16
- package/src/tools/sentiment/web-sentiment.ts +27 -11
- package/src/tools/technical/backtest.ts +78 -47
- package/src/tools/technical/indicators.ts +40 -17
- package/src/types/index.ts +8 -3
- package/src/types/market.ts +1 -0
- package/src/types/options.ts +17 -0
- package/src/types/portfolio.ts +46 -4
- package/src/types/sentiment.ts +2 -2
- package/src/workflows/compare-assets.ts +67 -19
- package/src/workflows/index.ts +3 -4
- package/src/workflows/options-screener.ts +98 -22
- package/src/workflows/portfolio-builder.ts +40 -29
- 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
- package/dist/workflows/types.d.ts +0 -4
- package/dist/workflows/types.js +0 -2
- package/dist/workflows/types.js.map +0 -1
- package/gui/web/dist/assets/CatalogOverlay-D1ImSJTe.js +0 -1
- package/gui/web/dist/assets/index-DBrWq43L.css +0 -1
- package/gui/web/dist/assets/index-RflHaj0y.js +0 -67
- package/src/runtime/index.ts +0 -55
- package/src/runtime/provider-ids.ts +0 -15
- package/src/workflows/types.ts +0 -4
|
@@ -1,50 +1,53 @@
|
|
|
1
|
-
import { Type } from "@sinclair/typebox";
|
|
2
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
import { isZeroFilledQuote } from "../../market-state/resolve.js";
|
|
4
|
+
import { resolveInstrumentForMutation } from "../../market-state/resolve-for-mutation.js";
|
|
5
|
+
import { MarketStateService, type WatchlistItemRecord } from "../../market-state/service.js";
|
|
6
|
+
import { initDefaultDatabase } from "../../memory/sqlite.js";
|
|
7
|
+
import { getQuotes, type TradingViewQuote } from "../../providers/tradingview.js";
|
|
5
8
|
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
interface WatchlistItem {
|
|
9
|
-
symbol: string;
|
|
10
|
-
addedAt: string;
|
|
11
|
-
targetPrice?: number;
|
|
12
|
-
stopPrice?: number;
|
|
13
|
-
notes?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function loadWatchlist(): WatchlistItem[] {
|
|
17
|
-
const watchlistPath = getWatchlistPath();
|
|
18
|
-
if (!existsSync(watchlistPath)) return [];
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(readFileSync(watchlistPath, "utf-8"));
|
|
21
|
-
} catch {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
9
|
+
import { getQuote } from "../../providers/yahoo-finance.js";
|
|
25
10
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
interface WatchlistCheck extends WatchlistItemRecord {
|
|
12
|
+
currentPrice: number | null;
|
|
13
|
+
alerts: string[];
|
|
14
|
+
statuses: string[];
|
|
15
|
+
sourceProvider?: "tradingview" | "yahoo";
|
|
16
|
+
dataCaveat?: string;
|
|
30
17
|
}
|
|
31
18
|
|
|
32
19
|
const params = Type.Object({
|
|
33
20
|
action: Type.Union(
|
|
34
|
-
[Type.Literal("add"), Type.Literal("remove"), Type.Literal("check")],
|
|
35
|
-
{ description: "One of: 'add', 'remove', or 'check'" },
|
|
36
|
-
),
|
|
37
|
-
symbol: Type.Optional(
|
|
38
|
-
Type.String({ description: "Ticker symbol (required for add/remove)" }),
|
|
21
|
+
[Type.Literal("add"), Type.Literal("update"), Type.Literal("remove"), Type.Literal("check")],
|
|
22
|
+
{ description: "One of: 'add', 'update', 'remove', or 'check'" },
|
|
39
23
|
),
|
|
24
|
+
symbol: Type.Optional(Type.String({ description: "Ticker symbol (required for add/remove)" })),
|
|
40
25
|
target_price: Type.Optional(
|
|
41
|
-
Type.
|
|
26
|
+
Type.Union([
|
|
27
|
+
Type.Number({ description: "Alert when price rises above this level" }),
|
|
28
|
+
Type.Null({ description: "Clear the existing target price during update" }),
|
|
29
|
+
]),
|
|
42
30
|
),
|
|
43
31
|
stop_price: Type.Optional(
|
|
44
|
-
Type.
|
|
32
|
+
Type.Union([
|
|
33
|
+
Type.Number({ description: "Alert when price falls below this level" }),
|
|
34
|
+
Type.Null({ description: "Clear the existing stop price during update" }),
|
|
35
|
+
]),
|
|
45
36
|
),
|
|
46
37
|
notes: Type.Optional(
|
|
47
|
-
Type.
|
|
38
|
+
Type.Union([
|
|
39
|
+
Type.String({ description: "Optional notes for why you're watching this" }),
|
|
40
|
+
Type.Null({ description: "Clear existing notes during update" }),
|
|
41
|
+
]),
|
|
42
|
+
),
|
|
43
|
+
thesis: Type.Optional(
|
|
44
|
+
Type.Union([
|
|
45
|
+
Type.String({ description: "Optional thesis for why you're watching this" }),
|
|
46
|
+
Type.Null({ description: "Clear the existing thesis during update" }),
|
|
47
|
+
]),
|
|
48
|
+
),
|
|
49
|
+
tags: Type.Optional(
|
|
50
|
+
Type.Array(Type.String(), { description: "Optional tags for organizing the watchlist item" }),
|
|
48
51
|
),
|
|
49
52
|
});
|
|
50
53
|
|
|
@@ -52,102 +55,234 @@ export const watchlistTool: AgentTool<typeof params> = {
|
|
|
52
55
|
name: "manage_watchlist",
|
|
53
56
|
label: "Watchlist",
|
|
54
57
|
description:
|
|
55
|
-
"Manage your watchlist of stocks and crypto. Add symbols with optional target and stop prices, remove symbols, or check current prices against your
|
|
58
|
+
"Manage your watchlist of stocks and crypto. Add symbols with optional target and stop prices, remove symbols, or check current prices against your watchlist levels.",
|
|
56
59
|
parameters: params,
|
|
57
|
-
async execute(
|
|
58
|
-
const
|
|
60
|
+
async execute(_toolCallId, args) {
|
|
61
|
+
const db = initDefaultDatabase();
|
|
62
|
+
const service = new MarketStateService(db);
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
64
|
+
try {
|
|
65
|
+
if (args.action === "add") {
|
|
66
|
+
if (!args.symbol) {
|
|
67
|
+
throw new Error("symbol is required for add action.");
|
|
68
|
+
}
|
|
69
|
+
const instrument = await resolveInstrumentForMutation(args.symbol);
|
|
70
|
+
if (instrument.status === "needs_selection") {
|
|
71
|
+
return {
|
|
72
|
+
content: [
|
|
73
|
+
{
|
|
74
|
+
type: "text",
|
|
75
|
+
text: `Could not verify ${instrument.query}. Choose one of the returned candidates before adding it to the watchlist.`,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
details: instrument,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const item = service.addWatchlistItem({
|
|
82
|
+
instrument: instrument.instrument,
|
|
83
|
+
targetPrice: args.target_price,
|
|
84
|
+
stopPrice: args.stop_price,
|
|
85
|
+
thesis: args.thesis,
|
|
86
|
+
notes: args.notes,
|
|
87
|
+
tags: args.tags,
|
|
88
|
+
});
|
|
89
|
+
const alerts = [];
|
|
90
|
+
if (args.target_price) alerts.push(`target: $${args.target_price}`);
|
|
91
|
+
if (args.stop_price) alerts.push(`stop: $${args.stop_price}`);
|
|
92
|
+
const alertStr = alerts.length > 0 ? ` (${alerts.join(", ")})` : "";
|
|
93
|
+
return {
|
|
94
|
+
content: [{ type: "text", text: `Added ${item.symbol} to watchlist${alertStr}` }],
|
|
95
|
+
details: item,
|
|
96
|
+
};
|
|
63
97
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
98
|
+
|
|
99
|
+
if (args.action === "remove") {
|
|
100
|
+
if (!args.symbol) {
|
|
101
|
+
throw new Error("symbol is required for remove action.");
|
|
102
|
+
}
|
|
103
|
+
const symbol = args.symbol.toUpperCase();
|
|
104
|
+
if (!service.removeWatchlistItemBySymbol(symbol)) {
|
|
105
|
+
return {
|
|
106
|
+
content: [{ type: "text", text: `${symbol} not found in watchlist` }],
|
|
107
|
+
details: null,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
content: [{ type: "text", text: `Removed ${symbol} from watchlist` }],
|
|
112
|
+
details: null,
|
|
113
|
+
};
|
|
77
114
|
}
|
|
78
|
-
saveWatchlist(items);
|
|
79
|
-
const alerts = [];
|
|
80
|
-
if (args.target_price) alerts.push(`target: $${args.target_price}`);
|
|
81
|
-
if (args.stop_price) alerts.push(`stop: $${args.stop_price}`);
|
|
82
|
-
const alertStr = alerts.length > 0 ? ` (${alerts.join(", ")})` : "";
|
|
83
|
-
return {
|
|
84
|
-
content: [{ type: "text", text: `Added ${symbol} to watchlist${alertStr}` }],
|
|
85
|
-
details: null,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
115
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
116
|
+
if (args.action === "update") {
|
|
117
|
+
if (!args.symbol) {
|
|
118
|
+
throw new Error("symbol is required for update action.");
|
|
119
|
+
}
|
|
120
|
+
const symbol = args.symbol.toUpperCase();
|
|
121
|
+
const item = service.updateWatchlistItemBySymbol(symbol, {
|
|
122
|
+
targetPrice: args.target_price,
|
|
123
|
+
stopPrice: args.stop_price,
|
|
124
|
+
notes: args.notes,
|
|
125
|
+
thesis: args.thesis,
|
|
126
|
+
tags: args.tags,
|
|
127
|
+
});
|
|
128
|
+
if (item == null) {
|
|
129
|
+
return {
|
|
130
|
+
content: [{ type: "text", text: `${symbol} not found in watchlist` }],
|
|
131
|
+
details: null,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
content: [{ type: "text", text: `Updated ${item.symbol} in watchlist` }],
|
|
136
|
+
details: item,
|
|
137
|
+
};
|
|
92
138
|
}
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
139
|
+
|
|
140
|
+
const items = service.listWatchlistItems();
|
|
141
|
+
if (items.length === 0) {
|
|
96
142
|
return {
|
|
97
|
-
content: [{ type: "text", text:
|
|
143
|
+
content: [{ type: "text", text: "Watchlist is empty. Use add action to add symbols." }],
|
|
98
144
|
details: null,
|
|
99
145
|
};
|
|
100
146
|
}
|
|
101
|
-
items.splice(idx, 1);
|
|
102
|
-
saveWatchlist(items);
|
|
103
|
-
return {
|
|
104
|
-
content: [{ type: "text", text: `Removed ${symbol} from watchlist` }],
|
|
105
|
-
details: null,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
147
|
|
|
109
|
-
|
|
110
|
-
|
|
148
|
+
const checks = await checkWatchlistPrices(items);
|
|
149
|
+
const alertItems = checks.filter((c) => c.alerts.length > 0);
|
|
150
|
+
const lines = [
|
|
151
|
+
`**Watchlist** — ${items.length} symbols${alertItems.length > 0 ? ` | ${alertItems.length} ALERT(S)` : ""}`,
|
|
152
|
+
"",
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
const tradingViewCaveats = Array.from(
|
|
156
|
+
new Set(
|
|
157
|
+
checks
|
|
158
|
+
.filter((c) => c.sourceProvider === "tradingview")
|
|
159
|
+
.map(
|
|
160
|
+
(c) =>
|
|
161
|
+
c.dataCaveat ??
|
|
162
|
+
"TradingView scanner data may be delayed about 15 minutes and comes from an unofficial endpoint.",
|
|
163
|
+
),
|
|
164
|
+
),
|
|
165
|
+
);
|
|
166
|
+
if (tradingViewCaveats.length > 0) {
|
|
167
|
+
lines.push(...tradingViewCaveats.map((caveat) => `Data caveat: ${caveat}`), "");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (const c of checks) {
|
|
171
|
+
const alertStr = c.alerts.length > 0 ? ` ** ${c.alerts.join(" | ")} **` : "";
|
|
172
|
+
const statusStr = c.statuses.length > 0 ? ` | ${c.statuses.join(" | ")}` : "";
|
|
173
|
+
const targetStr = c.targetPrice ? ` | Target: $${c.targetPrice}` : "";
|
|
174
|
+
const stopStr = c.stopPrice ? ` | Stop: $${c.stopPrice}` : "";
|
|
175
|
+
const sourceStr = c.sourceProvider
|
|
176
|
+
? ` | Source: ${c.sourceProvider === "tradingview" ? "TradingView" : "Yahoo"}`
|
|
177
|
+
: "";
|
|
178
|
+
const priceStr =
|
|
179
|
+
typeof c.currentPrice === "number" ? `$${c.currentPrice.toFixed(2)}` : "Unavailable";
|
|
180
|
+
lines.push(
|
|
181
|
+
` ${c.symbol}: ${priceStr}${targetStr}${stopStr}${sourceStr}${statusStr}${alertStr}`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
111
185
|
return {
|
|
112
|
-
content: [{ type: "text", text:
|
|
113
|
-
details:
|
|
186
|
+
content: [{ type: "text", text: lines.join("\n") }],
|
|
187
|
+
details: { items: checks },
|
|
114
188
|
};
|
|
189
|
+
} finally {
|
|
190
|
+
db.close();
|
|
115
191
|
}
|
|
192
|
+
},
|
|
193
|
+
};
|
|
116
194
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const alertItems = checks.filter((c) => c.alerts.length > 0);
|
|
136
|
-
const lines = [
|
|
137
|
-
`**Watchlist** — ${items.length} symbols${alertItems.length > 0 ? ` | ${alertItems.length} ALERT(S)` : ""}`,
|
|
138
|
-
"",
|
|
139
|
-
];
|
|
140
|
-
|
|
141
|
-
for (const c of checks) {
|
|
142
|
-
const alertStr = c.alerts.length > 0 ? ` ** ${c.alerts.join(" | ")} **` : "";
|
|
143
|
-
const targetStr = c.targetPrice ? ` | Target: $${c.targetPrice}` : "";
|
|
144
|
-
const stopStr = c.stopPrice ? ` | Stop: $${c.stopPrice}` : "";
|
|
145
|
-
lines.push(` ${c.symbol}: $${c.currentPrice.toFixed(2)}${targetStr}${stopStr}${alertStr}`);
|
|
195
|
+
async function checkWatchlistPrices(items: WatchlistItemRecord[]): Promise<WatchlistCheck[]> {
|
|
196
|
+
const tradingViewSymbols = items
|
|
197
|
+
.map((item) => item.symbol)
|
|
198
|
+
.filter((symbol) => !shouldSkipTradingView(symbol));
|
|
199
|
+
const tradingViewQuotes = new Map<string, TradingViewQuote>();
|
|
200
|
+
|
|
201
|
+
if (tradingViewSymbols.length > 0) {
|
|
202
|
+
const result = await wrapProvider("tradingview", () => getQuotes(tradingViewSymbols));
|
|
203
|
+
if (result.status === "ok" && result.data.length > 0) {
|
|
204
|
+
for (const quote of result.data) {
|
|
205
|
+
tradingViewQuotes.set(quote.requestedSymbol.toUpperCase(), {
|
|
206
|
+
...quote,
|
|
207
|
+
dataCaveat: result.stale
|
|
208
|
+
? `cached TradingView data from ${result.timestamp}; ${quote.dataCaveat}`
|
|
209
|
+
: quote.dataCaveat,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
146
212
|
}
|
|
213
|
+
}
|
|
147
214
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
215
|
+
return Promise.all(
|
|
216
|
+
items.map(async (item) => {
|
|
217
|
+
const tradingViewQuote = tradingViewQuotes.get(item.symbol.toUpperCase());
|
|
218
|
+
if (tradingViewQuote) {
|
|
219
|
+
return buildCheckResult(
|
|
220
|
+
item,
|
|
221
|
+
tradingViewQuote.price,
|
|
222
|
+
"tradingview",
|
|
223
|
+
tradingViewQuote.dataCaveat,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const result = await wrapProvider("yahoo", () => getQuote(item.symbol));
|
|
228
|
+
if (result.status === "unavailable") {
|
|
229
|
+
return {
|
|
230
|
+
...item,
|
|
231
|
+
currentPrice: null,
|
|
232
|
+
alerts: [`UNAVAILABLE: ${result.reason}`],
|
|
233
|
+
statuses: [],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
if (result.stale) {
|
|
237
|
+
return {
|
|
238
|
+
...item,
|
|
239
|
+
currentPrice: null,
|
|
240
|
+
alerts: ["UNAVAILABLE: provider returned stale market data"],
|
|
241
|
+
statuses: [],
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const quote = result.data;
|
|
245
|
+
if (isZeroFilledQuote(quote)) {
|
|
246
|
+
return {
|
|
247
|
+
...item,
|
|
248
|
+
currentPrice: null,
|
|
249
|
+
alerts: ["UNAVAILABLE: Yahoo returned no valid market data."],
|
|
250
|
+
statuses: [],
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
return buildCheckResult(item, quote.price, "yahoo");
|
|
254
|
+
}),
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function buildCheckResult(
|
|
259
|
+
item: WatchlistItemRecord,
|
|
260
|
+
price: number,
|
|
261
|
+
sourceProvider: "tradingview" | "yahoo",
|
|
262
|
+
dataCaveat?: string,
|
|
263
|
+
): WatchlistCheck {
|
|
264
|
+
const alerts: string[] = [];
|
|
265
|
+
const statuses: string[] = [];
|
|
266
|
+
if (item.targetPrice && price >= item.targetPrice) {
|
|
267
|
+
alerts.push(`TARGET HIT: $${price.toFixed(2)} >= $${item.targetPrice}`);
|
|
268
|
+
} else if (item.targetPrice) {
|
|
269
|
+
statuses.push(`Target pending: $${price.toFixed(2)} < $${item.targetPrice}`);
|
|
270
|
+
}
|
|
271
|
+
if (item.stopPrice && price <= item.stopPrice) {
|
|
272
|
+
alerts.push(`STOP ALERT: $${price.toFixed(2)} fell below $${item.stopPrice}`);
|
|
273
|
+
} else if (item.stopPrice) {
|
|
274
|
+
statuses.push(`Stop OK: $${price.toFixed(2)} > $${item.stopPrice}`);
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
...item,
|
|
278
|
+
currentPrice: price,
|
|
279
|
+
alerts,
|
|
280
|
+
statuses,
|
|
281
|
+
sourceProvider,
|
|
282
|
+
dataCaveat,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function shouldSkipTradingView(symbol: string): boolean {
|
|
287
|
+
return /(?:-USD|\.(?:TO|DE|T|L|HK))$/i.test(symbol.trim());
|
|
288
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Type } from "@sinclair/typebox";
|
|
2
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
3
|
-
import {
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
import { getConfig } from "../../config.js";
|
|
4
|
+
import { getPostComments, getSubredditPosts } from "../../providers/reddit.js";
|
|
4
5
|
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
5
|
-
import type { RedditSentimentResult } from "../../types/sentiment.js";
|
|
6
6
|
import { RedditAdapter } from "../../sentiment/adapters/reddit.js";
|
|
7
7
|
import { getSentimentPipeline } from "../../sentiment/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import type { RedditSentimentResult } from "../../types/sentiment.js";
|
|
9
|
+
import { renderUntrustedText, untrustedContentHeader } from "./untrusted-text.js";
|
|
9
10
|
|
|
10
11
|
const params = Type.Object({
|
|
11
12
|
subreddit: Type.Optional(
|
|
@@ -36,7 +37,7 @@ export const redditSentimentTool: AgentTool<typeof params, RedditSentimentResult
|
|
|
36
37
|
description:
|
|
37
38
|
"Analyze sentiment from financial Reddit communities. Supports single subreddit, multi-subreddit, and topic filtering. Returns scored posts with comment analysis and trend context.",
|
|
38
39
|
parameters: params,
|
|
39
|
-
async execute(
|
|
40
|
+
async execute(_toolCallId, args) {
|
|
40
41
|
const limit = Math.min(args.limit ?? 25, 100);
|
|
41
42
|
const config = getConfig();
|
|
42
43
|
|
|
@@ -47,7 +48,12 @@ export const redditSentimentTool: AgentTool<typeof params, RedditSentimentResult
|
|
|
47
48
|
} else if (args.subreddit) {
|
|
48
49
|
subreddits = [args.subreddit];
|
|
49
50
|
} else {
|
|
50
|
-
subreddits = config.sentiment?.defaultSubreddits ?? [
|
|
51
|
+
subreddits = config.sentiment?.defaultSubreddits ?? [
|
|
52
|
+
"wallstreetbets",
|
|
53
|
+
"stocks",
|
|
54
|
+
"investing",
|
|
55
|
+
"options",
|
|
56
|
+
];
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
// Fetch from all subreddits
|
|
@@ -64,21 +70,26 @@ export const redditSentimentTool: AgentTool<typeof params, RedditSentimentResult
|
|
|
64
70
|
|
|
65
71
|
if (allResults.length === 0) {
|
|
66
72
|
return {
|
|
67
|
-
content: [
|
|
73
|
+
content: [
|
|
74
|
+
{ type: "text", text: `⚠ Reddit sentiment unavailable (${warnings.join("; ")}).` },
|
|
75
|
+
],
|
|
68
76
|
details: null as any,
|
|
69
77
|
};
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
// Merge and filter by query if provided
|
|
73
81
|
const adapter = new RedditAdapter();
|
|
74
|
-
let allRecords = allResults.flatMap((r) =>
|
|
82
|
+
let allRecords = allResults.flatMap((r) =>
|
|
83
|
+
adapter.mapPostsToRecords(r, args.query ?? subreddits.join("+")),
|
|
84
|
+
);
|
|
75
85
|
|
|
76
86
|
// Topic filtering
|
|
77
87
|
if (args.query) {
|
|
78
88
|
const queryLower = args.query.toLowerCase();
|
|
79
|
-
allRecords = allRecords.filter(
|
|
80
|
-
r
|
|
81
|
-
|
|
89
|
+
allRecords = allRecords.filter(
|
|
90
|
+
(r) =>
|
|
91
|
+
r.text.toLowerCase().includes(queryLower) ||
|
|
92
|
+
(r.title?.toLowerCase().includes(queryLower) ?? false),
|
|
82
93
|
);
|
|
83
94
|
}
|
|
84
95
|
|
|
@@ -115,23 +126,33 @@ export const redditSentimentTool: AgentTool<typeof params, RedditSentimentResult
|
|
|
115
126
|
|
|
116
127
|
// Process through pipeline
|
|
117
128
|
const pipeline = getSentimentPipeline();
|
|
118
|
-
const pipelineResult = await pipeline.processRecords(
|
|
129
|
+
const pipelineResult = await pipeline.processRecords(
|
|
130
|
+
allRecords,
|
|
131
|
+
args.query ?? subreddits.join("+"),
|
|
132
|
+
);
|
|
119
133
|
|
|
120
134
|
// Build output using first result as base for backward compatibility
|
|
121
135
|
const firstResult = allResults[0];
|
|
122
136
|
const postRecords = pipelineResult.fresh.filter((r) => !r.metadata.isComment);
|
|
123
137
|
const commentRecords = pipelineResult.fresh.filter((r) => r.metadata.isComment);
|
|
124
|
-
const avgScore =
|
|
125
|
-
|
|
126
|
-
|
|
138
|
+
const avgScore =
|
|
139
|
+
postRecords.length > 0
|
|
140
|
+
? postRecords.reduce((s, r) => s + r.sentiment.score, 0) / postRecords.length
|
|
141
|
+
: 0;
|
|
127
142
|
|
|
128
143
|
const sentimentLabel =
|
|
129
|
-
avgScore > 0.3
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
144
|
+
avgScore > 0.3
|
|
145
|
+
? "Bullish"
|
|
146
|
+
: avgScore < -0.3
|
|
147
|
+
? "Bearish"
|
|
148
|
+
: avgScore > 0
|
|
149
|
+
? "Leaning Bullish"
|
|
150
|
+
: avgScore < 0
|
|
151
|
+
? "Leaning Bearish"
|
|
152
|
+
: "Neutral";
|
|
153
|
+
|
|
154
|
+
const subLabel =
|
|
155
|
+
subreddits.length === 1 ? `r/${subreddits[0]}` : `${subreddits.length} subreddits`;
|
|
135
156
|
const lines = [
|
|
136
157
|
`**Reddit: ${args.query ?? subLabel}** — ${postRecords.length} posts, ${commentRecords.length} comments`,
|
|
137
158
|
`Sentiment: ${avgScore.toFixed(2)} (${sentimentLabel})`,
|
|
@@ -142,16 +163,21 @@ export const redditSentimentTool: AgentTool<typeof params, RedditSentimentResult
|
|
|
142
163
|
}
|
|
143
164
|
|
|
144
165
|
lines.push("");
|
|
145
|
-
lines.push("
|
|
166
|
+
lines.push(untrustedContentHeader("Reddit posts"));
|
|
146
167
|
for (const post of postRecords.slice(0, 10)) {
|
|
147
|
-
const scoreIndicator =
|
|
148
|
-
|
|
168
|
+
const scoreIndicator =
|
|
169
|
+
post.sentiment.score > 0 ? "🟢" : post.sentiment.score < 0 ? "🔴" : "⚪";
|
|
170
|
+
lines.push(
|
|
171
|
+
` ${scoreIndicator} ⬆${post.engagement.score} 💬${post.engagement.replies ?? 0} — ${renderUntrustedText(post.title ?? post.text, 100)}`,
|
|
172
|
+
);
|
|
149
173
|
}
|
|
150
174
|
|
|
151
175
|
if (pipelineResult.trend && pipelineResult.trend.length > 0) {
|
|
152
176
|
const t = pipelineResult.trend[0];
|
|
153
177
|
lines.push("");
|
|
154
|
-
lines.push(
|
|
178
|
+
lines.push(
|
|
179
|
+
`Trend: ${t.sparkline} ${t.direction} (${t.delta >= 0 ? "+" : ""}${t.delta.toFixed(2)}, ${t.count} records)`,
|
|
180
|
+
);
|
|
155
181
|
}
|
|
156
182
|
|
|
157
183
|
if (warnings.length > 0) {
|