@treasuredata/tdx 0.3.0 → 0.3.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/README.md +28 -1690
- package/dist/build-info.json +2 -2
- package/dist/cli.js +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/auth-command.js +1 -1
- package/dist/commands/chat-command.js +1 -1
- package/dist/commands/claude-command.js +1 -1
- package/dist/commands/command.js +1 -1
- package/dist/commands/context-command.js +1 -1
- package/dist/commands/databases.js +1 -1
- package/dist/commands/describe.js +1 -1
- package/dist/commands/job-command.js +1 -1
- package/dist/commands/llm-command.js +1 -1
- package/dist/commands/llm-proxy.js +1 -1
- package/dist/commands/parent-segment-command.js +1 -1
- package/dist/commands/profiles-command.js +1 -1
- package/dist/commands/query-command.js +1 -1
- package/dist/commands/segment-command.js +1 -1
- package/dist/commands/segment-create-command.js +1 -1
- package/dist/commands/segment-fields-command.js +1 -1
- package/dist/commands/segment-pwd-command.js +1 -1
- package/dist/commands/segment-update-command.js +1 -1
- package/dist/commands/segment-use-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.js +1 -1
- package/dist/commands/workflow-command.js +1 -1
- package/dist/core/auth.js +1 -1
- package/dist/core/config.js +1 -1
- package/dist/core/global-context.js +1 -1
- package/dist/core/global-context.js.map +1 -1
- package/dist/core/profile.js +1 -1
- package/dist/core/project-config.js +1 -1
- package/dist/core/session.js +1 -1
- package/dist/index.js +1 -1
- package/dist/proxy/anthropic-adapter.js +1 -1
- package/dist/proxy/server.d.ts.map +1 -1
- package/dist/proxy/server.js +1 -1
- package/dist/proxy/server.js.map +1 -1
- package/dist/proxy/session-cache.js +1 -1
- package/dist/sdk/api.d.ts +3 -0
- 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 +1 -0
- 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.js +1 -1
- package/dist/sdk/index.d.ts +14 -1
- 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/job.d.ts +1 -0
- package/dist/sdk/job.d.ts.map +1 -1
- package/dist/sdk/job.js +1 -1
- package/dist/sdk/job.js.map +1 -1
- package/dist/sdk/llm.d.ts +1 -0
- 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 +1 -0
- 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 +1 -0
- 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 +1 -0
- 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 +1 -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.js +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/constants.js +1 -1
- package/dist/utils/file-permissions.js +1 -1
- package/dist/utils/format-detector.js +1 -1
- package/dist/utils/formatters.js +1 -1
- package/dist/utils/json-loader.js +1 -1
- package/dist/utils/model-aliases.js +1 -1
- package/dist/utils/option-validation.js +1 -1
- package/dist/utils/port.js +1 -1
- package/dist/utils/process.d.ts.map +1 -1
- package/dist/utils/process.js +1 -1
- package/dist/utils/process.js.map +1 -1
- package/dist/utils/prompt.js +1 -1
- package/dist/utils/segment-path-parser.js +1 -1
- 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/dist/utils/tdx-logger.d.ts.map +1 -1
- package/dist/utils/tdx-logger.js +1 -1
- package/dist/utils/tdx-logger.js.map +1 -1
- package/dist/utils/tree-formatter.js +1 -1
- package/dist/utils/version-check.js +1 -1
- package/dist/utils/workflow-utils.js +1 -1
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -1,1728 +1,66 @@
|
|
|
1
1
|
# tdx - AI-Native CLI for Treasure Data
|
|
2
2
|
|
|
3
|
-
> **Status:**
|
|
3
|
+
> **Status:** Under Active Development. SDK/CLI commands are subject to change (2025)
|
|
4
4
|
|
|
5
5
|
A modern, AI-native command-line interface for Treasure Data, optimized for both human engineers and AI coding assistants.
|
|
6
6
|
|
|
7
|
+
**Documentation:** [https://tdx.treasuredata.com/](https://tdx.treasuredata.com/)
|
|
8
|
+
|
|
7
9
|
## Features
|
|
8
10
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
11
|
+
- **AI-Native Design**: Consistent JSON output, predictable error codes, structured responses
|
|
12
|
+
- **Claude Code Integration**: Launch Claude Code with TD LLM API using `tdx claude`
|
|
13
|
+
- **Multi-Site Support**: Easy switching between US, JP, EU, and AP regions
|
|
14
|
+
- **Modern Distribution**: Install via `npx` or `npm` without prior setup
|
|
13
15
|
|
|
14
16
|
## Installation
|
|
15
17
|
|
|
16
18
|
```bash
|
|
17
|
-
#
|
|
18
|
-
npx @treasuredata/tdx databases
|
|
19
|
-
|
|
20
|
-
# Run latest version with npx
|
|
21
|
-
npx @treasuredata/tdx@latest databases
|
|
22
|
-
|
|
23
|
-
# Or install globally
|
|
19
|
+
# Install globally
|
|
24
20
|
npm install -g @treasuredata/tdx
|
|
25
21
|
|
|
26
|
-
#
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
# Run latest version with bunx
|
|
30
|
-
bunx @treasuredata/tdx@latest databases
|
|
22
|
+
# Or run directly with npx (no installation required)
|
|
23
|
+
npx @treasuredata/tdx databases
|
|
31
24
|
```
|
|
32
25
|
|
|
33
26
|
## Quick Start
|
|
34
27
|
|
|
35
|
-
### 1. Set Up Authentication
|
|
36
|
-
|
|
37
|
-
**Recommended: Use the interactive setup command**
|
|
38
|
-
|
|
39
28
|
```bash
|
|
40
|
-
#
|
|
29
|
+
# Set up authentication (interactive)
|
|
41
30
|
tdx auth setup
|
|
42
31
|
|
|
43
|
-
# Or specify site directly
|
|
44
|
-
tdx auth setup --site jp01
|
|
45
|
-
|
|
46
|
-
# Set up profile-specific authentication
|
|
47
|
-
tdx auth setup --profile work --site eu01
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
The setup command will:
|
|
51
|
-
- Guide you through site selection
|
|
52
|
-
- Securely prompt for your API key (hidden input)
|
|
53
|
-
- Validate the API key before saving
|
|
54
|
-
- Save to `~/.config/tdx/.env` (or `.env.{profile}` for profiles)
|
|
55
|
-
|
|
56
|
-
**Alternative: Manual configuration**
|
|
57
|
-
|
|
58
|
-
Create `~/.config/tdx/.env`:
|
|
59
|
-
```bash
|
|
60
|
-
TD_API_KEY=your-api-key-here/...
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Or set as environment variable:
|
|
64
|
-
```bash
|
|
65
|
-
export TD_API_KEY=your-api-key-here/...
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
**Check authentication status:**
|
|
69
|
-
```bash
|
|
70
|
-
tdx auth
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### 2. Run Commands
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
32
|
# List databases
|
|
77
33
|
tdx databases
|
|
78
34
|
|
|
79
|
-
# List databases in Tokyo region
|
|
80
|
-
tdx databases --site jp01
|
|
81
|
-
|
|
82
|
-
# Show table contents
|
|
83
|
-
tdx show sample_datasets.www_access --limit 10
|
|
84
|
-
|
|
85
35
|
# Run a query
|
|
86
|
-
tdx query "SELECT * FROM
|
|
87
|
-
|
|
88
|
-
# Get JSON output (two ways)
|
|
89
|
-
tdx databases --json
|
|
90
|
-
tdx databases --format json
|
|
91
|
-
|
|
92
|
-
# Get JSON Lines output
|
|
93
|
-
tdx query "SELECT * FROM users" --jsonl
|
|
36
|
+
tdx query "SELECT * FROM mydb.users LIMIT 10"
|
|
94
37
|
|
|
95
|
-
#
|
|
96
|
-
tdx query "SELECT * FROM users" --tsv
|
|
97
|
-
|
|
98
|
-
# Get human-readable table output (default)
|
|
99
|
-
tdx databases --format table
|
|
100
|
-
|
|
101
|
-
# Chat with AI (simplified - uses default agent)
|
|
38
|
+
# Chat with AI
|
|
102
39
|
tdx chat "Show me customer revenue trends"
|
|
103
40
|
|
|
104
|
-
#
|
|
105
|
-
tdx
|
|
106
|
-
|
|
107
|
-
# Start a new chat session
|
|
108
|
-
tdx chat --new "Tell me about data pipelines"
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Context Management
|
|
112
|
-
|
|
113
|
-
`tdx` provides a unified context system to reduce repetitive flags across commands. Context is resolved from multiple sources with the following priority:
|
|
114
|
-
|
|
115
|
-
1. **CLI flags** (highest priority) - `--database`, `--site`, etc.
|
|
116
|
-
2. **Session context** - Shell-scoped overrides set with `tdx use`
|
|
117
|
-
3. **Project config** - Per-project defaults in `tdx.json`
|
|
118
|
-
4. **Profile config** - Account-specific settings in `~/.config/tdx/tdx.json` or project `tdx.json`
|
|
119
|
-
5. **Global config** - Fallback defaults in `~/.config/tdx/tdx.json`
|
|
120
|
-
|
|
121
|
-
### Profiles
|
|
122
|
-
|
|
123
|
-
Profiles store long-lived account configurations for easy switching between environments:
|
|
124
|
-
|
|
125
|
-
```bash
|
|
126
|
-
# List all profiles with details
|
|
127
|
-
tdx profiles
|
|
128
|
-
|
|
129
|
-
# Set session profile (shell-scoped)
|
|
130
|
-
tdx use profile production
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
**Profile Structure:**
|
|
134
|
-
|
|
135
|
-
Profiles are defined in `tdx.json` files with a `profiles` object:
|
|
136
|
-
|
|
137
|
-
```json
|
|
138
|
-
{
|
|
139
|
-
"profiles": {
|
|
140
|
-
"production": {
|
|
141
|
-
"description": "Production environment for US region",
|
|
142
|
-
"site": "us01",
|
|
143
|
-
"database": "analytics",
|
|
144
|
-
"llm_project": "DataAnalytics"
|
|
145
|
-
},
|
|
146
|
-
"dev": {
|
|
147
|
-
"description": "Development and testing environment",
|
|
148
|
-
"site": "jp01",
|
|
149
|
-
"database": "dev_db"
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
**Profile Locations:**
|
|
156
|
-
- **User-level**: `~/.config/tdx/tdx.json` - Shared across all projects
|
|
157
|
-
- **Project-level**: `(project folder)/tdx.json` - Project-specific profiles
|
|
158
|
-
|
|
159
|
-
**Credentials:**
|
|
160
|
-
Store API keys separately from profiles:
|
|
161
|
-
```
|
|
162
|
-
~/.config/tdx/
|
|
163
|
-
├── tdx.json # User-level profiles
|
|
164
|
-
├── .env.production # Production credentials
|
|
165
|
-
└── .env.dev # Development credentials
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
**Example credential file** (`~/.config/tdx/.env.production`):
|
|
169
|
-
```
|
|
170
|
-
TD_API_KEY=1234/abcdefg...
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
**Profile Precedence:**
|
|
174
|
-
1. Project `tdx.json` profiles (local)
|
|
175
|
-
2. User `~/.config/tdx/tdx.json` profiles (user-level)
|
|
176
|
-
3. Directory-based profiles (deprecated)
|
|
177
|
-
|
|
178
|
-
**Note:** The `description` field is optional but recommended for documenting what each profile is for.
|
|
179
|
-
|
|
180
|
-
### Session Context
|
|
181
|
-
|
|
182
|
-
Set temporary overrides for the current shell session:
|
|
183
|
-
|
|
184
|
-
```bash
|
|
185
|
-
# Set session database
|
|
186
|
-
tdx use database mydb
|
|
187
|
-
|
|
188
|
-
# Set session LLM project
|
|
189
|
-
tdx use llm_project Analytics
|
|
190
|
-
|
|
191
|
-
# View current context
|
|
192
|
-
tdx context
|
|
193
|
-
|
|
194
|
-
# Clear session context
|
|
195
|
-
tdx context --clear
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
**How Session Scope Works:**
|
|
199
|
-
|
|
200
|
-
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:
|
|
201
|
-
|
|
202
|
-
- **Automatic isolation**: Each terminal window maintains its own independent session context
|
|
203
|
-
- **No manual setup**: Sessions are created automatically when you run `tdx use` commands
|
|
204
|
-
- **Persistent within shell**: Context persists across multiple commands in the same terminal
|
|
205
|
-
- **Automatic cleanup**: Sessions expire after 24 hours or when the shell is closed
|
|
206
|
-
|
|
207
|
-
**Example:**
|
|
208
|
-
```bash
|
|
209
|
-
# Terminal Window 1
|
|
210
|
-
tdx use database analytics
|
|
211
|
-
tdx tables # Uses database: analytics
|
|
212
|
-
|
|
213
|
-
# Terminal Window 2 (different PID)
|
|
214
|
-
tdx tables # Uses default database (separate session)
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
Session context persists until the shell is closed or explicitly cleared with `tdx context --clear`.
|
|
218
|
-
|
|
219
|
-
**Note:** For advanced session sharing across multiple processes or shells, see [Session ID Option](#session-id-option) in the Advanced Options section.
|
|
220
|
-
|
|
221
|
-
### Project Config
|
|
222
|
-
|
|
223
|
-
Store per-project defaults in `tdx.json` at your project root:
|
|
224
|
-
|
|
225
|
-
```json
|
|
226
|
-
{
|
|
227
|
-
"database": "customer_analytics",
|
|
228
|
-
"parent_segment": "active_users",
|
|
229
|
-
"llm_project": "CustomerInsights"
|
|
230
|
-
}
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
**Available Configuration Parameters:**
|
|
234
|
-
|
|
235
|
-
| Parameter | Type | Description | Example |
|
|
236
|
-
|-----------|------|-------------|---------|
|
|
237
|
-
| `description` | string | Optional description of the configuration | `"Production environment"` |
|
|
238
|
-
| `site` | string | TD site/region (us01, jp01, eu01, ap02) | `"us01"` |
|
|
239
|
-
| `database` | string | Default database for queries and table commands | `"analytics"` |
|
|
240
|
-
| `parent_segment` | string | Default parent segment for CDP commands | `"active_users"` |
|
|
241
|
-
| `llm_project` | string | Default LLM project for agent commands | `"DataAnalytics"` |
|
|
242
|
-
|
|
243
|
-
**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.
|
|
244
|
-
|
|
245
|
-
### View Context
|
|
246
|
-
|
|
247
|
-
See the currently resolved context and where each value comes from:
|
|
248
|
-
|
|
249
|
-
```bash
|
|
250
|
-
# Show current context
|
|
251
|
-
tdx context
|
|
252
|
-
|
|
253
|
-
# Show context with sources (debugging)
|
|
254
|
-
tdx context --debug
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
Example output:
|
|
258
|
-
```
|
|
259
|
-
[context]
|
|
260
|
-
site: us01 (global: ~/.config/tdx/tdx.json)
|
|
261
|
-
database: analytics (session)
|
|
262
|
-
llm_project: DataAnalytics (profile: production)
|
|
263
|
-
profile: production (session)
|
|
264
|
-
|
|
265
|
-
Configuration Files:
|
|
266
|
-
Session: /Users/user/.config/tdx/sessions/12345.json ✓
|
|
267
|
-
Global: /Users/user/.config/tdx/tdx.json ✓
|
|
268
|
-
Project: /Users/user/projects/myproject/tdx.json ✓
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
## Available Commands
|
|
272
|
-
|
|
273
|
-
```bash
|
|
274
|
-
tdx <command> [options] [arguments]
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
### Global Options
|
|
278
|
-
|
|
279
|
-
Available for all commands:
|
|
280
|
-
|
|
281
|
-
- `--site <site>`: TD site/region (us01, jp01, eu01, ap02) - default: us01
|
|
282
|
-
- `--format <format>`: Output format (table, json, jsonl, tsv) - default: table
|
|
283
|
-
- `--json`: Output in JSON format (shorthand for --format json)
|
|
284
|
-
- `--jsonl`: Output in JSON Lines format (shorthand for --format jsonl)
|
|
285
|
-
- `--tsv`: Output in TSV format (shorthand for --format tsv)
|
|
286
|
-
- `--output <file>`: Save output to file
|
|
287
|
-
- `--limit <rows>`: Maximum rows to display in table format - default: 40
|
|
288
|
-
- `--color`: Force ANSI color output (overrides TTY detection)
|
|
289
|
-
- `--no-color`: Disable ANSI color output (also respects NO_COLOR env var)
|
|
290
|
-
- `-v, --verbose`: Enable verbose logging
|
|
291
|
-
- `--timeout <seconds>`: Set operation timeout - default: 30
|
|
292
|
-
- `--dry-run`: Preview operation without executing
|
|
293
|
-
- `-y, --yes`: Skip confirmation prompts
|
|
294
|
-
|
|
295
|
-
**Note:** Shorthand flags (--json, --jsonl, --tsv) are only applied when --format is not explicitly specified. If both are provided, --format is used.
|
|
296
|
-
|
|
297
|
-
### Interactive Table Navigation
|
|
298
|
-
|
|
299
|
-
When viewing table output in an interactive terminal, `tdx` automatically pipes the output through `less` for easy navigation of large datasets. This allows you to:
|
|
300
|
-
|
|
301
|
-
- View all rows without truncation (unlimited data display)
|
|
302
|
-
- Scroll through wide tables without column truncation
|
|
303
|
-
- Search and navigate efficiently
|
|
304
|
-
|
|
305
|
-
**Keyboard shortcuts in less:**
|
|
306
|
-
|
|
307
|
-
| Key | Action |
|
|
308
|
-
|-----|--------|
|
|
309
|
-
| `q` | Quit and return to terminal |
|
|
310
|
-
| `↑` / `↓` | Scroll up/down one line |
|
|
311
|
-
| `Space` / `Page Down` | Scroll down one page |
|
|
312
|
-
| `b` / `Page Up` | Scroll up one page |
|
|
313
|
-
| `←` / `→` | Scroll left/right (for wide tables) |
|
|
314
|
-
| `/pattern` | Search forward for pattern |
|
|
315
|
-
| `?pattern` | Search backward for pattern |
|
|
316
|
-
| `n` | Repeat previous search forward |
|
|
317
|
-
| `N` | Repeat previous search backward |
|
|
318
|
-
| `g` | Go to first line |
|
|
319
|
-
| `G` | Go to last line |
|
|
320
|
-
| `h` | Show help |
|
|
321
|
-
|
|
322
|
-
**Note:** Less pagination is automatically enabled for table format output in interactive terminals. It's disabled when:
|
|
323
|
-
- Output is piped to another command
|
|
324
|
-
- Output is saved to a file with `--output`
|
|
325
|
-
- Using non-table formats (JSON, JSONL, TSV)
|
|
326
|
-
|
|
327
|
-
### Auth Commands
|
|
328
|
-
|
|
329
|
-
Set up and manage authentication for Treasure Data.
|
|
330
|
-
|
|
331
|
-
| Command | Description | Example |
|
|
332
|
-
|---------|-------------|---------|
|
|
333
|
-
| `auth setup` | Interactive API key setup (recommended) | `tdx auth setup` |
|
|
334
|
-
| `auth setup --site <site>` | Setup for specific site | `tdx auth setup --site jp01` |
|
|
335
|
-
| `auth setup --profile <name>` | Setup profile-specific auth | `tdx auth setup --profile work` |
|
|
336
|
-
| `auth` | Check authentication status and validate | `tdx auth` |
|
|
337
|
-
|
|
338
|
-
**Examples:**
|
|
339
|
-
```bash
|
|
340
|
-
# Interactive setup (recommended)
|
|
341
|
-
tdx auth setup
|
|
342
|
-
|
|
343
|
-
# Setup for Japan site
|
|
344
|
-
tdx auth setup --site jp01
|
|
345
|
-
|
|
346
|
-
# Setup work profile with EU site
|
|
347
|
-
tdx auth setup --profile work --site eu01
|
|
348
|
-
|
|
349
|
-
# Check authentication status
|
|
350
|
-
tdx auth
|
|
351
|
-
|
|
352
|
-
# Check status for specific site
|
|
353
|
-
tdx auth --site jp01
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
**What `tdx auth setup` does:**
|
|
357
|
-
- Guides you through site selection (arrow keys navigation)
|
|
358
|
-
- Securely prompts for API key (hidden input with password masking)
|
|
359
|
-
- **Validates API key** before saving (prevents invalid keys)
|
|
360
|
-
- Saves to `~/.config/tdx/.env` or `.env.{profile}` for profiles
|
|
361
|
-
- Registers profile metadata in `tdx.json` (when using `--profile`)
|
|
362
|
-
- ESC or Ctrl+C to cancel anytime
|
|
363
|
-
|
|
364
|
-
**Features:**
|
|
365
|
-
- 🔒 Secure password-masked input
|
|
366
|
-
- ✅ API key validation before saving
|
|
367
|
-
- 🎯 Arrow key navigation for site selection
|
|
368
|
-
- ⚡ Pre-selects site from `--site` flag
|
|
369
|
-
- 📋 Profile support with metadata tracking
|
|
370
|
-
|
|
371
|
-
### Chat Commands (Quick AI Interaction)
|
|
372
|
-
|
|
373
|
-
Simplified top-level command for chatting with LLM agents.
|
|
374
|
-
|
|
375
|
-
| Command | Description | Example |
|
|
376
|
-
|---------|-------------|---------|
|
|
377
|
-
| `chat <message>` | Chat (continues last session by default) | `tdx chat "Analyze my data"` |
|
|
378
|
-
| `chat <message> --agent <name>` | Chat with specific agent | `tdx chat "Hello" --agent "Data Analyst"` |
|
|
379
|
-
| `chat <message> --model <name>` | Chat using specific model or alias (haiku, sonnet) | `tdx chat "Help" --model "haiku"` |
|
|
380
|
-
| `chat <message> --temperature <n>` | Set temperature (0.0-2.0, default: 0.7) | `tdx chat "Be creative" --temperature 1.2` |
|
|
381
|
-
| `chat <message> --new` | Start a new chat session | `tdx chat --new "Fresh conversation"` |
|
|
382
|
-
|
|
383
|
-
**Examples**:
|
|
384
|
-
```bash
|
|
385
|
-
# Simple chat (uses default agent with claude-4.5-haiku)
|
|
386
|
-
tdx chat "Show me the top customers by revenue"
|
|
387
|
-
|
|
388
|
-
# Continue previous conversation (default behavior)
|
|
389
|
-
tdx chat "What about last quarter?"
|
|
390
|
-
|
|
391
|
-
# Start a new conversation
|
|
392
|
-
tdx chat --new "Tell me about data modeling best practices"
|
|
393
|
-
|
|
394
|
-
# Use model aliases for quick access
|
|
395
|
-
tdx chat "Quick question" --model "haiku" # Uses claude-4.5-haiku
|
|
396
|
-
tdx chat "Analyze this" --model "sonnet" # Uses claude-4.5-sonnet
|
|
397
|
-
|
|
398
|
-
# Use full model name
|
|
399
|
-
tdx chat "Help me write SQL" --model "claude-4.5-opus"
|
|
400
|
-
|
|
401
|
-
# Use specific agent by name (uses current project context)
|
|
402
|
-
tdx llm use "MyProject"
|
|
403
|
-
tdx chat "Analyze churn" --agent "Data Analyst"
|
|
404
|
-
|
|
405
|
-
# Override project for agent lookup
|
|
406
|
-
tdx chat "Hello" --agent "Analyst" --llm-project "OtherProject"
|
|
407
|
-
|
|
408
|
-
# Adjust temperature
|
|
409
|
-
tdx chat "Write a poem" --temperature 1.5
|
|
410
|
-
|
|
411
|
-
# Verbose mode shows chat session ID
|
|
412
|
-
tdx chat "Hello" --verbose
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
**How it works**:
|
|
416
|
-
- **Default behavior**: Continues last chat session automatically
|
|
417
|
-
- **Session persistence**: Last chat ID saved to `.cache/tdx/last_chat_id`
|
|
418
|
-
- **--new flag**: Starts a fresh chat session
|
|
419
|
-
- **--agent**: Use specific agent by name (resolves using project context)
|
|
420
|
-
- **--model**: Auto-creates/reuses agent per model (supports aliases: `haiku` → `claude-4.5-haiku`, `sonnet` → `claude-4.5-sonnet`)
|
|
421
|
-
- **--temperature**: Controls randomness (0.7 default, lower=focused, higher=creative)
|
|
422
|
-
|
|
423
|
-
### Database Commands
|
|
424
|
-
|
|
425
|
-
| Command | Description | Example |
|
|
426
|
-
|---------|-------------|---------|
|
|
427
|
-
| `databases` | List all databases | `tdx databases` |
|
|
428
|
-
| | Filter by pattern (glob/wildcards) | `tdx databases "prod_*"` or `tdx databases "*_analytics"` |
|
|
429
|
-
|
|
430
|
-
### Table Commands
|
|
431
|
-
|
|
432
|
-
All table commands use dot-separated patterns: `(database).(table)`
|
|
433
|
-
|
|
434
|
-
| Command | Description | Example |
|
|
435
|
-
|---------|-------------|---------|
|
|
436
|
-
| `tables` | List all tables from all databases | `tdx tables` |
|
|
437
|
-
| | List all tables from specific database | `tdx tables "mydb.*"` or `tdx tables --in mydb` |
|
|
438
|
-
| | List tables from database (--database flag) | `tdx tables --database mydb` |
|
|
439
|
-
| | Filter tables with pattern | `tdx tables "mydb.user_*"` |
|
|
440
|
-
| | Database pattern with table | `tdx tables "prod_*.access_log"` |
|
|
441
|
-
| | Wildcard database and table | `tdx tables "*.user*"` |
|
|
442
|
-
| | All tables from all databases | `tdx tables "*.*"` |
|
|
443
|
-
| `describe <table>` (alias: `desc`) | Show table schema | `tdx describe mydb.users` |
|
|
444
|
-
| | Using --in or --database flag | `tdx describe users --in mydb` or `tdx describe users -d mydb` |
|
|
445
|
-
| `show <table>` | Show table contents (SELECT * with limit) | `tdx show mydb.users` |
|
|
446
|
-
| | With custom row limit | `tdx show mydb.users --limit 10` |
|
|
447
|
-
| | With explicit catalog | `tdx show td.mydb.users --limit 5` |
|
|
448
|
-
| | Using --in or --database flag | `tdx show users --in mydb` or `tdx show users -d mydb` |
|
|
449
|
-
|
|
450
|
-
**Pattern syntax:**
|
|
451
|
-
- Database wildcard: `"mydb.*"` → all tables from mydb (use this or `--database mydb`)
|
|
452
|
-
- Database.table: `mydb.users` → specific table
|
|
453
|
-
- Wildcards: `"*.users"`, `"prod_*.user*"` → pattern matching
|
|
454
|
-
- Catalog: `"td.mydb.users"` → with catalog prefix
|
|
455
|
-
|
|
456
|
-
**Table-specific options:**
|
|
457
|
-
- `-d, --database <database>`: Specify database name when not included in pattern
|
|
458
|
-
- `--in <database>`: Alias for `--database` (natural language style)
|
|
459
|
-
|
|
460
|
-
**Alternative syntax for specifying database:**
|
|
461
|
-
|
|
462
|
-
There are multiple ways to specify the database for table commands:
|
|
463
|
-
|
|
464
|
-
```bash
|
|
465
|
-
# Using dot notation (recommended for patterns)
|
|
466
|
-
tdx tables "mydb.*"
|
|
467
|
-
|
|
468
|
-
# Using --in flag (natural language style, no quotes needed)
|
|
469
|
-
tdx tables --in mydb
|
|
470
|
-
|
|
471
|
-
# Using --database flag (or -d shorthand)
|
|
472
|
-
tdx tables --database mydb
|
|
473
|
-
tdx tables -d mydb
|
|
474
|
-
|
|
475
|
-
# All three are equivalent for listing all tables from a database
|
|
476
|
-
|
|
477
|
-
# Works with describe and show commands too
|
|
478
|
-
tdx describe users --in mydb
|
|
479
|
-
tdx show users --in mydb
|
|
480
|
-
|
|
481
|
-
# List tables matching pattern from "mydb"
|
|
482
|
-
tdx tables "user*" --in mydb
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
**Note:** If the pattern already includes a database (e.g., `mydb.users`), the `--database` option is ignored:
|
|
486
|
-
|
|
487
|
-
```bash
|
|
488
|
-
# Uses "mydb" from pattern, ignores --database option
|
|
489
|
-
tdx tables mydb.users --database other
|
|
490
|
-
# Result: Lists users table from mydb, not other
|
|
491
|
-
```
|
|
492
|
-
|
|
493
|
-
### Query Commands
|
|
494
|
-
|
|
495
|
-
Usage: `tdx query [options] [sql]`
|
|
496
|
-
|
|
497
|
-
| Option/Usage | Description | Example |
|
|
498
|
-
|--------------|-------------|---------|
|
|
499
|
-
| `<sql>` | Execute SQL query | `tdx query "SELECT * FROM table"` |
|
|
500
|
-
| `-f, --file <path>` | Execute SQL from file | `tdx query -f query.sql` |
|
|
501
|
-
| Multi-statement | Execute multiple statements (CLI or file) | `tdx query "SELECT 1; SELECT 2"` |
|
|
502
|
-
| | Multi-statement from file | `tdx query -f setup-and-query.sql` |
|
|
503
|
-
|
|
504
|
-
**Query-specific options**:
|
|
505
|
-
- `-f, --file <path>`: Read SQL from file
|
|
506
|
-
- `-d, --database <db>`: Database to query (default: information_schema)
|
|
507
|
-
- `--in <db>`: Alias for `--database` (natural language style)
|
|
508
|
-
- `--catalog <catalog>`: Trino catalog (default: td)
|
|
509
|
-
|
|
510
|
-
**Examples**:
|
|
511
|
-
```bash
|
|
512
|
-
# Query with --in flag
|
|
513
|
-
tdx query "SELECT * FROM users" --in mydb
|
|
514
|
-
|
|
515
|
-
# Equivalent to --database
|
|
516
|
-
tdx query "SELECT * FROM users" --database mydb
|
|
517
|
-
tdx query "SELECT * FROM users" -d mydb
|
|
518
|
-
```
|
|
519
|
-
|
|
520
|
-
### Job Commands
|
|
521
|
-
|
|
522
|
-
Manage and execute Treasure Data jobs (queries).
|
|
523
|
-
|
|
524
|
-
**List jobs**:
|
|
525
|
-
```bash
|
|
526
|
-
# List jobs (default: 40 jobs)
|
|
527
|
-
tdx jobs
|
|
528
|
-
|
|
529
|
-
# List more jobs with --limit
|
|
530
|
-
tdx jobs --limit 100
|
|
531
|
-
|
|
532
|
-
# Filter by status
|
|
533
|
-
tdx jobs --status running
|
|
534
|
-
tdx jobs --status success
|
|
535
|
-
tdx jobs --status error
|
|
536
|
-
tdx jobs --status queued
|
|
537
|
-
|
|
538
|
-
# Combine filters
|
|
539
|
-
tdx jobs --status running --limit 50
|
|
540
|
-
|
|
541
|
-
# Output as JSON
|
|
542
|
-
tdx jobs --format json
|
|
543
|
-
```
|
|
544
|
-
|
|
545
|
-
**Show job details**:
|
|
546
|
-
```bash
|
|
547
|
-
# Show job details
|
|
548
|
-
tdx job show <job-id>
|
|
549
|
-
|
|
550
|
-
# Show job as JSON
|
|
551
|
-
tdx job show <job-id> --format json
|
|
552
|
-
```
|
|
553
|
-
|
|
554
|
-
**Kill a job**:
|
|
555
|
-
```bash
|
|
556
|
-
# Kill a job (with confirmation)
|
|
557
|
-
tdx job kill <job-id>
|
|
558
|
-
|
|
559
|
-
# Skip confirmation prompt
|
|
560
|
-
tdx job kill <job-id> --yes
|
|
561
|
-
```
|
|
562
|
-
|
|
563
|
-
**Submit jobs**:
|
|
564
|
-
```bash
|
|
565
|
-
# Submit Trino query (default)
|
|
566
|
-
tdx job submit "SELECT * FROM mydb.table LIMIT 10"
|
|
567
|
-
|
|
568
|
-
# Submit with specific database
|
|
569
|
-
tdx job submit "SELECT * FROM table" --database mydb
|
|
570
|
-
|
|
571
|
-
# Submit Hive query from file
|
|
572
|
-
tdx job submit --job-type hive -f query.sql --database mydb
|
|
573
|
-
|
|
574
|
-
# Submit without specifying database (uses information_schema by default)
|
|
575
|
-
tdx job submit "SELECT 1"
|
|
576
|
-
```
|
|
577
|
-
|
|
578
|
-
**Get job results**:
|
|
579
|
-
```bash
|
|
580
|
-
# Get job results (table format)
|
|
581
|
-
tdx job result <job-id>
|
|
582
|
-
|
|
583
|
-
# Get results as JSON
|
|
584
|
-
tdx job result <job-id> --format json
|
|
585
|
-
|
|
586
|
-
# Save results to file
|
|
587
|
-
tdx job result <job-id> --output results.json
|
|
588
|
-
|
|
589
|
-
# Get results as TSV
|
|
590
|
-
tdx job result <job-id> --format tsv
|
|
591
|
-
```
|
|
592
|
-
|
|
593
|
-
**Job Command Options**:
|
|
594
|
-
- `--job-type <type>`: Job type - `trino` (default) or `hive`
|
|
595
|
-
- `-f, --file <path>`: Read query from file
|
|
596
|
-
- `--database <name>`: Database name (default: `information_schema`)
|
|
597
|
-
- `--status <status>`: Filter by job status - `queued`, `running`, `success`, or `error` (for `jobs` list)
|
|
598
|
-
- `--limit <number>`: Maximum number of jobs to list (default: 40, for `jobs` list)
|
|
599
|
-
|
|
600
|
-
### Segment Commands (CDP)
|
|
601
|
-
|
|
602
|
-
Usage: `tdx segment <subcommand> [options] [arguments]`
|
|
603
|
-
|
|
604
|
-
CDP (Customer Data Platform) segment management for audiences and activations with file-system-like navigation.
|
|
605
|
-
|
|
606
|
-
**Path Format:**
|
|
607
|
-
- Parent segment: `"My Audience"`
|
|
608
|
-
- Child segment: `"My Audience/High Value Users"`
|
|
609
|
-
- Nested folders: `"My Audience/Marketing/Campaigns/Email Q1"`
|
|
610
|
-
- Pattern matching: `"*DEMO"`, `"test*"`, `"*audience*"`
|
|
611
|
-
- **Note**: Names are case-sensitive
|
|
612
|
-
|
|
613
|
-
**Navigation Model:**
|
|
614
|
-
- Set context: `tdx segment use <path>` - Navigate into a parent or folder
|
|
615
|
-
- Show context: `tdx segment pwd` - Display current location
|
|
616
|
-
- List contents: `tdx segments` - Show folders + segments in current context
|
|
617
|
-
- All commands support both absolute paths and relative paths from context
|
|
618
|
-
|
|
619
|
-
#### Navigation Commands
|
|
620
|
-
|
|
621
|
-
| Command | Description | Example |
|
|
622
|
-
|---------|-------------|---------|
|
|
623
|
-
| `segment use <path>` | Set current context to parent or folder | `tdx segment use "My Audience/Marketing"` |
|
|
624
|
-
| `segment pwd` | Show current context path | `tdx segment pwd` |
|
|
625
|
-
| `segment use /` | Clear context (back to root) | `tdx segment use /` |
|
|
626
|
-
| `segment use ..` | Navigate to parent folder | `tdx segment use ..` |
|
|
627
|
-
|
|
628
|
-
#### Discovery Commands
|
|
629
|
-
|
|
630
|
-
| Command | Description | Example |
|
|
631
|
-
|---------|-------------|---------|
|
|
632
|
-
| `segments` | List contents in current context (or all parents if no context) | `tdx segments` |
|
|
633
|
-
| `segments <path>` | List folders + segments at specified path | `tdx segments "My Audience/Marketing"` |
|
|
634
|
-
| `segments <pattern>` | List parents matching pattern (glob) | `tdx segments "*DEMO"` |
|
|
635
|
-
| `segments -r` | List recursively (tree view) | `tdx segments -r` |
|
|
636
|
-
| `segments <path> -r` | Recursive tree from path | `tdx segments "My Audience" -r` |
|
|
637
|
-
| `segment describe <path>` | Show details (parent/folder/segment) | `tdx segment describe "My Audience/Marketing"` |
|
|
638
|
-
| `segment show <path>` | Execute segment SQL query and show results | `tdx segment show "My Audience/Premium Users"` |
|
|
639
|
-
| `segment sql <path>` | Get SQL query for segment | `tdx segment sql "My Audience/Marketing/Premium"` |
|
|
640
|
-
| `segment fields <parent>` | List available fields for segmentation | `tdx segment fields "My Audience"` |
|
|
641
|
-
|
|
642
|
-
#### Management Commands
|
|
643
|
-
|
|
644
|
-
| Command | Description | Example |
|
|
645
|
-
|---------|-------------|---------|
|
|
646
|
-
| `segment parent create <name>` | Create new parent segment (audience) | `tdx segment parent create "Customer 360" --database mydb --table customers` |
|
|
647
|
-
| `segment parent update <name>` | Update existing parent segment | `tdx segment parent update "Customer 360" --description "Updated"` |
|
|
648
|
-
| `segment create <path>` | Create child segment with filtering (supports nested paths) | `tdx segment create "My Audience/Marketing/Premium" --rule-file rule.json` |
|
|
649
|
-
| `segment update <path>` | Update child segment (supports nested paths) | `tdx segment update "My Audience/Marketing/Premium" --description "Updated"` |
|
|
650
|
-
| `segment folder create <parent> <folder>` | Create segment folder | `tdx segment folder create "My Audience" "Q1 2024"` |
|
|
651
|
-
|
|
652
|
-
#### Discovery Examples
|
|
653
|
-
|
|
654
|
-
**Navigation Workflow:**
|
|
655
|
-
|
|
656
|
-
```bash
|
|
657
|
-
# List all parent segments
|
|
658
|
-
tdx segments
|
|
659
|
-
# Output:
|
|
660
|
-
# [parent segments]
|
|
661
|
-
# 👥 My Audience (50K)
|
|
662
|
-
# 👥 Sales Leads (12.5K)
|
|
663
|
-
|
|
664
|
-
# Pattern matching for parents
|
|
665
|
-
tdx segments "*DEMO"
|
|
666
|
-
# Output:
|
|
667
|
-
# [parent segments]
|
|
668
|
-
# 👥 TREASUREBIKES DEMO (3.28K)
|
|
669
|
-
# 👥 TEST DEMO (1.5K)
|
|
670
|
-
|
|
671
|
-
# Navigate into a parent
|
|
672
|
-
tdx segment use "My Audience"
|
|
673
|
-
|
|
674
|
-
# List folders + segments in current context (unified view)
|
|
675
|
-
tdx segments
|
|
676
|
-
# Output:
|
|
677
|
-
# [/My Audience]
|
|
678
|
-
# 📁 Marketing
|
|
679
|
-
# 📁 Sales
|
|
680
|
-
# 🎯 Active Users (35K)
|
|
681
|
-
# 🎯 All Users (50K)
|
|
682
|
-
|
|
683
|
-
# Recursive tree view from current context
|
|
684
|
-
tdx segments -r
|
|
685
|
-
# Output:
|
|
686
|
-
# [/My Audience]
|
|
687
|
-
# 📁 Marketing
|
|
688
|
-
# ├── 📁 Campaigns
|
|
689
|
-
# │ ├── 🎯 Email Q1 (5.23K)
|
|
690
|
-
# │ └── 🎯 Email Q2 (6.12K)
|
|
691
|
-
# └── 🎯 Email Subscribers (15K)
|
|
692
|
-
# 🎯 Active Users (35K)
|
|
693
|
-
|
|
694
|
-
# Navigate to nested folder
|
|
695
|
-
tdx segment use "My Audience/Marketing/Campaigns"
|
|
696
|
-
tdx segment pwd
|
|
697
|
-
# Output: My Audience/Marketing/Campaigns
|
|
698
|
-
|
|
699
|
-
# List specific path without changing context
|
|
700
|
-
tdx segments "My Audience/Marketing"
|
|
701
|
-
tdx segments "My Audience" -r # Recursive from specific path
|
|
702
|
-
|
|
703
|
-
# Show details using absolute paths
|
|
704
|
-
tdx segment describe "My Audience/Marketing/Campaigns"
|
|
705
|
-
tdx segment describe "My Audience/High Value Users"
|
|
706
|
-
|
|
707
|
-
# Show details using relative paths (from context)
|
|
708
|
-
tdx segment use "My Audience/Marketing"
|
|
709
|
-
tdx segment describe "Campaigns" # Relative to Marketing
|
|
710
|
-
|
|
711
|
-
# Execute queries with paths
|
|
712
|
-
tdx segment show "My Audience/Premium Users" --limit 100
|
|
713
|
-
tdx segment sql "My Audience/Marketing/Email Subscribers" > query.sql
|
|
714
|
-
|
|
715
|
-
# List available fields for parent
|
|
716
|
-
tdx segment fields "My Audience"
|
|
717
|
-
```
|
|
718
|
-
|
|
719
|
-
#### Management Examples
|
|
720
|
-
|
|
721
|
-
**Create Parent Segment (Audience):**
|
|
722
|
-
|
|
723
|
-
```bash
|
|
724
|
-
# Create minimal parent segment
|
|
725
|
-
tdx segment parent create "Customer 360" \
|
|
726
|
-
--database customer_data \
|
|
727
|
-
--table customers \
|
|
728
|
-
--description "Complete customer view"
|
|
729
|
-
|
|
730
|
-
# Create with attributes from file
|
|
731
|
-
tdx segment parent create "Customer 360" \
|
|
732
|
-
--database customer_data \
|
|
733
|
-
--table customers \
|
|
734
|
-
--attributes-file examples/parent-segment-attributes.json \
|
|
735
|
-
--behaviors-file examples/parent-segment-behaviors.json
|
|
736
|
-
|
|
737
|
-
# Create with scheduling
|
|
738
|
-
tdx segment parent create "Customer 360" \
|
|
739
|
-
--database customer_data \
|
|
740
|
-
--table customers \
|
|
741
|
-
--schedule-type daily \
|
|
742
|
-
--schedule-option "03:00" \
|
|
743
|
-
--timezone "America/Los_Angeles"
|
|
744
|
-
```
|
|
745
|
-
|
|
746
|
-
**Update Parent Segment:**
|
|
747
|
-
|
|
748
|
-
```bash
|
|
749
|
-
# Update description
|
|
750
|
-
tdx segment parent update "Customer 360" \
|
|
751
|
-
--description "Updated customer view"
|
|
752
|
-
|
|
753
|
-
# Add new attributes
|
|
754
|
-
tdx segment parent update "Customer 360" \
|
|
755
|
-
--add-attributes-file new-attributes.json
|
|
756
|
-
|
|
757
|
-
# Update schedule
|
|
758
|
-
tdx segment parent update "Customer 360" \
|
|
759
|
-
--schedule-type weekly \
|
|
760
|
-
--schedule-option "0" # Sunday
|
|
761
|
-
```
|
|
762
|
-
|
|
763
|
-
**Create Child Segment with Filtering:**
|
|
764
|
-
|
|
765
|
-
```bash
|
|
766
|
-
# Create segment with simple rule (inline JSON)
|
|
767
|
-
tdx segment create "My Audience/High Value" \
|
|
768
|
-
--description "Customers with LTV > $1000" \
|
|
769
|
-
--rule '{"type":"And","conditions":[{"type":"Value","leftValue":{"name":"Lifetime Value"},"operator":{"type":"Greater","rightValue":1000}}]}'
|
|
770
|
-
|
|
771
|
-
# Create segment with complex rule (from file)
|
|
772
|
-
tdx segment create "My Audience/High Value US" \
|
|
773
|
-
--description "High value US customers" \
|
|
774
|
-
--rule-file examples/segment-rule-complex.json
|
|
775
|
-
|
|
776
|
-
# Create segment in folder
|
|
777
|
-
tdx segment create "My Audience/Premium" \
|
|
778
|
-
--rule-file examples/segment-rule-simple.json \
|
|
779
|
-
--folder "Geographic Segments"
|
|
780
|
-
|
|
781
|
-
# Create realtime segment
|
|
782
|
-
tdx segment create "My Audience/Realtime Active" \
|
|
783
|
-
--rule-file rule.json \
|
|
784
|
-
--kind 1 # 0=batch, 1=realtime, 2=funnel_stage
|
|
785
|
-
```
|
|
786
|
-
|
|
787
|
-
**Update Child Segment:**
|
|
788
|
-
|
|
789
|
-
```bash
|
|
790
|
-
# Update segment name
|
|
791
|
-
tdx segment update "My Audience/High Value" \
|
|
792
|
-
--name "Super High Value"
|
|
793
|
-
|
|
794
|
-
# Update segment rule
|
|
795
|
-
tdx segment update "My Audience/High Value" \
|
|
796
|
-
--description "Updated criteria" \
|
|
797
|
-
--rule-file updated-rule.json
|
|
798
|
-
|
|
799
|
-
# Move segment to folder
|
|
800
|
-
tdx segment update "My Audience/High Value" \
|
|
801
|
-
--folder "Premium Customers"
|
|
802
|
-
```
|
|
803
|
-
|
|
804
|
-
**Create Folders:**
|
|
805
|
-
|
|
806
|
-
```bash
|
|
807
|
-
# Create top-level folder
|
|
808
|
-
tdx segment folder create "My Audience" "Q1 2024 Campaigns" \
|
|
809
|
-
--description "Campaign segments for Q1"
|
|
810
|
-
|
|
811
|
-
# Create nested folder
|
|
812
|
-
tdx segment folder create "My Audience" "West Region" \
|
|
813
|
-
--parent-folder "Geographic Segments"
|
|
41
|
+
# Launch Claude Code with TD LLM
|
|
42
|
+
tdx claude
|
|
814
43
|
```
|
|
815
44
|
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
See `examples/segment-rule-simple.json` and `examples/segment-rule-complex.json` for rule examples.
|
|
819
|
-
|
|
820
|
-
Supported operators:
|
|
821
|
-
- **Comparison**: Equal, NotEqual, Greater, GreaterEqual, Less, LessEqual
|
|
822
|
-
- **Set**: In, NotIn
|
|
823
|
-
- **Text**: Contains, StartsWith, EndsWith
|
|
824
|
-
- **Pattern**: Regex
|
|
825
|
-
- **Time**: TimeWithinPast
|
|
45
|
+
## Documentation
|
|
826
46
|
|
|
827
|
-
|
|
828
|
-
```json
|
|
829
|
-
{
|
|
830
|
-
"type": "And",
|
|
831
|
-
"conditions": [
|
|
832
|
-
{
|
|
833
|
-
"type": "Value",
|
|
834
|
-
"leftValue": {"name": "Lifetime Value"},
|
|
835
|
-
"operator": {"type": "Greater", "rightValue": 1000}
|
|
836
|
-
},
|
|
837
|
-
{
|
|
838
|
-
"type": "Value",
|
|
839
|
-
"leftValue": {"name": "Country"},
|
|
840
|
-
"operator": {"type": "In", "rightValues": ["US", "UK", "CA"]}
|
|
841
|
-
}
|
|
842
|
-
]
|
|
843
|
-
}
|
|
844
|
-
```
|
|
47
|
+
For detailed documentation, visit [https://tdx.treasuredata.com/](https://tdx.treasuredata.com/):
|
|
845
48
|
|
|
846
|
-
|
|
49
|
+
- [Getting Started Guide](https://tdx.treasuredata.com/guide/)
|
|
50
|
+
- [Authentication](https://tdx.treasuredata.com/guide/authentication)
|
|
51
|
+
- [Commands Reference](https://tdx.treasuredata.com/commands/)
|
|
52
|
+
- [Claude Code Integration](https://tdx.treasuredata.com/commands/claude)
|
|
53
|
+
- [TD Skills for Claude Code](https://tdx.treasuredata.com/guide/td-skills)
|
|
847
54
|
|
|
848
|
-
|
|
55
|
+
## Requirements
|
|
849
56
|
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
| `activations <parent_name/child_name>` | List activations for a child segment | `tdx activations "My Audience/Premium Users"` |
|
|
57
|
+
- **Node.js 22.0.0 or higher** (Node.js 24 Active LTS recommended)
|
|
58
|
+
- TD API key with appropriate permissions
|
|
853
59
|
|
|
854
|
-
|
|
855
|
-
```bash
|
|
856
|
-
# List activations for a child segment (slash notation with names)
|
|
857
|
-
tdx activations "My Audience/Premium Users"
|
|
60
|
+
## License
|
|
858
61
|
|
|
859
|
-
|
|
860
|
-
tdx activations "My Audience/High Value Users" --format json
|
|
62
|
+
Apache-2.0
|
|
861
63
|
|
|
862
|
-
|
|
863
|
-
tdx activations "My Audience/Premium Users" --site jp01
|
|
864
|
-
```
|
|
865
|
-
|
|
866
|
-
### Workflow Commands
|
|
867
|
-
|
|
868
|
-
Usage: `tdx workflow <subcommand>` (alias: `tdx wf`)
|
|
869
|
-
|
|
870
|
-
Manage Treasure Data workflows powered by Digdag. Monitor execution sessions, view logs, and control workflow attempts.
|
|
871
|
-
|
|
872
|
-
| Subcommand | Description | Example |
|
|
873
|
-
|------------|-------------|---------|
|
|
874
|
-
| `projects [pattern]` | List workflow projects (supports glob patterns) | `tdx wf projects` or `tdx wf projects "cdp_*"` |
|
|
875
|
-
| `workflows [project]` (alias: `ls`) | List workflows (filter by project, supports globs) | `tdx wf workflows` or `tdx wf workflows "lda*"` |
|
|
876
|
-
| `sessions [project]` | List workflow execution sessions | `tdx wf sessions` or `tdx wf sessions myproject` or `tdx wf sessions myproject.daily_etl` |
|
|
877
|
-
| `attempts [project]` | List workflow attempts | `tdx wf attempts` or `tdx wf attempts myproject` or `tdx wf attempts myproject.workflow` |
|
|
878
|
-
| `attempt <attempt-id>` | Show specific attempt details | `tdx wf attempt 67890` |
|
|
879
|
-
| `tasks <attempt-id>` | Show tasks for an attempt | `tdx wf tasks 67890` |
|
|
880
|
-
| `logs <attempt-id> <task-name>` | Show logs for a specific task | `tdx wf logs 67890 +step1` |
|
|
881
|
-
| `kill <attempt-id>` | Kill a running attempt | `tdx wf kill 67890` |
|
|
882
|
-
| `retry <session-id\|attempt-id>` | Retry a session or attempt | `tdx wf retry session:12345` or `tdx wf retry attempt:67890` |
|
|
883
|
-
| `download <project-name> [output-dir]` | Download workflow project from TD console | `tdx wf download myproject` or `tdx wf download myproject ./workflows` |
|
|
884
|
-
| `push [project-name-or-dir]` | Push workflow project to TD console (digdag-style) | `cd myproject && tdx wf push myproject` or `tdx wf push ./myproject` |
|
|
885
|
-
| `delete <project-name-or-id>` | Delete workflow project from TD console | `tdx wf delete myproject` or `tdx wf delete 12345` |
|
|
886
|
-
|
|
887
|
-
**Workflow-specific options:**
|
|
888
|
-
|
|
889
|
-
For `sessions` command:
|
|
890
|
-
- `--status <status>`: Filter by status (running, success, error, blocked, all)
|
|
891
|
-
- `--from <timestamp>`: Start time filter (ISO 8601 format)
|
|
892
|
-
- `--to <timestamp>`: End time filter (ISO 8601 format)
|
|
893
|
-
|
|
894
|
-
For `attempts` command:
|
|
895
|
-
- `--include-retried`: Include retried attempts in the output
|
|
896
|
-
|
|
897
|
-
For `tasks` command:
|
|
898
|
-
- `--include-subtasks`: Include subtasks in the output
|
|
899
|
-
|
|
900
|
-
For `logs` command:
|
|
901
|
-
- `--offset <number>`: Starting offset for logs (default: 0)
|
|
902
|
-
|
|
903
|
-
For `download` command:
|
|
904
|
-
- `--revision <revision>`: Download specific revision (default: latest)
|
|
905
|
-
|
|
906
|
-
For `push` command:
|
|
907
|
-
- `--name <name>`: Project name (default: directory name)
|
|
908
|
-
- `--revision <revision>`: Revision name (default: timestamp)
|
|
909
|
-
- `--skip-validation`: Skip validation of .dig files
|
|
910
|
-
|
|
911
|
-
For `kill` command:
|
|
912
|
-
- `--reason <text>`: Reason for killing the attempt
|
|
913
|
-
- `-y, --yes`: Skip confirmation prompt
|
|
914
|
-
|
|
915
|
-
For `retry` command:
|
|
916
|
-
- `--from-task <task>`: Resume from specific task (session retry only)
|
|
917
|
-
- `--resume-from <task>`: Resume from specific task (attempt retry only)
|
|
918
|
-
- `--params <json>`: Override parameters (JSON string or @file.json)
|
|
919
|
-
- `--force`: Force retry even if not failed (attempt retry only)
|
|
920
|
-
- `-y, --yes`: Skip confirmation prompt
|
|
921
|
-
|
|
922
|
-
**Examples**:
|
|
923
|
-
```bash
|
|
924
|
-
# List all workflow projects
|
|
925
|
-
tdx wf projects
|
|
926
|
-
|
|
927
|
-
# Filter projects by pattern
|
|
928
|
-
tdx wf projects "cdp_segment_*"
|
|
929
|
-
|
|
930
|
-
# List all workflows
|
|
931
|
-
tdx wf workflows
|
|
932
|
-
|
|
933
|
-
# List workflows for a specific project
|
|
934
|
-
tdx wf workflows myproject
|
|
935
|
-
|
|
936
|
-
# Filter workflows by project pattern
|
|
937
|
-
tdx wf workflows "lda*"
|
|
938
|
-
|
|
939
|
-
# List all workflow sessions
|
|
940
|
-
tdx wf sessions
|
|
941
|
-
|
|
942
|
-
# List sessions for a specific project
|
|
943
|
-
tdx wf sessions myproject
|
|
944
|
-
|
|
945
|
-
# List sessions for specific workflow
|
|
946
|
-
tdx wf sessions myproject.daily_etl
|
|
947
|
-
|
|
948
|
-
# Filter sessions by status
|
|
949
|
-
tdx wf sessions --status error
|
|
950
|
-
|
|
951
|
-
# Filter sessions by time range
|
|
952
|
-
tdx wf sessions --from "2025-01-01" --to "2025-01-31"
|
|
953
|
-
|
|
954
|
-
# List all attempts
|
|
955
|
-
tdx wf attempts
|
|
956
|
-
|
|
957
|
-
# List attempts for a project
|
|
958
|
-
tdx wf attempts myproject
|
|
959
|
-
|
|
960
|
-
# List attempts for a workflow
|
|
961
|
-
tdx wf attempts myproject.daily_etl
|
|
962
|
-
|
|
963
|
-
# Include retried attempts
|
|
964
|
-
tdx wf attempts --include-retried
|
|
965
|
-
|
|
966
|
-
# Show specific attempt details
|
|
967
|
-
tdx wf attempt 67890
|
|
968
|
-
|
|
969
|
-
# Show tasks for an attempt
|
|
970
|
-
tdx wf tasks 67890
|
|
971
|
-
|
|
972
|
-
# Show tasks including subtasks
|
|
973
|
-
tdx wf tasks 67890 --include-subtasks
|
|
974
|
-
|
|
975
|
-
# View logs for a specific task
|
|
976
|
-
tdx wf logs 67890 +step1
|
|
977
|
-
|
|
978
|
-
# View logs with pagination
|
|
979
|
-
tdx wf logs 67890 +step1 --offset 100 --limit 500
|
|
980
|
-
|
|
981
|
-
# Kill a running attempt (with confirmation)
|
|
982
|
-
tdx wf kill 67890
|
|
983
|
-
|
|
984
|
-
# Kill with reason and skip confirmation
|
|
985
|
-
tdx wf kill 67890 --reason "manual stop" -y
|
|
986
|
-
|
|
987
|
-
# Retry entire session
|
|
988
|
-
tdx wf retry session:12345
|
|
989
|
-
|
|
990
|
-
# Retry session from specific task
|
|
991
|
-
tdx wf retry session:12345 --from-task +step2
|
|
992
|
-
|
|
993
|
-
# Retry attempt
|
|
994
|
-
tdx wf retry attempt:67890
|
|
995
|
-
|
|
996
|
-
# Retry attempt from specific task
|
|
997
|
-
tdx wf retry attempt:67890 --resume-from +step2
|
|
998
|
-
|
|
999
|
-
# Retry with parameter override
|
|
1000
|
-
tdx wf retry attempt:67890 --params '{"key":"value"}'
|
|
1001
|
-
|
|
1002
|
-
# Retry with params from file
|
|
1003
|
-
tdx wf retry attempt:67890 --params @params.json
|
|
1004
|
-
|
|
1005
|
-
# Force retry without confirmation
|
|
1006
|
-
tdx wf retry attempt:67890 --force -y
|
|
1007
|
-
|
|
1008
|
-
# Download workflow project
|
|
1009
|
-
tdx wf download myproject
|
|
1010
|
-
|
|
1011
|
-
# Download to specific directory
|
|
1012
|
-
tdx wf download myproject ./workflows
|
|
1013
|
-
|
|
1014
|
-
# Download specific revision
|
|
1015
|
-
tdx wf download myproject --revision v1.0.0
|
|
1016
|
-
|
|
1017
|
-
# Push workflow project (digdag-style: cd into project directory first)
|
|
1018
|
-
cd myproject
|
|
1019
|
-
tdx wf push myproject
|
|
1020
|
-
|
|
1021
|
-
# Push with custom revision
|
|
1022
|
-
cd myproject
|
|
1023
|
-
tdx wf push myproject --revision v1.0.0
|
|
1024
|
-
|
|
1025
|
-
# Push from parent directory with path
|
|
1026
|
-
tdx wf push ./myproject
|
|
1027
|
-
|
|
1028
|
-
# Push with --name override
|
|
1029
|
-
cd myproject
|
|
1030
|
-
tdx wf push myproject --name production_workflow
|
|
1031
|
-
|
|
1032
|
-
# Push from current directory without specifying name
|
|
1033
|
-
cd myproject
|
|
1034
|
-
tdx wf push
|
|
1035
|
-
|
|
1036
|
-
# Push without validation
|
|
1037
|
-
cd myproject
|
|
1038
|
-
tdx wf push myproject --skip-validation
|
|
1039
|
-
|
|
1040
|
-
# Delete workflow project (with confirmation)
|
|
1041
|
-
tdx wf delete myproject
|
|
1042
|
-
|
|
1043
|
-
# Delete by project ID
|
|
1044
|
-
tdx wf delete 12345
|
|
1045
|
-
|
|
1046
|
-
# Delete without confirmation
|
|
1047
|
-
tdx wf delete myproject -y
|
|
1048
|
-
|
|
1049
|
-
# Get workflow data as JSON
|
|
1050
|
-
tdx wf sessions --format json --output sessions.json
|
|
1051
|
-
```
|
|
1052
|
-
|
|
1053
|
-
### LLM Commands
|
|
1054
|
-
|
|
1055
|
-
Usage: `tdx llm <subcommand>`
|
|
1056
|
-
|
|
1057
|
-
Manage LLM projects, agents, and chat sessions with streaming support.
|
|
1058
|
-
|
|
1059
|
-
| Command | Description | Example |
|
|
1060
|
-
|---------|-------------|---------|
|
|
1061
|
-
| `llm use <project>` | Set current project context | `tdx llm use "MyProject"` |
|
|
1062
|
-
| `llm models` | List available LLM models | `tdx llm models` |
|
|
1063
|
-
| `llm projects [pattern]` | List all projects (with wildcard support) | `tdx llm projects` or `tdx llm projects "data*"` |
|
|
1064
|
-
| `llm project create <name>` | Create a new project | `tdx llm project create "MyProject"` |
|
|
1065
|
-
| `llm project delete <name>` | Delete a project | `tdx llm project delete "MyProject"` |
|
|
1066
|
-
| `llm agents [pattern]` | List agents in current project (with wildcard support) | `tdx llm agents` or `tdx llm agents "test*"` |
|
|
1067
|
-
| `llm agent show <name>` | Show agent details | `tdx llm agent show "Data Analyst"` |
|
|
1068
|
-
| `llm agent create <name>` | Create a new agent in current project | `tdx llm agent create "My Agent" --model <model>` |
|
|
1069
|
-
| `llm agent update <name>` | Update an agent | `tdx llm agent update "Agent" --name "New Name"` |
|
|
1070
|
-
| `llm agent delete <name>` | Delete an agent | `tdx llm agent delete "Agent"` |
|
|
1071
|
-
| `llm history [chat-id]` | List chat sessions or show messages | `tdx llm history` or `tdx llm history chat456` |
|
|
1072
|
-
| `llm proxy` | **[EXPERIMENTAL]** Start proxy server for Claude Code | `tdx llm proxy --port 4000` |
|
|
1073
|
-
| `claude` | Launch Claude Code with integrated LLM proxy | `tdx claude` |
|
|
1074
|
-
|
|
1075
|
-
**Project Resolution (Precedence Order):**
|
|
1076
|
-
|
|
1077
|
-
Agent commands resolve projects in this order:
|
|
1078
|
-
1. `--llm-project` global option (highest priority)
|
|
1079
|
-
2. `tdx llm use <project>` context (session-only)
|
|
1080
|
-
3. Default project `tdx_default_<username>` (auto-created)
|
|
1081
|
-
|
|
1082
|
-
**Command Options:**
|
|
1083
|
-
|
|
1084
|
-
For `project create`:
|
|
1085
|
-
- `--description <text>`: Project description
|
|
1086
|
-
|
|
1087
|
-
For `agent create`:
|
|
1088
|
-
- `--system-prompt <text>`: System prompt/instructions (default: empty)
|
|
1089
|
-
- `--model <name>`: Model type or alias (default: claude-4.5-haiku)
|
|
1090
|
-
- `--starter-message <text>`: Starter message for the agent
|
|
1091
|
-
- `--max-tool-iterations <n>`: Maximum tool iterations (default: 4)
|
|
1092
|
-
- `--temperature <n>`: Temperature 0.0-2.0 (default: 0.7)
|
|
1093
|
-
|
|
1094
|
-
For `agent update`:
|
|
1095
|
-
- `--name <text>`: New agent name
|
|
1096
|
-
- `--prompt <text>`: New prompt/instructions
|
|
1097
|
-
- `--description <text>`: New description
|
|
1098
|
-
- `--starter-message <text>`: New starter message
|
|
1099
|
-
|
|
1100
|
-
**Examples**:
|
|
1101
|
-
```bash
|
|
1102
|
-
# List available models
|
|
1103
|
-
tdx llm models
|
|
1104
|
-
|
|
1105
|
-
# List all projects
|
|
1106
|
-
tdx llm projects
|
|
1107
|
-
|
|
1108
|
-
# List projects matching pattern (wildcards: * = any chars, ? = single char)
|
|
1109
|
-
tdx llm projects "data*" # Projects starting with 'data'
|
|
1110
|
-
tdx llm projects "*_prod" # Projects ending with '_prod'
|
|
1111
|
-
|
|
1112
|
-
# Create a new project
|
|
1113
|
-
tdx llm project create "MyProject" --description "My data analysis project"
|
|
1114
|
-
|
|
1115
|
-
# Set current project context (session-only)
|
|
1116
|
-
tdx llm use "MyProject"
|
|
1117
|
-
|
|
1118
|
-
# Now all agent commands use "MyProject" by default:
|
|
1119
|
-
tdx llm agents # List agents in MyProject
|
|
1120
|
-
tdx llm agents "test*" # Filter agents by pattern
|
|
1121
|
-
tdx llm agent show "Data Analyst" # Show agent from MyProject
|
|
1122
|
-
tdx llm agent create "Analyst" --model gpt-5 # Create in MyProject
|
|
1123
|
-
tdx llm agent update "Analyst" --name "Senior Analyst"
|
|
1124
|
-
tdx llm agent delete "Analyst"
|
|
1125
|
-
|
|
1126
|
-
# Override project with --llm-project option (highest priority)
|
|
1127
|
-
tdx llm agents --llm-project "OtherProject"
|
|
1128
|
-
tdx llm agent show "Agent" --llm-project "OtherProject"
|
|
1129
|
-
|
|
1130
|
-
# Use default project (tdx_default_<username>) - no setup needed
|
|
1131
|
-
tdx llm agents # Uses tdx_default_leo if no context set
|
|
1132
|
-
tdx llm agent create "Bot" # Creates in default project
|
|
1133
|
-
|
|
1134
|
-
# Complete workflow: Create custom agent and chat with it
|
|
1135
|
-
tdx llm use "MyProject"
|
|
1136
|
-
tdx llm agent create "SQL Expert" \
|
|
1137
|
-
--system-prompt "You are an expert in SQL and data analysis. Help users write efficient queries." \
|
|
1138
|
-
--model "claude-4.5-sonnet"
|
|
1139
|
-
|
|
1140
|
-
# Now chat with your custom agent
|
|
1141
|
-
tdx chat "Help me analyze customer churn" --agent "SQL Expert"
|
|
1142
|
-
tdx chat "Show me the query for that" # Continues conversation
|
|
1143
|
-
|
|
1144
|
-
# Delete project
|
|
1145
|
-
tdx llm project delete "OldProject"
|
|
1146
|
-
|
|
1147
|
-
# Chat history
|
|
1148
|
-
tdx llm history # List recent chat sessions
|
|
1149
|
-
tdx llm history chat456 # Show specific chat messages
|
|
1150
|
-
|
|
1151
|
-
# JSON output
|
|
1152
|
-
tdx llm agents --format json --output agents.json
|
|
1153
|
-
```
|
|
1154
|
-
|
|
1155
|
-
### Claude Code Integration
|
|
1156
|
-
|
|
1157
|
-
The `tdx claude` command provides seamless integration with Claude Code by automatically:
|
|
1158
|
-
1. Creating/using a default project and agent (or using cached haiku/sonnet/opus agent)
|
|
1159
|
-
2. Finding an available port and starting an LLM proxy server in the background
|
|
1160
|
-
3. Generating `.claude/settings.local.json` configuration file
|
|
1161
|
-
4. Launching Claude Code with the proxy configured
|
|
1162
|
-
5. Stopping the proxy server when Claude Code exits
|
|
1163
|
-
|
|
1164
|
-
**Quick Start:**
|
|
1165
|
-
|
|
1166
|
-
```bash
|
|
1167
|
-
# Launch Claude Code with default settings (uses haiku model)
|
|
1168
|
-
tdx claude
|
|
1169
|
-
|
|
1170
|
-
# Use sonnet model instead
|
|
1171
|
-
tdx claude --model sonnet
|
|
1172
|
-
|
|
1173
|
-
# Use opus model
|
|
1174
|
-
tdx claude --model opus
|
|
1175
|
-
|
|
1176
|
-
# Enable debug/trace logging
|
|
1177
|
-
tdx --debug claude
|
|
1178
|
-
tdx --trace claude
|
|
1179
|
-
|
|
1180
|
-
# Pass arbitrary options to Claude Code using '--' separator
|
|
1181
|
-
# Continue previous session
|
|
1182
|
-
tdx claude --model sonnet -- -c
|
|
1183
|
-
|
|
1184
|
-
# Resume a specific session
|
|
1185
|
-
tdx claude -- -r session-id-here
|
|
1186
|
-
|
|
1187
|
-
# Combine tdx and Claude Code options
|
|
1188
|
-
tdx claude --debug -- -c
|
|
1189
|
-
```
|
|
1190
|
-
|
|
1191
|
-
**Requirements:**
|
|
1192
|
-
- Claude Code CLI must be installed (https://claude.com/claude-code)
|
|
1193
|
-
- The command will fail with a helpful error if Claude Code is not found
|
|
1194
|
-
|
|
1195
|
-
**Debugging:**
|
|
1196
|
-
- Logs are written to `~/.cache/tdx/logs/proxy.log`
|
|
1197
|
-
- Use `--debug` for HTTP request/response logging
|
|
1198
|
-
- Use `--trace` for ultra-verbose internal operation logging
|
|
1199
|
-
- View logs in real-time: `tail -f ~/.cache/tdx/logs/proxy.log`
|
|
1200
|
-
|
|
1201
|
-
**How It Works:**
|
|
1202
|
-
|
|
1203
|
-
1. Creates or reuses a default agent (e.g., `tdx_claude-4.5-haiku`) with the specified model
|
|
1204
|
-
2. Finds an available port starting from 4000 (tries 4001, 4002, etc. if occupied)
|
|
1205
|
-
3. Starts `tdx llm proxy` in the background on the found port
|
|
1206
|
-
4. Creates `.claude/settings.local.json` with:
|
|
1207
|
-
```json
|
|
1208
|
-
{
|
|
1209
|
-
"env": {
|
|
1210
|
-
"ANTHROPIC_BASE_URL": "http://127.0.0.1:4000",
|
|
1211
|
-
"ANTHROPIC_MODEL": "haiku"
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
```
|
|
1215
|
-
5. Launches Claude Code CLI
|
|
1216
|
-
6. When Claude Code exits, automatically stops the proxy server
|
|
1217
|
-
|
|
1218
|
-
**Options:**
|
|
1219
|
-
|
|
1220
|
-
- `--model <name>`: Model to use (haiku, sonnet, opus) - default: haiku
|
|
1221
|
-
- `--debug`: Enable debug mode (logs proxy request/response to stderr)
|
|
1222
|
-
|
|
1223
|
-
**Model Selection:**
|
|
1224
|
-
|
|
1225
|
-
The `--model` flag controls which TD agent is used:
|
|
1226
|
-
- `haiku` → Uses/creates `tdx_claude-4.5-haiku` agent (fast, cost-effective)
|
|
1227
|
-
- `sonnet` → Uses/creates `tdx_claude-4.5-sonnet` agent (balanced)
|
|
1228
|
-
- `opus` → Uses/creates `tdx_claude-opus` agent (most capable)
|
|
1229
|
-
|
|
1230
|
-
All agents are created in your default project (`tdx_default_<username>`) and cached for reuse.
|
|
1231
|
-
|
|
1232
|
-
**Advantages over Manual Setup:**
|
|
1233
|
-
- Zero configuration - just run `tdx claude` and start coding
|
|
1234
|
-
- Automatic port management - finds available port automatically
|
|
1235
|
-
- Automatic cleanup - stops proxy when Claude Code exits
|
|
1236
|
-
- Smart agent caching - reuses agents across sessions
|
|
1237
|
-
|
|
1238
|
-
#### LLM Proxy Server for Claude Code
|
|
1239
|
-
|
|
1240
|
-
> **⚠️ EXPERIMENTAL FEATURE**: This proxy server is experimental and may have limitations. Please report issues at https://github.com/treasure-data/tdx/issues
|
|
1241
|
-
|
|
1242
|
-
The `tdx llm proxy` command starts a local HTTP server that provides Anthropic-compatible API endpoints, allowing Claude Code and other AI coding assistants to use Treasure Data's LLM API as a backend.
|
|
1243
|
-
|
|
1244
|
-
**Starting the Proxy:**
|
|
1245
|
-
|
|
1246
|
-
```bash
|
|
1247
|
-
# Start proxy with default settings (port 4000)
|
|
1248
|
-
tdx llm proxy
|
|
1249
|
-
|
|
1250
|
-
# Specify custom port
|
|
1251
|
-
tdx llm proxy --port 8000
|
|
1252
|
-
|
|
1253
|
-
# Use specific project and agent
|
|
1254
|
-
tdx llm proxy --project "MyProject" --agent "MyAgent"
|
|
1255
|
-
|
|
1256
|
-
# Use context (set with 'tdx llm use')
|
|
1257
|
-
tdx llm use "MyProject/MyAgent"
|
|
1258
|
-
tdx llm proxy
|
|
1259
|
-
|
|
1260
|
-
# Enable debug mode to see request/response JSON
|
|
1261
|
-
tdx llm proxy --debug
|
|
1262
|
-
```
|
|
1263
|
-
|
|
1264
|
-
**Claude Code Configuration:**
|
|
1265
|
-
|
|
1266
|
-
Create a `.claude/settings.local.json` file in your project directory:
|
|
1267
|
-
|
|
1268
|
-
```json
|
|
1269
|
-
{
|
|
1270
|
-
"env": {
|
|
1271
|
-
"ANTHROPIC_BASE_URL": "http://127.0.0.1:4000",
|
|
1272
|
-
"ANTHROPIC_MODEL": "sonnet"
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
```
|
|
1276
|
-
|
|
1277
|
-
**Testing with Agent SDK:**
|
|
1278
|
-
|
|
1279
|
-
You can also test the proxy using [Claude Agent SDK](https://docs.claude.com/en/docs/agent-sdk/typescript):
|
|
1280
|
-
|
|
1281
|
-
```bash
|
|
1282
|
-
npm install @anthropic-ai/sdk
|
|
1283
|
-
```
|
|
1284
|
-
|
|
1285
|
-
The SDK reads `.claude/settings.json` for `ANTHROPIC_BASE_URL` configuration.
|
|
1286
|
-
|
|
1287
|
-
**How It Works:**
|
|
1288
|
-
|
|
1289
|
-
1. The proxy translates Anthropic Messages API calls to TD LLM API format
|
|
1290
|
-
2. Maintains conversation state across multiple requests
|
|
1291
|
-
3. Streams responses in real-time using Server-Sent Events (SSE)
|
|
1292
|
-
4. Maps model names (sonnet/haiku/opus) to TD models
|
|
1293
|
-
5. Supports tool calls via prompt engineering (see Tool Support below)
|
|
1294
|
-
|
|
1295
|
-
**Proxy Options:**
|
|
1296
|
-
|
|
1297
|
-
- `--port <number>`: Port to run the server on (default: 4000)
|
|
1298
|
-
- `--project <name>`: LLM project name (uses context or default)
|
|
1299
|
-
- `--agent <name>`: Agent name (uses context or default)
|
|
1300
|
-
- `--debug`: Enable debug mode (logs request/response JSON to stderr)
|
|
1301
|
-
|
|
1302
|
-
**Tool Support:**
|
|
1303
|
-
|
|
1304
|
-
The proxy supports Anthropic-style tool calls via prompt engineering:
|
|
1305
|
-
|
|
1306
|
-
1. **Tool Definition Injection**: Tool definitions from the Anthropic request are converted into clear instructions and prepended to the user message
|
|
1307
|
-
2. **JSON-based Tool Calls**: The LLM is instructed to output tool calls as JSON: `{"tool_use":{"id":"toolu_xxx","name":"tool_name","input":{...}}}`
|
|
1308
|
-
3. **Automatic Detection**: The proxy parses the response stream to detect tool call JSON and converts it to proper Anthropic SSE events
|
|
1309
|
-
4. **Tool Results**: When the client sends tool results back, they're formatted and included in the next message to the LLM
|
|
1310
|
-
|
|
1311
|
-
This approach works around the architectural differences between TD's server-driven tool system and Anthropic's client-driven model.
|
|
1312
|
-
|
|
1313
|
-
**Known Limitations:**
|
|
1314
|
-
|
|
1315
|
-
- Tool calls rely on prompt engineering (LLM must output correct JSON format)
|
|
1316
|
-
- Non-streaming responses are not implemented
|
|
1317
|
-
- Image inputs are not supported
|
|
1318
|
-
- System prompt is prepended to first message only (not persisted in agent)
|
|
1319
|
-
- TD's built-in tools (knowledge base, functions) are not directly accessible
|
|
1320
|
-
|
|
1321
|
-
## Advanced Query Features
|
|
1322
|
-
|
|
1323
|
-
### File Input
|
|
1324
|
-
|
|
1325
|
-
Read SQL queries from files using the `-f` or `--file` option:
|
|
1326
|
-
|
|
1327
|
-
```bash
|
|
1328
|
-
# Execute SQL from file
|
|
1329
|
-
tdx query --file query.sql
|
|
1330
|
-
|
|
1331
|
-
# Short form
|
|
1332
|
-
tdx query -f query.sql
|
|
1333
|
-
|
|
1334
|
-
# With options
|
|
1335
|
-
tdx query -f query.sql --database mydb --format json --output results.json
|
|
1336
|
-
```
|
|
1337
|
-
|
|
1338
|
-
### Multi-Statement Execution
|
|
1339
|
-
|
|
1340
|
-
Execute multiple SQL statements sequentially by separating them with semicolons. This works for both command-line input and file input:
|
|
1341
|
-
|
|
1342
|
-
**From command line**:
|
|
1343
|
-
```bash
|
|
1344
|
-
tdx query "SELECT COUNT(*) FROM users; SELECT COUNT(*) FROM orders"
|
|
1345
|
-
```
|
|
1346
|
-
|
|
1347
|
-
**From file** (`setup-and-query.sql`):
|
|
1348
|
-
```sql
|
|
1349
|
-
CREATE TABLE temp_users AS SELECT * FROM users WHERE active = true;
|
|
1350
|
-
CREATE TABLE temp_orders AS SELECT * FROM orders WHERE user_id IN (SELECT id FROM temp_users);
|
|
1351
|
-
SELECT COUNT(*) as order_count FROM temp_orders;
|
|
1352
|
-
```
|
|
1353
|
-
|
|
1354
|
-
```bash
|
|
1355
|
-
tdx query -f setup-and-query.sql
|
|
1356
|
-
```
|
|
1357
|
-
|
|
1358
|
-
**Output behavior**:
|
|
1359
|
-
- Each statement executes sequentially with progress indication
|
|
1360
|
-
- **Console output**: All results displayed as they complete
|
|
1361
|
-
- **File output** (`--output results.txt`): All results appended to single file
|
|
1362
|
-
- **Fail-fast**: Execution stops on first error
|
|
1363
|
-
|
|
1364
|
-
**Example output**:
|
|
1365
|
-
```
|
|
1366
|
-
✔ Statement 1/3 - Query completed: Processed 1,000 rows in 2.3s
|
|
1367
|
-
┌────────────┐
|
|
1368
|
-
│ user_count │
|
|
1369
|
-
├────────────┤
|
|
1370
|
-
│ 1000 │
|
|
1371
|
-
└────────────┘
|
|
1372
|
-
✔ Statement 2/3 - Query completed: Processed 5,000 rows in 3.1s
|
|
1373
|
-
┌─────────────┐
|
|
1374
|
-
│ order_count │
|
|
1375
|
-
├─────────────┤
|
|
1376
|
-
│ 5000 │
|
|
1377
|
-
└─────────────┘
|
|
1378
|
-
✔ Statement 3/3 - Query completed: Processed 1 rows in 0.5s
|
|
1379
|
-
┌─────────────┐
|
|
1380
|
-
│ order_count │
|
|
1381
|
-
├─────────────┤
|
|
1382
|
-
│ 5000 │
|
|
1383
|
-
└─────────────┘
|
|
1384
|
-
```
|
|
1385
|
-
|
|
1386
|
-
**With `--output`** (file mode):
|
|
1387
|
-
```bash
|
|
1388
|
-
tdx query -f statements.sql --output results.txt
|
|
1389
|
-
```
|
|
1390
|
-
- Console shows only progress messages
|
|
1391
|
-
- All results written to `results.txt` (appended sequentially)
|
|
1392
|
-
- Message: "All results saved to results.txt"
|
|
1393
|
-
|
|
1394
|
-
## Output Formats
|
|
1395
|
-
|
|
1396
|
-
tdx supports multiple output formats for query results and command outputs:
|
|
1397
|
-
|
|
1398
|
-
### Table Format (default)
|
|
1399
|
-
Human-readable ASCII table with column types and row counts:
|
|
1400
|
-
```bash
|
|
1401
|
-
tdx query "SELECT name, age FROM users LIMIT 2"
|
|
1402
|
-
```
|
|
1403
|
-
```
|
|
1404
|
-
┌───────┬─────┐
|
|
1405
|
-
│ name │ age │
|
|
1406
|
-
│ string│ int │
|
|
1407
|
-
├───────┼─────┤
|
|
1408
|
-
│ Alice │ 25 │
|
|
1409
|
-
│ Bob │ 30 │
|
|
1410
|
-
├───────┴─────┤
|
|
1411
|
-
│ 2 rows │
|
|
1412
|
-
└─────────────┘
|
|
1413
|
-
```
|
|
1414
|
-
|
|
1415
|
-
### JSON Format
|
|
1416
|
-
Readable JSON array with newlines (no metadata):
|
|
1417
|
-
```bash
|
|
1418
|
-
tdx query "SELECT name, age FROM users LIMIT 2" --format json
|
|
1419
|
-
```
|
|
1420
|
-
```json
|
|
1421
|
-
[
|
|
1422
|
-
{"name":"Alice","age":25},
|
|
1423
|
-
{"name":"Bob","age":30}
|
|
1424
|
-
]
|
|
1425
|
-
```
|
|
1426
|
-
|
|
1427
|
-
Each object is compact (single line) but separated by newlines for readability.
|
|
1428
|
-
|
|
1429
|
-
Perfect for piping to `jq`:
|
|
1430
|
-
```bash
|
|
1431
|
-
tdx query "SELECT * FROM users" --format json | jq '.[0]'
|
|
1432
|
-
tdx query "SELECT * FROM users" --format json | jq 'length'
|
|
1433
|
-
```
|
|
1434
|
-
|
|
1435
|
-
### JSON Lines Format (jsonl)
|
|
1436
|
-
One JSON object per line - ideal for streaming and line-by-line processing:
|
|
1437
|
-
```bash
|
|
1438
|
-
tdx query "SELECT name, age FROM users LIMIT 2" --format jsonl
|
|
1439
|
-
```
|
|
1440
|
-
```
|
|
1441
|
-
{"name":"Alice","age":25}
|
|
1442
|
-
{"name":"Bob","age":30}
|
|
1443
|
-
```
|
|
1444
|
-
|
|
1445
|
-
Process line by line:
|
|
1446
|
-
```bash
|
|
1447
|
-
tdx query "SELECT * FROM users" --format jsonl | while read line; do
|
|
1448
|
-
echo "$line" | jq '.name'
|
|
1449
|
-
done
|
|
1450
|
-
```
|
|
1451
|
-
|
|
1452
|
-
### TSV Format
|
|
1453
|
-
Tab-separated values with header row:
|
|
1454
|
-
```bash
|
|
1455
|
-
tdx query "SELECT name, age FROM users LIMIT 2" --format tsv
|
|
1456
|
-
```
|
|
1457
|
-
```
|
|
1458
|
-
name age
|
|
1459
|
-
Alice 25
|
|
1460
|
-
Bob 30
|
|
1461
|
-
```
|
|
1462
|
-
|
|
1463
|
-
### Color Output
|
|
1464
|
-
|
|
1465
|
-
`tdx` automatically adds ANSI colors to output in interactive terminals to improve readability:
|
|
1466
|
-
|
|
1467
|
-
**Table format:**
|
|
1468
|
-
- Table borders: Dark gray (dim)
|
|
1469
|
-
- Column headers: Plain text (no color)
|
|
1470
|
-
- Type row: Dim gray
|
|
1471
|
-
- Data values: Plain text (no color)
|
|
1472
|
-
|
|
1473
|
-
**JSON format:**
|
|
1474
|
-
- Keys: Blue
|
|
1475
|
-
- Strings: Green
|
|
1476
|
-
- Numbers: Cyan
|
|
1477
|
-
- Booleans: Yellow
|
|
1478
|
-
- Null values: Dim
|
|
1479
|
-
|
|
1480
|
-
**JSONL format:**
|
|
1481
|
-
- Same color scheme as JSON format
|
|
1482
|
-
- Compact one-line-per-object output with colors in interactive terminals
|
|
1483
|
-
|
|
1484
|
-
**Automatic detection:**
|
|
1485
|
-
- Colors are enabled automatically when output is to an interactive terminal (TTY)
|
|
1486
|
-
- Colors are disabled automatically when:
|
|
1487
|
-
- Output is piped to another command
|
|
1488
|
-
- Output is saved to a file with `--output`
|
|
1489
|
-
- Respects the `NO_COLOR` environment variable (see https://no-color.org/)
|
|
1490
|
-
|
|
1491
|
-
**Manual control:**
|
|
1492
|
-
```bash
|
|
1493
|
-
# Force colors on (even when piping or saving to file)
|
|
1494
|
-
tdx databases --color
|
|
1495
|
-
tdx databases --color --output results.txt
|
|
1496
|
-
|
|
1497
|
-
# Disable colors (even in interactive terminal)
|
|
1498
|
-
tdx databases --no-color
|
|
1499
|
-
|
|
1500
|
-
# Disable colors via environment variable
|
|
1501
|
-
NO_COLOR=1 tdx databases
|
|
1502
|
-
```
|
|
1503
|
-
|
|
1504
|
-
**Priority order:**
|
|
1505
|
-
1. `--no-color` flag (highest priority)
|
|
1506
|
-
2. `--color` flag
|
|
1507
|
-
3. `NO_COLOR` environment variable
|
|
1508
|
-
4. TTY detection (automatic)
|
|
1509
|
-
|
|
1510
|
-
## Advanced Commands
|
|
1511
|
-
|
|
1512
|
-
### API Command (Raw HTTP Access)
|
|
1513
|
-
|
|
1514
|
-
Make authenticated HTTP requests to any Treasure Data API endpoint (similar to `gh api` from GitHub CLI).
|
|
1515
|
-
|
|
1516
|
-
**Usage:** `tdx api <endpoint> [options]`
|
|
1517
|
-
|
|
1518
|
-
| Option | Description | Example |
|
|
1519
|
-
|--------|-------------|---------|
|
|
1520
|
-
| `<endpoint>` | API endpoint path (must start with /) | `/v3/database/list` |
|
|
1521
|
-
| `-X, --method <method>` | HTTP method (GET, POST, PUT, DELETE, PATCH) | `-X POST` |
|
|
1522
|
-
| `--data <json>` | Request body as JSON string | `--data '{"name":"mydb"}'` |
|
|
1523
|
-
| `-f, --file <path>` | Read request body from file | `-f body.json` |
|
|
1524
|
-
| `-H, --header <header>` | Custom header (repeatable) | `-H "X-Custom: value"` |
|
|
1525
|
-
| `--type <api_type>` | API type (td, cdp, workflow, trino, llm) | `--type cdp` |
|
|
1526
|
-
|
|
1527
|
-
**Examples:**
|
|
1528
|
-
|
|
1529
|
-
```bash
|
|
1530
|
-
# GET request to TD API (default)
|
|
1531
|
-
tdx api /v3/database/list
|
|
1532
|
-
|
|
1533
|
-
# GET with path parameters
|
|
1534
|
-
tdx api /v3/database/show/mydb
|
|
1535
|
-
tdx api /v3/table/list/mydb
|
|
1536
|
-
tdx api /v3/table/show/mydb/users
|
|
1537
|
-
|
|
1538
|
-
# POST with inline JSON body (submit query)
|
|
1539
|
-
tdx api -X POST --data '{"query":"SELECT 1"}' /v3/job/issue/hive/mydb
|
|
1540
|
-
|
|
1541
|
-
# POST with data from file
|
|
1542
|
-
tdx api -X POST -f query.json /v3/job/issue/hive/mydb
|
|
1543
|
-
|
|
1544
|
-
# Custom headers
|
|
1545
|
-
tdx api -H "X-Custom: value" -H "X-Another: test" /v3/database/list
|
|
1546
|
-
|
|
1547
|
-
# CDP API endpoints (read-only)
|
|
1548
|
-
tdx api /entities/parent_segments --type cdp
|
|
1549
|
-
tdx api /audiences/12345/segments --type cdp
|
|
1550
|
-
tdx api -X POST --data '{"format":"sql"}' /audiences/12345/segments/query --type cdp
|
|
1551
|
-
|
|
1552
|
-
# Workflow API endpoints (read-only)
|
|
1553
|
-
tdx api /api/workflows --type workflow
|
|
1554
|
-
tdx api /api/projects --type workflow
|
|
1555
|
-
tdx api /api/attempts --type workflow
|
|
1556
|
-
|
|
1557
|
-
# Trino API endpoints (query submission - plain SQL, not JSON)
|
|
1558
|
-
tdx api -X POST --data 'SELECT 1' /v1/statement --type trino
|
|
1559
|
-
|
|
1560
|
-
# LLM API endpoints (read-only)
|
|
1561
|
-
tdx api /v1/agents --type llm
|
|
1562
|
-
tdx api /v1/models --type llm
|
|
1563
|
-
|
|
1564
|
-
# Show HTTP response headers (with --verbose)
|
|
1565
|
-
tdx api /v3/database/list --verbose
|
|
1566
|
-
|
|
1567
|
-
# Save output to file
|
|
1568
|
-
tdx api /v3/database/list --output databases.json
|
|
1569
|
-
|
|
1570
|
-
# Combine --verbose with --output to see headers while saving
|
|
1571
|
-
tdx api /v3/database/list --verbose --output databases.json
|
|
1572
|
-
```
|
|
1573
|
-
|
|
1574
|
-
**API Types:**
|
|
1575
|
-
|
|
1576
|
-
| Type | Base URL Pattern | Description |
|
|
1577
|
-
|------|-----------------|-------------|
|
|
1578
|
-
| `td` | `api.treasuredata.com` | TD REST API (databases, tables, jobs) |
|
|
1579
|
-
| `cdp` | `api-cdp.treasuredata.com` | CDP API (audiences, segments, activations) |
|
|
1580
|
-
| `workflow` | `api-workflow.treasuredata.com` | Workflow API (digdag) |
|
|
1581
|
-
| `trino` | `api-presto.treasuredata.com` | Trino Query Engine API |
|
|
1582
|
-
| `llm` | `llm-api.treasuredata.com` | LLM API (agents, chat) |
|
|
1583
|
-
|
|
1584
|
-
**Notes:**
|
|
1585
|
-
- All requests are automatically authenticated using your configured API key
|
|
1586
|
-
- Request body from `--data` must be valid JSON
|
|
1587
|
-
- `--data` and `--file` are mutually exclusive
|
|
1588
|
-
- Custom headers override default authentication headers
|
|
1589
|
-
- Response is output to stdout as JSON
|
|
1590
|
-
- Use `--verbose` to show HTTP request/response details in stderr:
|
|
1591
|
-
- Full target URL (shows site and API type)
|
|
1592
|
-
- Request headers (non-sensitive: User-Agent, X-TD-Client, Content-Type, etc.)
|
|
1593
|
-
- Response status and headers
|
|
1594
|
-
- Sensitive headers (Authorization, Cookie, etc.) are hidden for security
|
|
1595
|
-
|
|
1596
|
-
**Verbose Output Example:**
|
|
1597
|
-
```
|
|
1598
|
-
> POST https://api.treasuredata.com/v3/job/issue/hive/mydb
|
|
1599
|
-
> User-Agent: tdx/1.0.0 (darwin; node/24.0.0)
|
|
1600
|
-
> X-TD-Client: tdx
|
|
1601
|
-
> X-TD-Client-Version: 1.0.0
|
|
1602
|
-
> Content-Type: application/json
|
|
1603
|
-
>
|
|
1604
|
-
|
|
1605
|
-
< HTTP/1.1 200
|
|
1606
|
-
< content-type: application/json
|
|
1607
|
-
< x-td-request-id: abc123
|
|
1608
|
-
|
|
1609
|
-
{"job_id": "12345"}
|
|
1610
|
-
```
|
|
1611
|
-
|
|
1612
|
-
## Advanced Options
|
|
1613
|
-
|
|
1614
|
-
### Session ID Option
|
|
1615
|
-
|
|
1616
|
-
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:
|
|
1617
|
-
|
|
1618
|
-
**Usage:** `tdx --session <session-id> [command]`
|
|
1619
|
-
|
|
1620
|
-
**Examples:**
|
|
1621
|
-
|
|
1622
|
-
```bash
|
|
1623
|
-
# Process 1: Set session with explicit ID
|
|
1624
|
-
tdx --session my-workflow use database analytics
|
|
1625
|
-
tdx --session my-workflow use llm_project DataPipeline
|
|
1626
|
-
|
|
1627
|
-
# Process 2: Reuse the same session
|
|
1628
|
-
tdx --session my-workflow context
|
|
1629
|
-
# Shows: Database: analytics, LLM Project: DataPipeline
|
|
1630
|
-
|
|
1631
|
-
# Process 2: Run commands with shared context
|
|
1632
|
-
tdx --session my-workflow tables
|
|
1633
|
-
# Uses database: analytics
|
|
1634
|
-
|
|
1635
|
-
# Clean up when done
|
|
1636
|
-
tdx --session my-workflow use --clear
|
|
1637
|
-
```
|
|
1638
|
-
|
|
1639
|
-
**Use Cases:**
|
|
1640
|
-
- Sharing context between multiple terminal windows
|
|
1641
|
-
- Maintaining consistent context in CI/CD pipelines
|
|
1642
|
-
- Scripting scenarios where session persistence is needed
|
|
1643
|
-
|
|
1644
|
-
**Note:** The `--session` option must be specified before the command name (e.g., `tdx --session id tables`, not `tdx tables --session id`).
|
|
1645
|
-
|
|
1646
|
-
## Architecture
|
|
1647
|
-
|
|
1648
|
-
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:
|
|
1649
|
-
|
|
1650
|
-
```mermaid
|
|
1651
|
-
graph TD
|
|
1652
|
-
subgraph "Client Environments"
|
|
1653
|
-
NodeJS[Node.JS/CLI<br/>tdx commands]
|
|
1654
|
-
Browser[Web Browser<br/>Client-side]
|
|
1655
|
-
end
|
|
1656
|
-
|
|
1657
|
-
subgraph "TDX SDK - TypeScript"
|
|
1658
|
-
SDK[TDX SDK<br/>TypeScript/JavaScript API]
|
|
1659
|
-
end
|
|
1660
|
-
|
|
1661
|
-
subgraph "Treasure Data APIs"
|
|
1662
|
-
TD[TD REST API<br/>Databases, Tables, Jobs]
|
|
1663
|
-
Trino[Trino Streaming API<br/>Query Execution]
|
|
1664
|
-
CDP[CDP API<br/>Segments, Activations]
|
|
1665
|
-
end
|
|
1666
|
-
|
|
1667
|
-
NodeJS --> SDK
|
|
1668
|
-
Browser --> SDK
|
|
1669
|
-
|
|
1670
|
-
SDK -->|HTTPS| TD
|
|
1671
|
-
SDK -->|HTTPS| Trino
|
|
1672
|
-
SDK -->|HTTPS| CDP
|
|
1673
|
-
|
|
1674
|
-
style NodeJS fill:#d4f1d4
|
|
1675
|
-
style Browser fill:#ffd4d4
|
|
1676
|
-
style SDK fill:#fff5cc
|
|
1677
|
-
style TD fill:#e8e8f0
|
|
1678
|
-
style CDP fill:#e8e8f0
|
|
1679
|
-
style Trino fill:#e8e8f0
|
|
1680
|
-
```
|
|
1681
|
-
|
|
1682
|
-
## TDX SDK
|
|
1683
|
-
|
|
1684
|
-
**Usage Examples:**
|
|
1685
|
-
|
|
1686
|
-
**Node.js:**
|
|
1687
|
-
```typescript
|
|
1688
|
-
import { TDX, loadLocalSDKConfig } from '@treasuredata/tdx/sdk';
|
|
1689
|
-
|
|
1690
|
-
// Load config from environment or pass API key directly
|
|
1691
|
-
const config = loadLocalSDKConfig({
|
|
1692
|
-
site: 'us01',
|
|
1693
|
-
apiKey: 'your_key_id/your_key_secret' // Optional: omit to load from env
|
|
1694
|
-
});
|
|
1695
|
-
const tdx = new TDX(config);
|
|
1696
|
-
const result = await tdx.query('SELECT * FROM users');
|
|
1697
|
-
```
|
|
1698
|
-
|
|
1699
|
-
**Web Browser:**
|
|
1700
|
-
```html
|
|
1701
|
-
<script type="module">
|
|
1702
|
-
import { TDX } from 'https://unpkg.com/@treasuredata/tdx';
|
|
1703
|
-
// Browser: Create config object directly (loadLocalSDKConfig requires file system)
|
|
1704
|
-
const config = {
|
|
1705
|
-
site: 'us01',
|
|
1706
|
-
apiKey: 'your_key_id/your_key_secret',
|
|
1707
|
-
verbose: false
|
|
1708
|
-
};
|
|
1709
|
-
const tdx = new TDX(config);
|
|
1710
|
-
const result = await tdx.query('SELECT * FROM users');
|
|
1711
|
-
</script>
|
|
1712
|
-
```
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
## Requirements
|
|
1716
|
-
|
|
1717
|
-
- **Node.js 22.0.0 or higher** (Node.js 24 Active LTS recommended for development)
|
|
1718
|
-
- TD API key with appropriate permissions
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
## License
|
|
1722
|
-
|
|
1723
|
-
Apache-2.0
|
|
1724
|
-
|
|
1725
|
-
## Contributing
|
|
64
|
+
## Contributing
|
|
1726
65
|
|
|
1727
66
|
This project is maintained by the Treasure Data DevAI Unit.
|
|
1728
|
-
|