1.0.0 • Published 4 months ago

@subtotal-inc/ai-toolkit v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Subtotal AI Toolkit - TypeScript

The Subtotal AI Toolkit enables popular agent frameworks including LangChain and Vercel's AI SDK to integrate with Subtotal APIs through function calling. It also provides tooling to quickly integrate metered billing for prompt and completion token usage.

Installation

You don't need this source code unless you want to modify the package. If you just want to use the package run:

npm install @subtotal-inc/ai-toolkit

Requirements

  • Node 18+

Usage

The library needs to be configured with your account's secret API key available in your Subtotal Dashboard. Additionally, configuration enables you to specify the types of actions that can be taken using the toolkit.

import {SubtotalAIToolkit, Tools} from '@subtotal-inc/ai-toolkit/langchain';

const subtotalAIToolkit = new SubtotalAIToolkit({
  secretKey: process.env.SUBTOTAL_SECRET_KEY!,
  configuration: {
    tools: [Tools.getPurchases, Tools.getPurchaseDetails],
  },
});

Tools

The toolkit works with LangChain and Vercel's AI SDK and can be passed as a list of tools. For example:

import {AgentExecutor, createStructuredChatAgent} from 'langchain/agents';

const tools = subtotalAIToolkit.getTools();

const agent = await createStructuredChatAgent({
  llm,
  tools,
  prompt,
});

const agentExecutor = new AgentExecutor({
  agent,
  tools,
});

Model Context Protocol

The Subtotal AI Toolkit also supports the Model Context Protocol (MCP). See /examples/modelcontextprotocol for an example. The same configuration options are available, and the server can be run with all supported transports.

import {
  SubtotalAIToolkit,
  Tools,
} from '@subtotal-inc/ai-toolkit/modelcontextprotocol';
import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new SubtotalAIToolkit({
  secretKey: process.env.SUBTOTAL_SECRET_KEY!,
  configuration: {
    tools: [Tools.getPurchases, Tools.getPurchaseDetails],
  },
});

async function main() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
  console.error('Subtotal MCP Server running on stdio');
}

main().catch((error) => {
  console.error('Fatal error in main():', error);
  process.exit(1);
});
1.0.0

4 months ago

0.1.0

5 months ago