opencandle 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -87
- package/assets/logo.svg +187 -0
- package/dist/analysts/orchestrator.js +1 -2
- package/dist/analysts/orchestrator.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +38 -2
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +34 -5
- package/dist/config.js +29 -8
- package/dist/config.js.map +1 -1
- package/dist/infra/browser.d.ts +10 -0
- package/dist/infra/browser.js +1 -0
- package/dist/infra/browser.js.map +1 -1
- package/dist/infra/cache.d.ts +4 -0
- package/dist/infra/cache.js +4 -0
- package/dist/infra/cache.js.map +1 -1
- package/dist/infra/native-dependencies.d.ts +1 -0
- package/dist/infra/native-dependencies.js +10 -0
- package/dist/infra/native-dependencies.js.map +1 -0
- package/dist/infra/node-version.d.ts +2 -0
- package/dist/infra/node-version.js +23 -0
- package/dist/infra/node-version.js.map +1 -0
- package/dist/infra/rate-limiter.js +6 -0
- package/dist/infra/rate-limiter.js.map +1 -1
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +1 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/sqlite.js +42 -4
- package/dist/memory/sqlite.js.map +1 -1
- package/dist/memory/storage.d.ts +6 -0
- package/dist/memory/storage.js +3 -3
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/tool-defaults.d.ts +8 -0
- package/dist/memory/tool-defaults.js +59 -0
- package/dist/memory/tool-defaults.js.map +1 -0
- package/dist/onboarding/connect.d.ts +35 -0
- package/dist/onboarding/connect.js +118 -0
- package/dist/onboarding/connect.js.map +1 -0
- package/dist/onboarding/credential-interceptor.d.ts +44 -0
- package/dist/onboarding/credential-interceptor.js +72 -0
- package/dist/onboarding/credential-interceptor.js.map +1 -0
- package/dist/onboarding/degradation-accumulator.d.ts +21 -0
- package/dist/onboarding/degradation-accumulator.js +55 -0
- package/dist/onboarding/degradation-accumulator.js.map +1 -0
- package/dist/onboarding/prompt-user.d.ts +23 -0
- package/dist/onboarding/prompt-user.js +61 -0
- package/dist/onboarding/prompt-user.js.map +1 -0
- package/dist/onboarding/providers.d.ts +116 -0
- package/dist/onboarding/providers.js +239 -0
- package/dist/onboarding/providers.js.map +1 -0
- package/dist/onboarding/state.d.ts +31 -2
- package/dist/onboarding/state.js +141 -13
- package/dist/onboarding/state.js.map +1 -1
- package/dist/onboarding/tool-helpers.d.ts +34 -0
- package/dist/onboarding/tool-helpers.js +80 -0
- package/dist/onboarding/tool-helpers.js.map +1 -0
- package/dist/onboarding/tool-tags.d.ts +37 -0
- package/dist/onboarding/tool-tags.js +149 -0
- package/dist/onboarding/tool-tags.js.map +1 -0
- package/dist/onboarding/validation.d.ts +19 -0
- package/dist/onboarding/validation.js +117 -0
- package/dist/onboarding/validation.js.map +1 -0
- package/dist/pi/opencandle-extension.d.ts +7 -1
- package/dist/pi/opencandle-extension.js +488 -13
- package/dist/pi/opencandle-extension.js.map +1 -1
- package/dist/pi/session-storage.d.ts +2 -0
- package/dist/pi/session-storage.js +5 -0
- package/dist/pi/session-storage.js.map +1 -0
- package/dist/pi/session.d.ts +4 -1
- package/dist/pi/session.js +25 -3
- package/dist/pi/session.js.map +1 -1
- package/dist/pi/setup.d.ts +1 -2
- package/dist/pi/setup.js +67 -120
- package/dist/pi/setup.js.map +1 -1
- package/dist/pi/tool-adapter.d.ts +2 -2
- package/dist/pi/tool-adapter.js +14 -1
- package/dist/pi/tool-adapter.js.map +1 -1
- package/dist/prompts/context-builder.d.ts +22 -0
- package/dist/prompts/context-builder.js +47 -11
- package/dist/prompts/context-builder.js.map +1 -1
- package/dist/prompts/disclaimer.d.ts +6 -0
- package/dist/prompts/disclaimer.js +9 -0
- package/dist/prompts/disclaimer.js.map +1 -0
- package/dist/prompts/workflow-prompts.d.ts +8 -0
- package/dist/prompts/workflow-prompts.js +39 -5
- package/dist/prompts/workflow-prompts.js.map +1 -1
- package/dist/providers/alpha-vantage.js +20 -1
- package/dist/providers/alpha-vantage.js.map +1 -1
- package/dist/providers/exa-search.d.ts +39 -0
- package/dist/providers/exa-search.js +276 -0
- package/dist/providers/exa-search.js.map +1 -0
- package/dist/providers/finnhub.d.ts +17 -0
- package/dist/providers/finnhub.js +94 -0
- package/dist/providers/finnhub.js.map +1 -0
- package/dist/providers/fred.js +13 -1
- package/dist/providers/fred.js.map +1 -1
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/provider-credential-error.d.ts +8 -0
- package/dist/providers/provider-credential-error.js +22 -0
- package/dist/providers/provider-credential-error.js.map +1 -0
- package/dist/providers/reddit.d.ts +8 -0
- package/dist/providers/reddit.js +36 -9
- package/dist/providers/reddit.js.map +1 -1
- package/dist/providers/twitter.js +2 -8
- package/dist/providers/twitter.js.map +1 -1
- package/dist/providers/web-search.d.ts +17 -0
- package/dist/providers/web-search.js +224 -0
- package/dist/providers/web-search.js.map +1 -0
- package/dist/providers/wrap-provider.d.ts +7 -0
- package/dist/providers/wrap-provider.js +15 -0
- package/dist/providers/wrap-provider.js.map +1 -1
- package/dist/providers/yahoo-finance.js +70 -33
- package/dist/providers/yahoo-finance.js.map +1 -1
- package/dist/routing/classify-intent.js +22 -0
- package/dist/routing/classify-intent.js.map +1 -1
- package/dist/routing/defaults.js +1 -1
- package/dist/routing/defaults.js.map +1 -1
- package/dist/routing/index.d.ts +4 -0
- package/dist/routing/index.js +3 -0
- package/dist/routing/index.js.map +1 -1
- package/dist/routing/router-llm-client.d.ts +11 -0
- package/dist/routing/router-llm-client.js +42 -0
- package/dist/routing/router-llm-client.js.map +1 -0
- package/dist/routing/router-prompt.d.ts +2 -0
- package/dist/routing/router-prompt.js +138 -0
- package/dist/routing/router-prompt.js.map +1 -0
- package/dist/routing/router-types.d.ts +62 -0
- package/dist/routing/router-types.js +2 -0
- package/dist/routing/router-types.js.map +1 -0
- package/dist/routing/router.d.ts +10 -0
- package/dist/routing/router.js +194 -0
- package/dist/routing/router.js.map +1 -0
- package/dist/runtime/session-coordinator.d.ts +63 -4
- package/dist/runtime/session-coordinator.js +155 -4
- package/dist/runtime/session-coordinator.js.map +1 -1
- package/dist/runtime/tool-defaults-wrapper.d.ts +3 -0
- package/dist/runtime/tool-defaults-wrapper.js +25 -0
- package/dist/runtime/tool-defaults-wrapper.js.map +1 -0
- package/dist/sentiment/adapters/finnhub.d.ts +7 -0
- package/dist/sentiment/adapters/finnhub.js +39 -0
- package/dist/sentiment/adapters/finnhub.js.map +1 -0
- package/dist/sentiment/adapters/reddit.d.ts +11 -0
- package/dist/sentiment/adapters/reddit.js +54 -0
- package/dist/sentiment/adapters/reddit.js.map +1 -0
- package/dist/sentiment/adapters/twitter.d.ts +9 -0
- package/dist/sentiment/adapters/twitter.js +32 -0
- package/dist/sentiment/adapters/twitter.js.map +1 -0
- package/dist/sentiment/adapters/web.d.ts +9 -0
- package/dist/sentiment/adapters/web.js +40 -0
- package/dist/sentiment/adapters/web.js.map +1 -0
- package/dist/sentiment/index.d.ts +16 -0
- package/dist/sentiment/index.js +44 -0
- package/dist/sentiment/index.js.map +1 -0
- package/dist/sentiment/keywords.d.ts +2 -0
- package/dist/sentiment/keywords.js +9 -0
- package/dist/sentiment/keywords.js.map +1 -0
- package/dist/sentiment/pipeline.d.ts +9 -0
- package/dist/sentiment/pipeline.js +57 -0
- package/dist/sentiment/pipeline.js.map +1 -0
- package/dist/sentiment/scorer.d.ts +9 -0
- package/dist/sentiment/scorer.js +64 -0
- package/dist/sentiment/scorer.js.map +1 -0
- package/dist/sentiment/store.d.ts +24 -0
- package/dist/sentiment/store.js +182 -0
- package/dist/sentiment/store.js.map +1 -0
- package/dist/sentiment/trends.d.ts +13 -0
- package/dist/sentiment/trends.js +73 -0
- package/dist/sentiment/trends.js.map +1 -0
- package/dist/sentiment/types.d.ts +66 -0
- package/dist/sentiment/types.js +54 -0
- package/dist/sentiment/types.js.map +1 -0
- package/dist/system-prompt.js +29 -13
- package/dist/system-prompt.js.map +1 -1
- package/dist/tool-kit.d.ts +4 -4
- package/dist/tools/fundamentals/company-overview.d.ts +4 -2
- package/dist/tools/fundamentals/company-overview.js +27 -27
- package/dist/tools/fundamentals/company-overview.js.map +1 -1
- package/dist/tools/fundamentals/comps.d.ts +1 -1
- package/dist/tools/fundamentals/comps.js +45 -45
- package/dist/tools/fundamentals/comps.js.map +1 -1
- package/dist/tools/fundamentals/dcf.d.ts +1 -1
- package/dist/tools/fundamentals/dcf.js +82 -82
- package/dist/tools/fundamentals/dcf.js.map +1 -1
- package/dist/tools/fundamentals/earnings.d.ts +4 -2
- package/dist/tools/fundamentals/earnings.js +25 -25
- package/dist/tools/fundamentals/earnings.js.map +1 -1
- package/dist/tools/fundamentals/financials.d.ts +4 -2
- package/dist/tools/fundamentals/financials.js +23 -23
- package/dist/tools/fundamentals/financials.js.map +1 -1
- package/dist/tools/fundamentals/sec-filings.d.ts +1 -1
- package/dist/tools/index.d.ts +28 -1
- package/dist/tools/index.js +35 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/interaction/ask-user.d.ts +1 -1
- package/dist/tools/interaction/ask-user.js +28 -64
- package/dist/tools/interaction/ask-user.js.map +1 -1
- package/dist/tools/interaction/twitter-login.d.ts +1 -1
- package/dist/tools/macro/fear-greed.d.ts +1 -1
- package/dist/tools/macro/fred-data.d.ts +4 -2
- package/dist/tools/macro/fred-data.js +26 -26
- package/dist/tools/macro/fred-data.js.map +1 -1
- package/dist/tools/market/crypto-history.d.ts +1 -1
- package/dist/tools/market/crypto-price.d.ts +1 -1
- package/dist/tools/market/search-ticker.d.ts +1 -1
- package/dist/tools/market/stock-history.d.ts +1 -1
- package/dist/tools/market/stock-quote.d.ts +1 -1
- package/dist/tools/options/option-chain.d.ts +1 -1
- package/dist/tools/options/option-chain.js +4 -1
- package/dist/tools/options/option-chain.js.map +1 -1
- package/dist/tools/portfolio/correlation.d.ts +1 -1
- package/dist/tools/portfolio/predictions.d.ts +1 -1
- package/dist/tools/portfolio/risk-analysis.d.ts +1 -1
- package/dist/tools/portfolio/tracker.d.ts +1 -1
- package/dist/tools/portfolio/watchlist.d.ts +1 -1
- package/dist/tools/sentiment/reddit-sentiment.d.ts +4 -2
- package/dist/tools/sentiment/reddit-sentiment.js +107 -22
- package/dist/tools/sentiment/reddit-sentiment.js.map +1 -1
- package/dist/tools/sentiment/sentiment-summary.d.ts +7 -0
- package/dist/tools/sentiment/sentiment-summary.js +230 -0
- package/dist/tools/sentiment/sentiment-summary.js.map +1 -0
- package/dist/tools/sentiment/sentiment-trend.d.ts +22 -0
- package/dist/tools/sentiment/sentiment-trend.js +39 -0
- package/dist/tools/sentiment/sentiment-trend.js.map +1 -0
- package/dist/tools/sentiment/twitter-sentiment.d.ts +1 -1
- package/dist/tools/sentiment/twitter-sentiment.js +17 -0
- package/dist/tools/sentiment/twitter-sentiment.js.map +1 -1
- package/dist/tools/sentiment/web-search.d.ts +11 -0
- package/dist/tools/sentiment/web-search.js +115 -0
- package/dist/tools/sentiment/web-search.js.map +1 -0
- package/dist/tools/sentiment/web-sentiment.d.ts +8 -0
- package/dist/tools/sentiment/web-sentiment.js +66 -0
- package/dist/tools/sentiment/web-sentiment.js.map +1 -0
- package/dist/tools/technical/backtest.d.ts +1 -1
- package/dist/tools/technical/indicators.d.ts +1 -1
- package/dist/tools/technical/indicators.js +7 -1
- package/dist/tools/technical/indicators.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/sentiment.d.ts +21 -0
- package/dist/workflows/options-screener.js +7 -2
- package/dist/workflows/options-screener.js.map +1 -1
- package/dist/workflows/portfolio-builder.js +3 -3
- package/dist/workflows/portfolio-builder.js.map +1 -1
- package/gui/server/background-quotes.ts +31 -0
- package/gui/server/chat-event-adapter.ts +142 -0
- package/gui/server/invoke-tool.ts +89 -0
- package/gui/server/live-chat-event-adapter.ts +181 -0
- package/gui/server/model-setup.ts +100 -0
- package/gui/server/package.json +5 -0
- package/gui/server/projector.ts +212 -0
- package/gui/server/server.ts +592 -0
- package/gui/server/session-actions.ts +31 -0
- package/gui/server/tool-metadata.ts +88 -0
- package/gui/server/websocket.ts +128 -0
- package/gui/server/writer-lock.ts +118 -0
- package/gui/shared/chat-events.ts +118 -0
- package/gui/shared/event-reducer.ts +186 -0
- package/gui/web/dist/assets/CatalogOverlay-D1ImSJTe.js +1 -0
- package/gui/web/dist/assets/index-DBrWq43L.css +1 -0
- package/gui/web/dist/assets/index-RflHaj0y.js +67 -0
- package/gui/web/dist/assets/logo-CWpt6Y2a.svg +187 -0
- package/gui/web/dist/index.html +17 -0
- package/package.json +62 -20
- package/src/analysts/contracts.ts +189 -0
- package/src/analysts/orchestrator.ts +300 -0
- package/src/cli.ts +205 -0
- package/src/config.ts +161 -0
- package/src/index.ts +5 -0
- package/src/infra/browser.ts +111 -0
- package/src/infra/cache.ts +103 -0
- package/src/infra/http-client.ts +68 -0
- package/src/infra/index.ts +18 -0
- package/src/infra/native-dependencies.ts +12 -0
- package/src/infra/node-version.ts +24 -0
- package/src/infra/open-url.ts +28 -0
- package/src/infra/opencandle-paths.ts +64 -0
- package/src/infra/rate-limiter.ts +64 -0
- package/src/memory/index.ts +10 -0
- package/src/memory/manager.ts +159 -0
- package/src/memory/preference-extractor.ts +106 -0
- package/src/memory/retrieval.ts +70 -0
- package/src/memory/sqlite.ts +172 -0
- package/src/memory/storage.ts +204 -0
- package/src/memory/tool-defaults.ts +87 -0
- package/src/memory/types.ts +67 -0
- package/src/onboarding/connect.ts +184 -0
- package/src/onboarding/credential-interceptor.ts +134 -0
- package/src/onboarding/degradation-accumulator.ts +79 -0
- package/src/onboarding/prompt-user.ts +85 -0
- package/src/onboarding/providers.ts +315 -0
- package/src/onboarding/state.ts +218 -0
- package/src/onboarding/tool-helpers.ts +111 -0
- package/src/onboarding/tool-tags.ts +201 -0
- package/src/onboarding/validation.ts +158 -0
- package/src/pi/opencandle-extension.ts +724 -0
- package/src/pi/session-storage.ts +5 -0
- package/src/pi/session.ts +81 -0
- package/src/pi/setup.ts +371 -0
- package/src/pi/tool-adapter.ts +36 -0
- package/src/prompts/context-builder.ts +204 -0
- package/src/prompts/disclaimer.ts +9 -0
- package/src/prompts/sections.ts +46 -0
- package/src/prompts/workflow-prompts.ts +279 -0
- package/src/providers/alpha-vantage.ts +292 -0
- package/src/providers/coingecko.ts +96 -0
- package/src/providers/exa-search.ts +373 -0
- package/src/providers/fear-greed.ts +45 -0
- package/src/providers/finnhub.ts +124 -0
- package/src/providers/fred.ts +83 -0
- package/src/providers/index.ts +9 -0
- package/src/providers/provider-credential-error.ts +23 -0
- package/src/providers/reddit.ts +151 -0
- package/src/providers/sec-edgar.ts +96 -0
- package/src/providers/twitter.ts +173 -0
- package/src/providers/web-search.ts +293 -0
- package/src/providers/with-fallback.ts +41 -0
- package/src/providers/wrap-provider.ts +64 -0
- package/src/providers/yahoo-finance.ts +367 -0
- package/src/routing/classify-intent.ts +194 -0
- package/src/routing/defaults.ts +29 -0
- package/src/routing/entity-extractor.ts +140 -0
- package/src/routing/index.ts +26 -0
- package/src/routing/router-llm-client.ts +51 -0
- package/src/routing/router-prompt.ts +159 -0
- package/src/routing/router-types.ts +66 -0
- package/src/routing/router.ts +213 -0
- package/src/routing/slot-resolver.ts +152 -0
- package/src/routing/types.ts +63 -0
- package/src/runtime/evidence.ts +77 -0
- package/src/runtime/index.ts +55 -0
- package/src/runtime/prompt-step.ts +75 -0
- package/src/runtime/provider-ids.ts +15 -0
- package/src/runtime/provider-tracker.ts +40 -0
- package/src/runtime/run-context.ts +22 -0
- package/src/runtime/session-coordinator.ts +406 -0
- package/src/runtime/tool-defaults-wrapper.ts +35 -0
- package/src/runtime/validation.ts +214 -0
- package/src/runtime/workflow-events.ts +75 -0
- package/src/runtime/workflow-runner.ts +188 -0
- package/src/runtime/workflow-types.ts +102 -0
- package/src/sentiment/adapters/finnhub.ts +44 -0
- package/src/sentiment/adapters/reddit.ts +65 -0
- package/src/sentiment/adapters/twitter.ts +36 -0
- package/src/sentiment/adapters/web.ts +44 -0
- package/src/sentiment/index.ts +58 -0
- package/src/sentiment/keywords.ts +9 -0
- package/src/sentiment/pipeline.ts +68 -0
- package/src/sentiment/scorer.ts +78 -0
- package/src/sentiment/store.ts +260 -0
- package/src/sentiment/trends.ts +90 -0
- package/src/sentiment/types.ts +108 -0
- package/src/system-prompt.ts +115 -0
- package/src/tool-kit.ts +68 -0
- package/src/tools/AGENTS.md +36 -0
- package/src/tools/fundamentals/company-overview.ts +54 -0
- package/src/tools/fundamentals/comps.ts +156 -0
- package/src/tools/fundamentals/dcf.ts +267 -0
- package/src/tools/fundamentals/earnings.ts +47 -0
- package/src/tools/fundamentals/financials.ts +54 -0
- package/src/tools/fundamentals/sec-filings.ts +61 -0
- package/src/tools/index.ts +88 -0
- package/src/tools/interaction/ask-user.ts +81 -0
- package/src/tools/interaction/twitter-login.ts +93 -0
- package/src/tools/macro/fear-greed.ts +41 -0
- package/src/tools/macro/fred-data.ts +54 -0
- package/src/tools/market/crypto-history.ts +51 -0
- package/src/tools/market/crypto-price.ts +53 -0
- package/src/tools/market/search-ticker.ts +53 -0
- package/src/tools/market/stock-history.ts +79 -0
- package/src/tools/market/stock-quote.ts +64 -0
- package/src/tools/options/greeks.ts +82 -0
- package/src/tools/options/option-chain.ts +91 -0
- package/src/tools/portfolio/correlation.ts +162 -0
- package/src/tools/portfolio/predictions.ts +253 -0
- package/src/tools/portfolio/risk-analysis.ts +134 -0
- package/src/tools/portfolio/tracker.ts +147 -0
- package/src/tools/portfolio/watchlist.ts +153 -0
- package/src/tools/sentiment/reddit-sentiment.ts +164 -0
- package/src/tools/sentiment/sentiment-summary.ts +256 -0
- package/src/tools/sentiment/sentiment-trend.ts +58 -0
- package/src/tools/sentiment/twitter-sentiment.ts +96 -0
- package/src/tools/sentiment/web-search.ts +150 -0
- package/src/tools/sentiment/web-sentiment.ts +76 -0
- package/src/tools/technical/backtest.ts +246 -0
- package/src/tools/technical/indicators.ts +258 -0
- package/src/types/fundamentals.ts +46 -0
- package/src/types/index.ts +20 -0
- package/src/types/macro.ts +27 -0
- package/src/types/market.ts +43 -0
- package/src/types/options.ts +35 -0
- package/src/types/portfolio.ts +41 -0
- package/src/types/sentiment.ts +70 -0
- package/src/workflows/compare-assets.ts +39 -0
- package/src/workflows/index.ts +4 -0
- package/src/workflows/options-screener.ts +49 -0
- package/src/workflows/portfolio-builder.ts +52 -0
- package/src/workflows/types.ts +4 -0
- package/dist/tools/sentiment/news-sentiment.d.ts +0 -7
- package/dist/tools/sentiment/news-sentiment.js +0 -55
- package/dist/tools/sentiment/news-sentiment.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { promptUser } from "../../onboarding/prompt-user.js";
|
|
2
3
|
const AskUserParams = Type.Object({
|
|
3
4
|
question: Type.String({ description: "The question to ask the user" }),
|
|
4
5
|
question_type: Type.Union([Type.Literal("select"), Type.Literal("text"), Type.Literal("confirm")], { description: "Type of answer expected: select (pick from options), text (free input), or confirm (yes/no)" }),
|
|
@@ -6,24 +7,6 @@ const AskUserParams = Type.Object({
|
|
|
6
7
|
placeholder: Type.Optional(Type.String({ description: "Hint text for text input" })),
|
|
7
8
|
reason: Type.Optional(Type.String({ description: "Brief context for why this clarification is needed" })),
|
|
8
9
|
});
|
|
9
|
-
function cancelledResult(question, questionType) {
|
|
10
|
-
return {
|
|
11
|
-
content: [{ type: "text", text: "User cancelled the selection. Proceed with your best judgment and disclose your assumption." }],
|
|
12
|
-
details: { question, questionType, answer: null, cancelled: true },
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function answerResult(question, questionType, answer) {
|
|
16
|
-
return {
|
|
17
|
-
content: [{ type: "text", text: `User answered: ${answer}` }],
|
|
18
|
-
details: { question, questionType, answer, cancelled: false },
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function noUiResult(question, questionType) {
|
|
22
|
-
return {
|
|
23
|
-
content: [{ type: "text", text: "UI not available (non-interactive mode). Proceed with your best judgment and clearly disclose your assumption." }],
|
|
24
|
-
details: { question, questionType, answer: null, cancelled: true },
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
10
|
export function registerAskUserTool(pi, askUserHandler) {
|
|
28
11
|
pi.registerTool({
|
|
29
12
|
name: "ask_user",
|
|
@@ -33,54 +16,35 @@ export function registerAskUserTool(pi, askUserHandler) {
|
|
|
33
16
|
parameters: AskUserParams,
|
|
34
17
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
35
18
|
const { question, question_type: questionType } = params;
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
if (result.cancelled)
|
|
46
|
-
return cancelledResult(question, questionType);
|
|
47
|
-
return answerResult(question, questionType, result.answer);
|
|
48
|
-
}
|
|
49
|
-
if (!ctx?.hasUI) {
|
|
50
|
-
return noUiResult(question, questionType);
|
|
19
|
+
// Preserve the pre-refactor error message for the specific misuse case
|
|
20
|
+
// where the model asks a select question with no options — this is a
|
|
21
|
+
// model/caller bug, not a cancellation.
|
|
22
|
+
if (questionType === "select" && (!params.options || params.options.length === 0)) {
|
|
23
|
+
return {
|
|
24
|
+
content: [{ type: "text", text: "Error: No options provided for select question. Provide options or use text type instead." }],
|
|
25
|
+
details: { question, questionType, answer: null, cancelled: true },
|
|
26
|
+
};
|
|
51
27
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
case "text": {
|
|
68
|
-
const input = await ctx.ui.input(question, params.placeholder ?? "");
|
|
69
|
-
if (input === undefined || input.trim() === "") {
|
|
70
|
-
return cancelledResult(question, questionType);
|
|
71
|
-
}
|
|
72
|
-
return answerResult(question, questionType, input.trim());
|
|
73
|
-
}
|
|
74
|
-
case "confirm": {
|
|
75
|
-
const confirmed = await ctx.ui.confirm(question, params.reason ?? "");
|
|
76
|
-
return answerResult(question, questionType, confirmed ? "Yes" : "No");
|
|
77
|
-
}
|
|
78
|
-
default:
|
|
79
|
-
return {
|
|
80
|
-
content: [{ type: "text", text: `Unknown question type: ${questionType}. Use select, text, or confirm.` }],
|
|
81
|
-
details: { question, questionType, answer: null, cancelled: true },
|
|
82
|
-
};
|
|
28
|
+
const result = await promptUser(ctx, {
|
|
29
|
+
question,
|
|
30
|
+
questionType,
|
|
31
|
+
options: params.options,
|
|
32
|
+
placeholder: params.placeholder,
|
|
33
|
+
reason: params.reason,
|
|
34
|
+
}, askUserHandler);
|
|
35
|
+
if (result.cancelled) {
|
|
36
|
+
const text = !askUserHandler && !ctx?.hasUI
|
|
37
|
+
? "UI not available (non-interactive mode). Proceed with your best judgment and clearly disclose your assumption."
|
|
38
|
+
: "User cancelled the selection. Proceed with your best judgment and disclose your assumption.";
|
|
39
|
+
return {
|
|
40
|
+
content: [{ type: "text", text }],
|
|
41
|
+
details: { question, questionType, answer: null, cancelled: true },
|
|
42
|
+
};
|
|
83
43
|
}
|
|
44
|
+
return {
|
|
45
|
+
content: [{ type: "text", text: `User answered: ${result.answer}` }],
|
|
46
|
+
details: { question, questionType, answer: result.answer, cancelled: false },
|
|
47
|
+
};
|
|
84
48
|
},
|
|
85
49
|
});
|
|
86
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-user.js","sourceRoot":"","sources":["../../../src/tools/interaction/ask-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"ask-user.js","sourceRoot":"","sources":["../../../src/tools/interaction/ask-user.ts"],"names":[],"mappings":"AAAA,OA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C,CAAC;AACL,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { FearGreedData } from "../../types/sentiment.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{}>;
|
|
4
4
|
export declare const fearGreedTool: AgentTool<typeof params, FearGreedData>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { FredSeries } from "../../types/macro.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
4
|
series_id: import("@sinclair/typebox").TString;
|
|
5
5
|
limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
6
6
|
}>;
|
|
7
|
-
export declare const fredDataTool: AgentTool<typeof params, FredSeries
|
|
7
|
+
export declare const fredDataTool: AgentTool<typeof params, FredSeries | {
|
|
8
|
+
credentialRequired: unknown;
|
|
9
|
+
}>;
|
|
8
10
|
export {};
|
|
@@ -2,6 +2,7 @@ import { Type } from "@sinclair/typebox";
|
|
|
2
2
|
import { getSeries } from "../../providers/fred.js";
|
|
3
3
|
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
4
4
|
import { getConfig } from "../../config.js";
|
|
5
|
+
import { withCredentialCheck } from "../../onboarding/tool-helpers.js";
|
|
5
6
|
import { FRED_SERIES } from "../../types/macro.js";
|
|
6
7
|
const params = Type.Object({
|
|
7
8
|
series_id: Type.String({
|
|
@@ -12,34 +13,33 @@ const params = Type.Object({
|
|
|
12
13
|
export const fredDataTool = {
|
|
13
14
|
name: "get_economic_data",
|
|
14
15
|
label: "FRED Economic Data",
|
|
15
|
-
description: "Get economic data from FRED (Federal Reserve Economic Data): interest rates, CPI, GDP, unemployment, yield curve, and more. Requires
|
|
16
|
+
description: "Get economic data from FRED (Federal Reserve Economic Data): interest rates, CPI, GDP, unemployment, yield curve, and more. Requires FRED.",
|
|
16
17
|
parameters: params,
|
|
17
18
|
async execute(toolCallId, args) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return { content: [{ type: "text", text: prefix + text }], details: series };
|
|
19
|
+
return withCredentialCheck("fred", async () => {
|
|
20
|
+
const apiKey = getConfig().fredApiKey;
|
|
21
|
+
const limit = args.limit ?? 30;
|
|
22
|
+
const result = await wrapProvider("fred", () => getSeries(args.series_id.toUpperCase(), apiKey, limit));
|
|
23
|
+
if (result.status === "unavailable") {
|
|
24
|
+
return {
|
|
25
|
+
content: [{ type: "text", text: `⚠ FRED data unavailable for ${args.series_id.toUpperCase()} (${result.reason}).` }],
|
|
26
|
+
details: null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const series = result.data;
|
|
30
|
+
const latest = series.observations[series.observations.length - 1];
|
|
31
|
+
const header = `**${series.title}** (${series.id})`;
|
|
32
|
+
const meta = `Units: ${series.units} | Frequency: ${series.frequency} | Last updated: ${series.lastUpdated}`;
|
|
33
|
+
const current = latest ? `Latest: ${latest.value} (${latest.date})` : "No data";
|
|
34
|
+
// Show last 10 observations
|
|
35
|
+
const recent = series.observations.slice(-10);
|
|
36
|
+
const table = recent.map((o) => `${o.date}: ${o.value}`).join("\n");
|
|
37
|
+
const text = [header, meta, current, "", "Recent observations:", table].join("\n");
|
|
38
|
+
const prefix = result.stale
|
|
39
|
+
? `⚠ Using cached FRED data from ${result.timestamp} (FRED unavailable)\n`
|
|
40
|
+
: "";
|
|
41
|
+
return { content: [{ type: "text", text: prefix + text }], details: series };
|
|
42
|
+
});
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
//# sourceMappingURL=fred-data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fred-data.js","sourceRoot":"","sources":["../../../src/tools/macro/fred-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACzB,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC;QACrB,WAAW,EAAE,gCAAgC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;KACrH,CAAC;IACF,KAAK,EAAE,IAAI,CAAC,QAAQ,CAClB,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,+CAA+C,EAAE,CAAC,CAC9E;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"fred-data.js","sourceRoot":"","sources":["../../../src/tools/macro/fred-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;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,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAC/E,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { OHLCV } from "../../types/market.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
4
|
id: import("@sinclair/typebox").TString;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { CryptoPrice } from "../../types/market.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
4
|
id: import("@sinclair/typebox").TString;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { OHLCV } from "../../types/market.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
4
|
symbol: import("@sinclair/typebox").TString;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { StockQuote } from "../../types/market.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
4
|
symbol: import("@sinclair/typebox").TString;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { OptionsChain } from "../../types/options.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
4
|
symbol: import("@sinclair/typebox").TString;
|
|
@@ -32,7 +32,7 @@ export const optionChainTool = {
|
|
|
32
32
|
const lines = [
|
|
33
33
|
`**${chain.symbol} Options Chain** — Expiry: ${chain.expirationDate}`,
|
|
34
34
|
`Underlying: $${chain.underlyingPrice.toFixed(2)}`,
|
|
35
|
-
`Available expirations: ${
|
|
35
|
+
`Available expirations: ${formatAvailableExpirations(chain.expirationDates)}`,
|
|
36
36
|
"",
|
|
37
37
|
];
|
|
38
38
|
const showCalls = !normalizedType || normalizedType === "call";
|
|
@@ -62,6 +62,9 @@ export const optionChainTool = {
|
|
|
62
62
|
function sortByVolume(contracts) {
|
|
63
63
|
return [...contracts].sort((a, b) => b.volume - a.volume);
|
|
64
64
|
}
|
|
65
|
+
function formatAvailableExpirations(expirationDates) {
|
|
66
|
+
return expirationDates.join(", ");
|
|
67
|
+
}
|
|
65
68
|
function formatContract(c) {
|
|
66
69
|
const itm = c.inTheMoney ? "*" : " ";
|
|
67
70
|
return `${itm}$${c.strike.toFixed(2)} | $${c.bid.toFixed(2)}/$${c.ask.toFixed(2)} | $${c.lastPrice.toFixed(2)} | ${c.volume} | ${c.openInterest} | ${(c.impliedVolatility * 100).toFixed(1)}% | ${c.greeks.delta.toFixed(3)} | ${c.greeks.theta.toFixed(3)}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option-chain.js","sourceRoot":"","sources":["../../../src/tools/options/option-chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAGhE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACzB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,kDAAkD,EAAE,CAAC;IACxF,UAAU,EAAE,IAAI,CAAC,QAAQ,CACvB,IAAI,CAAC,MAAM,CAAC;QACV,WAAW,EACT,yEAAyE;KAC5E,CAAC,CACH;IACD,IAAI,EAAE,IAAI,CAAC,QAAQ,C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CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,0BAA0B,CAAC,eAAyB;IAC3D,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,cAAc,CAAC,CAAiB;IACvC,MAAM,GAAG,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACrC,OAAO,GAAG,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,YAAY,MAAM,CAAC,CAAC,CAAC,iBAAiB,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/P,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { OHLCV } from "../../types/market.js";
|
|
3
3
|
export declare function computeCorrelation(returnsA: number[], returnsB: number[]): number;
|
|
4
4
|
export declare function alignReturnsByDate(historiesBySymbol: Map<string, OHLCV[]>, minOverlap?: number): Map<string, number[]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { RiskMetrics } from "../../types/portfolio.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
4
|
symbol: import("@sinclair/typebox").TString;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { PortfolioSummary } from "../../types/portfolio.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
4
|
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"add">, import("@sinclair/typebox").TLiteral<"remove">, import("@sinclair/typebox").TLiteral<"view">]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
3
3
|
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"add">, import("@sinclair/typebox").TLiteral<"remove">, import("@sinclair/typebox").TLiteral<"check">]>;
|
|
4
4
|
symbol: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { AgentTool } from "@
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { RedditSentimentResult } from "../../types/sentiment.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
|
-
subreddit: import("@sinclair/typebox").TString
|
|
4
|
+
subreddit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
5
|
+
query: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
6
|
+
subreddits: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
5
7
|
limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
6
8
|
}>;
|
|
7
9
|
export declare const redditSentimentTool: AgentTool<typeof params, RedditSentimentResult>;
|
|
@@ -1,45 +1,130 @@
|
|
|
1
1
|
import { Type } from "@sinclair/typebox";
|
|
2
|
-
import { getSubredditPosts } from "../../providers/reddit.js";
|
|
2
|
+
import { getSubredditPosts, getPostComments } from "../../providers/reddit.js";
|
|
3
3
|
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
4
|
+
import { RedditAdapter } from "../../sentiment/adapters/reddit.js";
|
|
5
|
+
import { getSentimentPipeline } from "../../sentiment/index.js";
|
|
6
|
+
import { getConfig } from "../../config.js";
|
|
4
7
|
const params = Type.Object({
|
|
5
|
-
subreddit: Type.String({
|
|
6
|
-
description: "Subreddit name (e.g. wallstreetbets, stocks
|
|
7
|
-
}),
|
|
8
|
-
|
|
8
|
+
subreddit: Type.Optional(Type.String({
|
|
9
|
+
description: "Subreddit name (e.g. wallstreetbets, stocks). If omitted, searches across default subreddits.",
|
|
10
|
+
})),
|
|
11
|
+
query: Type.Optional(Type.String({
|
|
12
|
+
description: "Topic or ticker to filter posts by (e.g. AAPL, bitcoin). Searches titles and post bodies.",
|
|
13
|
+
})),
|
|
14
|
+
subreddits: Type.Optional(Type.Array(Type.String(), {
|
|
15
|
+
description: "Multiple subreddits to search. Overrides single subreddit param.",
|
|
16
|
+
})),
|
|
17
|
+
limit: Type.Optional(Type.Number({ description: "Number of posts per subreddit. Default: 25, max: 100" })),
|
|
9
18
|
});
|
|
10
19
|
export const redditSentimentTool = {
|
|
11
20
|
name: "get_reddit_sentiment",
|
|
12
21
|
label: "Reddit Sentiment",
|
|
13
|
-
description: "
|
|
22
|
+
description: "Analyze sentiment from financial Reddit communities. Supports single subreddit, multi-subreddit, and topic filtering. Returns scored posts with comment analysis and trend context.",
|
|
14
23
|
parameters: params,
|
|
15
24
|
async execute(toolCallId, args) {
|
|
16
25
|
const limit = Math.min(args.limit ?? 25, 100);
|
|
17
|
-
const
|
|
18
|
-
|
|
26
|
+
const config = getConfig();
|
|
27
|
+
// Determine subreddits to search
|
|
28
|
+
let subreddits;
|
|
29
|
+
if (args.subreddits && args.subreddits.length > 0) {
|
|
30
|
+
subreddits = args.subreddits;
|
|
31
|
+
}
|
|
32
|
+
else if (args.subreddit) {
|
|
33
|
+
subreddits = [args.subreddit];
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
subreddits = config.sentiment?.defaultSubreddits ?? ["wallstreetbets", "stocks", "investing", "options"];
|
|
37
|
+
}
|
|
38
|
+
// Fetch from all subreddits
|
|
39
|
+
const allResults = [];
|
|
40
|
+
const warnings = [];
|
|
41
|
+
for (const sub of subreddits) {
|
|
42
|
+
const providerResult = await wrapProvider("reddit", () => getSubredditPosts(sub, limit));
|
|
43
|
+
if (providerResult.status === "unavailable") {
|
|
44
|
+
warnings.push(`r/${sub}: ${providerResult.reason}`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
allResults.push(providerResult.data);
|
|
48
|
+
}
|
|
49
|
+
if (allResults.length === 0) {
|
|
19
50
|
return {
|
|
20
|
-
content: [{ type: "text", text: `⚠ Reddit sentiment unavailable
|
|
51
|
+
content: [{ type: "text", text: `⚠ Reddit sentiment unavailable (${warnings.join("; ")}).` }],
|
|
21
52
|
details: null,
|
|
22
53
|
};
|
|
23
54
|
}
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
55
|
+
// Merge and filter by query if provided
|
|
56
|
+
const adapter = new RedditAdapter();
|
|
57
|
+
let allRecords = allResults.flatMap((r) => adapter.mapPostsToRecords(r, args.query ?? subreddits.join("+")));
|
|
58
|
+
// Topic filtering
|
|
59
|
+
if (args.query) {
|
|
60
|
+
const queryLower = args.query.toLowerCase();
|
|
61
|
+
allRecords = allRecords.filter((r) => r.text.toLowerCase().includes(queryLower) ||
|
|
62
|
+
(r.title?.toLowerCase().includes(queryLower) ?? false));
|
|
63
|
+
}
|
|
64
|
+
// Deduplicate by sourceId (crossposts)
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
allRecords = allRecords.filter((r) => {
|
|
67
|
+
if (seen.has(r.sourceId))
|
|
68
|
+
return false;
|
|
69
|
+
seen.add(r.sourceId);
|
|
70
|
+
return true;
|
|
71
|
+
});
|
|
72
|
+
// Fetch comments for top 10 posts by engagement
|
|
73
|
+
const commentsPerPost = config.sentiment?.commentsPerPost ?? 5;
|
|
74
|
+
const topPosts = [...allRecords]
|
|
75
|
+
.sort((a, b) => b.engagement.score - a.engagement.score)
|
|
76
|
+
.slice(0, 10);
|
|
77
|
+
for (const post of topPosts) {
|
|
78
|
+
const sub = post.metadata.subreddit ?? subreddits[0];
|
|
79
|
+
if ((post.engagement.replies ?? 0) === 0)
|
|
80
|
+
continue;
|
|
81
|
+
try {
|
|
82
|
+
const comments = await getPostComments(sub, post.sourceId, commentsPerPost);
|
|
83
|
+
const commentRecords = adapter.mapCommentsToRecords(comments, post.sourceId, sub, args.query ?? subreddits.join("+"));
|
|
84
|
+
allRecords.push(...commentRecords);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Comment fetch failures are non-fatal
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Process through pipeline
|
|
91
|
+
const pipeline = getSentimentPipeline();
|
|
92
|
+
const pipelineResult = await pipeline.processRecords(allRecords, args.query ?? subreddits.join("+"));
|
|
93
|
+
// Build output using first result as base for backward compatibility
|
|
94
|
+
const firstResult = allResults[0];
|
|
95
|
+
const postRecords = pipelineResult.fresh.filter((r) => !r.metadata.isComment);
|
|
96
|
+
const commentRecords = pipelineResult.fresh.filter((r) => r.metadata.isComment);
|
|
97
|
+
const avgScore = postRecords.length > 0
|
|
98
|
+
? postRecords.reduce((s, r) => s + r.sentiment.score, 0) / postRecords.length
|
|
99
|
+
: 0;
|
|
100
|
+
const sentimentLabel = avgScore > 0.3 ? "Bullish" :
|
|
101
|
+
avgScore < -0.3 ? "Bearish" :
|
|
102
|
+
avgScore > 0 ? "Leaning Bullish" :
|
|
103
|
+
avgScore < 0 ? "Leaning Bearish" : "Neutral";
|
|
104
|
+
const subLabel = subreddits.length === 1 ? `r/${subreddits[0]}` : `${subreddits.length} subreddits`;
|
|
29
105
|
const lines = [
|
|
30
|
-
`**
|
|
31
|
-
`Sentiment
|
|
106
|
+
`**Reddit: ${args.query ?? subLabel}** — ${postRecords.length} posts, ${commentRecords.length} comments`,
|
|
107
|
+
`Sentiment: ${avgScore.toFixed(2)} (${sentimentLabel})`,
|
|
32
108
|
];
|
|
33
|
-
if (
|
|
34
|
-
lines.push(`
|
|
109
|
+
if (firstResult.topMentions.length > 0) {
|
|
110
|
+
lines.push(`Tickers: ${firstResult.topMentions.map((t) => `$${t}`).join(", ")}`);
|
|
35
111
|
}
|
|
36
112
|
lines.push("");
|
|
37
113
|
lines.push("Top posts:");
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
lines.push(` ⬆${post.score} 💬${post.
|
|
114
|
+
for (const post of postRecords.slice(0, 10)) {
|
|
115
|
+
const scoreIndicator = post.sentiment.score > 0 ? "🟢" : post.sentiment.score < 0 ? "🔴" : "⚪";
|
|
116
|
+
lines.push(` ${scoreIndicator} ⬆${post.engagement.score} 💬${post.engagement.replies ?? 0} — ${(post.title ?? post.text).slice(0, 100)}`);
|
|
117
|
+
}
|
|
118
|
+
if (pipelineResult.trend && pipelineResult.trend.length > 0) {
|
|
119
|
+
const t = pipelineResult.trend[0];
|
|
120
|
+
lines.push("");
|
|
121
|
+
lines.push(`Trend: ${t.sparkline} ${t.direction} (${t.delta >= 0 ? "+" : ""}${t.delta.toFixed(2)}, ${t.count} records)`);
|
|
122
|
+
}
|
|
123
|
+
if (warnings.length > 0) {
|
|
124
|
+
lines.push("");
|
|
125
|
+
lines.push(`⚠ ${warnings.join("; ")}`);
|
|
41
126
|
}
|
|
42
|
-
return { content: [{ type: "text", text: lines.join("\n") }], details:
|
|
127
|
+
return { content: [{ type: "text", text: lines.join("\n") }], details: firstResult };
|
|
43
128
|
},
|
|
44
129
|
};
|
|
45
130
|
//# sourceMappingURL=reddit-sentiment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reddit-sentiment.js","sourceRoot":"","sources":["../../../src/tools/sentiment/reddit-sentiment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"reddit-sentiment.js","sourceRoot":"","sources":["../../../src/tools/sentiment/reddit-sentiment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACzB,SAAS,EAAE,IAAI,CAAC,QAAQ,CACtB,IAAI,CAAC,MAAM,CAAC;QACV,WAAW,EACT,+FAA+F;KAClG,CAAC,CACH;IACD,KAAK,EAAE,IAAI,CAAC,QAAQ,CAClB,IAAI,CAAC,MAAM,CAAC;QACV,WAAW,EACT,2FAA2F;KAC9F,CAAC,CACH;IACD,UAAU,EAAE,IAAI,CAAC,QAAQ,CACvB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;QACxB,WAAW,EAAE,kEAAkE;KAChF,CAAC,CACH;IACD,KAAK,EAAE,IAAI,CAAC,QAAQ,CAClB,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,sDAAsD,EAAE,CAAC,CACrF;CACF,CAAC,CAAC;AAEH,MAAM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CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC;QAC3H,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IACvF,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
declare const params: import("@sinclair/typebox").TObject<{
|
|
3
|
+
query: import("@sinclair/typebox").TString;
|
|
4
|
+
hours: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const sentimentSummaryTool: AgentTool<typeof params>;
|
|
7
|
+
export {};
|