-
Notifications
You must be signed in to change notification settings - Fork 1
fix(cli): 空关键词回退本地搜索;SDK 复用 FederatedSearchParams 与 limit 校验 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { GeneHubClient } from '@nodeskai/genehub-sdk'; | ||
| import type { Gene } from '@nodeskai/genehub-types'; | ||
| import { Command } from 'commander'; | ||
| import { loadConfig } from '../config.js'; | ||
| import * as output from '../output.js'; | ||
|
|
||
| function formatAuthor(gene: Gene): string { | ||
| const a = gene.author; | ||
| if (!a) return '-'; | ||
| if (a.ref) return `${a.name} (${a.ref})`; | ||
| return `${a.name} (${a.type})`; | ||
| } | ||
|
|
||
| function formatGene(gene: Gene): void { | ||
| console.log(` ${gene.slug} v${gene.version}`); | ||
| console.log(` ${gene.short_description || gene.description || ''}`); | ||
| console.log(''); | ||
| console.log(` Category: ${gene.category}`); | ||
| console.log(` Tags: ${gene.tags?.join(', ') || '(none)'}`); | ||
| console.log(` Author: ${formatAuthor(gene)}`); | ||
| console.log(` Status: ${gene.is_published ? 'published' : 'unpublished'}`); | ||
| console.log(` Downloads: ${gene.install_count}`); | ||
| console.log(''); | ||
| console.log(' Compatibility:'); | ||
| if (gene.compatibility?.length) { | ||
| for (const c of gene.compatibility) { | ||
| console.log(` - ${c}`); | ||
| } | ||
| } else { | ||
| console.log(' (none)'); | ||
| } | ||
| console.log(''); | ||
| console.log( | ||
| ' Dependencies:', | ||
| gene.dependencies?.length | ||
| ? gene.dependencies.map((d) => `${d.slug}@${d.version}`).join(', ') | ||
| : '(none)', | ||
| ); | ||
| console.log(''); | ||
| console.log(' Install:'); | ||
| console.log(` genehub install ${gene.slug}`); | ||
| } | ||
|
|
||
| export const infoCommand = new Command('info') | ||
| .description('查看基因详情') | ||
| .argument('<slug>', '基因 slug') | ||
| .option('--json', 'JSON 格式输出', false) | ||
| .action(async (slug: string, opts: { json?: boolean }) => { | ||
| const config = await loadConfig(); | ||
| const client = new GeneHubClient({ registryUrl: config.registryUrl, token: config.token }); | ||
|
|
||
| try { | ||
| const gene = await client.getGene(slug); | ||
|
|
||
| if (opts.json) { | ||
| console.log(JSON.stringify(gene, null, 2)); | ||
| return; | ||
| } | ||
|
|
||
| formatGene(gene); | ||
| } catch (err) { | ||
| output.fail(err instanceof Error ? err.message : String(err)); | ||
| process.exit(1); | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import type { | |
| ApiResponse, | ||
| CreateAgentTemplateRequest, | ||
| CreateGenomeRequest, | ||
| FederatedSearchParams, | ||
| FederatedSearchResult, | ||
| Gene, | ||
| GeneListParams, | ||
|
|
@@ -73,15 +74,13 @@ export class GeneHubClient { | |
| } | ||
|
|
||
| /** 联邦搜索:合并本地 DB 与外部源(如 ClawHub)结果 */ | ||
| async federatedSearch(params: { | ||
| q: string; | ||
| category?: string; | ||
| limit?: number; | ||
| }): Promise<FederatedSearchResult> { | ||
| async federatedSearch(params: FederatedSearchParams): Promise<FederatedSearchResult> { | ||
| const qs = new URLSearchParams(); | ||
| qs.set('q', params.q); | ||
| if (params.category) qs.set('category', params.category); | ||
| if (params.limit != null) qs.set('limit', String(params.limit)); | ||
| if (Number.isFinite(params.limit) && (params.limit as number) > 0) { | ||
| qs.set('limit', String(params.limit)); | ||
| } | ||
|
Comment on lines
+81
to
+83
|
||
| return this.request<FederatedSearchResult>(`/api/v1/genes/search?${qs.toString()}`); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.