opencandle 0.11.1 → 0.12.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 +20 -24
- package/dist/analysts/contracts.js +0 -1
- package/dist/analysts/orchestrator.js +0 -1
- package/dist/cli-main.js +13 -7
- package/dist/cli-options.d.ts +4 -0
- package/dist/cli-options.js +33 -0
- package/dist/cli.js +8 -3
- package/dist/config.js +0 -1
- package/dist/doctor/cli-command.js +2 -1
- package/dist/doctor/render.js +0 -1
- package/dist/doctor/report.js +40 -11
- package/dist/gui/server/ask-user-bridge.d.ts +19 -0
- package/dist/gui/server/ask-user-bridge.js +55 -0
- package/dist/gui/server/automation-heartbeat.d.ts +25 -0
- package/dist/gui/server/automation-heartbeat.js +61 -0
- package/dist/gui/server/background-quotes.d.ts +39 -0
- package/dist/gui/server/background-quotes.js +71 -0
- package/dist/gui/server/chat-event-adapter.d.ts +16 -0
- package/dist/gui/server/chat-event-adapter.js +263 -0
- package/dist/gui/server/gui-session-manager.d.ts +2 -0
- package/dist/gui/server/gui-session-manager.js +4 -0
- package/dist/gui/server/http-routes.d.ts +69 -0
- package/dist/gui/server/http-routes.js +1008 -0
- package/dist/gui/server/invoke-tool.d.ts +47 -0
- package/dist/gui/server/invoke-tool.js +373 -0
- package/dist/gui/server/live-chat-event-adapter.d.ts +19 -0
- package/dist/gui/server/live-chat-event-adapter.js +206 -0
- package/dist/gui/server/local-session-coordinator.d.ts +26 -0
- package/dist/gui/server/local-session-coordinator.js +53 -0
- package/dist/gui/server/market-state-api.d.ts +138 -0
- package/dist/gui/server/market-state-api.js +355 -0
- package/dist/gui/server/model-setup.d.ts +64 -0
- package/dist/gui/server/model-setup.js +150 -0
- package/dist/gui/server/private-api-access.d.ts +6 -0
- package/dist/gui/server/private-api-access.js +53 -0
- package/dist/gui/server/projector.d.ts +49 -0
- package/dist/gui/server/projector.js +296 -0
- package/dist/gui/server/prompt-observation.d.ts +8 -0
- package/dist/gui/server/prompt-observation.js +43 -0
- package/dist/gui/server/quote-snapshot-store.d.ts +14 -0
- package/dist/gui/server/quote-snapshot-store.js +49 -0
- package/dist/gui/server/server.d.ts +1 -0
- package/dist/gui/server/server.js +259 -0
- package/dist/gui/server/session-actions.d.ts +60 -0
- package/dist/gui/server/session-actions.js +218 -0
- package/dist/gui/server/session-entry-wait.d.ts +27 -0
- package/dist/gui/server/session-entry-wait.js +129 -0
- package/dist/gui/server/session-list.d.ts +2 -0
- package/dist/gui/server/session-list.js +11 -0
- package/dist/gui/server/shutdown.d.ts +10 -0
- package/dist/gui/server/shutdown.js +29 -0
- package/dist/gui/server/tool-invoke-ack.d.ts +17 -0
- package/dist/gui/server/tool-invoke-ack.js +26 -0
- package/dist/gui/server/tool-metadata.d.ts +93 -0
- package/dist/gui/server/tool-metadata.js +148 -0
- package/dist/gui/server/websocket.d.ts +9 -0
- package/dist/gui/server/websocket.js +124 -0
- package/dist/gui/server/writer-lock.d.ts +1 -0
- package/dist/gui/server/writer-lock.js +1 -0
- package/dist/gui/server/ws-hub.d.ts +50 -0
- package/dist/gui/server/ws-hub.js +284 -0
- package/dist/gui/shared/chat-events.d.ts +174 -0
- package/dist/gui/shared/chat-events.js +13 -0
- package/dist/gui/shared/event-reducer.d.ts +3 -0
- package/dist/gui/shared/event-reducer.js +187 -0
- package/dist/index.js +0 -1
- package/dist/infra/cache.js +0 -1
- package/dist/infra/freshness.js +0 -1
- package/dist/infra/http-client.js +1 -2
- package/dist/infra/index.js +0 -1
- package/dist/infra/market-calendar.js +0 -1
- package/dist/infra/native-dependencies.js +0 -1
- package/dist/infra/node-version.js +0 -1
- package/dist/infra/open-url.js +0 -1
- package/dist/infra/opencandle-paths.js +0 -1
- package/dist/infra/rate-limiter.js +0 -1
- package/dist/market-state/alert-conditions.js +0 -1
- package/dist/market-state/alert-runner.d.ts +1 -0
- package/dist/market-state/alert-runner.js +5 -4
- package/dist/market-state/daily-report.js +0 -1
- package/dist/market-state/local-automation-service.js +0 -1
- package/dist/market-state/notification-delivery.js +0 -1
- package/dist/market-state/resolve-for-mutation.js +0 -1
- package/dist/market-state/resolve.js +0 -1
- package/dist/market-state/service.d.ts +26 -21
- package/dist/market-state/service.js +175 -36
- package/dist/market-state/summaries.js +1 -13
- package/dist/memory/index.js +0 -1
- package/dist/memory/manager.js +0 -1
- package/dist/memory/preference-extractor.js +0 -1
- package/dist/memory/retrieval.js +0 -1
- package/dist/memory/sqlite.js +60 -11
- package/dist/memory/storage.js +0 -1
- package/dist/memory/tool-defaults.js +0 -1
- package/dist/memory/types.js +0 -1
- package/dist/monitor.js +0 -1
- package/dist/onboarding/connect.js +0 -1
- package/dist/onboarding/credential-interceptor.js +0 -1
- package/dist/onboarding/degradation-accumulator.js +0 -1
- package/dist/onboarding/prompt-user.d.ts +1 -1
- package/dist/onboarding/prompt-user.js +0 -1
- package/dist/onboarding/provider-status.js +0 -1
- package/dist/onboarding/providers.js +0 -1
- package/dist/onboarding/state.js +0 -1
- package/dist/onboarding/tool-helpers.js +0 -1
- package/dist/onboarding/tool-tags.js +0 -1
- package/dist/onboarding/validate-model-key.d.ts +17 -0
- package/dist/onboarding/validate-model-key.js +54 -0
- package/dist/onboarding/validation.js +0 -1
- package/dist/pi/opencandle-extension.js +2 -2
- package/dist/pi/session-action-dedupe.js +0 -1
- package/dist/pi/session-storage.js +0 -1
- package/dist/pi/session-writer-lock.js +0 -1
- package/dist/pi/session.js +0 -1
- package/dist/pi/setup.d.ts +2 -0
- package/dist/pi/setup.js +10 -3
- package/dist/pi/tool-adapter.js +0 -1
- package/dist/pi/tui-session-coordinator.js +0 -1
- package/dist/prompts/context-builder.js +1 -2
- package/dist/prompts/disclaimer.js +0 -1
- package/dist/prompts/policy-cards.js +0 -1
- package/dist/prompts/sections.js +0 -1
- package/dist/prompts/symbol-preflight.js +0 -1
- package/dist/prompts/workflow-prompts.js +0 -1
- package/dist/providers/alpha-vantage.js +2 -3
- package/dist/providers/coingecko.js +0 -1
- package/dist/providers/errors.js +0 -1
- package/dist/providers/exa-search.js +11 -10
- package/dist/providers/external-tool-command.js +0 -1
- package/dist/providers/external-tool-error.js +0 -1
- package/dist/providers/fear-greed.js +0 -1
- package/dist/providers/finnhub.js +0 -1
- package/dist/providers/fred.js +0 -1
- package/dist/providers/index.js +0 -1
- package/dist/providers/polymarket.js +0 -1
- package/dist/providers/provider-credential-error.js +0 -1
- package/dist/providers/reddit-cli.js +0 -1
- package/dist/providers/reddit.js +0 -1
- package/dist/providers/sec-edgar.js +0 -1
- package/dist/providers/tradingview.js +1 -2
- package/dist/providers/twitter-cli.js +0 -1
- package/dist/providers/twitter.js +0 -1
- package/dist/providers/web-search.js +15 -12
- package/dist/providers/with-fallback.js +0 -1
- package/dist/providers/wrap-provider.js +0 -1
- package/dist/providers/yahoo-finance.js +67 -4
- package/dist/routing/classify-intent.js +0 -1
- package/dist/routing/defaults.js +0 -1
- package/dist/routing/entity-extractor.js +2 -3
- package/dist/routing/fund-symbols.js +0 -1
- package/dist/routing/horizon.js +0 -1
- package/dist/routing/index.js +0 -1
- package/dist/routing/legacy-rule-router.js +0 -1
- package/dist/routing/planning.js +0 -1
- package/dist/routing/route-manifest.js +0 -1
- package/dist/routing/router-llm-client.d.ts +2 -2
- package/dist/routing/router-llm-client.js +0 -1
- package/dist/routing/router-prompt.js +0 -1
- package/dist/routing/router-types.js +0 -1
- package/dist/routing/router.js +1 -2
- package/dist/routing/slot-resolver.js +0 -1
- package/dist/routing/symbol-disambiguator.js +0 -1
- package/dist/routing/turn-context.js +0 -1
- package/dist/routing/types.js +0 -1
- package/dist/runtime/answer-contracts.js +0 -1
- package/dist/runtime/artifact-contracts.js +0 -1
- package/dist/runtime/evidence.js +0 -1
- package/dist/runtime/numeric-claims.js +0 -1
- package/dist/runtime/planning-evidence.js +0 -1
- package/dist/runtime/prompt-step.js +0 -1
- package/dist/runtime/provider-tracker.js +0 -1
- package/dist/runtime/run-context.js +0 -1
- package/dist/runtime/session-coordinator.js +0 -1
- package/dist/runtime/session-title.js +0 -1
- package/dist/runtime/tool-defaults-wrapper.js +0 -1
- package/dist/runtime/validation.js +0 -1
- package/dist/runtime/workflow-events.js +0 -1
- package/dist/runtime/workflow-runner.d.ts +1 -0
- package/dist/runtime/workflow-runner.js +8 -3
- package/dist/runtime/workflow-types.js +0 -1
- package/dist/sentiment/adapters/finnhub.js +0 -1
- package/dist/sentiment/adapters/reddit.js +0 -1
- package/dist/sentiment/adapters/twitter.js +0 -1
- package/dist/sentiment/adapters/web.js +0 -1
- package/dist/sentiment/index.js +4 -2
- package/dist/sentiment/insights.js +0 -1
- package/dist/sentiment/keywords.js +0 -1
- package/dist/sentiment/pipeline.js +0 -1
- package/dist/sentiment/scorer.js +0 -1
- package/dist/sentiment/store.js +0 -1
- package/dist/sentiment/trends.js +0 -1
- package/dist/sentiment/types.js +0 -1
- package/dist/system-prompt.js +0 -1
- package/dist/tool-kit.js +0 -1
- package/dist/tools/fundamentals/company-overview.d.ts +1 -1
- package/dist/tools/fundamentals/company-overview.js +2 -1
- package/dist/tools/fundamentals/comps.js +6 -4
- package/dist/tools/fundamentals/dcf.js +0 -1
- package/dist/tools/fundamentals/earnings.d.ts +1 -1
- package/dist/tools/fundamentals/earnings.js +2 -1
- package/dist/tools/fundamentals/financials.js +2 -1
- package/dist/tools/fundamentals/sec-filings.js +0 -1
- package/dist/tools/index.d.ts +116 -2
- package/dist/tools/index.js +0 -1
- package/dist/tools/interaction/ask-user.js +11 -1
- package/dist/tools/macro/event-probabilities.js +0 -1
- package/dist/tools/macro/fear-greed.d.ts +1 -1
- package/dist/tools/macro/fear-greed.js +0 -1
- package/dist/tools/macro/fred-data.d.ts +1 -1
- package/dist/tools/macro/fred-data.js +2 -1
- package/dist/tools/market/crypto-history.js +0 -1
- package/dist/tools/market/crypto-price.d.ts +2 -2
- package/dist/tools/market/crypto-price.js +0 -1
- package/dist/tools/market/screen-stocks.js +0 -1
- package/dist/tools/market/search-ticker.js +1 -2
- package/dist/tools/market/stock-history.js +0 -1
- package/dist/tools/market/stock-quote.d.ts +2 -2
- package/dist/tools/market/stock-quote.js +0 -1
- package/dist/tools/options/greeks.js +0 -1
- package/dist/tools/options/option-chain.d.ts +2 -2
- package/dist/tools/options/option-chain.js +0 -1
- package/dist/tools/portfolio/alerts.d.ts +2 -1
- package/dist/tools/portfolio/alerts.js +228 -2
- package/dist/tools/portfolio/correlation.js +23 -5
- package/dist/tools/portfolio/daily-report.js +0 -1
- package/dist/tools/portfolio/holdings-overlap.js +0 -1
- package/dist/tools/portfolio/notifications.js +0 -1
- package/dist/tools/portfolio/risk-analysis.d.ts +1 -1
- package/dist/tools/portfolio/risk-analysis.js +0 -1
- package/dist/tools/portfolio/tracker.d.ts +3 -1
- package/dist/tools/portfolio/tracker.js +57 -10
- package/dist/tools/portfolio/watchlist.d.ts +3 -6
- package/dist/tools/portfolio/watchlist.js +101 -110
- package/dist/tools/sentiment/insight-format.js +0 -1
- package/dist/tools/sentiment/query-match.js +0 -1
- package/dist/tools/sentiment/reddit-sentiment.js +0 -1
- package/dist/tools/sentiment/sentiment-summary.js +8 -4
- package/dist/tools/sentiment/sentiment-trend.d.ts +5 -1
- package/dist/tools/sentiment/sentiment-trend.js +6 -2
- package/dist/tools/sentiment/twitter-sentiment.js +0 -1
- package/dist/tools/sentiment/untrusted-text.js +0 -1
- package/dist/tools/sentiment/web-search.d.ts +1 -1
- package/dist/tools/sentiment/web-search.js +0 -1
- package/dist/tools/sentiment/web-sentiment.js +0 -1
- package/dist/tools/technical/backtest.js +0 -1
- package/dist/tools/technical/indicators.js +0 -1
- package/dist/types/fundamentals.js +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/macro.js +0 -1
- package/dist/types/market.d.ts +6 -0
- package/dist/types/market.js +0 -1
- package/dist/types/options.js +0 -1
- package/dist/types/portfolio.js +0 -1
- package/dist/types/prediction-markets.js +0 -1
- package/dist/types/sentiment.js +0 -1
- package/dist/workflows/compare-assets.js +0 -1
- package/dist/workflows/index.js +0 -1
- package/dist/workflows/options-screener.js +0 -1
- package/dist/workflows/portfolio-builder.js +0 -1
- package/gui/web/dist/assets/CatalogOverlay-CAc7e3Pf.js +1 -0
- package/gui/web/dist/assets/index-BOEKd9wT.css +2 -0
- package/gui/web/dist/assets/index-C-H05cQ2.js +65 -0
- package/gui/web/dist/index.html +2 -2
- package/package.json +11 -12
- package/dist/analysts/contracts.js.map +0 -1
- package/dist/analysts/orchestrator.js.map +0 -1
- package/dist/cli-main.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/doctor/cli-command.js.map +0 -1
- package/dist/doctor/render.js.map +0 -1
- package/dist/doctor/report.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/infra/cache.js.map +0 -1
- package/dist/infra/freshness.js.map +0 -1
- package/dist/infra/http-client.js.map +0 -1
- package/dist/infra/index.js.map +0 -1
- package/dist/infra/market-calendar.js.map +0 -1
- package/dist/infra/native-dependencies.js.map +0 -1
- package/dist/infra/node-version.js.map +0 -1
- package/dist/infra/open-url.js.map +0 -1
- package/dist/infra/opencandle-paths.js.map +0 -1
- package/dist/infra/rate-limiter.js.map +0 -1
- package/dist/market-state/alert-conditions.js.map +0 -1
- package/dist/market-state/alert-runner.js.map +0 -1
- package/dist/market-state/daily-report.js.map +0 -1
- package/dist/market-state/local-automation-service.js.map +0 -1
- package/dist/market-state/notification-delivery.js.map +0 -1
- package/dist/market-state/resolve-for-mutation.js.map +0 -1
- package/dist/market-state/resolve.js.map +0 -1
- package/dist/market-state/service.js.map +0 -1
- package/dist/market-state/summaries.js.map +0 -1
- package/dist/memory/index.js.map +0 -1
- package/dist/memory/manager.js.map +0 -1
- package/dist/memory/preference-extractor.js.map +0 -1
- package/dist/memory/retrieval.js.map +0 -1
- package/dist/memory/sqlite.js.map +0 -1
- package/dist/memory/storage.js.map +0 -1
- package/dist/memory/tool-defaults.js.map +0 -1
- package/dist/memory/types.js.map +0 -1
- package/dist/monitor.js.map +0 -1
- package/dist/onboarding/connect.js.map +0 -1
- package/dist/onboarding/credential-interceptor.js.map +0 -1
- package/dist/onboarding/degradation-accumulator.js.map +0 -1
- package/dist/onboarding/prompt-user.js.map +0 -1
- package/dist/onboarding/provider-status.js.map +0 -1
- package/dist/onboarding/providers.js.map +0 -1
- package/dist/onboarding/state.js.map +0 -1
- package/dist/onboarding/tool-helpers.js.map +0 -1
- package/dist/onboarding/tool-tags.js.map +0 -1
- package/dist/onboarding/validation.js.map +0 -1
- package/dist/pi/opencandle-extension.js.map +0 -1
- package/dist/pi/session-action-dedupe.js.map +0 -1
- package/dist/pi/session-storage.js.map +0 -1
- package/dist/pi/session-writer-lock.js.map +0 -1
- package/dist/pi/session.js.map +0 -1
- package/dist/pi/setup.js.map +0 -1
- package/dist/pi/tool-adapter.js.map +0 -1
- package/dist/pi/tui-session-coordinator.js.map +0 -1
- package/dist/prompts/context-builder.js.map +0 -1
- package/dist/prompts/disclaimer.js.map +0 -1
- package/dist/prompts/policy-cards.js.map +0 -1
- package/dist/prompts/sections.js.map +0 -1
- package/dist/prompts/symbol-preflight.js.map +0 -1
- package/dist/prompts/workflow-prompts.js.map +0 -1
- package/dist/providers/alpha-vantage.js.map +0 -1
- package/dist/providers/coingecko.js.map +0 -1
- package/dist/providers/errors.js.map +0 -1
- package/dist/providers/exa-search.js.map +0 -1
- package/dist/providers/external-tool-command.js.map +0 -1
- package/dist/providers/external-tool-error.js.map +0 -1
- package/dist/providers/fear-greed.js.map +0 -1
- package/dist/providers/finnhub.js.map +0 -1
- package/dist/providers/fred.js.map +0 -1
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/polymarket.js.map +0 -1
- package/dist/providers/provider-credential-error.js.map +0 -1
- package/dist/providers/reddit-cli.js.map +0 -1
- package/dist/providers/reddit.js.map +0 -1
- package/dist/providers/sec-edgar.js.map +0 -1
- package/dist/providers/tradingview.js.map +0 -1
- package/dist/providers/twitter-cli.js.map +0 -1
- package/dist/providers/twitter.js.map +0 -1
- package/dist/providers/web-search.js.map +0 -1
- package/dist/providers/with-fallback.js.map +0 -1
- package/dist/providers/wrap-provider.js.map +0 -1
- package/dist/providers/yahoo-finance.js.map +0 -1
- package/dist/routing/classify-intent.js.map +0 -1
- package/dist/routing/defaults.js.map +0 -1
- package/dist/routing/entity-extractor.js.map +0 -1
- package/dist/routing/fund-symbols.js.map +0 -1
- package/dist/routing/horizon.js.map +0 -1
- package/dist/routing/index.js.map +0 -1
- package/dist/routing/legacy-rule-router.js.map +0 -1
- package/dist/routing/planning.js.map +0 -1
- package/dist/routing/route-manifest.js.map +0 -1
- package/dist/routing/router-llm-client.js.map +0 -1
- package/dist/routing/router-prompt.js.map +0 -1
- package/dist/routing/router-types.js.map +0 -1
- package/dist/routing/router.js.map +0 -1
- package/dist/routing/slot-resolver.js.map +0 -1
- package/dist/routing/symbol-disambiguator.js.map +0 -1
- package/dist/routing/turn-context.js.map +0 -1
- package/dist/routing/types.js.map +0 -1
- package/dist/runtime/answer-contracts.js.map +0 -1
- package/dist/runtime/artifact-contracts.js.map +0 -1
- package/dist/runtime/evidence.js.map +0 -1
- package/dist/runtime/numeric-claims.js.map +0 -1
- package/dist/runtime/planning-evidence.js.map +0 -1
- package/dist/runtime/prompt-step.js.map +0 -1
- package/dist/runtime/provider-tracker.js.map +0 -1
- package/dist/runtime/run-context.js.map +0 -1
- package/dist/runtime/session-coordinator.js.map +0 -1
- package/dist/runtime/session-title.js.map +0 -1
- package/dist/runtime/tool-defaults-wrapper.js.map +0 -1
- package/dist/runtime/validation.js.map +0 -1
- package/dist/runtime/workflow-events.js.map +0 -1
- package/dist/runtime/workflow-runner.js.map +0 -1
- package/dist/runtime/workflow-types.js.map +0 -1
- package/dist/sentiment/adapters/finnhub.js.map +0 -1
- package/dist/sentiment/adapters/reddit.js.map +0 -1
- package/dist/sentiment/adapters/twitter.js.map +0 -1
- package/dist/sentiment/adapters/web.js.map +0 -1
- package/dist/sentiment/index.js.map +0 -1
- package/dist/sentiment/insights.js.map +0 -1
- package/dist/sentiment/keywords.js.map +0 -1
- package/dist/sentiment/pipeline.js.map +0 -1
- package/dist/sentiment/scorer.js.map +0 -1
- package/dist/sentiment/store.js.map +0 -1
- package/dist/sentiment/trends.js.map +0 -1
- package/dist/sentiment/types.js.map +0 -1
- package/dist/system-prompt.js.map +0 -1
- package/dist/tool-kit.js.map +0 -1
- package/dist/tools/fundamentals/company-overview.js.map +0 -1
- package/dist/tools/fundamentals/comps.js.map +0 -1
- package/dist/tools/fundamentals/dcf.js.map +0 -1
- package/dist/tools/fundamentals/earnings.js.map +0 -1
- package/dist/tools/fundamentals/financials.js.map +0 -1
- package/dist/tools/fundamentals/sec-filings.js.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/interaction/ask-user.js.map +0 -1
- package/dist/tools/macro/event-probabilities.js.map +0 -1
- package/dist/tools/macro/fear-greed.js.map +0 -1
- package/dist/tools/macro/fred-data.js.map +0 -1
- package/dist/tools/market/crypto-history.js.map +0 -1
- package/dist/tools/market/crypto-price.js.map +0 -1
- package/dist/tools/market/screen-stocks.js.map +0 -1
- package/dist/tools/market/search-ticker.js.map +0 -1
- package/dist/tools/market/stock-history.js.map +0 -1
- package/dist/tools/market/stock-quote.js.map +0 -1
- package/dist/tools/options/greeks.js.map +0 -1
- package/dist/tools/options/option-chain.js.map +0 -1
- package/dist/tools/portfolio/alerts.js.map +0 -1
- package/dist/tools/portfolio/correlation.js.map +0 -1
- package/dist/tools/portfolio/daily-report.js.map +0 -1
- package/dist/tools/portfolio/holdings-overlap.js.map +0 -1
- package/dist/tools/portfolio/notifications.js.map +0 -1
- package/dist/tools/portfolio/risk-analysis.js.map +0 -1
- package/dist/tools/portfolio/tracker.js.map +0 -1
- package/dist/tools/portfolio/watchlist.js.map +0 -1
- package/dist/tools/sentiment/insight-format.js.map +0 -1
- package/dist/tools/sentiment/query-match.js.map +0 -1
- package/dist/tools/sentiment/reddit-sentiment.js.map +0 -1
- package/dist/tools/sentiment/sentiment-summary.js.map +0 -1
- package/dist/tools/sentiment/sentiment-trend.js.map +0 -1
- package/dist/tools/sentiment/twitter-sentiment.js.map +0 -1
- package/dist/tools/sentiment/untrusted-text.js.map +0 -1
- package/dist/tools/sentiment/web-search.js.map +0 -1
- package/dist/tools/sentiment/web-sentiment.js.map +0 -1
- package/dist/tools/technical/backtest.js.map +0 -1
- package/dist/tools/technical/indicators.js.map +0 -1
- package/dist/types/fundamentals.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/macro.js.map +0 -1
- package/dist/types/market.js.map +0 -1
- package/dist/types/options.js.map +0 -1
- package/dist/types/portfolio.js.map +0 -1
- package/dist/types/prediction-markets.js.map +0 -1
- package/dist/types/sentiment.js.map +0 -1
- package/dist/workflows/compare-assets.js.map +0 -1
- package/dist/workflows/index.js.map +0 -1
- package/dist/workflows/options-screener.js.map +0 -1
- package/dist/workflows/portfolio-builder.js.map +0 -1
- package/gui/server/ask-user-bridge.ts +0 -89
- package/gui/server/automation-heartbeat.ts +0 -97
- package/gui/server/background-quotes.ts +0 -127
- package/gui/server/chat-event-adapter.ts +0 -294
- package/gui/server/gui-session-manager.ts +0 -5
- package/gui/server/http-routes.ts +0 -1201
- package/gui/server/invoke-tool.ts +0 -490
- package/gui/server/live-chat-event-adapter.ts +0 -243
- package/gui/server/local-session-coordinator.ts +0 -97
- package/gui/server/market-state-api.ts +0 -331
- package/gui/server/model-setup.ts +0 -254
- package/gui/server/package.json +0 -5
- package/gui/server/private-api-access.ts +0 -62
- package/gui/server/projector.ts +0 -392
- package/gui/server/prompt-observation.ts +0 -58
- package/gui/server/quote-snapshot-store.ts +0 -50
- package/gui/server/server.ts +0 -289
- package/gui/server/session-actions.ts +0 -323
- package/gui/server/session-entry-wait.ts +0 -179
- package/gui/server/shutdown.ts +0 -47
- package/gui/server/tool-invoke-ack.ts +0 -49
- package/gui/server/tool-metadata.ts +0 -167
- package/gui/server/websocket.ts +0 -138
- package/gui/server/writer-lock.ts +0 -1
- package/gui/server/ws-hub.ts +0 -403
- package/gui/shared/chat-events.ts +0 -165
- package/gui/shared/event-reducer.ts +0 -220
- package/gui/web/dist/assets/CatalogOverlay-DZ1niyQm.js +0 -1
- package/gui/web/dist/assets/index-D4F9AJnn.css +0 -2
- package/gui/web/dist/assets/index-DtqMMBTr.js +0 -65
- package/src/analysts/contracts.ts +0 -176
- package/src/analysts/orchestrator.ts +0 -244
- package/src/cli-main.ts +0 -510
- package/src/cli.ts +0 -17
- package/src/config.ts +0 -272
- package/src/doctor/cli-command.ts +0 -83
- package/src/doctor/render.ts +0 -37
- package/src/doctor/report.ts +0 -638
- package/src/index.ts +0 -5
- package/src/infra/cache.ts +0 -127
- package/src/infra/freshness.ts +0 -165
- package/src/infra/http-client.ts +0 -134
- package/src/infra/index.ts +0 -14
- package/src/infra/market-calendar.ts +0 -193
- package/src/infra/native-dependencies.ts +0 -84
- package/src/infra/node-version.ts +0 -23
- package/src/infra/open-url.ts +0 -28
- package/src/infra/opencandle-paths.ts +0 -53
- package/src/infra/rate-limiter.ts +0 -77
- package/src/market-state/alert-conditions.ts +0 -82
- package/src/market-state/alert-runner.ts +0 -863
- package/src/market-state/daily-report.ts +0 -237
- package/src/market-state/local-automation-service.ts +0 -162
- package/src/market-state/notification-delivery.ts +0 -158
- package/src/market-state/resolve-for-mutation.ts +0 -24
- package/src/market-state/resolve.ts +0 -112
- package/src/market-state/service.ts +0 -2208
- package/src/market-state/summaries.ts +0 -75
- package/src/memory/index.ts +0 -10
- package/src/memory/manager.ts +0 -190
- package/src/memory/preference-extractor.ts +0 -106
- package/src/memory/retrieval.ts +0 -71
- package/src/memory/sqlite.ts +0 -577
- package/src/memory/storage.ts +0 -195
- package/src/memory/tool-defaults.ts +0 -108
- package/src/memory/types.ts +0 -71
- package/src/monitor.ts +0 -123
- package/src/onboarding/connect.ts +0 -177
- package/src/onboarding/credential-interceptor.ts +0 -122
- package/src/onboarding/degradation-accumulator.ts +0 -77
- package/src/onboarding/prompt-user.ts +0 -85
- package/src/onboarding/provider-status.ts +0 -382
- package/src/onboarding/providers.ts +0 -442
- package/src/onboarding/state.ts +0 -216
- package/src/onboarding/tool-helpers.ts +0 -104
- package/src/onboarding/tool-tags.ts +0 -244
- package/src/onboarding/validation.ts +0 -152
- package/src/pi/opencandle-extension.ts +0 -1294
- package/src/pi/session-action-dedupe.ts +0 -155
- package/src/pi/session-storage.ts +0 -5
- package/src/pi/session-writer-lock.ts +0 -426
- package/src/pi/session.ts +0 -84
- package/src/pi/setup.ts +0 -399
- package/src/pi/tool-adapter.ts +0 -49
- package/src/pi/tui-session-coordinator.ts +0 -351
- package/src/prompts/context-builder.ts +0 -326
- package/src/prompts/disclaimer.ts +0 -9
- package/src/prompts/policy-cards.ts +0 -228
- package/src/prompts/sections.ts +0 -46
- package/src/prompts/symbol-preflight.ts +0 -80
- package/src/prompts/workflow-prompts.ts +0 -504
- package/src/providers/alpha-vantage.ts +0 -340
- package/src/providers/coingecko.ts +0 -95
- package/src/providers/errors.ts +0 -9
- package/src/providers/exa-search.ts +0 -375
- package/src/providers/external-tool-command.ts +0 -164
- package/src/providers/external-tool-error.ts +0 -20
- package/src/providers/fear-greed.ts +0 -45
- package/src/providers/finnhub.ts +0 -125
- package/src/providers/fred.ts +0 -83
- package/src/providers/index.ts +0 -17
- package/src/providers/polymarket.ts +0 -214
- package/src/providers/provider-credential-error.ts +0 -23
- package/src/providers/reddit-cli.ts +0 -286
- package/src/providers/reddit.ts +0 -106
- package/src/providers/sec-edgar.ts +0 -326
- package/src/providers/tradingview.ts +0 -399
- package/src/providers/twitter-cli.ts +0 -202
- package/src/providers/twitter.ts +0 -102
- package/src/providers/web-search.ts +0 -303
- package/src/providers/with-fallback.ts +0 -42
- package/src/providers/wrap-provider.ts +0 -105
- package/src/providers/yahoo-finance.ts +0 -984
- package/src/routing/classify-intent.ts +0 -380
- package/src/routing/defaults.ts +0 -29
- package/src/routing/entity-extractor.ts +0 -557
- package/src/routing/fund-symbols.ts +0 -58
- package/src/routing/horizon.ts +0 -7
- package/src/routing/index.ts +0 -70
- package/src/routing/legacy-rule-router.ts +0 -13
- package/src/routing/planning.ts +0 -829
- package/src/routing/route-manifest.ts +0 -308
- package/src/routing/router-llm-client.ts +0 -64
- package/src/routing/router-prompt.ts +0 -159
- package/src/routing/router-types.ts +0 -84
- package/src/routing/router.ts +0 -1332
- package/src/routing/slot-resolver.ts +0 -213
- package/src/routing/symbol-disambiguator.ts +0 -72
- package/src/routing/turn-context.ts +0 -108
- package/src/routing/types.ts +0 -77
- package/src/runtime/answer-contracts.ts +0 -693
- package/src/runtime/artifact-contracts.ts +0 -77
- package/src/runtime/evidence.ts +0 -78
- package/src/runtime/numeric-claims.ts +0 -108
- package/src/runtime/planning-evidence.ts +0 -597
- package/src/runtime/prompt-step.ts +0 -185
- package/src/runtime/provider-tracker.ts +0 -40
- package/src/runtime/run-context.ts +0 -32
- package/src/runtime/session-coordinator.ts +0 -1037
- package/src/runtime/session-title.ts +0 -60
- package/src/runtime/tool-defaults-wrapper.ts +0 -43
- package/src/runtime/validation.ts +0 -211
- package/src/runtime/workflow-events.ts +0 -77
- package/src/runtime/workflow-runner.ts +0 -182
- package/src/runtime/workflow-types.ts +0 -105
- package/src/sentiment/adapters/finnhub.ts +0 -49
- package/src/sentiment/adapters/reddit.ts +0 -65
- package/src/sentiment/adapters/twitter.ts +0 -36
- package/src/sentiment/adapters/web.ts +0 -44
- package/src/sentiment/index.ts +0 -49
- package/src/sentiment/insights.ts +0 -269
- package/src/sentiment/keywords.ts +0 -31
- package/src/sentiment/pipeline.ts +0 -91
- package/src/sentiment/scorer.ts +0 -89
- package/src/sentiment/store.ts +0 -260
- package/src/sentiment/trends.ts +0 -96
- package/src/sentiment/types.ts +0 -112
- package/src/system-prompt.ts +0 -115
- package/src/tool-kit.ts +0 -69
- package/src/tools/AGENTS.md +0 -36
- package/src/tools/fundamentals/company-overview.ts +0 -64
- package/src/tools/fundamentals/comps.ts +0 -180
- package/src/tools/fundamentals/dcf.ts +0 -447
- package/src/tools/fundamentals/earnings.ts +0 -57
- package/src/tools/fundamentals/financials.ts +0 -63
- package/src/tools/fundamentals/sec-filings.ts +0 -105
- package/src/tools/index.ts +0 -104
- package/src/tools/interaction/ask-user.ts +0 -93
- package/src/tools/macro/event-probabilities.ts +0 -141
- package/src/tools/macro/fear-greed.ts +0 -41
- package/src/tools/macro/fred-data.ts +0 -92
- package/src/tools/market/crypto-history.ts +0 -72
- package/src/tools/market/crypto-price.ts +0 -65
- package/src/tools/market/screen-stocks.ts +0 -290
- package/src/tools/market/search-ticker.ts +0 -254
- package/src/tools/market/stock-history.ts +0 -104
- package/src/tools/market/stock-quote.ts +0 -73
- package/src/tools/options/greeks.ts +0 -81
- package/src/tools/options/option-chain.ts +0 -134
- package/src/tools/portfolio/alerts.ts +0 -457
- package/src/tools/portfolio/correlation.ts +0 -189
- package/src/tools/portfolio/daily-report.ts +0 -107
- package/src/tools/portfolio/holdings-overlap.ts +0 -139
- package/src/tools/portfolio/notifications.ts +0 -45
- package/src/tools/portfolio/risk-analysis.ts +0 -173
- package/src/tools/portfolio/tracker.ts +0 -308
- package/src/tools/portfolio/watchlist.ts +0 -288
- package/src/tools/sentiment/insight-format.ts +0 -50
- package/src/tools/sentiment/query-match.ts +0 -117
- package/src/tools/sentiment/reddit-sentiment.ts +0 -403
- package/src/tools/sentiment/sentiment-summary.ts +0 -383
- package/src/tools/sentiment/sentiment-trend.ts +0 -75
- package/src/tools/sentiment/twitter-sentiment.ts +0 -287
- package/src/tools/sentiment/untrusted-text.ts +0 -21
- package/src/tools/sentiment/web-search.ts +0 -186
- package/src/tools/sentiment/web-sentiment.ts +0 -96
- package/src/tools/technical/backtest.ts +0 -336
- package/src/tools/technical/indicators.ts +0 -281
- package/src/types/fundamentals.ts +0 -47
- package/src/types/index.ts +0 -26
- package/src/types/macro.ts +0 -27
- package/src/types/market.ts +0 -46
- package/src/types/options.ts +0 -53
- package/src/types/portfolio.ts +0 -83
- package/src/types/prediction-markets.ts +0 -13
- package/src/types/sentiment.ts +0 -129
- package/src/workflows/compare-assets.ts +0 -89
- package/src/workflows/index.ts +0 -3
- package/src/workflows/options-screener.ts +0 -125
- package/src/workflows/portfolio-builder.ts +0 -63
|
@@ -1,447 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { Type } from "@sinclair/typebox";
|
|
3
|
-
import { getConfig } from "../../config.js";
|
|
4
|
-
import { getFinancials, getOverview } from "../../providers/alpha-vantage.js";
|
|
5
|
-
import { ProviderCredentialError } from "../../providers/provider-credential-error.js";
|
|
6
|
-
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
7
|
-
import { getQuote, getYahooFinancials } from "../../providers/yahoo-finance.js";
|
|
8
|
-
import type { ProviderResult } from "../../runtime/evidence.js";
|
|
9
|
-
import type { FinancialStatement } from "../../types/fundamentals.js";
|
|
10
|
-
|
|
11
|
-
export interface DCFResult {
|
|
12
|
-
intrinsicValue: number;
|
|
13
|
-
enterpriseValue: number;
|
|
14
|
-
terminalValue: number;
|
|
15
|
-
netDebt: number;
|
|
16
|
-
projectedCashFlows: Array<{ year: number; fcf: number; presentValue: number }>;
|
|
17
|
-
assumptions: {
|
|
18
|
-
fcf: number;
|
|
19
|
-
growthRate: number;
|
|
20
|
-
discountRate: number;
|
|
21
|
-
terminalGrowth: number;
|
|
22
|
-
years: number;
|
|
23
|
-
};
|
|
24
|
-
sensitivityTable: Array<{ growthRate: number; discountRate: number; intrinsicValue: number }>;
|
|
25
|
-
warnings: string[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface DCFParams {
|
|
29
|
-
freeCashFlow: number;
|
|
30
|
-
growthRate: number;
|
|
31
|
-
discountRate: number;
|
|
32
|
-
terminalGrowth: number;
|
|
33
|
-
years: number;
|
|
34
|
-
netDebt: number;
|
|
35
|
-
sharesOutstanding: number;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function computeDCF(params: DCFParams): DCFResult {
|
|
39
|
-
const {
|
|
40
|
-
freeCashFlow,
|
|
41
|
-
growthRate,
|
|
42
|
-
discountRate,
|
|
43
|
-
terminalGrowth,
|
|
44
|
-
years,
|
|
45
|
-
netDebt,
|
|
46
|
-
sharesOutstanding,
|
|
47
|
-
} = params;
|
|
48
|
-
|
|
49
|
-
// Gordon Growth requires discount > terminal growth; a non-positive spread
|
|
50
|
-
// divides by zero or flips the terminal value's sign.
|
|
51
|
-
if (discountRate <= terminalGrowth) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`Gordon Growth constraint violated: terminal growth (${(terminalGrowth * 100).toFixed(1)}%) must be below the discount rate (${(discountRate * 100).toFixed(1)}%).`,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Project future cash flows (mid-year convention: discount at year-0.5)
|
|
58
|
-
const projectedCashFlows: Array<{ year: number; fcf: number; presentValue: number }> = [];
|
|
59
|
-
for (let y = 1; y <= years; y++) {
|
|
60
|
-
const fcf = freeCashFlow * (1 + growthRate) ** y;
|
|
61
|
-
const pv = fcf / (1 + discountRate) ** (y - 0.5); // mid-year convention
|
|
62
|
-
projectedCashFlows.push({ year: y, fcf, presentValue: pv });
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Terminal value (Gordon Growth Model), discounted at full year (end of projection)
|
|
66
|
-
const finalFCF = freeCashFlow * (1 + growthRate) ** years;
|
|
67
|
-
const terminalValue = (finalFCF * (1 + terminalGrowth)) / (discountRate - terminalGrowth);
|
|
68
|
-
const pvTerminal = terminalValue / (1 + discountRate) ** years;
|
|
69
|
-
|
|
70
|
-
// Enterprise value
|
|
71
|
-
const sumPVs = projectedCashFlows.reduce((s, cf) => s + cf.presentValue, 0);
|
|
72
|
-
const enterpriseValue = sumPVs + pvTerminal;
|
|
73
|
-
|
|
74
|
-
// Equity value → per share
|
|
75
|
-
const equityValue = enterpriseValue - netDebt;
|
|
76
|
-
const intrinsicValue = equityValue / sharesOutstanding;
|
|
77
|
-
|
|
78
|
-
// Sensitivity table: vary growth ±2% and discount ±2%
|
|
79
|
-
const sensitivityTable: Array<{
|
|
80
|
-
growthRate: number;
|
|
81
|
-
discountRate: number;
|
|
82
|
-
intrinsicValue: number;
|
|
83
|
-
}> = [];
|
|
84
|
-
for (let gDelta = -0.02; gDelta <= 0.02; gDelta += 0.01) {
|
|
85
|
-
for (let dDelta = -0.02; dDelta <= 0.02; dDelta += 0.01) {
|
|
86
|
-
const g = growthRate + gDelta;
|
|
87
|
-
const d = discountRate + dDelta;
|
|
88
|
-
if (d <= terminalGrowth || d <= 0 || g < 0) continue;
|
|
89
|
-
const sensResult = computeDCFSimple(
|
|
90
|
-
freeCashFlow,
|
|
91
|
-
g,
|
|
92
|
-
d,
|
|
93
|
-
terminalGrowth,
|
|
94
|
-
years,
|
|
95
|
-
netDebt,
|
|
96
|
-
sharesOutstanding,
|
|
97
|
-
);
|
|
98
|
-
sensitivityTable.push({ growthRate: g, discountRate: d, intrinsicValue: sensResult });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Validation warnings (inspired by Anthropic financial plugins + Dexter)
|
|
103
|
-
const warnings: string[] = [];
|
|
104
|
-
const tvPctOfEV = pvTerminal / enterpriseValue;
|
|
105
|
-
if (tvPctOfEV > 0.85) {
|
|
106
|
-
warnings.push(
|
|
107
|
-
`Terminal value is ${(tvPctOfEV * 100).toFixed(0)}% of enterprise value (typical: 40-80%). The valuation is heavily dependent on terminal assumptions.`,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
const spreadPct = discountRate - terminalGrowth;
|
|
111
|
-
if (spreadPct < 0.02) {
|
|
112
|
-
warnings.push(
|
|
113
|
-
`Terminal growth (${(terminalGrowth * 100).toFixed(1)}%) is very close to discount rate (${(discountRate * 100).toFixed(1)}%). Small changes in assumptions will produce large swings in value.`,
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
if (discountRate < 0.05 || discountRate > 0.2) {
|
|
117
|
-
warnings.push(
|
|
118
|
-
`Discount rate of ${(discountRate * 100).toFixed(1)}% is outside typical WACC range (5-20%).`,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
if (growthRate > 0.2) {
|
|
122
|
-
warnings.push(
|
|
123
|
-
`Growth rate of ${(growthRate * 100).toFixed(1)}% exceeds 20%. High growth is difficult to sustain — consider a multi-stage model.`,
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
intrinsicValue,
|
|
129
|
-
enterpriseValue,
|
|
130
|
-
terminalValue,
|
|
131
|
-
netDebt,
|
|
132
|
-
projectedCashFlows,
|
|
133
|
-
assumptions: {
|
|
134
|
-
fcf: freeCashFlow,
|
|
135
|
-
growthRate,
|
|
136
|
-
discountRate,
|
|
137
|
-
terminalGrowth,
|
|
138
|
-
years,
|
|
139
|
-
},
|
|
140
|
-
sensitivityTable,
|
|
141
|
-
warnings,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function computeDCFSimple(
|
|
146
|
-
fcf: number,
|
|
147
|
-
g: number,
|
|
148
|
-
d: number,
|
|
149
|
-
tg: number,
|
|
150
|
-
years: number,
|
|
151
|
-
debt: number,
|
|
152
|
-
shares: number,
|
|
153
|
-
): number {
|
|
154
|
-
let sumPV = 0;
|
|
155
|
-
for (let y = 1; y <= years; y++) {
|
|
156
|
-
sumPV += (fcf * (1 + g) ** y) / (1 + d) ** (y - 0.5); // mid-year convention
|
|
157
|
-
}
|
|
158
|
-
const finalFCF = fcf * (1 + g) ** years;
|
|
159
|
-
const tv = (finalFCF * (1 + tg)) / (d - tg);
|
|
160
|
-
const pvTV = tv / (1 + d) ** years;
|
|
161
|
-
return (sumPV + pvTV - debt) / shares;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function computeNetDebt(f: FinancialStatement): number | null {
|
|
165
|
-
if (f.totalDebt != null && f.cashAndEquivalents != null) {
|
|
166
|
-
return f.totalDebt - f.cashAndEquivalents;
|
|
167
|
-
}
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async function optionalAlphaVantage<T>(
|
|
172
|
-
apiKey: string | undefined,
|
|
173
|
-
fn: (apiKey: string) => Promise<T>,
|
|
174
|
-
): Promise<ProviderResult<T>> {
|
|
175
|
-
if (!apiKey) {
|
|
176
|
-
return {
|
|
177
|
-
status: "unavailable",
|
|
178
|
-
reason: "Alpha Vantage API key not configured",
|
|
179
|
-
provider: "alphavantage",
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
try {
|
|
183
|
-
return await wrapProvider("alphavantage", () => fn(apiKey));
|
|
184
|
-
} catch (error) {
|
|
185
|
-
if (error instanceof ProviderCredentialError) {
|
|
186
|
-
return {
|
|
187
|
-
status: "unavailable",
|
|
188
|
-
reason: `Alpha Vantage credential ${error.reason}`,
|
|
189
|
-
provider: "alphavantage",
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
throw error;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const params = Type.Object({
|
|
197
|
-
symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT)" }),
|
|
198
|
-
growth_rate: Type.Optional(
|
|
199
|
-
Type.Number({
|
|
200
|
-
description:
|
|
201
|
-
"Annual FCF growth rate as decimal (e.g. 0.10 for 10%). If omitted, estimated from historical data.",
|
|
202
|
-
}),
|
|
203
|
-
),
|
|
204
|
-
discount_rate: Type.Optional(
|
|
205
|
-
Type.Number({ description: "Discount rate / WACC as decimal (default: 0.10 for 10%)" }),
|
|
206
|
-
),
|
|
207
|
-
terminal_growth: Type.Optional(
|
|
208
|
-
Type.Number({ description: "Terminal growth rate as decimal (default: 0.03 for 3%)" }),
|
|
209
|
-
),
|
|
210
|
-
projection_years: Type.Optional(
|
|
211
|
-
Type.Number({ description: "Years to project forward (default: 5)" }),
|
|
212
|
-
),
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
export const dcfTool: AgentTool<typeof params> = {
|
|
216
|
-
name: "compute_dcf",
|
|
217
|
-
label: "DCF Valuation",
|
|
218
|
-
description:
|
|
219
|
-
"Compute a Discounted Cash Flow (DCF) intrinsic value estimate for a stock. Uses free cash flow, growth projections, and a discount rate to estimate what the stock is worth. Returns intrinsic value per share, margin of safety vs current price, and a sensitivity table.",
|
|
220
|
-
parameters: params,
|
|
221
|
-
async execute(_toolCallId, args) {
|
|
222
|
-
const symbol = args.symbol.toUpperCase();
|
|
223
|
-
const config = getConfig();
|
|
224
|
-
const alphaVantageApiKey = config.alphaVantageApiKey;
|
|
225
|
-
|
|
226
|
-
const [alphaVantageFinancialsResult, quoteResult] = await Promise.all([
|
|
227
|
-
optionalAlphaVantage(alphaVantageApiKey, (apiKey) => getFinancials(symbol, apiKey)),
|
|
228
|
-
wrapProvider("yahoo", () => getQuote(symbol)),
|
|
229
|
-
]);
|
|
230
|
-
|
|
231
|
-
const missing: string[] = [];
|
|
232
|
-
if (quoteResult.status === "unavailable") missing.push(`stock quote (${quoteResult.reason})`);
|
|
233
|
-
|
|
234
|
-
if (quoteResult.status === "unavailable") {
|
|
235
|
-
return {
|
|
236
|
-
content: [
|
|
237
|
-
{
|
|
238
|
-
type: "text",
|
|
239
|
-
text: `⚠ DCF valuation unavailable for ${symbol}. Missing: ${missing.join(", ")}. Both financials and current price are required.`,
|
|
240
|
-
},
|
|
241
|
-
],
|
|
242
|
-
details: null,
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const quote = quoteResult.data;
|
|
247
|
-
if (quote.price <= 0) {
|
|
248
|
-
return {
|
|
249
|
-
content: [
|
|
250
|
-
{
|
|
251
|
-
type: "text",
|
|
252
|
-
text: `⚠ DCF valuation unavailable for ${symbol}. Missing: current stock price. DCF output requires a real current quote price.`,
|
|
253
|
-
},
|
|
254
|
-
],
|
|
255
|
-
details: null,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
let financialsSource = "Alpha Vantage";
|
|
260
|
-
let financials: FinancialStatement[];
|
|
261
|
-
if (alphaVantageFinancialsResult.status === "ok" && !alphaVantageFinancialsResult.stale) {
|
|
262
|
-
financials = alphaVantageFinancialsResult.data;
|
|
263
|
-
} else {
|
|
264
|
-
const alphaVantageReason =
|
|
265
|
-
alphaVantageFinancialsResult.status === "ok"
|
|
266
|
-
? `stale cached financial statements${
|
|
267
|
-
alphaVantageFinancialsResult.timestamp
|
|
268
|
-
? ` from ${alphaVantageFinancialsResult.timestamp}`
|
|
269
|
-
: ""
|
|
270
|
-
}`
|
|
271
|
-
: alphaVantageFinancialsResult.reason;
|
|
272
|
-
const yahooFinancialsResult = await wrapProvider("yahoo", () => getYahooFinancials(symbol));
|
|
273
|
-
if (yahooFinancialsResult.status === "unavailable") {
|
|
274
|
-
return {
|
|
275
|
-
content: [
|
|
276
|
-
{
|
|
277
|
-
type: "text",
|
|
278
|
-
text: `⚠ DCF valuation unavailable for ${symbol}. Missing: financial statements (Alpha Vantage: ${alphaVantageReason}; Yahoo Finance: ${yahooFinancialsResult.reason}). Both financials and current price are required.`,
|
|
279
|
-
},
|
|
280
|
-
],
|
|
281
|
-
details: null,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
if (yahooFinancialsResult.stale) {
|
|
285
|
-
const cachedAt = yahooFinancialsResult.timestamp
|
|
286
|
-
? ` from ${yahooFinancialsResult.timestamp}`
|
|
287
|
-
: "";
|
|
288
|
-
return {
|
|
289
|
-
content: [
|
|
290
|
-
{
|
|
291
|
-
type: "text",
|
|
292
|
-
text: `⚠ DCF valuation unavailable for ${symbol}. Yahoo Finance returned stale cached financial statements${cachedAt} after Alpha Vantage could not provide fresh financial statements (${alphaVantageReason}). DCF output requires fresh financial statements and a current price.`,
|
|
293
|
-
},
|
|
294
|
-
],
|
|
295
|
-
details: null,
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
financials = yahooFinancialsResult.data;
|
|
299
|
-
financialsSource = "Yahoo Finance";
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const latestFCF = financials[0]?.freeCashFlow ?? 0;
|
|
303
|
-
if (latestFCF <= 0) {
|
|
304
|
-
return {
|
|
305
|
-
content: [
|
|
306
|
-
{
|
|
307
|
-
type: "text",
|
|
308
|
-
text: `${symbol} has negative or zero free cash flow ($${latestFCF.toLocaleString()}). DCF is not meaningful for companies without positive FCF.`,
|
|
309
|
-
},
|
|
310
|
-
],
|
|
311
|
-
details: null,
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// Estimate growth from historical FCF if not provided
|
|
316
|
-
let growthRate = args.growth_rate ?? 0.1;
|
|
317
|
-
if (!args.growth_rate && financials.length >= 2) {
|
|
318
|
-
const olderFCF = financials[1]?.freeCashFlow;
|
|
319
|
-
if (olderFCF && olderFCF > 0) {
|
|
320
|
-
growthRate = Math.max(0.02, Math.min(0.25, (latestFCF - olderFCF) / olderFCF));
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const discountRate = args.discount_rate ?? 0.1;
|
|
325
|
-
const terminalGrowth = args.terminal_growth ?? 0.03;
|
|
326
|
-
if (discountRate <= terminalGrowth) {
|
|
327
|
-
return {
|
|
328
|
-
content: [
|
|
329
|
-
{
|
|
330
|
-
type: "text",
|
|
331
|
-
text: `⚠ Invalid DCF assumptions for ${symbol}: terminal growth (${(terminalGrowth * 100).toFixed(1)}%) must be below the discount rate (${(discountRate * 100).toFixed(1)}%) for the Gordon Growth terminal value to be meaningful. Lower terminal_growth or raise discount_rate.`,
|
|
332
|
-
},
|
|
333
|
-
],
|
|
334
|
-
details: null,
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
const years = args.projection_years ?? 5;
|
|
339
|
-
// Prefer an actual reported share count, then derive from market cap
|
|
340
|
-
// only when needed. Never substitute a placeholder share count.
|
|
341
|
-
const statementSharesOutstanding = financials[0]?.sharesOutstanding;
|
|
342
|
-
let marketCap = quote.marketCap > 0 ? quote.marketCap : 0;
|
|
343
|
-
let sharesOutstanding =
|
|
344
|
-
statementSharesOutstanding && statementSharesOutstanding > 0 ? statementSharesOutstanding : 0;
|
|
345
|
-
if (sharesOutstanding <= 0 && marketCap <= 0) {
|
|
346
|
-
const overviewResult = await optionalAlphaVantage(alphaVantageApiKey, (apiKey) =>
|
|
347
|
-
getOverview(symbol, apiKey),
|
|
348
|
-
);
|
|
349
|
-
if (overviewResult.status === "ok" && overviewResult.data.marketCap > 0) {
|
|
350
|
-
marketCap = overviewResult.data.marketCap;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
if (sharesOutstanding <= 0 && quote.price > 0 && marketCap > 0) {
|
|
354
|
-
sharesOutstanding = marketCap / quote.price;
|
|
355
|
-
}
|
|
356
|
-
if (sharesOutstanding <= 0) {
|
|
357
|
-
return {
|
|
358
|
-
content: [
|
|
359
|
-
{
|
|
360
|
-
type: "text",
|
|
361
|
-
text: `⚠ Cannot compute a per-share DCF for ${symbol}: shares outstanding are unavailable from financial statements and cannot be derived because ${quote.price <= 0 ? "the current quote price is unavailable" : "market capitalization is unavailable from the overview and quote providers"}. Per-share intrinsic value requires a real share count.`,
|
|
362
|
-
},
|
|
363
|
-
],
|
|
364
|
-
details: null,
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
// Signed on purpose: net cash (negative net debt) adds to equity value.
|
|
368
|
-
// Omit the adjustment if debt/cash fields are missing; assets minus
|
|
369
|
-
// liabilities is book equity, not a net-cash proxy.
|
|
370
|
-
const computedNetDebt = financials[0] ? computeNetDebt(financials[0]) : null;
|
|
371
|
-
const netDebt = computedNetDebt ?? 0;
|
|
372
|
-
|
|
373
|
-
const result = computeDCF({
|
|
374
|
-
freeCashFlow: latestFCF,
|
|
375
|
-
growthRate,
|
|
376
|
-
discountRate,
|
|
377
|
-
terminalGrowth,
|
|
378
|
-
years,
|
|
379
|
-
netDebt,
|
|
380
|
-
sharesOutstanding,
|
|
381
|
-
});
|
|
382
|
-
if (computedNetDebt == null) {
|
|
383
|
-
result.warnings.push(
|
|
384
|
-
"Net debt adjustment omitted because total debt and cash equivalents were unavailable.",
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const marginOfSafety = (result.intrinsicValue - quote.price) / result.intrinsicValue;
|
|
389
|
-
const upside = (result.intrinsicValue - quote.price) / quote.price;
|
|
390
|
-
|
|
391
|
-
const lines = [
|
|
392
|
-
`**${symbol} DCF Valuation**`,
|
|
393
|
-
``,
|
|
394
|
-
`Current Price: $${quote.price.toFixed(2)}`,
|
|
395
|
-
`Intrinsic Value: $${result.intrinsicValue.toFixed(2)}`,
|
|
396
|
-
`Margin of Safety: ${(marginOfSafety * 100).toFixed(1)}%`,
|
|
397
|
-
`Upside/Downside: ${upside >= 0 ? "+" : ""}${(upside * 100).toFixed(1)}%`,
|
|
398
|
-
``,
|
|
399
|
-
`**Assumptions**`,
|
|
400
|
-
`Financial statements source: ${financialsSource}`,
|
|
401
|
-
`Free Cash Flow: $${(latestFCF / 1e9).toFixed(2)}B`,
|
|
402
|
-
`Growth Rate: ${(growthRate * 100).toFixed(1)}%`,
|
|
403
|
-
`Discount Rate (WACC): ${(discountRate * 100).toFixed(1)}%`,
|
|
404
|
-
`Terminal Growth: ${(terminalGrowth * 100).toFixed(1)}%`,
|
|
405
|
-
`Projection: ${years} years`,
|
|
406
|
-
``,
|
|
407
|
-
`**Projected Cash Flows**`,
|
|
408
|
-
...result.projectedCashFlows.map(
|
|
409
|
-
(cf) =>
|
|
410
|
-
` Year ${cf.year}: FCF $${(cf.fcf / 1e9).toFixed(2)}B → PV $${(cf.presentValue / 1e9).toFixed(2)}B`,
|
|
411
|
-
),
|
|
412
|
-
` Terminal Value: $${(result.terminalValue / 1e9).toFixed(2)}B`,
|
|
413
|
-
` Enterprise Value: $${(result.enterpriseValue / 1e9).toFixed(2)}B`,
|
|
414
|
-
``,
|
|
415
|
-
`**Sensitivity Table** (Intrinsic Value at different Growth/Discount rates)`,
|
|
416
|
-
...formatSensitivityTable(result.sensitivityTable),
|
|
417
|
-
...(result.warnings.length > 0
|
|
418
|
-
? ["", "**Warnings**", ...result.warnings.map((warning) => `- ${warning}`)]
|
|
419
|
-
: []),
|
|
420
|
-
];
|
|
421
|
-
|
|
422
|
-
return {
|
|
423
|
-
content: [{ type: "text", text: lines.join("\n") }],
|
|
424
|
-
details: { ...result, currentPrice: quote.price, marginOfSafety, upside },
|
|
425
|
-
};
|
|
426
|
-
},
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
function formatSensitivityTable(
|
|
430
|
-
table: Array<{ growthRate: number; discountRate: number; intrinsicValue: number }>,
|
|
431
|
-
): string[] {
|
|
432
|
-
if (table.length === 0) return [" (insufficient data for sensitivity table)"];
|
|
433
|
-
|
|
434
|
-
const discountRates = [...new Set(table.map((e) => e.discountRate))].sort((a, b) => a - b);
|
|
435
|
-
const growthRates = [...new Set(table.map((e) => e.growthRate))].sort((a, b) => a - b);
|
|
436
|
-
|
|
437
|
-
const header = ` ${"Growth↓/WACC→".padEnd(14)} ${discountRates.map((d) => `${(d * 100).toFixed(0)}%`.padStart(8)).join("")}`;
|
|
438
|
-
const rows = growthRates.map((g) => {
|
|
439
|
-
const cells = discountRates.map((d) => {
|
|
440
|
-
const entry = table.find((e) => e.growthRate === g && e.discountRate === d);
|
|
441
|
-
return entry ? `$${entry.intrinsicValue.toFixed(0)}`.padStart(8) : "N/A".padStart(8);
|
|
442
|
-
});
|
|
443
|
-
return ` ${`${(g * 100).toFixed(0)}%`.padEnd(14)} ${cells.join("")}`;
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
return [header, ...rows];
|
|
447
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { Type } from "@sinclair/typebox";
|
|
3
|
-
import { getConfig } from "../../config.js";
|
|
4
|
-
import { withCredentialCheck } from "../../onboarding/tool-helpers.js";
|
|
5
|
-
import { getEarnings } from "../../providers/alpha-vantage.js";
|
|
6
|
-
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
7
|
-
import type { EarningsData } from "../../types/fundamentals.js";
|
|
8
|
-
|
|
9
|
-
const params = Type.Object({
|
|
10
|
-
symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT)" }),
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const earningsTool: AgentTool<
|
|
14
|
-
typeof params,
|
|
15
|
-
EarningsData | { credentialRequired: unknown }
|
|
16
|
-
> = {
|
|
17
|
-
name: "get_earnings",
|
|
18
|
-
label: "Earnings History",
|
|
19
|
-
description:
|
|
20
|
-
"Get quarterly earnings: reported EPS, estimated EPS, and surprise percentage for the last 8 quarters. Requires Alpha Vantage.",
|
|
21
|
-
parameters: params,
|
|
22
|
-
async execute(_toolCallId, args) {
|
|
23
|
-
return withCredentialCheck("alpha_vantage", async () => {
|
|
24
|
-
const apiKey = getConfig().alphaVantageApiKey!;
|
|
25
|
-
const result = await wrapProvider("alphavantage", () =>
|
|
26
|
-
getEarnings(args.symbol.toUpperCase(), apiKey),
|
|
27
|
-
);
|
|
28
|
-
if (result.status === "unavailable") {
|
|
29
|
-
return {
|
|
30
|
-
content: [
|
|
31
|
-
{
|
|
32
|
-
type: "text",
|
|
33
|
-
text: `⚠ Earnings data unavailable for ${args.symbol.toUpperCase()} (${result.reason}). Analysis will proceed without earnings history.`,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
details: null as any,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const earnings = result.data;
|
|
40
|
-
if (earnings.quarterly.length === 0) {
|
|
41
|
-
return {
|
|
42
|
-
content: [{ type: "text", text: `No earnings data found for ${args.symbol}` }],
|
|
43
|
-
details: earnings,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const header = `${args.symbol.toUpperCase()} — Quarterly Earnings (last ${earnings.quarterly.length} quarters)`;
|
|
48
|
-
const rows = earnings.quarterly.map((q) => {
|
|
49
|
-
const sign = q.surprisePercent >= 0 ? "+" : "";
|
|
50
|
-
return `${q.date} | Reported: $${q.reportedEPS.toFixed(2)} | Est: $${q.estimatedEPS.toFixed(2)} | Surprise: ${sign}${q.surprisePercent.toFixed(1)}%`;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const text = [header, ...rows].join("\n");
|
|
54
|
-
return { content: [{ type: "text", text }], details: earnings };
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { Type } from "@sinclair/typebox";
|
|
3
|
-
import { getConfig } from "../../config.js";
|
|
4
|
-
import { withCredentialCheck } from "../../onboarding/tool-helpers.js";
|
|
5
|
-
import { getFinancials } from "../../providers/alpha-vantage.js";
|
|
6
|
-
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
7
|
-
import type { FinancialStatement } from "../../types/fundamentals.js";
|
|
8
|
-
|
|
9
|
-
const params = Type.Object({
|
|
10
|
-
symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT)" }),
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const financialsTool: AgentTool<
|
|
14
|
-
typeof params,
|
|
15
|
-
FinancialStatement[] | { credentialRequired: unknown }
|
|
16
|
-
> = {
|
|
17
|
-
name: "get_financials",
|
|
18
|
-
label: "Financial Statements",
|
|
19
|
-
description:
|
|
20
|
-
"Get annual income statement data: revenue, gross profit, operating income, net income, and EPS. Requires Alpha Vantage.",
|
|
21
|
-
parameters: params,
|
|
22
|
-
async execute(_toolCallId, args) {
|
|
23
|
-
return withCredentialCheck("alpha_vantage", async () => {
|
|
24
|
-
const apiKey = getConfig().alphaVantageApiKey!;
|
|
25
|
-
const result = await wrapProvider("alphavantage", () =>
|
|
26
|
-
getFinancials(args.symbol.toUpperCase(), apiKey),
|
|
27
|
-
);
|
|
28
|
-
if (result.status === "unavailable") {
|
|
29
|
-
return {
|
|
30
|
-
content: [
|
|
31
|
-
{
|
|
32
|
-
type: "text",
|
|
33
|
-
text: `⚠ Financial statements unavailable for ${args.symbol.toUpperCase()} (${result.reason}). Analysis will proceed without financials.`,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
details: [],
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const statements = result.data;
|
|
40
|
-
if (statements.length === 0) {
|
|
41
|
-
return {
|
|
42
|
-
content: [{ type: "text", text: `No financial data found for ${args.symbol}` }],
|
|
43
|
-
details: [],
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const header = `${args.symbol.toUpperCase()} — Annual Income Statement (${statements.length} years)`;
|
|
48
|
-
const rows = statements.map(
|
|
49
|
-
(s) =>
|
|
50
|
-
`${s.fiscalDate} | Rev: $${fmt(s.revenue)} | GP: $${fmt(s.grossProfit)} | OpInc: $${fmt(s.operatingIncome)} | Net: $${fmt(s.netIncome)}`,
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const text = [header, ...rows].join("\n");
|
|
54
|
-
return { content: [{ type: "text", text }], details: statements };
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
function fmt(n: number): string {
|
|
60
|
-
if (n >= 1e9) return `${(n / 1e9).toFixed(2)}B`;
|
|
61
|
-
if (n >= 1e6) return `${(n / 1e6).toFixed(2)}M`;
|
|
62
|
-
return n.toLocaleString();
|
|
63
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { Type } from "@sinclair/typebox";
|
|
3
|
-
import { searchFilings } from "../../providers/sec-edgar.js";
|
|
4
|
-
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
5
|
-
import { renderUntrustedText, untrustedContentHeader } from "../sentiment/untrusted-text.js";
|
|
6
|
-
|
|
7
|
-
const params = Type.Object({
|
|
8
|
-
symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT, TSLA)" }),
|
|
9
|
-
form_types: Type.Optional(
|
|
10
|
-
Type.Array(Type.String(), {
|
|
11
|
-
description:
|
|
12
|
-
"Filing types to search: 10-K (annual), 10-Q (quarterly), 8-K (material events). Default: all three.",
|
|
13
|
-
}),
|
|
14
|
-
),
|
|
15
|
-
limit: Type.Optional(
|
|
16
|
-
Type.Number({ description: "Maximum number of filings to return (default: 10)" }),
|
|
17
|
-
),
|
|
18
|
-
include_snippets: Type.Optional(
|
|
19
|
-
Type.Boolean({
|
|
20
|
-
description:
|
|
21
|
-
"Include short filing-text evidence snippets for risk/MD&A/litigation themes. Default: true.",
|
|
22
|
-
}),
|
|
23
|
-
),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const secFilingsTool: AgentTool<typeof params> = {
|
|
27
|
-
name: "get_sec_filings",
|
|
28
|
-
label: "SEC Filings",
|
|
29
|
-
description:
|
|
30
|
-
"Search SEC EDGAR for company filings (10-K annual reports, 10-Q quarterly reports, 8-K material events). Returns filing dates, types, and direct links to the documents. Free API, no key required.",
|
|
31
|
-
parameters: params,
|
|
32
|
-
async execute(_toolCallId, args) {
|
|
33
|
-
const symbol = args.symbol.toUpperCase();
|
|
34
|
-
const formTypes = args.form_types ?? ["10-K", "10-Q", "8-K"];
|
|
35
|
-
const limit = args.limit ?? 10;
|
|
36
|
-
const includeSnippets = args.include_snippets ?? true;
|
|
37
|
-
|
|
38
|
-
const result = await wrapProvider("sec-edgar", () =>
|
|
39
|
-
searchFilings(symbol, formTypes, limit, { includeSnippets, snippetLimitPerFiling: 2 }),
|
|
40
|
-
);
|
|
41
|
-
if (result.status === "unavailable") {
|
|
42
|
-
return {
|
|
43
|
-
content: [
|
|
44
|
-
{ type: "text", text: `⚠ SEC filings unavailable for ${symbol} (${result.reason}).` },
|
|
45
|
-
],
|
|
46
|
-
details: null,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const filings = result.data;
|
|
50
|
-
|
|
51
|
-
if (filings.length === 0) {
|
|
52
|
-
return {
|
|
53
|
-
content: [
|
|
54
|
-
{
|
|
55
|
-
type: "text",
|
|
56
|
-
text: `No SEC filings found for ${symbol}. Verify the ticker is a US-listed company.`,
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
details: null,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const lines = [
|
|
64
|
-
`**${symbol} SEC Filings** (${filings.length} found)`,
|
|
65
|
-
``,
|
|
66
|
-
...filings.map(
|
|
67
|
-
(f) =>
|
|
68
|
-
` ${f.formType.padEnd(6)} | Filed: ${f.filedDate} | Period: ${f.periodOfReport || "N/A"} | ${f.entityName}`,
|
|
69
|
-
),
|
|
70
|
-
``,
|
|
71
|
-
`Links:`,
|
|
72
|
-
...filings.map((f) => ` ${f.formType} (${f.filedDate}): ${f.url}`),
|
|
73
|
-
``,
|
|
74
|
-
`Primary documents:`,
|
|
75
|
-
...filings.flatMap((f) => [
|
|
76
|
-
` ${f.formType} (${f.filedDate}): ${f.primaryDocumentUrl ?? "N/A"}`,
|
|
77
|
-
...(f.items?.length ? [` 8-K items: ${f.items.join(", ")}`] : []),
|
|
78
|
-
]),
|
|
79
|
-
...(includeSnippets
|
|
80
|
-
? [
|
|
81
|
-
``,
|
|
82
|
-
`Evidence snippets (short excerpts; review source filing for full context):`,
|
|
83
|
-
untrustedContentHeader("SEC filing snippets"),
|
|
84
|
-
...filings.flatMap((f) =>
|
|
85
|
-
f.evidenceWarning
|
|
86
|
-
? [` ${f.formType} ${f.filedDate}: ${f.evidenceWarning}`]
|
|
87
|
-
: f.evidenceSnippets?.length
|
|
88
|
-
? f.evidenceSnippets.map(
|
|
89
|
-
(snippet) =>
|
|
90
|
-
` ${f.formType} ${f.filedDate}: ${renderUntrustedText(snippet, 500)}`,
|
|
91
|
-
)
|
|
92
|
-
: [
|
|
93
|
-
` ${f.formType} ${f.filedDate}: No keyword snippet found in fetched primary document.`,
|
|
94
|
-
],
|
|
95
|
-
),
|
|
96
|
-
]
|
|
97
|
-
: []),
|
|
98
|
-
];
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
content: [{ type: "text", text: lines.join("\n") }],
|
|
102
|
-
details: { symbol, filings },
|
|
103
|
-
};
|
|
104
|
-
},
|
|
105
|
-
};
|