Feature/Add stripe toolkit (#3522)

add stripe toolkit
This commit is contained in:
Henry Heng 2024-11-15 20:28:07 +00:00 committed by GitHub
parent eaec34f0bc
commit 38ddbd8283
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 326 additions and 1 deletions

View File

@ -0,0 +1,27 @@
import { INodeParams, INodeCredential } from '../src/Interface'
class StripeApi implements INodeCredential {
label: string
name: string
version: number
description: string
inputs: INodeParams[]
constructor() {
this.label = 'Stripe API'
this.name = 'stripeApi'
this.version = 1.0
this.description =
'Refer to <a target="_blank" href="https://support.airtable.com/docs/creating-and-using-api-keys-and-access-tokens">official guide</a> on how to get accessToken on Airtable'
this.inputs = [
{
label: 'Stripe API Token',
name: 'stripeApiToken',
type: 'password',
placeholder: '<STRIPE_API_TOKEN>'
}
]
}
}
module.exports = { credClass: StripeApi }

View File

@ -0,0 +1,271 @@
import { StripeAgentToolkit } from '@stripe/agent-toolkit/langchain'
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { convertMultiOptionsToStringArray, getCredentialData, getCredentialParam } from '../../../src/utils'
class StripeTool_Tools implements INode {
label: string
name: string
version: number
description: string
type: string
icon: string
category: string
baseClasses: string[]
credential: INodeParams
inputs: INodeParams[]
badge?: string
constructor() {
this.label = 'StripeAgentTool'
this.name = 'stripeAgentTool'
this.version = 1.0
this.type = 'stripeAgentTool'
this.icon = 'stripe.png'
this.category = 'Tools'
this.description = 'Use Stripe Agent function calling for financial transactions'
this.badge = 'BETA'
this.inputs = [
{
label: 'Payment Links',
name: 'paymentLinks',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Products',
name: 'products',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Prices',
name: 'prices',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Balance',
name: 'balance',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Invoice Items',
name: 'invoiceItems',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Invoices',
name: 'invoices',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Customers',
name: 'customers',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
}
]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['stripeApi']
}
this.baseClasses = [this.type, 'Tool']
}
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const stripeApiToken = getCredentialParam('stripeApiToken', credentialData, nodeData)
const _paymentLinks = nodeData.inputs?.paymentLinks as string
let paymentLinks: string[] = convertMultiOptionsToStringArray(_paymentLinks)
const _products = nodeData.inputs?.products as string
let products: string[] = convertMultiOptionsToStringArray(_products)
const _prices = nodeData.inputs?.prices as string
let prices: string[] = convertMultiOptionsToStringArray(_prices)
const _balance = nodeData.inputs?.balance as string
let balance: string[] = convertMultiOptionsToStringArray(_balance)
const _invoiceItems = nodeData.inputs?.invoiceItems as string
let invoiceItems: string[] = convertMultiOptionsToStringArray(_invoiceItems)
const _invoices = nodeData.inputs?.invoices as string
let invoices: string[] = convertMultiOptionsToStringArray(_invoices)
const _customers = nodeData.inputs?.customers as string
let customers: string[] = convertMultiOptionsToStringArray(_customers)
const actionObj: any = {}
if (paymentLinks.length > 0) {
actionObj['paymentLinks'] = {}
if (paymentLinks.includes('create')) actionObj['paymentLinks'].create = true
if (paymentLinks.includes('read')) actionObj['paymentLinks'].read = true
if (paymentLinks.includes('update')) actionObj['paymentLinks'].update = true
}
if (products.length > 0) {
actionObj['products'] = {}
if (products.includes('create')) actionObj['products'].create = true
if (products.includes('read')) actionObj['products'].read = true
if (products.includes('update')) actionObj['products'].update = true
}
if (prices.length > 0) {
actionObj['prices'] = {}
if (prices.includes('create')) actionObj['prices'].create = true
if (prices.includes('read')) actionObj['prices'].read = true
if (prices.includes('update')) actionObj['prices'].update = true
}
if (balance.length > 0) {
actionObj['balance'] = {}
if (balance.includes('create')) actionObj['balance'].create = true
if (balance.includes('read')) actionObj['balance'].read = true
if (balance.includes('update')) actionObj['balance'].update = true
}
if (invoiceItems.length > 0) {
actionObj['invoiceItems'] = {}
if (invoiceItems.includes('create')) actionObj['invoiceItems'].create = true
if (invoiceItems.includes('read')) actionObj['invoiceItems'].read = true
if (invoiceItems.includes('update')) actionObj['invoiceItems'].update = true
}
if (invoices.length > 0) {
actionObj['invoices'] = {}
if (invoices.includes('create')) actionObj['invoices'].create = true
if (invoices.includes('read')) actionObj['invoices'].read = true
if (invoices.includes('update')) actionObj['invoices'].update = true
}
if (customers.length > 0) {
actionObj['customers'] = {}
if (customers.includes('create')) actionObj['customers'].create = true
if (customers.includes('read')) actionObj['customers'].read = true
if (customers.includes('update')) actionObj['customers'].update = true
}
const stripeAgentToolkit = new StripeAgentToolkit({
secretKey: stripeApiToken,
configuration: {
actions: actionObj
}
})
const stripeTool = stripeAgentToolkit.getTools()
for (const tool of stripeTool) {
// convert tool name into small letter, and space to underscore, ex: Create Payment Link => create_payment_link
tool.name = tool.name.split(' ').join('_').toLowerCase()
}
return stripeTool
}
}
module.exports = { nodeClass: StripeTool_Tools }

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

View File

@ -59,6 +59,7 @@
"@opensearch-project/opensearch": "^1.2.0", "@opensearch-project/opensearch": "^1.2.0",
"@pinecone-database/pinecone": "2.2.2", "@pinecone-database/pinecone": "2.2.2",
"@qdrant/js-client-rest": "^1.9.0", "@qdrant/js-client-rest": "^1.9.0",
"@stripe/agent-toolkit": "^0.1.20",
"@supabase/supabase-js": "^2.29.0", "@supabase/supabase-js": "^2.29.0",
"@types/js-yaml": "^4.0.5", "@types/js-yaml": "^4.0.5",
"@types/jsdom": "^21.1.1", "@types/jsdom": "^21.1.1",
@ -69,9 +70,9 @@
"assemblyai": "^4.2.2", "assemblyai": "^4.2.2",
"axios": "1.6.2", "axios": "1.6.2",
"cheerio": "^1.0.0-rc.12", "cheerio": "^1.0.0-rc.12",
"couchbase": "4.4.1",
"chromadb": "^1.5.11", "chromadb": "^1.5.11",
"cohere-ai": "^7.7.5", "cohere-ai": "^7.7.5",
"couchbase": "4.4.1",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"css-what": "^6.1.0", "css-what": "^6.1.0",
"d3-dsv": "2", "d3-dsv": "2",

View File

@ -220,6 +220,9 @@ importers:
'@qdrant/js-client-rest': '@qdrant/js-client-rest':
specifier: ^1.9.0 specifier: ^1.9.0
version: 1.9.0(typescript@5.5.2) version: 1.9.0(typescript@5.5.2)
'@stripe/agent-toolkit':
specifier: ^0.1.20
version: 0.1.20(@langchain/core@0.2.18(langchain@0.2.11(@aws-sdk/client-s3@3.529.1)(@aws-sdk/credential-provider-node@3.529.1)(@gomomento/sdk-core@1.68.1)(@gomomento/sdk@1.68.1(encoding@0.1.13))(@langchain/anthropic@0.2.1)(@langchain/aws@0.0.9)(@langchain/cohere@0.0.7)(@langchain/community@0.2.17)(@langchain/google-genai@0.0.22)(@langchain/google-vertexai@0.0.19)(@langchain/groq@0.0.8)(@langchain/mistralai@0.0.26)(@langchain/ollama@0.0.2)(@mendable/firecrawl-js@0.0.28)(@notionhq/client@2.2.14(encoding@0.1.13))(@pinecone-database/pinecone@2.2.2)(@supabase/supabase-js@2.39.8(bufferutil@4.0.8)(utf-8-validate@6.0.4))(apify-client@2.9.3)(assemblyai@4.3.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(axios@1.6.2)(cheerio@1.0.0-rc.12)(chromadb@1.8.1(@google/generative-ai@0.15.0)(cohere-ai@7.10.0(encoding@0.1.13))(encoding@0.1.13)(openai@4.57.3(encoding@0.1.13)(zod@3.22.4)))(couchbase@4.4.1)(d3-dsv@2.0.0)(encoding@0.1.13)(faiss-node@0.5.1)(fast-xml-parser@4.4.1)(html-to-text@9.0.5)(ignore@5.3.1)(ioredis@5.3.2)(jsdom@22.1.0(bufferutil@4.0.8)(canvas@2.11.2(encoding@0.1.13))(utf-8-validate@6.0.4))(mammoth@1.7.0)(mongodb@6.3.0(gcp-metadata@6.1.0(encoding@0.1.13))(socks@2.8.1))(notion-to-md@3.1.1(encoding@0.1.13))(openai@4.57.3(encoding@0.1.13)(zod@3.22.4))(pdf-parse@1.1.1)(playwright@1.42.1)(puppeteer@20.9.0(bufferutil@4.0.8)(encoding@0.1.13)(typescript@5.5.2)(utf-8-validate@6.0.4))(pyodide@0.25.0(bufferutil@4.0.8)(utf-8-validate@6.0.4))(redis@4.6.13)(srt-parser-2@1.2.3)(typeorm@0.3.20(ioredis@5.3.2)(mongodb@6.3.0(gcp-metadata@6.1.0(encoding@0.1.13))(socks@2.8.1))(mysql2@3.11.4)(pg@8.11.3)(redis@4.6.13)(sqlite3@5.1.7)(ts-node@10.9.2(@swc/core@1.4.6)(@types/node@20.12.12)(typescript@5.5.2)))(weaviate-ts-client@1.6.0(encoding@0.1.13)(graphql@16.8.1))(ws@8.16.0(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.57.3(encoding@0.1.13)(zod@3.22.4)))(ai@3.2.22(openai@4.57.3(encoding@0.1.13)(zod@3.22.4))(react@18.2.0)(solid-js@1.7.1)(svelte@4.2.18)(vue@3.4.31(typescript@5.5.2))(zod@3.22.4))
'@supabase/supabase-js': '@supabase/supabase-js':
specifier: ^2.29.0 specifier: ^2.29.0
version: 2.39.8(bufferutil@4.0.8)(utf-8-validate@6.0.4) version: 2.39.8(bufferutil@4.0.8)(utf-8-validate@6.0.4)
@ -5273,6 +5276,13 @@ packages:
'@sqltools/formatter@1.2.5': '@sqltools/formatter@1.2.5':
resolution: { integrity: sha512-Uy0+khmZqUrUGm5dmMqVlnvufZRSK0FbYzVgp0UMstm+F5+W2/jnEEQyc9vo1ZR/E5ZI/B1WjjoTqBqwJL6Krw== } resolution: { integrity: sha512-Uy0+khmZqUrUGm5dmMqVlnvufZRSK0FbYzVgp0UMstm+F5+W2/jnEEQyc9vo1ZR/E5ZI/B1WjjoTqBqwJL6Krw== }
'@stripe/agent-toolkit@0.1.20':
resolution: { integrity: sha512-Qg7OVkkIQhsOwjQOQiwG6ldKBDNM42tjc6qyTBPCR+8aMrf33vTfhHjvLv8NjtOCt2eElBdVqH78JBS5DZi1Xg== }
engines: { node: '>=18' }
peerDependencies:
'@langchain/core': 0.2.18
ai: ^3.4.7
'@supabase/functions-js@2.1.5': '@supabase/functions-js@2.1.5':
resolution: { integrity: sha512-BNzC5XhCzzCaggJ8s53DP+WeHHGT/NfTsx2wUSSGKR2/ikLFQTBCDzMvGz/PxYMqRko/LwncQtKXGOYp1PkPaw== } resolution: { integrity: sha512-BNzC5XhCzzCaggJ8s53DP+WeHHGT/NfTsx2wUSSGKR2/ikLFQTBCDzMvGz/PxYMqRko/LwncQtKXGOYp1PkPaw== }
@ -14812,6 +14822,10 @@ packages:
resolution: { integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== } resolution: { integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== }
engines: { node: '>=8' } engines: { node: '>=8' }
stripe@17.3.1:
resolution: { integrity: sha512-E9/u+GFBPkYnTmfFCoKX3+gP4R3SkZoGunHe4cw9J+sqkj5uxpLFf1LscuI9BuEyIQ0PFAgPTHavgQwRtOvnag== }
engines: { node: '>=12.*' }
strnum@1.0.5: strnum@1.0.5:
resolution: { integrity: sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA== } resolution: { integrity: sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA== }
@ -22832,6 +22846,13 @@ snapshots:
'@sqltools/formatter@1.2.5': {} '@sqltools/formatter@1.2.5': {}
'@stripe/agent-toolkit@0.1.20(@langchain/core@0.2.18(langchain@0.2.11(@aws-sdk/client-s3@3.529.1)(@aws-sdk/credential-provider-node@3.529.1)(@gomomento/sdk-core@1.68.1)(@gomomento/sdk@1.68.1(encoding@0.1.13))(@langchain/anthropic@0.2.1)(@langchain/aws@0.0.9)(@langchain/cohere@0.0.7)(@langchain/community@0.2.17)(@langchain/google-genai@0.0.22)(@langchain/google-vertexai@0.0.19)(@langchain/groq@0.0.8)(@langchain/mistralai@0.0.26)(@langchain/ollama@0.0.2)(@mendable/firecrawl-js@0.0.28)(@notionhq/client@2.2.14(encoding@0.1.13))(@pinecone-database/pinecone@2.2.2)(@supabase/supabase-js@2.39.8(bufferutil@4.0.8)(utf-8-validate@6.0.4))(apify-client@2.9.3)(assemblyai@4.3.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(axios@1.6.2)(cheerio@1.0.0-rc.12)(chromadb@1.8.1(@google/generative-ai@0.15.0)(cohere-ai@7.10.0(encoding@0.1.13))(encoding@0.1.13)(openai@4.57.3(encoding@0.1.13)(zod@3.22.4)))(couchbase@4.4.1)(d3-dsv@2.0.0)(encoding@0.1.13)(faiss-node@0.5.1)(fast-xml-parser@4.4.1)(html-to-text@9.0.5)(ignore@5.3.1)(ioredis@5.3.2)(jsdom@22.1.0(bufferutil@4.0.8)(canvas@2.11.2(encoding@0.1.13))(utf-8-validate@6.0.4))(mammoth@1.7.0)(mongodb@6.3.0(gcp-metadata@6.1.0(encoding@0.1.13))(socks@2.8.1))(notion-to-md@3.1.1(encoding@0.1.13))(openai@4.57.3(encoding@0.1.13)(zod@3.22.4))(pdf-parse@1.1.1)(playwright@1.42.1)(puppeteer@20.9.0(bufferutil@4.0.8)(encoding@0.1.13)(typescript@5.5.2)(utf-8-validate@6.0.4))(pyodide@0.25.0(bufferutil@4.0.8)(utf-8-validate@6.0.4))(redis@4.6.13)(srt-parser-2@1.2.3)(typeorm@0.3.20(ioredis@5.3.2)(mongodb@6.3.0(gcp-metadata@6.1.0(encoding@0.1.13))(socks@2.8.1))(mysql2@3.11.4)(pg@8.11.3)(redis@4.6.13)(sqlite3@5.1.7)(ts-node@10.9.2(@swc/core@1.4.6)(@types/node@20.12.12)(typescript@5.5.2)))(weaviate-ts-client@1.6.0(encoding@0.1.13)(graphql@16.8.1))(ws@8.16.0(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.57.3(encoding@0.1.13)(zod@3.22.4)))(ai@3.2.22(openai@4.57.3(encoding@0.1.13)(zod@3.22.4))(react@18.2.0)(solid-js@1.7.1)(svelte@4.2.18)(vue@3.4.31(typescript@5.5.2))(zod@3.22.4))':
dependencies:
'@langchain/core': 0.2.18(langchain@0.2.11(@aws-sdk/client-s3@3.529.1)(@aws-sdk/credential-provider-node@3.529.1)(@gomomento/sdk-core@1.68.1)(@gomomento/sdk@1.68.1(encoding@0.1.13))(@langchain/anthropic@0.2.1)(@langchain/aws@0.0.9)(@langchain/cohere@0.0.7)(@langchain/community@0.2.17)(@langchain/google-genai@0.0.22)(@langchain/google-vertexai@0.0.19)(@langchain/groq@0.0.8)(@langchain/mistralai@0.0.26)(@langchain/ollama@0.0.2)(@mendable/firecrawl-js@0.0.28)(@notionhq/client@2.2.14(encoding@0.1.13))(@pinecone-database/pinecone@2.2.2)(@supabase/supabase-js@2.39.8(bufferutil@4.0.8)(utf-8-validate@6.0.4))(apify-client@2.9.3)(assemblyai@4.3.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(axios@1.6.2)(cheerio@1.0.0-rc.12)(chromadb@1.8.1(@google/generative-ai@0.15.0)(cohere-ai@7.10.0(encoding@0.1.13))(encoding@0.1.13)(openai@4.57.3(encoding@0.1.13)(zod@3.22.4)))(couchbase@4.4.1)(d3-dsv@2.0.0)(encoding@0.1.13)(faiss-node@0.5.1)(fast-xml-parser@4.4.1)(html-to-text@9.0.5)(ignore@5.3.1)(ioredis@5.3.2)(jsdom@22.1.0(bufferutil@4.0.8)(canvas@2.11.2(encoding@0.1.13))(utf-8-validate@6.0.4))(mammoth@1.7.0)(mongodb@6.3.0(gcp-metadata@6.1.0(encoding@0.1.13))(socks@2.8.1))(notion-to-md@3.1.1(encoding@0.1.13))(openai@4.57.3(encoding@0.1.13)(zod@3.22.4))(pdf-parse@1.1.1)(playwright@1.42.1)(puppeteer@20.9.0(bufferutil@4.0.8)(encoding@0.1.13)(typescript@5.5.2)(utf-8-validate@6.0.4))(pyodide@0.25.0(bufferutil@4.0.8)(utf-8-validate@6.0.4))(redis@4.6.13)(srt-parser-2@1.2.3)(typeorm@0.3.20(ioredis@5.3.2)(mongodb@6.3.0(gcp-metadata@6.1.0(encoding@0.1.13))(socks@2.8.1))(mysql2@3.11.4)(pg@8.11.3)(redis@4.6.13)(sqlite3@5.1.7)(ts-node@10.9.2(@swc/core@1.4.6)(@types/node@20.12.12)(typescript@5.5.2)))(weaviate-ts-client@1.6.0(encoding@0.1.13)(graphql@16.8.1))(ws@8.16.0(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.57.3(encoding@0.1.13)(zod@3.22.4))
ai: 3.2.22(openai@4.57.3(encoding@0.1.13)(zod@3.22.4))(react@18.2.0)(solid-js@1.7.1)(svelte@4.2.18)(vue@3.4.31(typescript@5.5.2))(zod@3.22.4)
stripe: 17.3.1
zod: 3.23.8
'@supabase/functions-js@2.1.5': '@supabase/functions-js@2.1.5':
dependencies: dependencies:
'@supabase/node-fetch': 2.6.15 '@supabase/node-fetch': 2.6.15
@ -34568,6 +34589,11 @@ snapshots:
strip-json-comments@3.1.1: {} strip-json-comments@3.1.1: {}
stripe@17.3.1:
dependencies:
'@types/node': 20.12.12
qs: 6.12.1
strnum@1.0.5: {} strnum@1.0.5: {}
stubs@3.0.0: {} stubs@3.0.0: {}