@memberjunction/core-actions 2.107.0 → 2.109.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/custom/ai/find-best-action.action.d.ts +53 -0
- package/dist/custom/ai/find-best-action.action.d.ts.map +1 -0
- package/dist/custom/ai/find-best-action.action.js +211 -0
- package/dist/custom/ai/find-best-action.action.js.map +1 -0
- package/dist/custom/ai/find-best-agent.action.d.ts +53 -0
- package/dist/custom/ai/find-best-agent.action.d.ts.map +1 -0
- package/dist/custom/ai/find-best-agent.action.js +194 -0
- package/dist/custom/ai/find-best-agent.action.js.map +1 -0
- package/dist/custom/ai/summarize-content.action.d.ts +3 -3
- package/dist/custom/ai/summarize-content.action.d.ts.map +1 -1
- package/dist/custom/ai/summarize-content.action.js +51 -143
- package/dist/custom/ai/summarize-content.action.js.map +1 -1
- package/dist/custom/code-execution/execute-code.action.d.ts +61 -0
- package/dist/custom/code-execution/execute-code.action.d.ts.map +1 -0
- package/dist/custom/code-execution/execute-code.action.js +172 -0
- package/dist/custom/code-execution/execute-code.action.js.map +1 -0
- package/dist/custom/data/csv-parser.action.js +1 -1
- package/dist/custom/data/csv-parser.action.js.map +1 -1
- package/dist/custom/data/execute-research-query.action.d.ts +36 -18
- package/dist/custom/data/execute-research-query.action.d.ts.map +1 -1
- package/dist/custom/data/execute-research-query.action.js +221 -114
- package/dist/custom/data/execute-research-query.action.js.map +1 -1
- package/dist/custom/data/explore-database-schema.action.d.ts +4 -0
- package/dist/custom/data/explore-database-schema.action.d.ts.map +1 -1
- package/dist/custom/data/explore-database-schema.action.js +101 -8
- package/dist/custom/data/explore-database-schema.action.js.map +1 -1
- package/dist/custom/data/get-entity-details.action.d.ts +63 -0
- package/dist/custom/data/get-entity-details.action.d.ts.map +1 -0
- package/dist/custom/data/get-entity-details.action.js +284 -0
- package/dist/custom/data/get-entity-details.action.js.map +1 -0
- package/dist/custom/data/get-entity-list.action.d.ts +57 -0
- package/dist/custom/data/get-entity-list.action.d.ts.map +1 -0
- package/dist/custom/data/get-entity-list.action.js +177 -0
- package/dist/custom/data/get-entity-list.action.js.map +1 -0
- package/dist/custom/visualization/create-svg-chart.action.d.ts +97 -0
- package/dist/custom/visualization/create-svg-chart.action.d.ts.map +1 -0
- package/dist/custom/visualization/create-svg-chart.action.js +326 -0
- package/dist/custom/visualization/create-svg-chart.action.js.map +1 -0
- package/dist/custom/visualization/create-svg-diagram.action.d.ts +151 -0
- package/dist/custom/visualization/create-svg-diagram.action.d.ts.map +1 -0
- package/dist/custom/visualization/create-svg-diagram.action.js +764 -0
- package/dist/custom/visualization/create-svg-diagram.action.js.map +1 -0
- package/dist/custom/visualization/create-svg-infographic.action.d.ts +72 -0
- package/dist/custom/visualization/create-svg-infographic.action.d.ts.map +1 -0
- package/dist/custom/visualization/create-svg-infographic.action.js +343 -0
- package/dist/custom/visualization/create-svg-infographic.action.js.map +1 -0
- package/dist/custom/visualization/create-svg-network.action.d.ts +106 -0
- package/dist/custom/visualization/create-svg-network.action.d.ts.map +1 -0
- package/dist/custom/visualization/create-svg-network.action.js +687 -0
- package/dist/custom/visualization/create-svg-network.action.js.map +1 -0
- package/dist/custom/visualization/create-svg-sketch-diagram.action.d.ts +97 -0
- package/dist/custom/visualization/create-svg-sketch-diagram.action.d.ts.map +1 -0
- package/dist/custom/visualization/create-svg-sketch-diagram.action.js +730 -0
- package/dist/custom/visualization/create-svg-sketch-diagram.action.js.map +1 -0
- package/dist/custom/visualization/create-svg-word-cloud.action.d.ts +94 -0
- package/dist/custom/visualization/create-svg-word-cloud.action.d.ts.map +1 -0
- package/dist/custom/visualization/create-svg-word-cloud.action.js +497 -0
- package/dist/custom/visualization/create-svg-word-cloud.action.js.map +1 -0
- package/dist/custom/visualization/shared/svg-theming.d.ts +91 -0
- package/dist/custom/visualization/shared/svg-theming.d.ts.map +1 -0
- package/dist/custom/visualization/shared/svg-theming.js +235 -0
- package/dist/custom/visualization/shared/svg-theming.js.map +1 -0
- package/dist/custom/visualization/shared/svg-types.d.ts +354 -0
- package/dist/custom/visualization/shared/svg-types.d.ts.map +1 -0
- package/dist/custom/visualization/shared/svg-types.js +11 -0
- package/dist/custom/visualization/shared/svg-types.js.map +1 -0
- package/dist/custom/visualization/shared/svg-utils.d.ts +166 -0
- package/dist/custom/visualization/shared/svg-utils.d.ts.map +1 -0
- package/dist/custom/visualization/shared/svg-utils.js +555 -0
- package/dist/custom/visualization/shared/svg-utils.js.map +1 -0
- package/dist/custom/web/google-custom-search.action.d.ts +6 -1
- package/dist/custom/web/google-custom-search.action.d.ts.map +1 -1
- package/dist/custom/web/google-custom-search.action.js +78 -10
- package/dist/custom/web/google-custom-search.action.js.map +1 -1
- package/dist/custom/web/web-page-content.action.d.ts +24 -0
- package/dist/custom/web/web-page-content.action.d.ts.map +1 -1
- package/dist/custom/web/web-page-content.action.js +90 -9
- package/dist/custom/web/web-page-content.action.js.map +1 -1
- package/dist/generated/action_subclasses.d.ts +4 -4
- package/dist/generated/action_subclasses.js +13 -13
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -1
- package/package.json +30 -12
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LoadGetEntityListAction = exports.GetEntityListAction = void 0;
|
|
10
|
+
const global_1 = require("@memberjunction/global");
|
|
11
|
+
const actions_1 = require("@memberjunction/actions");
|
|
12
|
+
const global_2 = require("@memberjunction/global");
|
|
13
|
+
const core_1 = require("@memberjunction/core");
|
|
14
|
+
/**
|
|
15
|
+
* Action that returns a lightweight list of all entities in the system.
|
|
16
|
+
* Returns only entity name, schema name, and description - perfect for discovering
|
|
17
|
+
* what entities exist before drilling into details with Explore Database Schema.
|
|
18
|
+
*
|
|
19
|
+
* This action is optimized for research agents that need to:
|
|
20
|
+
* - Discover available entities without guessing names
|
|
21
|
+
* - Get a quick overview of the data model
|
|
22
|
+
* - Find entities by description/purpose
|
|
23
|
+
* - Identify correct entity names before detailed exploration
|
|
24
|
+
*
|
|
25
|
+
* Features:
|
|
26
|
+
* - Uses cached metadata (no database queries)
|
|
27
|
+
* - Extremely fast and lightweight
|
|
28
|
+
* - Optional schema filtering
|
|
29
|
+
* - Optional scope filtering
|
|
30
|
+
* - Sorted alphabetically for easy scanning
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Get all entities
|
|
35
|
+
* await runAction({
|
|
36
|
+
* ActionName: 'Get Entity List'
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Get only entities in specific schema
|
|
40
|
+
* await runAction({
|
|
41
|
+
* ActionName: 'Get Entity List',
|
|
42
|
+
* Params: [{
|
|
43
|
+
* Name: 'SchemaFilter',
|
|
44
|
+
* Value: 'dbo'
|
|
45
|
+
* }]
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
let GetEntityListAction = class GetEntityListAction extends actions_1.BaseAction {
|
|
50
|
+
async InternalRunAction(params) {
|
|
51
|
+
try {
|
|
52
|
+
// Extract parameters
|
|
53
|
+
const schemaFilter = this.getStringParam(params, "schemafilter");
|
|
54
|
+
const scopeFilter = this.getStringParam(params, "scopefilter");
|
|
55
|
+
const includeVirtualEntities = this.getBooleanParam(params, "includevirtualentities", true);
|
|
56
|
+
const startTime = Date.now();
|
|
57
|
+
// Get MJ metadata (cached, no DB queries)
|
|
58
|
+
const md = new core_1.Metadata();
|
|
59
|
+
let entities = md.Entities;
|
|
60
|
+
// Apply filters
|
|
61
|
+
if (schemaFilter) {
|
|
62
|
+
const schemas = schemaFilter.split(',').map(s => s.trim().toLowerCase());
|
|
63
|
+
entities = entities.filter(e => schemas.includes(e.SchemaName.toLowerCase()));
|
|
64
|
+
}
|
|
65
|
+
if (scopeFilter) {
|
|
66
|
+
entities = entities.filter(e => {
|
|
67
|
+
if (!e.ScopeDefault)
|
|
68
|
+
return true; // Include entities with no scope
|
|
69
|
+
const scopes = e.ScopeDefault.split(',').map(s => s.trim().toLowerCase());
|
|
70
|
+
return scopes.includes(scopeFilter.toLowerCase()) || scopes.includes('all');
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (!includeVirtualEntities) {
|
|
74
|
+
entities = entities.filter(e => !e.VirtualEntity);
|
|
75
|
+
}
|
|
76
|
+
// Build lightweight entity list (name, schema, description only)
|
|
77
|
+
const entityList = entities.map(e => ({
|
|
78
|
+
Name: e.Name,
|
|
79
|
+
SchemaName: e.SchemaName,
|
|
80
|
+
Description: e.Description || '',
|
|
81
|
+
IsVirtual: e.VirtualEntity
|
|
82
|
+
})).sort((a, b) => {
|
|
83
|
+
// Sort by schema first, then by name
|
|
84
|
+
if (a.SchemaName !== b.SchemaName) {
|
|
85
|
+
return a.SchemaName.localeCompare(b.SchemaName);
|
|
86
|
+
}
|
|
87
|
+
return a.Name.localeCompare(b.Name);
|
|
88
|
+
});
|
|
89
|
+
const executionTimeMs = Date.now() - startTime;
|
|
90
|
+
// Build detailed message for agent consumption
|
|
91
|
+
const message = this.buildDetailedMessage(entityList, schemaFilter, scopeFilter);
|
|
92
|
+
return {
|
|
93
|
+
Success: true,
|
|
94
|
+
ResultCode: "SUCCESS",
|
|
95
|
+
Message: message,
|
|
96
|
+
Entities: entityList,
|
|
97
|
+
TotalCount: entityList.length,
|
|
98
|
+
ExecutionTimeMs: executionTimeMs
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
103
|
+
return {
|
|
104
|
+
Success: false,
|
|
105
|
+
ResultCode: "LIST_FAILED",
|
|
106
|
+
Message: `Entity list retrieval failed: ${errorMessage}`
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Build detailed message with entity list for agent consumption
|
|
112
|
+
*/
|
|
113
|
+
buildDetailedMessage(entities, schemaFilter, scopeFilter) {
|
|
114
|
+
const lines = [];
|
|
115
|
+
// Header
|
|
116
|
+
lines.push(`# Entity List`);
|
|
117
|
+
lines.push(`\nFound ${entities.length} entity(ies)`);
|
|
118
|
+
if (schemaFilter) {
|
|
119
|
+
lines.push(`Schema Filter: ${schemaFilter}`);
|
|
120
|
+
}
|
|
121
|
+
if (scopeFilter) {
|
|
122
|
+
lines.push(`Scope Filter: ${scopeFilter}`);
|
|
123
|
+
}
|
|
124
|
+
lines.push(`\n---\n`);
|
|
125
|
+
// Group by schema
|
|
126
|
+
const schemas = [...new Set(entities.map(e => e.SchemaName))].sort();
|
|
127
|
+
for (const schema of schemas) {
|
|
128
|
+
const schemaEntities = entities.filter(e => e.SchemaName === schema);
|
|
129
|
+
lines.push(`\n## Schema: ${schema} (${schemaEntities.length} entities)\n`);
|
|
130
|
+
for (const entity of schemaEntities) {
|
|
131
|
+
const virtualFlag = entity.IsVirtual ? ' [VIRTUAL]' : '';
|
|
132
|
+
lines.push(`- **${entity.Name}**${virtualFlag}`);
|
|
133
|
+
if (entity.Description) {
|
|
134
|
+
lines.push(` ${entity.Description}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
lines.push(`\n---`);
|
|
139
|
+
lines.push(`\nUse "Explore Database Schema" action with EntityPattern parameter to get detailed field information for specific entities.`);
|
|
140
|
+
return lines.join('\n');
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Helper to get string parameter value
|
|
144
|
+
*/
|
|
145
|
+
getStringParam(params, paramName) {
|
|
146
|
+
const param = params.Params.find(p => p.Name.toLowerCase() === paramName.toLowerCase() &&
|
|
147
|
+
p.Type === 'Input');
|
|
148
|
+
return param?.Value ? String(param.Value) : undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Helper to get boolean parameter value
|
|
152
|
+
*/
|
|
153
|
+
getBooleanParam(params, paramName, defaultValue) {
|
|
154
|
+
const param = params.Params.find(p => p.Name.toLowerCase() === paramName.toLowerCase() &&
|
|
155
|
+
p.Type === 'Input');
|
|
156
|
+
if (param?.Value != null) {
|
|
157
|
+
const val = String(param.Value).toLowerCase();
|
|
158
|
+
if (val === 'true' || val === '1' || val === 'yes')
|
|
159
|
+
return true;
|
|
160
|
+
if (val === 'false' || val === '0' || val === 'no')
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return defaultValue;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
exports.GetEntityListAction = GetEntityListAction;
|
|
167
|
+
exports.GetEntityListAction = GetEntityListAction = __decorate([
|
|
168
|
+
(0, global_1.RegisterClass)(actions_1.BaseAction, "Get Entity List")
|
|
169
|
+
], GetEntityListAction);
|
|
170
|
+
/**
|
|
171
|
+
* Load function to ensure the class is registered and not tree-shaken
|
|
172
|
+
*/
|
|
173
|
+
function LoadGetEntityListAction() {
|
|
174
|
+
global_2.MJGlobal.Instance.ClassFactory.GetRegistration(actions_1.BaseAction, "Get Entity List");
|
|
175
|
+
}
|
|
176
|
+
exports.LoadGetEntityListAction = LoadGetEntityListAction;
|
|
177
|
+
//# sourceMappingURL=get-entity-list.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-entity-list.action.js","sourceRoot":"","sources":["../../../src/custom/data/get-entity-list.action.ts"],"names":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C,IAAI,CAAC,CAAC,CAAC,EAAE,CACjC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,WAAW,EAAE;YAChD,CAAC,CAAC,IAAI,KAAK,OAAO,CACrB,CAAC;QACF,IAAI,KAAK,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;YAC9C,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,KAAK;gBAAE,OAAO,IAAI,CAAC;YAChE,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,IAAI;gBAAE,OAAO,KAAK,CAAC;QACrE,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ,CAAA;AA9IY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAa,EAAC,oBAAU,EAAE,iBAAiB,CAAC;GAChC,mBAAmB,CA8I/B;AAED;;GAEG;AACH,SAAgB,uBAAuB;IACnC,iBAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,eAAe,CAAC,oBAAU,EAAE,iBAAiB,CAAC,CAAC;AAClF,CAAC;AAFD,0DAEC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ActionResultSimple, RunActionParams } from "@memberjunction/actions-base";
|
|
2
|
+
import { BaseAction } from "@memberjunction/actions";
|
|
3
|
+
/**
|
|
4
|
+
* Action that generates SVG charts from data using Vega-Lite.
|
|
5
|
+
* Supports various chart types including bar, line, pie, scatter, area, and more.
|
|
6
|
+
*
|
|
7
|
+
* This action is designed for AI agents and workflows to create publication-quality
|
|
8
|
+
* visualizations from structured data without writing visualization code.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Simple bar chart
|
|
13
|
+
* await runAction({
|
|
14
|
+
* ActionName: 'Create SVG Chart',
|
|
15
|
+
* Params: [
|
|
16
|
+
* { Name: 'ChartType', Value: 'bar' },
|
|
17
|
+
* { Name: 'Data', Value: JSON.stringify([
|
|
18
|
+
* { category: 'A', value: 28 },
|
|
19
|
+
* { category: 'B', value: 55 },
|
|
20
|
+
* { category: 'C', value: 43 }
|
|
21
|
+
* ]) },
|
|
22
|
+
* { Name: 'XField', Value: 'category' },
|
|
23
|
+
* { Name: 'YField', Value: 'value' },
|
|
24
|
+
* { Name: 'Title', Value: 'Sample Bar Chart' }
|
|
25
|
+
* ]
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Pie chart
|
|
29
|
+
* await runAction({
|
|
30
|
+
* ActionName: 'Create SVG Chart',
|
|
31
|
+
* Params: [
|
|
32
|
+
* { Name: 'ChartType', Value: 'pie' },
|
|
33
|
+
* { Name: 'Data', Value: JSON.stringify([
|
|
34
|
+
* { category: 'LLM', count: 67 },
|
|
35
|
+
* { category: 'Embeddings', count: 10 }
|
|
36
|
+
* ]) },
|
|
37
|
+
* { Name: 'ThetaField', Value: 'count' },
|
|
38
|
+
* { Name: 'ColorField', Value: 'category' },
|
|
39
|
+
* { Name: 'Width', Value: '400' },
|
|
40
|
+
* { Name: 'Height', Value: '300' }
|
|
41
|
+
* ]
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class CreateSVGChartAction extends BaseAction {
|
|
46
|
+
/**
|
|
47
|
+
* Generates an SVG chart from the provided data and configuration
|
|
48
|
+
*
|
|
49
|
+
* @param params - The action parameters containing:
|
|
50
|
+
* - ChartType: Type of chart (bar, line, pie, scatter, area, etc.)
|
|
51
|
+
* - Data: JSON array of data objects
|
|
52
|
+
* - XField: Field name for X axis (for bar, line, scatter, area)
|
|
53
|
+
* - YField: Field name for Y axis (for bar, line, scatter, area)
|
|
54
|
+
* - ThetaField: Field name for pie slice size (for pie charts)
|
|
55
|
+
* - ColorField: Field name for color encoding (optional)
|
|
56
|
+
* - Title: Chart title (optional)
|
|
57
|
+
* - Width: Chart width in pixels (optional, default: 400)
|
|
58
|
+
* - Height: Chart height in pixels (optional, default: 300)
|
|
59
|
+
* - VegaLiteSpec: Full Vega-Lite JSON spec (optional, overrides other params)
|
|
60
|
+
*
|
|
61
|
+
* @returns A promise resolving to an ActionResultSimple with:
|
|
62
|
+
* - Success: true if chart was generated successfully
|
|
63
|
+
* - ResultCode: "SUCCESS" or error code
|
|
64
|
+
* - Message: The SVG string or error message
|
|
65
|
+
*/
|
|
66
|
+
protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
|
|
67
|
+
/**
|
|
68
|
+
* Builds a Vega-Lite specification from action parameters
|
|
69
|
+
*/
|
|
70
|
+
private buildVegaLiteSpec;
|
|
71
|
+
/**
|
|
72
|
+
* Builds encoding for Cartesian charts (bar, line, scatter, area)
|
|
73
|
+
*/
|
|
74
|
+
private buildCartesianEncoding;
|
|
75
|
+
/**
|
|
76
|
+
* Builds encoding for pie/arc charts
|
|
77
|
+
*/
|
|
78
|
+
private buildPieEncoding;
|
|
79
|
+
/**
|
|
80
|
+
* Infers the Vega-Lite field type from field name
|
|
81
|
+
*/
|
|
82
|
+
private inferFieldType;
|
|
83
|
+
/**
|
|
84
|
+
* Helper to safely parse JSON that might already be an object
|
|
85
|
+
*/
|
|
86
|
+
private parseJSON;
|
|
87
|
+
/**
|
|
88
|
+
* Helper to get parameter value by name (case-insensitive)
|
|
89
|
+
*/
|
|
90
|
+
private getParamValue;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Loader function to ensure the CreateSVGChartAction class is included in the bundle.
|
|
94
|
+
* This prevents tree-shaking from removing the class during the build process.
|
|
95
|
+
*/
|
|
96
|
+
export declare function LoadCreateSVGChartAction(): void;
|
|
97
|
+
//# sourceMappingURL=create-svg-chart.action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-svg-chart.action.d.ts","sourceRoot":"","sources":["../../../src/custom/visualization/create-svg-chart.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAMrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBACa,oBAAqB,SAAQ,UAAU;IAChD;;;;;;;;;;;;;;;;;;;OAmBG;cACa,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAmEvF;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA4EzB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAqB9B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;OAEG;IACH,OAAO,CAAC,cAAc;IAiBtB;;OAEG;IACH,OAAO,CAAC,SAAS;IAuBjB;;OAEG;IACH,OAAO,CAAC,aAAa;CASxB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,SAEvC"}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.LoadCreateSVGChartAction = exports.CreateSVGChartAction = void 0;
|
|
33
|
+
const actions_1 = require("@memberjunction/actions");
|
|
34
|
+
const global_1 = require("@memberjunction/global");
|
|
35
|
+
const vega = __importStar(require("vega"));
|
|
36
|
+
const vegaLite = __importStar(require("vega-lite"));
|
|
37
|
+
/**
|
|
38
|
+
* Action that generates SVG charts from data using Vega-Lite.
|
|
39
|
+
* Supports various chart types including bar, line, pie, scatter, area, and more.
|
|
40
|
+
*
|
|
41
|
+
* This action is designed for AI agents and workflows to create publication-quality
|
|
42
|
+
* visualizations from structured data without writing visualization code.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // Simple bar chart
|
|
47
|
+
* await runAction({
|
|
48
|
+
* ActionName: 'Create SVG Chart',
|
|
49
|
+
* Params: [
|
|
50
|
+
* { Name: 'ChartType', Value: 'bar' },
|
|
51
|
+
* { Name: 'Data', Value: JSON.stringify([
|
|
52
|
+
* { category: 'A', value: 28 },
|
|
53
|
+
* { category: 'B', value: 55 },
|
|
54
|
+
* { category: 'C', value: 43 }
|
|
55
|
+
* ]) },
|
|
56
|
+
* { Name: 'XField', Value: 'category' },
|
|
57
|
+
* { Name: 'YField', Value: 'value' },
|
|
58
|
+
* { Name: 'Title', Value: 'Sample Bar Chart' }
|
|
59
|
+
* ]
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Pie chart
|
|
63
|
+
* await runAction({
|
|
64
|
+
* ActionName: 'Create SVG Chart',
|
|
65
|
+
* Params: [
|
|
66
|
+
* { Name: 'ChartType', Value: 'pie' },
|
|
67
|
+
* { Name: 'Data', Value: JSON.stringify([
|
|
68
|
+
* { category: 'LLM', count: 67 },
|
|
69
|
+
* { category: 'Embeddings', count: 10 }
|
|
70
|
+
* ]) },
|
|
71
|
+
* { Name: 'ThetaField', Value: 'count' },
|
|
72
|
+
* { Name: 'ColorField', Value: 'category' },
|
|
73
|
+
* { Name: 'Width', Value: '400' },
|
|
74
|
+
* { Name: 'Height', Value: '300' }
|
|
75
|
+
* ]
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
let CreateSVGChartAction = class CreateSVGChartAction extends actions_1.BaseAction {
|
|
80
|
+
/**
|
|
81
|
+
* Generates an SVG chart from the provided data and configuration
|
|
82
|
+
*
|
|
83
|
+
* @param params - The action parameters containing:
|
|
84
|
+
* - ChartType: Type of chart (bar, line, pie, scatter, area, etc.)
|
|
85
|
+
* - Data: JSON array of data objects
|
|
86
|
+
* - XField: Field name for X axis (for bar, line, scatter, area)
|
|
87
|
+
* - YField: Field name for Y axis (for bar, line, scatter, area)
|
|
88
|
+
* - ThetaField: Field name for pie slice size (for pie charts)
|
|
89
|
+
* - ColorField: Field name for color encoding (optional)
|
|
90
|
+
* - Title: Chart title (optional)
|
|
91
|
+
* - Width: Chart width in pixels (optional, default: 400)
|
|
92
|
+
* - Height: Chart height in pixels (optional, default: 300)
|
|
93
|
+
* - VegaLiteSpec: Full Vega-Lite JSON spec (optional, overrides other params)
|
|
94
|
+
*
|
|
95
|
+
* @returns A promise resolving to an ActionResultSimple with:
|
|
96
|
+
* - Success: true if chart was generated successfully
|
|
97
|
+
* - ResultCode: "SUCCESS" or error code
|
|
98
|
+
* - Message: The SVG string or error message
|
|
99
|
+
*/
|
|
100
|
+
async InternalRunAction(params) {
|
|
101
|
+
try {
|
|
102
|
+
// Check if a full Vega-Lite spec was provided
|
|
103
|
+
const specParam = this.getParamValue(params, 'VegaLiteSpec');
|
|
104
|
+
let vlSpec;
|
|
105
|
+
if (specParam) {
|
|
106
|
+
// Use the provided spec directly
|
|
107
|
+
vlSpec = this.parseJSON(specParam, 'VegaLiteSpec');
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// Build spec from individual parameters
|
|
111
|
+
const chartType = this.getParamValue(params, 'ChartType');
|
|
112
|
+
const dataParam = this.getParamValue(params, 'Data');
|
|
113
|
+
if (!chartType) {
|
|
114
|
+
return {
|
|
115
|
+
Success: false,
|
|
116
|
+
Message: "ChartType parameter is required (or provide VegaLiteSpec)",
|
|
117
|
+
ResultCode: "MISSING_PARAMETERS"
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (!dataParam) {
|
|
121
|
+
return {
|
|
122
|
+
Success: false,
|
|
123
|
+
Message: "Data parameter is required (or provide VegaLiteSpec)",
|
|
124
|
+
ResultCode: "MISSING_PARAMETERS"
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const data = this.parseJSON(dataParam, 'Data');
|
|
128
|
+
if (!Array.isArray(data)) {
|
|
129
|
+
return {
|
|
130
|
+
Success: false,
|
|
131
|
+
Message: "Data parameter must be a JSON array",
|
|
132
|
+
ResultCode: "INVALID_DATA"
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// Build the Vega-Lite spec
|
|
136
|
+
vlSpec = this.buildVegaLiteSpec(params, chartType.toLowerCase(), data);
|
|
137
|
+
}
|
|
138
|
+
// Compile Vega-Lite to Vega
|
|
139
|
+
const vegaSpec = vegaLite.compile(vlSpec).spec;
|
|
140
|
+
// Create a headless view and render to SVG
|
|
141
|
+
const view = new vega.View(vega.parse(vegaSpec), { renderer: 'none' });
|
|
142
|
+
const svg = await view.toSVG();
|
|
143
|
+
return {
|
|
144
|
+
Success: true,
|
|
145
|
+
ResultCode: "SUCCESS",
|
|
146
|
+
Message: svg
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return {
|
|
151
|
+
Success: false,
|
|
152
|
+
Message: `Failed to generate chart: ${error instanceof Error ? error.message : String(error)}`,
|
|
153
|
+
ResultCode: "CHART_GENERATION_FAILED"
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Builds a Vega-Lite specification from action parameters
|
|
159
|
+
*/
|
|
160
|
+
buildVegaLiteSpec(params, chartType, data) {
|
|
161
|
+
const title = this.getParamValue(params, 'Title');
|
|
162
|
+
const width = parseInt(this.getParamValue(params, 'Width') || '400');
|
|
163
|
+
const height = parseInt(this.getParamValue(params, 'Height') || '300');
|
|
164
|
+
const baseSpec = {
|
|
165
|
+
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
|
|
166
|
+
width,
|
|
167
|
+
height,
|
|
168
|
+
data: { values: data },
|
|
169
|
+
padding: 20,
|
|
170
|
+
autosize: {
|
|
171
|
+
type: 'fit',
|
|
172
|
+
contains: 'padding'
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
if (title) {
|
|
176
|
+
baseSpec.title = {
|
|
177
|
+
text: title,
|
|
178
|
+
anchor: 'middle',
|
|
179
|
+
offset: 20,
|
|
180
|
+
fontSize: 16,
|
|
181
|
+
fontWeight: 'bold'
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
// Add config for better spacing and readability
|
|
185
|
+
baseSpec.config = {
|
|
186
|
+
axis: {
|
|
187
|
+
labelFontSize: 11,
|
|
188
|
+
titleFontSize: 12,
|
|
189
|
+
titlePadding: 10,
|
|
190
|
+
labelPadding: 5
|
|
191
|
+
},
|
|
192
|
+
legend: {
|
|
193
|
+
labelFontSize: 11,
|
|
194
|
+
titleFontSize: 12,
|
|
195
|
+
padding: 10
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
// Build encoding based on chart type
|
|
199
|
+
switch (chartType) {
|
|
200
|
+
case 'bar':
|
|
201
|
+
case 'line':
|
|
202
|
+
case 'area':
|
|
203
|
+
case 'point':
|
|
204
|
+
case 'scatter':
|
|
205
|
+
// For line and area charts, handle missing data points properly
|
|
206
|
+
if (chartType === 'line' || chartType === 'area') {
|
|
207
|
+
baseSpec.mark = {
|
|
208
|
+
type: chartType,
|
|
209
|
+
point: chartType === 'line', // Show points on line charts
|
|
210
|
+
interpolate: 'monotone', // Smooth curves
|
|
211
|
+
tooltip: true
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
baseSpec.mark = chartType === 'scatter' ? 'point' : chartType;
|
|
216
|
+
}
|
|
217
|
+
baseSpec.encoding = this.buildCartesianEncoding(params);
|
|
218
|
+
break;
|
|
219
|
+
case 'pie':
|
|
220
|
+
case 'arc':
|
|
221
|
+
baseSpec.mark = 'arc';
|
|
222
|
+
baseSpec.encoding = this.buildPieEncoding(params);
|
|
223
|
+
break;
|
|
224
|
+
default:
|
|
225
|
+
throw new Error(`Unsupported chart type: ${chartType}. Supported types: bar, line, area, point, scatter, pie`);
|
|
226
|
+
}
|
|
227
|
+
return baseSpec;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Builds encoding for Cartesian charts (bar, line, scatter, area)
|
|
231
|
+
*/
|
|
232
|
+
buildCartesianEncoding(params) {
|
|
233
|
+
const xField = this.getParamValue(params, 'XField');
|
|
234
|
+
const yField = this.getParamValue(params, 'YField');
|
|
235
|
+
const colorField = this.getParamValue(params, 'ColorField');
|
|
236
|
+
if (!xField || !yField) {
|
|
237
|
+
throw new Error("XField and YField are required for this chart type");
|
|
238
|
+
}
|
|
239
|
+
const encoding = {
|
|
240
|
+
x: { field: xField, type: this.inferFieldType(xField) },
|
|
241
|
+
y: { field: yField, type: 'quantitative' }
|
|
242
|
+
};
|
|
243
|
+
if (colorField) {
|
|
244
|
+
encoding.color = { field: colorField, type: 'nominal' };
|
|
245
|
+
}
|
|
246
|
+
return encoding;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Builds encoding for pie/arc charts
|
|
250
|
+
*/
|
|
251
|
+
buildPieEncoding(params) {
|
|
252
|
+
const thetaField = this.getParamValue(params, 'ThetaField');
|
|
253
|
+
const colorField = this.getParamValue(params, 'ColorField');
|
|
254
|
+
if (!thetaField) {
|
|
255
|
+
throw new Error("ThetaField is required for pie charts");
|
|
256
|
+
}
|
|
257
|
+
const encoding = {
|
|
258
|
+
theta: { field: thetaField, type: 'quantitative' }
|
|
259
|
+
};
|
|
260
|
+
if (colorField) {
|
|
261
|
+
encoding.color = { field: colorField, type: 'nominal' };
|
|
262
|
+
}
|
|
263
|
+
return encoding;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Infers the Vega-Lite field type from field name
|
|
267
|
+
*/
|
|
268
|
+
inferFieldType(fieldName) {
|
|
269
|
+
const lowerName = fieldName.toLowerCase();
|
|
270
|
+
// Temporal hints
|
|
271
|
+
if (lowerName.includes('date') || lowerName.includes('time') || lowerName.includes('year') || lowerName.includes('month')) {
|
|
272
|
+
return 'temporal';
|
|
273
|
+
}
|
|
274
|
+
// Quantitative hints
|
|
275
|
+
if (lowerName.includes('count') || lowerName.includes('value') || lowerName.includes('amount') || lowerName.includes('total')) {
|
|
276
|
+
return 'quantitative';
|
|
277
|
+
}
|
|
278
|
+
// Default to nominal for categorical data
|
|
279
|
+
return 'nominal';
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Helper to safely parse JSON that might already be an object
|
|
283
|
+
*/
|
|
284
|
+
parseJSON(value, paramName) {
|
|
285
|
+
// If it's already an object/array, return it
|
|
286
|
+
if (typeof value === 'object' && value !== null) {
|
|
287
|
+
return value;
|
|
288
|
+
}
|
|
289
|
+
// If it's a string, parse it
|
|
290
|
+
if (typeof value === 'string') {
|
|
291
|
+
try {
|
|
292
|
+
return JSON.parse(value);
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
throw new Error(`Parameter '${paramName}' contains invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// For other types, error
|
|
299
|
+
throw new Error(`Parameter '${paramName}' must be a JSON string or object. Received ${typeof value}.`);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Helper to get parameter value by name (case-insensitive)
|
|
303
|
+
*/
|
|
304
|
+
getParamValue(params, paramName) {
|
|
305
|
+
const param = params.Params.find(p => p.Name.trim().toLowerCase() === paramName.toLowerCase());
|
|
306
|
+
if (param?.Value && typeof param.Value === 'string') {
|
|
307
|
+
return param?.Value?.trim() || null;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
return param?.Value || null;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
exports.CreateSVGChartAction = CreateSVGChartAction;
|
|
315
|
+
exports.CreateSVGChartAction = CreateSVGChartAction = __decorate([
|
|
316
|
+
(0, global_1.RegisterClass)(actions_1.BaseAction, "__CreateSVGChart")
|
|
317
|
+
], CreateSVGChartAction);
|
|
318
|
+
/**
|
|
319
|
+
* Loader function to ensure the CreateSVGChartAction class is included in the bundle.
|
|
320
|
+
* This prevents tree-shaking from removing the class during the build process.
|
|
321
|
+
*/
|
|
322
|
+
function LoadCreateSVGChartAction() {
|
|
323
|
+
// this function is a stub that is used to force the bundler to include the above class in the final bundle and not tree shake them out
|
|
324
|
+
}
|
|
325
|
+
exports.LoadCreateSVGChartAction = LoadCreateSVGChartAction;
|
|
326
|
+
//# sourceMappingURL=create-svg-chart.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-svg-chart.action.js","sourceRoot":"","sources":["../../../src/custom/visualization/create-svg-chart.action.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAAqD;AACrD,mDAAuD;AACvD,2CAA6B;AAC7B,oDAAsC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,oBAAU;IAChD;;;;;;;;;;;;;;;;;;;OAmBG;IACO,KAAK,CAAC,iBAAiB,CAAC,MAAuB;QACrD,IAAI,CAAC;YACD,8CAA8C;YAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;YAE7D,IAAI,MAAoB,CAAC;YAEzB,IAAI,SAAS,EAAE,CAAC;gBACZ,iCAAiC;gBACjC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAe,SAAS,EAAE,cAAc,CAAC,CAAC;YACrE,CAAC;iBAAM,CAAC;gBACJ,wCAAwC;gBACxC,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;gBAC1D,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAErD,IAAI,CAAC,SAAS,EAAE,CAAC;oBACb,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,OAAO,EAAE,2DAA2D;wBACpE,UAAU,EAAE,oBAAoB;qBACnC,CAAC;gBACN,CAAC;gBAED,IAAI,CAAC,SAAS,EAAE,CAAC;oBACb,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,OAAO,EAAE,sDAAsD;wBAC/D,UAAU,E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