@zhive/cli 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/README.md +118 -0
- package/dist/agent/analysis.js +160 -0
- package/dist/agent/app.js +122 -0
- package/dist/agent/chat-prompt.js +65 -0
- package/dist/agent/commands/registry.js +12 -0
- package/dist/agent/components/AsciiTicker.js +81 -0
- package/dist/agent/components/CommandInput.js +65 -0
- package/dist/agent/components/HoneycombBoot.js +291 -0
- package/dist/agent/components/Spinner.js +37 -0
- package/dist/agent/config.js +75 -0
- package/dist/agent/edit-section.js +59 -0
- package/dist/agent/fetch-rules.js +21 -0
- package/dist/agent/helpers.js +22 -0
- package/dist/agent/hooks/useAgent.js +480 -0
- package/dist/agent/memory-prompt.js +47 -0
- package/dist/agent/model.js +92 -0
- package/dist/agent/objects.js +1 -0
- package/dist/agent/process-lifecycle.js +18 -0
- package/dist/agent/prompt.js +353 -0
- package/dist/agent/run-headless.js +189 -0
- package/dist/agent/skills/index.js +2 -0
- package/dist/agent/skills/skill-parser.js +149 -0
- package/dist/agent/skills/types.js +1 -0
- package/dist/agent/theme.js +41 -0
- package/dist/agent/tools/index.js +76 -0
- package/dist/agent/tools/market/client.js +41 -0
- package/dist/agent/tools/market/index.js +3 -0
- package/dist/agent/tools/market/tools.js +518 -0
- package/dist/agent/tools/mindshare/client.js +124 -0
- package/dist/agent/tools/mindshare/index.js +3 -0
- package/dist/agent/tools/mindshare/tools.js +563 -0
- package/dist/agent/tools/read-skill-tool.js +30 -0
- package/dist/agent/tools/ta/index.js +1 -0
- package/dist/agent/tools/ta/indicators.js +201 -0
- package/dist/agent/types.js +1 -0
- package/dist/agents.js +110 -0
- package/dist/ai-providers.js +66 -0
- package/dist/avatar.js +34 -0
- package/dist/backtest/default-backtest-data.js +200 -0
- package/dist/backtest/fetch.js +41 -0
- package/dist/backtest/import.js +106 -0
- package/dist/backtest/index.js +10 -0
- package/dist/backtest/results.js +113 -0
- package/dist/backtest/runner.js +134 -0
- package/dist/backtest/storage.js +11 -0
- package/dist/backtest/types.js +1 -0
- package/dist/commands/create/ai-generate.js +126 -0
- package/dist/commands/create/commands/index.js +10 -0
- package/dist/commands/create/generate.js +73 -0
- package/dist/commands/create/presets/data.js +225 -0
- package/dist/commands/create/presets/formatting.js +81 -0
- package/dist/commands/create/presets/index.js +3 -0
- package/dist/commands/create/presets/options.js +307 -0
- package/dist/commands/create/presets/types.js +1 -0
- package/dist/commands/create/presets.js +613 -0
- package/dist/commands/create/ui/CreateApp.js +172 -0
- package/dist/commands/create/ui/steps/ApiKeyStep.js +89 -0
- package/dist/commands/create/ui/steps/AvatarStep.js +16 -0
- package/dist/commands/create/ui/steps/DoneStep.js +14 -0
- package/dist/commands/create/ui/steps/IdentityStep.js +125 -0
- package/dist/commands/create/ui/steps/NameStep.js +148 -0
- package/dist/commands/create/ui/steps/ScaffoldStep.js +59 -0
- package/dist/commands/create/ui/steps/SoulStep.js +21 -0
- package/dist/commands/create/ui/steps/StrategyStep.js +20 -0
- package/dist/commands/create/ui/steps/StreamingGenerationStep.js +56 -0
- package/dist/commands/create/ui/validation.js +34 -0
- package/dist/commands/create/validate-api-key.js +27 -0
- package/dist/commands/install.js +50 -0
- package/dist/commands/list/commands/index.js +7 -0
- package/dist/commands/list/ui/ListApp.js +79 -0
- package/dist/commands/migrate-templates/commands/index.js +9 -0
- package/dist/commands/migrate-templates/migrate.js +87 -0
- package/dist/commands/migrate-templates/ui/MigrateApp.js +132 -0
- package/dist/commands/run/commands/index.js +17 -0
- package/dist/commands/run/run-headless.js +111 -0
- package/dist/commands/shared/theme.js +57 -0
- package/dist/commands/shared/welcome.js +304 -0
- package/dist/commands/start/commands/backtest.js +35 -0
- package/dist/commands/start/commands/index.js +62 -0
- package/dist/commands/start/commands/prediction.js +73 -0
- package/dist/commands/start/commands/skills.js +44 -0
- package/dist/commands/start/commands/skills.test.js +140 -0
- package/dist/commands/start/hooks/types.js +1 -0
- package/dist/commands/start/hooks/useAgent.js +177 -0
- package/dist/commands/start/hooks/useChat.js +266 -0
- package/dist/commands/start/hooks/usePollActivity.js +45 -0
- package/dist/commands/start/hooks/utils.js +152 -0
- package/dist/commands/start/services/backtest/default-backtest-data.js +200 -0
- package/dist/commands/start/services/backtest/fetch.js +42 -0
- package/dist/commands/start/services/backtest/import.js +109 -0
- package/dist/commands/start/services/backtest/index.js +10 -0
- package/dist/commands/start/services/backtest/results.js +113 -0
- package/dist/commands/start/services/backtest/runner.js +103 -0
- package/dist/commands/start/services/backtest/storage.js +11 -0
- package/dist/commands/start/services/backtest/types.js +1 -0
- package/dist/commands/start/services/command-registry.js +13 -0
- package/dist/commands/start/ui/AsciiTicker.js +81 -0
- package/dist/commands/start/ui/CommandInput.js +65 -0
- package/dist/commands/start/ui/HoneycombBoot.js +291 -0
- package/dist/commands/start/ui/PollText.js +23 -0
- package/dist/commands/start/ui/PredictionsPanel.js +88 -0
- package/dist/commands/start/ui/SelectAgentApp.js +93 -0
- package/dist/commands/start/ui/Spinner.js +29 -0
- package/dist/commands/start/ui/SpinnerContext.js +20 -0
- package/dist/commands/start/ui/app.js +36 -0
- package/dist/commands/start-all/AgentProcessManager.js +98 -0
- package/dist/commands/start-all/commands/index.js +24 -0
- package/dist/commands/start-all/ui/Dashboard.js +91 -0
- package/dist/components/AsciiTicker.js +81 -0
- package/dist/components/CharacterSummaryCard.js +33 -0
- package/dist/components/CodeBlock.js +11 -0
- package/dist/components/ColoredStats.js +18 -0
- package/dist/components/Header.js +10 -0
- package/dist/components/HoneycombLoader.js +190 -0
- package/dist/components/InputGuard.js +6 -0
- package/dist/components/MultiSelectPrompt.js +45 -0
- package/dist/components/SelectPrompt.js +20 -0
- package/dist/components/Spinner.js +16 -0
- package/dist/components/StepIndicator.js +31 -0
- package/dist/components/StreamingText.js +50 -0
- package/dist/components/TextPrompt.js +28 -0
- package/dist/components/stdout-spinner.js +48 -0
- package/dist/config.js +28 -0
- package/dist/create/CreateApp.js +153 -0
- package/dist/create/ai-generate.js +147 -0
- package/dist/create/generate.js +73 -0
- package/dist/create/steps/ApiKeyStep.js +97 -0
- package/dist/create/steps/AvatarStep.js +16 -0
- package/dist/create/steps/BioStep.js +14 -0
- package/dist/create/steps/DoneStep.js +14 -0
- package/dist/create/steps/IdentityStep.js +163 -0
- package/dist/create/steps/NameStep.js +71 -0
- package/dist/create/steps/ScaffoldStep.js +58 -0
- package/dist/create/steps/SoulStep.js +58 -0
- package/dist/create/steps/StrategyStep.js +58 -0
- package/dist/create/validate-api-key.js +47 -0
- package/dist/create/welcome.js +304 -0
- package/dist/index.js +60 -0
- package/dist/list/ListApp.js +79 -0
- package/dist/load-agent-env.js +30 -0
- package/dist/migrate-templates/MigrateApp.js +131 -0
- package/dist/migrate-templates/migrate.js +86 -0
- package/dist/presets.js +613 -0
- package/dist/shared/agent/agent-runtime.js +144 -0
- package/dist/shared/agent/analysis.js +171 -0
- package/dist/shared/agent/helpers.js +1 -0
- package/dist/shared/agent/prompts/chat-prompt.js +60 -0
- package/dist/shared/agent/prompts/megathread.js +202 -0
- package/dist/shared/agent/prompts/memory-prompt.js +47 -0
- package/dist/shared/agent/prompts/prompt.js +18 -0
- package/dist/shared/agent/skills/index.js +2 -0
- package/dist/shared/agent/skills/skill-parser.js +167 -0
- package/dist/shared/agent/skills/skill-parser.test.js +190 -0
- package/dist/shared/agent/skills/types.js +1 -0
- package/dist/shared/agent/tools/edit-section.js +60 -0
- package/dist/shared/agent/tools/execute-skill-tool.js +134 -0
- package/dist/shared/agent/tools/fetch-rules.js +22 -0
- package/dist/shared/agent/tools/formatting.js +48 -0
- package/dist/shared/agent/tools/index.js +87 -0
- package/dist/shared/agent/tools/market/client.js +41 -0
- package/dist/shared/agent/tools/market/index.js +3 -0
- package/dist/shared/agent/tools/market/tools.js +497 -0
- package/dist/shared/agent/tools/mindshare/client.js +124 -0
- package/dist/shared/agent/tools/mindshare/index.js +3 -0
- package/dist/shared/agent/tools/mindshare/tools.js +167 -0
- package/dist/shared/agent/tools/read-skill-tool.js +30 -0
- package/dist/shared/agent/tools/ta/index.js +1 -0
- package/dist/shared/agent/tools/ta/indicators.js +201 -0
- package/dist/shared/agent/types.js +1 -0
- package/dist/shared/agent/utils.js +43 -0
- package/dist/shared/config/agent.js +177 -0
- package/dist/shared/config/ai-providers.js +156 -0
- package/dist/shared/config/config.js +22 -0
- package/dist/shared/config/constant.js +8 -0
- package/dist/shared/config/env-loader.js +30 -0
- package/dist/shared/types.js +1 -0
- package/dist/start/AgentProcessManager.js +98 -0
- package/dist/start/Dashboard.js +92 -0
- package/dist/start/SelectAgentApp.js +81 -0
- package/dist/start/StartApp.js +189 -0
- package/dist/start/patch-headless.js +101 -0
- package/dist/start/patch-managed-mode.js +142 -0
- package/dist/start/start-command.js +24 -0
- package/dist/theme.js +54 -0
- package/package.json +68 -0
- package/templates/components/HoneycombBoot.tsx +343 -0
- package/templates/fetch-rules.ts +23 -0
- package/templates/skills/mindshare/SKILL.md +197 -0
- package/templates/skills/ta/SKILL.md +179 -0
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import { tool } from 'ai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getMindshareClient, } from './client.js';
|
|
4
|
+
const timeframeSchema = z
|
|
5
|
+
.enum(['30m', '24h', '3D', '7D', '1M', '3M', 'YTD'])
|
|
6
|
+
.optional()
|
|
7
|
+
.describe('Timeframe for mindshare data. Defaults to 24h.');
|
|
8
|
+
const rankBySchema = z
|
|
9
|
+
.enum(['delta', 'value'])
|
|
10
|
+
.optional()
|
|
11
|
+
.describe('Rank by "delta" (change) or "value" (absolute). Defaults to value.');
|
|
12
|
+
const limitSchema = z
|
|
13
|
+
.number()
|
|
14
|
+
.int()
|
|
15
|
+
.min(1)
|
|
16
|
+
.max(100)
|
|
17
|
+
.optional()
|
|
18
|
+
.describe('Number of results to return (max 100). Defaults to 20.');
|
|
19
|
+
function formatMindshare(ms) {
|
|
20
|
+
const value = ms?.value != null ? `${(ms.value * 100).toFixed(4)}%` : 'N/A';
|
|
21
|
+
const rawDelta = ms?.delta ?? 0;
|
|
22
|
+
const deltaSign = rawDelta >= 0 ? '+' : '';
|
|
23
|
+
const delta = `${deltaSign}${(rawDelta * 100).toFixed(2)}%`;
|
|
24
|
+
const rank = ms?.rank != null ? `#${ms.rank}` : 'N/A';
|
|
25
|
+
return { value, delta, rank };
|
|
26
|
+
}
|
|
27
|
+
export const getProjectLeaderboardTool = tool({
|
|
28
|
+
description: 'Get the top trending projects by mindshare. Returns a ranked list of projects sorted by mindshare value or delta change. Use this to identify what projects are gaining attention.',
|
|
29
|
+
inputSchema: z.object({
|
|
30
|
+
timeframe: timeframeSchema,
|
|
31
|
+
rankBy: rankBySchema,
|
|
32
|
+
limit: limitSchema,
|
|
33
|
+
}),
|
|
34
|
+
execute: async ({ timeframe, rankBy, limit }) => {
|
|
35
|
+
try {
|
|
36
|
+
const client = getMindshareClient();
|
|
37
|
+
const data = await client.getProjectLeaderboard(timeframe, rankBy, limit);
|
|
38
|
+
if (data.length === 0) {
|
|
39
|
+
return 'No projects found in the mindshare leaderboard.';
|
|
40
|
+
}
|
|
41
|
+
const lines = [
|
|
42
|
+
`Top ${data.length} Projects by Mindshare (${timeframe ?? '24h'}, ranked by ${rankBy ?? 'value'}):`,
|
|
43
|
+
'',
|
|
44
|
+
'Rank | Project | Mindshare | Delta',
|
|
45
|
+
'--- | --- | --- | ---',
|
|
46
|
+
];
|
|
47
|
+
for (const item of data) {
|
|
48
|
+
const ms = formatMindshare(item.mindshare);
|
|
49
|
+
lines.push(`${ms.rank} | ${item.name} | ${ms.value} | ${ms.delta}`);
|
|
50
|
+
}
|
|
51
|
+
const output = lines.join('\n');
|
|
52
|
+
return output;
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
56
|
+
return `Error fetching project leaderboard: ${message}`;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
export const getProjectMindshareTool = tool({
|
|
61
|
+
description: 'Get the mindshare data for a specific project by ID. Returns current mindshare value, delta change, and ranking position.',
|
|
62
|
+
inputSchema: z.object({
|
|
63
|
+
projectId: z.string().describe('The project ID to look up.'),
|
|
64
|
+
timeframe: timeframeSchema,
|
|
65
|
+
}),
|
|
66
|
+
execute: async ({ projectId, timeframe }) => {
|
|
67
|
+
try {
|
|
68
|
+
const client = getMindshareClient();
|
|
69
|
+
const data = await client.getProjectMindshare(projectId, timeframe);
|
|
70
|
+
const ms = formatMindshare(data.mindshare);
|
|
71
|
+
const lines = [
|
|
72
|
+
`Mindshare for ${data.name ?? projectId} (${timeframe ?? '24h'}):`,
|
|
73
|
+
'',
|
|
74
|
+
`- Rank: ${ms.rank}`,
|
|
75
|
+
`- Mindshare Value: ${ms.value}`,
|
|
76
|
+
`- Delta Change: ${ms.delta}`,
|
|
77
|
+
];
|
|
78
|
+
if (data.symbol) {
|
|
79
|
+
lines.push(`- Symbol: ${data.symbol}`);
|
|
80
|
+
}
|
|
81
|
+
const output = lines.join('\n');
|
|
82
|
+
return output;
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
86
|
+
return `Error fetching project mindshare: ${message}`;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
export const getProjectMindshareTimeseriesTool = tool({
|
|
91
|
+
description: 'Get historical mindshare data for a specific project. Returns timeseries data points showing mindshare value over time.',
|
|
92
|
+
inputSchema: z.object({
|
|
93
|
+
projectId: z.string().describe('The project ID to look up.'),
|
|
94
|
+
timeframe: timeframeSchema,
|
|
95
|
+
}),
|
|
96
|
+
execute: async ({ projectId, timeframe }) => {
|
|
97
|
+
try {
|
|
98
|
+
const client = getMindshareClient();
|
|
99
|
+
const data = await client.getProjectMindshareTimeseries(projectId, timeframe);
|
|
100
|
+
if (!data.data_points || data.data_points.length === 0) {
|
|
101
|
+
return `No historical mindshare data available for project ${projectId}.`;
|
|
102
|
+
}
|
|
103
|
+
const points = data.data_points;
|
|
104
|
+
const lines = [
|
|
105
|
+
`Mindshare Timeseries for ${projectId} (${timeframe ?? '24h'}, ${points.length} data points):`,
|
|
106
|
+
'',
|
|
107
|
+
];
|
|
108
|
+
const maxDisplay = 20;
|
|
109
|
+
const displayPoints = points.length > maxDisplay ? [...points.slice(0, 5), null, ...points.slice(-10)] : points;
|
|
110
|
+
for (const point of displayPoints) {
|
|
111
|
+
if (point === null) {
|
|
112
|
+
lines.push(`... (${points.length - 15} more points) ...`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const date = new Date(point.timestamp).toISOString();
|
|
116
|
+
lines.push(`${date}: ${(point.value * 100).toFixed(4)}%`);
|
|
117
|
+
}
|
|
118
|
+
const firstValue = points[0].value;
|
|
119
|
+
const lastValue = points[points.length - 1].value;
|
|
120
|
+
const changePercent = ((lastValue - firstValue) / firstValue) * 100;
|
|
121
|
+
const sign = changePercent >= 0 ? '+' : '';
|
|
122
|
+
lines.push('');
|
|
123
|
+
lines.push(`Period change: ${sign}${changePercent.toFixed(2)}%`);
|
|
124
|
+
const output = lines.join('\n');
|
|
125
|
+
return output;
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
129
|
+
return `Error fetching project mindshare timeseries: ${message}`;
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
export const getProjectLeaderboardBySectorTool = tool({
|
|
134
|
+
description: 'Get the top projects within a specific sector by mindshare. Use this to analyze which projects are gaining attention in a particular market segment.',
|
|
135
|
+
inputSchema: z.object({
|
|
136
|
+
sectorId: z.string().describe('The sector ID to filter by.'),
|
|
137
|
+
timeframe: timeframeSchema,
|
|
138
|
+
rankBy: rankBySchema,
|
|
139
|
+
limit: limitSchema,
|
|
140
|
+
filterBy: z
|
|
141
|
+
.enum(['all', 'preTGE', 'nonePreTGE'])
|
|
142
|
+
.optional()
|
|
143
|
+
.describe('Filter by project stage: all, preTGE (pre-token launch), or nonePreTGE.'),
|
|
144
|
+
}),
|
|
145
|
+
execute: async ({ sectorId, timeframe, rankBy, limit, filterBy }) => {
|
|
146
|
+
try {
|
|
147
|
+
const client = getMindshareClient();
|
|
148
|
+
const data = await client.getProjectLeaderboardBySector(sectorId, timeframe, rankBy, limit, filterBy);
|
|
149
|
+
if (data.length === 0) {
|
|
150
|
+
return `No projects found in sector ${sectorId}.`;
|
|
151
|
+
}
|
|
152
|
+
const lines = [
|
|
153
|
+
`Top ${data.length} Projects in Sector "${sectorId}" (${timeframe ?? '24h'}, ranked by ${rankBy ?? 'value'}):`,
|
|
154
|
+
'',
|
|
155
|
+
'Rank | Project | Mindshare | Delta',
|
|
156
|
+
'--- | --- | --- | ---',
|
|
157
|
+
];
|
|
158
|
+
for (const item of data) {
|
|
159
|
+
const ms = formatMindshare(item.mindshare);
|
|
160
|
+
lines.push(`${ms.rank} | ${item.name} | ${ms.value} | ${ms.delta}`);
|
|
161
|
+
}
|
|
162
|
+
const output = lines.join('\n');
|
|
163
|
+
return output;
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
167
|
+
return `Error fetching sector project leaderboard: ${message}`;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
export const getSectorLeaderboardTool = tool({
|
|
172
|
+
description: 'Get the top sectors by mindshare. Returns a ranked list of market sectors (e.g., DeFi, Gaming, AI) sorted by mindshare. Use this to identify trending market themes.',
|
|
173
|
+
inputSchema: z.object({
|
|
174
|
+
timeframe: timeframeSchema,
|
|
175
|
+
rankBy: rankBySchema,
|
|
176
|
+
limit: limitSchema,
|
|
177
|
+
}),
|
|
178
|
+
execute: async ({ timeframe, rankBy, limit }) => {
|
|
179
|
+
try {
|
|
180
|
+
const client = getMindshareClient();
|
|
181
|
+
const data = await client.getSectorLeaderboard(timeframe, rankBy, limit);
|
|
182
|
+
if (data.length === 0) {
|
|
183
|
+
return 'No sectors found in the mindshare leaderboard.';
|
|
184
|
+
}
|
|
185
|
+
const lines = [
|
|
186
|
+
`Top ${data.length} Sectors by Mindshare (${timeframe ?? '24h'}, ranked by ${rankBy ?? 'value'}):`,
|
|
187
|
+
'',
|
|
188
|
+
'Rank | Sector | Mindshare | Delta',
|
|
189
|
+
'--- | --- | --- | ---',
|
|
190
|
+
];
|
|
191
|
+
for (const item of data) {
|
|
192
|
+
const ms = formatMindshare(item.mindshare);
|
|
193
|
+
lines.push(`${ms.rank} | ${item.id} | ${ms.value} | ${ms.delta}`);
|
|
194
|
+
}
|
|
195
|
+
const output = lines.join('\n');
|
|
196
|
+
return output;
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
200
|
+
return `Error fetching sector leaderboard: ${message}`;
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
export const getSectorMindshareTool = tool({
|
|
205
|
+
description: 'Get the mindshare data for a specific sector by ID. Returns current mindshare value, delta change, and historical timeseries.',
|
|
206
|
+
inputSchema: z.object({
|
|
207
|
+
sectorId: z.string().describe('The sector ID to look up.'),
|
|
208
|
+
timeframe: timeframeSchema,
|
|
209
|
+
}),
|
|
210
|
+
execute: async ({ sectorId, timeframe }) => {
|
|
211
|
+
try {
|
|
212
|
+
const client = getMindshareClient();
|
|
213
|
+
const data = await client.getSectorMindshare(sectorId, timeframe);
|
|
214
|
+
const ms = formatMindshare(data.mindshare);
|
|
215
|
+
const lines = [
|
|
216
|
+
`Mindshare for Sector "${sectorId}" (${timeframe ?? '24h'}):`,
|
|
217
|
+
'',
|
|
218
|
+
`- Mindshare Value: ${ms.value}`,
|
|
219
|
+
`- Delta Change: ${ms.delta}`,
|
|
220
|
+
];
|
|
221
|
+
const output = lines.join('\n');
|
|
222
|
+
return output;
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
226
|
+
return `Error fetching sector mindshare: ${message}`;
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
export const getSectorMindshareTimeseriesTool = tool({
|
|
231
|
+
description: 'Get historical mindshare data for a specific sector. Returns timeseries data points showing sector mindshare value over time.',
|
|
232
|
+
inputSchema: z.object({
|
|
233
|
+
sectorId: z.string().describe('The sector ID to look up.'),
|
|
234
|
+
timeframe: timeframeSchema,
|
|
235
|
+
}),
|
|
236
|
+
execute: async ({ sectorId, timeframe }) => {
|
|
237
|
+
try {
|
|
238
|
+
const client = getMindshareClient();
|
|
239
|
+
const data = await client.getSectorMindshareTimeseries(sectorId, timeframe);
|
|
240
|
+
if (data.length === 0) {
|
|
241
|
+
return `No historical mindshare data available for sector ${sectorId}.`;
|
|
242
|
+
}
|
|
243
|
+
const lines = [
|
|
244
|
+
`Mindshare Timeseries for Sector "${sectorId}" (${timeframe ?? '24h'}, ${data.length} data points):`,
|
|
245
|
+
'',
|
|
246
|
+
];
|
|
247
|
+
const maxDisplay = 20;
|
|
248
|
+
const displayPoints = data.length > maxDisplay ? [...data.slice(0, 5), null, ...data.slice(-10)] : data;
|
|
249
|
+
for (const point of displayPoints) {
|
|
250
|
+
if (point === null) {
|
|
251
|
+
lines.push(`... (${data.length - 15} more points) ...`);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const date = new Date(point.timestamp).toISOString();
|
|
255
|
+
lines.push(`${date}: ${(point.value * 100).toFixed(4)}%`);
|
|
256
|
+
}
|
|
257
|
+
const firstValue = data[0].value;
|
|
258
|
+
const lastValue = data[data.length - 1].value;
|
|
259
|
+
const changePercent = ((lastValue - firstValue) / firstValue) * 100;
|
|
260
|
+
const sign = changePercent >= 0 ? '+' : '';
|
|
261
|
+
lines.push('');
|
|
262
|
+
lines.push(`Period change: ${sign}${changePercent.toFixed(2)}%`);
|
|
263
|
+
const output = lines.join('\n');
|
|
264
|
+
return output;
|
|
265
|
+
}
|
|
266
|
+
catch (err) {
|
|
267
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
268
|
+
return `Error fetching sector mindshare timeseries: ${message}`;
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
export const getUserLeaderboardTool = tool({
|
|
273
|
+
description: 'Get the top users (KOLs/influencers) by mindshare. Returns a ranked list of users who drive the most social attention. Use this to identify key opinion leaders.',
|
|
274
|
+
inputSchema: z.object({
|
|
275
|
+
timeframe: timeframeSchema,
|
|
276
|
+
rankBy: rankBySchema,
|
|
277
|
+
limit: limitSchema,
|
|
278
|
+
page: z.number().int().min(1).optional().describe('Page number for pagination. Defaults to 1.'),
|
|
279
|
+
}),
|
|
280
|
+
execute: async ({ timeframe, rankBy, limit, page }) => {
|
|
281
|
+
try {
|
|
282
|
+
const client = getMindshareClient();
|
|
283
|
+
const data = await client.getUserLeaderboard(timeframe, rankBy, limit, page);
|
|
284
|
+
if (data.length === 0) {
|
|
285
|
+
return 'No users found in the mindshare leaderboard.';
|
|
286
|
+
}
|
|
287
|
+
const lines = [
|
|
288
|
+
`Top ${data.length} Users by Mindshare (${timeframe ?? '24h'}, ranked by ${rankBy ?? 'value'}):`,
|
|
289
|
+
'',
|
|
290
|
+
'Rank | User | Mindshare | Delta',
|
|
291
|
+
'--- | --- | --- | ---',
|
|
292
|
+
];
|
|
293
|
+
for (const item of data) {
|
|
294
|
+
const ms = formatMindshare(item.mindshare);
|
|
295
|
+
const displayName = item.name || item.username;
|
|
296
|
+
lines.push(`${ms.rank} | @${item.username} (${displayName}) | ${ms.value} | ${ms.delta}`);
|
|
297
|
+
}
|
|
298
|
+
const output = lines.join('\n');
|
|
299
|
+
return output;
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
303
|
+
return `Error fetching user leaderboard: ${message}`;
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
export const getUserLeaderboardByProjectTool = tool({
|
|
308
|
+
description: 'Get the top users (KOLs/influencers) for a specific project by mindshare. Returns users who are driving the most attention for this project.',
|
|
309
|
+
inputSchema: z.object({
|
|
310
|
+
projectId: z.string().describe('The project ID to filter by.'),
|
|
311
|
+
timeframe: timeframeSchema,
|
|
312
|
+
rankBy: rankBySchema,
|
|
313
|
+
limit: limitSchema,
|
|
314
|
+
page: z.number().int().min(1).optional().describe('Page number for pagination. Defaults to 1.'),
|
|
315
|
+
}),
|
|
316
|
+
execute: async ({ projectId, timeframe, rankBy, limit, page }) => {
|
|
317
|
+
try {
|
|
318
|
+
const client = getMindshareClient();
|
|
319
|
+
const data = await client.getUserLeaderboardByProject(projectId, timeframe, rankBy, limit, page);
|
|
320
|
+
if (data.length === 0) {
|
|
321
|
+
return `No users found for project ${projectId}.`;
|
|
322
|
+
}
|
|
323
|
+
const lines = [
|
|
324
|
+
`Top ${data.length} Users for Project "${projectId}" (${timeframe ?? '24h'}, ranked by ${rankBy ?? 'value'}):`,
|
|
325
|
+
'',
|
|
326
|
+
'Rank | User | Mindshare | Delta',
|
|
327
|
+
'--- | --- | --- | ---',
|
|
328
|
+
];
|
|
329
|
+
for (const item of data) {
|
|
330
|
+
const ms = formatMindshare(item.mindshare);
|
|
331
|
+
const displayName = item.name || item.username;
|
|
332
|
+
lines.push(`${ms.rank} | @${item.username} (${displayName}) | ${ms.value} | ${ms.delta}`);
|
|
333
|
+
}
|
|
334
|
+
const output = lines.join('\n');
|
|
335
|
+
return output;
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
339
|
+
return `Error fetching project user leaderboard: ${message}`;
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
export const getUserMindshareTool = tool({
|
|
344
|
+
description: 'Get the mindshare data for a specific user by ID. Returns current mindshare value, delta change, and ranking position.',
|
|
345
|
+
inputSchema: z.object({
|
|
346
|
+
userId: z.string().describe('The user ID to look up.'),
|
|
347
|
+
timeframe: timeframeSchema,
|
|
348
|
+
withTimeseries: z
|
|
349
|
+
.boolean()
|
|
350
|
+
.optional()
|
|
351
|
+
.describe('Include historical timeseries data. Defaults to false.'),
|
|
352
|
+
}),
|
|
353
|
+
execute: async ({ userId, timeframe, withTimeseries }) => {
|
|
354
|
+
try {
|
|
355
|
+
const client = getMindshareClient();
|
|
356
|
+
const data = await client.getUserMindshare(userId, timeframe, withTimeseries);
|
|
357
|
+
const ms = formatMindshare(data.mindshare);
|
|
358
|
+
const displayName = data.name || data.username;
|
|
359
|
+
const lines = [
|
|
360
|
+
`Mindshare for @${data.username ?? userId} (${displayName}) (${timeframe ?? '24h'}):`,
|
|
361
|
+
'',
|
|
362
|
+
`- Rank: ${ms.rank}`,
|
|
363
|
+
`- Mindshare Value: ${ms.value}`,
|
|
364
|
+
`- Delta Change: ${ms.delta}`,
|
|
365
|
+
];
|
|
366
|
+
const output = lines.join('\n');
|
|
367
|
+
return output;
|
|
368
|
+
}
|
|
369
|
+
catch (err) {
|
|
370
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
371
|
+
return `Error fetching user mindshare: ${message}`;
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
export const getUserMindshareTimeseriesTool = tool({
|
|
376
|
+
description: 'Get historical mindshare data for a specific user. Returns timeseries data points showing user mindshare value over time.',
|
|
377
|
+
inputSchema: z.object({
|
|
378
|
+
userId: z.string().describe('The user ID to look up.'),
|
|
379
|
+
timeframe: timeframeSchema,
|
|
380
|
+
}),
|
|
381
|
+
execute: async ({ userId, timeframe }) => {
|
|
382
|
+
try {
|
|
383
|
+
const client = getMindshareClient();
|
|
384
|
+
const data = await client.getUserMindshareTimeseries(userId, timeframe);
|
|
385
|
+
if (data.length === 0) {
|
|
386
|
+
return `No historical mindshare data available for user ${userId}.`;
|
|
387
|
+
}
|
|
388
|
+
const lines = [
|
|
389
|
+
`Mindshare Timeseries for User "${userId}" (${timeframe ?? '24h'}, ${data.length} data points):`,
|
|
390
|
+
'',
|
|
391
|
+
];
|
|
392
|
+
const maxDisplay = 20;
|
|
393
|
+
const displayPoints = data.length > maxDisplay ? [...data.slice(0, 5), null, ...data.slice(-10)] : data;
|
|
394
|
+
for (const point of displayPoints) {
|
|
395
|
+
if (point === null) {
|
|
396
|
+
lines.push(`... (${data.length - 15} more points) ...`);
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
const date = new Date(point.timestamp).toISOString();
|
|
400
|
+
lines.push(`${date}: ${(point.value * 100).toFixed(4)}%`);
|
|
401
|
+
}
|
|
402
|
+
const firstValue = data[0].value;
|
|
403
|
+
const lastValue = data[data.length - 1].value;
|
|
404
|
+
const changePercent = ((lastValue - firstValue) / firstValue) * 100;
|
|
405
|
+
const sign = changePercent >= 0 ? '+' : '';
|
|
406
|
+
lines.push('');
|
|
407
|
+
lines.push(`Period change: ${sign}${changePercent.toFixed(2)}%`);
|
|
408
|
+
const output = lines.join('\n');
|
|
409
|
+
return output;
|
|
410
|
+
}
|
|
411
|
+
catch (err) {
|
|
412
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
413
|
+
return `Error fetching user mindshare timeseries: ${message}`;
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
export const getMindshareDeltaSignalsTool = tool({
|
|
418
|
+
description: 'Get mindshare delta spike signals. These signals indicate sudden spikes in mindshare for projects, suggesting rapid increase in social attention. Use this to detect early momentum shifts.',
|
|
419
|
+
inputSchema: z.object({
|
|
420
|
+
projectId: z.string().optional().describe('Optional project ID to filter signals.'),
|
|
421
|
+
minThreshold: z
|
|
422
|
+
.number()
|
|
423
|
+
.optional()
|
|
424
|
+
.describe('Minimum delta threshold percentage (e.g., 10 for 10% spike).'),
|
|
425
|
+
limit: limitSchema,
|
|
426
|
+
page: z.number().int().min(1).optional().describe('Page number for pagination. Defaults to 1.'),
|
|
427
|
+
includeTrendingTopics: z
|
|
428
|
+
.boolean()
|
|
429
|
+
.optional()
|
|
430
|
+
.describe('Include trending topics for each signal. Defaults to false.'),
|
|
431
|
+
}),
|
|
432
|
+
execute: async ({ projectId, minThreshold, limit, page, includeTrendingTopics }) => {
|
|
433
|
+
try {
|
|
434
|
+
const client = getMindshareClient();
|
|
435
|
+
const data = await client.getMindshareDeltaSignals(projectId, minThreshold, limit, page, includeTrendingTopics);
|
|
436
|
+
if (!data.signals || data.signals.length === 0) {
|
|
437
|
+
return 'No mindshare delta signals found.';
|
|
438
|
+
}
|
|
439
|
+
const lines = [
|
|
440
|
+
`Mindshare Delta Signals (${data.signals.length} signals, page ${data.page}):`,
|
|
441
|
+
'',
|
|
442
|
+
'Project | Threshold | Current | Time',
|
|
443
|
+
'--- | --- | --- | ---',
|
|
444
|
+
];
|
|
445
|
+
for (const signal of data.signals) {
|
|
446
|
+
const time = new Date(signal.timestamp).toISOString();
|
|
447
|
+
lines.push(`${signal.project_name} | +${signal.threshold.toFixed(2)}% | ${(signal.current_value * 100).toFixed(4)}% | ${time}`);
|
|
448
|
+
}
|
|
449
|
+
const output = lines.join('\n');
|
|
450
|
+
return output;
|
|
451
|
+
}
|
|
452
|
+
catch (err) {
|
|
453
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
454
|
+
return `Error fetching mindshare delta signals: ${message}`;
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
export const getMindshareMASignalsTool = tool({
|
|
459
|
+
description: 'Get mindshare moving average spike signals. These signals indicate when mindshare exceeds its moving average by a threshold, suggesting sustained attention above normal levels.',
|
|
460
|
+
inputSchema: z.object({
|
|
461
|
+
projectId: z.string().optional().describe('Optional project ID to filter signals.'),
|
|
462
|
+
minThreshold: z
|
|
463
|
+
.number()
|
|
464
|
+
.optional()
|
|
465
|
+
.describe('Minimum threshold in standard deviations above MA.'),
|
|
466
|
+
limit: limitSchema,
|
|
467
|
+
page: z.number().int().min(1).optional().describe('Page number for pagination. Defaults to 1.'),
|
|
468
|
+
includeTrendingTopics: z
|
|
469
|
+
.boolean()
|
|
470
|
+
.optional()
|
|
471
|
+
.describe('Include trending topics for each signal. Defaults to false.'),
|
|
472
|
+
}),
|
|
473
|
+
execute: async ({ projectId, minThreshold, limit, page, includeTrendingTopics }) => {
|
|
474
|
+
try {
|
|
475
|
+
const client = getMindshareClient();
|
|
476
|
+
const data = await client.getMindshareMASignals(projectId, minThreshold, limit, page, includeTrendingTopics);
|
|
477
|
+
if (!data.signals || data.signals.length === 0) {
|
|
478
|
+
return 'No mindshare MA signals found.';
|
|
479
|
+
}
|
|
480
|
+
const lines = [
|
|
481
|
+
`Mindshare MA Signals (${data.signals.length} signals, page ${data.page}):`,
|
|
482
|
+
'',
|
|
483
|
+
'Project | Threshold (std dev) | Current | Time',
|
|
484
|
+
'--- | --- | --- | ---',
|
|
485
|
+
];
|
|
486
|
+
for (const signal of data.signals) {
|
|
487
|
+
const time = new Date(signal.timestamp).toISOString();
|
|
488
|
+
lines.push(`${signal.project_name} | +${signal.threshold.toFixed(2)}σ | ${(signal.current_value * 100).toFixed(4)}% | ${time}`);
|
|
489
|
+
}
|
|
490
|
+
const output = lines.join('\n');
|
|
491
|
+
return output;
|
|
492
|
+
}
|
|
493
|
+
catch (err) {
|
|
494
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
495
|
+
return `Error fetching mindshare MA signals: ${message}`;
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
});
|
|
499
|
+
export const getMindshareSMAZScoreSignalsTool = tool({
|
|
500
|
+
description: 'Get mindshare SMA Z-Score signals. These signals detect statistical anomalies in mindshare using Z-scores. High Z-scores indicate mindshare levels significantly above historical norms.',
|
|
501
|
+
inputSchema: z.object({
|
|
502
|
+
projectId: z.string().optional().describe('Optional project ID to filter signals.'),
|
|
503
|
+
limit: limitSchema,
|
|
504
|
+
cursor: z
|
|
505
|
+
.string()
|
|
506
|
+
.optional()
|
|
507
|
+
.describe('Cursor for pagination (signal ID from previous response).'),
|
|
508
|
+
mode: z
|
|
509
|
+
.enum(['asc', 'desc'])
|
|
510
|
+
.optional()
|
|
511
|
+
.describe('Sort order: desc (newest first) or asc (oldest first). Defaults to desc.'),
|
|
512
|
+
includeSignalSummary: z
|
|
513
|
+
.boolean()
|
|
514
|
+
.optional()
|
|
515
|
+
.describe('Include signal summaries. Defaults to false.'),
|
|
516
|
+
}),
|
|
517
|
+
execute: async ({ projectId, limit, cursor, mode, includeSignalSummary }) => {
|
|
518
|
+
try {
|
|
519
|
+
const client = getMindshareClient();
|
|
520
|
+
const data = await client.getMindshareSMAZScoreSignals(projectId, limit, cursor, mode, includeSignalSummary);
|
|
521
|
+
if (!data.signals || data.signals.length === 0) {
|
|
522
|
+
return 'No mindshare SMA Z-Score signals found.';
|
|
523
|
+
}
|
|
524
|
+
const lines = [
|
|
525
|
+
`Mindshare SMA Z-Score Signals (${data.signals.length} signals):`,
|
|
526
|
+
'',
|
|
527
|
+
'Project | Z-Score | Current | SMA | Time',
|
|
528
|
+
'--- | --- | --- | --- | ---',
|
|
529
|
+
];
|
|
530
|
+
for (const signal of data.signals) {
|
|
531
|
+
const time = new Date(signal.timestamp).toISOString();
|
|
532
|
+
const zScoreSign = signal.z_score >= 0 ? '+' : '';
|
|
533
|
+
lines.push(`${signal.project_name} | ${zScoreSign}${signal.z_score.toFixed(2)} | ${(signal.current_value * 100).toFixed(4)}% | ${(signal.sma_value * 100).toFixed(4)}% | ${time}`);
|
|
534
|
+
}
|
|
535
|
+
if (data.next_cursor) {
|
|
536
|
+
lines.push('');
|
|
537
|
+
lines.push(`Next cursor: ${data.next_cursor}`);
|
|
538
|
+
}
|
|
539
|
+
const output = lines.join('\n');
|
|
540
|
+
return output;
|
|
541
|
+
}
|
|
542
|
+
catch (err) {
|
|
543
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
544
|
+
return `Error fetching mindshare SMA Z-Score signals: ${message}`;
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
export const mindshareTools = {
|
|
549
|
+
getProjectLeaderboard: getProjectLeaderboardTool,
|
|
550
|
+
getProjectMindshare: getProjectMindshareTool,
|
|
551
|
+
getProjectMindshareTimeseries: getProjectMindshareTimeseriesTool,
|
|
552
|
+
getProjectLeaderboardBySector: getProjectLeaderboardBySectorTool,
|
|
553
|
+
getSectorLeaderboard: getSectorLeaderboardTool,
|
|
554
|
+
getSectorMindshare: getSectorMindshareTool,
|
|
555
|
+
getSectorMindshareTimeseries: getSectorMindshareTimeseriesTool,
|
|
556
|
+
getUserLeaderboard: getUserLeaderboardTool,
|
|
557
|
+
getUserLeaderboardByProject: getUserLeaderboardByProjectTool,
|
|
558
|
+
getUserMindshare: getUserMindshareTool,
|
|
559
|
+
getUserMindshareTimeseries: getUserMindshareTimeseriesTool,
|
|
560
|
+
getMindshareDeltaSignals: getMindshareDeltaSignalsTool,
|
|
561
|
+
getMindshareMASignals: getMindshareMASignalsTool,
|
|
562
|
+
getMindshareSMAZScoreSignals: getMindshareSMAZScoreSignalsTool,
|
|
563
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { tool } from 'ai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Create a tool that allows the agent to read skill knowledge.
|
|
5
|
+
* Returns the full SKILL.md body content when called.
|
|
6
|
+
*/
|
|
7
|
+
export function createReadSkillTool(skillRegistry) {
|
|
8
|
+
const readSkillTool = tool({
|
|
9
|
+
description: 'Read a skill to get detailed knowledge and instructions. Call this when you need specialized expertise for analysis. Use the skill ID from the available skills list.',
|
|
10
|
+
inputSchema: z.object({
|
|
11
|
+
skillId: z
|
|
12
|
+
.string()
|
|
13
|
+
.describe('The skill ID to read (from the available skills list in your prompt)'),
|
|
14
|
+
}),
|
|
15
|
+
execute: async ({ skillId }) => {
|
|
16
|
+
const skill = skillRegistry.get(skillId);
|
|
17
|
+
if (skill === undefined) {
|
|
18
|
+
const availableIds = Array.from(skillRegistry.keys());
|
|
19
|
+
if (availableIds.length === 0) {
|
|
20
|
+
return `Skill "${skillId}" not found. No skills are currently available.`;
|
|
21
|
+
}
|
|
22
|
+
const idList = availableIds.join(', ');
|
|
23
|
+
return `Skill "${skillId}" not found. Available skills: ${idList}`;
|
|
24
|
+
}
|
|
25
|
+
const output = `# ${skill.metadata.name}\n\n${skill.body}`;
|
|
26
|
+
return output;
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
return readSkillTool;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { computeSMA, computeEMA, computeRSI, computeMACD, computeBollingerBands } from './indicators.js';
|