@takoviz/ai-sdk 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.
- package/PUBLISH.md +45 -0
- package/README.md +125 -0
- package/VERCEL_REGISTRY.md +104 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +58 -0
- package/dist/types.d.ts +36 -0
- package/dist/types.js +1 -0
- package/package.json +53 -0
- package/test.ts +22 -0
package/PUBLISH.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Publishing to npm
|
|
2
|
+
|
|
3
|
+
## Steps to Publish
|
|
4
|
+
|
|
5
|
+
1. **Login to npm** (if not already logged in):
|
|
6
|
+
```bash
|
|
7
|
+
npm login
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
2. **Build the package**:
|
|
11
|
+
```bash
|
|
12
|
+
npm run build
|
|
13
|
+
```
|
|
14
|
+
This compiles TypeScript to JavaScript in the `dist/` folder.
|
|
15
|
+
|
|
16
|
+
3. **Publish to npm**:
|
|
17
|
+
```bash
|
|
18
|
+
npm publish --access public
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The package will be published as `@takoviz/ai-sdk` version `1.0.0`.
|
|
22
|
+
|
|
23
|
+
4. **Verify publication**:
|
|
24
|
+
- Check at: https://www.npmjs.com/package/@takoviz/ai-sdk
|
|
25
|
+
- Test installation: `npm install @takoviz/ai-sdk`
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Updating Version
|
|
30
|
+
|
|
31
|
+
To publish a new version:
|
|
32
|
+
|
|
33
|
+
1. Update version in `package.json`:
|
|
34
|
+
```bash
|
|
35
|
+
npm version patch # For bug fixes (1.0.0 -> 1.0.1)
|
|
36
|
+
npm version minor # For new features (1.0.0 -> 1.1.0)
|
|
37
|
+
npm version major # For breaking changes (1.0.0 -> 2.0.0)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
2. Build and publish:
|
|
41
|
+
```bash
|
|
42
|
+
npm run build
|
|
43
|
+
npm publish --access public
|
|
44
|
+
git push && git push --tags
|
|
45
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Tako AI SDK
|
|
2
|
+
|
|
3
|
+
Add powerful knowledge search with data visualizations to your AI applications using Tako's knowledge base.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @takoviz/ai-sdk ai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
Get your API key from the [Tako Dashboard](https://trytako.com) and set it as an environment variable:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
export TAKO_API_KEY=your_api_key_here
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { takoSearch } from '@takoviz/ai-sdk';
|
|
23
|
+
import { generateText } from 'ai';
|
|
24
|
+
|
|
25
|
+
const { text } = await generateText({
|
|
26
|
+
model: 'openai/gpt-4o-mini',
|
|
27
|
+
prompt: 'What is the stock price of Nvidia?',
|
|
28
|
+
tools: {
|
|
29
|
+
takoSearch: takoSearch(),
|
|
30
|
+
},
|
|
31
|
+
maxSteps: 5,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log(text);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Configuration Options
|
|
38
|
+
|
|
39
|
+
You can customize the search behavior by passing a configuration object:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const { text } = await generateText({
|
|
43
|
+
model: 'openai/gpt-4o-mini',
|
|
44
|
+
prompt: 'What is the GDP of major economies?',
|
|
45
|
+
tools: {
|
|
46
|
+
takoSearch: takoSearch({
|
|
47
|
+
apiKey: 'your_api_key', // Optional: override environment variable
|
|
48
|
+
sourceIndexes: ['tako', 'web'], // Default: ['tako', 'web']
|
|
49
|
+
searchEffort: 'deep', // Options: 'fast', 'deep', 'auto'. Default: 'fast'
|
|
50
|
+
countryCode: 'US', // Default: 'US'
|
|
51
|
+
locale: 'en-US', // Default: 'en-US'
|
|
52
|
+
outputSettings: {
|
|
53
|
+
knowledgeCardSettings: {
|
|
54
|
+
imageDarkMode: true, // Default: false
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
maxSteps: 5,
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## API Reference
|
|
64
|
+
|
|
65
|
+
### `takoSearch(config?: TakoSearchConfig)`
|
|
66
|
+
|
|
67
|
+
Creates a Tako knowledge search tool for use with Vercel AI SDK.
|
|
68
|
+
|
|
69
|
+
#### Parameters
|
|
70
|
+
|
|
71
|
+
- `config.apiKey` (optional): Tako API key. Defaults to `TAKO_API_KEY` environment variable.
|
|
72
|
+
- `config.sourceIndexes` (optional): Array of index sources to search. Options: `'tako'`, `'web'`, `'connected_data'`. Default: `['tako', 'web']`.
|
|
73
|
+
- `config.searchEffort` (optional): Search depth. Options: `'fast'`, `'deep'`, `'auto'`. Default: `'fast'`.
|
|
74
|
+
- `config.countryCode` (optional): ISO3166-1 alpha-2 country code. Default: `'US'`.
|
|
75
|
+
- `config.locale` (optional): Language/region identifier. Default: `'en-US'`.
|
|
76
|
+
- `config.outputSettings` (optional): Output customization options.
|
|
77
|
+
|
|
78
|
+
#### Returns
|
|
79
|
+
|
|
80
|
+
A Vercel AI SDK tool that accepts a natural language query and returns Tako knowledge cards with visualizations, data, and sources.
|
|
81
|
+
|
|
82
|
+
## Response Format
|
|
83
|
+
|
|
84
|
+
The tool returns a `TakoSearchResponse` object:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
{
|
|
88
|
+
outputs: {
|
|
89
|
+
knowledge_cards: [
|
|
90
|
+
{
|
|
91
|
+
card_id: string;
|
|
92
|
+
title: string;
|
|
93
|
+
description: string;
|
|
94
|
+
webpage_url: string;
|
|
95
|
+
image_url: string;
|
|
96
|
+
sources: Array<{ source_name: string; url: string }>;
|
|
97
|
+
visualization_data: {
|
|
98
|
+
data: any[];
|
|
99
|
+
viz_config: Record<string, any>;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
];
|
|
103
|
+
answer: string;
|
|
104
|
+
};
|
|
105
|
+
request_id: string;
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## TypeScript
|
|
110
|
+
|
|
111
|
+
This package includes full TypeScript type definitions. Import types as needed:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import type { TakoSearchConfig, TakoSearchResponse, TakoKnowledgeCard } from '@takodata/ai-sdk';
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
|
120
|
+
|
|
121
|
+
## Links
|
|
122
|
+
|
|
123
|
+
- [Tako Documentation](https://docs.tako.com)
|
|
124
|
+
- [Vercel AI SDK Documentation](https://sdk.vercel.ai/docs)
|
|
125
|
+
- [GitHub Repository](https://github.com/TakoData/ai-sdk)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Adding Tako to Vercel AI Registry
|
|
2
|
+
|
|
3
|
+
After publishing to npm, follow these steps to add Tako to the official Vercel AI tools registry.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- ✅ Package published to npm at `@takoviz/ai-sdk`
|
|
8
|
+
- ✅ README with clear documentation
|
|
9
|
+
- ✅ Working code example tested
|
|
10
|
+
- ✅ API key instructions in README
|
|
11
|
+
|
|
12
|
+
## Steps
|
|
13
|
+
|
|
14
|
+
### 1. Fork and Clone Vercel AI Repository
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
git clone https://github.com/vercel/ai.git
|
|
18
|
+
cd ai
|
|
19
|
+
pnpm install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Create Feature Branch
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
git checkout -b feat/add-tool-tako-search
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 3. Add Tool Entry
|
|
29
|
+
|
|
30
|
+
Edit `content/tools-registry/registry.ts` and add this entry to the tools array:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
{
|
|
34
|
+
slug: 'tako-search',
|
|
35
|
+
name: 'Tako Search',
|
|
36
|
+
description: 'Search Tako\'s knowledge base for data visualizations, insights, and well-sourced information with charts and analytics.',
|
|
37
|
+
packageName: '@takoviz/ai-sdk',
|
|
38
|
+
installCommand: {
|
|
39
|
+
pnpm: 'pnpm add @takoviz/ai-sdk',
|
|
40
|
+
npm: 'npm install @takoviz/ai-sdk',
|
|
41
|
+
yarn: 'yarn add @takoviz/ai-sdk',
|
|
42
|
+
bun: 'bun add @takoviz/ai-sdk',
|
|
43
|
+
},
|
|
44
|
+
codeExample: `import { takoSearch } from '@takoviz/ai-sdk';
|
|
45
|
+
import { generateText } from 'ai';
|
|
46
|
+
|
|
47
|
+
const { text } = await generateText({
|
|
48
|
+
model: 'openai/gpt-4o-mini',
|
|
49
|
+
prompt: 'What is the stock price of Nvidia?',
|
|
50
|
+
tools: {
|
|
51
|
+
takoSearch: takoSearch(),
|
|
52
|
+
},
|
|
53
|
+
maxSteps: 5,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
console.log(text);`,
|
|
57
|
+
docsUrl: 'https://github.com/TakoData/ai-sdk#readme',
|
|
58
|
+
npmUrl: 'https://www.npmjs.com/package/@takoviz/ai-sdk',
|
|
59
|
+
websiteUrl: 'https://tako.com',
|
|
60
|
+
apiKeyEnvName: 'TAKO_API_KEY',
|
|
61
|
+
apiKeyUrl: 'https://trytako.com',
|
|
62
|
+
tags: ['search', 'data', 'visualization', 'analytics'],
|
|
63
|
+
},
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 4. Test Locally
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pnpm dev
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Navigate to the tools registry page and verify your tool appears correctly.
|
|
73
|
+
|
|
74
|
+
### 5. Create Pull Request
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
git add content/tools-registry/registry.ts
|
|
78
|
+
git commit -m "feat(tools-registry): add tako-search"
|
|
79
|
+
git push origin feat/add-tool-tako-search
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Then:
|
|
83
|
+
1. Go to https://github.com/vercel/ai
|
|
84
|
+
2. Click "New Pull Request"
|
|
85
|
+
3. Use title: `feat(tools-registry): add tako-search`
|
|
86
|
+
4. Description:
|
|
87
|
+
```
|
|
88
|
+
Adds Tako Search tool to the registry.
|
|
89
|
+
|
|
90
|
+
Tako Search provides access to Tako's knowledge base with data visualizations,
|
|
91
|
+
charts, and well-sourced analytics for AI applications.
|
|
92
|
+
|
|
93
|
+
- Package: @takoviz/ai-sdk
|
|
94
|
+
- Docs: https://github.com/TakoData/ai-sdk
|
|
95
|
+
- Website: https://tako.com
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 6. Wait for Review
|
|
99
|
+
|
|
100
|
+
The Vercel team will review and merge your PR. Once merged, Tako will appear in the official AI SDK tools registry at https://sdk.vercel.ai/docs/ai-sdk-ui/tools-registry!
|
|
101
|
+
|
|
102
|
+
## Reference
|
|
103
|
+
|
|
104
|
+
Official guide: https://github.com/vercel/ai/blob/main/contributing/add-new-tool-to-registry.md
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TakoSearchConfig, TakoSearchResponse } from "./types";
|
|
2
|
+
export declare function takoSearch(config?: TakoSearchConfig): import("@ai-sdk/provider-utils").Tool<{
|
|
3
|
+
query: string;
|
|
4
|
+
}, TakoSearchResponse>;
|
|
5
|
+
export type { TakoSearchConfig, TakoSearchResponse, TakoKnowledgeCard, TakoSource, TakoVisualizationData, } from "./types";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { tool } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export function takoSearch(config = {}) {
|
|
4
|
+
const { apiKey = process.env.TAKO_API_KEY || process.env.TAKO_API_TOKEN, sourceIndexes = ["tako", "web"], searchEffort = "fast", outputSettings, countryCode = "US", locale = "en-US", } = config;
|
|
5
|
+
return tool({
|
|
6
|
+
description: "Search Tako's knowledge base for visualized data, insights, and information. Use this to find knowledge cards with charts, data visualizations, and well-sourced answers to questions.",
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
query: z
|
|
9
|
+
.string()
|
|
10
|
+
.min(1)
|
|
11
|
+
.max(500)
|
|
12
|
+
.describe("The search query - use natural language to describe what you're looking for"),
|
|
13
|
+
}),
|
|
14
|
+
execute: async ({ query }) => {
|
|
15
|
+
if (!apiKey) {
|
|
16
|
+
throw new Error("TAKO_API_KEY is required. Set it in environment variables or pass it in config.");
|
|
17
|
+
}
|
|
18
|
+
const requestBody = {
|
|
19
|
+
inputs: {
|
|
20
|
+
text: query,
|
|
21
|
+
},
|
|
22
|
+
source_indexes: sourceIndexes,
|
|
23
|
+
search_effort: searchEffort,
|
|
24
|
+
country_code: countryCode,
|
|
25
|
+
locale: locale,
|
|
26
|
+
};
|
|
27
|
+
if (outputSettings) {
|
|
28
|
+
requestBody.output_settings = {
|
|
29
|
+
knowledge_card_settings: {
|
|
30
|
+
image_dark_mode: outputSettings.knowledgeCardSettings?.imageDarkMode,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const response = await fetch("https://trytako.com/api/v1/knowledge_search", {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: {
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
"X-API-Key": apiKey,
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify(requestBody),
|
|
42
|
+
});
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
const errorText = await response.text();
|
|
45
|
+
throw new Error(`Tako API error: ${response.status} - ${errorText}`);
|
|
46
|
+
}
|
|
47
|
+
const data = await response.json();
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error instanceof Error) {
|
|
52
|
+
throw new Error(`Failed to search with Tako: ${error.message}`);
|
|
53
|
+
}
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface TakoSearchConfig {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
sourceIndexes?: ("tako" | "web" | "connected_data")[];
|
|
4
|
+
searchEffort?: "fast" | "deep" | "auto";
|
|
5
|
+
outputSettings?: {
|
|
6
|
+
knowledgeCardSettings?: {
|
|
7
|
+
imageDarkMode?: boolean;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
countryCode?: string;
|
|
11
|
+
locale?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface TakoSource {
|
|
14
|
+
source_name: string;
|
|
15
|
+
url: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TakoVisualizationData {
|
|
18
|
+
data: any[];
|
|
19
|
+
viz_config: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
export interface TakoKnowledgeCard {
|
|
22
|
+
card_id: string;
|
|
23
|
+
title: string;
|
|
24
|
+
description: string;
|
|
25
|
+
webpage_url: string;
|
|
26
|
+
image_url: string;
|
|
27
|
+
sources: TakoSource[];
|
|
28
|
+
visualization_data: TakoVisualizationData;
|
|
29
|
+
}
|
|
30
|
+
export interface TakoSearchResponse {
|
|
31
|
+
outputs: {
|
|
32
|
+
knowledge_cards: TakoKnowledgeCard[];
|
|
33
|
+
answer: string;
|
|
34
|
+
};
|
|
35
|
+
request_id: string;
|
|
36
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@takoviz/ai-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Tako knowledge search tool for Vercel AI SDK",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"test": "tsx test.ts",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"tako",
|
|
21
|
+
"knowledge-search",
|
|
22
|
+
"ai-sdk",
|
|
23
|
+
"vercel",
|
|
24
|
+
"data-visualization",
|
|
25
|
+
"ai",
|
|
26
|
+
"tools"
|
|
27
|
+
],
|
|
28
|
+
"author": "Tako",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"homepage": "https://tako.com",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/TakoData/ai-sdk.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/TakoData/ai-sdk/issues"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"ai": "^6.0.18"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@ai-sdk/anthropic": "^3.0.8",
|
|
43
|
+
"@ai-sdk/gateway": "^3.0.9",
|
|
44
|
+
"@ai-sdk/openai": "^3.0.7",
|
|
45
|
+
"@ai-sdk/provider-utils": "^4.0.4",
|
|
46
|
+
"zod": "^3.22.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^20.0.0",
|
|
50
|
+
"tsx": "^4.0.0",
|
|
51
|
+
"typescript": "^5.0.0"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/test.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { takoSearch } from './src/index.js';
|
|
2
|
+
import { generateText } from 'ai';
|
|
3
|
+
import { openai } from '@ai-sdk/openai';
|
|
4
|
+
|
|
5
|
+
async function test() {
|
|
6
|
+
const result = await generateText({
|
|
7
|
+
model: openai('gpt-4o-mini'),
|
|
8
|
+
prompt: 'What is the stock price of Nvidia?',
|
|
9
|
+
tools: {
|
|
10
|
+
takoSearch: takoSearch(),
|
|
11
|
+
},
|
|
12
|
+
maxSteps: 5,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
console.log('Result text:', result.text);
|
|
16
|
+
console.log('\nTool calls:', JSON.stringify(result.toolCalls, null, 2));
|
|
17
|
+
console.log('\nTool results:', JSON.stringify(result.toolResults, null, 2));
|
|
18
|
+
console.log('\nSteps:', result.steps.length);
|
|
19
|
+
console.log('\nWarnings:', result.warnings);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
test().catch(console.error);
|