@1aboveio/content-skills 0.0.0-stage → 0.1.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.
Files changed (53) hide show
  1. package/README.md +24 -2
  2. package/package.json +33 -4
  3. package/skills/article-review/LICENSE +3 -0
  4. package/skills/article-review/SKILL.md +66 -0
  5. package/skills/article-review/references/report-format.md +68 -0
  6. package/skills/article-review/references/template-guide.md +79 -0
  7. package/skills/article-review/references/template-wechat-payments.md +125 -0
  8. package/skills/article-review/release-check.mjs +93 -0
  9. package/skills/article-to-image/LICENSE +3 -0
  10. package/skills/article-to-image/SKILL.md +91 -0
  11. package/skills/article-to-image/references/formats.md +53 -0
  12. package/skills/article-to-image/release-check.mjs +93 -0
  13. package/skills/flowchart-svg/LICENSE +3 -0
  14. package/skills/flowchart-svg/SKILL.md +43 -0
  15. package/skills/flowchart-svg/release-check.mjs +93 -0
  16. package/skills/flowchart-svg/scripts/export_png.sh +8 -0
  17. package/skills/image-gen/LICENSE +3 -0
  18. package/skills/image-gen/SKILL.md +192 -0
  19. package/skills/image-gen/release-check.mjs +93 -0
  20. package/skills/image-gen/scripts/credentials.mjs +217 -0
  21. package/skills/image-gen/scripts/credentials.test.mjs +212 -0
  22. package/skills/image-gen/scripts/generate.mjs +240 -0
  23. package/skills/image-gen/scripts/options.mjs +293 -0
  24. package/skills/image-gen/scripts/options.test.mjs +245 -0
  25. package/skills/mermaid/LICENSE +3 -0
  26. package/skills/mermaid/SKILL.md +635 -0
  27. package/skills/mermaid/release-check.mjs +93 -0
  28. package/skills/wechat-article-writer/LICENSE +3 -0
  29. package/skills/wechat-article-writer/SKILL.md +92 -0
  30. package/skills/wechat-article-writer/references/style-selector.md +133 -0
  31. package/skills/wechat-article-writer/references/writing-rules.md +152 -0
  32. package/skills/wechat-article-writer/release-check.mjs +93 -0
  33. package/skills/wechat-article-writer/templates/wechat-comparison.md +52 -0
  34. package/skills/wechat-article-writer/templates/wechat-howto.md +51 -0
  35. package/skills/wechat-article-writer/templates/wechat-insight.md +50 -0
  36. package/skills/wechat-article-writer/templates/wechat-pitfall.md +52 -0
  37. package/skills/wechat-publisher/LICENSE +3 -0
  38. package/skills/wechat-publisher/SKILL.md +171 -0
  39. package/skills/wechat-publisher/references/api.md +105 -0
  40. package/skills/wechat-publisher/references/layout-rules.md +57 -0
  41. package/skills/wechat-publisher/references/wechat-safe-template.html +86 -0
  42. package/skills/wechat-publisher/release-check.mjs +93 -0
  43. package/skills/wechat-publisher/scripts/md_to_wechat_html.py +194 -0
  44. package/skills/wechat-publisher/scripts/publish.py +239 -0
  45. package/skills/wechat-search/LICENSE +3 -0
  46. package/skills/wechat-search/SKILL.md +211 -0
  47. package/skills/wechat-search/release-check.mjs +93 -0
  48. package/skills/wechat-search/scripts/start-chrome.sh +83 -0
  49. package/skills/xai-search/LICENSE +3 -0
  50. package/skills/xai-search/SKILL.md +79 -0
  51. package/skills/xai-search/release-check.mjs +93 -0
  52. package/skills/xai-search/scripts/xai_search.sh +187 -0
  53. package/skills/xai-search/tests/smoke_test.sh +36 -0
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
4
+ import { homedir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const DAY_MS = 24 * 60 * 60 * 1000;
9
+ const WEEK_MS = 7 * DAY_MS;
10
+ const here = dirname(fileURLToPath(import.meta.url));
11
+
12
+ function readJson(path, fallback = {}) {
13
+ try { return JSON.parse(readFileSync(path, 'utf8')); } catch { return fallback; }
14
+ }
15
+
16
+ function frontmatterValue(text, key) {
17
+ const frontmatter = /^---\n([\s\S]*?)\n---/.exec(text)?.[1] ?? '';
18
+ const match = new RegExp('^' + key + ':\\s*([^\\n]+)$', 'm').exec(frontmatter);
19
+ return match?.[1].trim().replace(/^['"]|['"]$/g, '') ?? null;
20
+ }
21
+
22
+ function repositoryOf(source) {
23
+ const value = String(source ?? '').trim();
24
+ const match = /^(?:git@github\.com:|https:\/\/github\.com\/)?([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+?)(?:\.git)?$/.exec(value);
25
+ return match?.[1] ?? null;
26
+ }
27
+
28
+ function stableVersion(value) {
29
+ const match = /^v?(\d+)\.(\d+)\.(\d+)$/.exec(String(value ?? '').trim());
30
+ return match ? match.slice(1).map(Number) : null;
31
+ }
32
+
33
+ function newer(left, right) {
34
+ for (let index = 0; index < 3; index += 1) {
35
+ if (left[index] !== right[index]) return left[index] > right[index];
36
+ }
37
+ return false;
38
+ }
39
+
40
+ function writeCache(path, value) {
41
+ try {
42
+ mkdirSync(dirname(path), { recursive: true });
43
+ writeFileSync(path, JSON.stringify(value));
44
+ } catch { /* A read-only cache must not block skill use. */ }
45
+ }
46
+
47
+ function main(now = Date.now()) {
48
+ if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
49
+ const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
50
+ const name = frontmatterValue(skill, 'name');
51
+ const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
52
+ if (!name || !localVersion) return;
53
+
54
+ const lock = readJson(join(process.env.HOME || homedir(), '.agents', '.skill-lock.json'));
55
+ const entry = lock.skills?.[name];
56
+ const repository = repositoryOf(entry?.sourceUrl || entry?.source);
57
+ if (!repository) return;
58
+
59
+ const cacheRoot = process.env.XDG_CACHE_HOME || join(process.env.HOME || homedir(), '.cache');
60
+ const cachePath = join(cacheRoot, '1aboveio-skills', 'release-check.json');
61
+ const all = readJson(cachePath);
62
+ const cache = all[repository] && typeof all[repository] === 'object' ? all[repository] : {};
63
+
64
+ if (!cache.lastCheck || now - cache.lastCheck >= DAY_MS) {
65
+ const result = spawnSync('gh', ['api', 'repos/' + repository + '/releases/latest', '--jq', '.tag_name'], {
66
+ encoding: 'utf8',
67
+ stdio: ['ignore', 'pipe', 'ignore'],
68
+ timeout: 1500,
69
+ });
70
+ cache.lastCheck = now;
71
+ if (result.status === 0 && stableVersion(result.stdout)) cache.latestTag = result.stdout.trim();
72
+ else delete cache.latestTag;
73
+ all[repository] = cache;
74
+ writeCache(cachePath, all);
75
+ }
76
+
77
+ const latestVersion = stableVersion(cache.latestTag);
78
+ if (!latestVersion || !newer(latestVersion, localVersion)) return;
79
+ if (cache.notifiedTag === cache.latestTag && cache.notifiedAt && now - cache.notifiedAt < WEEK_MS) return;
80
+
81
+ cache.notifiedTag = cache.latestTag;
82
+ cache.notifiedAt = now;
83
+ all[repository] = cache;
84
+ writeCache(cachePath, all);
85
+ const command = `npx skills@1.5.23 add '${repository}#${cache.latestTag}' --global --agent universal claude-code --skill ${name} --yes`;
86
+ process.stdout.write(
87
+ `UPDATE_AVAILABLE: A newer 1AboveIO skills release (${cache.latestTag}) is available; this skill is `
88
+ + `v${localVersion.join('.')}. Ask once whether to refresh ${name}. On approval run \`${command}\`. `
89
+ + 'The refreshed instructions apply next session. Either way, continue the current task and do not ask again this session.\n',
90
+ );
91
+ }
92
+
93
+ try { main(); } catch { /* Update checks are advisory and always fail silent. */ }
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env bash
2
+ # start-chrome.sh — Launch Chrome with CDP enabled for weixin-search skill
3
+ # Usage: ./start-chrome.sh [--port 18801] [--profile /tmp/chrome-cdp]
4
+
5
+ set -euo pipefail
6
+
7
+ CDP_PORT="${CDP_PORT:-18801}"
8
+ USER_DATA_DIR="${USER_DATA_DIR:-/tmp/chrome-cdp-profile}"
9
+
10
+ # Parse args
11
+ while [[ $# -gt 0 ]]; do
12
+ case "$1" in
13
+ --port) CDP_PORT="$2"; shift 2 ;;
14
+ --profile) USER_DATA_DIR="$2"; shift 2 ;;
15
+ *) echo "Unknown arg: $1"; exit 1 ;;
16
+ esac
17
+ done
18
+
19
+ # Find Chrome binary
20
+ CHROME=""
21
+ for candidate in \
22
+ google-chrome \
23
+ google-chrome-stable \
24
+ chromium \
25
+ chromium-browser \
26
+ /usr/bin/google-chrome \
27
+ /usr/bin/chromium \
28
+ /snap/bin/chromium; do
29
+ if command -v "$candidate" &>/dev/null || [ -x "$candidate" ]; then
30
+ CHROME="$candidate"
31
+ break
32
+ fi
33
+ done
34
+
35
+ if [ -z "$CHROME" ]; then
36
+ echo "❌ Chrome/Chromium not found. Install with:"
37
+ echo " sudo apt install google-chrome-stable # Debian/Ubuntu"
38
+ echo " sudo dnf install google-chrome-stable # Fedora"
39
+ echo " sudo snap install chromium # Snap"
40
+ exit 1
41
+ fi
42
+
43
+ # Check if CDP port already in use
44
+ if curl -s --max-time 1 "http://localhost:${CDP_PORT}/json/version" &>/dev/null; then
45
+ echo "✅ Chrome already running on CDP port ${CDP_PORT}"
46
+ echo " Tabs: http://localhost:${CDP_PORT}/json"
47
+ exit 0
48
+ fi
49
+
50
+ mkdir -p "$USER_DATA_DIR"
51
+
52
+ echo "🚀 Starting Chrome..."
53
+ echo " Binary: $CHROME"
54
+ echo " CDP port: $CDP_PORT"
55
+ echo " Profile: $USER_DATA_DIR"
56
+
57
+ "$CHROME" \
58
+ --remote-debugging-port="${CDP_PORT}" \
59
+ --user-data-dir="${USER_DATA_DIR}" \
60
+ --no-first-run \
61
+ --no-default-browser-check \
62
+ --disable-background-networking \
63
+ --disable-client-side-phishing-detection \
64
+ --disable-sync \
65
+ &
66
+
67
+ # Wait for Chrome to become ready
68
+ echo -n "⏳ Waiting for CDP..."
69
+ for i in $(seq 1 15); do
70
+ if curl -s --max-time 1 "http://localhost:${CDP_PORT}/json/version" &>/dev/null; then
71
+ echo " ready!"
72
+ echo ""
73
+ echo "✅ Chrome CDP available at http://localhost:${CDP_PORT}"
74
+ echo " Verify tabs: curl http://localhost:${CDP_PORT}/json"
75
+ exit 0
76
+ fi
77
+ echo -n "."
78
+ sleep 1
79
+ done
80
+
81
+ echo ""
82
+ echo "⚠️ Chrome started but CDP not responding after 15s."
83
+ echo " Check manually: curl http://localhost:${CDP_PORT}/json/version"
@@ -0,0 +1,3 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 1AboveIO
@@ -0,0 +1,79 @@
1
+ ---
2
+ name: xai-search
3
+ description: "Fetch real X (Twitter) posts via xAI/Grok live-search: tweets from specific handles, reactions/sentiment on a topic or event, date-filtered posts, live commentary; also explicit Grok/xAI web search or domain-scoped search. Prefer over generic web search when the request centers on X content or names xAI/Grok. NOT for code search, file reads, known-URL scraping, or general research."
4
+ metadata:
5
+ openclaw:
6
+ emoji: "🔍"
7
+ config:
8
+ apiKey:
9
+ type: secret
10
+ required: true
11
+ description: xAI API key (get from console.x.ai)
12
+ release-version: 0.36.0
13
+ ---
14
+ **Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
15
+ # xAI Search (X/Twitter + Web)
16
+
17
+ Search X (formerly Twitter) and the web in real time using xAI's Grok live-search API.
18
+
19
+ ## Prerequisites
20
+
21
+ 1. **Get xAI API key** from [console.x.ai](https://console.x.ai)
22
+ 2. Configure in OpenClaw: `skills.entries.xai-search.apiKey`, or set `XAI_API_KEY` in the environment.
23
+ 3. `jq` and `curl` must be available.
24
+
25
+ ## Invocation
26
+
27
+ Run the bundled script. Pass the skill directory's absolute path or `cd` into it first — the script lives at `scripts/xai_search.sh` relative to this SKILL.md.
28
+
29
+ ### X (Twitter) search
30
+ ```bash
31
+ scripts/xai_search.sh x "What are people saying about AI?"
32
+ scripts/xai_search.sh x "latest updates" --handles elonmusk,xai
33
+ scripts/xai_search.sh x "product launch" --from 2026-01-01 --to 2026-02-01
34
+ ```
35
+
36
+ ### Web search
37
+ ```bash
38
+ scripts/xai_search.sh web "xAI company news"
39
+ scripts/xai_search.sh web "AI research" --domains arxiv.org,openai.com
40
+ ```
41
+
42
+ ## Parameters
43
+
44
+ | Parameter | Applies to | Description |
45
+ |-----------|------------|-------------|
46
+ | `--handles user1,user2` | `x` | Restrict to posts from these handles |
47
+ | `--from YYYY-MM-DD` | `x` | Start date (inclusive) |
48
+ | `--to YYYY-MM-DD` | `x` | End date (inclusive) |
49
+ | `--domains d1,d2` | `web` | Restrict to these domains |
50
+ | `--model MODEL` | both | Override model (default: `grok-4-1-fast-reasoning`) |
51
+ | `--json` | both | Print the raw JSON response instead of formatted text + sources |
52
+
53
+ The script prints the assistant's text answer followed by a `Sources:` block of cited URLs.
54
+
55
+ ## Models
56
+
57
+ | Model | Description |
58
+ |-------|-------------|
59
+ | `grok-4-1-fast-reasoning` | Default. Fast reasoning variant, 2M context, strong tool calling. |
60
+ | `grok-4-1-fast-non-reasoning` | Same family, no chain-of-thought; cheaper for simple lookups. |
61
+
62
+ ## API Usage (curl)
63
+
64
+ ```bash
65
+ curl https://api.x.ai/v1/responses \
66
+ -H "Authorization: Bearer $XAI_API_KEY" \
67
+ -H "Content-Type: application/json" \
68
+ -d '{
69
+ "model": "grok-4-1-fast-reasoning",
70
+ "input": "What are people saying about xAI on X?",
71
+ "tools": [{"type": "x_search"}],
72
+ "tool_choice": "required"
73
+ }'
74
+ ```
75
+
76
+ ## Related Skills
77
+
78
+ - `gemini` skill (when installed) — alternative for general research
79
+ - [web_search](built-in) — Brave Search for web queries
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
4
+ import { homedir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const DAY_MS = 24 * 60 * 60 * 1000;
9
+ const WEEK_MS = 7 * DAY_MS;
10
+ const here = dirname(fileURLToPath(import.meta.url));
11
+
12
+ function readJson(path, fallback = {}) {
13
+ try { return JSON.parse(readFileSync(path, 'utf8')); } catch { return fallback; }
14
+ }
15
+
16
+ function frontmatterValue(text, key) {
17
+ const frontmatter = /^---\n([\s\S]*?)\n---/.exec(text)?.[1] ?? '';
18
+ const match = new RegExp('^' + key + ':\\s*([^\\n]+)$', 'm').exec(frontmatter);
19
+ return match?.[1].trim().replace(/^['"]|['"]$/g, '') ?? null;
20
+ }
21
+
22
+ function repositoryOf(source) {
23
+ const value = String(source ?? '').trim();
24
+ const match = /^(?:git@github\.com:|https:\/\/github\.com\/)?([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+?)(?:\.git)?$/.exec(value);
25
+ return match?.[1] ?? null;
26
+ }
27
+
28
+ function stableVersion(value) {
29
+ const match = /^v?(\d+)\.(\d+)\.(\d+)$/.exec(String(value ?? '').trim());
30
+ return match ? match.slice(1).map(Number) : null;
31
+ }
32
+
33
+ function newer(left, right) {
34
+ for (let index = 0; index < 3; index += 1) {
35
+ if (left[index] !== right[index]) return left[index] > right[index];
36
+ }
37
+ return false;
38
+ }
39
+
40
+ function writeCache(path, value) {
41
+ try {
42
+ mkdirSync(dirname(path), { recursive: true });
43
+ writeFileSync(path, JSON.stringify(value));
44
+ } catch { /* A read-only cache must not block skill use. */ }
45
+ }
46
+
47
+ function main(now = Date.now()) {
48
+ if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
49
+ const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
50
+ const name = frontmatterValue(skill, 'name');
51
+ const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
52
+ if (!name || !localVersion) return;
53
+
54
+ const lock = readJson(join(process.env.HOME || homedir(), '.agents', '.skill-lock.json'));
55
+ const entry = lock.skills?.[name];
56
+ const repository = repositoryOf(entry?.sourceUrl || entry?.source);
57
+ if (!repository) return;
58
+
59
+ const cacheRoot = process.env.XDG_CACHE_HOME || join(process.env.HOME || homedir(), '.cache');
60
+ const cachePath = join(cacheRoot, '1aboveio-skills', 'release-check.json');
61
+ const all = readJson(cachePath);
62
+ const cache = all[repository] && typeof all[repository] === 'object' ? all[repository] : {};
63
+
64
+ if (!cache.lastCheck || now - cache.lastCheck >= DAY_MS) {
65
+ const result = spawnSync('gh', ['api', 'repos/' + repository + '/releases/latest', '--jq', '.tag_name'], {
66
+ encoding: 'utf8',
67
+ stdio: ['ignore', 'pipe', 'ignore'],
68
+ timeout: 1500,
69
+ });
70
+ cache.lastCheck = now;
71
+ if (result.status === 0 && stableVersion(result.stdout)) cache.latestTag = result.stdout.trim();
72
+ else delete cache.latestTag;
73
+ all[repository] = cache;
74
+ writeCache(cachePath, all);
75
+ }
76
+
77
+ const latestVersion = stableVersion(cache.latestTag);
78
+ if (!latestVersion || !newer(latestVersion, localVersion)) return;
79
+ if (cache.notifiedTag === cache.latestTag && cache.notifiedAt && now - cache.notifiedAt < WEEK_MS) return;
80
+
81
+ cache.notifiedTag = cache.latestTag;
82
+ cache.notifiedAt = now;
83
+ all[repository] = cache;
84
+ writeCache(cachePath, all);
85
+ const command = `npx skills@1.5.23 add '${repository}#${cache.latestTag}' --global --agent universal claude-code --skill ${name} --yes`;
86
+ process.stdout.write(
87
+ `UPDATE_AVAILABLE: A newer 1AboveIO skills release (${cache.latestTag}) is available; this skill is `
88
+ + `v${localVersion.join('.')}. Ask once whether to refresh ${name}. On approval run \`${command}\`. `
89
+ + 'The refreshed instructions apply next session. Either way, continue the current task and do not ask again this session.\n',
90
+ );
91
+ }
92
+
93
+ try { main(); } catch { /* Update checks are advisory and always fail silent. */ }
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env bash
2
+ # xAI Search CLI - Search X (Twitter) and Web using xAI Responses API
3
+ # Usage:
4
+ # xai_search.sh x "query" [--handles user1,user2] [--from YYYY-MM-DD] [--to YYYY-MM-DD]
5
+ # xai_search.sh web "query" [--domains domain1,domain2]
6
+
7
+ set -euo pipefail
8
+
9
+ # Get API key from config or environment
10
+ if [[ -z "${XAI_API_KEY:-}" ]]; then
11
+ # Try to get from OpenClaw skill config
12
+ if command -v jq &>/dev/null && [[ -f ~/.openclaw/openclaw.json ]]; then
13
+ XAI_API_KEY=$(jq -r '.skills.entries["xai-search"].apiKey // empty' ~/.openclaw/openclaw.json 2>/dev/null || true)
14
+ fi
15
+ fi
16
+
17
+ if [[ -z "${XAI_API_KEY:-}" ]]; then
18
+ echo "ERROR: XAI_API_KEY not set. Set environment variable or configure in openclaw.json" >&2
19
+ exit 1
20
+ fi
21
+
22
+ if ! command -v jq &>/dev/null; then
23
+ echo "ERROR: jq is required but not installed. Install jq to use this script." >&2
24
+ exit 1
25
+ fi
26
+
27
+ MODE="${1:-}"
28
+ QUERY="${2:-}"
29
+
30
+ if [[ -z "$MODE" || -z "$QUERY" ]]; then
31
+ echo "Usage:" >&2
32
+ echo " xai_search.sh x \"query\" [options] # Search X (Twitter)" >&2
33
+ echo " xai_search.sh web \"query\" [options] # Search the web" >&2
34
+ echo "" >&2
35
+ echo "Options:" >&2
36
+ echo " --handles user1,user2 Only search posts from these handles (X only)" >&2
37
+ echo " --from YYYY-MM-DD Start date" >&2
38
+ echo " --to YYYY-MM-DD End date" >&2
39
+ echo " --domains d1,d2 Only search these domains (web only)" >&2
40
+ echo " --model MODEL Model to use (default: grok-4-1-fast-reasoning)" >&2
41
+ echo " --json Output raw JSON response" >&2
42
+ exit 2
43
+ fi
44
+
45
+ shift 2
46
+
47
+ # Parse options
48
+ HANDLES=""
49
+ FROM_DATE=""
50
+ TO_DATE=""
51
+ DOMAINS=""
52
+ MODEL="grok-4-1-fast-reasoning"
53
+ RAW_JSON=0
54
+
55
+ while [[ $# -gt 0 ]]; do
56
+ case $1 in
57
+ --handles)
58
+ HANDLES="$2"
59
+ shift 2
60
+ ;;
61
+ --from)
62
+ FROM_DATE="$2"
63
+ shift 2
64
+ ;;
65
+ --to)
66
+ TO_DATE="$2"
67
+ shift 2
68
+ ;;
69
+ --domains)
70
+ DOMAINS="$2"
71
+ shift 2
72
+ ;;
73
+ --model)
74
+ MODEL="$2"
75
+ shift 2
76
+ ;;
77
+ --json)
78
+ RAW_JSON=1
79
+ shift
80
+ ;;
81
+ *)
82
+ echo "Unknown option: $1" >&2
83
+ exit 2
84
+ ;;
85
+ esac
86
+ done
87
+
88
+ # Convert comma-delimited list to JSON array.
89
+ csv_to_json_array() {
90
+ local csv="$1"
91
+ if [[ -z "$csv" ]]; then
92
+ jq -cn '[]'
93
+ else
94
+ jq -cn --arg csv "$csv" '$csv | split(",") | map(gsub("^\\s+|\\s+$"; "")) | map(select(length > 0))'
95
+ fi
96
+ }
97
+
98
+ if [[ "$MODE" != "web" && "$MODE" != "x" ]]; then
99
+ echo "ERROR: mode must be 'web' or 'x'" >&2
100
+ exit 2
101
+ fi
102
+
103
+ TOOLS_JSON=""
104
+ if [[ "$MODE" == "web" ]]; then
105
+ if [[ -n "$DOMAINS" ]]; then
106
+ DOMAIN_ARRAY=$(csv_to_json_array "$DOMAINS")
107
+ TOOLS_JSON=$(jq -cn --argjson domains "$DOMAIN_ARRAY" '[{type:"web_search", allowed_domains:$domains}]')
108
+ else
109
+ TOOLS_JSON='[{"type":"web_search"}]'
110
+ fi
111
+ else
112
+ HANDLE_ARRAY=$(csv_to_json_array "$HANDLES")
113
+ TOOLS_JSON=$(jq -cn \
114
+ --argjson handles "$HANDLE_ARRAY" \
115
+ --arg from "$FROM_DATE" \
116
+ --arg to "$TO_DATE" \
117
+ '[{
118
+ type: "x_search",
119
+ allowed_x_handles: (if ($handles | length) > 0 then $handles else null end),
120
+ from_date: (if $from != "" then $from else null end),
121
+ to_date: (if $to != "" then $to else null end)
122
+ }]')
123
+ fi
124
+
125
+ REQUEST_JSON=$(jq -cn \
126
+ --arg model "$MODEL" \
127
+ --arg input "$QUERY" \
128
+ --argjson tools "$TOOLS_JSON" \
129
+ '{
130
+ model: $model,
131
+ input: $input,
132
+ tools: $tools,
133
+ tool_choice: "required"
134
+ }')
135
+
136
+ RESPONSE=$(curl -sS https://api.x.ai/v1/responses \
137
+ -H "Authorization: Bearer $XAI_API_KEY" \
138
+ -H "Content-Type: application/json" \
139
+ -d "$REQUEST_JSON")
140
+
141
+ ERROR=$(echo "$RESPONSE" | jq -r '.error.message // .error // empty' 2>/dev/null || true)
142
+ if [[ -n "$ERROR" ]]; then
143
+ echo "ERROR: $ERROR" >&2
144
+ exit 1
145
+ fi
146
+
147
+ if [[ "$RAW_JSON" -eq 1 ]]; then
148
+ echo "$RESPONSE" | jq '.'
149
+ exit 0
150
+ fi
151
+
152
+ OUTPUT_TEXT=$(echo "$RESPONSE" | jq -r '
153
+ if (.output_text // "") != "" then
154
+ .output_text
155
+ else
156
+ [
157
+ .output[]?
158
+ | select(.type == "message" and .role == "assistant")
159
+ | .content[]?
160
+ | if .type == "output_text" or .type == "text" then (.text // "") else empty end
161
+ ] | join("\n")
162
+ end
163
+ ' 2>/dev/null || true)
164
+
165
+ if [[ -z "${OUTPUT_TEXT// }" ]]; then
166
+ echo "ERROR: No response text from API" >&2
167
+ exit 1
168
+ fi
169
+
170
+ echo "$OUTPUT_TEXT"
171
+
172
+ SOURCES=$(echo "$RESPONSE" | jq -r '
173
+ [
174
+ .output[]?
175
+ | select(.type == "message" and .role == "assistant")
176
+ | .content[]?
177
+ | .annotations[]?
178
+ | select(.type == "url_citation")
179
+ | .url?
180
+ ] | unique | .[]?
181
+ ' 2>/dev/null || true)
182
+
183
+ if [[ -n "$SOURCES" ]]; then
184
+ echo ""
185
+ echo "Sources:"
186
+ echo "$SOURCES"
187
+ fi
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ SCRIPT="$ROOT_DIR/scripts/xai_search.sh"
6
+
7
+ if [[ ! -x "$SCRIPT" ]]; then
8
+ chmod +x "$SCRIPT"
9
+ fi
10
+
11
+ # Best-effort: populate XAI_API_KEY from OpenClaw config if env not set
12
+ if [[ -z "${XAI_API_KEY:-}" ]] && command -v jq &>/dev/null && [[ -f "$HOME/.openclaw/openclaw.json" ]]; then
13
+ XAI_API_KEY=$(jq -r '.skills.entries["xai-search"].apiKey // empty' "$HOME/.openclaw/openclaw.json" 2>/dev/null || true)
14
+ export XAI_API_KEY
15
+ fi
16
+
17
+ if [[ -z "${XAI_API_KEY:-}" ]]; then
18
+ echo "SKIP: XAI_API_KEY is not set (env or openclaw.json); smoke test is best-effort."
19
+ exit 0
20
+ fi
21
+
22
+ echo "Running web mode smoke test..."
23
+ WEB_OUT="$("$SCRIPT" web "latest xAI updates" --domains x.ai)"
24
+ if [[ -z "${WEB_OUT// }" ]]; then
25
+ echo "FAIL: web mode returned empty output"
26
+ exit 1
27
+ fi
28
+
29
+ echo "Running x mode smoke test..."
30
+ X_OUT="$("$SCRIPT" x "xAI announcements" --handles xai --from 2025-01-01)"
31
+ if [[ -z "${X_OUT// }" ]]; then
32
+ echo "FAIL: x mode returned empty output"
33
+ exit 1
34
+ fi
35
+
36
+ echo "PASS: smoke tests produced non-empty output for both modes."