@treasuredata/tdx 0.1.4 → 0.1.5
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 +330 -145
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/client/cdp-client.js +1 -1
- package/dist/client/http-client.js +1 -1
- package/dist/client/llm-client.js +1 -1
- package/dist/client/rate-limiter.js +1 -1
- package/dist/client/td-client.js +1 -1
- package/dist/client/trino-client.js +1 -1
- package/dist/client/workflow-client.js +1 -1
- package/dist/commands/activations.js +1 -1
- package/dist/commands/api-command.js +1 -1
- package/dist/commands/chat-command.d.ts +2 -2
- package/dist/commands/chat-command.d.ts.map +1 -1
- package/dist/commands/chat-command.js +1 -1
- package/dist/commands/chat-command.js.map +1 -1
- package/dist/commands/command.js +1 -1
- package/dist/commands/context-command.d.ts +14 -0
- package/dist/commands/context-command.d.ts.map +1 -0
- package/dist/commands/context-command.js +1 -0
- package/dist/commands/context-command.js.map +1 -0
- package/dist/commands/databases.js +1 -1
- package/dist/commands/describe.js +1 -1
- package/dist/commands/llm-command.js +1 -1
- package/dist/commands/profiles-command.d.ts +16 -0
- package/dist/commands/profiles-command.d.ts.map +1 -0
- package/dist/commands/profiles-command.js +1 -0
- package/dist/commands/profiles-command.js.map +1 -0
- package/dist/commands/query-command.js +1 -1
- package/dist/commands/segment-command.js +1 -1
- package/dist/commands/segments.js +1 -1
- package/dist/commands/show.js +1 -1
- package/dist/commands/tables.js +1 -1
- package/dist/commands/use-command.d.ts +18 -0
- package/dist/commands/use-command.d.ts.map +1 -0
- package/dist/commands/use-command.js +1 -0
- package/dist/commands/use-command.js.map +1 -0
- package/dist/commands/workflow-command.js +1 -1
- package/dist/core/auth.js +1 -1
- package/dist/core/config.d.ts +15 -4
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +1 -1
- package/dist/core/config.js.map +1 -1
- package/dist/core/global-context.d.ts +48 -0
- package/dist/core/global-context.d.ts.map +1 -0
- package/dist/core/global-context.js +1 -0
- package/dist/core/global-context.js.map +1 -0
- package/dist/core/profile.d.ts +117 -0
- package/dist/core/profile.d.ts.map +1 -0
- package/dist/core/profile.js +1 -0
- package/dist/core/profile.js.map +1 -0
- package/dist/core/project-config.d.ts +54 -0
- package/dist/core/project-config.d.ts.map +1 -0
- package/dist/core/project-config.js +1 -0
- package/dist/core/project-config.js.map +1 -0
- package/dist/core/session.d.ts +73 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +1 -0
- package/dist/core/session.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/sdk/api.js +1 -1
- package/dist/sdk/database.js +1 -1
- package/dist/sdk/errors.js +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/llm.js +1 -1
- package/dist/sdk/query.js +1 -1
- package/dist/sdk/segment.js +1 -1
- package/dist/sdk/table.js +1 -1
- package/dist/sdk/workflow.js +1 -1
- package/dist/types/endpoints.js +1 -1
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/utils/agent-ref-parser.js +1 -1
- package/dist/utils/chat-cache.js +1 -1
- package/dist/utils/colors.js +1 -1
- package/dist/utils/command-output.js +1 -1
- package/dist/utils/file-permissions.d.ts +41 -0
- package/dist/utils/file-permissions.d.ts.map +1 -0
- package/dist/utils/file-permissions.js +1 -0
- package/dist/utils/file-permissions.js.map +1 -0
- package/dist/utils/format-detector.js +1 -1
- package/dist/utils/formatters.js +1 -1
- package/dist/utils/option-validation.js +1 -1
- package/dist/utils/process.d.ts +18 -0
- package/dist/utils/process.d.ts.map +1 -0
- package/dist/utils/process.js +1 -0
- package/dist/utils/process.js.map +1 -0
- package/dist/utils/segment-ref-parser.js +1 -1
- package/dist/utils/spinner.js +1 -1
- package/dist/utils/sql-parser.js +1 -1
- package/dist/utils/sse-parser.js +1 -1
- package/dist/utils/string-utils.js +1 -1
- package/dist/utils/table-ref-parser.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,42 +11,6 @@ A modern, AI-native command-line interface for Treasure Data, optimized for both
|
|
|
11
11
|
- 🚀 **Modern Distribution**: Install via `npx` or `npm` without prior setup
|
|
12
12
|
- ⚡ **Fast & Efficient**: Built with TypeScript on Node.js 24+
|
|
13
13
|
|
|
14
|
-
## Architecture
|
|
15
|
-
|
|
16
|
-
The `tdx` project is designed with a layered architecture that separates the CLI interface from the core SDK, allowing the TypeScript SDK to be used in multiple environments:
|
|
17
|
-
|
|
18
|
-
```mermaid
|
|
19
|
-
graph TD
|
|
20
|
-
subgraph "Client Environments"
|
|
21
|
-
NodeJS[Node.JS/CLI<br/>tdx commands]
|
|
22
|
-
Browser[Web Browser<br/>Client-side]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
subgraph "TDX SDK - TypeScript"
|
|
26
|
-
SDK[TDX SDK<br/>TypeScript/JavaScript API]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
subgraph "Treasure Data APIs"
|
|
30
|
-
TD[TD REST API<br/>Databases, Tables, Jobs]
|
|
31
|
-
Trino[Trino Streaming API<br/>Query Execution]
|
|
32
|
-
CDP[CDP API<br/>Segments, Activations]
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
NodeJS --> SDK
|
|
36
|
-
Browser --> SDK
|
|
37
|
-
|
|
38
|
-
SDK -->|HTTPS| TD
|
|
39
|
-
SDK -->|HTTPS| Trino
|
|
40
|
-
SDK -->|HTTPS| CDP
|
|
41
|
-
|
|
42
|
-
style NodeJS fill:#d4f1d4
|
|
43
|
-
style Browser fill:#ffd4d4
|
|
44
|
-
style SDK fill:#fff5cc
|
|
45
|
-
style TD fill:#e8e8f0
|
|
46
|
-
style CDP fill:#e8e8f0
|
|
47
|
-
style Trino fill:#e8e8f0
|
|
48
|
-
```
|
|
49
|
-
|
|
50
14
|
## Installation
|
|
51
15
|
|
|
52
16
|
```bash
|
|
@@ -115,8 +79,154 @@ tdx databases --format table
|
|
|
115
79
|
# Chat with AI (simplified - uses default agent)
|
|
116
80
|
tdx chat "Show me customer revenue trends"
|
|
117
81
|
|
|
118
|
-
# Continue previous chat
|
|
119
|
-
tdx chat
|
|
82
|
+
# Continue previous chat (default behavior)
|
|
83
|
+
tdx chat "What about last month?"
|
|
84
|
+
|
|
85
|
+
# Start a new chat session
|
|
86
|
+
tdx chat --new "Tell me about data pipelines"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Context Management
|
|
90
|
+
|
|
91
|
+
`tdx` provides a unified context system to reduce repetitive flags across commands. Context is resolved from multiple sources with the following priority:
|
|
92
|
+
|
|
93
|
+
1. **CLI flags** (highest priority) - `--database`, `--site`, etc.
|
|
94
|
+
2. **Session context** - Shell-scoped overrides set with `tdx use`
|
|
95
|
+
3. **Project config** - Per-project defaults in `tdx.json`
|
|
96
|
+
4. **Profile config** - Account-specific settings in `~/.config/tdx/profiles/<name>/tdx.json`
|
|
97
|
+
5. **Global config** - Fallback defaults in `~/.config/tdx/tdx.json`
|
|
98
|
+
|
|
99
|
+
### Profiles
|
|
100
|
+
|
|
101
|
+
Profiles store long-lived account configurations for easy switching between environments:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# List all profiles with details
|
|
105
|
+
tdx profiles
|
|
106
|
+
|
|
107
|
+
# Switch active profile
|
|
108
|
+
tdx use profile production
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Profile Structure:**
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
~/.config/tdx/profiles/
|
|
115
|
+
├── production/
|
|
116
|
+
│ ├── tdx.json # Configuration (site, database, llm_project, etc.)
|
|
117
|
+
│ └── .env # Credentials (TD_API_KEY)
|
|
118
|
+
└── dev/
|
|
119
|
+
├── tdx.json # Development environment config
|
|
120
|
+
└── .env # Development credentials
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Example Production Profile** (`~/.config/tdx/profiles/production/tdx.json`):
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"description": "Production environment for US region",
|
|
127
|
+
"site": "us01",
|
|
128
|
+
"database": "analytics",
|
|
129
|
+
"llm_project": "DataAnalytics"
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Example Development Profile** (`~/.config/tdx/profiles/dev/tdx.json`):
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"description": "Development and testing environment",
|
|
137
|
+
"site": "jp01",
|
|
138
|
+
"database": "dev_db"
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Note:** The `description` field is optional but recommended for documenting what each profile is for.
|
|
143
|
+
|
|
144
|
+
### Session Context
|
|
145
|
+
|
|
146
|
+
Set temporary overrides for the current shell session:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Set session database
|
|
150
|
+
tdx use database mydb
|
|
151
|
+
|
|
152
|
+
# Set session LLM project
|
|
153
|
+
tdx use llm_project Analytics
|
|
154
|
+
|
|
155
|
+
# Clear session context
|
|
156
|
+
tdx use --clear
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**How Session Scope Works:**
|
|
160
|
+
|
|
161
|
+
Sessions are automatically scoped to your current shell window. Each terminal window/tab has a unique process ID (PID), and `tdx` uses the parent process ID (PPID) to identify and isolate sessions. This means:
|
|
162
|
+
|
|
163
|
+
- **Automatic isolation**: Each terminal window maintains its own independent session context
|
|
164
|
+
- **No manual setup**: Sessions are created automatically when you run `tdx use` commands
|
|
165
|
+
- **Persistent within shell**: Context persists across multiple commands in the same terminal
|
|
166
|
+
- **Automatic cleanup**: Sessions expire after 24 hours or when the shell is closed
|
|
167
|
+
|
|
168
|
+
**Example:**
|
|
169
|
+
```bash
|
|
170
|
+
# Terminal Window 1
|
|
171
|
+
tdx use database analytics
|
|
172
|
+
tdx tables # Uses database: analytics
|
|
173
|
+
|
|
174
|
+
# Terminal Window 2 (different PID)
|
|
175
|
+
tdx tables # Uses default database (separate session)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Session context persists until the shell is closed or explicitly cleared with `tdx use --clear`.
|
|
179
|
+
|
|
180
|
+
**Note:** For advanced session sharing across multiple processes or shells, see [Session ID Option](#session-id-option) in the Advanced Options section.
|
|
181
|
+
|
|
182
|
+
### Project Config
|
|
183
|
+
|
|
184
|
+
Store per-project defaults in `tdx.json` at your project root:
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"database": "customer_analytics",
|
|
189
|
+
"parent_segment": "active_users",
|
|
190
|
+
"llm_project": "CustomerInsights"
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Available Configuration Parameters:**
|
|
195
|
+
|
|
196
|
+
| Parameter | Type | Description | Example |
|
|
197
|
+
|-----------|------|-------------|---------|
|
|
198
|
+
| `description` | string | Optional description of the configuration | `"Production environment"` |
|
|
199
|
+
| `site` | string | TD site/region (us01, jp01, eu01, ap02) | `"us01"` |
|
|
200
|
+
| `database` | string | Default database for queries and table commands | `"analytics"` |
|
|
201
|
+
| `parent_segment` | string | Default parent segment for CDP commands | `"active_users"` |
|
|
202
|
+
| `llm_project` | string | Default LLM project for agent commands | `"DataAnalytics"` |
|
|
203
|
+
|
|
204
|
+
**Security Note:** Project configs should never contain API keys since they may be committed to version control. Use profiles or global `.env` files for credentials.
|
|
205
|
+
|
|
206
|
+
### View Context
|
|
207
|
+
|
|
208
|
+
See the currently resolved context and where each value comes from:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
# Show current context
|
|
212
|
+
tdx context
|
|
213
|
+
|
|
214
|
+
# Show context with sources (debugging)
|
|
215
|
+
tdx context --debug
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Example output:
|
|
219
|
+
```
|
|
220
|
+
[context]
|
|
221
|
+
site: us01 (global: ~/.config/tdx/tdx.json)
|
|
222
|
+
database: analytics (session)
|
|
223
|
+
llm_project: DataAnalytics (profile: production)
|
|
224
|
+
profile: production (active)
|
|
225
|
+
|
|
226
|
+
Configuration Files:
|
|
227
|
+
Session: /Users/user/.config/tdx/sessions/12345.json ✓
|
|
228
|
+
Profile: /Users/user/.config/tdx/profiles/production/tdx.json ✓
|
|
229
|
+
Global: /Users/user/.config/tdx/tdx.json ✓
|
|
120
230
|
```
|
|
121
231
|
|
|
122
232
|
## Available Commands
|
|
@@ -181,20 +291,23 @@ Simplified top-level command for chatting with LLM agents.
|
|
|
181
291
|
|
|
182
292
|
| Command | Description | Example |
|
|
183
293
|
|---------|-------------|---------|
|
|
184
|
-
| `chat <message>` | Chat
|
|
294
|
+
| `chat <message>` | Chat (continues last session by default) | `tdx chat "Analyze my data"` |
|
|
185
295
|
| `chat <message> --agent <ref>` | Chat with specific agent | `tdx chat "Hello" --agent "Project/Agent"` |
|
|
186
296
|
| `chat <message> --model <name>` | Chat using specific model | `tdx chat "Help" --model "gpt-5"` |
|
|
187
297
|
| `chat <message> --temperature <n>` | Set temperature (0.0-2.0, default: 0.7) | `tdx chat "Be creative" --temperature 1.2` |
|
|
188
|
-
| `chat <message> --
|
|
298
|
+
| `chat <message> --new` | Start a new chat session | `tdx chat --new "Fresh conversation"` |
|
|
189
299
|
|
|
190
300
|
**Examples**:
|
|
191
301
|
```bash
|
|
192
302
|
# Simple chat (uses default agent with claude-4.5-sonnet)
|
|
193
303
|
tdx chat "Show me the top customers by revenue"
|
|
194
304
|
|
|
195
|
-
# Continue previous conversation
|
|
196
|
-
tdx chat
|
|
197
|
-
tdx chat
|
|
305
|
+
# Continue previous conversation (default behavior)
|
|
306
|
+
tdx chat "What about last quarter?"
|
|
307
|
+
tdx chat "And the quarter before that?"
|
|
308
|
+
|
|
309
|
+
# Start a new conversation
|
|
310
|
+
tdx chat --new "Tell me about data modeling best practices"
|
|
198
311
|
|
|
199
312
|
# Use specific agent
|
|
200
313
|
tdx chat "Analyze churn" --agent "MyProject/Data Analyst"
|
|
@@ -213,113 +326,13 @@ tdx chat "Hello" --verbose
|
|
|
213
326
|
```
|
|
214
327
|
|
|
215
328
|
**How it works**:
|
|
216
|
-
- **Default behavior**:
|
|
329
|
+
- **Default behavior**: Continues last chat session automatically (or creates new if none exists)
|
|
217
330
|
- **Session persistence**: Last chat ID saved to `.cache/tdx/last_chat_id`
|
|
218
|
-
- **--
|
|
331
|
+
- **--new flag**: Starts a fresh chat session
|
|
219
332
|
- **--agent**: Use specific agent (requires `"project/agent"` format)
|
|
220
333
|
- **--model**: Reuses or creates agent per model (e.g., `tdx_gpt-5`)
|
|
221
334
|
- **--temperature**: Controls randomness (0.7 default, lower=focused, higher=creative)
|
|
222
335
|
|
|
223
|
-
### API Command (Raw HTTP Access)
|
|
224
|
-
|
|
225
|
-
Make authenticated HTTP requests to any Treasure Data API endpoint (similar to `gh api` from GitHub CLI).
|
|
226
|
-
|
|
227
|
-
**Usage:** `tdx api <endpoint> [options]`
|
|
228
|
-
|
|
229
|
-
| Option | Description | Example |
|
|
230
|
-
|--------|-------------|---------|
|
|
231
|
-
| `<endpoint>` | API endpoint path (must start with /) | `/v3/database/list` |
|
|
232
|
-
| `-X, --method <method>` | HTTP method (GET, POST, PUT, DELETE, PATCH) | `-X POST` |
|
|
233
|
-
| `--data <json>` | Request body as JSON string | `--data '{"name":"mydb"}'` |
|
|
234
|
-
| `-f, --file <path>` | Read request body from file | `-f body.json` |
|
|
235
|
-
| `-H, --header <header>` | Custom header (repeatable) | `-H "X-Custom: value"` |
|
|
236
|
-
| `--type <api_type>` | API type (td, cdp, workflow, trino, llm) | `--type cdp` |
|
|
237
|
-
|
|
238
|
-
**Examples:**
|
|
239
|
-
|
|
240
|
-
```bash
|
|
241
|
-
# GET request to TD API (default)
|
|
242
|
-
tdx api /v3/database/list
|
|
243
|
-
|
|
244
|
-
# GET with path parameters
|
|
245
|
-
tdx api /v3/database/show/mydb
|
|
246
|
-
tdx api /v3/table/list/mydb
|
|
247
|
-
tdx api /v3/table/show/mydb/users
|
|
248
|
-
|
|
249
|
-
# POST with inline JSON body (submit query)
|
|
250
|
-
tdx api -X POST --data '{"query":"SELECT 1"}' /v3/job/issue/hive/mydb
|
|
251
|
-
|
|
252
|
-
# POST with data from file
|
|
253
|
-
tdx api -X POST -f query.json /v3/job/issue/hive/mydb
|
|
254
|
-
|
|
255
|
-
# Custom headers
|
|
256
|
-
tdx api -H "X-Custom: value" -H "X-Another: test" /v3/database/list
|
|
257
|
-
|
|
258
|
-
# CDP API endpoints (read-only)
|
|
259
|
-
tdx api /entities/parent_segments --type cdp
|
|
260
|
-
tdx api /audiences/12345/segments --type cdp
|
|
261
|
-
tdx api -X POST --data '{"format":"sql"}' /audiences/12345/segments/query --type cdp
|
|
262
|
-
|
|
263
|
-
# Workflow API endpoints (read-only)
|
|
264
|
-
tdx api /api/workflows --type workflow
|
|
265
|
-
tdx api /api/projects --type workflow
|
|
266
|
-
tdx api /api/attempts --type workflow
|
|
267
|
-
|
|
268
|
-
# Trino API endpoints (query submission - plain SQL, not JSON)
|
|
269
|
-
tdx api -X POST --data 'SELECT 1' /v1/statement --type trino
|
|
270
|
-
|
|
271
|
-
# LLM API endpoints (read-only)
|
|
272
|
-
tdx api /v1/agents --type llm
|
|
273
|
-
tdx api /v1/models --type llm
|
|
274
|
-
|
|
275
|
-
# Show HTTP response headers (with --verbose)
|
|
276
|
-
tdx api /v3/database/list --verbose
|
|
277
|
-
|
|
278
|
-
# Save output to file
|
|
279
|
-
tdx api /v3/database/list --output databases.json
|
|
280
|
-
|
|
281
|
-
# Combine --verbose with --output to see headers while saving
|
|
282
|
-
tdx api /v3/database/list --verbose --output databases.json
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
**API Types:**
|
|
286
|
-
|
|
287
|
-
| Type | Base URL Pattern | Description |
|
|
288
|
-
|------|-----------------|-------------|
|
|
289
|
-
| `td` | `api.treasuredata.com` | TD REST API (databases, tables, jobs) |
|
|
290
|
-
| `cdp` | `api-cdp.treasuredata.com` | CDP API (audiences, segments, activations) |
|
|
291
|
-
| `workflow` | `api-workflow.treasuredata.com` | Workflow API (digdag) |
|
|
292
|
-
| `trino` | `api-presto.treasuredata.com` | Trino Query Engine API |
|
|
293
|
-
| `llm` | `llm-api.treasuredata.com` | LLM API (agents, chat) |
|
|
294
|
-
|
|
295
|
-
**Notes:**
|
|
296
|
-
- All requests are automatically authenticated using your configured API key
|
|
297
|
-
- Request body from `--data` must be valid JSON
|
|
298
|
-
- `--data` and `--file` are mutually exclusive
|
|
299
|
-
- Custom headers override default authentication headers
|
|
300
|
-
- Response is output to stdout as JSON
|
|
301
|
-
- Use `--verbose` to show HTTP request/response details in stderr:
|
|
302
|
-
- Full target URL (shows site and API type)
|
|
303
|
-
- Request headers (non-sensitive: User-Agent, X-TD-Client, Content-Type, etc.)
|
|
304
|
-
- Response status and headers
|
|
305
|
-
- Sensitive headers (Authorization, Cookie, etc.) are hidden for security
|
|
306
|
-
|
|
307
|
-
**Verbose Output Example:**
|
|
308
|
-
```
|
|
309
|
-
> POST https://api.treasuredata.com/v3/job/issue/hive/mydb
|
|
310
|
-
> User-Agent: tdx/1.0.0 (darwin; node/24.0.0)
|
|
311
|
-
> X-TD-Client: tdx
|
|
312
|
-
> X-TD-Client-Version: 1.0.0
|
|
313
|
-
> Content-Type: application/json
|
|
314
|
-
>
|
|
315
|
-
|
|
316
|
-
< HTTP/1.1 200
|
|
317
|
-
< content-type: application/json
|
|
318
|
-
< x-td-request-id: abc123
|
|
319
|
-
|
|
320
|
-
{"job_id": "12345"}
|
|
321
|
-
```
|
|
322
|
-
|
|
323
336
|
### Database Commands
|
|
324
337
|
|
|
325
338
|
| Command | Description | Example |
|
|
@@ -910,6 +923,178 @@ NO_COLOR=1 tdx databases
|
|
|
910
923
|
3. `NO_COLOR` environment variable
|
|
911
924
|
4. TTY detection (automatic)
|
|
912
925
|
|
|
926
|
+
## Advanced Commands
|
|
927
|
+
|
|
928
|
+
### API Command (Raw HTTP Access)
|
|
929
|
+
|
|
930
|
+
Make authenticated HTTP requests to any Treasure Data API endpoint (similar to `gh api` from GitHub CLI).
|
|
931
|
+
|
|
932
|
+
**Usage:** `tdx api <endpoint> [options]`
|
|
933
|
+
|
|
934
|
+
| Option | Description | Example |
|
|
935
|
+
|--------|-------------|---------|
|
|
936
|
+
| `<endpoint>` | API endpoint path (must start with /) | `/v3/database/list` |
|
|
937
|
+
| `-X, --method <method>` | HTTP method (GET, POST, PUT, DELETE, PATCH) | `-X POST` |
|
|
938
|
+
| `--data <json>` | Request body as JSON string | `--data '{"name":"mydb"}'` |
|
|
939
|
+
| `-f, --file <path>` | Read request body from file | `-f body.json` |
|
|
940
|
+
| `-H, --header <header>` | Custom header (repeatable) | `-H "X-Custom: value"` |
|
|
941
|
+
| `--type <api_type>` | API type (td, cdp, workflow, trino, llm) | `--type cdp` |
|
|
942
|
+
|
|
943
|
+
**Examples:**
|
|
944
|
+
|
|
945
|
+
```bash
|
|
946
|
+
# GET request to TD API (default)
|
|
947
|
+
tdx api /v3/database/list
|
|
948
|
+
|
|
949
|
+
# GET with path parameters
|
|
950
|
+
tdx api /v3/database/show/mydb
|
|
951
|
+
tdx api /v3/table/list/mydb
|
|
952
|
+
tdx api /v3/table/show/mydb/users
|
|
953
|
+
|
|
954
|
+
# POST with inline JSON body (submit query)
|
|
955
|
+
tdx api -X POST --data '{"query":"SELECT 1"}' /v3/job/issue/hive/mydb
|
|
956
|
+
|
|
957
|
+
# POST with data from file
|
|
958
|
+
tdx api -X POST -f query.json /v3/job/issue/hive/mydb
|
|
959
|
+
|
|
960
|
+
# Custom headers
|
|
961
|
+
tdx api -H "X-Custom: value" -H "X-Another: test" /v3/database/list
|
|
962
|
+
|
|
963
|
+
# CDP API endpoints (read-only)
|
|
964
|
+
tdx api /entities/parent_segments --type cdp
|
|
965
|
+
tdx api /audiences/12345/segments --type cdp
|
|
966
|
+
tdx api -X POST --data '{"format":"sql"}' /audiences/12345/segments/query --type cdp
|
|
967
|
+
|
|
968
|
+
# Workflow API endpoints (read-only)
|
|
969
|
+
tdx api /api/workflows --type workflow
|
|
970
|
+
tdx api /api/projects --type workflow
|
|
971
|
+
tdx api /api/attempts --type workflow
|
|
972
|
+
|
|
973
|
+
# Trino API endpoints (query submission - plain SQL, not JSON)
|
|
974
|
+
tdx api -X POST --data 'SELECT 1' /v1/statement --type trino
|
|
975
|
+
|
|
976
|
+
# LLM API endpoints (read-only)
|
|
977
|
+
tdx api /v1/agents --type llm
|
|
978
|
+
tdx api /v1/models --type llm
|
|
979
|
+
|
|
980
|
+
# Show HTTP response headers (with --verbose)
|
|
981
|
+
tdx api /v3/database/list --verbose
|
|
982
|
+
|
|
983
|
+
# Save output to file
|
|
984
|
+
tdx api /v3/database/list --output databases.json
|
|
985
|
+
|
|
986
|
+
# Combine --verbose with --output to see headers while saving
|
|
987
|
+
tdx api /v3/database/list --verbose --output databases.json
|
|
988
|
+
```
|
|
989
|
+
|
|
990
|
+
**API Types:**
|
|
991
|
+
|
|
992
|
+
| Type | Base URL Pattern | Description |
|
|
993
|
+
|------|-----------------|-------------|
|
|
994
|
+
| `td` | `api.treasuredata.com` | TD REST API (databases, tables, jobs) |
|
|
995
|
+
| `cdp` | `api-cdp.treasuredata.com` | CDP API (audiences, segments, activations) |
|
|
996
|
+
| `workflow` | `api-workflow.treasuredata.com` | Workflow API (digdag) |
|
|
997
|
+
| `trino` | `api-presto.treasuredata.com` | Trino Query Engine API |
|
|
998
|
+
| `llm` | `llm-api.treasuredata.com` | LLM API (agents, chat) |
|
|
999
|
+
|
|
1000
|
+
**Notes:**
|
|
1001
|
+
- All requests are automatically authenticated using your configured API key
|
|
1002
|
+
- Request body from `--data` must be valid JSON
|
|
1003
|
+
- `--data` and `--file` are mutually exclusive
|
|
1004
|
+
- Custom headers override default authentication headers
|
|
1005
|
+
- Response is output to stdout as JSON
|
|
1006
|
+
- Use `--verbose` to show HTTP request/response details in stderr:
|
|
1007
|
+
- Full target URL (shows site and API type)
|
|
1008
|
+
- Request headers (non-sensitive: User-Agent, X-TD-Client, Content-Type, etc.)
|
|
1009
|
+
- Response status and headers
|
|
1010
|
+
- Sensitive headers (Authorization, Cookie, etc.) are hidden for security
|
|
1011
|
+
|
|
1012
|
+
**Verbose Output Example:**
|
|
1013
|
+
```
|
|
1014
|
+
> POST https://api.treasuredata.com/v3/job/issue/hive/mydb
|
|
1015
|
+
> User-Agent: tdx/1.0.0 (darwin; node/24.0.0)
|
|
1016
|
+
> X-TD-Client: tdx
|
|
1017
|
+
> X-TD-Client-Version: 1.0.0
|
|
1018
|
+
> Content-Type: application/json
|
|
1019
|
+
>
|
|
1020
|
+
|
|
1021
|
+
< HTTP/1.1 200
|
|
1022
|
+
< content-type: application/json
|
|
1023
|
+
< x-td-request-id: abc123
|
|
1024
|
+
|
|
1025
|
+
{"job_id": "12345"}
|
|
1026
|
+
```
|
|
1027
|
+
|
|
1028
|
+
## Advanced Options
|
|
1029
|
+
|
|
1030
|
+
### Session ID Option
|
|
1031
|
+
|
|
1032
|
+
By default, sessions are tied to the shell's process ID (PPID). You can explicitly specify a session ID using `--session` to share context across multiple processes or shells:
|
|
1033
|
+
|
|
1034
|
+
**Usage:** `tdx --session <session-id> [command]`
|
|
1035
|
+
|
|
1036
|
+
**Examples:**
|
|
1037
|
+
|
|
1038
|
+
```bash
|
|
1039
|
+
# Process 1: Set session with explicit ID
|
|
1040
|
+
tdx --session my-workflow use database analytics
|
|
1041
|
+
tdx --session my-workflow use llm_project DataPipeline
|
|
1042
|
+
|
|
1043
|
+
# Process 2: Reuse the same session
|
|
1044
|
+
tdx --session my-workflow context
|
|
1045
|
+
# Shows: Database: analytics, LLM Project: DataPipeline
|
|
1046
|
+
|
|
1047
|
+
# Process 2: Run commands with shared context
|
|
1048
|
+
tdx --session my-workflow tables
|
|
1049
|
+
# Uses database: analytics
|
|
1050
|
+
|
|
1051
|
+
# Clean up when done
|
|
1052
|
+
tdx --session my-workflow use --clear
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
**Use Cases:**
|
|
1056
|
+
- Sharing context between multiple terminal windows
|
|
1057
|
+
- Maintaining consistent context in CI/CD pipelines
|
|
1058
|
+
- Scripting scenarios where session persistence is needed
|
|
1059
|
+
|
|
1060
|
+
**Note:** The `--session` option must be specified before the command name (e.g., `tdx --session id tables`, not `tdx tables --session id`).
|
|
1061
|
+
|
|
1062
|
+
## Architecture
|
|
1063
|
+
|
|
1064
|
+
The `tdx` project is designed with a layered architecture that separates the CLI interface from the core SDK, allowing the TypeScript SDK to be used in multiple environments:
|
|
1065
|
+
|
|
1066
|
+
```mermaid
|
|
1067
|
+
graph TD
|
|
1068
|
+
subgraph "Client Environments"
|
|
1069
|
+
NodeJS[Node.JS/CLI<br/>tdx commands]
|
|
1070
|
+
Browser[Web Browser<br/>Client-side]
|
|
1071
|
+
end
|
|
1072
|
+
|
|
1073
|
+
subgraph "TDX SDK - TypeScript"
|
|
1074
|
+
SDK[TDX SDK<br/>TypeScript/JavaScript API]
|
|
1075
|
+
end
|
|
1076
|
+
|
|
1077
|
+
subgraph "Treasure Data APIs"
|
|
1078
|
+
TD[TD REST API<br/>Databases, Tables, Jobs]
|
|
1079
|
+
Trino[Trino Streaming API<br/>Query Execution]
|
|
1080
|
+
CDP[CDP API<br/>Segments, Activations]
|
|
1081
|
+
end
|
|
1082
|
+
|
|
1083
|
+
NodeJS --> SDK
|
|
1084
|
+
Browser --> SDK
|
|
1085
|
+
|
|
1086
|
+
SDK -->|HTTPS| TD
|
|
1087
|
+
SDK -->|HTTPS| Trino
|
|
1088
|
+
SDK -->|HTTPS| CDP
|
|
1089
|
+
|
|
1090
|
+
style NodeJS fill:#d4f1d4
|
|
1091
|
+
style Browser fill:#ffd4d4
|
|
1092
|
+
style SDK fill:#fff5cc
|
|
1093
|
+
style TD fill:#e8e8f0
|
|
1094
|
+
style CDP fill:#e8e8f0
|
|
1095
|
+
style Trino fill:#e8e8f0
|
|
1096
|
+
```
|
|
1097
|
+
|
|
913
1098
|
## TDX SDK
|
|
914
1099
|
|
|
915
1100
|
**Usage Examples:**
|