@agi-cli/sdk 0.1.139 → 0.1.141

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.
Files changed (40) hide show
  1. package/package.json +6 -6
  2. package/src/config/src/index.ts +2 -0
  3. package/src/config/src/manager.ts +10 -7
  4. package/src/core/src/index.ts +1 -1
  5. package/src/core/src/providers/resolver.ts +16 -1
  6. package/src/core/src/tools/builtin/bash.ts +1 -1
  7. package/src/core/src/tools/builtin/edit.ts +1 -1
  8. package/src/core/src/tools/builtin/finish.ts +1 -1
  9. package/src/core/src/tools/builtin/fs/cd.ts +1 -1
  10. package/src/core/src/tools/builtin/fs/ls.ts +1 -1
  11. package/src/core/src/tools/builtin/fs/pwd.ts +1 -1
  12. package/src/core/src/tools/builtin/fs/read.ts +1 -1
  13. package/src/core/src/tools/builtin/fs/tree.ts +1 -1
  14. package/src/core/src/tools/builtin/fs/write.ts +1 -1
  15. package/src/core/src/tools/builtin/git.ts +2 -2
  16. package/src/core/src/tools/builtin/glob.ts +1 -1
  17. package/src/core/src/tools/builtin/grep.ts +1 -1
  18. package/src/core/src/tools/builtin/patch.ts +1 -1
  19. package/src/core/src/tools/builtin/progress.ts +1 -1
  20. package/src/core/src/tools/builtin/ripgrep.ts +1 -1
  21. package/src/core/src/tools/builtin/terminal.ts +1 -1
  22. package/src/core/src/tools/builtin/todos.ts +1 -1
  23. package/src/core/src/tools/builtin/websearch.ts +1 -1
  24. package/src/core/src/tools/loader.ts +1 -1
  25. package/src/index.ts +7 -1
  26. package/src/prompts/src/providers/default.txt +2 -4
  27. package/src/prompts/src/providers.ts +17 -14
  28. package/src/providers/src/catalog.ts +481 -268
  29. package/src/providers/src/env.ts +1 -0
  30. package/src/providers/src/index.ts +6 -0
  31. package/src/providers/src/moonshot-client.ts +25 -0
  32. package/src/providers/src/openai-oauth-client.ts +5 -1
  33. package/src/providers/src/opencode-client.ts +2 -18
  34. package/src/providers/src/openrouter-client.ts +3 -2
  35. package/src/providers/src/pricing.ts +3 -0
  36. package/src/providers/src/utils.ts +42 -2
  37. package/src/skills/tool.ts +1 -1
  38. package/src/types/src/config.ts +3 -0
  39. package/src/types/src/index.ts +1 -0
  40. package/src/types/src/provider.ts +3 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agi-cli/sdk",
3
- "version": "0.1.139",
3
+ "version": "0.1.141",
4
4
  "description": "AI agent SDK for building intelligent assistants - tree-shakable and comprehensive",
5
5
  "author": "nitishxyz",
6
6
  "license": "MIT",
@@ -90,14 +90,14 @@
90
90
  "typecheck": "tsc --noEmit"
91
91
  },
92
92
  "dependencies": {
93
- "@ai-sdk/anthropic": "^2.0.16",
94
- "@ai-sdk/google": "^2.0.14",
95
- "@ai-sdk/openai": "^2.0.30",
96
- "@ai-sdk/openai-compatible": "^1.0.18",
93
+ "@ai-sdk/anthropic": "^3.0.0",
94
+ "@ai-sdk/google": "^3.0.0",
95
+ "@ai-sdk/openai": "^3.0.0",
96
+ "@ai-sdk/openai-compatible": "^2.0.0",
97
97
  "@openauthjs/openauth": "^0.4.3",
98
98
  "@openrouter/ai-sdk-provider": "^1.2.0",
99
99
  "@solana/web3.js": "^1.95.2",
100
- "ai": "^5.0.43",
100
+ "ai": "^6.0.0",
101
101
  "bs58": "^6.0.0",
102
102
  "bun-pty": "^0.3.2",
103
103
  "diff": "^8.0.2",
@@ -17,6 +17,7 @@ const DEFAULTS: {
17
17
  agent: 'general',
18
18
  provider: 'openai',
19
19
  model: 'gpt-4o-mini',
20
+ toolApproval: 'auto',
20
21
  },
21
22
  providers: {
22
23
  openai: { enabled: true },
@@ -27,6 +28,7 @@ const DEFAULTS: {
27
28
  solforge: { enabled: false },
28
29
  zai: { enabled: false },
29
30
  'zai-coding': { enabled: false },
31
+ moonshot: { enabled: false },
30
32
  },
31
33
  };
32
34
 
@@ -54,20 +54,23 @@ export async function ensureEnv(
54
54
 
55
55
  export async function writeDefaults(
56
56
  scope: Scope,
57
- updates: Partial<{ agent: string; provider: ProviderId; model: string }>,
57
+ updates: Partial<{
58
+ agent: string;
59
+ provider: ProviderId;
60
+ model: string;
61
+ toolApproval: 'auto' | 'dangerous' | 'all';
62
+ }>,
58
63
  projectRoot?: string,
59
64
  ) {
60
65
  const { cfg } = await read(projectRoot);
61
66
  if (scope === 'local') {
62
67
  const next = {
63
- projectRoot: cfg.projectRoot,
64
68
  defaults: {
65
- agent: updates.agent ?? cfg.defaults.agent,
69
+ ...cfg.defaults,
70
+ ...updates,
66
71
  provider: (updates.provider ?? cfg.defaults.provider) as ProviderId,
67
- model: updates.model ?? cfg.defaults.model,
68
72
  },
69
73
  providers: cfg.providers,
70
- paths: cfg.paths,
71
74
  };
72
75
  const path = `${cfg.paths.dataDir}/config.json`;
73
76
  await Bun.write(path, JSON.stringify(next, null, 2));
@@ -77,9 +80,9 @@ export async function writeDefaults(
77
80
  const path = getGlobalConfigPath();
78
81
  const next = {
79
82
  defaults: {
80
- agent: updates.agent ?? cfg.defaults.agent,
83
+ ...cfg.defaults,
84
+ ...updates,
81
85
  provider: (updates.provider ?? cfg.defaults.provider) as ProviderId,
82
- model: updates.model ?? cfg.defaults.model,
83
86
  },
84
87
  providers: cfg.providers,
85
88
  };
@@ -8,7 +8,7 @@ export {
8
8
  streamObject,
9
9
  tool,
10
10
  } from 'ai';
11
- export type { CoreMessage, Tool } from 'ai';
11
+ export type { ModelMessage, Tool } from 'ai';
12
12
 
13
13
  // =======================
14
14
  // Provider & Model Resolution
@@ -35,7 +35,8 @@ export type ProviderName =
35
35
  | 'opencode'
36
36
  | 'solforge'
37
37
  | 'zai'
38
- | 'zai-coding';
38
+ | 'zai-coding'
39
+ | 'moonshot';
39
40
 
40
41
  export type ModelConfig = {
41
42
  apiKey?: string;
@@ -206,6 +207,20 @@ export async function resolveModel(
206
207
  return instance(model);
207
208
  }
208
209
 
210
+ if (provider === 'moonshot') {
211
+ const entry = catalog[provider];
212
+ const apiKey = config.apiKey || process.env.MOONSHOT_API_KEY || '';
213
+ const baseURL =
214
+ config.baseURL || entry?.api || 'https://api.moonshot.ai/v1';
215
+ const headers = apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined;
216
+ const instance = createOpenAICompatible({
217
+ name: entry?.label ?? 'Moonshot AI',
218
+ baseURL,
219
+ headers,
220
+ });
221
+ return instance(model);
222
+ }
223
+
209
224
  throw new Error(`Unsupported provider: ${provider}`);
210
225
  }
211
226
 
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import { spawn } from 'node:child_process';
4
4
  import DESCRIPTION from './bash.txt' with { type: 'text' };
5
5
  import { createToolError, type ToolResponse } from '../error.ts';
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import { readFile, writeFile, access } from 'node:fs/promises';
4
4
  import { constants } from 'node:fs';
5
5
  import DESCRIPTION from './edit.txt' with { type: 'text' };
@@ -1,4 +1,4 @@
1
- import { z } from 'zod';
1
+ import { z } from 'zod/v3';
2
2
  import { tool } from 'ai';
3
3
  import DESCRIPTION from './finish.txt' with { type: 'text' };
4
4
  import type { ToolResponse } from '../error.ts';
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import DESCRIPTION from './cd.txt' with { type: 'text' };
4
4
 
5
5
  // description imported above
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import { exec } from 'node:child_process';
4
4
  import { promisify } from 'node:util';
5
5
  import { expandTilde, isAbsoluteLike, resolveSafePath } from './util.ts';
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import DESCRIPTION from './pwd.txt' with { type: 'text' };
4
4
 
5
5
  // description imported above
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import { expandTilde, isAbsoluteLike, resolveSafePath } from './util.ts';
5
5
  import DESCRIPTION from './read.txt' with { type: 'text' };
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import { exec } from 'node:child_process';
4
4
  import { promisify } from 'node:util';
5
5
  import { expandTilde, isAbsoluteLike, resolveSafePath } from './util.ts';
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import { readFile, writeFile, mkdir } from 'node:fs/promises';
4
4
  import {
5
5
  buildWriteArtifact,
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import { exec } from 'node:child_process';
4
4
  import { promisify } from 'node:util';
5
5
  import GIT_STATUS_DESCRIPTION from './git.status.txt' with { type: 'text' };
@@ -37,7 +37,7 @@ export function buildGitTools(
37
37
 
38
38
  const git_status = tool({
39
39
  description: GIT_STATUS_DESCRIPTION,
40
- inputSchema: z.object({}).optional(),
40
+ inputSchema: z.object({}),
41
41
  async execute(): Promise<
42
42
  ToolResponse<{ staged: number; unstaged: number; raw: string[] }>
43
43
  > {
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import fg from 'fast-glob';
4
4
  import { join } from 'node:path';
5
5
  import { stat } from 'node:fs/promises';
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import { exec } from 'node:child_process';
4
4
  import { promisify } from 'node:util';
5
5
  import { join } from 'node:path';
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import DESCRIPTION from './patch.txt' with { type: 'text' };
4
4
  import { createToolError, type ToolResponse } from '../error.ts';
5
5
  import { applyPatchOperations } from './patch/apply.ts';
@@ -1,5 +1,5 @@
1
1
  import { tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import DESCRIPTION from './progress.txt' with { type: 'text' };
4
4
 
5
5
  // Progress update tool: allows the model to emit lightweight status signals
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import { spawn } from 'node:child_process';
4
4
  import { join } from 'node:path';
5
5
  import DESCRIPTION from './ripgrep.txt' with { type: 'text' };
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import DESCRIPTION from './terminal.txt' with { type: 'text' };
4
4
  import { createToolError } from '../error.ts';
5
5
  import type { TerminalManager } from '../../terminals/index.ts';
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import DESCRIPTION from './todos.txt' with { type: 'text' };
4
4
 
5
5
  const STATUS_ENUM = z.enum([
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import DESCRIPTION from './websearch.txt' with { type: 'text' };
4
4
  import { createToolError, type ToolResponse } from '../error.ts';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v3';
3
3
  import { finishTool } from './builtin/finish.ts';
4
4
  import { buildFsTools } from './builtin/fs/index.ts';
5
5
  import { buildGitTools } from './builtin/git.ts';
package/src/index.ts CHANGED
@@ -44,7 +44,11 @@ export {
44
44
  getFastModelForAuth,
45
45
  getModelNpmBinding,
46
46
  isAnthropicBasedModel,
47
+ getUnderlyingProviderKey,
48
+ getModelInfo,
49
+ modelSupportsReasoning,
47
50
  } from './providers/src/index.ts';
51
+ export type { UnderlyingProviderKey } from './providers/src/index.ts';
48
52
  export {
49
53
  isProviderAuthorized,
50
54
  ensureProviderEnv,
@@ -100,6 +104,8 @@ export {
100
104
  export type { OpenRouterProviderConfig } from './providers/src/index.ts';
101
105
  export { createOpencodeModel } from './providers/src/index.ts';
102
106
  export type { OpencodeProviderConfig } from './providers/src/index.ts';
107
+ export { createMoonshotModel } from './providers/src/index.ts';
108
+ export type { MoonshotProviderConfig } from './providers/src/index.ts';
103
109
 
104
110
  // =======================
105
111
  // Authentication (from internal auth module)
@@ -165,7 +171,7 @@ export {
165
171
  streamObject,
166
172
  tool,
167
173
  } from './core/src/index.ts';
168
- export type { CoreMessage, Tool } from './core/src/index.ts';
174
+ export type { ModelMessage, Tool } from './core/src/index.ts';
169
175
  // Re-export from AI SDK
170
176
  export type { ToolCallPart } from 'ai';
171
177
 
@@ -1,4 +1,4 @@
1
- You are a coding agent running in the Codex CLI, a terminal-based coding assistant. Codex CLI is an open source project led by OpenAI. You are expected to be precise, safe, and helpful.
1
+ You are a coding agent running in a terminal-based coding assistant. You are expected to be precise, safe, and helpful.
2
2
 
3
3
  Your capabilities:
4
4
 
@@ -6,8 +6,6 @@ Your capabilities:
6
6
  - Communicate with the user by streaming thinking & responses, and by making & updating plans.
7
7
  - Emit function calls to run terminal commands and apply patches. Depending on how this specific run is configured, you can request that these function calls be escalated to the user for approval before running. More on this in the "Sandbox and approvals" section.
8
8
 
9
- Within this context, Codex refers to the open-source agentic coding interface (not the old Codex language model built by OpenAI).
10
-
11
9
  ## Tool Ecosystem
12
10
 
13
11
  You have access to a rich set of specialized tools optimized for coding tasks:
@@ -282,7 +280,7 @@ If completing the user's task requires writing or modifying files, your code and
282
280
 
283
281
  ## Sandbox and approvals
284
282
 
285
- The Codex CLI harness supports several different sandboxing, and approval configurations that the user can choose from.
283
+ The CLI harness supports several different sandboxing, and approval configurations that the user can choose from.
286
284
 
287
285
  Filesystem sandboxing prevents you from editing files without user approval. The options are:
288
286
 
@@ -2,6 +2,8 @@
2
2
  // Loads src/prompts/providers/<provider>.txt and returns its contents (trimmed).
3
3
 
4
4
  import { debugLog } from './debug.ts';
5
+ import { getModelNpmBinding, isProviderId } from '../../providers/src/utils.ts';
6
+ import type { ProviderId } from '../../types/src/index.ts';
5
7
  // Embed default provider prompts into the binary via text imports
6
8
  // Only user-defined overrides should be read from disk.
7
9
  // eslint-disable-next-line @typescript-eslint/consistent-type-imports
@@ -22,18 +24,14 @@ function sanitizeModelId(modelId: string): string {
22
24
  .replace(/[/]+/g, '__');
23
25
  }
24
26
 
25
- function inferFamilyFromModel(modelId: string): string | undefined {
26
- const m = modelId.toLowerCase();
27
- if (m.includes('claude')) return 'anthropic';
28
- if (m.includes('gemini')) return 'google';
29
- if (m.includes('gpt') || m.startsWith('o') || m.includes('openai'))
30
- return 'openai';
31
- // Other common families you may add prompts for later:
32
- // if (m.includes('llama')) return 'meta';
33
- // if (m.includes('mistral')) return 'mistral';
34
- // if (m.includes('deepseek')) return 'deepseek';
35
- // if (m.includes('qwen')) return 'qwen';
36
- // if (m.includes('moonshot') || m.includes('kimi')) return 'moonshot';
27
+ function inferFamilyFromModel(
28
+ provider: ProviderId,
29
+ modelId: string,
30
+ ): string | undefined {
31
+ const npm = getModelNpmBinding(provider, modelId);
32
+ if (npm === '@ai-sdk/anthropic') return 'anthropic';
33
+ if (npm === '@ai-sdk/openai') return 'openai';
34
+ if (npm === '@ai-sdk/google') return 'google';
37
35
  return undefined;
38
36
  }
39
37
 
@@ -66,10 +64,15 @@ export async function providerBasePrompt(
66
64
 
67
65
  // 2) Provider-family fallback for openrouter/opencode/solforge using embedded defaults
68
66
  if (
69
- (id === 'openrouter' || id === 'opencode' || id === 'solforge') &&
67
+ isProviderId(id) &&
68
+ (id === 'openrouter' ||
69
+ id === 'opencode' ||
70
+ id === 'solforge' ||
71
+ id === 'zai' ||
72
+ id === 'zai-coding') &&
70
73
  modelId
71
74
  ) {
72
- const family = inferFamilyFromModel(modelId);
75
+ const family = inferFamilyFromModel(id, modelId);
73
76
  if (family) {
74
77
  const embedded = (
75
78
  family === 'openai'