opencandle 0.4.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/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +19 -3
- package/dist/config.js +61 -2
- package/dist/config.js.map +1 -1
- package/dist/infra/browser.d.ts +1 -3
- package/dist/infra/browser.js +1 -1
- package/dist/infra/browser.js.map +1 -1
- 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/manager.d.ts +9 -0
- package/dist/memory/manager.js +28 -11
- package/dist/memory/manager.js.map +1 -1
- package/dist/memory/storage.d.ts +3 -2
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/types.js +4 -0
- package/dist/memory/types.js.map +1 -1
- package/dist/pi/opencandle-extension.js +230 -36
- package/dist/pi/opencandle-extension.js.map +1 -1
- package/dist/pi/setup.js +10 -0
- package/dist/pi/setup.js.map +1 -1
- package/dist/prompts/context-builder.d.ts +18 -3
- package/dist/prompts/context-builder.js +102 -16
- package/dist/prompts/context-builder.js.map +1 -1
- package/dist/prompts/disclaimer.js +1 -1
- package/dist/prompts/disclaimer.js.map +1 -1
- package/dist/prompts/policy-cards.d.ts +13 -0
- package/dist/prompts/policy-cards.js +197 -0
- package/dist/prompts/policy-cards.js.map +1 -0
- package/dist/prompts/sections.js +3 -3
- package/dist/prompts/sections.js.map +1 -1
- package/dist/prompts/workflow-prompts.js +170 -18
- 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 +134 -3
- 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 +3 -3
- 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 +7 -1
- package/dist/routing/index.js +4 -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-prompt.js +45 -42
- package/dist/routing/router-prompt.js.map +1 -1
- package/dist/routing/router-types.d.ts +9 -0
- package/dist/routing/router.d.ts +1 -0
- package/dist/routing/router.js +456 -12
- package/dist/routing/router.js.map +1 -1
- 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 +20 -2
- package/dist/runtime/session-coordinator.js +47 -14
- package/dist/runtime/session-coordinator.js.map +1 -1
- package/dist/system-prompt.js +4 -1
- package/dist/system-prompt.js.map +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.js +1 -1
- package/dist/tools/fundamentals/comps.js.map +1 -1
- package/dist/tools/fundamentals/dcf.js +1 -1
- package/dist/tools/fundamentals/dcf.js.map +1 -1
- package/dist/tools/fundamentals/earnings.js +1 -1
- package/dist/tools/fundamentals/earnings.js.map +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 +1 -0
- 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 +1 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/macro/fear-greed.js +1 -1
- package/dist/tools/macro/fear-greed.js.map +1 -1
- package/dist/tools/macro/fred-data.js +29 -5
- package/dist/tools/macro/fred-data.js.map +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.js +1 -1
- package/dist/tools/market/crypto-price.js.map +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.js +1 -1
- package/dist/tools/market/stock-history.js.map +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.js +9 -4
- package/dist/tools/options/option-chain.js.map +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.js +1 -1
- package/dist/tools/portfolio/predictions.js.map +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.js +1 -1
- package/dist/tools/portfolio/tracker.js.map +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.js +1 -1
- package/dist/tools/sentiment/reddit-sentiment.js.map +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/twitter-sentiment.js +1 -1
- package/dist/tools/sentiment/twitter-sentiment.js.map +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.js +1 -1
- package/dist/tools/sentiment/web-sentiment.js.map +1 -1
- package/dist/tools/technical/backtest.d.ts +2 -2
- package/dist/tools/technical/backtest.js +41 -27
- package/dist/tools/technical/backtest.js.map +1 -1
- package/dist/tools/technical/indicators.js +1 -3
- 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 +88 -7
- package/dist/workflows/options-screener.js.map +1 -1
- package/dist/workflows/portfolio-builder.js +7 -3
- package/dist/workflows/portfolio-builder.js.map +1 -1
- package/gui/server/ask-user-bridge.ts +82 -0
- package/gui/server/gui-session-manager.ts +5 -0
- package/gui/server/projector.ts +47 -5
- package/gui/server/prompt-observation.ts +61 -0
- package/gui/server/server.ts +119 -8
- package/gui/server/session-entry-wait.ts +81 -0
- package/gui/web/dist/assets/{CatalogOverlay-D1ImSJTe.js → CatalogOverlay-Bmp6Knu7.js} +1 -1
- package/gui/web/dist/assets/index-Bxt9QpLX.css +1 -0
- package/gui/web/dist/assets/index-CZ9DHZYy.js +67 -0
- package/gui/web/dist/index.html +2 -2
- package/package.json +18 -12
- package/src/cli.ts +2 -1
- package/src/config.ts +89 -5
- package/src/infra/browser.ts +1 -1
- package/src/infra/rate-limiter.ts +10 -1
- package/src/memory/manager.ts +43 -10
- package/src/memory/storage.ts +3 -2
- package/src/memory/types.ts +4 -0
- package/src/pi/opencandle-extension.ts +273 -42
- package/src/pi/setup.ts +10 -0
- package/src/prompts/context-builder.ts +128 -17
- package/src/prompts/disclaimer.ts +1 -1
- package/src/prompts/policy-cards.ts +220 -0
- package/src/prompts/sections.ts +3 -3
- package/src/prompts/workflow-prompts.ts +172 -18
- package/src/providers/alpha-vantage.ts +24 -1
- package/src/providers/sec-edgar.ts +220 -4
- package/src/providers/web-search.ts +1 -1
- package/src/providers/yahoo-finance.ts +171 -4
- package/src/routing/classify-intent.ts +94 -3
- package/src/routing/defaults.ts +3 -3
- package/src/routing/entity-extractor.ts +164 -13
- package/src/routing/index.ts +44 -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-prompt.ts +50 -46
- package/src/routing/router-types.ts +21 -0
- package/src/routing/router.ts +511 -12
- package/src/routing/slot-resolver.ts +44 -6
- package/src/routing/turn-context.ts +111 -0
- package/src/routing/types.ts +13 -1
- package/src/runtime/answer-contracts.ts +633 -0
- package/src/runtime/artifact-contracts.ts +76 -0
- package/src/runtime/planning-evidence.ts +591 -0
- package/src/runtime/session-coordinator.ts +78 -12
- package/src/system-prompt.ts +4 -1
- package/src/tools/fundamentals/company-overview.ts +1 -1
- package/src/tools/fundamentals/comps.ts +1 -1
- package/src/tools/fundamentals/dcf.ts +1 -1
- package/src/tools/fundamentals/earnings.ts +1 -1
- package/src/tools/fundamentals/financials.ts +1 -1
- package/src/tools/fundamentals/sec-filings.ts +25 -2
- package/src/tools/index.ts +3 -0
- package/src/tools/macro/fear-greed.ts +1 -1
- package/src/tools/macro/fred-data.ts +31 -5
- package/src/tools/market/crypto-history.ts +18 -2
- package/src/tools/market/crypto-price.ts +1 -1
- package/src/tools/market/search-ticker.ts +1 -1
- package/src/tools/market/stock-history.ts +1 -1
- package/src/tools/market/stock-quote.ts +1 -1
- package/src/tools/options/greeks.ts +0 -1
- package/src/tools/options/option-chain.ts +9 -4
- package/src/tools/portfolio/correlation.ts +1 -1
- package/src/tools/portfolio/holdings-overlap.ts +123 -0
- package/src/tools/portfolio/predictions.ts +1 -1
- package/src/tools/portfolio/risk-analysis.ts +1 -1
- package/src/tools/portfolio/tracker.ts +1 -1
- package/src/tools/portfolio/watchlist.ts +10 -4
- package/src/tools/sentiment/reddit-sentiment.ts +1 -1
- package/src/tools/sentiment/sentiment-summary.ts +62 -2
- package/src/tools/sentiment/twitter-sentiment.ts +1 -1
- package/src/tools/sentiment/web-search.ts +36 -3
- package/src/tools/sentiment/web-sentiment.ts +1 -1
- package/src/tools/technical/backtest.ts +50 -29
- package/src/tools/technical/indicators.ts +1 -3
- package/src/types/options.ts +17 -0
- package/src/types/portfolio.ts +32 -0
- package/src/workflows/compare-assets.ts +38 -2
- package/src/workflows/options-screener.ts +85 -7
- package/src/workflows/portfolio-builder.ts +7 -3
- package/dist/runtime/index.d.ts +0 -16
- package/dist/runtime/index.js +0 -10
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/provider-ids.d.ts +0 -14
- package/dist/runtime/provider-ids.js +0 -14
- package/dist/runtime/provider-ids.js.map +0 -1
- package/gui/web/dist/assets/index-DBrWq43L.css +0 -1
- package/gui/web/dist/assets/index-RflHaj0y.js +0 -67
- package/src/runtime/index.ts +0 -55
- package/src/runtime/provider-ids.ts +0 -15
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
export const ROUTE_KINDS = [
|
|
2
|
+
"workflow_dispatch",
|
|
3
|
+
"agent_task",
|
|
4
|
+
"clarification",
|
|
5
|
+
"pass_through",
|
|
6
|
+
];
|
|
7
|
+
export const TOOL_BUNDLE_TOOLS = {
|
|
8
|
+
core_market: [
|
|
9
|
+
"search_ticker",
|
|
10
|
+
"get_stock_quote",
|
|
11
|
+
"get_stock_history",
|
|
12
|
+
"get_crypto_price",
|
|
13
|
+
"get_crypto_history",
|
|
14
|
+
"get_company_overview",
|
|
15
|
+
"get_financials",
|
|
16
|
+
"get_earnings",
|
|
17
|
+
"compare_companies",
|
|
18
|
+
"compute_dcf",
|
|
19
|
+
"get_technical_indicators",
|
|
20
|
+
"backtest_strategy",
|
|
21
|
+
"analyze_risk",
|
|
22
|
+
"analyze_correlation",
|
|
23
|
+
"analyze_holdings_overlap",
|
|
24
|
+
"track_portfolio",
|
|
25
|
+
"manage_watchlist",
|
|
26
|
+
"track_prediction",
|
|
27
|
+
"search_web",
|
|
28
|
+
],
|
|
29
|
+
options: ["get_option_chain", "get_stock_quote", "search_ticker", "search_web"],
|
|
30
|
+
macro: ["get_economic_data", "get_fear_greed", "search_web"],
|
|
31
|
+
sentiment: [
|
|
32
|
+
"get_reddit_sentiment",
|
|
33
|
+
"get_twitter_sentiment",
|
|
34
|
+
"get_web_sentiment",
|
|
35
|
+
"get_sentiment_trend",
|
|
36
|
+
"get_sentiment_summary",
|
|
37
|
+
"get_fear_greed",
|
|
38
|
+
"search_web",
|
|
39
|
+
],
|
|
40
|
+
sec: ["get_sec_filings", "get_company_overview", "search_web"],
|
|
41
|
+
clarification: ["ask_user"],
|
|
42
|
+
};
|
|
43
|
+
export const ROUTE_CAPABILITY_MANIFEST = {
|
|
44
|
+
workflow_dispatch: {
|
|
45
|
+
routeKind: "workflow_dispatch",
|
|
46
|
+
legacyRoute: "workflow",
|
|
47
|
+
promptPlaybook: "workflow_dispatch",
|
|
48
|
+
toolBundles: ["core_market"],
|
|
49
|
+
memoryScopes: ["investor_profile", "workflow_history"],
|
|
50
|
+
allowWorkflow: true,
|
|
51
|
+
},
|
|
52
|
+
agent_task: {
|
|
53
|
+
routeKind: "agent_task",
|
|
54
|
+
legacyRoute: "fallback",
|
|
55
|
+
promptPlaybook: "agent_task",
|
|
56
|
+
toolBundles: ["core_market"],
|
|
57
|
+
memoryScopes: ["investor_profile", "workflow_history"],
|
|
58
|
+
allowWorkflow: false,
|
|
59
|
+
},
|
|
60
|
+
clarification: {
|
|
61
|
+
routeKind: "clarification",
|
|
62
|
+
legacyRoute: "fallback",
|
|
63
|
+
promptPlaybook: "clarification",
|
|
64
|
+
toolBundles: ["clarification"],
|
|
65
|
+
memoryScopes: ["investor_profile", "workflow_history"],
|
|
66
|
+
allowWorkflow: true,
|
|
67
|
+
},
|
|
68
|
+
pass_through: {
|
|
69
|
+
routeKind: "pass_through",
|
|
70
|
+
legacyRoute: "fallback",
|
|
71
|
+
promptPlaybook: "pass_through",
|
|
72
|
+
toolBundles: [],
|
|
73
|
+
memoryScopes: [],
|
|
74
|
+
allowWorkflow: false,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
export const WORKFLOW_CAPABILITY_MANIFEST = {
|
|
78
|
+
portfolio_builder: {
|
|
79
|
+
workflow: "portfolio_builder",
|
|
80
|
+
dispatchable: true,
|
|
81
|
+
requiredSlots: ["budget"],
|
|
82
|
+
toolBundles: ["core_market", "macro", "sentiment", "clarification"],
|
|
83
|
+
memoryScopes: ["investor_profile", "interaction_feedback", "workflow_history"],
|
|
84
|
+
promptPlaybook: "workflow_dispatch",
|
|
85
|
+
},
|
|
86
|
+
options_screener: {
|
|
87
|
+
workflow: "options_screener",
|
|
88
|
+
dispatchable: true,
|
|
89
|
+
requiredSlots: ["symbol"],
|
|
90
|
+
toolBundles: ["core_market", "options", "sentiment", "clarification"],
|
|
91
|
+
memoryScopes: ["investor_profile", "interaction_feedback", "workflow_history"],
|
|
92
|
+
promptPlaybook: "workflow_dispatch",
|
|
93
|
+
},
|
|
94
|
+
compare_assets: {
|
|
95
|
+
workflow: "compare_assets",
|
|
96
|
+
dispatchable: true,
|
|
97
|
+
requiredSlots: ["symbols"],
|
|
98
|
+
toolBundles: ["core_market", "macro", "sentiment", "clarification"],
|
|
99
|
+
memoryScopes: ["investor_profile", "workflow_history"],
|
|
100
|
+
promptPlaybook: "workflow_dispatch",
|
|
101
|
+
},
|
|
102
|
+
single_asset_analysis: {
|
|
103
|
+
workflow: "single_asset_analysis",
|
|
104
|
+
dispatchable: false,
|
|
105
|
+
requiredSlots: ["symbol"],
|
|
106
|
+
toolBundles: ["core_market", "options", "sentiment", "sec", "clarification"],
|
|
107
|
+
memoryScopes: ["investor_profile", "workflow_history"],
|
|
108
|
+
promptPlaybook: "agent_task",
|
|
109
|
+
},
|
|
110
|
+
watchlist_or_tracking: {
|
|
111
|
+
workflow: "watchlist_or_tracking",
|
|
112
|
+
dispatchable: false,
|
|
113
|
+
requiredSlots: [],
|
|
114
|
+
toolBundles: ["core_market", "clarification"],
|
|
115
|
+
memoryScopes: ["investor_profile", "workflow_history"],
|
|
116
|
+
promptPlaybook: "agent_task",
|
|
117
|
+
},
|
|
118
|
+
general_finance_qa: {
|
|
119
|
+
workflow: "general_finance_qa",
|
|
120
|
+
dispatchable: false,
|
|
121
|
+
requiredSlots: [],
|
|
122
|
+
toolBundles: ["core_market", "macro", "sentiment", "sec", "clarification"],
|
|
123
|
+
memoryScopes: ["investor_profile", "workflow_history"],
|
|
124
|
+
promptPlaybook: "agent_task",
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
export function isRouteKind(value) {
|
|
128
|
+
return ROUTE_KINDS.includes(value);
|
|
129
|
+
}
|
|
130
|
+
export function isToolBundleName(value) {
|
|
131
|
+
return Object.hasOwn(TOOL_BUNDLE_TOOLS, value);
|
|
132
|
+
}
|
|
133
|
+
export function legacyRouteForRouteKind(routeKind) {
|
|
134
|
+
return ROUTE_CAPABILITY_MANIFEST[routeKind].legacyRoute;
|
|
135
|
+
}
|
|
136
|
+
export function isDispatchableWorkflow(workflow) {
|
|
137
|
+
if (!workflow)
|
|
138
|
+
return false;
|
|
139
|
+
return WORKFLOW_CAPABILITY_MANIFEST[workflow]?.dispatchable === true;
|
|
140
|
+
}
|
|
141
|
+
export function routeKindFromLegacyRoute(route, missingRequired = []) {
|
|
142
|
+
if (missingRequired.length > 0)
|
|
143
|
+
return "clarification";
|
|
144
|
+
return route === "workflow" ? "workflow_dispatch" : "agent_task";
|
|
145
|
+
}
|
|
146
|
+
export function workflowRequiredSlots(workflow) {
|
|
147
|
+
if (!workflow)
|
|
148
|
+
return [];
|
|
149
|
+
return WORKFLOW_CAPABILITY_MANIFEST[workflow]?.requiredSlots ?? [];
|
|
150
|
+
}
|
|
151
|
+
export function computeMissingRequiredSlots(workflow, entities, slots = {}, existingMissing = []) {
|
|
152
|
+
const missing = new Set();
|
|
153
|
+
const existing = new Set(existingMissing);
|
|
154
|
+
for (const slot of workflowRequiredSlots(workflow)) {
|
|
155
|
+
if (slot === "budget" && entities.budget === undefined && !slotHasValue(slots.budget)) {
|
|
156
|
+
missing.add("budget");
|
|
157
|
+
}
|
|
158
|
+
if (slot === "symbol" && entities.symbols.length === 0 && !slotHasValue(slots.symbol)) {
|
|
159
|
+
missing.add("symbol");
|
|
160
|
+
}
|
|
161
|
+
if (slot === "symbols" && entities.symbols.length < 2 && !slotHasValue(slots.symbols)) {
|
|
162
|
+
missing.add("symbols");
|
|
163
|
+
}
|
|
164
|
+
existing.delete(slot);
|
|
165
|
+
}
|
|
166
|
+
for (const slot of existing) {
|
|
167
|
+
if (!slotHasValue(slots[slot]))
|
|
168
|
+
missing.add(slot);
|
|
169
|
+
}
|
|
170
|
+
return Array.from(missing);
|
|
171
|
+
}
|
|
172
|
+
function slotHasValue(slot) {
|
|
173
|
+
if (!slot)
|
|
174
|
+
return false;
|
|
175
|
+
if (Array.isArray(slot.value))
|
|
176
|
+
return slot.value.length > 0;
|
|
177
|
+
return slot.value !== undefined && slot.value !== null && slot.value !== "";
|
|
178
|
+
}
|
|
179
|
+
export function selectToolBundles(output) {
|
|
180
|
+
if (output.routeKind === "pass_through")
|
|
181
|
+
return [];
|
|
182
|
+
if (output.routeKind === "clarification")
|
|
183
|
+
return ["clarification"];
|
|
184
|
+
const bundles = new Set();
|
|
185
|
+
const routeBundles = ROUTE_CAPABILITY_MANIFEST[output.routeKind]?.toolBundles ?? [];
|
|
186
|
+
routeBundles.forEach((bundle) => bundles.add(bundle));
|
|
187
|
+
if (output.workflow) {
|
|
188
|
+
const workflow = WORKFLOW_CAPABILITY_MANIFEST[output.workflow];
|
|
189
|
+
workflow?.toolBundles.forEach((bundle) => bundles.add(bundle));
|
|
190
|
+
}
|
|
191
|
+
const metrics = output.entities.compareMetrics ?? [];
|
|
192
|
+
const horizon = output.entities.timeHorizon ?? "";
|
|
193
|
+
if (metrics.includes("macro_hedge") || metrics.includes("interest_rates") || /\b(?:macro|rate|inflation)\b/i.test(horizon)) {
|
|
194
|
+
bundles.add("macro");
|
|
195
|
+
}
|
|
196
|
+
if (output.entities.symbols.length > 0) {
|
|
197
|
+
bundles.add("core_market");
|
|
198
|
+
}
|
|
199
|
+
if (output.entities.optionStrategy) {
|
|
200
|
+
bundles.add("options");
|
|
201
|
+
}
|
|
202
|
+
return Array.from(bundles);
|
|
203
|
+
}
|
|
204
|
+
export function activeToolsForBundles(bundles, availableToolNames) {
|
|
205
|
+
const selected = new Set();
|
|
206
|
+
for (const bundle of bundles) {
|
|
207
|
+
for (const tool of TOOL_BUNDLE_TOOLS[bundle] ?? []) {
|
|
208
|
+
selected.add(tool);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (!availableToolNames)
|
|
212
|
+
return Array.from(selected);
|
|
213
|
+
const available = new Set(availableToolNames);
|
|
214
|
+
return Array.from(selected).filter((tool) => available.has(tool));
|
|
215
|
+
}
|
|
216
|
+
export function memoryScopesForRoute(routeKind, workflow) {
|
|
217
|
+
if (workflow)
|
|
218
|
+
return WORKFLOW_CAPABILITY_MANIFEST[workflow]?.memoryScopes ?? [];
|
|
219
|
+
return ROUTE_CAPABILITY_MANIFEST[routeKind]?.memoryScopes ?? [];
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=route-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-manifest.js","sourceRoot":"","sources":["../../src/routing/route-manifest.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,WAAW,GAA+B;IACrD,mBAAmB;IACnB,YAAY;IACZ,eAAe;IACf,cAAc;CACf,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAA8C;IAC1E,WAAW,EAAE;QACX,eAAe;QACf,iBAAiB;QACjB,mBAAmB;QACnB,kBAAkB;QAClB,oBAAoB;QACpB,sBAAsB;QACtB,gBAAgB;QAChB,cAAc;QACd,mBAAmB;QACnB,aAAa;QACb,0BAA0B;QAC1B,mBAAmB;QACnB,cAAc;QACd,qBAAqB;QACrB,0BAA0B;QAC1B,iBAAiB;QACjB,kBAAkB;QAClB,kBAAkB;QAClB,YAAY;KACb;IACD,OAAO,EAAE,CAAC,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,YAAY,CAAC;IAC/E,KAAK,EAAE,CAAC,mBAAmB,EAAE,gBAAgB,EAAE,YAAY,CAAC;IAC5D,SAAS,EAAE;QACT,sBAAsB;QACtB,uBAAuB;QACvB,mBAAmB;QACnB,qBAAqB;QACrB,uBAAuB;QACvB,gBAAgB;QAChB,YAAY;KACb;IACD,GAAG,EAAE,CAAC,iBAAiB,EAAE,sBAAsB,EAAE,YAAY,CAAC;IAC9D,aAAa,EAAE,CAAC,UAAU,CAAC;CAC5B,CAAC;AA0BF,MAAM,CAAC,MAAM,yBAAyB,GAA6C;IACjF,iBAAiB,EAAE;QACjB,SAAS,EAAE,mBAAmB;QAC9B,WAAW,EAAE,UAAU;QACvB,cAAc,EAAE,mBAAmB;QACnC,WAAW,EAAE,CAAC,aAAa,CAAC;QAC5B,YAAY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IAAI,GAAG,EAAU,CAAC;IACnC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,iBAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YACnD,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,IAAI,CAAC,kBAAkB;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC9C,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,SAA0B,EAC1B,QAAgD;IAEhD,IAAI,QAAQ;QAAE,OAAO,4BAA4B,CAAC,QAAQ,CAAC,EAAE,YAAY,IAAI,EAAE,CAAC;IAChF,OAAO,yBAAyB,CAAC,SAAS,CAAC,EAAE,YAAY,IAAI,EAAE,CAAC;AAClE,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ROUTE_CAPABILITY_MANIFEST, WORKFLOW_CAPABILITY_MANIFEST, } from "./route-manifest.js";
|
|
1
2
|
/**
|
|
2
3
|
* Privacy note — priorTurns rendering:
|
|
3
4
|
* Conversational text rendered into the router prompt via `priorTurns` is NOT
|
|
@@ -8,44 +9,27 @@
|
|
|
8
9
|
* so they no longer reach the router. See
|
|
9
10
|
* `openspec/changes/router-context-and-observability/` for the follow-up.
|
|
10
11
|
*/
|
|
11
|
-
/**
|
|
12
|
-
* List of workflows the router may emit. Keep this in sync with
|
|
13
|
-
* `WorkflowType` in `src/routing/types.ts` minus the `unclassified` sentinel.
|
|
14
|
-
*/
|
|
15
|
-
const WORKFLOW_CATALOG = [
|
|
16
|
-
{
|
|
17
|
-
name: "portfolio_builder",
|
|
18
|
-
when: "user asks to build/allocate a portfolio, invest a budget across positions",
|
|
19
|
-
required: ["budget"],
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
name: "options_screener",
|
|
23
|
-
when: "user asks for options trades / calls / puts on a specific ticker",
|
|
24
|
-
required: ["symbol"],
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: "compare_assets",
|
|
28
|
-
when: "user asks to compare two or more symbols (vs / versus / which is better)",
|
|
29
|
-
required: ["symbols (>=2)"],
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: "single_asset_analysis",
|
|
33
|
-
when: "user asks for a full analysis / deep dive / 'is X attractive' on ONE symbol",
|
|
34
|
-
required: ["symbol"],
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: "watchlist_or_tracking",
|
|
38
|
-
when: "user manages or asks about their saved watchlist / prediction history",
|
|
39
|
-
required: [],
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: "general_finance_qa",
|
|
43
|
-
when: "definitional / conceptual 'what is X', 'explain Y' questions",
|
|
44
|
-
required: [],
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
12
|
function renderCatalog() {
|
|
48
|
-
|
|
13
|
+
const descriptions = {
|
|
14
|
+
portfolio_builder: "user asks to build/allocate a portfolio, invest a budget across positions",
|
|
15
|
+
options_screener: "user asks for options trades / calls / puts on a specific ticker",
|
|
16
|
+
compare_assets: "user asks to compare two or more symbols (vs / versus / which is better)",
|
|
17
|
+
single_asset_analysis: "user asks for a full analysis / deep dive / 'is X attractive' on ONE symbol",
|
|
18
|
+
watchlist_or_tracking: "user manages or asks about their saved watchlist / prediction history",
|
|
19
|
+
general_finance_qa: "definitional / conceptual questions plus broad market structure, sector, industry, monetary policy, and emerging markets research",
|
|
20
|
+
};
|
|
21
|
+
return Object.values(WORKFLOW_CAPABILITY_MANIFEST).map((w) => {
|
|
22
|
+
const required = w.requiredSlots.length > 0
|
|
23
|
+
? ` [required: ${w.requiredSlots.join(", ")}]`
|
|
24
|
+
: "";
|
|
25
|
+
const mode = w.dispatchable ? "dispatchable workflow" : "agent-task workflow label";
|
|
26
|
+
return `- "${w.workflow}" (${mode}): ${descriptions[w.workflow]}${required}`;
|
|
27
|
+
}).join("\n");
|
|
28
|
+
}
|
|
29
|
+
function renderRouteKinds() {
|
|
30
|
+
return Object.values(ROUTE_CAPABILITY_MANIFEST)
|
|
31
|
+
.map((route) => `- "${route.routeKind}" -> legacy route "${route.legacyRoute}"`)
|
|
32
|
+
.join("\n");
|
|
49
33
|
}
|
|
50
34
|
function renderProfile(profile) {
|
|
51
35
|
const entries = Object.entries(profile);
|
|
@@ -70,6 +54,7 @@ function renderRecentRuns(runs) {
|
|
|
70
54
|
const SCHEMA_SPEC = `You MUST respond with a SINGLE JSON object and nothing else (no markdown fences, no prose outside the JSON). The object MUST conform to this TypeScript interface exactly:
|
|
71
55
|
|
|
72
56
|
interface RouterOutput {
|
|
57
|
+
routeKind: "workflow_dispatch" | "agent_task" | "clarification" | "pass_through";
|
|
73
58
|
route: "workflow" | "fallback";
|
|
74
59
|
workflow?: "portfolio_builder" | "options_screener" | "compare_assets" | "single_asset_analysis" | "watchlist_or_tracking" | "general_finance_qa";
|
|
75
60
|
entities: {
|
|
@@ -80,10 +65,16 @@ interface RouterOutput {
|
|
|
80
65
|
riskProfile?: string; // "conservative" | "balanced" | "aggressive"
|
|
81
66
|
direction?: "bullish" | "bearish";
|
|
82
67
|
dteHint?: string;
|
|
68
|
+
optionStrategy?: "covered_call" | "protective_put"; // set when user explicitly asks for a known option strategy
|
|
69
|
+
heldSymbol?: string; // for covered calls/protective puts: ticker the user owns/holds
|
|
70
|
+
catalystSymbols?: string[]; // tickers mentioned as event/catalyst context, not the option-chain underlying
|
|
71
|
+
costBasis?: number; // per-share basis when user says "cost basis is $X"
|
|
72
|
+
shareQuantity?: number; // number of shares owned when stated, e.g. "200 shares"
|
|
73
|
+
compareMetrics?: string[]; // optional compare focus tags, e.g. "sentiment", "macro_hedge"
|
|
83
74
|
};
|
|
84
75
|
slots: Record<string, {
|
|
85
76
|
value: unknown;
|
|
86
|
-
source: "user" | "preference" | "default"
|
|
77
|
+
source: "user" | "preference" | "default" | "prior_context" | "memory";
|
|
87
78
|
confidence: "high" | "medium" | "low";
|
|
88
79
|
}>;
|
|
89
80
|
preference_updates: Array<{
|
|
@@ -93,17 +84,26 @@ interface RouterOutput {
|
|
|
93
84
|
source: "inferred";
|
|
94
85
|
}>;
|
|
95
86
|
missing_required: string[]; // required slot names the turn/profile/defaults did not fill
|
|
87
|
+
tool_bundles: Array<"core_market" | "options" | "macro" | "sentiment" | "sec" | "clarification">;
|
|
88
|
+
diagnostics: Array<{ code: string; message: string }>;
|
|
96
89
|
reasoning: string; // one or two short sentences; used for debugging only
|
|
97
90
|
}`;
|
|
98
91
|
const ROUTING_RULES = `Routing rules:
|
|
99
|
-
- Choose
|
|
100
|
-
-
|
|
101
|
-
-
|
|
102
|
-
-
|
|
92
|
+
- Choose routeKind = "workflow_dispatch" ONLY when the turn clearly matches a dispatchable workflow (portfolio_builder, options_screener, or compare_assets) AND required slots are filled from the turn, trusted prior context, or profile snapshot.
|
|
93
|
+
- For single_asset_analysis, watchlist_or_tracking, and general_finance_qa, set routeKind = "agent_task" even when you set the workflow label. These are workflow labels for prompt/tool policy, not structured workflow dispatch.
|
|
94
|
+
- Choose routeKind = "agent_task" for in-scope finance work that should be answered by the main agent, including simple data fetches like "AAPL quote" and open-ended questions like "entry levels on ASTS for 6 months".
|
|
95
|
+
- Choose routeKind = "clarification" when required slots are missing (e.g. options workflow needs a symbol, portfolio needs a budget). List specific slot names in missing_required. The main agent will use ask_user to collect them.
|
|
96
|
+
- Choose routeKind = "pass_through" when the request is outside OpenCandle's finance task surface.
|
|
97
|
+
- Set legacy route = "workflow" only for routeKind = "workflow_dispatch"; otherwise set legacy route = "fallback".
|
|
98
|
+
- DO NOT invent a "direct_tool" route. Tool execution belongs to the main agent.
|
|
99
|
+
- For covered call prompts, distinguish the owned underlying from catalyst tickers. Put the owned symbol first in symbols, set heldSymbol to the owned symbol, put event/context tickers in catalystSymbols, set workflow="options_screener", and preserve costBasis if stated.
|
|
100
|
+
- For protective put prompts, treat the owned/held ticker as the option-chain underlying, set optionStrategy="protective_put", direction="bearish", and preserve shareQuantity if stated. This is a hedge on an existing long share position, not a bullish call screen.
|
|
103
101
|
- Source attribution rules (per-slot source field):
|
|
104
102
|
- source = "user": the value came from THIS turn's text.
|
|
105
103
|
- source = "preference": the value came from profileSnapshot (not this turn).
|
|
106
104
|
- source = "default": a sensible default was applied (workflow fallback).
|
|
105
|
+
- source = "prior_context": the value came from prior conversation turns.
|
|
106
|
+
- source = "memory": the value came from retrieved non-profile memory.
|
|
107
107
|
- Preference updates:
|
|
108
108
|
- Emit preference_updates ONLY for stable user-dispositions stated (or very strongly implied) in the current turn. E.g. "I'm aggressive" → risk_profile=aggressive, high.
|
|
109
109
|
- Do NOT emit preference_updates that merely echo profileSnapshot.
|
|
@@ -112,6 +112,9 @@ const ROUTING_RULES = `Routing rules:
|
|
|
112
112
|
export function buildRouterPrompt(input) {
|
|
113
113
|
return `You are OpenCandle's routing agent. Your job is to classify the user's turn into one of the known workflows (or fallback), extract entities + per-slot provenance, and surface any stable preferences the user expressed. Your output feeds the main analyst agent — it does NOT go to the user.
|
|
114
114
|
|
|
115
|
+
ROUTE KINDS:
|
|
116
|
+
${renderRouteKinds()}
|
|
117
|
+
|
|
115
118
|
WORKFLOW CATALOG:
|
|
116
119
|
${renderCatalog()}
|
|
117
120
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-prompt.js","sourceRoot":"","sources":["../../src/routing/router-prompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router-prompt.js","sourceRoot":"","sources":["../../src/routing/router-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,4BAA4B,GAC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Aa;;;;;EAKb,aAAa,CAAC,KAAK,CAAC,eAAe,CAAC;;;EAGpC,gBAAgB,CAAC,KAAK,CAAC,kBAAkB,CAAC;;;EAG1C,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC;;;EAGlC,KAAK,CAAC,IAAI;;4CAEgC,CAAC;AAC7C,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ExtractedEntities, SlotSource, WorkflowType } from "./types.js";
|
|
2
2
|
export type RouterRoute = "workflow" | "fallback";
|
|
3
|
+
export type RouterRouteKind = "workflow_dispatch" | "agent_task" | "clarification" | "pass_through";
|
|
4
|
+
export type ToolBundleName = "core_market" | "options" | "macro" | "sentiment" | "sec" | "clarification";
|
|
3
5
|
export type RouterConfidence = "high" | "medium" | "low";
|
|
4
6
|
export interface RouterSlot {
|
|
5
7
|
value: unknown;
|
|
@@ -12,6 +14,10 @@ export interface RouterPreferenceUpdate {
|
|
|
12
14
|
confidence: RouterConfidence;
|
|
13
15
|
source: "inferred";
|
|
14
16
|
}
|
|
17
|
+
export interface RouterDiagnostic {
|
|
18
|
+
code: string;
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
15
21
|
/**
|
|
16
22
|
* Structured output from the LLM router. Mirrors existing types
|
|
17
23
|
* (`ClassificationResult`, `ExtractedEntities`, `SlotSource`) so downstream
|
|
@@ -21,12 +27,15 @@ export interface RouterPreferenceUpdate {
|
|
|
21
27
|
* routes, `workflow_type` at the storage layer is the sentinel `"fallback"`.
|
|
22
28
|
*/
|
|
23
29
|
export interface RouterOutput {
|
|
30
|
+
routeKind: RouterRouteKind;
|
|
24
31
|
route: RouterRoute;
|
|
25
32
|
workflow?: Exclude<WorkflowType, "unclassified">;
|
|
26
33
|
entities: ExtractedEntities;
|
|
27
34
|
slots: Record<string, RouterSlot>;
|
|
28
35
|
preference_updates: RouterPreferenceUpdate[];
|
|
29
36
|
missing_required: string[];
|
|
37
|
+
tool_bundles: ToolBundleName[];
|
|
38
|
+
diagnostics: RouterDiagnostic[];
|
|
30
39
|
reasoning: string;
|
|
31
40
|
}
|
|
32
41
|
/** Context passed into the router on each turn. */
|
package/dist/routing/router.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ import type { RouterInputContext, RouterLlmClient, RouterOutput } from "./router
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function route(input: RouterInputContext, client: RouterLlmClient): Promise<RouterOutput>;
|
|
10
10
|
export declare function validateRouterOutput(raw: string): RouterOutput;
|
|
11
|
+
export declare function postProcessRouterOutput(text: string, output: RouterOutput): RouterOutput;
|