@agi-cli/sdk 0.1.53 → 0.1.55
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 +52 -27
- package/src/agent/types.ts +1 -1
- package/src/auth/src/index.ts +70 -0
- package/src/auth/src/oauth.ts +172 -0
- package/src/config/src/index.ts +120 -0
- package/src/config/src/manager.ts +102 -0
- package/src/config/src/paths.ts +98 -0
- package/src/core/src/errors.ts +102 -0
- package/src/core/src/index.ts +75 -0
- package/src/core/src/providers/resolver.ts +84 -0
- package/src/core/src/streaming/artifacts.ts +41 -0
- package/src/core/src/tools/builtin/bash.ts +90 -0
- package/src/core/src/tools/builtin/bash.txt +7 -0
- package/src/core/src/tools/builtin/edit.ts +152 -0
- package/src/core/src/tools/builtin/edit.txt +7 -0
- package/src/core/src/tools/builtin/file-cache.ts +39 -0
- package/src/core/src/tools/builtin/finish.ts +11 -0
- package/src/core/src/tools/builtin/finish.txt +5 -0
- package/src/core/src/tools/builtin/fs/cd.ts +19 -0
- package/src/core/src/tools/builtin/fs/cd.txt +5 -0
- package/src/core/src/tools/builtin/fs/index.ts +20 -0
- package/src/core/src/tools/builtin/fs/ls.ts +60 -0
- package/src/core/src/tools/builtin/fs/ls.txt +8 -0
- package/src/core/src/tools/builtin/fs/pwd.ts +17 -0
- package/src/core/src/tools/builtin/fs/pwd.txt +5 -0
- package/src/core/src/tools/builtin/fs/read.ts +80 -0
- package/src/core/src/tools/builtin/fs/read.txt +8 -0
- package/src/core/src/tools/builtin/fs/tree.ts +71 -0
- package/src/core/src/tools/builtin/fs/tree.txt +8 -0
- package/src/core/src/tools/builtin/fs/util.ts +95 -0
- package/src/core/src/tools/builtin/fs/write.ts +61 -0
- package/src/core/src/tools/builtin/fs/write.txt +8 -0
- package/src/core/src/tools/builtin/git.commit.txt +6 -0
- package/src/core/src/tools/builtin/git.diff.txt +5 -0
- package/src/core/src/tools/builtin/git.status.txt +5 -0
- package/src/core/src/tools/builtin/git.ts +128 -0
- package/src/core/src/tools/builtin/grep.ts +140 -0
- package/src/core/src/tools/builtin/grep.txt +9 -0
- package/src/core/src/tools/builtin/ignore.ts +45 -0
- package/src/core/src/tools/builtin/patch.ts +269 -0
- package/src/core/src/tools/builtin/patch.txt +7 -0
- package/src/core/src/tools/builtin/plan.ts +58 -0
- package/src/core/src/tools/builtin/plan.txt +6 -0
- package/src/core/src/tools/builtin/progress.ts +55 -0
- package/src/core/src/tools/builtin/progress.txt +7 -0
- package/src/core/src/tools/builtin/ripgrep.ts +102 -0
- package/src/core/src/tools/builtin/ripgrep.txt +7 -0
- package/src/core/src/tools/builtin/websearch.ts +219 -0
- package/src/core/src/tools/builtin/websearch.txt +12 -0
- package/src/core/src/tools/loader.ts +398 -0
- package/src/core/src/types/index.ts +11 -0
- package/src/core/src/types/types.ts +4 -0
- package/src/index.ts +57 -58
- package/src/prompts/src/agents/build.txt +5 -0
- package/src/prompts/src/agents/general.txt +6 -0
- package/src/prompts/src/agents/plan.txt +13 -0
- package/src/prompts/src/base.txt +14 -0
- package/src/prompts/src/debug.ts +104 -0
- package/src/prompts/src/index.ts +1 -0
- package/src/prompts/src/modes/oneshot.txt +9 -0
- package/src/prompts/src/providers/anthropic.txt +151 -0
- package/src/prompts/src/providers/anthropicSpoof.txt +1 -0
- package/src/prompts/src/providers/default.txt +310 -0
- package/src/prompts/src/providers/google.txt +155 -0
- package/src/prompts/src/providers/openai.txt +310 -0
- package/src/prompts/src/providers.ts +116 -0
- package/src/providers/src/authorization.ts +17 -0
- package/src/providers/src/catalog.ts +4201 -0
- package/src/providers/src/env.ts +26 -0
- package/src/providers/src/index.ts +12 -0
- package/src/providers/src/pricing.ts +135 -0
- package/src/providers/src/utils.ts +24 -0
- package/src/providers/src/validate.ts +39 -0
- package/src/types/src/auth.ts +26 -0
- package/src/types/src/config.ts +40 -0
- package/src/types/src/index.ts +14 -0
- package/src/types/src/provider.ts +28 -0
- package/src/global.d.ts +0 -4
- package/src/tools/builtin/fs.ts +0 -1
- package/src/tools/builtin/git.ts +0 -1
- package/src/web-ui.ts +0 -8
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ProviderId } from '../../types/src/index.ts';
|
|
2
|
+
|
|
3
|
+
const ENV_VARS: Record<ProviderId, string> = {
|
|
4
|
+
openai: 'OPENAI_API_KEY',
|
|
5
|
+
anthropic: 'ANTHROPIC_API_KEY',
|
|
6
|
+
google: 'GOOGLE_GENERATIVE_AI_API_KEY',
|
|
7
|
+
openrouter: 'OPENROUTER_API_KEY',
|
|
8
|
+
opencode: 'OPENCODE_API_KEY',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function providerEnvVar(provider: ProviderId): string {
|
|
12
|
+
return ENV_VARS[provider];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function readEnvKey(provider: ProviderId): string | undefined {
|
|
16
|
+
const key = providerEnvVar(provider);
|
|
17
|
+
const value = process.env[key];
|
|
18
|
+
return value?.length ? value : undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function setEnvKey(provider: ProviderId, value: string | undefined) {
|
|
22
|
+
const key = providerEnvVar(provider);
|
|
23
|
+
if (value) {
|
|
24
|
+
process.env[key] = value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { isProviderAuthorized, ensureProviderEnv } from './authorization.ts';
|
|
2
|
+
export { catalog } from './catalog.ts';
|
|
3
|
+
export type { ProviderId, ModelInfo } from '../../types/src/index.ts';
|
|
4
|
+
export {
|
|
5
|
+
isProviderId,
|
|
6
|
+
providerIds,
|
|
7
|
+
defaultModelFor,
|
|
8
|
+
hasModel,
|
|
9
|
+
} from './utils.ts';
|
|
10
|
+
export { validateProviderModel } from './validate.ts';
|
|
11
|
+
export { estimateModelCostUsd } from './pricing.ts';
|
|
12
|
+
export { providerEnvVar, readEnvKey, setEnvKey } from './env.ts';
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { catalog } from './catalog.ts';
|
|
2
|
+
import type { ModelInfo, ProviderId } from '../../types/src/index.ts';
|
|
3
|
+
|
|
4
|
+
type ProviderName = ProviderId;
|
|
5
|
+
|
|
6
|
+
type UsageLike = {
|
|
7
|
+
inputTokens?: number | null;
|
|
8
|
+
outputTokens?: number | null;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type PricingEntry = {
|
|
12
|
+
/** Cost in USD per 1 million input tokens */
|
|
13
|
+
inputPerMillion: number;
|
|
14
|
+
/** Cost in USD per 1 million output tokens */
|
|
15
|
+
outputPerMillion: number;
|
|
16
|
+
match: (model: string) => boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const pricingTable: Record<ProviderName, PricingEntry[]> = {
|
|
20
|
+
openai: [
|
|
21
|
+
{
|
|
22
|
+
match: (model) => model.includes('gpt-4o-mini'),
|
|
23
|
+
inputPerMillion: 0.15,
|
|
24
|
+
outputPerMillion: 0.6,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
match: (model) => model.includes('gpt-4o'),
|
|
28
|
+
inputPerMillion: 5,
|
|
29
|
+
outputPerMillion: 15,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
match: (model) => model.includes('gpt-4.1-mini'),
|
|
33
|
+
inputPerMillion: 1,
|
|
34
|
+
outputPerMillion: 4,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
match: (model) => model.includes('gpt-4.1'),
|
|
38
|
+
inputPerMillion: 5,
|
|
39
|
+
outputPerMillion: 15,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
anthropic: [
|
|
43
|
+
{
|
|
44
|
+
match: (model) => model.includes('claude-3-haiku'),
|
|
45
|
+
inputPerMillion: 0.25,
|
|
46
|
+
outputPerMillion: 1.25,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
match: (model) => model.includes('claude-3-sonnet'),
|
|
50
|
+
inputPerMillion: 3,
|
|
51
|
+
outputPerMillion: 15,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
match: (model) => model.includes('claude-3-opus'),
|
|
55
|
+
inputPerMillion: 15,
|
|
56
|
+
outputPerMillion: 75,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
google: [
|
|
60
|
+
{
|
|
61
|
+
match: (model) => model.includes('gemini-1.5-flash'),
|
|
62
|
+
inputPerMillion: 0.35,
|
|
63
|
+
outputPerMillion: 1.05,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
match: (model) => model.includes('gemini-1.5-pro'),
|
|
67
|
+
inputPerMillion: 3.5,
|
|
68
|
+
outputPerMillion: 10.5,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
openrouter: [
|
|
72
|
+
// Prefer catalog pricing; keep empty to defer to catalog or undefined
|
|
73
|
+
],
|
|
74
|
+
opencode: [
|
|
75
|
+
// Pricing from catalog entries; leave empty here
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function findPricing(
|
|
80
|
+
provider: ProviderName,
|
|
81
|
+
model: string,
|
|
82
|
+
): PricingEntry | undefined {
|
|
83
|
+
const entries = pricingTable[provider];
|
|
84
|
+
if (!entries) return undefined;
|
|
85
|
+
return entries.find((entry) => {
|
|
86
|
+
try {
|
|
87
|
+
return entry.match(model);
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function findCatalogModel(
|
|
95
|
+
provider: ProviderName,
|
|
96
|
+
model: string,
|
|
97
|
+
): ModelInfo | undefined {
|
|
98
|
+
const entry = catalog[provider as keyof typeof catalog];
|
|
99
|
+
if (!entry) return undefined;
|
|
100
|
+
const idLower = model.toLowerCase();
|
|
101
|
+
return entry.models.find((m) => m.id?.toLowerCase() === idLower);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function estimateModelCostUsd(
|
|
105
|
+
provider: ProviderName,
|
|
106
|
+
model: string,
|
|
107
|
+
usage: UsageLike,
|
|
108
|
+
): number | undefined {
|
|
109
|
+
const inputTokens =
|
|
110
|
+
typeof usage.inputTokens === 'number' ? usage.inputTokens : 0;
|
|
111
|
+
const outputTokens =
|
|
112
|
+
typeof usage.outputTokens === 'number' ? usage.outputTokens : 0;
|
|
113
|
+
if (!inputTokens && !outputTokens) return undefined;
|
|
114
|
+
|
|
115
|
+
// Prefer centralized catalog costs when available
|
|
116
|
+
const m = findCatalogModel(provider, model);
|
|
117
|
+
if (m?.cost?.input != null || m?.cost?.output != null) {
|
|
118
|
+
const inputPerMillion =
|
|
119
|
+
typeof m.cost?.input === 'number' ? m.cost.input : 0;
|
|
120
|
+
const outputPerMillion =
|
|
121
|
+
typeof m.cost?.output === 'number' ? m.cost.output : 0;
|
|
122
|
+
const inputCost = (inputTokens * inputPerMillion) / 1_000_000;
|
|
123
|
+
const outputCost = (outputTokens * outputPerMillion) / 1_000_000;
|
|
124
|
+
const total = inputCost + outputCost;
|
|
125
|
+
return Number.isFinite(total) ? Number(total.toFixed(6)) : undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Fallback to legacy table if catalog lacks pricing
|
|
129
|
+
const entry = findPricing(provider, model.toLowerCase());
|
|
130
|
+
if (!entry) return undefined;
|
|
131
|
+
const inputCost = (inputTokens * entry.inputPerMillion) / 1_000_000;
|
|
132
|
+
const outputCost = (outputTokens * entry.outputPerMillion) / 1_000_000;
|
|
133
|
+
const total = inputCost + outputCost;
|
|
134
|
+
return Number.isFinite(total) ? Number(total.toFixed(6)) : undefined;
|
|
135
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { catalog } from './catalog.ts';
|
|
2
|
+
import type { ProviderId } from '../../types/src/index.ts';
|
|
3
|
+
|
|
4
|
+
export const providerIds = Object.keys(catalog) as ProviderId[];
|
|
5
|
+
|
|
6
|
+
export function isProviderId(value: unknown): value is ProviderId {
|
|
7
|
+
return typeof value === 'string' && providerIds.includes(value as ProviderId);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function defaultModelFor(provider: ProviderId): string | undefined {
|
|
11
|
+
return catalog[provider]?.models?.[0]?.id;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function listModels(provider: ProviderId): string[] {
|
|
15
|
+
return (catalog[provider]?.models ?? []).map((m) => m.id);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function hasModel(
|
|
19
|
+
provider: ProviderId,
|
|
20
|
+
model: string | undefined,
|
|
21
|
+
): boolean {
|
|
22
|
+
if (!model) return false;
|
|
23
|
+
return listModels(provider).includes(model);
|
|
24
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { catalog } from './catalog.ts';
|
|
2
|
+
import type { ProviderId } from '../../types/src/index.ts';
|
|
3
|
+
|
|
4
|
+
export type CapabilityRequest = {
|
|
5
|
+
wantsToolCalls?: boolean;
|
|
6
|
+
wantsVision?: boolean; // input image
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function validateProviderModel(
|
|
10
|
+
provider: string,
|
|
11
|
+
model: string,
|
|
12
|
+
cap?: CapabilityRequest,
|
|
13
|
+
) {
|
|
14
|
+
const p = provider as ProviderId;
|
|
15
|
+
if (!catalog[p]) {
|
|
16
|
+
throw new Error(`Provider not supported: ${provider}`);
|
|
17
|
+
}
|
|
18
|
+
const entry = catalog[p].models.find((m) => m.id === model);
|
|
19
|
+
if (!entry) {
|
|
20
|
+
const list = catalog[p].models
|
|
21
|
+
.slice(0, 10)
|
|
22
|
+
.map((m) => m.id)
|
|
23
|
+
.join(', ');
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Model not found for provider ${provider}: ${model}. Example models: ${list}${catalog[p].models.length > 10 ? ', ...' : ''}`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (cap?.wantsToolCalls && !entry.toolCall) {
|
|
29
|
+
throw new Error(`Model ${model} does not support tool calls.`);
|
|
30
|
+
}
|
|
31
|
+
if (cap?.wantsVision) {
|
|
32
|
+
const inputs = entry.modalities?.input as string[] | undefined;
|
|
33
|
+
const outputs = entry.modalities?.output as string[] | undefined;
|
|
34
|
+
const ok =
|
|
35
|
+
(inputs ?? []).includes('image') || (outputs ?? []).includes('image');
|
|
36
|
+
if (!ok)
|
|
37
|
+
throw new Error(`Model ${model} does not support vision input/output.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ProviderId } from './provider';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* API key authentication
|
|
5
|
+
*/
|
|
6
|
+
export type ApiAuth = { type: 'api'; key: string };
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* OAuth authentication tokens
|
|
10
|
+
*/
|
|
11
|
+
export type OAuth = {
|
|
12
|
+
type: 'oauth';
|
|
13
|
+
access: string;
|
|
14
|
+
refresh: string;
|
|
15
|
+
expires: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Union of all auth types
|
|
20
|
+
*/
|
|
21
|
+
export type AuthInfo = ApiAuth | OAuth;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Collection of auth credentials per provider
|
|
25
|
+
*/
|
|
26
|
+
export type AuthFile = Partial<Record<ProviderId, AuthInfo>>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ProviderId } from './provider';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration scope - where settings are stored
|
|
5
|
+
*/
|
|
6
|
+
export type Scope = 'global' | 'local';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Provider-specific configuration
|
|
10
|
+
*/
|
|
11
|
+
export type ProviderConfig = { enabled: boolean; apiKey?: string };
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Default settings for the CLI
|
|
15
|
+
*/
|
|
16
|
+
export type DefaultConfig = {
|
|
17
|
+
agent: string;
|
|
18
|
+
provider: ProviderId;
|
|
19
|
+
model: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Path configuration
|
|
24
|
+
*/
|
|
25
|
+
export type PathConfig = {
|
|
26
|
+
dataDir: string;
|
|
27
|
+
dbPath: string;
|
|
28
|
+
projectConfigPath: string | null;
|
|
29
|
+
globalConfigPath: string | null;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Complete AGI configuration object
|
|
34
|
+
*/
|
|
35
|
+
export type AGIConfig = {
|
|
36
|
+
projectRoot: string;
|
|
37
|
+
defaults: DefaultConfig;
|
|
38
|
+
providers: Record<ProviderId, ProviderConfig>;
|
|
39
|
+
paths: PathConfig;
|
|
40
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Provider types
|
|
2
|
+
export type { ProviderId, ModelInfo } from './provider';
|
|
3
|
+
|
|
4
|
+
// Auth types
|
|
5
|
+
export type { ApiAuth, OAuth, AuthInfo, AuthFile } from './auth';
|
|
6
|
+
|
|
7
|
+
// Config types
|
|
8
|
+
export type {
|
|
9
|
+
Scope,
|
|
10
|
+
ProviderConfig,
|
|
11
|
+
DefaultConfig,
|
|
12
|
+
PathConfig,
|
|
13
|
+
AGIConfig,
|
|
14
|
+
} from './config';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider identifiers for supported AI providers
|
|
3
|
+
*/
|
|
4
|
+
export type ProviderId =
|
|
5
|
+
| 'openai'
|
|
6
|
+
| 'anthropic'
|
|
7
|
+
| 'google'
|
|
8
|
+
| 'openrouter'
|
|
9
|
+
| 'opencode';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Information about a specific model
|
|
13
|
+
*/
|
|
14
|
+
export type ModelInfo = {
|
|
15
|
+
id: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
modalities?: { input?: string[]; output?: string[] };
|
|
18
|
+
toolCall?: boolean;
|
|
19
|
+
reasoning?: boolean;
|
|
20
|
+
attachment?: boolean;
|
|
21
|
+
temperature?: boolean | number;
|
|
22
|
+
knowledge?: string;
|
|
23
|
+
releaseDate?: string;
|
|
24
|
+
lastUpdated?: string;
|
|
25
|
+
openWeights?: boolean;
|
|
26
|
+
cost?: { input?: number; output?: number; cacheRead?: number };
|
|
27
|
+
limit?: { context?: number; output?: number };
|
|
28
|
+
};
|
package/src/global.d.ts
DELETED
package/src/tools/builtin/fs.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@agi-cli/core/tools/builtin/fs';
|
package/src/tools/builtin/git.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@agi-cli/core/tools/builtin/git';
|