tako-sdk 0.1.4 → 1.0.1
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/LICENSE +21 -0
- package/README.md +92 -77
- package/dist/index.cjs +3349 -92
- package/dist/index.d.cts +3391 -71
- package/dist/index.d.ts +3391 -71
- package/dist/index.js +3025 -84
- package/package.json +40 -24
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tako
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,121 +1,136 @@
|
|
|
1
|
-
# Tako SDK
|
|
1
|
+
# Tako TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Tako SDK provides typed access to the [Tako](https://tako.com) API from Node.js (≥ 18), the browser, and edge runtimes. It ships fully typed request/response models, a `Tako` client, and a live agent-streaming API. Generated from Tako's OpenAPI spec with `openapi-generator` (`typescript-fetch`) — zero runtime dependencies.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install tako-sdk
|
|
9
|
-
# or
|
|
10
|
-
yarn add tako-sdk
|
|
11
|
-
# or
|
|
12
|
-
pnpm add tako-sdk
|
|
13
9
|
```
|
|
14
10
|
|
|
15
|
-
##
|
|
11
|
+
## Authentication
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
import { createTakoClient } from 'tako-sdk';
|
|
13
|
+
Create an API key from your Tako account and keep it out of source control:
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
```typescript
|
|
16
|
+
import { Tako } from "tako-sdk";
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
const results = await tako.knowledgeSearch('AMD vs. Nvidia headcount since 2015');
|
|
25
|
-
console.log(results.outputs.knowledge_cards);
|
|
18
|
+
const tako = new Tako({ apiKey: process.env.TAKO_API_KEY! });
|
|
26
19
|
```
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
## Usage
|
|
29
22
|
|
|
30
23
|
```typescript
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export async function POST(request: Request) {
|
|
36
|
-
const { query, sourceIndexes } = await request.json();
|
|
37
|
-
const tako = createTakoClient(process.env.TAKO_API_KEY!);
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
const results = await tako.knowledgeSearch(query, sourceIndexes);
|
|
41
|
-
return NextResponse.json(results);
|
|
42
|
-
} catch (error: any) {
|
|
43
|
-
return NextResponse.json(
|
|
44
|
-
{ error: error.message || 'An error occurred' },
|
|
45
|
-
{ status: error.status || 500 }
|
|
46
|
-
);
|
|
47
|
-
}
|
|
24
|
+
const results = await tako.search({ query: "S&P 500 performance this year" });
|
|
25
|
+
console.log(results.request_id);
|
|
26
|
+
for (const card of results.cards ?? []) {
|
|
27
|
+
console.log(card.title, card.webpage_url);
|
|
48
28
|
}
|
|
49
29
|
```
|
|
50
30
|
|
|
51
|
-
|
|
31
|
+
### Operations
|
|
52
32
|
|
|
53
|
-
|
|
33
|
+
| Method | Description |
|
|
34
|
+
| -------------------------- | ----------------------------------------------------------------------- |
|
|
35
|
+
| `tako.search(request)` | Search the Tako knowledge base; returns matching cards and web results. |
|
|
36
|
+
| `tako.answer(request)` | Get a written answer with supporting cards. |
|
|
37
|
+
| `tako.createCard(request)` | Build a visualization card from component configurations. |
|
|
38
|
+
| `tako.contents(request)` | Fetch downloadable content (e.g. a CSV) for a card or web URL. |
|
|
54
39
|
|
|
55
|
-
|
|
40
|
+
Fetch the underlying data for a card returned by a search (guard for cards with no exportable `content`):
|
|
56
41
|
|
|
57
42
|
```typescript
|
|
58
|
-
const
|
|
43
|
+
const results = await tako.search({ query: "US Oil Prices" });
|
|
44
|
+
const card = (results.cards ?? []).find((c) => c.webpage_url && c.content);
|
|
45
|
+
if (card?.webpage_url) {
|
|
46
|
+
const contents = await tako.contents({ url: card.webpage_url });
|
|
47
|
+
for (const item of contents.contents ?? []) console.log(item.format, item.url); // url is populated only in URL delivery mode (url?: string | null)
|
|
48
|
+
}
|
|
59
49
|
```
|
|
60
50
|
|
|
61
|
-
|
|
62
|
-
- `apiKey` (string): Your Tako API key
|
|
51
|
+
> **Async only.** JavaScript is uniformly promise-based, so there is a single `Tako` client (unlike the Python SDK's separate `Tako`/`AsyncTako`). Every operation returns a `Promise`.
|
|
63
52
|
|
|
64
|
-
|
|
53
|
+
## Streaming
|
|
65
54
|
|
|
66
|
-
|
|
55
|
+
Stream an agent run live over Server-Sent Events. The stream yields typed `AgentStreamEnvelope` objects and auto-reconnects (resuming via the last `seq`) on transient drops. Always close it (or use `try`/`finally`):
|
|
67
56
|
|
|
68
57
|
```typescript
|
|
69
|
-
const
|
|
58
|
+
const stream = tako.agent.stream({ query: "Compare Nvidia and AMD revenue" });
|
|
59
|
+
try {
|
|
60
|
+
for await (const event of stream) {
|
|
61
|
+
console.log(event.seq, event.block.kind);
|
|
62
|
+
}
|
|
63
|
+
// The stream ends at stream_done. If it ended without a terminal result
|
|
64
|
+
// (and produced at least one event, so run_id is known), poll for status:
|
|
65
|
+
if (stream.result === null && stream.run_id !== null) {
|
|
66
|
+
const run = await tako.agent.get(stream.run_id);
|
|
67
|
+
console.log(run.status);
|
|
68
|
+
}
|
|
69
|
+
} finally {
|
|
70
|
+
await stream.close();
|
|
71
|
+
}
|
|
70
72
|
```
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
- `text` (string): The natural language query text
|
|
74
|
-
- `sourceIndexes` (SourceIndex[], optional): Array of source indexes to search within. Available values: `SourceIndex.TAKO` or `SourceIndex.WEB`
|
|
74
|
+
Tune reconnect behavior with the second argument — `maxRetries` (reconnect attempts after a transient drop, default 5) and `readTimeoutMs` (idle read before a connection is treated as dropped, default 120000):
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
```typescript
|
|
77
|
+
const stream = tako.agent.stream({ query: "..." }, { maxRetries: 5, readTimeoutMs: 120_000 });
|
|
78
|
+
```
|
|
77
79
|
|
|
78
|
-
|
|
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
|
|
80
|
+
Non-streaming dispatch/poll is also available: `tako.agent.run(request)` returns an `AgentRun` (202 dispatch); `tako.agent.get(runId)` polls for status.
|
|
87
81
|
|
|
88
|
-
|
|
82
|
+
## Configuration
|
|
89
83
|
|
|
90
|
-
|
|
84
|
+
By default the client targets the Tako production API (`https://tako.com/api`). Override the base path for staging or self-host:
|
|
91
85
|
|
|
92
|
-
|
|
86
|
+
```typescript
|
|
87
|
+
const tako = new Tako({ apiKey: "...", basePath: "https://staging.tako.com/api" });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Error handling
|
|
91
|
+
|
|
92
|
+
Non-2xx responses throw a `ResponseError` carrying the raw `Response`:
|
|
93
93
|
|
|
94
94
|
```typescript
|
|
95
|
-
import {
|
|
96
|
-
TakoException,
|
|
97
|
-
TakoUnauthorizedException,
|
|
98
|
-
TakoRateLimitException,
|
|
99
|
-
} from 'tako-sdk';
|
|
95
|
+
import { ResponseError } from "tako-sdk";
|
|
100
96
|
|
|
101
97
|
try {
|
|
102
|
-
|
|
103
|
-
} catch (
|
|
104
|
-
if (
|
|
105
|
-
console.error(
|
|
106
|
-
} else if (error instanceof TakoRateLimitException) {
|
|
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);
|
|
98
|
+
await tako.search({ query: "..." });
|
|
99
|
+
} catch (err) {
|
|
100
|
+
if (err instanceof ResponseError) {
|
|
101
|
+
console.error(err.response.status, await err.response.text());
|
|
112
102
|
} else {
|
|
113
|
-
|
|
103
|
+
throw err;
|
|
114
104
|
}
|
|
115
105
|
}
|
|
116
106
|
```
|
|
117
107
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
108
|
+
## TypeScript
|
|
109
|
+
|
|
110
|
+
All request/response models are exported as types:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import type {
|
|
114
|
+
SearchRequest,
|
|
115
|
+
SearchResponse, // .cards is Array<TakoCard>
|
|
116
|
+
AnswerResponse, // .cards is Array<TakoCard>
|
|
117
|
+
ContentsRequest,
|
|
118
|
+
ContentsResponse,
|
|
119
|
+
CreateCardRequest,
|
|
120
|
+
TakoCard, // card type returned by search() and answer()
|
|
121
|
+
KnowledgeCard, // card type returned by createCard()
|
|
122
|
+
AgentRunRequest,
|
|
123
|
+
AgentStreamEnvelope,
|
|
124
|
+
} from "tako-sdk";
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`search` and `answer` return `TakoCard[]` via `SearchResponse.cards` / `AnswerResponse.cards`. `createCard` returns a `KnowledgeCard`.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT
|
|
132
|
+
|
|
133
|
+
## Links
|
|
134
|
+
|
|
135
|
+
- [Tako documentation](https://docs.tako.com)
|
|
136
|
+
- [GitHub repository](https://github.com/TakoData/tako-sdk-ts)
|