zero-ai-cli 1.0.0 β 1.0.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/package.json +1 -1
- package/packages/cli/src/index.ts +2 -2
- package/packages/cli/src/interactive.ts +1 -1
- package/packages/cli/src/once.ts +1 -1
- package/packages/core/src/providers/extended.ts +8 -0
- package/packages/core/src/providers/registry.ts +1 -1
- package/packages/core/src/tools/builtin.ts +9 -0
- package/packages/core/src/tools/linter.ts +9 -0
- package/packages/core/src/tools/repo-map.ts +10 -0
- package/packages/sdk/src/index.ts +2 -2
package/package.json
CHANGED
|
@@ -21,8 +21,8 @@ import {
|
|
|
21
21
|
getAllBuiltinTools,
|
|
22
22
|
AgentEngine,
|
|
23
23
|
DEFAULT_PERMISSION_CONFIG,
|
|
24
|
-
} from "
|
|
25
|
-
import type { PermissionRequest, PermissionDecision, Message } from "
|
|
24
|
+
} from "../../core/src/index.js";
|
|
25
|
+
import type { PermissionRequest, PermissionDecision, Message } from "../../core/src/index.js";
|
|
26
26
|
import { runInteractive } from "./interactive.js";
|
|
27
27
|
import { runOnce } from "./once.js";
|
|
28
28
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import * as readline from "node:readline";
|
|
7
7
|
import chalk from "chalk";
|
|
8
|
-
import type { AgentEngine, Message, FileMemoryStore, ContextManager } from "
|
|
8
|
+
import type { AgentEngine, Message, FileMemoryStore, ContextManager } from "../../core/src/index.js";
|
|
9
9
|
|
|
10
10
|
interface ZeroRuntime {
|
|
11
11
|
agentRegistry: any;
|
package/packages/cli/src/once.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LLMProvider } from "../types.js";
|
|
2
|
+
import { OpenAICompatibleClient } from "./registry.js";
|
|
3
|
+
export function createDeepSeekProvider():LLMProvider{return{id:"deepseek",name:"DeepSeek",type:"openai",models:[{id:"deepseek-v4-pro",name:"DeepSeek V4 Pro",contextWindow:1000000,maxOutputTokens:8192,supportsImages:false,supportsToolUse:true,supportsStreaming:true},{id:"deepseek-v4-flash",name:"DeepSeek V4 Flash",contextWindow:1000000,maxOutputTokens:8192,supportsImages:false,supportsToolUse:true,supportsStreaming:true}],createClient:(c)=>new OpenAICompatibleClient(c,"https://api.deepseek.com/v1")};}
|
|
4
|
+
export function createGrokProvider():LLMProvider{return{id:"grok",name:"Grok (xAI)",type:"openai",models:[{id:"grok-4.5",name:"Grok 4.5",contextWindow:500000,maxOutputTokens:8192,supportsImages:true,supportsToolUse:true,supportsStreaming:true}],createClient:(c)=>new OpenAICompatibleClient(c,"https://api.x.ai/v1")};}
|
|
5
|
+
export function createOpenRouterProvider():LLMProvider{return{id:"openrouter",name:"OpenRouter",type:"openai",models:[{id:"openai/gpt-4o",name:"GPT-4o",contextWindow:128000,maxOutputTokens:4096,supportsImages:true,supportsToolUse:true,supportsStreaming:true}],createClient:(c)=>new OpenAICompatibleClient({...c,headers:{"HTTP-Referer":"https://zero.dev","X-Title":"ZERO",...c.headers}},"https://openrouter.ai/api/v1")};}
|
|
6
|
+
export function createTogetherProvider():LLMProvider{return{id:"together",name:"Together AI",type:"openai",models:[{id:"meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo",name:"Llama 3.1 405B",contextWindow:131072,maxOutputTokens:4096,supportsImages:false,supportsToolUse:false,supportsStreaming:true}],createClient:(c)=>new OpenAICompatibleClient(c,"https://api.together.xyz/v1")};}
|
|
7
|
+
export function createFireworksProvider():LLMProvider{return{id:"fireworks",name:"Fireworks AI",type:"openai",models:[{id:"accounts/fireworks/models/llama-v3p1-405b-instruct",name:"Llama 3.1 405B",contextWindow:131072,maxOutputTokens:4096,supportsImages:false,supportsToolUse:false,supportsStreaming:true}],createClient:(c)=>new OpenAICompatibleClient(c,"https://api.fireworks.ai/inference/v1")};}
|
|
8
|
+
export function getExtendedProviders():LLMProvider[]{return[createDeepSeekProvider(),createGrokProvider(),createOpenRouterProvider(),createTogetherProvider(),createFireworksProvider()];}
|
|
@@ -263,7 +263,7 @@ function createCustomProvider(): LLMProvider {
|
|
|
263
263
|
// OpenAI-Compatible Client
|
|
264
264
|
// ============================================================================
|
|
265
265
|
|
|
266
|
-
class OpenAICompatibleClient implements LLMClient {
|
|
266
|
+
export class OpenAICompatibleClient implements LLMClient {
|
|
267
267
|
constructor(private config: ProviderConfig, private baseUrl: string) {}
|
|
268
268
|
|
|
269
269
|
async chat(messages: Message[], options?: ChatOptions): Promise<ChatResponse> {
|
|
@@ -566,3 +566,12 @@ export function getAllBuiltinTools(): ToolDefinition[] {
|
|
|
566
566
|
webSearchTool,
|
|
567
567
|
];
|
|
568
568
|
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Get all tools including extended tools (lint, repo-map)
|
|
572
|
+
*/
|
|
573
|
+
export async function getAllTools(): Promise<ToolDefinition[]> {
|
|
574
|
+
const { lintTool } = await import("./linter.js");
|
|
575
|
+
const { repoMapTool } = await import("./repo-map.js");
|
|
576
|
+
return [...getAllBuiltinTools(), lintTool, repoMapTool];
|
|
577
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import type { ToolDefinition, ToolResult } from "../types.js";
|
|
4
|
+
interface LR { file:string; language:string; errors:{line:number;column:number;message:string;rule?:string}[]; warnings:{line:number;column:number;message:string;rule?:string}[]; success:boolean; }
|
|
5
|
+
const E:Record<string,string>={".ts":"typescript",".tsx":"typescript",".js":"javascript",".jsx":"javascript",".py":"python",".go":"go",".rs":"rust",".java":"java",".rb":"ruby",".php":"php",".c":"c",".cpp":"cpp",".cs":"csharp",".swift":"swift",".kt":"kotlin",".sh":"shell",".html":"html",".css":"css",".json":"json",".yaml":"yaml",".yml":"yaml",".md":"markdown",".sql":"sql"};
|
|
6
|
+
export function detectLanguage(f:string):string{return E[path.extname(f).toLowerCase()]||"unknown";}
|
|
7
|
+
export async function lintFile(fp:string,wd:string):Promise<LR>{try{const c=await fs.readFile(path.resolve(wd,fp),"utf-8");const lang=detectLanguage(fp);const er:any[]=[],wa:any[]=[];const ls=c.split("\n");for(let i=0;i<ls.length;i++){const l=ls[i],n=i+1;if(l.length>120)wa.push({line:n,column:121,message:`Line too long (${l.length})`,rule:"max-line-length"});if(l.match(/\bdebugger\b/))er.push({line:n,column:1,message:"Remove debugger",rule:"no-debugger"});if(lang==="python"&&l.match(/\t/))er.push({line:n,column:1,message:"Tab found",rule:"W191"});}return{file:fp,language:lang,errors:er,warnings:wa,success:er.length===0};}catch(e){return{file:fp,language:"unknown",errors:[{line:0,column:0,message:String(e)}],warnings:[],success:false};}}
|
|
8
|
+
export function formatLintResult(r:LR):string{const l=[`π Lint: ${r.file} (${r.language})`,""];if(r.errors.length)l.push(`β ${r.errors.length} errors`);if(r.warnings.length)l.push(`β οΈ ${r.warnings.length} warnings`);if(!r.errors.length&&!r.warnings.length)l.push("β
No issues!");return l.join("\n");}
|
|
9
|
+
export const lintTool:ToolDefinition={name:"lint",description:"Lint a file.",parameters:{path:{type:"string",description:"File",required:true}},category:"file",requiresApproval:false,handler:async(a,c)=>{const r=await lintFile(a.path as string,c.workingDirectory);return{success:r.success,output:formatLintResult(r),data:r};}};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import type { ToolDefinition, ToolResult } from "../types.js";
|
|
4
|
+
interface RM{path:string;language:string;classes:string[];functions:string[];exports:string[];imports:string[];lines:number;}
|
|
5
|
+
const IG=new Set(["node_modules",".git","__pycache__","dist","build","coverage",".next","target","vendor",".venv",".cache"]);
|
|
6
|
+
const CE=new Set([".ts",".tsx",".js",".jsx",".py",".go",".rs",".java",".rb",".php",".c",".cpp",".cs",".swift",".kt"]);
|
|
7
|
+
function sy(c:string,e:string){const cl:string[]=[],fn:string[]=[],ex:string[]=[],im:string[]=[];for(const l of c.split("\n")){const t=l.trim();if([".ts",".tsx",".js",".jsx"].includes(e)){const m=t.match(/^(?:export\s+)?(?:abstract\s+)?class\s+(\w+)/);if(m)cl.push(m[1]);const f=t.match(/^(?:export\s+)?(?:async\s+)?function\s+(\w+)/);if(f)fn.push(f[1]);}else if(e===".py"){const m=t.match(/^class\s+(\w+)/);if(m)cl.push(m[1]);const f=t.match(/^def\s+(\w+)/);if(f&&!t.startsWith(" "))fn.push(f[1]);}else if(e===".go"){const m=t.match(/^type\s+(\w+)\s+struct/);if(m)cl.push(m[1]);const f=t.match(/^func\s+(?:\(\w+\s+\*?\w+\)\s+)?(\w+)/);if(f)fn.push(f[1]);}else if(e===".rs"){const m=t.match(/^(?:pub\s+)?struct\s+(\w+)/);if(m)cl.push(m[1]);const f=t.match(/^(?:pub\s+)?fn\s+(\w+)/);if(f)fn.push(f[1]);}}return{classes:cl,functions:fn,exports:ex,imports:im};}
|
|
8
|
+
export async function generateRepoMap(wd:string,max=50):Promise<RM[]>{const e:RM[]=[];async function w(d:string,p:string){if(e.length>=max)return;try{for(const f of await fs.readdir(d,{withFileTypes:true})){if(e.length>=max)return;if(f.name.startsWith(".")||IG.has(f.name))continue;const fp=path.join(d,f.name),r=p?`${p}/${f.name}`:f.name;if(f.isDirectory())await w(fp,r);else if(f.isFile()&&CE.has(path.extname(f.name).toLowerCase())){try{const c=await fs.readFile(fp,"utf-8");const lm:Record<string,string>={".ts":"TypeScript",".tsx":"TypeScript",".js":"JavaScript",".jsx":"JavaScript",".py":"Python",".go":"Go",".rs":"Rust"};e.push({path:r,language:lm[path.extname(f.name).toLowerCase()]||path.extname(f.name).slice(1),...sy(c,path.extname(f.name).toLowerCase()),lines:c.split("\n").length});}catch{}}}}catch{}}await w(wd,"");return e;}
|
|
9
|
+
export function formatRepoMap(e:RM[]):string{const l=["πΊοΈ Repository Map:",""];const d=new Map<string,RM[]>();for(const x of e){const p=path.dirname(x.path)||".";if(!d.has(p))d.set(p,[]);d.get(p)!.push(x);}for(const[dir,files]of d){l.push(`π ${dir}/`);for(const f of files)l.push(` π ${path.basename(f.path)} (${f.language}, ${f.lines} lines)`);}l.push("",`π ${e.length} files, ${e.reduce((s,x)=>s+x.lines,0)} lines`);return l.join("\n");}
|
|
10
|
+
export const repoMapTool:ToolDefinition={name:"repo_map",description:"Generate repo map.",parameters:{path:{type:"string",description:"Dir",required:false},maxFiles:{type:"number",description:"Max",required:false}},category:"search",requiresApproval:false,handler:async(a,c)=>{const d=a.path?path.resolve(c.workingDirectory,a.path as string):c.workingDirectory;const e=await generateRepoMap(d,(a.maxFiles as number)||50);return{success:true,output:formatRepoMap(e),data:{entries:e,count:e.length}};}};
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
MCPManager,
|
|
31
31
|
createAutoPermissionHandler,
|
|
32
32
|
getAllBuiltinTools,
|
|
33
|
-
} from "
|
|
33
|
+
} from "../../core/src/index.js";
|
|
34
34
|
import type {
|
|
35
35
|
AgentResult,
|
|
36
36
|
Message,
|
|
@@ -39,7 +39,7 @@ import type {
|
|
|
39
39
|
AgentConfig,
|
|
40
40
|
MCPServerConfig,
|
|
41
41
|
TokenUsage,
|
|
42
|
-
} from "
|
|
42
|
+
} from "../../core/src/index.js";
|
|
43
43
|
|
|
44
44
|
export interface ZeroOptions {
|
|
45
45
|
provider?: string;
|