opencandle 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +106 -14
- package/assets/logo.svg +187 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +40 -3
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +25 -0
- package/dist/config.js +72 -0
- package/dist/config.js.map +1 -1
- package/dist/infra/browser.d.ts +11 -3
- package/dist/infra/browser.js +2 -1
- package/dist/infra/browser.js.map +1 -1
- package/dist/infra/native-dependencies.d.ts +1 -0
- package/dist/infra/native-dependencies.js +10 -0
- package/dist/infra/native-dependencies.js.map +1 -0
- package/dist/infra/node-version.d.ts +2 -0
- package/dist/infra/node-version.js +23 -0
- package/dist/infra/node-version.js.map +1 -0
- package/dist/infra/rate-limiter.d.ts +4 -0
- package/dist/infra/rate-limiter.js +5 -1
- package/dist/infra/rate-limiter.js.map +1 -1
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +1 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/manager.d.ts +9 -0
- package/dist/memory/manager.js +28 -11
- package/dist/memory/manager.js.map +1 -1
- package/dist/memory/sqlite.js +42 -4
- package/dist/memory/sqlite.js.map +1 -1
- package/dist/memory/storage.d.ts +7 -0
- package/dist/memory/storage.js +3 -3
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/tool-defaults.d.ts +8 -0
- package/dist/memory/tool-defaults.js +59 -0
- package/dist/memory/tool-defaults.js.map +1 -0
- package/dist/memory/types.js +4 -0
- package/dist/memory/types.js.map +1 -1
- package/dist/onboarding/connect.d.ts +13 -1
- package/dist/onboarding/connect.js +21 -10
- package/dist/onboarding/connect.js.map +1 -1
- package/dist/onboarding/prompt-user.d.ts +1 -1
- package/dist/onboarding/providers.d.ts +7 -0
- package/dist/onboarding/providers.js +6 -3
- package/dist/onboarding/providers.js.map +1 -1
- package/dist/onboarding/tool-helpers.d.ts +1 -1
- package/dist/pi/opencandle-extension.d.ts +7 -1
- package/dist/pi/opencandle-extension.js +391 -21
- package/dist/pi/opencandle-extension.js.map +1 -1
- package/dist/pi/session-storage.d.ts +2 -0
- package/dist/pi/session-storage.js +5 -0
- package/dist/pi/session-storage.js.map +1 -0
- package/dist/pi/session.d.ts +4 -1
- package/dist/pi/session.js +25 -3
- package/dist/pi/session.js.map +1 -1
- package/dist/pi/setup.d.ts +1 -1
- package/dist/pi/setup.js +11 -1
- package/dist/pi/setup.js.map +1 -1
- package/dist/pi/tool-adapter.d.ts +2 -2
- package/dist/pi/tool-adapter.js +14 -1
- package/dist/pi/tool-adapter.js.map +1 -1
- package/dist/prompts/context-builder.d.ts +40 -3
- package/dist/prompts/context-builder.js +140 -19
- package/dist/prompts/context-builder.js.map +1 -1
- package/dist/prompts/disclaimer.d.ts +6 -0
- package/dist/prompts/disclaimer.js +9 -0
- package/dist/prompts/disclaimer.js.map +1 -0
- package/dist/prompts/policy-cards.d.ts +13 -0
- package/dist/prompts/policy-cards.js +197 -0
- package/dist/prompts/policy-cards.js.map +1 -0
- package/dist/prompts/sections.js +3 -3
- package/dist/prompts/sections.js.map +1 -1
- package/dist/prompts/workflow-prompts.d.ts +8 -0
- package/dist/prompts/workflow-prompts.js +208 -22
- package/dist/prompts/workflow-prompts.js.map +1 -1
- package/dist/providers/alpha-vantage.js +23 -1
- package/dist/providers/alpha-vantage.js.map +1 -1
- package/dist/providers/sec-edgar.d.ts +8 -1
- package/dist/providers/sec-edgar.js +172 -5
- package/dist/providers/sec-edgar.js.map +1 -1
- package/dist/providers/yahoo-finance.d.ts +2 -0
- package/dist/providers/yahoo-finance.js +203 -35
- package/dist/providers/yahoo-finance.js.map +1 -1
- package/dist/routing/classify-intent.d.ts +3 -0
- package/dist/routing/classify-intent.js +82 -3
- package/dist/routing/classify-intent.js.map +1 -1
- package/dist/routing/defaults.js +4 -4
- package/dist/routing/defaults.js.map +1 -1
- package/dist/routing/entity-extractor.d.ts +1 -0
- package/dist/routing/entity-extractor.js +158 -12
- package/dist/routing/entity-extractor.js.map +1 -1
- package/dist/routing/index.d.ts +10 -0
- package/dist/routing/index.js +7 -0
- package/dist/routing/index.js.map +1 -1
- package/dist/routing/legacy-rule-router.d.ts +9 -0
- package/dist/routing/legacy-rule-router.js +12 -0
- package/dist/routing/legacy-rule-router.js.map +1 -0
- package/dist/routing/planning.d.ts +54 -0
- package/dist/routing/planning.js +531 -0
- package/dist/routing/planning.js.map +1 -0
- package/dist/routing/route-manifest.d.ts +35 -0
- package/dist/routing/route-manifest.js +221 -0
- package/dist/routing/route-manifest.js.map +1 -0
- package/dist/routing/router-llm-client.d.ts +11 -0
- package/dist/routing/router-llm-client.js +42 -0
- package/dist/routing/router-llm-client.js.map +1 -0
- package/dist/routing/router-prompt.d.ts +2 -0
- package/dist/routing/router-prompt.js +141 -0
- package/dist/routing/router-prompt.js.map +1 -0
- package/dist/routing/router-types.d.ts +71 -0
- package/dist/routing/router-types.js +2 -0
- package/dist/routing/router-types.js.map +1 -0
- package/dist/routing/router.d.ts +11 -0
- package/dist/routing/router.js +638 -0
- package/dist/routing/router.js.map +1 -0
- package/dist/routing/slot-resolver.js +46 -6
- package/dist/routing/slot-resolver.js.map +1 -1
- package/dist/routing/turn-context.d.ts +44 -0
- package/dist/routing/turn-context.js +45 -0
- package/dist/routing/turn-context.js.map +1 -0
- package/dist/routing/types.d.ts +13 -1
- package/dist/runtime/answer-contracts.d.ts +82 -0
- package/dist/runtime/answer-contracts.js +414 -0
- package/dist/runtime/answer-contracts.js.map +1 -0
- package/dist/runtime/artifact-contracts.d.ts +14 -0
- package/dist/runtime/artifact-contracts.js +57 -0
- package/dist/runtime/artifact-contracts.js.map +1 -0
- package/dist/runtime/planning-evidence.d.ts +99 -0
- package/dist/runtime/planning-evidence.js +445 -0
- package/dist/runtime/planning-evidence.js.map +1 -0
- package/dist/runtime/session-coordinator.d.ts +81 -3
- package/dist/runtime/session-coordinator.js +201 -17
- package/dist/runtime/session-coordinator.js.map +1 -1
- package/dist/runtime/tool-defaults-wrapper.d.ts +3 -0
- package/dist/runtime/tool-defaults-wrapper.js +25 -0
- package/dist/runtime/tool-defaults-wrapper.js.map +1 -0
- package/dist/sentiment/store.js +5 -0
- package/dist/sentiment/store.js.map +1 -1
- package/dist/system-prompt.js +23 -12
- package/dist/system-prompt.js.map +1 -1
- package/dist/tool-kit.d.ts +4 -4
- package/dist/tools/fundamentals/company-overview.d.ts +1 -1
- package/dist/tools/fundamentals/company-overview.js +1 -1
- package/dist/tools/fundamentals/company-overview.js.map +1 -1
- package/dist/tools/fundamentals/comps.d.ts +1 -1
- package/dist/tools/fundamentals/comps.js +1 -1
- package/dist/tools/fundamentals/comps.js.map +1 -1
- package/dist/tools/fundamentals/dcf.d.ts +1 -1
- package/dist/tools/fundamentals/dcf.js +1 -1
- package/dist/tools/fundamentals/dcf.js.map +1 -1
- package/dist/tools/fundamentals/earnings.d.ts +1 -1
- package/dist/tools/fundamentals/earnings.js +1 -1
- package/dist/tools/fundamentals/earnings.js.map +1 -1
- package/dist/tools/fundamentals/financials.d.ts +1 -1
- package/dist/tools/fundamentals/financials.js +1 -1
- package/dist/tools/fundamentals/financials.js.map +1 -1
- package/dist/tools/fundamentals/sec-filings.d.ts +2 -1
- package/dist/tools/fundamentals/sec-filings.js +19 -2
- package/dist/tools/fundamentals/sec-filings.js.map +1 -1
- package/dist/tools/index.d.ts +29 -1
- package/dist/tools/index.js +30 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/interaction/ask-user.d.ts +1 -1
- package/dist/tools/interaction/twitter-login.d.ts +1 -1
- package/dist/tools/macro/fear-greed.d.ts +1 -1
- package/dist/tools/macro/fear-greed.js +1 -1
- package/dist/tools/macro/fear-greed.js.map +1 -1
- package/dist/tools/macro/fred-data.d.ts +1 -1
- package/dist/tools/macro/fred-data.js +29 -5
- package/dist/tools/macro/fred-data.js.map +1 -1
- package/dist/tools/market/crypto-history.d.ts +1 -1
- package/dist/tools/market/crypto-history.js +18 -2
- package/dist/tools/market/crypto-history.js.map +1 -1
- package/dist/tools/market/crypto-price.d.ts +1 -1
- package/dist/tools/market/crypto-price.js +1 -1
- package/dist/tools/market/crypto-price.js.map +1 -1
- package/dist/tools/market/search-ticker.d.ts +1 -1
- package/dist/tools/market/search-ticker.js +1 -1
- package/dist/tools/market/search-ticker.js.map +1 -1
- package/dist/tools/market/stock-history.d.ts +1 -1
- package/dist/tools/market/stock-history.js +1 -1
- package/dist/tools/market/stock-history.js.map +1 -1
- package/dist/tools/market/stock-quote.d.ts +1 -1
- package/dist/tools/market/stock-quote.js +1 -1
- package/dist/tools/market/stock-quote.js.map +1 -1
- package/dist/tools/options/greeks.js +0 -1
- package/dist/tools/options/greeks.js.map +1 -1
- package/dist/tools/options/option-chain.d.ts +1 -1
- package/dist/tools/options/option-chain.js +13 -5
- package/dist/tools/options/option-chain.js.map +1 -1
- package/dist/tools/portfolio/correlation.d.ts +1 -1
- package/dist/tools/portfolio/correlation.js +1 -1
- package/dist/tools/portfolio/correlation.js.map +1 -1
- package/dist/tools/portfolio/holdings-overlap.d.ts +8 -0
- package/dist/tools/portfolio/holdings-overlap.js +105 -0
- package/dist/tools/portfolio/holdings-overlap.js.map +1 -0
- package/dist/tools/portfolio/predictions.d.ts +1 -1
- package/dist/tools/portfolio/predictions.js +1 -1
- package/dist/tools/portfolio/predictions.js.map +1 -1
- package/dist/tools/portfolio/risk-analysis.d.ts +1 -1
- package/dist/tools/portfolio/risk-analysis.js +1 -1
- package/dist/tools/portfolio/risk-analysis.js.map +1 -1
- package/dist/tools/portfolio/tracker.d.ts +1 -1
- package/dist/tools/portfolio/tracker.js +1 -1
- package/dist/tools/portfolio/tracker.js.map +1 -1
- package/dist/tools/portfolio/watchlist.d.ts +1 -1
- package/dist/tools/portfolio/watchlist.js +12 -4
- package/dist/tools/portfolio/watchlist.js.map +1 -1
- package/dist/tools/sentiment/reddit-sentiment.d.ts +1 -1
- package/dist/tools/sentiment/reddit-sentiment.js +1 -1
- package/dist/tools/sentiment/reddit-sentiment.js.map +1 -1
- package/dist/tools/sentiment/sentiment-summary.d.ts +1 -1
- package/dist/tools/sentiment/sentiment-summary.js +57 -2
- package/dist/tools/sentiment/sentiment-summary.js.map +1 -1
- package/dist/tools/sentiment/sentiment-trend.d.ts +1 -1
- package/dist/tools/sentiment/twitter-sentiment.d.ts +1 -1
- package/dist/tools/sentiment/twitter-sentiment.js +1 -1
- package/dist/tools/sentiment/twitter-sentiment.js.map +1 -1
- package/dist/tools/sentiment/web-search.d.ts +1 -1
- package/dist/tools/sentiment/web-search.js +32 -3
- package/dist/tools/sentiment/web-search.js.map +1 -1
- package/dist/tools/sentiment/web-sentiment.d.ts +1 -1
- package/dist/tools/sentiment/web-sentiment.js +1 -1
- package/dist/tools/sentiment/web-sentiment.js.map +1 -1
- package/dist/tools/technical/backtest.d.ts +3 -3
- package/dist/tools/technical/backtest.js +41 -27
- package/dist/tools/technical/backtest.js.map +1 -1
- package/dist/tools/technical/indicators.d.ts +1 -1
- package/dist/tools/technical/indicators.js +8 -4
- package/dist/tools/technical/indicators.js.map +1 -1
- package/dist/types/options.d.ts +10 -0
- package/dist/types/portfolio.d.ts +27 -0
- package/dist/workflows/compare-assets.js +38 -2
- package/dist/workflows/compare-assets.js.map +1 -1
- package/dist/workflows/options-screener.js +94 -8
- package/dist/workflows/options-screener.js.map +1 -1
- package/dist/workflows/portfolio-builder.js +9 -5
- package/dist/workflows/portfolio-builder.js.map +1 -1
- package/gui/server/ask-user-bridge.ts +82 -0
- package/gui/server/background-quotes.ts +31 -0
- package/gui/server/chat-event-adapter.ts +142 -0
- package/gui/server/gui-session-manager.ts +5 -0
- package/gui/server/invoke-tool.ts +89 -0
- package/gui/server/live-chat-event-adapter.ts +181 -0
- package/gui/server/model-setup.ts +100 -0
- package/gui/server/package.json +5 -0
- package/gui/server/projector.ts +254 -0
- package/gui/server/prompt-observation.ts +61 -0
- package/gui/server/server.ts +703 -0
- package/gui/server/session-actions.ts +31 -0
- package/gui/server/session-entry-wait.ts +81 -0
- package/gui/server/tool-metadata.ts +88 -0
- package/gui/server/websocket.ts +128 -0
- package/gui/server/writer-lock.ts +118 -0
- package/gui/shared/chat-events.ts +118 -0
- package/gui/shared/event-reducer.ts +186 -0
- package/gui/web/dist/assets/CatalogOverlay-Bmp6Knu7.js +1 -0
- package/gui/web/dist/assets/index-Bxt9QpLX.css +1 -0
- package/gui/web/dist/assets/index-CZ9DHZYy.js +67 -0
- package/gui/web/dist/assets/logo-CWpt6Y2a.svg +187 -0
- package/gui/web/dist/index.html +17 -0
- package/package.json +50 -18
- package/src/analysts/contracts.ts +189 -0
- package/src/analysts/orchestrator.ts +300 -0
- package/src/cli.ts +206 -0
- package/src/config.ts +245 -0
- package/src/index.ts +5 -0
- package/src/infra/browser.ts +111 -0
- package/src/infra/cache.ts +103 -0
- package/src/infra/http-client.ts +68 -0
- package/src/infra/index.ts +18 -0
- package/src/infra/native-dependencies.ts +12 -0
- package/src/infra/node-version.ts +24 -0
- package/src/infra/open-url.ts +28 -0
- package/src/infra/opencandle-paths.ts +64 -0
- package/src/infra/rate-limiter.ts +73 -0
- package/src/memory/index.ts +10 -0
- package/src/memory/manager.ts +192 -0
- package/src/memory/preference-extractor.ts +106 -0
- package/src/memory/retrieval.ts +70 -0
- package/src/memory/sqlite.ts +172 -0
- package/src/memory/storage.ts +205 -0
- package/src/memory/tool-defaults.ts +87 -0
- package/src/memory/types.ts +71 -0
- package/src/onboarding/connect.ts +184 -0
- package/src/onboarding/credential-interceptor.ts +134 -0
- package/src/onboarding/degradation-accumulator.ts +79 -0
- package/src/onboarding/prompt-user.ts +85 -0
- package/src/onboarding/providers.ts +315 -0
- package/src/onboarding/state.ts +218 -0
- package/src/onboarding/tool-helpers.ts +111 -0
- package/src/onboarding/tool-tags.ts +201 -0
- package/src/onboarding/validation.ts +158 -0
- package/src/pi/opencandle-extension.ts +955 -0
- package/src/pi/session-storage.ts +5 -0
- package/src/pi/session.ts +81 -0
- package/src/pi/setup.ts +381 -0
- package/src/pi/tool-adapter.ts +36 -0
- package/src/prompts/context-builder.ts +315 -0
- package/src/prompts/disclaimer.ts +9 -0
- package/src/prompts/policy-cards.ts +220 -0
- package/src/prompts/sections.ts +46 -0
- package/src/prompts/workflow-prompts.ts +433 -0
- package/src/providers/alpha-vantage.ts +315 -0
- package/src/providers/coingecko.ts +96 -0
- package/src/providers/exa-search.ts +373 -0
- package/src/providers/fear-greed.ts +45 -0
- package/src/providers/finnhub.ts +124 -0
- package/src/providers/fred.ts +83 -0
- package/src/providers/index.ts +9 -0
- package/src/providers/provider-credential-error.ts +23 -0
- package/src/providers/reddit.ts +151 -0
- package/src/providers/sec-edgar.ts +312 -0
- package/src/providers/twitter.ts +173 -0
- package/src/providers/web-search.ts +293 -0
- package/src/providers/with-fallback.ts +41 -0
- package/src/providers/wrap-provider.ts +64 -0
- package/src/providers/yahoo-finance.ts +534 -0
- package/src/routing/classify-intent.ts +285 -0
- package/src/routing/defaults.ts +29 -0
- package/src/routing/entity-extractor.ts +291 -0
- package/src/routing/index.ts +70 -0
- package/src/routing/legacy-rule-router.ts +13 -0
- package/src/routing/planning.ts +732 -0
- package/src/routing/route-manifest.ts +287 -0
- package/src/routing/router-llm-client.ts +51 -0
- package/src/routing/router-prompt.ts +163 -0
- package/src/routing/router-types.ts +87 -0
- package/src/routing/router.ts +712 -0
- package/src/routing/slot-resolver.ts +190 -0
- package/src/routing/turn-context.ts +111 -0
- package/src/routing/types.ts +75 -0
- package/src/runtime/answer-contracts.ts +633 -0
- package/src/runtime/artifact-contracts.ts +76 -0
- package/src/runtime/evidence.ts +77 -0
- package/src/runtime/planning-evidence.ts +591 -0
- package/src/runtime/prompt-step.ts +75 -0
- package/src/runtime/provider-tracker.ts +40 -0
- package/src/runtime/run-context.ts +22 -0
- package/src/runtime/session-coordinator.ts +472 -0
- package/src/runtime/tool-defaults-wrapper.ts +35 -0
- package/src/runtime/validation.ts +214 -0
- package/src/runtime/workflow-events.ts +75 -0
- package/src/runtime/workflow-runner.ts +188 -0
- package/src/runtime/workflow-types.ts +102 -0
- package/src/sentiment/adapters/finnhub.ts +44 -0
- package/src/sentiment/adapters/reddit.ts +65 -0
- package/src/sentiment/adapters/twitter.ts +36 -0
- package/src/sentiment/adapters/web.ts +44 -0
- package/src/sentiment/index.ts +58 -0
- package/src/sentiment/keywords.ts +9 -0
- package/src/sentiment/pipeline.ts +68 -0
- package/src/sentiment/scorer.ts +78 -0
- package/src/sentiment/store.ts +260 -0
- package/src/sentiment/trends.ts +90 -0
- package/src/sentiment/types.ts +108 -0
- package/src/system-prompt.ts +118 -0
- package/src/tool-kit.ts +68 -0
- package/src/tools/AGENTS.md +36 -0
- package/src/tools/fundamentals/company-overview.ts +54 -0
- package/src/tools/fundamentals/comps.ts +156 -0
- package/src/tools/fundamentals/dcf.ts +267 -0
- package/src/tools/fundamentals/earnings.ts +47 -0
- package/src/tools/fundamentals/financials.ts +54 -0
- package/src/tools/fundamentals/sec-filings.ts +84 -0
- package/src/tools/index.ts +91 -0
- package/src/tools/interaction/ask-user.ts +81 -0
- package/src/tools/interaction/twitter-login.ts +93 -0
- package/src/tools/macro/fear-greed.ts +41 -0
- package/src/tools/macro/fred-data.ts +80 -0
- package/src/tools/market/crypto-history.ts +67 -0
- package/src/tools/market/crypto-price.ts +53 -0
- package/src/tools/market/search-ticker.ts +53 -0
- package/src/tools/market/stock-history.ts +79 -0
- package/src/tools/market/stock-quote.ts +64 -0
- package/src/tools/options/greeks.ts +81 -0
- package/src/tools/options/option-chain.ts +96 -0
- package/src/tools/portfolio/correlation.ts +162 -0
- package/src/tools/portfolio/holdings-overlap.ts +123 -0
- package/src/tools/portfolio/predictions.ts +253 -0
- package/src/tools/portfolio/risk-analysis.ts +134 -0
- package/src/tools/portfolio/tracker.ts +147 -0
- package/src/tools/portfolio/watchlist.ts +159 -0
- package/src/tools/sentiment/reddit-sentiment.ts +164 -0
- package/src/tools/sentiment/sentiment-summary.ts +316 -0
- package/src/tools/sentiment/sentiment-trend.ts +58 -0
- package/src/tools/sentiment/twitter-sentiment.ts +96 -0
- package/src/tools/sentiment/web-search.ts +183 -0
- package/src/tools/sentiment/web-sentiment.ts +76 -0
- package/src/tools/technical/backtest.ts +267 -0
- package/src/tools/technical/indicators.ts +256 -0
- package/src/types/fundamentals.ts +46 -0
- package/src/types/index.ts +20 -0
- package/src/types/macro.ts +27 -0
- package/src/types/market.ts +43 -0
- package/src/types/options.ts +52 -0
- package/src/types/portfolio.ts +73 -0
- package/src/types/sentiment.ts +70 -0
- package/src/workflows/compare-assets.ts +75 -0
- package/src/workflows/index.ts +4 -0
- package/src/workflows/options-screener.ts +127 -0
- package/src/workflows/portfolio-builder.ts +56 -0
- package/src/workflows/types.ts +4 -0
- package/dist/runtime/index.d.ts +0 -16
- package/dist/runtime/index.js +0 -10
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/provider-ids.d.ts +0 -14
- package/dist/runtime/provider-ids.js +0 -14
- package/dist/runtime/provider-ids.js.map +0 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
3
|
+
import { getOverview, getFinancials } from "../../providers/alpha-vantage.js";
|
|
4
|
+
import { getQuote } from "../../providers/yahoo-finance.js";
|
|
5
|
+
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
6
|
+
import { getConfig } from "../../config.js";
|
|
7
|
+
import { withCredentialCheck } from "../../onboarding/tool-helpers.js";
|
|
8
|
+
import type { FinancialStatement } from "../../types/fundamentals.js";
|
|
9
|
+
|
|
10
|
+
export interface DCFResult {
|
|
11
|
+
intrinsicValue: number;
|
|
12
|
+
enterpriseValue: number;
|
|
13
|
+
terminalValue: number;
|
|
14
|
+
netDebt: number;
|
|
15
|
+
projectedCashFlows: Array<{ year: number; fcf: number; presentValue: number }>;
|
|
16
|
+
assumptions: {
|
|
17
|
+
fcf: number;
|
|
18
|
+
growthRate: number;
|
|
19
|
+
discountRate: number;
|
|
20
|
+
terminalGrowth: number;
|
|
21
|
+
years: number;
|
|
22
|
+
};
|
|
23
|
+
sensitivityTable: Array<{ growthRate: number; discountRate: number; intrinsicValue: number }>;
|
|
24
|
+
warnings: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface DCFParams {
|
|
28
|
+
freeCashFlow: number;
|
|
29
|
+
growthRate: number;
|
|
30
|
+
discountRate: number;
|
|
31
|
+
terminalGrowth: number;
|
|
32
|
+
years: number;
|
|
33
|
+
netDebt: number;
|
|
34
|
+
sharesOutstanding: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function computeDCF(params: DCFParams): DCFResult {
|
|
38
|
+
const { freeCashFlow, growthRate, discountRate, terminalGrowth, years, netDebt, sharesOutstanding } = params;
|
|
39
|
+
|
|
40
|
+
// Project future cash flows (mid-year convention: discount at year-0.5)
|
|
41
|
+
const projectedCashFlows: Array<{ year: number; fcf: number; presentValue: number }> = [];
|
|
42
|
+
for (let y = 1; y <= years; y++) {
|
|
43
|
+
const fcf = freeCashFlow * (1 + growthRate) ** y;
|
|
44
|
+
const pv = fcf / (1 + discountRate) ** (y - 0.5); // mid-year convention
|
|
45
|
+
projectedCashFlows.push({ year: y, fcf, presentValue: pv });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Terminal value (Gordon Growth Model), discounted at full year (end of projection)
|
|
49
|
+
const finalFCF = freeCashFlow * (1 + growthRate) ** years;
|
|
50
|
+
const terminalValue = (finalFCF * (1 + terminalGrowth)) / (discountRate - terminalGrowth);
|
|
51
|
+
const pvTerminal = terminalValue / (1 + discountRate) ** years;
|
|
52
|
+
|
|
53
|
+
// Enterprise value
|
|
54
|
+
const sumPVs = projectedCashFlows.reduce((s, cf) => s + cf.presentValue, 0);
|
|
55
|
+
const enterpriseValue = sumPVs + pvTerminal;
|
|
56
|
+
|
|
57
|
+
// Equity value → per share
|
|
58
|
+
const equityValue = enterpriseValue - netDebt;
|
|
59
|
+
const intrinsicValue = equityValue / sharesOutstanding;
|
|
60
|
+
|
|
61
|
+
// Sensitivity table: vary growth ±2% and discount ±2%
|
|
62
|
+
const sensitivityTable: Array<{ growthRate: number; discountRate: number; intrinsicValue: number }> = [];
|
|
63
|
+
for (let gDelta = -0.02; gDelta <= 0.02; gDelta += 0.01) {
|
|
64
|
+
for (let dDelta = -0.02; dDelta <= 0.02; dDelta += 0.01) {
|
|
65
|
+
const g = growthRate + gDelta;
|
|
66
|
+
const d = discountRate + dDelta;
|
|
67
|
+
if (d <= terminalGrowth || d <= 0 || g < 0) continue;
|
|
68
|
+
const sensResult = computeDCFSimple(freeCashFlow, g, d, terminalGrowth, years, netDebt, sharesOutstanding);
|
|
69
|
+
sensitivityTable.push({ growthRate: g, discountRate: d, intrinsicValue: sensResult });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Validation warnings (inspired by Anthropic financial plugins + Dexter)
|
|
74
|
+
const warnings: string[] = [];
|
|
75
|
+
const tvPctOfEV = pvTerminal / enterpriseValue;
|
|
76
|
+
if (tvPctOfEV > 0.85) {
|
|
77
|
+
warnings.push(`Terminal value is ${(tvPctOfEV * 100).toFixed(0)}% of enterprise value (typical: 40-80%). The valuation is heavily dependent on terminal assumptions.`);
|
|
78
|
+
}
|
|
79
|
+
const spreadPct = discountRate - terminalGrowth;
|
|
80
|
+
if (spreadPct < 0.02) {
|
|
81
|
+
warnings.push(`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.`);
|
|
82
|
+
}
|
|
83
|
+
if (discountRate < 0.05 || discountRate > 0.20) {
|
|
84
|
+
warnings.push(`Discount rate of ${(discountRate * 100).toFixed(1)}% is outside typical WACC range (5-20%).`);
|
|
85
|
+
}
|
|
86
|
+
if (growthRate > 0.20) {
|
|
87
|
+
warnings.push(`Growth rate of ${(growthRate * 100).toFixed(1)}% exceeds 20%. High growth is difficult to sustain — consider a multi-stage model.`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
intrinsicValue,
|
|
92
|
+
enterpriseValue,
|
|
93
|
+
terminalValue,
|
|
94
|
+
netDebt,
|
|
95
|
+
projectedCashFlows,
|
|
96
|
+
assumptions: {
|
|
97
|
+
fcf: freeCashFlow,
|
|
98
|
+
growthRate,
|
|
99
|
+
discountRate,
|
|
100
|
+
terminalGrowth,
|
|
101
|
+
years,
|
|
102
|
+
},
|
|
103
|
+
sensitivityTable,
|
|
104
|
+
warnings,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function computeDCFSimple(
|
|
109
|
+
fcf: number, g: number, d: number, tg: number, years: number, debt: number, shares: number,
|
|
110
|
+
): number {
|
|
111
|
+
let sumPV = 0;
|
|
112
|
+
for (let y = 1; y <= years; y++) {
|
|
113
|
+
sumPV += (fcf * (1 + g) ** y) / (1 + d) ** (y - 0.5); // mid-year convention
|
|
114
|
+
}
|
|
115
|
+
const finalFCF = fcf * (1 + g) ** years;
|
|
116
|
+
const tv = (finalFCF * (1 + tg)) / (d - tg);
|
|
117
|
+
const pvTV = tv / (1 + d) ** years;
|
|
118
|
+
return (sumPV + pvTV - debt) / shares;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function computeNetDebt(f: FinancialStatement): number {
|
|
122
|
+
if (f.totalDebt != null && f.cashAndEquivalents != null) {
|
|
123
|
+
return f.totalDebt - f.cashAndEquivalents;
|
|
124
|
+
}
|
|
125
|
+
// Fallback: totalLiabilities - totalAssets (negative means net cash position)
|
|
126
|
+
return f.totalLiabilities - f.totalAssets;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const params = Type.Object({
|
|
130
|
+
symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT)" }),
|
|
131
|
+
growth_rate: Type.Optional(
|
|
132
|
+
Type.Number({ description: "Annual FCF growth rate as decimal (e.g. 0.10 for 10%). If omitted, estimated from historical data." }),
|
|
133
|
+
),
|
|
134
|
+
discount_rate: Type.Optional(
|
|
135
|
+
Type.Number({ description: "Discount rate / WACC as decimal (default: 0.10 for 10%)" }),
|
|
136
|
+
),
|
|
137
|
+
terminal_growth: Type.Optional(
|
|
138
|
+
Type.Number({ description: "Terminal growth rate as decimal (default: 0.03 for 3%)" }),
|
|
139
|
+
),
|
|
140
|
+
projection_years: Type.Optional(
|
|
141
|
+
Type.Number({ description: "Years to project forward (default: 5)" }),
|
|
142
|
+
),
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
export const dcfTool: AgentTool<typeof params> = {
|
|
146
|
+
name: "compute_dcf",
|
|
147
|
+
label: "DCF Valuation",
|
|
148
|
+
description:
|
|
149
|
+
"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.",
|
|
150
|
+
parameters: params,
|
|
151
|
+
async execute(_toolCallId, args) {
|
|
152
|
+
return withCredentialCheck("alpha_vantage", async () => {
|
|
153
|
+
const symbol = args.symbol.toUpperCase();
|
|
154
|
+
const config = getConfig();
|
|
155
|
+
|
|
156
|
+
const [overviewResult, financialsResult, quoteResult] = await Promise.all([
|
|
157
|
+
wrapProvider("alphavantage", () => getOverview(symbol, config.alphaVantageApiKey!)),
|
|
158
|
+
wrapProvider("alphavantage", () => getFinancials(symbol, config.alphaVantageApiKey!)),
|
|
159
|
+
wrapProvider("yahoo", () => getQuote(symbol)),
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
const missing: string[] = [];
|
|
163
|
+
if (overviewResult.status === "unavailable") missing.push(`company overview (${overviewResult.reason})`);
|
|
164
|
+
if (financialsResult.status === "unavailable") missing.push(`financial statements (${financialsResult.reason})`);
|
|
165
|
+
if (quoteResult.status === "unavailable") missing.push(`stock quote (${quoteResult.reason})`);
|
|
166
|
+
|
|
167
|
+
if (financialsResult.status === "unavailable" || quoteResult.status === "unavailable") {
|
|
168
|
+
return {
|
|
169
|
+
content: [{ type: "text", text: `⚠ DCF valuation unavailable for ${symbol}. Missing: ${missing.join(", ")}. Both financials and current price are required.` }],
|
|
170
|
+
details: null,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const overview = overviewResult.status === "ok" ? overviewResult.data : null;
|
|
175
|
+
const financials = financialsResult.data;
|
|
176
|
+
const quote = quoteResult.data;
|
|
177
|
+
|
|
178
|
+
const latestFCF = financials[0]?.freeCashFlow ?? 0;
|
|
179
|
+
if (latestFCF <= 0) {
|
|
180
|
+
return {
|
|
181
|
+
content: [{ type: "text", text: `${symbol} has negative or zero free cash flow ($${latestFCF.toLocaleString()}). DCF is not meaningful for companies without positive FCF.` }],
|
|
182
|
+
details: null,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Estimate growth from historical FCF if not provided
|
|
187
|
+
let growthRate = args.growth_rate ?? 0.10;
|
|
188
|
+
if (!args.growth_rate && financials.length >= 2) {
|
|
189
|
+
const olderFCF = financials[1]?.freeCashFlow;
|
|
190
|
+
if (olderFCF && olderFCF > 0) {
|
|
191
|
+
growthRate = Math.max(0.02, Math.min(0.25, (latestFCF - olderFCF) / olderFCF));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const discountRate = args.discount_rate ?? 0.10;
|
|
196
|
+
const terminalGrowth = args.terminal_growth ?? 0.03;
|
|
197
|
+
const years = args.projection_years ?? 5;
|
|
198
|
+
const marketCap = overview?.marketCap ?? 0;
|
|
199
|
+
const sharesOutstanding = quote.price > 0 && marketCap > 0 ? marketCap / quote.price : 1;
|
|
200
|
+
const netDebt = financials[0] ? computeNetDebt(financials[0]) : 0;
|
|
201
|
+
|
|
202
|
+
const result = computeDCF({
|
|
203
|
+
freeCashFlow: latestFCF,
|
|
204
|
+
growthRate,
|
|
205
|
+
discountRate,
|
|
206
|
+
terminalGrowth,
|
|
207
|
+
years,
|
|
208
|
+
netDebt: Math.max(0, netDebt),
|
|
209
|
+
sharesOutstanding,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const marginOfSafety = (result.intrinsicValue - quote.price) / result.intrinsicValue;
|
|
213
|
+
const upside = (result.intrinsicValue - quote.price) / quote.price;
|
|
214
|
+
|
|
215
|
+
const lines = [
|
|
216
|
+
`**${symbol} DCF Valuation**`,
|
|
217
|
+
``,
|
|
218
|
+
`Current Price: $${quote.price.toFixed(2)}`,
|
|
219
|
+
`Intrinsic Value: $${result.intrinsicValue.toFixed(2)}`,
|
|
220
|
+
`Margin of Safety: ${(marginOfSafety * 100).toFixed(1)}%`,
|
|
221
|
+
`Upside/Downside: ${upside >= 0 ? "+" : ""}${(upside * 100).toFixed(1)}%`,
|
|
222
|
+
``,
|
|
223
|
+
`**Assumptions**`,
|
|
224
|
+
`Free Cash Flow: $${(latestFCF / 1e9).toFixed(2)}B`,
|
|
225
|
+
`Growth Rate: ${(growthRate * 100).toFixed(1)}%`,
|
|
226
|
+
`Discount Rate (WACC): ${(discountRate * 100).toFixed(1)}%`,
|
|
227
|
+
`Terminal Growth: ${(terminalGrowth * 100).toFixed(1)}%`,
|
|
228
|
+
`Projection: ${years} years`,
|
|
229
|
+
``,
|
|
230
|
+
`**Projected Cash Flows**`,
|
|
231
|
+
...result.projectedCashFlows.map((cf) =>
|
|
232
|
+
` Year ${cf.year}: FCF $${(cf.fcf / 1e9).toFixed(2)}B → PV $${(cf.presentValue / 1e9).toFixed(2)}B`
|
|
233
|
+
),
|
|
234
|
+
` Terminal Value: $${(result.terminalValue / 1e9).toFixed(2)}B`,
|
|
235
|
+
` Enterprise Value: $${(result.enterpriseValue / 1e9).toFixed(2)}B`,
|
|
236
|
+
``,
|
|
237
|
+
`**Sensitivity Table** (Intrinsic Value at different Growth/Discount rates)`,
|
|
238
|
+
...formatSensitivityTable(result.sensitivityTable),
|
|
239
|
+
];
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
content: [{ type: "text", text: lines.join("\n") }],
|
|
243
|
+
details: { ...result, currentPrice: quote.price, marginOfSafety, upside },
|
|
244
|
+
};
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
function formatSensitivityTable(
|
|
250
|
+
table: Array<{ growthRate: number; discountRate: number; intrinsicValue: number }>,
|
|
251
|
+
): string[] {
|
|
252
|
+
if (table.length === 0) return [" (insufficient data for sensitivity table)"];
|
|
253
|
+
|
|
254
|
+
const discountRates = [...new Set(table.map((e) => e.discountRate))].sort((a, b) => a - b);
|
|
255
|
+
const growthRates = [...new Set(table.map((e) => e.growthRate))].sort((a, b) => a - b);
|
|
256
|
+
|
|
257
|
+
const header = ` ${"Growth↓/WACC→".padEnd(14)} ${discountRates.map((d) => `${(d * 100).toFixed(0)}%`.padStart(8)).join("")}`;
|
|
258
|
+
const rows = growthRates.map((g) => {
|
|
259
|
+
const cells = discountRates.map((d) => {
|
|
260
|
+
const entry = table.find((e) => e.growthRate === g && e.discountRate === d);
|
|
261
|
+
return entry ? `$${entry.intrinsicValue.toFixed(0)}`.padStart(8) : "N/A".padStart(8);
|
|
262
|
+
});
|
|
263
|
+
return ` ${`${(g * 100).toFixed(0)}%`.padEnd(14)} ${cells.join("")}`;
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
return [header, ...rows];
|
|
267
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
3
|
+
import { getEarnings } from "../../providers/alpha-vantage.js";
|
|
4
|
+
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
5
|
+
import { getConfig } from "../../config.js";
|
|
6
|
+
import { withCredentialCheck } from "../../onboarding/tool-helpers.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<typeof params, EarningsData | { credentialRequired: unknown }> = {
|
|
14
|
+
name: "get_earnings",
|
|
15
|
+
label: "Earnings History",
|
|
16
|
+
description:
|
|
17
|
+
"Get quarterly earnings: reported EPS, estimated EPS, and surprise percentage for the last 8 quarters. Requires Alpha Vantage.",
|
|
18
|
+
parameters: params,
|
|
19
|
+
async execute(_toolCallId, args) {
|
|
20
|
+
return withCredentialCheck("alpha_vantage", async () => {
|
|
21
|
+
const apiKey = getConfig().alphaVantageApiKey!;
|
|
22
|
+
const result = await wrapProvider("alphavantage", () => getEarnings(args.symbol.toUpperCase(), apiKey));
|
|
23
|
+
if (result.status === "unavailable") {
|
|
24
|
+
return {
|
|
25
|
+
content: [{ type: "text", text: `⚠ Earnings data unavailable for ${args.symbol.toUpperCase()} (${result.reason}). Analysis will proceed without earnings history.` }],
|
|
26
|
+
details: null as any,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const earnings = result.data;
|
|
30
|
+
if (earnings.quarterly.length === 0) {
|
|
31
|
+
return {
|
|
32
|
+
content: [{ type: "text", text: `No earnings data found for ${args.symbol}` }],
|
|
33
|
+
details: earnings,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const header = `${args.symbol.toUpperCase()} — Quarterly Earnings (last ${earnings.quarterly.length} quarters)`;
|
|
38
|
+
const rows = earnings.quarterly.map((q) => {
|
|
39
|
+
const sign = q.surprisePercent >= 0 ? "+" : "";
|
|
40
|
+
return `${q.date} | Reported: $${q.reportedEPS.toFixed(2)} | Est: $${q.estimatedEPS.toFixed(2)} | Surprise: ${sign}${q.surprisePercent.toFixed(1)}%`;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const text = [header, ...rows].join("\n");
|
|
44
|
+
return { content: [{ type: "text", text }], details: earnings };
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
3
|
+
import { getFinancials } from "../../providers/alpha-vantage.js";
|
|
4
|
+
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
5
|
+
import { getConfig } from "../../config.js";
|
|
6
|
+
import { withCredentialCheck } from "../../onboarding/tool-helpers.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<typeof params, FinancialStatement[] | { credentialRequired: unknown }> = {
|
|
14
|
+
name: "get_financials",
|
|
15
|
+
label: "Financial Statements",
|
|
16
|
+
description:
|
|
17
|
+
"Get annual income statement data: revenue, gross profit, operating income, net income, and EPS. Requires Alpha Vantage.",
|
|
18
|
+
parameters: params,
|
|
19
|
+
async execute(_toolCallId, args) {
|
|
20
|
+
return withCredentialCheck("alpha_vantage", async () => {
|
|
21
|
+
const apiKey = getConfig().alphaVantageApiKey!;
|
|
22
|
+
const result = await wrapProvider("alphavantage", () =>
|
|
23
|
+
getFinancials(args.symbol.toUpperCase(), apiKey),
|
|
24
|
+
);
|
|
25
|
+
if (result.status === "unavailable") {
|
|
26
|
+
return {
|
|
27
|
+
content: [{ type: "text", text: `⚠ Financial statements unavailable for ${args.symbol.toUpperCase()} (${result.reason}). Analysis will proceed without financials.` }],
|
|
28
|
+
details: [],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const statements = result.data;
|
|
32
|
+
if (statements.length === 0) {
|
|
33
|
+
return {
|
|
34
|
+
content: [{ type: "text", text: `No financial data found for ${args.symbol}` }],
|
|
35
|
+
details: [],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const header = `${args.symbol.toUpperCase()} — Annual Income Statement (${statements.length} years)`;
|
|
40
|
+
const rows = statements.map((s) =>
|
|
41
|
+
`${s.fiscalDate} | Rev: $${fmt(s.revenue)} | GP: $${fmt(s.grossProfit)} | OpInc: $${fmt(s.operatingIncome)} | Net: $${fmt(s.netIncome)}`,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const text = [header, ...rows].join("\n");
|
|
45
|
+
return { content: [{ type: "text", text }], details: statements };
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function fmt(n: number): string {
|
|
51
|
+
if (n >= 1e9) return `${(n / 1e9).toFixed(2)}B`;
|
|
52
|
+
if (n >= 1e6) return `${(n / 1e6).toFixed(2)}M`;
|
|
53
|
+
return n.toLocaleString();
|
|
54
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
3
|
+
import { searchFilings } from "../../providers/sec-edgar.js";
|
|
4
|
+
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
5
|
+
|
|
6
|
+
const params = Type.Object({
|
|
7
|
+
symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT, TSLA)" }),
|
|
8
|
+
form_types: Type.Optional(
|
|
9
|
+
Type.Array(Type.String(), {
|
|
10
|
+
description: "Filing types to search: 10-K (annual), 10-Q (quarterly), 8-K (material events). Default: all three.",
|
|
11
|
+
}),
|
|
12
|
+
),
|
|
13
|
+
limit: Type.Optional(
|
|
14
|
+
Type.Number({ description: "Maximum number of filings to return (default: 10)" }),
|
|
15
|
+
),
|
|
16
|
+
include_snippets: Type.Optional(
|
|
17
|
+
Type.Boolean({ description: "Include short filing-text evidence snippets for risk/MD&A/litigation themes. Default: true." }),
|
|
18
|
+
),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const secFilingsTool: AgentTool<typeof params> = {
|
|
22
|
+
name: "get_sec_filings",
|
|
23
|
+
label: "SEC Filings",
|
|
24
|
+
description:
|
|
25
|
+
"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.",
|
|
26
|
+
parameters: params,
|
|
27
|
+
async execute(_toolCallId, args) {
|
|
28
|
+
const symbol = args.symbol.toUpperCase();
|
|
29
|
+
const formTypes = args.form_types ?? ["10-K", "10-Q", "8-K"];
|
|
30
|
+
const limit = args.limit ?? 10;
|
|
31
|
+
const includeSnippets = args.include_snippets ?? true;
|
|
32
|
+
|
|
33
|
+
const result = await wrapProvider("sec-edgar", () =>
|
|
34
|
+
searchFilings(symbol, formTypes, limit, { includeSnippets, snippetLimitPerFiling: 2 })
|
|
35
|
+
);
|
|
36
|
+
if (result.status === "unavailable") {
|
|
37
|
+
return {
|
|
38
|
+
content: [{ type: "text", text: `⚠ SEC filings unavailable for ${symbol} (${result.reason}).` }],
|
|
39
|
+
details: null,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const filings = result.data;
|
|
43
|
+
|
|
44
|
+
if (filings.length === 0) {
|
|
45
|
+
return {
|
|
46
|
+
content: [{ type: "text", text: `No SEC filings found for ${symbol}. Verify the ticker is a US-listed company.` }],
|
|
47
|
+
details: null,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const lines = [
|
|
52
|
+
`**${symbol} SEC Filings** (${filings.length} found)`,
|
|
53
|
+
``,
|
|
54
|
+
...filings.map((f) =>
|
|
55
|
+
` ${f.formType.padEnd(6)} | Filed: ${f.filedDate} | Period: ${f.periodOfReport || "N/A"} | ${f.entityName}`
|
|
56
|
+
),
|
|
57
|
+
``,
|
|
58
|
+
`Links:`,
|
|
59
|
+
...filings.map((f) => ` ${f.formType} (${f.filedDate}): ${f.url}`),
|
|
60
|
+
``,
|
|
61
|
+
`Primary documents:`,
|
|
62
|
+
...filings.flatMap((f) => [
|
|
63
|
+
` ${f.formType} (${f.filedDate}): ${f.primaryDocumentUrl ?? "N/A"}`,
|
|
64
|
+
...(f.items?.length ? [` 8-K items: ${f.items.join(", ")}`] : []),
|
|
65
|
+
]),
|
|
66
|
+
...(includeSnippets
|
|
67
|
+
? [
|
|
68
|
+
``,
|
|
69
|
+
`Evidence snippets (short excerpts; review source filing for full context):`,
|
|
70
|
+
...filings.flatMap((f) =>
|
|
71
|
+
(f.evidenceSnippets?.length
|
|
72
|
+
? f.evidenceSnippets.map((snippet) => ` ${f.formType} ${f.filedDate}: ${snippet}`)
|
|
73
|
+
: [` ${f.formType} ${f.filedDate}: No keyword snippet found in fetched primary document.`])
|
|
74
|
+
),
|
|
75
|
+
]
|
|
76
|
+
: []),
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
content: [{ type: "text", text: lines.join("\n") }],
|
|
81
|
+
details: { symbol, filings },
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import { stockQuoteTool } from "./market/stock-quote.js";
|
|
3
|
+
import { stockHistoryTool } from "./market/stock-history.js";
|
|
4
|
+
import { cryptoPriceTool } from "./market/crypto-price.js";
|
|
5
|
+
import { cryptoHistoryTool } from "./market/crypto-history.js";
|
|
6
|
+
import { searchTickerTool } from "./market/search-ticker.js";
|
|
7
|
+
import { companyOverviewTool } from "./fundamentals/company-overview.js";
|
|
8
|
+
import { financialsTool } from "./fundamentals/financials.js";
|
|
9
|
+
import { earningsTool } from "./fundamentals/earnings.js";
|
|
10
|
+
import { fredDataTool } from "./macro/fred-data.js";
|
|
11
|
+
import { fearGreedTool } from "./macro/fear-greed.js";
|
|
12
|
+
import { redditSentimentTool } from "./sentiment/reddit-sentiment.js";
|
|
13
|
+
import { twitterSentimentTool } from "./sentiment/twitter-sentiment.js";
|
|
14
|
+
import { technicalIndicatorsTool } from "./technical/indicators.js";
|
|
15
|
+
import { portfolioTrackerTool } from "./portfolio/tracker.js";
|
|
16
|
+
import { riskAnalysisTool } from "./portfolio/risk-analysis.js";
|
|
17
|
+
import { watchlistTool } from "./portfolio/watchlist.js";
|
|
18
|
+
import { correlationTool } from "./portfolio/correlation.js";
|
|
19
|
+
import { holdingsOverlapTool } from "./portfolio/holdings-overlap.js";
|
|
20
|
+
import { optionChainTool } from "./options/option-chain.js";
|
|
21
|
+
import { dcfTool } from "./fundamentals/dcf.js";
|
|
22
|
+
import { compsTool } from "./fundamentals/comps.js";
|
|
23
|
+
import { secFilingsTool } from "./fundamentals/sec-filings.js";
|
|
24
|
+
import { backtestTool } from "./technical/backtest.js";
|
|
25
|
+
import { predictionsTool } from "./portfolio/predictions.js";
|
|
26
|
+
import { webSearchTool } from "./sentiment/web-search.js";
|
|
27
|
+
import { webSentimentTool } from "./sentiment/web-sentiment.js";
|
|
28
|
+
import { sentimentTrendTool } from "./sentiment/sentiment-trend.js";
|
|
29
|
+
import { sentimentSummaryTool } from "./sentiment/sentiment-summary.js";
|
|
30
|
+
|
|
31
|
+
export { stockQuoteTool } from "./market/stock-quote.js";
|
|
32
|
+
export { stockHistoryTool } from "./market/stock-history.js";
|
|
33
|
+
export { cryptoPriceTool } from "./market/crypto-price.js";
|
|
34
|
+
export { cryptoHistoryTool } from "./market/crypto-history.js";
|
|
35
|
+
export { searchTickerTool } from "./market/search-ticker.js";
|
|
36
|
+
export { companyOverviewTool } from "./fundamentals/company-overview.js";
|
|
37
|
+
export { financialsTool } from "./fundamentals/financials.js";
|
|
38
|
+
export { earningsTool } from "./fundamentals/earnings.js";
|
|
39
|
+
export { dcfTool } from "./fundamentals/dcf.js";
|
|
40
|
+
export { compsTool } from "./fundamentals/comps.js";
|
|
41
|
+
export { secFilingsTool } from "./fundamentals/sec-filings.js";
|
|
42
|
+
export { fredDataTool } from "./macro/fred-data.js";
|
|
43
|
+
export { fearGreedTool } from "./macro/fear-greed.js";
|
|
44
|
+
export { redditSentimentTool } from "./sentiment/reddit-sentiment.js";
|
|
45
|
+
export { twitterSentimentTool } from "./sentiment/twitter-sentiment.js";
|
|
46
|
+
export { webSearchTool } from "./sentiment/web-search.js";
|
|
47
|
+
export { webSentimentTool } from "./sentiment/web-sentiment.js";
|
|
48
|
+
export { sentimentTrendTool } from "./sentiment/sentiment-trend.js";
|
|
49
|
+
export { sentimentSummaryTool } from "./sentiment/sentiment-summary.js";
|
|
50
|
+
export { technicalIndicatorsTool } from "./technical/indicators.js";
|
|
51
|
+
export { backtestTool } from "./technical/backtest.js";
|
|
52
|
+
export { portfolioTrackerTool } from "./portfolio/tracker.js";
|
|
53
|
+
export { riskAnalysisTool } from "./portfolio/risk-analysis.js";
|
|
54
|
+
export { watchlistTool } from "./portfolio/watchlist.js";
|
|
55
|
+
export { correlationTool } from "./portfolio/correlation.js";
|
|
56
|
+
export { holdingsOverlapTool } from "./portfolio/holdings-overlap.js";
|
|
57
|
+
export { predictionsTool } from "./portfolio/predictions.js";
|
|
58
|
+
export { optionChainTool } from "./options/option-chain.js";
|
|
59
|
+
|
|
60
|
+
export function getAllTools(): AgentTool<any>[] {
|
|
61
|
+
return [
|
|
62
|
+
searchTickerTool,
|
|
63
|
+
stockQuoteTool,
|
|
64
|
+
stockHistoryTool,
|
|
65
|
+
cryptoPriceTool,
|
|
66
|
+
cryptoHistoryTool,
|
|
67
|
+
companyOverviewTool,
|
|
68
|
+
financialsTool,
|
|
69
|
+
earningsTool,
|
|
70
|
+
dcfTool,
|
|
71
|
+
compsTool,
|
|
72
|
+
secFilingsTool,
|
|
73
|
+
fredDataTool,
|
|
74
|
+
fearGreedTool,
|
|
75
|
+
redditSentimentTool,
|
|
76
|
+
twitterSentimentTool,
|
|
77
|
+
technicalIndicatorsTool,
|
|
78
|
+
backtestTool,
|
|
79
|
+
portfolioTrackerTool,
|
|
80
|
+
riskAnalysisTool,
|
|
81
|
+
watchlistTool,
|
|
82
|
+
correlationTool,
|
|
83
|
+
holdingsOverlapTool,
|
|
84
|
+
predictionsTool,
|
|
85
|
+
optionChainTool,
|
|
86
|
+
webSearchTool,
|
|
87
|
+
webSentimentTool,
|
|
88
|
+
sentimentTrendTool,
|
|
89
|
+
sentimentSummaryTool,
|
|
90
|
+
];
|
|
91
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { promptUser } from "../../onboarding/prompt-user.js";
|
|
4
|
+
import type { AskUserHandler } from "../../types/index.js";
|
|
5
|
+
|
|
6
|
+
interface AskUserDetails {
|
|
7
|
+
question: string;
|
|
8
|
+
questionType: string;
|
|
9
|
+
answer: string | null;
|
|
10
|
+
cancelled: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const AskUserParams = Type.Object({
|
|
14
|
+
question: Type.String({ description: "The question to ask the user" }),
|
|
15
|
+
question_type: Type.Union(
|
|
16
|
+
[Type.Literal("select"), Type.Literal("text"), Type.Literal("confirm")],
|
|
17
|
+
{ description: "Type of answer expected: select (pick from options), text (free input), or confirm (yes/no)" },
|
|
18
|
+
),
|
|
19
|
+
options: Type.Optional(
|
|
20
|
+
Type.Array(Type.String(), { description: "Choices for select-type questions" }),
|
|
21
|
+
),
|
|
22
|
+
placeholder: Type.Optional(
|
|
23
|
+
Type.String({ description: "Hint text for text input" }),
|
|
24
|
+
),
|
|
25
|
+
reason: Type.Optional(
|
|
26
|
+
Type.String({ description: "Brief context for why this clarification is needed" }),
|
|
27
|
+
),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export function registerAskUserTool(pi: ExtensionAPI, askUserHandler?: AskUserHandler): void {
|
|
31
|
+
pi.registerTool({
|
|
32
|
+
name: "ask_user",
|
|
33
|
+
label: "Ask User",
|
|
34
|
+
description:
|
|
35
|
+
"Ask the user a clarification question when their request is ambiguous or missing key details. Use select for multiple-choice, text for free input, or confirm for yes/no.",
|
|
36
|
+
promptSnippet:
|
|
37
|
+
"ask_user: Ask the user a clarification question when their request is ambiguous or missing key details",
|
|
38
|
+
parameters: AskUserParams,
|
|
39
|
+
|
|
40
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
41
|
+
const { question, question_type: questionType } = params;
|
|
42
|
+
|
|
43
|
+
// Preserve the pre-refactor error message for the specific misuse case
|
|
44
|
+
// where the model asks a select question with no options — this is a
|
|
45
|
+
// model/caller bug, not a cancellation.
|
|
46
|
+
if (questionType === "select" && (!params.options || params.options.length === 0)) {
|
|
47
|
+
return {
|
|
48
|
+
content: [{ type: "text", text: "Error: No options provided for select question. Provide options or use text type instead." }],
|
|
49
|
+
details: { question, questionType, answer: null, cancelled: true } as AskUserDetails,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const result = await promptUser(
|
|
54
|
+
ctx!,
|
|
55
|
+
{
|
|
56
|
+
question,
|
|
57
|
+
questionType,
|
|
58
|
+
options: params.options,
|
|
59
|
+
placeholder: params.placeholder,
|
|
60
|
+
reason: params.reason,
|
|
61
|
+
},
|
|
62
|
+
askUserHandler,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
if (result.cancelled) {
|
|
66
|
+
const text = !askUserHandler && !ctx?.hasUI
|
|
67
|
+
? "UI not available (non-interactive mode). Proceed with your best judgment and clearly disclose your assumption."
|
|
68
|
+
: "User cancelled the selection. Proceed with your best judgment and disclose your assumption.";
|
|
69
|
+
return {
|
|
70
|
+
content: [{ type: "text", text }],
|
|
71
|
+
details: { question, questionType, answer: null, cancelled: true } as AskUserDetails,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
content: [{ type: "text", text: `User answered: ${result.answer}` }],
|
|
77
|
+
details: { question, questionType, answer: result.answer, cancelled: false } as AskUserDetails,
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|