equilibria-mcp-server 1.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.
Files changed (164) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/LICENSE +21 -0
  3. package/README.md +240 -0
  4. package/dist/builders/YAMLBuilder.d.ts +77 -0
  5. package/dist/builders/YAMLBuilder.d.ts.map +1 -0
  6. package/dist/builders/YAMLBuilder.js +251 -0
  7. package/dist/builders/YAMLBuilder.js.map +1 -0
  8. package/dist/economics/constants.d.ts +39 -0
  9. package/dist/economics/constants.d.ts.map +1 -0
  10. package/dist/economics/constants.js +46 -0
  11. package/dist/economics/constants.js.map +1 -0
  12. package/dist/economics/formulas.d.ts +19 -0
  13. package/dist/economics/formulas.d.ts.map +1 -0
  14. package/dist/economics/formulas.js +260 -0
  15. package/dist/economics/formulas.js.map +1 -0
  16. package/dist/economics/index.d.ts +9 -0
  17. package/dist/economics/index.d.ts.map +1 -0
  18. package/dist/economics/index.js +9 -0
  19. package/dist/economics/index.js.map +1 -0
  20. package/dist/economics/validators.d.ts +18 -0
  21. package/dist/economics/validators.d.ts.map +1 -0
  22. package/dist/economics/validators.js +111 -0
  23. package/dist/economics/validators.js.map +1 -0
  24. package/dist/errors/index.d.ts +172 -0
  25. package/dist/errors/index.d.ts.map +1 -0
  26. package/dist/errors/index.js +313 -0
  27. package/dist/errors/index.js.map +1 -0
  28. package/dist/formatters/index.d.ts +8 -0
  29. package/dist/formatters/index.d.ts.map +1 -0
  30. package/dist/formatters/index.js +8 -0
  31. package/dist/formatters/index.js.map +1 -0
  32. package/dist/formatters/redux.d.ts +15 -0
  33. package/dist/formatters/redux.d.ts.map +1 -0
  34. package/dist/formatters/redux.js +35 -0
  35. package/dist/formatters/redux.js.map +1 -0
  36. package/dist/formatters/yaml.d.ts +18 -0
  37. package/dist/formatters/yaml.d.ts.map +1 -0
  38. package/dist/formatters/yaml.js +40 -0
  39. package/dist/formatters/yaml.js.map +1 -0
  40. package/dist/index.d.ts +11 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +19 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/server.d.ts +14 -0
  45. package/dist/server.d.ts.map +1 -0
  46. package/dist/server.js +86 -0
  47. package/dist/server.js.map +1 -0
  48. package/dist/templates/advancedMicro.d.ts +8 -0
  49. package/dist/templates/advancedMicro.d.ts.map +1 -0
  50. package/dist/templates/advancedMicro.js +834 -0
  51. package/dist/templates/advancedMicro.js.map +1 -0
  52. package/dist/templates/consumer.d.ts +12 -0
  53. package/dist/templates/consumer.d.ts.map +1 -0
  54. package/dist/templates/consumer.js +1978 -0
  55. package/dist/templates/consumer.js.map +1 -0
  56. package/dist/templates/elasticity.d.ts +8 -0
  57. package/dist/templates/elasticity.d.ts.map +1 -0
  58. package/dist/templates/elasticity.js +500 -0
  59. package/dist/templates/elasticity.js.map +1 -0
  60. package/dist/templates/externalities.d.ts +11 -0
  61. package/dist/templates/externalities.d.ts.map +1 -0
  62. package/dist/templates/externalities.js +997 -0
  63. package/dist/templates/externalities.js.map +1 -0
  64. package/dist/templates/financeBehavioral.d.ts +8 -0
  65. package/dist/templates/financeBehavioral.d.ts.map +1 -0
  66. package/dist/templates/financeBehavioral.js +860 -0
  67. package/dist/templates/financeBehavioral.js.map +1 -0
  68. package/dist/templates/growth.d.ts +8 -0
  69. package/dist/templates/growth.d.ts.map +1 -0
  70. package/dist/templates/growth.js +740 -0
  71. package/dist/templates/growth.js.map +1 -0
  72. package/dist/templates/index.d.ts +31 -0
  73. package/dist/templates/index.d.ts.map +1 -0
  74. package/dist/templates/index.js +91 -0
  75. package/dist/templates/index.js.map +1 -0
  76. package/dist/templates/inequality.d.ts +8 -0
  77. package/dist/templates/inequality.d.ts.map +1 -0
  78. package/dist/templates/inequality.js +562 -0
  79. package/dist/templates/inequality.js.map +1 -0
  80. package/dist/templates/intertemporalMacro.d.ts +8 -0
  81. package/dist/templates/intertemporalMacro.d.ts.map +1 -0
  82. package/dist/templates/intertemporalMacro.js +550 -0
  83. package/dist/templates/intertemporalMacro.js.map +1 -0
  84. package/dist/templates/isLM.d.ts +8 -0
  85. package/dist/templates/isLM.d.ts.map +1 -0
  86. package/dist/templates/isLM.js +747 -0
  87. package/dist/templates/isLM.js.map +1 -0
  88. package/dist/templates/macro.d.ts +8 -0
  89. package/dist/templates/macro.d.ts.map +1 -0
  90. package/dist/templates/macro.js +600 -0
  91. package/dist/templates/macro.js.map +1 -0
  92. package/dist/templates/marketStructures.d.ts +11 -0
  93. package/dist/templates/marketStructures.d.ts.map +1 -0
  94. package/dist/templates/marketStructures.js +1135 -0
  95. package/dist/templates/marketStructures.js.map +1 -0
  96. package/dist/templates/newKeynesian.d.ts +8 -0
  97. package/dist/templates/newKeynesian.d.ts.map +1 -0
  98. package/dist/templates/newKeynesian.js +633 -0
  99. package/dist/templates/newKeynesian.js.map +1 -0
  100. package/dist/templates/oligopoly.d.ts +11 -0
  101. package/dist/templates/oligopoly.d.ts.map +1 -0
  102. package/dist/templates/oligopoly.js +1113 -0
  103. package/dist/templates/oligopoly.js.map +1 -0
  104. package/dist/templates/ppf.d.ts +8 -0
  105. package/dist/templates/ppf.d.ts.map +1 -0
  106. package/dist/templates/ppf.js +439 -0
  107. package/dist/templates/ppf.js.map +1 -0
  108. package/dist/templates/producer.d.ts +11 -0
  109. package/dist/templates/producer.d.ts.map +1 -0
  110. package/dist/templates/producer.js +979 -0
  111. package/dist/templates/producer.js.map +1 -0
  112. package/dist/templates/production.d.ts +8 -0
  113. package/dist/templates/production.d.ts.map +1 -0
  114. package/dist/templates/production.js +574 -0
  115. package/dist/templates/production.js.map +1 -0
  116. package/dist/templates/supplyDemand.d.ts +8 -0
  117. package/dist/templates/supplyDemand.d.ts.map +1 -0
  118. package/dist/templates/supplyDemand.js +1282 -0
  119. package/dist/templates/supplyDemand.js.map +1 -0
  120. package/dist/templates/tradeGrowth.d.ts +8 -0
  121. package/dist/templates/tradeGrowth.d.ts.map +1 -0
  122. package/dist/templates/tradeGrowth.js +637 -0
  123. package/dist/templates/tradeGrowth.js.map +1 -0
  124. package/dist/tools/index.d.ts +25 -0
  125. package/dist/tools/index.d.ts.map +1 -0
  126. package/dist/tools/index.js +54 -0
  127. package/dist/tools/index.js.map +1 -0
  128. package/dist/tools/models.d.ts +8 -0
  129. package/dist/tools/models.d.ts.map +1 -0
  130. package/dist/tools/models.js +828 -0
  131. package/dist/tools/models.js.map +1 -0
  132. package/dist/tools/output.d.ts +8 -0
  133. package/dist/tools/output.d.ts.map +1 -0
  134. package/dist/tools/output.js +236 -0
  135. package/dist/tools/output.js.map +1 -0
  136. package/dist/tools/templates.d.ts +8 -0
  137. package/dist/tools/templates.d.ts.map +1 -0
  138. package/dist/tools/templates.js +247 -0
  139. package/dist/tools/templates.js.map +1 -0
  140. package/dist/tools/validation.d.ts +8 -0
  141. package/dist/tools/validation.d.ts.map +1 -0
  142. package/dist/tools/validation.js +181 -0
  143. package/dist/tools/validation.js.map +1 -0
  144. package/dist/types/index.d.ts +187 -0
  145. package/dist/types/index.d.ts.map +1 -0
  146. package/dist/types/index.js +7 -0
  147. package/dist/types/index.js.map +1 -0
  148. package/dist/utils/cache.d.ts +99 -0
  149. package/dist/utils/cache.d.ts.map +1 -0
  150. package/dist/utils/cache.js +192 -0
  151. package/dist/utils/cache.js.map +1 -0
  152. package/dist/utils/index.d.ts +8 -0
  153. package/dist/utils/index.d.ts.map +1 -0
  154. package/dist/utils/index.js +8 -0
  155. package/dist/utils/index.js.map +1 -0
  156. package/dist/utils/logger.d.ts +128 -0
  157. package/dist/utils/logger.d.ts.map +1 -0
  158. package/dist/utils/logger.js +251 -0
  159. package/dist/utils/logger.js.map +1 -0
  160. package/dist/validation/index.d.ts +42 -0
  161. package/dist/validation/index.d.ts.map +1 -0
  162. package/dist/validation/index.js +282 -0
  163. package/dist/validation/index.js.map +1 -0
  164. package/package.json +73 -0
@@ -0,0 +1,828 @@
1
+ /**
2
+ * Model Building Tools
3
+ *
4
+ * Mid-level tools for incrementally constructing economic visualizations.
5
+ */
6
+ import { YAMLBuilder } from '../builders/YAMLBuilder.js';
7
+ import { formatAsYAML } from '../formatters/yaml.js';
8
+ // Shared builder instance for multi-step construction
9
+ let currentBuilder = null;
10
+ /**
11
+ * Tool: create_chart
12
+ *
13
+ * Creates a new chart or starts a new document.
14
+ */
15
+ const createChart = {
16
+ tool: {
17
+ name: 'create_chart',
18
+ description: 'Create a new economic chart. This initializes or adds to the current document being built. Use export_document to get the final YAML.',
19
+ inputSchema: {
20
+ type: 'object',
21
+ properties: {
22
+ id: {
23
+ type: 'string',
24
+ description: 'Unique identifier for the chart',
25
+ },
26
+ title: {
27
+ type: 'string',
28
+ description: 'Display title for the chart',
29
+ },
30
+ xAxis: {
31
+ type: 'object',
32
+ properties: {
33
+ label: { type: 'string' },
34
+ min: { type: 'number' },
35
+ max: { type: 'number' },
36
+ },
37
+ required: ['label', 'min', 'max'],
38
+ },
39
+ yAxis: {
40
+ type: 'object',
41
+ properties: {
42
+ label: { type: 'string' },
43
+ min: { type: 'number' },
44
+ max: { type: 'number' },
45
+ },
46
+ required: ['label', 'min', 'max'],
47
+ },
48
+ newDocument: {
49
+ type: 'boolean',
50
+ description: 'Start a new document (discards current if any)',
51
+ default: false,
52
+ },
53
+ },
54
+ required: ['id', 'xAxis', 'yAxis'],
55
+ },
56
+ },
57
+ handler: async (args, context) => {
58
+ const id = args.id;
59
+ const title = args.title;
60
+ const xAxis = args.xAxis;
61
+ const yAxis = args.yAxis;
62
+ const newDocument = args.newDocument;
63
+ if (newDocument || !currentBuilder) {
64
+ currentBuilder = new YAMLBuilder();
65
+ }
66
+ currentBuilder.addChart({
67
+ id,
68
+ title,
69
+ xAxis: {
70
+ label: xAxis.label,
71
+ min: xAxis.min,
72
+ max: xAxis.max,
73
+ },
74
+ yAxis: {
75
+ label: yAxis.label,
76
+ min: yAxis.min,
77
+ max: yAxis.max,
78
+ },
79
+ elements: [],
80
+ });
81
+ context.sessionState.set('currentChartId', id);
82
+ return {
83
+ content: [
84
+ {
85
+ type: 'text',
86
+ text: `Created chart "${id}". Use add_curve, add_point, add_area to add elements, then export_document to get the YAML.`,
87
+ },
88
+ ],
89
+ };
90
+ },
91
+ };
92
+ /**
93
+ * Tool: add_curve
94
+ *
95
+ * Adds a curve/line to the current chart.
96
+ */
97
+ const addCurve = {
98
+ tool: {
99
+ name: 'add_curve',
100
+ description: 'Add a curve or line to the current chart. The equation should be a mathematical expression in terms of x.',
101
+ inputSchema: {
102
+ type: 'object',
103
+ properties: {
104
+ id: {
105
+ type: 'string',
106
+ description: 'Unique identifier for the curve',
107
+ },
108
+ equation: {
109
+ type: 'string',
110
+ description: 'Mathematical equation (e.g., "100 - 2*x", "x^2", "50 + slope * x")',
111
+ },
112
+ label: {
113
+ type: 'string',
114
+ description: 'Label for the curve (shown in legend)',
115
+ },
116
+ color: {
117
+ type: 'string',
118
+ description: 'Hex color (e.g., "#FF0000")',
119
+ },
120
+ chartId: {
121
+ type: 'string',
122
+ description: 'Chart to add to (uses current chart if not specified)',
123
+ },
124
+ lineStyle: {
125
+ type: 'string',
126
+ enum: ['solid', 'dashed', 'dotted'],
127
+ description: 'Line style',
128
+ },
129
+ domain: {
130
+ type: 'object',
131
+ properties: {
132
+ min: { type: 'number' },
133
+ max: { type: 'number' },
134
+ },
135
+ description: 'Domain restriction for the curve',
136
+ },
137
+ },
138
+ required: ['id', 'equation'],
139
+ },
140
+ },
141
+ handler: async (args, context) => {
142
+ if (!currentBuilder) {
143
+ return {
144
+ content: [
145
+ {
146
+ type: 'text',
147
+ text: 'No document started. Use create_chart first.',
148
+ },
149
+ ],
150
+ isError: true,
151
+ };
152
+ }
153
+ const chartId = args.chartId ||
154
+ context.sessionState.get('currentChartId');
155
+ if (!chartId) {
156
+ return {
157
+ content: [
158
+ {
159
+ type: 'text',
160
+ text: 'No chart specified. Use create_chart first or specify chartId.',
161
+ },
162
+ ],
163
+ isError: true,
164
+ };
165
+ }
166
+ const element = {
167
+ id: args.id,
168
+ type: 'line',
169
+ equation: args.equation,
170
+ };
171
+ if (args.label)
172
+ element.label = args.label;
173
+ if (args.color)
174
+ element.color = args.color;
175
+ if (args.lineStyle)
176
+ element.lineStyle = args.lineStyle;
177
+ if (args.domain)
178
+ element.domain = args.domain;
179
+ currentBuilder.addElement(chartId, element);
180
+ return {
181
+ content: [
182
+ {
183
+ type: 'text',
184
+ text: `Added curve "${args.id}" with equation "${args.equation}" to chart "${chartId}".`,
185
+ },
186
+ ],
187
+ };
188
+ },
189
+ };
190
+ /**
191
+ * Tool: add_point
192
+ *
193
+ * Adds a point to the current chart.
194
+ */
195
+ const addPoint = {
196
+ tool: {
197
+ name: 'add_point',
198
+ description: 'Add a point to the current chart. Can be at explicit coordinates or at the intersection of two curves.',
199
+ inputSchema: {
200
+ type: 'object',
201
+ properties: {
202
+ id: {
203
+ type: 'string',
204
+ description: 'Unique identifier for the point',
205
+ },
206
+ x: {
207
+ type: ['number', 'string'],
208
+ description: 'X coordinate (number or expression)',
209
+ },
210
+ y: {
211
+ type: ['number', 'string'],
212
+ description: 'Y coordinate (number or expression)',
213
+ },
214
+ intersection: {
215
+ type: 'object',
216
+ properties: {
217
+ curve1: { type: 'string' },
218
+ curve2: { type: 'string' },
219
+ index: { type: 'number' },
220
+ },
221
+ description: 'Find point at intersection of two curves (alternative to x,y)',
222
+ },
223
+ label: {
224
+ type: 'string',
225
+ description: 'Label for the point',
226
+ },
227
+ color: {
228
+ type: 'string',
229
+ description: 'Hex color',
230
+ },
231
+ chartId: {
232
+ type: 'string',
233
+ description: 'Chart to add to',
234
+ },
235
+ droplines: {
236
+ type: 'object',
237
+ properties: {
238
+ x: { type: 'boolean' },
239
+ y: { type: 'boolean' },
240
+ },
241
+ description: 'Show droplines to axes',
242
+ },
243
+ },
244
+ required: ['id'],
245
+ },
246
+ },
247
+ handler: async (args, context) => {
248
+ if (!currentBuilder) {
249
+ return {
250
+ content: [
251
+ {
252
+ type: 'text',
253
+ text: 'No document started. Use create_chart first.',
254
+ },
255
+ ],
256
+ isError: true,
257
+ };
258
+ }
259
+ const chartId = args.chartId ||
260
+ context.sessionState.get('currentChartId');
261
+ if (!chartId) {
262
+ return {
263
+ content: [
264
+ {
265
+ type: 'text',
266
+ text: 'No chart specified.',
267
+ },
268
+ ],
269
+ isError: true,
270
+ };
271
+ }
272
+ const element = {
273
+ id: args.id,
274
+ type: 'point',
275
+ };
276
+ if (args.intersection) {
277
+ element.intersection = args.intersection;
278
+ }
279
+ else {
280
+ if (args.x !== undefined)
281
+ element.x = args.x;
282
+ if (args.y !== undefined)
283
+ element.y = args.y;
284
+ }
285
+ if (args.label)
286
+ element.label = args.label;
287
+ if (args.color)
288
+ element.color = args.color;
289
+ if (args.droplines)
290
+ element.droplines = args.droplines;
291
+ currentBuilder.addElement(chartId, element);
292
+ return {
293
+ content: [
294
+ {
295
+ type: 'text',
296
+ text: `Added point "${args.id}" to chart "${chartId}".`,
297
+ },
298
+ ],
299
+ };
300
+ },
301
+ };
302
+ /**
303
+ * Tool: add_area
304
+ *
305
+ * Adds a shaded area to the current chart.
306
+ */
307
+ const addArea = {
308
+ tool: {
309
+ name: 'add_area',
310
+ description: 'Add a shaded area to the current chart. Useful for showing surplus, deadweight loss, etc.',
311
+ inputSchema: {
312
+ type: 'object',
313
+ properties: {
314
+ id: {
315
+ type: 'string',
316
+ description: 'Unique identifier for the area',
317
+ },
318
+ topBoundary: {
319
+ type: 'string',
320
+ description: 'Top boundary (curve ID or expression)',
321
+ },
322
+ bottomBoundary: {
323
+ type: 'string',
324
+ description: 'Bottom boundary (curve ID or expression)',
325
+ },
326
+ leftBoundary: {
327
+ type: 'string',
328
+ description: 'Left boundary (curve ID or value)',
329
+ },
330
+ rightBoundary: {
331
+ type: 'string',
332
+ description: 'Right boundary (curve ID or value)',
333
+ },
334
+ label: {
335
+ type: 'string',
336
+ description: 'Label for the area',
337
+ },
338
+ color: {
339
+ type: 'string',
340
+ description: 'Fill color',
341
+ },
342
+ opacity: {
343
+ type: 'number',
344
+ description: 'Fill opacity (0-1)',
345
+ },
346
+ chartId: {
347
+ type: 'string',
348
+ description: 'Chart to add to',
349
+ },
350
+ },
351
+ required: ['id', 'topBoundary', 'bottomBoundary', 'leftBoundary', 'rightBoundary'],
352
+ },
353
+ },
354
+ handler: async (args, context) => {
355
+ if (!currentBuilder) {
356
+ return {
357
+ content: [
358
+ {
359
+ type: 'text',
360
+ text: 'No document started. Use create_chart first.',
361
+ },
362
+ ],
363
+ isError: true,
364
+ };
365
+ }
366
+ const chartId = args.chartId ||
367
+ context.sessionState.get('currentChartId');
368
+ if (!chartId) {
369
+ return {
370
+ content: [
371
+ {
372
+ type: 'text',
373
+ text: 'No chart specified.',
374
+ },
375
+ ],
376
+ isError: true,
377
+ };
378
+ }
379
+ const element = {
380
+ id: args.id,
381
+ type: 'area',
382
+ topBoundary: args.topBoundary,
383
+ bottomBoundary: args.bottomBoundary,
384
+ leftBoundary: args.leftBoundary,
385
+ rightBoundary: args.rightBoundary,
386
+ };
387
+ if (args.label)
388
+ element.label = args.label;
389
+ if (args.color)
390
+ element.color = args.color;
391
+ if (args.opacity !== undefined)
392
+ element.opacity = args.opacity;
393
+ currentBuilder.addElement(chartId, element);
394
+ return {
395
+ content: [
396
+ {
397
+ type: 'text',
398
+ text: `Added area "${args.id}" to chart "${chartId}".`,
399
+ },
400
+ ],
401
+ };
402
+ },
403
+ };
404
+ /**
405
+ * Tool: add_parameter
406
+ *
407
+ * Adds a parameter to the document.
408
+ */
409
+ const addParameter = {
410
+ tool: {
411
+ name: 'add_parameter',
412
+ description: 'Add a parameter to the document. Parameters can be used in expressions and made interactive with sliders.',
413
+ inputSchema: {
414
+ type: 'object',
415
+ properties: {
416
+ name: {
417
+ type: 'string',
418
+ description: 'Parameter name (used in expressions)',
419
+ },
420
+ value: {
421
+ type: 'number',
422
+ description: 'Initial value',
423
+ },
424
+ min: {
425
+ type: 'number',
426
+ description: 'Minimum value (for slider)',
427
+ },
428
+ max: {
429
+ type: 'number',
430
+ description: 'Maximum value (for slider)',
431
+ },
432
+ step: {
433
+ type: 'number',
434
+ description: 'Step size (for slider)',
435
+ },
436
+ label: {
437
+ type: 'string',
438
+ description: 'Display label',
439
+ },
440
+ chartId: {
441
+ type: 'string',
442
+ description: 'Chart to add to (global if not specified)',
443
+ },
444
+ },
445
+ required: ['name', 'value'],
446
+ },
447
+ },
448
+ handler: async (args) => {
449
+ if (!currentBuilder) {
450
+ return {
451
+ content: [
452
+ {
453
+ type: 'text',
454
+ text: 'No document started. Use create_chart first.',
455
+ },
456
+ ],
457
+ isError: true,
458
+ };
459
+ }
460
+ const name = args.name;
461
+ const param = {
462
+ value: args.value,
463
+ };
464
+ if (args.min !== undefined)
465
+ param.min = args.min;
466
+ if (args.max !== undefined)
467
+ param.max = args.max;
468
+ if (args.step !== undefined)
469
+ param.step = args.step;
470
+ if (args.label)
471
+ param.label = args.label;
472
+ const chartId = args.chartId;
473
+ currentBuilder.addParameter(name, param, chartId);
474
+ return {
475
+ content: [
476
+ {
477
+ type: 'text',
478
+ text: chartId
479
+ ? `Added parameter "${name}" to chart "${chartId}".`
480
+ : `Added global parameter "${name}".`,
481
+ },
482
+ ],
483
+ };
484
+ },
485
+ };
486
+ /**
487
+ * Tool: add_annotation
488
+ *
489
+ * Adds a text annotation to the current chart.
490
+ */
491
+ const addAnnotation = {
492
+ tool: {
493
+ name: 'add_annotation',
494
+ description: 'Add a text annotation (label, callout, or note) to the current chart at specified coordinates.',
495
+ inputSchema: {
496
+ type: 'object',
497
+ properties: {
498
+ id: {
499
+ type: 'string',
500
+ description: 'Unique identifier for the annotation',
501
+ },
502
+ text: {
503
+ type: 'string',
504
+ description: 'Text content of the annotation (can include parameter interpolation like "${P_eq:.2f}")',
505
+ },
506
+ x: {
507
+ type: ['number', 'string'],
508
+ description: 'X position (number or expression)',
509
+ },
510
+ y: {
511
+ type: ['number', 'string'],
512
+ description: 'Y position (number or expression)',
513
+ },
514
+ color: {
515
+ type: 'string',
516
+ description: 'Text color (hex code)',
517
+ },
518
+ fontSize: {
519
+ type: 'number',
520
+ description: 'Font size in pixels',
521
+ },
522
+ chartId: {
523
+ type: 'string',
524
+ description: 'Chart to add to (uses current chart if not specified)',
525
+ },
526
+ },
527
+ required: ['id', 'text', 'x', 'y'],
528
+ },
529
+ },
530
+ handler: async (args, context) => {
531
+ if (!currentBuilder) {
532
+ return {
533
+ content: [
534
+ {
535
+ type: 'text',
536
+ text: 'No document started. Use create_chart first.',
537
+ },
538
+ ],
539
+ isError: true,
540
+ };
541
+ }
542
+ const chartId = args.chartId ||
543
+ context.sessionState.get('currentChartId');
544
+ if (!chartId) {
545
+ return {
546
+ content: [
547
+ {
548
+ type: 'text',
549
+ text: 'No chart specified. Use create_chart first or specify chartId.',
550
+ },
551
+ ],
552
+ isError: true,
553
+ };
554
+ }
555
+ const annotation = {
556
+ id: args.id,
557
+ text: args.text,
558
+ x: args.x,
559
+ y: args.y,
560
+ color: args.color,
561
+ fontSize: args.fontSize,
562
+ };
563
+ // Remove undefined properties
564
+ Object.keys(annotation).forEach((key) => {
565
+ if (annotation[key] === undefined) {
566
+ delete annotation[key];
567
+ }
568
+ });
569
+ currentBuilder.addAnnotation(chartId, annotation);
570
+ return {
571
+ content: [
572
+ {
573
+ type: 'text',
574
+ text: `Added annotation "${args.id}" at (${args.x}, ${args.y}) to chart "${chartId}".`,
575
+ },
576
+ ],
577
+ };
578
+ },
579
+ };
580
+ /**
581
+ * Tool: add_vertical_line
582
+ *
583
+ * Adds a vertical line to the current chart.
584
+ */
585
+ const addVerticalLine = {
586
+ tool: {
587
+ name: 'add_vertical_line',
588
+ description: 'Add a vertical line at a specific x value. Useful for marking quantities, reference points, or constraints.',
589
+ inputSchema: {
590
+ type: 'object',
591
+ properties: {
592
+ id: {
593
+ type: 'string',
594
+ description: 'Unique identifier for the line',
595
+ },
596
+ x: {
597
+ type: ['number', 'string'],
598
+ description: 'X position (number or expression)',
599
+ },
600
+ label: {
601
+ type: 'string',
602
+ description: 'Label for the line',
603
+ },
604
+ color: {
605
+ type: 'string',
606
+ description: 'Line color (hex code)',
607
+ },
608
+ lineStyle: {
609
+ type: 'string',
610
+ enum: ['solid', 'dashed', 'dotted'],
611
+ description: 'Line style',
612
+ },
613
+ chartId: {
614
+ type: 'string',
615
+ description: 'Chart to add to',
616
+ },
617
+ },
618
+ required: ['id', 'x'],
619
+ },
620
+ },
621
+ handler: async (args, context) => {
622
+ if (!currentBuilder) {
623
+ return {
624
+ content: [
625
+ {
626
+ type: 'text',
627
+ text: 'No document started. Use create_chart first.',
628
+ },
629
+ ],
630
+ isError: true,
631
+ };
632
+ }
633
+ const chartId = args.chartId ||
634
+ context.sessionState.get('currentChartId');
635
+ if (!chartId) {
636
+ return {
637
+ content: [
638
+ {
639
+ type: 'text',
640
+ text: 'No chart specified.',
641
+ },
642
+ ],
643
+ isError: true,
644
+ };
645
+ }
646
+ const element = {
647
+ id: args.id,
648
+ type: 'verticalLine',
649
+ x: args.x,
650
+ };
651
+ if (args.label)
652
+ element.label = args.label;
653
+ if (args.color)
654
+ element.color = args.color;
655
+ if (args.lineStyle)
656
+ element.lineStyle = args.lineStyle;
657
+ currentBuilder.addElement(chartId, element);
658
+ return {
659
+ content: [
660
+ {
661
+ type: 'text',
662
+ text: `Added vertical line "${args.id}" at x=${args.x} to chart "${chartId}".`,
663
+ },
664
+ ],
665
+ };
666
+ },
667
+ };
668
+ /**
669
+ * Tool: add_horizontal_line
670
+ *
671
+ * Adds a horizontal line to the current chart.
672
+ */
673
+ const addHorizontalLine = {
674
+ tool: {
675
+ name: 'add_horizontal_line',
676
+ description: 'Add a horizontal line at a specific y value. Useful for marking prices, reference levels, or constraints.',
677
+ inputSchema: {
678
+ type: 'object',
679
+ properties: {
680
+ id: {
681
+ type: 'string',
682
+ description: 'Unique identifier for the line',
683
+ },
684
+ y: {
685
+ type: ['number', 'string'],
686
+ description: 'Y position (number or expression)',
687
+ },
688
+ label: {
689
+ type: 'string',
690
+ description: 'Label for the line',
691
+ },
692
+ color: {
693
+ type: 'string',
694
+ description: 'Line color (hex code)',
695
+ },
696
+ lineStyle: {
697
+ type: 'string',
698
+ enum: ['solid', 'dashed', 'dotted'],
699
+ description: 'Line style',
700
+ },
701
+ chartId: {
702
+ type: 'string',
703
+ description: 'Chart to add to',
704
+ },
705
+ },
706
+ required: ['id', 'y'],
707
+ },
708
+ },
709
+ handler: async (args, context) => {
710
+ if (!currentBuilder) {
711
+ return {
712
+ content: [
713
+ {
714
+ type: 'text',
715
+ text: 'No document started. Use create_chart first.',
716
+ },
717
+ ],
718
+ isError: true,
719
+ };
720
+ }
721
+ const chartId = args.chartId ||
722
+ context.sessionState.get('currentChartId');
723
+ if (!chartId) {
724
+ return {
725
+ content: [
726
+ {
727
+ type: 'text',
728
+ text: 'No chart specified.',
729
+ },
730
+ ],
731
+ isError: true,
732
+ };
733
+ }
734
+ const element = {
735
+ id: args.id,
736
+ type: 'horizontalLine',
737
+ y: args.y,
738
+ };
739
+ if (args.label)
740
+ element.label = args.label;
741
+ if (args.color)
742
+ element.color = args.color;
743
+ if (args.lineStyle)
744
+ element.lineStyle = args.lineStyle;
745
+ currentBuilder.addElement(chartId, element);
746
+ return {
747
+ content: [
748
+ {
749
+ type: 'text',
750
+ text: `Added horizontal line "${args.id}" at y=${args.y} to chart "${chartId}".`,
751
+ },
752
+ ],
753
+ };
754
+ },
755
+ };
756
+ /**
757
+ * Tool: export_document
758
+ *
759
+ * Exports the current document as YAML.
760
+ */
761
+ const exportDocument = {
762
+ tool: {
763
+ name: 'export_document',
764
+ description: 'Export the current document being built as YAML. This is the final step after using create_chart, add_curve, etc.',
765
+ inputSchema: {
766
+ type: 'object',
767
+ properties: {
768
+ title: {
769
+ type: 'string',
770
+ description: 'Document title',
771
+ },
772
+ description: {
773
+ type: 'string',
774
+ description: 'Document description',
775
+ },
776
+ clear: {
777
+ type: 'boolean',
778
+ description: 'Clear the document after export',
779
+ default: false,
780
+ },
781
+ },
782
+ },
783
+ },
784
+ handler: async (args) => {
785
+ if (!currentBuilder) {
786
+ return {
787
+ content: [
788
+ {
789
+ type: 'text',
790
+ text: 'No document to export. Use create_chart first.',
791
+ },
792
+ ],
793
+ isError: true,
794
+ };
795
+ }
796
+ if (args.title) {
797
+ currentBuilder.setTitle(args.title);
798
+ }
799
+ if (args.description) {
800
+ currentBuilder.setDescription(args.description);
801
+ }
802
+ const document = currentBuilder.build();
803
+ const yaml = formatAsYAML(document);
804
+ if (args.clear) {
805
+ currentBuilder = null;
806
+ }
807
+ return {
808
+ content: [
809
+ {
810
+ type: 'text',
811
+ text: yaml,
812
+ },
813
+ ],
814
+ };
815
+ },
816
+ };
817
+ export const modelTools = [
818
+ createChart,
819
+ addCurve,
820
+ addPoint,
821
+ addArea,
822
+ addParameter,
823
+ addAnnotation,
824
+ addVerticalLine,
825
+ addHorizontalLine,
826
+ exportDocument,
827
+ ];
828
+ //# sourceMappingURL=models.js.map