@undesirables/plugin-tcg-oracle 1.0.0 → 2.0.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/dist/index.js CHANGED
@@ -1,434 +1,554 @@
1
- /**
2
- * TCG Oracle — ElizaOS Plugin v1.0.0
3
- * ====================================
4
- * AI-powered trading card market intelligence for ElizaOS agents.
5
- * Native TypeScript rewrite of the Python G.A.M.E. SDK version.
6
- *
7
- * Features:
8
- * - Search 370K+ TCG products across 25 games (Pokemon, MTG, Yu-Gi-Oh, etc.)
9
- * - AI Vision card grading (PSA/Beckett prediction via Qwen VL)
10
- * - Monte Carlo price simulation (Heston, Merton, Kou stochastic models)
11
- * - Real-time market snapshots from TCGCSV daily data
12
- * - License key purchase & verification (Ethereum NFT)
13
- *
14
- * @see https://the-undesirables.com
15
- * @see https://github.com/sailorpepe/elizaos-tcg-oracle-plugin
16
- */
17
- import { validateTcgOracleConfig } from "./environment.js";
18
- // ============================================================
19
- // Configuration
20
- // ============================================================
21
- const SUPPORTED_GAMES = [
22
- "Pokemon",
23
- "Magic: The Gathering",
24
- "Yu-Gi-Oh!",
25
- "Lorcana",
26
- "One Piece",
27
- "Flesh and Blood",
28
- "Star Wars: Unlimited",
29
- "Dragon Ball Super",
30
- "Digimon",
31
- "MetaZoo",
32
- "Union Arena",
33
- "Gundam Card Game",
34
- "LoL Riftbound",
1
+ // src/environment.ts
2
+ function validateTcgOracleConfig(runtime) {
3
+ const url = runtime.getSetting?.("TCG_ORACLE_URL") || process.env.TCG_ORACLE_URL || "";
4
+ if (!url) {
5
+ return {
6
+ valid: false,
7
+ error: "TCG_ORACLE_URL is required. Set it in your character.json settings or as an environment variable. Example: https://oracle.the-undesirables.com"
8
+ };
9
+ }
10
+ try {
11
+ new URL(url);
12
+ } catch {
13
+ return {
14
+ valid: false,
15
+ error: `TCG_ORACLE_URL is not a valid URL: "${url}"`
16
+ };
17
+ }
18
+ return { valid: true };
19
+ }
20
+
21
+ // src/services.ts
22
+ import { Service } from "@elizaos/core";
23
+ var MarketMonitorService = class _MarketMonitorService extends Service {
24
+ // Use a string getter to satisfy ElizaOS ServiceType constraints if needed,
25
+ // or define static serviceType depending on the core version.
26
+ static serviceType = "TCG_MARKET_MONITOR";
27
+ get capabilityDescription() {
28
+ return "Monitors TCG market data for price spikes and trending cards";
29
+ }
30
+ static async start(runtime) {
31
+ const service = new _MarketMonitorService();
32
+ await service.initialize(runtime);
33
+ return service;
34
+ }
35
+ monitorInterval = null;
36
+ async initialize(_runtime) {
37
+ console.log("[TCG Oracle Service] Market Monitor Service initialized.");
38
+ }
39
+ async stop() {
40
+ if (this.monitorInterval) {
41
+ clearInterval(this.monitorInterval);
42
+ }
43
+ console.log("[TCG Oracle Service] Market Monitor Service stopped.");
44
+ }
45
+ pollMarket() {
46
+ console.log("[TCG Oracle Service] Background task: Polling TCG market for price spikes...");
47
+ }
48
+ };
49
+
50
+ // src/index.ts
51
+ var SUPPORTED_GAMES = [
52
+ "Pokemon",
53
+ "Magic: The Gathering",
54
+ "Yu-Gi-Oh!",
55
+ "Lorcana",
56
+ "One Piece",
57
+ "Flesh and Blood",
58
+ "Star Wars: Unlimited",
59
+ "Dragon Ball Super",
60
+ "Digimon",
61
+ "MetaZoo",
62
+ "Union Arena",
63
+ "Gundam Card Game",
64
+ "LoL Riftbound"
35
65
  ];
36
- const SIMULATION_MODELS = ["heston", "merton", "kou"];
37
- // ============================================================
38
- // API Client
39
- // ============================================================
66
+ var SIMULATION_MODELS = ["conformal", "merton", "gbm"];
40
67
  function getBaseUrl(runtime) {
41
- return (runtime.getSetting?.("TCG_ORACLE_URL") ||
42
- process.env.TCG_ORACLE_URL ||
43
- "");
68
+ return runtime.getSetting?.("TCG_ORACLE_URL") || process.env.TCG_ORACLE_URL || "";
44
69
  }
45
70
  async function callApi(baseUrl, endpoint, params) {
46
- if (!baseUrl) {
47
- return {
48
- error: "TCG_ORACLE_URL not set. Set it in your character.json settings or as an environment variable. Install the server: pip install undesirables-mcp-server",
49
- };
50
- }
51
- const url = new URL(`${baseUrl}${endpoint}`);
52
- for (const [key, value] of Object.entries(params)) {
53
- if (value !== undefined && value !== null && value !== "") {
54
- url.searchParams.set(key, String(value));
55
- }
71
+ if (!baseUrl) {
72
+ return {
73
+ error: "TCG_ORACLE_URL not set. Set it in your character.json settings or as an environment variable. Install the server: pip install undesirables-mcp-server"
74
+ };
75
+ }
76
+ const url = new URL(`${baseUrl}${endpoint}`);
77
+ for (const [key, value] of Object.entries(params)) {
78
+ if (value !== void 0 && value !== null && value !== "") {
79
+ url.searchParams.set(key, String(value));
56
80
  }
57
- try {
58
- const controller = new AbortController();
59
- const timeout = setTimeout(() => controller.abort(), 30_000);
60
- const response = await fetch(url.toString(), {
61
- signal: controller.signal,
62
- headers: { "User-Agent": "elizaos-tcg-oracle-plugin/1.0.0" },
63
- });
64
- clearTimeout(timeout);
65
- if (!response.ok) {
66
- return { error: `API returned HTTP ${response.status}` };
67
- }
68
- const json = (await response.json());
69
- return { data: json.data || json };
81
+ }
82
+ try {
83
+ const controller = new AbortController();
84
+ const timeout = setTimeout(() => controller.abort(), 3e4);
85
+ const response = await fetch(url.toString(), {
86
+ signal: controller.signal,
87
+ headers: { "User-Agent": "elizaos-tcg-oracle-plugin/1.0.0" }
88
+ });
89
+ clearTimeout(timeout);
90
+ if (!response.ok) {
91
+ return { error: `API returned HTTP ${response.status}` };
70
92
  }
71
- catch (err) {
72
- if (err.name === "AbortError") {
73
- return { error: "TCG Oracle API timed out (30s)" };
74
- }
75
- return {
76
- error: "Failed to connect to TCG Oracle API. Is the server running?",
77
- };
93
+ const json = await response.json();
94
+ return { data: json.data || json };
95
+ } catch (err) {
96
+ if (err.name === "AbortError") {
97
+ return { error: "TCG Oracle API timed out (30s)" };
78
98
  }
99
+ return {
100
+ error: "Failed to connect to TCG Oracle API. Is the server running?"
101
+ };
102
+ }
79
103
  }
80
- // ============================================================
81
- // Helper: Truncate data safely before JSON.stringify
82
- // ============================================================
83
104
  function safeStringify(data, maxItems = 10) {
84
- if (Array.isArray(data)) {
85
- return JSON.stringify(data.slice(0, maxItems), null, 2);
86
- }
87
- return JSON.stringify(data, null, 2).slice(0, 2000);
105
+ if (Array.isArray(data)) {
106
+ return JSON.stringify(data.slice(0, maxItems), null, 2);
107
+ }
108
+ return JSON.stringify(data, null, 2).slice(0, 2e3);
88
109
  }
89
- // ============================================================
90
- // ACTION 1: Search TCG Products
91
- // ============================================================
92
- const searchAction = {
93
- name: "TCG_ORACLE_SEARCH",
94
- description: "Search for trading card products across 25 games including Pokemon, Magic: The Gathering, Yu-Gi-Oh, Lorcana, One Piece, and more. Returns product names, set info, and current market prices from 370K+ real products sourced from TCGCSV daily.",
95
- similes: [
96
- "SEARCH_CARDS",
97
- "FIND_CARD",
98
- "CARD_LOOKUP",
99
- "CARD_SEARCH",
100
- "TCG_SEARCH",
101
- "FIND_POKEMON",
102
- "SEARCH_MTG",
103
- ],
104
- parameters: [
105
- {
106
- name: "query",
107
- description: "The card name, set name, or keyword to search for (e.g., 'Charizard', 'Base Set', 'Pikachu VMAX')",
108
- required: true,
109
- schema: { type: "string" },
110
- },
111
- {
112
- name: "limit",
113
- description: "Maximum number of results to return (default: 10, max: 50)",
114
- required: false,
115
- schema: { type: "number" },
116
- },
110
+ var searchAction = {
111
+ name: "TCG_ORACLE_SEARCH",
112
+ description: "Search for trading card products across 25+ games including Pokemon, Magic: The Gathering, Yu-Gi-Oh, Lorcana, One Piece, and more. Returns product names, set info, and current market prices from 446K+ real products sourced from TCGCSV daily.",
113
+ similes: [
114
+ "SEARCH_CARDS",
115
+ "FIND_CARD",
116
+ "CARD_LOOKUP",
117
+ "CARD_SEARCH",
118
+ "TCG_SEARCH",
119
+ "FIND_POKEMON",
120
+ "SEARCH_MTG"
121
+ ],
122
+ parameters: [
123
+ {
124
+ name: "query",
125
+ description: "The card name, set name, or keyword to search for (e.g., 'Charizard', 'Base Set', 'Pikachu VMAX')",
126
+ required: true,
127
+ schema: { type: "string" }
128
+ },
129
+ {
130
+ name: "limit",
131
+ description: "Maximum number of results to return (default: 10, max: 50)",
132
+ required: false,
133
+ schema: { type: "number" }
134
+ }
135
+ ],
136
+ examples: [
137
+ [
138
+ { name: "{{user1}}", content: { text: "Search for Charizard cards" } },
139
+ { name: "{{agentName}}", content: { text: "Searching TCG Oracle for Charizard...", action: "TCG_ORACLE_SEARCH" } }
117
140
  ],
118
- examples: [
119
- [
120
- { name: "{{user1}}", content: { text: "Search for Charizard cards" } },
121
- { name: "{{agentName}}", content: { text: "Searching TCG Oracle for Charizard...", action: "TCG_ORACLE_SEARCH" } },
122
- ],
123
- [
124
- { name: "{{user1}}", content: { text: "What Pikachu VMAX cards are available?" } },
125
- { name: "{{agentName}}", content: { text: "Looking up Pikachu VMAX products...", action: "TCG_ORACLE_SEARCH" } },
126
- ],
127
- [
128
- { name: "{{user1}}", content: { text: "Find me Base Set holographic cards" } },
129
- { name: "{{agentName}}", content: { text: "Searching for Base Set holographic cards...", action: "TCG_ORACLE_SEARCH" } },
130
- ],
141
+ [
142
+ { name: "{{user1}}", content: { text: "What Pikachu VMAX cards are available?" } },
143
+ { name: "{{agentName}}", content: { text: "Looking up Pikachu VMAX products...", action: "TCG_ORACLE_SEARCH" } }
131
144
  ],
132
- validate: async (runtime) => {
133
- return !!getBaseUrl(runtime);
134
- },
135
- handler: async (runtime, message, _state, _options, callback) => {
136
- const text = message.content.text || "";
137
- // Extract search query — strip common prefixes
138
- const query = text
139
- .replace(/^(search|find|look up|lookup|what|show me)\s+(for\s+)?/i, "")
140
- .replace(/\s+cards?\s*$/i, "")
141
- .trim();
142
- if (!query) {
143
- if (callback)
144
- await callback({ text: "What card would you like me to search for?" });
145
- return { success: false, error: "No search query provided" };
146
- }
147
- const result = await callApi(getBaseUrl(runtime), "/api/v1/search", {
148
- query,
149
- limit: 10,
150
- });
151
- if (result.error) {
152
- if (callback)
153
- await callback({ text: `Search failed: ${result.error}` });
154
- return { success: false, error: result.error };
155
- }
156
- const summary = safeStringify(result.data);
157
- const responseText = `Found products matching "${query}":\n\n${summary}`;
158
- if (callback)
159
- await callback({ text: responseText }, "TCG_ORACLE_SEARCH");
160
- return { success: true, text: responseText, data: { search_results: result.data } };
161
- },
145
+ [
146
+ { name: "{{user1}}", content: { text: "Find me Base Set holographic cards" } },
147
+ { name: "{{agentName}}", content: { text: "Searching for Base Set holographic cards...", action: "TCG_ORACLE_SEARCH" } }
148
+ ]
149
+ ],
150
+ validate: async (runtime) => {
151
+ return !!getBaseUrl(runtime);
152
+ },
153
+ handler: async (runtime, message, _state, _options, callback) => {
154
+ const text = message.content.text || "";
155
+ const query = text.replace(/^(search|find|look up|lookup|what|show me)\s+(for\s+)?/i, "").replace(/\s+cards?\s*$/i, "").trim();
156
+ if (!query) {
157
+ if (callback) await callback({ text: "What card would you like me to search for?" });
158
+ return { success: false, error: "No search query provided" };
159
+ }
160
+ const result = await callApi(getBaseUrl(runtime), "/api/v1/search", {
161
+ query,
162
+ limit: 10
163
+ });
164
+ if (result.error) {
165
+ if (callback) await callback({ text: `Search failed: ${result.error}` });
166
+ return { success: false, error: result.error };
167
+ }
168
+ const summary = safeStringify(result.data);
169
+ const responseText = `Found products matching "${query}":
170
+
171
+ ${summary}`;
172
+ if (callback) await callback({ text: responseText }, "TCG_ORACLE_SEARCH");
173
+ return { success: true, text: responseText, data: { search_results: result.data } };
174
+ }
162
175
  };
163
- // ============================================================
164
- // ACTION 2: AI Card Grading
165
- // ============================================================
166
- const gradeAction = {
167
- name: "TCG_ORACLE_GRADE",
168
- description: "Grade a TCG card image using AI vision (Qwen VL model running locally). Predicts PSA and Beckett grading scores by analyzing centering, corners, edges, surface condition, and print quality. Works with Pokemon, MTG, Yu-Gi-Oh, and other TCG cards.",
169
- similes: [
170
- "GRADE_CARD",
171
- "CARD_GRADING",
172
- "PSA_GRADE",
173
- "BECKETT_GRADE",
174
- "RATE_CARD",
175
- "EVALUATE_CARD",
176
- ],
177
- parameters: [
178
- {
179
- name: "image_url",
180
- description: "Direct URL to the card image (PNG, JPG, or WebP)",
181
- required: true,
182
- schema: { type: "string" },
183
- },
184
- {
185
- name: "game",
186
- description: "The TCG game this card belongs to (default: Pokemon)",
187
- required: false,
188
- schema: { type: "string" },
189
- },
176
+ var gradeAction = {
177
+ name: "TCG_ORACLE_GRADE",
178
+ description: "Grade a TCG card image using AI vision (Qwen VL model running locally). Predicts PSA and Beckett grading scores by analyzing centering, corners, edges, surface condition, and print quality. Works with Pokemon, MTG, Yu-Gi-Oh, and other TCG cards.",
179
+ similes: [
180
+ "GRADE_CARD",
181
+ "CARD_GRADING",
182
+ "PSA_GRADE",
183
+ "BECKETT_GRADE",
184
+ "RATE_CARD",
185
+ "EVALUATE_CARD"
186
+ ],
187
+ parameters: [
188
+ {
189
+ name: "image_url",
190
+ description: "Direct URL to the card image (PNG, JPG, or WebP)",
191
+ required: true,
192
+ schema: { type: "string" }
193
+ },
194
+ {
195
+ name: "game",
196
+ description: "The TCG game this card belongs to (default: Pokemon)",
197
+ required: false,
198
+ schema: { type: "string" }
199
+ }
200
+ ],
201
+ examples: [
202
+ [
203
+ { name: "{{user1}}", content: { text: "Grade this card: https://example.com/charizard.jpg" } },
204
+ { name: "{{agentName}}", content: { text: "Analyzing card image for grading...", action: "TCG_ORACLE_GRADE" } }
190
205
  ],
191
- examples: [
192
- [
193
- { name: "{{user1}}", content: { text: "Grade this card: https://example.com/charizard.jpg" } },
194
- { name: "{{agentName}}", content: { text: "Analyzing card image for grading...", action: "TCG_ORACLE_GRADE" } },
195
- ],
196
- [
197
- { name: "{{user1}}", content: { text: "What PSA grade would this get? https://i.imgur.com/card.png" } },
198
- { name: "{{agentName}}", content: { text: "Running AI vision grading analysis...", action: "TCG_ORACLE_GRADE" } },
199
- ],
200
- [
201
- { name: "{{user1}}", content: { text: "Rate the condition of this Magic card https://example.com/mtg.jpg" } },
202
- { name: "{{agentName}}", content: { text: "Evaluating card condition for Beckett grading...", action: "TCG_ORACLE_GRADE" } },
203
- ],
206
+ [
207
+ { name: "{{user1}}", content: { text: "What PSA grade would this get? https://i.imgur.com/card.png" } },
208
+ { name: "{{agentName}}", content: { text: "Running AI vision grading analysis...", action: "TCG_ORACLE_GRADE" } }
204
209
  ],
205
- validate: async (runtime) => !!getBaseUrl(runtime),
206
- handler: async (runtime, message, _state, _options, callback) => {
207
- const text = message.content.text || "";
208
- // Extract URL from message
209
- const urlMatch = text.match(/https?:\/\/[^\s]+/);
210
- if (!urlMatch) {
211
- if (callback)
212
- await callback({ text: "Please provide a card image URL to grade." });
213
- return { success: false, error: "No image URL found in message" };
214
- }
215
- const result = await callApi(getBaseUrl(runtime), "/api/v1/grade", {
216
- image_url: urlMatch[0],
217
- game: "Pokemon",
218
- });
219
- if (result.error) {
220
- if (callback)
221
- await callback({ text: `Grading failed: ${result.error}` });
222
- return { success: false, error: result.error };
223
- }
224
- const summary = safeStringify(result.data);
225
- const responseText = `Card grading complete:\n\n${summary}`;
226
- if (callback)
227
- await callback({ text: responseText }, "TCG_ORACLE_GRADE");
228
- return { success: true, text: responseText, data: { grade_result: result.data } };
229
- },
210
+ [
211
+ { name: "{{user1}}", content: { text: "Rate the condition of this Magic card https://example.com/mtg.jpg" } },
212
+ { name: "{{agentName}}", content: { text: "Evaluating card condition for Beckett grading...", action: "TCG_ORACLE_GRADE" } }
213
+ ]
214
+ ],
215
+ validate: async (runtime) => !!getBaseUrl(runtime),
216
+ handler: async (runtime, message, _state, _options, callback) => {
217
+ const text = message.content.text || "";
218
+ const urlMatch = text.match(/https?:\/\/[^\s]+/);
219
+ if (!urlMatch) {
220
+ if (callback) await callback({ text: "Please provide a card image URL to grade." });
221
+ return { success: false, error: "No image URL found in message" };
222
+ }
223
+ const result = await callApi(getBaseUrl(runtime), "/api/v1/grade", {
224
+ image_url: urlMatch[0],
225
+ game: "Pokemon"
226
+ });
227
+ if (result.error) {
228
+ if (callback) await callback({ text: `Grading failed: ${result.error}` });
229
+ return { success: false, error: result.error };
230
+ }
231
+ const summary = safeStringify(result.data);
232
+ const responseText = `Card grading complete:
233
+
234
+ ${summary}`;
235
+ if (callback) await callback({ text: responseText }, "TCG_ORACLE_GRADE");
236
+ return { success: true, text: responseText, data: { grade_result: result.data } };
237
+ }
230
238
  };
231
- // ============================================================
232
- // ACTION 3: Monte Carlo Price Simulation
233
- // ============================================================
234
- const simulateAction = {
235
- name: "TCG_ORACLE_SIMULATE",
236
- description: "Run Monte Carlo simulation on a TCG card's price to predict future value. Uses real drift and volatility computed from TCGCSV historical data. Supports three stochastic models: Heston (stochastic volatility), Merton (jump-diffusion), and Kou (double-exponential jumps). Returns percentile bands (5th, 25th, 50th, 75th, 95th) for the forecast period.",
237
- similes: [
238
- "SIMULATE_PRICE",
239
- "PRICE_PREDICTION",
240
- "FORECAST_PRICE",
241
- "MONTE_CARLO",
242
- "PRICE_FORECAST",
243
- "WHAT_WILL_THIS_BE_WORTH",
244
- ],
245
- parameters: [
246
- {
247
- name: "card_name",
248
- description: "Name of the card to simulate",
249
- required: true,
250
- schema: { type: "string" },
251
- },
252
- {
253
- name: "current_price",
254
- description: "Current price in USD",
255
- required: true,
256
- schema: { type: "number" },
257
- },
258
- {
259
- name: "model",
260
- description: "Stochastic model: 'heston', 'merton', or 'kou'",
261
- required: false,
262
- schema: { type: "string", enumValues: ["heston", "merton", "kou"] },
263
- },
264
- {
265
- name: "days",
266
- description: "Forecast horizon in days (default: 30)",
267
- required: false,
268
- schema: { type: "number" },
269
- },
239
+ var simulateAction = {
240
+ name: "TCG_ORACLE_SIMULATE",
241
+ description: "Forecast a TCG card's future value with a conformal-calibrated risk model \u2014 honest VaR plus Safe-Hold/Momentum letter grades. Monte Carlo (GBM/Merton) is opt-in via the model parameter. Uses real drift and volatility computed from TCGCSV historical data. Monte Carlo models available opt-in: merton (jump-diffusion) and gbm. Returns percentile bands (5th, 25th, 50th, 75th, 95th) for the forecast period.",
242
+ similes: [
243
+ "SIMULATE_PRICE",
244
+ "PRICE_PREDICTION",
245
+ "FORECAST_PRICE",
246
+ "MONTE_CARLO",
247
+ "PRICE_FORECAST",
248
+ "WHAT_WILL_THIS_BE_WORTH"
249
+ ],
250
+ parameters: [
251
+ {
252
+ name: "card_name",
253
+ description: "Name of the card to simulate",
254
+ required: true,
255
+ schema: { type: "string" }
256
+ },
257
+ {
258
+ name: "current_price",
259
+ description: "Current price in USD",
260
+ required: true,
261
+ schema: { type: "number" }
262
+ },
263
+ {
264
+ name: "model",
265
+ description: "Forecast model (default 'conformal'): 'conformal' (regime-aware split-conformal bands, honest calibrated VaR), or opt into Monte Carlo with 'merton' (jump-diffusion) or 'gbm'",
266
+ required: false,
267
+ schema: { type: "string", enumValues: ["conformal", "merton", "gbm"] }
268
+ },
269
+ {
270
+ name: "days",
271
+ description: "Forecast horizon in days (default: 30)",
272
+ required: false,
273
+ schema: { type: "number" }
274
+ }
275
+ ],
276
+ examples: [
277
+ [
278
+ { name: "{{user1}}", content: { text: "Simulate the price of Charizard VMAX at $350 for 60 days" } },
279
+ { name: "{{agentName}}", content: { text: "Running Monte Carlo simulation on Charizard VMAX...", action: "TCG_ORACLE_SIMULATE" } }
270
280
  ],
271
- examples: [
272
- [
273
- { name: "{{user1}}", content: { text: "Simulate the price of Charizard VMAX at $350 for 60 days" } },
274
- { name: "{{agentName}}", content: { text: "Running Monte Carlo simulation on Charizard VMAX...", action: "TCG_ORACLE_SIMULATE" } },
275
- ],
276
- [
277
- { name: "{{user1}}", content: { text: "What will a PSA 10 Base Set Blastoise worth $800 be in 90 days using merton model?" } },
278
- { name: "{{agentName}}", content: { text: "Running Merton jump-diffusion simulation for Blastoise...", action: "TCG_ORACLE_SIMULATE" } },
279
- ],
280
- [
281
- { name: "{{user1}}", content: { text: "Forecast Lorcana Elsa at $25 for 30 days" } },
282
- { name: "{{agentName}}", content: { text: "Simulating Lorcana Elsa price trajectory...", action: "TCG_ORACLE_SIMULATE" } },
283
- ],
281
+ [
282
+ { name: "{{user1}}", content: { text: "What will a PSA 10 Base Set Blastoise worth $800 be in 90 days using merton model?" } },
283
+ { name: "{{agentName}}", content: { text: "Running Merton jump-diffusion simulation for Blastoise...", action: "TCG_ORACLE_SIMULATE" } }
284
284
  ],
285
- validate: async (runtime) => !!getBaseUrl(runtime),
286
- handler: async (runtime, message, _state, options, callback) => {
287
- const text = message.content.text || "";
288
- // Try to extract parameters from text
289
- const priceMatch = text.match(/\$?([\d,]+(?:\.\d{2})?)/);
290
- const daysMatch = text.match(/(\d+)\s*days?/i);
291
- const modelMatch = text.match(/\b(heston|merton|kou)\b/i);
292
- const cardName = text
293
- .replace(/simulate|price|forecast|monte carlo|at|\$[\d,.]+|\d+\s*days?|heston|merton|kou/gi, "")
294
- .replace(/\s+/g, " ")
295
- .trim() || "Unknown Card";
296
- const currentPrice = priceMatch ? parseFloat(priceMatch[1].replace(",", "")) : 0;
297
- const days = daysMatch ? parseInt(daysMatch[1]) : 30;
298
- const model = modelMatch ? modelMatch[1].toLowerCase() : "heston";
299
- if (currentPrice <= 0) {
300
- if (callback)
301
- await callback({ text: "Please provide a current price for the simulation. Example: 'Simulate Charizard VMAX at $350 for 60 days'" });
302
- return { success: false, error: "Invalid or missing current price" };
303
- }
304
- const result = await callApi(getBaseUrl(runtime), "/api/v1/simulate", {
305
- card_name: cardName,
306
- current_price: currentPrice,
307
- model,
308
- days,
309
- simulations: 10000,
310
- });
311
- if (result.error) {
312
- if (callback)
313
- await callback({ text: `Simulation failed: ${result.error}` });
314
- return { success: false, error: result.error };
315
- }
316
- const summary = safeStringify(result.data);
317
- const responseText = `Monte Carlo simulation for ${cardName} ($${currentPrice}, ${model} model, ${days} days):\n\n${summary}`;
318
- if (callback)
319
- await callback({ text: responseText }, "TCG_ORACLE_SIMULATE");
320
- return { success: true, text: responseText, data: { simulation_result: result.data } };
321
- },
285
+ [
286
+ { name: "{{user1}}", content: { text: "Forecast Lorcana Elsa at $25 for 30 days" } },
287
+ { name: "{{agentName}}", content: { text: "Simulating Lorcana Elsa price trajectory...", action: "TCG_ORACLE_SIMULATE" } }
288
+ ]
289
+ ],
290
+ validate: async (runtime) => !!getBaseUrl(runtime),
291
+ handler: async (runtime, message, _state, options, callback) => {
292
+ const text = message.content.text || "";
293
+ const priceMatch = text.match(/\$?([\d,]+(?:\.\d{2})?)/);
294
+ const daysMatch = text.match(/(\d+)\s*days?/i);
295
+ const modelMatch = text.match(/\b(conformal|merton|gbm)\b/i);
296
+ const cardName = text.replace(/simulate|price|forecast|monte carlo|at|\$[\d,.]+|\d+\s*days?|conformal|merton|gbm/gi, "").replace(/\s+/g, " ").trim() || "Unknown Card";
297
+ const currentPrice = priceMatch ? parseFloat(priceMatch[1].replace(",", "")) : 0;
298
+ const days = daysMatch ? parseInt(daysMatch[1]) : 30;
299
+ const model = modelMatch ? modelMatch[1].toLowerCase() : "conformal";
300
+ if (currentPrice <= 0) {
301
+ if (callback) await callback({ text: "Please provide a current price for the simulation. Example: 'Simulate Charizard VMAX at $350 for 60 days'" });
302
+ return { success: false, error: "Invalid or missing current price" };
303
+ }
304
+ const result = await callApi(getBaseUrl(runtime), "/api/v1/simulate", {
305
+ card_name: cardName,
306
+ current_price: currentPrice,
307
+ model,
308
+ days,
309
+ simulations: 1e4
310
+ });
311
+ if (result.error) {
312
+ if (callback) await callback({ text: `Simulation failed: ${result.error}` });
313
+ return { success: false, error: result.error };
314
+ }
315
+ const summary = safeStringify(result.data);
316
+ const responseText = `Monte Carlo simulation for ${cardName} ($${currentPrice}, ${model} model, ${days} days):
317
+
318
+ ${summary}`;
319
+ if (callback) await callback({ text: responseText }, "TCG_ORACLE_SIMULATE");
320
+ return { success: true, text: responseText, data: { simulation_result: result.data } };
321
+ }
322
322
  };
323
- // ============================================================
324
- // ACTION 4: Market Snapshot
325
- // ============================================================
326
- const marketAction = {
327
- name: "TCG_ORACLE_MARKET",
328
- description: "Retrieve the latest daily market data snapshot from TCGCSV for a specific game. Returns top movers, price changes, volume data, and market trends. Data is refreshed daily via automated pipeline.",
329
- similes: [
330
- "MARKET_SNAPSHOT",
331
- "MARKET_DATA",
332
- "TCG_MARKET",
333
- "CARD_MARKET",
334
- "TOP_MOVERS",
335
- "PRICE_CHANGES",
323
+ var marketAction = {
324
+ name: "TCG_ORACLE_MARKET",
325
+ description: "Retrieve the latest daily market data snapshot from TCGCSV for a specific game. Returns top movers, price changes, volume data, and market trends. Data is refreshed daily via automated pipeline.",
326
+ similes: [
327
+ "MARKET_SNAPSHOT",
328
+ "MARKET_DATA",
329
+ "TCG_MARKET",
330
+ "CARD_MARKET",
331
+ "TOP_MOVERS",
332
+ "PRICE_CHANGES"
333
+ ],
334
+ parameters: [
335
+ {
336
+ name: "game",
337
+ description: "Game name: Pokemon, Magic: The Gathering, Yu-Gi-Oh, Lorcana, One Piece, etc",
338
+ required: false,
339
+ schema: { type: "string" }
340
+ }
341
+ ],
342
+ examples: [
343
+ [
344
+ { name: "{{user1}}", content: { text: "Show me the Pokemon market snapshot" } },
345
+ { name: "{{agentName}}", content: { text: "Pulling the latest Pokemon market data...", action: "TCG_ORACLE_MARKET" } }
336
346
  ],
337
- parameters: [
338
- {
339
- name: "game",
340
- description: "Game name: Pokemon, Magic: The Gathering, Yu-Gi-Oh, Lorcana, One Piece, etc",
341
- required: false,
342
- schema: { type: "string" },
343
- },
347
+ [
348
+ { name: "{{user1}}", content: { text: "What's happening in the Yu-Gi-Oh market today?" } },
349
+ { name: "{{agentName}}", content: { text: "Fetching Yu-Gi-Oh market snapshot...", action: "TCG_ORACLE_MARKET" } }
344
350
  ],
345
- examples: [
346
- [
347
- { name: "{{user1}}", content: { text: "Show me the Pokemon market snapshot" } },
348
- { name: "{{agentName}}", content: { text: "Pulling the latest Pokemon market data...", action: "TCG_ORACLE_MARKET" } },
349
- ],
350
- [
351
- { name: "{{user1}}", content: { text: "What's happening in the Yu-Gi-Oh market today?" } },
352
- { name: "{{agentName}}", content: { text: "Fetching Yu-Gi-Oh market snapshot...", action: "TCG_ORACLE_MARKET" } },
353
- ],
354
- [
355
- { name: "{{user1}}", content: { text: "Top movers in Magic: The Gathering" } },
356
- { name: "{{agentName}}", content: { text: "Pulling Magic: The Gathering market data...", action: "TCG_ORACLE_MARKET" } },
357
- ],
351
+ [
352
+ { name: "{{user1}}", content: { text: "Top movers in Magic: The Gathering" } },
353
+ { name: "{{agentName}}", content: { text: "Pulling Magic: The Gathering market data...", action: "TCG_ORACLE_MARKET" } }
354
+ ]
355
+ ],
356
+ validate: async (runtime) => !!getBaseUrl(runtime),
357
+ handler: async (runtime, message, _state, _options, callback) => {
358
+ const text = message.content.text?.toLowerCase() || "";
359
+ let game = "Pokemon";
360
+ for (const g of SUPPORTED_GAMES) {
361
+ if (text.includes(g.toLowerCase())) {
362
+ game = g;
363
+ break;
364
+ }
365
+ }
366
+ const result = await callApi(getBaseUrl(runtime), "/api/v1/market", { game });
367
+ if (result.error) {
368
+ if (callback) await callback({ text: `Market data failed: ${result.error}` });
369
+ return { success: false, error: result.error };
370
+ }
371
+ const summary = safeStringify(result.data, 25);
372
+ const responseText = `Market snapshot for ${game}:
373
+
374
+ ${summary}`;
375
+ if (callback) await callback({ text: responseText }, "TCG_ORACLE_MARKET");
376
+ return { success: true, text: responseText, data: { market_data: result.data } };
377
+ }
378
+ };
379
+ var gradeOrNotAction = {
380
+ name: "TCG_ORACLE_GRADE_OR_NOT",
381
+ description: "Answers 'will grading this card make me money?' by combining AI grade prediction with PSA fee schedules, shipping costs, and graded market values. Returns a GO/NO-GO verdict with expected ROI and profit scenarios (best case, predicted, worst case).",
382
+ similes: [
383
+ "SHOULD_I_GRADE",
384
+ "GRADE_ROI",
385
+ "GRADING_PROFIT",
386
+ "IS_IT_WORTH_GRADING",
387
+ "GRADE_OR_NOT"
388
+ ],
389
+ parameters: [
390
+ {
391
+ name: "card_name",
392
+ description: "Name of the card to evaluate (e.g., 'Base Set Charizard Holo')",
393
+ required: true,
394
+ schema: { type: "string" }
395
+ },
396
+ {
397
+ name: "predicted_grade",
398
+ description: "Your predicted PSA grade (0 = auto-estimate)",
399
+ required: false,
400
+ schema: { type: "number" }
401
+ },
402
+ {
403
+ name: "raw_price",
404
+ description: "Current raw card value in USD (0 = auto-lookup)",
405
+ required: false,
406
+ schema: { type: "number" }
407
+ }
408
+ ],
409
+ examples: [
410
+ [
411
+ { name: "{{user1}}", content: { text: "Should I grade my Base Set Charizard?" } },
412
+ { name: "{{agentName}}", content: { text: "Running Grade-or-Not analysis...", action: "TCG_ORACLE_GRADE_OR_NOT" } }
358
413
  ],
359
- validate: async (runtime) => !!getBaseUrl(runtime),
360
- handler: async (runtime, message, _state, _options, callback) => {
361
- const text = message.content.text?.toLowerCase() || "";
362
- // Detect game from message
363
- let game = "Pokemon";
364
- for (const g of SUPPORTED_GAMES) {
365
- if (text.includes(g.toLowerCase())) {
366
- game = g;
367
- break;
368
- }
369
- }
370
- const result = await callApi(getBaseUrl(runtime), "/api/v1/market", { game });
371
- if (result.error) {
372
- if (callback)
373
- await callback({ text: `Market data failed: ${result.error}` });
374
- return { success: false, error: result.error };
375
- }
376
- const summary = safeStringify(result.data, 25);
377
- const responseText = `Market snapshot for ${game}:\n\n${summary}`;
378
- if (callback)
379
- await callback({ text: responseText }, "TCG_ORACLE_MARKET");
380
- return { success: true, text: responseText, data: { market_data: result.data } };
414
+ [
415
+ { name: "{{user1}}", content: { text: "Is it worth grading a PSA 8 Pikachu VMAX worth $45?" } },
416
+ { name: "{{agentName}}", content: { text: "Calculating grading ROI for Pikachu VMAX...", action: "TCG_ORACLE_GRADE_OR_NOT" } }
417
+ ]
418
+ ],
419
+ validate: async (runtime) => !!getBaseUrl(runtime),
420
+ handler: async (runtime, message, _state, _options, callback) => {
421
+ const text = message.content.text || "";
422
+ const cardName = text.replace(/^(should i|is it worth|grade or not|grading roi|will grading)\s*/i, "").replace(/\s*(make me money|be profitable|worth it)\s*\??$/i, "").replace(/^(grade|grading)\s*/i, "").replace(/\bmy\b/i, "").trim() || "Unknown Card";
423
+ const priceMatch = text.match(/\$?([\d,]+(?:\.\d{2})?)/);
424
+ const gradeMatch = text.match(/\bpsa\s*(\d+(?:\.\d)?)\b/i) || text.match(/\bgrade\s*(\d+(?:\.\d)?)\b/i);
425
+ const params = { card_name: cardName };
426
+ if (priceMatch) params.raw_price = parseFloat(priceMatch[1].replace(",", ""));
427
+ if (gradeMatch) params.predicted_grade = parseFloat(gradeMatch[1]);
428
+ const result = await callApi(getBaseUrl(runtime), "/api/v1/grade-or-not", params);
429
+ if (result.error) {
430
+ if (callback) await callback({ text: `Grade-or-Not analysis failed: ${result.error}` });
431
+ return { success: false, error: result.error };
432
+ }
433
+ const data = result.data;
434
+ const verdict = data?.verdict || "Unknown";
435
+ const explanation = data?.explanation || "";
436
+ const responseText = `Grade-or-Not verdict for ${cardName}:
437
+
438
+ ${verdict}
439
+ ${explanation}
440
+
441
+ Full analysis:
442
+ ${safeStringify(data)}`;
443
+ if (callback) await callback({ text: responseText }, "TCG_ORACLE_GRADE_OR_NOT");
444
+ return { success: true, text: responseText, data: { grade_or_not: data } };
445
+ }
446
+ };
447
+ var trendingAction = {
448
+ name: "TCG_ORACLE_TRENDING",
449
+ description: "Returns the top trending trading cards by market activity (30-day sales volume, views, and price velocity). Covers all 25 supported TCG games. Useful for spotting market momentum and emerging opportunities.",
450
+ similes: [
451
+ "TRENDING_CARDS",
452
+ "HOT_CARDS",
453
+ "TOP_MOVERS",
454
+ "WHATS_TRENDING",
455
+ "POPULAR_CARDS",
456
+ "MARKET_TRENDS"
457
+ ],
458
+ parameters: [
459
+ {
460
+ name: "game",
461
+ description: "Filter by game name (empty = all games)",
462
+ required: false,
463
+ schema: { type: "string" }
381
464
  },
465
+ {
466
+ name: "limit",
467
+ description: "Number of results (default: 25, max: 100)",
468
+ required: false,
469
+ schema: { type: "number" }
470
+ }
471
+ ],
472
+ examples: [
473
+ [
474
+ { name: "{{user1}}", content: { text: "What Pokemon cards are trending right now?" } },
475
+ { name: "{{agentName}}", content: { text: "Pulling trending Pokemon cards...", action: "TCG_ORACLE_TRENDING" } }
476
+ ],
477
+ [
478
+ { name: "{{user1}}", content: { text: "Show me the hottest cards across all games" } },
479
+ { name: "{{agentName}}", content: { text: "Fetching trending cards across all TCG games...", action: "TCG_ORACLE_TRENDING" } }
480
+ ]
481
+ ],
482
+ validate: async (runtime) => !!getBaseUrl(runtime),
483
+ handler: async (runtime, message, _state, _options, callback) => {
484
+ const text = message.content?.text?.toLowerCase() || "";
485
+ let game = "";
486
+ for (const g of SUPPORTED_GAMES) {
487
+ if (text.includes(g.toLowerCase())) {
488
+ game = g;
489
+ break;
490
+ }
491
+ }
492
+ const params = { limit: 25 };
493
+ if (game) params.game = game;
494
+ const result = await callApi(getBaseUrl(runtime), "/api/v1/trending", params);
495
+ if (result.error) {
496
+ if (callback) await callback({ text: `Trending cards failed: ${result.error}` });
497
+ return { success: false, error: result.error };
498
+ }
499
+ const summary = safeStringify(result.data, 15);
500
+ const responseText = `Trending cards${game ? ` for ${game}` : " across all games"}:
501
+
502
+ ${summary}`;
503
+ if (callback) await callback({ text: responseText }, "TCG_ORACLE_TRENDING");
504
+ return { success: true, text: responseText, data: { trending: result.data } };
505
+ }
382
506
  };
383
- // ============================================================
384
- // PROVIDER: TCG Oracle Context
385
- // ============================================================
386
- const tcgOracleProvider = {
387
- name: "tcg-oracle",
388
- description: "Provides TCG Oracle market intelligence context to the agent",
389
- get: async (runtime, _message, _state) => {
390
- const baseUrl = getBaseUrl(runtime);
391
- const status = baseUrl ? "connected" : "not configured";
392
- return {
393
- text: `[TCG Oracle]
507
+ var tcgOracleProvider = {
508
+ name: "tcg-oracle",
509
+ description: "Provides TCG Oracle market intelligence context to the agent",
510
+ get: async (runtime, _message, _state) => {
511
+ const baseUrl = getBaseUrl(runtime);
512
+ const status = baseUrl ? "connected" : "not configured";
513
+ return {
514
+ text: `[TCG Oracle v1.1.0]
394
515
  Status: ${status}
395
- Database: 370,158 products across 25 games
516
+ Database: 446K+ products across 25+ games
396
517
  Data source: TCGCSV daily snapshots
397
- Models: Heston (stochastic vol), Merton (jump-diffusion), Kou (double-exp)
518
+ Models: conformal (default \u2014 regime-aware split-conformal bands, honest VaR), merton (jump-diffusion), gbm \u2014 Monte Carlo is opt-in
519
+ Actions: search, grade, simulate, market, grade-or-not, trending
398
520
  Supported games: ${SUPPORTED_GAMES.join(", ")}
399
521
  API: ${baseUrl || "TCG_ORACLE_URL not set"}
400
522
 
401
- The agent can search cards, grade card images, simulate prices via Monte Carlo, and pull market snapshots.`,
402
- values: {
403
- tcgOracleStatus: status,
404
- tcgOracleUrl: baseUrl || "not set",
405
- totalProducts: 370158,
406
- },
407
- };
408
- },
523
+ The agent can search cards, grade card images, simulate prices via Monte Carlo, pull market snapshots, check grading ROI, view trending cards, and scan for grading arbitrage opportunities.`,
524
+ values: {
525
+ tcgOracleStatus: status,
526
+ tcgOracleUrl: baseUrl || "not set",
527
+ totalProducts: 370158
528
+ }
529
+ };
530
+ }
409
531
  };
410
- // ============================================================
411
- // PLUGIN EXPORT
412
- // ============================================================
413
- const tcgOraclePlugin = {
414
- name: "@undesirables/plugin-tcg-oracle",
415
- description: "TCG Oracle — AI-powered trading card market intelligence for ElizaOS agents. " +
416
- "Covers 370K+ products across 25 games with Monte Carlo price simulation " +
417
- "(Heston/Merton/Kou), AI vision card grading, and real-time market snapshots. " +
418
- "Powered by TCGCSV daily data pipeline.",
419
- init: async (config, runtime) => {
420
- const validation = validateTcgOracleConfig(runtime);
421
- if (!validation.valid) {
422
- console.warn(`⚠️ TCG Oracle: ${validation.error}`);
423
- }
424
- else {
425
- console.log(`✅ TCG Oracle connected to ${runtime.getSetting?.("TCG_ORACLE_URL")}`);
426
- }
427
- },
428
- actions: [searchAction, gradeAction, simulateAction, marketAction],
429
- providers: [tcgOracleProvider],
430
- evaluators: [],
532
+ var tcgOraclePlugin = {
533
+ name: "@undesirables/plugin-tcg-oracle",
534
+ description: "TCG Oracle \u2014 AI-powered trading card market intelligence for ElizaOS agents. Covers 446K+ products across 25+ games with conformal-calibrated risk forecasts \u2014 honest VaR plus Safe-Hold/Momentum letter grades, with Monte Carlo (GBM/Merton) available opt-in \u2014 AI vision card grading with ROI analysis, trending cards feed, and real-time market snapshots. Powered by TCGCSV daily data pipeline.",
535
+ init: async (config, runtime) => {
536
+ const validation = validateTcgOracleConfig(runtime);
537
+ if (!validation.valid) {
538
+ console.warn(`\u26A0\uFE0F TCG Oracle: ${validation.error}`);
539
+ } else {
540
+ console.log(`\u2705 TCG Oracle v1.1.0 connected to ${runtime.getSetting?.("TCG_ORACLE_URL")}`);
541
+ }
542
+ },
543
+ actions: [searchAction, gradeAction, simulateAction, marketAction, gradeOrNotAction, trendingAction],
544
+ providers: [tcgOracleProvider],
545
+ evaluators: [],
546
+ services: [MarketMonitorService]
547
+ };
548
+ var index_default = tcgOraclePlugin;
549
+ export {
550
+ SIMULATION_MODELS,
551
+ SUPPORTED_GAMES,
552
+ index_default as default
431
553
  };
432
- export default tcgOraclePlugin;
433
- export { SUPPORTED_GAMES, SIMULATION_MODELS };
434
554
  //# sourceMappingURL=index.js.map