@1aboveio/content-skills 0.1.7 → 0.1.9
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/package.json +2 -2
- package/skills/article-review/SKILL.md +1 -1
- package/skills/article-review/release-check.mjs +3 -1
- package/skills/article-to-image/SKILL.md +1 -1
- package/skills/article-to-image/release-check.mjs +3 -1
- package/skills/flowchart-svg/SKILL.md +1 -1
- package/skills/flowchart-svg/release-check.mjs +3 -1
- package/skills/image-gen/SKILL.md +1 -1
- package/skills/image-gen/release-check.mjs +3 -1
- package/skills/mermaid/SKILL.md +1 -1
- package/skills/mermaid/release-check.mjs +3 -1
- package/skills/wechat-article-writer/SKILL.md +1 -1
- package/skills/wechat-article-writer/release-check.mjs +3 -1
- package/skills/wechat-publisher/SKILL.md +1 -1
- package/skills/wechat-publisher/release-check.mjs +3 -1
- package/skills/wechat-search/SKILL.md +1 -1
- package/skills/wechat-search/release-check.mjs +3 -1
- package/skills/xai-search/SKILL.md +88 -13
- package/skills/xai-search/release-check.mjs +3 -1
- package/skills/xai-search/scripts/xai_search.sh +125 -149
- package/skills/image-gen/scripts/credentials.test.mjs +0 -212
- package/skills/image-gen/scripts/options.test.mjs +0 -245
- package/skills/xai-search/tests/smoke_test.sh +0 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1aboveio/content-skills",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "WeChat articles, reviews and covers, diagrams, image generation and xAI search.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"id": "content",
|
|
28
28
|
"core": "@1aboveio/core-skills",
|
|
29
29
|
"coreSkills": [],
|
|
30
|
-
"digest": "
|
|
30
|
+
"digest": "55495e45d4dd54c565a31be6163bb8daf699f3c8489eb7a32a0c921a256248f4"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -6,7 +6,7 @@ description: >
|
|
|
6
6
|
Use when a user shares an article, pastes article text, sends a URL, or asks to
|
|
7
7
|
review, rate, critique, evaluate, 评价, 点评, 分析, or 看看 any article, post, or 文章.
|
|
8
8
|
Default template is 公众号-支付行业.
|
|
9
|
-
release-version: 0.
|
|
9
|
+
release-version: 0.44.0
|
|
10
10
|
---
|
|
11
11
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
12
12
|
# 文章评审引擎
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: article-to-image
|
|
3
3
|
description: "Generate article cover images: WeChat banner/square (公众号封面), Xiaohongshu (小红书封面), LinkedIn banner, general wide. Brainstorms 4 visual directions from the article, then renders each format with correct aspect ratios and title-safe zones. Use when given an article and asked for covers, banners, or 出图."
|
|
4
|
-
release-version: 0.
|
|
4
|
+
release-version: 0.44.0
|
|
5
5
|
---
|
|
6
6
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
7
7
|
# Article-to-Image
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: flowchart-svg
|
|
3
3
|
description: Create polished flowcharts directly as SVG and export PNG copies. Use when asked to draw, design, render, or deliver process diagrams, architecture diagrams, consulting workflows, decision flows, swimlanes, or other flowcharts as image files, especially when final outputs must include .svg and .png versions.
|
|
4
|
-
release-version: 0.
|
|
4
|
+
release-version: 0.44.0
|
|
5
5
|
---
|
|
6
6
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
7
7
|
# Flowchart SVG
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: image-gen
|
|
3
3
|
description: Generate an image from a text prompt with OpenAI gpt-image-2 or Google Nano Banana (Gemini), saved to an image file. Use whenever the user asks to generate, create, make, draw, paint, render, or design an image, picture, illustration, photo, artwork, logo, icon, avatar, banner, hero image, thumbnail, poster, wallpaper, sticker, or concept art — including phrasings like "an image of X", "a picture of X", "show me what X would look like", or a request for a visual for a slide, blog post, README, or social post. Also triggers on Chinese phrasings such as 生成图片, 画一张图, 做一张海报, 设计一个 logo. NOT for charts or data visualizations (dataviz), flowcharts or architecture diagrams (flowchart-svg), or editing an existing image file.
|
|
4
|
-
release-version: 0.
|
|
4
|
+
release-version: 0.44.0
|
|
5
5
|
---
|
|
6
6
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
7
7
|
# Image Generation
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
package/skills/mermaid/SKILL.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: mermaid
|
|
3
3
|
description: Create and edit Mermaid diagrams for architecture, API flows, database schemas, workflows, and data models.
|
|
4
4
|
user-invocable: true
|
|
5
|
-
release-version: 0.
|
|
5
|
+
release-version: 0.44.0
|
|
6
6
|
---
|
|
7
7
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
8
8
|
# Mermaid Diagram Creation
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: wechat-article-writer
|
|
3
3
|
description: "Write WeChat 公众号 articles in Chinese content styles — 踩坑型 (pitfall-story), 实操型 (how-to), 对比型 (comparison), 观察型 (industry insight) — in the account's house style from the nearest WRITING.md. Use for drafting from scratch, rewriting a draft, adapting source material into a publishable article, or picking the right style. NOT for business or technical documents (write-doc)."
|
|
4
|
-
release-version: 0.
|
|
4
|
+
release-version: 0.44.0
|
|
5
5
|
---
|
|
6
6
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
7
7
|
# WeChat Article Writer (公众号写作)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: wechat-publisher
|
|
3
3
|
description: "Publish articles to a WeChat Official Account (公众号) via API: push Markdown to the draft box (or auto-publish with --publish), convert Markdown to WeChat HTML, upload images to the media library. Requires AppID + AppSecret + whitelisted server IP on a 认证订阅号/服务号. Consumes wechat-article-writer's Markdown."
|
|
4
|
-
release-version: 0.
|
|
4
|
+
release-version: 0.44.0
|
|
5
5
|
---
|
|
6
6
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
7
7
|
# WeChat Publisher (公众号发布)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: wechat-search
|
|
3
3
|
description: "Search WeChat 公众号 articles via Sogou Weixin, or read/summarize an article from a mp.weixin.qq.com URL (读/分析/总结) — suggest proactively when such a URL appears. Use for Chinese WeChat content, industry reports, competitor or trending topics. Requires Chrome Browser Relay. NOT general web search (web_search)."
|
|
4
|
-
release-version: 0.
|
|
4
|
+
release-version: 0.44.0
|
|
5
5
|
---
|
|
6
6
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
7
7
|
# WeChat Article Search & Reader (搜狗微信搜索)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -8,8 +8,8 @@ metadata:
|
|
|
8
8
|
apiKey:
|
|
9
9
|
type: secret
|
|
10
10
|
required: true
|
|
11
|
-
description:
|
|
12
|
-
release-version: 0.
|
|
11
|
+
description: API key for direct xAI or the explicitly configured Responses gateway
|
|
12
|
+
release-version: 0.44.0
|
|
13
13
|
---
|
|
14
14
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
15
15
|
# xAI Search (X/Twitter + Web)
|
|
@@ -18,10 +18,48 @@ Search X (formerly Twitter) and the web in real time using xAI's Grok live-searc
|
|
|
18
18
|
|
|
19
19
|
## Prerequisites
|
|
20
20
|
|
|
21
|
-
1.
|
|
22
|
-
2.
|
|
21
|
+
1. Choose direct xAI or a Responses-compatible gateway, as below.
|
|
22
|
+
2. Set `XAI_API_KEY`, or configure `skills.entries["xai-search"].apiKey` in
|
|
23
|
+
`~/.openclaw/openclaw.json`. A nonempty environment key takes precedence.
|
|
23
24
|
3. `jq` and `curl` must be available.
|
|
24
25
|
|
|
26
|
+
## Endpoint and credentials
|
|
27
|
+
|
|
28
|
+
With no new configuration, requests still go to `https://api.x.ai/v1/responses`
|
|
29
|
+
with the default model `grok-4-1-fast-reasoning`. Get a direct xAI key from
|
|
30
|
+
[console.x.ai](https://console.x.ai).
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
export XAI_API_KEY='<direct-xai-key>'
|
|
34
|
+
scripts/xai_search.sh x "latest xAI announcements"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
For Sub2API, use the deployment's **public HTTPS API base ending in `/v1`**, not
|
|
38
|
+
an internal OAuth proxy URL. Use a **Sub2API API key assigned to a Grok group**,
|
|
39
|
+
not the direct xAI key. Select a model that this group/account actually exposes:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
export XAI_BASE_URL='https://sub2api.example.com/v1'
|
|
43
|
+
export XAI_API_KEY='<sub2api-grok-group-key>'
|
|
44
|
+
scripts/xai_search.sh x "latest xAI announcements" --model grok-4.5
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The example hostname is a placeholder for your deployment. `grok-4.5` is an
|
|
48
|
+
example supported by the inspected Sub2API checkout, not an entitlement promise.
|
|
49
|
+
Model mappings and available names depend on the deployment and subscription
|
|
50
|
+
account; do not assume every public xAI model is available.
|
|
51
|
+
|
|
52
|
+
`XAI_BASE_URL` defaults to `https://api.x.ai/v1`. The CLI removes all trailing
|
|
53
|
+
slashes and appends `/responses` exactly once, so configure an API base, not a full
|
|
54
|
+
Responses URL. An explicitly empty base is invalid. Bases must use HTTPS and
|
|
55
|
+
must not contain URL credentials, query parameters, or fragments. The selected
|
|
56
|
+
key goes only to this endpoint: there is no automatic direct-xAI fallback and
|
|
57
|
+
redirects are not followed. Unset `XAI_BASE_URL` and restore a direct key to
|
|
58
|
+
return to direct xAI. Keep keys out of prompts, command output, and committed files.
|
|
59
|
+
|
|
60
|
+
Native `x_search` and `web_search` require **Responses**. Do not use REST Chat
|
|
61
|
+
Completions or removed `search_parameters` for this workflow.
|
|
62
|
+
|
|
25
63
|
## Invocation
|
|
26
64
|
|
|
27
65
|
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.
|
|
@@ -43,21 +81,36 @@ scripts/xai_search.sh web "AI research" --domains arxiv.org,openai.com
|
|
|
43
81
|
|
|
44
82
|
| Parameter | Applies to | Description |
|
|
45
83
|
|-----------|------------|-------------|
|
|
46
|
-
| `--handles user1,user2` | `x` | Restrict to posts from these handles |
|
|
47
|
-
| `--from YYYY-MM-DD` | `x` |
|
|
48
|
-
| `--to YYYY-MM-DD` | `x` |
|
|
49
|
-
| `--domains d1,d2` | `web` | Restrict to these domains |
|
|
84
|
+
| `--handles user1,user2` | `x` | Restrict to posts from these handles; at most 20 |
|
|
85
|
+
| `--from YYYY-MM-DD` | `x` | Inclusive start at UTC midnight |
|
|
86
|
+
| `--to YYYY-MM-DD` | `x` | Exclusive end at UTC midnight |
|
|
87
|
+
| `--domains d1,d2` | `web` | Restrict to these domains; at most 5 |
|
|
50
88
|
| `--model MODEL` | both | Override model (default: `grok-4-1-fast-reasoning`) |
|
|
51
89
|
| `--json` | both | Print the raw JSON response instead of formatted text + sources |
|
|
90
|
+
| `--help` | both | Show configuration, date boundaries, and limits without credentials |
|
|
91
|
+
|
|
92
|
+
For example, `--from 2026-01-01 --to 2026-02-01` includes January 1 at
|
|
93
|
+
00:00 UTC through, but not including, February 1 at 00:00 UTC. Dates must be real
|
|
94
|
+
calendar dates in `YYYY-MM-DD` form. **Handle/date filters do not constrain thread
|
|
95
|
+
fetches.** CSV entries are trimmed; empty or whitespace-only entries and lists
|
|
96
|
+
above the limit are rejected before a request. Options that take values require
|
|
97
|
+
a nonempty value. Web domains are sent as `tools[].filters.allowed_domains`.
|
|
52
98
|
|
|
53
99
|
The script prints the assistant's text answer followed by a `Sources:` block of cited URLs.
|
|
100
|
+
`--json` preserves the response JSON instead. Any echoed API key is redacted in
|
|
101
|
+
both modes. HTTP errors, transport failures, malformed/non-JSON responses, and
|
|
102
|
+
formatted responses without text exit nonzero; upstream HTML and curl diagnostics
|
|
103
|
+
are not printed because they may contain credentials.
|
|
104
|
+
|
|
105
|
+
## Models and billing
|
|
54
106
|
|
|
55
|
-
|
|
107
|
+
`--model` overrides the unchanged direct default `grok-4-1-fast-reasoning`.
|
|
108
|
+
Choose the exact name exposed by your direct account or gateway's model mapping.
|
|
109
|
+
A gateway key and model must belong to the configured Grok group.
|
|
56
110
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
| `grok-4-1-fast-non-reasoning` | Same family, no chain-of-thought; cheaper for simple lookups. |
|
|
111
|
+
Sub2API may charge a search-call surcharge. Those call counts need not match
|
|
112
|
+
current upstream X pricing based on fetched posts/profiles, so do not use them
|
|
113
|
+
as exact upstream cost reconciliation.
|
|
61
114
|
|
|
62
115
|
## API Usage (curl)
|
|
63
116
|
|
|
@@ -73,6 +126,28 @@ curl https://api.x.ai/v1/responses \
|
|
|
73
126
|
}'
|
|
74
127
|
```
|
|
75
128
|
|
|
129
|
+
## Verification
|
|
130
|
+
|
|
131
|
+
The public CLI tests are offline, use a temporary HOME and a PATH-injected curl
|
|
132
|
+
stand-in, and need no real key or network:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
node --test skills/utils/xai-search/scripts/xai_search.test.mjs
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Do not run a live smoke implicitly. It makes paid requests and requires explicit
|
|
139
|
+
opt-in plus a non-secret account label. Set the endpoint, key, and model for the
|
|
140
|
+
account being tested, then run from the skill directory:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
XAI_LIVE_SMOKE=1 XAI_SMOKE_ACCOUNT='my-grok-group' XAI_SMOKE_MODEL='grok-4.5' \
|
|
144
|
+
bash tests/smoke_test.sh
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The smoke prints the tested account label and model. Offline capture proves the
|
|
148
|
+
client request, not live account entitlement, filter enforcement, or citation
|
|
149
|
+
fidelity. Those remain unverified until an explicitly authorized live test.
|
|
150
|
+
|
|
76
151
|
## Related Skills
|
|
77
152
|
|
|
78
153
|
- `gemini` skill (when installed) — alternative for general research
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -1,187 +1,163 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# xAI Search CLI -
|
|
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
|
-
|
|
2
|
+
# xAI Search CLI - native X/Web tools through the Responses API.
|
|
7
3
|
set -euo pipefail
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
usage() {
|
|
6
|
+
printf '%s\n' \
|
|
7
|
+
'Usage: xai_search.sh {x|web} "query" [options]' \
|
|
8
|
+
'' \
|
|
9
|
+
' --handles user1,user2 X only; at most 20 handles' \
|
|
10
|
+
' --from YYYY-MM-DD X only; inclusive UTC midnight' \
|
|
11
|
+
' --to YYYY-MM-DD X only; exclusive UTC midnight' \
|
|
12
|
+
' --domains d1,d2 Web only; at most 5 domains' \
|
|
13
|
+
' --model MODEL Default: grok-4-1-fast-reasoning' \
|
|
14
|
+
' --json Raw JSON instead of text and citation URLs' \
|
|
15
|
+
' --help Show this help' \
|
|
16
|
+
'' \
|
|
17
|
+
'XAI_BASE_URL defaults to https://api.x.ai/v1; trailing slashes are removed.' \
|
|
18
|
+
'Requests go only to <base>/responses (HTTPS); redirects are not followed.' \
|
|
19
|
+
'XAI_API_KEY overrides skills.entries["xai-search"].apiKey in ~/.openclaw/openclaw.json.' \
|
|
20
|
+
'For Sub2API, use its public /v1 base, a Grok-group key, and --model with an available model (e.g. grok-4.5).' \
|
|
21
|
+
'Native search requires Responses, not REST Chat Completions or legacy search_parameters.' \
|
|
22
|
+
'Handle/date filters do not constrain thread fetches. CSV entries must be nonempty.' \
|
|
23
|
+
'Sub2API search-call surcharges are not exact upstream fetched-post/profile cost reconciliation.'
|
|
24
|
+
}
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
echo "ERROR: jq is required but not installed. Install jq to use this script." >&2
|
|
24
|
-
exit 1
|
|
25
|
-
fi
|
|
26
|
+
fail() { printf 'ERROR: %s\n' "$1" >&2; exit "${2:-2}"; }
|
|
26
27
|
|
|
28
|
+
if [[ "${1:-}" == --help || "${1:-}" == -h ]]; then usage; exit 0; fi
|
|
27
29
|
MODE="${1:-}"
|
|
28
30
|
QUERY="${2:-}"
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
31
|
+
if [[ -z "$MODE" || -z "$QUERY" ]]; then usage >&2; exit 2; fi
|
|
32
|
+
[[ "$MODE" == x || "$MODE" == web ]] || fail "mode must be 'web' or 'x'"
|
|
45
33
|
shift 2
|
|
46
34
|
|
|
47
|
-
# Parse options
|
|
48
35
|
HANDLES=""
|
|
49
36
|
FROM_DATE=""
|
|
50
37
|
TO_DATE=""
|
|
51
38
|
DOMAINS=""
|
|
52
39
|
MODEL="grok-4-1-fast-reasoning"
|
|
53
40
|
RAW_JSON=0
|
|
54
|
-
|
|
55
41
|
while [[ $# -gt 0 ]]; do
|
|
56
|
-
case $1 in
|
|
57
|
-
--handles)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
;;
|
|
42
|
+
case "$1" in
|
|
43
|
+
--handles|--from|--to|--domains|--model)
|
|
44
|
+
[[ $# -ge 2 && -n "${2//[[:space:]]/}" && "$2" != --* ]] || fail "$1 requires a value"
|
|
45
|
+
case "$1" in
|
|
46
|
+
--handles) HANDLES="$2" ;;
|
|
47
|
+
--from) FROM_DATE="$2" ;;
|
|
48
|
+
--to) TO_DATE="$2" ;;
|
|
49
|
+
--domains) DOMAINS="$2" ;;
|
|
50
|
+
--model) MODEL="$2" ;;
|
|
51
|
+
esac
|
|
52
|
+
shift 2 ;;
|
|
53
|
+
--json) RAW_JSON=1; shift ;;
|
|
54
|
+
*) fail 'Unknown option (use --help)' ;;
|
|
85
55
|
esac
|
|
86
56
|
done
|
|
87
57
|
|
|
88
|
-
|
|
58
|
+
command -v jq &>/dev/null || fail 'jq is required but not installed.' 1
|
|
59
|
+
command -v curl &>/dev/null || fail 'curl is required but not installed.' 1
|
|
60
|
+
|
|
89
61
|
csv_to_json_array() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
jq -cn --arg csv "$csv" '$csv | split(",") | map(gsub("^\\s+|\\s+$"; "")) | map(select(length > 0))'
|
|
95
|
-
fi
|
|
62
|
+
jq -cen --arg csv "$1" --argjson max "$2" '
|
|
63
|
+
$csv | split(",") | map(gsub("^\\s+|\\s+$"; ""))
|
|
64
|
+
| select(length <= $max and all(.[]; length > 0))
|
|
65
|
+
' 2>/dev/null
|
|
96
66
|
}
|
|
97
67
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
68
|
+
# Validate the calendar without depending on GNU/BSD date parsing differences.
|
|
69
|
+
valid_date() {
|
|
70
|
+
jq -en --arg date "$1" '
|
|
71
|
+
$date | capture("\\A(?<y>[0-9]{4})-(?<m>[0-9]{2})-(?<d>[0-9]{2})\\z")
|
|
72
|
+
| (.y|tonumber) as $y | (.m|tonumber) as $m | (.d|tonumber) as $d
|
|
73
|
+
| [31, (if ($y%400 == 0 or ($y%4 == 0 and $y%100 != 0)) then 29 else 28 end),
|
|
74
|
+
31,30,31,30,31,31,30,31,30,31] as $days
|
|
75
|
+
| $y >= 1 and $m >= 1 and $m <= 12 and $d >= 1 and $d <= $days[$m-1]
|
|
76
|
+
' >/dev/null 2>&1
|
|
77
|
+
}
|
|
102
78
|
|
|
103
|
-
|
|
104
|
-
|
|
79
|
+
[[ -z "$FROM_DATE" ]] || valid_date "$FROM_DATE" || fail '--from requires a valid YYYY-MM-DD calendar date'
|
|
80
|
+
[[ -z "$TO_DATE" ]] || valid_date "$TO_DATE" || fail '--to requires a valid YYYY-MM-DD calendar date'
|
|
81
|
+
|
|
82
|
+
if [[ "$MODE" == web ]]; then
|
|
105
83
|
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}]')
|
|
84
|
+
DOMAIN_ARRAY=$(csv_to_json_array "$DOMAINS" 5) || fail '--domains requires 1 to 5 nonempty CSV entries'
|
|
85
|
+
TOOLS_JSON=$(jq -cn --argjson domains "$DOMAIN_ARRAY" '[{type:"web_search", filters:{allowed_domains:$domains}}]')
|
|
108
86
|
else
|
|
109
87
|
TOOLS_JSON='[{"type":"web_search"}]'
|
|
110
88
|
fi
|
|
111
89
|
else
|
|
112
|
-
HANDLE_ARRAY
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
to_date: (if $to != "" then $to else null end)
|
|
122
|
-
}]')
|
|
90
|
+
HANDLE_ARRAY='[]'
|
|
91
|
+
if [[ -n "$HANDLES" ]]; then
|
|
92
|
+
HANDLE_ARRAY=$(csv_to_json_array "$HANDLES" 20) || fail '--handles requires 1 to 20 nonempty CSV entries'
|
|
93
|
+
fi
|
|
94
|
+
TOOLS_JSON=$(jq -cn --argjson handles "$HANDLE_ARRAY" --arg from "$FROM_DATE" --arg to "$TO_DATE" '
|
|
95
|
+
[{type:"x_search"}
|
|
96
|
+
+ (if ($handles|length) > 0 then {allowed_x_handles:$handles} else {} end)
|
|
97
|
+
+ (if $from != "" then {from_date:$from} else {} end)
|
|
98
|
+
+ (if $to != "" then {to_date:$to} else {} end)]')
|
|
123
99
|
fi
|
|
124
100
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
101
|
+
BASE_URL="${XAI_BASE_URL-https://api.x.ai/v1}"
|
|
102
|
+
while [[ "$BASE_URL" == */ ]]; do BASE_URL="${BASE_URL%/}"; done
|
|
103
|
+
if ! jq -en --arg base "$BASE_URL" '$base | test("\\Ahttps://[^/@?#\\s]+(/[^?#\\s]*)?\\z")' >/dev/null; then
|
|
104
|
+
fail 'XAI_BASE_URL must be an HTTPS API base without credentials, query, or fragment'
|
|
145
105
|
fi
|
|
146
106
|
|
|
147
|
-
if [[ "$
|
|
148
|
-
|
|
149
|
-
|
|
107
|
+
if [[ -z "${XAI_API_KEY:-}" && -f "$HOME/.openclaw/openclaw.json" ]]; then
|
|
108
|
+
XAI_API_KEY=$(jq -r '.skills.entries["xai-search"].apiKey // empty' "$HOME/.openclaw/openclaw.json" 2>/dev/null || true)
|
|
109
|
+
fi
|
|
110
|
+
[[ -n "${XAI_API_KEY:-}" ]] || fail 'XAI_API_KEY not set. Set environment variable or configure in openclaw.json' 1
|
|
111
|
+
[[ "$XAI_API_KEY" != *$'\r'* && "$XAI_API_KEY" != *$'\n'* ]] || fail 'API key must not contain line breaks' 1
|
|
112
|
+
|
|
113
|
+
REQUEST_JSON=$(jq -cn --arg model "$MODEL" --arg input "$QUERY" --argjson tools "$TOOLS_JSON" \
|
|
114
|
+
'{model:$model, input:$input, tools:$tools, tool_choice:"required"}')
|
|
115
|
+
|
|
116
|
+
# Keep the key out of curl argv and private response files out of other users' reach.
|
|
117
|
+
umask 077
|
|
118
|
+
WORK_DIR=$(mktemp -d "${TMPDIR:-/tmp}/xai-search.XXXXXXXX")
|
|
119
|
+
trap 'rm -rf "$WORK_DIR"' EXIT
|
|
120
|
+
printf 'Authorization: Bearer %s\nContent-Type: application/json\n' "$XAI_API_KEY" > "$WORK_DIR/headers"
|
|
121
|
+
if HTTP_STATUS=$(curl --disable --silent --show-error --globoff --proto '=https' \
|
|
122
|
+
--url "$BASE_URL/responses" --header "@$WORK_DIR/headers" \
|
|
123
|
+
--data "$REQUEST_JSON" --output "$WORK_DIR/response" --write-out '%{http_code}' 2>/dev/null); then
|
|
124
|
+
:
|
|
125
|
+
else
|
|
126
|
+
CURL_STATUS=$?
|
|
127
|
+
fail "API transport failed (curl exit $CURL_STATUS); check endpoint and connectivity" 1
|
|
150
128
|
fi
|
|
151
129
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
' 2>/dev/null
|
|
130
|
+
# Decode before redaction so JSON escapes cannot hide an echoed credential.
|
|
131
|
+
if ! RESPONSE=$(jq -cs --arg key "$XAI_API_KEY" '
|
|
132
|
+
if length == 1 and (.[0] | type == "object") then
|
|
133
|
+
.[0] | walk(
|
|
134
|
+
if type == "string" then split($key) | join("[REDACTED]")
|
|
135
|
+
elif type == "object" then with_entries(.key |= (split($key) | join("[REDACTED]")))
|
|
136
|
+
else . end)
|
|
137
|
+
else error("Expected one response object") end
|
|
138
|
+
' "$WORK_DIR/response" 2>/dev/null); then
|
|
139
|
+
fail "API returned malformed or non-JSON response (HTTP $HTTP_STATUS)" 1
|
|
140
|
+
fi
|
|
141
|
+
ERROR=$(printf '%s' "$RESPONSE" | jq -r 'if .error then (.error | if type == "object" then (.message // "upstream error") else tostring end) else empty end' 2>/dev/null)
|
|
142
|
+
if [[ ! "$HTTP_STATUS" =~ ^2[0-9][0-9]$ ]]; then
|
|
143
|
+
fail "API HTTP $HTTP_STATUS: ${ERROR:-request failed}" 1
|
|
144
|
+
fi
|
|
145
|
+
[[ -z "$ERROR" ]] || fail "API error: $ERROR" 1
|
|
164
146
|
|
|
165
|
-
if [[
|
|
166
|
-
|
|
167
|
-
exit
|
|
147
|
+
if [[ "$RAW_JSON" -eq 1 ]]; then
|
|
148
|
+
printf '%s' "$RESPONSE" | jq '.'
|
|
149
|
+
exit 0
|
|
168
150
|
fi
|
|
169
151
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
.output[]?
|
|
175
|
-
| select(.type == "message" and .role == "assistant")
|
|
176
|
-
| .content[]?
|
|
177
|
-
| .annotations[]?
|
|
178
|
-
| select(.type == "url_citation")
|
|
179
|
-
| .url?
|
|
180
|
-
] | unique | .[]?
|
|
152
|
+
OUTPUT_TEXT=$(printf '%s' "$RESPONSE" | jq -r '
|
|
153
|
+
if (.output_text // "") != "" then .output_text
|
|
154
|
+
else [.output[]? | select(.type == "message" and .role == "assistant")
|
|
155
|
+
| .content[]? | if .type == "output_text" or .type == "text" then (.text // "") else empty end] | join("\n") end
|
|
181
156
|
' 2>/dev/null || true)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
157
|
+
[[ -n "${OUTPUT_TEXT//[[:space:]]/}" ]] || fail 'No response text from API' 1
|
|
158
|
+
printf '%s\n' "$OUTPUT_TEXT"
|
|
159
|
+
SOURCES=$(printf '%s' "$RESPONSE" | jq -r '
|
|
160
|
+
[.output[]? | select(.type == "message" and .role == "assistant") | .content[]?
|
|
161
|
+
| .annotations[]? | select(.type == "url_citation") | .url?] | unique | .[]?
|
|
162
|
+
' 2>/dev/null || true)
|
|
163
|
+
if [[ -n "$SOURCES" ]]; then printf '\nSources:\n%s\n' "$SOURCES"; fi
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { mkdtemp, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { describe, it } from 'node:test';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
DEFAULT_OPENAI_BASE_URL,
|
|
9
|
-
expandPiValue,
|
|
10
|
-
piModelsPath,
|
|
11
|
-
resolveGemini,
|
|
12
|
-
resolveOpenAI,
|
|
13
|
-
} from './credentials.mjs';
|
|
14
|
-
|
|
15
|
-
async function writeConfig(contents) {
|
|
16
|
-
const dir = await mkdtemp(join(tmpdir(), 'image-gen-creds-'));
|
|
17
|
-
const path = join(dir, 'models.json');
|
|
18
|
-
await writeFile(path, typeof contents === 'string' ? contents : JSON.stringify(contents));
|
|
19
|
-
return path;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const piConfig = (openai) => ({ providers: { openai } });
|
|
23
|
-
|
|
24
|
-
// A literal key, the case where the pi fallback can actually produce one.
|
|
25
|
-
const LITERAL = { baseUrl: 'https://pi-gateway.example/v1', apiKey: 'pi-key' };
|
|
26
|
-
|
|
27
|
-
describe('expandPiValue', () => {
|
|
28
|
-
it('passes literals through', () => {
|
|
29
|
-
assert.equal(expandPiValue('sk-literal', {}).value, 'sk-literal');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('expands $VAR and ${VAR}', () => {
|
|
33
|
-
assert.equal(expandPiValue('$KEY', { KEY: 'v' }).value, 'v');
|
|
34
|
-
assert.equal(expandPiValue('${KEY}', { KEY: 'v' }).value, 'v');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('expands variables embedded in surrounding text', () => {
|
|
38
|
-
const resolved = expandPiValue('https://$HOST/v1', { HOST: 'gw.example' });
|
|
39
|
-
|
|
40
|
-
assert.equal(resolved.value, 'https://gw.example/v1');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('reports every unresolved variable instead of expanding partially', () => {
|
|
44
|
-
const resolved = expandPiValue('$A-$B', { A: 'a' });
|
|
45
|
-
|
|
46
|
-
assert.equal(resolved.value, undefined);
|
|
47
|
-
assert.deepEqual(resolved.missing, ['B']);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('treats an empty variable as unset, as pi does', () => {
|
|
51
|
-
assert.deepEqual(expandPiValue('$KEY', { KEY: '' }).missing, ['KEY']);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('honors the $$ and $! escapes', () => {
|
|
55
|
-
assert.equal(expandPiValue('$$KEY', { KEY: 'v' }).value, '$KEY');
|
|
56
|
-
assert.equal(expandPiValue('$!cmd', {}).value, '!cmd');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('keeps a dangling $ or unterminated ${ literal', () => {
|
|
60
|
-
assert.equal(expandPiValue('pre$', {}).value, 'pre$');
|
|
61
|
-
assert.equal(expandPiValue('${unterminated', {}).value, '${unterminated');
|
|
62
|
-
assert.equal(expandPiValue('$ {KEY}', {}).value, '$ {KEY}');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('flags !command values rather than executing them', () => {
|
|
66
|
-
const resolved = expandPiValue('!security find-generic-password -w', {});
|
|
67
|
-
|
|
68
|
-
assert.equal(resolved.value, undefined);
|
|
69
|
-
assert.equal(resolved.command, 'security find-generic-password -w');
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('resolveOpenAI', () => {
|
|
74
|
-
it('prefers the environment over the pi config', async () => {
|
|
75
|
-
const configPath = await writeConfig(piConfig(LITERAL));
|
|
76
|
-
const resolved = await resolveOpenAI({
|
|
77
|
-
env: { OPENAI_API_KEY: 'env-key', OPENAI_BASE_URL: 'https://env-gateway.example/v1' },
|
|
78
|
-
configPath,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
assert.equal(resolved.ok, true);
|
|
82
|
-
assert.equal(resolved.apiKey, 'env-key');
|
|
83
|
-
assert.equal(resolved.baseUrl, 'https://env-gateway.example/v1');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('defaults the base URL when only the env key is set', async () => {
|
|
87
|
-
const resolved = await resolveOpenAI({ env: { OPENAI_API_KEY: 'k' }, configPath: '/nope' });
|
|
88
|
-
|
|
89
|
-
assert.equal(resolved.baseUrl, DEFAULT_OPENAI_BASE_URL);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('strips trailing slashes so the path join stays well formed', async () => {
|
|
93
|
-
const resolved = await resolveOpenAI({
|
|
94
|
-
env: { OPENAI_API_KEY: 'k', OPENAI_BASE_URL: 'https://gw.example/v1///' },
|
|
95
|
-
configPath: '/nope',
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
assert.equal(resolved.baseUrl, 'https://gw.example/v1');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('falls back to a literal pi key, taking pi\'s base URL with it', async () => {
|
|
102
|
-
const configPath = await writeConfig(piConfig(LITERAL));
|
|
103
|
-
const resolved = await resolveOpenAI({ env: {}, configPath });
|
|
104
|
-
|
|
105
|
-
assert.equal(resolved.ok, true);
|
|
106
|
-
assert.equal(resolved.apiKey, 'pi-key');
|
|
107
|
-
assert.equal(resolved.baseUrl, 'https://pi-gateway.example/v1');
|
|
108
|
-
assert.match(resolved.source, /^pi config/);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('expands a pi key that references another variable', async () => {
|
|
112
|
-
const configPath = await writeConfig(piConfig({ ...LITERAL, apiKey: '$GAPSEE_KEY' }));
|
|
113
|
-
const resolved = await resolveOpenAI({ env: { GAPSEE_KEY: 'sk-real' }, configPath });
|
|
114
|
-
|
|
115
|
-
assert.equal(resolved.ok, true);
|
|
116
|
-
assert.equal(resolved.apiKey, 'sk-real');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('never sends an unexpanded template as the bearer token', async () => {
|
|
120
|
-
// The bug this guards: `$OPENAI_API_KEY` reaching the API verbatim.
|
|
121
|
-
const configPath = await writeConfig(piConfig({ ...LITERAL, apiKey: '$SOME_KEY' }));
|
|
122
|
-
const resolved = await resolveOpenAI({ env: {}, configPath });
|
|
123
|
-
|
|
124
|
-
assert.equal(resolved.ok, false);
|
|
125
|
-
assert.match(resolved.reason, /\$SOME_KEY/);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('explains why a pi entry pointing at $OPENAI_API_KEY can never satisfy the fallback', async () => {
|
|
129
|
-
const configPath = await writeConfig(piConfig({ ...LITERAL, apiKey: '$OPENAI_API_KEY' }));
|
|
130
|
-
const resolved = await resolveOpenAI({ env: {}, configPath });
|
|
131
|
-
|
|
132
|
-
assert.equal(resolved.ok, false);
|
|
133
|
-
assert.match(resolved.reason, /can never satisfy this fallback/);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('expands a templated pi base URL', async () => {
|
|
137
|
-
const configPath = await writeConfig(piConfig({ apiKey: 'pi-key', baseUrl: 'https://$GW/v1' }));
|
|
138
|
-
const resolved = await resolveOpenAI({ env: { GW: 'gw.example' }, configPath });
|
|
139
|
-
|
|
140
|
-
assert.equal(resolved.baseUrl, 'https://gw.example/v1');
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('fails rather than silently retargeting when the pi base URL cannot expand', async () => {
|
|
144
|
-
// Falling back to api.openai.com here would send a gateway key to OpenAI.
|
|
145
|
-
const configPath = await writeConfig(piConfig({ apiKey: 'pi-key', baseUrl: 'https://$GW/v1' }));
|
|
146
|
-
const resolved = await resolveOpenAI({ env: {}, configPath });
|
|
147
|
-
|
|
148
|
-
assert.equal(resolved.ok, false);
|
|
149
|
-
assert.match(resolved.reason, /\$GW/);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('defaults the base URL when the pi provider omits one', async () => {
|
|
153
|
-
const configPath = await writeConfig(piConfig({ apiKey: 'pi-key' }));
|
|
154
|
-
const resolved = await resolveOpenAI({ env: {}, configPath });
|
|
155
|
-
|
|
156
|
-
assert.equal(resolved.baseUrl, DEFAULT_OPENAI_BASE_URL);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('reports !command keys as unsupported instead of running them', async () => {
|
|
160
|
-
const configPath = await writeConfig(piConfig({ ...LITERAL, apiKey: '!echo sk-x' }));
|
|
161
|
-
const resolved = await resolveOpenAI({ env: {}, configPath });
|
|
162
|
-
|
|
163
|
-
assert.equal(resolved.ok, false);
|
|
164
|
-
assert.match(resolved.reason, /does not execute config commands/);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('ignores OPENAI_BASE_URL when the key comes from pi', async () => {
|
|
168
|
-
const configPath = await writeConfig(piConfig(LITERAL));
|
|
169
|
-
const resolved = await resolveOpenAI({
|
|
170
|
-
env: { OPENAI_BASE_URL: 'https://env-gateway.example/v1' },
|
|
171
|
-
configPath,
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
assert.equal(resolved.baseUrl, 'https://pi-gateway.example/v1');
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('fails with the config path when there is nothing to fall back to', async () => {
|
|
178
|
-
const missing = await resolveOpenAI({ env: {}, configPath: '/definitely/not/here.json' });
|
|
179
|
-
const malformed = await resolveOpenAI({ env: {}, configPath: await writeConfig('{ not json') });
|
|
180
|
-
const noKey = await writeConfig(piConfig({ baseUrl: 'https://x.example/v1' }));
|
|
181
|
-
const otherProvider = await writeConfig({ providers: { deepseek: { apiKey: 'k' } } });
|
|
182
|
-
|
|
183
|
-
assert.equal(missing.ok, false);
|
|
184
|
-
assert.match(missing.reason, /definitely\/not\/here\.json/);
|
|
185
|
-
assert.equal(malformed.ok, false);
|
|
186
|
-
assert.equal((await resolveOpenAI({ env: {}, configPath: noKey })).ok, false);
|
|
187
|
-
assert.equal((await resolveOpenAI({ env: {}, configPath: otherProvider })).ok, false);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe('piModelsPath', () => {
|
|
192
|
-
it('honors PI_CODING_AGENT_DIR', () => {
|
|
193
|
-
assert.equal(piModelsPath({ PI_CODING_AGENT_DIR: '/custom/agent' }), '/custom/agent/models.json');
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('defaults to the pi agent directory under $HOME', () => {
|
|
197
|
-
assert.match(piModelsPath({}), /[/\\]\.pi[/\\]agent[/\\]models\.json$/);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
describe('resolveGemini', () => {
|
|
202
|
-
it('reads the env key', () => {
|
|
203
|
-
assert.equal(resolveGemini({ env: { GEMINI_API_KEY: 'g-key' } }).apiKey, 'g-key');
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('fails with a reason without one', () => {
|
|
207
|
-
const resolved = resolveGemini({ env: {} });
|
|
208
|
-
|
|
209
|
-
assert.equal(resolved.ok, false);
|
|
210
|
-
assert.match(resolved.reason, /GEMINI_API_KEY/);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { describe, it } from 'node:test';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
GEMINI_ASPECT_RATIOS,
|
|
6
|
-
describeSizeMismatch,
|
|
7
|
-
extensionForMimeType,
|
|
8
|
-
imageDimensions,
|
|
9
|
-
geminiAspectRatio,
|
|
10
|
-
openAiSize,
|
|
11
|
-
parseArgs,
|
|
12
|
-
resolveOutputPath,
|
|
13
|
-
} from './options.mjs';
|
|
14
|
-
|
|
15
|
-
describe('parseArgs', () => {
|
|
16
|
-
it('joins the positional words into the prompt', () => {
|
|
17
|
-
const { prompt, errors } = parseArgs(['a', 'red', 'fox']);
|
|
18
|
-
|
|
19
|
-
assert.equal(prompt, 'a red fox');
|
|
20
|
-
assert.deepEqual(errors, []);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('accepts --flag value and --flag=value alike', () => {
|
|
24
|
-
assert.equal(parseArgs(['p', '--model', 'm']).flags.model, 'm');
|
|
25
|
-
assert.equal(parseArgs(['p', '--model=m']).flags.model, 'm');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('rejects an unknown flag instead of ignoring it', () => {
|
|
29
|
-
// The old parser accepted --qualtiy silently and generated at the default.
|
|
30
|
-
const { errors } = parseArgs(['p', '--qualtiy', 'high']);
|
|
31
|
-
|
|
32
|
-
assert.equal(errors.length, 1);
|
|
33
|
-
assert.match(errors[0], /Unknown option --qualtiy/);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('suggests the intended flag for a near miss', () => {
|
|
37
|
-
assert.match(parseArgs(['p', '--outpt', 'x.png']).errors[0], /Did you mean --output\?/);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('does not let a flag swallow the next flag as its value', () => {
|
|
41
|
-
// `--quality --output x.png` used to set quality="--output" and lose the path.
|
|
42
|
-
const { flags, errors } = parseArgs(['p', '--quality', '--output', 'x.png']);
|
|
43
|
-
|
|
44
|
-
assert.match(errors[0], /--quality needs a value/);
|
|
45
|
-
assert.equal(flags.output, 'x.png');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('reports a trailing flag with no value', () => {
|
|
49
|
-
assert.match(parseArgs(['p', '--output']).errors[0], /--output needs a value/);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('validates enumerated flag values', () => {
|
|
53
|
-
assert.match(parseArgs(['p', '--provider', 'midjourney']).errors[0], /Invalid --provider/);
|
|
54
|
-
assert.match(parseArgs(['p', '--quality', 'ultra']).errors[0], /Invalid --quality/);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('warns and drops a flag that does not apply to the chosen provider', () => {
|
|
58
|
-
const { flags, warnings } = parseArgs(['p', '--provider', 'gemini', '--quality', 'high']);
|
|
59
|
-
|
|
60
|
-
assert.equal(flags.quality, undefined);
|
|
61
|
-
assert.match(warnings[0], /--quality applies to openai only/);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('keeps provider-specific flags when the provider does match', () => {
|
|
65
|
-
assert.equal(parseArgs(['p', '--quality', 'high']).flags.quality, 'high');
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('openAiSize', () => {
|
|
70
|
-
it('defaults to a square', () => {
|
|
71
|
-
assert.equal(openAiSize(undefined).value, '1024x1024');
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('accepts the documented sizes and rejects others', () => {
|
|
75
|
-
assert.equal(openAiSize('1536x1024').value, '1536x1024');
|
|
76
|
-
assert.match(openAiSize('800x600').error, /Invalid size/);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('geminiAspectRatio', () => {
|
|
81
|
-
it('sends nothing when no size is given', () => {
|
|
82
|
-
assert.equal(geminiAspectRatio(undefined).value, undefined);
|
|
83
|
-
assert.equal(geminiAspectRatio('auto').value, undefined);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('passes a supported ratio straight through', () => {
|
|
87
|
-
assert.equal(geminiAspectRatio('16:9').value, '16:9');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('snaps pixel dimensions to the nearest supported ratio', () => {
|
|
91
|
-
// This is the whole point: --size used to be discarded for Gemini.
|
|
92
|
-
assert.equal(geminiAspectRatio('1536x1024').value, '3:2');
|
|
93
|
-
assert.equal(geminiAspectRatio('1024x1536').value, '2:3');
|
|
94
|
-
assert.equal(geminiAspectRatio('1920x1080').value, '16:9');
|
|
95
|
-
assert.equal(geminiAspectRatio('1024x1024').value, '1:1');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('reports what it snapped away from, so the change is visible', () => {
|
|
99
|
-
const snapped = geminiAspectRatio('1000x500');
|
|
100
|
-
|
|
101
|
-
// 2:1 is not supported; 16:9 is the closest thing to it that is.
|
|
102
|
-
assert.equal(snapped.value, '16:9');
|
|
103
|
-
assert.equal(snapped.snappedFrom, '1000x500');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('treats an exact square as exact, not snapped', () => {
|
|
107
|
-
assert.equal(geminiAspectRatio('1024x1024').snappedFrom, undefined);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('rejects a well-formed ratio the API does not support', () => {
|
|
111
|
-
const rejected = geminiAspectRatio('7:5');
|
|
112
|
-
|
|
113
|
-
assert.match(rejected.error, /does not support the aspect ratio "7:5"/);
|
|
114
|
-
assert.match(rejected.error, /16:9/);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('rejects unparseable sizes and zero dimensions', () => {
|
|
118
|
-
assert.match(geminiAspectRatio('huge').error, /Invalid size/);
|
|
119
|
-
assert.match(geminiAspectRatio('0x100').error, /zero dimension/);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('only ever emits ratios the API accepts', () => {
|
|
123
|
-
for (const size of ['1536x1024', '1024x1536', '1920x1080', '100x800', '800x100']) {
|
|
124
|
-
assert.ok(GEMINI_ASPECT_RATIOS.includes(geminiAspectRatio(size).value), size);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe('extensionForMimeType', () => {
|
|
130
|
-
it('maps the image types a provider may return', () => {
|
|
131
|
-
assert.equal(extensionForMimeType('image/png'), '.png');
|
|
132
|
-
assert.equal(extensionForMimeType('image/jpeg'), '.jpg');
|
|
133
|
-
assert.equal(extensionForMimeType('image/webp'), '.webp');
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('ignores charset parameters and casing', () => {
|
|
137
|
-
assert.equal(extensionForMimeType('IMAGE/JPEG; charset=binary'), '.jpg');
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('falls back to .png for anything unrecognized', () => {
|
|
141
|
-
assert.equal(extensionForMimeType(undefined), '.png');
|
|
142
|
-
assert.equal(extensionForMimeType('application/octet-stream'), '.png');
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe('resolveOutputPath', () => {
|
|
147
|
-
it('names the default file after the bytes actually returned', () => {
|
|
148
|
-
const resolved = resolveOutputPath({ defaultBase: './generated-1', mimeType: 'image/jpeg' });
|
|
149
|
-
|
|
150
|
-
assert.equal(resolved.path, './generated-1.jpg');
|
|
151
|
-
assert.equal(resolved.warning, undefined);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('honors an explicit path but flags an extension mismatch', () => {
|
|
155
|
-
const resolved = resolveOutputPath({ requested: 'logo.png', mimeType: 'image/webp' });
|
|
156
|
-
|
|
157
|
-
assert.equal(resolved.path, 'logo.png');
|
|
158
|
-
assert.match(resolved.warning, /image\/webp/);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('stays quiet when the extension already matches', () => {
|
|
162
|
-
assert.equal(resolveOutputPath({ requested: 'logo.png', mimeType: 'image/png' }).warning, undefined);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('appends an extension when the requested path has none', () => {
|
|
166
|
-
assert.equal(resolveOutputPath({ requested: 'logo', mimeType: 'image/png' }).path, 'logo.png');
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
describe('imageDimensions', () => {
|
|
171
|
-
const png = (w, h) => {
|
|
172
|
-
const b = Buffer.alloc(24);
|
|
173
|
-
b.writeUInt32BE(0x89504e47, 0);
|
|
174
|
-
b.writeUInt32BE(w, 16);
|
|
175
|
-
b.writeUInt32BE(h, 20);
|
|
176
|
-
return b;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
it('reads PNG dimensions', () => {
|
|
180
|
-
assert.deepEqual(imageDimensions(png(1536, 1024)), { width: 1536, height: 1024 });
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('reads JPEG dimensions from the start-of-frame marker', () => {
|
|
184
|
-
const b = Buffer.alloc(32, 0);
|
|
185
|
-
b[0] = 0xff; b[1] = 0xd8; // SOI
|
|
186
|
-
b[2] = 0xff; b[3] = 0xe0; // APP0, skipped via its length
|
|
187
|
-
b.writeUInt16BE(6, 4);
|
|
188
|
-
b[10] = 0xff; b[11] = 0xc0; // SOF0
|
|
189
|
-
b.writeUInt16BE(17, 12);
|
|
190
|
-
b.writeUInt16BE(480, 15); // height
|
|
191
|
-
b.writeUInt16BE(640, 17); // width
|
|
192
|
-
|
|
193
|
-
assert.deepEqual(imageDimensions(b), { width: 640, height: 480 });
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('reads WebP VP8X canvas size', () => {
|
|
197
|
-
const b = Buffer.alloc(32, 0);
|
|
198
|
-
b.write('RIFF', 0, 'ascii');
|
|
199
|
-
b.write('WEBP', 8, 'ascii');
|
|
200
|
-
b.write('VP8X', 12, 'ascii');
|
|
201
|
-
b.writeUIntLE(1023, 24, 3); // stored as width - 1
|
|
202
|
-
b.writeUIntLE(767, 27, 3);
|
|
203
|
-
|
|
204
|
-
assert.deepEqual(imageDimensions(b), { width: 1024, height: 768 });
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it('returns null for formats it cannot parse, rather than guessing', () => {
|
|
208
|
-
assert.equal(imageDimensions(Buffer.alloc(4)), null);
|
|
209
|
-
assert.equal(imageDimensions(Buffer.alloc(64, 7)), null);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe('describeSizeMismatch', () => {
|
|
214
|
-
it('reports a pixel-size substitution', () => {
|
|
215
|
-
// The observed case: 1024x1536 requested, 1402x1122 returned.
|
|
216
|
-
const warning = describeSizeMismatch({
|
|
217
|
-
requestedSize: '1024x1536',
|
|
218
|
-
actual: { width: 1402, height: 1122 },
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
assert.match(warning, /Requested 1024x1536 but the provider returned 1402x1122/);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('stays quiet when the size matches', () => {
|
|
225
|
-
assert.equal(
|
|
226
|
-
describeSizeMismatch({ requestedSize: '1536x1024', actual: { width: 1536, height: 1024 } }),
|
|
227
|
-
undefined,
|
|
228
|
-
);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('reports an aspect-ratio substitution within a rounding tolerance', () => {
|
|
232
|
-
assert.equal(
|
|
233
|
-
describeSizeMismatch({ aspectRatio: '16:9', actual: { width: 1920, height: 1080 } }),
|
|
234
|
-
undefined,
|
|
235
|
-
);
|
|
236
|
-
assert.match(
|
|
237
|
-
describeSizeMismatch({ aspectRatio: '16:9', actual: { width: 1024, height: 1024 } }),
|
|
238
|
-
/Requested aspect ratio 16:9/,
|
|
239
|
-
);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('says nothing when dimensions could not be read', () => {
|
|
243
|
-
assert.equal(describeSizeMismatch({ requestedSize: '1024x1024', actual: null }), undefined);
|
|
244
|
-
});
|
|
245
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
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."
|