chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:34:48 +08:00
commit 77bb5bf71f
3762 changed files with 353249 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
import rootConfig from '../../eslint.config.mjs'
export default [
...rootConfig,
{
languageOptions: {
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: import.meta.dirname,
},
},
},
]
+1
View File
@@ -0,0 +1 @@
This integration provides a suite of actions to generate various types of charts, including line plots, bar charts, pie charts, scatter plots, doughnut charts, radar charts, bubble charts, and horizontal bar charts. Each action accepts specific input data such as labels, values, and optional titles for the chart and its axes. The output of each action is a URL pointing to the generated chart image, allowing for easy embedding and sharing of the visualized data.
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-line-chart"><path d="M3 3v18h18"/><path d="m19 9-5 5-4-4-3 3"/></svg>

After

Width:  |  Height:  |  Size: 272 B

@@ -0,0 +1,24 @@
import { IntegrationDefinition } from '@botpress/sdk'
import { actionDefinitions } from 'src/definitions/actions'
export default new IntegrationDefinition({
name: 'charts',
title: 'Charts',
description: 'Easily generate a variety of charts, including line, bar, pie, and scatter plots, etc.',
version: '0.2.8',
readme: 'hub.md',
icon: 'icon.svg',
actions: actionDefinitions,
secrets: {
QUICKCHARTS_API_KEY: {
description: 'Quickcharts key',
},
},
__advanced: {
useLegacyZuiTransformer: true,
},
attributes: {
category: 'Other',
repo: 'botpress',
},
})
+20
View File
@@ -0,0 +1,20 @@
{
"name": "@botpresshub/charts",
"scripts": {
"check:type": "tsc --noEmit",
"check:bplint": "bp lint",
"build": "bp add -y && bp build",
"test": "vitest --run"
},
"private": true,
"dependencies": {
"@botpress/sdk": "workspace:*",
"axios": "^1.7.2"
},
"devDependencies": {
"@botpress/cli": "workspace:*",
"@botpress/common": "workspace:*",
"@botpress/sdk": "workspace:*",
"chart.js": "^3.9.1"
}
}
@@ -0,0 +1,44 @@
import { buildChart, ChartConfig } from './utils'
import * as bp from '.botpress'
export const generateBarChart: bp.IntegrationProps['actions']['generateBarChart'] = async ({
client,
input,
logger,
type,
ctx,
}) => {
logger.forBot().debug('Generating bar chart', { input, type })
const chartConfig: ChartConfig = {
type: 'bar',
data: {
labels: input.xData,
datasets: [
{
label: input.title || 'Bar Chart',
data: input.yData!,
},
],
},
options: {
scales: {
x: {
title: {
display: true,
text: input.xAxisTitle || 'X Axis',
},
},
y: {
title: {
display: true,
text: input.yAxisTitle || 'Y Axis',
},
},
},
},
}
const imageUrl = await buildChart({ chartConfig, botId: ctx.botId, client, fileName: 'bar_chart' })
return { imageUrl }
}
@@ -0,0 +1,43 @@
import { buildChart, ChartConfig } from './utils'
import * as bp from '.botpress'
export const generateBubbleChart: bp.IntegrationProps['actions']['generateBubbleChart'] = async ({
client,
input,
logger,
type,
ctx,
}) => {
logger.forBot().debug('Generating bubble chart', { input, type })
const chartConfig: ChartConfig = {
type: 'bubble',
data: {
datasets: [
{
label: input.title || 'Bubble Chart',
data: input.data!,
},
],
},
options: {
scales: {
x: {
title: {
display: true,
text: input.xAxisTitle || 'X Axis',
},
},
y: {
title: {
display: true,
text: input.yAxisTitle || 'Y Axis',
},
},
},
},
}
const imageUrl = await buildChart({ chartConfig, botId: ctx.botId, client, fileName: 'bubble_chart' })
return { imageUrl }
}
@@ -0,0 +1,28 @@
import { buildChart, ChartConfig } from './utils'
import * as bp from '.botpress'
export const generateDoughnutChart: bp.IntegrationProps['actions']['generateDoughnutChart'] = async ({
client,
input,
logger,
type,
ctx,
}) => {
logger.forBot().debug('Generating doughnut chart', { input, type })
const chartConfig: ChartConfig = {
type: 'doughnut',
data: {
labels: input.labels,
datasets: [
{
label: input.title || 'Doughnut Chart',
data: input.data!,
},
],
},
}
const imageUrl = await buildChart({ chartConfig, botId: ctx.botId, client, fileName: 'doughnut_chart' })
return { imageUrl }
}
@@ -0,0 +1,45 @@
import { buildChart, ChartConfig } from './utils'
import * as bp from '.botpress'
export const generateHorizontalBarChart: bp.IntegrationProps['actions']['generateHorizontalBarChart'] = async ({
client,
input,
logger,
type,
ctx,
}) => {
logger.forBot().debug('Generating horizontal bar chart', { input, type })
const chartConfig: ChartConfig = {
type: 'bar',
data: {
labels: input.xData,
datasets: [
{
label: input.title || 'Horizontal Bar Chart',
data: input.yData!,
},
],
},
options: {
indexAxis: 'y',
scales: {
x: {
title: {
display: true,
text: input.xAxisTitle || 'X Axis',
},
},
y: {
title: {
display: true,
text: input.yAxisTitle || 'Y Axis',
},
},
},
},
}
const imageUrl = await buildChart({ chartConfig, botId: ctx.botId, client, fileName: 'horizontal_bar_chart' })
return { imageUrl }
}
@@ -0,0 +1,44 @@
import { buildChart, ChartConfig } from './utils'
import * as bp from '.botpress'
export const generateLinePlot: bp.IntegrationProps['actions']['generateLinePlot'] = async ({
client,
input,
logger,
type,
ctx,
}) => {
logger.forBot().debug('Generating line plot', { input, type })
const chartConfig: ChartConfig = {
type: 'line',
data: {
labels: input.xData,
datasets: [
{
label: input.title || 'Line Plot',
data: input.yData!,
},
],
},
options: {
scales: {
x: {
title: {
display: true,
text: input.xAxisTitle || 'X Axis',
},
},
y: {
title: {
display: true,
text: input.yAxisTitle || 'Y Axis',
},
},
},
},
}
const imageUrl = await buildChart({ chartConfig, botId: ctx.botId, client, fileName: 'line_plot' })
return { imageUrl }
}
@@ -0,0 +1,28 @@
import { buildChart, ChartConfig } from './utils'
import * as bp from '.botpress'
export const generatePieChart: bp.IntegrationProps['actions']['generatePieChart'] = async ({
client,
input,
logger,
type,
ctx,
}) => {
logger.forBot().debug('Generating pie chart', { input, type })
const chartConfig: ChartConfig = {
type: 'pie',
data: {
labels: input.labels,
datasets: [
{
label: input.title || 'Pie Chart',
data: input.data!,
},
],
},
}
const imageUrl = await buildChart({ chartConfig, botId: ctx.botId, client, fileName: 'pie_chart' })
return { imageUrl }
}
@@ -0,0 +1,38 @@
import { buildChart, ChartConfig } from './utils'
import * as bp from '.botpress'
export const generateRadarChart: bp.IntegrationProps['actions']['generateRadarChart'] = async ({
client,
input,
logger,
type,
ctx,
}) => {
logger.forBot().debug('Generating radar chart', { input, type })
const chartConfig: ChartConfig = {
type: 'radar',
data: {
labels: input.labels,
datasets: [
{
label: input.title || 'Radar Chart',
data: input.data!,
},
],
},
options: {
scales: {
r: {
title: {
display: true,
text: input.axisTitle || 'Axis',
},
},
},
},
}
const imageUrl = await buildChart({ chartConfig, botId: ctx.botId, client, fileName: 'radar_chart' })
return { imageUrl }
}
@@ -0,0 +1,43 @@
import { buildChart, ChartConfig } from './utils'
import * as bp from '.botpress'
export const generateScatterPlot: bp.IntegrationProps['actions']['generateScatterPlot'] = async ({
client,
input,
logger,
type,
ctx,
}) => {
logger.forBot().debug('Generating scatter plot', { input, type })
const chartConfig: ChartConfig = {
type: 'scatter',
data: {
datasets: [
{
label: input.title || 'Scatter Plot',
data: input.data!,
},
],
},
options: {
scales: {
x: {
title: {
display: true,
text: input.xAxisTitle || 'X Axis',
},
},
y: {
title: {
display: true,
text: input.yAxisTitle || 'Y Axis',
},
},
},
},
}
const imageUrl = await buildChart({ chartConfig, botId: ctx.botId, client, fileName: 'scatter_plot' })
return { imageUrl }
}
+19
View File
@@ -0,0 +1,19 @@
import { generateBarChart } from './generate-bar-chart'
import { generateBubbleChart } from './generate-bubble-chart'
import { generateDoughnutChart } from './generate-doughnut-chart'
import { generateHorizontalBarChart } from './generate-horizontal-bar-chart'
import { generateLinePlot } from './generate-line-plot'
import { generatePieChart } from './generate-pie-chart'
import { generateRadarChart } from './generate-radar-chart'
import { generateScatterPlot } from './generate-scatter-plot'
export const actionImplementations = {
generateLinePlot,
generateBarChart,
generatePieChart,
generateScatterPlot,
generateBubbleChart,
generateDoughnutChart,
generateRadarChart,
generateHorizontalBarChart,
}
+35
View File
@@ -0,0 +1,35 @@
import axios from 'axios'
import type { ChartConfiguration } from 'chart.js' // do not import the implementation, only the types
import * as bp from '.botpress'
export type ChartConfig = ChartConfiguration
export type BuildChartProps = {
chartConfig: ChartConfig
client: bp.Client
botId: string
fileName: string
}
export const buildChart = async (props: BuildChartProps) => {
try {
const response = await axios.get('https://quickchart.io/chart', {
params: {
key: bp.secrets.QUICKCHARTS_API_KEY,
c: JSON.stringify(props.chartConfig),
},
responseType: 'arraybuffer',
})
const { file } = await props.client.uploadFile({
key: `${props.fileName}_${Date.now()}.png`,
content: response.data,
index: false,
accessPolicies: ['public_content'],
publicContentImmediatelyAccessible: true,
})
return file.url!
} catch (err) {
console.error(`Error generating ${props.fileName}:`, err)
throw err
}
}
@@ -0,0 +1,227 @@
import { z } from '@botpress/sdk'
const generateLinePlot = {
title: 'Line Plot',
description: 'Generate a line plot',
input: {
schema: z.object({
xData: z
.array(z.string().or(z.number()))
.catch(() => [1, 2, 3, 4, 5])
.describe('The data for the x axis')
.title('X Data'),
yData: z
.array(z.number())
.catch(() => [1, 2, 3, 4, 5])
.describe('the data for the y axis')
.title('Y Data'),
title: z.string().optional().describe('The title of the plot').title('Line Plot Title'),
xAxisTitle: z.string().optional().describe('The title of the x axis').title('X Axis Title'),
yAxisTitle: z.string().optional().describe('The title of the y axis').title('Y Axis Title'),
}),
},
output: {
schema: z.object({
imageUrl: z.string().describe('The url of the generated image').title('Image Url'),
}),
},
}
const generateBarChart = {
title: 'Bar Chart',
description: 'Generate a Bar chart',
input: {
schema: z.object({
xData: z
.array(z.string().or(z.number()))
.catch(() => [1, 2, 3, 4, 5])
.describe('The data for the x axis')
.title('X Data'),
yData: z
.array(z.number())
.catch(() => [1, 2, 3, 4, 5])
.describe('The data for the y axis')
.title('Y Data'),
title: z.string().optional().describe('The title of the Bar Chart').title('Bar Chart Title'),
xAxisTitle: z.string().optional().describe('The title of the x axis').title('X Axis Title'),
yAxisTitle: z.string().optional().describe('The title of the y axis').title('Y Axis Title'),
}),
},
output: {
schema: z.object({
imageUrl: z.string().describe('The url of the generated image').title('Image Url'),
}),
},
}
const generatePieChart = {
title: 'Pie Chart',
description: 'Generate a pie chart',
input: {
schema: z.object({
labels: z
.array(z.string())
.catch(() => ['Label 1', 'Label 2', 'Label 3'])
.describe('The labels for the data')
.title('Labels'),
data: z
.array(z.number())
.catch(() => [10, 20, 30])
.describe('The data to plot')
.title('Data'),
title: z.string().optional().describe('The title of the pie chart').title('Pie Chart Title'),
}),
},
output: {
schema: z.object({
imageUrl: z.string().describe('The url of the generated image').title('Image Url'),
}),
},
}
export const generateScatterPlot = {
title: 'Scatter Plot',
description: 'Generate a scatter plot',
input: {
schema: z.object({
data: z
.array(z.object({ x: z.number(), y: z.number() }))
.catch(() => [
{ x: 1, y: 2 },
{ x: 2, y: 3 },
{ x: 3, y: 4 },
])
.describe('The data to plot')
.title('Data'),
title: z.string().optional().describe('The title of the scatter plot').title('Scatter Plot Title'),
xAxisTitle: z.string().optional().describe('The title of the x axis').title('X Axis Title'),
yAxisTitle: z.string().optional().describe('The title of the y axis').title('Y Axis Title'),
}),
},
output: {
schema: z.object({
imageUrl: z.string().describe('The url of the generated image').title('Image Url'),
}),
},
}
const generateDoughnutChart = {
title: 'Doughnut Chart',
description: 'Generate a Doughnut Chart',
input: {
schema: z.object({
labels: z
.array(z.string())
.catch(() => ['Label 1', 'Label 2', 'Label 3'])
.describe('The labels for the data')
.title('Labels'),
data: z
.array(z.number())
.catch(() => [10, 20, 30])
.describe('The data to plot')
.title('Data'),
title: z.string().optional().describe('The title of the doughnut chart').title('Doughnut Chart Title'),
}),
},
output: {
schema: z.object({
imageUrl: z.string().describe('The url of the generated image').title('Image Url'),
}),
},
}
const generateRadarChart = {
title: 'Radar Chart',
description: 'Generate a radar Chart',
input: {
schema: z.object({
labels: z
.array(z.string())
.catch(() => ['Label 1', 'Label 2', 'Label 3'])
.describe('The labels for the data')
.title('Labels'),
data: z
.array(z.number())
.catch(() => [10, 20, 30])
.describe('The data to plot')
.title('Data'),
title: z.string().optional().describe('The title of the radar chart').title('Radar Chart Title'),
axisTitle: z.string().optional().describe('The title of the axis').title('Axis Title'),
}),
},
output: {
schema: z.object({
imageUrl: z.string().describe('The url of the generated image').title('Image Url'),
}),
},
}
const generateBubbleChart = {
title: 'Bubble Chart',
description: 'Generate a bubble Chart',
input: {
schema: z.object({
data: z
.array(
z.object({
x: z.number(),
y: z.number(),
r: z.number(),
})
)
.catch(() => [
{ x: 1, y: 2, r: 5 },
{ x: 2, y: 3, r: 10 },
{ x: 3, y: 4, r: 15 },
])
.describe('The data to plot')
.title('Data'),
title: z.string().optional().describe('The title of the bubble chart').title('Bubble Chart Title'),
xAxisTitle: z.string().optional().describe('The title of the x axis').title('X Axis Title'),
yAxisTitle: z.string().optional().describe('The title of the y axis').title('Y Axis Title'),
}),
},
output: {
schema: z.object({
imageUrl: z.string().describe('The url of the generated image').title('Image Url'),
}),
},
}
const generateHorizontalBarChart = {
title: 'Horizontal Bar Chart',
description: 'Generate a horizontal Chart',
input: {
schema: z.object({
xData: z
.array(z.string().or(z.number()))
.catch(() => [1, 2, 3, 4, 5])
.describe('The data for the x axis')
.title('X Data'),
yData: z
.array(z.number())
.catch(() => [1, 2, 3, 4, 5])
.describe('The data for the y axis')
.title('Y Data'),
title: z.string().optional().describe('The title of the bar chart').title('Bar Chart Title'),
xAxisTitle: z.string().optional().describe('The title of the x axis').title('X Axis Title'),
yAxisTitle: z.string().optional().describe('The title of the y axis').title('Y Axis Title'),
}),
},
output: {
schema: z.object({
imageUrl: z.string().describe('The url of the generated image').title('Image Url'),
}),
},
}
export const actionDefinitions = {
generateLinePlot,
generateBarChart,
generatePieChart,
generateScatterPlot,
generateDoughnutChart,
generateRadarChart,
generateBubbleChart,
generateHorizontalBarChart,
}
+11
View File
@@ -0,0 +1,11 @@
import { actionImplementations } from './actions'
import * as bp from '.botpress'
export default new bp.Integration({
register: async () => {},
unregister: async () => {},
actions: actionImplementations,
channels: {},
handler: async () => {},
})
+8
View File
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": { "*": ["./*"] },
"outDir": "dist"
},
"include": [".botpress/**/*", "definitions/**/*", "src/**/*", "*.ts"]
}
+2
View File
@@ -0,0 +1,2 @@
import config from '../../vitest.config'
export default config