@treasuredata/tdx 0.1.4 → 0.1.6
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 +496 -222
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/client/cdp-client.d.ts +1 -1
- package/dist/client/cdp-client.js +1 -1
- package/dist/client/cdp-client.js.map +1 -1
- package/dist/client/http-client.d.ts +22 -2
- package/dist/client/http-client.d.ts.map +1 -1
- package/dist/client/http-client.js +1 -1
- package/dist/client/http-client.js.map +1 -1
- package/dist/client/llm-client.d.ts +7 -1
- package/dist/client/llm-client.d.ts.map +1 -1
- package/dist/client/llm-client.js +1 -1
- package/dist/client/llm-client.js.map +1 -1
- package/dist/client/rate-limiter.js +1 -1
- package/dist/client/td-client.js +1 -1
- package/dist/client/td-client.js.map +1 -1
- package/dist/client/trino-client.d.ts +2 -11
- package/dist/client/trino-client.d.ts.map +1 -1
- package/dist/client/trino-client.js +1 -1
- package/dist/client/trino-client.js.map +1 -1
- package/dist/client/workflow-client.d.ts +44 -1
- package/dist/client/workflow-client.d.ts.map +1 -1
- package/dist/client/workflow-client.js +1 -1
- package/dist/client/workflow-client.js.map +1 -1
- package/dist/commands/activations.d.ts +1 -1
- package/dist/commands/activations.js +1 -1
- package/dist/commands/api-command.js +1 -1
- package/dist/commands/chat-command.d.ts +10 -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.d.ts.map +1 -1
- package/dist/commands/command.js +1 -1
- package/dist/commands/command.js.map +1 -1
- package/dist/commands/context-command.d.ts +15 -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.d.ts +59 -30
- package/dist/commands/llm-command.d.ts.map +1 -1
- package/dist/commands/llm-command.js +1 -1
- package/dist/commands/llm-command.js.map +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.d.ts.map +1 -1
- package/dist/commands/query-command.js +1 -1
- package/dist/commands/query-command.js.map +1 -1
- package/dist/commands/segment-command.d.ts +4 -4
- package/dist/commands/segment-command.d.ts.map +1 -1
- package/dist/commands/segment-command.js +1 -1
- package/dist/commands/segment-command.js.map +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 +17 -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.d.ts +24 -0
- package/dist/commands/workflow-command.d.ts.map +1 -1
- package/dist/commands/workflow-command.js +1 -1
- package/dist/commands/workflow-command.js.map +1 -1
- package/dist/core/auth.d.ts +21 -6
- package/dist/core/auth.d.ts.map +1 -1
- package/dist/core/auth.js +1 -1
- package/dist/core/auth.js.map +1 -1
- package/dist/core/config.d.ts +34 -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 +127 -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.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/sdk/api.d.ts.map +1 -1
- package/dist/sdk/api.js +1 -1
- package/dist/sdk/api.js.map +1 -1
- package/dist/sdk/database.d.ts.map +1 -1
- package/dist/sdk/database.js +1 -1
- package/dist/sdk/database.js.map +1 -1
- package/dist/sdk/errors.d.ts +107 -3
- package/dist/sdk/errors.d.ts.map +1 -1
- package/dist/sdk/errors.js +1 -1
- package/dist/sdk/errors.js.map +1 -1
- package/dist/sdk/index.d.ts +12 -5
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/llm.d.ts +91 -8
- package/dist/sdk/llm.d.ts.map +1 -1
- package/dist/sdk/llm.js +1 -1
- package/dist/sdk/llm.js.map +1 -1
- package/dist/sdk/query.d.ts.map +1 -1
- package/dist/sdk/query.js +1 -1
- package/dist/sdk/query.js.map +1 -1
- package/dist/sdk/segment.d.ts.map +1 -1
- package/dist/sdk/segment.js +1 -1
- package/dist/sdk/segment.js.map +1 -1
- package/dist/sdk/table.d.ts.map +1 -1
- package/dist/sdk/table.js +1 -1
- package/dist/sdk/table.js.map +1 -1
- package/dist/sdk/workflow.d.ts +103 -0
- package/dist/sdk/workflow.d.ts.map +1 -1
- package/dist/sdk/workflow.js +1 -1
- package/dist/sdk/workflow.js.map +1 -1
- package/dist/types/endpoints.d.ts +14 -14
- package/dist/types/endpoints.d.ts.map +1 -1
- package/dist/types/endpoints.js +1 -1
- package/dist/types/endpoints.js.map +1 -1
- package/dist/types/index.d.ts +14 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +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.d.ts +9 -8
- package/dist/utils/segment-ref-parser.d.ts.map +1 -1
- package/dist/utils/segment-ref-parser.js +1 -1
- package/dist/utils/segment-ref-parser.js.map +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.d.ts +22 -0
- package/dist/utils/string-utils.d.ts.map +1 -1
- package/dist/utils/string-utils.js +1 -1
- package/dist/utils/string-utils.js.map +1 -1
- package/dist/utils/table-ref-parser.js +1 -1
- package/dist/utils/workflow-utils.d.ts +25 -0
- package/dist/utils/workflow-utils.d.ts.map +1 -0
- package/dist/utils/workflow-utils.js +1 -0
- package/dist/utils/workflow-utils.js.map +1 -0
- package/package.json +5 -2
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,171 @@ 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/tdx.json` or project `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
|
+
# Set session profile (shell-scoped)
|
|
108
|
+
tdx use profile production
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Profile Structure:**
|
|
112
|
+
|
|
113
|
+
Profiles are defined in `tdx.json` files with a `profiles` object:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"profiles": {
|
|
118
|
+
"production": {
|
|
119
|
+
"description": "Production environment for US region",
|
|
120
|
+
"site": "us01",
|
|
121
|
+
"database": "analytics",
|
|
122
|
+
"llm_project": "DataAnalytics"
|
|
123
|
+
},
|
|
124
|
+
"dev": {
|
|
125
|
+
"description": "Development and testing environment",
|
|
126
|
+
"site": "jp01",
|
|
127
|
+
"database": "dev_db"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Profile Locations:**
|
|
134
|
+
- **User-level**: `~/.config/tdx/tdx.json` - Shared across all projects
|
|
135
|
+
- **Project-level**: `(project folder)/tdx.json` - Project-specific profiles
|
|
136
|
+
|
|
137
|
+
**Credentials:**
|
|
138
|
+
Store API keys separately from profiles:
|
|
139
|
+
```
|
|
140
|
+
~/.config/tdx/
|
|
141
|
+
├── tdx.json # User-level profiles
|
|
142
|
+
├── .env.production # Production credentials
|
|
143
|
+
└── .env.dev # Development credentials
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Example credential file** (`~/.config/tdx/.env.production`):
|
|
147
|
+
```
|
|
148
|
+
TD_API_KEY=1234/abcdefg...
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Profile Precedence:**
|
|
152
|
+
1. Project `tdx.json` profiles (local)
|
|
153
|
+
2. User `~/.config/tdx/tdx.json` profiles (user-level)
|
|
154
|
+
3. Directory-based profiles (deprecated)
|
|
155
|
+
|
|
156
|
+
**Note:** The `description` field is optional but recommended for documenting what each profile is for.
|
|
157
|
+
|
|
158
|
+
### Session Context
|
|
159
|
+
|
|
160
|
+
Set temporary overrides for the current shell session:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# Set session database
|
|
164
|
+
tdx use database mydb
|
|
165
|
+
|
|
166
|
+
# Set session LLM project
|
|
167
|
+
tdx use llm_project Analytics
|
|
168
|
+
|
|
169
|
+
# View current context
|
|
170
|
+
tdx context
|
|
171
|
+
|
|
172
|
+
# Clear session context
|
|
173
|
+
tdx context --clear
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**How Session Scope Works:**
|
|
177
|
+
|
|
178
|
+
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:
|
|
179
|
+
|
|
180
|
+
- **Automatic isolation**: Each terminal window maintains its own independent session context
|
|
181
|
+
- **No manual setup**: Sessions are created automatically when you run `tdx use` commands
|
|
182
|
+
- **Persistent within shell**: Context persists across multiple commands in the same terminal
|
|
183
|
+
- **Automatic cleanup**: Sessions expire after 24 hours or when the shell is closed
|
|
184
|
+
|
|
185
|
+
**Example:**
|
|
186
|
+
```bash
|
|
187
|
+
# Terminal Window 1
|
|
188
|
+
tdx use database analytics
|
|
189
|
+
tdx tables # Uses database: analytics
|
|
190
|
+
|
|
191
|
+
# Terminal Window 2 (different PID)
|
|
192
|
+
tdx tables # Uses default database (separate session)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Session context persists until the shell is closed or explicitly cleared with `tdx context --clear`.
|
|
196
|
+
|
|
197
|
+
**Note:** For advanced session sharing across multiple processes or shells, see [Session ID Option](#session-id-option) in the Advanced Options section.
|
|
198
|
+
|
|
199
|
+
### Project Config
|
|
200
|
+
|
|
201
|
+
Store per-project defaults in `tdx.json` at your project root:
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"database": "customer_analytics",
|
|
206
|
+
"parent_segment": "active_users",
|
|
207
|
+
"llm_project": "CustomerInsights"
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Available Configuration Parameters:**
|
|
212
|
+
|
|
213
|
+
| Parameter | Type | Description | Example |
|
|
214
|
+
|-----------|------|-------------|---------|
|
|
215
|
+
| `description` | string | Optional description of the configuration | `"Production environment"` |
|
|
216
|
+
| `site` | string | TD site/region (us01, jp01, eu01, ap02) | `"us01"` |
|
|
217
|
+
| `database` | string | Default database for queries and table commands | `"analytics"` |
|
|
218
|
+
| `parent_segment` | string | Default parent segment for CDP commands | `"active_users"` |
|
|
219
|
+
| `llm_project` | string | Default LLM project for agent commands | `"DataAnalytics"` |
|
|
220
|
+
|
|
221
|
+
**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.
|
|
222
|
+
|
|
223
|
+
### View Context
|
|
224
|
+
|
|
225
|
+
See the currently resolved context and where each value comes from:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
# Show current context
|
|
229
|
+
tdx context
|
|
230
|
+
|
|
231
|
+
# Show context with sources (debugging)
|
|
232
|
+
tdx context --debug
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Example output:
|
|
236
|
+
```
|
|
237
|
+
[context]
|
|
238
|
+
site: us01 (global: ~/.config/tdx/tdx.json)
|
|
239
|
+
database: analytics (session)
|
|
240
|
+
llm_project: DataAnalytics (profile: production)
|
|
241
|
+
profile: production (session)
|
|
242
|
+
|
|
243
|
+
Configuration Files:
|
|
244
|
+
Session: /Users/user/.config/tdx/sessions/12345.json ✓
|
|
245
|
+
Global: /Users/user/.config/tdx/tdx.json ✓
|
|
246
|
+
Project: /Users/user/projects/myproject/tdx.json ✓
|
|
120
247
|
```
|
|
121
248
|
|
|
122
249
|
## Available Commands
|
|
@@ -181,145 +308,48 @@ Simplified top-level command for chatting with LLM agents.
|
|
|
181
308
|
|
|
182
309
|
| Command | Description | Example |
|
|
183
310
|
|---------|-------------|---------|
|
|
184
|
-
| `chat <message>` | Chat
|
|
185
|
-
| `chat <message> --agent <
|
|
311
|
+
| `chat <message>` | Chat (continues last session by default) | `tdx chat "Analyze my data"` |
|
|
312
|
+
| `chat <message> --agent <name>` | Chat with specific agent | `tdx chat "Hello" --agent "Data Analyst"` |
|
|
186
313
|
| `chat <message> --model <name>` | Chat using specific model | `tdx chat "Help" --model "gpt-5"` |
|
|
187
314
|
| `chat <message> --temperature <n>` | Set temperature (0.0-2.0, default: 0.7) | `tdx chat "Be creative" --temperature 1.2` |
|
|
188
|
-
| `chat <message> --
|
|
315
|
+
| `chat <message> --new` | Start a new chat session | `tdx chat --new "Fresh conversation"` |
|
|
189
316
|
|
|
190
317
|
**Examples**:
|
|
191
318
|
```bash
|
|
192
319
|
# Simple chat (uses default agent with claude-4.5-sonnet)
|
|
193
320
|
tdx chat "Show me the top customers by revenue"
|
|
194
321
|
|
|
195
|
-
# Continue previous conversation
|
|
196
|
-
tdx chat
|
|
197
|
-
tdx chat -c "And the quarter before that?"
|
|
322
|
+
# Continue previous conversation (default behavior)
|
|
323
|
+
tdx chat "What about last quarter?"
|
|
198
324
|
|
|
199
|
-
#
|
|
200
|
-
tdx chat
|
|
325
|
+
# Start a new conversation
|
|
326
|
+
tdx chat --new "Tell me about data modeling best practices"
|
|
201
327
|
|
|
202
|
-
# Use specific model (reuses agent
|
|
328
|
+
# Use specific model (auto-creates/reuses agent)
|
|
203
329
|
tdx chat "Help me write SQL" --model "gpt-5"
|
|
204
330
|
|
|
205
|
-
#
|
|
206
|
-
tdx
|
|
331
|
+
# Use specific agent by name (uses current project context)
|
|
332
|
+
tdx llm use "MyProject"
|
|
333
|
+
tdx chat "Analyze churn" --agent "Data Analyst"
|
|
207
334
|
|
|
208
|
-
#
|
|
209
|
-
tdx chat "
|
|
335
|
+
# Override project for agent lookup
|
|
336
|
+
tdx chat "Hello" --agent "Analyst" --llm-project "OtherProject"
|
|
337
|
+
|
|
338
|
+
# Adjust temperature
|
|
339
|
+
tdx chat "Write a poem" --temperature 1.5
|
|
210
340
|
|
|
211
341
|
# Verbose mode shows chat session ID
|
|
212
342
|
tdx chat "Hello" --verbose
|
|
213
343
|
```
|
|
214
344
|
|
|
215
345
|
**How it works**:
|
|
216
|
-
- **Default behavior**:
|
|
346
|
+
- **Default behavior**: Continues last chat session automatically
|
|
217
347
|
- **Session persistence**: Last chat ID saved to `.cache/tdx/last_chat_id`
|
|
218
|
-
- **--
|
|
219
|
-
- **--agent**: Use specific agent (
|
|
220
|
-
- **--model**:
|
|
348
|
+
- **--new flag**: Starts a fresh chat session
|
|
349
|
+
- **--agent**: Use specific agent by name (resolves using project context)
|
|
350
|
+
- **--model**: Auto-creates/reuses agent per model (e.g., `tdx_gpt-5`)
|
|
221
351
|
- **--temperature**: Controls randomness (0.7 default, lower=focused, higher=creative)
|
|
222
352
|
|
|
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
353
|
### Database Commands
|
|
324
354
|
|
|
325
355
|
| Command | Description | Example |
|
|
@@ -433,20 +463,20 @@ CDP (Customer Data Platform) segment management for audiences and activations.
|
|
|
433
463
|
|
|
434
464
|
**Name Format Conventions:**
|
|
435
465
|
- Parent segment: `parent_name` (e.g., `"My Audience"`)
|
|
436
|
-
- Child segment: `parent_name
|
|
437
|
-
- Folder: `parent_name
|
|
438
|
-
- Pattern: Commands accept `(parent_name)(
|
|
466
|
+
- Child segment: `parent_name/child_name` (e.g., `"My Audience/High Value Users"`) - uses slash notation
|
|
467
|
+
- Folder: `parent_name/folder_name` (e.g., `"My Audience/Marketing"`)
|
|
468
|
+
- Pattern: Commands accept `(parent_name)(/child_name)?` format
|
|
439
469
|
- **Note**: Names are case-sensitive
|
|
440
470
|
|
|
441
471
|
| Command | Description | Example |
|
|
442
472
|
|---------|-------------|---------|
|
|
443
473
|
| `segments` | List all parent segments | `tdx segments` |
|
|
444
474
|
| `segments <parent_name>` | List child segments under parent | `tdx segments "My Audience"` |
|
|
445
|
-
| `segment describe <name>` (alias: `desc`) | Show parent or child segment details | `tdx segment describe "My Audience"` or `tdx segment desc "My Audience
|
|
446
|
-
| `segment show <name>` | Execute segment SQL query and show results | `tdx segment show "My Audience"` or `tdx segment show "My Audience
|
|
447
|
-
| `segment sql <name>` | Get SQL query for segment | `tdx segment sql "My Audience"` or `tdx segment sql "My Audience
|
|
475
|
+
| `segment describe <name>` (alias: `desc`) | Show parent or child segment details | `tdx segment describe "My Audience"` or `tdx segment desc "My Audience/Premium Users"` |
|
|
476
|
+
| `segment show <name>` | Execute segment SQL query and show results | `tdx segment show "My Audience"` or `tdx segment show "My Audience/Premium Users" --limit 100` |
|
|
477
|
+
| `segment sql <name>` | Get SQL query for segment | `tdx segment sql "My Audience"` or `tdx segment sql "My Audience/Premium Users"` |
|
|
448
478
|
| `segment folders <parent_name>` | List folders under parent | `tdx segment folders "My Audience"` |
|
|
449
|
-
| `segment folder show <parent_name
|
|
479
|
+
| `segment folder show <parent_name/folder_name>` | Show folder details | `tdx segment folder show "My Audience/Marketing"` |
|
|
450
480
|
|
|
451
481
|
**Examples**:
|
|
452
482
|
```bash
|
|
@@ -461,14 +491,14 @@ tdx segment describe "My Audience"
|
|
|
461
491
|
# or use the alias
|
|
462
492
|
tdx segment desc "My Audience"
|
|
463
493
|
|
|
464
|
-
# Show child segment metadata (
|
|
465
|
-
tdx segment describe "My Audience
|
|
494
|
+
# Show child segment metadata (slash notation)
|
|
495
|
+
tdx segment describe "My Audience/High Value Users"
|
|
466
496
|
|
|
467
497
|
# Execute parent segment query and show results (default: 40 rows)
|
|
468
498
|
tdx segment show "My Audience"
|
|
469
499
|
|
|
470
|
-
# Execute child segment query with custom limit (
|
|
471
|
-
tdx segment show "My Audience
|
|
500
|
+
# Execute child segment query with custom limit (slash notation)
|
|
501
|
+
tdx segment show "My Audience/Premium Users" --limit 100
|
|
472
502
|
|
|
473
503
|
# Execute segment query and save as JSON
|
|
474
504
|
tdx segment show "My Audience" --format json --output results.json
|
|
@@ -476,14 +506,14 @@ tdx segment show "My Audience" --format json --output results.json
|
|
|
476
506
|
# Get SQL for parent segment
|
|
477
507
|
tdx segment sql "My Audience" > parent-query.sql
|
|
478
508
|
|
|
479
|
-
# Get SQL for child segment with filtering (
|
|
480
|
-
tdx segment sql "My Audience
|
|
509
|
+
# Get SQL for child segment with filtering (slash notation)
|
|
510
|
+
tdx segment sql "My Audience/High Value Users" > child-query.sql
|
|
481
511
|
|
|
482
512
|
# List folders under parent
|
|
483
513
|
tdx segment folders "My Audience"
|
|
484
514
|
|
|
485
|
-
# Show folder details (parent
|
|
486
|
-
tdx segment folder show "My Audience
|
|
515
|
+
# Show folder details (parent/folder notation)
|
|
516
|
+
tdx segment folder show "My Audience/Marketing"
|
|
487
517
|
```
|
|
488
518
|
|
|
489
519
|
### Activation Commands (CDP)
|
|
@@ -492,18 +522,18 @@ Manage CDP activations (syndications) for segments.
|
|
|
492
522
|
|
|
493
523
|
| Command | Description | Example |
|
|
494
524
|
|---------|-------------|---------|
|
|
495
|
-
| `activations <parent_name
|
|
525
|
+
| `activations <parent_name/child_name>` | List activations for a child segment | `tdx activations "My Audience/Premium Users"` |
|
|
496
526
|
|
|
497
527
|
**Examples**:
|
|
498
528
|
```bash
|
|
499
|
-
# List activations for a child segment (
|
|
500
|
-
tdx activations "My Audience
|
|
529
|
+
# List activations for a child segment (slash notation with names)
|
|
530
|
+
tdx activations "My Audience/Premium Users"
|
|
501
531
|
|
|
502
532
|
# Get activations as JSON
|
|
503
|
-
tdx activations "My Audience
|
|
533
|
+
tdx activations "My Audience/High Value Users" --format json
|
|
504
534
|
|
|
505
535
|
# Using Tokyo region
|
|
506
|
-
tdx activations "My Audience
|
|
536
|
+
tdx activations "My Audience/Premium Users" --site jp01
|
|
507
537
|
```
|
|
508
538
|
|
|
509
539
|
### Workflow Commands
|
|
@@ -523,6 +553,9 @@ Manage Treasure Data workflows powered by Digdag. Monitor execution sessions, vi
|
|
|
523
553
|
| `logs <attempt-id> <task-name>` | Show logs for a specific task | `tdx wf logs 67890 +step1` |
|
|
524
554
|
| `kill <attempt-id>` | Kill a running attempt | `tdx wf kill 67890` |
|
|
525
555
|
| `retry <session-id\|attempt-id>` | Retry a session or attempt | `tdx wf retry session:12345` or `tdx wf retry attempt:67890` |
|
|
556
|
+
| `download <project-name> [output-dir]` | Download workflow project from TD console | `tdx wf download myproject` or `tdx wf download myproject ./workflows` |
|
|
557
|
+
| `push [project-name-or-dir]` | Push workflow project to TD console (digdag-style) | `cd myproject && tdx wf push myproject` or `tdx wf push ./myproject` |
|
|
558
|
+
| `delete <project-name-or-id>` | Delete workflow project from TD console | `tdx wf delete myproject` or `tdx wf delete 12345` |
|
|
526
559
|
|
|
527
560
|
**Workflow-specific options:**
|
|
528
561
|
|
|
@@ -540,6 +573,14 @@ For `tasks` command:
|
|
|
540
573
|
For `logs` command:
|
|
541
574
|
- `--offset <number>`: Starting offset for logs (default: 0)
|
|
542
575
|
|
|
576
|
+
For `download` command:
|
|
577
|
+
- `--revision <revision>`: Download specific revision (default: latest)
|
|
578
|
+
|
|
579
|
+
For `push` command:
|
|
580
|
+
- `--name <name>`: Project name (default: directory name)
|
|
581
|
+
- `--revision <revision>`: Revision name (default: timestamp)
|
|
582
|
+
- `--skip-validation`: Skip validation of .dig files
|
|
583
|
+
|
|
543
584
|
For `kill` command:
|
|
544
585
|
- `--reason <text>`: Reason for killing the attempt
|
|
545
586
|
- `-y, --yes`: Skip confirmation prompt
|
|
@@ -637,88 +678,149 @@ tdx wf retry attempt:67890 --params @params.json
|
|
|
637
678
|
# Force retry without confirmation
|
|
638
679
|
tdx wf retry attempt:67890 --force -y
|
|
639
680
|
|
|
681
|
+
# Download workflow project
|
|
682
|
+
tdx wf download myproject
|
|
683
|
+
|
|
684
|
+
# Download to specific directory
|
|
685
|
+
tdx wf download myproject ./workflows
|
|
686
|
+
|
|
687
|
+
# Download specific revision
|
|
688
|
+
tdx wf download myproject --revision v1.0.0
|
|
689
|
+
|
|
690
|
+
# Push workflow project (digdag-style: cd into project directory first)
|
|
691
|
+
cd myproject
|
|
692
|
+
tdx wf push myproject
|
|
693
|
+
|
|
694
|
+
# Push with custom revision
|
|
695
|
+
cd myproject
|
|
696
|
+
tdx wf push myproject --revision v1.0.0
|
|
697
|
+
|
|
698
|
+
# Push from parent directory with path
|
|
699
|
+
tdx wf push ./myproject
|
|
700
|
+
|
|
701
|
+
# Push with --name override
|
|
702
|
+
cd myproject
|
|
703
|
+
tdx wf push myproject --name production_workflow
|
|
704
|
+
|
|
705
|
+
# Push from current directory without specifying name
|
|
706
|
+
cd myproject
|
|
707
|
+
tdx wf push
|
|
708
|
+
|
|
709
|
+
# Push without validation
|
|
710
|
+
cd myproject
|
|
711
|
+
tdx wf push myproject --skip-validation
|
|
712
|
+
|
|
713
|
+
# Delete workflow project (with confirmation)
|
|
714
|
+
tdx wf delete myproject
|
|
715
|
+
|
|
716
|
+
# Delete by project ID
|
|
717
|
+
tdx wf delete 12345
|
|
718
|
+
|
|
719
|
+
# Delete without confirmation
|
|
720
|
+
tdx wf delete myproject -y
|
|
721
|
+
|
|
640
722
|
# Get workflow data as JSON
|
|
641
723
|
tdx wf sessions --format json --output sessions.json
|
|
642
724
|
```
|
|
643
725
|
|
|
644
|
-
###
|
|
726
|
+
### LLM Commands
|
|
645
727
|
|
|
646
|
-
Usage: `tdx
|
|
728
|
+
Usage: `tdx llm <subcommand>`
|
|
647
729
|
|
|
648
|
-
Manage LLM agents and chat sessions with streaming support.
|
|
730
|
+
Manage LLM projects, agents, and chat sessions with streaming support.
|
|
649
731
|
|
|
650
732
|
| Command | Description | Example |
|
|
651
733
|
|---------|-------------|---------|
|
|
652
|
-
| `
|
|
653
|
-
| `
|
|
654
|
-
| `
|
|
655
|
-
| `
|
|
656
|
-
| `
|
|
657
|
-
| `
|
|
658
|
-
| `agent
|
|
659
|
-
| `agent
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
734
|
+
| `llm use <project>` | Set current project context | `tdx llm use "MyProject"` |
|
|
735
|
+
| `llm models` | List available LLM models | `tdx llm models` |
|
|
736
|
+
| `llm projects [pattern]` | List all projects (with wildcard support) | `tdx llm projects` or `tdx llm projects "data*"` |
|
|
737
|
+
| `llm project create <name>` | Create a new project | `tdx llm project create "MyProject"` |
|
|
738
|
+
| `llm project delete <name>` | Delete a project | `tdx llm project delete "MyProject"` |
|
|
739
|
+
| `llm agents [pattern]` | List agents in current project (with wildcard support) | `tdx llm agents` or `tdx llm agents "test*"` |
|
|
740
|
+
| `llm agent show <name>` | Show agent details | `tdx llm agent show "Data Analyst"` |
|
|
741
|
+
| `llm agent create <name>` | Create a new agent in current project | `tdx llm agent create "My Agent" --model <model>` |
|
|
742
|
+
| `llm agent update <name>` | Update an agent | `tdx llm agent update "Agent" --name "New Name"` |
|
|
743
|
+
| `llm agent delete <name>` | Delete an agent | `tdx llm agent delete "Agent"` |
|
|
744
|
+
| `llm history [chat-id]` | List chat sessions or show messages | `tdx llm history` or `tdx llm history chat456` |
|
|
745
|
+
|
|
746
|
+
**Project Resolution (Precedence Order):**
|
|
747
|
+
|
|
748
|
+
Agent commands resolve projects in this order:
|
|
749
|
+
1. `--llm-project` global option (highest priority)
|
|
750
|
+
2. `tdx llm use <project>` context (session-only)
|
|
751
|
+
3. Default project `tdx_default_<username>` (auto-created)
|
|
752
|
+
|
|
753
|
+
**Command Options:**
|
|
754
|
+
|
|
755
|
+
For `project create`:
|
|
756
|
+
- `--description <text>`: Project description
|
|
757
|
+
|
|
758
|
+
For `agent create`:
|
|
670
759
|
- `--system-prompt <text>`: System prompt/instructions (default: empty)
|
|
671
760
|
- `--model <name>`: Model type (default: claude-4.5-sonnet)
|
|
672
761
|
- `--starter-message <text>`: Starter message for the agent
|
|
673
762
|
- `--max-tool-iterations <n>`: Maximum tool iterations (default: 4)
|
|
674
763
|
- `--temperature <n>`: Temperature 0.0-2.0 (default: 0.7)
|
|
675
764
|
|
|
676
|
-
For `update
|
|
765
|
+
For `agent update`:
|
|
677
766
|
- `--name <text>`: New agent name
|
|
678
767
|
- `--prompt <text>`: New prompt/instructions
|
|
679
768
|
- `--description <text>`: New description
|
|
680
769
|
- `--starter-message <text>`: New starter message
|
|
681
770
|
|
|
682
|
-
|
|
683
771
|
**Examples**:
|
|
684
772
|
```bash
|
|
685
773
|
# List available models
|
|
686
|
-
tdx
|
|
774
|
+
tdx llm models
|
|
687
775
|
|
|
688
776
|
# List all projects
|
|
689
|
-
tdx
|
|
777
|
+
tdx llm projects
|
|
690
778
|
|
|
691
|
-
# List
|
|
692
|
-
tdx
|
|
779
|
+
# List projects matching pattern (wildcards: * = any chars, ? = single char)
|
|
780
|
+
tdx llm projects "data*" # Projects starting with 'data'
|
|
781
|
+
tdx llm projects "*_prod" # Projects ending with '_prod'
|
|
693
782
|
|
|
694
|
-
#
|
|
695
|
-
tdx
|
|
783
|
+
# Create a new project
|
|
784
|
+
tdx llm project create "MyProject" --description "My data analysis project"
|
|
696
785
|
|
|
697
|
-
#
|
|
698
|
-
tdx
|
|
786
|
+
# Set current project context (session-only)
|
|
787
|
+
tdx llm use "MyProject"
|
|
699
788
|
|
|
700
|
-
#
|
|
701
|
-
tdx
|
|
702
|
-
|
|
703
|
-
|
|
789
|
+
# Now all agent commands use "MyProject" by default:
|
|
790
|
+
tdx llm agents # List agents in MyProject
|
|
791
|
+
tdx llm agents "test*" # Filter agents by pattern
|
|
792
|
+
tdx llm agent show "Data Analyst" # Show agent from MyProject
|
|
793
|
+
tdx llm agent create "Analyst" --model gpt-5 # Create in MyProject
|
|
794
|
+
tdx llm agent update "Analyst" --name "Senior Analyst"
|
|
795
|
+
tdx llm agent delete "Analyst"
|
|
704
796
|
|
|
705
|
-
#
|
|
706
|
-
tdx
|
|
797
|
+
# Override project with --llm-project option (highest priority)
|
|
798
|
+
tdx llm agents --llm-project "OtherProject"
|
|
799
|
+
tdx llm agent show "Agent" --llm-project "OtherProject"
|
|
707
800
|
|
|
708
|
-
#
|
|
709
|
-
tdx
|
|
801
|
+
# Use default project (tdx_default_<username>) - no setup needed
|
|
802
|
+
tdx llm agents # Uses tdx_default_leo if no context set
|
|
803
|
+
tdx llm agent create "Bot" # Creates in default project
|
|
710
804
|
|
|
711
|
-
#
|
|
712
|
-
tdx
|
|
805
|
+
# Complete workflow: Create custom agent and chat with it
|
|
806
|
+
tdx llm use "MyProject"
|
|
807
|
+
tdx llm agent create "SQL Expert" \
|
|
808
|
+
--system-prompt "You are an expert in SQL and data analysis. Help users write efficient queries." \
|
|
809
|
+
--model "claude-4.5-sonnet"
|
|
713
810
|
|
|
714
|
-
#
|
|
715
|
-
tdx agent
|
|
811
|
+
# Now chat with your custom agent
|
|
812
|
+
tdx chat "Help me analyze customer churn" --agent "SQL Expert"
|
|
813
|
+
tdx chat "Show me the query for that" # Continues conversation
|
|
716
814
|
|
|
717
|
-
#
|
|
718
|
-
tdx
|
|
815
|
+
# Delete project
|
|
816
|
+
tdx llm project delete "OldProject"
|
|
719
817
|
|
|
720
|
-
#
|
|
721
|
-
tdx
|
|
818
|
+
# Chat history
|
|
819
|
+
tdx llm history # List recent chat sessions
|
|
820
|
+
tdx llm history chat456 # Show specific chat messages
|
|
821
|
+
|
|
822
|
+
# JSON output
|
|
823
|
+
tdx llm agents --format json --output agents.json
|
|
722
824
|
```
|
|
723
825
|
|
|
724
826
|
## Advanced Query Features
|
|
@@ -910,6 +1012,178 @@ NO_COLOR=1 tdx databases
|
|
|
910
1012
|
3. `NO_COLOR` environment variable
|
|
911
1013
|
4. TTY detection (automatic)
|
|
912
1014
|
|
|
1015
|
+
## Advanced Commands
|
|
1016
|
+
|
|
1017
|
+
### API Command (Raw HTTP Access)
|
|
1018
|
+
|
|
1019
|
+
Make authenticated HTTP requests to any Treasure Data API endpoint (similar to `gh api` from GitHub CLI).
|
|
1020
|
+
|
|
1021
|
+
**Usage:** `tdx api <endpoint> [options]`
|
|
1022
|
+
|
|
1023
|
+
| Option | Description | Example |
|
|
1024
|
+
|--------|-------------|---------|
|
|
1025
|
+
| `<endpoint>` | API endpoint path (must start with /) | `/v3/database/list` |
|
|
1026
|
+
| `-X, --method <method>` | HTTP method (GET, POST, PUT, DELETE, PATCH) | `-X POST` |
|
|
1027
|
+
| `--data <json>` | Request body as JSON string | `--data '{"name":"mydb"}'` |
|
|
1028
|
+
| `-f, --file <path>` | Read request body from file | `-f body.json` |
|
|
1029
|
+
| `-H, --header <header>` | Custom header (repeatable) | `-H "X-Custom: value"` |
|
|
1030
|
+
| `--type <api_type>` | API type (td, cdp, workflow, trino, llm) | `--type cdp` |
|
|
1031
|
+
|
|
1032
|
+
**Examples:**
|
|
1033
|
+
|
|
1034
|
+
```bash
|
|
1035
|
+
# GET request to TD API (default)
|
|
1036
|
+
tdx api /v3/database/list
|
|
1037
|
+
|
|
1038
|
+
# GET with path parameters
|
|
1039
|
+
tdx api /v3/database/show/mydb
|
|
1040
|
+
tdx api /v3/table/list/mydb
|
|
1041
|
+
tdx api /v3/table/show/mydb/users
|
|
1042
|
+
|
|
1043
|
+
# POST with inline JSON body (submit query)
|
|
1044
|
+
tdx api -X POST --data '{"query":"SELECT 1"}' /v3/job/issue/hive/mydb
|
|
1045
|
+
|
|
1046
|
+
# POST with data from file
|
|
1047
|
+
tdx api -X POST -f query.json /v3/job/issue/hive/mydb
|
|
1048
|
+
|
|
1049
|
+
# Custom headers
|
|
1050
|
+
tdx api -H "X-Custom: value" -H "X-Another: test" /v3/database/list
|
|
1051
|
+
|
|
1052
|
+
# CDP API endpoints (read-only)
|
|
1053
|
+
tdx api /entities/parent_segments --type cdp
|
|
1054
|
+
tdx api /audiences/12345/segments --type cdp
|
|
1055
|
+
tdx api -X POST --data '{"format":"sql"}' /audiences/12345/segments/query --type cdp
|
|
1056
|
+
|
|
1057
|
+
# Workflow API endpoints (read-only)
|
|
1058
|
+
tdx api /api/workflows --type workflow
|
|
1059
|
+
tdx api /api/projects --type workflow
|
|
1060
|
+
tdx api /api/attempts --type workflow
|
|
1061
|
+
|
|
1062
|
+
# Trino API endpoints (query submission - plain SQL, not JSON)
|
|
1063
|
+
tdx api -X POST --data 'SELECT 1' /v1/statement --type trino
|
|
1064
|
+
|
|
1065
|
+
# LLM API endpoints (read-only)
|
|
1066
|
+
tdx api /v1/agents --type llm
|
|
1067
|
+
tdx api /v1/models --type llm
|
|
1068
|
+
|
|
1069
|
+
# Show HTTP response headers (with --verbose)
|
|
1070
|
+
tdx api /v3/database/list --verbose
|
|
1071
|
+
|
|
1072
|
+
# Save output to file
|
|
1073
|
+
tdx api /v3/database/list --output databases.json
|
|
1074
|
+
|
|
1075
|
+
# Combine --verbose with --output to see headers while saving
|
|
1076
|
+
tdx api /v3/database/list --verbose --output databases.json
|
|
1077
|
+
```
|
|
1078
|
+
|
|
1079
|
+
**API Types:**
|
|
1080
|
+
|
|
1081
|
+
| Type | Base URL Pattern | Description |
|
|
1082
|
+
|------|-----------------|-------------|
|
|
1083
|
+
| `td` | `api.treasuredata.com` | TD REST API (databases, tables, jobs) |
|
|
1084
|
+
| `cdp` | `api-cdp.treasuredata.com` | CDP API (audiences, segments, activations) |
|
|
1085
|
+
| `workflow` | `api-workflow.treasuredata.com` | Workflow API (digdag) |
|
|
1086
|
+
| `trino` | `api-presto.treasuredata.com` | Trino Query Engine API |
|
|
1087
|
+
| `llm` | `llm-api.treasuredata.com` | LLM API (agents, chat) |
|
|
1088
|
+
|
|
1089
|
+
**Notes:**
|
|
1090
|
+
- All requests are automatically authenticated using your configured API key
|
|
1091
|
+
- Request body from `--data` must be valid JSON
|
|
1092
|
+
- `--data` and `--file` are mutually exclusive
|
|
1093
|
+
- Custom headers override default authentication headers
|
|
1094
|
+
- Response is output to stdout as JSON
|
|
1095
|
+
- Use `--verbose` to show HTTP request/response details in stderr:
|
|
1096
|
+
- Full target URL (shows site and API type)
|
|
1097
|
+
- Request headers (non-sensitive: User-Agent, X-TD-Client, Content-Type, etc.)
|
|
1098
|
+
- Response status and headers
|
|
1099
|
+
- Sensitive headers (Authorization, Cookie, etc.) are hidden for security
|
|
1100
|
+
|
|
1101
|
+
**Verbose Output Example:**
|
|
1102
|
+
```
|
|
1103
|
+
> POST https://api.treasuredata.com/v3/job/issue/hive/mydb
|
|
1104
|
+
> User-Agent: tdx/1.0.0 (darwin; node/24.0.0)
|
|
1105
|
+
> X-TD-Client: tdx
|
|
1106
|
+
> X-TD-Client-Version: 1.0.0
|
|
1107
|
+
> Content-Type: application/json
|
|
1108
|
+
>
|
|
1109
|
+
|
|
1110
|
+
< HTTP/1.1 200
|
|
1111
|
+
< content-type: application/json
|
|
1112
|
+
< x-td-request-id: abc123
|
|
1113
|
+
|
|
1114
|
+
{"job_id": "12345"}
|
|
1115
|
+
```
|
|
1116
|
+
|
|
1117
|
+
## Advanced Options
|
|
1118
|
+
|
|
1119
|
+
### Session ID Option
|
|
1120
|
+
|
|
1121
|
+
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:
|
|
1122
|
+
|
|
1123
|
+
**Usage:** `tdx --session <session-id> [command]`
|
|
1124
|
+
|
|
1125
|
+
**Examples:**
|
|
1126
|
+
|
|
1127
|
+
```bash
|
|
1128
|
+
# Process 1: Set session with explicit ID
|
|
1129
|
+
tdx --session my-workflow use database analytics
|
|
1130
|
+
tdx --session my-workflow use llm_project DataPipeline
|
|
1131
|
+
|
|
1132
|
+
# Process 2: Reuse the same session
|
|
1133
|
+
tdx --session my-workflow context
|
|
1134
|
+
# Shows: Database: analytics, LLM Project: DataPipeline
|
|
1135
|
+
|
|
1136
|
+
# Process 2: Run commands with shared context
|
|
1137
|
+
tdx --session my-workflow tables
|
|
1138
|
+
# Uses database: analytics
|
|
1139
|
+
|
|
1140
|
+
# Clean up when done
|
|
1141
|
+
tdx --session my-workflow use --clear
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
**Use Cases:**
|
|
1145
|
+
- Sharing context between multiple terminal windows
|
|
1146
|
+
- Maintaining consistent context in CI/CD pipelines
|
|
1147
|
+
- Scripting scenarios where session persistence is needed
|
|
1148
|
+
|
|
1149
|
+
**Note:** The `--session` option must be specified before the command name (e.g., `tdx --session id tables`, not `tdx tables --session id`).
|
|
1150
|
+
|
|
1151
|
+
## Architecture
|
|
1152
|
+
|
|
1153
|
+
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:
|
|
1154
|
+
|
|
1155
|
+
```mermaid
|
|
1156
|
+
graph TD
|
|
1157
|
+
subgraph "Client Environments"
|
|
1158
|
+
NodeJS[Node.JS/CLI<br/>tdx commands]
|
|
1159
|
+
Browser[Web Browser<br/>Client-side]
|
|
1160
|
+
end
|
|
1161
|
+
|
|
1162
|
+
subgraph "TDX SDK - TypeScript"
|
|
1163
|
+
SDK[TDX SDK<br/>TypeScript/JavaScript API]
|
|
1164
|
+
end
|
|
1165
|
+
|
|
1166
|
+
subgraph "Treasure Data APIs"
|
|
1167
|
+
TD[TD REST API<br/>Databases, Tables, Jobs]
|
|
1168
|
+
Trino[Trino Streaming API<br/>Query Execution]
|
|
1169
|
+
CDP[CDP API<br/>Segments, Activations]
|
|
1170
|
+
end
|
|
1171
|
+
|
|
1172
|
+
NodeJS --> SDK
|
|
1173
|
+
Browser --> SDK
|
|
1174
|
+
|
|
1175
|
+
SDK -->|HTTPS| TD
|
|
1176
|
+
SDK -->|HTTPS| Trino
|
|
1177
|
+
SDK -->|HTTPS| CDP
|
|
1178
|
+
|
|
1179
|
+
style NodeJS fill:#d4f1d4
|
|
1180
|
+
style Browser fill:#ffd4d4
|
|
1181
|
+
style SDK fill:#fff5cc
|
|
1182
|
+
style TD fill:#e8e8f0
|
|
1183
|
+
style CDP fill:#e8e8f0
|
|
1184
|
+
style Trino fill:#e8e8f0
|
|
1185
|
+
```
|
|
1186
|
+
|
|
913
1187
|
## TDX SDK
|
|
914
1188
|
|
|
915
1189
|
**Usage Examples:**
|