grok-search-cli 0.1.2 → 0.1.3
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 +33 -17
- package/README.zh.md +33 -17
- package/dist/cli.js +97 -552
- package/dist/index.js +2 -0
- package/dist/search-DcS355m9.js +573 -0
- package/dist/src/args.d.ts +4 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/config.d.ts +35 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/openrouter.d.ts +38 -0
- package/dist/src/openrouter.test.d.ts +1 -0
- package/dist/src/output.d.ts +19 -0
- package/dist/src/providers.d.ts +12 -0
- package/dist/src/search.d.ts +34 -0
- package/dist/src/skill.d.ts +2 -0
- package/dist/src/types.d.ts +121 -0
- package/package.json +15 -6
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getProviderKind, resolveRuntimeConfig } from './config';
|
|
2
|
+
import { ApiMode, CompletedResult, GrokSearchConfig, SearchOptions, SearchResultPayload, StreamResult } from './types';
|
|
3
|
+
export interface SearchExecutionContext {
|
|
4
|
+
prompt: string;
|
|
5
|
+
runtimeConfig: ReturnType<typeof resolveRuntimeConfig>;
|
|
6
|
+
apiMode: ApiMode;
|
|
7
|
+
requestApi: string;
|
|
8
|
+
providerKind: ReturnType<typeof getProviderKind>;
|
|
9
|
+
options: SearchOptions;
|
|
10
|
+
startedAt: number;
|
|
11
|
+
abortSignal: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
export declare function createDefaultSearchOptions(model?: string): SearchOptions;
|
|
14
|
+
export declare function createSearchOptions(config: GrokSearchConfig): SearchOptions;
|
|
15
|
+
export declare function ensureLocalApiKey(): string;
|
|
16
|
+
export declare function shouldWarnAboutCompatFilters(apiMode: ApiMode, baseUrl: string | undefined, options: SearchOptions): boolean;
|
|
17
|
+
export declare function shouldUseOpenRouterResponses(apiMode: ApiMode, providerKind: ReturnType<typeof getProviderKind>): boolean;
|
|
18
|
+
export declare function getWarnings(apiMode: ApiMode, baseUrl: string | undefined, options: SearchOptions): string[];
|
|
19
|
+
export declare function createExecutionContext(prompt: string, config: GrokSearchConfig): SearchExecutionContext;
|
|
20
|
+
export declare function createLocalExecutionContext(prompt: string, options: SearchOptions): SearchExecutionContext;
|
|
21
|
+
export declare function createPayload(params: {
|
|
22
|
+
command: "all";
|
|
23
|
+
apiMode: ApiMode;
|
|
24
|
+
model: string;
|
|
25
|
+
prompt: string;
|
|
26
|
+
result: CompletedResult;
|
|
27
|
+
verbose: boolean;
|
|
28
|
+
requestApi: string;
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
startedAt: number;
|
|
31
|
+
}): SearchResultPayload;
|
|
32
|
+
export declare function runStreamRequest(params: SearchExecutionContext): Promise<StreamResult>;
|
|
33
|
+
export declare function runSearchRequest(params: SearchExecutionContext): Promise<CompletedResult>;
|
|
34
|
+
export declare function grokSearch(query: string, config: GrokSearchConfig): Promise<SearchResultPayload>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export type UtilityCommandName = "skill" | "doctor";
|
|
2
|
+
export type SearchCommandName = "all";
|
|
3
|
+
export type CommandName = SearchCommandName | UtilityCommandName;
|
|
4
|
+
export type ApiMode = "responses" | "completion";
|
|
5
|
+
export type ProviderKind = "xai" | "openrouter" | "third-party";
|
|
6
|
+
export interface SearchOptions {
|
|
7
|
+
model: string;
|
|
8
|
+
timeoutMs: number;
|
|
9
|
+
verbose: boolean;
|
|
10
|
+
allowedDomains: string[];
|
|
11
|
+
excludedDomains: string[];
|
|
12
|
+
allowedHandles: string[];
|
|
13
|
+
excludedHandles: string[];
|
|
14
|
+
fromDate?: string;
|
|
15
|
+
toDate?: string;
|
|
16
|
+
enableImageUnderstanding: boolean;
|
|
17
|
+
enableVideoUnderstanding: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface CliOptions extends SearchOptions {
|
|
20
|
+
json: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface GrokSearchConfig {
|
|
23
|
+
apiKey: string;
|
|
24
|
+
model?: string;
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
compatMode?: boolean | string;
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
verbose?: boolean;
|
|
29
|
+
allowedDomains?: string[];
|
|
30
|
+
excludedDomains?: string[];
|
|
31
|
+
allowedHandles?: string[];
|
|
32
|
+
excludedHandles?: string[];
|
|
33
|
+
fromDate?: string;
|
|
34
|
+
toDate?: string;
|
|
35
|
+
enableImageUnderstanding?: boolean;
|
|
36
|
+
enableVideoUnderstanding?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export type ParsedArgs = {
|
|
39
|
+
command: "skill";
|
|
40
|
+
} | {
|
|
41
|
+
command: "doctor";
|
|
42
|
+
} | {
|
|
43
|
+
command: SearchCommandName;
|
|
44
|
+
prompt: string;
|
|
45
|
+
options: CliOptions;
|
|
46
|
+
};
|
|
47
|
+
export interface UsageLike {
|
|
48
|
+
inputTokens?: number;
|
|
49
|
+
outputTokens?: number;
|
|
50
|
+
totalTokens?: number;
|
|
51
|
+
outputTokenDetails?: {
|
|
52
|
+
reasoningTokens?: number;
|
|
53
|
+
textTokens?: number;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export interface VerbosePayload {
|
|
57
|
+
model: string;
|
|
58
|
+
finishReason: string;
|
|
59
|
+
requestApi: string;
|
|
60
|
+
baseUrl?: string;
|
|
61
|
+
durationMs: number;
|
|
62
|
+
firstTokenLatencyMs?: number;
|
|
63
|
+
tokensPerSecond?: number;
|
|
64
|
+
usage: {
|
|
65
|
+
inputTokens?: number;
|
|
66
|
+
outputTokens?: number;
|
|
67
|
+
reasoningTokens?: number;
|
|
68
|
+
totalTokens?: number;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface SearchResultPayload {
|
|
72
|
+
command: SearchCommandName;
|
|
73
|
+
apiMode: ApiMode;
|
|
74
|
+
model: string;
|
|
75
|
+
prompt: string;
|
|
76
|
+
text: string;
|
|
77
|
+
finishReason: string;
|
|
78
|
+
usage: unknown;
|
|
79
|
+
sources: unknown[];
|
|
80
|
+
verbose?: VerbosePayload;
|
|
81
|
+
}
|
|
82
|
+
export interface StreamResult {
|
|
83
|
+
textStream: AsyncIterable<string>;
|
|
84
|
+
text: PromiseLike<string>;
|
|
85
|
+
finishReason: PromiseLike<string | undefined>;
|
|
86
|
+
usage: PromiseLike<unknown>;
|
|
87
|
+
sources: PromiseLike<unknown[]>;
|
|
88
|
+
}
|
|
89
|
+
export interface CompletedResult {
|
|
90
|
+
text: string;
|
|
91
|
+
finishReason?: string;
|
|
92
|
+
usage: unknown;
|
|
93
|
+
sources: unknown[];
|
|
94
|
+
}
|
|
95
|
+
export interface OpenRouterResponsesOutputTextAnnotation {
|
|
96
|
+
type?: string;
|
|
97
|
+
url?: string;
|
|
98
|
+
start_index?: number;
|
|
99
|
+
end_index?: number;
|
|
100
|
+
}
|
|
101
|
+
export interface OpenRouterResponsesOutputText {
|
|
102
|
+
type?: string;
|
|
103
|
+
text?: string;
|
|
104
|
+
annotations?: OpenRouterResponsesOutputTextAnnotation[];
|
|
105
|
+
}
|
|
106
|
+
export interface OpenRouterResponsesOutputItem {
|
|
107
|
+
type?: string;
|
|
108
|
+
role?: string;
|
|
109
|
+
content?: OpenRouterResponsesOutputText[];
|
|
110
|
+
}
|
|
111
|
+
export interface OpenRouterResponsesUsage {
|
|
112
|
+
input_tokens?: number;
|
|
113
|
+
output_tokens?: number;
|
|
114
|
+
total_tokens?: number;
|
|
115
|
+
}
|
|
116
|
+
export interface OpenRouterResponsesBody {
|
|
117
|
+
model?: string;
|
|
118
|
+
status?: string;
|
|
119
|
+
output?: OpenRouterResponsesOutputItem[];
|
|
120
|
+
usage?: OpenRouterResponsesUsage;
|
|
121
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grok-search-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "AI-friendly CLI for high-freshness web and X research with Grok search tool.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -22,6 +22,13 @@
|
|
|
22
22
|
],
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"type": "module",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
25
32
|
"bin": {
|
|
26
33
|
"grok-search": "dist/cli.js"
|
|
27
34
|
},
|
|
@@ -41,15 +48,17 @@
|
|
|
41
48
|
"dependencies": {
|
|
42
49
|
"@ai-sdk/openai-compatible": "^2.0.38",
|
|
43
50
|
"@ai-sdk/xai": "^3.0.77",
|
|
44
|
-
"ai": "^6.0.
|
|
45
|
-
"conf": "^
|
|
51
|
+
"ai": "^6.0.146",
|
|
52
|
+
"conf": "^15.1.0",
|
|
53
|
+
"p-defer": "^4.0.1"
|
|
46
54
|
},
|
|
47
55
|
"devDependencies": {
|
|
48
56
|
"@dotenvx/dotenvx": "^1.51.1",
|
|
49
|
-
"@types/node": "^
|
|
57
|
+
"@types/node": "^25.5.2",
|
|
50
58
|
"tsx": "^4.20.6",
|
|
51
|
-
"typescript": "^
|
|
52
|
-
"vite": "^8.0.3"
|
|
59
|
+
"typescript": "^6.0.2",
|
|
60
|
+
"vite": "^8.0.3",
|
|
61
|
+
"vite-plugin-dts": "^4.5.4"
|
|
53
62
|
},
|
|
54
63
|
"scripts": {
|
|
55
64
|
"build": "vite build",
|