@refhub/cli 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -19
- package/dist/client.d.ts +24 -19
- package/dist/client.js +77 -45
- package/dist/commands/discover.d.ts +12 -0
- package/dist/commands/discover.js +96 -0
- package/dist/commands/enrich.d.ts +2 -2
- package/dist/commands/enrich.js +4 -6
- package/dist/commands/pdf.d.ts +2 -2
- package/dist/commands/pdf.js +9 -9
- package/dist/index.js +6 -2
- package/dist/types.d.ts +26 -0
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ npm install -g @refhub/cli
|
|
|
18
18
|
### install from source
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
git clone https://github.com/refhub/refhub-cli
|
|
21
|
+
git clone https://github.com/refhub-io/refhub-cli
|
|
22
22
|
cd refhub-cli
|
|
23
23
|
npm install
|
|
24
24
|
npm run build
|
|
@@ -29,7 +29,7 @@ npm link
|
|
|
29
29
|
|
|
30
30
|
## // auth
|
|
31
31
|
|
|
32
|
-
The CLI uses
|
|
32
|
+
The CLI uses a RefHub API key for normal agent/runtime work:
|
|
33
33
|
|
|
34
34
|
**API key** — required for all vault/item/tag/relation/import/export/audit commands:
|
|
35
35
|
```bash
|
|
@@ -39,13 +39,7 @@ refhub --api-key <key> vaults list
|
|
|
39
39
|
```
|
|
40
40
|
Resolution order: `--api-key` flag → `REFHUB_API_KEY` env → exit 3.
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
export REFHUB_JWT=your_supabase_session_jwt
|
|
45
|
-
# or pass inline:
|
|
46
|
-
refhub enrich --vault <id> --jwt <token>
|
|
47
|
-
```
|
|
48
|
-
Resolution order: `--jwt` flag → `REFHUB_JWT` env → exit 3.
|
|
42
|
+
Session JWTs are no longer required for CLI enrichment or item PDF upload. Browser/account setup flows still use RefHub web auth: API key creation/revocation and Google Drive connect/disconnect.
|
|
49
43
|
|
|
50
44
|
---
|
|
51
45
|
|
|
@@ -58,7 +52,6 @@ refhub [--api-key <key>] [--table] <command> [subcommand] [options]
|
|
|
58
52
|
| flag | behavior |
|
|
59
53
|
|------|----------|
|
|
60
54
|
| `--api-key` | override `REFHUB_API_KEY` |
|
|
61
|
-
| `--jwt` | override `REFHUB_JWT` (used by `enrich` and `pdf upload`) |
|
|
62
55
|
| `--table` | human-readable table output (default: json) |
|
|
63
56
|
| `--version` | print version |
|
|
64
57
|
| `--help` | available on every command and subcommand |
|
|
@@ -150,28 +143,48 @@ refhub export --vault <id> [--format json|bibtex]
|
|
|
150
143
|
refhub audit --vault <id> [--since <ISO>] [--until <ISO>] [--limit] [--page]
|
|
151
144
|
```
|
|
152
145
|
|
|
146
|
+
|
|
147
|
+
### discover
|
|
148
|
+
|
|
149
|
+
Semantic Scholar discovery/enrichment through API-key routes (`vaults:read`).
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
refhub discover search --query "visual analytics" [--limit 10]
|
|
153
|
+
refhub discover lookup (--doi <doi> | --title <title>)
|
|
154
|
+
refhub discover recommendations --paper <paperId-or-DOI:id> [--limit]
|
|
155
|
+
refhub discover related --paper <paperId-or-DOI:id> [--limit]
|
|
156
|
+
refhub discover references --paper <paperId-or-DOI:id> [--limit]
|
|
157
|
+
refhub discover citations --paper <paperId-or-DOI:id> [--limit]
|
|
158
|
+
refhub discover cited-by --paper <paperId-or-DOI:id> [--limit]
|
|
159
|
+
refhub discover add --vault <id> --file <semantic-scholar-results.json> [--idempotency-key]
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`discover add` expects a JSON array of normalized Semantic Scholar paper objects, such as the `.data` returned by `discover search/recommendations/references/citations`, and upserts them into the target vault. Open-access PDF URLs are mapped to `pdf_url` where present.
|
|
163
|
+
|
|
153
164
|
### enrich
|
|
154
165
|
|
|
155
|
-
Enriches incomplete publication metadata by looking up each item's DOI against Semantic Scholar and patching missing fields (title, authors, year, abstract). Requires
|
|
166
|
+
Enriches incomplete publication metadata by looking up each item's DOI against Semantic Scholar and patching missing fields (title, authors, year, abstract). Requires only the RefHub API key (`vaults:read` for lookup plus `vaults:write` when patching items).
|
|
156
167
|
|
|
157
168
|
```bash
|
|
158
|
-
refhub enrich --vault <id> [--item <itemId>] [--dry-run]
|
|
169
|
+
refhub enrich --vault <id> [--item <itemId>] [--dry-run]
|
|
159
170
|
```
|
|
160
171
|
|
|
161
172
|
- omit `--item` to process all items in the vault that have a DOI and missing fields
|
|
162
173
|
- `--dry-run` shows what would be updated without writing anything
|
|
163
|
-
- rate-limited to 1 req/s
|
|
174
|
+
- rate-limited client-side to 1 req/s; backend cache/rate-limit/stale fallback also applies
|
|
164
175
|
|
|
165
176
|
### pdf
|
|
166
177
|
|
|
167
|
-
Uploads a PDF file to the user's linked Google Drive and links it to a
|
|
178
|
+
Uploads a PDF file to the user's linked Google Drive and links it to a vault item. Requires only the RefHub API key (`vaults:write`) after Google Drive has been connected in the RefHub web account UI.
|
|
168
179
|
|
|
169
180
|
```bash
|
|
170
|
-
refhub pdf upload --
|
|
181
|
+
refhub pdf upload --vault <vaultId> --item <itemId> --file <path/to/file.pdf>
|
|
171
182
|
```
|
|
172
183
|
|
|
173
|
-
-
|
|
174
|
-
-
|
|
184
|
+
- small PDFs use the raw API-key upload route: `POST /api/v1/vaults/:vaultId/items/:itemId/pdf`
|
|
185
|
+
- raw API uploads are capped by the backend at the smallest of `REFHUB_API_MAX_BODY_BYTES`, `GOOGLE_DRIVE_MAX_UPLOAD_BYTES`, and the Netlify synchronous Function ceiling (6 MiB); oversized raw requests return structured `413 pdf_upload_too_large_for_api`
|
|
186
|
+
- larger PDFs use the API-key resumable Drive flow: `POST /api/v1/vaults/:vaultId/items/:itemId/pdf/session`, direct `PUT` of the PDF bytes to the returned Google Drive `upload_url`, then `POST /api/v1/vaults/:vaultId/items/:itemId/pdf/complete`
|
|
187
|
+
- max file size: 26 MB by default, matching the backend Google Drive upload limit
|
|
175
188
|
|
|
176
189
|
---
|
|
177
190
|
|
|
@@ -223,6 +236,10 @@ npm run build # tsc → dist/
|
|
|
223
236
|
|
|
224
237
|
smoke test covers: `list_vaults` → `create_vault` → `tag_crud` → `relation_crud` → `export` → `delete_vault`.
|
|
225
238
|
|
|
239
|
+
### releases
|
|
240
|
+
|
|
241
|
+
Releases are published from GitHub Actions via npm Trusted Publishing. See [RELEASE.md](./RELEASE.md) for the version bump, tag, and publish procedure.
|
|
242
|
+
|
|
226
243
|
---
|
|
227
244
|
|
|
228
245
|
## // stack
|
|
@@ -243,6 +260,5 @@ smoke test covers: `list_vaults` → `create_vault` → `tag_crud` → `relation
|
|
|
243
260
|
not exposed by the cli:
|
|
244
261
|
|
|
245
262
|
- api key management (jwt-only, no cli command)
|
|
246
|
-
- google drive link/unlink (
|
|
247
|
-
- semantic scholar recommendations / references / citations / lookup (jwt-only, no cli command)
|
|
263
|
+
- google drive link/unlink setup (browser/JWT-only, no cli command)
|
|
248
264
|
- global audit log (jwt-only, non-vault-scoped, no cli command)
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiResponse, Vault, VaultDetail, Share, Item, UpsertResult, PreviewResult, Tag, Relation, BibTeXImportResult, AuditEntry, VaultStats, RelationType } from './types.js';
|
|
1
|
+
import type { ApiResponse, Vault, VaultDetail, Share, Item, UpsertResult, PreviewResult, Tag, Relation, BibTeXImportResult, AuditEntry, VaultStats, RelationType, SemanticScholarPaper, SemanticScholarDoiMetadata } from './types.js';
|
|
2
2
|
export declare class RefHubError extends Error {
|
|
3
3
|
readonly code: string;
|
|
4
4
|
readonly request_id: string;
|
|
@@ -7,10 +7,12 @@ export declare class RefHubError extends Error {
|
|
|
7
7
|
constructor(status: number, code: string, message: string, request_id: string, retry_after_seconds?: number);
|
|
8
8
|
}
|
|
9
9
|
export declare class RefHubClient {
|
|
10
|
+
static readonly RAW_PDF_UPLOAD_LIMIT_BYTES: number;
|
|
10
11
|
private readonly baseUrl;
|
|
11
12
|
private readonly headers;
|
|
12
13
|
constructor(apiKey: string);
|
|
13
14
|
private req;
|
|
15
|
+
private reqBinary;
|
|
14
16
|
private reqText;
|
|
15
17
|
listVaults(): Promise<ApiResponse<Vault[]>>;
|
|
16
18
|
getVault(vaultId: string): Promise<ApiResponse<VaultDetail>>;
|
|
@@ -131,16 +133,24 @@ export declare class RefHubClient {
|
|
|
131
133
|
limit?: number;
|
|
132
134
|
page?: number;
|
|
133
135
|
}): Promise<ApiResponse<AuditEntry[]>>;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
136
|
+
doiMetadata(doi: string): Promise<SemanticScholarDoiMetadata | null>;
|
|
137
|
+
semanticScholarLookup(body: {
|
|
138
|
+
doi?: string;
|
|
139
|
+
title?: string;
|
|
140
|
+
}): Promise<ApiResponse<{
|
|
141
|
+
paper_id: string;
|
|
142
|
+
}>>;
|
|
143
|
+
semanticScholarSearch(query: string, limit?: number): Promise<ApiResponse<SemanticScholarPaper[]>>;
|
|
144
|
+
semanticScholarPaperList(kind: 'recommendations' | 'related' | 'references' | 'citations' | 'cited-by', paperId: string, limit?: number): Promise<ApiResponse<SemanticScholarPaper[]>>;
|
|
145
|
+
uploadItemPdfRaw(vaultId: string, itemId: string, pdfBuffer: Buffer): Promise<ApiResponse<PdfUploadResult>>;
|
|
146
|
+
createItemPdfUploadSession(vaultId: string, itemId: string): Promise<ApiResponse<PdfUploadSession>>;
|
|
147
|
+
completeItemPdfUpload(vaultId: string, itemId: string, body: {
|
|
148
|
+
file_id: string;
|
|
149
|
+
web_view_link?: string | null;
|
|
150
|
+
source_url?: string | null;
|
|
151
|
+
}): Promise<ApiResponse<PdfUploadResult>>;
|
|
152
|
+
uploadItemPdfResumable(vaultId: string, itemId: string, pdfBuffer: Buffer): Promise<ApiResponse<PdfUploadResult>>;
|
|
153
|
+
uploadItemPdf(vaultId: string, itemId: string, pdfBuffer: Buffer): Promise<ApiResponse<PdfUploadResult>>;
|
|
144
154
|
}
|
|
145
155
|
export interface PdfUploadResult {
|
|
146
156
|
attempted: boolean;
|
|
@@ -152,14 +162,9 @@ export interface PdfUploadResult {
|
|
|
152
162
|
pdfUrl?: string;
|
|
153
163
|
sourceUrl?: string | null;
|
|
154
164
|
}
|
|
155
|
-
export
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
constructor(jwt: string);
|
|
159
|
-
private req;
|
|
160
|
-
doiMetadata(doi: string): Promise<DoiMetadata | null>;
|
|
161
|
-
uploadPublicationPdf(publicationId: string, pdfBuffer: Buffer): Promise<ApiResponse<PdfUploadResult>>;
|
|
165
|
+
export interface PdfUploadSession {
|
|
166
|
+
upload_url: string;
|
|
167
|
+
file_name?: string;
|
|
162
168
|
}
|
|
163
|
-
export declare function resolveManagementClient(jwt?: string): ManagementClient;
|
|
164
169
|
export declare function resolveClient(apiKey?: string): RefHubClient;
|
|
165
170
|
export declare function run(fn: () => Promise<void>): Promise<void>;
|
package/dist/client.js
CHANGED
|
@@ -13,6 +13,7 @@ export class RefHubError extends Error {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export class RefHubClient {
|
|
16
|
+
static RAW_PDF_UPLOAD_LIMIT_BYTES = 6 * 1024 * 1024;
|
|
16
17
|
baseUrl = 'https://refhub-api.netlify.app/api/v1';
|
|
17
18
|
headers;
|
|
18
19
|
constructor(apiKey) {
|
|
@@ -30,7 +31,22 @@ export class RefHubClient {
|
|
|
30
31
|
if (!res.ok) {
|
|
31
32
|
const payload = await res.json().catch(() => ({}));
|
|
32
33
|
const err = (payload['error'] ?? {});
|
|
33
|
-
throw new RefHubError(res.status, String(err['code'] ?? 'unknown_error'), String(err['message'] ?? `HTTP ${res.status}`), String(err['request_id'] ?? ''), typeof
|
|
34
|
+
throw new RefHubError(res.status, String(err['code'] ?? 'unknown_error'), String(err['message'] ?? `HTTP ${res.status}`), String(payload['meta']?.['request_id'] ?? err['request_id'] ?? ''), typeof err['details']?.['retry_after_seconds'] === 'number'
|
|
35
|
+
? Number(err['details']['retry_after_seconds'])
|
|
36
|
+
: typeof payload['retry_after_seconds'] === 'number' ? payload['retry_after_seconds'] : undefined);
|
|
37
|
+
}
|
|
38
|
+
return res.json();
|
|
39
|
+
}
|
|
40
|
+
async reqBinary(method, path, body, contentType = 'application/octet-stream') {
|
|
41
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
42
|
+
method,
|
|
43
|
+
headers: { ...this.headers, 'Content-Type': contentType },
|
|
44
|
+
body: body,
|
|
45
|
+
});
|
|
46
|
+
if (!res.ok) {
|
|
47
|
+
const payload = await res.json().catch(() => ({}));
|
|
48
|
+
const err = (payload['error'] ?? {});
|
|
49
|
+
throw new RefHubError(res.status, String(err['code'] ?? 'unknown_error'), String(err['message'] ?? `HTTP ${res.status}`), String(payload['meta']?.['request_id'] ?? err['request_id'] ?? ''));
|
|
34
50
|
}
|
|
35
51
|
return res.json();
|
|
36
52
|
}
|
|
@@ -39,7 +55,7 @@ export class RefHubClient {
|
|
|
39
55
|
if (!res.ok) {
|
|
40
56
|
const payload = await res.json().catch(() => ({}));
|
|
41
57
|
const err = (payload['error'] ?? {});
|
|
42
|
-
throw new RefHubError(res.status, String(err['code'] ?? 'unknown_error'), String(err['message'] ?? `HTTP ${res.status}`), String(err['request_id'] ?? ''));
|
|
58
|
+
throw new RefHubError(res.status, String(err['code'] ?? 'unknown_error'), String(err['message'] ?? `HTTP ${res.status}`), String(payload['meta']?.['request_id'] ?? err['request_id'] ?? ''));
|
|
43
59
|
}
|
|
44
60
|
return res.text();
|
|
45
61
|
}
|
|
@@ -80,7 +96,7 @@ export class RefHubClient {
|
|
|
80
96
|
if (params.page !== undefined)
|
|
81
97
|
q.set('page', String(params.page));
|
|
82
98
|
if (params.limit !== undefined)
|
|
83
|
-
q.set('
|
|
99
|
+
q.set('per_page', String(params.limit));
|
|
84
100
|
const qs = q.toString() ? `?${q}` : '';
|
|
85
101
|
return this.req('GET', `/vaults/${vaultId}/items${qs}`);
|
|
86
102
|
}
|
|
@@ -116,11 +132,11 @@ export class RefHubClient {
|
|
|
116
132
|
if (params.doi)
|
|
117
133
|
q.set('doi', params.doi);
|
|
118
134
|
if (params.tag_id)
|
|
119
|
-
q.set('
|
|
135
|
+
q.set('tag', params.tag_id);
|
|
120
136
|
if (params.page !== undefined)
|
|
121
137
|
q.set('page', String(params.page));
|
|
122
138
|
if (params.limit !== undefined)
|
|
123
|
-
q.set('
|
|
139
|
+
q.set('per_page', String(params.limit));
|
|
124
140
|
const qs = q.toString() ? `?${q}` : '';
|
|
125
141
|
return this.req('GET', `/vaults/${vaultId}/search${qs}`);
|
|
126
142
|
}
|
|
@@ -185,55 +201,71 @@ export class RefHubClient {
|
|
|
185
201
|
if (params.until)
|
|
186
202
|
q.set('until', params.until);
|
|
187
203
|
if (params.limit !== undefined)
|
|
188
|
-
q.set('
|
|
204
|
+
q.set('per_page', String(params.limit));
|
|
189
205
|
if (params.page !== undefined)
|
|
190
206
|
q.set('page', String(params.page));
|
|
191
207
|
const qs = q.toString() ? `?${q}` : '';
|
|
192
208
|
return this.req('GET', `/vaults/${vaultId}/audit${qs}`);
|
|
193
209
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
jwt;
|
|
198
|
-
constructor(jwt) {
|
|
199
|
-
this.jwt = jwt;
|
|
200
|
-
}
|
|
201
|
-
async req(method, path, body, contentType = 'application/json') {
|
|
202
|
-
const headers = {
|
|
203
|
-
Authorization: `Bearer ${this.jwt}`,
|
|
204
|
-
'Content-Type': contentType,
|
|
205
|
-
};
|
|
206
|
-
let fetchBody;
|
|
207
|
-
if (body !== undefined) {
|
|
208
|
-
fetchBody = body instanceof Buffer ? body : JSON.stringify(body);
|
|
209
|
-
}
|
|
210
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
211
|
-
method,
|
|
212
|
-
headers,
|
|
213
|
-
body: fetchBody,
|
|
214
|
-
});
|
|
215
|
-
if (!res.ok) {
|
|
216
|
-
const payload = await res.json().catch(() => ({}));
|
|
217
|
-
const err = (payload['error'] ?? {});
|
|
218
|
-
throw new RefHubError(res.status, String(err['code'] ?? 'unknown_error'), String(err['message'] ?? `HTTP ${res.status}`), String(payload['meta']?.['request_id'] ?? ''));
|
|
219
|
-
}
|
|
220
|
-
return res.json();
|
|
210
|
+
// ── Semantic Scholar discovery/enrichment ──────────────────────────────────
|
|
211
|
+
doiMetadata(doi) {
|
|
212
|
+
return this.req('POST', '/semantic-scholar/doi-metadata', { doi }).then((result) => result.data);
|
|
221
213
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return result.data;
|
|
214
|
+
semanticScholarLookup(body) {
|
|
215
|
+
return this.req('POST', '/semantic-scholar/lookup', body);
|
|
225
216
|
}
|
|
226
|
-
|
|
227
|
-
return this.req('POST',
|
|
217
|
+
semanticScholarSearch(query, limit) {
|
|
218
|
+
return this.req('POST', '/semantic-scholar/search', { query, ...(limit !== undefined ? { limit } : {}) });
|
|
228
219
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
220
|
+
semanticScholarPaperList(kind, paperId, limit) {
|
|
221
|
+
return this.req('POST', `/semantic-scholar/${kind}`, { paper_id: paperId, ...(limit !== undefined ? { limit } : {}) });
|
|
222
|
+
}
|
|
223
|
+
uploadItemPdfRaw(vaultId, itemId, pdfBuffer) {
|
|
224
|
+
return this.reqBinary('POST', `/vaults/${encodeURIComponent(vaultId)}/items/${encodeURIComponent(itemId)}/pdf`, pdfBuffer, 'application/pdf');
|
|
225
|
+
}
|
|
226
|
+
createItemPdfUploadSession(vaultId, itemId) {
|
|
227
|
+
return this.req('POST', `/vaults/${encodeURIComponent(vaultId)}/items/${encodeURIComponent(itemId)}/pdf/session`, {});
|
|
228
|
+
}
|
|
229
|
+
completeItemPdfUpload(vaultId, itemId, body) {
|
|
230
|
+
return this.req('POST', `/vaults/${encodeURIComponent(vaultId)}/items/${encodeURIComponent(itemId)}/pdf/complete`, body);
|
|
231
|
+
}
|
|
232
|
+
async uploadItemPdfResumable(vaultId, itemId, pdfBuffer) {
|
|
233
|
+
const session = await this.createItemPdfUploadSession(vaultId, itemId);
|
|
234
|
+
const driveResponse = await fetch(session.data.upload_url, {
|
|
235
|
+
method: 'PUT',
|
|
236
|
+
headers: {
|
|
237
|
+
'Content-Type': 'application/pdf',
|
|
238
|
+
'Content-Length': String(pdfBuffer.length),
|
|
239
|
+
},
|
|
240
|
+
body: pdfBuffer,
|
|
241
|
+
});
|
|
242
|
+
if (!driveResponse.ok) {
|
|
243
|
+
const body = await driveResponse.text().catch(() => '');
|
|
244
|
+
throw new Error(`Google Drive resumable upload failed (${driveResponse.status})${body ? `: ${body}` : ''}`);
|
|
245
|
+
}
|
|
246
|
+
const driveUpload = await driveResponse.json().catch(() => ({}));
|
|
247
|
+
if (!driveUpload.id) {
|
|
248
|
+
throw new Error('Google Drive upload completed without returning a file id');
|
|
249
|
+
}
|
|
250
|
+
return this.completeItemPdfUpload(vaultId, itemId, {
|
|
251
|
+
file_id: driveUpload.id,
|
|
252
|
+
web_view_link: driveUpload.webViewLink ?? null,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
async uploadItemPdf(vaultId, itemId, pdfBuffer) {
|
|
256
|
+
if (pdfBuffer.length > RefHubClient.RAW_PDF_UPLOAD_LIMIT_BYTES) {
|
|
257
|
+
return this.uploadItemPdfResumable(vaultId, itemId, pdfBuffer);
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
return await this.uploadItemPdfRaw(vaultId, itemId, pdfBuffer);
|
|
261
|
+
}
|
|
262
|
+
catch (err) {
|
|
263
|
+
if (err instanceof RefHubError && err.status === 413 && err.code === 'pdf_upload_too_large_for_api') {
|
|
264
|
+
return this.uploadItemPdfResumable(vaultId, itemId, pdfBuffer);
|
|
265
|
+
}
|
|
266
|
+
throw err;
|
|
267
|
+
}
|
|
235
268
|
}
|
|
236
|
-
return new ManagementClient(token);
|
|
237
269
|
}
|
|
238
270
|
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
239
271
|
export function resolveClient(apiKey) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import { RefHubClient } from '../client.js';
|
|
3
|
+
import type { SemanticScholarPaper } from '../types.js';
|
|
4
|
+
export declare function paperToItem(paper: SemanticScholarPaper): Record<string, unknown>;
|
|
5
|
+
export declare function handleDiscoverSearch(client: RefHubClient, query: string, limit: number | undefined, tableMode: boolean): Promise<void>;
|
|
6
|
+
export declare function handleDiscoverLookup(client: RefHubClient, opts: {
|
|
7
|
+
doi?: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
}, tableMode: boolean): Promise<void>;
|
|
10
|
+
export declare function handleDiscoverList(client: RefHubClient, kind: 'recommendations' | 'related' | 'references' | 'citations' | 'cited-by', paperId: string, limit: number | undefined, tableMode: boolean): Promise<void>;
|
|
11
|
+
export declare function handleDiscoverAdd(client: RefHubClient, vaultId: string, filePath: string, idempotencyKey: string | undefined, tableMode: boolean): Promise<void>;
|
|
12
|
+
export declare function registerDiscover(program: Command): void;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { resolveClient, run } from '../client.js';
|
|
3
|
+
import { format } from '../format.js';
|
|
4
|
+
function authorsToStrings(paper) {
|
|
5
|
+
return (paper.authors ?? []).map((a) => a.name).filter((name) => Boolean(name));
|
|
6
|
+
}
|
|
7
|
+
export function paperToItem(paper) {
|
|
8
|
+
const doi = paper.external_ids?.['DOI'] ?? paper.external_ids?.['doi'];
|
|
9
|
+
return {
|
|
10
|
+
title: paper.title ?? 'Untitled Semantic Scholar paper',
|
|
11
|
+
authors: authorsToStrings(paper),
|
|
12
|
+
year: paper.year ?? undefined,
|
|
13
|
+
journal: paper.venue ?? undefined,
|
|
14
|
+
doi: doi ?? undefined,
|
|
15
|
+
url: paper.url ?? undefined,
|
|
16
|
+
abstract: paper.abstract ?? undefined,
|
|
17
|
+
pdf_url: paper.open_access_pdf_url ?? undefined,
|
|
18
|
+
publication_type: 'article',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export async function handleDiscoverSearch(client, query, limit, tableMode) {
|
|
22
|
+
const result = await client.semanticScholarSearch(query, limit);
|
|
23
|
+
format(result, tableMode, ['paper_id', 'title', 'year', 'venue', 'citation_count', 'open_access_pdf_url']);
|
|
24
|
+
}
|
|
25
|
+
export async function handleDiscoverLookup(client, opts, tableMode) {
|
|
26
|
+
const result = await client.semanticScholarLookup(opts);
|
|
27
|
+
format(result, tableMode);
|
|
28
|
+
}
|
|
29
|
+
export async function handleDiscoverList(client, kind, paperId, limit, tableMode) {
|
|
30
|
+
const result = await client.semanticScholarPaperList(kind, paperId, limit);
|
|
31
|
+
format(result, tableMode, ['paper_id', 'title', 'year', 'venue', 'citation_count', 'open_access_pdf_url']);
|
|
32
|
+
}
|
|
33
|
+
export async function handleDiscoverAdd(client, vaultId, filePath, idempotencyKey, tableMode) {
|
|
34
|
+
const papers = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
35
|
+
if (!Array.isArray(papers)) {
|
|
36
|
+
process.stderr.write(JSON.stringify({ error: { code: 'invalid_file', message: 'File must contain a JSON array of Semantic Scholar paper results.' } }) + '\n');
|
|
37
|
+
process.exit(2);
|
|
38
|
+
}
|
|
39
|
+
const result = await client.upsertItems(vaultId, papers.map(paperToItem), idempotencyKey);
|
|
40
|
+
format(result, tableMode);
|
|
41
|
+
}
|
|
42
|
+
function addPaperListCommand(discover, name, description) {
|
|
43
|
+
discover
|
|
44
|
+
.command(name)
|
|
45
|
+
.description(description)
|
|
46
|
+
.requiredOption('--paper <paperId>', 'Semantic Scholar paper id, DOI:<doi>, or other supported paper identifier')
|
|
47
|
+
.option('--limit <n>', 'result limit, 1-25', (v) => parseInt(v, 10))
|
|
48
|
+
.action(async (opts, cmd) => {
|
|
49
|
+
const g = cmd.optsWithGlobals();
|
|
50
|
+
const client = resolveClient(g.apiKey);
|
|
51
|
+
await run(() => handleDiscoverList(client, name, opts.paper, opts.limit, g.table ?? false));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function registerDiscover(program) {
|
|
55
|
+
const discover = program.command('discover').description('Semantic Scholar discovery via RefHub API key');
|
|
56
|
+
discover
|
|
57
|
+
.command('search')
|
|
58
|
+
.description('Search Semantic Scholar by keyword/topic')
|
|
59
|
+
.requiredOption('--query <query>', 'keyword/topic query')
|
|
60
|
+
.option('--limit <n>', 'result limit, 1-25', (v) => parseInt(v, 10))
|
|
61
|
+
.action(async (opts, cmd) => {
|
|
62
|
+
const g = cmd.optsWithGlobals();
|
|
63
|
+
const client = resolveClient(g.apiKey);
|
|
64
|
+
await run(() => handleDiscoverSearch(client, opts.query, opts.limit, g.table ?? false));
|
|
65
|
+
});
|
|
66
|
+
discover
|
|
67
|
+
.command('lookup')
|
|
68
|
+
.description('Resolve a DOI or title to a Semantic Scholar paper id')
|
|
69
|
+
.option('--doi <doi>')
|
|
70
|
+
.option('--title <title>')
|
|
71
|
+
.action(async (opts, cmd) => {
|
|
72
|
+
if ((opts.doi && opts.title) || (!opts.doi && !opts.title)) {
|
|
73
|
+
process.stderr.write(JSON.stringify({ error: { code: 'invalid_lookup_request', message: 'Provide exactly one of --doi or --title.' } }) + '\n');
|
|
74
|
+
process.exit(2);
|
|
75
|
+
}
|
|
76
|
+
const g = cmd.optsWithGlobals();
|
|
77
|
+
const client = resolveClient(g.apiKey);
|
|
78
|
+
await run(() => handleDiscoverLookup(client, { doi: opts.doi, title: opts.title }, g.table ?? false));
|
|
79
|
+
});
|
|
80
|
+
addPaperListCommand(discover, 'recommendations', 'Get Semantic Scholar recommendations from a seed paper');
|
|
81
|
+
addPaperListCommand(discover, 'related', 'Alias for recommendations');
|
|
82
|
+
addPaperListCommand(discover, 'references', 'Get papers cited by a seed paper');
|
|
83
|
+
addPaperListCommand(discover, 'citations', 'Get papers citing a seed paper');
|
|
84
|
+
addPaperListCommand(discover, 'cited-by', 'Alias for citations');
|
|
85
|
+
discover
|
|
86
|
+
.command('add')
|
|
87
|
+
.description('Upsert selected Semantic Scholar paper JSON results into a vault')
|
|
88
|
+
.requiredOption('--vault <id>')
|
|
89
|
+
.requiredOption('--file <path>', 'JSON array of Semantic Scholar paper results')
|
|
90
|
+
.option('--idempotency-key <key>', 'safe retry key')
|
|
91
|
+
.action(async (opts, cmd) => {
|
|
92
|
+
const g = cmd.optsWithGlobals();
|
|
93
|
+
const client = resolveClient(g.apiKey);
|
|
94
|
+
await run(() => handleDiscoverAdd(client, opts.vault, opts.file, opts.idempotencyKey, g.table ?? false));
|
|
95
|
+
});
|
|
96
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
|
-
import { RefHubClient
|
|
2
|
+
import { RefHubClient } from '../client.js';
|
|
3
3
|
import type { Item } from '../types.js';
|
|
4
|
-
export declare function enrichItem(item: Item,
|
|
4
|
+
export declare function enrichItem(item: Item, client: RefHubClient, vaultId: string, dryRun: boolean): Promise<'enriched' | 'skipped' | 'not_found' | 'no_missing_fields'>;
|
|
5
5
|
export declare function registerEnrich(program: Command): void;
|
package/dist/commands/enrich.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolveClient,
|
|
2
|
-
export async function enrichItem(item,
|
|
1
|
+
import { resolveClient, run } from '../client.js';
|
|
2
|
+
export async function enrichItem(item, client, vaultId, dryRun) {
|
|
3
3
|
if (!item.doi)
|
|
4
4
|
return 'skipped';
|
|
5
5
|
const missing = [];
|
|
@@ -13,7 +13,7 @@ export async function enrichItem(item, mgmt, client, vaultId, dryRun) {
|
|
|
13
13
|
missing.push('abstract');
|
|
14
14
|
if (missing.length === 0)
|
|
15
15
|
return 'no_missing_fields';
|
|
16
|
-
const meta = await
|
|
16
|
+
const meta = await client.doiMetadata(item.doi);
|
|
17
17
|
if (!meta)
|
|
18
18
|
return 'not_found';
|
|
19
19
|
const patch = {};
|
|
@@ -39,11 +39,9 @@ export function registerEnrich(program) {
|
|
|
39
39
|
.requiredOption('--vault <id>', 'vault to enrich')
|
|
40
40
|
.option('--item <itemId>', 'enrich a single item instead of the whole vault')
|
|
41
41
|
.option('--dry-run', 'show what would be updated without writing')
|
|
42
|
-
.option('--jwt <token>', 'session JWT (overrides REFHUB_JWT env var)')
|
|
43
42
|
.action(async (opts, cmd) => {
|
|
44
43
|
const g = cmd.optsWithGlobals();
|
|
45
44
|
const client = resolveClient(g.apiKey);
|
|
46
|
-
const mgmt = resolveManagementClient(opts.jwt);
|
|
47
45
|
const dryRun = opts.dryRun ?? false;
|
|
48
46
|
await run(async () => {
|
|
49
47
|
let items;
|
|
@@ -63,7 +61,7 @@ export function registerEnrich(program) {
|
|
|
63
61
|
const counts = { enriched: 0, skipped: 0, not_found: 0, no_missing_fields: 0 };
|
|
64
62
|
const enriched = [];
|
|
65
63
|
for (const item of withDoi) {
|
|
66
|
-
const outcome = await enrichItem(item,
|
|
64
|
+
const outcome = await enrichItem(item, client, opts.vault, dryRun);
|
|
67
65
|
counts[outcome]++;
|
|
68
66
|
if (outcome === 'enriched')
|
|
69
67
|
enriched.push(item.id);
|
package/dist/commands/pdf.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
|
-
import {
|
|
3
|
-
export declare function handlePdfUpload(
|
|
2
|
+
import { RefHubClient } from '../client.js';
|
|
3
|
+
export declare function handlePdfUpload(client: RefHubClient, vaultId: string, itemId: string, filePath: string, tableMode: boolean): Promise<void>;
|
|
4
4
|
export declare function registerPdf(program: Command): void;
|
package/dist/commands/pdf.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/commands/pdf.ts
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
|
-
import {
|
|
3
|
+
import { resolveClient, run } from '../client.js';
|
|
4
4
|
import { format } from '../format.js';
|
|
5
|
-
export async function handlePdfUpload(
|
|
5
|
+
export async function handlePdfUpload(client, vaultId, itemId, filePath, tableMode) {
|
|
6
6
|
let pdfBuffer;
|
|
7
7
|
try {
|
|
8
8
|
pdfBuffer = readFileSync(filePath);
|
|
@@ -11,20 +11,20 @@ export async function handlePdfUpload(mgmt, publicationId, filePath, tableMode)
|
|
|
11
11
|
process.stderr.write(JSON.stringify({ error: { code: 'file_read_error', message: `Cannot read file: ${String(e)}` } }) + '\n');
|
|
12
12
|
process.exit(2);
|
|
13
13
|
}
|
|
14
|
-
const result = await
|
|
14
|
+
const result = await client.uploadItemPdf(vaultId, itemId, pdfBuffer);
|
|
15
15
|
format(result, tableMode);
|
|
16
16
|
}
|
|
17
17
|
export function registerPdf(program) {
|
|
18
|
-
const pdf = program.command('pdf').description('Upload a PDF to Google Drive for a
|
|
18
|
+
const pdf = program.command('pdf').description('Upload a PDF to Google Drive for a vault item');
|
|
19
19
|
pdf
|
|
20
20
|
.command('upload')
|
|
21
|
-
.description('Upload a PDF file and link it to a
|
|
22
|
-
.requiredOption('--
|
|
21
|
+
.description('Upload a PDF file and link it to a vault item')
|
|
22
|
+
.requiredOption('--vault <id>', 'vault ID')
|
|
23
|
+
.requiredOption('--item <id>', 'vault item ID')
|
|
23
24
|
.requiredOption('--file <path>', 'path to PDF file')
|
|
24
|
-
.option('--jwt <token>', 'session JWT (overrides REFHUB_JWT env var)')
|
|
25
25
|
.action(async (opts, cmd) => {
|
|
26
26
|
const g = cmd.optsWithGlobals();
|
|
27
|
-
const
|
|
28
|
-
await run(() => handlePdfUpload(
|
|
27
|
+
const client = resolveClient(g.apiKey);
|
|
28
|
+
await run(() => handlePdfUpload(client, opts.vault, opts.item, opts.file, g.table ?? false));
|
|
29
29
|
});
|
|
30
30
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// src/index.ts
|
|
3
3
|
import { Command } from 'commander';
|
|
4
|
+
import { createRequire } from 'module';
|
|
4
5
|
import { registerVaults } from './commands/vaults.js';
|
|
5
6
|
import { registerItems } from './commands/items.js';
|
|
6
7
|
import { registerTags } from './commands/tags.js';
|
|
@@ -10,13 +11,15 @@ import { registerExport } from './commands/export.js';
|
|
|
10
11
|
import { registerAudit } from './commands/audit.js';
|
|
11
12
|
import { registerEnrich } from './commands/enrich.js';
|
|
12
13
|
import { registerPdf } from './commands/pdf.js';
|
|
14
|
+
import { registerDiscover } from './commands/discover.js';
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
16
|
+
const { version } = require('../package.json');
|
|
13
17
|
const program = new Command();
|
|
14
18
|
program
|
|
15
19
|
.name('refhub')
|
|
16
20
|
.description('RefHub CLI — manage vaults, items, tags, and relations')
|
|
17
|
-
.version(
|
|
21
|
+
.version(version)
|
|
18
22
|
.option('--api-key <key>', 'RefHub API key (overrides REFHUB_API_KEY env var)')
|
|
19
|
-
.option('--jwt <token>', 'Supabase session JWT (overrides REFHUB_JWT env var)')
|
|
20
23
|
.option('--table', 'human-readable table output (default: JSON)');
|
|
21
24
|
registerVaults(program);
|
|
22
25
|
registerItems(program);
|
|
@@ -26,5 +29,6 @@ registerImport(program);
|
|
|
26
29
|
registerExport(program);
|
|
27
30
|
registerAudit(program);
|
|
28
31
|
registerEnrich(program);
|
|
32
|
+
registerDiscover(program);
|
|
29
33
|
registerPdf(program);
|
|
30
34
|
program.parseAsync();
|
package/dist/types.d.ts
CHANGED
|
@@ -97,3 +97,29 @@ export interface AuditEntry {
|
|
|
97
97
|
export interface ApiResponse<T> {
|
|
98
98
|
data: T;
|
|
99
99
|
}
|
|
100
|
+
export interface SemanticScholarAuthor {
|
|
101
|
+
author_id?: string | null;
|
|
102
|
+
name?: string | null;
|
|
103
|
+
}
|
|
104
|
+
export interface SemanticScholarPaper {
|
|
105
|
+
paper_id: string | null;
|
|
106
|
+
external_ids?: Record<string, string>;
|
|
107
|
+
title?: string | null;
|
|
108
|
+
abstract?: string | null;
|
|
109
|
+
year?: number | null;
|
|
110
|
+
venue?: string | null;
|
|
111
|
+
url?: string | null;
|
|
112
|
+
citation_count?: number | null;
|
|
113
|
+
open_access_pdf_url?: string | null;
|
|
114
|
+
authors?: SemanticScholarAuthor[];
|
|
115
|
+
}
|
|
116
|
+
export interface SemanticScholarDoiMetadata {
|
|
117
|
+
title: string;
|
|
118
|
+
authors: string[];
|
|
119
|
+
year?: number;
|
|
120
|
+
journal?: string;
|
|
121
|
+
doi: string;
|
|
122
|
+
url: string;
|
|
123
|
+
abstract?: string;
|
|
124
|
+
type: string;
|
|
125
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refhub/cli",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "refhub CLI execution layer for agent skills",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/refhub-io/refhub-cli"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/refhub-io/refhub-cli#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/refhub-io/refhub-cli/issues"
|
|
13
|
+
},
|
|
6
14
|
"engines": { "node": ">=18" },
|
|
7
15
|
"bin": { "refhub": "dist/index.js" },
|
|
8
16
|
"scripts": {
|