tako-sdk 0.1.1 → 0.1.3
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 +32 -5
- package/dist/index.cjs +44 -10
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +41 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,24 +71,51 @@ const results = await tako.knowledgeSearch('AMD vs. Nvidia headcount since 2015'
|
|
|
71
71
|
|
|
72
72
|
Parameters:
|
|
73
73
|
- `text` (string): The natural language query text
|
|
74
|
-
- `sourceIndexes` (
|
|
74
|
+
- `sourceIndexes` (SourceIndex[], optional): Array of source indexes to search within. Available values: `SourceIndex.TAKO` or `SourceIndex.WEB`
|
|
75
75
|
|
|
76
76
|
Returns: `Promise<KnowledgeSearchResponse>`
|
|
77
77
|
|
|
78
|
+
The response contains an array of knowledge cards in the `outputs.knowledge_cards` field. Each knowledge card contains:
|
|
79
|
+
- `card_id`: Unique identifier for the card
|
|
80
|
+
- `title`: Card title
|
|
81
|
+
- `description`: Detailed description of the card's content
|
|
82
|
+
- `webpage_url`: URL of a webpage hosting the interactive knowledge card
|
|
83
|
+
- `image_url`: URL of a static image of the knowledge card
|
|
84
|
+
- `embed_url`: URL of an embeddable iframe of the knowledge card
|
|
85
|
+
- `sources`: The sources of the knowledge card
|
|
86
|
+
- `methodologies`: The methodologies of the knowledge card
|
|
87
|
+
|
|
88
|
+
For detailed API response types and subfield structure, see the [Tako API Documentation](https://docs.trytako.com/api-reference/search).
|
|
89
|
+
|
|
78
90
|
## Error Handling
|
|
79
91
|
|
|
80
|
-
The SDK throws typed
|
|
92
|
+
The SDK throws typed exceptions for different errors:
|
|
81
93
|
|
|
82
94
|
```typescript
|
|
95
|
+
import {
|
|
96
|
+
TakoException,
|
|
97
|
+
TakoUnauthorizedException,
|
|
98
|
+
TakoRateLimitException,
|
|
99
|
+
} from 'tako-sdk';
|
|
100
|
+
|
|
83
101
|
try {
|
|
84
102
|
const results = await tako.knowledgeSearch(query);
|
|
85
|
-
} catch (error
|
|
86
|
-
if (error
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (error instanceof TakoUnauthorizedException) {
|
|
87
105
|
console.error('Authentication error:', error.message);
|
|
88
|
-
} else if (error
|
|
106
|
+
} else if (error instanceof TakoRateLimitException) {
|
|
89
107
|
console.error('Rate limit exceeded:', error.message);
|
|
108
|
+
} else if (error instanceof TakoNotFoundException) {
|
|
109
|
+
console.error('Resource not found:', error.message);
|
|
110
|
+
} else if (error instanceof TakoException) {
|
|
111
|
+
console.error('API error:', error.message);
|
|
90
112
|
} else {
|
|
91
113
|
console.error('Unexpected error:', error);
|
|
92
114
|
}
|
|
93
115
|
}
|
|
94
116
|
```
|
|
117
|
+
|
|
118
|
+
Each exception includes:
|
|
119
|
+
- `status`: HTTP status code
|
|
120
|
+
- `message`: Error message
|
|
121
|
+
- `details`: Additional error details from the API (if available)
|
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
SourceIndex: () => SourceIndex,
|
|
24
|
+
TakoException: () => TakoException,
|
|
25
|
+
TakoRateLimitException: () => TakoRateLimitException,
|
|
26
|
+
TakoUnauthorizedException: () => TakoUnauthorizedException,
|
|
24
27
|
createTakoClient: () => createTakoClient
|
|
25
28
|
});
|
|
26
29
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -31,6 +34,26 @@ var SourceIndex = /* @__PURE__ */ ((SourceIndex2) => {
|
|
|
31
34
|
SourceIndex2["WEB"] = "web";
|
|
32
35
|
return SourceIndex2;
|
|
33
36
|
})(SourceIndex || {});
|
|
37
|
+
var TakoException = class extends Error {
|
|
38
|
+
constructor(status, message, details) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.status = status;
|
|
41
|
+
this.details = details;
|
|
42
|
+
this.name = "TakoException";
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var TakoUnauthorizedException = class extends TakoException {
|
|
46
|
+
constructor(message = "Unauthorized", details) {
|
|
47
|
+
super(401, message, details);
|
|
48
|
+
this.name = "TakoUnauthorizedException";
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var TakoRateLimitException = class extends TakoException {
|
|
52
|
+
constructor(message = "Rate limit exceeded", details) {
|
|
53
|
+
super(429, message, details);
|
|
54
|
+
this.name = "TakoRateLimitException";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
34
57
|
|
|
35
58
|
// src/client.ts
|
|
36
59
|
var TakoClient = class {
|
|
@@ -43,7 +66,8 @@ var TakoClient = class {
|
|
|
43
66
|
throw new Error("API key is required");
|
|
44
67
|
}
|
|
45
68
|
this.apiKey = config.apiKey;
|
|
46
|
-
this.baseUrl = config.baseUrl || "https://trytako.com
|
|
69
|
+
this.baseUrl = config.baseUrl || "https://trytako.com";
|
|
70
|
+
this.pathPrefix = config.pathPrefix || "/api/v1";
|
|
47
71
|
}
|
|
48
72
|
/**
|
|
49
73
|
* Make a request to the Tako API
|
|
@@ -53,9 +77,9 @@ var TakoClient = class {
|
|
|
53
77
|
* @returns Response data
|
|
54
78
|
*/
|
|
55
79
|
async request(path, method, body) {
|
|
56
|
-
const url = `${this.baseUrl}${path}`;
|
|
80
|
+
const url = `${this.baseUrl}${this.pathPrefix}${path}`;
|
|
57
81
|
const headers = {
|
|
58
|
-
|
|
82
|
+
"X-API-Key": this.apiKey,
|
|
59
83
|
"Content-Type": "application/json"
|
|
60
84
|
};
|
|
61
85
|
const options = {
|
|
@@ -66,11 +90,17 @@ var TakoClient = class {
|
|
|
66
90
|
const response = await fetch(url, options);
|
|
67
91
|
if (!response.ok) {
|
|
68
92
|
const errorData = await response.json();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
93
|
+
const message = errorData.message || response.statusText;
|
|
94
|
+
switch (response.status) {
|
|
95
|
+
case 401:
|
|
96
|
+
throw new TakoUnauthorizedException(message, errorData);
|
|
97
|
+
case 429:
|
|
98
|
+
throw new TakoRateLimitException(message, errorData);
|
|
99
|
+
case 404:
|
|
100
|
+
return null;
|
|
101
|
+
default:
|
|
102
|
+
throw new TakoException(response.status, message, errorData);
|
|
103
|
+
}
|
|
74
104
|
}
|
|
75
105
|
return await response.json();
|
|
76
106
|
}
|
|
@@ -87,10 +117,11 @@ var TakoClient = class {
|
|
|
87
117
|
const requestBody = {
|
|
88
118
|
inputs: {
|
|
89
119
|
text,
|
|
90
|
-
...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : {}
|
|
120
|
+
...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : { source_indexes: ["tako" /* TAKO */] }
|
|
91
121
|
}
|
|
92
122
|
};
|
|
93
|
-
|
|
123
|
+
const response = await this.request("/knowledge_search", "POST", requestBody);
|
|
124
|
+
return response || { outputs: { knowledge_cards: [] } };
|
|
94
125
|
}
|
|
95
126
|
};
|
|
96
127
|
|
|
@@ -101,5 +132,8 @@ function createTakoClient(apiKey, baseUrl) {
|
|
|
101
132
|
// Annotate the CommonJS export names for ESM import in node:
|
|
102
133
|
0 && (module.exports = {
|
|
103
134
|
SourceIndex,
|
|
135
|
+
TakoException,
|
|
136
|
+
TakoRateLimitException,
|
|
137
|
+
TakoUnauthorizedException,
|
|
104
138
|
createTakoClient
|
|
105
139
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -8,6 +8,7 @@ declare enum SourceIndex {
|
|
|
8
8
|
interface TakoConfig {
|
|
9
9
|
apiKey: string;
|
|
10
10
|
baseUrl?: string;
|
|
11
|
+
pathPrefix?: string;
|
|
11
12
|
}
|
|
12
13
|
interface KnowledgeSearchInput {
|
|
13
14
|
text: string;
|
|
@@ -46,6 +47,17 @@ interface TakoError {
|
|
|
46
47
|
message: string;
|
|
47
48
|
details?: any;
|
|
48
49
|
}
|
|
50
|
+
declare class TakoException extends Error {
|
|
51
|
+
status: number;
|
|
52
|
+
details?: any | undefined;
|
|
53
|
+
constructor(status: number, message: string, details?: any | undefined);
|
|
54
|
+
}
|
|
55
|
+
declare class TakoUnauthorizedException extends TakoException {
|
|
56
|
+
constructor(message?: string, details?: any);
|
|
57
|
+
}
|
|
58
|
+
declare class TakoRateLimitException extends TakoException {
|
|
59
|
+
constructor(message?: string, details?: any);
|
|
60
|
+
}
|
|
49
61
|
|
|
50
62
|
/**
|
|
51
63
|
* Tako API Client
|
|
@@ -53,6 +65,7 @@ interface TakoError {
|
|
|
53
65
|
declare class TakoClient {
|
|
54
66
|
private apiKey;
|
|
55
67
|
private baseUrl;
|
|
68
|
+
private pathPrefix;
|
|
56
69
|
/**
|
|
57
70
|
* Create a new Tako API client
|
|
58
71
|
* @param config Configuration for the Tako API client
|
|
@@ -83,4 +96,4 @@ declare class TakoClient {
|
|
|
83
96
|
*/
|
|
84
97
|
declare function createTakoClient(apiKey: string, baseUrl?: string): TakoClient;
|
|
85
98
|
|
|
86
|
-
export { KnowledgeCard, KnowledgeSearchInput, KnowledgeSearchRequest, KnowledgeSearchResponse, Methodology, Source, SourceIndex, TakoConfig, TakoError, createTakoClient };
|
|
99
|
+
export { KnowledgeCard, KnowledgeSearchInput, KnowledgeSearchRequest, KnowledgeSearchResponse, Methodology, Source, SourceIndex, TakoConfig, TakoError, TakoException, TakoRateLimitException, TakoUnauthorizedException, createTakoClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare enum SourceIndex {
|
|
|
8
8
|
interface TakoConfig {
|
|
9
9
|
apiKey: string;
|
|
10
10
|
baseUrl?: string;
|
|
11
|
+
pathPrefix?: string;
|
|
11
12
|
}
|
|
12
13
|
interface KnowledgeSearchInput {
|
|
13
14
|
text: string;
|
|
@@ -46,6 +47,17 @@ interface TakoError {
|
|
|
46
47
|
message: string;
|
|
47
48
|
details?: any;
|
|
48
49
|
}
|
|
50
|
+
declare class TakoException extends Error {
|
|
51
|
+
status: number;
|
|
52
|
+
details?: any | undefined;
|
|
53
|
+
constructor(status: number, message: string, details?: any | undefined);
|
|
54
|
+
}
|
|
55
|
+
declare class TakoUnauthorizedException extends TakoException {
|
|
56
|
+
constructor(message?: string, details?: any);
|
|
57
|
+
}
|
|
58
|
+
declare class TakoRateLimitException extends TakoException {
|
|
59
|
+
constructor(message?: string, details?: any);
|
|
60
|
+
}
|
|
49
61
|
|
|
50
62
|
/**
|
|
51
63
|
* Tako API Client
|
|
@@ -53,6 +65,7 @@ interface TakoError {
|
|
|
53
65
|
declare class TakoClient {
|
|
54
66
|
private apiKey;
|
|
55
67
|
private baseUrl;
|
|
68
|
+
private pathPrefix;
|
|
56
69
|
/**
|
|
57
70
|
* Create a new Tako API client
|
|
58
71
|
* @param config Configuration for the Tako API client
|
|
@@ -83,4 +96,4 @@ declare class TakoClient {
|
|
|
83
96
|
*/
|
|
84
97
|
declare function createTakoClient(apiKey: string, baseUrl?: string): TakoClient;
|
|
85
98
|
|
|
86
|
-
export { KnowledgeCard, KnowledgeSearchInput, KnowledgeSearchRequest, KnowledgeSearchResponse, Methodology, Source, SourceIndex, TakoConfig, TakoError, createTakoClient };
|
|
99
|
+
export { KnowledgeCard, KnowledgeSearchInput, KnowledgeSearchRequest, KnowledgeSearchResponse, Methodology, Source, SourceIndex, TakoConfig, TakoError, TakoException, TakoRateLimitException, TakoUnauthorizedException, createTakoClient };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,26 @@ var SourceIndex = /* @__PURE__ */ ((SourceIndex2) => {
|
|
|
4
4
|
SourceIndex2["WEB"] = "web";
|
|
5
5
|
return SourceIndex2;
|
|
6
6
|
})(SourceIndex || {});
|
|
7
|
+
var TakoException = class extends Error {
|
|
8
|
+
constructor(status, message, details) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.details = details;
|
|
12
|
+
this.name = "TakoException";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var TakoUnauthorizedException = class extends TakoException {
|
|
16
|
+
constructor(message = "Unauthorized", details) {
|
|
17
|
+
super(401, message, details);
|
|
18
|
+
this.name = "TakoUnauthorizedException";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var TakoRateLimitException = class extends TakoException {
|
|
22
|
+
constructor(message = "Rate limit exceeded", details) {
|
|
23
|
+
super(429, message, details);
|
|
24
|
+
this.name = "TakoRateLimitException";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
7
27
|
|
|
8
28
|
// src/client.ts
|
|
9
29
|
var TakoClient = class {
|
|
@@ -16,7 +36,8 @@ var TakoClient = class {
|
|
|
16
36
|
throw new Error("API key is required");
|
|
17
37
|
}
|
|
18
38
|
this.apiKey = config.apiKey;
|
|
19
|
-
this.baseUrl = config.baseUrl || "https://trytako.com
|
|
39
|
+
this.baseUrl = config.baseUrl || "https://trytako.com";
|
|
40
|
+
this.pathPrefix = config.pathPrefix || "/api/v1";
|
|
20
41
|
}
|
|
21
42
|
/**
|
|
22
43
|
* Make a request to the Tako API
|
|
@@ -26,9 +47,9 @@ var TakoClient = class {
|
|
|
26
47
|
* @returns Response data
|
|
27
48
|
*/
|
|
28
49
|
async request(path, method, body) {
|
|
29
|
-
const url = `${this.baseUrl}${path}`;
|
|
50
|
+
const url = `${this.baseUrl}${this.pathPrefix}${path}`;
|
|
30
51
|
const headers = {
|
|
31
|
-
|
|
52
|
+
"X-API-Key": this.apiKey,
|
|
32
53
|
"Content-Type": "application/json"
|
|
33
54
|
};
|
|
34
55
|
const options = {
|
|
@@ -39,11 +60,17 @@ var TakoClient = class {
|
|
|
39
60
|
const response = await fetch(url, options);
|
|
40
61
|
if (!response.ok) {
|
|
41
62
|
const errorData = await response.json();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
const message = errorData.message || response.statusText;
|
|
64
|
+
switch (response.status) {
|
|
65
|
+
case 401:
|
|
66
|
+
throw new TakoUnauthorizedException(message, errorData);
|
|
67
|
+
case 429:
|
|
68
|
+
throw new TakoRateLimitException(message, errorData);
|
|
69
|
+
case 404:
|
|
70
|
+
return null;
|
|
71
|
+
default:
|
|
72
|
+
throw new TakoException(response.status, message, errorData);
|
|
73
|
+
}
|
|
47
74
|
}
|
|
48
75
|
return await response.json();
|
|
49
76
|
}
|
|
@@ -60,10 +87,11 @@ var TakoClient = class {
|
|
|
60
87
|
const requestBody = {
|
|
61
88
|
inputs: {
|
|
62
89
|
text,
|
|
63
|
-
...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : {}
|
|
90
|
+
...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : { source_indexes: ["tako" /* TAKO */] }
|
|
64
91
|
}
|
|
65
92
|
};
|
|
66
|
-
|
|
93
|
+
const response = await this.request("/knowledge_search", "POST", requestBody);
|
|
94
|
+
return response || { outputs: { knowledge_cards: [] } };
|
|
67
95
|
}
|
|
68
96
|
};
|
|
69
97
|
|
|
@@ -73,5 +101,8 @@ function createTakoClient(apiKey, baseUrl) {
|
|
|
73
101
|
}
|
|
74
102
|
export {
|
|
75
103
|
SourceIndex,
|
|
104
|
+
TakoException,
|
|
105
|
+
TakoRateLimitException,
|
|
106
|
+
TakoUnauthorizedException,
|
|
76
107
|
createTakoClient
|
|
77
108
|
};
|