tako-sdk 0.1.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/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # Tako SDK
2
+
3
+ A lightweight TypeScript SDK for the [Tako API](https://trytako.com).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install tako-sdk
9
+ # or
10
+ yarn add tako-sdk
11
+ # or
12
+ pnpm add tako-sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { createTakoClient } from 'tako-sdk';
19
+
20
+ // Initialize the client
21
+ const tako = createTakoClient(process.env.TAKO_API_KEY!);
22
+
23
+ // Search Tako Knowledge
24
+ const results = await tako.knowledgeSearch('AMD vs. Nvidia headcount since 2015');
25
+ console.log(results.outputs.knowledge_cards);
26
+ ```
27
+
28
+ ## Usage Examples
29
+
30
+ ### Next.js API Route (App Router)
31
+
32
+ ```typescript
33
+ // app/api/tako-search/route.ts
34
+ import { createTakoClient } from 'tako-sdk';
35
+ import { NextResponse } from 'next/server';
36
+
37
+ export async function POST(request: Request) {
38
+ const { query, sourceIndexes } = await request.json();
39
+ const tako = createTakoClient(process.env.TAKO_API_KEY!);
40
+
41
+ try {
42
+ const results = await tako.knowledgeSearch(query, sourceIndexes);
43
+ return NextResponse.json(results);
44
+ } catch (error: any) {
45
+ return NextResponse.json(
46
+ { error: error.message || 'An error occurred' },
47
+ { status: error.status || 500 }
48
+ );
49
+ }
50
+ }
51
+ ```
52
+
53
+ ### Edge API Route
54
+
55
+ ```typescript
56
+ // app/api/tako-edge/route.ts
57
+ import { createTakoClient } from 'tako-sdk';
58
+ import { NextResponse } from 'next/server';
59
+
60
+ export const runtime = 'edge';
61
+
62
+ export async function POST(request: Request) {
63
+ const { query, sourceIndexes } = await request.json();
64
+ const tako = createTakoClient(process.env.TAKO_API_KEY!);
65
+
66
+ try {
67
+ const results = await tako.knowledgeSearch(query, sourceIndexes);
68
+ return NextResponse.json(results);
69
+ } catch (error: any) {
70
+ return NextResponse.json(
71
+ { error: error.message || 'An error occurred' },
72
+ { status: error.status || 500 }
73
+ );
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## API Reference
79
+
80
+ ### `createTakoClient(apiKey, baseUrl?)`
81
+
82
+ Creates a new Tako API client.
83
+
84
+ ```typescript
85
+ const tako = createTakoClient('your-api-key');
86
+ ```
87
+
88
+ Parameters:
89
+ - `apiKey` (string): Your Tako API key
90
+ - `baseUrl` (string, optional): Override the default API base URL
91
+
92
+ ### `takoClient.knowledgeSearch(text, sourceIndexes?)`
93
+
94
+ Search Tako Knowledge using natural language.
95
+
96
+ ```typescript
97
+ const results = await tako.knowledgeSearch('AMD vs. Nvidia headcount since 2015');
98
+ ```
99
+
100
+ Parameters:
101
+ - `text` (string): The natural language query text
102
+ - `sourceIndexes` (string[], optional): Array of source indexes to search within
103
+
104
+ Returns: `Promise<KnowledgeSearchResponse>`
105
+
106
+ ## Examples
107
+
108
+ The SDK includes several examples in the `examples/` directory:
109
+
110
+ - `edge-api-route.ts` - Edge Runtime API route example
111
+ - `next-api-route.ts` - Standard Next.js API route example
112
+
113
+ ## Error Handling
114
+
115
+ The SDK throws typed errors with status codes and messages:
116
+
117
+ ```typescript
118
+ try {
119
+ const results = await tako.knowledgeSearch(query);
120
+ } catch (error: any) {
121
+ if (error.status === 401) {
122
+ console.error('Authentication error:', error.message);
123
+ } else if (error.status === 429) {
124
+ console.error('Rate limit exceeded:', error.message);
125
+ } else {
126
+ console.error('Unexpected error:', error);
127
+ }
128
+ }
129
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ SourceIndex: () => SourceIndex,
24
+ createTakoClient: () => createTakoClient
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/types.ts
29
+ var SourceIndex = /* @__PURE__ */ ((SourceIndex2) => {
30
+ SourceIndex2["TAKO"] = "tako";
31
+ SourceIndex2["WEB"] = "web";
32
+ return SourceIndex2;
33
+ })(SourceIndex || {});
34
+
35
+ // src/client.ts
36
+ var TakoClient = class {
37
+ /**
38
+ * Create a new Tako API client
39
+ * @param config Configuration for the Tako API client
40
+ */
41
+ constructor(config) {
42
+ if (!config.apiKey?.trim()) {
43
+ throw new Error("API key is required");
44
+ }
45
+ this.apiKey = config.apiKey;
46
+ this.baseUrl = config.baseUrl || "https://trytako.com/api/v1";
47
+ }
48
+ /**
49
+ * Make a request to the Tako API
50
+ * @param path API endpoint path
51
+ * @param method HTTP method
52
+ * @param body Request body
53
+ * @returns Response data
54
+ */
55
+ async request(path, method, body) {
56
+ const url = `${this.baseUrl}${path}`;
57
+ const headers = {
58
+ Authorization: `Bearer ${this.apiKey}`,
59
+ "Content-Type": "application/json"
60
+ };
61
+ const options = {
62
+ method,
63
+ headers,
64
+ body: body ? JSON.stringify(body) : void 0
65
+ };
66
+ try {
67
+ const response = await fetch(url, options);
68
+ if (!response.ok) {
69
+ const errorData = await response.json();
70
+ throw {
71
+ status: response.status,
72
+ message: errorData.message || response.statusText,
73
+ details: errorData
74
+ };
75
+ }
76
+ return await response.json();
77
+ } catch (error) {
78
+ if (error.status) {
79
+ throw error;
80
+ }
81
+ throw {
82
+ status: 500,
83
+ message: "Network error",
84
+ details: error
85
+ };
86
+ }
87
+ }
88
+ /**
89
+ * Search Tako Knowledge using natural language
90
+ * @param text The natural language query text
91
+ * @param sourceIndexes Optional array of source indexes to search within
92
+ * @returns Knowledge search results
93
+ */
94
+ async knowledgeSearch(text, sourceIndexes) {
95
+ if (!text?.trim()) {
96
+ throw new Error("Search text is required");
97
+ }
98
+ const requestBody = {
99
+ inputs: {
100
+ text,
101
+ ...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : {}
102
+ }
103
+ };
104
+ return this.request("/knowledge_search", "POST", requestBody);
105
+ }
106
+ };
107
+
108
+ // src/index.ts
109
+ function createTakoClient(apiKey, baseUrl) {
110
+ return new TakoClient({ apiKey, baseUrl });
111
+ }
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ SourceIndex,
115
+ createTakoClient
116
+ });
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Tako API Types
3
+ */
4
+ declare enum SourceIndex {
5
+ TAKO = "tako",
6
+ WEB = "web"
7
+ }
8
+ interface TakoConfig {
9
+ apiKey: string;
10
+ baseUrl?: string;
11
+ }
12
+ interface KnowledgeSearchInput {
13
+ text: string;
14
+ source_indexes?: SourceIndex[];
15
+ }
16
+ interface KnowledgeSearchRequest {
17
+ inputs: KnowledgeSearchInput;
18
+ }
19
+ interface Source {
20
+ source_name: string;
21
+ source_description: string;
22
+ source_index: string;
23
+ url: string;
24
+ }
25
+ interface Methodology {
26
+ methodology_name: string;
27
+ methodology_description?: string;
28
+ }
29
+ interface KnowledgeCard {
30
+ card_id: string;
31
+ title: string;
32
+ description: string;
33
+ webpage_url: string;
34
+ image_url: string;
35
+ embed_url: string;
36
+ sources: Source[];
37
+ methodologies?: Methodology[];
38
+ }
39
+ interface KnowledgeSearchResponse {
40
+ outputs: {
41
+ knowledge_cards: KnowledgeCard[];
42
+ };
43
+ }
44
+ interface TakoError {
45
+ status: number;
46
+ message: string;
47
+ details?: any;
48
+ }
49
+
50
+ /**
51
+ * Tako API Client
52
+ */
53
+ declare class TakoClient {
54
+ private apiKey;
55
+ private baseUrl;
56
+ /**
57
+ * Create a new Tako API client
58
+ * @param config Configuration for the Tako API client
59
+ */
60
+ constructor(config: TakoConfig);
61
+ /**
62
+ * Make a request to the Tako API
63
+ * @param path API endpoint path
64
+ * @param method HTTP method
65
+ * @param body Request body
66
+ * @returns Response data
67
+ */
68
+ private request;
69
+ /**
70
+ * Search Tako Knowledge using natural language
71
+ * @param text The natural language query text
72
+ * @param sourceIndexes Optional array of source indexes to search within
73
+ * @returns Knowledge search results
74
+ */
75
+ knowledgeSearch(text: string, sourceIndexes?: SourceIndex[]): Promise<KnowledgeSearchResponse>;
76
+ }
77
+
78
+ /**
79
+ * Create a new Tako API client
80
+ * @param apiKey Your Tako API key
81
+ * @param baseUrl Optional base URL for the Tako API
82
+ * @returns A configured Tako client
83
+ */
84
+ declare function createTakoClient(apiKey: string, baseUrl?: string): TakoClient;
85
+
86
+ export { KnowledgeCard, KnowledgeSearchInput, KnowledgeSearchRequest, KnowledgeSearchResponse, Methodology, Source, SourceIndex, TakoConfig, TakoError, createTakoClient };
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Tako API Types
3
+ */
4
+ declare enum SourceIndex {
5
+ TAKO = "tako",
6
+ WEB = "web"
7
+ }
8
+ interface TakoConfig {
9
+ apiKey: string;
10
+ baseUrl?: string;
11
+ }
12
+ interface KnowledgeSearchInput {
13
+ text: string;
14
+ source_indexes?: SourceIndex[];
15
+ }
16
+ interface KnowledgeSearchRequest {
17
+ inputs: KnowledgeSearchInput;
18
+ }
19
+ interface Source {
20
+ source_name: string;
21
+ source_description: string;
22
+ source_index: string;
23
+ url: string;
24
+ }
25
+ interface Methodology {
26
+ methodology_name: string;
27
+ methodology_description?: string;
28
+ }
29
+ interface KnowledgeCard {
30
+ card_id: string;
31
+ title: string;
32
+ description: string;
33
+ webpage_url: string;
34
+ image_url: string;
35
+ embed_url: string;
36
+ sources: Source[];
37
+ methodologies?: Methodology[];
38
+ }
39
+ interface KnowledgeSearchResponse {
40
+ outputs: {
41
+ knowledge_cards: KnowledgeCard[];
42
+ };
43
+ }
44
+ interface TakoError {
45
+ status: number;
46
+ message: string;
47
+ details?: any;
48
+ }
49
+
50
+ /**
51
+ * Tako API Client
52
+ */
53
+ declare class TakoClient {
54
+ private apiKey;
55
+ private baseUrl;
56
+ /**
57
+ * Create a new Tako API client
58
+ * @param config Configuration for the Tako API client
59
+ */
60
+ constructor(config: TakoConfig);
61
+ /**
62
+ * Make a request to the Tako API
63
+ * @param path API endpoint path
64
+ * @param method HTTP method
65
+ * @param body Request body
66
+ * @returns Response data
67
+ */
68
+ private request;
69
+ /**
70
+ * Search Tako Knowledge using natural language
71
+ * @param text The natural language query text
72
+ * @param sourceIndexes Optional array of source indexes to search within
73
+ * @returns Knowledge search results
74
+ */
75
+ knowledgeSearch(text: string, sourceIndexes?: SourceIndex[]): Promise<KnowledgeSearchResponse>;
76
+ }
77
+
78
+ /**
79
+ * Create a new Tako API client
80
+ * @param apiKey Your Tako API key
81
+ * @param baseUrl Optional base URL for the Tako API
82
+ * @returns A configured Tako client
83
+ */
84
+ declare function createTakoClient(apiKey: string, baseUrl?: string): TakoClient;
85
+
86
+ export { KnowledgeCard, KnowledgeSearchInput, KnowledgeSearchRequest, KnowledgeSearchResponse, Methodology, Source, SourceIndex, TakoConfig, TakoError, createTakoClient };
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ // src/types.ts
2
+ var SourceIndex = /* @__PURE__ */ ((SourceIndex2) => {
3
+ SourceIndex2["TAKO"] = "tako";
4
+ SourceIndex2["WEB"] = "web";
5
+ return SourceIndex2;
6
+ })(SourceIndex || {});
7
+
8
+ // src/client.ts
9
+ var TakoClient = class {
10
+ /**
11
+ * Create a new Tako API client
12
+ * @param config Configuration for the Tako API client
13
+ */
14
+ constructor(config) {
15
+ if (!config.apiKey?.trim()) {
16
+ throw new Error("API key is required");
17
+ }
18
+ this.apiKey = config.apiKey;
19
+ this.baseUrl = config.baseUrl || "https://trytako.com/api/v1";
20
+ }
21
+ /**
22
+ * Make a request to the Tako API
23
+ * @param path API endpoint path
24
+ * @param method HTTP method
25
+ * @param body Request body
26
+ * @returns Response data
27
+ */
28
+ async request(path, method, body) {
29
+ const url = `${this.baseUrl}${path}`;
30
+ const headers = {
31
+ Authorization: `Bearer ${this.apiKey}`,
32
+ "Content-Type": "application/json"
33
+ };
34
+ const options = {
35
+ method,
36
+ headers,
37
+ body: body ? JSON.stringify(body) : void 0
38
+ };
39
+ try {
40
+ const response = await fetch(url, options);
41
+ if (!response.ok) {
42
+ const errorData = await response.json();
43
+ throw {
44
+ status: response.status,
45
+ message: errorData.message || response.statusText,
46
+ details: errorData
47
+ };
48
+ }
49
+ return await response.json();
50
+ } catch (error) {
51
+ if (error.status) {
52
+ throw error;
53
+ }
54
+ throw {
55
+ status: 500,
56
+ message: "Network error",
57
+ details: error
58
+ };
59
+ }
60
+ }
61
+ /**
62
+ * Search Tako Knowledge using natural language
63
+ * @param text The natural language query text
64
+ * @param sourceIndexes Optional array of source indexes to search within
65
+ * @returns Knowledge search results
66
+ */
67
+ async knowledgeSearch(text, sourceIndexes) {
68
+ if (!text?.trim()) {
69
+ throw new Error("Search text is required");
70
+ }
71
+ const requestBody = {
72
+ inputs: {
73
+ text,
74
+ ...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : {}
75
+ }
76
+ };
77
+ return this.request("/knowledge_search", "POST", requestBody);
78
+ }
79
+ };
80
+
81
+ // src/index.ts
82
+ function createTakoClient(apiKey, baseUrl) {
83
+ return new TakoClient({ apiKey, baseUrl });
84
+ }
85
+ export {
86
+ SourceIndex,
87
+ createTakoClient
88
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "tako-sdk",
3
+ "version": "0.1.0",
4
+ "description": "JavaScript/TypeScript SDK for the Tako API",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsup src/index.ts --format cjs,esm --dts",
14
+ "lint": "eslint src/**/*.ts",
15
+ "test": "jest",
16
+ "prepublishOnly": "npm run build",
17
+ "test:js": "node test.js",
18
+ "test:ts": "node --loader ts-node/esm test.ts"
19
+ },
20
+ "keywords": [
21
+ "tako",
22
+ "api",
23
+ "sdk",
24
+ "typescript",
25
+ "javascript",
26
+ "nextjs"
27
+ ],
28
+ "author": "",
29
+ "license": "MIT",
30
+ "devDependencies": {
31
+ "@types/jest": "^29.5.3",
32
+ "@types/node": "^20.4.5",
33
+ "@typescript-eslint/eslint-plugin": "^6.2.0",
34
+ "@typescript-eslint/parser": "^6.2.0",
35
+ "eslint": "^8.46.0",
36
+ "jest": "^29.6.2",
37
+ "ts-jest": "^29.1.1",
38
+ "ts-node": "^10.9.2",
39
+ "tsup": "^7.1.0",
40
+ "typescript": "^5.1.6"
41
+ },
42
+ "peerDependencies": {
43
+ "typescript": ">=4.7.0"
44
+ },
45
+ "engines": {
46
+ "node": ">=14.0.0"
47
+ }
48
+ }