@youdotcom-oss/api 0.2.1 → 0.3.0
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 +26 -26
- package/bin/cli.js +22 -5
- package/package.json +1 -1
- package/src/cli.ts +1 -1
- package/src/search/search.utils.ts +21 -0
- package/src/shared/api.constants.ts +3 -3
package/README.md
CHANGED
|
@@ -19,11 +19,11 @@ Fast, lightweight API client and CLI tools for web search, AI answers, and conte
|
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
21
|
# Use with bunx (no install needed) - Schema-driven JSON input
|
|
22
|
-
bunx @youdotcom-oss/api search --json '{"query":"AI developments"}' --client
|
|
22
|
+
bunx @youdotcom-oss/api search --json '{"query":"AI developments"}' --client ClaudeCode
|
|
23
23
|
|
|
24
24
|
# Or install globally to use 'ydc' command
|
|
25
25
|
bun i -g @youdotcom-oss/api
|
|
26
|
-
ydc search --json '{"query":"AI developments"}' --client
|
|
26
|
+
ydc search --json '{"query":"AI developments"}' --client ClaudeCode
|
|
27
27
|
|
|
28
28
|
# Get comprehensive research with citations
|
|
29
29
|
bunx @youdotcom-oss/api deep-search --json '{
|
|
@@ -137,14 +137,14 @@ ydc search --json '{"query":"..."}' [options]
|
|
|
137
137
|
|
|
138
138
|
Examples:
|
|
139
139
|
# Basic search
|
|
140
|
-
ydc search --json '{"query":"machine learning"}' --client
|
|
140
|
+
ydc search --json '{"query":"machine learning"}' --client ClaudeCode
|
|
141
141
|
|
|
142
142
|
# Search with livecrawl (KEY FEATURE)
|
|
143
143
|
ydc search --json '{
|
|
144
144
|
"query":"documentation",
|
|
145
145
|
"livecrawl":"web",
|
|
146
146
|
"livecrawl_formats":"markdown"
|
|
147
|
-
}' --client
|
|
147
|
+
}' --client ClaudeCode
|
|
148
148
|
|
|
149
149
|
# Advanced filters
|
|
150
150
|
ydc search --json '{
|
|
@@ -153,10 +153,10 @@ Examples:
|
|
|
153
153
|
"fileType":"pdf",
|
|
154
154
|
"freshness":"month",
|
|
155
155
|
"count":10
|
|
156
|
-
}' --client
|
|
156
|
+
}' --client ClaudeCode
|
|
157
157
|
|
|
158
158
|
# Parse with jq
|
|
159
|
-
api search --json '{"query":"AI"}' --client
|
|
159
|
+
api search --json '{"query":"AI"}' --client ClaudeCode | \
|
|
160
160
|
jq -r '.results.web[] | .title'
|
|
161
161
|
|
|
162
162
|
# Extract livecrawl content
|
|
@@ -164,7 +164,7 @@ Examples:
|
|
|
164
164
|
"query":"docs",
|
|
165
165
|
"livecrawl":"web",
|
|
166
166
|
"livecrawl_formats":"markdown"
|
|
167
|
-
}' --client
|
|
167
|
+
}' --client ClaudeCode | \
|
|
168
168
|
jq -r '.results.web[0].contents.markdown'
|
|
169
169
|
```
|
|
170
170
|
|
|
@@ -190,18 +190,18 @@ ydc deep-search --json '{"query":"..."}' [options]
|
|
|
190
190
|
|
|
191
191
|
Examples:
|
|
192
192
|
# Comprehensive research with medium effort
|
|
193
|
-
api deep-search --json '{"query":"What is quantum computing?"}' --client
|
|
193
|
+
api deep-search --json '{"query":"What is quantum computing?"}' --client ClaudeCode
|
|
194
194
|
|
|
195
195
|
# High-effort deep research (up to 5 minutes)
|
|
196
196
|
api deep-search --json '{
|
|
197
197
|
"query":"Latest breakthroughs in AI agents",
|
|
198
198
|
"search_effort":"high"
|
|
199
|
-
}' --client
|
|
199
|
+
}' --client ClaudeCode
|
|
200
200
|
|
|
201
201
|
# Parse answer and sources
|
|
202
202
|
api deep-search --json '{
|
|
203
203
|
"query":"AI trends 2026"
|
|
204
|
-
}' --client
|
|
204
|
+
}' --client ClaudeCode | \
|
|
205
205
|
jq -r '.answer, "\nSources:", (.results[]? | "- \(.title): \(.url)")'
|
|
206
206
|
```
|
|
207
207
|
|
|
@@ -219,25 +219,25 @@ Examples:
|
|
|
219
219
|
api contents --json '{
|
|
220
220
|
"urls":["https://example.com"],
|
|
221
221
|
"formats":["markdown"]
|
|
222
|
-
}' --client
|
|
222
|
+
}' --client ClaudeCode
|
|
223
223
|
|
|
224
224
|
# Multiple formats
|
|
225
225
|
api contents --json '{
|
|
226
226
|
"urls":["https://example.com"],
|
|
227
227
|
"formats":["markdown","html","metadata"]
|
|
228
|
-
}' --client
|
|
228
|
+
}' --client ClaudeCode
|
|
229
229
|
|
|
230
230
|
# Multiple URLs
|
|
231
231
|
api contents --json '{
|
|
232
232
|
"urls":["https://a.com","https://b.com"],
|
|
233
233
|
"formats":["markdown"]
|
|
234
|
-
}' --client
|
|
234
|
+
}' --client ClaudeCode
|
|
235
235
|
|
|
236
236
|
# Save to file
|
|
237
237
|
api contents --json '{
|
|
238
238
|
"urls":["https://example.com"],
|
|
239
239
|
"formats":["markdown"]
|
|
240
|
-
}' --client
|
|
240
|
+
}' --client ClaudeCode | \
|
|
241
241
|
jq -r '.[0].markdown' > output.md
|
|
242
242
|
|
|
243
243
|
# With timeout
|
|
@@ -245,7 +245,7 @@ Examples:
|
|
|
245
245
|
"urls":["https://example.com"],
|
|
246
246
|
"formats":["markdown","metadata"],
|
|
247
247
|
"crawl_timeout":30
|
|
248
|
-
}' --client
|
|
248
|
+
}' --client ClaudeCode
|
|
249
249
|
```
|
|
250
250
|
|
|
251
251
|
**Available contents parameters** (use `--schema` to see full schema):
|
|
@@ -363,7 +363,7 @@ console.log(response[0].metadata); // Structured metadata
|
|
|
363
363
|
set -e
|
|
364
364
|
|
|
365
365
|
# Capture result, check exit code
|
|
366
|
-
if ! result=$(api search --json '{"query":"AI developments"}' --client
|
|
366
|
+
if ! result=$(api search --json '{"query":"AI developments"}' --client ClaudeCode); then
|
|
367
367
|
echo "Search failed with code $?"
|
|
368
368
|
exit 1
|
|
369
369
|
fi
|
|
@@ -377,7 +377,7 @@ echo "$result" | jq .
|
|
|
377
377
|
```bash
|
|
378
378
|
#!/usr/bin/env bash
|
|
379
379
|
for i in {1..3}; do
|
|
380
|
-
if api search --json '{"query":"AI"}' --client
|
|
380
|
+
if api search --json '{"query":"AI"}' --client ClaudeCode; then
|
|
381
381
|
exit 0
|
|
382
382
|
fi
|
|
383
383
|
[ $i -lt 3 ] && sleep 5
|
|
@@ -390,9 +390,9 @@ exit 1
|
|
|
390
390
|
|
|
391
391
|
```bash
|
|
392
392
|
#!/usr/bin/env bash
|
|
393
|
-
ydc search --json '{"query":"AI"}' --client
|
|
394
|
-
ydc search --json '{"query":"ML"}' --client
|
|
395
|
-
ydc search --json '{"query":"LLM"}' --client
|
|
393
|
+
ydc search --json '{"query":"AI"}' --client ClaudeCode &
|
|
394
|
+
ydc search --json '{"query":"ML"}' --client ClaudeCode &
|
|
395
|
+
ydc search --json '{"query":"LLM"}' --client ClaudeCode &
|
|
396
396
|
wait
|
|
397
397
|
```
|
|
398
398
|
|
|
@@ -408,18 +408,18 @@ search=$(api search --json '{
|
|
|
408
408
|
"count":5,
|
|
409
409
|
"livecrawl":"web",
|
|
410
410
|
"livecrawl_formats":"markdown"
|
|
411
|
-
}' --client
|
|
411
|
+
}' --client ClaudeCode)
|
|
412
412
|
|
|
413
413
|
# Get comprehensive research with citations
|
|
414
414
|
answer=$(api deep-search --json '{
|
|
415
415
|
"query":"Summarize AI developments in 2026",
|
|
416
416
|
"search_effort":"high"
|
|
417
|
-
}' --client
|
|
417
|
+
}' --client ClaudeCode)
|
|
418
418
|
|
|
419
419
|
# Extract top result URL and fetch content
|
|
420
420
|
url=$(echo "$search" | jq -r '.results.web[0].url')
|
|
421
421
|
ydc contents --json "{\"urls\":[\"$url\"],\"formats\":[\"markdown\"]}" \
|
|
422
|
-
--client
|
|
422
|
+
--client ClaudeCode | jq -r '.[0].markdown' > output.md
|
|
423
423
|
```
|
|
424
424
|
|
|
425
425
|
### Schema-Driven Agent
|
|
@@ -441,7 +441,7 @@ query=$(jq -n '{
|
|
|
441
441
|
}')
|
|
442
442
|
|
|
443
443
|
# Execute search
|
|
444
|
-
ydc search --json "$query" --client
|
|
444
|
+
ydc search --json "$query" --client ClaudeCode
|
|
445
445
|
```
|
|
446
446
|
|
|
447
447
|
## Agent Skills Integration
|
|
@@ -462,10 +462,10 @@ The [youdotcom-cli skill](https://github.com/youdotcom-oss/agent-skills/tree/mai
|
|
|
462
462
|
### Compatible Agents
|
|
463
463
|
|
|
464
464
|
Works with any bash-capable agent supporting Agent Skills:
|
|
465
|
-
- **OpenClaw** - Open source bash agent
|
|
466
465
|
- **Claude Code** - Anthropic's coding tool
|
|
467
|
-
- **Codex** - OpenAI's CLI agent
|
|
468
466
|
- **Cursor** - AI-powered code editor
|
|
467
|
+
- **Droid** - Factory.ai agent
|
|
468
|
+
- **Codex** - OpenAI's CLI agent
|
|
469
469
|
- **Roo Code** - VS Code extension
|
|
470
470
|
- And more...
|
|
471
471
|
|
package/bin/cli.js
CHANGED
|
@@ -15,7 +15,7 @@ import { parseArgs as parseArgs2 } from "node:util";
|
|
|
15
15
|
// package.json
|
|
16
16
|
var package_default = {
|
|
17
17
|
name: "@youdotcom-oss/api",
|
|
18
|
-
version: "0.
|
|
18
|
+
version: "0.3.0",
|
|
19
19
|
description: "You.com API client with bundled CLI for agents supporting Agent Skills",
|
|
20
20
|
license: "MIT",
|
|
21
21
|
engines: {
|
|
@@ -4768,9 +4768,9 @@ var ContentsItemSchema = object({
|
|
|
4768
4768
|
var ContentsApiResponseSchema = array(ContentsItemSchema);
|
|
4769
4769
|
|
|
4770
4770
|
// src/shared/api.constants.ts
|
|
4771
|
-
var SEARCH_API_URL = "https://ydc-index.io/v1/search";
|
|
4772
|
-
var DEEP_SEARCH_API_URL = "https://api.you.com/v1/deep_search";
|
|
4773
|
-
var CONTENTS_API_URL = "https://ydc-index.io/v1/contents";
|
|
4771
|
+
var SEARCH_API_URL = process.env.YDC_SEARCH_API_URL || "https://ydc-index.io/v1/search";
|
|
4772
|
+
var DEEP_SEARCH_API_URL = process.env.YDC_DEEP_SEARCH_API_URL || "https://api.you.com/v1/deep_search";
|
|
4773
|
+
var CONTENTS_API_URL = process.env.YDC_CONTENTS_API_URL || "https://ydc-index.io/v1/contents";
|
|
4774
4774
|
|
|
4775
4775
|
// src/shared/check-response-for-errors.ts
|
|
4776
4776
|
var checkResponseForErrors = (responseData) => {
|
|
@@ -5044,6 +5044,23 @@ var fetchSearchResults = async ({
|
|
|
5044
5044
|
throw new Error("Rate limited by You.com API. Please try again later.");
|
|
5045
5045
|
} else if (errorCode === 403) {
|
|
5046
5046
|
throw new Error("Forbidden. Please check your You.com API key.");
|
|
5047
|
+
} else if (errorCode === 402) {
|
|
5048
|
+
let errorMessage = "Free tier limit exceeded. Please upgrade to continue.";
|
|
5049
|
+
let upgradeUrl = "https://you.com/platform";
|
|
5050
|
+
try {
|
|
5051
|
+
const errorBody = await response.json();
|
|
5052
|
+
if (errorBody?.message) {
|
|
5053
|
+
errorMessage = errorBody.message;
|
|
5054
|
+
}
|
|
5055
|
+
if (errorBody?.upgrade_url) {
|
|
5056
|
+
upgradeUrl = errorBody.upgrade_url;
|
|
5057
|
+
}
|
|
5058
|
+
if (errorBody?.reset_at) {
|
|
5059
|
+
const resetDate = new Date(errorBody.reset_at).toLocaleDateString();
|
|
5060
|
+
errorMessage += ` Limit resets on ${resetDate}.`;
|
|
5061
|
+
}
|
|
5062
|
+
} catch {}
|
|
5063
|
+
throw new Error(`${errorMessage} Upgrade at: ${upgradeUrl}`);
|
|
5047
5064
|
}
|
|
5048
5065
|
throw new Error(`Failed to perform search. Error code: ${errorCode}`);
|
|
5049
5066
|
}
|
|
@@ -5225,7 +5242,7 @@ Output Format:
|
|
|
5225
5242
|
Invalid args: Error message on stderr (exit 2)
|
|
5226
5243
|
|
|
5227
5244
|
Examples:
|
|
5228
|
-
ydc search --json '{"query":"AI developments"}' --client
|
|
5245
|
+
ydc search --json '{"query":"AI developments"}' --client ClaudeCode
|
|
5229
5246
|
ydc deep-search --json '{"query":"What are the latest breakthroughs in AI?","search_effort":"high"}' --client MyAgent
|
|
5230
5247
|
ydc contents --json '{"urls":["https://example.com"],"formats":["markdown"]}'
|
|
5231
5248
|
ydc search --schema # Get JSON schema for search --json input
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -62,7 +62,7 @@ Output Format:
|
|
|
62
62
|
Invalid args: Error message on stderr (exit 2)
|
|
63
63
|
|
|
64
64
|
Examples:
|
|
65
|
-
ydc search --json '{"query":"AI developments"}' --client
|
|
65
|
+
ydc search --json '{"query":"AI developments"}' --client ClaudeCode
|
|
66
66
|
ydc deep-search --json '{"query":"What are the latest breakthroughs in AI?","search_effort":"high"}' --client MyAgent
|
|
67
67
|
ydc contents --json '{"urls":["https://example.com"],"formats":["markdown"]}'
|
|
68
68
|
ydc search --schema # Get JSON schema for search --json input
|
|
@@ -42,6 +42,27 @@ export const fetchSearchResults = async ({
|
|
|
42
42
|
throw new Error('Rate limited by You.com API. Please try again later.')
|
|
43
43
|
} else if (errorCode === 403) {
|
|
44
44
|
throw new Error('Forbidden. Please check your You.com API key.')
|
|
45
|
+
} else if (errorCode === 402) {
|
|
46
|
+
let errorMessage = 'Free tier limit exceeded. Please upgrade to continue.'
|
|
47
|
+
let upgradeUrl = 'https://you.com/platform'
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const errorBody = (await response.json()) as any
|
|
51
|
+
if (errorBody?.message) {
|
|
52
|
+
errorMessage = errorBody.message
|
|
53
|
+
}
|
|
54
|
+
if (errorBody?.upgrade_url) {
|
|
55
|
+
upgradeUrl = errorBody.upgrade_url
|
|
56
|
+
}
|
|
57
|
+
if (errorBody?.reset_at) {
|
|
58
|
+
const resetDate = new Date(errorBody.reset_at).toLocaleDateString()
|
|
59
|
+
errorMessage += ` Limit resets on ${resetDate}.`
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
// If parsing fails, use default message
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
throw new Error(`${errorMessage} Upgrade at: ${upgradeUrl}`)
|
|
45
66
|
}
|
|
46
67
|
|
|
47
68
|
throw new Error(`Failed to perform search. Error code: ${errorCode}`)
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* Exported for use in tests and external packages.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export const SEARCH_API_URL = 'https://ydc-index.io/v1/search'
|
|
9
|
-
export const DEEP_SEARCH_API_URL = 'https://api.you.com/v1/deep_search'
|
|
10
|
-
export const CONTENTS_API_URL = 'https://ydc-index.io/v1/contents'
|
|
8
|
+
export const SEARCH_API_URL = process.env.YDC_SEARCH_API_URL || 'https://ydc-index.io/v1/search'
|
|
9
|
+
export const DEEP_SEARCH_API_URL = process.env.YDC_DEEP_SEARCH_API_URL || 'https://api.you.com/v1/deep_search'
|
|
10
|
+
export const CONTENTS_API_URL = process.env.YDC_CONTENTS_API_URL || 'https://ydc-index.io/v1/contents'
|